From 680fc98d510281435c12bd7e957e8bfad064b59a Mon Sep 17 00:00:00 2001 From: luisc Date: Tue, 13 Feb 2024 17:30:01 -0600 Subject: [PATCH] Implemented proper functionality for the quest party options GUI. --- .../client/gui/SubGuiNpcPartyOptions.java | 61 +++++++++++++++++-- .../npcs/client/gui/SubGuiNpcQuest.java | 6 +- .../npcs/client/gui/util/GuiNpcButton.java | 32 +++++++--- .../npcs/controllers/data/PartyOptions.java | 7 +-- .../assets/customnpcs/lang/en_US.lang | 8 ++- 5 files changed, 91 insertions(+), 23 deletions(-) diff --git a/src/main/java/noppes/npcs/client/gui/SubGuiNpcPartyOptions.java b/src/main/java/noppes/npcs/client/gui/SubGuiNpcPartyOptions.java index 51f1a1063..c6f0e206c 100644 --- a/src/main/java/noppes/npcs/client/gui/SubGuiNpcPartyOptions.java +++ b/src/main/java/noppes/npcs/client/gui/SubGuiNpcPartyOptions.java @@ -5,16 +5,17 @@ import net.minecraft.util.StatCollector; import noppes.npcs.client.Client; import noppes.npcs.client.gui.util.*; import noppes.npcs.constants.EnumPacketServer; +import noppes.npcs.constants.EnumPartyExchange; +import noppes.npcs.constants.EnumPartyRequirements; import noppes.npcs.controllers.data.FactionOptions; import noppes.npcs.controllers.data.PartyOptions; import java.util.HashMap; import java.util.Vector; -public class SubGuiNpcPartyOptions extends SubGuiInterface +public class SubGuiNpcPartyOptions extends SubGuiInterface implements ITextfieldListener { private final PartyOptions options; - private HashMap data = new HashMap<>(); public SubGuiNpcPartyOptions(PartyOptions options) { @@ -29,16 +30,66 @@ public class SubGuiNpcPartyOptions extends SubGuiInterface { super.initGui(); + //Allow party - T/F button + addButton(new GuiNpcButton(0, guiLeft + 90, guiTop + 10, 60, 20, + new String[]{"gui.no", "gui.yes"}, options.allowParty ? 1 : 0)); + addLabel(new GuiNpcLabel(1, "party.allowParty", guiLeft + 10, guiTop + 17)); + + if (options.allowParty) { + //Party requirements - enum button + addButton(new GuiNpcButton(5, guiLeft + 110, guiTop + 35, 60, 20, + EnumPartyRequirements.values(), options.partyRequirements.ordinal())); + addLabel(new GuiNpcLabel(6, "party.partyRequirements", guiLeft + 10, guiTop + 42)); + + //Party rewards - enum button + addButton(new GuiNpcButton(10, guiLeft + 110, guiTop + 60, 60, 20, + EnumPartyExchange.values(), options.rewardControl.ordinal())); + addLabel(new GuiNpcLabel(11, "party.partyRewards", guiLeft + 10, guiTop + 67)); + + //Complete for - enum button + addButton(new GuiNpcButton(15, guiLeft + 110, guiTop + 85, 60, 20, + EnumPartyExchange.values(), options.completeFor.ordinal())); + addLabel(new GuiNpcLabel(16, "party.completeFor", guiLeft + 10, guiTop + 92)); + + //max party size - number field + GuiNpcTextField textField = new GuiNpcTextField(20, this, guiLeft + 110, guiTop + 110, + 40, 20, String.valueOf(options.maxPartySize)); + textField.integersOnly = true; + textField.setMinMaxDefault(1, Integer.MAX_VALUE, 4); + addTextField(textField); + addLabel(new GuiNpcLabel(20, "party.maxPartySize", guiLeft + 10, guiTop + 117)); + } + addButton(new GuiNpcButton(66, guiLeft + 20, guiTop + 192, 90, 20, "gui.done")); } protected void actionPerformed(GuiButton guibutton) { int id = guibutton.id; + switch (id) { + case 0: + options.allowParty = !options.allowParty; + break; + case 5: + options.partyRequirements = EnumPartyRequirements.valueOf(guibutton.displayString); + break; + case 10: + options.rewardControl = EnumPartyExchange.valueOf(guibutton.displayString); + break; + case 15: + options.completeFor = EnumPartyExchange.valueOf(guibutton.displayString); + break; + case 66: + close(); + break; + } + initGui(); + } - if(id == 66) - { - close(); + @Override + public void unFocused(GuiNpcTextField textfield) { + if (textfield.id == 20) { + options.maxPartySize = textfield.getInteger(); } } } diff --git a/src/main/java/noppes/npcs/client/gui/SubGuiNpcQuest.java b/src/main/java/noppes/npcs/client/gui/SubGuiNpcQuest.java index af9d2169a..79ac3ee37 100644 --- a/src/main/java/noppes/npcs/client/gui/SubGuiNpcQuest.java +++ b/src/main/java/noppes/npcs/client/gui/SubGuiNpcQuest.java @@ -63,8 +63,8 @@ public class SubGuiNpcQuest extends SubGuiInterface implements ISubGuiListener, addButton(new GuiNpcButton(6, guiLeft + 240, guiTop + 76, 60, 20, new String[]{"quest.item","quest.dialog","quest.kill","quest.location","quest.areakill"},quest.type.ordinal())); addButton(new GuiNpcButton(7, guiLeft + 303, guiTop + 76,50, 20, "selectServer.edit")); - addLabel(new GuiNpcLabel(17, "party.options", guiLeft + 180, guiTop + 105)); - addButton(new GuiNpcButton(18, guiLeft + 303, guiTop + 100, 50, 20, "selectServer.edit")); + addLabel(new GuiNpcLabel(17, "party.options", guiLeft + 180, guiTop + 135)); + addButton(new GuiNpcButton(18, guiLeft + 303, guiTop + 130, 50, 20, "selectServer.edit")); this.addButton(new GuiNpcButton(9, guiLeft + 7, guiTop + 102,90, 20, new String[]{"quest.npc","quest.instant"},quest.completion.ordinal())); if(quest.completerNpc.isEmpty() && npc != null) @@ -90,7 +90,7 @@ public class SubGuiNpcQuest extends SubGuiInterface implements ISubGuiListener, if(!quest.mail.subject.isEmpty()) getButton(13).setDisplayText(quest.mail.subject); } - + public void buttonEvent(GuiButton guibutton) { GuiNpcButton button = (GuiNpcButton) guibutton; diff --git a/src/main/java/noppes/npcs/client/gui/util/GuiNpcButton.java b/src/main/java/noppes/npcs/client/gui/util/GuiNpcButton.java index a59baa980..5e1c12201 100644 --- a/src/main/java/noppes/npcs/client/gui/util/GuiNpcButton.java +++ b/src/main/java/noppes/npcs/client/gui/util/GuiNpcButton.java @@ -4,12 +4,14 @@ import net.minecraft.client.Minecraft; import net.minecraft.client.gui.GuiButton; import net.minecraft.util.StatCollector; +import java.util.ArrayList; + public class GuiNpcButton extends GuiButton{ - + protected String[] display; private int displayValue = 0; public int id; - + public GuiNpcButton(int i, int j, int k, String s) { super(i, j, k, StatCollector.translateToLocal(s)); id = i; @@ -29,28 +31,42 @@ public class GuiNpcButton extends GuiButton{ this.display = display; this.displayValue = display.length == 0?0:val % display.length; } + + public GuiNpcButton(int i, int j, int k, int l, int m, Enum[] displayEnums, + int val) { + this(i, j, k, l, m, displayEnums.length == 0 ? "" : displayEnums[val % displayEnums.length].toString()); + + ArrayList strings = new ArrayList<>(); + for (Enum e : displayEnums) { + strings.add(e.toString()); + } + + this.display = strings.toArray(new String[0]); + this.displayValue = display.length == 0?0:val % display.length; + } + public void setDisplayText(String text){ this.displayString = StatCollector.translateToLocal(text); } public int getValue(){ return displayValue; } - + public void setEnabled(boolean bo){ this.enabled = bo; } public void setVisible(boolean b) { this.visible = b; - } + } public boolean getVisible() { return visible; } - + public void setDisplay(int value){ this.displayValue = value; this.setDisplayText(display[value]); - } - + } + public void setTextColor(int color){ this.packedFGColour = color; } @@ -65,7 +81,7 @@ public class GuiNpcButton extends GuiButton{ } return bo; } - + public int getWidth() { return width; } diff --git a/src/main/java/noppes/npcs/controllers/data/PartyOptions.java b/src/main/java/noppes/npcs/controllers/data/PartyOptions.java index f6e413764..aaad76ba3 100644 --- a/src/main/java/noppes/npcs/controllers/data/PartyOptions.java +++ b/src/main/java/noppes/npcs/controllers/data/PartyOptions.java @@ -1,23 +1,18 @@ package noppes.npcs.controllers.data; -import net.minecraft.entity.player.EntityPlayer; import net.minecraft.nbt.NBTTagCompound; -import net.minecraft.util.ChatComponentTranslation; import noppes.npcs.api.handler.data.IPartyOptions; import noppes.npcs.config.ConfigMain; import noppes.npcs.constants.EnumPartyExchange; import noppes.npcs.constants.EnumPartyRequirements; -import noppes.npcs.controllers.FactionController; -import noppes.npcs.controllers.PlayerDataController; public class PartyOptions implements IPartyOptions { - public boolean allowParty = false; public EnumPartyRequirements partyRequirements = EnumPartyRequirements.Leader; public EnumPartyExchange rewardControl = EnumPartyExchange.Leader; public EnumPartyExchange completeFor = EnumPartyExchange.Leader; public int maxPartySize = ConfigMain.DefaultMaxPartySize; - + public void readFromNBT(NBTTagCompound compound) { // Party Management diff --git a/src/main/resources/assets/customnpcs/lang/en_US.lang b/src/main/resources/assets/customnpcs/lang/en_US.lang index 7a29a70a4..65c68a44f 100644 --- a/src/main/resources/assets/customnpcs/lang/en_US.lang +++ b/src/main/resources/assets/customnpcs/lang/en_US.lang @@ -133,6 +133,8 @@ gui.off=Off gui.on=On party.accept=Accept +party.allowParty=Allow Partying +party.completeFor=Complete For party.createParty=Create Party party.disbandParty=Disband Party party.disbandConfirm=Are you sure you want to disband the party? @@ -148,11 +150,15 @@ party.leaderConfirm=Are you sure you want to make this player the party leader? party.leaveParty=Leave Party party.leaveConfirm=Are you sure you want to leave the party? party.makeLeader=Make Leader +party.maxPartySize=Max Party Size +party.options=Party Options party.party=Party party.partying=Partying! party.partyInfo1=You're not in a party! party.partyInfo2=Either wait for an invite party.partyInfo3=or create one. +party.partyRequirements=Party Requirements +party.partyRewards=Party Rewards scale.shared=Shared filter.contains=Contains @@ -1162,4 +1168,4 @@ markov.gender.either=Either markov.gender.female=Female markov.gender.male=Male -markov.generate=Generate \ No newline at end of file +markov.generate=Generate