diff --git a/src/main/java/noppes/npcs/client/gui/GuiNPCDialogSelection.java b/src/main/java/noppes/npcs/client/gui/GuiNPCDialogSelection.java deleted file mode 100644 index ad743701b..000000000 --- a/src/main/java/noppes/npcs/client/gui/GuiNPCDialogSelection.java +++ /dev/null @@ -1,119 +0,0 @@ -package noppes.npcs.client.gui; - -import net.minecraft.client.gui.GuiButton; -import net.minecraft.client.gui.GuiScreen; -import noppes.npcs.client.Client; -import noppes.npcs.client.NoppesUtil; -import noppes.npcs.client.gui.util.*; -import noppes.npcs.constants.EnumPacketServer; -import noppes.npcs.entity.EntityNPCInterface; - -import java.util.HashMap; -import java.util.Vector; - -public class GuiNPCDialogSelection extends GuiNPCInterface implements IScrollData -{ - private GuiNPCStringSlot slot; - private GuiScreen parent; - private HashMap data = new HashMap(); - private int dialog; - private boolean selectCategory = true; - public GuiSelectionListener listener; - public GuiNPCDialogSelection(EntityNPCInterface npc,GuiScreen parent,int dialog) - { - super(npc); - drawDefaultBackground = false; - title = "Select Dialog Category"; - this.parent = parent; - this.dialog = dialog; - - - if(dialog >= 0){ - Client.sendData(EnumPacketServer.DialogsGetFromDialog, dialog); - selectCategory = false; - title = "Select Dialog"; - }else - Client.sendData(EnumPacketServer.DialogCategoriesGet, dialog); - - if(parent instanceof GuiSelectionListener){ - listener = (GuiSelectionListener) parent; - } - } - - public void initGui() - { - super.initGui(); - Vector list = new Vector(); - - slot = new GuiNPCStringSlot(list,this,false,18); - slot.registerScrollButtons(4, 5); - - this.addButton(new GuiNpcButton(2, width / 2 -100, height - 41,98, 20, "gui.back")); - this.addButton(new GuiNpcButton(4, width / 2 + 2, height - 41,98, 20, "gui.select")); - } - - - public void drawScreen(int i, int j, float f) - { - slot.drawScreen(i, j, f); - super.drawScreen(i, j, f); - } - - protected void actionPerformed(GuiButton guibutton) - { - int id = guibutton.id; - if(id == 2) - { - if(selectCategory){ - close(); - NoppesUtil.openGUI(player, parent); - }else{ - title = "Select Dialog Category"; - selectCategory = true; - Client.sendData(EnumPacketServer.DialogCategoriesGet, dialog); - } - } - if(id == 4) - { - doubleClicked(); - } - } - public void doubleClicked() { - if(slot.selected == null || slot.selected.isEmpty()) - return; - if(selectCategory){ - selectCategory = false; - title = "Select Dialog"; - Client.sendData(EnumPacketServer.DialogsGet, data.get(slot.selected)); - } - else{ - dialog = data.get(slot.selected); - close(); - NoppesUtil.openGUI(player, parent); - } - - } - public void save() { - if(dialog >= 0){ - if(listener != null) - listener.selected(dialog, slot.selected); - } - } - - @Override - public void setData(Vector list, HashMap data) { - this.data = data; - this.slot.setList(list); - if(dialog >= 0) - for(String name : data.keySet()) - if(data.get(name) == dialog) - slot.selected = name; - } - - @Override - public void setSelected(String selected) { - - } - - -} diff --git a/src/main/java/noppes/npcs/client/gui/SubGuiMailmanSendSetup.java b/src/main/java/noppes/npcs/client/gui/SubGuiMailmanSendSetup.java index 097063ed8..fe72e3f8e 100644 --- a/src/main/java/noppes/npcs/client/gui/SubGuiMailmanSendSetup.java +++ b/src/main/java/noppes/npcs/client/gui/SubGuiMailmanSendSetup.java @@ -4,19 +4,17 @@ import net.minecraft.client.gui.GuiButton; import net.minecraft.client.gui.GuiScreen; import net.minecraft.nbt.NBTTagCompound; import noppes.npcs.client.Client; -import noppes.npcs.client.NoppesUtil; -import noppes.npcs.client.gui.global.GuiNPCQuestSelection; import noppes.npcs.client.gui.player.GuiMailmanWrite; +import noppes.npcs.client.gui.select.GuiQuestSelection; import noppes.npcs.client.gui.util.*; import noppes.npcs.constants.EnumPacketServer; import noppes.npcs.containers.ContainerMail; import noppes.npcs.controllers.data.PlayerMail; public class SubGuiMailmanSendSetup extends SubGuiInterface implements ITextfieldListener, GuiSelectionListener{ - + private PlayerMail mail; - private GuiNPCQuestSelection questSelection; - + public SubGuiMailmanSendSetup(PlayerMail mail, GuiScreen parent){ this.parent = parent; xSize = 256; @@ -40,10 +38,10 @@ public class SubGuiMailmanSendSetup extends SubGuiInterface implements ITextfiel title = "gui.select"; addButton(new GuiNpcButton(3, guiLeft + 70, guiTop + 130, 100, 20, title)); addButton(new GuiNpcButton(4, guiLeft + 171, guiTop + 130, 20, 20, "X")); - + addButton(new GuiNpcButton(0, guiLeft + 26, guiTop + 190, 100, 20, "gui.done")); addButton(new GuiNpcButton(1, guiLeft + 130, guiTop + 190, 100, 20, "gui.cancel")); - + if(player.openContainer instanceof ContainerMail){ ContainerMail container = (ContainerMail) player.openContainer; mail.items = container.mail.items; @@ -68,9 +66,7 @@ public class SubGuiMailmanSendSetup extends SubGuiInterface implements ITextfiel Client.sendData(EnumPacketServer.MailOpenSetup, mail.writeNBT()); } if(id == 3){ - questSelection = new GuiNPCQuestSelection(npc, getParent(), mail.questId); - questSelection.listener = this; - NoppesUtil.openGUI(player, questSelection); + setSubGui(new GuiQuestSelection(mail.questId)); } if(id == 4){ mail.questId = -1; @@ -81,13 +77,13 @@ public class SubGuiMailmanSendSetup extends SubGuiInterface implements ITextfiel @Override public void selected(int ob, String name) { - mail.questId = ob; - mail.questTitle = questSelection.getSelected(); + mail.questId = ob; + mail.questTitle = name; initGui(); } @Override public void save() { - + } @Override diff --git a/src/main/java/noppes/npcs/client/gui/SubGuiNpcAvailabilityDialog.java b/src/main/java/noppes/npcs/client/gui/SubGuiNpcAvailabilityDialog.java index 2ba36e16d..65ca11e53 100644 --- a/src/main/java/noppes/npcs/client/gui/SubGuiNpcAvailabilityDialog.java +++ b/src/main/java/noppes/npcs/client/gui/SubGuiNpcAvailabilityDialog.java @@ -3,7 +3,7 @@ package noppes.npcs.client.gui; import net.minecraft.client.gui.GuiButton; import net.minecraft.nbt.NBTTagCompound; import noppes.npcs.client.Client; -import noppes.npcs.client.NoppesUtil; +import noppes.npcs.client.gui.select.GuiDialogSelection; import noppes.npcs.client.gui.util.*; import noppes.npcs.constants.EnumAvailabilityDialog; import noppes.npcs.constants.EnumPacketServer; @@ -13,7 +13,7 @@ import noppes.npcs.controllers.data.Dialog; public class SubGuiNpcAvailabilityDialog extends SubGuiInterface implements GuiSelectionListener, IGuiData{ private Availability availabitily; private int slot = 0; - + public SubGuiNpcAvailabilityDialog(Availability availabitily){ this.availabitily = availabitily; setBackground("menubg.png"); @@ -51,10 +51,10 @@ public class SubGuiNpcAvailabilityDialog extends SubGuiInterface implements GuiS this.addButton(new GuiNpcButton(13, guiLeft + 56, y, 172, 20, "availability.selectdialog")); getButton(13).setEnabled(availabitily.dialog4Available != EnumAvailabilityDialog.Always); this.addButton(new GuiNpcButton(23, guiLeft + 230, y,20, 20, "X")); - - + + this.addButton(new GuiNpcButton(66, guiLeft + 82, guiTop + 192,98, 20, "gui.done")); - + updateGuiButtons(); } @@ -64,7 +64,7 @@ public class SubGuiNpcAvailabilityDialog extends SubGuiInterface implements GuiS getButton(11).setDisplayText("availability.selectdialog"); getButton(12).setDisplayText("availability.selectdialog"); getButton(13).setDisplayText("availability.selectdialog"); - + if(availabitily.dialogId >= 0){ Client.sendData(EnumPacketServer.DialogGet, availabitily.dialogId); } @@ -109,27 +109,19 @@ public class SubGuiNpcAvailabilityDialog extends SubGuiInterface implements GuiS } if(button.id == 10){ slot = 1; - GuiNPCDialogSelection gui = new GuiNPCDialogSelection(npc, getParent(), availabitily.dialogId); - gui.listener = this; - NoppesUtil.openGUI(player, gui); + setSubGui(new GuiDialogSelection(availabitily.questId)); } if(button.id == 11){ slot = 2; - GuiNPCDialogSelection gui = new GuiNPCDialogSelection(npc, getParent(), availabitily.dialog2Id); - gui.listener = this; - NoppesUtil.openGUI(player, gui); + setSubGui(new GuiDialogSelection(availabitily.quest2Id)); } if(button.id == 12){ slot = 3; - GuiNPCDialogSelection gui = new GuiNPCDialogSelection(npc, getParent(), availabitily.dialog3Id); - gui.listener = this; - NoppesUtil.openGUI(player, gui); + setSubGui(new GuiDialogSelection(availabitily.quest3Id)); } if(button.id == 13){ slot = 4; - GuiNPCDialogSelection gui = new GuiNPCDialogSelection(npc, getParent(), availabitily.dialog4Id); - gui.listener = this; - NoppesUtil.openGUI(player, gui); + setSubGui(new GuiDialogSelection(availabitily.quest4Id)); } if(button.id == 20){ availabitily.dialogId = -1; @@ -147,7 +139,6 @@ public class SubGuiNpcAvailabilityDialog extends SubGuiInterface implements GuiS availabitily.dialog4Id = -1; getButton(13).setDisplayText("availability.selectdialog"); } - if(button.id == 66){ close(); } @@ -163,7 +154,8 @@ public class SubGuiNpcAvailabilityDialog extends SubGuiInterface implements GuiS availabitily.dialog3Id = id; if(slot == 4) availabitily.dialog4Id = id; - } + updateGuiButtons(); + } @Override public void setGuiData(NBTTagCompound compound) { @@ -178,5 +170,4 @@ public class SubGuiNpcAvailabilityDialog extends SubGuiInterface implements GuiS if(availabitily.dialog4Id == dialog.id) getButton(13).setDisplayText(dialog.title); } - } diff --git a/src/main/java/noppes/npcs/client/gui/SubGuiNpcAvailabilityQuest.java b/src/main/java/noppes/npcs/client/gui/SubGuiNpcAvailabilityQuest.java index bdb2e1d8b..f8910438b 100644 --- a/src/main/java/noppes/npcs/client/gui/SubGuiNpcAvailabilityQuest.java +++ b/src/main/java/noppes/npcs/client/gui/SubGuiNpcAvailabilityQuest.java @@ -3,8 +3,8 @@ package noppes.npcs.client.gui; import net.minecraft.client.gui.GuiButton; import net.minecraft.nbt.NBTTagCompound; import noppes.npcs.client.Client; -import noppes.npcs.client.NoppesUtil; -import noppes.npcs.client.gui.global.GuiNPCQuestSelection; + +import noppes.npcs.client.gui.select.GuiQuestSelection; import noppes.npcs.client.gui.util.*; import noppes.npcs.constants.EnumAvailabilityQuest; import noppes.npcs.constants.EnumPacketServer; @@ -14,7 +14,7 @@ import noppes.npcs.controllers.data.Quest; public class SubGuiNpcAvailabilityQuest extends SubGuiInterface implements GuiSelectionListener, IGuiData { private Availability availabitily; private int slot = 0; - + public SubGuiNpcAvailabilityQuest(Availability availabitily){ this.availabitily = availabitily; setBackground("menubg.png"); @@ -29,7 +29,7 @@ public class SubGuiNpcAvailabilityQuest extends SubGuiInterface implements GuiSe addLabel(new GuiNpcLabel(1,"availability.available", guiLeft, guiTop + 4)); getLabel(1).center(xSize); - int y = guiTop + 12; + int y = guiTop + 12; this.addButton(new GuiNpcButton(0, guiLeft + 4, y, 90, 20, new String[]{"availability.always","availability.after","availability.before","availability.whenactive", "availability.whennotactive"},availabitily.questAvailable.ordinal())); this.addButton(new GuiNpcButton(10, guiLeft + 96, y, 192, 20, "availability.selectquest")); getButton(10).setEnabled(availabitily.questAvailable != EnumAvailabilityQuest.Always); @@ -52,10 +52,10 @@ public class SubGuiNpcAvailabilityQuest extends SubGuiInterface implements GuiSe this.addButton(new GuiNpcButton(13, guiLeft + 96, y, 192, 20, "availability.selectquest")); getButton(13).setEnabled(availabitily.quest4Available != EnumAvailabilityQuest.Always); this.addButton(new GuiNpcButton(23, guiLeft + 290, y, 20, 20, "X")); - - + + this.addButton(new GuiNpcButton(66, guiLeft + 82, guiTop + 192,98, 20, "gui.done")); - + updateGuiButtons(); } @@ -110,27 +110,19 @@ public class SubGuiNpcAvailabilityQuest extends SubGuiInterface implements GuiSe } if(button.id == 10){ slot = 1; - GuiNPCQuestSelection gui = new GuiNPCQuestSelection(npc, getParent(), availabitily.questId); - gui.listener = this; - NoppesUtil.openGUI(player, gui); + setSubGui(new GuiQuestSelection(availabitily.questId)); } if(button.id == 11){ slot = 2; - GuiNPCQuestSelection gui = new GuiNPCQuestSelection(npc, getParent(), availabitily.quest2Id); - gui.listener = this; - NoppesUtil.openGUI(player, gui); + setSubGui(new GuiQuestSelection(availabitily.quest2Id)); } if(button.id == 12){ slot = 3; - GuiNPCQuestSelection gui = new GuiNPCQuestSelection(npc, getParent(), availabitily.quest3Id); - gui.listener = this; - NoppesUtil.openGUI(player, gui); + setSubGui(new GuiQuestSelection(availabitily.quest3Id)); } if(button.id == 13){ slot = 4; - GuiNPCQuestSelection gui = new GuiNPCQuestSelection(npc, getParent(), availabitily.quest4Id); - gui.listener = this; - NoppesUtil.openGUI(player, gui); + setSubGui(new GuiQuestSelection(availabitily.quest4Id)); } if(button.id == 20){ @@ -165,6 +157,7 @@ public class SubGuiNpcAvailabilityQuest extends SubGuiInterface implements GuiSe availabitily.quest3Id = id; if(slot == 4) availabitily.quest4Id = id; + updateGuiButtons(); } @Override @@ -179,7 +172,7 @@ public class SubGuiNpcAvailabilityQuest extends SubGuiInterface implements GuiSe getButton(12).setDisplayText(quest.title); if(availabitily.quest4Id == quest.id) getButton(13).setDisplayText(quest.title); - + } } diff --git a/src/main/java/noppes/npcs/client/gui/SubGuiNpcDialog.java b/src/main/java/noppes/npcs/client/gui/SubGuiNpcDialog.java index a1dd989da..fe83d277a 100644 --- a/src/main/java/noppes/npcs/client/gui/SubGuiNpcDialog.java +++ b/src/main/java/noppes/npcs/client/gui/SubGuiNpcDialog.java @@ -3,9 +3,8 @@ package noppes.npcs.client.gui; import net.minecraft.client.gui.GuiButton; import net.minecraft.nbt.NBTTagCompound; import noppes.npcs.client.Client; -import noppes.npcs.client.NoppesUtil; import noppes.npcs.client.gui.global.GuiNPCManageDialogs; -import noppes.npcs.client.gui.global.GuiNPCQuestSelection; +import noppes.npcs.client.gui.select.GuiQuestSelection; import noppes.npcs.client.gui.select.GuiSoundSelection; import noppes.npcs.client.gui.util.*; import noppes.npcs.constants.EnumPacketServer; @@ -14,11 +13,9 @@ import noppes.npcs.controllers.data.PlayerMail; public class SubGuiNpcDialog extends SubGuiInterface implements ISubGuiListener, GuiSelectionListener,ITextfieldListener { - public int dialogCategoryID; public Dialog dialog; private final GuiNPCManageDialogs parent; - private GuiNPCQuestSelection questSelection; public SubGuiNpcDialog(GuiNPCManageDialogs parent, Dialog dialog, int catId) { @@ -96,9 +93,7 @@ public class SubGuiNpcDialog extends SubGuiInterface implements ISubGuiListener, setSubGui(new SubGuiNpcDialogOptions(dialog)); } if(id == 7 && dialog.id >= 0){ - questSelection = new GuiNPCQuestSelection(npc, getParent(), dialog.quest); - questSelection.listener = this; - NoppesUtil.openGUI(player, questSelection); + setSubGui(new GuiQuestSelection(dialog.quest)); } if(id == 8 && dialog.id >= 0){ dialog.quest = -1; @@ -164,6 +159,13 @@ public class SubGuiNpcDialog extends SubGuiInterface implements ISubGuiListener, else if(subgui instanceof SubGuiNpcCommand){ dialog.command = ((SubGuiNpcCommand) subgui).command; } + else if(subgui instanceof GuiQuestSelection){ + GuiQuestSelection gqs = (GuiQuestSelection) subgui; + if(gqs.selectedQuest != null) { + dialog.quest = gqs.selectedQuest.id; + initGui(); + } + } else if(subgui instanceof SubGuiMailmanSendSetup){ initGui(); } diff --git a/src/main/java/noppes/npcs/client/gui/SubGuiNpcDialogOption.java b/src/main/java/noppes/npcs/client/gui/SubGuiNpcDialogOption.java index d28d5f93d..458be325a 100644 --- a/src/main/java/noppes/npcs/client/gui/SubGuiNpcDialogOption.java +++ b/src/main/java/noppes/npcs/client/gui/SubGuiNpcDialogOption.java @@ -4,6 +4,7 @@ import net.minecraft.client.gui.GuiButton; import net.minecraft.nbt.NBTTagCompound; import noppes.npcs.client.Client; import noppes.npcs.client.NoppesUtil; +import noppes.npcs.client.gui.select.GuiDialogSelection; import noppes.npcs.client.gui.util.*; import noppes.npcs.constants.EnumOptionType; import noppes.npcs.constants.EnumPacketServer; @@ -13,7 +14,7 @@ import noppes.npcs.controllers.data.DialogOption; public class SubGuiNpcDialogOption extends SubGuiInterface implements IGuiData, ITextfieldListener, GuiSelectionListener, ISubGuiListener{ private DialogOption option; public static int LastColor = 0xe0e0e0; - + public SubGuiNpcDialogOption(DialogOption option){ this.option = option; setBackground("menubg.png"); @@ -27,17 +28,17 @@ public class SubGuiNpcDialogOption extends SubGuiInterface implements IGuiData, super.initGui(); this.addLabel(new GuiNpcLabel(66, "dialog.editoption", guiLeft, guiTop + 4)); this.getLabel(66).center(xSize); - + this.addLabel(new GuiNpcLabel(0, "gui.title", guiLeft + 4, guiTop + 20)); this.addTextField(new GuiNpcTextField(0, this, this.fontRendererObj, guiLeft + 40, guiTop + 15, 196, 20, option.title)); - + String color = Integer.toHexString(option.optionColor); while(color.length() < 6) color = 0 + color; addLabel(new GuiNpcLabel(2, "gui.color", guiLeft + 4, guiTop + 45)); this.addButton(new GuiNpcButton(2, guiLeft + 62, guiTop + 40, 92, 20, color)); this.getButton(2).setTextColor(option.optionColor); - + this.addLabel(new GuiNpcLabel(1, "dialog.optiontype", guiLeft + 4, guiTop + 67)); this.addButton(new GuiNpcButton(1, guiLeft + 62, guiTop + 62, 92, 20, new String[]{"gui.close","dialog.dialog","gui.disabled","menu.role","tile.commandBlock.name"},option.optionType.ordinal())); @@ -58,7 +59,7 @@ public class SubGuiNpcDialogOption extends SubGuiInterface implements IGuiData, } this.addButton(new GuiNpcButton(66, guiLeft + 82, guiTop + 190,98, 20, "gui.done")); - + } @Override @@ -73,9 +74,7 @@ public class SubGuiNpcDialogOption extends SubGuiInterface implements IGuiData, this.setSubGui(new SubGuiColorSelector(option.optionColor)); } if(button.id == 3){ - GuiNPCDialogSelection gui = new GuiNPCDialogSelection(npc, getParent(), option.dialogId); - gui.listener = this; - NoppesUtil.openGUI(player, gui); + setSubGui(new GuiDialogSelection(option.dialogId)); } if(button.id == 66) { @@ -115,8 +114,16 @@ public class SubGuiNpcDialogOption extends SubGuiInterface implements IGuiData, @Override public void subGuiClosed(SubGuiInterface subgui) { - LastColor = option.optionColor = ((SubGuiColorSelector)subgui).color; - initGui(); + if(subgui instanceof SubGuiColorSelector) { + LastColor = option.optionColor = ((SubGuiColorSelector)subgui).color; + } + if(subgui instanceof GuiDialogSelection) { + Dialog dialog = ((GuiDialogSelection)subgui).selectedDialog; + if(dialog != null) { + option.dialogId = dialog.id; + } + } + initGui(); } } diff --git a/src/main/java/noppes/npcs/client/gui/SubGuiNpcQuest.java b/src/main/java/noppes/npcs/client/gui/SubGuiNpcQuest.java index 7c11c716a..482b04217 100644 --- a/src/main/java/noppes/npcs/client/gui/SubGuiNpcQuest.java +++ b/src/main/java/noppes/npcs/client/gui/SubGuiNpcQuest.java @@ -3,12 +3,11 @@ package noppes.npcs.client.gui; import net.minecraft.client.gui.GuiButton; import net.minecraft.nbt.NBTTagCompound; import noppes.npcs.client.Client; -import noppes.npcs.client.NoppesUtil; import noppes.npcs.client.gui.global.GuiNPCManageQuest; -import noppes.npcs.client.gui.global.GuiNPCQuestSelection; import noppes.npcs.client.gui.questtypes.GuiNpcQuestTypeDialog; import noppes.npcs.client.gui.questtypes.GuiNpcQuestTypeKill; import noppes.npcs.client.gui.questtypes.GuiNpcQuestTypeLocation; +import noppes.npcs.client.gui.select.GuiQuestSelection; import noppes.npcs.client.gui.util.*; import noppes.npcs.constants.*; import noppes.npcs.controllers.data.PlayerMail; @@ -21,7 +20,6 @@ public class SubGuiNpcQuest extends SubGuiInterface implements ISubGuiListener, public Quest quest; private final GuiNPCManageQuest parent; private boolean questlogTA = false; - private GuiNPCQuestSelection questSelection; public SubGuiNpcQuest(GuiNPCManageQuest parent, Quest quest, int catId) { @@ -52,8 +50,6 @@ public class SubGuiNpcQuest extends SubGuiInterface implements ISubGuiListener, addLabel(new GuiNpcLabel(5, "quest.reward", guiLeft + 7, guiTop + 81)); addButton(new GuiNpcButton(5, guiLeft + 120, guiTop + 76, 50, 20, "selectServer.edit")); - - addLabel(new GuiNpcLabel(10, "faction.options", guiLeft + 180, guiTop + 33)); addButton(new GuiNpcButton(10, guiLeft + 303, guiTop + 28, 50, 20, "selectServer.edit")); @@ -155,9 +151,10 @@ public class SubGuiNpcQuest extends SubGuiInterface implements ISubGuiListener, initGui(); } if(button.id == 15 && quest.id >= 0){ - questSelection = new GuiNPCQuestSelection(npc, getParent(), quest.nextQuestid); - questSelection.listener = this; - NoppesUtil.openGUI(player, questSelection); + setSubGui(new GuiQuestSelection(quest.nextQuestid)); +// questSelection = new GuiNPCQuestSelection(npc, getParent(), quest.nextQuestid); +// questSelection.listener = this; +// NoppesUtil.openGUI(player, questSelection); } if(button.id == 18) { @@ -206,7 +203,7 @@ public class SubGuiNpcQuest extends SubGuiInterface implements ISubGuiListener, SubGuiNpcCommand sub = (SubGuiNpcCommand) subgui; quest.command = sub.command; } - else if(subgui instanceof SubGuiMailmanSendSetup){ + else { initGui(); } } diff --git a/src/main/java/noppes/npcs/client/gui/advanced/GuiNPCDialogNpcOptions.java b/src/main/java/noppes/npcs/client/gui/advanced/GuiNPCDialogNpcOptions.java index e242b27e2..4e4b7d066 100644 --- a/src/main/java/noppes/npcs/client/gui/advanced/GuiNPCDialogNpcOptions.java +++ b/src/main/java/noppes/npcs/client/gui/advanced/GuiNPCDialogNpcOptions.java @@ -5,7 +5,7 @@ import net.minecraft.client.gui.GuiScreen; import net.minecraft.nbt.NBTTagCompound; import noppes.npcs.client.Client; import noppes.npcs.client.NoppesUtil; -import noppes.npcs.client.gui.GuiNPCDialogSelection; +import noppes.npcs.client.gui.select.GuiDialogSelection; import noppes.npcs.client.gui.util.*; import noppes.npcs.constants.EnumPacketServer; import noppes.npcs.controllers.data.DialogOption; @@ -31,7 +31,7 @@ public class GuiNPCDialogNpcOptions extends GuiNPCInterface2 implements GuiSelec int offset = i >=6 ?200:0; this.addButton(new GuiNpcButton(i + 20, guiLeft + 20 + offset, guiTop + 13 + i % 6 * 22, 20, 20, "X")); this.addLabel(new GuiNpcLabel(i, "" + i, guiLeft + 6 + offset, guiTop + 18 + i % 6 * 22)); - + String title = "dialog.selectoption"; if(data.containsKey(i)) title = data.get(i).title; @@ -46,7 +46,7 @@ public class GuiNPCDialogNpcOptions extends GuiNPCInterface2 implements GuiSelec private int selectedSlot; protected void actionPerformed(GuiButton guibutton) { int id = guibutton.id; - + if (id == 1) { NoppesUtil.openGUI(player, parent); } @@ -56,7 +56,7 @@ public class GuiNPCDialogNpcOptions extends GuiNPCInterface2 implements GuiSelec int dialogID = -1; if(data.containsKey(id)) dialogID = data.get(id).dialogId; - NoppesUtil.openGUI(player, new GuiNPCDialogSelection(npc, this, dialogID)); + setSubGui(new GuiDialogSelection(dialogID)); } if (id >= 20 && id < 40) { int slot = id - 20; @@ -79,10 +79,10 @@ public class GuiNPCDialogNpcOptions extends GuiNPCInterface2 implements GuiSelec @Override public void setGuiData(NBTTagCompound compound) { int pos = compound.getInteger("Position"); - + DialogOption dialog = new DialogOption(); dialog.readNBT(compound); - + data.put(pos, dialog); initGui(); } diff --git a/src/main/java/noppes/npcs/client/gui/global/GuiNPCQuestSelection.java b/src/main/java/noppes/npcs/client/gui/global/GuiNPCQuestSelection.java deleted file mode 100644 index e10014473..000000000 --- a/src/main/java/noppes/npcs/client/gui/global/GuiNPCQuestSelection.java +++ /dev/null @@ -1,125 +0,0 @@ -package noppes.npcs.client.gui.global; - -import net.minecraft.client.gui.GuiButton; -import net.minecraft.client.gui.GuiScreen; -import noppes.npcs.client.Client; -import noppes.npcs.client.NoppesUtil; -import noppes.npcs.client.gui.util.*; -import noppes.npcs.constants.EnumPacketServer; -import noppes.npcs.entity.EntityNPCInterface; - -import java.util.HashMap; -import java.util.Vector; - -public class GuiNPCQuestSelection extends GuiNPCInterface implements IScrollData -{ - private GuiNPCStringSlot slot; - private GuiScreen parent; - private HashMap data = new HashMap(); - private int quest; - private boolean selectCategory = true; - public GuiSelectionListener listener; - - - public GuiNPCQuestSelection(EntityNPCInterface npc, GuiScreen parent, int quest) - { - super(npc); - drawDefaultBackground = false; - title = "Select Quest Category"; - this.parent = parent; - this.quest = quest; - - if(quest >= 0){ - Client.sendData(EnumPacketServer.QuestsGetFromQuest, quest); - selectCategory = false; - title = "Select Quest"; - }else - Client.sendData(EnumPacketServer.QuestCategoriesGet, quest); - - if(parent instanceof GuiSelectionListener) - listener = (GuiSelectionListener) parent; - } - - public String getSelected(){ - return slot.selected; - } - - public void initGui() - { - super.initGui(); - Vector list = new Vector(); - - slot = new GuiNPCStringSlot(list,this,false,18); - slot.registerScrollButtons(4, 5); - - - this.addButton(new GuiNpcButton(2, width / 2 -100, height - 41,98, 20, "gui.back")); - this.addButton(new GuiNpcButton(4, width / 2 + 2, height - 41,98, 20, "gui.select")); - } - - - public void drawScreen(int i, int j, float f) - { - slot.drawScreen(i, j, f); - super.drawScreen(i, j, f); - } - - protected void actionPerformed(GuiButton guibutton) - { - int id = guibutton.id; - if(id == 2) - { - if(selectCategory){ - close(); - NoppesUtil.openGUI(player, parent); - }else{ - title = "Select Quest Category"; - selectCategory = true; - Client.sendData(EnumPacketServer.QuestCategoriesGet, quest); - } - } - if(id == 4) - { - doubleClicked(); - } - } - - public void doubleClicked() { - if(slot.selected == null || slot.selected.isEmpty()) - return; - if(selectCategory){ - selectCategory = false; - title = "Select Quest"; - Client.sendData(EnumPacketServer.QuestsGet, data.get(slot.selected)); - } - else{ - quest = data.get(slot.selected); - close(); - NoppesUtil.openGUI(player, parent); - } - } - - public void save() { - if(quest >= 0){ - if(listener != null){ - listener.selected(quest, slot.selected); - } - } - } - - @Override - public void setData(Vector list, HashMap data) { - this.data = data; - this.slot.setList(list); - if(quest >= 0) - for(String name : data.keySet()) - if(data.get(name) == quest) - slot.selected = name; - } - - @Override - public void setSelected(String selected) { - - } - -} diff --git a/src/main/java/noppes/npcs/client/gui/questtypes/GuiNpcQuestTypeDialog.java b/src/main/java/noppes/npcs/client/gui/questtypes/GuiNpcQuestTypeDialog.java index 78e8f1406..bfdaf32fc 100644 --- a/src/main/java/noppes/npcs/client/gui/questtypes/GuiNpcQuestTypeDialog.java +++ b/src/main/java/noppes/npcs/client/gui/questtypes/GuiNpcQuestTypeDialog.java @@ -4,8 +4,7 @@ import net.minecraft.client.gui.GuiButton; import net.minecraft.client.gui.GuiScreen; import net.minecraft.nbt.NBTTagCompound; import noppes.npcs.client.Client; -import noppes.npcs.client.NoppesUtil; -import noppes.npcs.client.gui.GuiNPCDialogSelection; +import noppes.npcs.client.gui.select.GuiDialogSelection; import noppes.npcs.client.gui.util.GuiNpcButton; import noppes.npcs.client.gui.util.GuiSelectionListener; import noppes.npcs.client.gui.util.IGuiData; @@ -66,10 +65,7 @@ public class GuiNpcQuestTypeDialog extends SubGuiInterface implements GuiSelecti int id = -1; if(quest.dialogs.containsKey(selectedSlot)) id = quest.dialogs.get(selectedSlot); - - GuiNPCDialogSelection gui = new GuiNPCDialogSelection(npc, getParent(), id); - gui.listener = this; - NoppesUtil.openGUI(player, gui); + setSubGui(new GuiDialogSelection(id)); } if (button.id >= 9 && button.id < 15) { int slot = button.id - 9; diff --git a/src/main/java/noppes/npcs/client/gui/roles/GuiNpcConversation.java b/src/main/java/noppes/npcs/client/gui/roles/GuiNpcConversation.java index 2be969a75..4fc3be082 100644 --- a/src/main/java/noppes/npcs/client/gui/roles/GuiNpcConversation.java +++ b/src/main/java/noppes/npcs/client/gui/roles/GuiNpcConversation.java @@ -3,9 +3,8 @@ package noppes.npcs.client.gui.roles; import net.minecraft.client.gui.GuiButton; import net.minecraft.nbt.NBTTagCompound; import noppes.npcs.client.Client; -import noppes.npcs.client.NoppesUtil; import noppes.npcs.client.gui.SubGuiNpcAvailability; -import noppes.npcs.client.gui.global.GuiNPCQuestSelection; +import noppes.npcs.client.gui.select.GuiQuestSelection; import noppes.npcs.client.gui.util.*; import noppes.npcs.constants.EnumPacketServer; import noppes.npcs.entity.EntityNPCInterface; @@ -13,14 +12,13 @@ import noppes.npcs.roles.JobConversation; import noppes.npcs.roles.JobConversation.ConversationLine; public class GuiNpcConversation extends GuiNPCInterface2 implements ITextfieldListener, GuiSelectionListener -{ +{ private JobConversation job; - + private int slot = -1; - private GuiNPCQuestSelection questSelection; - + public GuiNpcConversation(EntityNPCInterface npc){ - super(npc); + super(npc); job = (JobConversation) npc.jobInterface; } @@ -29,7 +27,7 @@ public class GuiNpcConversation extends GuiNPCInterface2 implements ITextfieldLi addLabel(new GuiNpcLabel(40, "gui.name", guiLeft + 40, guiTop + 4)); addLabel(new GuiNpcLabel(41, "gui.name", guiLeft + 240, guiTop + 4)); - + addLabel(new GuiNpcLabel(42, "conversation.delay", guiLeft + 164, guiTop + 4)); addLabel(new GuiNpcLabel(43, "conversation.delay", guiLeft + 364, guiTop + 4)); @@ -39,7 +37,7 @@ public class GuiNpcConversation extends GuiNPCInterface2 implements ITextfieldLi this.addLabel(new GuiNpcLabel(i, "" + (i + 1), guiLeft + 5 + offset - (i > 8?6:0), guiTop + 18 + i % 7 * 22)); this.addTextField(new GuiNpcTextField(i, this, this.fontRendererObj, guiLeft + 13 + offset, guiTop + 13 + i % 7 * 22, 100, 20, line.npc)); this.addButton(new GuiNpcButton(i, guiLeft + 115 + offset, guiTop + 13 + i % 7 * 22, 46, 20, "conversation.line")); - + if(i > 0){ this.addTextField(new GuiNpcTextField(i + 14, this, this.fontRendererObj, guiLeft + 164 + offset, guiTop + 13 + i % 7 * 22, 30, 20, line.delay + "")); this.getTextField(i + 14).integersOnly = true; @@ -55,7 +53,7 @@ public class GuiNpcConversation extends GuiNPCInterface2 implements ITextfieldLi addTextField(new GuiNpcTextField(54, this, fontRendererObj, guiLeft + 260, guiTop + 191, 40, 20, job.range + "")); getTextField(54).integersOnly = true; getTextField(54).setMinMaxDefault(4, Integer.MAX_VALUE, 20); - + addLabel(new GuiNpcLabel(51, "quest.quest", guiLeft + 13, guiTop + 175)); String title = job.questTitle; if(title.isEmpty()) @@ -76,9 +74,9 @@ public class GuiNpcConversation extends GuiNPCInterface2 implements ITextfieldLi ConversationLine line = job.getLine(slot); setSubGui(new SubGuiNpcConversationLine(line.text, line.sound)); } - if(button.id == 51){ - NoppesUtil.openGUI(player, new GuiNPCQuestSelection(npc, this, job.quest)); - } + if(button.id == 51){ + setSubGui(new GuiQuestSelection(job.quest)); + } if(button.id == 52){ job.quest = -1; job.questTitle = ""; @@ -93,9 +91,9 @@ public class GuiNpcConversation extends GuiNPCInterface2 implements ITextfieldLi } @Override public void selected(int ob, String name) { - job.quest = ob; - job.questTitle = questSelection.getSelected(); - initGui(); + job.quest = ob; + job.questTitle = name; + initGui(); } @Override @@ -108,7 +106,7 @@ public class GuiNpcConversation extends GuiNPCInterface2 implements ITextfieldLi line.sound = sub.sound; } } - + @Override public void save() { Client.sendData(EnumPacketServer.JobSave, job.writeToNBT(new NBTTagCompound())); diff --git a/src/main/java/noppes/npcs/client/gui/select/GuiDialogSelection.java b/src/main/java/noppes/npcs/client/gui/select/GuiDialogSelection.java index 0389d9ec1..00721f6f7 100644 --- a/src/main/java/noppes/npcs/client/gui/select/GuiDialogSelection.java +++ b/src/main/java/noppes/npcs/client/gui/select/GuiDialogSelection.java @@ -1,124 +1,186 @@ -//package noppes.npcs.client.gui.select; -// -//import com.google.common.collect.Lists; -//import net.minecraft.client.gui.GuiButton; -//import noppes.npcs.client.gui.util.*; -//import noppes.npcs.controllers.DialogController; -//import noppes.npcs.controllers.data.Dialog; -//import noppes.npcs.controllers.data.DialogCategory; -// -//import java.util.HashMap; -// -//public class GuiDialogSelection extends SubGuiInterface implements ICustomScrollListener{ -// private HashMap categoryData = new HashMap(); -// private HashMap dialogData = new HashMap(); -// -// private GuiCustomScroll scrollCategories; -// private GuiCustomScroll scrollDialogs; -// -// private DialogCategory selectedCategory; -// public Dialog selectedDialog; -// -// private GuiSelectionListener listener; -// -// public GuiDialogSelection(int dialog){ -// drawDefaultBackground = false; -// title = ""; -// setBackground("menubg.png"); -// xSize = 366; -// ySize = 226; -// this.selectedDialog = DialogController.instance.dialogs.get(dialog); -// if(selectedDialog != null) { -// selectedCategory = selectedDialog.category; -// } -// } -// -// @Override -// public void initGui(){ -// super.initGui(); -// -// if(parent instanceof GuiSelectionListener){ -// listener = (GuiSelectionListener) parent; -// } -// this.addLabel(new GuiNpcLabel(0, "gui.categories", guiLeft + 8, guiTop + 4)); -// this.addLabel(new GuiNpcLabel(1, "dialog.dialogs", guiLeft + 175, guiTop + 4)); -// -// this.addButton(new GuiNpcButton(2, guiLeft + xSize - 26, guiTop + 4, 20, 20, "X")); -// -// HashMap categoryData = new HashMap(); -// HashMap dialogData = new HashMap(); -// -// for(DialogCategory category : DialogController.instance.categories.values()) { -// categoryData.put(category.title, category); -// } -// this.categoryData = categoryData; -// -// if(selectedCategory != null) { -// for(Dialog dialog : selectedCategory.dialogs.values()) { -// dialogData.put(dialog.title, dialog); -// } -// } -// this.dialogData = dialogData; -// -// if(scrollCategories == null){ -// scrollCategories = new GuiCustomScroll(this,0); -// scrollCategories.setSize(170, 200); -// } -// scrollCategories.setList(Lists.newArrayList(categoryData.keySet())); -// if(selectedCategory != null) { -// scrollCategories.setSelected(selectedCategory.title); -// } -// -// scrollCategories.guiLeft = guiLeft + 4; -// scrollCategories.guiTop = guiTop + 14; -// this.addScroll(scrollCategories); -// -// if(scrollDialogs == null){ -// scrollDialogs = new GuiCustomScroll(this,1); -// scrollDialogs.setSize(170, 200); -// } -// scrollDialogs.setList(Lists.newArrayList(dialogData.keySet())); -// if(selectedDialog != null) { -// scrollDialogs.setSelected(selectedDialog.title); -// } -// scrollDialogs.guiLeft = guiLeft + 175; -// scrollDialogs.guiTop = guiTop + 14; -// this.addScroll(scrollDialogs); -// } -// -// @Override -// public void scrollClicked(int i, int j, int k, GuiCustomScroll guiCustomScroll) { -// if(guiCustomScroll.id == 0){ -// selectedCategory = categoryData.get(scrollCategories.getSelected()); -// selectedDialog = null; -// scrollDialogs.selected = -1; -// } -// if(guiCustomScroll.id == 1){ -// selectedDialog = dialogData.get(scrollDialogs.getSelected()); -// } -// initGui(); -// } -// -// @Override -// public void scrollDoubleClicked(String selection, GuiCustomScroll scroll) { -// if(selectedDialog == null) -// return; -// if(listener != null) { -// listener.selected(selectedDialog.id, selectedDialog.title); -// } -// close(); -// } -// -// @Override -// protected void actionPerformed(GuiButton guibutton){ -// int id = guibutton.id; -// if(id == 2){ -// if(selectedDialog != null) { -// scrollDoubleClicked(null, null); -// } -// else { -// close(); -// } -// } -// } -//} +package noppes.npcs.client.gui.select; + +import com.google.common.collect.Lists; +import net.minecraft.client.gui.GuiButton; +import noppes.npcs.client.gui.util.*; +import noppes.npcs.controllers.DialogController; +import noppes.npcs.controllers.data.Dialog; +import noppes.npcs.controllers.data.DialogCategory; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; + +public class GuiDialogSelection extends SubGuiInterface implements ICustomScrollListener { + private HashMap categoryData = new HashMap(); + private HashMap dialogData = new HashMap(); + + private GuiCustomScroll scrollCategories; + private GuiCustomScroll scrollDialogs; + + private DialogCategory selectedCategory; + public Dialog selectedDialog; + + private GuiSelectionListener listener; + private String catSearch = ""; + private String dialogSearch = ""; + + public GuiDialogSelection(int dialog){ + drawDefaultBackground = false; + title = ""; + setBackground("menubg.png"); + xSize = 366; + ySize = 226; + this.selectedDialog = DialogController.Instance.dialogs.get(dialog); + if(selectedDialog != null) { + selectedCategory = selectedDialog.category; + } + } + + @Override + public void initGui(){ + super.initGui(); + + if(parent instanceof GuiSelectionListener){ + listener = (GuiSelectionListener) parent; + } + this.addLabel(new GuiNpcLabel(0, "gui.categories", guiLeft + 8, guiTop + 4)); + this.addLabel(new GuiNpcLabel(1, "dialog.dialogs", guiLeft + 184, guiTop + 4)); + + this.addButton(new GuiNpcButton(2, guiLeft + xSize - 56, guiTop + ySize - 35, 50, 20, "gui.done")); + this.addButton(new GuiNpcButton(3, guiLeft + xSize - 108, guiTop + ySize - 35, 50, 20, "gui.cancel")); + + HashMap categoryData = new HashMap(); + HashMap dialogData = new HashMap(); + + for(DialogCategory category : DialogController.Instance.categories.values()) { + categoryData.put(category.title, category); + } + this.categoryData = categoryData; + + if(selectedCategory != null) { + for(Dialog dialog : selectedCategory.dialogs.values()) { + dialogData.put(dialog.title, dialog); + } + } + this.dialogData = dialogData; + + if(scrollCategories == null){ + scrollCategories = new GuiCustomScroll(this,0); + scrollCategories.setSize(177, 153); + } + scrollCategories.setList(getCatSearch()); + if(selectedCategory != null) { + scrollCategories.setSelected(selectedCategory.title); + } + scrollCategories.guiLeft = guiLeft + 4; + scrollCategories.guiTop = guiTop + 14; + this.addScroll(scrollCategories); + addTextField(new GuiNpcTextField(33, this, fontRendererObj, guiLeft + 4, guiTop + 169, 177, 20, catSearch)); + + if(scrollDialogs == null){ + scrollDialogs = new GuiCustomScroll(this,1); + scrollDialogs.setSize(177, 153); + } + scrollDialogs.setList(getDialogSearch()); + if(selectedDialog != null) { + scrollDialogs.setSelected(selectedDialog.title); + } + scrollDialogs.guiLeft = guiLeft + 182; + scrollDialogs.guiTop = guiTop + 14; + this.addScroll(scrollDialogs); + addTextField(new GuiNpcTextField(44, this, fontRendererObj, guiLeft + 182, guiTop + 169, 177, 20, dialogSearch)); + } + + @Override + public void keyTyped(char c, int i) + { + super.keyTyped(c, i); + if(getTextField(33) != null){ + if(getTextField(33).isFocused()){ + if(catSearch.equals(getTextField(33).getText())) + return; + catSearch = getTextField(33).getText().toLowerCase(); + scrollCategories.setList(getCatSearch()); + } + } + if(getTextField(44) != null){ + if(getTextField(44).isFocused()){ + if(dialogSearch.equals(getTextField(44).getText())) + return; + dialogSearch = getTextField(44).getText().toLowerCase(); + scrollDialogs.setList(getDialogSearch()); + } + } + } + + private List getCatSearch(){ + if(catSearch.isEmpty()){ + return Lists.newArrayList(categoryData.keySet()); + } + List list = new ArrayList(); + for(String name : Lists.newArrayList(categoryData.keySet())){ + if(name.toLowerCase().contains(catSearch)) + list.add(name); + } + return list; + } + + private List getDialogSearch(){ + if(selectedCategory == null){ + return Lists.newArrayList(dialogData.keySet()); + } + + if(dialogSearch.isEmpty()){ + return new ArrayList(Lists.newArrayList(dialogData.keySet())); + } + List list = new ArrayList(); + for(String name : Lists.newArrayList(dialogData.keySet())){ + if(name.toLowerCase().contains(dialogSearch)) + list.add(name); + } + return list; + } + + @Override + public void customScrollClicked(int i, int j, int k, GuiCustomScroll guiCustomScroll) { + if(guiCustomScroll.id == 0){ + selectedCategory = categoryData.get(scrollCategories.getSelected()); + selectedDialog = null; + scrollDialogs.selected = -1; + scrollDialogs.resetScroll(); + getTextField(44).setText(""); + dialogSearch = ""; + } + if(guiCustomScroll.id == 1){ + selectedDialog = dialogData.get(scrollDialogs.getSelected()); + } + initGui(); + } + + @Override + public void customScrollDoubleClicked(String selection, GuiCustomScroll scroll) { + if(selectedDialog == null) + return; + if(listener != null) { + listener.selected(selectedDialog.id, selectedDialog.title); + } + close(); + } + + @Override + protected void actionPerformed(GuiButton guibutton){ + int id = guibutton.id; + if(id == 2){ + if(selectedDialog != null) { + customScrollDoubleClicked(null, null); + } + else { + close(); + } + } + if(id == 3){ + close(); + } + } +} diff --git a/src/main/java/noppes/npcs/client/gui/select/GuiQuestSelection.java b/src/main/java/noppes/npcs/client/gui/select/GuiQuestSelection.java index 0ba761347..c0b284b4f 100644 --- a/src/main/java/noppes/npcs/client/gui/select/GuiQuestSelection.java +++ b/src/main/java/noppes/npcs/client/gui/select/GuiQuestSelection.java @@ -1,124 +1,186 @@ -//package noppes.npcs.client.gui.select; -// -//import com.google.common.collect.Lists; -//import net.minecraft.client.gui.GuiButton; -//import noppes.npcs.client.gui.util.*; -//import noppes.npcs.controllers.QuestController; -//import noppes.npcs.controllers.data.Quest; -//import noppes.npcs.controllers.data.QuestCategory; -// -//import java.util.HashMap; -// -//public class GuiQuestSelection extends SubGuiInterface implements ICustomScrollListener{ -// private HashMap categoryData = new HashMap(); -// private HashMap questData = new HashMap(); -// -// private GuiCustomScroll scrollCategories; -// private GuiCustomScroll scrollQuests; -// -// private QuestCategory selectedCategory; -// public Quest selectedQuest; -// -// private GuiSelectionListener listener; -// -// public GuiQuestSelection(int quest){ -// drawDefaultBackground = false; -// title = ""; -// setBackground("menubg.png"); -// xSize = 366; -// ySize = 226; -// this.selectedQuest = QuestController.instance.quests.get(quest); -// if(selectedQuest != null) { -// selectedCategory = selectedQuest.category; -// } -// } -// -// @Override -// public void initGui(){ -// super.initGui(); -// -// if(parent instanceof GuiSelectionListener){ -// listener = (GuiSelectionListener) parent; -// } -// this.addLabel(new GuiNpcLabel(0, "gui.categories", guiLeft + 8, guiTop + 4)); -// this.addLabel(new GuiNpcLabel(1, "quest.quests", guiLeft + 175, guiTop + 4)); -// -// this.addButton(new GuiNpcButton(2, guiLeft + xSize - 26, guiTop + 4, 20, 20, "X")); -// -// HashMap categoryData = new HashMap(); -// HashMap questData = new HashMap(); -// -// for(QuestCategory category : QuestController.instance.categories.values()) { -// categoryData.put(category.title, category); -// } -// this.categoryData = categoryData; -// -// if(selectedCategory != null) { -// for(Quest quest : selectedCategory.quests.values()) { -// questData.put(quest.title, quest); -// } -// } -// this.questData = questData; -// -// if(scrollCategories == null){ -// scrollCategories = new GuiCustomScroll(this,0); -// scrollCategories.setSize(170, 200); -// } -// scrollCategories.setList(Lists.newArrayList(categoryData.keySet())); -// if(selectedCategory != null) { -// scrollCategories.setSelected(selectedCategory.title); -// } -// -// scrollCategories.guiLeft = guiLeft + 4; -// scrollCategories.guiTop = guiTop + 14; -// this.addScroll(scrollCategories); -// -// if(scrollQuests == null){ -// scrollQuests = new GuiCustomScroll(this,1); -// scrollQuests.setSize(170, 200); -// } -// scrollQuests.setList(Lists.newArrayList(questData.keySet())); -// if(selectedQuest != null) { -// scrollQuests.setSelected(selectedQuest.title); -// } -// scrollQuests.guiLeft = guiLeft + 175; -// scrollQuests.guiTop = guiTop + 14; -// this.addScroll(scrollQuests); -// } -// -// @Override -// public void scrollClicked(int i, int j, int k, GuiCustomScroll guiCustomScroll) { -// if(guiCustomScroll.id == 0){ -// selectedCategory = categoryData.get(scrollCategories.getSelected()); -// selectedQuest = null; -// scrollQuests.selected = -1; -// } -// if(guiCustomScroll.id == 1){ -// selectedQuest = questData.get(scrollQuests.getSelected()); -// } -// initGui(); -// } -// -// @Override -// public void scrollDoubleClicked(String selection, GuiCustomScroll scroll) { -// if(selectedQuest == null) -// return; -// if(listener != null) { -// listener.selected(selectedQuest.id, selectedQuest.title); -// } -// close(); -// } -// -// @Override -// protected void actionPerformed(GuiButton guibutton){ -// int id = guibutton.id; -// if(id == 2){ -// if(selectedQuest != null) { -// scrollDoubleClicked(null, null); -// } -// else { -// close(); -// } -// } -// } -//} +package noppes.npcs.client.gui.select; + +import com.google.common.collect.Lists; +import net.minecraft.client.gui.GuiButton; +import noppes.npcs.client.gui.util.*; +import noppes.npcs.controllers.QuestController; +import noppes.npcs.controllers.data.Quest; +import noppes.npcs.controllers.data.QuestCategory; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; + +public class GuiQuestSelection extends SubGuiInterface implements ICustomScrollListener { + private HashMap categoryData = new HashMap(); + private HashMap questData = new HashMap(); + + private GuiCustomScroll scrollCategories; + private GuiCustomScroll scrollQuests; + + private QuestCategory selectedCategory; + public Quest selectedQuest; + + private GuiSelectionListener listener; + private String catSearch = ""; + private String questSearch = ""; + + public GuiQuestSelection(int quest){ + drawDefaultBackground = false; + title = ""; + setBackground("menubg.png"); + xSize = 366; + ySize = 226; + this.selectedQuest = QuestController.Instance.quests.get(quest); + if(selectedQuest != null) { + selectedCategory = selectedQuest.category; + } + } + + @Override + public void initGui(){ + super.initGui(); + + if(parent instanceof GuiSelectionListener){ + listener = (GuiSelectionListener) parent; + } + this.addLabel(new GuiNpcLabel(0, "gui.categories", guiLeft + 8, guiTop + 4)); + this.addLabel(new GuiNpcLabel(1, "quest.quests", guiLeft + 184, guiTop + 4)); + + this.addButton(new GuiNpcButton(2, guiLeft + xSize - 56, guiTop + ySize - 35, 50, 20, "gui.done")); + this.addButton(new GuiNpcButton(3, guiLeft + xSize - 108, guiTop + ySize - 35, 50, 20, "gui.cancel")); + + HashMap categoryData = new HashMap(); + HashMap questData = new HashMap(); + + for(QuestCategory category : QuestController.Instance.categories.values()) { + categoryData.put(category.title, category); + } + this.categoryData = categoryData; + + if(selectedCategory != null) { + for(Quest quest : selectedCategory.quests.values()) { + questData.put(quest.title, quest); + } + } + this.questData = questData; + + if(scrollCategories == null){ + scrollCategories = new GuiCustomScroll(this,0, 0); + scrollCategories.setSize(177, 153); + } + scrollCategories.setList(getCatSearch()); + if(selectedCategory != null) { + scrollCategories.setSelected(selectedCategory.title); + } + scrollCategories.guiLeft = guiLeft + 4; + scrollCategories.guiTop = guiTop + 14; + this.addScroll(scrollCategories); + addTextField(new GuiNpcTextField(33, this, fontRendererObj, guiLeft + 4, guiTop + 169, 177, 20, catSearch)); + + if(scrollQuests == null){ + scrollQuests = new GuiCustomScroll(this,1, 0); + scrollQuests.setSize(177, 153); + } + scrollQuests.setList(getQuestSearch()); + if(selectedQuest != null) { + scrollQuests.setSelected(selectedQuest.title); + } + scrollQuests.guiLeft = guiLeft + 182; + scrollQuests.guiTop = guiTop + 14; + this.addScroll(scrollQuests); + addTextField(new GuiNpcTextField(44, this, fontRendererObj, guiLeft + 182, guiTop + 169, 177, 20, questSearch)); + } + + @Override + public void keyTyped(char c, int i) + { + super.keyTyped(c, i); + if(getTextField(33) != null){ + if(getTextField(33).isFocused()){ + if(catSearch.equals(getTextField(33).getText())) + return; + catSearch = getTextField(33).getText().toLowerCase(); + scrollCategories.setList(getCatSearch()); + } + } + if(getTextField(44) != null){ + if(getTextField(44).isFocused()){ + if(questSearch.equals(getTextField(44).getText())) + return; + questSearch = getTextField(44).getText().toLowerCase(); + scrollQuests.setList(getQuestSearch()); + } + } + } + + private List getCatSearch(){ + if(catSearch.isEmpty()){ + return Lists.newArrayList(categoryData.keySet()); + } + List list = new ArrayList(); + for(String name : Lists.newArrayList(categoryData.keySet())){ + if(name.toLowerCase().contains(catSearch)) + list.add(name); + } + return list; + } + + private List getQuestSearch(){ + if(selectedCategory == null){ + return Lists.newArrayList(questData.keySet()); + } + + if(questSearch.isEmpty()){ + return new ArrayList(Lists.newArrayList(questData.keySet())); + } + List list = new ArrayList(); + for(String name : Lists.newArrayList(questData.keySet())){ + if(name.toLowerCase().contains(questSearch)) + list.add(name); + } + return list; + } + + @Override + public void customScrollClicked(int i, int j, int k, GuiCustomScroll guiCustomScroll) { + if(guiCustomScroll.id == 0){ + selectedCategory = categoryData.get(scrollCategories.getSelected()); + selectedQuest = null; + scrollQuests.selected = -1; + scrollQuests.resetScroll(); + getTextField(44).setText(""); + questSearch = ""; + } + if(guiCustomScroll.id == 1){ + selectedQuest = questData.get(scrollQuests.getSelected()); + } + initGui(); + } + + @Override + public void customScrollDoubleClicked(String selection, GuiCustomScroll scroll) { + if(selectedQuest == null) + return; + if(listener != null) { + listener.selected(selectedQuest.id, selectedQuest.title); + } + close(); + } + + @Override + protected void actionPerformed(GuiButton guibutton){ + int id = guibutton.id; + if(id == 2){ + if(selectedQuest != null) { + customScrollDoubleClicked(null, null); + } + else { + close(); + } + } + if(id == 3){ + close(); + } + } +} diff --git a/src/main/java/noppes/npcs/client/gui/util/GuiCustomScroll.java b/src/main/java/noppes/npcs/client/gui/util/GuiCustomScroll.java index d13c2968a..727d26cab 100644 --- a/src/main/java/noppes/npcs/client/gui/util/GuiCustomScroll.java +++ b/src/main/java/noppes/npcs/client/gui/util/GuiCustomScroll.java @@ -35,6 +35,7 @@ public class GuiCustomScroll extends GuiScreen private boolean isSorted = true; public boolean visible = true; private boolean selectable = true; + private boolean hasSubGUI = false; private int lastClickedItem; private long lastClickedTime = 0; @@ -116,7 +117,7 @@ public class GuiCustomScroll extends GuiScreen hoverCount++; } - if(hover != -1 && hoverableText && hoverCount > 100){ + if(!hasSubGUI && hover != -1 && hoverableText && hoverCount > 100){ String displayString = StatCollector.translateToLocal(list.get(hover)); GL11.glColor4f(1, 1, 1, 1); List lines = TextSplitter.splitText(displayString, 30); @@ -176,7 +177,7 @@ public class GuiCustomScroll extends GuiScreen hoverCount++; } - if(hover != -1 && hoverableText && hoverCount > 100){ + if(!hasSubGUI && hover != -1 && hoverableText && hoverCount > 100){ String displayString = StatCollector.translateToLocal(list.get(hover)); GL11.glColor4f(1, 1, 1, 1); List lines = TextSplitter.splitText(displayString, 30); @@ -374,4 +375,9 @@ public class GuiCustomScroll extends GuiScreen public void resetScroll(){ scrollY = 0; } + + public void updateSubGUI(boolean hasSubGUI) + { + this.hasSubGUI = hasSubGUI; + } } diff --git a/src/main/java/noppes/npcs/client/gui/util/GuiNPCInterface.java b/src/main/java/noppes/npcs/client/gui/util/GuiNPCInterface.java index 4ad9b1965..7cdd72efd 100644 --- a/src/main/java/noppes/npcs/client/gui/util/GuiNPCInterface.java +++ b/src/main/java/noppes/npcs/client/gui/util/GuiNPCInterface.java @@ -238,28 +238,29 @@ public abstract class GuiNPCInterface extends GuiScreen drawBackground(); } + boolean subGui = hasSubGui(); drawCenteredString(fontRendererObj, title, width / 2, guiTop + 4, 0xffffff); for(GuiNpcLabel label : labels.values()) label.drawLabel(this,fontRendererObj); for(GuiNpcTextField tf : textfields.values()){ tf.drawTextBox(i, j); } - for(GuiCustomScroll scroll : scrolls.values()) - scroll.drawScreen(i, j, f, hasSubGui()?0:this.mouseWheel); - + for(GuiCustomScroll scroll : scrolls.values()){ + scroll.updateSubGUI(subGui); + scroll.drawScreen(i, j, f, subGui?0:this.mouseWheel); + } for(GuiScreen gui : extra.values()) gui.drawScreen(i, j, f); super.drawScreen(i, j, f); for(GuiCustomScroll scroll : scrolls.values()) if(scroll.hoverableText){ - scroll.drawHover(i, j, f, hasSubGui()?0:this.mouseWheel); + scroll.drawHover(i, j, f, subGui?0:this.mouseWheel); } for(GuiNpcButton button : buttons.values()){ + button.updateSubGUI(subGui); if(!button.hoverableText.isEmpty()){ - button.drawHover(i, j, hasSubGui()); + button.drawHover(i, j, subGui); } - if(hasSubGui() != button.getHasSubGUI()) - button.updateSubGUI(hasSubGui()); } if(subgui != null)