diff --git a/src/main/java/kamkeel/npcs/client/gui/components/CollapsibleSection.java b/src/main/java/kamkeel/npcs/client/gui/components/CollapsibleSection.java index 7873be926..4b4e50be1 100644 --- a/src/main/java/kamkeel/npcs/client/gui/components/CollapsibleSection.java +++ b/src/main/java/kamkeel/npcs/client/gui/components/CollapsibleSection.java @@ -4,6 +4,9 @@ import noppes.npcs.client.gui.util.ModernColors; import net.minecraft.client.Minecraft; import net.minecraft.client.gui.FontRenderer; import net.minecraft.client.gui.Gui; +import net.minecraft.client.renderer.Tessellator; +import net.minecraft.util.ResourceLocation; +import org.lwjgl.opengl.GL11; /** * A collapsible section header that can expand/collapse its content. @@ -27,6 +30,14 @@ public class CollapsibleSection extends Gui { protected int spacing = 4; protected int topPadding = 4; // Padding between header and first content row + // Remove button + protected Runnable onRemove = null; + protected boolean hoveringRemoveBtn = false; + protected int removeBtnSize = 14; + + // Icon + protected static final ResourceLocation X_ICON = new ResourceLocation("customnpcs", "textures/gui/auction/x_icon.png"); + // Colors protected int headerBg = ModernColors.SECTION_HEADER_BG; protected int headerBgHover = ModernColors.SECTION_HEADER_HOVER; @@ -133,7 +144,38 @@ public class CollapsibleSection extends Gui { // Draw title int titleX = x + 14; - fr.drawString(title, titleX, y + (headerHeight - fr.FONT_HEIGHT) / 2, headerText); + int titleEndX = x + width; + + // Draw remove button if present + if (onRemove != null) { + int btnX = x + width - removeBtnSize - 4; + int btnY = y + (headerHeight - removeBtnSize) / 2; + titleEndX = btnX - 4; + + hoveringRemoveBtn = mouseX >= btnX && mouseX < btnX + removeBtnSize && + mouseY >= btnY && mouseY < btnY + removeBtnSize; + + int btnBg = hoveringRemoveBtn ? 0xFFCC4444 : 0xFFAA3333; + drawRect(btnX, btnY, btnX + removeBtnSize, btnY + removeBtnSize, btnBg); + Minecraft.getMinecraft().getTextureManager().bindTexture(X_ICON); + GL11.glColor4f(1f, 1f, 1f, 1f); + GL11.glEnable(GL11.GL_BLEND); + int iconSize = removeBtnSize - 4; + int ix = btnX + 2; + int iy = btnY + 2; + Tessellator t = Tessellator.instance; + t.startDrawingQuads(); + t.addVertexWithUV(ix, iy + iconSize, zLevel, 0, 1); + t.addVertexWithUV(ix + iconSize, iy + iconSize, zLevel, 1, 1); + t.addVertexWithUV(ix + iconSize, iy, zLevel, 1, 0); + t.addVertexWithUV(ix, iy, zLevel, 0, 0); + t.draw(); + GL11.glDisable(GL11.GL_BLEND); + } + + // Draw title (truncated if needed) + String displayTitle = fr.trimStringToWidth(title, titleEndX - titleX); + fr.drawString(displayTitle, titleX, y + (headerHeight - fr.FONT_HEIGHT) / 2, headerText); // Return whether content should be drawn return expanded || expandProgress > 0.01f; @@ -158,6 +200,14 @@ public class CollapsibleSection extends Gui { // Check if header was clicked if (mouseX >= x && mouseX < x + width && mouseY >= y && mouseY < y + headerHeight) { + + // Check remove button first + if (onRemove != null && hoveringRemoveBtn) { + onRemove.run(); + return true; + } + + // Otherwise toggle expand toggle(); return true; } @@ -208,6 +258,11 @@ public class CollapsibleSection extends Gui { return this; } + public CollapsibleSection setOnRemove(Runnable action) { + this.onRemove = action; + return this; + } + public CollapsibleSection setColors(int headerBg, int headerText, int arrow) { this.headerBg = headerBg; this.headerBgHover = ModernColors.lighten(headerBg, 0.1f); diff --git a/src/main/java/kamkeel/npcs/client/gui/modern/DialogEditorPanel.java b/src/main/java/kamkeel/npcs/client/gui/modern/DialogEditorPanel.java index c5cad2b12..8df6eb094 100644 --- a/src/main/java/kamkeel/npcs/client/gui/modern/DialogEditorPanel.java +++ b/src/main/java/kamkeel/npcs/client/gui/modern/DialogEditorPanel.java @@ -321,17 +321,10 @@ public class DialogEditorPanel extends Gui { return true; } - // CHECK EXPANDED DROPDOWNS FIRST - use SCREEN coordinates - for (ModernDropdown dropdown : getAllDropdowns()) { - if (dropdown.isExpanded()) { - int prevIndex = dropdown.getSelectedIndex(); - if (dropdown.mouseClickedScreenSpace(mouseX, mouseY, button)) { - if (dropdown.getSelectedIndex() != prevIndex) { - markDirty(); - } - return true; - } - } + // CHECK EXPANDED DROPDOWNS FIRST - delegate to current tab's field panel + if (tabs[currentTab].handleExpandedDropdownScreenClick(mouseX, mouseY, button)) { + markDirty(); + return true; } // Adjust mouseY for scroll (for components inside scrollable content) @@ -353,14 +346,18 @@ public class DialogEditorPanel extends Gui { public void mouseReleased(int mouseX, int mouseY) { scrollPanel.mouseReleased(mouseX, mouseY); // Let text areas handle mouse release - textTab.getTextArea().mouseReleased(mouseX, mouseY); - settingsTab.getCommandArea().mouseReleased(mouseX, mouseY); + ModernTextArea textArea = textTab.getTextArea(); + if (textArea != null) textArea.mouseReleased(mouseX, mouseY); + ModernTextArea cmdArea = settingsTab.getCommandArea(); + if (cmdArea != null) cmdArea.mouseReleased(mouseX, mouseY); } public void mouseDragged(int mouseX, int mouseY) { scrollPanel.mouseDragged(mouseX, mouseY); - textTab.getTextArea().mouseDragged(mouseX, mouseY); - settingsTab.getCommandArea().mouseDragged(mouseX, mouseY); + ModernTextArea textArea = textTab.getTextArea(); + if (textArea != null) textArea.mouseDragged(mouseX, mouseY); + ModernTextArea cmdArea = settingsTab.getCommandArea(); + if (cmdArea != null) cmdArea.mouseDragged(mouseX, mouseY); } public void updateScreen() { @@ -369,12 +366,6 @@ public class DialogEditorPanel extends Gui { } } - // === Option Management === - - public void removeOption(int slot) { - optionsTab.removeOption(slot); - } - // === Utility === public void markDirty() { dirty = true; } @@ -432,18 +423,10 @@ public class DialogEditorPanel extends Gui { } public void onColorSelected(int slot, int color) { - if (slot < 100) { - feedbackTab.onColorSelected(slot, color); + if (slot >= 100) { + optionsTab.onColorSelected(slot, color); } else { - // Option color (slot 100+) - int optionSlot = slot - 100; - for (OptionEditorV2 editor : optionsTab.getOptionEditors()) { - if (editor.getSlot() == optionSlot) { - editor.getColorBtn().setColor(color); - markDirty(); - return; - } - } + feedbackTab.onColorSelected(slot, color); } } diff --git a/src/main/java/kamkeel/npcs/client/gui/modern/tabs/AvailabilityRow.java b/src/main/java/kamkeel/npcs/client/gui/modern/tabs/AvailabilityRow.java deleted file mode 100644 index 671088bbc..000000000 --- a/src/main/java/kamkeel/npcs/client/gui/modern/tabs/AvailabilityRow.java +++ /dev/null @@ -1,99 +0,0 @@ -package kamkeel.npcs.client.gui.modern.tabs; - -import kamkeel.npcs.client.gui.components.ModernButton; -import kamkeel.npcs.client.gui.components.ModernDropdown; -import kamkeel.npcs.client.gui.components.ModernSelectButton; -import kamkeel.npcs.client.gui.modern.DialogEditorPanel; -import noppes.npcs.client.gui.util.IDialogEditorListener; -import net.minecraft.client.Minecraft; -import net.minecraft.client.gui.FontRenderer; - -import java.util.List; - -/** - * A row component for quest/dialog availability requirements. - * Contains a condition dropdown, select button, and clear button. - */ -public class AvailabilityRow { - private int baseId; - private int slot; - private String type; - - private ModernDropdown conditionDropdown; - private ModernSelectButton selectBtn; - private ModernButton clearBtn; - - private int x, y, width; - - public AvailabilityRow(int baseId, int slot, String type, List conditions) { - this.baseId = baseId; - this.slot = slot; - this.type = type; - - conditionDropdown = new ModernDropdown(baseId, 0, 0, 70, 16); - conditionDropdown.setOptions(conditions); - - selectBtn = new ModernSelectButton(baseId + 1, 0, 0, 80, 16, "Select " + type + "..."); - clearBtn = new ModernButton(baseId + 2, 0, 0, 16, 16, "X"); - } - - public void setBounds(int x, int y, int width) { - this.x = x; - this.y = y; - this.width = width; - } - - public void draw(int mouseX, int mouseY, FontRenderer fr) { - conditionDropdown.setBounds(x, y, 70, 16); - conditionDropdown.drawBase(mouseX, mouseY); - - boolean enabled = conditionDropdown.getSelectedIndex() != 0; - selectBtn.setEnabled(enabled); - selectBtn.setBounds(x + 74, y, width - 94, 16); - selectBtn.draw(mouseX, mouseY); - - clearBtn.xPosition = x + width - 16; - clearBtn.yPosition = y; - clearBtn.width = 16; - clearBtn.height = 16; - clearBtn.enabled = enabled; - clearBtn.drawButton(Minecraft.getMinecraft(), mouseX, mouseY); - } - - public boolean mouseClicked(int mouseX, int mouseY, int button, DialogEditorPanel panel, String selectType) { - if (conditionDropdown.mouseClicked(mouseX, mouseY, button)) return true; - if (selectBtn.mouseClicked(mouseX, mouseY, button)) { - IDialogEditorListener listener = panel.getListener(); - if (listener != null) { - if ("quest".equals(selectType)) { - listener.onQuestSelectRequested(slot + 1); - } else { - listener.onDialogSelectRequested(slot); - } - } - return true; - } - if (clearBtn.mousePressed(Minecraft.getMinecraft(), mouseX, mouseY)) { - selectBtn.clearSelection(); - return true; - } - return false; - } - - public void setData(int condition, int selectedId) { - conditionDropdown.setSelectedIndex(condition); - if (selectedId >= 0) { - selectBtn.setSelected(selectedId, type + " #" + selectedId); - } else { - selectBtn.clearSelection(); - } - } - - public void setSelected(int id, String name) { - selectBtn.setSelected(id, name); - } - - public int getCondition() { return conditionDropdown.getSelectedIndex(); } - public int getSelectedId() { return selectBtn.getSelectedId(); } - public ModernDropdown getConditionDropdown() { return conditionDropdown; } -} diff --git a/src/main/java/kamkeel/npcs/client/gui/modern/tabs/DialogAvailabilityTab.java b/src/main/java/kamkeel/npcs/client/gui/modern/tabs/DialogAvailabilityTab.java index 42962573e..990582c0e 100644 --- a/src/main/java/kamkeel/npcs/client/gui/modern/tabs/DialogAvailabilityTab.java +++ b/src/main/java/kamkeel/npcs/client/gui/modern/tabs/DialogAvailabilityTab.java @@ -1,10 +1,14 @@ package kamkeel.npcs.client.gui.modern.tabs; -import kamkeel.npcs.client.gui.components.*; +import kamkeel.npcs.client.gui.components.ModernDropdown; import kamkeel.npcs.client.gui.modern.DialogEditorPanel; -import noppes.npcs.client.gui.util.ModernColors; import net.minecraft.client.gui.FontRenderer; +import noppes.npcs.client.gui.builder.FieldDef; +import noppes.npcs.client.gui.builder.ModernFieldPanel; +import noppes.npcs.client.gui.builder.ModernFieldPanelListener; +import noppes.npcs.client.gui.util.IDialogEditorListener; import noppes.npcs.constants.EnumAvailabilityDialog; +import noppes.npcs.constants.EnumAvailabilityFaction; import noppes.npcs.constants.EnumAvailabilityFactionType; import noppes.npcs.constants.EnumAvailabilityQuest; import noppes.npcs.constants.EnumDayTime; @@ -12,295 +16,211 @@ import noppes.npcs.controllers.data.Availability; import noppes.npcs.controllers.data.Dialog; import java.util.ArrayList; -import java.util.Arrays; import java.util.List; /** * Availability tab for the dialog editor. * Contains quest, dialog, faction requirements and time/level settings. + * Uses ModernFieldPanel with custom AVAILABILITY_ROW and FACTION_ROW field types. */ public class DialogAvailabilityTab extends DialogEditorTab { - private int componentGap = 3; + private static final String[] QUEST_CONDITIONS = {"Always", "After", "Before", "Active", "Not Active", "Acceptable", "Not Acceptable"}; + private static final String[] DIALOG_CONDITIONS = {"Always", "After", "Before"}; - // Quest Requirements Section - private CollapsibleSection questReqSection; - private List questReqRows = new ArrayList<>(); - - // Dialog Requirements Section - private CollapsibleSection dialogReqSection; - private List dialogReqRows = new ArrayList<>(); - - // Faction Requirements Section - private CollapsibleSection factionReqSection; - private List factionRows = new ArrayList<>(); - - // Time & Level Section - private CollapsibleSection timeSection; - private ModernDropdown dayTimeDropdown; - private ModernNumberField minLevelField; + private ModernFieldPanel fieldPanel; public DialogAvailabilityTab(DialogEditorPanel parent) { super(parent); - initComponents(); + fieldPanel = new ModernFieldPanel(); + fieldPanel.setListener(new ModernFieldPanelListener() { + @Override + public void onSelectAction(String action, int slot) { + IDialogEditorListener listener = parent.getListener(); + if (listener == null) return; + switch (action) { + case "quest": + listener.onQuestSelectRequested(slot); + break; + case "dialog": + listener.onDialogSelectRequested(slot); + break; + case "faction": + listener.onFactionSelectRequested(slot); + break; + } + } + + @Override + public void onColorSelect(int slot, int currentColor) { + // No color fields in this tab + } + + @Override + public void onFieldChanged() { + markDirty(); + } + }); } - private void initComponents() { - // Quest Requirements - questReqSection = new CollapsibleSection(500, "Quest Requirements"); - for (int i = 0; i < 4; i++) { - questReqRows.add(new AvailabilityRow(510 + i * 10, i, "Quest", - Arrays.asList("Always", "After", "Before", "Active", "Not Active", "Acceptable", "Not Acceptable"))); - } + private List createFieldDefs() { + Availability a = dialog.availability; + List defs = new ArrayList<>(); + + // Quest Requirements (expanded by default) + defs.add(FieldDef.section("Quest Requirements").collapsed(true)); + defs.add(FieldDef.availabilityRow("", QUEST_CONDITIONS, + () -> a.questAvailable.ordinal(), v -> a.questAvailable = EnumAvailabilityQuest.values()[v], + () -> a.questId, v -> a.questId = v, + () -> a.questId >= 0 ? "Quest #" + a.questId : "") + .action("quest").slot(1).clearable(() -> a.questId = -1)); + defs.add(FieldDef.availabilityRow("", QUEST_CONDITIONS, + () -> a.quest2Available.ordinal(), v -> a.quest2Available = EnumAvailabilityQuest.values()[v], + () -> a.quest2Id, v -> a.quest2Id = v, + () -> a.quest2Id >= 0 ? "Quest #" + a.quest2Id : "") + .action("quest").slot(2).clearable(() -> a.quest2Id = -1)); + defs.add(FieldDef.availabilityRow("", QUEST_CONDITIONS, + () -> a.quest3Available.ordinal(), v -> a.quest3Available = EnumAvailabilityQuest.values()[v], + () -> a.quest3Id, v -> a.quest3Id = v, + () -> a.quest3Id >= 0 ? "Quest #" + a.quest3Id : "") + .action("quest").slot(3).clearable(() -> a.quest3Id = -1)); + defs.add(FieldDef.availabilityRow("", QUEST_CONDITIONS, + () -> a.quest4Available.ordinal(), v -> a.quest4Available = EnumAvailabilityQuest.values()[v], + () -> a.quest4Id, v -> a.quest4Id = v, + () -> a.quest4Id >= 0 ? "Quest #" + a.quest4Id : "") + .action("quest").slot(4).clearable(() -> a.quest4Id = -1)); // Dialog Requirements - dialogReqSection = new CollapsibleSection(550, "Dialog Requirements", false); - for (int i = 0; i < 4; i++) { - dialogReqRows.add(new AvailabilityRow(560 + i * 10, i, "Dialog", - Arrays.asList("Always", "After", "Before"))); - } + defs.add(FieldDef.section("Dialog Requirements").collapsed(true)); + defs.add(FieldDef.availabilityRow("", DIALOG_CONDITIONS, + () -> a.dialogAvailable.ordinal(), v -> a.dialogAvailable = EnumAvailabilityDialog.values()[v], + () -> a.dialogId, v -> a.dialogId = v, + () -> a.dialogId >= 0 ? "Dialog #" + a.dialogId : "") + .action("dialog").slot(0).clearable(() -> a.dialogId = -1)); + defs.add(FieldDef.availabilityRow("", DIALOG_CONDITIONS, + () -> a.dialog2Available.ordinal(), v -> a.dialog2Available = EnumAvailabilityDialog.values()[v], + () -> a.dialog2Id, v -> a.dialog2Id = v, + () -> a.dialog2Id >= 0 ? "Dialog #" + a.dialog2Id : "") + .action("dialog").slot(1).clearable(() -> a.dialog2Id = -1)); + defs.add(FieldDef.availabilityRow("", DIALOG_CONDITIONS, + () -> a.dialog3Available.ordinal(), v -> a.dialog3Available = EnumAvailabilityDialog.values()[v], + () -> a.dialog3Id, v -> a.dialog3Id = v, + () -> a.dialog3Id >= 0 ? "Dialog #" + a.dialog3Id : "") + .action("dialog").slot(2).clearable(() -> a.dialog3Id = -1)); + defs.add(FieldDef.availabilityRow("", DIALOG_CONDITIONS, + () -> a.dialog4Available.ordinal(), v -> a.dialog4Available = EnumAvailabilityDialog.values()[v], + () -> a.dialog4Id, v -> a.dialog4Id = v, + () -> a.dialog4Id >= 0 ? "Dialog #" + a.dialog4Id : "") + .action("dialog").slot(3).clearable(() -> a.dialog4Id = -1)); // Faction Requirements - factionReqSection = new CollapsibleSection(600, "Faction Requirements", false); - for (int i = 0; i < 2; i++) { - factionRows.add(new FactionRow(610 + i * 10, i)); - } + defs.add(FieldDef.section("Faction Requirements").collapsed(true)); + defs.add(FieldDef.factionRow("", + () -> a.factionAvailable.ordinal(), v -> a.factionAvailable = EnumAvailabilityFactionType.values()[v], + () -> a.factionStance.ordinal(), v -> a.factionStance = EnumAvailabilityFaction.values()[v], + () -> a.factionId, v -> a.factionId = v, + () -> a.factionId >= 0 ? "Faction #" + a.factionId : "") + .action("faction").slot(0).clearable(() -> a.factionId = -1)); + defs.add(FieldDef.factionRow("", + () -> a.faction2Available.ordinal(), v -> a.faction2Available = EnumAvailabilityFactionType.values()[v], + () -> a.faction2Stance.ordinal(), v -> a.faction2Stance = EnumAvailabilityFaction.values()[v], + () -> a.faction2Id, v -> a.faction2Id = v, + () -> a.faction2Id >= 0 ? "Faction #" + a.faction2Id : "") + .action("faction").slot(1).clearable(() -> a.faction2Id = -1)); // Time & Level - timeSection = new CollapsibleSection(650, "Time & Level", false); - dayTimeDropdown = new ModernDropdown(651, 0, 0, 80, 16); - dayTimeDropdown.setOptions(Arrays.asList("Always", "Night", "Day")); - minLevelField = new ModernNumberField(652, 0, 0, 50, 16, 0); - minLevelField.setIntegerBounds(0, 1000, 0); + defs.add(FieldDef.section("Time & Level").collapsed(true)); + defs.add(FieldDef.row( + FieldDef.stringEnumField("Time", new String[]{"Always", "Night", "Day"}, + () -> new String[]{"Always", "Night", "Day"}[a.daytime.ordinal()], + v -> { + if ("Night".equals(v)) a.daytime = EnumDayTime.Night; + else if ("Day".equals(v)) a.daytime = EnumDayTime.Day; + else a.daytime = EnumDayTime.Always; + }), + FieldDef.intField("Min Lvl", () -> a.minPlayerLevel, v -> a.minPlayerLevel = v) + .range(0, 1000) + )); + + return defs; } @Override public void loadFromDialog(Dialog dialog) { this.dialog = dialog; if (dialog == null || dialog.availability == null) return; - - loadAvailability(dialog.availability); - } - - private void loadAvailability(Availability avail) { - // Quest requirements - questReqRows.get(0).setData(avail.questAvailable.ordinal(), avail.questId); - questReqRows.get(1).setData(avail.quest2Available.ordinal(), avail.quest2Id); - questReqRows.get(2).setData(avail.quest3Available.ordinal(), avail.quest3Id); - questReqRows.get(3).setData(avail.quest4Available.ordinal(), avail.quest4Id); - - // Dialog requirements - dialogReqRows.get(0).setData(avail.dialogAvailable.ordinal(), avail.dialogId); - dialogReqRows.get(1).setData(avail.dialog2Available.ordinal(), avail.dialog2Id); - dialogReqRows.get(2).setData(avail.dialog3Available.ordinal(), avail.dialog3Id); - dialogReqRows.get(3).setData(avail.dialog4Available.ordinal(), avail.dialog4Id); - - // Faction requirements - factionRows.get(0).setData(avail.factionAvailable.ordinal(), avail.factionStance.ordinal(), avail.factionId); - factionRows.get(1).setData(avail.faction2Available.ordinal(), avail.faction2Stance.ordinal(), avail.faction2Id); - - // Time & level - dayTimeDropdown.setSelectedIndex(avail.daytime.ordinal()); - minLevelField.setInteger(avail.minPlayerLevel); + fieldPanel.setFields(createFieldDefs()); } @Override public void saveToDialog(Dialog dialog) { - if (dialog == null || dialog.availability == null) return; - - saveAvailability(dialog.availability); - } - - private void saveAvailability(Availability avail) { - // Quest requirements - avail.questAvailable = EnumAvailabilityQuest.values()[questReqRows.get(0).getCondition()]; - avail.questId = questReqRows.get(0).getSelectedId(); - avail.quest2Available = EnumAvailabilityQuest.values()[questReqRows.get(1).getCondition()]; - avail.quest2Id = questReqRows.get(1).getSelectedId(); - avail.quest3Available = EnumAvailabilityQuest.values()[questReqRows.get(2).getCondition()]; - avail.quest3Id = questReqRows.get(2).getSelectedId(); - avail.quest4Available = EnumAvailabilityQuest.values()[questReqRows.get(3).getCondition()]; - avail.quest4Id = questReqRows.get(3).getSelectedId(); - - // Dialog requirements - avail.dialogAvailable = EnumAvailabilityDialog.values()[dialogReqRows.get(0).getCondition()]; - avail.dialogId = dialogReqRows.get(0).getSelectedId(); - avail.dialog2Available = EnumAvailabilityDialog.values()[dialogReqRows.get(1).getCondition()]; - avail.dialog2Id = dialogReqRows.get(1).getSelectedId(); - avail.dialog3Available = EnumAvailabilityDialog.values()[dialogReqRows.get(2).getCondition()]; - avail.dialog3Id = dialogReqRows.get(2).getSelectedId(); - avail.dialog4Available = EnumAvailabilityDialog.values()[dialogReqRows.get(3).getCondition()]; - avail.dialog4Id = dialogReqRows.get(3).getSelectedId(); - - // Faction requirements - avail.factionAvailable = EnumAvailabilityFactionType.values()[factionRows.get(0).getCondition()]; - avail.factionStance = noppes.npcs.constants.EnumAvailabilityFaction.values()[factionRows.get(0).getStance()]; - avail.factionId = factionRows.get(0).getSelectedId(); - avail.faction2Available = EnumAvailabilityFactionType.values()[factionRows.get(1).getCondition()]; - avail.faction2Stance = noppes.npcs.constants.EnumAvailabilityFaction.values()[factionRows.get(1).getStance()]; - avail.faction2Id = factionRows.get(1).getSelectedId(); - - // Time & level - avail.daytime = EnumDayTime.values()[dayTimeDropdown.getSelectedIndex()]; - avail.minPlayerLevel = minLevelField.getInteger(); + // No-op: immediate binding via FieldDef closures } @Override public int draw(int cx, int cw, int startY, int mouseX, int mouseY, FontRenderer fr) { - int y = startY; - int rowH = 20; - - // Quest Requirements - questReqSection.setPosition(cx, y, cw); - questReqSection.setContentHeight(rowH * 4 + 8); - if (questReqSection.draw(mouseX, mouseY)) { - int dy = questReqSection.getContentY(); - for (AvailabilityRow row : questReqRows) { - row.setBounds(cx + 4, dy, cw - 8); - row.draw(mouseX, mouseY, fr); - dy += rowH; - } - } - y += questReqSection.getTotalHeight() + componentGap; - - // Dialog Requirements - dialogReqSection.setPosition(cx, y, cw); - dialogReqSection.setContentHeight(rowH * 4 + 8); - if (dialogReqSection.draw(mouseX, mouseY)) { - int dy = dialogReqSection.getContentY(); - for (AvailabilityRow row : dialogReqRows) { - row.setBounds(cx + 4, dy, cw - 8); - row.draw(mouseX, mouseY, fr); - dy += rowH; - } - } - y += dialogReqSection.getTotalHeight() + componentGap; - - // Faction Requirements - factionReqSection.setPosition(cx, y, cw); - factionReqSection.setContentHeight(rowH * 2 + 8); - if (factionReqSection.draw(mouseX, mouseY)) { - int dy = factionReqSection.getContentY(); - for (FactionRow row : factionRows) { - row.setBounds(cx + 4, dy, cw - 8); - row.draw(mouseX, mouseY, fr); - dy += rowH; - } - } - y += factionReqSection.getTotalHeight() + componentGap; - - // Time & Level - timeSection.setPosition(cx, y, cw); - timeSection.setContentHeight(rowH + 8); - if (timeSection.draw(mouseX, mouseY)) { - int dy = timeSection.getContentY(); - fr.drawString("Time:", cx + 4, dy + 4, ModernColors.TEXT_LIGHT); - dayTimeDropdown.setBounds(cx + 35, dy, 70, 16); - dayTimeDropdown.drawBase(mouseX, mouseY); - - fr.drawString("Min Lvl:", cx + 115, dy + 4, ModernColors.TEXT_LIGHT); - minLevelField.setBounds(cx + 160, dy, 40, 16); - minLevelField.draw(mouseX, mouseY); - } - y += timeSection.getTotalHeight() + componentGap; - - return y - startY; + return fieldPanel.draw(cx, cw, startY, mouseX, mouseY, fr); } @Override public boolean mouseClicked(int mouseX, int mouseY, int button) { - if (questReqSection.mouseClicked(mouseX, mouseY, button)) return true; - if (questReqSection.isExpanded()) { - for (AvailabilityRow row : questReqRows) { - if (row.mouseClicked(mouseX, mouseY, button, parent, "quest")) { - markDirty(); - return true; - } - } - } - - if (dialogReqSection.mouseClicked(mouseX, mouseY, button)) return true; - if (dialogReqSection.isExpanded()) { - for (AvailabilityRow row : dialogReqRows) { - if (row.mouseClicked(mouseX, mouseY, button, parent, "dialog")) { - markDirty(); - return true; - } - } - } - - if (factionReqSection.mouseClicked(mouseX, mouseY, button)) return true; - if (factionReqSection.isExpanded()) { - for (FactionRow row : factionRows) { - if (row.mouseClicked(mouseX, mouseY, button, parent)) { - markDirty(); - return true; - } - } - } - - if (timeSection.mouseClicked(mouseX, mouseY, button)) return true; - if (timeSection.isExpanded()) { - // Only mark dirty if dropdown selection actually changes - int prevIndex = dayTimeDropdown.getSelectedIndex(); - if (dayTimeDropdown.mouseClicked(mouseX, mouseY, button)) { - if (dayTimeDropdown.getSelectedIndex() != prevIndex) { - markDirty(); - } - return true; - } - // Don't mark dirty on field click - only on content change - if (minLevelField.handleClick(mouseX, mouseY, button)) { return true; } - } - - return false; + return fieldPanel.mouseClicked(mouseX, mouseY, button); } @Override public boolean keyTyped(char c, int keyCode) { - if (minLevelField.keyTyped(c, keyCode)) { markDirty(); return true; } - return false; + return fieldPanel.keyTyped(c, keyCode); } @Override public void updateScreen() { - minLevelField.updateCursorCounter(); + fieldPanel.updateScreen(); } @Override public List getDropdowns() { - List dropdowns = new ArrayList<>(); - dropdowns.add(dayTimeDropdown); - for (AvailabilityRow row : questReqRows) dropdowns.add(row.getConditionDropdown()); - for (AvailabilityRow row : dialogReqRows) dropdowns.add(row.getConditionDropdown()); - for (FactionRow row : factionRows) { - dropdowns.add(row.getConditionDropdown()); - dropdowns.add(row.getStanceDropdown()); - } - return dropdowns; + return fieldPanel.getDropdowns(); + } + + @Override + public boolean handleExpandedDropdownScreenClick(int mouseX, int mouseY, int button) { + return fieldPanel.handleExpandedDropdownScreenClick(mouseX, mouseY, button); } // === Selection Callbacks === public void onQuestSelected(int slot, int questId, String questName) { + if (dialog == null || dialog.availability == null) return; + Availability a = dialog.availability; // slot 1-4 are availability quest slots - int reqSlot = slot - 1; - if (reqSlot >= 0 && reqSlot < questReqRows.size()) { - questReqRows.get(reqSlot).setSelected(questId, questName); + switch (slot) { + case 1: a.questId = questId; break; + case 2: a.quest2Id = questId; break; + case 3: a.quest3Id = questId; break; + case 4: a.quest4Id = questId; break; } markDirty(); + // Display syncs from getter on next draw } public void onDialogSelected(int slot, int dialogId, String dialogName) { - if (slot >= 0 && slot < dialogReqRows.size()) { - dialogReqRows.get(slot).setSelected(dialogId, dialogName); + if (dialog == null || dialog.availability == null) return; + Availability a = dialog.availability; + switch (slot) { + case 0: a.dialogId = dialogId; break; + case 1: a.dialog2Id = dialogId; break; + case 2: a.dialog3Id = dialogId; break; + case 3: a.dialog4Id = dialogId; break; } markDirty(); } public void onFactionSelected(int slot, int factionId, String factionName) { - if (slot >= 0 && slot < factionRows.size()) { - factionRows.get(slot).setSelected(factionId, factionName); + if (dialog == null || dialog.availability == null) return; + Availability a = dialog.availability; + switch (slot) { + case 0: a.factionId = factionId; break; + case 1: a.faction2Id = factionId; break; } markDirty(); } diff --git a/src/main/java/kamkeel/npcs/client/gui/modern/tabs/DialogEditorTab.java b/src/main/java/kamkeel/npcs/client/gui/modern/tabs/DialogEditorTab.java index fc8164bff..69c626e13 100644 --- a/src/main/java/kamkeel/npcs/client/gui/modern/tabs/DialogEditorTab.java +++ b/src/main/java/kamkeel/npcs/client/gui/modern/tabs/DialogEditorTab.java @@ -68,6 +68,14 @@ public abstract class DialogEditorTab extends Gui { this.dialog = dialog; } + /** + * Handle clicks on expanded dropdowns in screen space. + * Override in tabs that use ModernFieldPanel. + */ + public boolean handleExpandedDropdownScreenClick(int mouseX, int mouseY, int button) { + return false; + } + /** * Mark the editor as dirty (unsaved changes). */ diff --git a/src/main/java/kamkeel/npcs/client/gui/modern/tabs/DialogFeedbackTab.java b/src/main/java/kamkeel/npcs/client/gui/modern/tabs/DialogFeedbackTab.java index cb41845e9..5f95b31a4 100644 --- a/src/main/java/kamkeel/npcs/client/gui/modern/tabs/DialogFeedbackTab.java +++ b/src/main/java/kamkeel/npcs/client/gui/modern/tabs/DialogFeedbackTab.java @@ -1,292 +1,147 @@ package kamkeel.npcs.client.gui.modern.tabs; -import kamkeel.npcs.client.gui.components.*; +import kamkeel.npcs.client.gui.components.ModernDropdown; import kamkeel.npcs.client.gui.modern.DialogEditorPanel; -import noppes.npcs.client.gui.util.ModernColors; -import noppes.npcs.client.gui.util.IDialogEditorListener; import net.minecraft.client.gui.FontRenderer; +import noppes.npcs.client.gui.builder.FieldDef; +import noppes.npcs.client.gui.builder.ModernFieldPanel; +import noppes.npcs.client.gui.builder.ModernFieldPanelListener; +import noppes.npcs.client.gui.util.IDialogEditorListener; import noppes.npcs.controllers.data.Dialog; -import java.util.ArrayList; import java.util.Arrays; import java.util.List; /** * Feedback tab for the dialog editor. * Contains display options, sound settings, and color configuration. + * Uses ModernFieldPanel for declarative field rendering. */ public class DialogFeedbackTab extends DialogEditorTab { - private int componentGap = 3; - - // Display Section - private CollapsibleSection displaySection; - private ModernCheckbox hideNpcToggle; - private ModernCheckbox showWheelToggle; - private ModernCheckbox darkenScreenToggle; - private ModernCheckbox disableEscToggle; - private ModernDropdown renderTypeDropdown; - private ModernCheckbox showPrevBlocksToggle; - private ModernCheckbox showOptionLineToggle; - - // Sound Section - private CollapsibleSection soundSection; - private ModernTextField soundField; - private ModernSelectButton soundSelectBtn; - private ModernTextField textSoundField; - private ModernNumberField textPitchField; - - // Colors Section - private CollapsibleSection colorsSection; - private ModernColorButton textColorBtn; - private ModernColorButton titleColorBtn; + private ModernFieldPanel fieldPanel; public DialogFeedbackTab(DialogEditorPanel parent) { super(parent); - initComponents(); + fieldPanel = new ModernFieldPanel(); + fieldPanel.setListener(new ModernFieldPanelListener() { + @Override + public void onSelectAction(String action, int slot) { + IDialogEditorListener listener = parent.getListener(); + if (listener == null) return; + if ("sound".equals(action)) { + listener.onSoundSelectRequested(); + } + } + + @Override + public void onColorSelect(int slot, int currentColor) { + IDialogEditorListener listener = parent.getListener(); + if (listener != null) { + listener.onColorSelectRequested(slot, currentColor); + } + } + + @Override + public void onFieldChanged() { + markDirty(); + } + }); } - private void initComponents() { - // Display Section - displaySection = new CollapsibleSection(300, "Display"); - hideNpcToggle = new ModernCheckbox(301, 0, 0, false); - showWheelToggle = new ModernCheckbox(302, 0, 0, false); - darkenScreenToggle = new ModernCheckbox(303, 0, 0, true); - disableEscToggle = new ModernCheckbox(304, 0, 0, false); - renderTypeDropdown = new ModernDropdown(305, 0, 0, 80, 16); - renderTypeDropdown.setOptions(Arrays.asList("Instant", "Gradual")); - showPrevBlocksToggle = new ModernCheckbox(306, 0, 0, true); - showOptionLineToggle = new ModernCheckbox(307, 0, 0, true); + private List createFieldDefs() { + return Arrays.asList( + // Display section (expanded by default) + FieldDef.section("Display").collapsed(true), + FieldDef.boolField("Hide NPC", () -> dialog.hideNPC, v -> dialog.hideNPC = v), + FieldDef.boolField("Show Wheel", () -> dialog.showWheel, v -> dialog.showWheel = v), + FieldDef.boolField("Darken Screen", () -> dialog.darkenScreen, v -> dialog.darkenScreen = v), + FieldDef.boolField("Disable ESC", () -> dialog.disableEsc, v -> dialog.disableEsc = v), + FieldDef.stringEnumField("Render Type", new String[]{"Instant", "Gradual"}, + () -> dialog.renderGradual ? "Gradual" : "Instant", + v -> dialog.renderGradual = "Gradual".equals(v)), + FieldDef.boolField("Prev Blocks", () -> dialog.showPreviousBlocks, v -> dialog.showPreviousBlocks = v), + FieldDef.boolField("Option Line", () -> dialog.showOptionLine, v -> dialog.showOptionLine = v), - // Sound Section - soundSection = new CollapsibleSection(310, "Sound", false); - soundField = new ModernTextField(311, 0, 0, 100, 16); - soundField.setPlaceholder("Sound path..."); - soundSelectBtn = new ModernSelectButton(312, 0, 0, 50, 16, "..."); - textSoundField = new ModernTextField(313, 0, 0, 100, 16); - textSoundField.setPlaceholder("Text sound..."); - textPitchField = new ModernNumberField(314, 0, 0, 40, 16, 1.0f); - textPitchField.setFloatBounds(0.1f, 2.0f, 1.0f); + // Sound section + FieldDef.section("Sound").collapsed(true), + FieldDef.row( + FieldDef.stringField("Sound", () -> dialog.sound, v -> dialog.sound = v).placeholder("Sound path..."), + FieldDef.selectField("...", () -> "...").action("sound") + ), + FieldDef.stringField("Text Sound", () -> dialog.textSound, v -> dialog.textSound = v) + .placeholder("Text sound...") + .visibleWhen(() -> dialog.renderGradual), + FieldDef.floatField("Pitch", () -> dialog.textPitch, v -> dialog.textPitch = v) + .range(0.1f, 2.0f) + .visibleWhen(() -> dialog.renderGradual), - // Colors Section - colorsSection = new CollapsibleSection(320, "Colors", false); - textColorBtn = new ModernColorButton(321, 0, 0, 50, 16, 0xE0E0E0); - titleColorBtn = new ModernColorButton(322, 0, 0, 50, 16, 0xE0E0E0); + // Colors section + FieldDef.section("Colors").collapsed(true), + FieldDef.row( + FieldDef.colorField("Text", () -> dialog.color, v -> dialog.color = v).slot(0), + FieldDef.colorField("Title", () -> dialog.titleColor, v -> dialog.titleColor = v).slot(1) + ) + ); } @Override public void loadFromDialog(Dialog dialog) { this.dialog = dialog; if (dialog == null) return; - - hideNpcToggle.setValue(dialog.hideNPC); - showWheelToggle.setValue(dialog.showWheel); - darkenScreenToggle.setValue(dialog.darkenScreen); - disableEscToggle.setValue(dialog.disableEsc); - renderTypeDropdown.setSelectedIndex(dialog.renderGradual ? 1 : 0); - showPrevBlocksToggle.setValue(dialog.showPreviousBlocks); - showOptionLineToggle.setValue(dialog.showOptionLine); - soundField.setText(dialog.sound); - textSoundField.setText(dialog.textSound); - textPitchField.setFloat(dialog.textPitch); - textColorBtn.setColor(dialog.color); - titleColorBtn.setColor(dialog.titleColor); + fieldPanel.setFields(createFieldDefs()); } @Override public void saveToDialog(Dialog dialog) { - if (dialog == null) return; - - dialog.hideNPC = hideNpcToggle.getValue(); - dialog.showWheel = showWheelToggle.getValue(); - dialog.darkenScreen = darkenScreenToggle.getValue(); - dialog.disableEsc = disableEscToggle.getValue(); - dialog.renderGradual = renderTypeDropdown.getSelectedIndex() == 1; - dialog.showPreviousBlocks = showPrevBlocksToggle.getValue(); - dialog.showOptionLine = showOptionLineToggle.getValue(); - dialog.sound = soundField.getText(); - dialog.textSound = textSoundField.getText(); - dialog.textPitch = textPitchField.getFloat(); - dialog.color = textColorBtn.getColor(); - dialog.titleColor = titleColorBtn.getColor(); + // No-op: immediate binding via FieldDef closures } @Override public int draw(int cx, int cw, int startY, int mouseX, int mouseY, FontRenderer fr) { - int y = startY; - int toggleX = cx + cw - 36; - int rowH = 18; - - // Display Section - displaySection.setPosition(cx, y, cw); - displaySection.setContentHeight(rowH * 7 + 10); - if (displaySection.draw(mouseX, mouseY)) { - int dy = displaySection.getContentY(); - - fr.drawString("Hide NPC", cx + 4, dy + 4, ModernColors.TEXT_LIGHT); - hideNpcToggle.setPosition(toggleX, dy); - hideNpcToggle.draw(mouseX, mouseY); - dy += rowH; - - fr.drawString("Show Wheel", cx + 4, dy + 4, ModernColors.TEXT_LIGHT); - showWheelToggle.setPosition(toggleX, dy); - showWheelToggle.draw(mouseX, mouseY); - dy += rowH; - - fr.drawString("Darken Screen", cx + 4, dy + 4, ModernColors.TEXT_LIGHT); - darkenScreenToggle.setPosition(toggleX, dy); - darkenScreenToggle.draw(mouseX, mouseY); - dy += rowH; - - fr.drawString("Disable ESC", cx + 4, dy + 4, ModernColors.TEXT_LIGHT); - disableEscToggle.setPosition(toggleX, dy); - disableEscToggle.draw(mouseX, mouseY); - dy += rowH; - - fr.drawString("Render Type", cx + 4, dy + 4, ModernColors.TEXT_LIGHT); - renderTypeDropdown.setBounds(cx + cw - 80, dy, 80, 16); - renderTypeDropdown.drawBase(mouseX, mouseY); - dy += rowH; - - fr.drawString("Prev Blocks", cx + 4, dy + 4, ModernColors.TEXT_LIGHT); - showPrevBlocksToggle.setPosition(toggleX, dy); - showPrevBlocksToggle.draw(mouseX, mouseY); - dy += rowH; - - fr.drawString("Option Line", cx + 4, dy + 4, ModernColors.TEXT_LIGHT); - showOptionLineToggle.setPosition(toggleX, dy); - showOptionLineToggle.draw(mouseX, mouseY); - } - y += displaySection.getTotalHeight() + componentGap; - - // Sound Section - soundSection.setPosition(cx, y, cw); - boolean gradual = renderTypeDropdown.getSelectedIndex() == 1; - soundSection.setContentHeight(gradual ? rowH * 3 + 6 : rowH + 4); - if (soundSection.draw(mouseX, mouseY)) { - int dy = soundSection.getContentY(); - - fr.drawString("Sound", cx + 4, dy + 4, ModernColors.TEXT_LIGHT); - soundField.setBounds(cx + 45, dy, cw - 95, 16); - soundField.draw(mouseX, mouseY); - soundSelectBtn.setBounds(cx + cw - 45, dy, 45, 16); - soundSelectBtn.draw(mouseX, mouseY); - dy += rowH; - - if (gradual) { - fr.drawString("Text Sound", cx + 4, dy + 4, ModernColors.TEXT_LIGHT); - textSoundField.setBounds(cx + 65, dy, cw - 65, 16); - textSoundField.draw(mouseX, mouseY); - dy += rowH; - - fr.drawString("Pitch", cx + 4, dy + 4, ModernColors.TEXT_LIGHT); - textPitchField.setBounds(cx + 35, dy, 50, 16); - textPitchField.draw(mouseX, mouseY); - } - } - y += soundSection.getTotalHeight() + componentGap; - - // Colors Section - colorsSection.setPosition(cx, y, cw); - colorsSection.setContentHeight(rowH + 4); - if (colorsSection.draw(mouseX, mouseY)) { - int dy = colorsSection.getContentY(); - - fr.drawString("Text", cx + 4, dy + 4, ModernColors.TEXT_LIGHT); - textColorBtn.setBounds(cx + 30, dy, 50, 16); - textColorBtn.draw(mouseX, mouseY); - - fr.drawString("Title", cx + 90, dy + 4, ModernColors.TEXT_LIGHT); - titleColorBtn.setBounds(cx + 115, dy, 50, 16); - titleColorBtn.draw(mouseX, mouseY); - } - y += colorsSection.getTotalHeight() + componentGap; - - return y - startY; + return fieldPanel.draw(cx, cw, startY, mouseX, mouseY, fr); } @Override public boolean mouseClicked(int mouseX, int mouseY, int button) { - IDialogEditorListener listener = parent.getListener(); - - if (displaySection.mouseClicked(mouseX, mouseY, button)) return true; - if (displaySection.isExpanded()) { - // Toggles actually change state on click, so markDirty is correct for them - if (hideNpcToggle.mouseClicked(mouseX, mouseY, button)) { markDirty(); return true; } - if (showWheelToggle.mouseClicked(mouseX, mouseY, button)) { markDirty(); return true; } - if (darkenScreenToggle.mouseClicked(mouseX, mouseY, button)) { markDirty(); return true; } - if (disableEscToggle.mouseClicked(mouseX, mouseY, button)) { markDirty(); return true; } - // Dropdown: only mark dirty if selection changes - int prevIndex = renderTypeDropdown.getSelectedIndex(); - if (renderTypeDropdown.mouseClicked(mouseX, mouseY, button)) { - if (renderTypeDropdown.getSelectedIndex() != prevIndex) { - markDirty(); - } - return true; - } - if (showPrevBlocksToggle.mouseClicked(mouseX, mouseY, button)) { markDirty(); return true; } - if (showOptionLineToggle.mouseClicked(mouseX, mouseY, button)) { markDirty(); return true; } - } - - if (soundSection.mouseClicked(mouseX, mouseY, button)) return true; - if (soundSection.isExpanded()) { - // Don't mark dirty on click - only mark dirty when content changes (in keyTyped) - if (soundField.handleClick(mouseX, mouseY, button)) { return true; } - if (soundSelectBtn.mouseClicked(mouseX, mouseY, button)) { - if (listener != null) listener.onSoundSelectRequested(); - return true; - } - if (textSoundField.handleClick(mouseX, mouseY, button)) { return true; } - if (textPitchField.handleClick(mouseX, mouseY, button)) { return true; } - } - - if (colorsSection.mouseClicked(mouseX, mouseY, button)) return true; - if (colorsSection.isExpanded()) { - if (textColorBtn.mouseClicked(mouseX, mouseY, button)) { - if (listener != null) listener.onColorSelectRequested(0, textColorBtn.getColor()); - return true; - } - if (titleColorBtn.mouseClicked(mouseX, mouseY, button)) { - if (listener != null) listener.onColorSelectRequested(1, titleColorBtn.getColor()); - return true; - } - } - - return false; + return fieldPanel.mouseClicked(mouseX, mouseY, button); } @Override public boolean keyTyped(char c, int keyCode) { - if (soundField.keyTyped(c, keyCode)) { markDirty(); return true; } - if (textSoundField.keyTyped(c, keyCode)) { markDirty(); return true; } - if (textPitchField.keyTyped(c, keyCode)) { markDirty(); return true; } - return false; + return fieldPanel.keyTyped(c, keyCode); } @Override public void updateScreen() { - soundField.updateCursorCounter(); - textSoundField.updateCursorCounter(); - textPitchField.updateCursorCounter(); + fieldPanel.updateScreen(); } @Override public List getDropdowns() { - List dropdowns = new ArrayList<>(); - dropdowns.add(renderTypeDropdown); - return dropdowns; + return fieldPanel.getDropdowns(); + } + + @Override + public boolean handleExpandedDropdownScreenClick(int mouseX, int mouseY, int button) { + return fieldPanel.handleExpandedDropdownScreenClick(mouseX, mouseY, button); } // === Selection Callbacks === public void onSoundSelected(String soundPath) { - soundField.setText(soundPath); - markDirty(); + if (dialog != null) { + dialog.sound = soundPath; + fieldPanel.refresh(); + markDirty(); + } } public void onColorSelected(int slot, int color) { - if (slot == 0) textColorBtn.setColor(color); - else if (slot == 1) titleColorBtn.setColor(color); + if (dialog == null) return; + if (slot == 0) dialog.color = color; + else if (slot == 1) dialog.titleColor = color; markDirty(); + // Color buttons sync from data on next draw, no refresh needed } } diff --git a/src/main/java/kamkeel/npcs/client/gui/modern/tabs/DialogOptionsTab.java b/src/main/java/kamkeel/npcs/client/gui/modern/tabs/DialogOptionsTab.java index 70d6769c4..2774375f1 100644 --- a/src/main/java/kamkeel/npcs/client/gui/modern/tabs/DialogOptionsTab.java +++ b/src/main/java/kamkeel/npcs/client/gui/modern/tabs/DialogOptionsTab.java @@ -1,146 +1,190 @@ package kamkeel.npcs.client.gui.modern.tabs; -import kamkeel.npcs.client.gui.components.ModernButton; import kamkeel.npcs.client.gui.components.ModernDropdown; import kamkeel.npcs.client.gui.modern.DialogEditorPanel; -import noppes.npcs.client.gui.util.ModernColors; -import net.minecraft.client.Minecraft; import net.minecraft.client.gui.FontRenderer; +import noppes.npcs.client.gui.builder.FieldDef; +import noppes.npcs.client.gui.builder.ModernFieldPanel; +import noppes.npcs.client.gui.builder.ModernFieldPanelListener; +import noppes.npcs.client.gui.util.IDialogEditorListener; import noppes.npcs.constants.EnumOptionType; +import noppes.npcs.controllers.DialogController; import noppes.npcs.controllers.data.Dialog; import noppes.npcs.controllers.data.DialogOption; -import java.util.ArrayList; -import java.util.List; +import java.util.*; /** * Options tab for the dialog editor. - * Contains up to 6 dialog option editors. + * Contains up to 6 dialog option editors rendered via ModernFieldPanel. + * Uses FieldDef sections with dynamic titles, remove buttons, and visibility predicates. */ public class DialogOptionsTab extends DialogEditorTab { - private List optionEditors = new ArrayList<>(); - private ModernButton addOptionBtn; - private int componentGap = 3; + private static final String[] OPTION_TYPES = {"Quit", "Dialog", "Disabled", "Role", "Command"}; + + private ModernFieldPanel fieldPanel; + private Map sectionExpandState = new HashMap<>(); public DialogOptionsTab(DialogEditorPanel parent) { super(parent); - initComponents(); + fieldPanel = new ModernFieldPanel(); + fieldPanel.setListener(new ModernFieldPanelListener() { + @Override + public void onSelectAction(String action, int slot) { + IDialogEditorListener listener = parent.getListener(); + if (listener == null) return; + if ("optionDialog".equals(action)) { + listener.onOptionDialogSelectRequested(slot); + } + } + + @Override + public void onColorSelect(int slot, int currentColor) { + IDialogEditorListener listener = parent.getListener(); + if (listener != null) { + listener.onColorSelectRequested(slot, currentColor); + } + } + + @Override + public void onFieldChanged() { + markDirty(); + } + }); } - private void initComponents() { - addOptionBtn = new ModernButton(200, 0, 0, 80, 16, "+ Add Option"); + private List createFieldDefs() { + List defs = new ArrayList<>(); + + for (int slot = 0; slot < 6; slot++) { + DialogOption opt = dialog.options.get(slot); + if (opt == null || opt.optionType == EnumOptionType.Disabled) continue; + + final int s = slot; + boolean expanded = sectionExpandState.getOrDefault(slot, true); + + defs.add(FieldDef.section("Option " + s) + .collapsed(expanded) + .titleSupplier(() -> "Option " + s + ": " + dialog.options.get(s).title) + .removeAction(() -> removeOption(s))); + + defs.add(FieldDef.stringField("Title", + () -> dialog.options.get(s).title, v -> dialog.options.get(s).title = v) + .maxLength(64)); + + defs.add(FieldDef.row( + FieldDef.stringEnumField("Type", OPTION_TYPES, + () -> OPTION_TYPES[dialog.options.get(s).optionType.ordinal()], + v -> { + for (int i = 0; i < OPTION_TYPES.length; i++) { + if (OPTION_TYPES[i].equals(v)) { + dialog.options.get(s).optionType = EnumOptionType.values()[i]; + break; + } + } + }), + FieldDef.colorField("Color", + () -> dialog.options.get(s).optionColor, v -> dialog.options.get(s).optionColor = v) + .slot(100 + s) + )); + + defs.add(FieldDef.selectField("Target", + () -> { + int did = dialog.options.get(s).dialogId; + if (did < 0) return ""; + Dialog d = DialogController.Instance.dialogs.get(did); + return d != null ? "(ID: " + did + ") " + d.title : "Dialog #" + did; + }) + .action("optionDialog").slot(s) + .visibleWhen(() -> dialog.options.get(s).optionType == EnumOptionType.DialogOption)); + + defs.add(FieldDef.stringField("Cmd", + () -> dialog.options.get(s).command, v -> dialog.options.get(s).command = v) + .maxLength(32767) + .visibleWhen(() -> dialog.options.get(s).optionType == EnumOptionType.CommandBlock)); + } + + if (countActiveOptions() < 6) { + defs.add(FieldDef.actionButton("+ Add Option", this::addNewOption)); + } + + return defs; + } + + private int countActiveOptions() { + int count = 0; + for (int i = 0; i < 6; i++) { + DialogOption opt = dialog.options.get(i); + if (opt != null && opt.optionType != EnumOptionType.Disabled) count++; + } + return count; + } + + private List getActiveSlots() { + List slots = new ArrayList<>(); + for (int i = 0; i < 6; i++) { + DialogOption opt = dialog.options.get(i); + if (opt != null && opt.optionType != EnumOptionType.Disabled) slots.add(i); + } + return slots; + } + + private void saveExpandStates() { + List activeSlots = getActiveSlots(); + List sections = fieldPanel.getSections(); + for (int i = 0; i < Math.min(activeSlots.size(), sections.size()); i++) { + sectionExpandState.put(activeSlots.get(i), sections.get(i).section.isExpanded()); + } } @Override public void loadFromDialog(Dialog dialog) { this.dialog = dialog; - rebuildOptionEditors(); + if (dialog == null) return; + saveExpandStates(); + fieldPanel.setFields(createFieldDefs()); } @Override public void saveToDialog(Dialog dialog) { - if (dialog == null) return; - - for (OptionEditorV2 editor : optionEditors) { - DialogOption opt = dialog.options.get(editor.getSlot()); - if (opt != null) { - opt.title = editor.getTitleField().getText(); - int typeIdx = editor.getTypeIndex(); - opt.optionType = EnumOptionType.values()[typeIdx]; - opt.optionColor = editor.getColorBtn().getColor(); - opt.dialogId = editor.getTargetDialogId(); - opt.command = editor.getCommand(); - } - } - } - - public void rebuildOptionEditors() { - optionEditors.clear(); - - if (dialog == null) return; - - for (int i = 0; i < 6; i++) { - DialogOption opt = dialog.options.get(i); - if (opt != null && opt.optionType != EnumOptionType.Disabled) { - OptionEditorV2 editor = new OptionEditorV2(1000 + i * 20, i, opt); - optionEditors.add(editor); - } - } + // No-op: immediate binding via FieldDef closures } @Override public int draw(int cx, int cw, int startY, int mouseX, int mouseY, FontRenderer fr) { - int y = startY; - - if (optionEditors.isEmpty()) { - fr.drawString("No options defined.", cx, y, ModernColors.TEXT_DARK); - y += 14; - } else { - for (OptionEditorV2 editor : optionEditors) { - editor.setBounds(cx, y, cw); - editor.draw(mouseX, mouseY, fr); - y += editor.getHeight() + componentGap; - } - } - - // Add option button - if (optionEditors.size() < 6) { - y += 4; - addOptionBtn.xPosition = cx; - addOptionBtn.yPosition = y; - addOptionBtn.width = 100; - addOptionBtn.height = 18; - addOptionBtn.drawButton(Minecraft.getMinecraft(), mouseX, mouseY); - y += 22; - } - - return y - startY; + return fieldPanel.draw(cx, cw, startY, mouseX, mouseY, fr); } @Override public boolean mouseClicked(int mouseX, int mouseY, int button) { - for (OptionEditorV2 editor : optionEditors) { - if (editor.mouseClicked(mouseX, mouseY, button, parent)) { - markDirty(); - return true; - } - } - if (addOptionBtn.mousePressed(Minecraft.getMinecraft(), mouseX, mouseY)) { - addNewOption(); - return true; - } - return false; + return fieldPanel.mouseClicked(mouseX, mouseY, button); } @Override public boolean keyTyped(char c, int keyCode) { - for (OptionEditorV2 editor : optionEditors) { - if (editor.keyTyped(c, keyCode)) { markDirty(); return true; } - } - return false; + return fieldPanel.keyTyped(c, keyCode); } @Override public void updateScreen() { - for (OptionEditorV2 editor : optionEditors) { - editor.updateCursorCounter(); - } + fieldPanel.updateScreen(); } @Override public List getDropdowns() { - List dropdowns = new ArrayList<>(); - for (OptionEditorV2 editor : optionEditors) { - dropdowns.add(editor.getTypeDropdown()); - } - return dropdowns; + return fieldPanel.getDropdowns(); + } + + @Override + public boolean handleExpandedDropdownScreenClick(int mouseX, int mouseY, int button) { + return fieldPanel.handleExpandedDropdownScreenClick(mouseX, mouseY, button); } // === Option Management === private void addNewOption() { - if (dialog == null || optionEditors.size() >= 6) return; + if (dialog == null) return; for (int i = 0; i < 6; i++) { DialogOption opt = dialog.options.get(i); @@ -149,7 +193,8 @@ public class DialogOptionsTab extends DialogEditorTab { newOpt.title = "New Option"; newOpt.optionType = EnumOptionType.QuitOption; dialog.options.put(i, newOpt); - rebuildOptionEditors(); + saveExpandStates(); + fieldPanel.setFields(createFieldDefs()); markDirty(); return; } @@ -161,24 +206,33 @@ public class DialogOptionsTab extends DialogEditorTab { DialogOption opt = dialog.options.get(slot); if (opt != null) { opt.optionType = EnumOptionType.Disabled; - rebuildOptionEditors(); + saveExpandStates(); + sectionExpandState.remove(slot); + fieldPanel.setFields(createFieldDefs()); markDirty(); } } - // === Accessors === - - public List getOptionEditors() { - return optionEditors; - } + // === Selection Callbacks === public void onOptionDialogSelected(int optionSlot, int dialogId, String dialogName) { - for (OptionEditorV2 editor : optionEditors) { - if (editor.getSlot() == optionSlot) { - editor.setTargetDialog(dialogId, dialogName); - markDirty(); - return; - } + if (dialog == null) return; + DialogOption opt = dialog.options.get(optionSlot); + if (opt != null) { + opt.dialogId = dialogId; + fieldPanel.refresh(); + markDirty(); + } + } + + public void onColorSelected(int slot, int color) { + if (dialog == null) return; + int optionSlot = slot - 100; + DialogOption opt = dialog.options.get(optionSlot); + if (opt != null) { + opt.optionColor = color; + markDirty(); + // Color buttons sync from data on next draw } } } diff --git a/src/main/java/kamkeel/npcs/client/gui/modern/tabs/DialogSettingsTab.java b/src/main/java/kamkeel/npcs/client/gui/modern/tabs/DialogSettingsTab.java index c744faa2f..b2dc0561c 100644 --- a/src/main/java/kamkeel/npcs/client/gui/modern/tabs/DialogSettingsTab.java +++ b/src/main/java/kamkeel/npcs/client/gui/modern/tabs/DialogSettingsTab.java @@ -1,246 +1,146 @@ package kamkeel.npcs.client.gui.modern.tabs; -import kamkeel.npcs.client.gui.components.*; +import kamkeel.npcs.client.gui.components.ModernDropdown; +import kamkeel.npcs.client.gui.components.ModernTextArea; import kamkeel.npcs.client.gui.modern.DialogEditorPanel; -import noppes.npcs.client.gui.util.ModernColors; -import noppes.npcs.client.gui.util.IDialogEditorListener; -import net.minecraft.client.Minecraft; import net.minecraft.client.gui.FontRenderer; +import noppes.npcs.client.gui.builder.FieldDef; +import noppes.npcs.client.gui.builder.ModernFieldPanel; +import noppes.npcs.client.gui.builder.ModernFieldPanelListener; +import noppes.npcs.client.gui.util.IDialogEditorListener; import noppes.npcs.controllers.data.Dialog; -import java.util.ArrayList; +import java.util.Arrays; import java.util.List; /** * Settings tab for the dialog editor. * Contains quest, mail, and command configuration. + * Uses ModernFieldPanel for declarative field rendering. */ public class DialogSettingsTab extends DialogEditorTab { - private int componentGap = 3; - - // Quest Section - private CollapsibleSection questSection; - private ModernSelectButton questSelectBtn; - private ModernButton clearQuestBtn; - - // Mail Section - private CollapsibleSection mailSection; - private ModernTextField mailSubjectField; - private ModernTextField mailSenderField; - private ModernButton mailEditBtn; - private ModernButton clearMailBtn; - - // Command Section - private CollapsibleSection commandSection; - private ModernTextArea commandArea; + private ModernFieldPanel fieldPanel; public DialogSettingsTab(DialogEditorPanel parent) { super(parent); - initComponents(); + fieldPanel = new ModernFieldPanel(); + fieldPanel.setListener(new ModernFieldPanelListener() { + @Override + public void onSelectAction(String action, int slot) { + IDialogEditorListener listener = parent.getListener(); + if (listener == null) return; + switch (action) { + case "quest": + listener.onQuestSelectRequested(0); + break; + case "mail": + listener.onMailSetupRequested(); + break; + } + } + + @Override + public void onColorSelect(int slot, int currentColor) { + // No color fields in this tab + } + + @Override + public void onFieldChanged() { + markDirty(); + } + }); } - private void initComponents() { - // Quest Section - questSection = new CollapsibleSection(400, "Quest"); - questSelectBtn = new ModernSelectButton(401, 0, 0, 100, 16, "Select Quest..."); - clearQuestBtn = new ModernButton(402, 0, 0, 16, 16, "X"); + private List createFieldDefs() { + return Arrays.asList( + // Quest section (expanded by default) + FieldDef.section("Quest").collapsed(true), + FieldDef.selectField("Quest", () -> dialog.quest >= 0 ? "Quest #" + dialog.quest : "Select...") + .action("quest").slot(0) + .clearable(() -> dialog.quest = -1), - // Mail Section - mailSection = new CollapsibleSection(410, "Mail", false); - mailSubjectField = new ModernTextField(411, 0, 0, 100, 16); - mailSubjectField.setMaxLength(64); - mailSubjectField.setPlaceholder("Subject..."); - mailSenderField = new ModernTextField(412, 0, 0, 100, 16); - mailSenderField.setMaxLength(32); - mailSenderField.setPlaceholder("Sender..."); - mailEditBtn = new ModernButton(413, 0, 0, 80, 16, "Edit..."); - clearMailBtn = new ModernButton(414, 0, 0, 16, 16, "X"); + // Mail section + FieldDef.section("Mail").collapsed(true), + FieldDef.stringField("Subject", () -> dialog.mail != null ? dialog.mail.subject : "", v -> { + if (dialog.mail != null) dialog.mail.subject = v; + }).maxLength(64).placeholder("Subject..."), + FieldDef.stringField("Sender", () -> dialog.mail != null ? dialog.mail.sender : "", v -> { + if (dialog.mail != null) dialog.mail.sender = v; + }).maxLength(32).placeholder("Sender..."), + FieldDef.row( + FieldDef.selectField("Edit...", () -> "Edit...").action("mail"), + FieldDef.selectField("Clear", () -> "Clear").onAction(() -> { + if (dialog.mail != null) { + dialog.mail.subject = ""; + dialog.mail.sender = ""; + } + }) + ), - // Command Section - commandSection = new CollapsibleSection(420, "Command", false); - commandArea = new ModernTextArea(421, 0, 0, 100, 60); - commandArea.setMaxLength(32767); + // Command section + FieldDef.section("Command").collapsed(true), + FieldDef.textAreaField("", () -> dialog.command, v -> dialog.command = v) + .maxLength(32767).height(70) + ); } @Override public void loadFromDialog(Dialog dialog) { this.dialog = dialog; if (dialog == null) return; - - if (dialog.quest >= 0) { - questSelectBtn.setSelected(dialog.quest, "Quest #" + dialog.quest); - } else { - questSelectBtn.clearSelection(); - } - - // Mail inline fields - if (dialog.mail != null) { - mailSubjectField.setText(dialog.mail.subject); - mailSenderField.setText(dialog.mail.sender); - } else { - mailSubjectField.setText(""); - mailSenderField.setText(""); - } - - commandArea.setText(dialog.command); + fieldPanel.setFields(createFieldDefs()); } @Override public void saveToDialog(Dialog dialog) { - if (dialog == null) return; - - dialog.quest = questSelectBtn.getSelectedId(); - - // Mail inline fields - if (dialog.mail != null) { - dialog.mail.subject = mailSubjectField.getText(); - dialog.mail.sender = mailSenderField.getText(); - } - - dialog.command = commandArea.getText(); + // No-op: immediate binding via FieldDef closures } @Override public int draw(int cx, int cw, int startY, int mouseX, int mouseY, FontRenderer fr) { - int y = startY; - int rowH = 18; - - // Quest Section - questSection.setPosition(cx, y, cw); - questSection.setContentHeight(rowH + 4); - if (questSection.draw(mouseX, mouseY)) { - int dy = questSection.getContentY(); - questSelectBtn.setBounds(cx + 4, dy, cw - 28, 16); - questSelectBtn.draw(mouseX, mouseY); - clearQuestBtn.xPosition = cx + cw - 20; - clearQuestBtn.yPosition = dy; - clearQuestBtn.width = 16; - clearQuestBtn.height = 16; - clearQuestBtn.drawButton(Minecraft.getMinecraft(), mouseX, mouseY); - } - y += questSection.getTotalHeight() + componentGap; - - // Mail Section (inline subject, sender, edit button) - mailSection.setPosition(cx, y, cw); - mailSection.setContentHeight(rowH * 3 + 8); - if (mailSection.draw(mouseX, mouseY)) { - int dy = mailSection.getContentY(); - - // Subject row - fr.drawString("Subject:", cx + 4, dy + 4, ModernColors.TEXT_GRAY); - mailSubjectField.setBounds(cx + 55, dy, cw - 59, 16); - mailSubjectField.draw(mouseX, mouseY); - dy += rowH; - - // Sender row - fr.drawString("Sender:", cx + 4, dy + 4, ModernColors.TEXT_GRAY); - mailSenderField.setBounds(cx + 55, dy, cw - 59, 16); - mailSenderField.draw(mouseX, mouseY); - dy += rowH; - - // Edit and Clear buttons row - mailEditBtn.xPosition = cx + 4; - mailEditBtn.yPosition = dy; - mailEditBtn.width = 80; - mailEditBtn.height = 16; - mailEditBtn.drawButton(Minecraft.getMinecraft(), mouseX, mouseY); - - clearMailBtn.xPosition = cx + 88; - clearMailBtn.yPosition = dy; - clearMailBtn.width = 50; - clearMailBtn.height = 16; - clearMailBtn.displayString = "Clear"; - clearMailBtn.drawButton(Minecraft.getMinecraft(), mouseX, mouseY); - } - y += mailSection.getTotalHeight() + componentGap; - - // Command Section - commandSection.setPosition(cx, y, cw); - commandSection.setContentHeight(80); - if (commandSection.draw(mouseX, mouseY)) { - int dy = commandSection.getContentY(); - commandArea.setBounds(cx + 4, dy, cw - 8, 70); - commandArea.draw(mouseX, mouseY); - } - y += commandSection.getTotalHeight() + componentGap; - - return y - startY; + return fieldPanel.draw(cx, cw, startY, mouseX, mouseY, fr); } @Override public boolean mouseClicked(int mouseX, int mouseY, int button) { - IDialogEditorListener listener = parent.getListener(); - - if (questSection.mouseClicked(mouseX, mouseY, button)) return true; - if (questSection.isExpanded()) { - if (questSelectBtn.mouseClicked(mouseX, mouseY, button)) { - if (listener != null) listener.onQuestSelectRequested(0); - return true; - } - if (clearQuestBtn.mousePressed(Minecraft.getMinecraft(), mouseX, mouseY)) { - questSelectBtn.clearSelection(); - markDirty(); - return true; - } - } - - if (mailSection.mouseClicked(mouseX, mouseY, button)) return true; - if (mailSection.isExpanded()) { - // Don't mark dirty on click - only mark dirty when content changes (in keyTyped) - if (mailSubjectField.handleClick(mouseX, mouseY, button)) { return true; } - if (mailSenderField.handleClick(mouseX, mouseY, button)) { return true; } - if (mailEditBtn.mousePressed(Minecraft.getMinecraft(), mouseX, mouseY)) { - if (listener != null) listener.onMailSetupRequested(); - return true; - } - if (clearMailBtn.mousePressed(Minecraft.getMinecraft(), mouseX, mouseY)) { - mailSubjectField.setText(""); - mailSenderField.setText(""); - markDirty(); - return true; - } - } - - if (commandSection.mouseClicked(mouseX, mouseY, button)) return true; - if (commandSection.isExpanded()) { - // Don't mark dirty on click - only mark dirty when content changes (in keyTyped) - if (commandArea.handleClick(mouseX, mouseY, button)) { return true; } - } - - return false; + return fieldPanel.mouseClicked(mouseX, mouseY, button); } @Override public boolean keyTyped(char c, int keyCode) { - if (mailSubjectField.keyTyped(c, keyCode)) { markDirty(); return true; } - if (mailSenderField.keyTyped(c, keyCode)) { markDirty(); return true; } - if (commandArea.keyTyped(c, keyCode)) { markDirty(); return true; } - return false; + return fieldPanel.keyTyped(c, keyCode); } @Override public void updateScreen() { - mailSubjectField.updateCursorCounter(); - mailSenderField.updateCursorCounter(); - commandArea.updateCursorCounter(); + fieldPanel.updateScreen(); } @Override public List getDropdowns() { - return new ArrayList<>(); // No dropdowns in this tab + return fieldPanel.getDropdowns(); + } + + @Override + public boolean handleExpandedDropdownScreenClick(int mouseX, int mouseY, int button) { + return fieldPanel.handleExpandedDropdownScreenClick(mouseX, mouseY, button); } // === Selection Callbacks === public void onQuestSelected(int questId, String questName) { - questSelectBtn.setSelected(questId, questName); - markDirty(); + if (dialog != null) { + dialog.quest = questId; + markDirty(); + // Display syncs from getter on next draw + } } // === Accessors === public ModernTextArea getCommandArea() { - return commandArea; + List areas = fieldPanel.getTextAreas(); + return areas.isEmpty() ? null : areas.get(0); } } diff --git a/src/main/java/kamkeel/npcs/client/gui/modern/tabs/DialogTextTab.java b/src/main/java/kamkeel/npcs/client/gui/modern/tabs/DialogTextTab.java index e940e9507..8956bd72e 100644 --- a/src/main/java/kamkeel/npcs/client/gui/modern/tabs/DialogTextTab.java +++ b/src/main/java/kamkeel/npcs/client/gui/modern/tabs/DialogTextTab.java @@ -2,119 +2,102 @@ package kamkeel.npcs.client.gui.modern.tabs; import kamkeel.npcs.client.gui.components.ModernDropdown; import kamkeel.npcs.client.gui.components.ModernTextArea; -import kamkeel.npcs.client.gui.components.ModernTextField; import kamkeel.npcs.client.gui.modern.DialogEditorPanel; -import noppes.npcs.client.gui.util.ModernColors; import net.minecraft.client.gui.FontRenderer; +import noppes.npcs.client.gui.builder.FieldDef; +import noppes.npcs.client.gui.builder.ModernFieldPanel; +import noppes.npcs.client.gui.builder.ModernFieldPanelListener; import noppes.npcs.controllers.data.Dialog; -import java.util.ArrayList; +import java.util.Arrays; import java.util.List; /** * Text tab for the dialog editor. * Contains title and dialog text fields. + * Uses ModernFieldPanel for declarative field rendering. */ public class DialogTextTab extends DialogEditorTab { - private ModernTextField titleField; - private ModernTextArea textArea; + private ModernFieldPanel fieldPanel; public DialogTextTab(DialogEditorPanel parent) { super(parent); - initComponents(); + fieldPanel = new ModernFieldPanel(); + fieldPanel.setListener(new ModernFieldPanelListener() { + @Override + public void onSelectAction(String action, int slot) {} + + @Override + public void onColorSelect(int slot, int currentColor) {} + + @Override + public void onFieldChanged() { + markDirty(); + } + }); } - private void initComponents() { - titleField = new ModernTextField(100, 0, 0, 100, 16); - titleField.setMaxLength(64); - titleField.setPlaceholder("Dialog title..."); - - textArea = new ModernTextArea(101, 0, 0, 100, 80); - textArea.setMaxLength(2000); + private List createFieldDefs() { + return Arrays.asList( + FieldDef.stringField("Title", () -> dialog.title, v -> dialog.title = v) + .maxLength(64).placeholder("Dialog title..."), + FieldDef.textAreaField("Dialog Text", () -> dialog.text, v -> dialog.text = v) + .maxLength(2000).fillHeight().charCount() + ); } @Override public void loadFromDialog(Dialog dialog) { this.dialog = dialog; if (dialog == null) return; - - titleField.setText(dialog.title); - textArea.setText(dialog.text); + fieldPanel.setFields(createFieldDefs()); } @Override public void saveToDialog(Dialog dialog) { - if (dialog == null) return; - - dialog.title = titleField.getText(); - dialog.text = textArea.getText(); + // No-op: immediate binding via FieldDef closures } @Override public int draw(int cx, int cw, int startY, int mouseX, int mouseY, FontRenderer fr) { - int y = startY; - - fr.drawString("Title:", cx, y, ModernColors.TEXT_LIGHT); - y += 10; - - titleField.setBounds(cx, y, cw, 16); - titleField.draw(mouseX, mouseY); - y += 20; - - fr.drawString("Dialog Text:", cx, y, ModernColors.TEXT_LIGHT); - y += 10; - - // Calculate available height for text area - int areaH = Math.max(80, parent.getAvailableContentHeight() - 60); - textArea.setBounds(cx, y, cw, areaH); - textArea.draw(mouseX, mouseY); - y += areaH + 4; - - // Character count - String charCount = textArea.getCharacterCount() + " / " + textArea.getMaxLength(); - int countW = fr.getStringWidth(charCount); - int countColor = textArea.getCharacterCount() > 1800 ? ModernColors.ACCENT_RED : - textArea.getCharacterCount() > 1500 ? ModernColors.ACCENT_ORANGE : ModernColors.TEXT_GRAY; - fr.drawString(charCount, cx + cw - countW, y, countColor); - y += 12; - - return y - startY; + fieldPanel.setAvailableHeight(parent.getAvailableContentHeight()); + return fieldPanel.draw(cx, cw, startY, mouseX, mouseY, fr); } @Override public boolean mouseClicked(int mouseX, int mouseY, int button) { - // Don't mark dirty on click - only mark dirty when content changes (in keyTyped) - if (titleField.handleClick(mouseX, mouseY, button)) return true; - if (textArea.handleClick(mouseX, mouseY, button)) return true; - return false; + return fieldPanel.mouseClicked(mouseX, mouseY, button); } @Override public boolean keyTyped(char c, int keyCode) { - if (titleField.keyTyped(c, keyCode)) { markDirty(); return true; } - if (textArea.keyTyped(c, keyCode)) { markDirty(); return true; } - return false; + return fieldPanel.keyTyped(c, keyCode); } @Override public void updateScreen() { - titleField.updateCursorCounter(); - textArea.updateCursorCounter(); + fieldPanel.updateScreen(); } @Override public List getDropdowns() { - return new ArrayList<>(); // No dropdowns in this tab + return fieldPanel.getDropdowns(); + } + + @Override + public boolean handleExpandedDropdownScreenClick(int mouseX, int mouseY, int button) { + return fieldPanel.handleExpandedDropdownScreenClick(mouseX, mouseY, button); } // === Accessors for parent panel === public ModernTextArea getTextArea() { - return textArea; + List areas = fieldPanel.getTextAreas(); + return areas.isEmpty() ? null : areas.get(0); } public String getTitle() { - return titleField.getText(); + return dialog != null ? dialog.title : ""; } } diff --git a/src/main/java/kamkeel/npcs/client/gui/modern/tabs/FactionRow.java b/src/main/java/kamkeel/npcs/client/gui/modern/tabs/FactionRow.java deleted file mode 100644 index d2fb1ab65..000000000 --- a/src/main/java/kamkeel/npcs/client/gui/modern/tabs/FactionRow.java +++ /dev/null @@ -1,106 +0,0 @@ -package kamkeel.npcs.client.gui.modern.tabs; - -import kamkeel.npcs.client.gui.components.ModernButton; -import kamkeel.npcs.client.gui.components.ModernDropdown; -import kamkeel.npcs.client.gui.components.ModernSelectButton; -import kamkeel.npcs.client.gui.modern.DialogEditorPanel; -import noppes.npcs.client.gui.util.IDialogEditorListener; -import net.minecraft.client.Minecraft; -import net.minecraft.client.gui.FontRenderer; - -import java.util.Arrays; - -/** - * A row component for faction availability requirements. - * Contains condition dropdown, stance dropdown, select button, and clear button. - */ -public class FactionRow { - private int baseId; - private int slot; - - private ModernDropdown conditionDropdown; - private ModernDropdown stanceDropdown; - private ModernSelectButton selectBtn; - private ModernButton clearBtn; - - private int x, y, width; - - public FactionRow(int baseId, int slot) { - this.baseId = baseId; - this.slot = slot; - - conditionDropdown = new ModernDropdown(baseId, 0, 0, 55, 16); - conditionDropdown.setOptions(Arrays.asList("Always", "Is", "Is Not")); - - stanceDropdown = new ModernDropdown(baseId + 1, 0, 0, 60, 16); - stanceDropdown.setOptions(Arrays.asList("Friendly", "Neutral", "Unfriendly")); - - selectBtn = new ModernSelectButton(baseId + 2, 0, 0, 60, 16, "Faction..."); - clearBtn = new ModernButton(baseId + 3, 0, 0, 16, 16, "X"); - } - - public void setBounds(int x, int y, int width) { - this.x = x; - this.y = y; - this.width = width; - } - - public void draw(int mouseX, int mouseY, FontRenderer fr) { - conditionDropdown.setBounds(x, y, 55, 16); - conditionDropdown.drawBase(mouseX, mouseY); - - boolean enabled = conditionDropdown.getSelectedIndex() != 0; - - stanceDropdown.setEnabled(enabled); - stanceDropdown.setBounds(x + 58, y, 60, 16); - stanceDropdown.drawBase(mouseX, mouseY); - - selectBtn.setEnabled(enabled); - selectBtn.setBounds(x + 122, y, width - 142, 16); - selectBtn.draw(mouseX, mouseY); - - clearBtn.xPosition = x + width - 16; - clearBtn.yPosition = y; - clearBtn.width = 16; - clearBtn.height = 16; - clearBtn.enabled = enabled; - clearBtn.drawButton(Minecraft.getMinecraft(), mouseX, mouseY); - } - - public boolean mouseClicked(int mouseX, int mouseY, int button, DialogEditorPanel panel) { - if (conditionDropdown.mouseClicked(mouseX, mouseY, button)) return true; - if (stanceDropdown.mouseClicked(mouseX, mouseY, button)) return true; - if (selectBtn.mouseClicked(mouseX, mouseY, button)) { - IDialogEditorListener listener = panel.getListener(); - if (listener != null) { - listener.onFactionSelectRequested(slot); - } - return true; - } - if (clearBtn.mousePressed(Minecraft.getMinecraft(), mouseX, mouseY)) { - selectBtn.clearSelection(); - return true; - } - return false; - } - - public void setData(int condition, int stance, int selectedId) { - conditionDropdown.setSelectedIndex(condition); - stanceDropdown.setSelectedIndex(stance); - if (selectedId >= 0) { - selectBtn.setSelected(selectedId, "Faction #" + selectedId); - } else { - selectBtn.clearSelection(); - } - } - - public void setSelected(int id, String name) { - selectBtn.setSelected(id, name); - } - - public int getCondition() { return conditionDropdown.getSelectedIndex(); } - public int getStance() { return stanceDropdown.getSelectedIndex(); } - public int getSelectedId() { return selectBtn.getSelectedId(); } - public ModernDropdown getConditionDropdown() { return conditionDropdown; } - public ModernDropdown getStanceDropdown() { return stanceDropdown; } -} diff --git a/src/main/java/kamkeel/npcs/client/gui/modern/tabs/OptionEditorV2.java b/src/main/java/kamkeel/npcs/client/gui/modern/tabs/OptionEditorV2.java deleted file mode 100644 index 16df76131..000000000 --- a/src/main/java/kamkeel/npcs/client/gui/modern/tabs/OptionEditorV2.java +++ /dev/null @@ -1,178 +0,0 @@ -package kamkeel.npcs.client.gui.modern.tabs; - -import kamkeel.npcs.client.gui.components.*; -import kamkeel.npcs.client.gui.modern.DialogEditorPanel; -import noppes.npcs.client.gui.util.ModernColors; -import noppes.npcs.client.gui.util.IDialogEditorListener; -import net.minecraft.client.Minecraft; -import net.minecraft.client.gui.FontRenderer; -import noppes.npcs.controllers.data.DialogOption; - -import java.util.Arrays; - -/** - * Editor component for a single dialog option. - * Contains title, type dropdown, color button, target dialog selector, and command field. - */ -public class OptionEditorV2 { - private int baseId; - private int slot; - - private CollapsibleSection section; - private ModernTextField titleField; - private ModernDropdown typeDropdown; - private ModernColorButton colorBtn; - private ModernSelectButton targetDialogBtn; - private ModernTextField commandField; - private ModernButton removeBtn; - - private int targetDialogId = -1; - private int x, y, width; - - public OptionEditorV2(int baseId, int slot, DialogOption opt) { - this.baseId = baseId; - this.slot = slot; - - section = new CollapsibleSection(baseId, "Option " + slot + ": " + opt.title); - - titleField = new ModernTextField(baseId + 1, 0, 0, 100, 16); - titleField.setText(opt.title); - titleField.setMaxLength(64); - - typeDropdown = new ModernDropdown(baseId + 2, 0, 0, 80, 16); - typeDropdown.setOptions(Arrays.asList("Quit", "Dialog", "Disabled", "Role", "Command")); - typeDropdown.setSelectedIndex(opt.optionType.ordinal()); - - colorBtn = new ModernColorButton(baseId + 3, 0, 0, 50, 16, opt.optionColor); - - targetDialogBtn = new ModernSelectButton(baseId + 4, 0, 0, 80, 16, "Select..."); - if (opt.dialogId >= 0) { - targetDialogBtn.setSelected(opt.dialogId, "Dialog #" + opt.dialogId); - } - targetDialogId = opt.dialogId; - - commandField = new ModernTextField(baseId + 5, 0, 0, 100, 16); - commandField.setText(opt.command); - commandField.setMaxLength(32767); - - removeBtn = new ModernButton(baseId + 6, 0, 0, 16, 16, "X"); - } - - public void setBounds(int x, int y, int width) { - this.x = x; - this.y = y; - this.width = width; - section.setPosition(x, y, width); - } - - public int getHeight() { - return section.getTotalHeight(); - } - - public void draw(int mouseX, int mouseY, FontRenderer fr) { - int typeIdx = typeDropdown.getSelectedIndex(); - boolean isDialog = typeIdx == 1; - boolean isCommand = typeIdx == 4; - - int contentH = 56; - if (isDialog) contentH += 20; - if (isCommand) contentH += 20; - section.setContentHeight(contentH); - - // Update section title - section.setTitle("Option " + slot + ": " + titleField.getText()); - - if (section.draw(mouseX, mouseY)) { - int cx = section.getContentX(); - int cy = section.getContentY(); - int cw = section.getContentWidth(); - - // Row 1: Title + Remove - fr.drawString("Title", cx, cy + 4, ModernColors.TEXT_GRAY); - titleField.setBounds(cx + 30, cy, cw - 50, 16); - titleField.draw(mouseX, mouseY); - removeBtn.xPosition = cx + cw - 16; - removeBtn.yPosition = cy; - removeBtn.width = 16; - removeBtn.height = 16; - removeBtn.drawButton(Minecraft.getMinecraft(), mouseX, mouseY); - cy += 20; - - // Row 2: Type + Color - fr.drawString("Type", cx, cy + 4, ModernColors.TEXT_GRAY); - typeDropdown.setBounds(cx + 30, cy, 70, 16); - typeDropdown.drawBase(mouseX, mouseY); - - fr.drawString("Color", cx + 110, cy + 4, ModernColors.TEXT_GRAY); - colorBtn.setBounds(cx + 140, cy, 50, 16); - colorBtn.draw(mouseX, mouseY); - cy += 20; - - // Row 3: Target dialog (if type=Dialog) - if (isDialog) { - fr.drawString("Target", cx, cy + 4, ModernColors.TEXT_GRAY); - targetDialogBtn.setBounds(cx + 40, cy, cw - 40, 16); - targetDialogBtn.draw(mouseX, mouseY); - cy += 20; - } - - // Row 4: Command (if type=Command) - if (isCommand) { - fr.drawString("Cmd", cx, cy + 4, ModernColors.TEXT_GRAY); - commandField.setBounds(cx + 30, cy, cw - 30, 16); - commandField.draw(mouseX, mouseY); - } - } - } - - public boolean mouseClicked(int mouseX, int mouseY, int button, DialogEditorPanel panel) { - if (section.mouseClicked(mouseX, mouseY, button)) return true; - // Only handle content clicks if section is expanded - if (section.isExpanded()) { - if (titleField.handleClick(mouseX, mouseY, button)) return true; - if (typeDropdown.mouseClicked(mouseX, mouseY, button)) return true; - if (colorBtn.mouseClicked(mouseX, mouseY, button)) { - IDialogEditorListener listener = panel.getListener(); - if (listener != null) listener.onColorSelectRequested(100 + slot, colorBtn.getColor()); - return true; - } - if (targetDialogBtn.mouseClicked(mouseX, mouseY, button)) { - IDialogEditorListener listener = panel.getListener(); - if (listener != null) listener.onOptionDialogSelectRequested(slot); - return true; - } - if (commandField.handleClick(mouseX, mouseY, button)) return true; - if (removeBtn.mousePressed(Minecraft.getMinecraft(), mouseX, mouseY)) { - panel.removeOption(slot); - return true; - } - } - return false; - } - - public boolean keyTyped(char c, int keyCode) { - if (titleField.keyTyped(c, keyCode)) return true; - if (commandField.keyTyped(c, keyCode)) return true; - return false; - } - - public void updateCursorCounter() { - titleField.updateCursorCounter(); - commandField.updateCursorCounter(); - } - - public void setTargetDialog(int id, String name) { - targetDialogId = id; - targetDialogBtn.setSelected(id, name); - } - - // === Getters === - - public int getSlot() { return slot; } - public ModernDropdown getTypeDropdown() { return typeDropdown; } - public ModernTextField getTitleField() { return titleField; } - public ModernColorButton getColorBtn() { return colorBtn; } - public int getTargetDialogId() { return targetDialogId; } - public String getCommand() { return commandField.getText(); } - public int getTypeIndex() { return typeDropdown.getSelectedIndex(); } -} diff --git a/src/main/java/noppes/npcs/client/gui/builder/FieldDef.java b/src/main/java/noppes/npcs/client/gui/builder/FieldDef.java index 9263cc880..fa2e6f7e3 100644 --- a/src/main/java/noppes/npcs/client/gui/builder/FieldDef.java +++ b/src/main/java/noppes/npcs/client/gui/builder/FieldDef.java @@ -54,6 +54,39 @@ public class FieldDef { private FieldDef leftChild; private FieldDef rightChild; + // Modern field extensions + private int maxLength = 0; + private int textAreaHeight = 80; + private String placeholder = ""; + private int callbackSlot = 0; + private String callbackAction = ""; + private Runnable onActionCallback; + private boolean showCharCount = false; + + // Collapsible section support + private boolean collapsible = false; + private boolean defaultExpanded = true; + + // Action button support + private Runnable actionRunnable; + + // Section remove + dynamic title + private Runnable removeAction; + private Supplier titleSupplier; + + // Dynamic height for TEXT_AREA + private boolean fillRemainingHeight = false; + + // Availability/Faction row support + private Supplier conditionGetter; + private Consumer conditionSetter; + private Supplier stanceGetter; + private Consumer stanceSetter; + private Supplier idGetter; + private Consumer idSetter; + private Supplier displayNameGetter; + private String[] conditionValues; + private FieldDef(String label, FieldType type) { this.label = label; this.type = type; @@ -148,6 +181,88 @@ public class FieldDef { return def; } + // ═══════════════════════════════════════════════════════════════════ + // MODERN FIELD FACTORIES + // ═══════════════════════════════════════════════════════════════════ + + /** + * Multi-line text area field rendered as ModernTextArea by ModernFieldPanel. + */ + public static FieldDef textAreaField(String label, Supplier getter, Consumer setter) { + FieldDef def = new FieldDef(label, FieldType.TEXT_AREA); + def.getter = () -> getter.get(); + def.setter = v -> setter.accept((String) v); + return def; + } + + /** + * Color field rendered as ModernColorButton by ModernFieldPanel. + * Triggers onColorSelect callback via listener. + */ + public static FieldDef colorField(String label, Supplier getter, Consumer setter) { + FieldDef def = new FieldDef(label, FieldType.COLOR); + def.getter = () -> getter.get(); + def.setter = v -> setter.accept((Integer) v); + return def; + } + + /** + * External selector field rendered as ModernSelectButton by ModernFieldPanel. + * Use .action() and .slot() to identify the callback, or .onAction() for direct callback. + */ + public static FieldDef selectField(String label, Supplier displayGetter) { + FieldDef def = new FieldDef(label, FieldType.SELECT); + def.getter = () -> displayGetter.get(); + return def; + } + + /** + * Availability requirement row: condition dropdown + select button + clear button. + * Used for quest/dialog requirements with condition-based enabling. + */ + public static FieldDef availabilityRow(String label, String[] conditions, + Supplier condGetter, Consumer condSetter, + Supplier idGetter, Consumer idSetter, + Supplier displayGetter) { + FieldDef def = new FieldDef(label, FieldType.AVAILABILITY_ROW); + def.conditionValues = conditions; + def.conditionGetter = condGetter; + def.conditionSetter = condSetter; + def.idGetter = idGetter; + def.idSetter = idSetter; + def.displayNameGetter = displayGetter; + return def; + } + + /** + * Faction requirement row: condition dropdown + stance dropdown + select button + clear button. + */ + public static FieldDef factionRow(String label, + Supplier condGetter, Consumer condSetter, + Supplier stanceGetter, Consumer stanceSetter, + Supplier idGetter, Consumer idSetter, + Supplier displayGetter) { + FieldDef def = new FieldDef(label, FieldType.FACTION_ROW); + def.conditionGetter = condGetter; + def.conditionSetter = condSetter; + def.stanceGetter = stanceGetter; + def.stanceSetter = stanceSetter; + def.idGetter = idGetter; + def.idSetter = idSetter; + def.displayNameGetter = displayGetter; + return def; + } + + /** + * Action button field — renders as a clickable button that executes a Runnable. + * Used for "Add", "Delete", or other action triggers within a field list. + */ + public static FieldDef actionButton(String label, Runnable action) { + FieldDef def = new FieldDef(label, FieldType.ACTION_BUTTON); + def.actionRunnable = action; + return def; + } + // ═══════════════════════════════════════════════════════════════════ // CONVENIENCE FACTORIES (SUB_GUI wrappers) // ═══════════════════════════════════════════════════════════════════ @@ -260,6 +375,96 @@ public class FieldDef { return this; } + public FieldDef maxLength(int max) { + this.maxLength = max; + return this; + } + + public FieldDef placeholder(String text) { + this.placeholder = text; + return this; + } + + public FieldDef height(int h) { + this.textAreaHeight = h; + return this; + } + + /** + * Makes a SECTION_HEADER render as a CollapsibleSection (expanded by default). + */ + public FieldDef collapsed() { + this.collapsible = true; + this.defaultExpanded = false; + return this; + } + + /** + * Makes a SECTION_HEADER render as a CollapsibleSection with the given expand state. + */ + public FieldDef collapsed(boolean startExpanded) { + this.collapsible = true; + this.defaultExpanded = startExpanded; + return this; + } + + /** + * Callback action type for SELECT/COLOR fields (e.g. "quest", "sound", "dialog"). + */ + public FieldDef action(String action) { + this.callbackAction = action; + return this; + } + + /** + * Callback slot identifier for SELECT/COLOR fields. + */ + public FieldDef slot(int slot) { + this.callbackSlot = slot; + return this; + } + + /** + * Direct action callback for SELECT fields (alternative to action/slot). + */ + public FieldDef onAction(Runnable callback) { + this.onActionCallback = callback; + return this; + } + + /** + * Show character count below a TEXT_AREA field. + */ + public FieldDef charCount() { + this.showCharCount = true; + return this; + } + + /** + * Set dynamic title supplier for SECTION_HEADER (updated each draw). + */ + public FieldDef titleSupplier(Supplier supplier) { + this.titleSupplier = supplier; + return this; + } + + /** + * Set remove action for SECTION_HEADER (adds "X" button to header). + */ + public FieldDef removeAction(Runnable action) { + this.removeAction = action; + return this; + } + + /** + * Make TEXT_AREA fill remaining available height. + * Requires ModernFieldPanel.setAvailableHeight() to be called. + */ + public FieldDef fillHeight() { + this.fillRemainingHeight = true; + return this; + } + // ═══════════════════════════════════════════════════════════════════ // GETTERS // ═══════════════════════════════════════════════════════════════════ @@ -308,6 +513,33 @@ public class FieldDef { public FieldDef getLeftChild() { return leftChild; } public FieldDef getRightChild() { return rightChild; } + // Modern field getters + public int getMaxLength() { return maxLength; } + public int getTextAreaHeight() { return textAreaHeight; } + public String getPlaceholder() { return placeholder; } + public int getCallbackSlot() { return callbackSlot; } + public String getCallbackAction() { return callbackAction; } + public Runnable getOnActionCallback() { return onActionCallback; } + public boolean showsCharCount() { return showCharCount; } + public boolean isCollapsible() { return collapsible; } + public boolean isDefaultExpanded() { return defaultExpanded; } + + // Availability/Faction row getters + public Supplier getConditionGetter() { return conditionGetter; } + public Consumer getConditionSetter() { return conditionSetter; } + public Supplier getStanceGetter() { return stanceGetter; } + public Consumer getStanceSetter() { return stanceSetter; } + public Supplier getIdGetter() { return idGetter; } + public Consumer getIdSetter() { return idSetter; } + public Supplier getDisplayNameGetter() { return displayNameGetter; } + public String[] getConditionValues() { return conditionValues; } + + // Action button / section extensions + public Runnable getActionRunnable() { return actionRunnable; } + public Runnable getRemoveAction() { return removeAction; } + public Supplier getTitleSupplier() { return titleSupplier; } + public boolean shouldFillHeight() { return fillRemainingHeight; } + // ═══════════════════════════════════════════════════════════════════ // LIST MANIPULATION (for mod injection) // ═══════════════════════════════════════════════════════════════════ diff --git a/src/main/java/noppes/npcs/client/gui/builder/FieldType.java b/src/main/java/noppes/npcs/client/gui/builder/FieldType.java index 052e2f4cd..e13145e2e 100644 --- a/src/main/java/noppes/npcs/client/gui/builder/FieldType.java +++ b/src/main/java/noppes/npcs/client/gui/builder/FieldType.java @@ -15,5 +15,11 @@ public enum FieldType { SECTION_HEADER, LABEL, EFFECTS_LIST, - ROW + ROW, + TEXT_AREA, + COLOR, + SELECT, + AVAILABILITY_ROW, + FACTION_ROW, + ACTION_BUTTON } diff --git a/src/main/java/noppes/npcs/client/gui/builder/ModernFieldPanel.java b/src/main/java/noppes/npcs/client/gui/builder/ModernFieldPanel.java new file mode 100644 index 000000000..5f715bd39 --- /dev/null +++ b/src/main/java/noppes/npcs/client/gui/builder/ModernFieldPanel.java @@ -0,0 +1,1279 @@ +package noppes.npcs.client.gui.builder; + +import cpw.mods.fml.relauncher.Side; +import cpw.mods.fml.relauncher.SideOnly; +import kamkeel.npcs.client.gui.components.*; +import net.minecraft.client.Minecraft; +import net.minecraft.client.gui.FontRenderer; +import net.minecraft.client.gui.Gui; +import noppes.npcs.client.gui.util.ModernColors; + +import java.util.*; +import java.util.function.Consumer; +import java.util.function.Supplier; + +/** + * Modern renderer that converts a list of {@link FieldDef} definitions into Modern GUI components. + *

+ * This is the modern-component equivalent of {@link GuiFieldBuilder}. Both share {@link FieldDef} + * definitions but render to different component systems: + *

    + *
  • {@code GuiFieldBuilder} → legacy widgets ({@code GuiNpcButton}, {@code GuiScrollWindow})
  • + *
  • {@code ModernFieldPanel} → modern components ({@code ModernCheckbox}, {@code ModernDropdown})
  • + *
+ *

+ * Uses immediate data binding via FieldDef closures — changes write directly to the data model. + *

+ * Supports collapsible sections, conditional visibility, two-column rows, and custom field types + * (AVAILABILITY_ROW, FACTION_ROW). + */ +@SideOnly(Side.CLIENT) +public class ModernFieldPanel extends Gui { + + // === Layout constants === + protected int rowHeight = 18; + protected int sectionGap = 3; + protected int indent = 4; + + // === Field definitions === + protected List fields = new ArrayList<>(); + + // === Built components === + // Entries correspond 1:1 with fields list (null for non-renderable types like SECTION_HEADER) + protected Map entries = new LinkedHashMap<>(); + + // === Section tracking === + // Ordered list of sections (SECTION_HEADER defs that are collapsible) + protected List sections = new ArrayList<>(); + + // === All dropdowns for z-order === + protected List allDropdowns = new ArrayList<>(); + + // === Listener === + protected ModernFieldPanelListener listener; + + // === ID counter === + protected int nextId = 2000; + + // === Available height for fillHeight calculation === + protected int availableHeight = -1; + protected int drawStartY; + + // ═══════════════════════════════════════════════════════════════════ + // SETUP + // ═══════════════════════════════════════════════════════════════════ + + /** + * Set the field definitions and build all Modern components. + * Call this when the data object changes (e.g., new dialog selected). + */ + public void setFields(List fields) { + this.fields = fields != null ? fields : new ArrayList<>(); + buildComponents(); + } + + public void setListener(ModernFieldPanelListener listener) { + this.listener = listener; + } + + /** + * Set available height for fillHeight() text areas. + */ + public void setAvailableHeight(int height) { + this.availableHeight = height; + } + + /** + * Get ordered list of collapsible sections (for preserving expand state across rebuilds). + */ + public List getSections() { + return sections; + } + + // ═══════════════════════════════════════════════════════════════════ + // COMPONENT BUILDING + // ═══════════════════════════════════════════════════════════════════ + + protected void buildComponents() { + entries.clear(); + sections.clear(); + allDropdowns.clear(); + nextId = 2000; + + SectionInfo currentSection = null; + + for (FieldDef def : fields) { + if (def.getType() == FieldType.SECTION_HEADER) { + if (def.isCollapsible()) { + String sectionTitle = def.getTitleSupplier() != null + ? def.getTitleSupplier().get() : def.getLabel(); + CollapsibleSection cs = new CollapsibleSection(nextId++, sectionTitle, def.isDefaultExpanded()); + if (def.getRemoveAction() != null) { + cs.setOnRemove(def.getRemoveAction()); + } + SectionInfo info = new SectionInfo(def, cs); + sections.add(info); + currentSection = info; + } else { + currentSection = null; + } + entries.put(def, null); + continue; + } + + if (def.getType() == FieldType.ROW) { + FieldEntry leftEntry = buildEntry(def.getLeftChild()); + FieldEntry rightEntry = buildEntry(def.getRightChild()); + FieldEntry rowEntry = new FieldEntry(def); + rowEntry.leftChild = leftEntry; + rowEntry.rightChild = rightEntry; + entries.put(def, rowEntry); + if (currentSection != null) currentSection.fields.add(def); + continue; + } + + FieldEntry entry = buildEntry(def); + entries.put(def, entry); + if (currentSection != null) currentSection.fields.add(def); + } + } + + protected FieldEntry buildEntry(FieldDef def) { + if (def == null) return null; + FieldEntry entry = new FieldEntry(def); + + switch (def.getType()) { + case STRING: { + ModernTextField tf = new ModernTextField(nextId++, 0, 0, 100, 16); + if (def.getMaxLength() > 0) tf.setMaxLength(def.getMaxLength()); + if (def.getPlaceholder() != null && !def.getPlaceholder().isEmpty()) + tf.setPlaceholder(def.getPlaceholder()); + String val = def.getValue() != null ? def.getValue().toString() : ""; + tf.setText(val); + entry.textField = tf; + break; + } + case INT: { + int val = def.getValue() instanceof Number ? ((Number) def.getValue()).intValue() : 0; + ModernNumberField nf = new ModernNumberField(nextId++, 0, 0, 50, 16, val); + if (def.hasRange()) nf.setIntegerBounds((int) def.getMin(), (int) def.getMax(), val); + entry.textField = nf; + break; + } + case FLOAT: { + float val = def.getValue() instanceof Number ? ((Number) def.getValue()).floatValue() : 0f; + ModernNumberField nf = new ModernNumberField(nextId++, 0, 0, 50, 16, val); + if (def.hasRange()) nf.setFloatBounds(def.getMin(), def.getMax(), val); + entry.textField = nf; + break; + } + case BOOLEAN: { + boolean val = def.getValue() instanceof Boolean ? (Boolean) def.getValue() : false; + ModernCheckbox cb = new ModernCheckbox(nextId++, 0, 0, val); + entry.checkbox = cb; + break; + } + case ENUM: { + Class> ec = def.getEnumClass(); + if (ec != null) { + Enum[] constants = ec.getEnumConstants(); + List names = new ArrayList<>(); + for (Enum c : constants) names.add(c.toString()); + ModernDropdown dd = new ModernDropdown(nextId++, 0, 0, 80, 16); + dd.setOptions(names); + int selected = def.getValue() instanceof Enum ? ((Enum) def.getValue()).ordinal() : 0; + dd.setSelectedIndex(selected); + entry.dropdown = dd; + allDropdowns.add(dd); + } + break; + } + case STRING_ENUM: { + String[] values = def.getStringEnumValues(); + if (values != null && values.length > 0) { + ModernDropdown dd = new ModernDropdown(nextId++, 0, 0, 80, 16); + dd.setOptions(Arrays.asList(values)); + String curVal = def.getStringEnumValue(); + int selected = 0; + for (int i = 0; i < values.length; i++) { + if (values[i].equals(curVal)) { selected = i; break; } + } + dd.setSelectedIndex(selected); + entry.dropdown = dd; + allDropdowns.add(dd); + } + break; + } + case TEXT_AREA: { + ModernTextArea ta = new ModernTextArea(nextId++, 0, 0, 100, def.getTextAreaHeight()); + if (def.getMaxLength() > 0) ta.setMaxStringLength(def.getMaxLength()); + String val = def.getValue() != null ? def.getValue().toString() : ""; + ta.setText(val); + entry.textArea = ta; + break; + } + case COLOR: { + int val = def.getValue() instanceof Number ? ((Number) def.getValue()).intValue() : 0xFFFFFF; + ModernColorButton cb = new ModernColorButton(nextId++, 0, 0, 50, 16, val); + entry.colorButton = cb; + break; + } + case SELECT: { + String display = def.getValue() != null ? def.getValue().toString() : "Select..."; + ModernSelectButton sb = new ModernSelectButton(nextId++, 0, 0, 100, 16, display); + sb.setDisplayText(display); + entry.selectButton = sb; + break; + } + case AVAILABILITY_ROW: { + buildAvailabilityRow(entry, def); + break; + } + case FACTION_ROW: { + buildFactionRow(entry, def); + break; + } + case ACTION_BUTTON: { + ModernButton btn = new ModernButton(nextId++, 0, 0, 80, 18, def.getLabel()); + entry.actionButton = btn; + break; + } + default: + break; + } + + return entry; + } + + protected void buildAvailabilityRow(FieldEntry entry, FieldDef def) { + String[] conditions = def.getConditionValues(); + if (conditions == null) conditions = new String[]{"Always"}; + + ModernDropdown condDd = new ModernDropdown(nextId++, 0, 0, 70, 16); + condDd.setOptions(Arrays.asList(conditions)); + int condIdx = def.getConditionGetter() != null ? def.getConditionGetter().get() : 0; + condDd.setSelectedIndex(condIdx); + entry.dropdown = condDd; + allDropdowns.add(condDd); + + String display = def.getDisplayNameGetter() != null ? def.getDisplayNameGetter().get() : "Select..."; + ModernSelectButton sb = new ModernSelectButton(nextId++, 0, 0, 80, 16); + sb.setDisplayText(display != null && !display.isEmpty() ? display : ""); + entry.selectButton = sb; + + ModernButton clearBtn = new ModernButton(nextId++, 0, 0, 16, 16, "X"); + entry.clearButton = clearBtn; + } + + protected void buildFactionRow(FieldEntry entry, FieldDef def) { + String[] factionConds = {"Always", "Is", "Is Not"}; + ModernDropdown condDd = new ModernDropdown(nextId++, 0, 0, 55, 16); + condDd.setOptions(Arrays.asList(factionConds)); + int condIdx = def.getConditionGetter() != null ? def.getConditionGetter().get() : 0; + condDd.setSelectedIndex(condIdx); + entry.dropdown = condDd; + allDropdowns.add(condDd); + + String[] stances = {"Friendly", "Neutral", "Unfriendly"}; + ModernDropdown stanceDd = new ModernDropdown(nextId++, 0, 0, 60, 16); + stanceDd.setOptions(Arrays.asList(stances)); + int stanceIdx = def.getStanceGetter() != null ? def.getStanceGetter().get() : 0; + stanceDd.setSelectedIndex(stanceIdx); + entry.stanceDropdown = stanceDd; + allDropdowns.add(stanceDd); + + String display = def.getDisplayNameGetter() != null ? def.getDisplayNameGetter().get() : ""; + ModernSelectButton sb = new ModernSelectButton(nextId++, 0, 0, 60, 16); + sb.setDisplayText(display != null && !display.isEmpty() ? display : ""); + entry.selectButton = sb; + + ModernButton clearBtn = new ModernButton(nextId++, 0, 0, 16, 16, "X"); + entry.clearButton = clearBtn; + } + + // ═══════════════════════════════════════════════════════════════════ + // DRAWING + // ═══════════════════════════════════════════════════════════════════ + + /** + * Draw all fields. Returns total content height. + * + * @param cx Content X position + * @param cw Content width + * @param startY Starting Y position + * @param mouseX Mouse X (scroll-adjusted) + * @param mouseY Mouse Y (scroll-adjusted) + * @param fr FontRenderer + * @return Total height drawn + */ + public int draw(int cx, int cw, int startY, int mouseX, int mouseY, FontRenderer fr) { + int y = startY; + drawStartY = startY; + SectionInfo currentSection = null; + int sectionIdx = 0; + + for (FieldDef def : fields) { + // Section header + if (def.getType() == FieldType.SECTION_HEADER) { + if (def.isCollapsible() && sectionIdx < sections.size()) { + currentSection = sections.get(sectionIdx++); + CollapsibleSection cs = currentSection.section; + // Sync dynamic title + if (def.getTitleSupplier() != null) { + cs.setTitle(def.getTitleSupplier().get()); + } + cs.setPosition(cx, y, cw); + + // Calculate content height for this section + int contentH = calculateSectionContentHeight(currentSection, cw, fr); + cs.setContentHeight(contentH); + + if (cs.draw(mouseX, mouseY)) { + // Content is visible - draw fields inside + int dy = cs.getContentY(); + dy = drawSectionFields(currentSection, cx, cw, dy, mouseX, mouseY, fr); + } + y += cs.getTotalHeight() + sectionGap; + } else { + // Non-collapsible section header (plain label) + currentSection = null; + y += 3; + fr.drawString(def.getLabel(), cx + indent, y + 2, 0xFFFF55); + y += 15; + } + continue; + } + + // Skip fields that belong to a collapsible section (drawn by the section) + if (currentSection != null && currentSection.fields.contains(def)) { + continue; + } + + // Top-level field (not in any section) + if (!def.isVisible()) continue; + + y = drawField(def, cx, cw, y, mouseX, mouseY, fr); + } + + return y - startY; + } + + protected int drawSectionFields(SectionInfo section, int cx, int cw, int y, int mouseX, int mouseY, FontRenderer fr) { + for (FieldDef def : section.fields) { + if (!def.isVisible()) continue; + y = drawField(def, cx, cw, y, mouseX, mouseY, fr); + } + return y; + } + + protected int drawField(FieldDef def, int cx, int cw, int y, int mouseX, int mouseY, FontRenderer fr) { + FieldEntry entry = entries.get(def); + if (entry == null) return y; + + switch (def.getType()) { + case ROW: + return drawRow(def, entry, cx, cw, y, mouseX, mouseY, fr); + case BOOLEAN: + return drawBooleanField(def, entry, cx, cw, y, mouseX, mouseY, fr); + case STRING: + return drawTextField(def, entry, cx, cw, y, mouseX, mouseY, fr); + case INT: + case FLOAT: + return drawNumberField(def, entry, cx, cw, y, mouseX, mouseY, fr); + case ENUM: + case STRING_ENUM: + return drawDropdownField(def, entry, cx, cw, y, mouseX, mouseY, fr); + case TEXT_AREA: + return drawTextAreaField(def, entry, cx, cw, y, mouseX, mouseY, fr); + case COLOR: + return drawColorField(def, entry, cx, cw, y, mouseX, mouseY, fr); + case SELECT: + return drawSelectField(def, entry, cx, cw, y, mouseX, mouseY, fr); + case AVAILABILITY_ROW: + return drawAvailabilityRow(def, entry, cx, cw, y, mouseX, mouseY, fr); + case FACTION_ROW: + return drawFactionRow(def, entry, cx, cw, y, mouseX, mouseY, fr); + case LABEL: + return drawLabelField(def, cx, cw, y, fr); + case ACTION_BUTTON: + return drawActionButton(def, entry, cx, cw, y, mouseX, mouseY, fr); + default: { + int customH = drawCustomField(def, entry, cx, cw, y, mouseX, mouseY, fr); + return customH >= 0 ? customH : y; + } + } + } + + protected int drawBooleanField(FieldDef def, FieldEntry entry, int cx, int cw, int y, int mouseX, int mouseY, FontRenderer fr) { + if (entry.checkbox == null) return y; + // Sync value from data + boolean val = def.getValue() instanceof Boolean ? (Boolean) def.getValue() : false; + entry.checkbox.setValue(val); + entry.checkbox.setEnabled(def.isEnabled()); + + // Label on left, checkbox on right + fr.drawString(def.getLabel(), cx + indent, y + 4, ModernColors.TEXT_LIGHT); + int checkX = cx + cw - entry.checkbox.getSize() - 4; + entry.checkbox.setPosition(checkX, y); + entry.checkbox.draw(mouseX, mouseY); + return y + rowHeight; + } + + protected int drawTextField(FieldDef def, FieldEntry entry, int cx, int cw, int y, int mouseX, int mouseY, FontRenderer fr) { + if (entry.textField == null) return y; + entry.textField.setEnabled(def.isEnabled()); + + boolean hasLabel = def.getLabel() != null && !def.getLabel().isEmpty(); + if (hasLabel) { + fr.drawString(def.getLabel(), cx + indent, y + 4, ModernColors.TEXT_LIGHT); + int labelW = fr.getStringWidth(def.getLabel()) + 8; + entry.textField.setBounds(cx + indent + labelW, y, cw - indent - labelW - 4, 16); + } else { + entry.textField.setBounds(cx + indent, y, cw - indent * 2, 16); + } + entry.textField.draw(mouseX, mouseY); + return y + rowHeight; + } + + protected int drawNumberField(FieldDef def, FieldEntry entry, int cx, int cw, int y, int mouseX, int mouseY, FontRenderer fr) { + if (entry.textField == null) return y; + entry.textField.setEnabled(def.isEnabled()); + + boolean hasLabel = def.getLabel() != null && !def.getLabel().isEmpty(); + if (hasLabel) { + fr.drawString(def.getLabel(), cx + indent, y + 4, ModernColors.TEXT_LIGHT); + int labelW = fr.getStringWidth(def.getLabel()) + 8; + entry.textField.setBounds(cx + indent + labelW, y, 50, 16); + } else { + entry.textField.setBounds(cx + indent, y, 50, 16); + } + entry.textField.draw(mouseX, mouseY); + return y + rowHeight; + } + + protected int drawDropdownField(FieldDef def, FieldEntry entry, int cx, int cw, int y, int mouseX, int mouseY, FontRenderer fr) { + if (entry.dropdown == null) return y; + entry.dropdown.setEnabled(def.isEnabled()); + + // Sync dropdown selection from data + syncDropdownFromData(def, entry.dropdown); + + boolean hasLabel = def.getLabel() != null && !def.getLabel().isEmpty(); + if (hasLabel) { + fr.drawString(def.getLabel(), cx + indent, y + 4, ModernColors.TEXT_LIGHT); + entry.dropdown.setBounds(cx + cw - 80, y, 80, 16); + } else { + entry.dropdown.setBounds(cx + indent, y, cw - indent * 2, 16); + } + entry.dropdown.drawBase(mouseX, mouseY); + return y + rowHeight; + } + + protected int drawTextAreaField(FieldDef def, FieldEntry entry, int cx, int cw, int y, int mouseX, int mouseY, FontRenderer fr) { + if (entry.textArea == null) return y; + entry.textArea.setEnabled(def.isEnabled()); + + boolean hasLabel = def.getLabel() != null && !def.getLabel().isEmpty(); + if (hasLabel) { + fr.drawString(def.getLabel(), cx + indent, y, ModernColors.TEXT_LIGHT); + y += 10; + } + + int areaH = def.getTextAreaHeight(); + if (def.shouldFillHeight() && availableHeight > 0) { + int consumed = y - drawStartY; // height used by fields above + int overhead = (hasLabel ? 10 : 0) + (def.showsCharCount() ? 16 : 4); + areaH = Math.max(80, availableHeight - consumed - overhead); + } + + entry.textArea.setBounds(cx + indent, y, cw - indent * 2, areaH); + entry.textArea.draw(mouseX, mouseY); + y += areaH + 4; + + // Character count + if (def.showsCharCount() && def.getMaxLength() > 0) { + String charCount = entry.textArea.getCharacterCount() + " / " + entry.textArea.getMaxLength(); + int countW = fr.getStringWidth(charCount); + int limit = def.getMaxLength(); + int count = entry.textArea.getCharacterCount(); + int countColor = count > (int)(limit * 0.9) ? ModernColors.ACCENT_RED : + count > (int)(limit * 0.75) ? ModernColors.ACCENT_ORANGE : ModernColors.TEXT_GRAY; + fr.drawString(charCount, cx + cw - countW - indent, y, countColor); + y += 12; + } + + return y; + } + + protected int drawColorField(FieldDef def, FieldEntry entry, int cx, int cw, int y, int mouseX, int mouseY, FontRenderer fr) { + if (entry.colorButton == null) return y; + // Sync color from data + int val = def.getValue() instanceof Number ? ((Number) def.getValue()).intValue() : 0xFFFFFF; + entry.colorButton.setColor(val); + entry.colorButton.setEnabled(def.isEnabled()); + + boolean hasLabel = def.getLabel() != null && !def.getLabel().isEmpty(); + if (hasLabel) { + fr.drawString(def.getLabel(), cx + indent, y + 4, ModernColors.TEXT_LIGHT); + int labelW = fr.getStringWidth(def.getLabel()) + 8; + entry.colorButton.setBounds(cx + indent + labelW, y, 50, 16); + } else { + entry.colorButton.setBounds(cx + indent, y, 50, 16); + } + entry.colorButton.draw(mouseX, mouseY); + return y + rowHeight; + } + + protected int drawSelectField(FieldDef def, FieldEntry entry, int cx, int cw, int y, int mouseX, int mouseY, FontRenderer fr) { + if (entry.selectButton == null) return y; + entry.selectButton.setEnabled(def.isEnabled()); + + // Sync display from data + String display = def.getValue() != null ? def.getValue().toString() : ""; + entry.selectButton.setDisplayText(display); + + boolean hasLabel = def.getLabel() != null && !def.getLabel().isEmpty(); + int fieldX, fieldW; + if (hasLabel) { + fr.drawString(def.getLabel(), cx + indent, y + 4, ModernColors.TEXT_LIGHT); + int labelW = fr.getStringWidth(def.getLabel()) + 8; + fieldX = cx + indent + labelW; + fieldW = cw - indent - labelW - 4; + } else { + fieldX = cx + indent; + fieldW = cw - indent * 2; + } + + // Account for clear button + if (def.hasClearAction()) { + entry.selectButton.setBounds(fieldX, y, fieldW - 20, 16); + entry.selectButton.draw(mouseX, mouseY); + // Draw clear button + if (entry.clearButton == null) { + entry.clearButton = new ModernButton(nextId++, 0, 0, 16, 16, "X"); + } + entry.clearButton.xPosition = fieldX + fieldW - 16; + entry.clearButton.yPosition = y; + entry.clearButton.width = 16; + entry.clearButton.height = 16; + entry.clearButton.enabled = def.isEnabled(); + entry.clearButton.drawButton(Minecraft.getMinecraft(), mouseX, mouseY); + } else { + entry.selectButton.setBounds(fieldX, y, fieldW, 16); + entry.selectButton.draw(mouseX, mouseY); + } + return y + rowHeight; + } + + protected int drawAvailabilityRow(FieldDef def, FieldEntry entry, int cx, int cw, int y, int mouseX, int mouseY, FontRenderer fr) { + if (entry.dropdown == null || entry.selectButton == null) return y; + + // Sync condition from data + int condIdx = def.getConditionGetter() != null ? def.getConditionGetter().get() : 0; + entry.dropdown.setSelectedIndex(condIdx); + boolean enabled = condIdx != 0; + + // Sync display name + String display = def.getDisplayNameGetter() != null ? def.getDisplayNameGetter().get() : ""; + entry.selectButton.setDisplayText(display != null && !display.isEmpty() ? display : ""); + + int ix = cx + indent; + int iw = cw - indent - 4; + + // Condition dropdown + entry.dropdown.setBounds(ix, y, 70, 16); + entry.dropdown.drawBase(mouseX, mouseY); + + // Select button + entry.selectButton.setEnabled(enabled); + entry.selectButton.setBounds(ix + 74, y, iw - 94, 16); + entry.selectButton.draw(mouseX, mouseY); + + // Clear button + if (entry.clearButton != null) { + entry.clearButton.xPosition = ix + iw - 16; + entry.clearButton.yPosition = y; + entry.clearButton.width = 16; + entry.clearButton.height = 16; + entry.clearButton.enabled = enabled; + entry.clearButton.drawButton(Minecraft.getMinecraft(), mouseX, mouseY); + } + + return y + rowHeight + 2; + } + + protected int drawFactionRow(FieldDef def, FieldEntry entry, int cx, int cw, int y, int mouseX, int mouseY, FontRenderer fr) { + if (entry.dropdown == null || entry.selectButton == null) return y; + + // Sync condition from data + int condIdx = def.getConditionGetter() != null ? def.getConditionGetter().get() : 0; + entry.dropdown.setSelectedIndex(condIdx); + boolean enabled = condIdx != 0; + + // Sync stance from data + if (entry.stanceDropdown != null) { + int stanceIdx = def.getStanceGetter() != null ? def.getStanceGetter().get() : 0; + entry.stanceDropdown.setSelectedIndex(stanceIdx); + entry.stanceDropdown.setEnabled(enabled); + } + + // Sync display name + String display = def.getDisplayNameGetter() != null ? def.getDisplayNameGetter().get() : ""; + entry.selectButton.setDisplayText(display != null && !display.isEmpty() ? display : ""); + + int ix = cx + indent; + int iw = cw - indent - 4; + + // Condition dropdown + entry.dropdown.setBounds(ix, y, 55, 16); + entry.dropdown.drawBase(mouseX, mouseY); + + // Stance dropdown + if (entry.stanceDropdown != null) { + entry.stanceDropdown.setBounds(ix + 58, y, 60, 16); + entry.stanceDropdown.drawBase(mouseX, mouseY); + } + + // Select button + entry.selectButton.setEnabled(enabled); + entry.selectButton.setBounds(ix + 122, y, iw - 142, 16); + entry.selectButton.draw(mouseX, mouseY); + + // Clear button + if (entry.clearButton != null) { + entry.clearButton.xPosition = ix + iw - 16; + entry.clearButton.yPosition = y; + entry.clearButton.width = 16; + entry.clearButton.height = 16; + entry.clearButton.enabled = enabled; + entry.clearButton.drawButton(Minecraft.getMinecraft(), mouseX, mouseY); + } + + return y + rowHeight + 2; + } + + protected int drawLabelField(FieldDef def, int cx, int cw, int y, FontRenderer fr) { + String text = def.getValue() != null ? def.getValue().toString() : ""; + boolean hasLabel = def.getLabel() != null && !def.getLabel().isEmpty(); + if (hasLabel) { + fr.drawString(def.getLabel(), cx + indent, y + 4, ModernColors.TEXT_LIGHT); + int labelW = fr.getStringWidth(def.getLabel()) + 8; + fr.drawString(text, cx + indent + labelW, y + 4, ModernColors.TEXT_GRAY); + } else { + fr.drawString(text, cx + indent, y + 4, ModernColors.TEXT_GRAY); + } + return y + rowHeight; + } + + protected int drawRow(FieldDef def, FieldEntry entry, int cx, int cw, int y, int mouseX, int mouseY, FontRenderer fr) { + FieldDef left = def.getLeftChild(); + FieldDef right = def.getRightChild(); + boolean leftVis = left != null && left.isVisible(); + boolean rightVis = right != null && right.isVisible(); + + if (leftVis && rightVis) { + int halfW = cw / 2; + drawField(left, cx, halfW - 2, y, mouseX, mouseY, fr); + drawField(right, cx + halfW + 2, halfW - 2, y, mouseX, mouseY, fr); + } else if (leftVis) { + drawField(left, cx, cw, y, mouseX, mouseY, fr); + } else if (rightVis) { + drawField(right, cx, cw, y, mouseX, mouseY, fr); + } + + if (leftVis || rightVis) return y + rowHeight; + return y; + } + + protected int drawActionButton(FieldDef def, FieldEntry entry, int cx, int cw, int y, int mouseX, int mouseY, FontRenderer fr) { + if (entry.actionButton == null) return y; + entry.actionButton.enabled = def.isEnabled(); + entry.actionButton.displayString = def.getLabel(); + + int btnW = Math.min(100, cw - indent * 2); + entry.actionButton.xPosition = cx + indent; + entry.actionButton.yPosition = y; + entry.actionButton.width = btnW; + entry.actionButton.height = 18; + entry.actionButton.drawButton(Minecraft.getMinecraft(), mouseX, mouseY); + return y + 22; + } + + protected void syncDropdownFromData(FieldDef def, ModernDropdown dd) { + if (def.getType() == FieldType.STRING_ENUM) { + String curVal = def.getStringEnumValue(); + String[] values = def.getStringEnumValues(); + if (values != null && curVal != null) { + for (int i = 0; i < values.length; i++) { + if (values[i].equals(curVal)) { dd.setSelectedIndex(i); break; } + } + } + } else if (def.getType() == FieldType.ENUM) { + int idx = def.getValue() instanceof Enum ? ((Enum) def.getValue()).ordinal() : 0; + dd.setSelectedIndex(idx); + } + } + + protected int calculateSectionContentHeight(SectionInfo section, int cw, FontRenderer fr) { + int h = 0; + for (FieldDef def : section.fields) { + if (!def.isVisible()) continue; + h += getFieldHeight(def, cw, fr); + } + return h + 4; // padding + } + + protected int getFieldHeight(FieldDef def, int cw, FontRenderer fr) { + switch (def.getType()) { + case TEXT_AREA: { + int h = def.getTextAreaHeight() + 4; + if (def.getLabel() != null && !def.getLabel().isEmpty()) h += 10; + if (def.showsCharCount()) h += 12; + return h; + } + case AVAILABILITY_ROW: + case FACTION_ROW: + return rowHeight + 2; + case ROW: + return rowHeight; + default: + return rowHeight; + } + } + + // ═══════════════════════════════════════════════════════════════════ + // EVENT HANDLING + // ═══════════════════════════════════════════════════════════════════ + + /** + * Handle mouse click. Returns true if handled. + */ + public boolean mouseClicked(int mouseX, int mouseY, int button) { + // Check section header clicks + for (SectionInfo section : sections) { + if (section.section.mouseClicked(mouseX, mouseY, button)) { + return true; + } + } + + // Check fields + for (Map.Entry e : entries.entrySet()) { + FieldDef def = e.getKey(); + FieldEntry entry = e.getValue(); + if (entry == null || !def.isVisible()) continue; + + // Skip fields in collapsed sections + if (isInCollapsedSection(def)) continue; + + if (handleFieldClick(def, entry, mouseX, mouseY, button)) { + return true; + } + } + return false; + } + + @SuppressWarnings({"unchecked", "rawtypes"}) + protected boolean handleFieldClick(FieldDef def, FieldEntry entry, int mouseX, int mouseY, int button) { + switch (def.getType()) { + case ROW: { + if (entry.leftChild != null && def.getLeftChild() != null && def.getLeftChild().isVisible()) { + if (handleFieldClick(def.getLeftChild(), entry.leftChild, mouseX, mouseY, button)) return true; + } + if (entry.rightChild != null && def.getRightChild() != null && def.getRightChild().isVisible()) { + if (handleFieldClick(def.getRightChild(), entry.rightChild, mouseX, mouseY, button)) return true; + } + return false; + } + case BOOLEAN: { + if (entry.checkbox != null && entry.checkbox.mouseClicked(mouseX, mouseY, button)) { + def.setValue(entry.checkbox.getValue()); + notifyChanged(); + return true; + } + return false; + } + case STRING: { + if (entry.textField != null && entry.textField.handleClick(mouseX, mouseY, button)) return true; + return false; + } + case INT: + case FLOAT: { + if (entry.textField != null && entry.textField.handleClick(mouseX, mouseY, button)) return true; + return false; + } + case ENUM: { + if (entry.dropdown != null) { + int prev = entry.dropdown.getSelectedIndex(); + if (entry.dropdown.mouseClicked(mouseX, mouseY, button)) { + if (entry.dropdown.getSelectedIndex() != prev) { + Class> ec = def.getEnumClass(); + if (ec != null) { + Enum[] constants = ec.getEnumConstants(); + int idx = entry.dropdown.getSelectedIndex(); + if (idx >= 0 && idx < constants.length) { + def.setValue(constants[idx]); + } + } + notifyChanged(); + } + return true; + } + } + return false; + } + case STRING_ENUM: { + if (entry.dropdown != null) { + int prev = entry.dropdown.getSelectedIndex(); + if (entry.dropdown.mouseClicked(mouseX, mouseY, button)) { + if (entry.dropdown.getSelectedIndex() != prev) { + String[] values = def.getStringEnumValues(); + int idx = entry.dropdown.getSelectedIndex(); + if (values != null && idx >= 0 && idx < values.length) { + def.setStringEnumValue(values[idx]); + } + notifyChanged(); + } + return true; + } + } + return false; + } + case TEXT_AREA: { + if (entry.textArea != null && entry.textArea.handleClick(mouseX, mouseY, button)) return true; + return false; + } + case COLOR: { + if (entry.colorButton != null && entry.colorButton.mouseClicked(mouseX, mouseY, button)) { + if (listener != null) { + int currentColor = def.getValue() instanceof Number ? ((Number) def.getValue()).intValue() : 0xFFFFFF; + listener.onColorSelect(def.getCallbackSlot(), currentColor); + } + return true; + } + return false; + } + case SELECT: { + // Handle clear button first + if (def.hasClearAction() && entry.clearButton != null) { + if (entry.clearButton.mousePressed(Minecraft.getMinecraft(), mouseX, mouseY)) { + def.getClearAction().run(); + notifyChanged(); + return true; + } + } + if (entry.selectButton != null && entry.selectButton.mouseClicked(mouseX, mouseY, button)) { + if (def.getOnActionCallback() != null) { + def.getOnActionCallback().run(); + notifyChanged(); + } else if (listener != null && !def.getCallbackAction().isEmpty()) { + listener.onSelectAction(def.getCallbackAction(), def.getCallbackSlot()); + } + return true; + } + return false; + } + case AVAILABILITY_ROW: { + return handleAvailabilityRowClick(def, entry, mouseX, mouseY, button); + } + case FACTION_ROW: { + return handleFactionRowClick(def, entry, mouseX, mouseY, button); + } + case ACTION_BUTTON: { + if (entry.actionButton != null && entry.actionButton.mousePressed(Minecraft.getMinecraft(), mouseX, mouseY)) { + if (def.getActionRunnable() != null) def.getActionRunnable().run(); + notifyChanged(); + return true; + } + return false; + } + default: + return handleCustomFieldClick(def, entry, mouseX, mouseY, button); + } + } + + protected boolean handleAvailabilityRowClick(FieldDef def, FieldEntry entry, int mouseX, int mouseY, int button) { + if (entry.dropdown != null) { + int prev = entry.dropdown.getSelectedIndex(); + if (entry.dropdown.mouseClicked(mouseX, mouseY, button)) { + if (entry.dropdown.getSelectedIndex() != prev) { + if (def.getConditionSetter() != null) + def.getConditionSetter().accept(entry.dropdown.getSelectedIndex()); + notifyChanged(); + } + return true; + } + } + if (entry.selectButton != null && entry.selectButton.mouseClicked(mouseX, mouseY, button)) { + if (listener != null && !def.getCallbackAction().isEmpty()) { + listener.onSelectAction(def.getCallbackAction(), def.getCallbackSlot()); + } + return true; + } + if (entry.clearButton != null && entry.clearButton.mousePressed(Minecraft.getMinecraft(), mouseX, mouseY)) { + if (def.hasClearAction()) def.getClearAction().run(); + notifyChanged(); + return true; + } + return false; + } + + protected boolean handleFactionRowClick(FieldDef def, FieldEntry entry, int mouseX, int mouseY, int button) { + if (entry.dropdown != null) { + int prev = entry.dropdown.getSelectedIndex(); + if (entry.dropdown.mouseClicked(mouseX, mouseY, button)) { + if (entry.dropdown.getSelectedIndex() != prev) { + if (def.getConditionSetter() != null) + def.getConditionSetter().accept(entry.dropdown.getSelectedIndex()); + notifyChanged(); + } + return true; + } + } + if (entry.stanceDropdown != null) { + int prev = entry.stanceDropdown.getSelectedIndex(); + if (entry.stanceDropdown.mouseClicked(mouseX, mouseY, button)) { + if (entry.stanceDropdown.getSelectedIndex() != prev) { + if (def.getStanceSetter() != null) + def.getStanceSetter().accept(entry.stanceDropdown.getSelectedIndex()); + notifyChanged(); + } + return true; + } + } + if (entry.selectButton != null && entry.selectButton.mouseClicked(mouseX, mouseY, button)) { + if (listener != null && !def.getCallbackAction().isEmpty()) { + listener.onSelectAction(def.getCallbackAction(), def.getCallbackSlot()); + } + return true; + } + if (entry.clearButton != null && entry.clearButton.mousePressed(Minecraft.getMinecraft(), mouseX, mouseY)) { + if (def.hasClearAction()) def.getClearAction().run(); + notifyChanged(); + return true; + } + return false; + } + + /** + * Handle key typed. Returns true if handled. + */ + public boolean keyTyped(char c, int keyCode) { + for (Map.Entry e : entries.entrySet()) { + FieldDef def = e.getKey(); + FieldEntry entry = e.getValue(); + if (entry == null || !def.isVisible()) continue; + if (isInCollapsedSection(def)) continue; + + if (handleFieldKeyTyped(def, entry, c, keyCode)) return true; + } + return false; + } + + protected boolean handleFieldKeyTyped(FieldDef def, FieldEntry entry, char c, int keyCode) { + switch (def.getType()) { + case ROW: { + if (entry.leftChild != null && def.getLeftChild() != null && def.getLeftChild().isVisible()) { + if (handleFieldKeyTyped(def.getLeftChild(), entry.leftChild, c, keyCode)) return true; + } + if (entry.rightChild != null && def.getRightChild() != null && def.getRightChild().isVisible()) { + if (handleFieldKeyTyped(def.getRightChild(), entry.rightChild, c, keyCode)) return true; + } + return false; + } + case STRING: { + if (entry.textField != null && entry.textField.keyTyped(c, keyCode)) { + def.setValue(entry.textField.getText()); + notifyChanged(); + return true; + } + return false; + } + case INT: { + if (entry.textField != null && entry.textField.keyTyped(c, keyCode)) { + try { + def.setValue(Integer.parseInt(entry.textField.getText())); + } catch (NumberFormatException ignored) {} + notifyChanged(); + return true; + } + return false; + } + case FLOAT: { + if (entry.textField != null && entry.textField.keyTyped(c, keyCode)) { + try { + def.setValue(Float.parseFloat(entry.textField.getText())); + } catch (NumberFormatException ignored) {} + notifyChanged(); + return true; + } + return false; + } + case TEXT_AREA: { + if (entry.textArea != null && entry.textArea.keyTyped(c, keyCode)) { + def.setValue(entry.textArea.getText()); + notifyChanged(); + return true; + } + return false; + } + default: + return handleCustomFieldKeyTyped(def, entry, c, keyCode); + } + } + + /** + * Update cursor blink state for text fields. + */ + public void updateScreen() { + for (Map.Entry e : entries.entrySet()) { + FieldEntry entry = e.getValue(); + if (entry == null) continue; + updateEntryScreen(entry); + } + } + + protected void updateEntryScreen(FieldEntry entry) { + if (entry.textField != null) entry.textField.updateCursorCounter(); + if (entry.textArea != null) entry.textArea.updateCursorCounter(); + if (entry.leftChild != null) updateEntryScreen(entry.leftChild); + if (entry.rightChild != null) updateEntryScreen(entry.rightChild); + } + + /** + * Get all dropdowns for z-order rendering by parent. + */ + public List getDropdowns() { + return allDropdowns; + } + + /** + * Get all text areas for mouseReleased/mouseDragged delegation. + */ + public List getTextAreas() { + List areas = new ArrayList<>(); + for (FieldEntry entry : entries.values()) { + if (entry != null) collectTextAreas(entry, areas); + } + return areas; + } + + protected void collectTextAreas(FieldEntry entry, List areas) { + if (entry.textArea != null) areas.add(entry.textArea); + if (entry.leftChild != null) collectTextAreas(entry.leftChild, areas); + if (entry.rightChild != null) collectTextAreas(entry.rightChild, areas); + } + + // ═══════════════════════════════════════════════════════════════════ + // HELPERS + // ═══════════════════════════════════════════════════════════════════ + + // ═══════════════════════════════════════════════════════════════════ + // EXTENSIBILITY HOOKS + // ═══════════════════════════════════════════════════════════════════ + + /** + * Override to draw a custom field type. Return total Y after drawing, or -1 if not handled. + */ + protected int drawCustomField(FieldDef def, FieldEntry entry, int cx, int cw, int y, int mouseX, int mouseY, FontRenderer fr) { + return -1; + } + + /** + * Override to handle clicks for a custom field type. Return true if handled. + */ + protected boolean handleCustomFieldClick(FieldDef def, FieldEntry entry, int mouseX, int mouseY, int button) { + return false; + } + + /** + * Override to handle key events for a custom field type. Return true if handled. + */ + protected boolean handleCustomFieldKeyTyped(FieldDef def, FieldEntry entry, char c, int keyCode) { + return false; + } + + /** + * Handle clicks on expanded dropdowns in SCREEN space (no scroll offset). + * Writes the selected value back to the FieldDef data model. + */ + public boolean handleExpandedDropdownScreenClick(int mouseX, int mouseY, int button) { + for (Map.Entry e : entries.entrySet()) { + FieldDef def = e.getKey(); + FieldEntry entry = e.getValue(); + if (entry == null) continue; + if (tryDropdownScreenClick(def, entry, mouseX, mouseY, button)) return true; + } + return false; + } + + @SuppressWarnings({"unchecked", "rawtypes"}) + protected boolean tryDropdownScreenClick(FieldDef def, FieldEntry entry, int mouseX, int mouseY, int button) { + // Check main dropdown + if (entry.dropdown != null && entry.dropdown.isExpanded()) { + int prev = entry.dropdown.getSelectedIndex(); + if (entry.dropdown.mouseClickedScreenSpace(mouseX, mouseY, button)) { + if (entry.dropdown.getSelectedIndex() != prev) { + writeDropdownToData(def, entry.dropdown); + notifyChanged(); + } + return true; + } + } + // Check stance dropdown (faction rows) + if (entry.stanceDropdown != null && entry.stanceDropdown.isExpanded()) { + int prev = entry.stanceDropdown.getSelectedIndex(); + if (entry.stanceDropdown.mouseClickedScreenSpace(mouseX, mouseY, button)) { + if (entry.stanceDropdown.getSelectedIndex() != prev) { + if (def.getStanceSetter() != null) + def.getStanceSetter().accept(entry.stanceDropdown.getSelectedIndex()); + notifyChanged(); + } + return true; + } + } + // Check ROW children + if (def.getType() == FieldType.ROW) { + if (entry.leftChild != null && def.getLeftChild() != null) + if (tryDropdownScreenClick(def.getLeftChild(), entry.leftChild, mouseX, mouseY, button)) return true; + if (entry.rightChild != null && def.getRightChild() != null) + if (tryDropdownScreenClick(def.getRightChild(), entry.rightChild, mouseX, mouseY, button)) return true; + } + return false; + } + + @SuppressWarnings({"unchecked", "rawtypes"}) + protected void writeDropdownToData(FieldDef def, ModernDropdown dd) { + int idx = dd.getSelectedIndex(); + switch (def.getType()) { + case STRING_ENUM: { + String[] vals = def.getStringEnumValues(); + if (vals != null && idx >= 0 && idx < vals.length) + def.setStringEnumValue(vals[idx]); + break; + } + case ENUM: { + Class> ec = def.getEnumClass(); + if (ec != null) { + Enum[] constants = ec.getEnumConstants(); + if (idx >= 0 && idx < constants.length) + def.setValue(constants[idx]); + } + break; + } + case AVAILABILITY_ROW: + case FACTION_ROW: { + if (def.getConditionSetter() != null) + def.getConditionSetter().accept(idx); + break; + } + } + } + + protected boolean isInCollapsedSection(FieldDef def) { + for (SectionInfo section : sections) { + if (section.fields.contains(def) && !section.section.isExpanded()) { + return true; + } + } + return false; + } + + protected void notifyChanged() { + if (listener != null) listener.onFieldChanged(); + } + + /** + * Reload component values from data. Call after external changes (e.g., selector callbacks). + */ + public void refresh() { + for (Map.Entry e : entries.entrySet()) { + FieldDef def = e.getKey(); + FieldEntry entry = e.getValue(); + if (entry == null) continue; + refreshEntry(def, entry); + } + } + + protected void refreshEntry(FieldDef def, FieldEntry entry) { + switch (def.getType()) { + case STRING: + if (entry.textField != null) { + String val = def.getValue() != null ? def.getValue().toString() : ""; + entry.textField.setText(val); + } + break; + case INT: + if (entry.textField != null) { + int ival = def.getValue() instanceof Number ? ((Number) def.getValue()).intValue() : 0; + entry.textField.setText(String.valueOf(ival)); + } + break; + case FLOAT: + if (entry.textField != null) { + float fval = def.getValue() instanceof Number ? ((Number) def.getValue()).floatValue() : 0f; + entry.textField.setText(String.valueOf(fval)); + } + break; + case TEXT_AREA: + if (entry.textArea != null) { + String tval = def.getValue() != null ? def.getValue().toString() : ""; + entry.textArea.setText(tval); + } + break; + case ROW: + if (entry.leftChild != null && def.getLeftChild() != null) refreshEntry(def.getLeftChild(), entry.leftChild); + if (entry.rightChild != null && def.getRightChild() != null) refreshEntry(def.getRightChild(), entry.rightChild); + break; + default: + // BOOLEAN, ENUM, STRING_ENUM, COLOR, SELECT, AVAILABILITY_ROW, FACTION_ROW + // are synced from data every draw() call + break; + } + } + + // ═══════════════════════════════════════════════════════════════════ + // INNER CLASSES + // ═══════════════════════════════════════════════════════════════════ + + /** + * Holds the Modern component(s) created for a single FieldDef. + */ + protected static class FieldEntry { + final FieldDef def; + + // One of these is populated based on FieldType + ModernTextField textField; + ModernTextArea textArea; + ModernCheckbox checkbox; + ModernDropdown dropdown; + ModernColorButton colorButton; + ModernSelectButton selectButton; + ModernButton clearButton; + ModernButton actionButton; + + // Faction row extra + ModernDropdown stanceDropdown; + + // Row children + FieldEntry leftChild; + FieldEntry rightChild; + + FieldEntry(FieldDef def) { + this.def = def; + } + } + + /** + * Groups a CollapsibleSection with its child FieldDefs. + */ + public static class SectionInfo { + public final FieldDef headerDef; + public final CollapsibleSection section; + public final List fields = new ArrayList<>(); + + SectionInfo(FieldDef headerDef, CollapsibleSection section) { + this.headerDef = headerDef; + this.section = section; + } + } +} diff --git a/src/main/java/noppes/npcs/client/gui/builder/ModernFieldPanelListener.java b/src/main/java/noppes/npcs/client/gui/builder/ModernFieldPanelListener.java new file mode 100644 index 000000000..cc941494f --- /dev/null +++ b/src/main/java/noppes/npcs/client/gui/builder/ModernFieldPanelListener.java @@ -0,0 +1,31 @@ +package noppes.npcs.client.gui.builder; + +import cpw.mods.fml.relauncher.Side; +import cpw.mods.fml.relauncher.SideOnly; + +/** + * Callback interface for ModernFieldPanel events. + * Implemented by the parent GUI to handle external selection and dirty tracking. + */ +@SideOnly(Side.CLIENT) +public interface ModernFieldPanelListener { + + /** + * Called when an external selector action is requested (quest, dialog, faction, sound, mail). + * @param action The action type (e.g. "quest", "dialog", "faction", "sound", "mail") + * @param slot The slot identifier for the request + */ + void onSelectAction(String action, int slot); + + /** + * Called when a color picker is requested. + * @param slot The color slot identifier + * @param currentColor The current color value + */ + void onColorSelect(int slot, int currentColor); + + /** + * Called when any field value changes (for dirty tracking). + */ + void onFieldChanged(); +} diff --git a/src/main/java/noppes/npcs/client/gui/builder/ScrollableFieldPanel.java b/src/main/java/noppes/npcs/client/gui/builder/ScrollableFieldPanel.java new file mode 100644 index 000000000..959304934 --- /dev/null +++ b/src/main/java/noppes/npcs/client/gui/builder/ScrollableFieldPanel.java @@ -0,0 +1,201 @@ +package noppes.npcs.client.gui.builder; + +import cpw.mods.fml.relauncher.Side; +import cpw.mods.fml.relauncher.SideOnly; +import kamkeel.npcs.client.gui.components.ModernDropdown; +import kamkeel.npcs.client.gui.components.ModernTextArea; +import kamkeel.npcs.client.gui.components.ScrollPanel; +import net.minecraft.client.Minecraft; +import net.minecraft.client.gui.FontRenderer; + +import java.util.List; + +/** + * Self-contained scrollable field panel that wraps {@link ScrollPanel} + {@link ModernFieldPanel}. + *

+ * Handles scissor clipping, scroll coordinate translation, dropdown z-order, + * and text area mouse delegation automatically. + *

+ * Usage: + *

+ * ScrollableFieldPanel panel = new ScrollableFieldPanel(x, y, width, height);
+ * panel.setFields(fieldDefs);
+ * panel.setListener(listener);
+ *
+ * // In draw:
+ * panel.draw(mouseX, mouseY);
+ *
+ * // Events:
+ * panel.mouseClicked(mouseX, mouseY, button);
+ * panel.keyTyped(c, keyCode);
+ * panel.mouseScrolled(delta);
+ * panel.mouseDragged(mouseX, mouseY);
+ * panel.mouseReleased(mouseX, mouseY);
+ * panel.updateScreen();
+ * 
+ */ +@SideOnly(Side.CLIENT) +public class ScrollableFieldPanel { + + protected ScrollPanel scrollPanel; + protected ModernFieldPanel fieldPanel; + + // Layout + protected int x, y, width, height; + protected int padding = 4; + + public ScrollableFieldPanel(int x, int y, int width, int height) { + this.x = x; + this.y = y; + this.width = width; + this.height = height; + this.scrollPanel = new ScrollPanel(x, y, width, height); + this.scrollPanel.setBackgroundColor(0); // Transparent + this.fieldPanel = new ModernFieldPanel(); + } + + // === Setup === + + public void setFields(List fields) { + fieldPanel.setFields(fields); + } + + public void setListener(ModernFieldPanelListener listener) { + fieldPanel.setListener(listener); + } + + public void setBounds(int x, int y, int width, int height) { + this.x = x; + this.y = y; + this.width = width; + this.height = height; + scrollPanel.setBounds(x, y, width, height); + } + + public void resetScroll() { + scrollPanel.resetScroll(); + } + + /** + * Set available height for fillHeight() text areas. + */ + public void setAvailableHeight(int height) { + fieldPanel.setAvailableHeight(height); + } + + // === Drawing === + + public void draw(int mouseX, int mouseY) { + FontRenderer fr = Minecraft.getMinecraft().fontRenderer; + + // Sync dropdown screen positions BEFORE scissor + updateDropdownScreenPositions(); + + // Begin scissor + scroll translation + scrollPanel.beginDraw(); + + // Draw fields + int contentX = x + padding; + int contentW = width - padding * 2 - getScrollbarWidth(); + int startY = y + padding; + int contentMouseY = scrollPanel.toContentY(mouseY); + + int contentHeight = fieldPanel.draw(contentX, contentW, startY, mouseX, contentMouseY, fr); + scrollPanel.setContentHeight(contentHeight + padding); + + // End scissor, draw scrollbar + scrollPanel.endDraw(mouseX, mouseY); + + // Draw expanded dropdowns in screen space (above scissor) + drawExpandedDropdownsScreenSpace(mouseX, mouseY); + } + + protected void updateDropdownScreenPositions() { + for (ModernDropdown dd : fieldPanel.getDropdowns()) { + int screenY = scrollPanel.toScreenY(dd.getY()); + dd.setScreenPosition(dd.getX(), screenY); + } + } + + protected void drawExpandedDropdownsScreenSpace(int mouseX, int mouseY) { + for (ModernDropdown dd : fieldPanel.getDropdowns()) { + if (dd.isExpanded()) { + dd.drawOverlayScreenSpace(mouseX, mouseY); + } + } + } + + protected int getScrollbarWidth() { + return scrollPanel.needsScrollbar() ? 6 : 0; + } + + // === Event Handling === + + public boolean mouseClicked(int mouseX, int mouseY, int button) { + // Check expanded dropdowns in SCREEN space first - with data write-back + if (fieldPanel.handleExpandedDropdownScreenClick(mouseX, mouseY, button)) { + return true; + } + + // Check scrollbar + if (scrollPanel.mouseClicked(mouseX, mouseY, button)) { + return true; + } + + // Delegate to field panel with scroll-adjusted Y + int adjMouseY = scrollPanel.toContentY(mouseY); + return fieldPanel.mouseClicked(mouseX, adjMouseY, button); + } + + public boolean keyTyped(char c, int keyCode) { + return fieldPanel.keyTyped(c, keyCode); + } + + public void mouseScrolled(int delta) { + scrollPanel.mouseScrolled(delta); + } + + public void mouseDragged(int mouseX, int mouseY) { + scrollPanel.mouseDragged(mouseX, mouseY); + for (ModernTextArea ta : fieldPanel.getTextAreas()) { + ta.mouseDragged(mouseX, mouseY); + } + } + + public void mouseReleased(int mouseX, int mouseY) { + scrollPanel.mouseReleased(mouseX, mouseY); + for (ModernTextArea ta : fieldPanel.getTextAreas()) { + ta.mouseReleased(mouseX, mouseY); + } + } + + public void updateScreen() { + fieldPanel.updateScreen(); + } + + // === Accessors === + + public ModernFieldPanel getFieldPanel() { + return fieldPanel; + } + + public ScrollPanel getScrollPanel() { + return scrollPanel; + } + + public List getDropdowns() { + return fieldPanel.getDropdowns(); + } + + public List getTextAreas() { + return fieldPanel.getTextAreas(); + } + + public void refresh() { + fieldPanel.refresh(); + } + + public boolean isInside(int mouseX, int mouseY) { + return scrollPanel.isInside(mouseX, mouseY); + } +} diff --git a/src/main/java/noppes/npcs/client/gui/global/GuiDialogTree.java b/src/main/java/noppes/npcs/client/gui/global/GuiDialogTree.java index d76a9a98e..e12d74063 100644 --- a/src/main/java/noppes/npcs/client/gui/global/GuiDialogTree.java +++ b/src/main/java/noppes/npcs/client/gui/global/GuiDialogTree.java @@ -962,7 +962,8 @@ public class GuiDialogTree extends GuiModernScreen implements IDialogEditorParen @Override protected void drawOverlay(int mouseX, int mouseY, float partialTicks) { // Diagram (draw first so legend bar + buttons appear on top) - if (diagram != null) { + // Skip when SubGui is open so SubGui appears on top + if (diagram != null && !hasSubGui()) { diagram.drawDiagram(mouseX, mouseY); } @@ -977,9 +978,8 @@ public class GuiDialogTree extends GuiModernScreen implements IDialogEditorParen handleTop + rightDividerLineHeight, 0xFF707070); } - // Right panel - either modern editor or text (custom font) - // Skip when SubGui is open so SubGui appears on top (z-order fix) - if (rightPanelVisible && !hasSubGui()) { + // Right panel - always draw (SubGui re-draws on top below) + if (rightPanelVisible) { if (editorPanel != null && editMode) { editorPanel.draw(mouseX, mouseY); } else if (!rightPanelTexts.isEmpty()) { @@ -1012,6 +1012,11 @@ public class GuiDialogTree extends GuiModernScreen implements IDialogEditorParen drawRect(msgX - 4, contentY + 2, msgX + msgW + 4, contentY + 14, 0xC0000000); fontRendererObj.drawString(msg, msgX, contentY + 4, 0x55FF55); } + + // Re-draw SubGui on top of overlay content (z-order fix) + if (hasSubGui()) { + getSubGui().drawScreen(mouseX, mouseY, partialTicks); + } } private void drawLegendBar() { @@ -1582,7 +1587,7 @@ public class GuiDialogTree extends GuiModernScreen implements IDialogEditorParen super.handleMouseInput(); // Handle scroll wheel for editor panel int scroll = org.lwjgl.input.Mouse.getDWheel(); - if (scroll != 0 && editorPanel != null && editMode) { + if (scroll != 0 && editorPanel != null && editMode && !hasSubGui()) { int mouseX = org.lwjgl.input.Mouse.getX() * width / mc.displayWidth; int mouseY = height - org.lwjgl.input.Mouse.getY() * height / mc.displayHeight - 1; if (editorPanel.isInside(mouseX, mouseY)) { diff --git a/src/main/java/noppes/npcs/client/gui/util/GuiNpcTextArea.java b/src/main/java/noppes/npcs/client/gui/util/GuiNpcTextArea.java index f131544ac..6a3abfae9 100644 --- a/src/main/java/noppes/npcs/client/gui/util/GuiNpcTextArea.java +++ b/src/main/java/noppes/npcs/client/gui/util/GuiNpcTextArea.java @@ -47,6 +47,7 @@ public class GuiNpcTextArea extends GuiNpcTextField { this.height = h; this.xPosition = x; this.yPosition = y; + syncGuiTextFieldBounds(w, h); updateLineList(); } diff --git a/src/main/java/noppes/npcs/client/gui/util/GuiNpcTextField.java b/src/main/java/noppes/npcs/client/gui/util/GuiNpcTextField.java index 436b47bb5..99a7ef686 100644 --- a/src/main/java/noppes/npcs/client/gui/util/GuiNpcTextField.java +++ b/src/main/java/noppes/npcs/client/gui/util/GuiNpcTextField.java @@ -361,4 +361,13 @@ public class GuiNpcTextField extends GuiTextField { GL11.glEnable(GL11.GL_ALPHA_TEST); GL11.glEnable(GL11.GL_TEXTURE_2D); } + + /** + * Sync GuiTextField.width/height for subclasses that shadow these fields. + * Since GuiNpcTextField does NOT shadow width/height, this.width writes to GuiTextField.width. + */ + protected void syncGuiTextFieldBounds(int w, int h) { + this.width = w; + this.height = h; + } }