From cc40d196da82d113dc8d039198ca70562533ced1 Mon Sep 17 00:00:00 2001 From: ilotterytea Date: Thu, 30 May 2024 00:48:46 +0500 Subject: feat: item purchase functionality --- .../com/ilotterytea/maxoning/ui/PurchaseItem.java | 46 +++++++++++++++++++--- 1 file changed, 41 insertions(+), 5 deletions(-) (limited to 'core/src/com/ilotterytea/maxoning/ui') 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; + } } -- cgit v1.2.3