This commit is contained in:
Kam committed 2026-02-05 20:31:18 -05:00
1 parent fff0bfd63b
commit 7a1b4c20cf
21 files changed
+158 -1840

No files matched your search

@@ -32,6 +32,10 @@ public class ModernButton extends GuiNpcButton {
protected boolean pressed = false;
protected boolean hovered = false;
// Color button mode
protected boolean colorMode = false;
protected int displayColor = 0xFFFFFF;
// Multi-value support (like GuiNpcButton)
protected String[] values;
protected int valueIndex = 0;
@@ -194,6 +198,30 @@ public class ModernButton extends GuiNpcButton {
}
}
// === Color Button Mode ===
public ModernButton setColorMode(int color) {
this.colorMode = true;
this.displayColor = color & 0xFFFFFF;
return this;
}
public void setColor(int color) {
this.displayColor = color & 0xFFFFFF;
}
public int getColor() {
return displayColor;
}
protected int getContrastColor(int bgColor) {
int r = (bgColor >> 16) & 0xFF;
int g = (bgColor >> 8) & 0xFF;
int b = bgColor & 0xFF;
double luminance = (0.299 * r + 0.587 * g + 0.114 * b) / 255.0;
return luminance > 0.5 ? 0x000000 : 0xFFFFFF;
}
// === Rendering ===
@Override
@@ -204,6 +232,11 @@ public class ModernButton extends GuiNpcButton {
hovered = mouseX >= xPosition && mouseY >= yPosition &&
mouseX < xPosition + width && mouseY < yPosition + height;
if (colorMode) {
drawColorButton(fr, mouseX, mouseY);
return;
}
// Determine colors based on state
int bg, border, text;
if (!enabled) {
@@ -286,6 +319,20 @@ public class ModernButton extends GuiNpcButton {
return sb.toString();
}
protected void drawColorButton(FontRenderer fr, int mouseX, int mouseY) {
int border = hovered ? ModernColors.INPUT_BORDER_FOCUSED : ModernColors.INPUT_BORDER;
drawRect(xPosition - 1, yPosition - 1, xPosition + width + 1, yPosition + height + 1, border);
drawRect(xPosition, yPosition, xPosition + width, yPosition + height, 0xFF000000 | displayColor);
if (!enabled) {
drawRect(xPosition, yPosition, xPosition + width, yPosition + height, 0x80000000);
}
String hex = String.format("%06X", displayColor & 0xFFFFFF);
int textColor = getContrastColor(displayColor);
int textX = xPosition + (width - fr.getStringWidth(hex)) / 2;
int textY = yPosition + (height - fr.FONT_HEIGHT) / 2;
fr.drawString(hex, textX, textY, textColor);
}
// === Mouse Handling ===
@Override
@@ -1,130 +0,0 @@
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; }
}
@@ -1,69 +0,0 @@
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;
}
}
@@ -1,96 +0,0 @@
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; }
}
@@ -1,134 +0,0 @@
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;
}
}
@@ -1,6 +1,7 @@
package kamkeel.npcs.client.gui.modern;
import kamkeel.npcs.client.gui.components.*;
import kamkeel.npcs.client.gui.components.ModernDropdown;
import kamkeel.npcs.client.gui.components.ScrollPanel;
import kamkeel.npcs.client.gui.modern.tabs.*;
import noppes.npcs.client.gui.util.ModernColors;
import noppes.npcs.client.gui.util.IDialogEditorListener;
@@ -345,19 +346,10 @@ public class DialogEditorPanel extends Gui {
public void mouseReleased(int mouseX, int mouseY) {
scrollPanel.mouseReleased(mouseX, mouseY);
// Let text areas handle mouse release
ModernTextArea textArea = textTab.getTextArea();
if (textArea != null) textArea.mouseReleased(mouseX, mouseY);
ModernTextArea cmdArea = settingsTab.getCommandArea();
if (cmdArea != null) cmdArea.mouseReleased(mouseX, mouseY);
}
public void mouseDragged(int mouseX, int mouseY) {
scrollPanel.mouseDragged(mouseX, mouseY);
ModernTextArea textArea = textTab.getTextArea();
if (textArea != null) textArea.mouseDragged(mouseX, mouseY);
ModernTextArea cmdArea = settingsTab.getCommandArea();
if (cmdArea != null) cmdArea.mouseDragged(mouseX, mouseY);
}
public void updateScreen() {
@@ -1,552 +0,0 @@
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();
}
}
@@ -1,7 +1,7 @@
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.GuiNpcTextField;
import noppes.npcs.client.gui.util.ModernColors;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.ScaledResolution;
@@ -31,8 +31,8 @@ public abstract class ModernCategorySelector<C, I> extends ModernSubGuiInterface
protected List<String> filteredItems = new ArrayList<>();
// Components
protected ModernTextField catSearchField;
protected ModernTextField itemSearchField;
protected GuiNpcTextField catSearchField;
protected GuiNpcTextField itemSearchField;
protected ModernButton doneBtn;
protected ModernButton cancelBtn;
@@ -161,13 +161,9 @@ public abstract class ModernCategorySelector<C, I> extends ModernSubGuiInterface
// Search fields at top
int searchH = 18;
catSearchField = new ModernTextField(0, catListX, contentY, catListW, searchH);
catSearchField.setPlaceholder(getCategorySearchPlaceholder());
catSearchField.setText(catSearch);
catSearchField = new GuiNpcTextField(0, catListX, contentY, catListW, searchH, catSearch);
itemSearchField = new ModernTextField(1, itemListX, contentY, itemListW, searchH);
itemSearchField.setPlaceholder(getItemSearchPlaceholder());
itemSearchField.setText(itemSearch);
itemSearchField = new GuiNpcTextField(1, itemListX, contentY, itemListW, searchH, itemSearch);
// List area below search
listY = contentY + searchH + 4;
@@ -1,7 +1,7 @@
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.GuiNpcTextField;
import noppes.npcs.client.gui.util.ModernColors;
import net.minecraft.client.gui.GuiButton;
import net.minecraft.client.resources.IResource;
@@ -25,7 +25,7 @@ public class ModernColorPicker extends ModernSubGuiInterface {
public int color;
// Components
private ModernTextField hexField;
private GuiNpcTextField hexField;
private ModernButton doneBtn;
private ModernButton cancelBtn;
@@ -66,10 +66,8 @@ public class ModernColorPicker extends ModernSubGuiInterface {
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());
hexField = new GuiNpcTextField(0, previewX + previewSize + 12, fieldRowY, 100, 18, getHexString());
hexField.setMaxStringLength(6);
// Buttons at bottom with proper margin
int btnY = guiTop + ySize - 32;
@@ -1,7 +1,7 @@
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.GuiNpcTextField;
import noppes.npcs.client.gui.util.ModernColors;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.ScaledResolution;
@@ -27,7 +27,7 @@ public class ModernFactionSelector extends ModernSubGuiInterface {
private List<String> filteredFactions = new ArrayList<>();
// Components
private ModernTextField searchField;
private GuiNpcTextField searchField;
private ModernButton doneBtn;
private ModernButton cancelBtn;
@@ -87,9 +87,7 @@ public class ModernFactionSelector extends ModernSubGuiInterface {
// Search field at top
int searchH = 18;
searchField = new ModernTextField(0, listX, contentY, listWidth, searchH);
searchField.setPlaceholder("Filter factions...");
searchField.setText(searchText);
searchField = new GuiNpcTextField(0, listX, contentY, listWidth, searchH, searchText);
// List area below search
listY = contentY + searchH + 4;
@@ -1,7 +1,7 @@
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.GuiNpcTextField;
import noppes.npcs.client.gui.util.ModernColors;
import net.minecraft.client.gui.Gui;
import net.minecraft.item.ItemStack;
@@ -21,8 +21,8 @@ public class ModernMailEditor extends ModernSubGuiInterface {
private PlayerMail mail;
// Components
private ModernTextField subjectField;
private ModernTextField senderField;
private GuiNpcTextField subjectField;
private GuiNpcTextField senderField;
private ModernButton questBtn;
private ModernButton questClearBtn;
private ModernButton prevPageBtn;
@@ -126,15 +126,13 @@ public class ModernMailEditor extends ModernSubGuiInterface {
// 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);
subjectField = new GuiNpcTextField(0, guiLeft + pad + labelW, rowY, fieldW, 18, mail.subject);
subjectField.setMaxStringLength(64);
rowY += rowH;
// Sender row
senderField = new ModernTextField(1, guiLeft + pad + labelW, rowY, fieldW, 18);
senderField.setText(mail.sender);
senderField.setMaxLength(64);
senderField = new GuiNpcTextField(1, guiLeft + pad + labelW, rowY, fieldW, 18, mail.sender);
senderField.setMaxStringLength(64);
rowY += rowH;
// Quest row
@@ -3,7 +3,7 @@ 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.GuiNpcTextField;
import noppes.npcs.client.gui.util.ModernColors;
import net.minecraft.client.Minecraft;
import net.minecraft.client.audio.SoundHandler;
@@ -30,8 +30,8 @@ public class ModernSoundSelector extends ModernSubGuiInterface {
private final HashMap<String, List<String>> domains = new HashMap<>();
// Components
private ModernTextField domainSearchField;
private ModernTextField soundSearchField;
private GuiNpcTextField domainSearchField;
private GuiNpcTextField soundSearchField;
private ModernButton playBtn;
private ModernButton stopBtn;
private ModernButton doneBtn;
@@ -127,13 +127,9 @@ public class ModernSoundSelector extends ModernSubGuiInterface {
// Search fields at top
int searchH = 18;
domainSearchField = new ModernTextField(0, domainListX, contentY, domainListW, searchH);
domainSearchField.setPlaceholder("Filter...");
domainSearchField.setText(domainSearch);
domainSearchField = new GuiNpcTextField(0, domainListX, contentY, domainListW, searchH, domainSearch);
soundSearchField = new ModernTextField(1, soundListX, contentY, soundListW, searchH);
soundSearchField.setPlaceholder("Filter sounds...");
soundSearchField.setText(soundSearch);
soundSearchField = new GuiNpcTextField(1, soundListX, contentY, soundListW, searchH, soundSearch);
// List area below search
listY = contentY + searchH + 4;
@@ -1,743 +0,0 @@
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;
}
}
}
@@ -1,7 +1,6 @@
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.modern.DialogEditorPanel;
import net.minecraft.client.gui.FontRenderer;
import noppes.npcs.client.gui.builder.FieldDef;
@@ -137,10 +136,4 @@ public class DialogSettingsTab extends DialogEditorTab {
}
}
// === Accessors ===
public ModernTextArea getCommandArea() {
List<ModernTextArea> areas = fieldPanel.getTextAreas();
return areas.isEmpty() ? null : areas.get(0);
}
}
@@ -1,7 +1,6 @@
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.modern.DialogEditorPanel;
import net.minecraft.client.gui.FontRenderer;
import noppes.npcs.client.gui.builder.FieldDef;
@@ -92,11 +91,6 @@ public class DialogTextTab extends DialogEditorTab {
// === Accessors for parent panel ===
public ModernTextArea getTextArea() {
List<ModernTextArea> areas = fieldPanel.getTextAreas();
return areas.isEmpty() ? null : areas.get(0);
}
public String getTitle() {
return dialog != null ? dialog.title : "";
}
@@ -186,7 +186,7 @@ public class FieldDef {
// ═══════════════════════════════════════════════════════════════════
/**
* Multi-line text area field rendered as ModernTextArea by ModernFieldPanel.
* Multi-line text area field rendered as GuiNpcTextArea by ModernFieldPanel.
*/
public static FieldDef textAreaField(String label, Supplier<String> getter, Consumer<String> setter) {
FieldDef def = new FieldDef(label, FieldType.TEXT_AREA);
@@ -196,7 +196,7 @@ public class FieldDef {
}
/**
* Color field rendered as ModernColorButton by ModernFieldPanel.
* Color field rendered as ModernButton (color mode) by ModernFieldPanel.
* Triggers onColorSelect callback via listener.
*/
public static FieldDef colorField(String label, Supplier<Integer> getter, Consumer<Integer> setter) {
@@ -2,10 +2,16 @@ package noppes.npcs.client.gui.builder;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
import kamkeel.npcs.client.gui.components.*;
import kamkeel.npcs.client.gui.components.CollapsibleSection;
import kamkeel.npcs.client.gui.components.ModernButton;
import kamkeel.npcs.client.gui.components.ModernCheckbox;
import kamkeel.npcs.client.gui.components.ModernDropdown;
import kamkeel.npcs.client.gui.components.ModernSelectButton;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.FontRenderer;
import net.minecraft.client.gui.Gui;
import noppes.npcs.client.gui.util.GuiNpcTextArea;
import noppes.npcs.client.gui.util.GuiNpcTextField;
import noppes.npcs.client.gui.util.ModernColors;
import java.util.*;
@@ -144,26 +150,25 @@ public class ModernFieldPanel extends Gui {
switch (def.getType()) {
case STRING: {
ModernTextField tf = new ModernTextField(nextId++, 0, 0, 100, 16);
if (def.getMaxLength() > 0) tf.setMaxLength(def.getMaxLength());
if (def.getPlaceholder() != null && !def.getPlaceholder().isEmpty())
tf.setPlaceholder(def.getPlaceholder());
String val = def.getValue() != null ? def.getValue().toString() : "";
tf.setText(val);
GuiNpcTextField tf = new GuiNpcTextField(nextId++, 0, 0, 100, 16, val);
if (def.getMaxLength() > 0) tf.setMaxStringLength(def.getMaxLength());
entry.textField = tf;
break;
}
case INT: {
int val = def.getValue() instanceof Number ? ((Number) def.getValue()).intValue() : 0;
ModernNumberField nf = new ModernNumberField(nextId++, 0, 0, 50, 16, val);
if (def.hasRange()) nf.setIntegerBounds((int) def.getMin(), (int) def.getMax(), val);
GuiNpcTextField nf = new GuiNpcTextField(nextId++, 0, 0, 50, 16, String.valueOf(val));
nf.integersOnly = true;
if (def.hasRange()) nf.setMinMaxDefault((int) def.getMin(), (int) def.getMax(), val);
entry.textField = nf;
break;
}
case FLOAT: {
float val = def.getValue() instanceof Number ? ((Number) def.getValue()).floatValue() : 0f;
ModernNumberField nf = new ModernNumberField(nextId++, 0, 0, 50, 16, val);
if (def.hasRange()) nf.setFloatBounds(def.getMin(), def.getMax(), val);
GuiNpcTextField nf = new GuiNpcTextField(nextId++, 0, 0, 50, 16, String.valueOf(val));
nf.floatsOnly = true;
if (def.hasRange()) nf.setMinMaxDefaultFloat(def.getMin(), def.getMax(), val);
entry.textField = nf;
break;
}
@@ -205,16 +210,15 @@ public class ModernFieldPanel extends Gui {
break;
}
case TEXT_AREA: {
ModernTextArea ta = new ModernTextArea(nextId++, 0, 0, 100, def.getTextAreaHeight());
if (def.getMaxLength() > 0) ta.setMaxStringLength(def.getMaxLength());
String val = def.getValue() != null ? def.getValue().toString() : "";
ta.setText(val);
GuiNpcTextArea ta = new GuiNpcTextArea(nextId++, 0, 0, 100, def.getTextAreaHeight(), val);
if (def.getMaxLength() > 0) ta.setMaxStringLength(def.getMaxLength());
entry.textArea = ta;
break;
}
case COLOR: {
int val = def.getValue() instanceof Number ? ((Number) def.getValue()).intValue() : 0xFFFFFF;
ModernColorButton cb = new ModernColorButton(nextId++, 0, 0, 50, 16, val);
ModernButton cb = new ModernButton(nextId++, 0, 0, 50, 16, "").setColorMode(val);
entry.colorButton = cb;
break;
}
@@ -510,17 +514,23 @@ public class ModernFieldPanel extends Gui {
// Sync color from data
int val = def.getValue() instanceof Number ? ((Number) def.getValue()).intValue() : 0xFFFFFF;
entry.colorButton.setColor(val);
entry.colorButton.setEnabled(def.isEnabled());
entry.colorButton.enabled = def.isEnabled();
boolean hasLabel = def.getLabel() != null && !def.getLabel().isEmpty();
if (hasLabel) {
fr.drawString(def.getLabel(), cx + indent, y + 4, ModernColors.TEXT_LIGHT);
int labelW = fr.getStringWidth(def.getLabel()) + 8;
entry.colorButton.setBounds(cx + indent + labelW, y, 50, 16);
entry.colorButton.xPosition = cx + indent + labelW;
entry.colorButton.yPosition = y;
entry.colorButton.width = 50;
entry.colorButton.height = 16;
} else {
entry.colorButton.setBounds(cx + indent, y, 50, 16);
entry.colorButton.xPosition = cx + indent;
entry.colorButton.yPosition = y;
entry.colorButton.width = 50;
entry.colorButton.height = 16;
}
entry.colorButton.draw(mouseX, mouseY);
entry.colorButton.drawButton(Minecraft.getMinecraft(), mouseX, mouseY);
return y + rowHeight;
}
@@ -843,7 +853,7 @@ public class ModernFieldPanel extends Gui {
return false;
}
case COLOR: {
if (entry.colorButton != null && entry.colorButton.mouseClicked(mouseX, mouseY, button)) {
if (entry.colorButton != null && entry.colorButton.mousePressed(Minecraft.getMinecraft(), mouseX, mouseY)) {
if (listener != null) {
int currentColor = def.getValue() instanceof Number ? ((Number) def.getValue()).intValue() : 0xFFFFFF;
listener.onColorSelect(def.getCallbackSlot(), currentColor);
@@ -1046,23 +1056,6 @@ public class ModernFieldPanel extends Gui {
return allDropdowns;
}
/**
* Get all text areas for mouseReleased/mouseDragged delegation.
*/
public List<ModernTextArea> getTextAreas() {
List<ModernTextArea> areas = new ArrayList<>();
for (FieldEntry entry : entries.values()) {
if (entry != null) collectTextAreas(entry, areas);
}
return areas;
}
protected void collectTextAreas(FieldEntry entry, List<ModernTextArea> areas) {
if (entry.textArea != null) areas.add(entry.textArea);
if (entry.leftChild != null) collectTextAreas(entry.leftChild, areas);
if (entry.rightChild != null) collectTextAreas(entry.rightChild, areas);
}
// ═══════════════════════════════════════════════════════════════════
// HELPERS
// ═══════════════════════════════════════════════════════════════════
@@ -1242,11 +1235,11 @@ public class ModernFieldPanel extends Gui {
final FieldDef def;
// One of these is populated based on FieldType
ModernTextField textField;
ModernTextArea textArea;
GuiNpcTextField textField;
GuiNpcTextArea textArea;
ModernCheckbox checkbox;
ModernDropdown dropdown;
ModernColorButton colorButton;
ModernButton colorButton;
ModernSelectButton selectButton;
ModernButton clearButton;
ModernButton actionButton;
@@ -3,7 +3,6 @@ package noppes.npcs.client.gui.builder;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
import kamkeel.npcs.client.gui.components.ModernDropdown;
import kamkeel.npcs.client.gui.components.ModernTextArea;
import kamkeel.npcs.client.gui.components.ScrollPanel;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.FontRenderer;
@@ -157,16 +156,10 @@ public class ScrollableFieldPanel {
public void mouseDragged(int mouseX, int mouseY) {
scrollPanel.mouseDragged(mouseX, mouseY);
for (ModernTextArea ta : fieldPanel.getTextAreas()) {
ta.mouseDragged(mouseX, mouseY);
}
}
public void mouseReleased(int mouseX, int mouseY) {
scrollPanel.mouseReleased(mouseX, mouseY);
for (ModernTextArea ta : fieldPanel.getTextAreas()) {
ta.mouseReleased(mouseX, mouseY);
}
}
public void updateScreen() {
@@ -187,10 +180,6 @@ public class ScrollableFieldPanel {
return fieldPanel.getDropdowns();
}
public List<ModernTextArea> getTextAreas() {
return fieldPanel.getTextAreas();
}
public void refresh() {
fieldPanel.refresh();
}
@@ -14,13 +14,12 @@ import net.minecraft.client.gui.Gui;
* - ModernToggle
* - ModernDropdown
* - ModernLabel
* - ModernColorButton
* - ModernSelectButton
* - CollapsibleSection
* - ScrollPanel
*
* Components that wrap Minecraft classes (ModernButton extends GuiNpcButton,
* ModernTextField extends GuiNpcTextField) should NOT extend this class.
* Components that wrap Minecraft classes (ModernButton extends GuiNpcButton)
* should NOT extend this class.
*/
public abstract class AbstractGuiComponent extends Gui {
@@ -40,6 +40,10 @@ public class GuiNpcTextArea extends GuiNpcTextField {
this.setText(s);
}
public GuiNpcTextArea(int id, int x, int y, int width, int height, String text) {
this(id, null, x, y, width, height, text != null ? text : "");
}
public void setBounds(int x, int y, int w, int h) {
this.posX = x;
this.posY = y;
@@ -419,4 +423,25 @@ public class GuiNpcTextArea extends GuiNpcTextField {
}
drawTexturedModalRect(x, y, width, 11, 5, 1);
}
public void draw(int mouseX, int mouseY) { drawTextBox(mouseX, mouseY); }
@Override
public boolean keyTyped(char c, int keyCode) { return textboxKeyTyped(c, keyCode); }
public boolean handleClick(int mouseX, int mouseY, int button) {
boolean wasInside = isInside(mouseX, mouseY);
mouseClicked(mouseX, mouseY, button);
return wasInside && button == 0;
}
public boolean isInside(int mouseX, int mouseY) {
return mouseX >= posX && mouseX < posX + width &&
mouseY >= posY && mouseY < posY + height;
}
public void setEnabled(boolean enabled) {
this.enabled = enabled;
this.canEdit = enabled;
}
}
@@ -50,6 +50,10 @@ public class GuiNpcTextField extends GuiTextField {
this(id, parent, Minecraft.getMinecraft().fontRenderer, i, j, k, l, s);
}
public GuiNpcTextField(int id, int x, int y, int width, int height, String text) {
this(id, null, Minecraft.getMinecraft().fontRenderer, x, y, width, height, text != null ? text : "");
}
public void initGui() {
}
@@ -195,6 +199,26 @@ public class GuiNpcTextField extends GuiTextField {
}
}
public void setBounds(int x, int y, int w, int h) {
this.xPosition = x;
this.yPosition = y;
this.width = w;
this.height = h;
}
public void draw(int mouseX, int mouseY) { drawTextBox(); }
public boolean keyTyped(char c, int keyCode) { return textboxKeyTyped(c, keyCode); }
public boolean handleClick(int mouseX, int mouseY, int button) {
boolean wasInside = isMouseOver(mouseX, mouseY);
mouseClicked(mouseX, mouseY, button);
return wasInside && button == 0;
}
public int getX() { return xPosition; }
public int getY() { return yPosition; }
public void drawTextBox(int mousX, int mousY) {
drawTextBox();
}