Skip to content

Commit

Permalink
Merge pull request #61 from hdescottes/Add_rarity_to_items
Browse files Browse the repository at this point in the history
Add rarity to items
  • Loading branch information
hdescottes authored Jun 2, 2024
2 parents c30bf9f + 1de6d2b commit 87f9523
Show file tree
Hide file tree
Showing 6 changed files with 405 additions and 323 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ lib/
*.hprof
.DS_Store
*.sav
/**/settings/keys.json
**/settings

### STS ###
.apt_generated
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ graph TD;

- [x] battle feature
- [ ] entities' animation while attacking
- [ ] ultimate attack cutscene
- [ ] implement bonus gained by class
- [ ] implement magic, resist, ... stats

Expand Down
36 changes: 36 additions & 0 deletions core/src/main/java/com/gdx/game/inventory/InventoryItem.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.gdx.game.inventory;

import com.badlogic.gdx.graphics.Color;
import com.badlogic.gdx.graphics.g2d.TextureRegion;
import com.badlogic.gdx.math.MathUtils;
import com.badlogic.gdx.scenes.scene2d.ui.Image;
Expand Down Expand Up @@ -61,10 +62,36 @@ public enum ItemTypeID {
NONE
}

public enum ItemRarity {
COMMON("Common", Color.DARK_GRAY),
UNCOMMON("Uncommon", Color.GREEN),
RARE("Rare", Color.BLUE),
EPIC("Epic", Color.MAGENTA),
LEGENDARY("Legendary", Color.ORANGE),
UNIQUE("Unique", Color.RED);

private final String value;
private final Color itemRarityColor;

ItemRarity(String value, Color itemRarityColor) {
this.value = value;
this.itemRarityColor = itemRarityColor;
}

public String getValue() {
return value;
}

public Color getColor() {
return itemRarityColor;
}
}

private int itemAttributes;
private int itemUseType;
private int itemUseTypeValue;
private ItemTypeID itemTypeID;
private ItemRarity itemRarity;
private String itemShortDescription;
private int itemValue;

Expand All @@ -88,6 +115,7 @@ public InventoryItem(InventoryItem inventoryItem) {
this.itemAttributes = inventoryItem.getItemAttributes();
this.itemUseType = inventoryItem.getItemUseType();
this.itemUseTypeValue = inventoryItem.getItemUseTypeValue();
this.itemRarity = inventoryItem.getItemRarity();
this.itemShortDescription = inventoryItem.getItemShortDescription();
this.itemValue = inventoryItem.getItemValue();
}
Expand Down Expand Up @@ -132,6 +160,14 @@ public void setItemUseType(int itemUseType) {
this.itemUseType = itemUseType;
}

public ItemRarity getItemRarity() {
return itemRarity;
}

public void setItemRarity(ItemRarity itemRarity) {
this.itemRarity = itemRarity;
}

public String getItemShortDescription() {
return itemShortDescription;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,12 @@ public void setVisible(InventorySlot inventorySlot, boolean visible) {
}
}

public void updateDescription(InventorySlot inventorySlot){
public void updateTooltip(InventorySlot inventorySlot) {
if (inventorySlot.hasItem()) {
StringBuilder string = new StringBuilder();
InventoryItem item = inventorySlot.getTopInventoryItem();
string.append(String.format("Rarity: %s", item.getItemRarity().getValue()));
string.append(System.getProperty("line.separator"));
string.append(item.getItemShortDescription());
if (item.isInventoryItemOffensive()) {
string.append(System.getProperty("line.separator"));
Expand All @@ -52,6 +54,9 @@ public void updateDescription(InventorySlot inventorySlot){
string.append(String.format("Trade Value: %s GP", item.getTradeValue()));

description.setText(string);

this.getTitleLabel().setText(item.getItemTypeID().toString());
this.getTitleLabel().setColor(item.getItemRarity().getColor());
} else {
description.setText("");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public void enter(InputEvent event, float x, float y, int pointer, Actor fromAct
currentCoords.set(x, y);
inventorySlot.localToStageCoordinates(currentCoords);

tooltip.updateDescription(inventorySlot);
tooltip.updateTooltip(inventorySlot);
tooltip.setPosition(currentCoords.x + offset.x, currentCoords.y + offset.y);
tooltip.toFront();
tooltip.setVisible(inventorySlot, true);
Expand Down
Loading

0 comments on commit 87f9523

Please sign in to comment.