diff --git a/src/main/java/betterquesting/client/gui2/editors/GuiPrerequisiteEditor.java b/src/main/java/betterquesting/client/gui2/editors/GuiPrerequisiteEditor.java index 6264d4ea0..65db021e2 100644 --- a/src/main/java/betterquesting/client/gui2/editors/GuiPrerequisiteEditor.java +++ b/src/main/java/betterquesting/client/gui2/editors/GuiPrerequisiteEditor.java @@ -15,7 +15,11 @@ import betterquesting.api2.client.gui.events.PEventBroadcaster; import betterquesting.api2.client.gui.events.PanelEvent; import betterquesting.api2.client.gui.events.types.PEventButton; -import betterquesting.api2.client.gui.misc.*; +import betterquesting.api2.client.gui.misc.GuiAlign; +import betterquesting.api2.client.gui.misc.GuiPadding; +import betterquesting.api2.client.gui.misc.GuiRectangle; +import betterquesting.api2.client.gui.misc.GuiTransform; +import betterquesting.api2.client.gui.misc.IGuiRect; import betterquesting.api2.client.gui.panels.CanvasEmpty; import betterquesting.api2.client.gui.panels.CanvasTextured; import betterquesting.api2.client.gui.panels.bars.PanelVScrollBar; @@ -32,16 +36,16 @@ import betterquesting.client.gui2.GuiQuest; import betterquesting.network.handlers.NetQuestEdit; import betterquesting.questing.QuestDatabase; +import java.util.Arrays; +import java.util.Collections; +import java.util.List; import net.minecraft.client.gui.GuiScreen; import net.minecraft.nbt.NBTTagCompound; import net.minecraft.nbt.NBTTagList; import org.lwjgl.input.Keyboard; -import java.util.Arrays; -import java.util.Collections; -import java.util.List; - public class GuiPrerequisiteEditor extends GuiScreenCanvas implements IPEventListener, IVolatileScreen, INeedsRefresh { + private IQuest quest; private final int questID; @@ -77,31 +81,39 @@ public void initPanel() { Keyboard.enableRepeatEvents(true); // Background panel - CanvasTextured cvBackground = new CanvasTextured(new GuiTransform(GuiAlign.FULL_BOX, new GuiPadding(0, 0, 0, 0), 0), PresetTexture.PANEL_MAIN.getTexture()); + CanvasTextured cvBackground = new CanvasTextured(new GuiTransform(GuiAlign.FULL_BOX, new GuiPadding(0, 0, 0, 0), 0), + PresetTexture.PANEL_MAIN.getTexture()); this.addPanel(cvBackground); - PanelTextBox panTxt = new PanelTextBox(new GuiTransform(GuiAlign.TOP_EDGE, new GuiPadding(0, 16, 0, -32), 0), QuestTranslation.translate("betterquesting.title.pre_requisites")).setAlignment(1); + PanelTextBox panTxt = new PanelTextBox(new GuiTransform(GuiAlign.TOP_EDGE, new GuiPadding(0, 16, 0, -32), 0), + QuestTranslation.translate("betterquesting.title.pre_requisites")).setAlignment(1); panTxt.setColor(PresetColor.TEXT_HEADER.getColor()); cvBackground.addPanel(panTxt); - btnLogic = new PanelButton(new GuiTransform(GuiAlign.TOP_RIGHT, -116, 8, 100, 16, 0), 8, QuestTranslation.translate("betterquesting.btn.logic") + ": " + quest.getProperty(NativeProps.LOGIC_QUEST)); + btnLogic = new PanelButton(new GuiTransform(GuiAlign.TOP_RIGHT, -116, 8, 100, 16, 0), + 9, + QuestTranslation.translate("betterquesting.btn.logic") + ": " + quest.getProperty(NativeProps.LOGIC_QUEST)); cvBackground.addPanel(btnLogic); cvBackground.addPanel(new PanelButton(new GuiTransform(GuiAlign.BOTTOM_CENTER, -100, -16, 200, 16, 0), 0, QuestTranslation.translate("gui.back"))); - // === RIGHT SIDE === CanvasEmpty cvRight = new CanvasEmpty(new GuiTransform(GuiAlign.HALF_RIGHT, new GuiPadding(8, 32, 16, 24), 0)); cvBackground.addPanel(cvRight); - PanelTextBox txtDb = new PanelTextBox(new GuiTransform(GuiAlign.TOP_EDGE, new GuiPadding(0, 0, 0, -16), 0), QuestTranslation.translate("betterquesting.gui.database")).setAlignment(1).setColor(PresetColor.TEXT_MAIN.getColor()); + PanelTextBox txtDb = new PanelTextBox(new GuiTransform(GuiAlign.TOP_EDGE, new GuiPadding(0, 0, 0, -16), 0), + QuestTranslation.translate("betterquesting.gui.database")).setAlignment(1) + .setColor(PresetColor.TEXT_MAIN.getColor()); cvRight.addPanel(txtDb); - PanelTextField searchBox = new PanelTextField<>(new GuiTransform(GuiAlign.TOP_EDGE, new GuiPadding(0, 16, 8, -32), 0), "", FieldFilterString.INSTANCE); + PanelTextField searchBox = new PanelTextField<>(new GuiTransform(GuiAlign.TOP_EDGE, new GuiPadding(0, 16, 8, -32), 0), + "", + FieldFilterString.INSTANCE); searchBox.setWatermark("Search..."); cvRight.addPanel(searchBox); canvasDB = new CanvasQuestDatabase(new GuiTransform(GuiAlign.FULL_BOX, new GuiPadding(0, 32, 8, 24), 0)) { + @Override protected boolean addResult(DBEntry entry, int index, int width) { PanelButtonStorage> btnAdd = new PanelButtonStorage<>(new GuiRectangle(0, index * 16, 16, 16, 0), 2, "", entry); @@ -109,7 +121,11 @@ protected boolean addResult(DBEntry entry, int index, int width) { btnAdd.setActive(!containsReq(quest, entry.getID())); this.addPanel(btnAdd); - PanelButtonStorage> btnEdit = new PanelButtonStorage<>(new GuiRectangle(16, index * 16, width - 32, 16, 0), 1, QuestTranslation.translate(entry.getValue().getProperty(NativeProps.NAME)), entry); + PanelButtonStorage> btnEdit = new PanelButtonStorage<>(new GuiRectangle(16, index * 16, width - 32, 16, 0), + 1, + QuestTranslation.translate(entry.getValue() + .getProperty(NativeProps.NAME)), + entry); this.addPanel(btnEdit); PanelButtonStorage> btnDel = new PanelButtonStorage<>(new GuiRectangle(width - 16, index * 16, 16, 16, 0), 4, "", entry); @@ -118,6 +134,7 @@ protected boolean addResult(DBEntry entry, int index, int width) { return true; } + }; cvRight.addPanel(canvasDB); @@ -127,7 +144,9 @@ protected boolean addResult(DBEntry entry, int index, int width) { cvRight.addPanel(scDb); canvasDB.setScrollDriverY(scDb); - PanelButton btnNew = new PanelButton(new GuiTransform(GuiAlign.BOTTOM_EDGE, new GuiPadding(0, -16, 0, 0), 0), 5, QuestTranslation.translate("betterquesting.btn.new")); + PanelButton btnNew = new PanelButton(new GuiTransform(GuiAlign.BOTTOM_EDGE, new GuiPadding(0, -16, 0, 0), 0), + 5, + QuestTranslation.translate("betterquesting.btn.new")); cvRight.addPanel(btnNew); // === LEFT SIDE === @@ -135,7 +154,9 @@ protected boolean addResult(DBEntry entry, int index, int width) { CanvasEmpty cvLeft = new CanvasEmpty(new GuiTransform(GuiAlign.HALF_LEFT, new GuiPadding(16, 32, 8, 24), 0)); cvBackground.addPanel(cvLeft); - PanelTextBox txtQuest = new PanelTextBox(new GuiTransform(GuiAlign.TOP_EDGE, new GuiPadding(0, 0, 0, -16), 0), QuestTranslation.translate(quest.getProperty(NativeProps.NAME))).setAlignment(1).setColor(PresetColor.TEXT_MAIN.getColor()); + PanelTextBox txtQuest = new PanelTextBox(new GuiTransform(GuiAlign.TOP_EDGE, new GuiPadding(0, 0, 0, -16), 0), + QuestTranslation.translate(quest.getProperty(NativeProps.NAME))).setAlignment(1) + .setColor(PresetColor.TEXT_MAIN.getColor()); cvLeft.addPanel(txtQuest); canvasPreReq = new CanvasScrolling(new GuiTransform(GuiAlign.FULL_BOX, new GuiPadding(0, 16, 8, 0), 0)); @@ -163,11 +184,15 @@ private void refreshReqCanvas() { List> arrReq = QuestDatabase.INSTANCE.bulkLookup(quest.getRequirements()); for (int i = 0; i < arrReq.size(); i++) { - PanelButtonStorage> btnEdit = new PanelButtonStorage<>(new GuiRectangle(0, i * 16, width - 48, 16, 0), 1, - QuestTranslation.translate(arrReq.get(i).getValue().getProperty(NativeProps.NAME)), arrReq.get(i)); + PanelButtonStorage> btnEdit = new PanelButtonStorage<>(new GuiRectangle(0, i * 16, width - 64, 16, 0), + 1, + QuestTranslation.translate(arrReq.get(i) + .getValue() + .getProperty(NativeProps.NAME)), + arrReq.get(i)); canvasPreReq.addPanel(btnEdit); - PanelButtonStorage> btnType = new PanelButtonStorage<>(new GuiRectangle(width - 48, i * 16, 16, 16, 0), 6, "", arrReq.get(i)); + PanelButtonStorage> btnType = new PanelButtonStorage<>(new GuiRectangle(width - 64, i * 16, 16, 16, 0), 6, "", arrReq.get(i)); int arrReqID = arrReq.get(i).getID(); btnType.setIcon(quest.getRequirementType(arrReqID).getIcon().getTexture()); if (quest.getRequirementType(arrReqID) == IQuest.RequirementType.NORMAL) @@ -178,11 +203,16 @@ else if (quest.getRequirementType(arrReqID) == IQuest.RequirementType.IMPLICIT) btnType.setTooltip(Collections.singletonList(QuestTranslation.translate("betterquesting.btn.visible_hidden"))); canvasPreReq.addPanel(btnType); - PanelButtonStorage> btnUp = new PanelButtonStorage<>(new GuiRectangle(width - 32, i * 16, 16, 16, 0), 7, "", arrReq.get(i)); + PanelButtonStorage> btnUp = new PanelButtonStorage<>(new GuiRectangle(width - 48, i * 16, 16, 16, 0), 7, "", arrReq.get(i)); btnUp.setIcon(PresetIcon.ICON_UP.getTexture()); btnUp.setActive(arrReq.size() > 1); canvasPreReq.addPanel(btnUp); + PanelButtonStorage> btnDown = new PanelButtonStorage<>(new GuiRectangle(width - 32, i * 16, 16, 16, 0), 8, "", arrReq.get(i)); + btnDown.setIcon(PresetIcon.ICON_DOWN.getTexture()); + btnDown.setActive(arrReq.size() > 1); + canvasPreReq.addPanel(btnDown); + PanelButtonStorage> btnRem = new PanelButtonStorage<>(new GuiRectangle(width - 16, i * 16, 16, 16, 0), 3, "", arrReq.get(i)); btnRem.setIcon(PresetIcon.ICON_NEGATIVE.getTexture()); canvasPreReq.addPanel(btnRem); @@ -216,7 +246,9 @@ private void onButtonPress(PEventButton event) { } else if (btn.getButtonID() == 4 && btn instanceof PanelButtonStorage) { // Delete DBEntry entry = ((PanelButtonStorage>) btn).getStoredValue(); NBTTagCompound payload = new NBTTagCompound(); - payload.setIntArray("questIDs", new int[]{entry.getID()}); + payload.setIntArray("questIDs", new int[]{ + entry.getID() + }); payload.setInteger("action", 1); NetQuestEdit.sendEdit(payload); } else if (btn.getButtonID() == 5) { // New @@ -231,11 +263,15 @@ private void onButtonPress(PEventButton event) { DBEntry entry = ((PanelButtonStorage>) btn).getStoredValue(); quest.setRequirementType(entry.getID(), quest.getRequirementType(entry.getID()).next()); SendChanges(); - } else if (btn.getButtonID() == 7) { // Reorder + } else if (btn.getButtonID() == 7) { // Up DBEntry entry = ((PanelButtonStorage>) btn).getStoredValue(); - reorderReq(quest, entry.getID()); + reorderReq(quest, entry.getID(), false); SendChanges(); - } else if (btn.getButtonID() == 8) { // Logic + } else if (btn.getButtonID() == 8) { // Down + DBEntry entry = ((PanelButtonStorage>) btn).getStoredValue(); + reorderReq(quest, entry.getID(), true); + SendChanges(); + } else if (btn.getButtonID() == 9) { // Logic EnumLogic[] logicList = EnumLogic.values(); EnumLogic logic = quest.getProperty(NativeProps.LOGIC_QUEST); logic = logicList[(logic.ordinal() + 1) % logicList.length]; @@ -253,7 +289,7 @@ private boolean containsReq(IQuest quest, int id) { return false; } - private void reorderReq(IQuest quest, int id) { + private void reorderReq(IQuest quest, int id, boolean down) { int[] orig = quest.getRequirements(); int indexToShift = -1; @@ -266,7 +302,7 @@ private void reorderReq(IQuest quest, int id) { if (indexToShift < 0) return; - int indexFrom = (indexToShift - 1 + orig.length) % orig.length; + int indexFrom = (indexToShift + (down ? 1 : -1) + orig.length) % orig.length; int tmp = orig[indexToShift]; orig[indexToShift] = orig[indexFrom]; orig[indexFrom] = tmp; @@ -314,4 +350,5 @@ private void SendChanges() { payload.setInteger("action", 0); NetQuestEdit.sendEdit(payload); } + } diff --git a/src/main/java/betterquesting/client/gui2/editors/GuiQuestLinesEditor.java b/src/main/java/betterquesting/client/gui2/editors/GuiQuestLinesEditor.java index eb0d5b157..783a0318d 100644 --- a/src/main/java/betterquesting/client/gui2/editors/GuiQuestLinesEditor.java +++ b/src/main/java/betterquesting/client/gui2/editors/GuiQuestLinesEditor.java @@ -1,5 +1,10 @@ package betterquesting.client.gui2.editors; +import java.util.List; + +import org.lwjgl.input.Keyboard; +import org.lwjgl.util.vector.Vector4f; + import betterquesting.api.client.gui.misc.INeedsRefresh; import betterquesting.api.client.gui.misc.IVolatileScreen; import betterquesting.api.enums.EnumQuestVisibility; @@ -15,7 +20,11 @@ import betterquesting.api2.client.gui.events.PEventBroadcaster; import betterquesting.api2.client.gui.events.PanelEvent; import betterquesting.api2.client.gui.events.types.PEventButton; -import betterquesting.api2.client.gui.misc.*; +import betterquesting.api2.client.gui.misc.GuiAlign; +import betterquesting.api2.client.gui.misc.GuiPadding; +import betterquesting.api2.client.gui.misc.GuiRectangle; +import betterquesting.api2.client.gui.misc.GuiTransform; +import betterquesting.api2.client.gui.misc.IGuiRect; import betterquesting.api2.client.gui.panels.CanvasEmpty; import betterquesting.api2.client.gui.panels.CanvasTextured; import betterquesting.api2.client.gui.panels.bars.PanelVScrollBar; @@ -35,12 +44,9 @@ import net.minecraft.client.gui.GuiScreen; import net.minecraft.nbt.NBTTagCompound; import net.minecraft.nbt.NBTTagList; -import org.lwjgl.input.Keyboard; -import org.lwjgl.util.vector.Vector4f; - -import java.util.List; public class GuiQuestLinesEditor extends GuiScreenCanvas implements IPEventListener, IVolatileScreen, INeedsRefresh { + private CanvasScrolling lineList; private PanelTextField tfName; private PanelTextField tfDesc; @@ -73,8 +79,10 @@ public void refreshGui() { btnIcon.setActive(true); btnVis.setActive(true); btnVis.setText(QuestTranslation.translate("betterquesting.btn.show") + ": " + selected.getProperty(NativeProps.VISIBILITY)); - if (!tfName.isFocused()) tfName.setText(selected.getUnlocalisedName()); - if (!tfDesc.isFocused()) tfDesc.setText(selected.getUnlocalisedDescription()); + if (!tfName.isFocused()) + tfName.setText(selected.getUnlocalisedName()); + if (!tfDesc.isFocused()) + tfDesc.setText(selected.getUnlocalisedDescription()); } } @@ -89,10 +97,12 @@ public void initPanel() { Keyboard.enableRepeatEvents(true); // Background panel - CanvasTextured cvBackground = new CanvasTextured(new GuiTransform(GuiAlign.FULL_BOX, new GuiPadding(0, 0, 0, 0), 0), PresetTexture.PANEL_MAIN.getTexture()); + CanvasTextured cvBackground = new CanvasTextured(new GuiTransform(GuiAlign.FULL_BOX, new GuiPadding(0, 0, 0, 0), 0), + PresetTexture.PANEL_MAIN.getTexture()); this.addPanel(cvBackground); - PanelTextBox panTxt = new PanelTextBox(new GuiTransform(GuiAlign.TOP_EDGE, new GuiPadding(0, 16, 0, -32), 0), QuestTranslation.translate("betterquesting.title.edit_line1")).setAlignment(1); + PanelTextBox panTxt = new PanelTextBox(new GuiTransform(GuiAlign.TOP_EDGE, new GuiPadding(0, 16, 0, -32), 0), + QuestTranslation.translate("betterquesting.title.edit_line1")).setAlignment(1); panTxt.setColor(PresetColor.TEXT_HEADER.getColor()); cvBackground.addPanel(panTxt); @@ -107,10 +117,14 @@ public void initPanel() { cvBackground.addPanel(scList); lineList.setScrollDriverY(scList); - PanelButton btnAdd = new PanelButton(new GuiTransform(new Vector4f(0F, 1F, 0.25F, 1F), new GuiPadding(16, -40, 0, 24), 0), 1, QuestTranslation.translate("betterquesting.btn.new")); + PanelButton btnAdd = new PanelButton(new GuiTransform(new Vector4f(0F, 1F, 0.25F, 1F), new GuiPadding(16, -40, 0, 24), 0), + 1, + QuestTranslation.translate("betterquesting.btn.new")); cvBackground.addPanel(btnAdd); - PanelButton btnImport = new PanelButton(new GuiTransform(new Vector4f(0.25F, 1F, 0.5F, 1F), new GuiPadding(0, -40, 16, 24), 0), 2, QuestTranslation.translate("betterquesting.btn.import")); + PanelButton btnImport = new PanelButton(new GuiTransform(new Vector4f(0.25F, 1F, 0.5F, 1F), new GuiPadding(0, -40, 16, 24), 0), + 2, + QuestTranslation.translate("betterquesting.btn.import")); cvBackground.addPanel(btnImport); // Right side @@ -118,14 +132,16 @@ public void initPanel() { CanvasEmpty cvRight = new CanvasEmpty(new GuiTransform(GuiAlign.HALF_RIGHT, new GuiPadding(8, 32, 16, 24), 0)); cvBackground.addPanel(cvRight); - PanelTextBox txtName = new PanelTextBox(new GuiTransform(GuiAlign.TOP_EDGE, new GuiPadding(0, 4, 0, -16), 0), QuestTranslation.translate("betterquesting.gui.name")); + PanelTextBox txtName = new PanelTextBox(new GuiTransform(GuiAlign.TOP_EDGE, new GuiPadding(0, 4, 0, -16), 0), + QuestTranslation.translate("betterquesting.gui.name")); txtName.setColor(PresetColor.TEXT_MAIN.getColor()); cvRight.addPanel(txtName); tfName = new PanelTextField<>(new GuiTransform(GuiAlign.TOP_EDGE, new GuiPadding(0, 16, 0, -32), 0), "", FieldFilterString.INSTANCE); cvRight.addPanel(tfName); - PanelTextBox txtDesc = new PanelTextBox(new GuiTransform(GuiAlign.TOP_EDGE, new GuiPadding(0, 36, 0, -48), 0), QuestTranslation.translate("betterquesting.gui.description")); + PanelTextBox txtDesc = new PanelTextBox(new GuiTransform(GuiAlign.TOP_EDGE, new GuiPadding(0, 36, 0, -48), 0), + QuestTranslation.translate("betterquesting.gui.description")); txtDesc.setColor(PresetColor.TEXT_MAIN.getColor()); cvRight.addPanel(txtDesc); @@ -133,41 +149,56 @@ public void initPanel() { tfDesc.setMaxLength(Integer.MAX_VALUE); cvRight.addPanel(tfDesc); - btnIcon = new PanelButton(new GuiTransform(GuiAlign.TOP_EDGE, new GuiPadding(0, 80, 0, -96), 0), -1, QuestTranslation.translate("betterquesting.btn.icon")) { + btnIcon = new PanelButton(new GuiTransform(GuiAlign.TOP_EDGE, new GuiPadding(0, 80, 0, -96), 0), + -1, + QuestTranslation.translate("betterquesting.btn.icon")) { + @Override public void onButtonClick() { - if (selected == null) return; + if (selected == null) + return; mc.displayGuiScreen(new GuiItemSelection(GuiQuestLinesEditor.this, selected.getProperty(NativeProps.ICON), value -> { selected.setProperty(NativeProps.ICON, value); SendChanges(new DBEntry<>(selID, selected)); })); } + }; btnIcon.setActive(selected != null); cvRight.addPanel(btnIcon); - btnVis = new PanelButton(new GuiTransform(GuiAlign.TOP_EDGE, new GuiPadding(0, 96, 0, -112), 0), -1, QuestTranslation.translate("betterquesting.btn.show") + ": " + (selected == null ? EnumQuestVisibility.NORMAL : selected.getProperty(NativeProps.VISIBILITY))) { + btnVis = new PanelButton(new GuiTransform(GuiAlign.TOP_EDGE, new GuiPadding(0, 96, 0, -112), 0), + -1, + QuestTranslation.translate("betterquesting.btn.show") + ": " + (selected == null ? EnumQuestVisibility.NORMAL : selected + .getProperty(NativeProps.VISIBILITY))) { + @Override public void onButtonClick() { - if (selected == null) return; + if (selected == null) + return; EnumQuestVisibility[] visList = EnumQuestVisibility.values(); EnumQuestVisibility vis = selected.getProperty(NativeProps.VISIBILITY); vis = visList[(vis.ordinal() + 1) % visList.length]; selected.setProperty(NativeProps.VISIBILITY, vis); this.setText(QuestTranslation.translate("betterquesting.btn.show") + ": " + vis); } + }; btnVis.setActive(selected != null); cvRight.addPanel(btnVis); - PanelButton btnManage = new PanelButton(new GuiTransform(GuiAlign.TOP_EDGE, new GuiPadding(0, 112, 0, -128), 0), 3, QuestTranslation.translate("betterquesting.btn.add_remove_quests")); + PanelButton btnManage = new PanelButton(new GuiTransform(GuiAlign.TOP_EDGE, new GuiPadding(0, 112, 0, -128), 0), + 3, + QuestTranslation.translate("betterquesting.btn.add_remove_quests")); cvRight.addPanel(btnManage); - btnDesign = new PanelButton(new GuiTransform(GuiAlign.TOP_EDGE, new GuiPadding(0, 128, 0, -144), 0), 4, QuestTranslation.translate("betterquesting.btn.designer")); + btnDesign = new PanelButton(new GuiTransform(GuiAlign.TOP_EDGE, new GuiPadding(0, 128, 0, -144), 0), + 4, + QuestTranslation.translate("betterquesting.btn.designer")); btnDesign.setActive(selected != null); cvRight.addPanel(btnDesign); - PanelButton btnTextEditor = new PanelButton(new GuiTransform(GuiAlign.TOP_RIGHT, new GuiPadding(-16, 48, 0, -64), 0), 8, "Aa"); + PanelButton btnTextEditor = new PanelButton(new GuiTransform(GuiAlign.TOP_RIGHT, new GuiPadding(-16, 48, 0, -64), 0), 9, "Aa"); cvRight.addPanel(btnTextEditor); // Dividers @@ -194,8 +225,10 @@ public void onButtonClick() { btnIcon.setActive(true); btnVis.setActive(true); btnVis.setText(QuestTranslation.translate("betterquesting.btn.show") + ": " + selected.getProperty(NativeProps.VISIBILITY)); - if (!tfName.isFocused()) tfName.setText(selected.getUnlocalisedName()); - if (!tfDesc.isFocused()) tfDesc.setText(selected.getUnlocalisedDescription()); + if (!tfName.isFocused()) + tfName.setText(selected.getUnlocalisedName()); + if (!tfDesc.isFocused()) + tfDesc.setText(selected.getUnlocalisedDescription()); } } @@ -276,14 +309,23 @@ private void onButtonPress(PEventButton event) { { DBEntry entry = ((PanelButtonStorage>) btn).getStoredValue(); NBTTagCompound payload = new NBTTagCompound(); - payload.setIntArray("chapterIDs", new int[]{entry.getID()}); + payload.setIntArray("chapterIDs", new int[] { + entry.getID() + }); payload.setInteger("action", 1); NetChapterEdit.sendEdit(payload); } else if (btn.getButtonID() == 7 && btn instanceof PanelButtonStorage) // Move Up { DBEntry entry = ((PanelButtonStorage>) btn).getStoredValue(); int order = QuestLineDatabase.INSTANCE.getOrderIndex(entry.getID()); - if (order > 0) SendReorder(order); + if (order > 0) + SendReorder(order, false); + } else if (btn.getButtonID() == 8 && btn instanceof PanelButtonStorage) // Move Down + { + DBEntry entry = ((PanelButtonStorage>) btn).getStoredValue(); + int order = QuestLineDatabase.INSTANCE.getOrderIndex(entry.getID()); + if (order < QuestLineDatabase.INSTANCE.getSortedEntries().size() - 1) + SendReorder(order, true); } else if (btn.getButtonID() == 8) // Big Description Editor { mc.displayGuiScreen(new GuiTextEditor(this, tfDesc.getRawText(), value -> { @@ -304,13 +346,20 @@ private void reloadList() { for (DBEntry entry : QuestLineDatabase.INSTANCE.getSortedEntries()) { IQuestLine ql = entry.getValue(); - PanelButtonStorage> tmp = new PanelButtonStorage<>(new GuiRectangle(0, i * 16, w - 32, 16, 0), 5, QuestTranslation.translate(ql.getUnlocalisedName()), entry); + PanelButtonStorage> tmp = new PanelButtonStorage<>(new GuiRectangle(0, i * 16, w - 48, 16, 0), + 5, + QuestTranslation.translate(ql.getUnlocalisedName()), + entry); tmp.setActive(entry.getID() != selID); lineList.addPanel(tmp); - lineList.addPanel(new PanelButtonStorage<>(new GuiRectangle(w - 32, i * 16, 16, 16, 0), 6, "", entry).setIcon(PresetIcon.ICON_TRASH.getTexture())); - PanelButton btnUp = new PanelButtonStorage<>(new GuiRectangle(w - 16, i * 16, 16, 16, 0), 7, "", entry).setIcon(PresetIcon.ICON_UP.getTexture()); - btnUp.setActive(QuestLineDatabase.INSTANCE.getSortedEntries().size() > 1); + lineList.addPanel(new PanelButtonStorage<>(new GuiRectangle(w - 48, i * 16, 16, 16, 0), 6, "", entry).setIcon(PresetIcon.ICON_TRASH.getTexture())); + PanelButton btnUp = new PanelButtonStorage<>(new GuiRectangle(w - 32, i * 16, 16, 16, 0), 7, "", entry).setIcon(PresetIcon.ICON_UP.getTexture()); + btnUp.setActive(i > 0); lineList.addPanel(btnUp); + PanelButton btnDown = new PanelButtonStorage<>(new GuiRectangle(w - 16, i * 16, 16, 16, 0), 8, "", entry).setIcon(PresetIcon.ICON_DOWN + .getTexture()); + btnDown.setActive(i < QuestLineDatabase.INSTANCE.getSortedEntries().size() - 1); + lineList.addPanel(btnDown); i++; } } @@ -327,16 +376,18 @@ private void SendChanges(DBEntry chapter) { NetChapterEdit.sendEdit(payload); } - private void SendReorder(int indexToShift) { - if (indexToShift < 0) return; + private void SendReorder(int indexToShift, boolean down) { + if (indexToShift < 0) + return; List> entries = QuestLineDatabase.INSTANCE.getSortedEntries(); - if (indexToShift >= entries.size()) return; + if (indexToShift >= entries.size()) + return; int[] chapterIDs = new int[entries.size()]; for (int i = 0; i < entries.size(); i++) { chapterIDs[i] = entries.get(i).getID(); } - int indexFrom = (indexToShift - 1 + chapterIDs.length) % chapterIDs.length; + int indexFrom = (indexToShift + (down ? 1 : -1) + chapterIDs.length) % chapterIDs.length; int tmp = chapterIDs[indexToShift]; chapterIDs[indexToShift] = chapterIDs[indexFrom]; chapterIDs[indexFrom] = tmp; @@ -346,4 +397,5 @@ private void SendReorder(int indexToShift) { payload.setInteger("action", 2); NetChapterEdit.sendEdit(payload); } + } diff --git a/src/main/java/betterquesting/client/gui2/editors/GuiTaskEditor.java b/src/main/java/betterquesting/client/gui2/editors/GuiTaskEditor.java index f5378948b..9f3ac7bab 100644 --- a/src/main/java/betterquesting/client/gui2/editors/GuiTaskEditor.java +++ b/src/main/java/betterquesting/client/gui2/editors/GuiTaskEditor.java @@ -14,7 +14,11 @@ import betterquesting.api2.client.gui.events.PEventBroadcaster; import betterquesting.api2.client.gui.events.PanelEvent; import betterquesting.api2.client.gui.events.types.PEventButton; -import betterquesting.api2.client.gui.misc.*; +import betterquesting.api2.client.gui.misc.GuiAlign; +import betterquesting.api2.client.gui.misc.GuiPadding; +import betterquesting.api2.client.gui.misc.GuiRectangle; +import betterquesting.api2.client.gui.misc.GuiTransform; +import betterquesting.api2.client.gui.misc.IGuiRect; import betterquesting.api2.client.gui.panels.CanvasTextured; import betterquesting.api2.client.gui.panels.bars.PanelVScrollBar; import betterquesting.api2.client.gui.panels.content.PanelLine; @@ -22,31 +26,38 @@ import betterquesting.api2.client.gui.panels.lists.CanvasScrolling; import betterquesting.api2.client.gui.panels.lists.CanvasSearch; import betterquesting.api2.client.gui.themes.presets.PresetColor; +import betterquesting.api2.client.gui.themes.presets.PresetIcon; import betterquesting.api2.client.gui.themes.presets.PresetLine; import betterquesting.api2.client.gui.themes.presets.PresetTexture; import betterquesting.api2.registry.IFactoryData; import betterquesting.api2.storage.DBEntry; +import betterquesting.api2.storage.IDatabaseNBT; import betterquesting.api2.utils.QuestTranslation; import betterquesting.client.gui2.editors.nbt.GuiNbtEditor; import betterquesting.network.handlers.NetQuestEdit; import betterquesting.questing.QuestDatabase; import betterquesting.questing.tasks.TaskRegistry; +import it.unimi.dsi.fastutil.ints.Int2IntMap; +import it.unimi.dsi.fastutil.ints.Int2IntOpenHashMap; +import java.util.ArrayDeque; +import java.util.Comparator; +import java.util.Iterator; +import java.util.List; +import javax.annotation.Nullable; import net.minecraft.client.gui.GuiScreen; import net.minecraft.nbt.NBTTagCompound; import net.minecraft.nbt.NBTTagList; import net.minecraft.util.text.TextFormatting; import org.lwjgl.util.vector.Vector4f; -import java.util.ArrayDeque; -import java.util.Comparator; -import java.util.Iterator; -import java.util.List; - public class GuiTaskEditor extends GuiScreenCanvas implements IPEventListener, IVolatileScreen, INeedsRefresh { + private CanvasScrolling qtList; private IQuest quest; private final int qID; + @Nullable // Not null when tasks are reordered. + private Int2IntMap taskIndexBeforeReorder = null; // currentIndex -> oldIndex public GuiTaskEditor(GuiScreen parent, IQuest quest) { super(parent); @@ -79,16 +90,24 @@ public void initPanel() { PEventBroadcaster.INSTANCE.register(this, PEventButton.class); // Background panel - CanvasTextured cvBackground = new CanvasTextured(new GuiTransform(GuiAlign.FULL_BOX, new GuiPadding(0, 0, 0, 0), 0), PresetTexture.PANEL_MAIN.getTexture()); + CanvasTextured cvBackground = new CanvasTextured(new GuiTransform(GuiAlign.FULL_BOX, new GuiPadding(0, 0, 0, 0), 0), + PresetTexture.PANEL_MAIN.getTexture()); this.addPanel(cvBackground); - PanelTextBox panTxt = new PanelTextBox(new GuiTransform(GuiAlign.TOP_EDGE, new GuiPadding(0, 16, 0, -32), 0), QuestTranslation.translate("betterquesting.title.edit_tasks")).setAlignment(1); + PanelTextBox panTxt = new PanelTextBox(new GuiTransform(GuiAlign.TOP_EDGE, new GuiPadding(0, 16, 0, -32), 0), + QuestTranslation.translate("betterquesting.title.edit_tasks")).setAlignment(1); panTxt.setColor(PresetColor.TEXT_HEADER.getColor()); cvBackground.addPanel(panTxt); cvBackground.addPanel(new PanelButton(new GuiTransform(GuiAlign.BOTTOM_CENTER, -100, -16, 200, 16, 0), 0, QuestTranslation.translate("gui.back"))); - CanvasSearch, IFactoryData> cvRegSearch = new CanvasSearch, IFactoryData>((new GuiTransform(GuiAlign.HALF_RIGHT, new GuiPadding(8, 48, 24, 32), 0))) { + CanvasSearch, IFactoryData> cvRegSearch = new CanvasSearch, IFactoryData>((new GuiTransform(GuiAlign.HALF_RIGHT, + new GuiPadding(8, + 48, + 24, + 32), + 0))) { + @Override protected Iterator> getIterator() { List> list = TaskRegistry.INSTANCE.getAll(); @@ -98,7 +117,8 @@ protected Iterator> getIterator() { @Override protected void queryMatches(IFactoryData value, String query, ArrayDeque> results) { - if (value.getRegistryName().toString().toLowerCase().contains(query.toLowerCase())) results.add(value); + if (value.getRegistryName().toString().toLowerCase().contains(query.toLowerCase())) + results.add(value); } @Override @@ -106,6 +126,7 @@ protected boolean addResult(IFactoryData entry, int index this.addPanel(new PanelButtonStorage<>(new GuiRectangle(0, index * 16, cachedWidth, 16, 0), 1, entry.getRegistryName().toString(), entry)); return true; } + }; cvBackground.addPanel(cvRegSearch); @@ -113,7 +134,9 @@ protected boolean addResult(IFactoryData entry, int index cvBackground.addPanel(scReg); cvRegSearch.setScrollDriverY(scReg); - PanelTextField tfSearch = new PanelTextField<>(new GuiTransform(new Vector4f(0.5F, 0F, 1F, 0F), new GuiPadding(8, 32, 16, -48), 0), "", FieldFilterString.INSTANCE); + PanelTextField tfSearch = new PanelTextField<>(new GuiTransform(new Vector4f(0.5F, 0F, 1F, 0F), new GuiPadding(8, 32, 16, -48), 0), + "", + FieldFilterString.INSTANCE); tfSearch.setCallback(cvRegSearch::setSearchFilter); tfSearch.setWatermark("Search..."); cvBackground.addPanel(tfSearch); @@ -177,6 +200,16 @@ private void onButtonPress(PEventButton event) { SendChanges(); })); } + } else if (btn.getButtonID() == 4 && btn instanceof PanelButtonStorage) // Up + { + ITask task = ((PanelButtonStorage) btn).getStoredValue(); + int idx = quest.getTasks().getID(task); + reorder(idx, false); + } else if (btn.getButtonID() == 5 && btn instanceof PanelButtonStorage) // Down + { + ITask task = ((PanelButtonStorage) btn).getStoredValue(); + int idx = quest.getTasks().getID(task); + reorder(idx, true); } } @@ -188,8 +221,23 @@ private void refreshTasks() { for (int i = 0; i < dbTsk.size(); i++) { ITask task = dbTsk.get(i).getValue(); - qtList.addPanel(new PanelButtonStorage<>(new GuiRectangle(0, i * 16, w - 16, 16, 0), 3, QuestTranslation.translate(task.getUnlocalisedName()), task)); - qtList.addPanel(new PanelButtonStorage<>(new GuiRectangle(w - 16, i * 16, 16, 16, 0), 2, "" + TextFormatting.RED + TextFormatting.BOLD + "x", task)); + int index = taskIndexBeforeReorder == null ? i : taskIndexBeforeReorder.get(i); + qtList.addPanel(new PanelButtonStorage<>(new GuiRectangle(0, i * 16, w - 48, 16, 0), + 3, + (index + 1) + ". " + QuestTranslation.translate(task.getUnlocalisedName()), + task)); + + PanelButton btnUp = new PanelButtonStorage<>(new GuiRectangle(w - 48, i * 16, 16, 16, 0), 4, "", task).setIcon(PresetIcon.ICON_UP.getTexture()); + btnUp.setActive(i > 0); + qtList.addPanel(btnUp); + PanelButton btnDown = new PanelButtonStorage<>(new GuiRectangle(w - 32, i * 16, 16, 16, 0), 5, "", task).setIcon(PresetIcon.ICON_DOWN.getTexture()); + btnDown.setActive(i < dbTsk.size() - 1); + qtList.addPanel(btnDown); + + qtList.addPanel(new PanelButtonStorage<>(new GuiRectangle(w - 16, i * 16, 16, 16, 0), + 2, + "" + TextFormatting.RED + TextFormatting.BOLD + "x", + task)); } } @@ -204,4 +252,34 @@ private void SendChanges() { payload.setInteger("action", 0); NetQuestEdit.sendEdit(payload); } + + private void reorder(int index, boolean down) { + + int size = quest.getTasks().size(); + + int indexFrom = (index + (down ? 1 : -1) + size) % size; + + IDatabaseNBT tasks = quest.getTasks(); + + if (taskIndexBeforeReorder == null) { + taskIndexBeforeReorder = new Int2IntOpenHashMap(); + for (DBEntry entry : tasks.getEntries()) { + taskIndexBeforeReorder.put(entry.getID(), entry.getID()); + } + } + + ITask task = tasks.getValue(index); + ITask task2 = tasks.getValue(indexFrom); + tasks.removeID(index); + tasks.removeID(indexFrom); + tasks.add(index, task2); + tasks.add(indexFrom, task); + + int tmp = taskIndexBeforeReorder.get(index); + taskIndexBeforeReorder.put(index, taskIndexBeforeReorder.get(indexFrom)); + taskIndexBeforeReorder.put(indexFrom, tmp); + + SendChanges(); + } + }