Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/banker improvements #162

Open
wants to merge 11 commits into
base: master
Choose a base branch
from
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -30,7 +30,8 @@ public class BankerScreen extends BaseUIModelScreen<FlowLayout> {
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;
Expand All @@ -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
Expand All @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,19 +10,19 @@

<label>
<text>Bank Menu</text>
<color>white</color>
<color>black</color>
<positioning type="relative">50,5</positioning>
</label>

<label id="total-money">
<text translate="true">menu.taleofkingdoms.banker.total_money</text>
<color>white</color>
<color>black</color>
<positioning type="relative">50,8</positioning>
</label>

<label id="total-money-bank">
<text translate="true">menu.taleofkingdoms.banker.total_money_bank</text>
<color>white</color>
<color>black</color>
<positioning type="relative">50,12</positioning>
</label>

Expand All @@ -39,7 +39,7 @@

<button id="deposit-button">
<text translate="true">menu.taleofkingdoms.banker.deposit</text>
<positioning type="relative">50,50</positioning>
<positioning type="relative">50,30</positioning>
<sizing>
<horizontal method="fixed">150</horizontal>
<vertical method="fixed">20</vertical>
Expand All @@ -48,16 +48,82 @@

<button id="withdraw-button">
<text translate="true">menu.taleofkingdoms.banker.withdraw</text>
<positioning type="relative">50,60</positioning>
<positioning type="relative">50,40</positioning>
<sizing>
<horizontal method="fixed">150</horizontal>
<vertical method="fixed">20</vertical>
</sizing>
</button>

<label>
<text>Deposit</text>
<color>black</color>
<positioning type="relative">15,70</positioning>
</label>

<button id="percent-20-button-you">
<text>20%</text>
<positioning type="relative">35,70</positioning>
<sizing>
<horizontal method="fixed">45</horizontal>
<vertical method="fixed">20</vertical>
</sizing>
</button>

<button id="percent-50-button-you">
<text>50%</text>
<positioning type="relative">50,70</positioning>
<sizing>
<horizontal method="fixed">45</horizontal>
<vertical method="fixed">20</vertical>
</sizing>
</button>

<button id="percent-100-button-you">
<text>100%</text>
<positioning type="relative">65,70</positioning>
<sizing>
<horizontal method="fixed">45</horizontal>
<vertical method="fixed">20</vertical>
</sizing>
</button>

<label>
<text>Withdraw</text>
<color>black</color>
<positioning type="relative">15,80</positioning>
</label>

<button id="percent-20-button-bank">
<text>20%</text>
<positioning type="relative">35,80</positioning>
<sizing>
<horizontal method="fixed">45</horizontal>
<vertical method="fixed">20</vertical>
</sizing>
</button>

<button id="percent-50-button-bank">
<text>50%</text>
<positioning type="relative">50,80</positioning>
<sizing>
<horizontal method="fixed">45</horizontal>
<vertical method="fixed">20</vertical>
</sizing>
</button>

<button id="percent-100-button-bank">
<text>100%</text>
<positioning type="relative">65,80</positioning>
<sizing>
<horizontal method="fixed">45</horizontal>
<vertical method="fixed">20</vertical>
</sizing>
</button>

<button id="exit-button">
<text translate="true">menu.taleofkingdoms.generic.exit</text>
<positioning type="relative">50,85</positioning>
<positioning type="relative">50,125</positioning>
<sizing>
<horizontal method="fixed">150</horizontal>
<vertical method="fixed">20</vertical>
Expand All @@ -84,4 +150,4 @@
</surface>
</flow-layout>
</components>
</owo-ui>
</owo-ui>
Loading