diff --git a/src/client/java/com/convallyria/taleofkingdoms/client/gui/entity/BankerScreen.java b/src/client/java/com/convallyria/taleofkingdoms/client/gui/entity/BankerScreen.java index b6ddf9d6..0dff84a0 100644 --- a/src/client/java/com/convallyria/taleofkingdoms/client/gui/entity/BankerScreen.java +++ b/src/client/java/com/convallyria/taleofkingdoms/client/gui/entity/BankerScreen.java @@ -2,11 +2,11 @@ import com.convallyria.taleofkingdoms.TaleOfKingdoms; import com.convallyria.taleofkingdoms.client.TaleOfKingdomsClient; -import com.convallyria.taleofkingdoms.common.packet.c2s.BankerInteractPacket; -import com.convallyria.taleofkingdoms.common.translation.Translations; import com.convallyria.taleofkingdoms.common.entity.guild.BankerEntity; import com.convallyria.taleofkingdoms.common.entity.guild.banker.BankerMethod; import com.convallyria.taleofkingdoms.common.packet.Packets; +import com.convallyria.taleofkingdoms.common.packet.c2s.BankerInteractPacket; +import com.convallyria.taleofkingdoms.common.translation.Translations; import com.convallyria.taleofkingdoms.common.world.ConquestInstance; import com.convallyria.taleofkingdoms.common.world.guild.GuildPlayer; import io.wispforest.owo.ui.base.BaseUIModelScreen; @@ -30,7 +30,8 @@ public class BankerScreen extends BaseUIModelScreen { private LabelComponent totalMoney, totalMoneyBank; public BankerScreen(PlayerEntity player, BankerEntity entity, ConquestInstance instance) { - super(FlowLayout.class, BaseUIModelScreen.DataSource.asset(Identifier.of(TaleOfKingdoms.MODID, "banker_ui_model"))); + super(FlowLayout.class, BaseUIModelScreen.DataSource.asset( + Identifier.of(TaleOfKingdoms.MODID, "banker_ui_model"))); this.player = player; this.entity = entity; this.instance = instance; @@ -40,65 +41,104 @@ public BankerScreen(PlayerEntity player, BankerEntity entity, ConquestInstance i @Override protected void build(FlowLayout rootComponent) { - final FlowLayout inner = rootComponent.childById(FlowLayout.class, "inner"); - this.totalMoney = inner.childById(LabelComponent.class, "total-money").text(Text.translatable(Translations.BANK_TOTAL_MONEY.getKey(), guildPlayer.getCoins())); - this.totalMoneyBank = inner.childById(LabelComponent.class, "total-money-bank").text(Text.translatable(Translations.BANK_TOTAL_MONEY_BANK.getKey(), guildPlayer.getBankerCoins())); + this.totalMoney = rootComponent.childById(LabelComponent.class, "total-money") + .text(Text.translatable(Translations.BANK_TOTAL_MONEY.getKey(), guildPlayer.getCoins())); + this.totalMoneyBank = rootComponent.childById(LabelComponent.class, "total-money-bank") + .text(Text.translatable(Translations.BANK_TOTAL_MONEY_BANK.getKey(), guildPlayer.getBankerCoins())); - final TextBoxComponent textInput = inner.childById(TextBoxComponent.class, "input-box"); + final TextBoxComponent textInput = rootComponent.childById(TextBoxComponent.class, "input-box"); - inner.childById(ButtonComponent.class, "deposit-button").onPress(b -> { + rootComponent.childById(ButtonComponent.class, "deposit-button").onPress(b -> { try { int coins = Integer.parseInt(textInput.getText()); - if (guildPlayer.getCoins() == 0 && guildPlayer.getBankerCoins() == 0) { - Translations.BANK_ZERO.send(player); - this.close(); - return; - } - - if (guildPlayer.getCoins() >= coins) { - Translations.BANK_NO_SPEND.send(player); - this.close(); - if (MinecraftClient.getInstance().getServer() == null) { - TaleOfKingdomsClient.getAPI().getClientPacket(Packets.BANKER_INTERACT) - .sendPacket(player, new BankerInteractPacket(BankerMethod.DEPOSIT, coins)); - return; - } - guildPlayer.setCoins(guildPlayer.getCoins() - coins); - guildPlayer.setBankerCoins(guildPlayer.getBankerCoins() + coins); - } + handleTransaction(coins, BankerMethod.DEPOSIT); } catch (NumberFormatException e) { Translations.BANK_INPUT.send(player); this.close(); } }); - inner.childById(ButtonComponent.class, "withdraw-button").onPress(b -> { + rootComponent.childById(ButtonComponent.class, "withdraw-button").onPress(b -> { try { int coins = Integer.parseInt(textInput.getText()); - if (guildPlayer.getCoins() == 0 && guildPlayer.getBankerCoins() == 0) { - Translations.BANK_ZERO.send(player); - this.close(); - return; - } - if (guildPlayer.getBankerCoins() >= coins) { - Translations.BANK_THERE.send(player); - this.close(); - if (MinecraftClient.getInstance().getServer() == null) { - TaleOfKingdomsClient.getAPI().getClientPacket(Packets.BANKER_INTERACT) - .sendPacket(player, new BankerInteractPacket(BankerMethod.WITHDRAW, coins)); - return; - } - guildPlayer.setBankerCoins(guildPlayer.getBankerCoins() - coins); - instance.addCoins(player.getUuid(), coins); - } + handleTransaction(coins, BankerMethod.WITHDRAW); } catch (NumberFormatException e) { Translations.BANK_INPUT.send(player); this.close(); } }); - inner.childById(ButtonComponent.class, "exit-button").onPress(b -> this.close()); + rootComponent.childById(ButtonComponent.class, "percent-20-button-you").onPress(b -> { + int amount = (int) (guildPlayer.getCoins() * 0.20); + handleTransaction(amount, BankerMethod.DEPOSIT); + }); + + rootComponent.childById(ButtonComponent.class, "percent-50-button-you").onPress(b -> { + int amount = (int) (guildPlayer.getCoins() * 0.50); + handleTransaction(amount, BankerMethod.DEPOSIT); + }); + + rootComponent.childById(ButtonComponent.class, "percent-100-button-you").onPress(b -> { + int amount = guildPlayer.getCoins(); + handleTransaction(amount, BankerMethod.DEPOSIT); + }); + + rootComponent.childById(ButtonComponent.class, "percent-20-button-bank").onPress(b -> { + int amount = (int) (guildPlayer.getBankerCoins() * 0.20); + handleTransaction(amount, BankerMethod.WITHDRAW); + }); + + rootComponent.childById(ButtonComponent.class, "percent-50-button-bank").onPress(b -> { + int amount = (int) (guildPlayer.getBankerCoins() * 0.50); + handleTransaction(amount, BankerMethod.WITHDRAW); + }); + + rootComponent.childById(ButtonComponent.class, "percent-100-button-bank").onPress(b -> { + int amount = guildPlayer.getBankerCoins(); + handleTransaction(amount, BankerMethod.WITHDRAW); + }); + + rootComponent.childById(ButtonComponent.class, "exit-button").onPress(b -> this.close()); + } + + private void handleTransaction(int coins, BankerMethod method) { + if (coins <= 0) { + Translations.BANK_ZERO.send(player); + return; + } + + if (guildPlayer.getCoins() == 0 && guildPlayer.getBankerCoins() == 0) { + Translations.BANK_ZERO.send(player); + return; + } + + if (method == BankerMethod.DEPOSIT) { + if (guildPlayer.getCoins() >= coins) { + if (MinecraftClient.getInstance().getServer() == null) { + TaleOfKingdomsClient.getAPI().getClientPacket(Packets.BANKER_INTERACT) + .sendPacket(player, new BankerInteractPacket(method, coins)); + } else { + guildPlayer.setCoins(guildPlayer.getCoins() - coins); + guildPlayer.setBankerCoins(guildPlayer.getBankerCoins() + coins); + } + Translations.BANK_NO_SPEND.send(player); + } else { + Translations.BANK_ZERO.send(player); + } + } else if (method == BankerMethod.WITHDRAW) { + if (guildPlayer.getBankerCoins() >= coins) { + if (MinecraftClient.getInstance().getServer() == null) { + TaleOfKingdomsClient.getAPI().getClientPacket(Packets.BANKER_INTERACT) + .sendPacket(player, new BankerInteractPacket(method, coins)); + } else { + guildPlayer.setBankerCoins(guildPlayer.getBankerCoins() - coins); + instance.addCoins(player.getUuid(), coins); + } + } else { + Translations.BANK_THERE.send(player); + } + } } @Override @@ -109,8 +149,10 @@ public void close() { @Override public void render(DrawContext context, int mouseX, int mouseY, float delta) { super.render(context, mouseX, mouseY, delta); - this.totalMoney.text(Text.translatable(Translations.BANK_TOTAL_MONEY.getKey(), guildPlayer.getCoins())); - this.totalMoneyBank.text(Text.translatable(Translations.BANK_TOTAL_MONEY_BANK.getKey(), guildPlayer.getBankerCoins())); + this.totalMoney.text(Text.translatable( + Translations.BANK_TOTAL_MONEY.getKey(), guildPlayer.getCoins())); + this.totalMoneyBank.text(Text.translatable( + Translations.BANK_TOTAL_MONEY_BANK.getKey(), guildPlayer.getBankerCoins())); } @Override diff --git a/src/client/java/com/convallyria/taleofkingdoms/client/gui/generic/ScreenContinueConquest.java b/src/client/java/com/convallyria/taleofkingdoms/client/gui/generic/ScreenContinueConquest.java index b1a4caa4..dae70e33 100644 --- a/src/client/java/com/convallyria/taleofkingdoms/client/gui/generic/ScreenContinueConquest.java +++ b/src/client/java/com/convallyria/taleofkingdoms/client/gui/generic/ScreenContinueConquest.java @@ -31,13 +31,12 @@ public void init() { @Override public void render(DrawContext context, int mouseX, int mouseY, float delta) { - this.renderBackground(context, mouseX, mouseY, delta); + super.render(context, mouseX, mouseY, delta); context.drawCenteredTextWithShadow(this.textRenderer, MinecraftClient.getInstance().player.getName().getString() + ", your conquest, " + instance.getName() + ", has come far.", this.width / 2, this.height / 2 + 40, 0xFFFFFF); context.drawCenteredTextWithShadow(this.textRenderer, "Now you seek to venture further, and continue your journey.", this.width / 2, this.height / 2 + 50, 0xFFFFFF); context.drawCenteredTextWithShadow(this.textRenderer, "Safe travels, and go forth!", this.width / 2, this.height / 2 + 60, 0xFFFFFF); - super.render(context, mouseX, mouseY, delta); } @Override diff --git a/src/main/resources/assets/taleofkingdoms/owo_ui/banker_ui_model.xml b/src/main/resources/assets/taleofkingdoms/owo_ui/banker_ui_model.xml index 16029758..8eb11336 100644 --- a/src/main/resources/assets/taleofkingdoms/owo_ui/banker_ui_model.xml +++ b/src/main/resources/assets/taleofkingdoms/owo_ui/banker_ui_model.xml @@ -10,19 +10,19 @@ @@ -39,7 +39,7 @@ + + + + + + + + + + + + + + + +