mirror of
https://github.com/KAMKEEL/CustomNPC-Plus.git
synced 2026-11-19 16:29:39 +00:00
Dialog System
This commit is contained in:
1 parent
e010408257
commit
fff0bfd63b
19 files changed
+2359
-1220
No files matched your search
@@ -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);
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -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<String> 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; }
|
||||
}
|
||||
@@ -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<AvailabilityRow> questReqRows = new ArrayList<>();
|
||||
|
||||
// Dialog Requirements Section
|
||||
private CollapsibleSection dialogReqSection;
|
||||
private List<AvailabilityRow> dialogReqRows = new ArrayList<>();
|
||||
|
||||
// Faction Requirements Section
|
||||
private CollapsibleSection factionReqSection;
|
||||
private List<FactionRow> 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<FieldDef> createFieldDefs() {
|
||||
Availability a = dialog.availability;
|
||||
List<FieldDef> 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<ModernDropdown> getDropdowns() {
|
||||
List<ModernDropdown> 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();
|
||||
}
|
||||
|
||||
@@ -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).
|
||||
*/
|
||||
|
||||
@@ -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<FieldDef> 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<ModernDropdown> getDropdowns() {
|
||||
List<ModernDropdown> 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
|
||||
}
|
||||
}
|
||||
@@ -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<OptionEditorV2> 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<Integer, Boolean> 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<FieldDef> createFieldDefs() {
|
||||
List<FieldDef> 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<Integer> getActiveSlots() {
|
||||
List<Integer> 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<Integer> activeSlots = getActiveSlots();
|
||||
List<ModernFieldPanel.SectionInfo> 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<ModernDropdown> getDropdowns() {
|
||||
List<ModernDropdown> 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<OptionEditorV2> 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
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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<FieldDef> 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<ModernDropdown> 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<ModernTextArea> areas = fieldPanel.getTextAreas();
|
||||
return areas.isEmpty() ? null : areas.get(0);
|
||||
}
|
||||
}
|
||||
@@ -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<FieldDef> 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<ModernDropdown> 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<ModernTextArea> areas = fieldPanel.getTextAreas();
|
||||
return areas.isEmpty() ? null : areas.get(0);
|
||||
}
|
||||
|
||||
public String getTitle() {
|
||||
return titleField.getText();
|
||||
return dialog != null ? dialog.title : "";
|
||||
}
|
||||
}
|
||||
@@ -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; }
|
||||
}
|
||||
@@ -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(); }
|
||||
}
|
||||
@@ -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<String> titleSupplier;
|
||||
|
||||
// Dynamic height for TEXT_AREA
|
||||
private boolean fillRemainingHeight = false;
|
||||
|
||||
// Availability/Faction row support
|
||||
private Supplier<Integer> conditionGetter;
|
||||
private Consumer<Integer> conditionSetter;
|
||||
private Supplier<Integer> stanceGetter;
|
||||
private Consumer<Integer> stanceSetter;
|
||||
private Supplier<Integer> idGetter;
|
||||
private Consumer<Integer> idSetter;
|
||||
private Supplier<String> 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<String> getter, Consumer<String> 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<Integer> getter, Consumer<Integer> 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<String> 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<Integer> condGetter, Consumer<Integer> condSetter,
|
||||
Supplier<Integer> idGetter, Consumer<Integer> idSetter,
|
||||
Supplier<String> 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<Integer> condGetter, Consumer<Integer> condSetter,
|
||||
Supplier<Integer> stanceGetter, Consumer<Integer> stanceSetter,
|
||||
Supplier<Integer> idGetter, Consumer<Integer> idSetter,
|
||||
Supplier<String> 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<String> 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<Integer> getConditionGetter() { return conditionGetter; }
|
||||
public Consumer<Integer> getConditionSetter() { return conditionSetter; }
|
||||
public Supplier<Integer> getStanceGetter() { return stanceGetter; }
|
||||
public Consumer<Integer> getStanceSetter() { return stanceSetter; }
|
||||
public Supplier<Integer> getIdGetter() { return idGetter; }
|
||||
public Consumer<Integer> getIdSetter() { return idSetter; }
|
||||
public Supplier<String> getDisplayNameGetter() { return displayNameGetter; }
|
||||
public String[] getConditionValues() { return conditionValues; }
|
||||
|
||||
// Action button / section extensions
|
||||
public Runnable getActionRunnable() { return actionRunnable; }
|
||||
public Runnable getRemoveAction() { return removeAction; }
|
||||
public Supplier<String> getTitleSupplier() { return titleSupplier; }
|
||||
public boolean shouldFillHeight() { return fillRemainingHeight; }
|
||||
|
||||
// ═══════════════════════════════════════════════════════════════════
|
||||
// LIST MANIPULATION (for mod injection)
|
||||
// ═══════════════════════════════════════════════════════════════════
|
||||
|
||||
@@ -15,5 +15,11 @@ public enum FieldType {
|
||||
SECTION_HEADER,
|
||||
LABEL,
|
||||
EFFECTS_LIST,
|
||||
ROW
|
||||
ROW,
|
||||
TEXT_AREA,
|
||||
COLOR,
|
||||
SELECT,
|
||||
AVAILABILITY_ROW,
|
||||
FACTION_ROW,
|
||||
ACTION_BUTTON
|
||||
}
|
||||
File diff suppressed because it is too large.
Load diff
@@ -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();
|
||||
}
|
||||
@@ -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}.
|
||||
* <p>
|
||||
* Handles scissor clipping, scroll coordinate translation, dropdown z-order,
|
||||
* and text area mouse delegation automatically.
|
||||
* <p>
|
||||
* Usage:
|
||||
* <pre>
|
||||
* 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();
|
||||
* </pre>
|
||||
*/
|
||||
@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<FieldDef> 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<ModernDropdown> getDropdowns() {
|
||||
return fieldPanel.getDropdowns();
|
||||
}
|
||||
|
||||
public List<ModernTextArea> getTextAreas() {
|
||||
return fieldPanel.getTextAreas();
|
||||
}
|
||||
|
||||
public void refresh() {
|
||||
fieldPanel.refresh();
|
||||
}
|
||||
|
||||
public boolean isInside(int mouseX, int mouseY) {
|
||||
return scrollPanel.isInside(mouseX, mouseY);
|
||||
}
|
||||
}
|
||||
@@ -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)) {
|
||||
|
||||
@@ -47,6 +47,7 @@ public class GuiNpcTextArea extends GuiNpcTextField {
|
||||
this.height = h;
|
||||
this.xPosition = x;
|
||||
this.yPosition = y;
|
||||
syncGuiTextFieldBounds(w, h);
|
||||
updateLineList();
|
||||
}
|
||||
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user