summaryrefslogtreecommitdiff
path: root/core/src/com/ilotterytea/maxoning/ui
diff options
context:
space:
mode:
authorilotterytea <iltsu@alright.party>2024-05-30 00:48:46 +0500
committerilotterytea <iltsu@alright.party>2024-05-30 00:48:46 +0500
commitcc40d196da82d113dc8d039198ca70562533ced1 (patch)
treea05172e983e1983aabf17ac62cfcfe2653199fcc /core/src/com/ilotterytea/maxoning/ui
parenta99ad4295f6415578b700f9dede0e15eea77c7ae (diff)
feat: item purchase functionality
Diffstat (limited to 'core/src/com/ilotterytea/maxoning/ui')
-rw-r--r--core/src/com/ilotterytea/maxoning/ui/PurchaseItem.java46
1 files changed, 41 insertions, 5 deletions
diff --git a/core/src/com/ilotterytea/maxoning/ui/PurchaseItem.java b/core/src/com/ilotterytea/maxoning/ui/PurchaseItem.java
index 7f6d44c..fb69d4f 100644
--- a/core/src/com/ilotterytea/maxoning/ui/PurchaseItem.java
+++ b/core/src/com/ilotterytea/maxoning/ui/PurchaseItem.java
@@ -9,6 +9,12 @@ import com.ilotterytea.maxoning.MaxonConstants;
import com.ilotterytea.maxoning.player.MaxonItem;
public class PurchaseItem extends Table {
+ private double price;
+ private final Label priceLabel;
+ private final MaxonItem item;
+
+ private boolean isDisabled = false;
+
public PurchaseItem(
Skin skin,
MaxonItem item
@@ -19,31 +25,61 @@ public class PurchaseItem extends Table {
super.add(item.icon).size(64f).pad(6f);
+ this.price = item.price;
+ this.item = item;
+
Table summary = new Table();
summary.align(Align.topLeft);
Label name = new Label(item.name, skin, "item_title");
name.setAlignment(Align.left);
- Label desc = new Label(String.format("%s SQP (%s/click)", MaxonConstants.DECIMAL_FORMAT.format(item.price), MaxonConstants.DECIMAL_FORMAT.format(item.multiplier)), skin, "item_price");
- desc.setAlignment(Align.left);
+ this.priceLabel = new Label(String.format("%s SQP (%s/click)", MaxonConstants.DECIMAL_FORMAT.format(price), MaxonConstants.DECIMAL_FORMAT.format(item.multiplier)), skin, "item_price");
+ this.priceLabel.setAlignment(Align.left);
summary.add(name).align(Align.left).row();
- summary.add(desc).grow();
+ summary.add(this.priceLabel).grow();
super.add(summary).grow();
super.addListener(new ClickListener() {
@Override
public void enter(InputEvent event, float x, float y, int pointer, Actor fromActor) {
- PurchaseItem.super.setBackground("shop_item_hover");
super.enter(event, x, y, pointer, fromActor);
+ if (!isDisabled) {
+ PurchaseItem.super.setBackground("shop_item_hover");
+ }
}
@Override
public void exit(InputEvent event, float x, float y, int pointer, Actor toActor) {
- PurchaseItem.super.setBackground("shop_item");
super.exit(event, x, y, pointer, toActor);
+ if (!isDisabled) {
+ PurchaseItem.super.setBackground("shop_item");
+ }
}
});
}
+
+ public void setPrice(double price) {
+ this.price = price;
+ this.priceLabel.setText(String.format("%s SQP (%s/click)", MaxonConstants.DECIMAL_FORMAT.format(price), MaxonConstants.DECIMAL_FORMAT.format(item.multiplier)));
+ }
+
+ public double getPrice() {
+ return price;
+ }
+
+ public boolean isDisabled() {
+ return isDisabled;
+ }
+
+ public void setDisabled(boolean disabled) {
+ isDisabled = disabled;
+
+ super.setBackground(isDisabled ? "bg" : "shop_item");
+ }
+
+ public MaxonItem getItem() {
+ return item;
+ }
}