mirror of
https://github.com/KAMKEEL/CustomNPC-Plus.git
synced 2026-11-21 04:32:39 +00:00
Dialog Graph Editor
This commit is contained in:
1 parent
ba23b9f650
commit
5417cf8126
45 files changed
+11512
-16
No files matched your search
@@ -0,0 +1,218 @@
|
||||
package kamkeel.npcs.client.gui.components;
|
||||
|
||||
import noppes.npcs.client.gui.util.ModernColors;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.gui.FontRenderer;
|
||||
import net.minecraft.client.gui.Gui;
|
||||
|
||||
/**
|
||||
* A collapsible section header that can expand/collapse its content.
|
||||
* Used in the editor panel to organize settings into groups.
|
||||
*/
|
||||
public class CollapsibleSection extends Gui {
|
||||
|
||||
// Identity
|
||||
protected int id;
|
||||
protected String title;
|
||||
|
||||
// State
|
||||
protected boolean expanded = true;
|
||||
protected boolean hovered = false;
|
||||
|
||||
// Layout
|
||||
protected int x, y, width;
|
||||
protected int headerHeight = 18;
|
||||
protected int contentHeight = 0; // Set by owner based on content
|
||||
protected int indent = 8;
|
||||
protected int spacing = 4;
|
||||
protected int topPadding = 4; // Padding between header and first content row
|
||||
|
||||
// Colors
|
||||
protected int headerBg = ModernColors.SECTION_HEADER_BG;
|
||||
protected int headerBgHover = ModernColors.SECTION_HEADER_HOVER;
|
||||
protected int headerText = ModernColors.TEXT_LIGHT;
|
||||
protected int arrowColor = ModernColors.SECTION_ARROW;
|
||||
|
||||
// Animation
|
||||
protected float expandProgress = 1.0f; // 0 = collapsed, 1 = expanded
|
||||
protected float animSpeed = 8.0f; // Units per second
|
||||
protected long lastDrawTime = 0;
|
||||
|
||||
public CollapsibleSection(int id, String title) {
|
||||
this.id = id;
|
||||
this.title = title;
|
||||
}
|
||||
|
||||
public CollapsibleSection(int id, String title, boolean expanded) {
|
||||
this.id = id;
|
||||
this.title = title;
|
||||
this.expanded = expanded;
|
||||
this.expandProgress = expanded ? 1.0f : 0.0f;
|
||||
}
|
||||
|
||||
// === Layout ===
|
||||
|
||||
public void setPosition(int x, int y, int width) {
|
||||
this.x = x;
|
||||
this.y = y;
|
||||
this.width = width;
|
||||
}
|
||||
|
||||
public void setContentHeight(int height) {
|
||||
this.contentHeight = height;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get total height of this section (header + content if expanded).
|
||||
*/
|
||||
public int getTotalHeight() {
|
||||
if (!expanded && expandProgress <= 0.01f) {
|
||||
return headerHeight;
|
||||
}
|
||||
return headerHeight + topPadding + (int)(contentHeight * expandProgress) + spacing;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the Y position where content should start (after header + padding).
|
||||
*/
|
||||
public int getContentY() {
|
||||
return y + headerHeight + topPadding;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the X position for indented content.
|
||||
*/
|
||||
public int getContentX() {
|
||||
return x + indent;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the width available for content.
|
||||
*/
|
||||
public int getContentWidth() {
|
||||
return width - indent;
|
||||
}
|
||||
|
||||
// === Drawing ===
|
||||
|
||||
/**
|
||||
* Draw the section header. Content is drawn by the owner.
|
||||
* @return true if content should be drawn (expanded)
|
||||
*/
|
||||
public boolean draw(int mouseX, int mouseY) {
|
||||
FontRenderer fr = Minecraft.getMinecraft().fontRenderer;
|
||||
|
||||
// Update animation with proper delta time
|
||||
long currentTime = System.currentTimeMillis();
|
||||
float deltaTime = lastDrawTime == 0 ? 0.016f : (currentTime - lastDrawTime) / 1000.0f;
|
||||
lastDrawTime = currentTime;
|
||||
|
||||
float targetProgress = expanded ? 1.0f : 0.0f;
|
||||
if (Math.abs(expandProgress - targetProgress) > 0.001f) {
|
||||
float step = animSpeed * deltaTime;
|
||||
if (expandProgress < targetProgress) {
|
||||
expandProgress = Math.min(targetProgress, expandProgress + step);
|
||||
} else {
|
||||
expandProgress = Math.max(targetProgress, expandProgress - step);
|
||||
}
|
||||
} else {
|
||||
expandProgress = targetProgress;
|
||||
}
|
||||
|
||||
// Check hover
|
||||
hovered = mouseX >= x && mouseX < x + width &&
|
||||
mouseY >= y && mouseY < y + headerHeight;
|
||||
|
||||
// Draw header background
|
||||
int bgColor = hovered ? headerBgHover : headerBg;
|
||||
drawRect(x, y, x + width, y + headerHeight, bgColor);
|
||||
|
||||
// Draw expand/collapse arrow
|
||||
String arrow = expanded ? "\u25BC" : "\u25B6"; // ▼ or ▶
|
||||
fr.drawString(arrow, x + 4, y + (headerHeight - fr.FONT_HEIGHT) / 2, arrowColor);
|
||||
|
||||
// Draw title
|
||||
int titleX = x + 14;
|
||||
fr.drawString(title, titleX, y + (headerHeight - fr.FONT_HEIGHT) / 2, headerText);
|
||||
|
||||
// Return whether content should be drawn
|
||||
return expanded || expandProgress > 0.01f;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the current expand progress for animation purposes.
|
||||
* Can be used to clip content drawing during collapse animation.
|
||||
*/
|
||||
public float getExpandProgress() {
|
||||
return expandProgress;
|
||||
}
|
||||
|
||||
// === Interaction ===
|
||||
|
||||
/**
|
||||
* Handle mouse click. Returns true if handled.
|
||||
*/
|
||||
public boolean mouseClicked(int mouseX, int mouseY, int button) {
|
||||
if (button != 0) return false;
|
||||
|
||||
// Check if header was clicked
|
||||
if (mouseX >= x && mouseX < x + width &&
|
||||
mouseY >= y && mouseY < y + headerHeight) {
|
||||
toggle();
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Toggle expanded state.
|
||||
*/
|
||||
public void toggle() {
|
||||
expanded = !expanded;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set expanded state.
|
||||
*/
|
||||
public void setExpanded(boolean expanded) {
|
||||
this.expanded = expanded;
|
||||
// Instant state change for programmatic changes
|
||||
expandProgress = expanded ? 1.0f : 0.0f;
|
||||
}
|
||||
|
||||
// === Getters/Setters ===
|
||||
|
||||
public int getId() { return id; }
|
||||
public String getTitle() { return title; }
|
||||
public boolean isExpanded() { return expanded; }
|
||||
public boolean isHovered() { return hovered; }
|
||||
public int getX() { return x; }
|
||||
public int getY() { return y; }
|
||||
public int getWidth() { return width; }
|
||||
public int getHeaderHeight() { return headerHeight; }
|
||||
public int getIndent() { return indent; }
|
||||
|
||||
public CollapsibleSection setTitle(String title) {
|
||||
this.title = title;
|
||||
return this;
|
||||
}
|
||||
|
||||
public CollapsibleSection setHeaderHeight(int height) {
|
||||
this.headerHeight = height;
|
||||
return this;
|
||||
}
|
||||
|
||||
public CollapsibleSection setIndent(int indent) {
|
||||
this.indent = indent;
|
||||
return this;
|
||||
}
|
||||
|
||||
public CollapsibleSection setColors(int headerBg, int headerText, int arrow) {
|
||||
this.headerBg = headerBg;
|
||||
this.headerBgHover = ModernColors.lighten(headerBg, 0.1f);
|
||||
this.headerText = headerText;
|
||||
this.arrowColor = arrow;
|
||||
return this;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,334 @@
|
||||
package kamkeel.npcs.client.gui.components;
|
||||
|
||||
import noppes.npcs.client.gui.util.ModernColors;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.gui.FontRenderer;
|
||||
import noppes.npcs.client.gui.util.GuiNpcButton;
|
||||
|
||||
/**
|
||||
* Modern styled button extending GuiNpcButton.
|
||||
* Flat design matching the GuiModernScreen aesthetic with modern colors.
|
||||
* Inherits hover text, icon support, and multi-value cycling from GuiNpcButton.
|
||||
*/
|
||||
public class ModernButton extends GuiNpcButton {
|
||||
|
||||
// Styling (can be customized per-button)
|
||||
protected int bgColor = ModernColors.BUTTON_BG;
|
||||
protected int bgColorHover = ModernColors.BUTTON_BG_HOVER;
|
||||
protected int bgColorPressed = ModernColors.BUTTON_BG_PRESSED;
|
||||
protected int bgColorDisabled = ModernColors.BUTTON_BG_DISABLED;
|
||||
protected int borderColor = ModernColors.BUTTON_BORDER;
|
||||
protected int borderColorHover = ModernColors.BUTTON_BORDER_HOVER;
|
||||
protected int textColor = ModernColors.TEXT_WHITE;
|
||||
protected int textColorDisabled = ModernColors.TEXT_DARK;
|
||||
|
||||
// Layout
|
||||
protected int paddingX = 6;
|
||||
protected int paddingY = 2;
|
||||
protected int minWidth = 20;
|
||||
protected int minHeight = 16;
|
||||
|
||||
// State
|
||||
protected boolean pressed = false;
|
||||
protected boolean hovered = false;
|
||||
|
||||
// Multi-value support (like GuiNpcButton)
|
||||
protected String[] values;
|
||||
protected int valueIndex = 0;
|
||||
|
||||
/**
|
||||
* Create a simple button with text.
|
||||
*/
|
||||
public ModernButton(int id, int x, int y, int width, int height, String text) {
|
||||
super(id, x, y, width, height, text);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a button with minimum size based on text.
|
||||
*/
|
||||
public ModernButton(int id, int x, int y, String text) {
|
||||
super(id, x, y, 60, 20, text);
|
||||
fitToText(Minecraft.getMinecraft().fontRenderer);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a multi-value button (uses parent's display array).
|
||||
*/
|
||||
public ModernButton(int id, int x, int y, int width, int height, String[] values, int startIndex) {
|
||||
super(id, x, y, width, height, values, startIndex);
|
||||
// Also store in local values for modern methods
|
||||
this.values = values;
|
||||
this.valueIndex = startIndex;
|
||||
}
|
||||
|
||||
// === Size Methods ===
|
||||
|
||||
/**
|
||||
* Set button size.
|
||||
*/
|
||||
public ModernButton setSize(int w, int h) {
|
||||
this.width = Math.max(minWidth, w);
|
||||
this.height = Math.max(minHeight, h);
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set button bounds (position and size).
|
||||
*/
|
||||
public ModernButton setBounds(int x, int y, int w, int h) {
|
||||
this.xPosition = x;
|
||||
this.yPosition = y;
|
||||
return setSize(w, h);
|
||||
}
|
||||
|
||||
/**
|
||||
* Auto-size button based on text width.
|
||||
*/
|
||||
public ModernButton fitToText(FontRenderer fr) {
|
||||
if (fr == null) fr = Minecraft.getMinecraft().fontRenderer;
|
||||
int textWidth = fr.getStringWidth(displayString);
|
||||
this.width = Math.max(minWidth, textWidth + paddingX * 2);
|
||||
this.height = Math.max(minHeight, fr.FONT_HEIGHT + paddingY * 2);
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set minimum dimensions.
|
||||
*/
|
||||
public ModernButton setMinSize(int minW, int minH) {
|
||||
this.minWidth = minW;
|
||||
this.minHeight = minH;
|
||||
// Enforce minimums on current size
|
||||
if (width < minWidth) width = minWidth;
|
||||
if (height < minHeight) height = minHeight;
|
||||
return this;
|
||||
}
|
||||
|
||||
// === Style Methods ===
|
||||
|
||||
/**
|
||||
* Set background color for normal state.
|
||||
*/
|
||||
public ModernButton setBackgroundColor(int color) {
|
||||
this.bgColor = color;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set all background colors at once.
|
||||
*/
|
||||
public ModernButton setBackgroundColors(int normal, int hover, int pressed, int disabled) {
|
||||
this.bgColor = normal;
|
||||
this.bgColorHover = hover;
|
||||
this.bgColorPressed = pressed;
|
||||
this.bgColorDisabled = disabled;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set border color.
|
||||
*/
|
||||
public ModernButton setBorderColor(int color) {
|
||||
this.borderColor = color;
|
||||
this.borderColorHover = ModernColors.lighten(color, 0.2f);
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set text colors.
|
||||
*/
|
||||
public ModernButton setTextColors(int normal, int disabled) {
|
||||
this.textColor = normal;
|
||||
this.textColorDisabled = disabled;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set padding around text.
|
||||
*/
|
||||
public ModernButton setPadding(int px, int py) {
|
||||
this.paddingX = px;
|
||||
this.paddingY = py;
|
||||
return this;
|
||||
}
|
||||
|
||||
// === Multi-Value Support (delegates to parent where appropriate) ===
|
||||
|
||||
/**
|
||||
* Get current value index (for multi-value buttons).
|
||||
* Uses parent's getValue() for consistency.
|
||||
*/
|
||||
@Override
|
||||
public int getValue() {
|
||||
return super.getValue();
|
||||
}
|
||||
|
||||
/**
|
||||
* Set current value index.
|
||||
*/
|
||||
public ModernButton setValue(int index) {
|
||||
setDisplay(index);
|
||||
if (values != null && index >= 0 && index < values.length) {
|
||||
this.valueIndex = index;
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Cycle to next value.
|
||||
*/
|
||||
public void nextValue() {
|
||||
if (values != null && values.length > 0) {
|
||||
valueIndex = (valueIndex + 1) % values.length;
|
||||
setDisplay(valueIndex);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Cycle to previous value.
|
||||
*/
|
||||
public void prevValue() {
|
||||
if (values != null && values.length > 0) {
|
||||
valueIndex = (valueIndex - 1 + values.length) % values.length;
|
||||
setDisplay(valueIndex);
|
||||
}
|
||||
}
|
||||
|
||||
// === Rendering ===
|
||||
|
||||
@Override
|
||||
public void drawButton(Minecraft mc, int mouseX, int mouseY) {
|
||||
if (!this.visible) return;
|
||||
|
||||
FontRenderer fr = mc.fontRenderer;
|
||||
hovered = mouseX >= xPosition && mouseY >= yPosition &&
|
||||
mouseX < xPosition + width && mouseY < yPosition + height;
|
||||
|
||||
// Determine colors based on state
|
||||
int bg, border, text;
|
||||
if (!enabled) {
|
||||
bg = bgColorDisabled;
|
||||
border = borderColor;
|
||||
text = textColorDisabled;
|
||||
} else if (pressed && hovered) {
|
||||
bg = bgColorPressed;
|
||||
border = borderColorHover;
|
||||
text = textColor;
|
||||
} else if (hovered) {
|
||||
bg = bgColorHover;
|
||||
border = borderColorHover;
|
||||
text = textColor;
|
||||
} else {
|
||||
bg = bgColor;
|
||||
border = borderColor;
|
||||
text = textColor;
|
||||
}
|
||||
|
||||
// Draw background
|
||||
drawRect(xPosition, yPosition, xPosition + width, yPosition + height, bg);
|
||||
|
||||
// Draw border (1px)
|
||||
drawHorizontalLine(xPosition, xPosition + width - 1, yPosition, border);
|
||||
drawHorizontalLine(xPosition, xPosition + width - 1, yPosition + height - 1, border);
|
||||
drawVerticalLine(xPosition, yPosition, yPosition + height - 1, border);
|
||||
drawVerticalLine(xPosition + width - 1, yPosition, yPosition + height - 1, border);
|
||||
|
||||
// Draw text centered
|
||||
String displayText = displayString;
|
||||
int maxTextWidth = width - paddingX * 2;
|
||||
if (fr.getStringWidth(displayText) > maxTextWidth) {
|
||||
// Truncate with ellipsis
|
||||
displayText = trimToWidth(fr, displayText, maxTextWidth - fr.getStringWidth("..")) + "..";
|
||||
}
|
||||
|
||||
int textX = xPosition + (width - fr.getStringWidth(displayText)) / 2;
|
||||
int textY = yPosition + (height - fr.FONT_HEIGHT) / 2;
|
||||
|
||||
// Draw shadow first for better readability
|
||||
fr.drawString(displayText, textX + 1, textY + 1, ModernColors.darken(text, 0.6f));
|
||||
fr.drawString(displayText, textX, textY, text);
|
||||
}
|
||||
|
||||
/**
|
||||
* Draw horizontal line (like Gui.drawHorizontalLine but public).
|
||||
*/
|
||||
protected void drawHorizontalLine(int x1, int x2, int y, int color) {
|
||||
if (x2 < x1) {
|
||||
int temp = x1;
|
||||
x1 = x2;
|
||||
x2 = temp;
|
||||
}
|
||||
drawRect(x1, y, x2 + 1, y + 1, color);
|
||||
}
|
||||
|
||||
/**
|
||||
* Draw vertical line.
|
||||
*/
|
||||
protected void drawVerticalLine(int x, int y1, int y2, int color) {
|
||||
if (y2 < y1) {
|
||||
int temp = y1;
|
||||
y1 = y2;
|
||||
y2 = temp;
|
||||
}
|
||||
drawRect(x, y1, x + 1, y2 + 1, color);
|
||||
}
|
||||
|
||||
/**
|
||||
* Trim text to fit within width.
|
||||
*/
|
||||
protected String trimToWidth(FontRenderer fr, String text, int maxWidth) {
|
||||
if (fr.getStringWidth(text) <= maxWidth) return text;
|
||||
StringBuilder sb = new StringBuilder();
|
||||
for (char c : text.toCharArray()) {
|
||||
if (fr.getStringWidth(sb.toString() + c) > maxWidth) break;
|
||||
sb.append(c);
|
||||
}
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
// === Mouse Handling ===
|
||||
|
||||
@Override
|
||||
public boolean mousePressed(Minecraft mc, int mouseX, int mouseY) {
|
||||
boolean result = super.mousePressed(mc, mouseX, mouseY);
|
||||
if (result) {
|
||||
pressed = true;
|
||||
// Cycle value for multi-value buttons
|
||||
if (values != null) {
|
||||
nextValue();
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void mouseReleased(int mouseX, int mouseY) {
|
||||
pressed = false;
|
||||
super.mouseReleased(mouseX, mouseY);
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle right-click for reverse cycling (multi-value buttons).
|
||||
*/
|
||||
public boolean mouseRightPressed(Minecraft mc, int mouseX, int mouseY) {
|
||||
if (enabled && visible && hovered && values != null) {
|
||||
prevValue();
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
// === State Accessors ===
|
||||
|
||||
public boolean isHovered() {
|
||||
return hovered;
|
||||
}
|
||||
|
||||
public boolean isPressed() {
|
||||
return pressed;
|
||||
}
|
||||
|
||||
public void setEnabled(boolean enabled) {
|
||||
this.enabled = enabled;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,161 @@
|
||||
package kamkeel.npcs.client.gui.components;
|
||||
|
||||
import noppes.npcs.client.gui.util.ModernColors;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.gui.FontRenderer;
|
||||
import net.minecraft.client.gui.Gui;
|
||||
|
||||
/**
|
||||
* Modern styled checkbox component.
|
||||
* Square box: hollow border when OFF, filled green when ON.
|
||||
* Single click to toggle.
|
||||
*/
|
||||
public class ModernCheckbox extends Gui {
|
||||
|
||||
// Identity
|
||||
protected int id;
|
||||
protected String label;
|
||||
|
||||
// State
|
||||
protected boolean value = false;
|
||||
protected boolean enabled = true;
|
||||
protected boolean hovered = false;
|
||||
|
||||
// Position/Size
|
||||
protected int x, y;
|
||||
protected int size = 14;
|
||||
protected int labelGap = 6;
|
||||
|
||||
// Colors
|
||||
protected int borderColor = ModernColors.INPUT_BORDER;
|
||||
protected int borderColorHover = ModernColors.INPUT_BORDER_FOCUSED;
|
||||
protected int fillOff = ModernColors.INPUT_BG;
|
||||
protected int fillOn = ModernColors.ACCENT_GREEN;
|
||||
protected int labelColor = ModernColors.TEXT_LIGHT;
|
||||
protected int labelColorDisabled = ModernColors.TEXT_DARK;
|
||||
|
||||
public ModernCheckbox(int id, int x, int y, String label, boolean value) {
|
||||
this.id = id;
|
||||
this.x = x;
|
||||
this.y = y;
|
||||
this.label = label;
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
public ModernCheckbox(int id, int x, int y, boolean value) {
|
||||
this(id, x, y, null, value);
|
||||
}
|
||||
|
||||
// === Drawing ===
|
||||
|
||||
public void draw(int mouseX, int mouseY) {
|
||||
FontRenderer fr = Minecraft.getMinecraft().fontRenderer;
|
||||
|
||||
// Check hover on checkbox
|
||||
hovered = enabled && mouseX >= x && mouseX < x + size &&
|
||||
mouseY >= y && mouseY < y + size;
|
||||
|
||||
int border = !enabled ? ModernColors.INPUT_BORDER :
|
||||
(hovered ? borderColorHover : borderColor);
|
||||
|
||||
// Draw border (hollow box outline)
|
||||
drawRect(x, y, x + size, y + 1, border); // top
|
||||
drawRect(x, y + size - 1, x + size, y + size, border); // bottom
|
||||
drawRect(x, y, x + 1, y + size, border); // left
|
||||
drawRect(x + size - 1, y, x + size, y + size, border); // right
|
||||
|
||||
// Fill interior
|
||||
if (value) {
|
||||
// Filled green when ON
|
||||
int fill = enabled ? fillOn : ModernColors.darken(fillOn, 0.4f);
|
||||
drawRect(x + 2, y + 2, x + size - 2, y + size - 2, fill);
|
||||
} else {
|
||||
// Dark background when OFF
|
||||
int fill = enabled ? fillOff : ModernColors.INPUT_BG_DISABLED;
|
||||
drawRect(x + 1, y + 1, x + size - 1, y + size - 1, fill);
|
||||
}
|
||||
|
||||
// Draw label to the right
|
||||
if (label != null && !label.isEmpty()) {
|
||||
int labelY = y + (size - fr.FONT_HEIGHT) / 2;
|
||||
int labelX = x + size + labelGap;
|
||||
fr.drawString(label, labelX, labelY, enabled ? labelColor : labelColorDisabled);
|
||||
}
|
||||
}
|
||||
|
||||
// === Interaction ===
|
||||
|
||||
/**
|
||||
* Handle mouse click. Returns true if handled.
|
||||
*/
|
||||
public boolean mouseClicked(int mouseX, int mouseY, int button) {
|
||||
if (button != 0 || !enabled) return false;
|
||||
|
||||
// Check if checkbox was clicked
|
||||
if (mouseX >= x && mouseX < x + size &&
|
||||
mouseY >= y && mouseY < y + size) {
|
||||
toggle();
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Toggle the value.
|
||||
*/
|
||||
public void toggle() {
|
||||
value = !value;
|
||||
}
|
||||
|
||||
// === Getters/Setters ===
|
||||
|
||||
public int getId() { return id; }
|
||||
public boolean getValue() { return value; }
|
||||
|
||||
public void setValue(boolean value) {
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
public boolean isEnabled() { return enabled; }
|
||||
|
||||
public void setEnabled(boolean enabled) {
|
||||
this.enabled = enabled;
|
||||
}
|
||||
|
||||
public String getLabel() { return label; }
|
||||
|
||||
public void setLabel(String label) {
|
||||
this.label = label;
|
||||
}
|
||||
|
||||
public void setPosition(int x, int y) {
|
||||
this.x = x;
|
||||
this.y = y;
|
||||
}
|
||||
|
||||
public int getX() { return x; }
|
||||
public int getY() { return y; }
|
||||
public int getSize() { return size; }
|
||||
|
||||
public ModernCheckbox setSize(int size) {
|
||||
this.size = size;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get total width including label.
|
||||
*/
|
||||
public int getTotalWidth(FontRenderer fr) {
|
||||
if (label == null || label.isEmpty()) {
|
||||
return size;
|
||||
}
|
||||
return size + labelGap + fr.getStringWidth(label);
|
||||
}
|
||||
|
||||
public ModernCheckbox setColors(int borderColor, int fillOn) {
|
||||
this.borderColor = borderColor;
|
||||
this.fillOn = fillOn;
|
||||
return this;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,130 @@
|
||||
package kamkeel.npcs.client.gui.components;
|
||||
|
||||
import noppes.npcs.client.gui.util.ModernColors;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.gui.FontRenderer;
|
||||
import net.minecraft.client.gui.Gui;
|
||||
|
||||
/**
|
||||
* A button that displays a color swatch and hex value.
|
||||
* Clicking opens a color picker (handled by parent).
|
||||
*/
|
||||
public class ModernColorButton extends Gui {
|
||||
|
||||
// Identity
|
||||
protected int id;
|
||||
|
||||
// Position/Size
|
||||
protected int x, y, width, height;
|
||||
|
||||
// Color
|
||||
protected int color = 0xFFFFFF;
|
||||
|
||||
// State
|
||||
protected boolean enabled = true;
|
||||
protected boolean hovered = false;
|
||||
|
||||
// Colors
|
||||
protected int borderColor = ModernColors.INPUT_BORDER;
|
||||
protected int borderColorHover = ModernColors.INPUT_BORDER_FOCUSED;
|
||||
protected int disabledOverlay = 0x80000000;
|
||||
|
||||
public ModernColorButton(int id, int x, int y, int width, int height) {
|
||||
this.id = id;
|
||||
this.x = x;
|
||||
this.y = y;
|
||||
this.width = width;
|
||||
this.height = height;
|
||||
}
|
||||
|
||||
public ModernColorButton(int id, int x, int y, int width, int height, int color) {
|
||||
this(id, x, y, width, height);
|
||||
this.color = color;
|
||||
}
|
||||
|
||||
// === Drawing ===
|
||||
|
||||
public void draw(int mouseX, int mouseY) {
|
||||
FontRenderer fr = Minecraft.getMinecraft().fontRenderer;
|
||||
|
||||
hovered = enabled && isInside(mouseX, mouseY);
|
||||
|
||||
// Draw border
|
||||
int border = hovered ? borderColorHover : borderColor;
|
||||
drawRect(x - 1, y - 1, x + width + 1, y + height + 1, border);
|
||||
|
||||
// Draw color swatch
|
||||
drawRect(x, y, x + width, y + height, 0xFF000000 | color);
|
||||
|
||||
// Draw disabled overlay
|
||||
if (!enabled) {
|
||||
drawRect(x, y, x + width, y + height, disabledOverlay);
|
||||
}
|
||||
|
||||
// Draw hex text
|
||||
String hex = String.format("%06X", color & 0xFFFFFF);
|
||||
int textColor = getContrastColor(color);
|
||||
int textX = x + (width - fr.getStringWidth(hex)) / 2;
|
||||
int textY = y + (height - fr.FONT_HEIGHT) / 2;
|
||||
fr.drawString(hex, textX, textY, textColor);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a contrasting text color (black or white) based on background brightness.
|
||||
*/
|
||||
protected int getContrastColor(int bgColor) {
|
||||
int r = (bgColor >> 16) & 0xFF;
|
||||
int g = (bgColor >> 8) & 0xFF;
|
||||
int b = bgColor & 0xFF;
|
||||
// Calculate relative luminance
|
||||
double luminance = (0.299 * r + 0.587 * g + 0.114 * b) / 255.0;
|
||||
return luminance > 0.5 ? 0x000000 : 0xFFFFFF;
|
||||
}
|
||||
|
||||
// === Interaction ===
|
||||
|
||||
public boolean mouseClicked(int mouseX, int mouseY, int button) {
|
||||
if (button != 0 || !enabled) return false;
|
||||
return isInside(mouseX, mouseY);
|
||||
}
|
||||
|
||||
public boolean isInside(int mouseX, int mouseY) {
|
||||
return mouseX >= x && mouseX < x + width &&
|
||||
mouseY >= y && mouseY < y + height;
|
||||
}
|
||||
|
||||
// === Getters/Setters ===
|
||||
|
||||
public int getId() { return id; }
|
||||
|
||||
public int getColor() { return color; }
|
||||
|
||||
public void setColor(int color) {
|
||||
this.color = color & 0xFFFFFF;
|
||||
}
|
||||
|
||||
public boolean isEnabled() { return enabled; }
|
||||
|
||||
public void setEnabled(boolean enabled) {
|
||||
this.enabled = enabled;
|
||||
}
|
||||
|
||||
public boolean isHovered() { return hovered; }
|
||||
|
||||
public void setPosition(int x, int y) {
|
||||
this.x = x;
|
||||
this.y = y;
|
||||
}
|
||||
|
||||
public void setBounds(int x, int y, int width, int height) {
|
||||
this.x = x;
|
||||
this.y = y;
|
||||
this.width = width;
|
||||
this.height = height;
|
||||
}
|
||||
|
||||
public int getX() { return x; }
|
||||
public int getY() { return y; }
|
||||
public int getWidth() { return width; }
|
||||
public int getHeight() { return height; }
|
||||
}
|
||||
@@ -0,0 +1,394 @@
|
||||
package kamkeel.npcs.client.gui.components;
|
||||
|
||||
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.gui.ScaledResolution;
|
||||
import org.lwjgl.opengl.GL11;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Modern styled dropdown/select component.
|
||||
* Allows selection from a list of options.
|
||||
*/
|
||||
public class ModernDropdown extends Gui {
|
||||
|
||||
// Static: track the currently expanded dropdown to ensure only one is open
|
||||
protected static ModernDropdown activeDropdown = null;
|
||||
|
||||
// Identity
|
||||
protected int id;
|
||||
|
||||
// Position/Size
|
||||
protected int x, y, width, height;
|
||||
|
||||
// Options
|
||||
protected List<String> options = new ArrayList<>();
|
||||
protected int selectedIndex = 0;
|
||||
|
||||
// State
|
||||
protected boolean expanded = false;
|
||||
protected boolean enabled = true;
|
||||
protected boolean hovered = false;
|
||||
protected int hoveredOption = -1;
|
||||
|
||||
// Colors
|
||||
protected int bgColor = ModernColors.INPUT_BG;
|
||||
protected int bgColorHover = ModernColors.INPUT_BG_FOCUSED;
|
||||
protected int borderColor = ModernColors.INPUT_BORDER;
|
||||
protected int borderColorFocused = ModernColors.INPUT_BORDER_FOCUSED;
|
||||
protected int textColor = ModernColors.TEXT_LIGHT;
|
||||
protected int textColorDisabled = ModernColors.TEXT_DARK;
|
||||
protected int dropdownBg = ModernColors.PANEL_BG_SOLID;
|
||||
protected int optionHover = ModernColors.SELECTION_BG;
|
||||
protected int arrowColor = ModernColors.TEXT_GRAY;
|
||||
|
||||
// Layout
|
||||
protected int paddingX = 4;
|
||||
protected int maxDropdownHeight = 120;
|
||||
|
||||
// Screen-space position for overlay rendering (to handle scroll offsets)
|
||||
protected int screenX, screenY;
|
||||
|
||||
public ModernDropdown(int id, int x, int y, int width, int height) {
|
||||
this.id = id;
|
||||
this.x = x;
|
||||
this.y = y;
|
||||
this.width = width;
|
||||
this.height = height;
|
||||
}
|
||||
|
||||
// === Drawing ===
|
||||
|
||||
/**
|
||||
* Draw the dropdown. Use drawBase() + drawOverlay() for z-order control.
|
||||
*/
|
||||
public void draw(int mouseX, int mouseY) {
|
||||
drawBase(mouseX, mouseY);
|
||||
if (expanded) {
|
||||
drawOverlay(mouseX, mouseY);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Draw only the base button (not the expanded dropdown).
|
||||
* Call this first, then call drawOverlay() later for proper z-order.
|
||||
*/
|
||||
public void drawBase(int mouseX, int mouseY) {
|
||||
FontRenderer fr = Minecraft.getMinecraft().fontRenderer;
|
||||
|
||||
// Check hover state
|
||||
hovered = enabled && isInsideMain(mouseX, mouseY);
|
||||
|
||||
// Draw main button
|
||||
int bg = !enabled ? ModernColors.INPUT_BG_DISABLED : (hovered || expanded ? bgColorHover : bgColor);
|
||||
int border = expanded ? borderColorFocused : borderColor;
|
||||
|
||||
drawRect(x - 1, y - 1, x + width + 1, y + height + 1, border);
|
||||
drawRect(x, y, x + width, y + height, bg);
|
||||
|
||||
// Draw selected text
|
||||
String displayText = selectedIndex >= 0 && selectedIndex < options.size() ?
|
||||
options.get(selectedIndex) : "";
|
||||
displayText = fr.trimStringToWidth(displayText, width - paddingX * 2 - 12);
|
||||
int textY = y + (height - fr.FONT_HEIGHT) / 2;
|
||||
fr.drawString(displayText, x + paddingX, textY, enabled ? textColor : textColorDisabled);
|
||||
|
||||
// Draw arrow
|
||||
String arrow = expanded ? "\u25B2" : "\u25BC"; // ▲ or ▼
|
||||
int arrowX = x + width - paddingX - fr.getStringWidth(arrow);
|
||||
fr.drawString(arrow, arrowX, textY, arrowColor);
|
||||
}
|
||||
|
||||
/**
|
||||
* Draw the expanded dropdown overlay. Call this AFTER all other components
|
||||
* to ensure it renders on top.
|
||||
*/
|
||||
public void drawOverlay(int mouseX, int mouseY) {
|
||||
if (!expanded) return;
|
||||
FontRenderer fr = Minecraft.getMinecraft().fontRenderer;
|
||||
drawDropdown(mouseX, mouseY, fr);
|
||||
}
|
||||
|
||||
protected void drawDropdown(int mouseX, int mouseY, FontRenderer fr) {
|
||||
int optionHeight = fr.FONT_HEIGHT + 4;
|
||||
int dropdownHeight = Math.min(options.size() * optionHeight, maxDropdownHeight);
|
||||
int dropdownY = y + height;
|
||||
|
||||
// Use scissor for scrolling if needed
|
||||
Minecraft mc = Minecraft.getMinecraft();
|
||||
ScaledResolution sr = new ScaledResolution(mc, mc.displayWidth, mc.displayHeight);
|
||||
int scale = sr.getScaleFactor();
|
||||
|
||||
// Draw dropdown background with border
|
||||
drawRect(x - 1, dropdownY, x + width + 1, dropdownY + dropdownHeight + 1, borderColorFocused);
|
||||
drawRect(x, dropdownY, x + width, dropdownY + dropdownHeight, dropdownBg);
|
||||
|
||||
GL11.glEnable(GL11.GL_SCISSOR_TEST);
|
||||
GL11.glScissor(x * scale, mc.displayHeight - (dropdownY + dropdownHeight) * scale,
|
||||
width * scale, dropdownHeight * scale);
|
||||
|
||||
// Draw options
|
||||
hoveredOption = -1;
|
||||
for (int i = 0; i < options.size(); i++) {
|
||||
int optY = dropdownY + i * optionHeight;
|
||||
|
||||
// Check hover
|
||||
if (mouseX >= x && mouseX < x + width &&
|
||||
mouseY >= optY && mouseY < optY + optionHeight) {
|
||||
hoveredOption = i;
|
||||
drawRect(x, optY, x + width, optY + optionHeight, optionHover);
|
||||
}
|
||||
|
||||
// Draw text
|
||||
String text = fr.trimStringToWidth(options.get(i), width - paddingX * 2);
|
||||
int textCol = (i == selectedIndex) ? ModernColors.ACCENT_BLUE : textColor;
|
||||
fr.drawString(text, x + paddingX, optY + 2, textCol);
|
||||
}
|
||||
|
||||
GL11.glDisable(GL11.GL_SCISSOR_TEST);
|
||||
}
|
||||
|
||||
// === Interaction ===
|
||||
|
||||
public boolean mouseClicked(int mouseX, int mouseY, int button) {
|
||||
if (button != 0) return false;
|
||||
|
||||
if (!enabled) return false;
|
||||
|
||||
if (expanded) {
|
||||
// Check if clicked on an option
|
||||
if (hoveredOption >= 0) {
|
||||
selectedIndex = hoveredOption;
|
||||
expanded = false;
|
||||
if (activeDropdown == this) activeDropdown = null;
|
||||
return true;
|
||||
}
|
||||
// Clicked outside - close
|
||||
expanded = false;
|
||||
if (activeDropdown == this) activeDropdown = null;
|
||||
return isInsideMain(mouseX, mouseY);
|
||||
} else {
|
||||
// Check if clicked on main button
|
||||
if (isInsideMain(mouseX, mouseY)) {
|
||||
// Close any other open dropdown first
|
||||
if (activeDropdown != null && activeDropdown != this) {
|
||||
activeDropdown.close();
|
||||
}
|
||||
activeDropdown = this;
|
||||
expanded = true;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean isInsideMain(int mouseX, int mouseY) {
|
||||
return mouseX >= x && mouseX < x + width &&
|
||||
mouseY >= y && mouseY < y + height;
|
||||
}
|
||||
|
||||
public boolean isInsideDropdown(int mouseX, int mouseY) {
|
||||
if (!expanded) return false;
|
||||
FontRenderer fr = Minecraft.getMinecraft().fontRenderer;
|
||||
int optionHeight = fr.FONT_HEIGHT + 4;
|
||||
int dropdownHeight = Math.min(options.size() * optionHeight, maxDropdownHeight);
|
||||
int dropdownY = y + height;
|
||||
|
||||
return mouseX >= x && mouseX < x + width &&
|
||||
mouseY >= dropdownY && mouseY < dropdownY + dropdownHeight;
|
||||
}
|
||||
|
||||
public boolean isInside(int mouseX, int mouseY) {
|
||||
return isInsideMain(mouseX, mouseY) || isInsideDropdown(mouseX, mouseY);
|
||||
}
|
||||
|
||||
public void close() {
|
||||
expanded = false;
|
||||
if (activeDropdown == this) activeDropdown = null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Close any currently active dropdown. Call this when clicking elsewhere
|
||||
* in the UI to dismiss open dropdowns.
|
||||
*/
|
||||
public static void closeActiveDropdown() {
|
||||
if (activeDropdown != null) {
|
||||
activeDropdown.expanded = false;
|
||||
activeDropdown = null;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if any dropdown is currently expanded.
|
||||
*/
|
||||
public static boolean hasActiveDropdown() {
|
||||
return activeDropdown != null && activeDropdown.expanded;
|
||||
}
|
||||
|
||||
// === Getters/Setters ===
|
||||
|
||||
public int getId() { return id; }
|
||||
|
||||
public int getSelectedIndex() { return selectedIndex; }
|
||||
|
||||
public void setSelectedIndex(int index) {
|
||||
this.selectedIndex = Math.max(0, Math.min(index, options.size() - 1));
|
||||
}
|
||||
|
||||
public String getSelectedValue() {
|
||||
if (selectedIndex >= 0 && selectedIndex < options.size()) {
|
||||
return options.get(selectedIndex);
|
||||
}
|
||||
return "";
|
||||
}
|
||||
|
||||
public void setSelectedValue(String value) {
|
||||
int idx = options.indexOf(value);
|
||||
if (idx >= 0) {
|
||||
selectedIndex = idx;
|
||||
}
|
||||
}
|
||||
|
||||
public List<String> getOptions() { return options; }
|
||||
|
||||
public void setOptions(List<String> options) {
|
||||
this.options = options != null ? options : new ArrayList<>();
|
||||
if (selectedIndex >= this.options.size()) {
|
||||
selectedIndex = this.options.isEmpty() ? -1 : 0;
|
||||
}
|
||||
}
|
||||
|
||||
public void addOption(String option) {
|
||||
options.add(option);
|
||||
}
|
||||
|
||||
public void clearOptions() {
|
||||
options.clear();
|
||||
selectedIndex = -1;
|
||||
}
|
||||
|
||||
public boolean isExpanded() { return expanded; }
|
||||
|
||||
public boolean isEnabled() { return enabled; }
|
||||
|
||||
public void setEnabled(boolean enabled) {
|
||||
this.enabled = enabled;
|
||||
if (!enabled) expanded = false;
|
||||
}
|
||||
|
||||
public void setPosition(int x, int y) {
|
||||
this.x = x;
|
||||
this.y = y;
|
||||
}
|
||||
|
||||
public void setBounds(int x, int y, int width, int height) {
|
||||
this.x = x;
|
||||
this.y = y;
|
||||
this.width = width;
|
||||
this.height = height;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set screen-space position for overlay rendering (handles scroll offsets).
|
||||
*/
|
||||
public void setScreenPosition(int screenX, int screenY) {
|
||||
this.screenX = screenX;
|
||||
this.screenY = screenY;
|
||||
}
|
||||
|
||||
/**
|
||||
* Draw the expanded dropdown overlay in screen-space coordinates.
|
||||
* Call this AFTER disabling scissor test and popping scroll translation.
|
||||
*/
|
||||
public void drawOverlayScreenSpace(int mouseX, int mouseY) {
|
||||
if (!expanded) return;
|
||||
FontRenderer fr = Minecraft.getMinecraft().fontRenderer;
|
||||
|
||||
int optionHeight = fr.FONT_HEIGHT + 4;
|
||||
int dropdownHeight = Math.min(options.size() * optionHeight, maxDropdownHeight);
|
||||
int dropdownY = screenY + height;
|
||||
|
||||
// Draw dropdown background with border at screen position
|
||||
drawRect(screenX - 1, dropdownY, screenX + width + 1, dropdownY + dropdownHeight + 1, borderColorFocused);
|
||||
drawRect(screenX, dropdownY, screenX + width, dropdownY + dropdownHeight, dropdownBg);
|
||||
|
||||
// Draw options with screen-space hit detection
|
||||
hoveredOption = -1;
|
||||
for (int i = 0; i < options.size(); i++) {
|
||||
int optY = dropdownY + i * optionHeight;
|
||||
|
||||
// Check hover using screen coordinates
|
||||
if (mouseX >= screenX && mouseX < screenX + width &&
|
||||
mouseY >= optY && mouseY < optY + optionHeight) {
|
||||
hoveredOption = i;
|
||||
drawRect(screenX, optY, screenX + width, optY + optionHeight, optionHover);
|
||||
}
|
||||
|
||||
// Draw text
|
||||
String text = fr.trimStringToWidth(options.get(i), width - paddingX * 2);
|
||||
int textCol = (i == selectedIndex) ? ModernColors.ACCENT_BLUE : textColor;
|
||||
fr.drawString(text, screenX + paddingX, optY + 2, textCol);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle mouse click using screen-space coordinates for expanded dropdown.
|
||||
*/
|
||||
public boolean mouseClickedScreenSpace(int mouseX, int mouseY, int button) {
|
||||
if (button != 0 || !enabled) return false;
|
||||
|
||||
if (expanded) {
|
||||
// Check if clicked on an option using screen coordinates
|
||||
if (hoveredOption >= 0) {
|
||||
selectedIndex = hoveredOption;
|
||||
expanded = false;
|
||||
if (activeDropdown == this) activeDropdown = null;
|
||||
return true;
|
||||
}
|
||||
// Clicked outside - close
|
||||
expanded = false;
|
||||
if (activeDropdown == this) activeDropdown = null;
|
||||
return isInsideMainScreenSpace(mouseX, mouseY);
|
||||
} else {
|
||||
// Check if clicked on main button using screen coordinates
|
||||
if (isInsideMainScreenSpace(mouseX, mouseY)) {
|
||||
// Close any other open dropdown first
|
||||
if (activeDropdown != null && activeDropdown != this) {
|
||||
activeDropdown.close();
|
||||
}
|
||||
activeDropdown = this;
|
||||
expanded = true;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if mouse is inside the main dropdown button using screen coordinates.
|
||||
*/
|
||||
protected boolean isInsideMainScreenSpace(int mouseX, int mouseY) {
|
||||
return mouseX >= screenX && mouseX < screenX + width &&
|
||||
mouseY >= screenY && mouseY < screenY + height;
|
||||
}
|
||||
|
||||
public int getX() { return x; }
|
||||
public int getY() { return y; }
|
||||
public int getWidth() { return width; }
|
||||
public int getHeight() { return height; }
|
||||
|
||||
/**
|
||||
* Get the height when expanded (for z-ordering).
|
||||
*/
|
||||
public int getExpandedHeight() {
|
||||
if (!expanded) return height;
|
||||
FontRenderer fr = Minecraft.getMinecraft().fontRenderer;
|
||||
int optionHeight = fr.FONT_HEIGHT + 4;
|
||||
return height + Math.min(options.size() * optionHeight, maxDropdownHeight);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,144 @@
|
||||
package kamkeel.npcs.client.gui.components;
|
||||
|
||||
import noppes.npcs.client.gui.util.ModernColors;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.gui.FontRenderer;
|
||||
import net.minecraft.client.gui.Gui;
|
||||
|
||||
/**
|
||||
* Modern styled label component.
|
||||
* Supports single or multi-line text, alignment, and optional background.
|
||||
*/
|
||||
public class ModernLabel extends Gui {
|
||||
|
||||
// Identity
|
||||
protected int id;
|
||||
protected String text;
|
||||
|
||||
// Position/Size
|
||||
protected int x, y;
|
||||
protected int width = 0; // 0 = auto-width based on text
|
||||
protected int height = 0;
|
||||
|
||||
// Alignment
|
||||
public static final int ALIGN_LEFT = 0;
|
||||
public static final int ALIGN_CENTER = 1;
|
||||
public static final int ALIGN_RIGHT = 2;
|
||||
protected int alignment = ALIGN_LEFT;
|
||||
|
||||
// Styling
|
||||
protected int textColor = ModernColors.TEXT_LIGHT;
|
||||
protected int bgColor = 0; // 0 = no background
|
||||
protected int padding = 2;
|
||||
protected boolean shadow = false;
|
||||
|
||||
public ModernLabel(int id, int x, int y, String text) {
|
||||
this.id = id;
|
||||
this.x = x;
|
||||
this.y = y;
|
||||
this.text = text;
|
||||
}
|
||||
|
||||
public ModernLabel(int id, int x, int y, int width, String text) {
|
||||
this.id = id;
|
||||
this.x = x;
|
||||
this.y = y;
|
||||
this.width = width;
|
||||
this.text = text;
|
||||
}
|
||||
|
||||
// === Drawing ===
|
||||
|
||||
public void draw(int mouseX, int mouseY) {
|
||||
FontRenderer fr = Minecraft.getMinecraft().fontRenderer;
|
||||
|
||||
int textWidth = fr.getStringWidth(text);
|
||||
int actualWidth = width > 0 ? width : textWidth + padding * 2;
|
||||
int actualHeight = height > 0 ? height : fr.FONT_HEIGHT + padding * 2;
|
||||
|
||||
// Draw background if set
|
||||
if (bgColor != 0) {
|
||||
drawRect(x, y, x + actualWidth, y + actualHeight, bgColor);
|
||||
}
|
||||
|
||||
// Calculate text position based on alignment
|
||||
int textX;
|
||||
switch (alignment) {
|
||||
case ALIGN_CENTER:
|
||||
textX = x + (actualWidth - textWidth) / 2;
|
||||
break;
|
||||
case ALIGN_RIGHT:
|
||||
textX = x + actualWidth - textWidth - padding;
|
||||
break;
|
||||
default: // ALIGN_LEFT
|
||||
textX = x + padding;
|
||||
}
|
||||
|
||||
int textY = y + (actualHeight - fr.FONT_HEIGHT) / 2;
|
||||
|
||||
// Draw text
|
||||
if (shadow) {
|
||||
fr.drawStringWithShadow(text, textX, textY, textColor);
|
||||
} else {
|
||||
fr.drawString(text, textX, textY, textColor);
|
||||
}
|
||||
}
|
||||
|
||||
// === Getters/Setters ===
|
||||
|
||||
public int getId() { return id; }
|
||||
public String getText() { return text; }
|
||||
|
||||
public void setText(String text) {
|
||||
this.text = text;
|
||||
}
|
||||
|
||||
public void setPosition(int x, int y) {
|
||||
this.x = x;
|
||||
this.y = y;
|
||||
}
|
||||
|
||||
public int getX() { return x; }
|
||||
public int getY() { return y; }
|
||||
|
||||
public int getWidth() {
|
||||
if (width > 0) return width;
|
||||
return Minecraft.getMinecraft().fontRenderer.getStringWidth(text) + padding * 2;
|
||||
}
|
||||
|
||||
public int getHeight() {
|
||||
if (height > 0) return height;
|
||||
return Minecraft.getMinecraft().fontRenderer.FONT_HEIGHT + padding * 2;
|
||||
}
|
||||
|
||||
public ModernLabel setSize(int width, int height) {
|
||||
this.width = width;
|
||||
this.height = height;
|
||||
return this;
|
||||
}
|
||||
|
||||
public ModernLabel setAlignment(int align) {
|
||||
this.alignment = align;
|
||||
return this;
|
||||
}
|
||||
|
||||
public ModernLabel setColor(int color) {
|
||||
this.textColor = color;
|
||||
return this;
|
||||
}
|
||||
|
||||
public ModernLabel setBackground(int color) {
|
||||
this.bgColor = color;
|
||||
return this;
|
||||
}
|
||||
|
||||
public ModernLabel setShadow(boolean shadow) {
|
||||
this.shadow = shadow;
|
||||
return this;
|
||||
}
|
||||
|
||||
public ModernLabel setPadding(int padding) {
|
||||
this.padding = padding;
|
||||
return this;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,69 @@
|
||||
package kamkeel.npcs.client.gui.components;
|
||||
|
||||
/**
|
||||
* A text field specialized for numeric input.
|
||||
* Supports integers and floats with min/max validation.
|
||||
* Leverages GuiNpcTextField's existing numeric support.
|
||||
*/
|
||||
public class ModernNumberField extends ModernTextField {
|
||||
|
||||
public ModernNumberField(int id, int x, int y, int width, int height) {
|
||||
super(id, x, y, width, height);
|
||||
setText("0");
|
||||
integersOnly = true;
|
||||
}
|
||||
|
||||
public ModernNumberField(int id, int x, int y, int width, int height, int value) {
|
||||
super(id, x, y, width, height);
|
||||
integersOnly = true;
|
||||
setText(String.valueOf(value));
|
||||
}
|
||||
|
||||
public ModernNumberField(int id, int x, int y, int width, int height, float value) {
|
||||
super(id, x, y, width, height);
|
||||
floatsOnly = true;
|
||||
setText(String.valueOf(value));
|
||||
}
|
||||
|
||||
/**
|
||||
* Configure for integer input with min/max bounds.
|
||||
*/
|
||||
public ModernNumberField setIntegerBounds(int min, int max, int defaultVal) {
|
||||
integersOnly = true;
|
||||
floatsOnly = false;
|
||||
doublesOnly = false;
|
||||
setMinMaxDefault(min, max, defaultVal);
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Configure for float input with min/max bounds.
|
||||
*/
|
||||
public ModernNumberField setFloatBounds(float min, float max, float defaultVal) {
|
||||
floatsOnly = true;
|
||||
integersOnly = false;
|
||||
doublesOnly = false;
|
||||
setMinMaxDefaultFloat(min, max, defaultVal);
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the value as an integer.
|
||||
*/
|
||||
public void setInteger(int value) {
|
||||
value = Math.max(min, Math.min(max, value));
|
||||
setText(String.valueOf(value));
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the value as a float.
|
||||
*/
|
||||
public void setFloat(float value) {
|
||||
value = Math.max(minFloat, Math.min(maxFloat, value));
|
||||
setText(String.valueOf(value));
|
||||
}
|
||||
|
||||
public void setIntegersOnly(boolean integersOnly) {
|
||||
this.integersOnly = integersOnly;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,163 @@
|
||||
package kamkeel.npcs.client.gui.components;
|
||||
|
||||
import noppes.npcs.client.gui.util.ModernColors;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.gui.FontRenderer;
|
||||
import net.minecraft.client.gui.Gui;
|
||||
|
||||
/**
|
||||
* A button that displays selected item text and triggers selection on click.
|
||||
* The parent handles opening the actual selection GUI.
|
||||
*/
|
||||
public class ModernSelectButton extends Gui {
|
||||
|
||||
// Identity
|
||||
protected int id;
|
||||
protected int slot = 0; // For multi-slot selections
|
||||
|
||||
// Position/Size
|
||||
protected int x, y, width, height;
|
||||
|
||||
// Display
|
||||
protected String displayText = "";
|
||||
protected String placeholder = "Select...";
|
||||
protected int selectedId = -1;
|
||||
|
||||
// State
|
||||
protected boolean enabled = true;
|
||||
protected boolean hovered = false;
|
||||
|
||||
// Colors
|
||||
protected int bgColor = ModernColors.BUTTON_BG;
|
||||
protected int bgColorHover = ModernColors.BUTTON_BG_HOVER;
|
||||
protected int bgColorDisabled = ModernColors.BUTTON_BG_DISABLED;
|
||||
protected int borderColor = ModernColors.BUTTON_BORDER;
|
||||
protected int borderColorHover = ModernColors.BUTTON_BORDER_HOVER;
|
||||
protected int textColor = ModernColors.TEXT_LIGHT;
|
||||
protected int textColorDisabled = ModernColors.TEXT_DARK;
|
||||
protected int placeholderColor = ModernColors.TEXT_DARK;
|
||||
|
||||
// Padding
|
||||
protected int paddingX = 4;
|
||||
|
||||
public ModernSelectButton(int id, int x, int y, int width, int height) {
|
||||
this.id = id;
|
||||
this.x = x;
|
||||
this.y = y;
|
||||
this.width = width;
|
||||
this.height = height;
|
||||
}
|
||||
|
||||
public ModernSelectButton(int id, int x, int y, int width, int height, String placeholder) {
|
||||
this(id, x, y, width, height);
|
||||
this.placeholder = placeholder;
|
||||
}
|
||||
|
||||
// === Drawing ===
|
||||
|
||||
public void draw(int mouseX, int mouseY) {
|
||||
FontRenderer fr = Minecraft.getMinecraft().fontRenderer;
|
||||
|
||||
hovered = enabled && isInside(mouseX, mouseY);
|
||||
|
||||
// Background
|
||||
int bg = !enabled ? bgColorDisabled : (hovered ? bgColorHover : bgColor);
|
||||
int border = hovered ? borderColorHover : borderColor;
|
||||
|
||||
// Draw border
|
||||
drawRect(x - 1, y - 1, x + width + 1, y + height + 1, border);
|
||||
// Draw background
|
||||
drawRect(x, y, x + width, y + height, bg);
|
||||
|
||||
// Draw text
|
||||
String text = (displayText != null && !displayText.isEmpty()) ? displayText : placeholder;
|
||||
text = fr.trimStringToWidth(text, width - paddingX * 2);
|
||||
int textY = y + (height - fr.FONT_HEIGHT) / 2;
|
||||
|
||||
int textCol;
|
||||
if (!enabled) {
|
||||
textCol = textColorDisabled;
|
||||
} else if (displayText != null && !displayText.isEmpty()) {
|
||||
textCol = textColor;
|
||||
} else {
|
||||
textCol = placeholderColor;
|
||||
}
|
||||
|
||||
fr.drawString(text, x + paddingX, textY, textCol);
|
||||
}
|
||||
|
||||
// === Interaction ===
|
||||
|
||||
public boolean mouseClicked(int mouseX, int mouseY, int button) {
|
||||
if (button != 0 || !enabled) return false;
|
||||
return isInside(mouseX, mouseY);
|
||||
}
|
||||
|
||||
public boolean isInside(int mouseX, int mouseY) {
|
||||
return mouseX >= x && mouseX < x + width &&
|
||||
mouseY >= y && mouseY < y + height;
|
||||
}
|
||||
|
||||
// === Selection Management ===
|
||||
|
||||
public void setSelected(int id, String name) {
|
||||
this.selectedId = id;
|
||||
this.displayText = name;
|
||||
}
|
||||
|
||||
public void clearSelection() {
|
||||
this.selectedId = -1;
|
||||
this.displayText = "";
|
||||
}
|
||||
|
||||
public boolean hasSelection() {
|
||||
return selectedId >= 0;
|
||||
}
|
||||
|
||||
// === Getters/Setters ===
|
||||
|
||||
public int getId() { return id; }
|
||||
|
||||
public int getSlot() { return slot; }
|
||||
|
||||
public void setSlot(int slot) { this.slot = slot; }
|
||||
|
||||
public int getSelectedId() { return selectedId; }
|
||||
|
||||
public String getDisplayText() { return displayText; }
|
||||
|
||||
public void setDisplayText(String text) {
|
||||
this.displayText = text;
|
||||
}
|
||||
|
||||
public String getPlaceholder() { return placeholder; }
|
||||
|
||||
public void setPlaceholder(String placeholder) {
|
||||
this.placeholder = placeholder;
|
||||
}
|
||||
|
||||
public boolean isEnabled() { return enabled; }
|
||||
|
||||
public void setEnabled(boolean enabled) {
|
||||
this.enabled = enabled;
|
||||
}
|
||||
|
||||
public boolean isHovered() { return hovered; }
|
||||
|
||||
public void setPosition(int x, int y) {
|
||||
this.x = x;
|
||||
this.y = y;
|
||||
}
|
||||
|
||||
public void setBounds(int x, int y, int width, int height) {
|
||||
this.x = x;
|
||||
this.y = y;
|
||||
this.width = width;
|
||||
this.height = height;
|
||||
}
|
||||
|
||||
public int getX() { return x; }
|
||||
public int getY() { return y; }
|
||||
public int getWidth() { return width; }
|
||||
public int getHeight() { return height; }
|
||||
}
|
||||
@@ -0,0 +1,96 @@
|
||||
package kamkeel.npcs.client.gui.components;
|
||||
|
||||
import noppes.npcs.client.gui.util.GuiNpcTextArea;
|
||||
|
||||
/**
|
||||
* Modern styled text area extending GuiNpcTextArea.
|
||||
* Provides convenience methods like setBounds() for dynamic positioning.
|
||||
* Designed for use in panels that manage their own rendering/input.
|
||||
*/
|
||||
public class ModernTextArea extends GuiNpcTextArea {
|
||||
|
||||
/**
|
||||
* Create a text area with position and size.
|
||||
*/
|
||||
public ModernTextArea(int id, int x, int y, int width, int height) {
|
||||
super(id, null, x, y, width, height, "");
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a text area with initial text.
|
||||
*/
|
||||
public ModernTextArea(int id, int x, int y, int width, int height, String text) {
|
||||
super(id, null, x, y, width, height, text != null ? text : "");
|
||||
}
|
||||
|
||||
// === Convenience Methods ===
|
||||
|
||||
/**
|
||||
* Draw the text area. Alias for drawTextBox(mouseX, mouseY).
|
||||
*/
|
||||
public void draw(int mouseX, int mouseY) {
|
||||
drawTextBox(mouseX, mouseY);
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle key typed. Alias for textboxKeyTyped().
|
||||
*/
|
||||
public boolean keyTyped(char c, int keyCode) {
|
||||
return textboxKeyTyped(c, keyCode);
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle mouse click with boolean return.
|
||||
* GuiNpcTextArea.mouseClicked returns void, so we wrap it.
|
||||
*/
|
||||
public boolean handleClick(int mouseX, int mouseY, int button) {
|
||||
boolean wasInside = isInside(mouseX, mouseY);
|
||||
super.mouseClicked(mouseX, mouseY, button);
|
||||
return wasInside && button == 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set max length. Alias for setMaxStringLength().
|
||||
*/
|
||||
public ModernTextArea setMaxLength(int max) {
|
||||
setMaxStringLength(max);
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set enabled state.
|
||||
*/
|
||||
public void setEnabled(boolean enabled) {
|
||||
this.enabled = enabled;
|
||||
this.canEdit = enabled;
|
||||
}
|
||||
|
||||
/**
|
||||
* Mouse released - no-op, scrollbar handled internally by drawTextBox.
|
||||
*/
|
||||
public void mouseReleased(int mouseX, int mouseY) {
|
||||
// GuiNpcTextArea handles scrollbar internally
|
||||
}
|
||||
|
||||
/**
|
||||
* Mouse dragged - no-op, scrollbar handled internally by drawTextBox.
|
||||
*/
|
||||
public void mouseDragged(int mouseX, int mouseY) {
|
||||
// GuiNpcTextArea handles scrollbar internally
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if a point is inside this text area.
|
||||
*/
|
||||
public boolean isInside(int mouseX, int mouseY) {
|
||||
return mouseX >= posX && mouseX < posX + width &&
|
||||
mouseY >= posY && mouseY < posY + height;
|
||||
}
|
||||
|
||||
// === Position Getters ===
|
||||
|
||||
public int getX() { return posX; }
|
||||
public int getY() { return posY; }
|
||||
public int getWidth() { return width; }
|
||||
public int getHeight() { return height; }
|
||||
}
|
||||
@@ -0,0 +1,134 @@
|
||||
package kamkeel.npcs.client.gui.components;
|
||||
|
||||
import net.minecraft.client.Minecraft;
|
||||
import noppes.npcs.client.gui.util.GuiNpcTextField;
|
||||
|
||||
/**
|
||||
* Modern styled text field extending GuiNpcTextField.
|
||||
* Provides additional convenience methods like setBounds() for dynamic positioning.
|
||||
* Designed for use in panels that manage their own rendering/input.
|
||||
*/
|
||||
public class ModernTextField extends GuiNpcTextField {
|
||||
|
||||
protected String placeholder = "";
|
||||
|
||||
/**
|
||||
* Create a text field with position and size.
|
||||
*/
|
||||
public ModernTextField(int id, int x, int y, int width, int height) {
|
||||
super(id, null, Minecraft.getMinecraft().fontRenderer, x, y, width, height, "");
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a text field with initial text.
|
||||
*/
|
||||
public ModernTextField(int id, int x, int y, int width, int height, String text) {
|
||||
super(id, null, Minecraft.getMinecraft().fontRenderer, x, y, width, height, text != null ? text : "");
|
||||
}
|
||||
|
||||
// === Convenience Methods ===
|
||||
|
||||
/**
|
||||
* Set bounds (position and size) for dynamic layout.
|
||||
*/
|
||||
public void setBounds(int x, int y, int width, int height) {
|
||||
this.xPosition = x;
|
||||
this.yPosition = y;
|
||||
this.width = width;
|
||||
this.height = height;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set position only.
|
||||
*/
|
||||
public void setPosition(int x, int y) {
|
||||
this.xPosition = x;
|
||||
this.yPosition = y;
|
||||
}
|
||||
|
||||
/**
|
||||
* Draw the text field. Alias for drawTextBox() for API compatibility.
|
||||
*/
|
||||
public void draw(int mouseX, int mouseY) {
|
||||
drawTextBox();
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle key typed. Alias for textboxKeyTyped() for API compatibility.
|
||||
*/
|
||||
public boolean keyTyped(char c, int keyCode) {
|
||||
return textboxKeyTyped(c, keyCode);
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle mouse click with boolean return.
|
||||
* GuiNpcTextField.mouseClicked returns void, so we wrap it.
|
||||
*/
|
||||
public boolean handleClick(int mouseX, int mouseY, int button) {
|
||||
boolean wasInside = isInside(mouseX, mouseY);
|
||||
super.mouseClicked(mouseX, mouseY, button);
|
||||
return wasInside && button == 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set max length. Alias for setMaxStringLength() for API compatibility.
|
||||
*/
|
||||
public ModernTextField setMaxLength(int max) {
|
||||
setMaxStringLength(max);
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set placeholder text (note: GuiNpcTextField doesn't display placeholders,
|
||||
* but we keep the method for API compatibility).
|
||||
*/
|
||||
public ModernTextField setPlaceholder(String placeholder) {
|
||||
this.placeholder = placeholder != null ? placeholder : "";
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get placeholder text.
|
||||
*/
|
||||
public String getPlaceholder() {
|
||||
return placeholder;
|
||||
}
|
||||
|
||||
// === Position/Size Getters ===
|
||||
|
||||
public int getX() { return xPosition; }
|
||||
public int getY() { return yPosition; }
|
||||
public int getWidth() { return width; }
|
||||
public int getHeight() { return height; }
|
||||
|
||||
/**
|
||||
* Check if a point is inside this field.
|
||||
*/
|
||||
public boolean isInside(int mouseX, int mouseY) {
|
||||
return mouseX >= xPosition && mouseX < xPosition + width &&
|
||||
mouseY >= yPosition && mouseY < yPosition + height;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set enabled state.
|
||||
*/
|
||||
public void setEnabled(boolean enabled) {
|
||||
this.enabled = enabled;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set colors (no-op for compatibility, uses default MC styling).
|
||||
*/
|
||||
public ModernTextField setColors(int bg, int border, int text) {
|
||||
// GuiNpcTextField uses default styling
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set multi-line mode (no-op, use ModernTextArea for multi-line).
|
||||
*/
|
||||
public ModernTextField setMultiLine(boolean multi) {
|
||||
// Use ModernTextArea for multi-line
|
||||
return this;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,194 @@
|
||||
package kamkeel.npcs.client.gui.components;
|
||||
|
||||
import noppes.npcs.client.gui.util.ModernColors;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.gui.FontRenderer;
|
||||
import net.minecraft.client.gui.Gui;
|
||||
|
||||
/**
|
||||
* Modern toggle switch component.
|
||||
* A sliding on/off switch with animation.
|
||||
*/
|
||||
public class ModernToggle extends Gui {
|
||||
|
||||
// Identity
|
||||
protected int id;
|
||||
protected String label;
|
||||
|
||||
// State
|
||||
protected boolean value = false;
|
||||
protected boolean enabled = true;
|
||||
protected boolean hovered = false;
|
||||
|
||||
// Position
|
||||
protected int x, y;
|
||||
protected int toggleWidth = 36;
|
||||
protected int toggleHeight = 16;
|
||||
protected int labelGap = 6;
|
||||
|
||||
// Animation
|
||||
protected float animProgress = 0; // 0 = off, 1 = on
|
||||
protected float animSpeed = 0.25f;
|
||||
|
||||
// Colors
|
||||
protected int trackOff = ModernColors.TOGGLE_OFF;
|
||||
protected int trackOn = ModernColors.TOGGLE_ON;
|
||||
protected int knobColor = ModernColors.TOGGLE_KNOB;
|
||||
protected int labelColor = ModernColors.TEXT_LIGHT;
|
||||
protected int labelColorDisabled = ModernColors.TEXT_DARK;
|
||||
|
||||
public ModernToggle(int id, int x, int y, String label, boolean value) {
|
||||
this.id = id;
|
||||
this.x = x;
|
||||
this.y = y;
|
||||
this.label = label;
|
||||
this.value = value;
|
||||
this.animProgress = value ? 1.0f : 0.0f;
|
||||
}
|
||||
|
||||
// === Drawing ===
|
||||
|
||||
public void draw(int mouseX, int mouseY) {
|
||||
FontRenderer fr = Minecraft.getMinecraft().fontRenderer;
|
||||
|
||||
// Update animation
|
||||
float target = value ? 1.0f : 0.0f;
|
||||
if (Math.abs(animProgress - target) > 0.01f) {
|
||||
animProgress += (target - animProgress) * animSpeed;
|
||||
} else {
|
||||
animProgress = target;
|
||||
}
|
||||
|
||||
// Check hover on toggle
|
||||
hovered = enabled && mouseX >= x && mouseX < x + toggleWidth &&
|
||||
mouseY >= y && mouseY < y + toggleHeight;
|
||||
|
||||
// Draw label first (to the left)
|
||||
if (label != null && !label.isEmpty()) {
|
||||
int labelY = y + (toggleHeight - fr.FONT_HEIGHT) / 2;
|
||||
int labelX = x - labelGap - fr.getStringWidth(label);
|
||||
fr.drawString(label, labelX, labelY, enabled ? labelColor : labelColorDisabled);
|
||||
}
|
||||
|
||||
// Interpolate track color
|
||||
int trackColor = ModernColors.blend(trackOff, trackOn, animProgress);
|
||||
if (!enabled) {
|
||||
trackColor = ModernColors.darken(trackColor, 0.4f);
|
||||
}
|
||||
|
||||
// Draw track (rounded rectangle approximation)
|
||||
int radius = toggleHeight / 2;
|
||||
drawRect(x + radius, y, x + toggleWidth - radius, y + toggleHeight, trackColor);
|
||||
drawCircle(x + radius, y + radius, radius, trackColor);
|
||||
drawCircle(x + toggleWidth - radius, y + radius, radius, trackColor);
|
||||
|
||||
// Calculate knob position
|
||||
int knobRadius = radius - 2;
|
||||
int knobMinX = x + radius;
|
||||
int knobMaxX = x + toggleWidth - radius;
|
||||
int knobX = knobMinX + (int)((knobMaxX - knobMinX) * animProgress);
|
||||
|
||||
// Draw knob
|
||||
int knob = enabled ? knobColor : ModernColors.darken(knobColor, 0.3f);
|
||||
if (hovered) {
|
||||
knob = ModernColors.lighten(knob, 0.1f);
|
||||
}
|
||||
drawCircle(knobX, y + radius, knobRadius, knob);
|
||||
}
|
||||
|
||||
/**
|
||||
* Draw a filled circle (approximation using rectangles).
|
||||
*/
|
||||
protected void drawCircle(int cx, int cy, int radius, int color) {
|
||||
// Simple approximation - draw a series of horizontal lines
|
||||
for (int dy = -radius; dy <= radius; dy++) {
|
||||
int dx = (int) Math.sqrt(radius * radius - dy * dy);
|
||||
drawRect(cx - dx, cy + dy, cx + dx, cy + dy + 1, color);
|
||||
}
|
||||
}
|
||||
|
||||
// === Interaction ===
|
||||
|
||||
/**
|
||||
* Handle mouse click. Returns true if handled.
|
||||
*/
|
||||
public boolean mouseClicked(int mouseX, int mouseY, int button) {
|
||||
if (button != 0 || !enabled) return false;
|
||||
|
||||
// Check if toggle was clicked
|
||||
if (mouseX >= x && mouseX < x + toggleWidth &&
|
||||
mouseY >= y && mouseY < y + toggleHeight) {
|
||||
toggle();
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Toggle the value.
|
||||
*/
|
||||
public void toggle() {
|
||||
value = !value;
|
||||
}
|
||||
|
||||
// === Getters/Setters ===
|
||||
|
||||
public int getId() { return id; }
|
||||
public boolean getValue() { return value; }
|
||||
|
||||
public void setValue(boolean value) {
|
||||
this.value = value;
|
||||
// Don't reset animation - let it animate to new value
|
||||
}
|
||||
|
||||
public void setValueImmediate(boolean value) {
|
||||
this.value = value;
|
||||
this.animProgress = value ? 1.0f : 0.0f;
|
||||
}
|
||||
|
||||
public boolean isEnabled() { return enabled; }
|
||||
|
||||
public void setEnabled(boolean enabled) {
|
||||
this.enabled = enabled;
|
||||
}
|
||||
|
||||
public String getLabel() { return label; }
|
||||
|
||||
public void setLabel(String label) {
|
||||
this.label = label;
|
||||
}
|
||||
|
||||
public void setPosition(int x, int y) {
|
||||
this.x = x;
|
||||
this.y = y;
|
||||
}
|
||||
|
||||
public int getX() { return x; }
|
||||
public int getY() { return y; }
|
||||
public int getWidth() { return toggleWidth; }
|
||||
public int getHeight() { return toggleHeight; }
|
||||
|
||||
/**
|
||||
* Get total width including label.
|
||||
*/
|
||||
public int getTotalWidth(FontRenderer fr) {
|
||||
if (label == null || label.isEmpty()) {
|
||||
return toggleWidth;
|
||||
}
|
||||
return toggleWidth + labelGap + fr.getStringWidth(label);
|
||||
}
|
||||
|
||||
public ModernToggle setColors(int trackOff, int trackOn, int knob) {
|
||||
this.trackOff = trackOff;
|
||||
this.trackOn = trackOn;
|
||||
this.knobColor = knob;
|
||||
return this;
|
||||
}
|
||||
|
||||
public ModernToggle setSize(int width, int height) {
|
||||
this.toggleWidth = width;
|
||||
this.toggleHeight = height;
|
||||
return this;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,286 @@
|
||||
package kamkeel.npcs.client.gui.components;
|
||||
|
||||
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.gui.ScaledResolution;
|
||||
import org.lwjgl.opengl.GL11;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* A scrollable panel component for containing other UI elements.
|
||||
* Uses GL scissor for clipping content that overflows the panel bounds.
|
||||
*/
|
||||
public class ScrollPanel extends Gui {
|
||||
|
||||
// Position and size
|
||||
protected int x, y, width, height;
|
||||
|
||||
// Scroll state
|
||||
protected float scrollY = 0;
|
||||
protected float targetScrollY = 0;
|
||||
protected int contentHeight = 0;
|
||||
protected float scrollSpeed = 0.3f; // Lerp speed
|
||||
|
||||
// Scrollbar
|
||||
protected int scrollbarWidth = 6;
|
||||
protected boolean showScrollbar = true;
|
||||
protected boolean isDraggingScrollbar = false;
|
||||
protected int dragStartY;
|
||||
protected float dragStartScroll;
|
||||
|
||||
// Content elements (managed by owner, we just track height)
|
||||
protected List<ScrollPanelElement> elements = new ArrayList<>();
|
||||
|
||||
// Colors
|
||||
protected int backgroundColor = ModernColors.PANEL_BG_SOLID;
|
||||
protected int scrollbarBg = ModernColors.SCROLLBAR_BG;
|
||||
protected int scrollbarThumb = ModernColors.SCROLLBAR_THUMB;
|
||||
protected int scrollbarThumbHover = ModernColors.SCROLLBAR_THUMB_HOVER;
|
||||
|
||||
// State
|
||||
protected boolean hoveringScrollbar = false;
|
||||
|
||||
public ScrollPanel(int x, int y, int width, int height) {
|
||||
this.x = x;
|
||||
this.y = y;
|
||||
this.width = width;
|
||||
this.height = height;
|
||||
}
|
||||
|
||||
// === Position/Size ===
|
||||
|
||||
public void setBounds(int x, int y, int width, int height) {
|
||||
this.x = x;
|
||||
this.y = y;
|
||||
this.width = width;
|
||||
this.height = height;
|
||||
}
|
||||
|
||||
public void setContentHeight(int height) {
|
||||
this.contentHeight = height;
|
||||
// Clamp scroll if content shrunk
|
||||
float maxScroll = getMaxScroll();
|
||||
if (scrollY > maxScroll) {
|
||||
scrollY = maxScroll;
|
||||
targetScrollY = maxScroll;
|
||||
}
|
||||
}
|
||||
|
||||
public int getContentHeight() {
|
||||
return contentHeight;
|
||||
}
|
||||
|
||||
public int getScrollY() {
|
||||
return (int) scrollY;
|
||||
}
|
||||
|
||||
public void setScrollY(float scroll) {
|
||||
this.scrollY = Math.max(0, Math.min(scroll, getMaxScroll()));
|
||||
this.targetScrollY = scrollY;
|
||||
}
|
||||
|
||||
// === Drawing ===
|
||||
|
||||
/**
|
||||
* Begin drawing the scroll panel. Call this before drawing content.
|
||||
* Sets up GL scissor for clipping.
|
||||
*/
|
||||
public void beginDraw() {
|
||||
// Update scroll animation
|
||||
if (Math.abs(scrollY - targetScrollY) > 0.5f) {
|
||||
scrollY += (targetScrollY - scrollY) * scrollSpeed;
|
||||
} else {
|
||||
scrollY = targetScrollY;
|
||||
}
|
||||
|
||||
// Draw background
|
||||
drawRect(x, y, x + width, y + height, backgroundColor);
|
||||
|
||||
// Set up scissor (convert to screen coordinates)
|
||||
Minecraft mc = Minecraft.getMinecraft();
|
||||
ScaledResolution sr = new ScaledResolution(mc, mc.displayWidth, mc.displayHeight);
|
||||
int scale = sr.getScaleFactor();
|
||||
|
||||
int scissorX = x * scale;
|
||||
int scissorY = mc.displayHeight - (y + height) * scale;
|
||||
int scissorW = (width - (needsScrollbar() ? scrollbarWidth : 0)) * scale;
|
||||
int scissorH = height * scale;
|
||||
|
||||
GL11.glEnable(GL11.GL_SCISSOR_TEST);
|
||||
GL11.glScissor(scissorX, scissorY, scissorW, scissorH);
|
||||
|
||||
// Translate for scroll offset
|
||||
GL11.glPushMatrix();
|
||||
GL11.glTranslatef(0, -scrollY, 0);
|
||||
}
|
||||
|
||||
/**
|
||||
* End drawing the scroll panel. Call this after drawing content.
|
||||
* Disables GL scissor and draws scrollbar.
|
||||
*/
|
||||
public void endDraw(int mouseX, int mouseY) {
|
||||
GL11.glPopMatrix();
|
||||
GL11.glDisable(GL11.GL_SCISSOR_TEST);
|
||||
|
||||
// Draw scrollbar if needed
|
||||
if (needsScrollbar()) {
|
||||
drawScrollbar(mouseX, mouseY);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Draw the scrollbar.
|
||||
*/
|
||||
protected void drawScrollbar(int mouseX, int mouseY) {
|
||||
int sbX = x + width - scrollbarWidth;
|
||||
int sbY = y;
|
||||
int sbH = height;
|
||||
|
||||
// Track background
|
||||
drawRect(sbX, sbY, sbX + scrollbarWidth, sbY + sbH, scrollbarBg);
|
||||
|
||||
// Calculate thumb size and position
|
||||
float viewRatio = (float) height / contentHeight;
|
||||
int thumbH = Math.max(20, (int) (sbH * viewRatio));
|
||||
int maxThumbY = sbH - thumbH;
|
||||
int thumbY = (int) (maxThumbY * (scrollY / getMaxScroll()));
|
||||
|
||||
// Check hover
|
||||
hoveringScrollbar = mouseX >= sbX && mouseX < sbX + scrollbarWidth &&
|
||||
mouseY >= sbY + thumbY && mouseY < sbY + thumbY + thumbH;
|
||||
|
||||
// Draw thumb
|
||||
int thumbColor = (hoveringScrollbar || isDraggingScrollbar) ? scrollbarThumbHover : scrollbarThumb;
|
||||
drawRect(sbX + 1, sbY + thumbY, sbX + scrollbarWidth - 1, sbY + thumbY + thumbH, thumbColor);
|
||||
}
|
||||
|
||||
// === Scrolling ===
|
||||
|
||||
public boolean needsScrollbar() {
|
||||
return showScrollbar && contentHeight > height;
|
||||
}
|
||||
|
||||
public float getMaxScroll() {
|
||||
return Math.max(0, contentHeight - height);
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle mouse scroll wheel.
|
||||
* @param delta Scroll wheel delta (positive = scroll up)
|
||||
*/
|
||||
public void mouseScrolled(int delta) {
|
||||
if (!needsScrollbar()) return;
|
||||
|
||||
float scrollAmount = delta * 20;
|
||||
targetScrollY = Math.max(0, Math.min(targetScrollY - scrollAmount, getMaxScroll()));
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle mouse click. Returns true if handled.
|
||||
*/
|
||||
public boolean mouseClicked(int mouseX, int mouseY, int button) {
|
||||
if (button != 0) return false;
|
||||
|
||||
// Check scrollbar click
|
||||
if (needsScrollbar()) {
|
||||
int sbX = x + width - scrollbarWidth;
|
||||
if (mouseX >= sbX && mouseX < sbX + scrollbarWidth &&
|
||||
mouseY >= y && mouseY < y + height) {
|
||||
|
||||
// Calculate thumb position
|
||||
float viewRatio = (float) height / contentHeight;
|
||||
int thumbH = Math.max(20, (int) (height * viewRatio));
|
||||
int maxThumbY = height - thumbH;
|
||||
int thumbY = (int) (maxThumbY * (scrollY / getMaxScroll()));
|
||||
|
||||
if (mouseY >= y + thumbY && mouseY < y + thumbY + thumbH) {
|
||||
// Clicked on thumb - start dragging
|
||||
isDraggingScrollbar = true;
|
||||
dragStartY = mouseY;
|
||||
dragStartScroll = scrollY;
|
||||
} else {
|
||||
// Clicked on track - jump to position
|
||||
float clickRatio = (float) (mouseY - y - thumbH / 2) / (height - thumbH);
|
||||
clickRatio = Math.max(0, Math.min(1, clickRatio));
|
||||
targetScrollY = clickRatio * getMaxScroll();
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle mouse drag.
|
||||
*/
|
||||
public void mouseDragged(int mouseX, int mouseY) {
|
||||
if (isDraggingScrollbar) {
|
||||
int deltaY = mouseY - dragStartY;
|
||||
float viewRatio = (float) height / contentHeight;
|
||||
int thumbH = Math.max(20, (int) (height * viewRatio));
|
||||
int maxThumbY = height - thumbH;
|
||||
|
||||
float scrollDelta = (deltaY / (float) maxThumbY) * getMaxScroll();
|
||||
scrollY = Math.max(0, Math.min(dragStartScroll + scrollDelta, getMaxScroll()));
|
||||
targetScrollY = scrollY;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle mouse release.
|
||||
*/
|
||||
public void mouseReleased(int mouseX, int mouseY) {
|
||||
isDraggingScrollbar = false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if a point is inside the panel content area.
|
||||
*/
|
||||
public boolean isInside(int mouseX, int mouseY) {
|
||||
return mouseX >= x && mouseX < x + width &&
|
||||
mouseY >= y && mouseY < y + height;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if a point is inside the content area (excluding scrollbar).
|
||||
*/
|
||||
public boolean isInsideContent(int mouseX, int mouseY) {
|
||||
int contentW = width - (needsScrollbar() ? scrollbarWidth : 0);
|
||||
return mouseX >= x && mouseX < x + contentW &&
|
||||
mouseY >= y && mouseY < y + height;
|
||||
}
|
||||
|
||||
/**
|
||||
* Transform a screen Y coordinate to content Y coordinate.
|
||||
*/
|
||||
public int toContentY(int screenY) {
|
||||
return (int) (screenY + scrollY);
|
||||
}
|
||||
|
||||
/**
|
||||
* Transform a content Y coordinate to screen Y coordinate.
|
||||
*/
|
||||
public int toScreenY(int contentY) {
|
||||
return (int) (contentY - scrollY);
|
||||
}
|
||||
|
||||
// === Getters ===
|
||||
|
||||
public int getX() { return x; }
|
||||
public int getY() { return y; }
|
||||
public int getWidth() { return width; }
|
||||
public int getHeight() { return height; }
|
||||
public int getContentWidth() { return width - (needsScrollbar() ? scrollbarWidth : 0); }
|
||||
|
||||
// === Simple element interface ===
|
||||
|
||||
public interface ScrollPanelElement {
|
||||
int getHeight();
|
||||
void draw(int x, int y, int width, int mouseX, int mouseY);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,514 @@
|
||||
package kamkeel.npcs.client.gui.modern;
|
||||
|
||||
import kamkeel.npcs.client.gui.components.*;
|
||||
import kamkeel.npcs.client.gui.modern.tabs.*;
|
||||
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 net.minecraft.client.gui.Gui;
|
||||
import net.minecraft.client.gui.ScaledResolution;
|
||||
import noppes.npcs.controllers.data.Dialog;
|
||||
import org.lwjgl.opengl.GL11;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Complete dialog editor panel v2 with 5 tabs.
|
||||
* Now refactored to use separate tab classes for better organization.
|
||||
*
|
||||
* Tabs:
|
||||
* 0 - Text (title, dialog text)
|
||||
* 1 - Options (6 option slots)
|
||||
* 2 - Feedback (sound, visual options)
|
||||
* 3 - Settings (quest, mail, command)
|
||||
* 4 - Availability (requirements)
|
||||
*/
|
||||
public class DialogEditorPanel extends Gui {
|
||||
|
||||
// === Layout ===
|
||||
protected int x, y, width, height;
|
||||
protected int headerHeight = 22;
|
||||
protected int tabBarHeight = 20;
|
||||
protected int footerHeight = 24;
|
||||
protected int padding = 4;
|
||||
|
||||
// === State ===
|
||||
protected Dialog dialog;
|
||||
protected boolean dirty = false;
|
||||
protected int currentTab = 0;
|
||||
protected float scrollY = 0;
|
||||
protected float targetScrollY = 0;
|
||||
protected int contentHeight = 0;
|
||||
|
||||
// === Tab Names ===
|
||||
protected static final String[] TAB_NAMES = {"Text", "Options", "Feedback", "Settings", "Availability"};
|
||||
|
||||
// === Tabs ===
|
||||
protected DialogTextTab textTab;
|
||||
protected DialogOptionsTab optionsTab;
|
||||
protected DialogFeedbackTab feedbackTab;
|
||||
protected DialogSettingsTab settingsTab;
|
||||
protected DialogAvailabilityTab availabilityTab;
|
||||
protected DialogEditorTab[] tabs;
|
||||
|
||||
// === Tab hover ===
|
||||
protected int hoveredTab = -1;
|
||||
|
||||
// === Listener ===
|
||||
protected IDialogEditorListener listener;
|
||||
|
||||
// === Scrollbar ===
|
||||
protected int scrollbarWidth = 6;
|
||||
protected boolean isDraggingScrollbar = false;
|
||||
protected int dragStartY;
|
||||
protected float dragStartScroll;
|
||||
|
||||
// === Footer ===
|
||||
protected boolean hoverTestBtn = false;
|
||||
protected boolean hoverSaveBtn = false;
|
||||
protected int saveBtnX, saveBtnY, saveBtnW, saveBtnH;
|
||||
|
||||
public DialogEditorPanel(int x, int y, int width, int height) {
|
||||
this.x = x;
|
||||
this.y = y;
|
||||
this.width = width;
|
||||
this.height = height;
|
||||
initTabs();
|
||||
}
|
||||
|
||||
// === Tab Initialization ===
|
||||
|
||||
protected void initTabs() {
|
||||
textTab = new DialogTextTab(this);
|
||||
optionsTab = new DialogOptionsTab(this);
|
||||
feedbackTab = new DialogFeedbackTab(this);
|
||||
settingsTab = new DialogSettingsTab(this);
|
||||
availabilityTab = new DialogAvailabilityTab(this);
|
||||
|
||||
tabs = new DialogEditorTab[] {
|
||||
textTab, optionsTab, feedbackTab, settingsTab, availabilityTab
|
||||
};
|
||||
}
|
||||
|
||||
// === Data Loading ===
|
||||
|
||||
public void setDialog(Dialog dialog) {
|
||||
this.dialog = dialog;
|
||||
this.dirty = false;
|
||||
this.scrollY = 0;
|
||||
this.targetScrollY = 0;
|
||||
|
||||
for (DialogEditorTab tab : tabs) {
|
||||
tab.setDialog(dialog);
|
||||
tab.loadFromDialog(dialog);
|
||||
}
|
||||
}
|
||||
|
||||
// === Data Saving ===
|
||||
|
||||
public void saveToDialog() {
|
||||
if (dialog == null) return;
|
||||
|
||||
for (DialogEditorTab tab : tabs) {
|
||||
tab.saveToDialog(dialog);
|
||||
}
|
||||
|
||||
dirty = false;
|
||||
}
|
||||
|
||||
// === Drawing ===
|
||||
|
||||
public void draw(int mouseX, int mouseY) {
|
||||
if (dialog == null) {
|
||||
drawNoSelection();
|
||||
return;
|
||||
}
|
||||
|
||||
FontRenderer fr = Minecraft.getMinecraft().fontRenderer;
|
||||
|
||||
// Update scroll animation
|
||||
if (Math.abs(scrollY - targetScrollY) > 0.5f) {
|
||||
scrollY += (targetScrollY - scrollY) * 0.3f;
|
||||
} else {
|
||||
scrollY = targetScrollY;
|
||||
}
|
||||
|
||||
// Background
|
||||
drawRect(x, y, x + width, y + height, ModernColors.PANEL_BG_SOLID);
|
||||
|
||||
// Header
|
||||
drawHeader(mouseX, mouseY, fr);
|
||||
|
||||
// Tab bar
|
||||
drawTabBar(mouseX, mouseY, fr);
|
||||
|
||||
// Content area with scissor
|
||||
int contentY = y + headerHeight + tabBarHeight;
|
||||
int contentAreaH = height - headerHeight - tabBarHeight - footerHeight;
|
||||
|
||||
Minecraft mc = Minecraft.getMinecraft();
|
||||
ScaledResolution sr = new ScaledResolution(mc, mc.displayWidth, mc.displayHeight);
|
||||
int scale = sr.getScaleFactor();
|
||||
|
||||
// Update screen positions for all dropdowns BEFORE scroll translation
|
||||
updateDropdownScreenPositions();
|
||||
|
||||
GL11.glEnable(GL11.GL_SCISSOR_TEST);
|
||||
GL11.glScissor(x * scale, mc.displayHeight - (contentY + contentAreaH) * scale,
|
||||
(width - scrollbarWidth) * scale, contentAreaH * scale);
|
||||
|
||||
GL11.glPushMatrix();
|
||||
GL11.glTranslatef(0, -scrollY, 0);
|
||||
|
||||
// Draw current tab content
|
||||
int contentX = x + padding;
|
||||
int contentW = width - padding * 2 - scrollbarWidth;
|
||||
int startY = y + headerHeight + tabBarHeight + padding;
|
||||
contentHeight = tabs[currentTab].draw(contentX, contentW, startY, mouseX, (int)(mouseY + scrollY), fr);
|
||||
|
||||
GL11.glPopMatrix();
|
||||
GL11.glDisable(GL11.GL_SCISSOR_TEST);
|
||||
|
||||
// Clamp scroll position when content height changes
|
||||
int maxScroll = Math.max(0, contentHeight - contentAreaH);
|
||||
if (scrollY > maxScroll) {
|
||||
scrollY = maxScroll;
|
||||
targetScrollY = maxScroll;
|
||||
}
|
||||
|
||||
// Draw scrollbar
|
||||
if (contentHeight > contentAreaH) {
|
||||
drawScrollbar(mouseX, mouseY, contentY, contentAreaH);
|
||||
}
|
||||
|
||||
// Draw expanded dropdowns in SCREEN SPACE (no translation!)
|
||||
drawExpandedDropdownsScreenSpace(mouseX, mouseY);
|
||||
|
||||
// Footer
|
||||
drawFooter(mouseX, mouseY, fr);
|
||||
}
|
||||
|
||||
protected void drawNoSelection() {
|
||||
FontRenderer fr = Minecraft.getMinecraft().fontRenderer;
|
||||
drawRect(x, y, x + width, y + height, ModernColors.PANEL_BG_SOLID);
|
||||
String msg = "Select a dialog to edit";
|
||||
int msgW = fr.getStringWidth(msg);
|
||||
fr.drawString(msg, x + (width - msgW) / 2, y + height / 2, ModernColors.TEXT_DARK);
|
||||
}
|
||||
|
||||
protected void drawHeader(int mouseX, int mouseY, FontRenderer fr) {
|
||||
drawRect(x, y, x + width, y + headerHeight, ModernColors.TOP_BAR_BG);
|
||||
|
||||
String title = dialog.title;
|
||||
if (title.length() > 20) title = title.substring(0, 17) + "...";
|
||||
if (dirty) title = "* " + title;
|
||||
|
||||
fr.drawString(title, x + padding, y + (headerHeight - fr.FONT_HEIGHT) / 2,
|
||||
dirty ? ModernColors.DIRTY_INDICATOR : ModernColors.TEXT_WHITE);
|
||||
|
||||
String idStr = "#" + dialog.id;
|
||||
int idW = fr.getStringWidth(idStr);
|
||||
fr.drawString(idStr, x + width - padding - idW, y + (headerHeight - fr.FONT_HEIGHT) / 2,
|
||||
ModernColors.TEXT_GRAY);
|
||||
}
|
||||
|
||||
protected void drawTabBar(int mouseX, int mouseY, FontRenderer fr) {
|
||||
int tabY = y + headerHeight;
|
||||
int tabW = width / TAB_NAMES.length;
|
||||
|
||||
hoveredTab = -1;
|
||||
|
||||
for (int i = 0; i < TAB_NAMES.length; i++) {
|
||||
int tabX = x + i * tabW;
|
||||
boolean active = i == currentTab;
|
||||
boolean hovered = mouseX >= tabX && mouseX < tabX + tabW &&
|
||||
mouseY >= tabY && mouseY < tabY + tabBarHeight;
|
||||
|
||||
if (hovered) hoveredTab = i;
|
||||
|
||||
int bg = active ? ModernColors.BUTTON_BG_PRESSED : (hovered ? ModernColors.BUTTON_BG_HOVER : ModernColors.BUTTON_BG);
|
||||
drawRect(tabX, tabY, tabX + tabW, tabY + tabBarHeight, bg);
|
||||
|
||||
String text = TAB_NAMES[i];
|
||||
int textW = fr.getStringWidth(text);
|
||||
fr.drawString(text, tabX + (tabW - textW) / 2, tabY + (tabBarHeight - fr.FONT_HEIGHT) / 2,
|
||||
active ? ModernColors.TEXT_WHITE : ModernColors.TEXT_LIGHT);
|
||||
|
||||
if (active) {
|
||||
drawRect(tabX, tabY + tabBarHeight - 2, tabX + tabW, tabY + tabBarHeight, ModernColors.ACCENT_BLUE);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected void drawScrollbar(int mouseX, int mouseY, int contentY, int contentAreaH) {
|
||||
int sbX = x + width - scrollbarWidth;
|
||||
drawRect(sbX, contentY, sbX + scrollbarWidth, contentY + contentAreaH, ModernColors.SCROLLBAR_BG);
|
||||
|
||||
float viewRatio = (float) contentAreaH / contentHeight;
|
||||
int thumbH = Math.max(20, (int)(contentAreaH * viewRatio));
|
||||
int maxScroll = contentHeight - contentAreaH;
|
||||
int thumbY = maxScroll > 0 ? (int)((contentAreaH - thumbH) * (scrollY / maxScroll)) : 0;
|
||||
|
||||
boolean hoverThumb = mouseX >= sbX && mouseX < sbX + scrollbarWidth &&
|
||||
mouseY >= contentY + thumbY && mouseY < contentY + thumbY + thumbH;
|
||||
int thumbColor = (hoverThumb || isDraggingScrollbar) ? ModernColors.SCROLLBAR_THUMB_HOVER : ModernColors.SCROLLBAR_THUMB;
|
||||
drawRect(sbX + 1, contentY + thumbY, sbX + scrollbarWidth - 1, contentY + thumbY + thumbH, thumbColor);
|
||||
}
|
||||
|
||||
protected void drawFooter(int mouseX, int mouseY, FontRenderer fr) {
|
||||
int footerY = y + height - footerHeight;
|
||||
drawRect(x, footerY, x + width, y + height, ModernColors.SECTION_HEADER_BG);
|
||||
|
||||
// Test button on the right
|
||||
String testText = "Test";
|
||||
int testW = fr.getStringWidth(testText) + 8;
|
||||
int testH = footerHeight - 6;
|
||||
int testX = x + width - testW - 6;
|
||||
int testY = footerY + 3;
|
||||
|
||||
hoverTestBtn = mouseX >= testX && mouseX < testX + testW &&
|
||||
mouseY >= testY && mouseY < testY + testH;
|
||||
|
||||
int testBg = hoverTestBtn ? ModernColors.BUTTON_BG_HOVER : ModernColors.BUTTON_BG;
|
||||
drawRect(testX, testY, testX + testW, testY + testH, testBg);
|
||||
drawRect(testX, testY, testX + testW, testY + 1, ModernColors.ACCENT_BLUE);
|
||||
fr.drawString(testText, testX + 4, testY + (testH - fr.FONT_HEIGHT) / 2 + 1, ModernColors.TEXT_LIGHT);
|
||||
|
||||
// Save hint/button
|
||||
String saveText = dirty ? "Ctrl+S to Save" : "No changes";
|
||||
int saveW = fr.getStringWidth(saveText);
|
||||
int saveX = x + (width - testW - 10 - saveW) / 2;
|
||||
int saveY = footerY + (footerHeight - fr.FONT_HEIGHT) / 2;
|
||||
|
||||
saveBtnX = saveX - 4;
|
||||
saveBtnY = saveY - 2;
|
||||
saveBtnW = saveW + 8;
|
||||
saveBtnH = fr.FONT_HEIGHT + 4;
|
||||
|
||||
hoverSaveBtn = dirty && mouseX >= saveBtnX && mouseX < saveBtnX + saveBtnW &&
|
||||
mouseY >= saveBtnY && mouseY < saveBtnY + saveBtnH;
|
||||
|
||||
if (dirty && hoverSaveBtn) {
|
||||
drawRect(saveBtnX, saveBtnY, saveBtnX + saveBtnW, saveBtnY + saveBtnH, ModernColors.BUTTON_BG_HOVER);
|
||||
}
|
||||
|
||||
fr.drawString(saveText, saveX, saveY, dirty ? (hoverSaveBtn ? ModernColors.ACCENT_GREEN : ModernColors.ACCENT_ORANGE) : ModernColors.TEXT_DARK);
|
||||
}
|
||||
|
||||
// === Dropdown Handling ===
|
||||
|
||||
protected void updateDropdownScreenPositions() {
|
||||
for (ModernDropdown dropdown : getAllDropdowns()) {
|
||||
int screenDropdownY = dropdown.getY() - (int)scrollY;
|
||||
dropdown.setScreenPosition(dropdown.getX(), screenDropdownY);
|
||||
}
|
||||
}
|
||||
|
||||
protected void drawExpandedDropdownsScreenSpace(int mouseX, int mouseY) {
|
||||
for (ModernDropdown dropdown : getAllDropdowns()) {
|
||||
if (dropdown.isExpanded()) {
|
||||
dropdown.drawOverlayScreenSpace(mouseX, mouseY);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected List<ModernDropdown> getAllDropdowns() {
|
||||
List<ModernDropdown> all = new ArrayList<>();
|
||||
for (DialogEditorTab tab : tabs) {
|
||||
all.addAll(tab.getDropdowns());
|
||||
}
|
||||
return all;
|
||||
}
|
||||
|
||||
protected void closeAllDropdowns() {
|
||||
for (ModernDropdown dropdown : getAllDropdowns()) {
|
||||
dropdown.close();
|
||||
}
|
||||
}
|
||||
|
||||
// === Interaction ===
|
||||
|
||||
public boolean mouseClicked(int mouseX, int mouseY, int button) {
|
||||
if (dialog == null) return false;
|
||||
|
||||
// Tab clicks
|
||||
if (hoveredTab >= 0 && mouseY >= y + headerHeight && mouseY < y + headerHeight + tabBarHeight) {
|
||||
currentTab = hoveredTab;
|
||||
scrollY = 0;
|
||||
targetScrollY = 0;
|
||||
closeAllDropdowns();
|
||||
return true;
|
||||
}
|
||||
|
||||
// Footer clicks
|
||||
int footerY = y + height - footerHeight;
|
||||
if (mouseY >= footerY && mouseY < y + height) {
|
||||
if (hoverTestBtn && listener != null) {
|
||||
listener.onTestRequested();
|
||||
return true;
|
||||
}
|
||||
if (hoverSaveBtn && dirty && listener != null) {
|
||||
listener.onSaveRequested();
|
||||
return true;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
// Scrollbar
|
||||
int contentY = y + headerHeight + tabBarHeight;
|
||||
int contentAreaH = height - headerHeight - tabBarHeight - footerHeight;
|
||||
int sbX = x + width - scrollbarWidth;
|
||||
if (contentHeight > contentAreaH && mouseX >= sbX && mouseX < sbX + scrollbarWidth) {
|
||||
isDraggingScrollbar = true;
|
||||
dragStartY = mouseY;
|
||||
dragStartScroll = scrollY;
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Adjust mouseY for scroll (for components inside scrollable content)
|
||||
int adjMouseY = (int)(mouseY + scrollY);
|
||||
|
||||
// Delegate to current tab
|
||||
return tabs[currentTab].mouseClicked(mouseX, adjMouseY, button);
|
||||
}
|
||||
|
||||
public boolean keyTyped(char c, int keyCode) {
|
||||
if (dialog == null) return false;
|
||||
return tabs[currentTab].keyTyped(c, keyCode);
|
||||
}
|
||||
|
||||
public void mouseScrolled(int delta) {
|
||||
int contentAreaH = height - headerHeight - tabBarHeight - footerHeight;
|
||||
if (contentHeight <= contentAreaH) return;
|
||||
|
||||
int maxScroll = contentHeight - contentAreaH;
|
||||
targetScrollY = Math.max(0, Math.min(targetScrollY - delta * 20, maxScroll));
|
||||
}
|
||||
|
||||
public void mouseReleased(int mouseX, int mouseY) {
|
||||
isDraggingScrollbar = false;
|
||||
// Let text areas handle mouse release
|
||||
textTab.getTextArea().mouseReleased(mouseX, mouseY);
|
||||
settingsTab.getCommandArea().mouseReleased(mouseX, mouseY);
|
||||
}
|
||||
|
||||
public void mouseDragged(int mouseX, int mouseY) {
|
||||
if (isDraggingScrollbar) {
|
||||
int contentY = y + headerHeight + tabBarHeight;
|
||||
int contentAreaH = height - headerHeight - tabBarHeight - footerHeight;
|
||||
int maxScroll = contentHeight - contentAreaH;
|
||||
|
||||
float viewRatio = (float) contentAreaH / contentHeight;
|
||||
int thumbH = Math.max(20, (int)(contentAreaH * viewRatio));
|
||||
int trackH = contentAreaH - thumbH;
|
||||
|
||||
if (trackH > 0) {
|
||||
int deltaY = mouseY - dragStartY;
|
||||
float scrollDelta = (deltaY / (float)trackH) * maxScroll;
|
||||
scrollY = Math.max(0, Math.min(dragStartScroll + scrollDelta, maxScroll));
|
||||
targetScrollY = scrollY;
|
||||
}
|
||||
}
|
||||
textTab.getTextArea().mouseDragged(mouseX, mouseY);
|
||||
settingsTab.getCommandArea().mouseDragged(mouseX, mouseY);
|
||||
}
|
||||
|
||||
public void updateScreen() {
|
||||
for (DialogEditorTab tab : tabs) {
|
||||
tab.updateScreen();
|
||||
}
|
||||
}
|
||||
|
||||
// === Option Management ===
|
||||
|
||||
public void removeOption(int slot) {
|
||||
optionsTab.removeOption(slot);
|
||||
}
|
||||
|
||||
// === Utility ===
|
||||
|
||||
public void markDirty() { dirty = true; }
|
||||
public void clearDirty() { dirty = false; }
|
||||
public boolean isDirty() { return dirty; }
|
||||
public Dialog getDialog() { return dialog; }
|
||||
public IDialogEditorListener getListener() { return listener; }
|
||||
|
||||
public boolean isInside(int mouseX, int mouseY) {
|
||||
return mouseX >= x && mouseX < x + width && mouseY >= y && mouseY < y + height;
|
||||
}
|
||||
|
||||
public void setBounds(int x, int y, int width, int height) {
|
||||
this.x = x;
|
||||
this.y = y;
|
||||
this.width = width;
|
||||
this.height = height;
|
||||
}
|
||||
|
||||
public void setListener(IDialogEditorListener listener) {
|
||||
this.listener = listener;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get available content height for tabs to use for sizing components.
|
||||
*/
|
||||
public int getAvailableContentHeight() {
|
||||
return height - headerHeight - tabBarHeight - footerHeight;
|
||||
}
|
||||
|
||||
// === Selection Callbacks ===
|
||||
|
||||
public void onQuestSelected(int slot, int questId, String questName) {
|
||||
if (slot == 0) {
|
||||
settingsTab.onQuestSelected(questId, questName);
|
||||
} else {
|
||||
availabilityTab.onQuestSelected(slot, questId, questName);
|
||||
}
|
||||
}
|
||||
|
||||
public void onDialogSelected(int slot, int dialogId, String dialogName) {
|
||||
availabilityTab.onDialogSelected(slot, dialogId, dialogName);
|
||||
}
|
||||
|
||||
public void onFactionSelected(int slot, int factionId, String factionName) {
|
||||
availabilityTab.onFactionSelected(slot, factionId, factionName);
|
||||
}
|
||||
|
||||
public void onSoundSelected(String soundPath) {
|
||||
feedbackTab.onSoundSelected(soundPath);
|
||||
}
|
||||
|
||||
public void onColorSelected(int slot, int color) {
|
||||
if (slot < 100) {
|
||||
feedbackTab.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;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void onOptionDialogSelected(int optionSlot, int dialogId, String dialogName) {
|
||||
optionsTab.onOptionDialogSelected(optionSlot, dialogId, dialogName);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,215 @@
|
||||
package kamkeel.npcs.client.gui.modern;
|
||||
|
||||
import noppes.npcs.client.gui.util.ModernColors;
|
||||
import noppes.npcs.client.gui.util.GuiNPCInterface;
|
||||
import noppes.npcs.client.gui.util.GuiUtil;
|
||||
import noppes.npcs.client.gui.util.ICustomScrollListener;
|
||||
import noppes.npcs.client.gui.util.ISubGuiListener;
|
||||
|
||||
/**
|
||||
* Abstract base class for fullscreen modern GUIs.
|
||||
* Provides a configurable three-panel layout (left nav, center content, right actions)
|
||||
* with percentage-based sizing, panel backgrounds/borders, and an optional resizable divider.
|
||||
*
|
||||
* Subclasses override abstract hooks to populate each panel region.
|
||||
* Designed for reuse across Dialog Tree, Cloner, Quest Manager, etc.
|
||||
*
|
||||
* Renamed from GuiDirectory for the Modern GUI system.
|
||||
*/
|
||||
public abstract class GuiModernScreen extends GuiNPCInterface implements ICustomScrollListener, ISubGuiListener {
|
||||
|
||||
// ===== LAYOUT CONFIG (subclasses may override in constructor) =====
|
||||
protected float leftPanelPercent = 0.20f;
|
||||
protected float rightPanelPercent = 0.10f;
|
||||
protected int minLeftPanelW = 80;
|
||||
protected int minRightPanelW = 40;
|
||||
protected int minCenterW = 100;
|
||||
|
||||
// ===== LAYOUT CONSTANTS =====
|
||||
protected int pad = 10;
|
||||
protected int topBarH = 24;
|
||||
protected int gap = 4;
|
||||
protected int btnH = 20;
|
||||
|
||||
// ===== PANEL COLORS (using ModernColors) =====
|
||||
protected int panelBg = ModernColors.PANEL_BG;
|
||||
protected int panelBorder = ModernColors.PANEL_BORDER;
|
||||
protected int topBarBg = ModernColors.TOP_BAR_BG;
|
||||
|
||||
// ===== COMPUTED LAYOUT (populated by computeLayout) =====
|
||||
protected int originX, originY, usableW, usableH;
|
||||
protected int leftPanelW, rightPanelW;
|
||||
protected int contentX, contentY, contentW, contentH;
|
||||
protected int rightX;
|
||||
|
||||
// ===== OPTIONAL RESIZABLE DIVIDER (between left and center) =====
|
||||
protected boolean enableDivider = false;
|
||||
protected int dividerWidth = 5;
|
||||
protected int dividerLineHeight = 20;
|
||||
protected int minDividerPanelW = 50;
|
||||
private int dividerOffset;
|
||||
private boolean isDragging = false;
|
||||
private int dragStartX;
|
||||
|
||||
// ===== CONSTRUCTOR =====
|
||||
public GuiModernScreen() {
|
||||
super();
|
||||
closeOnEsc = true;
|
||||
drawDefaultBackground = true;
|
||||
}
|
||||
|
||||
// ===== LAYOUT COMPUTATION =====
|
||||
protected void computeLayout() {
|
||||
originX = pad;
|
||||
originY = pad;
|
||||
usableW = width - 2 * pad;
|
||||
usableH = height - 2 * pad;
|
||||
|
||||
leftPanelW = Math.max(minLeftPanelW, (int)(usableW * leftPanelPercent));
|
||||
rightPanelW = Math.max(minRightPanelW, (int)(usableW * rightPanelPercent));
|
||||
|
||||
if (rightPanelPercent <= 0) {
|
||||
rightPanelW = 0;
|
||||
}
|
||||
|
||||
int gapCount = rightPanelW > 0 ? 3 : 2;
|
||||
contentW = usableW - leftPanelW - rightPanelW - gapCount * gap;
|
||||
if (contentW < minCenterW) {
|
||||
contentW = minCenterW;
|
||||
}
|
||||
|
||||
contentX = originX + leftPanelW + gap;
|
||||
contentY = originY + topBarH + gap;
|
||||
contentH = usableH - topBarH - gap;
|
||||
rightX = contentX + contentW + gap;
|
||||
|
||||
if (enableDivider && dividerOffset == 0) {
|
||||
dividerOffset = leftPanelW;
|
||||
}
|
||||
}
|
||||
|
||||
// ===== INIT GUI =====
|
||||
@Override
|
||||
public void initGui() {
|
||||
super.initGui();
|
||||
computeLayout();
|
||||
initTopBar(originY + 2);
|
||||
initLeftPanel();
|
||||
initCenterPanel();
|
||||
if (rightPanelW > 0) {
|
||||
initRightPanel(contentY + 4);
|
||||
}
|
||||
}
|
||||
|
||||
// ===== DRAWING =====
|
||||
@Override
|
||||
public void drawScreen(int mouseX, int mouseY, float partialTicks) {
|
||||
drawTopBar();
|
||||
drawPanels();
|
||||
super.drawScreen(mouseX, mouseY, partialTicks);
|
||||
// Draw divider AFTER super.drawScreen() so it renders on top of GUI elements
|
||||
if (enableDivider) {
|
||||
drawDivider(mouseX, mouseY);
|
||||
}
|
||||
drawOverlay(mouseX, mouseY, partialTicks);
|
||||
}
|
||||
|
||||
protected void drawTopBar() {
|
||||
GuiUtil.drawRectD(originX, originY, originX + usableW, originY + topBarH, topBarBg);
|
||||
}
|
||||
|
||||
protected void drawPanels() {
|
||||
// Left nav panel border
|
||||
GuiUtil.drawRectD(originX - 1, contentY - 1, originX + leftPanelW + 1, originY + usableH + 1, panelBorder);
|
||||
|
||||
// Right action panel border (if present)
|
||||
if (rightPanelW > 0) {
|
||||
GuiUtil.drawRectD(rightX - 1, contentY - 1, rightX + rightPanelW + 1, originY + usableH + 1, panelBorder);
|
||||
}
|
||||
}
|
||||
|
||||
protected void drawDivider(int mouseX, int mouseY) {
|
||||
if (!enableDivider) return;
|
||||
int divX = originX + dividerOffset;
|
||||
int regionTop = contentY;
|
||||
int regionHeight = contentH;
|
||||
int handleTop = regionTop + (regionHeight - dividerLineHeight) / 2;
|
||||
drawRect(divX + 1, handleTop, divX + dividerWidth - 1, handleTop + dividerLineHeight, 0xFF707070);
|
||||
}
|
||||
|
||||
/** Override for extra drawing after super.drawScreen (e.g. status text) */
|
||||
protected void drawOverlay(int mouseX, int mouseY, float partialTicks) {
|
||||
}
|
||||
|
||||
// ===== DIVIDER MOUSE HANDLING =====
|
||||
@Override
|
||||
public void mouseClicked(int mouseX, int mouseY, int mouseButton) {
|
||||
if (enableDivider && !hasSubGui()) {
|
||||
int divX = originX + dividerOffset;
|
||||
int regionTop = contentY;
|
||||
int handleTop = regionTop + (contentH - dividerLineHeight) / 2;
|
||||
int handleBottom = handleTop + dividerLineHeight;
|
||||
if (mouseX >= divX && mouseX <= divX + dividerWidth &&
|
||||
mouseY >= handleTop && mouseY <= handleBottom) {
|
||||
isDragging = true;
|
||||
resizingActive = true;
|
||||
dragStartX = mouseX;
|
||||
return;
|
||||
}
|
||||
}
|
||||
super.mouseClicked(mouseX, mouseY, mouseButton);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void mouseClickMove(int mouseX, int mouseY, int clickedMouseButton, long timeSinceLastClick) {
|
||||
if (isDragging) {
|
||||
int dx = mouseX - dragStartX;
|
||||
dragStartX = mouseX;
|
||||
dividerOffset += dx;
|
||||
|
||||
int maxOffset = (usableW - (rightPanelW > 0 ? rightPanelW + gap : 0)) - dividerWidth - minDividerPanelW;
|
||||
dividerOffset = Math.max(minDividerPanelW, Math.min(dividerOffset, maxOffset));
|
||||
|
||||
onDividerMoved(dividerOffset);
|
||||
return;
|
||||
}
|
||||
super.mouseClickMove(mouseX, mouseY, clickedMouseButton, timeSinceLastClick);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void mouseMovedOrUp(int mouseX, int mouseY, int state) {
|
||||
if (isDragging) {
|
||||
isDragging = false;
|
||||
resizingActive = false;
|
||||
return;
|
||||
}
|
||||
super.mouseMovedOrUp(mouseX, mouseY, state);
|
||||
}
|
||||
|
||||
/** Called when divider is dragged. Override to update scroll sizes. */
|
||||
protected void onDividerMoved(int newOffset) {
|
||||
}
|
||||
|
||||
// Accessors for divider offset
|
||||
protected int getDividerOffset() {
|
||||
return dividerOffset;
|
||||
}
|
||||
|
||||
protected void setDividerOffset(int offset) {
|
||||
this.dividerOffset = offset;
|
||||
}
|
||||
|
||||
// ===== ABSTRACT HOOKS (subclass must implement) =====
|
||||
|
||||
/** Populate top bar buttons. topBtnY is the y-coordinate for the button row. */
|
||||
protected abstract void initTopBar(int topBtnY);
|
||||
|
||||
/** Populate the left navigation panel (scrolls, search fields, buttons). */
|
||||
protected abstract void initLeftPanel();
|
||||
|
||||
/** Populate the center content panel (main scroll list). */
|
||||
protected abstract void initCenterPanel();
|
||||
|
||||
/** Populate the right action panel. startY is the first button y-coordinate. */
|
||||
protected abstract void initRightPanel(int startY);
|
||||
}
|
||||
@@ -0,0 +1,552 @@
|
||||
package kamkeel.npcs.client.gui.modern;
|
||||
|
||||
import kamkeel.npcs.client.gui.components.ModernButton;
|
||||
import kamkeel.npcs.client.gui.components.ModernTextField;
|
||||
import kamkeel.npcs.network.PacketClient;
|
||||
import kamkeel.npcs.network.packets.request.animation.AnimationsGetPacket;
|
||||
import noppes.npcs.client.gui.util.ModernColors;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.gui.ScaledResolution;
|
||||
import noppes.npcs.client.gui.util.IScrollData;
|
||||
import noppes.npcs.constants.EnumScrollData;
|
||||
import org.lwjgl.opengl.GL11;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
/**
|
||||
* Modern styled animation selector.
|
||||
* Two-column layout: Built-in animations | Custom animations
|
||||
* Features search fields, double-click selection, and draggable divider.
|
||||
*/
|
||||
public class ModernAnimationSelector extends ModernSubGuiInterface implements IScrollData {
|
||||
|
||||
// Selected values to return
|
||||
public int selectedAnimationId = -1;
|
||||
public String selectedBuiltInName = "";
|
||||
|
||||
// Data maps
|
||||
private HashMap<String, Integer> builtInData = new HashMap<>();
|
||||
private HashMap<String, Integer> customData = new HashMap<>();
|
||||
|
||||
// Filtered lists for display
|
||||
private List<String> filteredBuiltIn = new ArrayList<>();
|
||||
private List<String> filteredCustom = new ArrayList<>();
|
||||
|
||||
// Components
|
||||
private ModernTextField builtInSearchField;
|
||||
private ModernTextField customSearchField;
|
||||
private ModernButton doneBtn;
|
||||
private ModernButton cancelBtn;
|
||||
private ModernButton clearBtn;
|
||||
|
||||
// Scroll state
|
||||
private int builtInScrollY = 0;
|
||||
private int customScrollY = 0;
|
||||
private int selectedBuiltInIndex = -1;
|
||||
private int selectedCustomIndex = -1;
|
||||
|
||||
// Layout
|
||||
private int listY;
|
||||
private int listHeight;
|
||||
private int builtInListX, builtInListW;
|
||||
private int customListX, customListW;
|
||||
private int rowHeight = 14;
|
||||
|
||||
// Draggable divider
|
||||
private int dividerOffset;
|
||||
private boolean isDraggingDivider = false;
|
||||
private int dividerDragStartX;
|
||||
private int dividerWidth = 5;
|
||||
private int minColumnWidth = 80;
|
||||
|
||||
// Search strings
|
||||
private String builtInSearch = "";
|
||||
private String customSearch = "";
|
||||
|
||||
// Initial values
|
||||
private int initialAnimationId;
|
||||
private String initialAnimationName;
|
||||
|
||||
// Double-click tracking
|
||||
private long lastClickTime = 0;
|
||||
private int lastClickedIndex = -1;
|
||||
private boolean lastClickWasBuiltIn = false;
|
||||
|
||||
// Button IDs
|
||||
private static final int ID_DONE = 100;
|
||||
private static final int ID_CANCEL = 101;
|
||||
private static final int ID_CLEAR = 102;
|
||||
|
||||
/**
|
||||
* Constructor for selecting by ID (user animations).
|
||||
*/
|
||||
public ModernAnimationSelector(int animationId) {
|
||||
this(animationId, "");
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructor for selecting by name (built-in) or ID (user).
|
||||
*/
|
||||
public ModernAnimationSelector(int animationId, String animationName) {
|
||||
xSize = 420;
|
||||
ySize = 280;
|
||||
setHeaderTitle("Select Animation");
|
||||
|
||||
this.initialAnimationId = animationId;
|
||||
this.initialAnimationName = animationName != null ? animationName : "";
|
||||
this.selectedAnimationId = animationId;
|
||||
this.selectedBuiltInName = this.initialAnimationName;
|
||||
|
||||
// Request animation data from server
|
||||
PacketClient.sendClient(new AnimationsGetPacket());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setData(Vector<String> list, HashMap<String, Integer> data, EnumScrollData type) {
|
||||
if (type == EnumScrollData.BUILTIN_ANIMATIONS) {
|
||||
this.builtInData = data;
|
||||
|
||||
// Check if initial name matches a built-in animation
|
||||
if (!initialAnimationName.isEmpty()) {
|
||||
for (String name : builtInData.keySet()) {
|
||||
if (name.equalsIgnoreCase(initialAnimationName)) {
|
||||
selectedBuiltInName = name;
|
||||
selectedAnimationId = -1;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
updateBuiltInList();
|
||||
if (!selectedBuiltInName.isEmpty()) {
|
||||
selectedBuiltInIndex = filteredBuiltIn.indexOf(selectedBuiltInName);
|
||||
}
|
||||
} else if (type == EnumScrollData.ANIMATIONS) {
|
||||
this.customData = data;
|
||||
|
||||
// Find the name for our initial animation ID
|
||||
if (selectedBuiltInName.isEmpty() && initialAnimationId >= 0) {
|
||||
for (String name : data.keySet()) {
|
||||
if (data.get(name) == initialAnimationId) {
|
||||
updateCustomList();
|
||||
selectedCustomIndex = filteredCustom.indexOf(name);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
updateCustomList();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setSelected(String selected) {
|
||||
// Not used
|
||||
}
|
||||
|
||||
@Override
|
||||
public void initGui() {
|
||||
super.initGui();
|
||||
|
||||
int contentY = getContentY() + 6;
|
||||
int contentH = getContentHeight() - 6;
|
||||
|
||||
// Initialize divider offset if not set
|
||||
if (dividerOffset == 0) {
|
||||
dividerOffset = (xSize - 24) / 2;
|
||||
}
|
||||
|
||||
// Layout calculations
|
||||
int pad = 8;
|
||||
builtInListX = guiLeft + pad;
|
||||
builtInListW = dividerOffset - pad;
|
||||
customListX = guiLeft + dividerOffset + dividerWidth;
|
||||
customListW = xSize - dividerOffset - dividerWidth - pad;
|
||||
|
||||
// Enforce minimum widths
|
||||
if (builtInListW < minColumnWidth) {
|
||||
builtInListW = minColumnWidth;
|
||||
dividerOffset = builtInListW + pad;
|
||||
customListX = guiLeft + dividerOffset + dividerWidth;
|
||||
customListW = xSize - dividerOffset - dividerWidth - pad;
|
||||
}
|
||||
if (customListW < minColumnWidth) {
|
||||
customListW = minColumnWidth;
|
||||
dividerOffset = xSize - pad - dividerWidth - customListW;
|
||||
builtInListW = dividerOffset - pad;
|
||||
customListX = guiLeft + dividerOffset + dividerWidth;
|
||||
}
|
||||
|
||||
// Search fields at top
|
||||
int searchH = 18;
|
||||
builtInSearchField = new ModernTextField(0, builtInListX, contentY, builtInListW, searchH);
|
||||
builtInSearchField.setPlaceholder("Filter built-in...");
|
||||
builtInSearchField.setText(builtInSearch);
|
||||
|
||||
customSearchField = new ModernTextField(1, customListX, contentY, customListW, searchH);
|
||||
customSearchField.setPlaceholder("Filter custom...");
|
||||
customSearchField.setText(customSearch);
|
||||
|
||||
// List area below search
|
||||
listY = contentY + searchH + 4;
|
||||
listHeight = contentH - searchH - 36 - 8;
|
||||
|
||||
// Buttons at bottom
|
||||
int btnY = guiTop + ySize - 32;
|
||||
int btnWidth = 60;
|
||||
int btnGap = 8;
|
||||
|
||||
clearBtn = new ModernButton(ID_CLEAR, guiLeft + pad, btnY, btnWidth, 20, "Clear");
|
||||
cancelBtn = new ModernButton(ID_CANCEL, guiLeft + xSize - pad - btnWidth * 2 - btnGap, btnY, btnWidth, 20, "Cancel");
|
||||
doneBtn = new ModernButton(ID_DONE, guiLeft + xSize - pad - btnWidth, btnY, btnWidth, 20, "Done");
|
||||
doneBtn.setBackgroundColor(ModernColors.ACCENT_BLUE);
|
||||
|
||||
// Update lists
|
||||
updateBuiltInList();
|
||||
updateCustomList();
|
||||
|
||||
// Set initial selection indices
|
||||
if (!selectedBuiltInName.isEmpty()) {
|
||||
selectedBuiltInIndex = filteredBuiltIn.indexOf(selectedBuiltInName);
|
||||
}
|
||||
if (selectedAnimationId >= 0 && selectedBuiltInName.isEmpty()) {
|
||||
for (String name : customData.keySet()) {
|
||||
if (customData.get(name) == selectedAnimationId) {
|
||||
selectedCustomIndex = filteredCustom.indexOf(name);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void updateBuiltInList() {
|
||||
if (builtInSearch.isEmpty()) {
|
||||
filteredBuiltIn = new ArrayList<>(builtInData.keySet());
|
||||
} else {
|
||||
filteredBuiltIn = new ArrayList<>();
|
||||
String searchLower = builtInSearch.toLowerCase();
|
||||
for (String name : builtInData.keySet()) {
|
||||
if (name.toLowerCase().contains(searchLower)) {
|
||||
filteredBuiltIn.add(name);
|
||||
}
|
||||
}
|
||||
}
|
||||
Collections.sort(filteredBuiltIn);
|
||||
}
|
||||
|
||||
private void updateCustomList() {
|
||||
if (customSearch.isEmpty()) {
|
||||
filteredCustom = new ArrayList<>(customData.keySet());
|
||||
} else {
|
||||
filteredCustom = new ArrayList<>();
|
||||
String searchLower = customSearch.toLowerCase();
|
||||
for (String name : customData.keySet()) {
|
||||
if (name.toLowerCase().contains(searchLower)) {
|
||||
filteredCustom.add(name);
|
||||
}
|
||||
}
|
||||
}
|
||||
Collections.sort(filteredCustom);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void drawContent(int mouseX, int mouseY, float partialTicks) {
|
||||
// Draw column headers
|
||||
int headerY = getContentY() - 2;
|
||||
fontRendererObj.drawString("Built-in Animations", builtInListX, headerY - 10, ModernColors.TEXT_LIGHT);
|
||||
fontRendererObj.drawString("Custom Animations", customListX, headerY - 10, ModernColors.TEXT_LIGHT);
|
||||
|
||||
// Draw search fields
|
||||
builtInSearchField.draw(mouseX, mouseY);
|
||||
customSearchField.draw(mouseX, mouseY);
|
||||
|
||||
// Draw list backgrounds
|
||||
drawRect(builtInListX, listY, builtInListX + builtInListW, listY + listHeight, ModernColors.INPUT_BG);
|
||||
drawRect(customListX, listY, customListX + customListW, listY + listHeight, ModernColors.INPUT_BG);
|
||||
|
||||
// Draw divider handle
|
||||
int divX = guiLeft + dividerOffset;
|
||||
int handleTop = listY + (listHeight - 20) / 2;
|
||||
int handleColor = isDraggingDivider ? ModernColors.ACCENT_BLUE : 0xFF707070;
|
||||
drawRect(divX + 1, handleTop, divX + dividerWidth - 1, handleTop + 20, handleColor);
|
||||
|
||||
// Draw built-in list
|
||||
drawList(builtInListX, listY, builtInListW, listHeight, filteredBuiltIn, selectedBuiltInIndex,
|
||||
builtInScrollY, mouseX, mouseY, true);
|
||||
|
||||
// Draw custom list
|
||||
drawList(customListX, listY, customListW, listHeight, filteredCustom, selectedCustomIndex,
|
||||
customScrollY, mouseX, mouseY, false);
|
||||
|
||||
// Draw selected animation info
|
||||
String info = "";
|
||||
if (!selectedBuiltInName.isEmpty()) {
|
||||
info = "Selected: " + selectedBuiltInName + " (Built-in)";
|
||||
} else if (selectedAnimationId >= 0) {
|
||||
String name = getCustomNameForId(selectedAnimationId);
|
||||
info = "Selected: " + (name != null ? name : "Unknown") + " (ID: " + selectedAnimationId + ")";
|
||||
}
|
||||
if (!info.isEmpty()) {
|
||||
int infoY = listY + listHeight + 4;
|
||||
fontRendererObj.drawString(info, guiLeft + 8, infoY, ModernColors.TEXT_GRAY);
|
||||
}
|
||||
|
||||
// Draw buttons
|
||||
clearBtn.drawButton(mc, mouseX, mouseY);
|
||||
doneBtn.drawButton(mc, mouseX, mouseY);
|
||||
cancelBtn.drawButton(mc, mouseX, mouseY);
|
||||
}
|
||||
|
||||
private String getCustomNameForId(int id) {
|
||||
for (Map.Entry<String, Integer> entry : customData.entrySet()) {
|
||||
if (entry.getValue() == id) {
|
||||
return entry.getKey();
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
private void drawList(int x, int y, int w, int h, List<String> items, int selectedIdx,
|
||||
int scrollY, int mouseX, int mouseY, boolean isBuiltIn) {
|
||||
Minecraft mc = Minecraft.getMinecraft();
|
||||
ScaledResolution sr = new ScaledResolution(mc, mc.displayWidth, mc.displayHeight);
|
||||
int scale = sr.getScaleFactor();
|
||||
|
||||
GL11.glEnable(GL11.GL_SCISSOR_TEST);
|
||||
GL11.glScissor(x * scale, mc.displayHeight - (y + h) * scale, w * scale, h * scale);
|
||||
|
||||
int visibleRows = h / rowHeight;
|
||||
int startIdx = scrollY / rowHeight;
|
||||
int endIdx = Math.min(startIdx + visibleRows + 2, items.size());
|
||||
|
||||
for (int i = startIdx; i < endIdx; i++) {
|
||||
int rowY = y + i * rowHeight - scrollY;
|
||||
if (rowY + rowHeight < y || rowY > y + h) continue;
|
||||
|
||||
if (i == selectedIdx) {
|
||||
drawRect(x, rowY, x + w, rowY + rowHeight, ModernColors.SELECTION_BG);
|
||||
} else {
|
||||
if (mouseX >= x && mouseX < x + w && mouseY >= rowY && mouseY < rowY + rowHeight) {
|
||||
drawRect(x, rowY, x + w, rowY + rowHeight, ModernColors.HOVER_HIGHLIGHT);
|
||||
}
|
||||
}
|
||||
|
||||
String text = items.get(i);
|
||||
String displayText = fontRendererObj.trimStringToWidth(text, w - 4);
|
||||
int textColor = i == selectedIdx ? ModernColors.TEXT_WHITE : ModernColors.TEXT_LIGHT;
|
||||
fontRendererObj.drawString(displayText, x + 2, rowY + 2, textColor);
|
||||
}
|
||||
|
||||
GL11.glDisable(GL11.GL_SCISSOR_TEST);
|
||||
|
||||
// Draw scrollbar if needed
|
||||
int totalHeight = items.size() * rowHeight;
|
||||
if (totalHeight > h) {
|
||||
int sbX = x + w - 4;
|
||||
float viewRatio = (float) h / totalHeight;
|
||||
int thumbH = Math.max(10, (int) (h * viewRatio));
|
||||
float maxScroll = totalHeight - h;
|
||||
int thumbY = maxScroll > 0 ? (int) ((scrollY / maxScroll) * (h - thumbH)) : 0;
|
||||
|
||||
drawRect(sbX, y, sbX + 4, y + h, ModernColors.SCROLLBAR_BG);
|
||||
drawRect(sbX, y + thumbY, sbX + 4, y + thumbY + thumbH, ModernColors.SCROLLBAR_THUMB);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateScreen() {
|
||||
super.updateScreen();
|
||||
builtInSearchField.updateCursorCounter();
|
||||
customSearchField.updateCursorCounter();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void mouseClicked(int mouseX, int mouseY, int button) {
|
||||
super.mouseClicked(mouseX, mouseY, button);
|
||||
|
||||
// Check divider drag start
|
||||
if (button == 0) {
|
||||
int divX = guiLeft + dividerOffset;
|
||||
if (mouseX >= divX && mouseX < divX + dividerWidth &&
|
||||
mouseY >= listY && mouseY < listY + listHeight) {
|
||||
isDraggingDivider = true;
|
||||
dividerDragStartX = mouseX;
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
// Check search field clicks
|
||||
builtInSearchField.mouseClicked(mouseX, mouseY, button);
|
||||
customSearchField.mouseClicked(mouseX, mouseY, button);
|
||||
|
||||
// Check built-in list click
|
||||
if (button == 0 && mouseX >= builtInListX && mouseX < builtInListX + builtInListW &&
|
||||
mouseY >= listY && mouseY < listY + listHeight) {
|
||||
int clickedIdx = (mouseY - listY + builtInScrollY) / rowHeight;
|
||||
if (clickedIdx >= 0 && clickedIdx < filteredBuiltIn.size()) {
|
||||
// Double-click detection
|
||||
long now = System.currentTimeMillis();
|
||||
if (clickedIdx == lastClickedIndex && lastClickWasBuiltIn && now - lastClickTime < 400) {
|
||||
confirm();
|
||||
return;
|
||||
}
|
||||
lastClickedIndex = clickedIdx;
|
||||
lastClickTime = now;
|
||||
lastClickWasBuiltIn = true;
|
||||
|
||||
selectedBuiltInIndex = clickedIdx;
|
||||
selectedBuiltInName = filteredBuiltIn.get(clickedIdx);
|
||||
selectedAnimationId = -1;
|
||||
selectedCustomIndex = -1;
|
||||
}
|
||||
}
|
||||
|
||||
// Check custom list click
|
||||
if (button == 0 && mouseX >= customListX && mouseX < customListX + customListW &&
|
||||
mouseY >= listY && mouseY < listY + listHeight) {
|
||||
int clickedIdx = (mouseY - listY + customScrollY) / rowHeight;
|
||||
if (clickedIdx >= 0 && clickedIdx < filteredCustom.size()) {
|
||||
// Double-click detection
|
||||
long now = System.currentTimeMillis();
|
||||
if (clickedIdx == lastClickedIndex && !lastClickWasBuiltIn && now - lastClickTime < 400) {
|
||||
confirm();
|
||||
return;
|
||||
}
|
||||
lastClickedIndex = clickedIdx;
|
||||
lastClickTime = now;
|
||||
lastClickWasBuiltIn = false;
|
||||
|
||||
selectedCustomIndex = clickedIdx;
|
||||
String name = filteredCustom.get(clickedIdx);
|
||||
selectedAnimationId = customData.get(name);
|
||||
selectedBuiltInName = "";
|
||||
selectedBuiltInIndex = -1;
|
||||
}
|
||||
}
|
||||
|
||||
// Check button clicks
|
||||
if (clearBtn.mousePressed(mc, mouseX, mouseY)) {
|
||||
selectedBuiltInName = "";
|
||||
selectedAnimationId = -1;
|
||||
selectedBuiltInIndex = -1;
|
||||
selectedCustomIndex = -1;
|
||||
close();
|
||||
return;
|
||||
}
|
||||
if (doneBtn.mousePressed(mc, mouseX, mouseY)) {
|
||||
confirm();
|
||||
return;
|
||||
}
|
||||
if (cancelBtn.mousePressed(mc, mouseX, mouseY)) {
|
||||
selectedAnimationId = initialAnimationId;
|
||||
selectedBuiltInName = initialAnimationName;
|
||||
close();
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void mouseClickMove(int mouseX, int mouseY, int button, long timeSinceLastClick) {
|
||||
if (isDraggingDivider) {
|
||||
int dx = mouseX - dividerDragStartX;
|
||||
dividerDragStartX = mouseX;
|
||||
dividerOffset += dx;
|
||||
|
||||
int pad = 8;
|
||||
int minOffset = pad + minColumnWidth;
|
||||
int maxOffset = xSize - pad - dividerWidth - minColumnWidth;
|
||||
dividerOffset = Math.max(minOffset, Math.min(dividerOffset, maxOffset));
|
||||
|
||||
builtInListW = dividerOffset - pad;
|
||||
customListX = guiLeft + dividerOffset + dividerWidth;
|
||||
customListW = xSize - dividerOffset - dividerWidth - pad;
|
||||
|
||||
builtInSearchField.setBounds(builtInListX, builtInSearchField.getY(), builtInListW, 18);
|
||||
customSearchField.setBounds(customListX, customSearchField.getY(), customListW, 18);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void mouseMovedOrUp(int mouseX, int mouseY, int state) {
|
||||
isDraggingDivider = false;
|
||||
super.mouseMovedOrUp(mouseX, mouseY, state);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void handleMouseInput() {
|
||||
super.handleMouseInput();
|
||||
|
||||
int delta = org.lwjgl.input.Mouse.getEventDWheel();
|
||||
if (delta != 0) {
|
||||
int mouseX = org.lwjgl.input.Mouse.getEventX() * width / mc.displayWidth;
|
||||
int mouseY = height - org.lwjgl.input.Mouse.getEventY() * height / mc.displayHeight - 1;
|
||||
|
||||
int scrollAmount = delta > 0 ? -rowHeight * 2 : rowHeight * 2;
|
||||
|
||||
if (mouseX >= builtInListX && mouseX < builtInListX + builtInListW &&
|
||||
mouseY >= listY && mouseY < listY + listHeight) {
|
||||
int maxScroll = Math.max(0, filteredBuiltIn.size() * rowHeight - listHeight);
|
||||
builtInScrollY = Math.max(0, Math.min(builtInScrollY + scrollAmount, maxScroll));
|
||||
}
|
||||
|
||||
if (mouseX >= customListX && mouseX < customListX + customListW &&
|
||||
mouseY >= listY && mouseY < listY + listHeight) {
|
||||
int maxScroll = Math.max(0, filteredCustom.size() * rowHeight - listHeight);
|
||||
customScrollY = Math.max(0, Math.min(customScrollY + scrollAmount, maxScroll));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void keyTyped(char typedChar, int keyCode) {
|
||||
if (builtInSearchField.isFocused()) {
|
||||
String prev = builtInSearchField.getText();
|
||||
builtInSearchField.keyTyped(typedChar, keyCode);
|
||||
String newText = builtInSearchField.getText();
|
||||
if (!newText.equals(prev)) {
|
||||
builtInSearch = newText;
|
||||
updateBuiltInList();
|
||||
builtInScrollY = 0;
|
||||
if (!selectedBuiltInName.isEmpty()) {
|
||||
selectedBuiltInIndex = filteredBuiltIn.indexOf(selectedBuiltInName);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (customSearchField.isFocused()) {
|
||||
String prev = customSearchField.getText();
|
||||
customSearchField.keyTyped(typedChar, keyCode);
|
||||
String newText = customSearchField.getText();
|
||||
if (!newText.equals(prev)) {
|
||||
customSearch = newText;
|
||||
updateCustomList();
|
||||
customScrollY = 0;
|
||||
String customName = getCustomNameForId(selectedAnimationId);
|
||||
if (customName != null) {
|
||||
selectedCustomIndex = filteredCustom.indexOf(customName);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
super.keyTyped(typedChar, keyCode);
|
||||
}
|
||||
|
||||
private void confirm() {
|
||||
close();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the name of the selected animation (for display purposes).
|
||||
*/
|
||||
public String getSelectedName() {
|
||||
if (!selectedBuiltInName.isEmpty()) {
|
||||
return selectedBuiltInName;
|
||||
}
|
||||
return getCustomNameForId(selectedAnimationId);
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if a built-in animation was selected.
|
||||
*/
|
||||
public boolean isBuiltInSelected() {
|
||||
return !selectedBuiltInName.isEmpty();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,496 @@
|
||||
package kamkeel.npcs.client.gui.modern;
|
||||
|
||||
import kamkeel.npcs.client.gui.components.ModernButton;
|
||||
import kamkeel.npcs.client.gui.components.ModernTextField;
|
||||
import noppes.npcs.client.gui.util.ModernColors;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.gui.ScaledResolution;
|
||||
import org.lwjgl.opengl.GL11;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
/**
|
||||
* Abstract base class for modern styled two-column selectors (categories | items).
|
||||
* Features draggable divider, search fields, and double-click selection.
|
||||
*
|
||||
* @param <C> Category type
|
||||
* @param <I> Item type
|
||||
*/
|
||||
public abstract class ModernCategorySelector<C, I> extends ModernSubGuiInterface {
|
||||
|
||||
// Selected values
|
||||
protected C selectedCategory;
|
||||
protected I selectedItem;
|
||||
|
||||
// Data maps
|
||||
protected HashMap<String, C> categoryData = new HashMap<>();
|
||||
protected HashMap<String, I> itemData = new HashMap<>();
|
||||
|
||||
// Lists for display
|
||||
protected List<String> filteredCategories = new ArrayList<>();
|
||||
protected List<String> filteredItems = new ArrayList<>();
|
||||
|
||||
// Components
|
||||
protected ModernTextField catSearchField;
|
||||
protected ModernTextField itemSearchField;
|
||||
protected ModernButton doneBtn;
|
||||
protected ModernButton cancelBtn;
|
||||
|
||||
// Scroll state
|
||||
protected int catScrollY = 0;
|
||||
protected int itemScrollY = 0;
|
||||
protected int selectedCatIndex = -1;
|
||||
protected int selectedItemIndex = -1;
|
||||
|
||||
// Layout
|
||||
protected int listY;
|
||||
protected int listHeight;
|
||||
protected int catListX, catListW;
|
||||
protected int itemListX, itemListW;
|
||||
protected int rowHeight = 14;
|
||||
|
||||
// Draggable divider
|
||||
protected int dividerOffset;
|
||||
protected boolean isDraggingDivider = false;
|
||||
protected int dividerDragStartX;
|
||||
protected int dividerWidth = 5;
|
||||
protected int minColumnWidth = 80;
|
||||
|
||||
// Search strings
|
||||
protected String catSearch = "";
|
||||
protected String itemSearch = "";
|
||||
|
||||
// Button IDs
|
||||
protected static final int ID_DONE = 100;
|
||||
protected static final int ID_CANCEL = 101;
|
||||
|
||||
// Double-click tracking
|
||||
protected long lastClickTime = 0;
|
||||
protected int lastClickedIndex = -1;
|
||||
|
||||
public ModernCategorySelector() {
|
||||
xSize = 420;
|
||||
ySize = 280;
|
||||
}
|
||||
|
||||
// ===== Abstract methods to be implemented by subclasses =====
|
||||
|
||||
/** Load all categories into categoryData map */
|
||||
protected abstract void loadAllCategories();
|
||||
|
||||
/** Load items for a specific category into itemData map */
|
||||
protected abstract void loadItemsForCategory(C category);
|
||||
|
||||
/** Get the display title for a category */
|
||||
protected abstract String getCategoryTitle(C category);
|
||||
|
||||
/** Get the display title for an item */
|
||||
protected abstract String getItemTitle(I item);
|
||||
|
||||
/** Get the ID of an item (for selection tracking) */
|
||||
protected abstract int getItemId(I item);
|
||||
|
||||
/** Get the header title for the SubGui */
|
||||
protected abstract String getHeaderTitle();
|
||||
|
||||
/** Get the column header for categories */
|
||||
protected abstract String getCategoryColumnTitle();
|
||||
|
||||
/** Get the column header for items */
|
||||
protected abstract String getItemColumnTitle();
|
||||
|
||||
/** Get the search placeholder for categories */
|
||||
protected String getCategorySearchPlaceholder() {
|
||||
return "Filter " + getCategoryColumnTitle().toLowerCase() + "...";
|
||||
}
|
||||
|
||||
/** Get the search placeholder for items */
|
||||
protected String getItemSearchPlaceholder() {
|
||||
return "Filter " + getItemColumnTitle().toLowerCase() + "...";
|
||||
}
|
||||
|
||||
// ===== Initialization =====
|
||||
|
||||
protected void loadData() {
|
||||
categoryData.clear();
|
||||
loadAllCategories();
|
||||
filteredCategories = new ArrayList<>(categoryData.keySet());
|
||||
Collections.sort(filteredCategories);
|
||||
}
|
||||
|
||||
protected void loadItemsForSelectedCategory() {
|
||||
itemData.clear();
|
||||
if (selectedCategory != null) {
|
||||
loadItemsForCategory(selectedCategory);
|
||||
}
|
||||
updateItemList();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void initGui() {
|
||||
super.initGui();
|
||||
|
||||
int contentY = getContentY() + 6;
|
||||
int contentH = getContentHeight() - 6;
|
||||
|
||||
// Initialize divider offset if not set
|
||||
if (dividerOffset == 0) {
|
||||
dividerOffset = (xSize - 24) / 2; // Default 50/50 split
|
||||
}
|
||||
|
||||
// Layout calculations with draggable divider
|
||||
int pad = 8;
|
||||
catListX = guiLeft + pad;
|
||||
catListW = dividerOffset - pad;
|
||||
itemListX = guiLeft + dividerOffset + dividerWidth;
|
||||
itemListW = xSize - dividerOffset - dividerWidth - pad;
|
||||
|
||||
// Enforce minimum widths
|
||||
if (catListW < minColumnWidth) {
|
||||
catListW = minColumnWidth;
|
||||
dividerOffset = catListW + pad;
|
||||
itemListX = guiLeft + dividerOffset + dividerWidth;
|
||||
itemListW = xSize - dividerOffset - dividerWidth - pad;
|
||||
}
|
||||
if (itemListW < minColumnWidth) {
|
||||
itemListW = minColumnWidth;
|
||||
dividerOffset = xSize - pad - dividerWidth - itemListW;
|
||||
catListW = dividerOffset - pad;
|
||||
itemListX = guiLeft + dividerOffset + dividerWidth;
|
||||
}
|
||||
|
||||
// Search fields at top
|
||||
int searchH = 18;
|
||||
catSearchField = new ModernTextField(0, catListX, contentY, catListW, searchH);
|
||||
catSearchField.setPlaceholder(getCategorySearchPlaceholder());
|
||||
catSearchField.setText(catSearch);
|
||||
|
||||
itemSearchField = new ModernTextField(1, itemListX, contentY, itemListW, searchH);
|
||||
itemSearchField.setPlaceholder(getItemSearchPlaceholder());
|
||||
itemSearchField.setText(itemSearch);
|
||||
|
||||
// List area below search
|
||||
listY = contentY + searchH + 4;
|
||||
listHeight = contentH - searchH - 36 - 8;
|
||||
|
||||
// Buttons at bottom
|
||||
int btnY = guiTop + ySize - 32;
|
||||
int btnWidth = 60;
|
||||
int btnGap = 8;
|
||||
|
||||
cancelBtn = new ModernButton(ID_CANCEL, guiLeft + xSize - pad - btnWidth * 2 - btnGap, btnY, btnWidth, 20, "Cancel");
|
||||
doneBtn = new ModernButton(ID_DONE, guiLeft + xSize - pad - btnWidth, btnY, btnWidth, 20, "Done");
|
||||
doneBtn.setBackgroundColor(ModernColors.ACCENT_BLUE);
|
||||
|
||||
// Set initial selection indices
|
||||
if (selectedCategory != null) {
|
||||
selectedCatIndex = filteredCategories.indexOf(getCategoryTitle(selectedCategory));
|
||||
}
|
||||
if (selectedItem != null) {
|
||||
selectedItemIndex = filteredItems.indexOf(getItemTitle(selectedItem));
|
||||
}
|
||||
}
|
||||
|
||||
protected void updateCategoryList() {
|
||||
if (catSearch.isEmpty()) {
|
||||
filteredCategories = new ArrayList<>(categoryData.keySet());
|
||||
} else {
|
||||
filteredCategories = new ArrayList<>();
|
||||
String searchLower = catSearch.toLowerCase();
|
||||
for (String name : categoryData.keySet()) {
|
||||
if (name.toLowerCase().contains(searchLower)) {
|
||||
filteredCategories.add(name);
|
||||
}
|
||||
}
|
||||
}
|
||||
Collections.sort(filteredCategories);
|
||||
}
|
||||
|
||||
protected void updateItemList() {
|
||||
if (itemSearch.isEmpty()) {
|
||||
filteredItems = new ArrayList<>(itemData.keySet());
|
||||
} else {
|
||||
filteredItems = new ArrayList<>();
|
||||
String searchLower = itemSearch.toLowerCase();
|
||||
for (String name : itemData.keySet()) {
|
||||
if (name.toLowerCase().contains(searchLower)) {
|
||||
filteredItems.add(name);
|
||||
}
|
||||
}
|
||||
}
|
||||
Collections.sort(filteredItems);
|
||||
}
|
||||
|
||||
// ===== Drawing =====
|
||||
|
||||
@Override
|
||||
protected void drawContent(int mouseX, int mouseY, float partialTicks) {
|
||||
// Draw column headers
|
||||
int headerY = getContentY() - 2;
|
||||
fontRendererObj.drawString(getCategoryColumnTitle(), catListX, headerY - 10, ModernColors.TEXT_LIGHT);
|
||||
fontRendererObj.drawString(getItemColumnTitle(), itemListX, headerY - 10, ModernColors.TEXT_LIGHT);
|
||||
|
||||
// Draw search fields
|
||||
catSearchField.draw(mouseX, mouseY);
|
||||
itemSearchField.draw(mouseX, mouseY);
|
||||
|
||||
// Draw list backgrounds
|
||||
drawRect(catListX, listY, catListX + catListW, listY + listHeight, ModernColors.INPUT_BG);
|
||||
drawRect(itemListX, listY, itemListX + itemListW, listY + listHeight, ModernColors.INPUT_BG);
|
||||
|
||||
// Draw divider handle
|
||||
int divX = guiLeft + dividerOffset;
|
||||
int handleTop = listY + (listHeight - 20) / 2;
|
||||
int handleColor = isDraggingDivider ? ModernColors.ACCENT_BLUE : 0xFF707070;
|
||||
drawRect(divX + 1, handleTop, divX + dividerWidth - 1, handleTop + 20, handleColor);
|
||||
|
||||
// Draw category list
|
||||
drawList(catListX, listY, catListW, listHeight, filteredCategories, selectedCatIndex,
|
||||
catScrollY, mouseX, mouseY);
|
||||
|
||||
// Draw item list
|
||||
drawList(itemListX, listY, itemListW, listHeight, filteredItems, selectedItemIndex,
|
||||
itemScrollY, mouseX, mouseY);
|
||||
|
||||
// Draw selected item info
|
||||
if (selectedItem != null) {
|
||||
String info = "Selected: " + getItemTitle(selectedItem) + " (ID: " + getItemId(selectedItem) + ")";
|
||||
int infoY = listY + listHeight + 4;
|
||||
fontRendererObj.drawString(info, guiLeft + 8, infoY, ModernColors.TEXT_GRAY);
|
||||
}
|
||||
|
||||
// Draw buttons
|
||||
doneBtn.drawButton(mc, mouseX, mouseY);
|
||||
cancelBtn.drawButton(mc, mouseX, mouseY);
|
||||
}
|
||||
|
||||
protected void drawList(int x, int y, int w, int h, List<String> items, int selectedIdx,
|
||||
int scrollY, int mouseX, int mouseY) {
|
||||
// Set up scissor
|
||||
Minecraft mc = Minecraft.getMinecraft();
|
||||
ScaledResolution sr = new ScaledResolution(mc, mc.displayWidth, mc.displayHeight);
|
||||
int scale = sr.getScaleFactor();
|
||||
|
||||
GL11.glEnable(GL11.GL_SCISSOR_TEST);
|
||||
GL11.glScissor(x * scale, mc.displayHeight - (y + h) * scale, w * scale, h * scale);
|
||||
|
||||
int visibleRows = h / rowHeight;
|
||||
int startIdx = scrollY / rowHeight;
|
||||
int endIdx = Math.min(startIdx + visibleRows + 2, items.size());
|
||||
|
||||
for (int i = startIdx; i < endIdx; i++) {
|
||||
int rowY = y + i * rowHeight - scrollY;
|
||||
if (rowY + rowHeight < y || rowY > y + h) continue;
|
||||
|
||||
// Draw selection background
|
||||
if (i == selectedIdx) {
|
||||
drawRect(x, rowY, x + w, rowY + rowHeight, ModernColors.SELECTION_BG);
|
||||
} else {
|
||||
// Hover highlight
|
||||
if (mouseX >= x && mouseX < x + w && mouseY >= rowY && mouseY < rowY + rowHeight) {
|
||||
drawRect(x, rowY, x + w, rowY + rowHeight, ModernColors.HOVER_HIGHLIGHT);
|
||||
}
|
||||
}
|
||||
|
||||
// Draw text
|
||||
String text = items.get(i);
|
||||
String displayText = fontRendererObj.trimStringToWidth(text, w - 4);
|
||||
int textColor = i == selectedIdx ? ModernColors.TEXT_WHITE : ModernColors.TEXT_LIGHT;
|
||||
fontRendererObj.drawString(displayText, x + 2, rowY + 2, textColor);
|
||||
}
|
||||
|
||||
GL11.glDisable(GL11.GL_SCISSOR_TEST);
|
||||
|
||||
// Draw scrollbar if needed
|
||||
int totalHeight = items.size() * rowHeight;
|
||||
if (totalHeight > h) {
|
||||
int sbX = x + w - 4;
|
||||
float viewRatio = (float) h / totalHeight;
|
||||
int thumbH = Math.max(10, (int) (h * viewRatio));
|
||||
float maxScroll = totalHeight - h;
|
||||
int thumbY = maxScroll > 0 ? (int) ((scrollY / maxScroll) * (h - thumbH)) : 0;
|
||||
|
||||
drawRect(sbX, y, sbX + 4, y + h, ModernColors.SCROLLBAR_BG);
|
||||
drawRect(sbX, y + thumbY, sbX + 4, y + thumbY + thumbH, ModernColors.SCROLLBAR_THUMB);
|
||||
}
|
||||
}
|
||||
|
||||
// ===== Interaction =====
|
||||
|
||||
@Override
|
||||
public void updateScreen() {
|
||||
super.updateScreen();
|
||||
catSearchField.updateCursorCounter();
|
||||
itemSearchField.updateCursorCounter();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void mouseClicked(int mouseX, int mouseY, int button) {
|
||||
super.mouseClicked(mouseX, mouseY, button);
|
||||
|
||||
// Check divider drag start
|
||||
if (button == 0) {
|
||||
int divX = guiLeft + dividerOffset;
|
||||
if (mouseX >= divX && mouseX < divX + dividerWidth &&
|
||||
mouseY >= listY && mouseY < listY + listHeight) {
|
||||
isDraggingDivider = true;
|
||||
dividerDragStartX = mouseX;
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
// Check search field clicks
|
||||
catSearchField.mouseClicked(mouseX, mouseY, button);
|
||||
itemSearchField.mouseClicked(mouseX, mouseY, button);
|
||||
|
||||
// Check category list click
|
||||
if (button == 0 && mouseX >= catListX && mouseX < catListX + catListW &&
|
||||
mouseY >= listY && mouseY < listY + listHeight) {
|
||||
int clickedIdx = (mouseY - listY + catScrollY) / rowHeight;
|
||||
if (clickedIdx >= 0 && clickedIdx < filteredCategories.size()) {
|
||||
selectedCatIndex = clickedIdx;
|
||||
String catName = filteredCategories.get(clickedIdx);
|
||||
selectedCategory = categoryData.get(catName);
|
||||
selectedItem = null;
|
||||
selectedItemIndex = -1;
|
||||
itemScrollY = 0;
|
||||
loadItemsForSelectedCategory();
|
||||
}
|
||||
}
|
||||
|
||||
// Check item list click
|
||||
if (button == 0 && mouseX >= itemListX && mouseX < itemListX + itemListW &&
|
||||
mouseY >= listY && mouseY < listY + listHeight) {
|
||||
int clickedIdx = (mouseY - listY + itemScrollY) / rowHeight;
|
||||
if (clickedIdx >= 0 && clickedIdx < filteredItems.size()) {
|
||||
// Double-click detection
|
||||
long now = System.currentTimeMillis();
|
||||
if (clickedIdx == lastClickedIndex && now - lastClickTime < 400) {
|
||||
// Double-click - confirm and close
|
||||
confirm();
|
||||
return;
|
||||
}
|
||||
lastClickedIndex = clickedIdx;
|
||||
lastClickTime = now;
|
||||
|
||||
selectedItemIndex = clickedIdx;
|
||||
String itemName = filteredItems.get(clickedIdx);
|
||||
selectedItem = itemData.get(itemName);
|
||||
}
|
||||
}
|
||||
|
||||
// Check button clicks
|
||||
if (doneBtn.mousePressed(mc, mouseX, mouseY)) {
|
||||
confirm();
|
||||
return;
|
||||
}
|
||||
if (cancelBtn.mousePressed(mc, mouseX, mouseY)) {
|
||||
selectedItem = null;
|
||||
close();
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void mouseClickMove(int mouseX, int mouseY, int button, long timeSinceLastClick) {
|
||||
if (isDraggingDivider) {
|
||||
int dx = mouseX - dividerDragStartX;
|
||||
dividerDragStartX = mouseX;
|
||||
dividerOffset += dx;
|
||||
|
||||
// Enforce minimum widths
|
||||
int pad = 8;
|
||||
int minOffset = pad + minColumnWidth;
|
||||
int maxOffset = xSize - pad - dividerWidth - minColumnWidth;
|
||||
dividerOffset = Math.max(minOffset, Math.min(dividerOffset, maxOffset));
|
||||
|
||||
// Recalculate column widths
|
||||
catListW = dividerOffset - pad;
|
||||
itemListX = guiLeft + dividerOffset + dividerWidth;
|
||||
itemListW = xSize - dividerOffset - dividerWidth - pad;
|
||||
|
||||
// Update search field widths
|
||||
catSearchField.setBounds(catListX, catSearchField.getY(), catListW, 18);
|
||||
itemSearchField.setBounds(itemListX, itemSearchField.getY(), itemListW, 18);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void mouseMovedOrUp(int mouseX, int mouseY, int state) {
|
||||
isDraggingDivider = false;
|
||||
super.mouseMovedOrUp(mouseX, mouseY, state);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void handleMouseInput() {
|
||||
super.handleMouseInput();
|
||||
|
||||
int delta = org.lwjgl.input.Mouse.getEventDWheel();
|
||||
if (delta != 0) {
|
||||
int mouseX = org.lwjgl.input.Mouse.getEventX() * width / mc.displayWidth;
|
||||
int mouseY = height - org.lwjgl.input.Mouse.getEventY() * height / mc.displayHeight - 1;
|
||||
|
||||
int scrollAmount = delta > 0 ? -rowHeight * 2 : rowHeight * 2;
|
||||
|
||||
// Check which list is hovered
|
||||
if (mouseX >= catListX && mouseX < catListX + catListW &&
|
||||
mouseY >= listY && mouseY < listY + listHeight) {
|
||||
int maxScroll = Math.max(0, filteredCategories.size() * rowHeight - listHeight);
|
||||
catScrollY = Math.max(0, Math.min(catScrollY + scrollAmount, maxScroll));
|
||||
}
|
||||
|
||||
if (mouseX >= itemListX && mouseX < itemListX + itemListW &&
|
||||
mouseY >= listY && mouseY < listY + listHeight) {
|
||||
int maxScroll = Math.max(0, filteredItems.size() * rowHeight - listHeight);
|
||||
itemScrollY = Math.max(0, Math.min(itemScrollY + scrollAmount, maxScroll));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void keyTyped(char typedChar, int keyCode) {
|
||||
// Handle category search field
|
||||
if (catSearchField.isFocused()) {
|
||||
String prev = catSearchField.getText();
|
||||
catSearchField.keyTyped(typedChar, keyCode);
|
||||
String newText = catSearchField.getText();
|
||||
if (!newText.equals(prev)) {
|
||||
catSearch = newText;
|
||||
updateCategoryList();
|
||||
catScrollY = 0;
|
||||
if (selectedCategory != null) {
|
||||
selectedCatIndex = filteredCategories.indexOf(getCategoryTitle(selectedCategory));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Handle item search field
|
||||
if (itemSearchField.isFocused()) {
|
||||
String prev = itemSearchField.getText();
|
||||
itemSearchField.keyTyped(typedChar, keyCode);
|
||||
String newText = itemSearchField.getText();
|
||||
if (!newText.equals(prev)) {
|
||||
itemSearch = newText;
|
||||
updateItemList();
|
||||
itemScrollY = 0;
|
||||
if (selectedItem != null) {
|
||||
selectedItemIndex = filteredItems.indexOf(getItemTitle(selectedItem));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Handle ESC
|
||||
super.keyTyped(typedChar, keyCode);
|
||||
}
|
||||
|
||||
protected void confirm() {
|
||||
close();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the selected item, or null if none selected.
|
||||
*/
|
||||
public I getSelectedItem() {
|
||||
return selectedItem;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,255 @@
|
||||
package kamkeel.npcs.client.gui.modern;
|
||||
|
||||
import kamkeel.npcs.client.gui.components.ModernButton;
|
||||
import kamkeel.npcs.client.gui.components.ModernTextField;
|
||||
import noppes.npcs.client.gui.util.ModernColors;
|
||||
import net.minecraft.client.gui.GuiButton;
|
||||
import net.minecraft.client.resources.IResource;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
import org.lwjgl.opengl.GL11;
|
||||
|
||||
import javax.imageio.ImageIO;
|
||||
import java.awt.image.BufferedImage;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
|
||||
/**
|
||||
* Modern styled color picker SubGui.
|
||||
* Features color wheel selection, hex input field, and color preview swatch.
|
||||
*/
|
||||
public class ModernColorPicker extends ModernSubGuiInterface {
|
||||
|
||||
private static final ResourceLocation COLOR_WHEEL = new ResourceLocation("customnpcs:textures/gui/color.png");
|
||||
|
||||
// Current selected color (RGB without alpha)
|
||||
public int color;
|
||||
|
||||
// Components
|
||||
private ModernTextField hexField;
|
||||
private ModernButton doneBtn;
|
||||
private ModernButton cancelBtn;
|
||||
|
||||
// Color wheel position
|
||||
private int wheelX, wheelY;
|
||||
private int wheelSize = 130; // Larger wheel
|
||||
|
||||
// Preview swatch position
|
||||
private int previewX, previewY;
|
||||
private int previewSize = 24; // Slightly smaller to fit better
|
||||
|
||||
// Button IDs
|
||||
private static final int ID_DONE = 100;
|
||||
private static final int ID_CANCEL = 101;
|
||||
|
||||
public ModernColorPicker(int initialColor) {
|
||||
this.color = initialColor & 0xFFFFFF; // Strip alpha
|
||||
xSize = 200; // Increased for comfortable layout
|
||||
ySize = 250; // Increased for proper spacing between content and buttons
|
||||
setHeaderTitle("Color Picker");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void initGui() {
|
||||
super.initGui();
|
||||
|
||||
// Calculate positions with more top padding
|
||||
int contentY = getContentY() + 12;
|
||||
int centerX = guiLeft + xSize / 2;
|
||||
|
||||
// Color wheel centered
|
||||
wheelX = centerX - wheelSize / 2;
|
||||
wheelY = contentY;
|
||||
|
||||
// Preview swatch and hex field below wheel with proper spacing
|
||||
int fieldRowY = wheelY + wheelSize + 14;
|
||||
previewX = guiLeft + 16; // Fixed left margin
|
||||
previewY = fieldRowY;
|
||||
|
||||
// Hex field next to preview
|
||||
hexField = new ModernTextField(0, previewX + previewSize + 12, fieldRowY, 100, 18);
|
||||
hexField.setMaxLength(6);
|
||||
hexField.setPlaceholder("RRGGBB");
|
||||
hexField.setText(getHexString());
|
||||
|
||||
// Buttons at bottom with proper margin
|
||||
int btnY = guiTop + ySize - 32;
|
||||
int btnWidth = 70; // Slightly wider buttons
|
||||
int totalBtnWidth = btnWidth * 2 + 10;
|
||||
int btnStartX = centerX - totalBtnWidth / 2;
|
||||
|
||||
cancelBtn = new ModernButton(ID_CANCEL, btnStartX, btnY, btnWidth, 20, "Cancel");
|
||||
doneBtn = new ModernButton(ID_DONE, btnStartX + btnWidth + 10, btnY, btnWidth, 20, "Done");
|
||||
|
||||
// Use accent color for Done button
|
||||
doneBtn.setBackgroundColor(ModernColors.ACCENT_BLUE);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void drawContent(int mouseX, int mouseY, float partialTicks) {
|
||||
// Draw color wheel
|
||||
mc.getTextureManager().bindTexture(COLOR_WHEEL);
|
||||
GL11.glColor4f(1, 1, 1, 1);
|
||||
drawTexturedModalRect(wheelX, wheelY, 0, 0, wheelSize, wheelSize);
|
||||
|
||||
// Draw preview swatch with border
|
||||
drawRect(previewX - 1, previewY - 1, previewX + previewSize + 1, previewY + previewSize + 1, ModernColors.PANEL_BORDER);
|
||||
drawRect(previewX, previewY, previewX + previewSize, previewY + previewSize, 0xFF000000 | color);
|
||||
|
||||
// Draw hex label
|
||||
fontRendererObj.drawString("#", hexField.getX() - 10, hexField.getY() + 5, ModernColors.TEXT_LIGHT);
|
||||
|
||||
// Draw hex field
|
||||
hexField.draw(mouseX, mouseY);
|
||||
|
||||
// Draw buttons
|
||||
doneBtn.drawButton(mc, mouseX, mouseY);
|
||||
cancelBtn.drawButton(mc, mouseX, mouseY);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateScreen() {
|
||||
super.updateScreen();
|
||||
hexField.updateCursorCounter();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void mouseClicked(int mouseX, int mouseY, int button) {
|
||||
super.mouseClicked(mouseX, mouseY, button);
|
||||
|
||||
// Check hex field click
|
||||
hexField.mouseClicked(mouseX, mouseY, button);
|
||||
|
||||
// Check color wheel click
|
||||
if (button == 0 && isInsideWheel(mouseX, mouseY)) {
|
||||
pickColorFromWheel(mouseX, mouseY);
|
||||
}
|
||||
|
||||
// Check button clicks
|
||||
if (doneBtn.mousePressed(mc, mouseX, mouseY)) {
|
||||
close();
|
||||
return;
|
||||
}
|
||||
if (cancelBtn.mousePressed(mc, mouseX, mouseY)) {
|
||||
// Reset color to original? For now just close
|
||||
close();
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void actionPerformed(GuiButton btn) {
|
||||
super.actionPerformed(btn);
|
||||
// Buttons handled in mouseClicked
|
||||
}
|
||||
|
||||
@Override
|
||||
public void keyTyped(char typedChar, int keyCode) {
|
||||
// Handle hex field input
|
||||
if (hexField.isFocused()) {
|
||||
String prev = hexField.getText();
|
||||
hexField.keyTyped(typedChar, keyCode);
|
||||
String newText = hexField.getText();
|
||||
|
||||
// Only allow hex characters
|
||||
if (!newText.equals(prev)) {
|
||||
String filtered = filterHex(newText);
|
||||
if (!filtered.equals(newText)) {
|
||||
hexField.setText(filtered);
|
||||
} else {
|
||||
// Update color if valid
|
||||
updateColorFromHex();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Handle ESC
|
||||
super.keyTyped(typedChar, keyCode);
|
||||
}
|
||||
|
||||
/**
|
||||
* Filter input to only allow hex characters.
|
||||
*/
|
||||
private String filterHex(String input) {
|
||||
StringBuilder sb = new StringBuilder();
|
||||
for (char c : input.toUpperCase().toCharArray()) {
|
||||
if ((c >= '0' && c <= '9') || (c >= 'A' && c <= 'F')) {
|
||||
sb.append(c);
|
||||
}
|
||||
}
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
/**
|
||||
* Update color value from hex field text.
|
||||
*/
|
||||
private void updateColorFromHex() {
|
||||
String hex = hexField.getText();
|
||||
if (hex.isEmpty()) return;
|
||||
|
||||
try {
|
||||
color = Integer.parseInt(hex, 16);
|
||||
} catch (NumberFormatException e) {
|
||||
// Invalid hex, ignore
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if mouse is inside the color wheel area.
|
||||
*/
|
||||
private boolean isInsideWheel(int mouseX, int mouseY) {
|
||||
return mouseX >= wheelX && mouseX < wheelX + wheelSize &&
|
||||
mouseY >= wheelY && mouseY < wheelY + wheelSize;
|
||||
}
|
||||
|
||||
/**
|
||||
* Pick color from the wheel texture at clicked position.
|
||||
*/
|
||||
private void pickColorFromWheel(int mouseX, int mouseY) {
|
||||
InputStream stream = null;
|
||||
try {
|
||||
IResource resource = mc.getResourceManager().getResource(COLOR_WHEEL);
|
||||
BufferedImage image = ImageIO.read(stream = resource.getInputStream());
|
||||
|
||||
// Scale mouse position to texture coordinates
|
||||
// The texture is assumed to be a certain size, compute ratio
|
||||
int texX = (mouseX - wheelX) * image.getWidth() / wheelSize;
|
||||
int texY = (mouseY - wheelY) * image.getHeight() / wheelSize;
|
||||
|
||||
// Clamp to texture bounds
|
||||
texX = Math.max(0, Math.min(texX, image.getWidth() - 1));
|
||||
texY = Math.max(0, Math.min(texY, image.getHeight() - 1));
|
||||
|
||||
color = image.getRGB(texX, texY) & 0xFFFFFF;
|
||||
hexField.setText(getHexString());
|
||||
|
||||
} catch (IOException e) {
|
||||
// Ignore errors
|
||||
} finally {
|
||||
if (stream != null) {
|
||||
try {
|
||||
stream.close();
|
||||
} catch (IOException e) {
|
||||
// Ignore
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get color as hex string (6 chars, uppercase).
|
||||
*/
|
||||
private String getHexString() {
|
||||
String hex = Integer.toHexString(color).toUpperCase();
|
||||
while (hex.length() < 6) {
|
||||
hex = "0" + hex;
|
||||
}
|
||||
return hex;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the selected color.
|
||||
*/
|
||||
public int getColor() {
|
||||
return color;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,93 @@
|
||||
package kamkeel.npcs.client.gui.modern;
|
||||
|
||||
import noppes.npcs.controllers.DialogController;
|
||||
import noppes.npcs.controllers.data.Dialog;
|
||||
import noppes.npcs.controllers.data.DialogCategory;
|
||||
|
||||
/**
|
||||
* Modern styled dialog selector SubGui.
|
||||
* Features two-column layout (categories | dialogs) with draggable divider, search fields, and preview.
|
||||
*/
|
||||
public class ModernDialogSelector extends ModernCategorySelector<DialogCategory, Dialog> {
|
||||
|
||||
// Keep public field for backward compatibility
|
||||
public Dialog selectedDialog;
|
||||
|
||||
public ModernDialogSelector(int dialogId) {
|
||||
super();
|
||||
setHeaderTitle("Select Dialog");
|
||||
|
||||
// Load dialog data
|
||||
loadData();
|
||||
|
||||
// Find initial selection
|
||||
if (dialogId > 0) {
|
||||
selectedDialog = DialogController.Instance.dialogs.get(dialogId);
|
||||
selectedItem = selectedDialog;
|
||||
if (selectedDialog != null) {
|
||||
selectedCategory = selectedDialog.category;
|
||||
loadItemsForSelectedCategory();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void loadAllCategories() {
|
||||
for (DialogCategory cat : DialogController.Instance.categories.values()) {
|
||||
categoryData.put(cat.title, cat);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void loadItemsForCategory(DialogCategory category) {
|
||||
if (category != null) {
|
||||
for (Dialog d : category.dialogs.values()) {
|
||||
itemData.put(d.title, d);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String getCategoryTitle(DialogCategory category) {
|
||||
return category.title;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String getItemTitle(Dialog item) {
|
||||
return item.title;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected int getItemId(Dialog item) {
|
||||
return item.id;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String getHeaderTitle() {
|
||||
return "Select Dialog";
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String getCategoryColumnTitle() {
|
||||
return "Categories";
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String getItemColumnTitle() {
|
||||
return "Dialogs";
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void confirm() {
|
||||
// Sync with backward-compatible public field
|
||||
selectedDialog = selectedItem;
|
||||
super.confirm();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the selected dialog, or null if none selected.
|
||||
*/
|
||||
public Dialog getSelectedDialog() {
|
||||
return selectedItem;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,307 @@
|
||||
package kamkeel.npcs.client.gui.modern;
|
||||
|
||||
import kamkeel.npcs.client.gui.components.ModernButton;
|
||||
import kamkeel.npcs.client.gui.components.ModernTextField;
|
||||
import noppes.npcs.client.gui.util.ModernColors;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.gui.ScaledResolution;
|
||||
import noppes.npcs.controllers.FactionController;
|
||||
import noppes.npcs.controllers.data.Faction;
|
||||
import org.lwjgl.opengl.GL11;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
/**
|
||||
* Modern styled faction selector SubGui.
|
||||
* Features single-column layout with search field.
|
||||
*/
|
||||
public class ModernFactionSelector extends ModernSubGuiInterface {
|
||||
|
||||
// Selected value
|
||||
public Faction selectedFaction;
|
||||
|
||||
// Data map
|
||||
private HashMap<String, Faction> factionData = new HashMap<>();
|
||||
|
||||
// List for display
|
||||
private List<String> filteredFactions = new ArrayList<>();
|
||||
|
||||
// Components
|
||||
private ModernTextField searchField;
|
||||
private ModernButton doneBtn;
|
||||
private ModernButton cancelBtn;
|
||||
|
||||
// Scroll state
|
||||
private int scrollY = 0;
|
||||
private int selectedIndex = -1;
|
||||
|
||||
// Layout
|
||||
private int listX, listY;
|
||||
private int listWidth, listHeight;
|
||||
private int rowHeight = 16; // Slightly taller rows for faction color indicator
|
||||
|
||||
// Search string
|
||||
private String searchText = "";
|
||||
|
||||
// Button IDs
|
||||
private static final int ID_DONE = 100;
|
||||
private static final int ID_CANCEL = 101;
|
||||
|
||||
// Double-click tracking
|
||||
private long lastClickTime = 0;
|
||||
private int lastClickedIndex = -1;
|
||||
|
||||
public ModernFactionSelector(int factionId) {
|
||||
xSize = 280;
|
||||
ySize = 260;
|
||||
setHeaderTitle("Select Faction");
|
||||
|
||||
// Load faction data
|
||||
loadData();
|
||||
|
||||
// Find initial selection
|
||||
if (factionId >= 0) {
|
||||
selectedFaction = FactionController.getInstance().factions.get(factionId);
|
||||
}
|
||||
}
|
||||
|
||||
private void loadData() {
|
||||
factionData.clear();
|
||||
for (Faction faction : FactionController.getInstance().factions.values()) {
|
||||
factionData.put(faction.name, faction);
|
||||
}
|
||||
filteredFactions = new ArrayList<>(factionData.keySet());
|
||||
Collections.sort(filteredFactions);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void initGui() {
|
||||
super.initGui();
|
||||
|
||||
int contentY = getContentY() + 6;
|
||||
int contentH = getContentHeight() - 6;
|
||||
|
||||
int pad = 8;
|
||||
listX = guiLeft + pad;
|
||||
listWidth = xSize - pad * 2;
|
||||
|
||||
// Search field at top
|
||||
int searchH = 18;
|
||||
searchField = new ModernTextField(0, listX, contentY, listWidth, searchH);
|
||||
searchField.setPlaceholder("Filter factions...");
|
||||
searchField.setText(searchText);
|
||||
|
||||
// List area below search
|
||||
listY = contentY + searchH + 4;
|
||||
listHeight = contentH - searchH - 36 - 8;
|
||||
|
||||
// Buttons at bottom
|
||||
int btnY = guiTop + ySize - 32;
|
||||
int btnWidth = 60;
|
||||
int btnGap = 8;
|
||||
|
||||
cancelBtn = new ModernButton(ID_CANCEL, guiLeft + xSize - pad - btnWidth * 2 - btnGap, btnY, btnWidth, 20, "Cancel");
|
||||
doneBtn = new ModernButton(ID_DONE, guiLeft + xSize - pad - btnWidth, btnY, btnWidth, 20, "Done");
|
||||
doneBtn.setBackgroundColor(ModernColors.ACCENT_BLUE);
|
||||
|
||||
// Set initial selection index
|
||||
if (selectedFaction != null) {
|
||||
selectedIndex = filteredFactions.indexOf(selectedFaction.name);
|
||||
}
|
||||
}
|
||||
|
||||
private void updateList() {
|
||||
if (searchText.isEmpty()) {
|
||||
filteredFactions = new ArrayList<>(factionData.keySet());
|
||||
} else {
|
||||
filteredFactions = new ArrayList<>();
|
||||
String searchLower = searchText.toLowerCase();
|
||||
for (String name : factionData.keySet()) {
|
||||
if (name.toLowerCase().contains(searchLower)) {
|
||||
filteredFactions.add(name);
|
||||
}
|
||||
}
|
||||
}
|
||||
Collections.sort(filteredFactions);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void drawContent(int mouseX, int mouseY, float partialTicks) {
|
||||
// Draw search field
|
||||
searchField.draw(mouseX, mouseY);
|
||||
|
||||
// Draw list background
|
||||
drawRect(listX, listY, listX + listWidth, listY + listHeight, ModernColors.INPUT_BG);
|
||||
|
||||
// Draw faction list
|
||||
drawFactionList(mouseX, mouseY);
|
||||
|
||||
// Draw selected faction info
|
||||
if (selectedFaction != null) {
|
||||
String info = "Selected: " + selectedFaction.name + " (ID: " + selectedFaction.id + ")";
|
||||
int infoY = listY + listHeight + 4;
|
||||
fontRendererObj.drawString(info, guiLeft + 8, infoY, ModernColors.TEXT_GRAY);
|
||||
}
|
||||
|
||||
// Draw buttons
|
||||
doneBtn.drawButton(mc, mouseX, mouseY);
|
||||
cancelBtn.drawButton(mc, mouseX, mouseY);
|
||||
}
|
||||
|
||||
private void drawFactionList(int mouseX, int mouseY) {
|
||||
// Set up scissor
|
||||
Minecraft mc = Minecraft.getMinecraft();
|
||||
ScaledResolution sr = new ScaledResolution(mc, mc.displayWidth, mc.displayHeight);
|
||||
int scale = sr.getScaleFactor();
|
||||
|
||||
GL11.glEnable(GL11.GL_SCISSOR_TEST);
|
||||
GL11.glScissor(listX * scale, mc.displayHeight - (listY + listHeight) * scale, listWidth * scale, listHeight * scale);
|
||||
|
||||
int visibleRows = listHeight / rowHeight;
|
||||
int startIdx = scrollY / rowHeight;
|
||||
int endIdx = Math.min(startIdx + visibleRows + 2, filteredFactions.size());
|
||||
|
||||
for (int i = startIdx; i < endIdx; i++) {
|
||||
int rowY = listY + i * rowHeight - scrollY;
|
||||
if (rowY + rowHeight < listY || rowY > listY + listHeight) continue;
|
||||
|
||||
String factionName = filteredFactions.get(i);
|
||||
Faction faction = factionData.get(factionName);
|
||||
|
||||
// Draw selection background
|
||||
if (i == selectedIndex) {
|
||||
drawRect(listX, rowY, listX + listWidth, rowY + rowHeight, ModernColors.SELECTION_BG);
|
||||
} else {
|
||||
// Hover highlight
|
||||
if (mouseX >= listX && mouseX < listX + listWidth && mouseY >= rowY && mouseY < rowY + rowHeight) {
|
||||
drawRect(listX, rowY, listX + listWidth, rowY + rowHeight, ModernColors.HOVER_HIGHLIGHT);
|
||||
}
|
||||
}
|
||||
|
||||
// Draw faction color indicator
|
||||
int colorBoxX = listX + 4;
|
||||
int colorBoxY = rowY + 2;
|
||||
int colorBoxSize = rowHeight - 4;
|
||||
if (faction != null) {
|
||||
drawRect(colorBoxX, colorBoxY, colorBoxX + colorBoxSize, colorBoxY + colorBoxSize, 0xFF000000 | faction.color);
|
||||
}
|
||||
|
||||
// Draw text
|
||||
String displayText = fontRendererObj.trimStringToWidth(factionName, listWidth - colorBoxSize - 12);
|
||||
int textColor = i == selectedIndex ? ModernColors.TEXT_WHITE : ModernColors.TEXT_LIGHT;
|
||||
fontRendererObj.drawString(displayText, colorBoxX + colorBoxSize + 4, rowY + 3, textColor);
|
||||
}
|
||||
|
||||
GL11.glDisable(GL11.GL_SCISSOR_TEST);
|
||||
|
||||
// Draw scrollbar if needed
|
||||
int totalHeight = filteredFactions.size() * rowHeight;
|
||||
if (totalHeight > listHeight) {
|
||||
int sbX = listX + listWidth - 4;
|
||||
float viewRatio = (float) listHeight / totalHeight;
|
||||
int thumbH = Math.max(10, (int) (listHeight * viewRatio));
|
||||
float maxScroll = totalHeight - listHeight;
|
||||
int thumbY = maxScroll > 0 ? (int) ((scrollY / maxScroll) * (listHeight - thumbH)) : 0;
|
||||
|
||||
drawRect(sbX, listY, sbX + 4, listY + listHeight, ModernColors.SCROLLBAR_BG);
|
||||
drawRect(sbX, listY + thumbY, sbX + 4, listY + thumbY + thumbH, ModernColors.SCROLLBAR_THUMB);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateScreen() {
|
||||
super.updateScreen();
|
||||
searchField.updateCursorCounter();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void mouseClicked(int mouseX, int mouseY, int button) {
|
||||
super.mouseClicked(mouseX, mouseY, button);
|
||||
|
||||
// Check search field click
|
||||
searchField.mouseClicked(mouseX, mouseY, button);
|
||||
|
||||
// Check list click
|
||||
if (button == 0 && mouseX >= listX && mouseX < listX + listWidth &&
|
||||
mouseY >= listY && mouseY < listY + listHeight) {
|
||||
int clickedIdx = (mouseY - listY + scrollY) / rowHeight;
|
||||
if (clickedIdx >= 0 && clickedIdx < filteredFactions.size()) {
|
||||
// Double-click detection
|
||||
long now = System.currentTimeMillis();
|
||||
if (clickedIdx == lastClickedIndex && now - lastClickTime < 400) {
|
||||
// Double-click - confirm and close
|
||||
confirm();
|
||||
return;
|
||||
}
|
||||
lastClickedIndex = clickedIdx;
|
||||
lastClickTime = now;
|
||||
|
||||
selectedIndex = clickedIdx;
|
||||
String factionName = filteredFactions.get(clickedIdx);
|
||||
selectedFaction = factionData.get(factionName);
|
||||
}
|
||||
}
|
||||
|
||||
// Check button clicks
|
||||
if (doneBtn.mousePressed(mc, mouseX, mouseY)) {
|
||||
confirm();
|
||||
return;
|
||||
}
|
||||
if (cancelBtn.mousePressed(mc, mouseX, mouseY)) {
|
||||
selectedFaction = null;
|
||||
close();
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void handleMouseInput() {
|
||||
super.handleMouseInput();
|
||||
|
||||
int delta = org.lwjgl.input.Mouse.getEventDWheel();
|
||||
if (delta != 0) {
|
||||
int mouseX = org.lwjgl.input.Mouse.getEventX() * width / mc.displayWidth;
|
||||
int mouseY = height - org.lwjgl.input.Mouse.getEventY() * height / mc.displayHeight - 1;
|
||||
|
||||
// Check if mouse is over list
|
||||
if (mouseX >= listX && mouseX < listX + listWidth &&
|
||||
mouseY >= listY && mouseY < listY + listHeight) {
|
||||
int scrollAmount = delta > 0 ? -rowHeight * 2 : rowHeight * 2;
|
||||
int maxScroll = Math.max(0, filteredFactions.size() * rowHeight - listHeight);
|
||||
scrollY = Math.max(0, Math.min(scrollY + scrollAmount, maxScroll));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void keyTyped(char typedChar, int keyCode) {
|
||||
// Handle search field
|
||||
if (searchField.isFocused()) {
|
||||
String prev = searchField.getText();
|
||||
searchField.keyTyped(typedChar, keyCode);
|
||||
String newText = searchField.getText();
|
||||
if (!newText.equals(prev)) {
|
||||
searchText = newText;
|
||||
updateList();
|
||||
scrollY = 0;
|
||||
if (selectedFaction != null) {
|
||||
selectedIndex = filteredFactions.indexOf(selectedFaction.name);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Handle ESC
|
||||
super.keyTyped(typedChar, keyCode);
|
||||
}
|
||||
|
||||
private void confirm() {
|
||||
close();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the selected faction, or null if none selected.
|
||||
*/
|
||||
public Faction getSelectedFaction() {
|
||||
return selectedFaction;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,544 @@
|
||||
package kamkeel.npcs.client.gui.modern;
|
||||
|
||||
import kamkeel.npcs.client.gui.components.ModernButton;
|
||||
import kamkeel.npcs.client.gui.components.ModernTextField;
|
||||
import noppes.npcs.client.gui.util.ModernColors;
|
||||
import net.minecraft.client.gui.Gui;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import noppes.npcs.controllers.QuestController;
|
||||
import noppes.npcs.controllers.data.PlayerMail;
|
||||
import noppes.npcs.controllers.data.Quest;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Modern styled mail editor SubGui.
|
||||
* Features subject, sender, multi-page message editor, quest link, and item display.
|
||||
*/
|
||||
public class ModernMailEditor extends ModernSubGuiInterface {
|
||||
|
||||
private PlayerMail mail;
|
||||
|
||||
// Components
|
||||
private ModernTextField subjectField;
|
||||
private ModernTextField senderField;
|
||||
private ModernButton questBtn;
|
||||
private ModernButton questClearBtn;
|
||||
private ModernButton prevPageBtn;
|
||||
private ModernButton nextPageBtn;
|
||||
private ModernButton doneBtn;
|
||||
private ModernButton cancelBtn;
|
||||
|
||||
// Message editing
|
||||
private List<String> messageLines = new ArrayList<>();
|
||||
private int currentPage = 0;
|
||||
private int linesPerPage = 8;
|
||||
private int cursorLine = 0;
|
||||
private int cursorPos = 0;
|
||||
private boolean messageAreaFocused = false;
|
||||
|
||||
// Layout
|
||||
private int messageAreaX, messageAreaY;
|
||||
private int messageAreaW, messageAreaH;
|
||||
private int lineHeight = 12;
|
||||
|
||||
// Button IDs
|
||||
private static final int ID_QUEST = 100;
|
||||
private static final int ID_QUEST_CLEAR = 101;
|
||||
private static final int ID_PREV_PAGE = 102;
|
||||
private static final int ID_NEXT_PAGE = 103;
|
||||
private static final int ID_DONE = 104;
|
||||
private static final int ID_CANCEL = 105;
|
||||
|
||||
// Cursor blink
|
||||
private int cursorCounter = 0;
|
||||
|
||||
// Pending quest selection
|
||||
private boolean pendingQuestSelect = false;
|
||||
|
||||
public ModernMailEditor(PlayerMail mail) {
|
||||
this.mail = mail;
|
||||
xSize = 340;
|
||||
ySize = 320;
|
||||
setHeaderTitle("Mail Setup");
|
||||
|
||||
// Load message into lines
|
||||
loadMessageLines();
|
||||
}
|
||||
|
||||
private void loadMessageLines() {
|
||||
messageLines.clear();
|
||||
String[] pages = mail.getPageText();
|
||||
for (String page : pages) {
|
||||
// Split each page into lines
|
||||
String[] lines = page.split("\n", -1);
|
||||
for (String line : lines) {
|
||||
messageLines.add(line);
|
||||
}
|
||||
// Add page break marker (empty string signals new page)
|
||||
if (messageLines.size() > 0) {
|
||||
messageLines.add(""); // Page separator
|
||||
}
|
||||
}
|
||||
// Ensure at least one line
|
||||
if (messageLines.isEmpty()) {
|
||||
messageLines.add("");
|
||||
}
|
||||
}
|
||||
|
||||
private void saveMessageToMail() {
|
||||
// Convert lines back to pages
|
||||
List<String> pages = new ArrayList<>();
|
||||
StringBuilder currentPage = new StringBuilder();
|
||||
int linesInPage = 0;
|
||||
|
||||
for (String line : messageLines) {
|
||||
if (linesInPage >= linesPerPage) {
|
||||
pages.add(currentPage.toString());
|
||||
currentPage = new StringBuilder();
|
||||
linesInPage = 0;
|
||||
}
|
||||
if (currentPage.length() > 0) {
|
||||
currentPage.append("\n");
|
||||
}
|
||||
currentPage.append(line);
|
||||
linesInPage++;
|
||||
}
|
||||
|
||||
if (currentPage.length() > 0 || pages.isEmpty()) {
|
||||
pages.add(currentPage.toString());
|
||||
}
|
||||
|
||||
mail.setPageText(pages.toArray(new String[0]));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void initGui() {
|
||||
super.initGui();
|
||||
|
||||
int contentY = getContentY() + 8;
|
||||
int pad = 10;
|
||||
int fieldW = xSize - pad * 2 - 70;
|
||||
int labelW = 60;
|
||||
int rowH = 24;
|
||||
|
||||
// Subject row
|
||||
int rowY = contentY;
|
||||
fontRendererObj.drawString("Subject:", guiLeft + pad, rowY + 5, ModernColors.TEXT_LIGHT);
|
||||
subjectField = new ModernTextField(0, guiLeft + pad + labelW, rowY, fieldW, 18);
|
||||
subjectField.setText(mail.subject);
|
||||
subjectField.setMaxLength(64);
|
||||
rowY += rowH;
|
||||
|
||||
// Sender row
|
||||
senderField = new ModernTextField(1, guiLeft + pad + labelW, rowY, fieldW, 18);
|
||||
senderField.setText(mail.sender);
|
||||
senderField.setMaxLength(64);
|
||||
rowY += rowH;
|
||||
|
||||
// Quest row
|
||||
String questLabel = mail.questId > 0 ? mail.questTitle : "None";
|
||||
if (questLabel.isEmpty() && mail.questId > 0) {
|
||||
Quest q = QuestController.Instance != null ? QuestController.Instance.quests.get(mail.questId) : null;
|
||||
questLabel = q != null ? q.title : "Quest #" + mail.questId;
|
||||
}
|
||||
if (questLabel.length() > 25) {
|
||||
questLabel = questLabel.substring(0, 22) + "...";
|
||||
}
|
||||
questBtn = new ModernButton(ID_QUEST, guiLeft + pad + labelW, rowY, fieldW - 24, 18, questLabel);
|
||||
questClearBtn = new ModernButton(ID_QUEST_CLEAR, guiLeft + pad + labelW + fieldW - 20, rowY, 20, 18, "X");
|
||||
questClearBtn.setBackgroundColor(ModernColors.ACCENT_RED);
|
||||
rowY += rowH + 8;
|
||||
|
||||
// Message area
|
||||
messageAreaX = guiLeft + pad;
|
||||
messageAreaY = rowY;
|
||||
messageAreaW = xSize - pad * 2;
|
||||
messageAreaH = linesPerPage * lineHeight + 8;
|
||||
|
||||
// Page navigation (below message area)
|
||||
int pageNavY = messageAreaY + messageAreaH + 4;
|
||||
int totalPages = getTotalPages();
|
||||
prevPageBtn = new ModernButton(ID_PREV_PAGE, messageAreaX, pageNavY, 30, 16, "<");
|
||||
nextPageBtn = new ModernButton(ID_NEXT_PAGE, messageAreaX + messageAreaW - 30, pageNavY, 30, 16, ">");
|
||||
prevPageBtn.enabled = currentPage > 0;
|
||||
nextPageBtn.enabled = currentPage < totalPages - 1 || canAddPage();
|
||||
|
||||
// Items display row (below page nav)
|
||||
// Items are visual-only in this SubGui, actual container is handled by parent
|
||||
int itemRowY = pageNavY + 24;
|
||||
|
||||
// Done/Cancel buttons at bottom
|
||||
int btnY = guiTop + ySize - 32;
|
||||
int btnWidth = 60;
|
||||
int btnGap = 8;
|
||||
|
||||
cancelBtn = new ModernButton(ID_CANCEL, guiLeft + xSize - pad - btnWidth * 2 - btnGap, btnY, btnWidth, 20, "Cancel");
|
||||
doneBtn = new ModernButton(ID_DONE, guiLeft + xSize - pad - btnWidth, btnY, btnWidth, 20, "Done");
|
||||
doneBtn.setBackgroundColor(ModernColors.ACCENT_BLUE);
|
||||
}
|
||||
|
||||
private int getTotalPages() {
|
||||
return Math.max(1, (messageLines.size() + linesPerPage - 1) / linesPerPage);
|
||||
}
|
||||
|
||||
private boolean canAddPage() {
|
||||
return getTotalPages() < 50; // Max 50 pages
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void drawContent(int mouseX, int mouseY, float partialTicks) {
|
||||
int pad = 10;
|
||||
int labelW = 60;
|
||||
int contentY = getContentY() + 8;
|
||||
int rowH = 24;
|
||||
|
||||
// Draw labels
|
||||
int rowY = contentY;
|
||||
fontRendererObj.drawString("Subject:", guiLeft + pad, rowY + 5, ModernColors.TEXT_LIGHT);
|
||||
rowY += rowH;
|
||||
fontRendererObj.drawString("Sender:", guiLeft + pad, rowY + 5, ModernColors.TEXT_LIGHT);
|
||||
rowY += rowH;
|
||||
fontRendererObj.drawString("Quest:", guiLeft + pad, rowY + 5, ModernColors.TEXT_LIGHT);
|
||||
|
||||
// Draw text fields
|
||||
subjectField.draw(mouseX, mouseY);
|
||||
senderField.draw(mouseX, mouseY);
|
||||
|
||||
// Draw quest button
|
||||
questBtn.drawButton(mc, mouseX, mouseY);
|
||||
questClearBtn.drawButton(mc, mouseX, mouseY);
|
||||
|
||||
// Draw message area background
|
||||
Gui.drawRect(messageAreaX - 1, messageAreaY - 1,
|
||||
messageAreaX + messageAreaW + 1, messageAreaY + messageAreaH + 1,
|
||||
messageAreaFocused ? ModernColors.ACCENT_BLUE : ModernColors.PANEL_BORDER);
|
||||
Gui.drawRect(messageAreaX, messageAreaY,
|
||||
messageAreaX + messageAreaW, messageAreaY + messageAreaH,
|
||||
ModernColors.INPUT_BG);
|
||||
|
||||
// Draw message lines for current page
|
||||
int startLine = currentPage * linesPerPage;
|
||||
int endLine = Math.min(startLine + linesPerPage, messageLines.size());
|
||||
|
||||
for (int i = startLine; i < endLine; i++) {
|
||||
int lineIdx = i - startLine;
|
||||
int lineY = messageAreaY + 4 + lineIdx * lineHeight;
|
||||
String line = messageLines.get(i);
|
||||
|
||||
// Draw line text
|
||||
String displayLine = fontRendererObj.trimStringToWidth(line, messageAreaW - 8);
|
||||
fontRendererObj.drawString(displayLine, messageAreaX + 4, lineY, ModernColors.TEXT_LIGHT);
|
||||
|
||||
// Draw cursor if focused and on this line
|
||||
if (messageAreaFocused && i == cursorLine && (cursorCounter / 6) % 2 == 0) {
|
||||
String beforeCursor = line.substring(0, Math.min(cursorPos, line.length()));
|
||||
int cursorX = messageAreaX + 4 + fontRendererObj.getStringWidth(beforeCursor);
|
||||
Gui.drawRect(cursorX, lineY - 1, cursorX + 1, lineY + lineHeight - 2, ModernColors.TEXT_WHITE);
|
||||
}
|
||||
}
|
||||
|
||||
// Draw page navigation
|
||||
prevPageBtn.drawButton(mc, mouseX, mouseY);
|
||||
nextPageBtn.drawButton(mc, mouseX, mouseY);
|
||||
|
||||
// Draw page indicator
|
||||
String pageText = "Page " + (currentPage + 1) + " / " + getTotalPages();
|
||||
int pageTextW = fontRendererObj.getStringWidth(pageText);
|
||||
int pageNavY = messageAreaY + messageAreaH + 4;
|
||||
fontRendererObj.drawString(pageText, messageAreaX + (messageAreaW - pageTextW) / 2,
|
||||
pageNavY + 4, ModernColors.TEXT_GRAY);
|
||||
|
||||
// Draw items label and slots
|
||||
int itemRowY = pageNavY + 24;
|
||||
fontRendererObj.drawString("Items:", guiLeft + pad, itemRowY + 5, ModernColors.TEXT_LIGHT);
|
||||
|
||||
int itemSlotX = guiLeft + pad + 50;
|
||||
int slotSize = 18;
|
||||
for (int i = 0; i < 4; i++) {
|
||||
int slotX = itemSlotX + i * (slotSize + 2);
|
||||
// Draw slot background
|
||||
Gui.drawRect(slotX, itemRowY, slotX + slotSize, itemRowY + slotSize, ModernColors.INPUT_BG);
|
||||
Gui.drawRect(slotX + 1, itemRowY + 1, slotX + slotSize - 1, itemRowY + slotSize - 1, ModernColors.PANEL_BG_SOLID);
|
||||
|
||||
// Draw item if present
|
||||
if (mail.items != null && i < mail.items.length && mail.items[i] != null) {
|
||||
ItemStack stack = mail.items[i];
|
||||
// Draw a placeholder indicator since we can't render items easily in SubGui
|
||||
fontRendererObj.drawString("?", slotX + 5, itemRowY + 4, ModernColors.TEXT_GRAY);
|
||||
}
|
||||
}
|
||||
|
||||
// Draw buttons
|
||||
doneBtn.drawButton(mc, mouseX, mouseY);
|
||||
cancelBtn.drawButton(mc, mouseX, mouseY);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateScreen() {
|
||||
super.updateScreen();
|
||||
subjectField.updateCursorCounter();
|
||||
senderField.updateCursorCounter();
|
||||
cursorCounter++;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void mouseClicked(int mouseX, int mouseY, int button) {
|
||||
super.mouseClicked(mouseX, mouseY, button);
|
||||
|
||||
// Check text field clicks
|
||||
boolean fieldClicked = false;
|
||||
if (subjectField.handleClick(mouseX, mouseY, button)) {
|
||||
fieldClicked = true;
|
||||
messageAreaFocused = false;
|
||||
}
|
||||
if (senderField.handleClick(mouseX, mouseY, button)) {
|
||||
fieldClicked = true;
|
||||
messageAreaFocused = false;
|
||||
}
|
||||
|
||||
// Check message area click
|
||||
if (button == 0 && mouseX >= messageAreaX && mouseX < messageAreaX + messageAreaW &&
|
||||
mouseY >= messageAreaY && mouseY < messageAreaY + messageAreaH) {
|
||||
messageAreaFocused = true;
|
||||
subjectField.setFocused(false);
|
||||
senderField.setFocused(false);
|
||||
|
||||
// Calculate clicked line and position
|
||||
int clickedLineIdx = (mouseY - messageAreaY - 4) / lineHeight;
|
||||
int absoluteLine = currentPage * linesPerPage + clickedLineIdx;
|
||||
if (absoluteLine >= 0 && absoluteLine < messageLines.size()) {
|
||||
cursorLine = absoluteLine;
|
||||
String line = messageLines.get(cursorLine);
|
||||
// Find cursor position based on click X
|
||||
int clickX = mouseX - messageAreaX - 4;
|
||||
cursorPos = 0;
|
||||
for (int i = 0; i <= line.length(); i++) {
|
||||
int textW = fontRendererObj.getStringWidth(line.substring(0, i));
|
||||
if (textW >= clickX) {
|
||||
cursorPos = i;
|
||||
break;
|
||||
}
|
||||
cursorPos = i;
|
||||
}
|
||||
}
|
||||
return;
|
||||
} else if (!fieldClicked) {
|
||||
messageAreaFocused = false;
|
||||
}
|
||||
|
||||
// Check button clicks
|
||||
if (questBtn.mousePressed(mc, mouseX, mouseY)) {
|
||||
pendingQuestSelect = true;
|
||||
// Save current state and close, parent will handle quest selection
|
||||
saveCurrentState();
|
||||
close();
|
||||
return;
|
||||
}
|
||||
if (questClearBtn.mousePressed(mc, mouseX, mouseY)) {
|
||||
mail.questId = -1;
|
||||
mail.questTitle = "";
|
||||
initGui();
|
||||
return;
|
||||
}
|
||||
if (prevPageBtn.mousePressed(mc, mouseX, mouseY)) {
|
||||
if (currentPage > 0) {
|
||||
currentPage--;
|
||||
initGui();
|
||||
}
|
||||
return;
|
||||
}
|
||||
if (nextPageBtn.mousePressed(mc, mouseX, mouseY)) {
|
||||
if (currentPage < getTotalPages() - 1) {
|
||||
currentPage++;
|
||||
} else if (canAddPage()) {
|
||||
// Add new page
|
||||
for (int i = 0; i < linesPerPage; i++) {
|
||||
messageLines.add("");
|
||||
}
|
||||
currentPage++;
|
||||
}
|
||||
initGui();
|
||||
return;
|
||||
}
|
||||
if (doneBtn.mousePressed(mc, mouseX, mouseY)) {
|
||||
saveCurrentState();
|
||||
close();
|
||||
return;
|
||||
}
|
||||
if (cancelBtn.mousePressed(mc, mouseX, mouseY)) {
|
||||
// Don't save changes
|
||||
close();
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void keyTyped(char typedChar, int keyCode) {
|
||||
// Handle text fields
|
||||
if (subjectField.isFocused()) {
|
||||
subjectField.keyTyped(typedChar, keyCode);
|
||||
mail.subject = subjectField.getText();
|
||||
return;
|
||||
}
|
||||
if (senderField.isFocused()) {
|
||||
senderField.keyTyped(typedChar, keyCode);
|
||||
mail.sender = senderField.getText();
|
||||
return;
|
||||
}
|
||||
|
||||
// Handle message area
|
||||
if (messageAreaFocused) {
|
||||
handleMessageInput(typedChar, keyCode);
|
||||
return;
|
||||
}
|
||||
|
||||
// Handle ESC
|
||||
super.keyTyped(typedChar, keyCode);
|
||||
}
|
||||
|
||||
private void handleMessageInput(char typedChar, int keyCode) {
|
||||
String currentLine = messageLines.get(cursorLine);
|
||||
|
||||
// Backspace
|
||||
if (keyCode == 14) {
|
||||
if (cursorPos > 0) {
|
||||
String newLine = currentLine.substring(0, cursorPos - 1) + currentLine.substring(cursorPos);
|
||||
messageLines.set(cursorLine, newLine);
|
||||
cursorPos--;
|
||||
} else if (cursorLine > 0) {
|
||||
// Merge with previous line
|
||||
String prevLine = messageLines.get(cursorLine - 1);
|
||||
messageLines.set(cursorLine - 1, prevLine + currentLine);
|
||||
messageLines.remove(cursorLine);
|
||||
cursorLine--;
|
||||
cursorPos = prevLine.length();
|
||||
updatePageAfterEdit();
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
// Delete
|
||||
if (keyCode == 211) {
|
||||
if (cursorPos < currentLine.length()) {
|
||||
String newLine = currentLine.substring(0, cursorPos) + currentLine.substring(cursorPos + 1);
|
||||
messageLines.set(cursorLine, newLine);
|
||||
} else if (cursorLine < messageLines.size() - 1) {
|
||||
// Merge with next line
|
||||
String nextLine = messageLines.get(cursorLine + 1);
|
||||
messageLines.set(cursorLine, currentLine + nextLine);
|
||||
messageLines.remove(cursorLine + 1);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
// Enter
|
||||
if (keyCode == 28) {
|
||||
String before = currentLine.substring(0, cursorPos);
|
||||
String after = currentLine.substring(cursorPos);
|
||||
messageLines.set(cursorLine, before);
|
||||
messageLines.add(cursorLine + 1, after);
|
||||
cursorLine++;
|
||||
cursorPos = 0;
|
||||
updatePageAfterEdit();
|
||||
return;
|
||||
}
|
||||
|
||||
// Arrow keys
|
||||
if (keyCode == 203) { // Left
|
||||
if (cursorPos > 0) {
|
||||
cursorPos--;
|
||||
} else if (cursorLine > 0) {
|
||||
cursorLine--;
|
||||
cursorPos = messageLines.get(cursorLine).length();
|
||||
updatePageAfterEdit();
|
||||
}
|
||||
return;
|
||||
}
|
||||
if (keyCode == 205) { // Right
|
||||
if (cursorPos < currentLine.length()) {
|
||||
cursorPos++;
|
||||
} else if (cursorLine < messageLines.size() - 1) {
|
||||
cursorLine++;
|
||||
cursorPos = 0;
|
||||
updatePageAfterEdit();
|
||||
}
|
||||
return;
|
||||
}
|
||||
if (keyCode == 200) { // Up
|
||||
if (cursorLine > 0) {
|
||||
cursorLine--;
|
||||
cursorPos = Math.min(cursorPos, messageLines.get(cursorLine).length());
|
||||
updatePageAfterEdit();
|
||||
}
|
||||
return;
|
||||
}
|
||||
if (keyCode == 208) { // Down
|
||||
if (cursorLine < messageLines.size() - 1) {
|
||||
cursorLine++;
|
||||
cursorPos = Math.min(cursorPos, messageLines.get(cursorLine).length());
|
||||
updatePageAfterEdit();
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
// Home/End
|
||||
if (keyCode == 199) { // Home
|
||||
cursorPos = 0;
|
||||
return;
|
||||
}
|
||||
if (keyCode == 207) { // End
|
||||
cursorPos = currentLine.length();
|
||||
return;
|
||||
}
|
||||
|
||||
// Regular character input
|
||||
if (typedChar >= 32 && typedChar < 127) {
|
||||
// Check line length limit
|
||||
if (currentLine.length() < 200) {
|
||||
String newLine = currentLine.substring(0, cursorPos) + typedChar + currentLine.substring(cursorPos);
|
||||
messageLines.set(cursorLine, newLine);
|
||||
cursorPos++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void updatePageAfterEdit() {
|
||||
// Ensure cursor is on visible page
|
||||
int cursorPage = cursorLine / linesPerPage;
|
||||
if (cursorPage != currentPage) {
|
||||
currentPage = cursorPage;
|
||||
initGui();
|
||||
}
|
||||
}
|
||||
|
||||
private void saveCurrentState() {
|
||||
mail.subject = subjectField.getText();
|
||||
mail.sender = senderField.getText();
|
||||
saveMessageToMail();
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if quest selection was requested.
|
||||
*/
|
||||
public boolean isPendingQuestSelect() {
|
||||
return pendingQuestSelect;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the selected quest after returning from quest selector.
|
||||
*/
|
||||
public void setQuest(int questId, String questTitle) {
|
||||
mail.questId = questId;
|
||||
mail.questTitle = questTitle;
|
||||
pendingQuestSelect = false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the mail being edited.
|
||||
*/
|
||||
public PlayerMail getMail() {
|
||||
return mail;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,93 @@
|
||||
package kamkeel.npcs.client.gui.modern;
|
||||
|
||||
import noppes.npcs.controllers.QuestController;
|
||||
import noppes.npcs.controllers.data.Quest;
|
||||
import noppes.npcs.controllers.data.QuestCategory;
|
||||
|
||||
/**
|
||||
* Modern styled quest selector SubGui.
|
||||
* Features two-column layout (categories | quests) with draggable divider, search fields, and preview.
|
||||
*/
|
||||
public class ModernQuestSelector extends ModernCategorySelector<QuestCategory, Quest> {
|
||||
|
||||
// Keep public field for backward compatibility
|
||||
public Quest selectedQuest;
|
||||
|
||||
public ModernQuestSelector(int questId) {
|
||||
super();
|
||||
setHeaderTitle("Select Quest");
|
||||
|
||||
// Load quest data
|
||||
loadData();
|
||||
|
||||
// Find initial selection
|
||||
if (questId > 0) {
|
||||
selectedQuest = QuestController.Instance.quests.get(questId);
|
||||
selectedItem = selectedQuest;
|
||||
if (selectedQuest != null) {
|
||||
selectedCategory = selectedQuest.category;
|
||||
loadItemsForSelectedCategory();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void loadAllCategories() {
|
||||
for (QuestCategory cat : QuestController.Instance.categories.values()) {
|
||||
categoryData.put(cat.title, cat);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void loadItemsForCategory(QuestCategory category) {
|
||||
if (category != null) {
|
||||
for (Quest q : category.quests.values()) {
|
||||
itemData.put(q.title, q);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String getCategoryTitle(QuestCategory category) {
|
||||
return category.title;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String getItemTitle(Quest item) {
|
||||
return item.title;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected int getItemId(Quest item) {
|
||||
return item.id;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String getHeaderTitle() {
|
||||
return "Select Quest";
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String getCategoryColumnTitle() {
|
||||
return "Categories";
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String getItemColumnTitle() {
|
||||
return "Quests";
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void confirm() {
|
||||
// Sync with backward-compatible public field
|
||||
selectedQuest = selectedItem;
|
||||
super.confirm();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the selected quest, or null if none selected.
|
||||
*/
|
||||
public Quest getSelectedQuest() {
|
||||
return selectedItem;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,448 @@
|
||||
package kamkeel.npcs.client.gui.modern;
|
||||
|
||||
import com.google.common.collect.Lists;
|
||||
import cpw.mods.fml.relauncher.ReflectionHelper;
|
||||
import kamkeel.npcs.client.gui.components.ModernButton;
|
||||
import kamkeel.npcs.client.gui.components.ModernTextField;
|
||||
import noppes.npcs.client.gui.util.ModernColors;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.audio.SoundHandler;
|
||||
import net.minecraft.client.audio.SoundRegistry;
|
||||
import net.minecraft.client.gui.GuiButton;
|
||||
import net.minecraft.client.gui.ScaledResolution;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
import noppes.npcs.client.controllers.MusicController;
|
||||
import org.lwjgl.opengl.GL11;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
/**
|
||||
* Modern styled sound selector SubGui.
|
||||
* Features two-column layout (domains | sounds), search fields, and preview button.
|
||||
*/
|
||||
public class ModernSoundSelector extends ModernSubGuiInterface {
|
||||
|
||||
// Selected values
|
||||
private String selectedDomain;
|
||||
public ResourceLocation selectedResource;
|
||||
|
||||
// Sound data
|
||||
private final HashMap<String, List<String>> domains = new HashMap<>();
|
||||
|
||||
// Components
|
||||
private ModernTextField domainSearchField;
|
||||
private ModernTextField soundSearchField;
|
||||
private ModernButton playBtn;
|
||||
private ModernButton stopBtn;
|
||||
private ModernButton doneBtn;
|
||||
private ModernButton cancelBtn;
|
||||
|
||||
// Lists
|
||||
private List<String> filteredDomains = new ArrayList<>();
|
||||
private List<String> filteredSounds = new ArrayList<>();
|
||||
|
||||
// Scroll state
|
||||
private int domainScrollY = 0;
|
||||
private int soundScrollY = 0;
|
||||
private int selectedDomainIndex = -1;
|
||||
private int selectedSoundIndex = -1;
|
||||
|
||||
// Layout
|
||||
private int listY;
|
||||
private int listHeight;
|
||||
private int domainListX, domainListW;
|
||||
private int soundListX, soundListW;
|
||||
private int rowHeight = 14;
|
||||
|
||||
// Search strings
|
||||
private String domainSearch = "";
|
||||
private String soundSearch = "";
|
||||
|
||||
// Button IDs
|
||||
private static final int ID_PLAY = 100;
|
||||
private static final int ID_STOP = 101;
|
||||
private static final int ID_DONE = 102;
|
||||
private static final int ID_CANCEL = 103;
|
||||
|
||||
// --- Cache static fields ---
|
||||
private static final long CACHE_DURATION = 180000L; // 3 minutes
|
||||
private static long lastCacheTime = 0;
|
||||
private static HashMap<String, List<String>> cachedDomains = new HashMap<>();
|
||||
|
||||
public ModernSoundSelector(String sound) {
|
||||
xSize = 400;
|
||||
ySize = 280;
|
||||
setHeaderTitle("Sound Selector");
|
||||
|
||||
loadSounds();
|
||||
|
||||
if (sound != null && !sound.isEmpty()) {
|
||||
selectedResource = new ResourceLocation(sound);
|
||||
selectedDomain = selectedResource.getResourceDomain();
|
||||
if (!domains.containsKey(selectedDomain)) {
|
||||
selectedDomain = null;
|
||||
selectedResource = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void loadSounds() {
|
||||
long now = System.currentTimeMillis();
|
||||
if (now - lastCacheTime < CACHE_DURATION && !cachedDomains.isEmpty()) {
|
||||
domains.putAll(cachedDomains);
|
||||
} else {
|
||||
SoundHandler handler = Minecraft.getMinecraft().getSoundHandler();
|
||||
SoundRegistry registry = ReflectionHelper.getPrivateValue(SoundHandler.class, handler, 4);
|
||||
Set<ResourceLocation> set = registry.getKeys();
|
||||
for (ResourceLocation location : set) {
|
||||
List<String> list = domains.get(location.getResourceDomain());
|
||||
if (list == null) {
|
||||
domains.put(location.getResourceDomain(), list = new ArrayList<String>());
|
||||
}
|
||||
list.add(location.getResourcePath());
|
||||
}
|
||||
cachedDomains.clear();
|
||||
cachedDomains.putAll(domains);
|
||||
lastCacheTime = now;
|
||||
}
|
||||
|
||||
// Sort domain keys
|
||||
filteredDomains = new ArrayList<>(domains.keySet());
|
||||
Collections.sort(filteredDomains);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void initGui() {
|
||||
super.initGui();
|
||||
|
||||
int contentY = getContentY() + 6;
|
||||
int contentH = getContentHeight() - 6;
|
||||
|
||||
// Layout calculations
|
||||
int pad = 6;
|
||||
domainListX = guiLeft + pad;
|
||||
domainListW = 100;
|
||||
soundListX = domainListX + domainListW + pad;
|
||||
soundListW = xSize - domainListW - pad * 3;
|
||||
|
||||
// Search fields at top
|
||||
int searchH = 18;
|
||||
domainSearchField = new ModernTextField(0, domainListX, contentY, domainListW, searchH);
|
||||
domainSearchField.setPlaceholder("Filter...");
|
||||
domainSearchField.setText(domainSearch);
|
||||
|
||||
soundSearchField = new ModernTextField(1, soundListX, contentY, soundListW, searchH);
|
||||
soundSearchField.setPlaceholder("Filter sounds...");
|
||||
soundSearchField.setText(soundSearch);
|
||||
|
||||
// List area below search
|
||||
listY = contentY + searchH + 4;
|
||||
listHeight = contentH - searchH - 36 - 8; // Leave room for buttons
|
||||
|
||||
// Buttons at bottom
|
||||
int btnY = guiTop + ySize - 32;
|
||||
int btnWidth = 50;
|
||||
int btnGap = 6;
|
||||
|
||||
playBtn = new ModernButton(ID_PLAY, guiLeft + pad, btnY, btnWidth, 20, "Play");
|
||||
playBtn.setBackgroundColor(ModernColors.ACCENT_GREEN);
|
||||
|
||||
stopBtn = new ModernButton(ID_STOP, guiLeft + pad + btnWidth + btnGap, btnY, btnWidth, 20, "Stop");
|
||||
stopBtn.setBackgroundColor(ModernColors.ACCENT_RED);
|
||||
|
||||
cancelBtn = new ModernButton(ID_CANCEL, guiLeft + xSize - pad - btnWidth * 2 - btnGap, btnY, btnWidth, 20, "Cancel");
|
||||
|
||||
doneBtn = new ModernButton(ID_DONE, guiLeft + xSize - pad - btnWidth, btnY, btnWidth, 20, "Done");
|
||||
doneBtn.setBackgroundColor(ModernColors.ACCENT_BLUE);
|
||||
|
||||
// Set initial selection
|
||||
if (selectedDomain != null) {
|
||||
selectedDomainIndex = filteredDomains.indexOf(selectedDomain);
|
||||
updateSoundList();
|
||||
if (selectedResource != null) {
|
||||
selectedSoundIndex = filteredSounds.indexOf(selectedResource.getResourcePath());
|
||||
}
|
||||
}
|
||||
|
||||
updateButtonStates();
|
||||
}
|
||||
|
||||
private void updateButtonStates() {
|
||||
playBtn.enabled = selectedResource != null;
|
||||
}
|
||||
|
||||
private void updateSoundList() {
|
||||
if (selectedDomain == null || !domains.containsKey(selectedDomain)) {
|
||||
filteredSounds = new ArrayList<>();
|
||||
return;
|
||||
}
|
||||
|
||||
List<String> allSounds = domains.get(selectedDomain);
|
||||
if (soundSearch.isEmpty()) {
|
||||
filteredSounds = new ArrayList<>(allSounds);
|
||||
} else {
|
||||
filteredSounds = new ArrayList<>();
|
||||
String searchLower = soundSearch.toLowerCase();
|
||||
for (String sound : allSounds) {
|
||||
if (sound.toLowerCase().contains(searchLower)) {
|
||||
filteredSounds.add(sound);
|
||||
}
|
||||
}
|
||||
}
|
||||
Collections.sort(filteredSounds);
|
||||
}
|
||||
|
||||
private void updateDomainList() {
|
||||
if (domainSearch.isEmpty()) {
|
||||
filteredDomains = new ArrayList<>(domains.keySet());
|
||||
} else {
|
||||
filteredDomains = new ArrayList<>();
|
||||
String searchLower = domainSearch.toLowerCase();
|
||||
for (String domain : domains.keySet()) {
|
||||
if (domain.toLowerCase().contains(searchLower)) {
|
||||
filteredDomains.add(domain);
|
||||
}
|
||||
}
|
||||
}
|
||||
Collections.sort(filteredDomains);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void drawContent(int mouseX, int mouseY, float partialTicks) {
|
||||
// Draw search fields
|
||||
domainSearchField.draw(mouseX, mouseY);
|
||||
soundSearchField.draw(mouseX, mouseY);
|
||||
|
||||
// Draw list backgrounds
|
||||
drawRect(domainListX, listY, domainListX + domainListW, listY + listHeight, ModernColors.INPUT_BG);
|
||||
drawRect(soundListX, listY, soundListX + soundListW, listY + listHeight, ModernColors.INPUT_BG);
|
||||
|
||||
// Draw domain list
|
||||
drawList(domainListX, listY, domainListW, listHeight, filteredDomains, selectedDomainIndex,
|
||||
domainScrollY, mouseX, mouseY);
|
||||
|
||||
// Draw sound list
|
||||
drawList(soundListX, listY, soundListW, listHeight, filteredSounds, selectedSoundIndex,
|
||||
soundScrollY, mouseX, mouseY);
|
||||
|
||||
// Draw selected sound info
|
||||
if (selectedResource != null) {
|
||||
String info = selectedResource.toString();
|
||||
int infoY = listY + listHeight + 2;
|
||||
fontRendererObj.drawString(info, guiLeft + 6, infoY, ModernColors.TEXT_GRAY);
|
||||
}
|
||||
|
||||
// Draw buttons
|
||||
playBtn.drawButton(mc, mouseX, mouseY);
|
||||
stopBtn.drawButton(mc, mouseX, mouseY);
|
||||
doneBtn.drawButton(mc, mouseX, mouseY);
|
||||
cancelBtn.drawButton(mc, mouseX, mouseY);
|
||||
}
|
||||
|
||||
private void drawList(int x, int y, int w, int h, List<String> items, int selectedIdx,
|
||||
int scrollY, int mouseX, int mouseY) {
|
||||
// Set up scissor
|
||||
Minecraft mc = Minecraft.getMinecraft();
|
||||
ScaledResolution sr = new ScaledResolution(mc, mc.displayWidth, mc.displayHeight);
|
||||
int scale = sr.getScaleFactor();
|
||||
|
||||
GL11.glEnable(GL11.GL_SCISSOR_TEST);
|
||||
GL11.glScissor(x * scale, mc.displayHeight - (y + h) * scale, w * scale, h * scale);
|
||||
|
||||
int visibleRows = h / rowHeight;
|
||||
int startIdx = scrollY / rowHeight;
|
||||
int endIdx = Math.min(startIdx + visibleRows + 1, items.size());
|
||||
|
||||
for (int i = startIdx; i < endIdx; i++) {
|
||||
int rowY = y + i * rowHeight - scrollY;
|
||||
|
||||
// Draw selection background
|
||||
if (i == selectedIdx) {
|
||||
drawRect(x, rowY, x + w, rowY + rowHeight, ModernColors.SELECTION_BG);
|
||||
} else {
|
||||
// Hover highlight
|
||||
if (mouseX >= x && mouseX < x + w && mouseY >= rowY && mouseY < rowY + rowHeight) {
|
||||
drawRect(x, rowY, x + w, rowY + rowHeight, ModernColors.HOVER_HIGHLIGHT);
|
||||
}
|
||||
}
|
||||
|
||||
// Draw text
|
||||
String text = items.get(i);
|
||||
String displayText = fontRendererObj.trimStringToWidth(text, w - 4);
|
||||
int textColor = i == selectedIdx ? ModernColors.TEXT_WHITE : ModernColors.TEXT_LIGHT;
|
||||
fontRendererObj.drawString(displayText, x + 2, rowY + 2, textColor);
|
||||
}
|
||||
|
||||
GL11.glDisable(GL11.GL_SCISSOR_TEST);
|
||||
|
||||
// Draw scrollbar if needed
|
||||
int totalHeight = items.size() * rowHeight;
|
||||
if (totalHeight > h) {
|
||||
int sbX = x + w - 4;
|
||||
float viewRatio = (float) h / totalHeight;
|
||||
int thumbH = Math.max(10, (int) (h * viewRatio));
|
||||
float maxScroll = totalHeight - h;
|
||||
int thumbY = (int) ((scrollY / maxScroll) * (h - thumbH));
|
||||
|
||||
drawRect(sbX, y, sbX + 4, y + h, ModernColors.SCROLLBAR_BG);
|
||||
drawRect(sbX, y + thumbY, sbX + 4, y + thumbY + thumbH, ModernColors.SCROLLBAR_THUMB);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateScreen() {
|
||||
super.updateScreen();
|
||||
domainSearchField.updateCursorCounter();
|
||||
soundSearchField.updateCursorCounter();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void mouseClicked(int mouseX, int mouseY, int button) {
|
||||
super.mouseClicked(mouseX, mouseY, button);
|
||||
|
||||
// Check search field clicks
|
||||
domainSearchField.mouseClicked(mouseX, mouseY, button);
|
||||
soundSearchField.mouseClicked(mouseX, mouseY, button);
|
||||
|
||||
// Check domain list click
|
||||
if (button == 0 && mouseX >= domainListX && mouseX < domainListX + domainListW &&
|
||||
mouseY >= listY && mouseY < listY + listHeight) {
|
||||
int clickedIdx = (mouseY - listY + domainScrollY) / rowHeight;
|
||||
if (clickedIdx >= 0 && clickedIdx < filteredDomains.size()) {
|
||||
selectedDomainIndex = clickedIdx;
|
||||
selectedDomain = filteredDomains.get(clickedIdx);
|
||||
selectedResource = null;
|
||||
selectedSoundIndex = -1;
|
||||
soundScrollY = 0;
|
||||
updateSoundList();
|
||||
updateButtonStates();
|
||||
}
|
||||
}
|
||||
|
||||
// Check sound list click
|
||||
if (button == 0 && mouseX >= soundListX && mouseX < soundListX + soundListW &&
|
||||
mouseY >= listY && mouseY < listY + listHeight) {
|
||||
int clickedIdx = (mouseY - listY + soundScrollY) / rowHeight;
|
||||
if (clickedIdx >= 0 && clickedIdx < filteredSounds.size()) {
|
||||
selectedSoundIndex = clickedIdx;
|
||||
String soundPath = filteredSounds.get(clickedIdx);
|
||||
selectedResource = new ResourceLocation(selectedDomain, soundPath);
|
||||
updateButtonStates();
|
||||
}
|
||||
}
|
||||
|
||||
// Check button clicks
|
||||
if (playBtn.mousePressed(mc, mouseX, mouseY)) {
|
||||
playSelectedSound();
|
||||
return;
|
||||
}
|
||||
if (stopBtn.mousePressed(mc, mouseX, mouseY)) {
|
||||
stopSound();
|
||||
return;
|
||||
}
|
||||
if (doneBtn.mousePressed(mc, mouseX, mouseY)) {
|
||||
close();
|
||||
return;
|
||||
}
|
||||
if (cancelBtn.mousePressed(mc, mouseX, mouseY)) {
|
||||
selectedResource = null;
|
||||
close();
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void handleMouseInput() {
|
||||
super.handleMouseInput();
|
||||
|
||||
int delta = org.lwjgl.input.Mouse.getEventDWheel();
|
||||
if (delta != 0) {
|
||||
int mouseX = org.lwjgl.input.Mouse.getEventX() * width / mc.displayWidth;
|
||||
int mouseY = height - org.lwjgl.input.Mouse.getEventY() * height / mc.displayHeight - 1;
|
||||
|
||||
int scrollAmount = delta > 0 ? -rowHeight * 2 : rowHeight * 2;
|
||||
|
||||
// Check which list is hovered
|
||||
if (mouseX >= domainListX && mouseX < domainListX + domainListW &&
|
||||
mouseY >= listY && mouseY < listY + listHeight) {
|
||||
int maxScroll = Math.max(0, filteredDomains.size() * rowHeight - listHeight);
|
||||
domainScrollY = Math.max(0, Math.min(domainScrollY + scrollAmount, maxScroll));
|
||||
}
|
||||
|
||||
if (mouseX >= soundListX && mouseX < soundListX + soundListW &&
|
||||
mouseY >= listY && mouseY < listY + listHeight) {
|
||||
int maxScroll = Math.max(0, filteredSounds.size() * rowHeight - listHeight);
|
||||
soundScrollY = Math.max(0, Math.min(soundScrollY + scrollAmount, maxScroll));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void keyTyped(char typedChar, int keyCode) {
|
||||
// Handle domain search field
|
||||
if (domainSearchField.isFocused()) {
|
||||
String prev = domainSearchField.getText();
|
||||
domainSearchField.keyTyped(typedChar, keyCode);
|
||||
String newText = domainSearchField.getText();
|
||||
if (!newText.equals(prev)) {
|
||||
domainSearch = newText;
|
||||
updateDomainList();
|
||||
domainScrollY = 0;
|
||||
// Update selection index
|
||||
if (selectedDomain != null) {
|
||||
selectedDomainIndex = filteredDomains.indexOf(selectedDomain);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Handle sound search field
|
||||
if (soundSearchField.isFocused()) {
|
||||
String prev = soundSearchField.getText();
|
||||
soundSearchField.keyTyped(typedChar, keyCode);
|
||||
String newText = soundSearchField.getText();
|
||||
if (!newText.equals(prev)) {
|
||||
soundSearch = newText;
|
||||
updateSoundList();
|
||||
soundScrollY = 0;
|
||||
// Update selection index
|
||||
if (selectedResource != null) {
|
||||
selectedSoundIndex = filteredSounds.indexOf(selectedResource.getResourcePath());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Handle ESC
|
||||
super.keyTyped(typedChar, keyCode);
|
||||
}
|
||||
|
||||
private void playSelectedSound() {
|
||||
if (selectedResource == null) return;
|
||||
MusicController.Instance.stopMusic();
|
||||
MusicController.Instance.playSound(selectedResource.toString(),
|
||||
(float) player.posX, (float) player.posY, (float) player.posZ);
|
||||
}
|
||||
|
||||
private void stopSound() {
|
||||
MusicController.Instance.stopAllSounds();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void close() {
|
||||
MusicController.Instance.stopAllSounds();
|
||||
super.close();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the selected sound resource location, or null if none selected.
|
||||
*/
|
||||
public ResourceLocation getSelectedSound() {
|
||||
return selectedResource;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the selected sound as a string, or empty string if none selected.
|
||||
*/
|
||||
public String getSelectedSoundString() {
|
||||
return selectedResource != null ? selectedResource.toString() : "";
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,160 @@
|
||||
package kamkeel.npcs.client.gui.modern;
|
||||
|
||||
import noppes.npcs.client.gui.util.ModernColors;
|
||||
import net.minecraft.client.gui.Gui;
|
||||
import net.minecraft.client.gui.GuiButton;
|
||||
import noppes.npcs.client.gui.util.GuiNpcLabel;
|
||||
import noppes.npcs.client.gui.util.SubGuiInterface;
|
||||
|
||||
/**
|
||||
* Base class for modern styled SubGuis.
|
||||
* Features:
|
||||
* - Semi-transparent dark overlay over parent screen
|
||||
* - Modern dark panel with accent border
|
||||
* - No texture-based background
|
||||
*/
|
||||
public class ModernSubGuiInterface extends SubGuiInterface {
|
||||
|
||||
// Overlay color (semi-transparent black)
|
||||
protected int overlayColor = 0x80000000;
|
||||
|
||||
// Panel colors
|
||||
protected int panelBg = ModernColors.PANEL_BG_SOLID;
|
||||
protected int panelBorder = ModernColors.ACCENT_BLUE;
|
||||
protected int panelBorderWidth = 1;
|
||||
|
||||
// Header (optional)
|
||||
protected String headerTitle = null;
|
||||
protected int headerHeight = 20;
|
||||
protected int headerBg = ModernColors.SECTION_HEADER_BG;
|
||||
protected int headerText = ModernColors.TEXT_WHITE;
|
||||
|
||||
public ModernSubGuiInterface() {
|
||||
// Disable default background drawing
|
||||
drawDefaultBackground = false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void drawScreen(int mouseX, int mouseY, float partialTicks) {
|
||||
// Draw semi-transparent overlay over entire screen
|
||||
Gui.drawRect(0, 0, width, height, overlayColor);
|
||||
|
||||
// Draw modern panel background
|
||||
drawModernPanel();
|
||||
|
||||
// Draw header if set
|
||||
if (headerTitle != null) {
|
||||
drawHeader();
|
||||
}
|
||||
|
||||
// Draw content (buttons, labels, etc.)
|
||||
drawButtonsModern(mouseX, mouseY);
|
||||
drawLabelsModern();
|
||||
|
||||
// Draw any custom content
|
||||
drawContent(mouseX, mouseY, partialTicks);
|
||||
}
|
||||
|
||||
/**
|
||||
* Draw the modern panel background.
|
||||
*/
|
||||
protected void drawModernPanel() {
|
||||
// Draw border
|
||||
Gui.drawRect(guiLeft - panelBorderWidth, guiTop - panelBorderWidth,
|
||||
guiLeft + xSize + panelBorderWidth, guiTop + ySize + panelBorderWidth,
|
||||
panelBorder);
|
||||
|
||||
// Draw panel background
|
||||
Gui.drawRect(guiLeft, guiTop, guiLeft + xSize, guiTop + ySize, panelBg);
|
||||
}
|
||||
|
||||
/**
|
||||
* Draw the header bar if headerTitle is set.
|
||||
*/
|
||||
protected void drawHeader() {
|
||||
// Header background
|
||||
Gui.drawRect(guiLeft, guiTop, guiLeft + xSize, guiTop + headerHeight, headerBg);
|
||||
|
||||
// Header text (centered)
|
||||
int textW = fontRendererObj.getStringWidth(headerTitle);
|
||||
int textX = guiLeft + (xSize - textW) / 2;
|
||||
int textY = guiTop + (headerHeight - fontRendererObj.FONT_HEIGHT) / 2;
|
||||
fontRendererObj.drawString(headerTitle, textX, textY, headerText);
|
||||
}
|
||||
|
||||
/**
|
||||
* Draw buttons with modern styling.
|
||||
*/
|
||||
protected void drawButtonsModern(int mouseX, int mouseY) {
|
||||
for (Object obj : buttonList) {
|
||||
if (obj instanceof GuiButton) {
|
||||
((GuiButton) obj).drawButton(mc, mouseX, mouseY);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Draw labels with modern styling.
|
||||
*/
|
||||
protected void drawLabelsModern() {
|
||||
for (Object obj : labels.values()) {
|
||||
if (obj instanceof GuiNpcLabel) {
|
||||
((GuiNpcLabel) obj).drawLabel(this, fontRendererObj);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Override this method to draw custom content.
|
||||
* Called after panel and header, before subgui.
|
||||
*/
|
||||
protected void drawContent(int mouseX, int mouseY, float partialTicks) {
|
||||
// Override in subclasses
|
||||
}
|
||||
|
||||
/**
|
||||
* Override drawBackground to do nothing - we handle it in drawScreen.
|
||||
*/
|
||||
@Override
|
||||
protected void drawBackground() {
|
||||
// Don't draw default textured background
|
||||
}
|
||||
|
||||
// === Configuration Methods ===
|
||||
|
||||
/**
|
||||
* Set the header title. Pass null to disable header.
|
||||
*/
|
||||
public void setHeaderTitle(String title) {
|
||||
this.headerTitle = title;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set panel colors.
|
||||
*/
|
||||
public void setPanelColors(int background, int border) {
|
||||
this.panelBg = background;
|
||||
this.panelBorder = border;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set overlay color (screen darkening).
|
||||
*/
|
||||
public void setOverlayColor(int color) {
|
||||
this.overlayColor = color;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get content area Y start (after header if present).
|
||||
*/
|
||||
protected int getContentY() {
|
||||
return guiTop + (headerTitle != null ? headerHeight : 0);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get content area height (excluding header if present).
|
||||
*/
|
||||
protected int getContentHeight() {
|
||||
return ySize - (headerTitle != null ? headerHeight : 0);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,743 @@
|
||||
package kamkeel.npcs.client.gui.modern;
|
||||
|
||||
import com.google.common.collect.Lists;
|
||||
import cpw.mods.fml.common.Loader;
|
||||
import cpw.mods.fml.common.ModContainer;
|
||||
import cpw.mods.fml.common.ObfuscationReflectionHelper;
|
||||
import kamkeel.npcs.client.gui.components.ModernButton;
|
||||
import kamkeel.npcs.client.gui.components.ModernTextField;
|
||||
import noppes.npcs.client.gui.util.ModernColors;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.gui.ScaledResolution;
|
||||
import net.minecraft.client.resources.*;
|
||||
import net.minecraft.item.crafting.CraftingManager;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
import net.minecraft.util.StatCollector;
|
||||
import noppes.npcs.CustomNpcs;
|
||||
import noppes.npcs.LogWriter;
|
||||
import noppes.npcs.entity.EntityNPCInterface;
|
||||
import org.lwjgl.opengl.GL11;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.UnsupportedEncodingException;
|
||||
import java.net.URL;
|
||||
import java.net.URLDecoder;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.*;
|
||||
import java.util.zip.ZipEntry;
|
||||
import java.util.zip.ZipFile;
|
||||
|
||||
/**
|
||||
* Modern styled texture selector.
|
||||
* Features domain/folder navigation on left, texture list on right,
|
||||
* with search fields and NPC preview.
|
||||
*/
|
||||
public class ModernTextureSelector extends ModernSubGuiInterface {
|
||||
|
||||
private final String UP_TEXT = "..<" + StatCollector.translateToLocal("gui.up") + ">..";
|
||||
|
||||
// Selection state
|
||||
private String location = "";
|
||||
private String selectedDomain;
|
||||
public ResourceLocation selectedResource;
|
||||
public boolean setNPCSkin = true;
|
||||
|
||||
// Data
|
||||
private final HashMap<String, List<TextureData>> domains = new HashMap<>();
|
||||
private final HashMap<String, TextureData> textures = new HashMap<>();
|
||||
|
||||
// Filtered lists
|
||||
private List<String> filteredFolders = new ArrayList<>();
|
||||
private List<String> filteredTextures = new ArrayList<>();
|
||||
|
||||
// Components
|
||||
private ModernTextField folderSearchField;
|
||||
private ModernTextField textureSearchField;
|
||||
private ModernButton doneBtn;
|
||||
private ModernButton cancelBtn;
|
||||
|
||||
// Layout
|
||||
private int listY;
|
||||
private int listHeight;
|
||||
private int folderListX, folderListW;
|
||||
private int textureListX, textureListW;
|
||||
private int rowHeight = 14;
|
||||
|
||||
// Scroll state
|
||||
private int folderScrollY = 0;
|
||||
private int textureScrollY = 0;
|
||||
private int selectedFolderIndex = -1;
|
||||
private int selectedTextureIndex = -1;
|
||||
|
||||
// Draggable divider
|
||||
private int dividerOffset;
|
||||
private boolean isDraggingDivider = false;
|
||||
private int dividerDragStartX;
|
||||
private int dividerWidth = 5;
|
||||
private int minColumnWidth = 100;
|
||||
|
||||
// Search strings
|
||||
private String folderSearch = "";
|
||||
private String textureSearch = "";
|
||||
|
||||
// NPC reference for preview
|
||||
private EntityNPCInterface npc;
|
||||
|
||||
// Double-click tracking
|
||||
private long lastClickTime = 0;
|
||||
private int lastClickedIndex = -1;
|
||||
private boolean lastClickWasFolder = false;
|
||||
|
||||
// Cache static fields
|
||||
private static final long CACHE_DURATION = 180000L; // 3 minutes
|
||||
private static long lastCacheTime = 0;
|
||||
private static HashMap<String, List<TextureData>> cachedDomains = new HashMap<>();
|
||||
public static HashMap<String, TextureData> cachedTextures = new HashMap<>();
|
||||
|
||||
// Button IDs
|
||||
private static final int ID_DONE = 100;
|
||||
private static final int ID_CANCEL = 101;
|
||||
|
||||
public ModernTextureSelector(EntityNPCInterface npc, String texture) {
|
||||
this.npc = npc;
|
||||
xSize = 420;
|
||||
ySize = 300;
|
||||
setHeaderTitle("Select Texture");
|
||||
|
||||
loadTextureData();
|
||||
|
||||
if (texture != null && !texture.isEmpty()) {
|
||||
selectedResource = new ResourceLocation(texture);
|
||||
selectedDomain = selectedResource.getResourceDomain();
|
||||
if (!domains.containsKey(selectedDomain)) {
|
||||
selectedDomain = null;
|
||||
}
|
||||
int i = selectedResource.getResourcePath().lastIndexOf('/');
|
||||
location = selectedResource.getResourcePath().substring(0, i + 1);
|
||||
}
|
||||
}
|
||||
|
||||
private void loadTextureData() {
|
||||
long now = System.currentTimeMillis();
|
||||
if (cachedDomains != null && now - lastCacheTime < CACHE_DURATION) {
|
||||
domains.putAll(cachedDomains);
|
||||
textures.putAll(cachedTextures);
|
||||
} else {
|
||||
buildTextureData();
|
||||
cachedDomains = new HashMap<>(domains);
|
||||
cachedTextures = new HashMap<>(textures);
|
||||
lastCacheTime = now;
|
||||
}
|
||||
}
|
||||
|
||||
private void buildTextureData() {
|
||||
SimpleReloadableResourceManager simplemanager = (SimpleReloadableResourceManager) Minecraft.getMinecraft().getResourceManager();
|
||||
Map<String, FallbackResourceManager> map = ObfuscationReflectionHelper.getPrivateValue(SimpleReloadableResourceManager.class, simplemanager, 2);
|
||||
HashSet<String> set = new HashSet<>();
|
||||
|
||||
for (String name : map.keySet()) {
|
||||
if (!(map.get(name) instanceof FallbackResourceManager)) continue;
|
||||
FallbackResourceManager manager = (FallbackResourceManager) map.get(name);
|
||||
List<IResourcePack> list = ObfuscationReflectionHelper.getPrivateValue(FallbackResourceManager.class, manager, 0);
|
||||
for (IResourcePack pack : list) {
|
||||
if (pack instanceof AbstractResourcePack) {
|
||||
AbstractResourcePack p = (AbstractResourcePack) pack;
|
||||
File file = NPCResourceHelper.getPackFile(p);
|
||||
if (file != null) set.add(file.getAbsolutePath());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for (String file : set) {
|
||||
File f = new File(file);
|
||||
if (f.isDirectory()) {
|
||||
checkFolder(new File(f, "assets"), f.getAbsolutePath().length());
|
||||
} else {
|
||||
progressFile(f);
|
||||
}
|
||||
}
|
||||
|
||||
for (ModContainer mod : Loader.instance().getModList()) {
|
||||
if (mod.getSource().exists()) progressFile(mod.getSource());
|
||||
}
|
||||
|
||||
ResourcePackRepository repos = Minecraft.getMinecraft().getResourcePackRepository();
|
||||
repos.updateRepositoryEntriesAll();
|
||||
List<?> entries = repos.getRepositoryEntries();
|
||||
for (Object obj : entries) {
|
||||
ResourcePackRepository.Entry entry = (ResourcePackRepository.Entry) obj;
|
||||
File file = new File(repos.getDirResourcepacks(), entry.getResourcePackName());
|
||||
if (file.exists()) progressFile(file);
|
||||
}
|
||||
|
||||
checkFolder(new File(CustomNpcs.Dir, "assets"), CustomNpcs.Dir.getAbsolutePath().length());
|
||||
|
||||
URL url = DefaultResourcePack.class.getResource("/");
|
||||
if (url != null) {
|
||||
File f = decodeFile(url.getFile());
|
||||
if (f.isDirectory()) {
|
||||
checkFolder(new File(f, "assets"), url.getFile().length());
|
||||
} else {
|
||||
progressFile(f);
|
||||
}
|
||||
}
|
||||
|
||||
url = CraftingManager.class.getResource("/assets/.mcassetsroot");
|
||||
if (url != null) {
|
||||
File f = decodeFile(url.getFile());
|
||||
if (f.isDirectory()) {
|
||||
checkFolder(new File(f, "assets"), url.getFile().length());
|
||||
} else {
|
||||
progressFile(f);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private File decodeFile(String url) {
|
||||
if (url.startsWith("file:")) url = url.substring(5);
|
||||
url = url.replace('/', File.separatorChar);
|
||||
int i = url.indexOf('!');
|
||||
if (i > 0) url = url.substring(0, i);
|
||||
try {
|
||||
url = URLDecoder.decode(url, StandardCharsets.UTF_8.name());
|
||||
} catch (UnsupportedEncodingException ignored) {}
|
||||
return new File(url);
|
||||
}
|
||||
|
||||
private void progressFile(File file) {
|
||||
try {
|
||||
if (!file.isDirectory() && (file.getName().endsWith(".jar") || file.getName().endsWith(".zip"))) {
|
||||
ZipFile zip = new ZipFile(file);
|
||||
Enumeration<? extends ZipEntry> entries = zip.entries();
|
||||
while (entries.hasMoreElements()) {
|
||||
ZipEntry zipentry = entries.nextElement();
|
||||
addFile(zipentry.getName());
|
||||
}
|
||||
zip.close();
|
||||
} else if (file.isDirectory()) {
|
||||
checkFolder(file, file.getAbsolutePath().length());
|
||||
}
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
private void checkFolder(File file, int length) {
|
||||
File[] files = file.listFiles();
|
||||
if (files == null) return;
|
||||
for (File f : files) {
|
||||
String name = null;
|
||||
try {
|
||||
name = f.getAbsolutePath().substring(length);
|
||||
name = name.replace("\\", "/");
|
||||
if (!name.startsWith("/")) name = "/" + name;
|
||||
if (f.isDirectory()) {
|
||||
addFile(name + "/");
|
||||
checkFolder(f, length);
|
||||
} else {
|
||||
addFile(name);
|
||||
}
|
||||
} catch (Throwable e) {
|
||||
LogWriter.error("error with: " + name);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void addFile(String name) {
|
||||
if (name.startsWith("/")) name = name.substring(1);
|
||||
if (!name.startsWith("assets/") || !name.endsWith(".png")) return;
|
||||
name = name.substring(7);
|
||||
int i = name.indexOf('/');
|
||||
String domain = name.substring(0, i);
|
||||
name = name.substring(i + 1);
|
||||
|
||||
List<TextureData> list = domains.get(domain);
|
||||
if (list == null) {
|
||||
domains.put(domain, list = new ArrayList<>());
|
||||
}
|
||||
boolean contains = false;
|
||||
for (TextureData data : list) {
|
||||
if (data.absoluteName.equals(name)) {
|
||||
contains = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (!contains) list.add(new TextureData(domain, name));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void initGui() {
|
||||
super.initGui();
|
||||
|
||||
int contentY = getContentY() + 6;
|
||||
int contentH = getContentHeight() - 6;
|
||||
|
||||
if (dividerOffset == 0) {
|
||||
dividerOffset = (xSize - 24) / 2;
|
||||
}
|
||||
|
||||
int pad = 8;
|
||||
folderListX = guiLeft + pad;
|
||||
folderListW = dividerOffset - pad;
|
||||
textureListX = guiLeft + dividerOffset + dividerWidth;
|
||||
textureListW = xSize - dividerOffset - dividerWidth - pad;
|
||||
|
||||
if (folderListW < minColumnWidth) {
|
||||
folderListW = minColumnWidth;
|
||||
dividerOffset = folderListW + pad;
|
||||
textureListX = guiLeft + dividerOffset + dividerWidth;
|
||||
textureListW = xSize - dividerOffset - dividerWidth - pad;
|
||||
}
|
||||
if (textureListW < minColumnWidth) {
|
||||
textureListW = minColumnWidth;
|
||||
dividerOffset = xSize - pad - dividerWidth - textureListW;
|
||||
folderListW = dividerOffset - pad;
|
||||
textureListX = guiLeft + dividerOffset + dividerWidth;
|
||||
}
|
||||
|
||||
int searchH = 18;
|
||||
folderSearchField = new ModernTextField(0, folderListX, contentY, folderListW, searchH);
|
||||
folderSearchField.setPlaceholder("Filter folders...");
|
||||
folderSearchField.setText(folderSearch);
|
||||
|
||||
textureSearchField = new ModernTextField(1, textureListX, contentY, textureListW, searchH);
|
||||
textureSearchField.setPlaceholder("Filter textures...");
|
||||
textureSearchField.setText(textureSearch);
|
||||
|
||||
listY = contentY + searchH + 4;
|
||||
listHeight = contentH - searchH - 36 - 8;
|
||||
|
||||
int btnY = guiTop + ySize - 32;
|
||||
int btnWidth = 60;
|
||||
int btnGap = 8;
|
||||
|
||||
cancelBtn = new ModernButton(ID_CANCEL, guiLeft + xSize - pad - btnWidth * 2 - btnGap, btnY, btnWidth, 20, "Cancel");
|
||||
doneBtn = new ModernButton(ID_DONE, guiLeft + xSize - pad - btnWidth, btnY, btnWidth, 20, "Done");
|
||||
doneBtn.setBackgroundColor(ModernColors.ACCENT_BLUE);
|
||||
|
||||
updateFolderList();
|
||||
updateTextureList();
|
||||
}
|
||||
|
||||
private void updateFolderList() {
|
||||
filteredFolders = new ArrayList<>();
|
||||
|
||||
if (selectedDomain == null) {
|
||||
// Show domains
|
||||
for (String domain : domains.keySet()) {
|
||||
if (folderSearch.isEmpty() || domain.toLowerCase().contains(folderSearch.toLowerCase())) {
|
||||
filteredFolders.add(domain);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
// Show folders within domain
|
||||
filteredFolders.add(UP_TEXT);
|
||||
|
||||
List<TextureData> data = domains.get(selectedDomain);
|
||||
Set<String> folders = new TreeSet<>();
|
||||
for (TextureData td : data) {
|
||||
if (location.isEmpty() || td.path.startsWith(location) && !td.path.equals(location)) {
|
||||
String path = td.path.substring(location.length());
|
||||
int i = path.indexOf('/');
|
||||
if (i < 0) continue;
|
||||
path = path.substring(0, i);
|
||||
if (!path.isEmpty()) folders.add(path);
|
||||
}
|
||||
}
|
||||
|
||||
for (String folder : folders) {
|
||||
if (folderSearch.isEmpty() || folder.toLowerCase().contains(folderSearch.toLowerCase())) {
|
||||
filteredFolders.add(folder);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Collections.sort(filteredFolders.subList(filteredFolders.contains(UP_TEXT) ? 1 : 0, filteredFolders.size()));
|
||||
}
|
||||
|
||||
private void updateTextureList() {
|
||||
textures.clear();
|
||||
filteredTextures = new ArrayList<>();
|
||||
|
||||
if (selectedDomain == null) return;
|
||||
|
||||
List<TextureData> data = domains.get(selectedDomain);
|
||||
String loc = location;
|
||||
if (selectedFolderIndex > 0 && selectedFolderIndex < filteredFolders.size()) {
|
||||
String folder = filteredFolders.get(selectedFolderIndex);
|
||||
if (!folder.equals(UP_TEXT)) {
|
||||
loc += folder + '/';
|
||||
}
|
||||
}
|
||||
|
||||
for (TextureData td : data) {
|
||||
if (td.path.equals(loc)) {
|
||||
if (textureSearch.isEmpty() || td.name.toLowerCase().contains(textureSearch.toLowerCase())) {
|
||||
if (!filteredTextures.contains(td.name)) {
|
||||
filteredTextures.add(td.name);
|
||||
textures.put(td.name, td);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Collections.sort(filteredTextures);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void drawContent(int mouseX, int mouseY, float partialTicks) {
|
||||
// Draw breadcrumb path
|
||||
String pathText = selectedDomain != null ? selectedDomain + ":" + location : "Select a domain";
|
||||
fontRendererObj.drawString(pathText, guiLeft + 8, getContentY() - 12, ModernColors.TEXT_GRAY);
|
||||
|
||||
// Draw column headers
|
||||
int headerY = getContentY() - 2;
|
||||
fontRendererObj.drawString(selectedDomain == null ? "Domains" : "Folders", folderListX, headerY - 10, ModernColors.TEXT_LIGHT);
|
||||
fontRendererObj.drawString("Textures", textureListX, headerY - 10, ModernColors.TEXT_LIGHT);
|
||||
|
||||
folderSearchField.draw(mouseX, mouseY);
|
||||
textureSearchField.draw(mouseX, mouseY);
|
||||
|
||||
drawRect(folderListX, listY, folderListX + folderListW, listY + listHeight, ModernColors.INPUT_BG);
|
||||
drawRect(textureListX, listY, textureListX + textureListW, listY + listHeight, ModernColors.INPUT_BG);
|
||||
|
||||
int divX = guiLeft + dividerOffset;
|
||||
int handleTop = listY + (listHeight - 20) / 2;
|
||||
int handleColor = isDraggingDivider ? ModernColors.ACCENT_BLUE : 0xFF707070;
|
||||
drawRect(divX + 1, handleTop, divX + dividerWidth - 1, handleTop + 20, handleColor);
|
||||
|
||||
drawFolderList(mouseX, mouseY);
|
||||
drawTextureList(mouseX, mouseY);
|
||||
|
||||
if (selectedResource != null) {
|
||||
String info = "Selected: " + selectedResource.toString();
|
||||
info = fontRendererObj.trimStringToWidth(info, xSize - 16);
|
||||
int infoY = listY + listHeight + 4;
|
||||
fontRendererObj.drawString(info, guiLeft + 8, infoY, ModernColors.TEXT_GRAY);
|
||||
}
|
||||
|
||||
doneBtn.drawButton(mc, mouseX, mouseY);
|
||||
cancelBtn.drawButton(mc, mouseX, mouseY);
|
||||
}
|
||||
|
||||
private void drawFolderList(int mouseX, int mouseY) {
|
||||
Minecraft mc = Minecraft.getMinecraft();
|
||||
ScaledResolution sr = new ScaledResolution(mc, mc.displayWidth, mc.displayHeight);
|
||||
int scale = sr.getScaleFactor();
|
||||
|
||||
GL11.glEnable(GL11.GL_SCISSOR_TEST);
|
||||
GL11.glScissor(folderListX * scale, mc.displayHeight - (listY + listHeight) * scale, folderListW * scale, listHeight * scale);
|
||||
|
||||
int visibleRows = listHeight / rowHeight;
|
||||
int startIdx = folderScrollY / rowHeight;
|
||||
int endIdx = Math.min(startIdx + visibleRows + 2, filteredFolders.size());
|
||||
|
||||
for (int i = startIdx; i < endIdx; i++) {
|
||||
int rowY = listY + i * rowHeight - folderScrollY;
|
||||
if (rowY + rowHeight < listY || rowY > listY + listHeight) continue;
|
||||
|
||||
String text = filteredFolders.get(i);
|
||||
boolean isUp = text.equals(UP_TEXT);
|
||||
|
||||
if (i == selectedFolderIndex) {
|
||||
drawRect(folderListX, rowY, folderListX + folderListW, rowY + rowHeight, ModernColors.SELECTION_BG);
|
||||
} else if (mouseX >= folderListX && mouseX < folderListX + folderListW && mouseY >= rowY && mouseY < rowY + rowHeight) {
|
||||
drawRect(folderListX, rowY, folderListX + folderListW, rowY + rowHeight, ModernColors.HOVER_HIGHLIGHT);
|
||||
}
|
||||
|
||||
String displayText = fontRendererObj.trimStringToWidth(text, folderListW - 4);
|
||||
int textColor = isUp ? ModernColors.ACCENT_BLUE : (i == selectedFolderIndex ? ModernColors.TEXT_WHITE : ModernColors.TEXT_LIGHT);
|
||||
fontRendererObj.drawString(displayText, folderListX + 2, rowY + 2, textColor);
|
||||
}
|
||||
|
||||
GL11.glDisable(GL11.GL_SCISSOR_TEST);
|
||||
|
||||
int totalHeight = filteredFolders.size() * rowHeight;
|
||||
if (totalHeight > listHeight) {
|
||||
int sbX = folderListX + folderListW - 4;
|
||||
float viewRatio = (float) listHeight / totalHeight;
|
||||
int thumbH = Math.max(10, (int) (listHeight * viewRatio));
|
||||
float maxScroll = totalHeight - listHeight;
|
||||
int thumbY = maxScroll > 0 ? (int) ((folderScrollY / maxScroll) * (listHeight - thumbH)) : 0;
|
||||
drawRect(sbX, listY, sbX + 4, listY + listHeight, ModernColors.SCROLLBAR_BG);
|
||||
drawRect(sbX, listY + thumbY, sbX + 4, listY + thumbY + thumbH, ModernColors.SCROLLBAR_THUMB);
|
||||
}
|
||||
}
|
||||
|
||||
private void drawTextureList(int mouseX, int mouseY) {
|
||||
Minecraft mc = Minecraft.getMinecraft();
|
||||
ScaledResolution sr = new ScaledResolution(mc, mc.displayWidth, mc.displayHeight);
|
||||
int scale = sr.getScaleFactor();
|
||||
|
||||
GL11.glEnable(GL11.GL_SCISSOR_TEST);
|
||||
GL11.glScissor(textureListX * scale, mc.displayHeight - (listY + listHeight) * scale, textureListW * scale, listHeight * scale);
|
||||
|
||||
int visibleRows = listHeight / rowHeight;
|
||||
int startIdx = textureScrollY / rowHeight;
|
||||
int endIdx = Math.min(startIdx + visibleRows + 2, filteredTextures.size());
|
||||
|
||||
for (int i = startIdx; i < endIdx; i++) {
|
||||
int rowY = listY + i * rowHeight - textureScrollY;
|
||||
if (rowY + rowHeight < listY || rowY > listY + listHeight) continue;
|
||||
|
||||
if (i == selectedTextureIndex) {
|
||||
drawRect(textureListX, rowY, textureListX + textureListW, rowY + rowHeight, ModernColors.SELECTION_BG);
|
||||
} else if (mouseX >= textureListX && mouseX < textureListX + textureListW && mouseY >= rowY && mouseY < rowY + rowHeight) {
|
||||
drawRect(textureListX, rowY, textureListX + textureListW, rowY + rowHeight, ModernColors.HOVER_HIGHLIGHT);
|
||||
}
|
||||
|
||||
String text = filteredTextures.get(i);
|
||||
String displayText = fontRendererObj.trimStringToWidth(text, textureListW - 4);
|
||||
int textColor = i == selectedTextureIndex ? ModernColors.TEXT_WHITE : ModernColors.TEXT_LIGHT;
|
||||
fontRendererObj.drawString(displayText, textureListX + 2, rowY + 2, textColor);
|
||||
}
|
||||
|
||||
GL11.glDisable(GL11.GL_SCISSOR_TEST);
|
||||
|
||||
int totalHeight = filteredTextures.size() * rowHeight;
|
||||
if (totalHeight > listHeight) {
|
||||
int sbX = textureListX + textureListW - 4;
|
||||
float viewRatio = (float) listHeight / totalHeight;
|
||||
int thumbH = Math.max(10, (int) (listHeight * viewRatio));
|
||||
float maxScroll = totalHeight - listHeight;
|
||||
int thumbY = maxScroll > 0 ? (int) ((textureScrollY / maxScroll) * (listHeight - thumbH)) : 0;
|
||||
drawRect(sbX, listY, sbX + 4, listY + listHeight, ModernColors.SCROLLBAR_BG);
|
||||
drawRect(sbX, listY + thumbY, sbX + 4, listY + thumbY + thumbH, ModernColors.SCROLLBAR_THUMB);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateScreen() {
|
||||
super.updateScreen();
|
||||
folderSearchField.updateCursorCounter();
|
||||
textureSearchField.updateCursorCounter();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void mouseClicked(int mouseX, int mouseY, int button) {
|
||||
super.mouseClicked(mouseX, mouseY, button);
|
||||
|
||||
if (button == 0) {
|
||||
int divX = guiLeft + dividerOffset;
|
||||
if (mouseX >= divX && mouseX < divX + dividerWidth &&
|
||||
mouseY >= listY && mouseY < listY + listHeight) {
|
||||
isDraggingDivider = true;
|
||||
dividerDragStartX = mouseX;
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
folderSearchField.mouseClicked(mouseX, mouseY, button);
|
||||
textureSearchField.mouseClicked(mouseX, mouseY, button);
|
||||
|
||||
// Folder list click
|
||||
if (button == 0 && mouseX >= folderListX && mouseX < folderListX + folderListW &&
|
||||
mouseY >= listY && mouseY < listY + listHeight) {
|
||||
int clickedIdx = (mouseY - listY + folderScrollY) / rowHeight;
|
||||
if (clickedIdx >= 0 && clickedIdx < filteredFolders.size()) {
|
||||
long now = System.currentTimeMillis();
|
||||
if (clickedIdx == lastClickedIndex && lastClickWasFolder && now - lastClickTime < 400) {
|
||||
// Double-click on folder
|
||||
handleFolderDoubleClick(clickedIdx);
|
||||
return;
|
||||
}
|
||||
lastClickedIndex = clickedIdx;
|
||||
lastClickTime = now;
|
||||
lastClickWasFolder = true;
|
||||
|
||||
selectedFolderIndex = clickedIdx;
|
||||
textureScrollY = 0;
|
||||
selectedTextureIndex = -1;
|
||||
updateTextureList();
|
||||
}
|
||||
}
|
||||
|
||||
// Texture list click
|
||||
if (button == 0 && mouseX >= textureListX && mouseX < textureListX + textureListW &&
|
||||
mouseY >= listY && mouseY < listY + listHeight) {
|
||||
int clickedIdx = (mouseY - listY + textureScrollY) / rowHeight;
|
||||
if (clickedIdx >= 0 && clickedIdx < filteredTextures.size()) {
|
||||
long now = System.currentTimeMillis();
|
||||
if (clickedIdx == lastClickedIndex && !lastClickWasFolder && now - lastClickTime < 400) {
|
||||
// Double-click on texture - confirm and close
|
||||
confirm();
|
||||
return;
|
||||
}
|
||||
lastClickedIndex = clickedIdx;
|
||||
lastClickTime = now;
|
||||
lastClickWasFolder = false;
|
||||
|
||||
selectedTextureIndex = clickedIdx;
|
||||
String textureName = filteredTextures.get(clickedIdx);
|
||||
TextureData data = textures.get(textureName);
|
||||
if (data != null) {
|
||||
selectedResource = new ResourceLocation(selectedDomain, data.absoluteName);
|
||||
if (setNPCSkin && npc != null) {
|
||||
npc.textureLocation = selectedResource;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (doneBtn.mousePressed(mc, mouseX, mouseY)) {
|
||||
confirm();
|
||||
return;
|
||||
}
|
||||
if (cancelBtn.mousePressed(mc, mouseX, mouseY)) {
|
||||
selectedResource = null;
|
||||
close();
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
private void handleFolderDoubleClick(int idx) {
|
||||
String selection = filteredFolders.get(idx);
|
||||
|
||||
if (selectedDomain == null) {
|
||||
// Select domain
|
||||
selectedDomain = selection;
|
||||
folderScrollY = 0;
|
||||
selectedFolderIndex = -1;
|
||||
} else if (selection.equals(UP_TEXT)) {
|
||||
// Go up
|
||||
int i = location.lastIndexOf('/', location.length() - 2);
|
||||
if (i < 0) {
|
||||
if (location.isEmpty()) {
|
||||
selectedDomain = null;
|
||||
}
|
||||
location = "";
|
||||
} else {
|
||||
location = location.substring(0, i + 1);
|
||||
}
|
||||
folderScrollY = 0;
|
||||
selectedFolderIndex = -1;
|
||||
} else {
|
||||
// Navigate into folder
|
||||
location = location + selection + '/';
|
||||
folderScrollY = 0;
|
||||
selectedFolderIndex = -1;
|
||||
}
|
||||
|
||||
textureScrollY = 0;
|
||||
selectedTextureIndex = -1;
|
||||
updateFolderList();
|
||||
updateTextureList();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void mouseClickMove(int mouseX, int mouseY, int button, long timeSinceLastClick) {
|
||||
if (isDraggingDivider) {
|
||||
int dx = mouseX - dividerDragStartX;
|
||||
dividerDragStartX = mouseX;
|
||||
dividerOffset += dx;
|
||||
|
||||
int pad = 8;
|
||||
int minOffset = pad + minColumnWidth;
|
||||
int maxOffset = xSize - pad - dividerWidth - minColumnWidth;
|
||||
dividerOffset = Math.max(minOffset, Math.min(dividerOffset, maxOffset));
|
||||
|
||||
folderListW = dividerOffset - pad;
|
||||
textureListX = guiLeft + dividerOffset + dividerWidth;
|
||||
textureListW = xSize - dividerOffset - dividerWidth - pad;
|
||||
|
||||
folderSearchField.setBounds(folderListX, folderSearchField.getY(), folderListW, 18);
|
||||
textureSearchField.setBounds(textureListX, textureSearchField.getY(), textureListW, 18);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void mouseMovedOrUp(int mouseX, int mouseY, int state) {
|
||||
isDraggingDivider = false;
|
||||
super.mouseMovedOrUp(mouseX, mouseY, state);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void handleMouseInput() {
|
||||
super.handleMouseInput();
|
||||
|
||||
int delta = org.lwjgl.input.Mouse.getEventDWheel();
|
||||
if (delta != 0) {
|
||||
int mouseX = org.lwjgl.input.Mouse.getEventX() * width / mc.displayWidth;
|
||||
int mouseY = height - org.lwjgl.input.Mouse.getEventY() * height / mc.displayHeight - 1;
|
||||
|
||||
int scrollAmount = delta > 0 ? -rowHeight * 2 : rowHeight * 2;
|
||||
|
||||
if (mouseX >= folderListX && mouseX < folderListX + folderListW &&
|
||||
mouseY >= listY && mouseY < listY + listHeight) {
|
||||
int maxScroll = Math.max(0, filteredFolders.size() * rowHeight - listHeight);
|
||||
folderScrollY = Math.max(0, Math.min(folderScrollY + scrollAmount, maxScroll));
|
||||
}
|
||||
|
||||
if (mouseX >= textureListX && mouseX < textureListX + textureListW &&
|
||||
mouseY >= listY && mouseY < listY + listHeight) {
|
||||
int maxScroll = Math.max(0, filteredTextures.size() * rowHeight - listHeight);
|
||||
textureScrollY = Math.max(0, Math.min(textureScrollY + scrollAmount, maxScroll));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void keyTyped(char typedChar, int keyCode) {
|
||||
if (folderSearchField.isFocused()) {
|
||||
String prev = folderSearchField.getText();
|
||||
folderSearchField.keyTyped(typedChar, keyCode);
|
||||
String newText = folderSearchField.getText();
|
||||
if (!newText.equals(prev)) {
|
||||
folderSearch = newText;
|
||||
updateFolderList();
|
||||
folderScrollY = 0;
|
||||
}
|
||||
}
|
||||
|
||||
if (textureSearchField.isFocused()) {
|
||||
String prev = textureSearchField.getText();
|
||||
textureSearchField.keyTyped(typedChar, keyCode);
|
||||
String newText = textureSearchField.getText();
|
||||
if (!newText.equals(prev)) {
|
||||
textureSearch = newText;
|
||||
updateTextureList();
|
||||
textureScrollY = 0;
|
||||
}
|
||||
}
|
||||
|
||||
super.keyTyped(typedChar, keyCode);
|
||||
}
|
||||
|
||||
private void confirm() {
|
||||
if (selectedResource != null && setNPCSkin && npc != null) {
|
||||
npc.display.setSkinTexture(selectedResource.toString());
|
||||
}
|
||||
if (npc != null) {
|
||||
npc.textureLocation = null;
|
||||
}
|
||||
close();
|
||||
}
|
||||
|
||||
public void setLocation(String domain, String location) {
|
||||
this.selectedDomain = domain;
|
||||
this.location = location;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the selected resource location.
|
||||
*/
|
||||
public ResourceLocation getSelectedResource() {
|
||||
return selectedResource;
|
||||
}
|
||||
|
||||
// Inner class for texture data
|
||||
static class TextureData {
|
||||
String domain;
|
||||
String absoluteName;
|
||||
String name;
|
||||
String path;
|
||||
|
||||
public TextureData(String domain, String absoluteName) {
|
||||
this.domain = domain;
|
||||
int i = absoluteName.lastIndexOf('/');
|
||||
name = absoluteName.substring(i + 1);
|
||||
path = absoluteName.substring(0, i + 1);
|
||||
this.absoluteName = absoluteName;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,99 @@
|
||||
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; }
|
||||
}
|
||||
@@ -0,0 +1,307 @@
|
||||
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 net.minecraft.client.gui.FontRenderer;
|
||||
import noppes.npcs.constants.EnumAvailabilityDialog;
|
||||
import noppes.npcs.constants.EnumAvailabilityFactionType;
|
||||
import noppes.npcs.constants.EnumAvailabilityQuest;
|
||||
import noppes.npcs.constants.EnumDayTime;
|
||||
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.
|
||||
*/
|
||||
public class DialogAvailabilityTab extends DialogEditorTab {
|
||||
|
||||
private int componentGap = 3;
|
||||
|
||||
// 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;
|
||||
|
||||
public DialogAvailabilityTab(DialogEditorPanel parent) {
|
||||
super(parent);
|
||||
initComponents();
|
||||
}
|
||||
|
||||
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")));
|
||||
}
|
||||
|
||||
// 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")));
|
||||
}
|
||||
|
||||
// Faction Requirements
|
||||
factionReqSection = new CollapsibleSection(600, "Faction Requirements", false);
|
||||
for (int i = 0; i < 2; i++) {
|
||||
factionRows.add(new FactionRow(610 + i * 10, i));
|
||||
}
|
||||
|
||||
// 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);
|
||||
}
|
||||
|
||||
@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);
|
||||
}
|
||||
|
||||
@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();
|
||||
}
|
||||
|
||||
@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;
|
||||
}
|
||||
|
||||
@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;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean keyTyped(char c, int keyCode) {
|
||||
if (minLevelField.keyTyped(c, keyCode)) { markDirty(); return true; }
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateScreen() {
|
||||
minLevelField.updateCursorCounter();
|
||||
}
|
||||
|
||||
@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;
|
||||
}
|
||||
|
||||
// === Selection Callbacks ===
|
||||
|
||||
public void onQuestSelected(int slot, int questId, String questName) {
|
||||
// slot 1-4 are availability quest slots
|
||||
int reqSlot = slot - 1;
|
||||
if (reqSlot >= 0 && reqSlot < questReqRows.size()) {
|
||||
questReqRows.get(reqSlot).setSelected(questId, questName);
|
||||
}
|
||||
markDirty();
|
||||
}
|
||||
|
||||
public void onDialogSelected(int slot, int dialogId, String dialogName) {
|
||||
if (slot >= 0 && slot < dialogReqRows.size()) {
|
||||
dialogReqRows.get(slot).setSelected(dialogId, dialogName);
|
||||
}
|
||||
markDirty();
|
||||
}
|
||||
|
||||
public void onFactionSelected(int slot, int factionId, String factionName) {
|
||||
if (slot >= 0 && slot < factionRows.size()) {
|
||||
factionRows.get(slot).setSelected(factionId, factionName);
|
||||
}
|
||||
markDirty();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,77 @@
|
||||
package kamkeel.npcs.client.gui.modern.tabs;
|
||||
|
||||
import kamkeel.npcs.client.gui.modern.DialogEditorPanel;
|
||||
import net.minecraft.client.gui.FontRenderer;
|
||||
import net.minecraft.client.gui.Gui;
|
||||
import noppes.npcs.controllers.data.Dialog;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Abstract base class for dialog editor tabs.
|
||||
* Each tab handles its own drawing, click handling, and keyboard input.
|
||||
*/
|
||||
public abstract class DialogEditorTab extends Gui {
|
||||
|
||||
protected DialogEditorPanel parent;
|
||||
protected Dialog dialog;
|
||||
|
||||
public DialogEditorTab(DialogEditorPanel parent) {
|
||||
this.parent = parent;
|
||||
}
|
||||
|
||||
/**
|
||||
* Called when a dialog is set/loaded into the editor.
|
||||
*/
|
||||
public abstract void loadFromDialog(Dialog dialog);
|
||||
|
||||
/**
|
||||
* Called when saving the dialog - copy component values back to dialog.
|
||||
*/
|
||||
public abstract void saveToDialog(Dialog dialog);
|
||||
|
||||
/**
|
||||
* Draw the tab content.
|
||||
* @return The total content height drawn
|
||||
*/
|
||||
public abstract int draw(int contentX, int contentWidth, int startY, int mouseX, int mouseY, FontRenderer fr);
|
||||
|
||||
/**
|
||||
* Handle mouse click within this tab.
|
||||
* @param mouseX Scroll-adjusted mouse X
|
||||
* @param mouseY Scroll-adjusted mouse Y
|
||||
* @param button Mouse button
|
||||
* @return true if click was handled
|
||||
*/
|
||||
public abstract boolean mouseClicked(int mouseX, int mouseY, int button);
|
||||
|
||||
/**
|
||||
* Handle key typed within this tab.
|
||||
* @return true if key was handled
|
||||
*/
|
||||
public abstract boolean keyTyped(char c, int keyCode);
|
||||
|
||||
/**
|
||||
* Update cursor blink state for text fields.
|
||||
*/
|
||||
public abstract void updateScreen();
|
||||
|
||||
/**
|
||||
* Get all dropdowns in this tab for z-order handling.
|
||||
*/
|
||||
public abstract List<kamkeel.npcs.client.gui.components.ModernDropdown> getDropdowns();
|
||||
|
||||
/**
|
||||
* Set the current dialog reference.
|
||||
*/
|
||||
public void setDialog(Dialog dialog) {
|
||||
this.dialog = dialog;
|
||||
}
|
||||
|
||||
/**
|
||||
* Mark the editor as dirty (unsaved changes).
|
||||
*/
|
||||
protected void markDirty() {
|
||||
parent.markDirty();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,292 @@
|
||||
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.gui.FontRenderer;
|
||||
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.
|
||||
*/
|
||||
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;
|
||||
|
||||
public DialogFeedbackTab(DialogEditorPanel parent) {
|
||||
super(parent);
|
||||
initComponents();
|
||||
}
|
||||
|
||||
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);
|
||||
|
||||
// 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);
|
||||
|
||||
// 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);
|
||||
}
|
||||
|
||||
@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);
|
||||
}
|
||||
|
||||
@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();
|
||||
}
|
||||
|
||||
@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;
|
||||
}
|
||||
|
||||
@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;
|
||||
}
|
||||
|
||||
@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;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateScreen() {
|
||||
soundField.updateCursorCounter();
|
||||
textSoundField.updateCursorCounter();
|
||||
textPitchField.updateCursorCounter();
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<ModernDropdown> getDropdowns() {
|
||||
List<ModernDropdown> dropdowns = new ArrayList<>();
|
||||
dropdowns.add(renderTypeDropdown);
|
||||
return dropdowns;
|
||||
}
|
||||
|
||||
// === Selection Callbacks ===
|
||||
|
||||
public void onSoundSelected(String soundPath) {
|
||||
soundField.setText(soundPath);
|
||||
markDirty();
|
||||
}
|
||||
|
||||
public void onColorSelected(int slot, int color) {
|
||||
if (slot == 0) textColorBtn.setColor(color);
|
||||
else if (slot == 1) titleColorBtn.setColor(color);
|
||||
markDirty();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,184 @@
|
||||
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.constants.EnumOptionType;
|
||||
import noppes.npcs.controllers.data.Dialog;
|
||||
import noppes.npcs.controllers.data.DialogOption;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Options tab for the dialog editor.
|
||||
* Contains up to 6 dialog option editors.
|
||||
*/
|
||||
public class DialogOptionsTab extends DialogEditorTab {
|
||||
|
||||
private List<OptionEditorV2> optionEditors = new ArrayList<>();
|
||||
private ModernButton addOptionBtn;
|
||||
private int componentGap = 3;
|
||||
|
||||
public DialogOptionsTab(DialogEditorPanel parent) {
|
||||
super(parent);
|
||||
initComponents();
|
||||
}
|
||||
|
||||
private void initComponents() {
|
||||
addOptionBtn = new ModernButton(200, 0, 0, 80, 16, "+ Add Option");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void loadFromDialog(Dialog dialog) {
|
||||
this.dialog = dialog;
|
||||
rebuildOptionEditors();
|
||||
}
|
||||
|
||||
@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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@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;
|
||||
}
|
||||
|
||||
@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;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean keyTyped(char c, int keyCode) {
|
||||
for (OptionEditorV2 editor : optionEditors) {
|
||||
if (editor.keyTyped(c, keyCode)) { markDirty(); return true; }
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateScreen() {
|
||||
for (OptionEditorV2 editor : optionEditors) {
|
||||
editor.updateCursorCounter();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<ModernDropdown> getDropdowns() {
|
||||
List<ModernDropdown> dropdowns = new ArrayList<>();
|
||||
for (OptionEditorV2 editor : optionEditors) {
|
||||
dropdowns.add(editor.getTypeDropdown());
|
||||
}
|
||||
return dropdowns;
|
||||
}
|
||||
|
||||
// === Option Management ===
|
||||
|
||||
private void addNewOption() {
|
||||
if (dialog == null || optionEditors.size() >= 6) return;
|
||||
|
||||
for (int i = 0; i < 6; i++) {
|
||||
DialogOption opt = dialog.options.get(i);
|
||||
if (opt == null || opt.optionType == EnumOptionType.Disabled) {
|
||||
DialogOption newOpt = new DialogOption();
|
||||
newOpt.title = "New Option";
|
||||
newOpt.optionType = EnumOptionType.QuitOption;
|
||||
dialog.options.put(i, newOpt);
|
||||
rebuildOptionEditors();
|
||||
markDirty();
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void removeOption(int slot) {
|
||||
if (dialog == null) return;
|
||||
DialogOption opt = dialog.options.get(slot);
|
||||
if (opt != null) {
|
||||
opt.optionType = EnumOptionType.Disabled;
|
||||
rebuildOptionEditors();
|
||||
markDirty();
|
||||
}
|
||||
}
|
||||
|
||||
// === Accessors ===
|
||||
|
||||
public List<OptionEditorV2> getOptionEditors() {
|
||||
return optionEditors;
|
||||
}
|
||||
|
||||
public void onOptionDialogSelected(int optionSlot, int dialogId, String dialogName) {
|
||||
for (OptionEditorV2 editor : optionEditors) {
|
||||
if (editor.getSlot() == optionSlot) {
|
||||
editor.setTargetDialog(dialogId, dialogName);
|
||||
markDirty();
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,246 @@
|
||||
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.Dialog;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Settings tab for the dialog editor.
|
||||
* Contains quest, mail, and command configuration.
|
||||
*/
|
||||
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;
|
||||
|
||||
public DialogSettingsTab(DialogEditorPanel parent) {
|
||||
super(parent);
|
||||
initComponents();
|
||||
}
|
||||
|
||||
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");
|
||||
|
||||
// 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");
|
||||
|
||||
// Command Section
|
||||
commandSection = new CollapsibleSection(420, "Command", false);
|
||||
commandArea = new ModernTextArea(421, 0, 0, 100, 60);
|
||||
commandArea.setMaxLength(32767);
|
||||
}
|
||||
|
||||
@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);
|
||||
}
|
||||
|
||||
@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();
|
||||
}
|
||||
|
||||
@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;
|
||||
}
|
||||
|
||||
@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;
|
||||
}
|
||||
|
||||
@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;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateScreen() {
|
||||
mailSubjectField.updateCursorCounter();
|
||||
mailSenderField.updateCursorCounter();
|
||||
commandArea.updateCursorCounter();
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<ModernDropdown> getDropdowns() {
|
||||
return new ArrayList<>(); // No dropdowns in this tab
|
||||
}
|
||||
|
||||
// === Selection Callbacks ===
|
||||
|
||||
public void onQuestSelected(int questId, String questName) {
|
||||
questSelectBtn.setSelected(questId, questName);
|
||||
markDirty();
|
||||
}
|
||||
|
||||
// === Accessors ===
|
||||
|
||||
public ModernTextArea getCommandArea() {
|
||||
return commandArea;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,120 @@
|
||||
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.controllers.data.Dialog;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Text tab for the dialog editor.
|
||||
* Contains title and dialog text fields.
|
||||
*/
|
||||
public class DialogTextTab extends DialogEditorTab {
|
||||
|
||||
private ModernTextField titleField;
|
||||
private ModernTextArea textArea;
|
||||
|
||||
public DialogTextTab(DialogEditorPanel parent) {
|
||||
super(parent);
|
||||
initComponents();
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void loadFromDialog(Dialog dialog) {
|
||||
this.dialog = dialog;
|
||||
if (dialog == null) return;
|
||||
|
||||
titleField.setText(dialog.title);
|
||||
textArea.setText(dialog.text);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void saveToDialog(Dialog dialog) {
|
||||
if (dialog == null) return;
|
||||
|
||||
dialog.title = titleField.getText();
|
||||
dialog.text = textArea.getText();
|
||||
}
|
||||
|
||||
@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;
|
||||
}
|
||||
|
||||
@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;
|
||||
}
|
||||
|
||||
@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;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateScreen() {
|
||||
titleField.updateCursorCounter();
|
||||
textArea.updateCursorCounter();
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<ModernDropdown> getDropdowns() {
|
||||
return new ArrayList<>(); // No dropdowns in this tab
|
||||
}
|
||||
|
||||
// === Accessors for parent panel ===
|
||||
|
||||
public ModernTextArea getTextArea() {
|
||||
return textArea;
|
||||
}
|
||||
|
||||
public String getTitle() {
|
||||
return titleField.getText();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,106 @@
|
||||
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; }
|
||||
}
|
||||
@@ -0,0 +1,178 @@
|
||||
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(); }
|
||||
}
|
||||
@@ -6,7 +6,6 @@ import net.minecraft.client.gui.GuiButton;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import noppes.npcs.client.EntityUtil;
|
||||
import noppes.npcs.client.NoppesUtil;
|
||||
import noppes.npcs.client.gui.global.GuiNPCManageDialogs;
|
||||
import noppes.npcs.client.gui.player.GuiDialogInteract;
|
||||
import noppes.npcs.client.gui.select.GuiQuestSelection;
|
||||
import noppes.npcs.client.gui.select.GuiSoundSelection;
|
||||
@@ -15,6 +14,7 @@ import noppes.npcs.client.gui.util.GuiNpcButtonYesNo;
|
||||
import noppes.npcs.client.gui.util.GuiNpcLabel;
|
||||
import noppes.npcs.client.gui.util.GuiNpcTextField;
|
||||
import noppes.npcs.client.gui.util.GuiSelectionListener;
|
||||
import noppes.npcs.client.gui.util.IDialogEditorParent;
|
||||
import noppes.npcs.client.gui.util.ISubGuiListener;
|
||||
import noppes.npcs.client.gui.util.ITextfieldListener;
|
||||
import noppes.npcs.client.gui.util.SubGuiInterface;
|
||||
@@ -25,9 +25,9 @@ import noppes.npcs.entity.EntityDialogNpc;
|
||||
public class SubGuiNpcDialog extends SubGuiInterface implements ISubGuiListener, GuiSelectionListener, ITextfieldListener {
|
||||
public int dialogCategoryID;
|
||||
public Dialog dialog;
|
||||
private final GuiNPCManageDialogs parent;
|
||||
private final IDialogEditorParent parent;
|
||||
|
||||
public SubGuiNpcDialog(GuiNPCManageDialogs parent, Dialog dialog, int catId) {
|
||||
public SubGuiNpcDialog(IDialogEditorParent parent, Dialog dialog, int catId) {
|
||||
this.parent = parent;
|
||||
this.dialog = dialog;
|
||||
this.dialogCategoryID = catId;
|
||||
@@ -79,8 +79,8 @@ public class SubGuiNpcDialog extends SubGuiInterface implements ISubGuiListener,
|
||||
addButton(new GuiNpcButton(16, guiLeft + 303, guiTop + 192, 50, 20, "gui.done"));
|
||||
addButton(new GuiNpcButton(17, guiLeft + 303 - 55, guiTop + 192, 50, 20, "gui.test"));
|
||||
|
||||
if (!parent.dialogQuestName.equals(""))
|
||||
getButton(7).setDisplayText(parent.dialogQuestName);
|
||||
if (!parent.getDialogQuestName().equals(""))
|
||||
getButton(7).setDisplayText(parent.getDialogQuestName());
|
||||
|
||||
if (!dialog.mail.subject.isEmpty())
|
||||
getButton(13).setDisplayText(dialog.mail.subject);
|
||||
@@ -105,7 +105,7 @@ public class SubGuiNpcDialog extends SubGuiInterface implements ISubGuiListener,
|
||||
}
|
||||
if (id == 8 && dialog.id >= 0) {
|
||||
dialog.quest = -1;
|
||||
parent.dialogQuestName = "";
|
||||
parent.setDialogQuestName("");
|
||||
initGui();
|
||||
}
|
||||
if (id == 9 && dialog.id >= 0) {
|
||||
@@ -148,14 +148,14 @@ public class SubGuiNpcDialog extends SubGuiInterface implements ISubGuiListener,
|
||||
guiNpcTextField.setText("");
|
||||
else {
|
||||
String name = guiNpcTextField.getText();
|
||||
if (name.isEmpty() || this.parent.dialogData.containsKey(name)) {
|
||||
if (name.isEmpty() || this.parent.getDialogData().containsKey(name)) {
|
||||
guiNpcTextField.setText(dialog.title);
|
||||
} else if (dialog.id >= 0) {
|
||||
String old = dialog.title;
|
||||
this.parent.dialogData.remove(old);
|
||||
this.parent.getDialogData().remove(old);
|
||||
dialog.title = name;
|
||||
this.parent.dialogData.put(dialog.title, dialog.id);
|
||||
this.parent.dialogScroll.replace(old, dialog.title);
|
||||
this.parent.getDialogData().put(dialog.title, dialog.id);
|
||||
this.parent.getDialogScroll().replace(old, dialog.title);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -192,7 +192,7 @@ public class SubGuiNpcDialog extends SubGuiInterface implements ISubGuiListener,
|
||||
@Override
|
||||
public void selected(int ob, String name) {
|
||||
dialog.quest = ob;
|
||||
parent.dialogQuestName = name;
|
||||
parent.setDialogQuestName(name);
|
||||
initGui();
|
||||
PacketClient.sendClient(new DialogSavePacket(this.dialogCategoryID, dialog.writeToNBT(new NBTTagCompound()), false));
|
||||
}
|
||||
|
||||
File diff suppressed because it is too large.
Load diff
@@ -23,6 +23,7 @@ import noppes.npcs.client.gui.util.GuiNpcButton;
|
||||
import noppes.npcs.client.gui.util.GuiNpcLabel;
|
||||
import noppes.npcs.client.gui.util.GuiNpcTextField;
|
||||
import noppes.npcs.client.gui.util.ICustomScrollListener;
|
||||
import noppes.npcs.client.gui.util.IDialogEditorParent;
|
||||
import noppes.npcs.client.gui.util.IGuiData;
|
||||
import noppes.npcs.client.gui.util.IScrollData;
|
||||
import noppes.npcs.client.gui.util.ISubGuiListener;
|
||||
@@ -37,7 +38,7 @@ import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Vector;
|
||||
|
||||
public class GuiNPCManageDialogs extends GuiNPCInterface2 implements IScrollData, ISubGuiListener, ICustomScrollListener, IGuiData, GuiYesNoCallback {
|
||||
public class GuiNPCManageDialogs extends GuiNPCInterface2 implements IScrollData, ISubGuiListener, ICustomScrollListener, IGuiData, GuiYesNoCallback, IDialogEditorParent {
|
||||
private GuiCustomScroll catScroll;
|
||||
public GuiCustomScroll dialogScroll;
|
||||
|
||||
@@ -106,6 +107,7 @@ public class GuiNPCManageDialogs extends GuiNPCInterface2 implements IScrollData
|
||||
this.addButton(new GuiNpcButton(4, guiLeft + 3, guiTop + 38, 58, 20, "gui.add"));
|
||||
this.addButton(new GuiNpcButton(5, guiLeft + 3, guiTop + 61, 58, 20, "gui.remove"));
|
||||
this.addButton(new GuiNpcButton(6, guiLeft + 3, guiTop + 94, 58, 20, "gui.edit"));
|
||||
this.addButton(new GuiNpcButton(9, guiLeft + 3, guiTop + 117, 58, 20, "gui.graph"));
|
||||
|
||||
this.addButton(new GuiNpcButton(33, guiLeft + 358, guiTop + 8, 58, 20, "dialog.dialogs"));
|
||||
getButton(33).setEnabled(false);
|
||||
@@ -113,6 +115,7 @@ public class GuiNPCManageDialogs extends GuiNPCInterface2 implements IScrollData
|
||||
this.addButton(new GuiNpcButton(1, guiLeft + 358, guiTop + 38, 58, 20, "gui.add"));
|
||||
this.addButton(new GuiNpcButton(2, guiLeft + 358, guiTop + 61, 58, 20, "gui.remove"));
|
||||
this.addButton(new GuiNpcButton(3, guiLeft + 358, guiTop + 117, 58, 20, "gui.copy"));
|
||||
this.addButton(new GuiNpcButton(8, guiLeft + 358, guiTop + 140, 58, 20, "gui.graph"));
|
||||
|
||||
if (dialog != null) {
|
||||
if (dialog.id != -1) {
|
||||
@@ -344,6 +347,18 @@ public class GuiNPCManageDialogs extends GuiNPCInterface2 implements IScrollData
|
||||
}
|
||||
}
|
||||
}
|
||||
// Graph (category) - left side button
|
||||
if (id == 9) {
|
||||
if (category != null && category.id >= 0) {
|
||||
NoppesUtil.openGUI(player, new GuiDialogTree(npc, category.id, dialogData));
|
||||
}
|
||||
}
|
||||
// Graph (individual dialog) - right side button
|
||||
if (id == 8) {
|
||||
if (category != null && category.id >= 0 && dialog != null && dialog.id >= 0) {
|
||||
NoppesUtil.openGUI(player, new GuiDialogTree(npc, dialog.id, 10));
|
||||
}
|
||||
}
|
||||
updateButtons();
|
||||
}
|
||||
|
||||
@@ -368,6 +383,8 @@ public class GuiNPCManageDialogs extends GuiNPCInterface2 implements IScrollData
|
||||
|
||||
getButton(0).setEnabled(enabled && diagEnabled);
|
||||
getButton(3).setEnabled(enabled && diagEnabled);
|
||||
getButton(9).setEnabled(enabled);
|
||||
getButton(8).setEnabled(enabled && diagEnabled);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -488,6 +505,19 @@ public class GuiNPCManageDialogs extends GuiNPCInterface2 implements IScrollData
|
||||
public void save() {
|
||||
}
|
||||
|
||||
// IDialogEditorParent
|
||||
@Override
|
||||
public HashMap<String, Integer> getDialogData() { return dialogData; }
|
||||
|
||||
@Override
|
||||
public GuiCustomScroll getDialogScroll() { return dialogScroll; }
|
||||
|
||||
@Override
|
||||
public String getDialogQuestName() { return dialogQuestName; }
|
||||
|
||||
@Override
|
||||
public void setDialogQuestName(String name) { dialogQuestName = name; }
|
||||
|
||||
@Override
|
||||
public void setData(Vector<String> list, HashMap<String, Integer> data, EnumScrollData type) {
|
||||
if (type == EnumScrollData.DIALOG_GROUP) {
|
||||
|
||||
@@ -0,0 +1,117 @@
|
||||
package noppes.npcs.client.gui.global;
|
||||
|
||||
import net.minecraft.client.gui.GuiButton;
|
||||
import noppes.npcs.client.gui.util.GuiNpcButton;
|
||||
import noppes.npcs.client.gui.util.GuiNpcLabel;
|
||||
import noppes.npcs.client.gui.util.GuiNpcTextField;
|
||||
import noppes.npcs.client.gui.util.ITextfieldListener;
|
||||
import noppes.npcs.client.gui.util.SubGuiInterface;
|
||||
import noppes.npcs.constants.EnumOptionType;
|
||||
import noppes.npcs.controllers.data.Dialog;
|
||||
import noppes.npcs.controllers.data.DialogOption;
|
||||
|
||||
/**
|
||||
* Sub-GUI shown during link mode: pick which option slot to use and set the title.
|
||||
*/
|
||||
public class SubGuiLinkDialog extends SubGuiInterface implements ITextfieldListener {
|
||||
|
||||
private final Dialog sourceDialog;
|
||||
private final Dialog targetDialog;
|
||||
|
||||
private int selectedSlot = -1;
|
||||
private String optionTitle;
|
||||
public boolean confirmed = false;
|
||||
|
||||
// Available slots (0-5)
|
||||
private static final int MAX_SLOTS = 6;
|
||||
|
||||
public SubGuiLinkDialog(Dialog source, Dialog target) {
|
||||
this.sourceDialog = source;
|
||||
this.targetDialog = target;
|
||||
this.optionTitle = target.title;
|
||||
setBackground("menubg.png");
|
||||
xSize = 250;
|
||||
ySize = 160;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void initGui() {
|
||||
super.initGui();
|
||||
|
||||
addLabel(new GuiNpcLabel(0, "Link: " + sourceDialog.title + " -> " + targetDialog.title,
|
||||
guiLeft + 4, guiTop + 6, 0xFFFFFF));
|
||||
|
||||
// Slot selector buttons
|
||||
addLabel(new GuiNpcLabel(1, "dialog.options", guiLeft + 4, guiTop + 26));
|
||||
|
||||
String[] slotLabels = new String[MAX_SLOTS];
|
||||
for (int i = 0; i < MAX_SLOTS; i++) {
|
||||
DialogOption existing = sourceDialog.options.get(i);
|
||||
if (existing != null && existing.optionType != EnumOptionType.Disabled) {
|
||||
slotLabels[i] = i + ": " + existing.title;
|
||||
} else {
|
||||
slotLabels[i] = i + ": (empty)";
|
||||
}
|
||||
}
|
||||
|
||||
// Find first available empty slot
|
||||
if (selectedSlot < 0) {
|
||||
for (int i = 0; i < MAX_SLOTS; i++) {
|
||||
DialogOption existing = sourceDialog.options.get(i);
|
||||
if (existing == null || existing.optionType == EnumOptionType.Disabled) {
|
||||
selectedSlot = i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (selectedSlot < 0) selectedSlot = 0;
|
||||
}
|
||||
|
||||
addButton(new GuiNpcButton(1, guiLeft + 70, guiTop + 22, 170, 20, slotLabels, selectedSlot));
|
||||
|
||||
// Option title field
|
||||
addLabel(new GuiNpcLabel(2, "gui.title", guiLeft + 4, guiTop + 52));
|
||||
addTextField(new GuiNpcTextField(2, this, fontRendererObj, guiLeft + 70, guiTop + 48, 170, 20, optionTitle));
|
||||
|
||||
// Confirm / Cancel
|
||||
addButton(new GuiNpcButton(10, guiLeft + 40, guiTop + 130, 80, 20, "gui.done"));
|
||||
addButton(new GuiNpcButton(11, guiLeft + 130, guiTop + 130, 80, 20, "gui.cancel"));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void buttonEvent(GuiButton guibutton) {
|
||||
int id = guibutton.id;
|
||||
if (id == 1) {
|
||||
selectedSlot = ((GuiNpcButton) guibutton).getValue();
|
||||
}
|
||||
if (id == 10) {
|
||||
// Confirm
|
||||
confirmed = true;
|
||||
applyLink();
|
||||
close();
|
||||
}
|
||||
if (id == 11) {
|
||||
// Cancel
|
||||
close();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void unFocused(GuiNpcTextField textField) {
|
||||
if (textField.id == 2) {
|
||||
optionTitle = textField.getText();
|
||||
}
|
||||
}
|
||||
|
||||
private void applyLink() {
|
||||
if (selectedSlot < 0 || selectedSlot >= MAX_SLOTS) return;
|
||||
|
||||
DialogOption option = sourceDialog.options.get(selectedSlot);
|
||||
if (option == null) {
|
||||
option = new DialogOption();
|
||||
sourceDialog.options.put(selectedSlot, option);
|
||||
}
|
||||
option.optionType = EnumOptionType.DialogOption;
|
||||
option.dialogId = targetDialog.id;
|
||||
option.title = optionTitle;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,220 @@
|
||||
package noppes.npcs.client.gui.util;
|
||||
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.gui.FontRenderer;
|
||||
import net.minecraft.client.gui.Gui;
|
||||
|
||||
/**
|
||||
* Abstract base class for standalone GUI components.
|
||||
* Provides common functionality for modern UI elements that don't extend
|
||||
* Minecraft's built-in widget classes.
|
||||
*
|
||||
* Components extending this class:
|
||||
* - ModernCheckbox
|
||||
* - ModernToggle
|
||||
* - ModernDropdown
|
||||
* - ModernLabel
|
||||
* - ModernColorButton
|
||||
* - ModernSelectButton
|
||||
* - CollapsibleSection
|
||||
* - ScrollPanel
|
||||
*
|
||||
* Components that wrap Minecraft classes (ModernButton extends GuiNpcButton,
|
||||
* ModernTextField extends GuiNpcTextField) should NOT extend this class.
|
||||
*/
|
||||
public abstract class AbstractGuiComponent extends Gui {
|
||||
|
||||
// === Identity ===
|
||||
protected int id;
|
||||
|
||||
// === Position & Size ===
|
||||
protected int x, y;
|
||||
protected int width, height;
|
||||
|
||||
// === State ===
|
||||
protected boolean enabled = true;
|
||||
protected boolean visible = true;
|
||||
protected boolean hovered = false;
|
||||
|
||||
// === Minecraft reference ===
|
||||
protected Minecraft mc = Minecraft.getMinecraft();
|
||||
|
||||
// === Constructors ===
|
||||
|
||||
protected AbstractGuiComponent() {
|
||||
this(0);
|
||||
}
|
||||
|
||||
protected AbstractGuiComponent(int id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
protected AbstractGuiComponent(int id, int x, int y, int width, int height) {
|
||||
this.id = id;
|
||||
this.x = x;
|
||||
this.y = y;
|
||||
this.width = width;
|
||||
this.height = height;
|
||||
}
|
||||
|
||||
// === Abstract Methods ===
|
||||
|
||||
/**
|
||||
* Draw this component.
|
||||
* @param mouseX Current mouse X position
|
||||
* @param mouseY Current mouse Y position
|
||||
*/
|
||||
public abstract void draw(int mouseX, int mouseY);
|
||||
|
||||
// === Optional Override Methods ===
|
||||
|
||||
/**
|
||||
* Handle mouse click event.
|
||||
* @param mouseX Mouse X position
|
||||
* @param mouseY Mouse Y position
|
||||
* @param button Mouse button (0=left, 1=right, 2=middle)
|
||||
* @return true if the click was handled
|
||||
*/
|
||||
public boolean mouseClicked(int mouseX, int mouseY, int button) {
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle mouse release event.
|
||||
* @param mouseX Mouse X position
|
||||
* @param mouseY Mouse Y position
|
||||
* @param button Mouse button
|
||||
* @return true if the release was handled
|
||||
*/
|
||||
public boolean mouseReleased(int mouseX, int mouseY, int button) {
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle key typed event.
|
||||
* @param c Character typed
|
||||
* @param keyCode Key code
|
||||
* @return true if the key was handled
|
||||
*/
|
||||
public boolean keyTyped(char c, int keyCode) {
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle mouse scroll event.
|
||||
* @param delta Scroll delta (positive = up, negative = down)
|
||||
* @return true if the scroll was handled
|
||||
*/
|
||||
public boolean mouseScrolled(int delta) {
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Called each tick to update animation states.
|
||||
*/
|
||||
public void updateScreen() {
|
||||
// Override if animation needed
|
||||
}
|
||||
|
||||
// === Utility Methods ===
|
||||
|
||||
/**
|
||||
* Check if the mouse is inside this component's bounds.
|
||||
*/
|
||||
public boolean isInside(int mouseX, int mouseY) {
|
||||
return mouseX >= x && mouseX < x + width &&
|
||||
mouseY >= y && mouseY < y + height;
|
||||
}
|
||||
|
||||
/**
|
||||
* Update hover state based on mouse position.
|
||||
* Call this at the start of draw() for proper hover detection.
|
||||
*/
|
||||
protected void updateHoverState(int mouseX, int mouseY) {
|
||||
hovered = enabled && isInside(mouseX, mouseY);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the font renderer.
|
||||
*/
|
||||
protected FontRenderer getFontRenderer() {
|
||||
return mc.fontRenderer;
|
||||
}
|
||||
|
||||
/**
|
||||
* Draw a string with the default font renderer.
|
||||
*/
|
||||
protected void drawText(String text, int x, int y, int color) {
|
||||
getFontRenderer().drawString(text, x, y, color);
|
||||
}
|
||||
|
||||
/**
|
||||
* Draw a string with shadow.
|
||||
*/
|
||||
protected void drawTextWithShadow(String text, int x, int y, int color) {
|
||||
getFontRenderer().drawStringWithShadow(text, x, y, color);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the width of a string in pixels.
|
||||
*/
|
||||
protected int getTextWidth(String text) {
|
||||
return getFontRenderer().getStringWidth(text);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the height of text in pixels.
|
||||
*/
|
||||
protected int getTextHeight() {
|
||||
return getFontRenderer().FONT_HEIGHT;
|
||||
}
|
||||
|
||||
/**
|
||||
* Trim a string to fit within a given width.
|
||||
*/
|
||||
protected String trimToWidth(String text, int maxWidth) {
|
||||
return getFontRenderer().trimStringToWidth(text, maxWidth);
|
||||
}
|
||||
|
||||
// === Getters & Setters ===
|
||||
|
||||
public int getId() { return id; }
|
||||
public void setId(int id) { this.id = id; }
|
||||
|
||||
public int getX() { return x; }
|
||||
public void setX(int x) { this.x = x; }
|
||||
|
||||
public int getY() { return y; }
|
||||
public void setY(int y) { this.y = y; }
|
||||
|
||||
public int getWidth() { return width; }
|
||||
public void setWidth(int width) { this.width = width; }
|
||||
|
||||
public int getHeight() { return height; }
|
||||
public void setHeight(int height) { this.height = height; }
|
||||
|
||||
public void setPosition(int x, int y) {
|
||||
this.x = x;
|
||||
this.y = y;
|
||||
}
|
||||
|
||||
public void setSize(int width, int height) {
|
||||
this.width = width;
|
||||
this.height = height;
|
||||
}
|
||||
|
||||
public void setBounds(int x, int y, int width, int height) {
|
||||
this.x = x;
|
||||
this.y = y;
|
||||
this.width = width;
|
||||
this.height = height;
|
||||
}
|
||||
|
||||
public boolean isEnabled() { return enabled; }
|
||||
public void setEnabled(boolean enabled) { this.enabled = enabled; }
|
||||
|
||||
public boolean isVisible() { return visible; }
|
||||
public void setVisible(boolean visible) { this.visible = visible; }
|
||||
|
||||
public boolean isHovered() { return hovered; }
|
||||
}
|
||||
@@ -0,0 +1,757 @@
|
||||
package noppes.npcs.client.gui.util;
|
||||
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.gui.Gui;
|
||||
import net.minecraft.client.gui.ScaledResolution;
|
||||
import noppes.npcs.client.ClientProxy;
|
||||
import org.lwjgl.input.Mouse;
|
||||
import org.lwjgl.opengl.GL11;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.Comparator;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Queue;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* Abstract pannable/zoomable canvas for rendering rectangular nodes with text
|
||||
* and curved connections. Text is rendered in screen-space for crisp display at any zoom.
|
||||
*/
|
||||
public abstract class GuiAdvancedDiagram extends Gui {
|
||||
|
||||
// ===== Inner Data Structures =====
|
||||
|
||||
public static class AdvancedNode {
|
||||
public int id;
|
||||
public String title;
|
||||
public String subtitle;
|
||||
public List<NodeSlot> slots;
|
||||
public int headerColor;
|
||||
public int x, y;
|
||||
public int width, height;
|
||||
public boolean selected;
|
||||
|
||||
public AdvancedNode(int id, String title) {
|
||||
this.id = id;
|
||||
this.title = title;
|
||||
this.slots = new ArrayList<>();
|
||||
this.headerColor = 0xFF4488CC;
|
||||
}
|
||||
}
|
||||
|
||||
public static class NodeSlot {
|
||||
public int index;
|
||||
public String label;
|
||||
public int color;
|
||||
public int targetNodeId;
|
||||
public int type; // 0=linked, 1=quit, 2=command, 3=disabled
|
||||
|
||||
public NodeSlot(int index, String label, int color, int targetNodeId, int type) {
|
||||
this.index = index;
|
||||
this.label = label;
|
||||
this.color = color;
|
||||
this.targetNodeId = targetNodeId;
|
||||
this.type = type;
|
||||
}
|
||||
}
|
||||
|
||||
public static class AdvancedConnection {
|
||||
public int sourceNodeId;
|
||||
public int sourceSlot;
|
||||
public int targetNodeId;
|
||||
public int color;
|
||||
|
||||
public AdvancedConnection(int sourceNodeId, int sourceSlot, int targetNodeId, int color) {
|
||||
this.sourceNodeId = sourceNodeId;
|
||||
this.sourceSlot = sourceSlot;
|
||||
this.targetNodeId = targetNodeId;
|
||||
this.color = color;
|
||||
}
|
||||
}
|
||||
|
||||
/** Buffered text entry for screen-space rendering */
|
||||
private static class PendingText {
|
||||
float worldX, worldY;
|
||||
String text;
|
||||
int color;
|
||||
boolean centered;
|
||||
int maxWidth;
|
||||
|
||||
PendingText(float wx, float wy, String text, int color, boolean centered, int maxWidth) {
|
||||
this.worldX = wx;
|
||||
this.worldY = wy;
|
||||
this.text = text;
|
||||
this.color = color;
|
||||
this.centered = centered;
|
||||
this.maxWidth = maxWidth;
|
||||
}
|
||||
}
|
||||
|
||||
// ===== Layout Constants =====
|
||||
protected int nodeMinWidth = 100;
|
||||
protected int nodeMaxWidth = 160;
|
||||
protected int nodeHeaderHeight = 14;
|
||||
protected int slotHeight = 11;
|
||||
protected int nodePadding = 4;
|
||||
protected int nodeSpacingX = 50;
|
||||
protected int nodeSpacingY = 35;
|
||||
protected int connectionPointRadius = 3;
|
||||
|
||||
// ===== Diagram Bounds =====
|
||||
protected int x, y, diagramWidth, diagramHeight;
|
||||
|
||||
// ===== Pan/Zoom =====
|
||||
protected float panX = 0, panY = 0;
|
||||
protected float zoom = 1.0f;
|
||||
protected static final float MIN_ZOOM = 0.3f;
|
||||
protected static final float MAX_ZOOM = 3.0f;
|
||||
|
||||
// ===== Dragging =====
|
||||
protected boolean dragging = false;
|
||||
protected int lastDragX, lastDragY;
|
||||
|
||||
// ===== Node Cache =====
|
||||
protected Map<Integer, AdvancedNode> nodes;
|
||||
protected List<AdvancedConnection> connections;
|
||||
|
||||
// ===== Selection/Hover =====
|
||||
protected int selectedNodeId = -1;
|
||||
protected int hoveredNodeId = -1;
|
||||
|
||||
// ===== Double-click =====
|
||||
private long lastClickTime = 0;
|
||||
private int lastClickedNodeId = -1;
|
||||
private static final long DOUBLE_CLICK_MS = 400;
|
||||
|
||||
// ===== Text Buffer =====
|
||||
private final List<PendingText> pendingTexts = new ArrayList<>();
|
||||
|
||||
// ===== Cached transform values =====
|
||||
private int cCenterX, cCenterY;
|
||||
|
||||
// ===== Parent =====
|
||||
protected GuiNPCInterface parent;
|
||||
|
||||
public GuiAdvancedDiagram(GuiNPCInterface parent, int x, int y, int width, int height) {
|
||||
this.parent = parent;
|
||||
this.x = x;
|
||||
this.y = y;
|
||||
this.diagramWidth = width;
|
||||
this.diagramHeight = height;
|
||||
}
|
||||
|
||||
// ===== Abstract Methods =====
|
||||
protected abstract List<AdvancedNode> createNodes();
|
||||
protected abstract List<AdvancedConnection> createConnections();
|
||||
protected abstract void onNodeClick(AdvancedNode node);
|
||||
protected abstract void onNodeDoubleClick(AdvancedNode node);
|
||||
|
||||
// ===== Cache Management =====
|
||||
public void invalidateCache() {
|
||||
nodes = null;
|
||||
connections = null;
|
||||
}
|
||||
|
||||
protected Map<Integer, AdvancedNode> getNodes() {
|
||||
if (nodes == null) {
|
||||
List<AdvancedNode> nodeList = createNodes();
|
||||
nodes = new HashMap<>();
|
||||
for (AdvancedNode node : nodeList) {
|
||||
nodes.put(node.id, node);
|
||||
}
|
||||
connections = createConnections();
|
||||
computeNodeSizes();
|
||||
layoutNodes();
|
||||
}
|
||||
return nodes;
|
||||
}
|
||||
|
||||
protected List<AdvancedConnection> getConnections() {
|
||||
getNodes();
|
||||
return connections;
|
||||
}
|
||||
|
||||
// ===== Font Helpers (using ClientProxy.Font) =====
|
||||
protected int fontWidth(String text) {
|
||||
return ClientProxy.Font.width(text);
|
||||
}
|
||||
|
||||
protected int fontHeight() {
|
||||
return ClientProxy.Font.height();
|
||||
}
|
||||
|
||||
// Font draw helper
|
||||
protected void fontDraw(String text, int x, int y, int color) {
|
||||
ClientProxy.Font.drawString(text, x, y, color);
|
||||
}
|
||||
|
||||
// Trim text to fit within maxWidth, adding ".." if needed
|
||||
protected String fontTrimToWidth(String text, int maxWidth) {
|
||||
if (ClientProxy.Font.width(text) <= maxWidth) return text;
|
||||
String ellipsis = "..";
|
||||
int ellipsisWidth = ClientProxy.Font.width(ellipsis);
|
||||
String trimmed = text;
|
||||
while (trimmed.length() > 1 && ClientProxy.Font.width(trimmed) + ellipsisWidth > maxWidth) {
|
||||
trimmed = trimmed.substring(0, trimmed.length() - 1);
|
||||
}
|
||||
return trimmed + ellipsis;
|
||||
}
|
||||
|
||||
// ===== World -> Screen coordinate transform =====
|
||||
private float toScreenX(float wx) {
|
||||
return (wx - cCenterX) * zoom + cCenterX + panX;
|
||||
}
|
||||
|
||||
private float toScreenY(float wy) {
|
||||
return (wy - cCenterY) * zoom + cCenterY + panY;
|
||||
}
|
||||
|
||||
// ===== Buffered text: add text at world coordinates, rendered later in screen-space =====
|
||||
private void bufferText(float worldX, float worldY, String text, int color, boolean centered, int maxWidth) {
|
||||
pendingTexts.add(new PendingText(worldX, worldY, text, color, centered, maxWidth));
|
||||
}
|
||||
|
||||
// ===== Node Size Computation =====
|
||||
protected void computeNodeSizes() {
|
||||
slotHeight = fontHeight() + 2;
|
||||
nodeHeaderHeight = fontHeight() + 4;
|
||||
|
||||
for (AdvancedNode node : nodes.values()) {
|
||||
int titleW = fontWidth(node.title) + nodePadding * 2;
|
||||
int w = Math.max(nodeMinWidth, titleW);
|
||||
if (node.subtitle != null) {
|
||||
int subW = fontWidth(node.subtitle) + nodePadding * 2;
|
||||
w = Math.max(w, subW);
|
||||
}
|
||||
for (NodeSlot slot : node.slots) {
|
||||
int slotW = fontWidth(slot.label) + nodePadding * 2 + connectionPointRadius * 2 + 4;
|
||||
w = Math.max(w, slotW);
|
||||
}
|
||||
node.width = Math.min(w, nodeMaxWidth);
|
||||
|
||||
int h = nodeHeaderHeight;
|
||||
if (node.subtitle != null) h += slotHeight;
|
||||
h += node.slots.size() * slotHeight;
|
||||
h += nodePadding;
|
||||
node.height = h;
|
||||
}
|
||||
}
|
||||
|
||||
// ===== Layered Tree Layout (Sugiyama-style) =====
|
||||
protected void layoutNodes() {
|
||||
if (nodes.isEmpty()) return;
|
||||
|
||||
Set<Integer> hasIncoming = new HashSet<>();
|
||||
Map<Integer, List<Integer>> outgoing = new HashMap<>();
|
||||
for (AdvancedNode n : nodes.values()) {
|
||||
outgoing.put(n.id, new ArrayList<Integer>());
|
||||
}
|
||||
for (AdvancedConnection conn : connections) {
|
||||
if (nodes.containsKey(conn.sourceNodeId) && nodes.containsKey(conn.targetNodeId)) {
|
||||
hasIncoming.add(conn.targetNodeId);
|
||||
outgoing.get(conn.sourceNodeId).add(conn.targetNodeId);
|
||||
}
|
||||
}
|
||||
|
||||
List<Integer> roots = new ArrayList<>();
|
||||
for (AdvancedNode n : nodes.values()) {
|
||||
if (!hasIncoming.contains(n.id)) {
|
||||
roots.add(n.id);
|
||||
}
|
||||
}
|
||||
if (roots.isEmpty()) {
|
||||
int minId = Integer.MAX_VALUE;
|
||||
for (int id : nodes.keySet()) {
|
||||
if (id < minId) minId = id;
|
||||
}
|
||||
roots.add(minId);
|
||||
}
|
||||
|
||||
Map<Integer, Integer> layerMap = new HashMap<>();
|
||||
Queue<Integer> queue = new LinkedList<>();
|
||||
for (int root : roots) {
|
||||
if (!layerMap.containsKey(root)) {
|
||||
layerMap.put(root, 0);
|
||||
queue.add(root);
|
||||
}
|
||||
}
|
||||
while (!queue.isEmpty()) {
|
||||
int curr = queue.poll();
|
||||
int currLayer = layerMap.get(curr);
|
||||
for (int target : outgoing.get(curr)) {
|
||||
if (!layerMap.containsKey(target)) {
|
||||
layerMap.put(target, currLayer + 1);
|
||||
queue.add(target);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
List<Integer> orphanIds = new ArrayList<>();
|
||||
for (AdvancedNode n : nodes.values()) {
|
||||
if (!layerMap.containsKey(n.id)) {
|
||||
orphanIds.add(n.id);
|
||||
}
|
||||
}
|
||||
Collections.sort(orphanIds);
|
||||
|
||||
int maxLayer = 0;
|
||||
for (int l : layerMap.values()) {
|
||||
if (l > maxLayer) maxLayer = l;
|
||||
}
|
||||
|
||||
Map<Integer, List<Integer>> layers = new HashMap<>();
|
||||
for (Map.Entry<Integer, Integer> entry : layerMap.entrySet()) {
|
||||
int layer = entry.getValue();
|
||||
if (!layers.containsKey(layer)) {
|
||||
layers.put(layer, new ArrayList<Integer>());
|
||||
}
|
||||
layers.get(layer).add(entry.getKey());
|
||||
}
|
||||
|
||||
for (List<Integer> layer : layers.values()) {
|
||||
Collections.sort(layer);
|
||||
}
|
||||
|
||||
// Barycenter ordering
|
||||
for (int pass = 0; pass < 4; pass++) {
|
||||
for (int l = 1; l <= maxLayer; l++) {
|
||||
List<Integer> layer = layers.get(l);
|
||||
if (layer == null) continue;
|
||||
final Map<Integer, Float> bary = new HashMap<>();
|
||||
for (int nodeId : layer) {
|
||||
float sum = 0;
|
||||
int count = 0;
|
||||
List<Integer> prevLayer = layers.get(l - 1);
|
||||
if (prevLayer != null) {
|
||||
for (AdvancedConnection conn : connections) {
|
||||
if (conn.targetNodeId == nodeId && prevLayer.contains(conn.sourceNodeId)) {
|
||||
sum += prevLayer.indexOf(conn.sourceNodeId);
|
||||
count++;
|
||||
}
|
||||
}
|
||||
}
|
||||
bary.put(nodeId, count > 0 ? sum / count : Float.MAX_VALUE);
|
||||
}
|
||||
Collections.sort(layer, new Comparator<Integer>() {
|
||||
@Override
|
||||
public int compare(Integer a, Integer b) {
|
||||
return Float.compare(bary.get(a), bary.get(b));
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
int startX = x + 30;
|
||||
int startY = y + 30;
|
||||
|
||||
for (int l = 0; l <= maxLayer; l++) {
|
||||
List<Integer> layer = layers.get(l);
|
||||
if (layer == null) continue;
|
||||
|
||||
int maxW = 0;
|
||||
for (int nodeId : layer) {
|
||||
AdvancedNode n = nodes.get(nodeId);
|
||||
if (n.width > maxW) maxW = n.width;
|
||||
}
|
||||
|
||||
int yOffset = startY;
|
||||
for (int nodeId : layer) {
|
||||
AdvancedNode n = nodes.get(nodeId);
|
||||
n.x = startX;
|
||||
n.y = yOffset;
|
||||
yOffset += n.height + nodeSpacingY;
|
||||
}
|
||||
startX += maxW + nodeSpacingX;
|
||||
}
|
||||
|
||||
// Orphan grid
|
||||
if (!orphanIds.isEmpty()) {
|
||||
int cols = (int) Math.ceil(Math.sqrt(orphanIds.size()));
|
||||
int gridX = startX + nodeSpacingX;
|
||||
int gridY = startY;
|
||||
int col = 0;
|
||||
int rowMaxH = 0;
|
||||
|
||||
for (int orphanId : orphanIds) {
|
||||
AdvancedNode n = nodes.get(orphanId);
|
||||
n.x = gridX;
|
||||
n.y = gridY;
|
||||
|
||||
if (n.height > rowMaxH) rowMaxH = n.height;
|
||||
col++;
|
||||
|
||||
if (col >= cols) {
|
||||
col = 0;
|
||||
gridX = startX + nodeSpacingX;
|
||||
gridY += rowMaxH + nodeSpacingY;
|
||||
rowMaxH = 0;
|
||||
} else {
|
||||
gridX += n.width + nodeSpacingX;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// ===== Drawing =====
|
||||
public void drawDiagram(int mouseX, int mouseY) {
|
||||
if (parent != null && parent.hasSubGui()) return;
|
||||
|
||||
if (isWithin(mouseX, mouseY)) {
|
||||
handleMouseScroll(Mouse.getDWheel());
|
||||
}
|
||||
|
||||
Minecraft mc = Minecraft.getMinecraft();
|
||||
ScaledResolution sr = new ScaledResolution(mc, mc.displayWidth, mc.displayHeight);
|
||||
int factor = sr.getScaleFactor();
|
||||
|
||||
Map<Integer, AdvancedNode> nodeMap = getNodes();
|
||||
List<AdvancedConnection> conns = getConnections();
|
||||
|
||||
// Cache transform center
|
||||
cCenterX = x + diagramWidth / 2;
|
||||
cCenterY = y + diagramHeight / 2;
|
||||
|
||||
// Update hover using world-space mouse
|
||||
float emx = ((float) mouseX - (cCenterX + panX)) / zoom + cCenterX;
|
||||
float emy = ((float) mouseY - (cCenterY + panY)) / zoom + cCenterY;
|
||||
hoveredNodeId = -1;
|
||||
if (isWithin(mouseX, mouseY)) {
|
||||
for (AdvancedNode node : nodeMap.values()) {
|
||||
if (emx >= node.x && emx <= node.x + node.width &&
|
||||
emy >= node.y && emy <= node.y + node.height) {
|
||||
hoveredNodeId = node.id;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Scissor clip
|
||||
GL11.glEnable(GL11.GL_SCISSOR_TEST);
|
||||
GL11.glScissor(x * factor, (sr.getScaledHeight() - (y + diagramHeight)) * factor,
|
||||
diagramWidth * factor, diagramHeight * factor);
|
||||
|
||||
// Background
|
||||
drawRect(x, y, x + diagramWidth, y + diagramHeight, 0xFF1A1A2E);
|
||||
|
||||
// ===== PASS 1: Geometry in zoom-transform =====
|
||||
GL11.glPushMatrix();
|
||||
GL11.glTranslatef(cCenterX + panX, cCenterY + panY, 0);
|
||||
GL11.glScalef(zoom, zoom, 1.0f);
|
||||
GL11.glTranslatef(-cCenterX, -cCenterY, 0);
|
||||
|
||||
// Highlight set
|
||||
Set<AdvancedConnection> highlightedConns = new HashSet<>();
|
||||
if (hoveredNodeId != -1) {
|
||||
for (AdvancedConnection conn : conns) {
|
||||
if (conn.sourceNodeId == hoveredNodeId || conn.targetNodeId == hoveredNodeId) {
|
||||
highlightedConns.add(conn);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Draw connections
|
||||
for (AdvancedConnection conn : conns) {
|
||||
AdvancedNode source = nodeMap.get(conn.sourceNodeId);
|
||||
AdvancedNode target = nodeMap.get(conn.targetNodeId);
|
||||
if (source == null || target == null) continue;
|
||||
boolean highlight = highlightedConns.contains(conn);
|
||||
drawConnection(source, conn.sourceSlot, target, conn.color, highlight);
|
||||
}
|
||||
|
||||
// Draw node geometry (rectangles, borders, circles) and buffer text
|
||||
pendingTexts.clear();
|
||||
for (AdvancedNode node : nodeMap.values()) {
|
||||
drawNodeGeometry(node);
|
||||
}
|
||||
|
||||
GL11.glPopMatrix();
|
||||
|
||||
// ===== PASS 2: Text rendered at base size with GL scaling =====
|
||||
// Using a single font size with GL scaling ensures text stays proportionally
|
||||
// positioned within boxes at all zoom levels
|
||||
if (zoom >= 0.35f) {
|
||||
for (PendingText pt : pendingTexts) {
|
||||
float sx = toScreenX(pt.worldX);
|
||||
float sy = toScreenY(pt.worldY);
|
||||
|
||||
// Cull text outside visible area
|
||||
if (sx > x + diagramWidth + 50 || sx < x - 200) continue;
|
||||
if (sy > y + diagramHeight + 20 || sy < y - 20) continue;
|
||||
|
||||
GL11.glPushMatrix();
|
||||
GL11.glTranslatef(sx, sy, 0);
|
||||
GL11.glScalef(zoom, zoom, 1.0f);
|
||||
|
||||
if (pt.centered) {
|
||||
String trimmed = fontTrimToWidth(pt.text, pt.maxWidth);
|
||||
int tw = fontWidth(trimmed);
|
||||
fontDraw(trimmed, -tw / 2, 0, pt.color);
|
||||
} else {
|
||||
String trimmed = fontTrimToWidth(pt.text, pt.maxWidth);
|
||||
fontDraw(trimmed, 0, 0, pt.color);
|
||||
}
|
||||
|
||||
GL11.glPopMatrix();
|
||||
}
|
||||
}
|
||||
|
||||
GL11.glDisable(GL11.GL_SCISSOR_TEST);
|
||||
}
|
||||
|
||||
// ===== Node Geometry (rectangles, borders, circles only - no text) =====
|
||||
protected void drawNodeGeometry(AdvancedNode node) {
|
||||
int nx = node.x;
|
||||
int ny = node.y;
|
||||
int nw = node.width;
|
||||
int nh = node.height;
|
||||
|
||||
// Node background
|
||||
drawRect(nx, ny, nx + nw, ny + nh, 0xE0202020);
|
||||
|
||||
// Header bar
|
||||
drawRect(nx, ny, nx + nw, ny + nodeHeaderHeight, node.headerColor);
|
||||
|
||||
// Border
|
||||
int borderColor;
|
||||
if (node.id == selectedNodeId) {
|
||||
borderColor = 0xFFFFFFFF;
|
||||
} else if (node.id == hoveredNodeId) {
|
||||
borderColor = 0xFFCCCCCC;
|
||||
} else {
|
||||
borderColor = 0xFF444444;
|
||||
}
|
||||
drawHorizontalLine(nx, nx + nw - 1, ny, borderColor);
|
||||
drawHorizontalLine(nx, nx + nw - 1, ny + nh - 1, borderColor);
|
||||
drawVerticalLine(nx, ny, ny + nh - 1, borderColor);
|
||||
drawVerticalLine(nx + nw - 1, ny, ny + nh - 1, borderColor);
|
||||
|
||||
// Buffer title text (centered in header)
|
||||
float titleCenterX = nx + nw / 2.0f;
|
||||
bufferText(titleCenterX, ny + 2, node.title, 0xFFFFFFFF, true, nw - nodePadding * 2);
|
||||
|
||||
int yPos = ny + nodeHeaderHeight;
|
||||
|
||||
// Buffer subtitle
|
||||
if (node.subtitle != null) {
|
||||
bufferText(nx + nodePadding, yPos + 1, node.subtitle, 0xFF999999, false, nw - nodePadding * 2);
|
||||
yPos += slotHeight;
|
||||
}
|
||||
|
||||
// Buffer slots + draw circles
|
||||
for (NodeSlot slot : node.slots) {
|
||||
bufferText(nx + nodePadding, yPos + 1, slot.label, slot.color, false,
|
||||
nw - nodePadding * 2 - connectionPointRadius * 2 - 6);
|
||||
|
||||
if (slot.targetNodeId >= 0) {
|
||||
int cpx = nx + nw - connectionPointRadius - 2;
|
||||
int cpy = yPos + slotHeight / 2;
|
||||
drawCircle(cpx, cpy, connectionPointRadius, slot.color);
|
||||
}
|
||||
|
||||
yPos += slotHeight;
|
||||
}
|
||||
}
|
||||
|
||||
// ===== Connection Rendering (Cubic Bezier) =====
|
||||
protected void drawConnection(AdvancedNode source, int slotIndex, AdvancedNode target, int color, boolean highlight) {
|
||||
int sx = source.x + source.width;
|
||||
int sy = source.y + nodeHeaderHeight + (source.subtitle != null ? slotHeight : 0)
|
||||
+ slotIndex * slotHeight + slotHeight / 2;
|
||||
|
||||
int tx = target.x;
|
||||
int ty = target.y + target.height / 2;
|
||||
|
||||
int dx = Math.abs(tx - sx);
|
||||
int offset = Math.max(40, dx / 3);
|
||||
int cx1 = sx + offset;
|
||||
int cy1 = sy;
|
||||
int cx2 = tx - offset;
|
||||
int cy2 = ty;
|
||||
|
||||
float r, g, b, a;
|
||||
if (highlight) {
|
||||
r = 1.0f; g = 1.0f; b = 0.0f; a = 1.0f;
|
||||
} else {
|
||||
r = ((color >> 16) & 0xFF) / 255f;
|
||||
g = ((color >> 8) & 0xFF) / 255f;
|
||||
b = (color & 0xFF) / 255f;
|
||||
a = 0.85f;
|
||||
}
|
||||
|
||||
GL11.glPushAttrib(GL11.GL_ENABLE_BIT | GL11.GL_COLOR_BUFFER_BIT | GL11.GL_HINT_BIT);
|
||||
GL11.glEnable(GL11.GL_BLEND);
|
||||
GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA);
|
||||
GL11.glEnable(GL11.GL_LINE_SMOOTH);
|
||||
GL11.glHint(GL11.GL_LINE_SMOOTH_HINT, GL11.GL_NICEST);
|
||||
GL11.glDisable(GL11.GL_TEXTURE_2D);
|
||||
GL11.glLineWidth(highlight ? 3.0f : 2.0f);
|
||||
GL11.glColor4f(r, g, b, a);
|
||||
|
||||
int segments = 60;
|
||||
GL11.glBegin(GL11.GL_LINE_STRIP);
|
||||
for (int i = 0; i <= segments; i++) {
|
||||
double t = (double) i / segments;
|
||||
double mt = 1.0 - t;
|
||||
double bx = mt * mt * mt * sx + 3 * mt * mt * t * cx1 + 3 * mt * t * t * cx2 + t * t * t * tx;
|
||||
double by = mt * mt * mt * sy + 3 * mt * mt * t * cy1 + 3 * mt * t * t * cy2 + t * t * t * ty;
|
||||
GL11.glVertex2d(bx, by);
|
||||
}
|
||||
GL11.glEnd();
|
||||
|
||||
// Arrow head
|
||||
double tangentX = 3 * (tx - cx2);
|
||||
double tangentY = 3 * (ty - cy2);
|
||||
double len = Math.sqrt(tangentX * tangentX + tangentY * tangentY);
|
||||
if (len > 0) {
|
||||
tangentX /= len;
|
||||
tangentY /= len;
|
||||
}
|
||||
|
||||
float arrowSize = 6;
|
||||
float ax1 = tx - arrowSize * (float)(tangentX - tangentY * 0.5);
|
||||
float ay1 = ty - arrowSize * (float)(tangentY + tangentX * 0.5);
|
||||
float ax2 = tx - arrowSize * (float)(tangentX + tangentY * 0.5);
|
||||
float ay2 = ty - arrowSize * (float)(tangentY - tangentX * 0.5);
|
||||
|
||||
GL11.glDisable(GL11.GL_CULL_FACE);
|
||||
GL11.glBegin(GL11.GL_TRIANGLES);
|
||||
GL11.glVertex2f(tx, ty);
|
||||
GL11.glVertex2f(ax1, ay1);
|
||||
GL11.glVertex2f(ax2, ay2);
|
||||
GL11.glEnd();
|
||||
GL11.glEnable(GL11.GL_CULL_FACE);
|
||||
|
||||
GL11.glEnable(GL11.GL_TEXTURE_2D);
|
||||
GL11.glDisable(GL11.GL_LINE_SMOOTH);
|
||||
GL11.glDisable(GL11.GL_BLEND);
|
||||
GL11.glPopAttrib();
|
||||
}
|
||||
|
||||
// ===== Drawing Helpers =====
|
||||
|
||||
protected void drawCircle(int cx, int cy, int radius, int color) {
|
||||
float r = ((color >> 16) & 0xFF) / 255f;
|
||||
float g = ((color >> 8) & 0xFF) / 255f;
|
||||
float b = (color & 0xFF) / 255f;
|
||||
|
||||
GL11.glPushAttrib(GL11.GL_ENABLE_BIT);
|
||||
GL11.glDisable(GL11.GL_TEXTURE_2D);
|
||||
GL11.glEnable(GL11.GL_BLEND);
|
||||
GL11.glColor4f(r, g, b, 1.0f);
|
||||
GL11.glBegin(GL11.GL_TRIANGLE_FAN);
|
||||
GL11.glVertex2i(cx, cy);
|
||||
int segs = 12;
|
||||
for (int i = 0; i <= segs; i++) {
|
||||
double angle = 2.0 * Math.PI * i / segs;
|
||||
GL11.glVertex2d(cx + radius * Math.cos(angle), cy + radius * Math.sin(angle));
|
||||
}
|
||||
GL11.glEnd();
|
||||
GL11.glEnable(GL11.GL_TEXTURE_2D);
|
||||
GL11.glPopAttrib();
|
||||
}
|
||||
|
||||
protected String trimToWidth(String text, int maxWidth) {
|
||||
if (fontWidth(text) <= maxWidth) return text;
|
||||
String trimmed = text;
|
||||
while (trimmed.length() > 1 && fontWidth(trimmed + "..") > maxWidth) {
|
||||
trimmed = trimmed.substring(0, trimmed.length() - 1);
|
||||
}
|
||||
return trimmed + "..";
|
||||
}
|
||||
|
||||
// ===== Mouse Handling =====
|
||||
|
||||
public boolean mouseClicked(int mouseX, int mouseY, int mouseButton) {
|
||||
if (parent != null && parent.hasSubGui()) return false;
|
||||
if (!isWithin(mouseX, mouseY)) return false;
|
||||
|
||||
if (mouseButton == 0) {
|
||||
float emx = ((float) mouseX - (cCenterX + panX)) / zoom + cCenterX;
|
||||
float emy = ((float) mouseY - (cCenterY + panY)) / zoom + cCenterY;
|
||||
|
||||
for (AdvancedNode node : getNodes().values()) {
|
||||
if (emx >= node.x && emx <= node.x + node.width &&
|
||||
emy >= node.y && emy <= node.y + node.height) {
|
||||
|
||||
long now = System.currentTimeMillis();
|
||||
if (node.id == lastClickedNodeId && (now - lastClickTime) < DOUBLE_CLICK_MS) {
|
||||
onNodeDoubleClick(node);
|
||||
lastClickedNodeId = -1;
|
||||
lastClickTime = 0;
|
||||
} else {
|
||||
selectedNodeId = node.id;
|
||||
onNodeClick(node);
|
||||
lastClickedNodeId = node.id;
|
||||
lastClickTime = now;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
dragging = true;
|
||||
lastDragX = mouseX;
|
||||
lastDragY = mouseY;
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public void mouseClickMove(int mouseX, int mouseY, int mouseButton, long timeSinceLastClick) {
|
||||
if (parent != null && parent.hasSubGui()) return;
|
||||
if (dragging) {
|
||||
int dx = mouseX - lastDragX;
|
||||
int dy = mouseY - lastDragY;
|
||||
panX += dx;
|
||||
panY += dy;
|
||||
lastDragX = mouseX;
|
||||
lastDragY = mouseY;
|
||||
}
|
||||
}
|
||||
|
||||
public void mouseReleased(int mouseX, int mouseY, int state) {
|
||||
dragging = false;
|
||||
}
|
||||
|
||||
public void handleMouseScroll(int scrollDelta) {
|
||||
if (scrollDelta == 0) return;
|
||||
zoom += scrollDelta * 0.0009f;
|
||||
if (zoom < MIN_ZOOM) zoom = MIN_ZOOM;
|
||||
if (zoom > MAX_ZOOM) zoom = MAX_ZOOM;
|
||||
}
|
||||
|
||||
public boolean isWithin(int mouseX, int mouseY) {
|
||||
if (parent != null && parent.hasSubGui()) return false;
|
||||
return mouseX >= x && mouseX < x + diagramWidth && mouseY >= y && mouseY < y + diagramHeight;
|
||||
}
|
||||
|
||||
// ===== Public API =====
|
||||
|
||||
public void setSelectedNode(int id) {
|
||||
this.selectedNodeId = id;
|
||||
}
|
||||
|
||||
public int getSelectedNodeId() {
|
||||
return selectedNodeId;
|
||||
}
|
||||
|
||||
public void setBounds(int x, int y, int width, int height) {
|
||||
this.x = x;
|
||||
this.y = y;
|
||||
this.diagramWidth = width;
|
||||
this.diagramHeight = height;
|
||||
}
|
||||
|
||||
// ===== Pan/Zoom Accessors =====
|
||||
public float getPanX() { return panX; }
|
||||
public float getPanY() { return panY; }
|
||||
public float getZoom() { return zoom; }
|
||||
|
||||
public void setPanX(float px) { this.panX = px; }
|
||||
public void setPanY(float py) { this.panY = py; }
|
||||
public void setZoom(float z) { this.zoom = z; }
|
||||
}
|
||||
@@ -98,10 +98,11 @@ public abstract class GuiDirectory extends GuiNPCInterface implements ICustomScr
|
||||
public void drawScreen(int mouseX, int mouseY, float partialTicks) {
|
||||
drawTopBar();
|
||||
drawPanels();
|
||||
super.drawScreen(mouseX, mouseY, partialTicks);
|
||||
// Draw divider AFTER super.drawScreen() so it renders on top of GUI elements
|
||||
if (enableDivider) {
|
||||
drawDivider(mouseX, mouseY);
|
||||
}
|
||||
super.drawScreen(mouseX, mouseY, partialTicks);
|
||||
drawOverlay(mouseX, mouseY, partialTicks);
|
||||
}
|
||||
|
||||
|
||||
@@ -17,7 +17,7 @@ import java.util.List;
|
||||
public class GuiNpcTextArea extends GuiNpcTextField {
|
||||
public boolean inMenu = true;
|
||||
public boolean numbersOnly = false;
|
||||
private int posX, posY, width, height;
|
||||
protected int posX, posY, width, height;
|
||||
private int cursorCounter;
|
||||
private FontContainer font;
|
||||
private int cursorPosition = 0;
|
||||
@@ -27,6 +27,7 @@ public class GuiNpcTextArea extends GuiNpcTextField {
|
||||
private boolean clickVerticalBar = false;
|
||||
private boolean wrapLine = true;
|
||||
private List<String> lines = new ArrayList<>();
|
||||
protected int storedMaxLength = Integer.MAX_VALUE;
|
||||
|
||||
public GuiNpcTextArea(int id, GuiScreen guiscreen, int i, int j, int k, int l, String s) {
|
||||
super(id, guiscreen, i, j, k, l, s);
|
||||
@@ -39,6 +40,30 @@ public class GuiNpcTextArea extends GuiNpcTextField {
|
||||
this.setText(s);
|
||||
}
|
||||
|
||||
public void setBounds(int x, int y, int w, int h) {
|
||||
this.posX = x;
|
||||
this.posY = y;
|
||||
this.width = w;
|
||||
this.height = h;
|
||||
this.xPosition = x;
|
||||
this.yPosition = y;
|
||||
updateLineList();
|
||||
}
|
||||
|
||||
public int getCharacterCount() {
|
||||
return getText().length();
|
||||
}
|
||||
|
||||
public int getMaxLength() {
|
||||
return storedMaxLength;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setMaxStringLength(int length) {
|
||||
super.setMaxStringLength(length);
|
||||
this.storedMaxLength = length;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setText(String text) {
|
||||
super.setText(text);
|
||||
@@ -69,10 +94,14 @@ public class GuiNpcTextArea extends GuiNpcTextField {
|
||||
public boolean textboxKeyTyped(char c, int i) {
|
||||
if (isFocused() && canEdit) {
|
||||
String originalText = getText();
|
||||
this.setText(originalText);
|
||||
// Handle newline specially - insert and return immediately
|
||||
if (c == '\r' || c == '\n') {
|
||||
this.setText(originalText.substring(0, cursorPosition) + c + originalText.substring(cursorPosition));
|
||||
cursorPosition++;
|
||||
updateLineList();
|
||||
return true;
|
||||
}
|
||||
// For all other characters, let parent handle
|
||||
this.setCursorPositionZero();
|
||||
this.moveCursorBy(cursorPosition);
|
||||
boolean bo = super.textboxKeyTyped(c, i);
|
||||
@@ -85,7 +114,6 @@ public class GuiNpcTextArea extends GuiNpcTextField {
|
||||
if (i == Keyboard.KEY_RIGHT && cursorPosition < newText.length())
|
||||
cursorPosition++;
|
||||
return bo;
|
||||
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,59 @@
|
||||
package noppes.npcs.client.gui.util;
|
||||
|
||||
/**
|
||||
* Listener interface for DialogEditorPanel callbacks.
|
||||
* Implemented by parent GUIs (like GuiDialogTree) to handle
|
||||
* selection requests and actions from the editor panel.
|
||||
*/
|
||||
public interface IDialogEditorListener {
|
||||
/**
|
||||
* Called when user clicks Save button.
|
||||
*/
|
||||
void onSaveRequested();
|
||||
|
||||
/**
|
||||
* Called when user clicks Test button.
|
||||
*/
|
||||
void onTestRequested();
|
||||
|
||||
/**
|
||||
* Called when user wants to select a quest.
|
||||
* @param slot The quest slot being selected (usually 0 for dialog quest)
|
||||
*/
|
||||
void onQuestSelectRequested(int slot);
|
||||
|
||||
/**
|
||||
* Called when user wants to select a dialog (for availability).
|
||||
* @param slot The dialog requirement slot
|
||||
*/
|
||||
void onDialogSelectRequested(int slot);
|
||||
|
||||
/**
|
||||
* Called when user wants to select a faction (for availability).
|
||||
* @param slot The faction requirement slot
|
||||
*/
|
||||
void onFactionSelectRequested(int slot);
|
||||
|
||||
/**
|
||||
* Called when user wants to select a sound.
|
||||
*/
|
||||
void onSoundSelectRequested();
|
||||
|
||||
/**
|
||||
* Called when user wants to pick a color.
|
||||
* @param slot 0 for text color, 1 for title color
|
||||
* @param currentColor The current color value
|
||||
*/
|
||||
void onColorSelectRequested(int slot, int currentColor);
|
||||
|
||||
/**
|
||||
* Called when user wants to edit mail settings.
|
||||
*/
|
||||
void onMailSetupRequested();
|
||||
|
||||
/**
|
||||
* Called when user wants to select a target dialog for an option.
|
||||
* @param optionSlot The option slot (0-5)
|
||||
*/
|
||||
void onOptionDialogSelectRequested(int optionSlot);
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
package noppes.npcs.client.gui.util;
|
||||
|
||||
import java.util.HashMap;
|
||||
|
||||
public interface IDialogEditorParent {
|
||||
HashMap<String, Integer> getDialogData();
|
||||
GuiCustomScroll getDialogScroll();
|
||||
String getDialogQuestName();
|
||||
void setDialogQuestName(String name);
|
||||
}
|
||||
@@ -0,0 +1,154 @@
|
||||
package noppes.npcs.client.gui.util;
|
||||
|
||||
/**
|
||||
* Color palette for the Modern GUI system.
|
||||
* All colors include alpha channel (0xAARRGGBB format).
|
||||
*/
|
||||
public class ModernColors {
|
||||
|
||||
// === Panel Backgrounds ===
|
||||
public static final int PANEL_BG = 0xC0101010; // Semi-transparent dark
|
||||
public static final int PANEL_BG_SOLID = 0xFF101010; // Solid dark
|
||||
public static final int PANEL_BORDER = 0xFF333333; // Dark gray border
|
||||
public static final int TOP_BAR_BG = 0xC0181818; // Top bar background
|
||||
|
||||
// === Button Colors ===
|
||||
public static final int BUTTON_BG = 0xFF2A2A2A; // Normal background
|
||||
public static final int BUTTON_BG_HOVER = 0xFF3A3A3A; // Hover background
|
||||
public static final int BUTTON_BG_PRESSED = 0xFF4A4A4A; // Pressed background
|
||||
public static final int BUTTON_BG_DISABLED = 0xFF1A1A1A; // Disabled background
|
||||
public static final int BUTTON_BORDER = 0xFF444444; // Button border
|
||||
public static final int BUTTON_BORDER_HOVER = 0xFF555555;// Hover border
|
||||
public static final int BUTTON_BORDER_FOCUSED = 0xFF6688CC; // Focused/active border
|
||||
|
||||
// === Text Colors ===
|
||||
public static final int TEXT_WHITE = 0xFFFFFFFF; // Primary text
|
||||
public static final int TEXT_LIGHT = 0xFFCCCCCC; // Secondary text
|
||||
public static final int TEXT_GRAY = 0xFF888888; // Muted text
|
||||
public static final int TEXT_DARK = 0xFF666666; // Disabled text
|
||||
public static final int TEXT_PLACEHOLDER = 0xFF555555; // Placeholder text
|
||||
|
||||
// === Accent Colors ===
|
||||
public static final int ACCENT_BLUE = 0xFF4488CC; // Primary accent (dialogs)
|
||||
public static final int ACCENT_GREEN = 0xFF55FF55; // Success/linked
|
||||
public static final int ACCENT_GOLD = 0xFFCC8800; // Quest-related
|
||||
public static final int ACCENT_RED = 0xFFFF5555; // Quit/delete
|
||||
public static final int ACCENT_ORANGE = 0xFFFFAA00; // Command/warning
|
||||
public static final int ACCENT_PURPLE = 0xFF7744AA; // Cross-category
|
||||
|
||||
// === Toggle Colors ===
|
||||
public static final int TOGGLE_ON = 0xFF55AA55; // Toggle enabled
|
||||
public static final int TOGGLE_OFF = 0xFF555555; // Toggle disabled
|
||||
public static final int TOGGLE_KNOB = 0xFFDDDDDD; // Toggle knob
|
||||
|
||||
// === Input Field Colors ===
|
||||
public static final int INPUT_BG = 0xFF1A1A1A; // Input background
|
||||
public static final int INPUT_BG_FOCUSED = 0xFF222222; // Focused input background
|
||||
public static final int INPUT_BG_DISABLED = 0xFF141414; // Disabled input background
|
||||
public static final int INPUT_BORDER = 0xFF444444; // Input border
|
||||
public static final int INPUT_BORDER_FOCUSED = 0xFF6688CC; // Focused input border
|
||||
public static final int INPUT_TEXT = 0xFFFFFFFF; // Input text
|
||||
public static final int SELECTION = 0x804488CC; // Text selection highlight
|
||||
|
||||
// === Scrollbar Colors ===
|
||||
public static final int SCROLLBAR_BG = 0xFF1A1A1A; // Scrollbar track
|
||||
public static final int SCROLLBAR_THUMB = 0xFF444444; // Scrollbar thumb
|
||||
public static final int SCROLLBAR_THUMB_HOVER = 0xFF555555; // Thumb hover
|
||||
|
||||
// === Collapsible Section ===
|
||||
public static final int SECTION_HEADER_BG = 0xFF252525; // Section header
|
||||
public static final int SECTION_HEADER_HOVER = 0xFF303030; // Header hover
|
||||
public static final int SECTION_ARROW = 0xFFAAAAAA; // Expand/collapse arrow
|
||||
|
||||
// === Selection & Highlight ===
|
||||
public static final int SELECTION_BG = 0xFF3A4A5A; // Selected item background
|
||||
public static final int HOVER_HIGHLIGHT = 0x40FFFFFF; // Hover overlay
|
||||
public static final int DIRTY_INDICATOR = 0xFFFFAA00; // Unsaved changes indicator
|
||||
|
||||
// === Legend Colors (Dialog Types) ===
|
||||
public static final int LEGEND_DIALOG = 0xFF4488CC; // Dialog type
|
||||
public static final int LEGEND_QUEST = 0xFFCC8800; // Quest type
|
||||
public static final int LEGEND_QUIT = 0xFFFF5555; // Quit type
|
||||
public static final int LEGEND_COMMAND = 0xFFFFAA00; // Command type
|
||||
public static final int LEGEND_TERMINAL = 0xFF666666; // Terminal type
|
||||
|
||||
// === Utility Methods ===
|
||||
|
||||
/**
|
||||
* Extract alpha component (0-255) from packed color.
|
||||
*/
|
||||
public static int getAlpha(int color) {
|
||||
return (color >> 24) & 0xFF;
|
||||
}
|
||||
|
||||
/**
|
||||
* Extract red component (0-255) from packed color.
|
||||
*/
|
||||
public static int getRed(int color) {
|
||||
return (color >> 16) & 0xFF;
|
||||
}
|
||||
|
||||
/**
|
||||
* Extract green component (0-255) from packed color.
|
||||
*/
|
||||
public static int getGreen(int color) {
|
||||
return (color >> 8) & 0xFF;
|
||||
}
|
||||
|
||||
/**
|
||||
* Extract blue component (0-255) from packed color.
|
||||
*/
|
||||
public static int getBlue(int color) {
|
||||
return color & 0xFF;
|
||||
}
|
||||
|
||||
/**
|
||||
* Create color from ARGB components (0-255 each).
|
||||
*/
|
||||
public static int pack(int a, int r, int g, int b) {
|
||||
return ((a & 0xFF) << 24) | ((r & 0xFF) << 16) | ((g & 0xFF) << 8) | (b & 0xFF);
|
||||
}
|
||||
|
||||
/**
|
||||
* Blend two colors by factor (0.0 = colorA, 1.0 = colorB).
|
||||
*/
|
||||
public static int blend(int colorA, int colorB, float factor) {
|
||||
if (factor <= 0) return colorA;
|
||||
if (factor >= 1) return colorB;
|
||||
|
||||
int aA = getAlpha(colorA), aB = getAlpha(colorB);
|
||||
int rA = getRed(colorA), rB = getRed(colorB);
|
||||
int gA = getGreen(colorA), gB = getGreen(colorB);
|
||||
int bA = getBlue(colorA), bB = getBlue(colorB);
|
||||
|
||||
int a = (int) (aA + (aB - aA) * factor);
|
||||
int r = (int) (rA + (rB - rA) * factor);
|
||||
int g = (int) (gA + (gB - gA) * factor);
|
||||
int b = (int) (bA + (bB - bA) * factor);
|
||||
|
||||
return pack(a, r, g, b);
|
||||
}
|
||||
|
||||
/**
|
||||
* Apply alpha to a color (replaces existing alpha).
|
||||
*/
|
||||
public static int withAlpha(int color, int alpha) {
|
||||
return (color & 0x00FFFFFF) | ((alpha & 0xFF) << 24);
|
||||
}
|
||||
|
||||
/**
|
||||
* Lighten a color by factor (0.0 = no change, 1.0 = white).
|
||||
*/
|
||||
public static int lighten(int color, float factor) {
|
||||
return blend(color, 0xFFFFFFFF, factor);
|
||||
}
|
||||
|
||||
/**
|
||||
* Darken a color by factor (0.0 = no change, 1.0 = black).
|
||||
*/
|
||||
public static int darken(int color, float factor) {
|
||||
int a = getAlpha(color);
|
||||
int darkened = blend(color, 0xFF000000, factor);
|
||||
return withAlpha(darkened, a);
|
||||
}
|
||||
}
|
||||
@@ -70,6 +70,7 @@ gui.none=None
|
||||
gui.time=Time
|
||||
gui.title=Title
|
||||
gui.categories=Categories
|
||||
gui.back=Back
|
||||
gui.close=Close
|
||||
gui.disabled=Disabled
|
||||
gui.increase=Increase
|
||||
@@ -119,6 +120,8 @@ gui.sync=Sync
|
||||
gui.range=Range
|
||||
gui.partly=Partially
|
||||
gui.copy=Copy
|
||||
gui.graph=Graph
|
||||
gui.graphone=Solo
|
||||
gui.clear=Clear
|
||||
gui.builtin=Built-in
|
||||
gui.custom=Custom
|
||||
|
||||
Reference in new issue
Block a user