mirror of
https://github.com/KAMKEEL/CustomNPC-Plus.git
synced 2026-11-24 21:04:27 +00:00
Compare commits
6
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
7a1b4c20cf | ||
|
|
fff0bfd63b | ||
|
|
e010408257 | ||
|
|
3e28c3cace | ||
|
|
fb45a79e22 | ||
|
|
5417cf8126 |
No files matched your search
+1
-35
@@ -4,34 +4,21 @@
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
## Features: ⚒️
|
## Scripting:
|
||||||
|
|
||||||
- **Syntax Highlighting:**
|
- **Syntax Highlighting:**
|
||||||
|
|
||||||
> Full color-coded script editor. Keywords, types, variables, methods, strings, and comments are all distinct. Scope-aware coloring distinguishes local fields from globals and chained method calls.
|
> Full color-coded script editor. Keywords, types, variables, methods, strings, and comments are all distinct. Scope-aware coloring distinguishes local fields from globals and chained method calls.
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
- **Autocomplete:**
|
- **Autocomplete:**
|
||||||
|
|
||||||
> Smart suggestions as you type. Context-aware for static vs instance access, shows method parameters, resolves chained calls, and suggests auto imports for classes. Frequently used members prioritized.
|
> Smart suggestions as you type. Context-aware for static vs instance access, shows method parameters, resolves chained calls, and suggests auto imports for classes. Frequently used members prioritized.
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
- **Error Detection:**
|
- **Error Detection:**
|
||||||
|
|
||||||
> Catch mistakes before running. Type mismatches, wrong arguments, missing methods, unused imports, duplicate definitions, and more -- all underlined with hover messages explaining the issue.
|
> Catch mistakes before running. Type mismatches, wrong arguments, missing methods, unused imports, duplicate definitions, and more -- all underlined with hover messages explaining the issue.
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
- **Hover Information:**
|
- **Hover Information:**
|
||||||
|
|
||||||
> Hover any symbol to see its type, documentation, and declaration. Works on methods, fields, classes, and even generics. Click to pin tooltips in place.
|
> Hover any symbol to see its type, documentation, and declaration. Works on methods, fields, classes, and even generics. Click to pin tooltips in place.
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
- **Script Editor Overhaul:**
|
- **Script Editor Overhaul:**
|
||||||
|
|
||||||
> - **Line Numbers** - Gutter with current line highlighting.
|
> - **Line Numbers** - Gutter with current line highlighting.
|
||||||
> - **Go To Line** - CTRL+G to jump to any line.
|
> - **Go To Line** - CTRL+G to jump to any line.
|
||||||
> - **Search & Replace** - CTRL+F / CTRL+H with real-time highlighting.
|
> - **Search & Replace** - CTRL+F / CTRL+H with real-time highlighting.
|
||||||
@@ -47,40 +34,19 @@
|
|||||||
> - **Fullscreen Mode** - Expand editor to fill the game window.
|
> - **Fullscreen Mode** - Expand editor to fill the game window.
|
||||||
> - **Shortcut Overlay** - View all keyboard shortcuts at a glance.
|
> - **Shortcut Overlay** - View all keyboard shortcuts at a glance.
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
- **Java Scripting (Janino):**
|
- **Java Scripting (Janino):**
|
||||||
|
|
||||||
> Write scripts in real Java compiled at runtime. Name methods after hooks for automatic wiring. Language selector per tab to switch between Java and JavaScript. External `.java` file support.
|
> Write scripts in real Java compiled at runtime. Name methods after hooks for automatic wiring. Language selector per tab to switch between Java and JavaScript. External `.java` file support.
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
- **Client-Side Scripting:**
|
- **Client-Side Scripting:**
|
||||||
|
|
||||||
> Run scripts on the client for responsive experiences. Server-controlled -- off by default, must be explicitly enabled. Script files sync automatically on login and reload.
|
> Run scripts on the client for responsive experiences. Server-controlled -- off by default, must be explicitly enabled. Script files sync automatically on login and reload.
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
- **Cloner Tab Overhaul:**
|
- **Cloner Tab Overhaul:**
|
||||||
|
|
||||||
> Folder-based organization for saved NPCs, items, and entries. Full-width directory browser for large collections. Improved tab navigation.
|
> Folder-based organization for saved NPCs, items, and entries. Full-width directory browser for large collections. Improved tab navigation.
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
- **Addon API Support:**
|
|
||||||
|
|
||||||
> Addons can ship type definitions that load into the script editor automatically. Full autocomplete, hover info, and documentation for addon APIs. Addons can extend existing CNPC+ types with new methods.
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
- **Animation Improvements:**
|
- **Animation Improvements:**
|
||||||
|
|
||||||
> Data store for passing data across animation events and frames. New consumer-based task system for animation lifecycle. Expanded scripting API for animation control.
|
> Data store for passing data across animation events and frames. New consumer-based task system for animation lifecycle. Expanded scripting API for animation control.
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
**Extras**
|
**Extras**
|
||||||
|
|
||||||
- Player Dialog Events now work like NPC Dialog Events.
|
- Player Dialog Events now work like NPC Dialog Events.
|
||||||
- Attack speed configuration for linked items.
|
- Attack speed configuration for linked items.
|
||||||
- Client-side balance prediction during Trader interactions.
|
- Client-side balance prediction during Trader interactions.
|
||||||
|
|||||||
+1
-64
@@ -2,142 +2,79 @@
|
|||||||
|
|
||||||
🟡 **In Testing**
|
🟡 **In Testing**
|
||||||
|
|
||||||
|
## Ability Update: ⚒️
|
||||||
|
|
||||||
## Features: ⚒️
|
|
||||||
|
|
||||||
- **Phase-Based Execution:**
|
- **Phase-Based Execution:**
|
||||||
|
|
||||||
> All abilities follow a Wind-up → Active → Completion flow. Wind-up lets players react, Active deals the effect.
|
> All abilities follow a Wind-up → Active → Completion flow. Wind-up lets players react, Active deals the effect.
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
- **Melee Abilities:**
|
- **Melee Abilities:**
|
||||||
|
|
||||||
> - **Slam** - Leap and AOE on impact.
|
> - **Slam** - Leap and AOE on impact.
|
||||||
> - **Heavy Hit** - Single powerful strike with bonus knockback.
|
> - **Heavy Hit** - Single powerful strike with bonus knockback.
|
||||||
> - **Cutter** - Slashing cone arc attack.
|
> - **Cutter** - Slashing cone arc attack.
|
||||||
> - **Shockwave** - AOE burst radiating from the caster.
|
> - **Shockwave** - AOE burst radiating from the caster.
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
- **Energy Orbs:**
|
- **Energy Orbs:**
|
||||||
|
|
||||||
> - **Orb** - Homing energy sphere.
|
> - **Orb** - Homing energy sphere.
|
||||||
> - **Dual Orb** - Two simultaneous homing orbs.
|
> - **Dual Orb** - Two simultaneous homing orbs.
|
||||||
> - **Orb Barrage** - Rapid volley of orbs in sequence.
|
> - **Orb Barrage** - Rapid volley of orbs in sequence.
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
- **Energy Discs:**
|
- **Energy Discs:**
|
||||||
|
|
||||||
> - **Disc** - Spinning flat projectile with optional boomerang.
|
> - **Disc** - Spinning flat projectile with optional boomerang.
|
||||||
> - **Dual Disc** - Two simultaneous discs.
|
> - **Dual Disc** - Two simultaneous discs.
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
- **Energy Beams:**
|
- **Energy Beams:**
|
||||||
|
|
||||||
> - **Beam** - Sustained homing beam from caster to target.
|
> - **Beam** - Sustained homing beam from caster to target.
|
||||||
> - **Dual Beam** - Two simultaneous beams.
|
> - **Dual Beam** - Two simultaneous beams.
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
- **Laser Shot:**
|
- **Laser Shot:**
|
||||||
|
|
||||||
> Instant-fire projectile with no homing. Pure aim.
|
> Instant-fire projectile with no homing. Pure aim.
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
- **Projectile:**
|
- **Projectile:**
|
||||||
|
|
||||||
> Standard projectile using classic Minecraft physics.
|
> Standard projectile using classic Minecraft physics.
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
- **Movement Abilities:**
|
- **Movement Abilities:**
|
||||||
|
|
||||||
> - **Charge** - Rush forward in a line, damaging everything in path.
|
> - **Charge** - Rush forward in a line, damaging everything in path.
|
||||||
> - **Dash** - Quick directional movement without damage.
|
> - **Dash** - Quick directional movement without damage.
|
||||||
> - **Teleport** - Instant relocation to the target.
|
> - **Teleport** - Instant relocation to the target.
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
- **AOE Abilities:**
|
- **AOE Abilities:**
|
||||||
|
|
||||||
> - **Sweeper** - Wide rotational sweep around the caster.
|
> - **Sweeper** - Wide rotational sweep around the caster.
|
||||||
> - **Vortex** - Pulls entities inward while dealing damage.
|
> - **Vortex** - Pulls entities inward while dealing damage.
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
- **Telegraph System:**
|
- **Telegraph System:**
|
||||||
|
|
||||||
> Visual ground indicators during wind-up. Supports Circle, Ring, Line, Cone, and Point shapes with color customization and warning phase transitions.
|
> Visual ground indicators during wind-up. Supports Circle, Ring, Line, Cone, and Point shapes with color customization and warning phase transitions.
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
- **Energy Projectile Customization:**
|
- **Energy Projectile Customization:**
|
||||||
|
|
||||||
> Modular data system for all energy projectiles: Anchor Point, Display Colors, Homing, Combat Stats, and Lifespan.
|
> Modular data system for all energy projectiles: Anchor Point, Display Colors, Homing, Combat Stats, and Lifespan.
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
- **Ability Effects:**
|
- **Ability Effects:**
|
||||||
|
|
||||||
> Abilities can apply potion effects on hit: Slowness, Weakness, Poison, Wither, Blindness, Nausea, Hunger, Mining Fatigue.
|
> Abilities can apply potion effects on hit: Slowness, Weakness, Poison, Wither, Blindness, Nausea, Hunger, Mining Fatigue.
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
- **Ability Conditions:**
|
- **Ability Conditions:**
|
||||||
|
|
||||||
> Condition system controlling when abilities can execute based on target state and custom predicates.
|
> Condition system controlling when abilities can execute based on target state and custom predicates.
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
- **Interruptible Wind-ups:**
|
- **Interruptible Wind-ups:**
|
||||||
|
|
||||||
> Abilities can be interrupted by damage during wind-up, forcing a configurable Dazed recovery state.
|
> Abilities can be interrupted by damage during wind-up, forcing a configurable Dazed recovery state.
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
- **Movement & Rotation Locking:**
|
- **Movement & Rotation Locking:**
|
||||||
|
|
||||||
> Lock caster movement, rotation, or both during Wind-up, Active, or both phases.
|
> Lock caster movement, rotation, or both during Wind-up, Active, or both phases.
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
- **Animation & Sound Integration:**
|
- **Animation & Sound Integration:**
|
||||||
|
|
||||||
> Wind-up and Active animations with optional duration sync. Custom sound events per phase.
|
> Wind-up and Active animations with optional duration sync. Custom sound events per phase.
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
- **Player Abilities:**
|
- **Player Abilities:**
|
||||||
|
|
||||||
> Players can unlock abilities, select one at a time, and share a universal cooldown.
|
> Players can unlock abilities, select one at a time, and share a universal cooldown.
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
- **Ability Preview:**
|
- **Ability Preview:**
|
||||||
|
|
||||||
> Live preview in the ability editor GUI. Test telegraphs, animations, and projectiles on a dummy NPC.
|
> Live preview in the ability editor GUI. Test telegraphs, animations, and projectiles on a dummy NPC.
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
- **Scripting API:**
|
- **Scripting API:**
|
||||||
|
|
||||||
> Full event support: Start, Execute, Interrupt, Complete, Hit (modifiable damage/knockback), and Tick events. Start, Execute, and Hit are cancelable.
|
> Full event support: Start, Execute, Interrupt, Complete, Hit (modifiable damage/knockback), and Tick events. Start, Execute, and Hit are cancelable.
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
- **Ability Commands:**
|
- **Ability Commands:**
|
||||||
|
|
||||||
> `/kam ability list`, `types`, `info`, `delete`, `reload` for managing custom abilities.
|
> `/kam ability list`, `types`, `info`, `delete`, `reload` for managing custom abilities.
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
**Extras**
|
**Extras**
|
||||||
|
|
||||||
- Global ability presets that update everywhere when edited.
|
- Global ability presets that update everywhere when edited.
|
||||||
- Weighted ability selection for NPC random usage.
|
- Weighted ability selection for NPC random usage.
|
||||||
- Configurable min/max range per ability.
|
- Configurable min/max range per ability.
|
||||||
|
|||||||
@@ -1,8 +1,6 @@
|
|||||||
# CNPC+ 1.11 Beta - Market Update
|
# CNPC+ 1.11 Beta - Market Update
|
||||||
|
|
||||||
🟡 **In Testing**
|
## Auction Features: ⚒️
|
||||||
|
|
||||||
## Features: ⚒️
|
|
||||||
|
|
||||||
- **Built-in Currency System:**
|
- **Built-in Currency System:**
|
||||||
> Fully configurable economy currency used across all Market features. Profile persistent across character slots with Vault support for Bukkit-compatible plugins.
|
> Fully configurable economy currency used across all Market features. Profile persistent across character slots with Vault support for Bukkit-compatible plugins.
|
||||||
@@ -50,7 +48,6 @@
|
|||||||
> `/kam auction open` for players. Admin commands for listing view and player activity inspection.
|
> `/kam auction open` for players. Admin commands for listing view and player activity inspection.
|
||||||
|
|
||||||
**Extras**
|
**Extras**
|
||||||
|
|
||||||
- Auction logging for server admins (tracks creates, bids, buyouts, sales, expirations, cancellations, claims).
|
- Auction logging for server admins (tracks creates, bids, buyouts, sales, expirations, cancellations, claims).
|
||||||
- Lifetime currency tracking per player (total earned and spent).
|
- Lifetime currency tracking per player (total earned and spent).
|
||||||
- Configurable starting balance and max balance cap.
|
- Configurable starting balance and max balance cap.
|
||||||
|
|||||||
@@ -0,0 +1,273 @@
|
|||||||
|
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.renderer.Tessellator;
|
||||||
|
import net.minecraft.util.ResourceLocation;
|
||||||
|
import org.lwjgl.opengl.GL11;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 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
|
||||||
|
|
||||||
|
// Remove button
|
||||||
|
protected Runnable onRemove = null;
|
||||||
|
protected boolean hoveringRemoveBtn = false;
|
||||||
|
protected int removeBtnSize = 14;
|
||||||
|
|
||||||
|
// Icon
|
||||||
|
protected static final ResourceLocation X_ICON = new ResourceLocation("customnpcs", "textures/gui/auction/x_icon.png");
|
||||||
|
|
||||||
|
// Colors
|
||||||
|
protected int headerBg = ModernColors.SECTION_HEADER_BG;
|
||||||
|
protected int headerBgHover = ModernColors.SECTION_HEADER_HOVER;
|
||||||
|
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;
|
||||||
|
int titleEndX = x + width;
|
||||||
|
|
||||||
|
// Draw remove button if present
|
||||||
|
if (onRemove != null) {
|
||||||
|
int btnX = x + width - removeBtnSize - 4;
|
||||||
|
int btnY = y + (headerHeight - removeBtnSize) / 2;
|
||||||
|
titleEndX = btnX - 4;
|
||||||
|
|
||||||
|
hoveringRemoveBtn = mouseX >= btnX && mouseX < btnX + removeBtnSize &&
|
||||||
|
mouseY >= btnY && mouseY < btnY + removeBtnSize;
|
||||||
|
|
||||||
|
int btnBg = hoveringRemoveBtn ? 0xFFCC4444 : 0xFFAA3333;
|
||||||
|
drawRect(btnX, btnY, btnX + removeBtnSize, btnY + removeBtnSize, btnBg);
|
||||||
|
Minecraft.getMinecraft().getTextureManager().bindTexture(X_ICON);
|
||||||
|
GL11.glColor4f(1f, 1f, 1f, 1f);
|
||||||
|
GL11.glEnable(GL11.GL_BLEND);
|
||||||
|
int iconSize = removeBtnSize - 4;
|
||||||
|
int ix = btnX + 2;
|
||||||
|
int iy = btnY + 2;
|
||||||
|
Tessellator t = Tessellator.instance;
|
||||||
|
t.startDrawingQuads();
|
||||||
|
t.addVertexWithUV(ix, iy + iconSize, zLevel, 0, 1);
|
||||||
|
t.addVertexWithUV(ix + iconSize, iy + iconSize, zLevel, 1, 1);
|
||||||
|
t.addVertexWithUV(ix + iconSize, iy, zLevel, 1, 0);
|
||||||
|
t.addVertexWithUV(ix, iy, zLevel, 0, 0);
|
||||||
|
t.draw();
|
||||||
|
GL11.glDisable(GL11.GL_BLEND);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Draw title (truncated if needed)
|
||||||
|
String displayTitle = fr.trimStringToWidth(title, titleEndX - titleX);
|
||||||
|
fr.drawString(displayTitle, titleX, y + (headerHeight - fr.FONT_HEIGHT) / 2, headerText);
|
||||||
|
|
||||||
|
// Return whether content should be drawn
|
||||||
|
return expanded || expandProgress > 0.01f;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 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) {
|
||||||
|
|
||||||
|
// Check remove button first
|
||||||
|
if (onRemove != null && hoveringRemoveBtn) {
|
||||||
|
onRemove.run();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Otherwise toggle expand
|
||||||
|
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 setOnRemove(Runnable action) {
|
||||||
|
this.onRemove = action;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public CollapsibleSection setColors(int headerBg, int headerText, int arrow) {
|
||||||
|
this.headerBg = headerBg;
|
||||||
|
this.headerBgHover = ModernColors.lighten(headerBg, 0.1f);
|
||||||
|
this.headerText = headerText;
|
||||||
|
this.arrowColor = arrow;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,381 @@
|
|||||||
|
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;
|
||||||
|
|
||||||
|
// Color button mode
|
||||||
|
protected boolean colorMode = false;
|
||||||
|
protected int displayColor = 0xFFFFFF;
|
||||||
|
|
||||||
|
// 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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// === 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
|
||||||
|
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;
|
||||||
|
|
||||||
|
if (colorMode) {
|
||||||
|
drawColorButton(fr, mouseX, mouseY);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 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();
|
||||||
|
}
|
||||||
|
|
||||||
|
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
|
||||||
|
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,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,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,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,295 @@
|
|||||||
|
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 void setBackgroundColor(int color) {
|
||||||
|
this.backgroundColor = color;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void resetScroll() {
|
||||||
|
this.scrollY = 0;
|
||||||
|
this.targetScrollY = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
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,428 @@
|
|||||||
|
package kamkeel.npcs.client.gui.modern;
|
||||||
|
|
||||||
|
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;
|
||||||
|
import net.minecraft.client.Minecraft;
|
||||||
|
import net.minecraft.client.gui.FontRenderer;
|
||||||
|
import net.minecraft.client.gui.Gui;
|
||||||
|
import noppes.npcs.controllers.data.Dialog;
|
||||||
|
|
||||||
|
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;
|
||||||
|
|
||||||
|
// === Scroll Panel (replaces manual scroll logic) ===
|
||||||
|
protected ScrollPanel scrollPanel;
|
||||||
|
|
||||||
|
// === 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;
|
||||||
|
|
||||||
|
// === 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();
|
||||||
|
initScrollPanel();
|
||||||
|
}
|
||||||
|
|
||||||
|
protected void initScrollPanel() {
|
||||||
|
int contentY = y + headerHeight + tabBarHeight;
|
||||||
|
int contentAreaH = height - headerHeight - tabBarHeight - footerHeight;
|
||||||
|
scrollPanel = new ScrollPanel(x, contentY, width, contentAreaH);
|
||||||
|
scrollPanel.setBackgroundColor(0); // Transparent - we draw our own background
|
||||||
|
}
|
||||||
|
|
||||||
|
protected int getScrollbarWidth() {
|
||||||
|
return scrollPanel != null ? 6 : 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
// === 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;
|
||||||
|
scrollPanel.resetScroll();
|
||||||
|
|
||||||
|
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;
|
||||||
|
|
||||||
|
// Background
|
||||||
|
drawRect(x, y, x + width, y + height, ModernColors.PANEL_BG_SOLID);
|
||||||
|
|
||||||
|
// Header
|
||||||
|
drawHeader(mouseX, mouseY, fr);
|
||||||
|
|
||||||
|
// Tab bar
|
||||||
|
drawTabBar(mouseX, mouseY, fr);
|
||||||
|
|
||||||
|
// Update screen positions for all dropdowns BEFORE scroll translation
|
||||||
|
updateDropdownScreenPositions();
|
||||||
|
|
||||||
|
// Draw scrollable content using ScrollPanel
|
||||||
|
int contentX = x + padding;
|
||||||
|
int contentW = width - padding * 2 - getScrollbarWidth();
|
||||||
|
int startY = y + headerHeight + tabBarHeight + padding;
|
||||||
|
|
||||||
|
scrollPanel.beginDraw();
|
||||||
|
|
||||||
|
// Draw current tab content
|
||||||
|
int contentHeight = tabs[currentTab].draw(contentX, contentW, startY,
|
||||||
|
mouseX, scrollPanel.toContentY(mouseY), fr);
|
||||||
|
|
||||||
|
// Update scroll panel's content height
|
||||||
|
scrollPanel.setContentHeight(contentHeight);
|
||||||
|
|
||||||
|
scrollPanel.endDraw(mouseX, mouseY);
|
||||||
|
|
||||||
|
// 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 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 = scrollPanel.toScreenY(dropdown.getY());
|
||||||
|
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;
|
||||||
|
scrollPanel.resetScroll();
|
||||||
|
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 - delegate to ScrollPanel
|
||||||
|
if (scrollPanel.mouseClicked(mouseX, mouseY, button)) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
// CHECK EXPANDED DROPDOWNS FIRST - delegate to current tab's field panel
|
||||||
|
if (tabs[currentTab].handleExpandedDropdownScreenClick(mouseX, mouseY, button)) {
|
||||||
|
markDirty();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Adjust mouseY for scroll (for components inside scrollable content)
|
||||||
|
int adjMouseY = scrollPanel.toContentY(mouseY);
|
||||||
|
|
||||||
|
// 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) {
|
||||||
|
scrollPanel.mouseScrolled(delta);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void mouseReleased(int mouseX, int mouseY) {
|
||||||
|
scrollPanel.mouseReleased(mouseX, mouseY);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void mouseDragged(int mouseX, int mouseY) {
|
||||||
|
scrollPanel.mouseDragged(mouseX, mouseY);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void updateScreen() {
|
||||||
|
for (DialogEditorTab tab : tabs) {
|
||||||
|
tab.updateScreen();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// === 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;
|
||||||
|
// Update scroll panel bounds
|
||||||
|
int contentY = y + headerHeight + tabBarHeight;
|
||||||
|
int contentAreaH = height - headerHeight - tabBarHeight - footerHeight;
|
||||||
|
scrollPanel.setBounds(x, contentY, width, contentAreaH);
|
||||||
|
}
|
||||||
|
|
||||||
|
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) {
|
||||||
|
optionsTab.onColorSelected(slot, color);
|
||||||
|
} else {
|
||||||
|
feedbackTab.onColorSelected(slot, color);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
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,492 @@
|
|||||||
|
package kamkeel.npcs.client.gui.modern;
|
||||||
|
|
||||||
|
import kamkeel.npcs.client.gui.components.ModernButton;
|
||||||
|
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;
|
||||||
|
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 GuiNpcTextField catSearchField;
|
||||||
|
protected GuiNpcTextField 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 GuiNpcTextField(0, catListX, contentY, catListW, searchH, catSearch);
|
||||||
|
|
||||||
|
itemSearchField = new GuiNpcTextField(1, itemListX, contentY, itemListW, searchH, 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,272 @@
|
|||||||
|
package kamkeel.npcs.client.gui.modern;
|
||||||
|
|
||||||
|
import kamkeel.npcs.client.gui.components.ModernButton;
|
||||||
|
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;
|
||||||
|
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 GuiNpcTextField 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 GuiNpcTextField(0, previewX + previewSize + 12, fieldRowY, 100, 18, getHexString());
|
||||||
|
hexField.setMaxStringLength(6);
|
||||||
|
|
||||||
|
// 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.
|
||||||
|
* Uses circular bounds for accurate detection.
|
||||||
|
*/
|
||||||
|
private boolean isInsideWheel(int mouseX, int mouseY) {
|
||||||
|
// First check rectangle bounds
|
||||||
|
if (mouseX < wheelX || mouseX >= wheelX + wheelSize ||
|
||||||
|
mouseY < wheelY || mouseY >= wheelY + wheelSize) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
// Then check circular bounds (wheel is circular)
|
||||||
|
int centerX = wheelX + wheelSize / 2;
|
||||||
|
int centerY = wheelY + wheelSize / 2;
|
||||||
|
int radius = wheelSize / 2;
|
||||||
|
int dx = mouseX - centerX;
|
||||||
|
int dy = mouseY - centerY;
|
||||||
|
return (dx * dx + dy * dy) <= (radius * radius);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Pick color from the wheel texture at clicked position.
|
||||||
|
* Uses the same 4x multiplier as the original SubGuiColorSelector
|
||||||
|
* since the texture is 480x480 and we display at variable size.
|
||||||
|
*/
|
||||||
|
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());
|
||||||
|
|
||||||
|
// Calculate texture coordinates using the same ratio as original
|
||||||
|
// Original: draws 120x120, texture is 480x480, uses *4 multiplier
|
||||||
|
// We draw wheelSize x wheelSize, so scale proportionally
|
||||||
|
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));
|
||||||
|
|
||||||
|
// Get pixel color, ignoring alpha and transparent pixels
|
||||||
|
int pixel = image.getRGB(texX, texY);
|
||||||
|
int alpha = (pixel >> 24) & 0xFF;
|
||||||
|
if (alpha > 0) {
|
||||||
|
color = pixel & 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,305 @@
|
|||||||
|
package kamkeel.npcs.client.gui.modern;
|
||||||
|
|
||||||
|
import kamkeel.npcs.client.gui.components.ModernButton;
|
||||||
|
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;
|
||||||
|
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 GuiNpcTextField 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 GuiNpcTextField(0, listX, contentY, listWidth, searchH, 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,542 @@
|
|||||||
|
package kamkeel.npcs.client.gui.modern;
|
||||||
|
|
||||||
|
import kamkeel.npcs.client.gui.components.ModernButton;
|
||||||
|
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;
|
||||||
|
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 GuiNpcTextField subjectField;
|
||||||
|
private GuiNpcTextField 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 GuiNpcTextField(0, guiLeft + pad + labelW, rowY, fieldW, 18, mail.subject);
|
||||||
|
subjectField.setMaxStringLength(64);
|
||||||
|
rowY += rowH;
|
||||||
|
|
||||||
|
// Sender row
|
||||||
|
senderField = new GuiNpcTextField(1, guiLeft + pad + labelW, rowY, fieldW, 18, mail.sender);
|
||||||
|
senderField.setMaxStringLength(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,444 @@
|
|||||||
|
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 noppes.npcs.client.gui.util.GuiNpcTextField;
|
||||||
|
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 GuiNpcTextField domainSearchField;
|
||||||
|
private GuiNpcTextField 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 GuiNpcTextField(0, domainListX, contentY, domainListW, searchH, domainSearch);
|
||||||
|
|
||||||
|
soundSearchField = new GuiNpcTextField(1, soundListX, contentY, soundListW, searchH, 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,182 @@
|
|||||||
|
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;
|
||||||
|
// Whether to draw overlay over entire screen (true) or just around panel (false)
|
||||||
|
protected boolean fullScreenOverlay = false;
|
||||||
|
|
||||||
|
// 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
|
||||||
|
// Only darken a region around the panel, not the entire screen
|
||||||
|
// This allows the diagram/tree view to remain visible
|
||||||
|
if (fullScreenOverlay) {
|
||||||
|
Gui.drawRect(0, 0, width, height, overlayColor);
|
||||||
|
} else {
|
||||||
|
// Draw overlay only behind and slightly around the panel
|
||||||
|
int margin = 20;
|
||||||
|
int overlayLeft = Math.max(0, guiLeft - margin);
|
||||||
|
int overlayTop = Math.max(0, guiTop - margin);
|
||||||
|
int overlayRight = Math.min(width, guiLeft + xSize + margin);
|
||||||
|
int overlayBottom = Math.min(height, guiTop + ySize + margin);
|
||||||
|
Gui.drawRect(overlayLeft, overlayTop, overlayRight, overlayBottom, 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;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set whether to draw overlay over entire screen or just around panel.
|
||||||
|
* Default is false (localized overlay to preserve visibility of parent content).
|
||||||
|
*/
|
||||||
|
public void setFullScreenOverlay(boolean fullScreen) {
|
||||||
|
this.fullScreenOverlay = fullScreen;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 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,227 @@
|
|||||||
|
package kamkeel.npcs.client.gui.modern.tabs;
|
||||||
|
|
||||||
|
import kamkeel.npcs.client.gui.components.ModernDropdown;
|
||||||
|
import kamkeel.npcs.client.gui.modern.DialogEditorPanel;
|
||||||
|
import net.minecraft.client.gui.FontRenderer;
|
||||||
|
import noppes.npcs.client.gui.builder.FieldDef;
|
||||||
|
import noppes.npcs.client.gui.builder.ModernFieldPanel;
|
||||||
|
import noppes.npcs.client.gui.builder.ModernFieldPanelListener;
|
||||||
|
import noppes.npcs.client.gui.util.IDialogEditorListener;
|
||||||
|
import noppes.npcs.constants.EnumAvailabilityDialog;
|
||||||
|
import noppes.npcs.constants.EnumAvailabilityFaction;
|
||||||
|
import noppes.npcs.constants.EnumAvailabilityFactionType;
|
||||||
|
import noppes.npcs.constants.EnumAvailabilityQuest;
|
||||||
|
import noppes.npcs.constants.EnumDayTime;
|
||||||
|
import noppes.npcs.controllers.data.Availability;
|
||||||
|
import noppes.npcs.controllers.data.Dialog;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Availability tab for the dialog editor.
|
||||||
|
* Contains quest, dialog, faction requirements and time/level settings.
|
||||||
|
* Uses ModernFieldPanel with custom AVAILABILITY_ROW and FACTION_ROW field types.
|
||||||
|
*/
|
||||||
|
public class DialogAvailabilityTab extends DialogEditorTab {
|
||||||
|
|
||||||
|
private static final String[] QUEST_CONDITIONS = {"Always", "After", "Before", "Active", "Not Active", "Acceptable", "Not Acceptable"};
|
||||||
|
private static final String[] DIALOG_CONDITIONS = {"Always", "After", "Before"};
|
||||||
|
|
||||||
|
private ModernFieldPanel fieldPanel;
|
||||||
|
|
||||||
|
public DialogAvailabilityTab(DialogEditorPanel parent) {
|
||||||
|
super(parent);
|
||||||
|
fieldPanel = new ModernFieldPanel();
|
||||||
|
fieldPanel.setListener(new ModernFieldPanelListener() {
|
||||||
|
@Override
|
||||||
|
public void onSelectAction(String action, int slot) {
|
||||||
|
IDialogEditorListener listener = parent.getListener();
|
||||||
|
if (listener == null) return;
|
||||||
|
switch (action) {
|
||||||
|
case "quest":
|
||||||
|
listener.onQuestSelectRequested(slot);
|
||||||
|
break;
|
||||||
|
case "dialog":
|
||||||
|
listener.onDialogSelectRequested(slot);
|
||||||
|
break;
|
||||||
|
case "faction":
|
||||||
|
listener.onFactionSelectRequested(slot);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onColorSelect(int slot, int currentColor) {
|
||||||
|
// No color fields in this tab
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onFieldChanged() {
|
||||||
|
markDirty();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
private List<FieldDef> createFieldDefs() {
|
||||||
|
Availability a = dialog.availability;
|
||||||
|
List<FieldDef> defs = new ArrayList<>();
|
||||||
|
|
||||||
|
// Quest Requirements (expanded by default)
|
||||||
|
defs.add(FieldDef.section("Quest Requirements").collapsed(true));
|
||||||
|
defs.add(FieldDef.availabilityRow("", QUEST_CONDITIONS,
|
||||||
|
() -> a.questAvailable.ordinal(), v -> a.questAvailable = EnumAvailabilityQuest.values()[v],
|
||||||
|
() -> a.questId, v -> a.questId = v,
|
||||||
|
() -> a.questId >= 0 ? "Quest #" + a.questId : "")
|
||||||
|
.action("quest").slot(1).clearable(() -> a.questId = -1));
|
||||||
|
defs.add(FieldDef.availabilityRow("", QUEST_CONDITIONS,
|
||||||
|
() -> a.quest2Available.ordinal(), v -> a.quest2Available = EnumAvailabilityQuest.values()[v],
|
||||||
|
() -> a.quest2Id, v -> a.quest2Id = v,
|
||||||
|
() -> a.quest2Id >= 0 ? "Quest #" + a.quest2Id : "")
|
||||||
|
.action("quest").slot(2).clearable(() -> a.quest2Id = -1));
|
||||||
|
defs.add(FieldDef.availabilityRow("", QUEST_CONDITIONS,
|
||||||
|
() -> a.quest3Available.ordinal(), v -> a.quest3Available = EnumAvailabilityQuest.values()[v],
|
||||||
|
() -> a.quest3Id, v -> a.quest3Id = v,
|
||||||
|
() -> a.quest3Id >= 0 ? "Quest #" + a.quest3Id : "")
|
||||||
|
.action("quest").slot(3).clearable(() -> a.quest3Id = -1));
|
||||||
|
defs.add(FieldDef.availabilityRow("", QUEST_CONDITIONS,
|
||||||
|
() -> a.quest4Available.ordinal(), v -> a.quest4Available = EnumAvailabilityQuest.values()[v],
|
||||||
|
() -> a.quest4Id, v -> a.quest4Id = v,
|
||||||
|
() -> a.quest4Id >= 0 ? "Quest #" + a.quest4Id : "")
|
||||||
|
.action("quest").slot(4).clearable(() -> a.quest4Id = -1));
|
||||||
|
|
||||||
|
// Dialog Requirements
|
||||||
|
defs.add(FieldDef.section("Dialog Requirements").collapsed(true));
|
||||||
|
defs.add(FieldDef.availabilityRow("", DIALOG_CONDITIONS,
|
||||||
|
() -> a.dialogAvailable.ordinal(), v -> a.dialogAvailable = EnumAvailabilityDialog.values()[v],
|
||||||
|
() -> a.dialogId, v -> a.dialogId = v,
|
||||||
|
() -> a.dialogId >= 0 ? "Dialog #" + a.dialogId : "")
|
||||||
|
.action("dialog").slot(0).clearable(() -> a.dialogId = -1));
|
||||||
|
defs.add(FieldDef.availabilityRow("", DIALOG_CONDITIONS,
|
||||||
|
() -> a.dialog2Available.ordinal(), v -> a.dialog2Available = EnumAvailabilityDialog.values()[v],
|
||||||
|
() -> a.dialog2Id, v -> a.dialog2Id = v,
|
||||||
|
() -> a.dialog2Id >= 0 ? "Dialog #" + a.dialog2Id : "")
|
||||||
|
.action("dialog").slot(1).clearable(() -> a.dialog2Id = -1));
|
||||||
|
defs.add(FieldDef.availabilityRow("", DIALOG_CONDITIONS,
|
||||||
|
() -> a.dialog3Available.ordinal(), v -> a.dialog3Available = EnumAvailabilityDialog.values()[v],
|
||||||
|
() -> a.dialog3Id, v -> a.dialog3Id = v,
|
||||||
|
() -> a.dialog3Id >= 0 ? "Dialog #" + a.dialog3Id : "")
|
||||||
|
.action("dialog").slot(2).clearable(() -> a.dialog3Id = -1));
|
||||||
|
defs.add(FieldDef.availabilityRow("", DIALOG_CONDITIONS,
|
||||||
|
() -> a.dialog4Available.ordinal(), v -> a.dialog4Available = EnumAvailabilityDialog.values()[v],
|
||||||
|
() -> a.dialog4Id, v -> a.dialog4Id = v,
|
||||||
|
() -> a.dialog4Id >= 0 ? "Dialog #" + a.dialog4Id : "")
|
||||||
|
.action("dialog").slot(3).clearable(() -> a.dialog4Id = -1));
|
||||||
|
|
||||||
|
// Faction Requirements
|
||||||
|
defs.add(FieldDef.section("Faction Requirements").collapsed(true));
|
||||||
|
defs.add(FieldDef.factionRow("",
|
||||||
|
() -> a.factionAvailable.ordinal(), v -> a.factionAvailable = EnumAvailabilityFactionType.values()[v],
|
||||||
|
() -> a.factionStance.ordinal(), v -> a.factionStance = EnumAvailabilityFaction.values()[v],
|
||||||
|
() -> a.factionId, v -> a.factionId = v,
|
||||||
|
() -> a.factionId >= 0 ? "Faction #" + a.factionId : "")
|
||||||
|
.action("faction").slot(0).clearable(() -> a.factionId = -1));
|
||||||
|
defs.add(FieldDef.factionRow("",
|
||||||
|
() -> a.faction2Available.ordinal(), v -> a.faction2Available = EnumAvailabilityFactionType.values()[v],
|
||||||
|
() -> a.faction2Stance.ordinal(), v -> a.faction2Stance = EnumAvailabilityFaction.values()[v],
|
||||||
|
() -> a.faction2Id, v -> a.faction2Id = v,
|
||||||
|
() -> a.faction2Id >= 0 ? "Faction #" + a.faction2Id : "")
|
||||||
|
.action("faction").slot(1).clearable(() -> a.faction2Id = -1));
|
||||||
|
|
||||||
|
// Time & Level
|
||||||
|
defs.add(FieldDef.section("Time & Level").collapsed(true));
|
||||||
|
defs.add(FieldDef.row(
|
||||||
|
FieldDef.stringEnumField("Time", new String[]{"Always", "Night", "Day"},
|
||||||
|
() -> new String[]{"Always", "Night", "Day"}[a.daytime.ordinal()],
|
||||||
|
v -> {
|
||||||
|
if ("Night".equals(v)) a.daytime = EnumDayTime.Night;
|
||||||
|
else if ("Day".equals(v)) a.daytime = EnumDayTime.Day;
|
||||||
|
else a.daytime = EnumDayTime.Always;
|
||||||
|
}),
|
||||||
|
FieldDef.intField("Min Lvl", () -> a.minPlayerLevel, v -> a.minPlayerLevel = v)
|
||||||
|
.range(0, 1000)
|
||||||
|
));
|
||||||
|
|
||||||
|
return defs;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void loadFromDialog(Dialog dialog) {
|
||||||
|
this.dialog = dialog;
|
||||||
|
if (dialog == null || dialog.availability == null) return;
|
||||||
|
fieldPanel.setFields(createFieldDefs());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void saveToDialog(Dialog dialog) {
|
||||||
|
// No-op: immediate binding via FieldDef closures
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int draw(int cx, int cw, int startY, int mouseX, int mouseY, FontRenderer fr) {
|
||||||
|
return fieldPanel.draw(cx, cw, startY, mouseX, mouseY, fr);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean mouseClicked(int mouseX, int mouseY, int button) {
|
||||||
|
return fieldPanel.mouseClicked(mouseX, mouseY, button);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean keyTyped(char c, int keyCode) {
|
||||||
|
return fieldPanel.keyTyped(c, keyCode);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void updateScreen() {
|
||||||
|
fieldPanel.updateScreen();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<ModernDropdown> getDropdowns() {
|
||||||
|
return fieldPanel.getDropdowns();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean handleExpandedDropdownScreenClick(int mouseX, int mouseY, int button) {
|
||||||
|
return fieldPanel.handleExpandedDropdownScreenClick(mouseX, mouseY, button);
|
||||||
|
}
|
||||||
|
|
||||||
|
// === Selection Callbacks ===
|
||||||
|
|
||||||
|
public void onQuestSelected(int slot, int questId, String questName) {
|
||||||
|
if (dialog == null || dialog.availability == null) return;
|
||||||
|
Availability a = dialog.availability;
|
||||||
|
// slot 1-4 are availability quest slots
|
||||||
|
switch (slot) {
|
||||||
|
case 1: a.questId = questId; break;
|
||||||
|
case 2: a.quest2Id = questId; break;
|
||||||
|
case 3: a.quest3Id = questId; break;
|
||||||
|
case 4: a.quest4Id = questId; break;
|
||||||
|
}
|
||||||
|
markDirty();
|
||||||
|
// Display syncs from getter on next draw
|
||||||
|
}
|
||||||
|
|
||||||
|
public void onDialogSelected(int slot, int dialogId, String dialogName) {
|
||||||
|
if (dialog == null || dialog.availability == null) return;
|
||||||
|
Availability a = dialog.availability;
|
||||||
|
switch (slot) {
|
||||||
|
case 0: a.dialogId = dialogId; break;
|
||||||
|
case 1: a.dialog2Id = dialogId; break;
|
||||||
|
case 2: a.dialog3Id = dialogId; break;
|
||||||
|
case 3: a.dialog4Id = dialogId; break;
|
||||||
|
}
|
||||||
|
markDirty();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void onFactionSelected(int slot, int factionId, String factionName) {
|
||||||
|
if (dialog == null || dialog.availability == null) return;
|
||||||
|
Availability a = dialog.availability;
|
||||||
|
switch (slot) {
|
||||||
|
case 0: a.factionId = factionId; break;
|
||||||
|
case 1: a.faction2Id = factionId; break;
|
||||||
|
}
|
||||||
|
markDirty();
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,85 @@
|
|||||||
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Handle clicks on expanded dropdowns in screen space.
|
||||||
|
* Override in tabs that use ModernFieldPanel.
|
||||||
|
*/
|
||||||
|
public boolean handleExpandedDropdownScreenClick(int mouseX, int mouseY, int button) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Mark the editor as dirty (unsaved changes).
|
||||||
|
*/
|
||||||
|
protected void markDirty() {
|
||||||
|
parent.markDirty();
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,147 @@
|
|||||||
|
package kamkeel.npcs.client.gui.modern.tabs;
|
||||||
|
|
||||||
|
import kamkeel.npcs.client.gui.components.ModernDropdown;
|
||||||
|
import kamkeel.npcs.client.gui.modern.DialogEditorPanel;
|
||||||
|
import net.minecraft.client.gui.FontRenderer;
|
||||||
|
import noppes.npcs.client.gui.builder.FieldDef;
|
||||||
|
import noppes.npcs.client.gui.builder.ModernFieldPanel;
|
||||||
|
import noppes.npcs.client.gui.builder.ModernFieldPanelListener;
|
||||||
|
import noppes.npcs.client.gui.util.IDialogEditorListener;
|
||||||
|
import noppes.npcs.controllers.data.Dialog;
|
||||||
|
|
||||||
|
import java.util.Arrays;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Feedback tab for the dialog editor.
|
||||||
|
* Contains display options, sound settings, and color configuration.
|
||||||
|
* Uses ModernFieldPanel for declarative field rendering.
|
||||||
|
*/
|
||||||
|
public class DialogFeedbackTab extends DialogEditorTab {
|
||||||
|
|
||||||
|
private ModernFieldPanel fieldPanel;
|
||||||
|
|
||||||
|
public DialogFeedbackTab(DialogEditorPanel parent) {
|
||||||
|
super(parent);
|
||||||
|
fieldPanel = new ModernFieldPanel();
|
||||||
|
fieldPanel.setListener(new ModernFieldPanelListener() {
|
||||||
|
@Override
|
||||||
|
public void onSelectAction(String action, int slot) {
|
||||||
|
IDialogEditorListener listener = parent.getListener();
|
||||||
|
if (listener == null) return;
|
||||||
|
if ("sound".equals(action)) {
|
||||||
|
listener.onSoundSelectRequested();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onColorSelect(int slot, int currentColor) {
|
||||||
|
IDialogEditorListener listener = parent.getListener();
|
||||||
|
if (listener != null) {
|
||||||
|
listener.onColorSelectRequested(slot, currentColor);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onFieldChanged() {
|
||||||
|
markDirty();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
private List<FieldDef> createFieldDefs() {
|
||||||
|
return Arrays.asList(
|
||||||
|
// Display section (expanded by default)
|
||||||
|
FieldDef.section("Display").collapsed(true),
|
||||||
|
FieldDef.boolField("Hide NPC", () -> dialog.hideNPC, v -> dialog.hideNPC = v),
|
||||||
|
FieldDef.boolField("Show Wheel", () -> dialog.showWheel, v -> dialog.showWheel = v),
|
||||||
|
FieldDef.boolField("Darken Screen", () -> dialog.darkenScreen, v -> dialog.darkenScreen = v),
|
||||||
|
FieldDef.boolField("Disable ESC", () -> dialog.disableEsc, v -> dialog.disableEsc = v),
|
||||||
|
FieldDef.stringEnumField("Render Type", new String[]{"Instant", "Gradual"},
|
||||||
|
() -> dialog.renderGradual ? "Gradual" : "Instant",
|
||||||
|
v -> dialog.renderGradual = "Gradual".equals(v)),
|
||||||
|
FieldDef.boolField("Prev Blocks", () -> dialog.showPreviousBlocks, v -> dialog.showPreviousBlocks = v),
|
||||||
|
FieldDef.boolField("Option Line", () -> dialog.showOptionLine, v -> dialog.showOptionLine = v),
|
||||||
|
|
||||||
|
// Sound section
|
||||||
|
FieldDef.section("Sound").collapsed(true),
|
||||||
|
FieldDef.row(
|
||||||
|
FieldDef.stringField("Sound", () -> dialog.sound, v -> dialog.sound = v).placeholder("Sound path..."),
|
||||||
|
FieldDef.selectField("...", () -> "...").action("sound")
|
||||||
|
),
|
||||||
|
FieldDef.stringField("Text Sound", () -> dialog.textSound, v -> dialog.textSound = v)
|
||||||
|
.placeholder("Text sound...")
|
||||||
|
.visibleWhen(() -> dialog.renderGradual),
|
||||||
|
FieldDef.floatField("Pitch", () -> dialog.textPitch, v -> dialog.textPitch = v)
|
||||||
|
.range(0.1f, 2.0f)
|
||||||
|
.visibleWhen(() -> dialog.renderGradual),
|
||||||
|
|
||||||
|
// Colors section
|
||||||
|
FieldDef.section("Colors").collapsed(true),
|
||||||
|
FieldDef.row(
|
||||||
|
FieldDef.colorField("Text", () -> dialog.color, v -> dialog.color = v).slot(0),
|
||||||
|
FieldDef.colorField("Title", () -> dialog.titleColor, v -> dialog.titleColor = v).slot(1)
|
||||||
|
)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void loadFromDialog(Dialog dialog) {
|
||||||
|
this.dialog = dialog;
|
||||||
|
if (dialog == null) return;
|
||||||
|
fieldPanel.setFields(createFieldDefs());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void saveToDialog(Dialog dialog) {
|
||||||
|
// No-op: immediate binding via FieldDef closures
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int draw(int cx, int cw, int startY, int mouseX, int mouseY, FontRenderer fr) {
|
||||||
|
return fieldPanel.draw(cx, cw, startY, mouseX, mouseY, fr);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean mouseClicked(int mouseX, int mouseY, int button) {
|
||||||
|
return fieldPanel.mouseClicked(mouseX, mouseY, button);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean keyTyped(char c, int keyCode) {
|
||||||
|
return fieldPanel.keyTyped(c, keyCode);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void updateScreen() {
|
||||||
|
fieldPanel.updateScreen();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<ModernDropdown> getDropdowns() {
|
||||||
|
return fieldPanel.getDropdowns();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean handleExpandedDropdownScreenClick(int mouseX, int mouseY, int button) {
|
||||||
|
return fieldPanel.handleExpandedDropdownScreenClick(mouseX, mouseY, button);
|
||||||
|
}
|
||||||
|
|
||||||
|
// === Selection Callbacks ===
|
||||||
|
|
||||||
|
public void onSoundSelected(String soundPath) {
|
||||||
|
if (dialog != null) {
|
||||||
|
dialog.sound = soundPath;
|
||||||
|
fieldPanel.refresh();
|
||||||
|
markDirty();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void onColorSelected(int slot, int color) {
|
||||||
|
if (dialog == null) return;
|
||||||
|
if (slot == 0) dialog.color = color;
|
||||||
|
else if (slot == 1) dialog.titleColor = color;
|
||||||
|
markDirty();
|
||||||
|
// Color buttons sync from data on next draw, no refresh needed
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,238 @@
|
|||||||
|
package kamkeel.npcs.client.gui.modern.tabs;
|
||||||
|
|
||||||
|
import kamkeel.npcs.client.gui.components.ModernDropdown;
|
||||||
|
import kamkeel.npcs.client.gui.modern.DialogEditorPanel;
|
||||||
|
import net.minecraft.client.gui.FontRenderer;
|
||||||
|
import noppes.npcs.client.gui.builder.FieldDef;
|
||||||
|
import noppes.npcs.client.gui.builder.ModernFieldPanel;
|
||||||
|
import noppes.npcs.client.gui.builder.ModernFieldPanelListener;
|
||||||
|
import noppes.npcs.client.gui.util.IDialogEditorListener;
|
||||||
|
import noppes.npcs.constants.EnumOptionType;
|
||||||
|
import noppes.npcs.controllers.DialogController;
|
||||||
|
import noppes.npcs.controllers.data.Dialog;
|
||||||
|
import noppes.npcs.controllers.data.DialogOption;
|
||||||
|
|
||||||
|
import java.util.*;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Options tab for the dialog editor.
|
||||||
|
* Contains up to 6 dialog option editors rendered via ModernFieldPanel.
|
||||||
|
* Uses FieldDef sections with dynamic titles, remove buttons, and visibility predicates.
|
||||||
|
*/
|
||||||
|
public class DialogOptionsTab extends DialogEditorTab {
|
||||||
|
|
||||||
|
private static final String[] OPTION_TYPES = {"Quit", "Dialog", "Disabled", "Role", "Command"};
|
||||||
|
|
||||||
|
private ModernFieldPanel fieldPanel;
|
||||||
|
private Map<Integer, Boolean> sectionExpandState = new HashMap<>();
|
||||||
|
|
||||||
|
public DialogOptionsTab(DialogEditorPanel parent) {
|
||||||
|
super(parent);
|
||||||
|
fieldPanel = new ModernFieldPanel();
|
||||||
|
fieldPanel.setListener(new ModernFieldPanelListener() {
|
||||||
|
@Override
|
||||||
|
public void onSelectAction(String action, int slot) {
|
||||||
|
IDialogEditorListener listener = parent.getListener();
|
||||||
|
if (listener == null) return;
|
||||||
|
if ("optionDialog".equals(action)) {
|
||||||
|
listener.onOptionDialogSelectRequested(slot);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onColorSelect(int slot, int currentColor) {
|
||||||
|
IDialogEditorListener listener = parent.getListener();
|
||||||
|
if (listener != null) {
|
||||||
|
listener.onColorSelectRequested(slot, currentColor);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onFieldChanged() {
|
||||||
|
markDirty();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
private List<FieldDef> createFieldDefs() {
|
||||||
|
List<FieldDef> defs = new ArrayList<>();
|
||||||
|
|
||||||
|
for (int slot = 0; slot < 6; slot++) {
|
||||||
|
DialogOption opt = dialog.options.get(slot);
|
||||||
|
if (opt == null || opt.optionType == EnumOptionType.Disabled) continue;
|
||||||
|
|
||||||
|
final int s = slot;
|
||||||
|
boolean expanded = sectionExpandState.getOrDefault(slot, true);
|
||||||
|
|
||||||
|
defs.add(FieldDef.section("Option " + s)
|
||||||
|
.collapsed(expanded)
|
||||||
|
.titleSupplier(() -> "Option " + s + ": " + dialog.options.get(s).title)
|
||||||
|
.removeAction(() -> removeOption(s)));
|
||||||
|
|
||||||
|
defs.add(FieldDef.stringField("Title",
|
||||||
|
() -> dialog.options.get(s).title, v -> dialog.options.get(s).title = v)
|
||||||
|
.maxLength(64));
|
||||||
|
|
||||||
|
defs.add(FieldDef.row(
|
||||||
|
FieldDef.stringEnumField("Type", OPTION_TYPES,
|
||||||
|
() -> OPTION_TYPES[dialog.options.get(s).optionType.ordinal()],
|
||||||
|
v -> {
|
||||||
|
for (int i = 0; i < OPTION_TYPES.length; i++) {
|
||||||
|
if (OPTION_TYPES[i].equals(v)) {
|
||||||
|
dialog.options.get(s).optionType = EnumOptionType.values()[i];
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}),
|
||||||
|
FieldDef.colorField("Color",
|
||||||
|
() -> dialog.options.get(s).optionColor, v -> dialog.options.get(s).optionColor = v)
|
||||||
|
.slot(100 + s)
|
||||||
|
));
|
||||||
|
|
||||||
|
defs.add(FieldDef.selectField("Target",
|
||||||
|
() -> {
|
||||||
|
int did = dialog.options.get(s).dialogId;
|
||||||
|
if (did < 0) return "";
|
||||||
|
Dialog d = DialogController.Instance.dialogs.get(did);
|
||||||
|
return d != null ? "(ID: " + did + ") " + d.title : "Dialog #" + did;
|
||||||
|
})
|
||||||
|
.action("optionDialog").slot(s)
|
||||||
|
.visibleWhen(() -> dialog.options.get(s).optionType == EnumOptionType.DialogOption));
|
||||||
|
|
||||||
|
defs.add(FieldDef.stringField("Cmd",
|
||||||
|
() -> dialog.options.get(s).command, v -> dialog.options.get(s).command = v)
|
||||||
|
.maxLength(32767)
|
||||||
|
.visibleWhen(() -> dialog.options.get(s).optionType == EnumOptionType.CommandBlock));
|
||||||
|
}
|
||||||
|
|
||||||
|
if (countActiveOptions() < 6) {
|
||||||
|
defs.add(FieldDef.actionButton("+ Add Option", this::addNewOption));
|
||||||
|
}
|
||||||
|
|
||||||
|
return defs;
|
||||||
|
}
|
||||||
|
|
||||||
|
private int countActiveOptions() {
|
||||||
|
int count = 0;
|
||||||
|
for (int i = 0; i < 6; i++) {
|
||||||
|
DialogOption opt = dialog.options.get(i);
|
||||||
|
if (opt != null && opt.optionType != EnumOptionType.Disabled) count++;
|
||||||
|
}
|
||||||
|
return count;
|
||||||
|
}
|
||||||
|
|
||||||
|
private List<Integer> getActiveSlots() {
|
||||||
|
List<Integer> slots = new ArrayList<>();
|
||||||
|
for (int i = 0; i < 6; i++) {
|
||||||
|
DialogOption opt = dialog.options.get(i);
|
||||||
|
if (opt != null && opt.optionType != EnumOptionType.Disabled) slots.add(i);
|
||||||
|
}
|
||||||
|
return slots;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void saveExpandStates() {
|
||||||
|
List<Integer> activeSlots = getActiveSlots();
|
||||||
|
List<ModernFieldPanel.SectionInfo> sections = fieldPanel.getSections();
|
||||||
|
for (int i = 0; i < Math.min(activeSlots.size(), sections.size()); i++) {
|
||||||
|
sectionExpandState.put(activeSlots.get(i), sections.get(i).section.isExpanded());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void loadFromDialog(Dialog dialog) {
|
||||||
|
this.dialog = dialog;
|
||||||
|
if (dialog == null) return;
|
||||||
|
saveExpandStates();
|
||||||
|
fieldPanel.setFields(createFieldDefs());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void saveToDialog(Dialog dialog) {
|
||||||
|
// No-op: immediate binding via FieldDef closures
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int draw(int cx, int cw, int startY, int mouseX, int mouseY, FontRenderer fr) {
|
||||||
|
return fieldPanel.draw(cx, cw, startY, mouseX, mouseY, fr);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean mouseClicked(int mouseX, int mouseY, int button) {
|
||||||
|
return fieldPanel.mouseClicked(mouseX, mouseY, button);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean keyTyped(char c, int keyCode) {
|
||||||
|
return fieldPanel.keyTyped(c, keyCode);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void updateScreen() {
|
||||||
|
fieldPanel.updateScreen();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<ModernDropdown> getDropdowns() {
|
||||||
|
return fieldPanel.getDropdowns();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean handleExpandedDropdownScreenClick(int mouseX, int mouseY, int button) {
|
||||||
|
return fieldPanel.handleExpandedDropdownScreenClick(mouseX, mouseY, button);
|
||||||
|
}
|
||||||
|
|
||||||
|
// === Option Management ===
|
||||||
|
|
||||||
|
private void addNewOption() {
|
||||||
|
if (dialog == null) 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);
|
||||||
|
saveExpandStates();
|
||||||
|
fieldPanel.setFields(createFieldDefs());
|
||||||
|
markDirty();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void removeOption(int slot) {
|
||||||
|
if (dialog == null) return;
|
||||||
|
DialogOption opt = dialog.options.get(slot);
|
||||||
|
if (opt != null) {
|
||||||
|
opt.optionType = EnumOptionType.Disabled;
|
||||||
|
saveExpandStates();
|
||||||
|
sectionExpandState.remove(slot);
|
||||||
|
fieldPanel.setFields(createFieldDefs());
|
||||||
|
markDirty();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// === Selection Callbacks ===
|
||||||
|
|
||||||
|
public void onOptionDialogSelected(int optionSlot, int dialogId, String dialogName) {
|
||||||
|
if (dialog == null) return;
|
||||||
|
DialogOption opt = dialog.options.get(optionSlot);
|
||||||
|
if (opt != null) {
|
||||||
|
opt.dialogId = dialogId;
|
||||||
|
fieldPanel.refresh();
|
||||||
|
markDirty();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void onColorSelected(int slot, int color) {
|
||||||
|
if (dialog == null) return;
|
||||||
|
int optionSlot = slot - 100;
|
||||||
|
DialogOption opt = dialog.options.get(optionSlot);
|
||||||
|
if (opt != null) {
|
||||||
|
opt.optionColor = color;
|
||||||
|
markDirty();
|
||||||
|
// Color buttons sync from data on next draw
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,139 @@
|
|||||||
|
package kamkeel.npcs.client.gui.modern.tabs;
|
||||||
|
|
||||||
|
import kamkeel.npcs.client.gui.components.ModernDropdown;
|
||||||
|
import kamkeel.npcs.client.gui.modern.DialogEditorPanel;
|
||||||
|
import net.minecraft.client.gui.FontRenderer;
|
||||||
|
import noppes.npcs.client.gui.builder.FieldDef;
|
||||||
|
import noppes.npcs.client.gui.builder.ModernFieldPanel;
|
||||||
|
import noppes.npcs.client.gui.builder.ModernFieldPanelListener;
|
||||||
|
import noppes.npcs.client.gui.util.IDialogEditorListener;
|
||||||
|
import noppes.npcs.controllers.data.Dialog;
|
||||||
|
|
||||||
|
import java.util.Arrays;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Settings tab for the dialog editor.
|
||||||
|
* Contains quest, mail, and command configuration.
|
||||||
|
* Uses ModernFieldPanel for declarative field rendering.
|
||||||
|
*/
|
||||||
|
public class DialogSettingsTab extends DialogEditorTab {
|
||||||
|
|
||||||
|
private ModernFieldPanel fieldPanel;
|
||||||
|
|
||||||
|
public DialogSettingsTab(DialogEditorPanel parent) {
|
||||||
|
super(parent);
|
||||||
|
fieldPanel = new ModernFieldPanel();
|
||||||
|
fieldPanel.setListener(new ModernFieldPanelListener() {
|
||||||
|
@Override
|
||||||
|
public void onSelectAction(String action, int slot) {
|
||||||
|
IDialogEditorListener listener = parent.getListener();
|
||||||
|
if (listener == null) return;
|
||||||
|
switch (action) {
|
||||||
|
case "quest":
|
||||||
|
listener.onQuestSelectRequested(0);
|
||||||
|
break;
|
||||||
|
case "mail":
|
||||||
|
listener.onMailSetupRequested();
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onColorSelect(int slot, int currentColor) {
|
||||||
|
// No color fields in this tab
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onFieldChanged() {
|
||||||
|
markDirty();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
private List<FieldDef> createFieldDefs() {
|
||||||
|
return Arrays.asList(
|
||||||
|
// Quest section (expanded by default)
|
||||||
|
FieldDef.section("Quest").collapsed(true),
|
||||||
|
FieldDef.selectField("Quest", () -> dialog.quest >= 0 ? "Quest #" + dialog.quest : "Select...")
|
||||||
|
.action("quest").slot(0)
|
||||||
|
.clearable(() -> dialog.quest = -1),
|
||||||
|
|
||||||
|
// Mail section
|
||||||
|
FieldDef.section("Mail").collapsed(true),
|
||||||
|
FieldDef.stringField("Subject", () -> dialog.mail != null ? dialog.mail.subject : "", v -> {
|
||||||
|
if (dialog.mail != null) dialog.mail.subject = v;
|
||||||
|
}).maxLength(64).placeholder("Subject..."),
|
||||||
|
FieldDef.stringField("Sender", () -> dialog.mail != null ? dialog.mail.sender : "", v -> {
|
||||||
|
if (dialog.mail != null) dialog.mail.sender = v;
|
||||||
|
}).maxLength(32).placeholder("Sender..."),
|
||||||
|
FieldDef.row(
|
||||||
|
FieldDef.selectField("Edit...", () -> "Edit...").action("mail"),
|
||||||
|
FieldDef.selectField("Clear", () -> "Clear").onAction(() -> {
|
||||||
|
if (dialog.mail != null) {
|
||||||
|
dialog.mail.subject = "";
|
||||||
|
dialog.mail.sender = "";
|
||||||
|
}
|
||||||
|
})
|
||||||
|
),
|
||||||
|
|
||||||
|
// Command section
|
||||||
|
FieldDef.section("Command").collapsed(true),
|
||||||
|
FieldDef.textAreaField("", () -> dialog.command, v -> dialog.command = v)
|
||||||
|
.maxLength(32767).height(70)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void loadFromDialog(Dialog dialog) {
|
||||||
|
this.dialog = dialog;
|
||||||
|
if (dialog == null) return;
|
||||||
|
fieldPanel.setFields(createFieldDefs());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void saveToDialog(Dialog dialog) {
|
||||||
|
// No-op: immediate binding via FieldDef closures
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int draw(int cx, int cw, int startY, int mouseX, int mouseY, FontRenderer fr) {
|
||||||
|
return fieldPanel.draw(cx, cw, startY, mouseX, mouseY, fr);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean mouseClicked(int mouseX, int mouseY, int button) {
|
||||||
|
return fieldPanel.mouseClicked(mouseX, mouseY, button);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean keyTyped(char c, int keyCode) {
|
||||||
|
return fieldPanel.keyTyped(c, keyCode);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void updateScreen() {
|
||||||
|
fieldPanel.updateScreen();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<ModernDropdown> getDropdowns() {
|
||||||
|
return fieldPanel.getDropdowns();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean handleExpandedDropdownScreenClick(int mouseX, int mouseY, int button) {
|
||||||
|
return fieldPanel.handleExpandedDropdownScreenClick(mouseX, mouseY, button);
|
||||||
|
}
|
||||||
|
|
||||||
|
// === Selection Callbacks ===
|
||||||
|
|
||||||
|
public void onQuestSelected(int questId, String questName) {
|
||||||
|
if (dialog != null) {
|
||||||
|
dialog.quest = questId;
|
||||||
|
markDirty();
|
||||||
|
// Display syncs from getter on next draw
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,97 @@
|
|||||||
|
package kamkeel.npcs.client.gui.modern.tabs;
|
||||||
|
|
||||||
|
import kamkeel.npcs.client.gui.components.ModernDropdown;
|
||||||
|
import kamkeel.npcs.client.gui.modern.DialogEditorPanel;
|
||||||
|
import net.minecraft.client.gui.FontRenderer;
|
||||||
|
import noppes.npcs.client.gui.builder.FieldDef;
|
||||||
|
import noppes.npcs.client.gui.builder.ModernFieldPanel;
|
||||||
|
import noppes.npcs.client.gui.builder.ModernFieldPanelListener;
|
||||||
|
import noppes.npcs.controllers.data.Dialog;
|
||||||
|
|
||||||
|
import java.util.Arrays;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Text tab for the dialog editor.
|
||||||
|
* Contains title and dialog text fields.
|
||||||
|
* Uses ModernFieldPanel for declarative field rendering.
|
||||||
|
*/
|
||||||
|
public class DialogTextTab extends DialogEditorTab {
|
||||||
|
|
||||||
|
private ModernFieldPanel fieldPanel;
|
||||||
|
|
||||||
|
public DialogTextTab(DialogEditorPanel parent) {
|
||||||
|
super(parent);
|
||||||
|
fieldPanel = new ModernFieldPanel();
|
||||||
|
fieldPanel.setListener(new ModernFieldPanelListener() {
|
||||||
|
@Override
|
||||||
|
public void onSelectAction(String action, int slot) {}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onColorSelect(int slot, int currentColor) {}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onFieldChanged() {
|
||||||
|
markDirty();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
private List<FieldDef> createFieldDefs() {
|
||||||
|
return Arrays.asList(
|
||||||
|
FieldDef.stringField("Title", () -> dialog.title, v -> dialog.title = v)
|
||||||
|
.maxLength(64).placeholder("Dialog title..."),
|
||||||
|
FieldDef.textAreaField("Dialog Text", () -> dialog.text, v -> dialog.text = v)
|
||||||
|
.maxLength(2000).fillHeight().charCount()
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void loadFromDialog(Dialog dialog) {
|
||||||
|
this.dialog = dialog;
|
||||||
|
if (dialog == null) return;
|
||||||
|
fieldPanel.setFields(createFieldDefs());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void saveToDialog(Dialog dialog) {
|
||||||
|
// No-op: immediate binding via FieldDef closures
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int draw(int cx, int cw, int startY, int mouseX, int mouseY, FontRenderer fr) {
|
||||||
|
fieldPanel.setAvailableHeight(parent.getAvailableContentHeight());
|
||||||
|
return fieldPanel.draw(cx, cw, startY, mouseX, mouseY, fr);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean mouseClicked(int mouseX, int mouseY, int button) {
|
||||||
|
return fieldPanel.mouseClicked(mouseX, mouseY, button);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean keyTyped(char c, int keyCode) {
|
||||||
|
return fieldPanel.keyTyped(c, keyCode);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void updateScreen() {
|
||||||
|
fieldPanel.updateScreen();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<ModernDropdown> getDropdowns() {
|
||||||
|
return fieldPanel.getDropdowns();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean handleExpandedDropdownScreenClick(int mouseX, int mouseY, int button) {
|
||||||
|
return fieldPanel.handleExpandedDropdownScreenClick(mouseX, mouseY, button);
|
||||||
|
}
|
||||||
|
|
||||||
|
// === Accessors for parent panel ===
|
||||||
|
|
||||||
|
public String getTitle() {
|
||||||
|
return dialog != null ? dialog.title : "";
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -6,7 +6,6 @@ import net.minecraft.client.gui.GuiButton;
|
|||||||
import net.minecraft.nbt.NBTTagCompound;
|
import net.minecraft.nbt.NBTTagCompound;
|
||||||
import noppes.npcs.client.EntityUtil;
|
import noppes.npcs.client.EntityUtil;
|
||||||
import noppes.npcs.client.NoppesUtil;
|
import noppes.npcs.client.NoppesUtil;
|
||||||
import noppes.npcs.client.gui.global.GuiNPCManageDialogs;
|
|
||||||
import noppes.npcs.client.gui.player.GuiDialogInteract;
|
import noppes.npcs.client.gui.player.GuiDialogInteract;
|
||||||
import noppes.npcs.client.gui.select.GuiQuestSelection;
|
import noppes.npcs.client.gui.select.GuiQuestSelection;
|
||||||
import noppes.npcs.client.gui.select.GuiSoundSelection;
|
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.GuiNpcLabel;
|
||||||
import noppes.npcs.client.gui.util.GuiNpcTextField;
|
import noppes.npcs.client.gui.util.GuiNpcTextField;
|
||||||
import noppes.npcs.client.gui.util.GuiSelectionListener;
|
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.ISubGuiListener;
|
||||||
import noppes.npcs.client.gui.util.ITextfieldListener;
|
import noppes.npcs.client.gui.util.ITextfieldListener;
|
||||||
import noppes.npcs.client.gui.util.SubGuiInterface;
|
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 class SubGuiNpcDialog extends SubGuiInterface implements ISubGuiListener, GuiSelectionListener, ITextfieldListener {
|
||||||
public int dialogCategoryID;
|
public int dialogCategoryID;
|
||||||
public Dialog dialog;
|
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.parent = parent;
|
||||||
this.dialog = dialog;
|
this.dialog = dialog;
|
||||||
this.dialogCategoryID = catId;
|
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(16, guiLeft + 303, guiTop + 192, 50, 20, "gui.done"));
|
||||||
addButton(new GuiNpcButton(17, guiLeft + 303 - 55, guiTop + 192, 50, 20, "gui.test"));
|
addButton(new GuiNpcButton(17, guiLeft + 303 - 55, guiTop + 192, 50, 20, "gui.test"));
|
||||||
|
|
||||||
if (!parent.dialogQuestName.equals(""))
|
if (!parent.getDialogQuestName().equals(""))
|
||||||
getButton(7).setDisplayText(parent.dialogQuestName);
|
getButton(7).setDisplayText(parent.getDialogQuestName());
|
||||||
|
|
||||||
if (!dialog.mail.subject.isEmpty())
|
if (!dialog.mail.subject.isEmpty())
|
||||||
getButton(13).setDisplayText(dialog.mail.subject);
|
getButton(13).setDisplayText(dialog.mail.subject);
|
||||||
@@ -105,7 +105,7 @@ public class SubGuiNpcDialog extends SubGuiInterface implements ISubGuiListener,
|
|||||||
}
|
}
|
||||||
if (id == 8 && dialog.id >= 0) {
|
if (id == 8 && dialog.id >= 0) {
|
||||||
dialog.quest = -1;
|
dialog.quest = -1;
|
||||||
parent.dialogQuestName = "";
|
parent.setDialogQuestName("");
|
||||||
initGui();
|
initGui();
|
||||||
}
|
}
|
||||||
if (id == 9 && dialog.id >= 0) {
|
if (id == 9 && dialog.id >= 0) {
|
||||||
@@ -148,14 +148,14 @@ public class SubGuiNpcDialog extends SubGuiInterface implements ISubGuiListener,
|
|||||||
guiNpcTextField.setText("");
|
guiNpcTextField.setText("");
|
||||||
else {
|
else {
|
||||||
String name = guiNpcTextField.getText();
|
String name = guiNpcTextField.getText();
|
||||||
if (name.isEmpty() || this.parent.dialogData.containsKey(name)) {
|
if (name.isEmpty() || this.parent.getDialogData().containsKey(name)) {
|
||||||
guiNpcTextField.setText(dialog.title);
|
guiNpcTextField.setText(dialog.title);
|
||||||
} else if (dialog.id >= 0) {
|
} else if (dialog.id >= 0) {
|
||||||
String old = dialog.title;
|
String old = dialog.title;
|
||||||
this.parent.dialogData.remove(old);
|
this.parent.getDialogData().remove(old);
|
||||||
dialog.title = name;
|
dialog.title = name;
|
||||||
this.parent.dialogData.put(dialog.title, dialog.id);
|
this.parent.getDialogData().put(dialog.title, dialog.id);
|
||||||
this.parent.dialogScroll.replace(old, dialog.title);
|
this.parent.getDialogScroll().replace(old, dialog.title);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -192,7 +192,7 @@ public class SubGuiNpcDialog extends SubGuiInterface implements ISubGuiListener,
|
|||||||
@Override
|
@Override
|
||||||
public void selected(int ob, String name) {
|
public void selected(int ob, String name) {
|
||||||
dialog.quest = ob;
|
dialog.quest = ob;
|
||||||
parent.dialogQuestName = name;
|
parent.setDialogQuestName(name);
|
||||||
initGui();
|
initGui();
|
||||||
PacketClient.sendClient(new DialogSavePacket(this.dialogCategoryID, dialog.writeToNBT(new NBTTagCompound()), false));
|
PacketClient.sendClient(new DialogSavePacket(this.dialogCategoryID, dialog.writeToNBT(new NBTTagCompound()), false));
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -54,6 +54,39 @@ public class FieldDef {
|
|||||||
private FieldDef leftChild;
|
private FieldDef leftChild;
|
||||||
private FieldDef rightChild;
|
private FieldDef rightChild;
|
||||||
|
|
||||||
|
// Modern field extensions
|
||||||
|
private int maxLength = 0;
|
||||||
|
private int textAreaHeight = 80;
|
||||||
|
private String placeholder = "";
|
||||||
|
private int callbackSlot = 0;
|
||||||
|
private String callbackAction = "";
|
||||||
|
private Runnable onActionCallback;
|
||||||
|
private boolean showCharCount = false;
|
||||||
|
|
||||||
|
// Collapsible section support
|
||||||
|
private boolean collapsible = false;
|
||||||
|
private boolean defaultExpanded = true;
|
||||||
|
|
||||||
|
// Action button support
|
||||||
|
private Runnable actionRunnable;
|
||||||
|
|
||||||
|
// Section remove + dynamic title
|
||||||
|
private Runnable removeAction;
|
||||||
|
private Supplier<String> titleSupplier;
|
||||||
|
|
||||||
|
// Dynamic height for TEXT_AREA
|
||||||
|
private boolean fillRemainingHeight = false;
|
||||||
|
|
||||||
|
// Availability/Faction row support
|
||||||
|
private Supplier<Integer> conditionGetter;
|
||||||
|
private Consumer<Integer> conditionSetter;
|
||||||
|
private Supplier<Integer> stanceGetter;
|
||||||
|
private Consumer<Integer> stanceSetter;
|
||||||
|
private Supplier<Integer> idGetter;
|
||||||
|
private Consumer<Integer> idSetter;
|
||||||
|
private Supplier<String> displayNameGetter;
|
||||||
|
private String[] conditionValues;
|
||||||
|
|
||||||
private FieldDef(String label, FieldType type) {
|
private FieldDef(String label, FieldType type) {
|
||||||
this.label = label;
|
this.label = label;
|
||||||
this.type = type;
|
this.type = type;
|
||||||
@@ -148,6 +181,88 @@ public class FieldDef {
|
|||||||
return def;
|
return def;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ═══════════════════════════════════════════════════════════════════
|
||||||
|
// MODERN FIELD FACTORIES
|
||||||
|
// ═══════════════════════════════════════════════════════════════════
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 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);
|
||||||
|
def.getter = () -> getter.get();
|
||||||
|
def.setter = v -> setter.accept((String) v);
|
||||||
|
return def;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 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) {
|
||||||
|
FieldDef def = new FieldDef(label, FieldType.COLOR);
|
||||||
|
def.getter = () -> getter.get();
|
||||||
|
def.setter = v -> setter.accept((Integer) v);
|
||||||
|
return def;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* External selector field rendered as ModernSelectButton by ModernFieldPanel.
|
||||||
|
* Use .action() and .slot() to identify the callback, or .onAction() for direct callback.
|
||||||
|
*/
|
||||||
|
public static FieldDef selectField(String label, Supplier<String> displayGetter) {
|
||||||
|
FieldDef def = new FieldDef(label, FieldType.SELECT);
|
||||||
|
def.getter = () -> displayGetter.get();
|
||||||
|
return def;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Availability requirement row: condition dropdown + select button + clear button.
|
||||||
|
* Used for quest/dialog requirements with condition-based enabling.
|
||||||
|
*/
|
||||||
|
public static FieldDef availabilityRow(String label, String[] conditions,
|
||||||
|
Supplier<Integer> condGetter, Consumer<Integer> condSetter,
|
||||||
|
Supplier<Integer> idGetter, Consumer<Integer> idSetter,
|
||||||
|
Supplier<String> displayGetter) {
|
||||||
|
FieldDef def = new FieldDef(label, FieldType.AVAILABILITY_ROW);
|
||||||
|
def.conditionValues = conditions;
|
||||||
|
def.conditionGetter = condGetter;
|
||||||
|
def.conditionSetter = condSetter;
|
||||||
|
def.idGetter = idGetter;
|
||||||
|
def.idSetter = idSetter;
|
||||||
|
def.displayNameGetter = displayGetter;
|
||||||
|
return def;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Faction requirement row: condition dropdown + stance dropdown + select button + clear button.
|
||||||
|
*/
|
||||||
|
public static FieldDef factionRow(String label,
|
||||||
|
Supplier<Integer> condGetter, Consumer<Integer> condSetter,
|
||||||
|
Supplier<Integer> stanceGetter, Consumer<Integer> stanceSetter,
|
||||||
|
Supplier<Integer> idGetter, Consumer<Integer> idSetter,
|
||||||
|
Supplier<String> displayGetter) {
|
||||||
|
FieldDef def = new FieldDef(label, FieldType.FACTION_ROW);
|
||||||
|
def.conditionGetter = condGetter;
|
||||||
|
def.conditionSetter = condSetter;
|
||||||
|
def.stanceGetter = stanceGetter;
|
||||||
|
def.stanceSetter = stanceSetter;
|
||||||
|
def.idGetter = idGetter;
|
||||||
|
def.idSetter = idSetter;
|
||||||
|
def.displayNameGetter = displayGetter;
|
||||||
|
return def;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Action button field — renders as a clickable button that executes a Runnable.
|
||||||
|
* Used for "Add", "Delete", or other action triggers within a field list.
|
||||||
|
*/
|
||||||
|
public static FieldDef actionButton(String label, Runnable action) {
|
||||||
|
FieldDef def = new FieldDef(label, FieldType.ACTION_BUTTON);
|
||||||
|
def.actionRunnable = action;
|
||||||
|
return def;
|
||||||
|
}
|
||||||
|
|
||||||
// ═══════════════════════════════════════════════════════════════════
|
// ═══════════════════════════════════════════════════════════════════
|
||||||
// CONVENIENCE FACTORIES (SUB_GUI wrappers)
|
// CONVENIENCE FACTORIES (SUB_GUI wrappers)
|
||||||
// ═══════════════════════════════════════════════════════════════════
|
// ═══════════════════════════════════════════════════════════════════
|
||||||
@@ -260,6 +375,96 @@ public class FieldDef {
|
|||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public FieldDef maxLength(int max) {
|
||||||
|
this.maxLength = max;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public FieldDef placeholder(String text) {
|
||||||
|
this.placeholder = text;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public FieldDef height(int h) {
|
||||||
|
this.textAreaHeight = h;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Makes a SECTION_HEADER render as a CollapsibleSection (expanded by default).
|
||||||
|
*/
|
||||||
|
public FieldDef collapsed() {
|
||||||
|
this.collapsible = true;
|
||||||
|
this.defaultExpanded = false;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Makes a SECTION_HEADER render as a CollapsibleSection with the given expand state.
|
||||||
|
*/
|
||||||
|
public FieldDef collapsed(boolean startExpanded) {
|
||||||
|
this.collapsible = true;
|
||||||
|
this.defaultExpanded = startExpanded;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Callback action type for SELECT/COLOR fields (e.g. "quest", "sound", "dialog").
|
||||||
|
*/
|
||||||
|
public FieldDef action(String action) {
|
||||||
|
this.callbackAction = action;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Callback slot identifier for SELECT/COLOR fields.
|
||||||
|
*/
|
||||||
|
public FieldDef slot(int slot) {
|
||||||
|
this.callbackSlot = slot;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Direct action callback for SELECT fields (alternative to action/slot).
|
||||||
|
*/
|
||||||
|
public FieldDef onAction(Runnable callback) {
|
||||||
|
this.onActionCallback = callback;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Show character count below a TEXT_AREA field.
|
||||||
|
*/
|
||||||
|
public FieldDef charCount() {
|
||||||
|
this.showCharCount = true;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set dynamic title supplier for SECTION_HEADER (updated each draw).
|
||||||
|
*/
|
||||||
|
public FieldDef titleSupplier(Supplier<String> supplier) {
|
||||||
|
this.titleSupplier = supplier;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set remove action for SECTION_HEADER (adds "X" button to header).
|
||||||
|
*/
|
||||||
|
public FieldDef removeAction(Runnable action) {
|
||||||
|
this.removeAction = action;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Make TEXT_AREA fill remaining available height.
|
||||||
|
* Requires ModernFieldPanel.setAvailableHeight() to be called.
|
||||||
|
*/
|
||||||
|
public FieldDef fillHeight() {
|
||||||
|
this.fillRemainingHeight = true;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
// ═══════════════════════════════════════════════════════════════════
|
// ═══════════════════════════════════════════════════════════════════
|
||||||
// GETTERS
|
// GETTERS
|
||||||
// ═══════════════════════════════════════════════════════════════════
|
// ═══════════════════════════════════════════════════════════════════
|
||||||
@@ -308,6 +513,33 @@ public class FieldDef {
|
|||||||
public FieldDef getLeftChild() { return leftChild; }
|
public FieldDef getLeftChild() { return leftChild; }
|
||||||
public FieldDef getRightChild() { return rightChild; }
|
public FieldDef getRightChild() { return rightChild; }
|
||||||
|
|
||||||
|
// Modern field getters
|
||||||
|
public int getMaxLength() { return maxLength; }
|
||||||
|
public int getTextAreaHeight() { return textAreaHeight; }
|
||||||
|
public String getPlaceholder() { return placeholder; }
|
||||||
|
public int getCallbackSlot() { return callbackSlot; }
|
||||||
|
public String getCallbackAction() { return callbackAction; }
|
||||||
|
public Runnable getOnActionCallback() { return onActionCallback; }
|
||||||
|
public boolean showsCharCount() { return showCharCount; }
|
||||||
|
public boolean isCollapsible() { return collapsible; }
|
||||||
|
public boolean isDefaultExpanded() { return defaultExpanded; }
|
||||||
|
|
||||||
|
// Availability/Faction row getters
|
||||||
|
public Supplier<Integer> getConditionGetter() { return conditionGetter; }
|
||||||
|
public Consumer<Integer> getConditionSetter() { return conditionSetter; }
|
||||||
|
public Supplier<Integer> getStanceGetter() { return stanceGetter; }
|
||||||
|
public Consumer<Integer> getStanceSetter() { return stanceSetter; }
|
||||||
|
public Supplier<Integer> getIdGetter() { return idGetter; }
|
||||||
|
public Consumer<Integer> getIdSetter() { return idSetter; }
|
||||||
|
public Supplier<String> getDisplayNameGetter() { return displayNameGetter; }
|
||||||
|
public String[] getConditionValues() { return conditionValues; }
|
||||||
|
|
||||||
|
// Action button / section extensions
|
||||||
|
public Runnable getActionRunnable() { return actionRunnable; }
|
||||||
|
public Runnable getRemoveAction() { return removeAction; }
|
||||||
|
public Supplier<String> getTitleSupplier() { return titleSupplier; }
|
||||||
|
public boolean shouldFillHeight() { return fillRemainingHeight; }
|
||||||
|
|
||||||
// ═══════════════════════════════════════════════════════════════════
|
// ═══════════════════════════════════════════════════════════════════
|
||||||
// LIST MANIPULATION (for mod injection)
|
// LIST MANIPULATION (for mod injection)
|
||||||
// ═══════════════════════════════════════════════════════════════════
|
// ═══════════════════════════════════════════════════════════════════
|
||||||
|
|||||||
@@ -15,5 +15,11 @@ public enum FieldType {
|
|||||||
SECTION_HEADER,
|
SECTION_HEADER,
|
||||||
LABEL,
|
LABEL,
|
||||||
EFFECTS_LIST,
|
EFFECTS_LIST,
|
||||||
ROW
|
ROW,
|
||||||
|
TEXT_AREA,
|
||||||
|
COLOR,
|
||||||
|
SELECT,
|
||||||
|
AVAILABILITY_ROW,
|
||||||
|
FACTION_ROW,
|
||||||
|
ACTION_BUTTON
|
||||||
}
|
}
|
||||||
File diff suppressed because it is too large.
Load diff
@@ -0,0 +1,31 @@
|
|||||||
|
package noppes.npcs.client.gui.builder;
|
||||||
|
|
||||||
|
import cpw.mods.fml.relauncher.Side;
|
||||||
|
import cpw.mods.fml.relauncher.SideOnly;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Callback interface for ModernFieldPanel events.
|
||||||
|
* Implemented by the parent GUI to handle external selection and dirty tracking.
|
||||||
|
*/
|
||||||
|
@SideOnly(Side.CLIENT)
|
||||||
|
public interface ModernFieldPanelListener {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Called when an external selector action is requested (quest, dialog, faction, sound, mail).
|
||||||
|
* @param action The action type (e.g. "quest", "dialog", "faction", "sound", "mail")
|
||||||
|
* @param slot The slot identifier for the request
|
||||||
|
*/
|
||||||
|
void onSelectAction(String action, int slot);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Called when a color picker is requested.
|
||||||
|
* @param slot The color slot identifier
|
||||||
|
* @param currentColor The current color value
|
||||||
|
*/
|
||||||
|
void onColorSelect(int slot, int currentColor);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Called when any field value changes (for dirty tracking).
|
||||||
|
*/
|
||||||
|
void onFieldChanged();
|
||||||
|
}
|
||||||
@@ -0,0 +1,190 @@
|
|||||||
|
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.ScrollPanel;
|
||||||
|
import net.minecraft.client.Minecraft;
|
||||||
|
import net.minecraft.client.gui.FontRenderer;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Self-contained scrollable field panel that wraps {@link ScrollPanel} + {@link ModernFieldPanel}.
|
||||||
|
* <p>
|
||||||
|
* Handles scissor clipping, scroll coordinate translation, dropdown z-order,
|
||||||
|
* and text area mouse delegation automatically.
|
||||||
|
* <p>
|
||||||
|
* Usage:
|
||||||
|
* <pre>
|
||||||
|
* ScrollableFieldPanel panel = new ScrollableFieldPanel(x, y, width, height);
|
||||||
|
* panel.setFields(fieldDefs);
|
||||||
|
* panel.setListener(listener);
|
||||||
|
*
|
||||||
|
* // In draw:
|
||||||
|
* panel.draw(mouseX, mouseY);
|
||||||
|
*
|
||||||
|
* // Events:
|
||||||
|
* panel.mouseClicked(mouseX, mouseY, button);
|
||||||
|
* panel.keyTyped(c, keyCode);
|
||||||
|
* panel.mouseScrolled(delta);
|
||||||
|
* panel.mouseDragged(mouseX, mouseY);
|
||||||
|
* panel.mouseReleased(mouseX, mouseY);
|
||||||
|
* panel.updateScreen();
|
||||||
|
* </pre>
|
||||||
|
*/
|
||||||
|
@SideOnly(Side.CLIENT)
|
||||||
|
public class ScrollableFieldPanel {
|
||||||
|
|
||||||
|
protected ScrollPanel scrollPanel;
|
||||||
|
protected ModernFieldPanel fieldPanel;
|
||||||
|
|
||||||
|
// Layout
|
||||||
|
protected int x, y, width, height;
|
||||||
|
protected int padding = 4;
|
||||||
|
|
||||||
|
public ScrollableFieldPanel(int x, int y, int width, int height) {
|
||||||
|
this.x = x;
|
||||||
|
this.y = y;
|
||||||
|
this.width = width;
|
||||||
|
this.height = height;
|
||||||
|
this.scrollPanel = new ScrollPanel(x, y, width, height);
|
||||||
|
this.scrollPanel.setBackgroundColor(0); // Transparent
|
||||||
|
this.fieldPanel = new ModernFieldPanel();
|
||||||
|
}
|
||||||
|
|
||||||
|
// === Setup ===
|
||||||
|
|
||||||
|
public void setFields(List<FieldDef> fields) {
|
||||||
|
fieldPanel.setFields(fields);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setListener(ModernFieldPanelListener listener) {
|
||||||
|
fieldPanel.setListener(listener);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setBounds(int x, int y, int width, int height) {
|
||||||
|
this.x = x;
|
||||||
|
this.y = y;
|
||||||
|
this.width = width;
|
||||||
|
this.height = height;
|
||||||
|
scrollPanel.setBounds(x, y, width, height);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void resetScroll() {
|
||||||
|
scrollPanel.resetScroll();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set available height for fillHeight() text areas.
|
||||||
|
*/
|
||||||
|
public void setAvailableHeight(int height) {
|
||||||
|
fieldPanel.setAvailableHeight(height);
|
||||||
|
}
|
||||||
|
|
||||||
|
// === Drawing ===
|
||||||
|
|
||||||
|
public void draw(int mouseX, int mouseY) {
|
||||||
|
FontRenderer fr = Minecraft.getMinecraft().fontRenderer;
|
||||||
|
|
||||||
|
// Sync dropdown screen positions BEFORE scissor
|
||||||
|
updateDropdownScreenPositions();
|
||||||
|
|
||||||
|
// Begin scissor + scroll translation
|
||||||
|
scrollPanel.beginDraw();
|
||||||
|
|
||||||
|
// Draw fields
|
||||||
|
int contentX = x + padding;
|
||||||
|
int contentW = width - padding * 2 - getScrollbarWidth();
|
||||||
|
int startY = y + padding;
|
||||||
|
int contentMouseY = scrollPanel.toContentY(mouseY);
|
||||||
|
|
||||||
|
int contentHeight = fieldPanel.draw(contentX, contentW, startY, mouseX, contentMouseY, fr);
|
||||||
|
scrollPanel.setContentHeight(contentHeight + padding);
|
||||||
|
|
||||||
|
// End scissor, draw scrollbar
|
||||||
|
scrollPanel.endDraw(mouseX, mouseY);
|
||||||
|
|
||||||
|
// Draw expanded dropdowns in screen space (above scissor)
|
||||||
|
drawExpandedDropdownsScreenSpace(mouseX, mouseY);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected void updateDropdownScreenPositions() {
|
||||||
|
for (ModernDropdown dd : fieldPanel.getDropdowns()) {
|
||||||
|
int screenY = scrollPanel.toScreenY(dd.getY());
|
||||||
|
dd.setScreenPosition(dd.getX(), screenY);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
protected void drawExpandedDropdownsScreenSpace(int mouseX, int mouseY) {
|
||||||
|
for (ModernDropdown dd : fieldPanel.getDropdowns()) {
|
||||||
|
if (dd.isExpanded()) {
|
||||||
|
dd.drawOverlayScreenSpace(mouseX, mouseY);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
protected int getScrollbarWidth() {
|
||||||
|
return scrollPanel.needsScrollbar() ? 6 : 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
// === Event Handling ===
|
||||||
|
|
||||||
|
public boolean mouseClicked(int mouseX, int mouseY, int button) {
|
||||||
|
// Check expanded dropdowns in SCREEN space first - with data write-back
|
||||||
|
if (fieldPanel.handleExpandedDropdownScreenClick(mouseX, mouseY, button)) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Check scrollbar
|
||||||
|
if (scrollPanel.mouseClicked(mouseX, mouseY, button)) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Delegate to field panel with scroll-adjusted Y
|
||||||
|
int adjMouseY = scrollPanel.toContentY(mouseY);
|
||||||
|
return fieldPanel.mouseClicked(mouseX, adjMouseY, button);
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean keyTyped(char c, int keyCode) {
|
||||||
|
return fieldPanel.keyTyped(c, keyCode);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void mouseScrolled(int delta) {
|
||||||
|
scrollPanel.mouseScrolled(delta);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void mouseDragged(int mouseX, int mouseY) {
|
||||||
|
scrollPanel.mouseDragged(mouseX, mouseY);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void mouseReleased(int mouseX, int mouseY) {
|
||||||
|
scrollPanel.mouseReleased(mouseX, mouseY);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void updateScreen() {
|
||||||
|
fieldPanel.updateScreen();
|
||||||
|
}
|
||||||
|
|
||||||
|
// === Accessors ===
|
||||||
|
|
||||||
|
public ModernFieldPanel getFieldPanel() {
|
||||||
|
return fieldPanel;
|
||||||
|
}
|
||||||
|
|
||||||
|
public ScrollPanel getScrollPanel() {
|
||||||
|
return scrollPanel;
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<ModernDropdown> getDropdowns() {
|
||||||
|
return fieldPanel.getDropdowns();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void refresh() {
|
||||||
|
fieldPanel.refresh();
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isInside(int mouseX, int mouseY) {
|
||||||
|
return scrollPanel.isInside(mouseX, mouseY);
|
||||||
|
}
|
||||||
|
}
|
||||||
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.GuiNpcLabel;
|
||||||
import noppes.npcs.client.gui.util.GuiNpcTextField;
|
import noppes.npcs.client.gui.util.GuiNpcTextField;
|
||||||
import noppes.npcs.client.gui.util.ICustomScrollListener;
|
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.IGuiData;
|
||||||
import noppes.npcs.client.gui.util.IScrollData;
|
import noppes.npcs.client.gui.util.IScrollData;
|
||||||
import noppes.npcs.client.gui.util.ISubGuiListener;
|
import noppes.npcs.client.gui.util.ISubGuiListener;
|
||||||
@@ -37,7 +38,7 @@ import java.util.HashMap;
|
|||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Vector;
|
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;
|
private GuiCustomScroll catScroll;
|
||||||
public GuiCustomScroll dialogScroll;
|
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(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(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(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"));
|
this.addButton(new GuiNpcButton(33, guiLeft + 358, guiTop + 8, 58, 20, "dialog.dialogs"));
|
||||||
getButton(33).setEnabled(false);
|
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(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(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(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 != null) {
|
||||||
if (dialog.id != -1) {
|
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();
|
updateButtons();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -368,6 +383,8 @@ public class GuiNPCManageDialogs extends GuiNPCInterface2 implements IScrollData
|
|||||||
|
|
||||||
getButton(0).setEnabled(enabled && diagEnabled);
|
getButton(0).setEnabled(enabled && diagEnabled);
|
||||||
getButton(3).setEnabled(enabled && diagEnabled);
|
getButton(3).setEnabled(enabled && diagEnabled);
|
||||||
|
getButton(9).setEnabled(enabled);
|
||||||
|
getButton(8).setEnabled(enabled && diagEnabled);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -488,6 +505,19 @@ public class GuiNPCManageDialogs extends GuiNPCInterface2 implements IScrollData
|
|||||||
public void save() {
|
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
|
@Override
|
||||||
public void setData(Vector<String> list, HashMap<String, Integer> data, EnumScrollData type) {
|
public void setData(Vector<String> list, HashMap<String, Integer> data, EnumScrollData type) {
|
||||||
if (type == EnumScrollData.DIALOG_GROUP) {
|
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,219 @@
|
|||||||
|
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
|
||||||
|
* - ModernSelectButton
|
||||||
|
* - CollapsibleSection
|
||||||
|
* - ScrollPanel
|
||||||
|
*
|
||||||
|
* Components that wrap Minecraft classes (ModernButton extends GuiNpcButton)
|
||||||
|
* 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,759 @@
|
|||||||
|
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) {
|
||||||
|
// Note: We removed the hasSubGui() check here. The diagram should continue
|
||||||
|
// drawing even when a SubGui is open - the SubGui renders on top via z-order.
|
||||||
|
// Previously this caused the entire diagram to disappear when opening dialogs.
|
||||||
|
|
||||||
|
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) {
|
public void drawScreen(int mouseX, int mouseY, float partialTicks) {
|
||||||
drawTopBar();
|
drawTopBar();
|
||||||
drawPanels();
|
drawPanels();
|
||||||
|
super.drawScreen(mouseX, mouseY, partialTicks);
|
||||||
|
// Draw divider AFTER super.drawScreen() so it renders on top of GUI elements
|
||||||
if (enableDivider) {
|
if (enableDivider) {
|
||||||
drawDivider(mouseX, mouseY);
|
drawDivider(mouseX, mouseY);
|
||||||
}
|
}
|
||||||
super.drawScreen(mouseX, mouseY, partialTicks);
|
|
||||||
drawOverlay(mouseX, mouseY, partialTicks);
|
drawOverlay(mouseX, mouseY, partialTicks);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -17,7 +17,7 @@ import java.util.List;
|
|||||||
public class GuiNpcTextArea extends GuiNpcTextField {
|
public class GuiNpcTextArea extends GuiNpcTextField {
|
||||||
public boolean inMenu = true;
|
public boolean inMenu = true;
|
||||||
public boolean numbersOnly = false;
|
public boolean numbersOnly = false;
|
||||||
private int posX, posY, width, height;
|
protected int posX, posY, width, height;
|
||||||
private int cursorCounter;
|
private int cursorCounter;
|
||||||
private FontContainer font;
|
private FontContainer font;
|
||||||
private int cursorPosition = 0;
|
private int cursorPosition = 0;
|
||||||
@@ -27,6 +27,7 @@ public class GuiNpcTextArea extends GuiNpcTextField {
|
|||||||
private boolean clickVerticalBar = false;
|
private boolean clickVerticalBar = false;
|
||||||
private boolean wrapLine = true;
|
private boolean wrapLine = true;
|
||||||
private List<String> lines = new ArrayList<>();
|
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) {
|
public GuiNpcTextArea(int id, GuiScreen guiscreen, int i, int j, int k, int l, String s) {
|
||||||
super(id, guiscreen, i, j, k, l, s);
|
super(id, guiscreen, i, j, k, l, s);
|
||||||
@@ -39,6 +40,35 @@ public class GuiNpcTextArea extends GuiNpcTextField {
|
|||||||
this.setText(s);
|
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;
|
||||||
|
this.width = w;
|
||||||
|
this.height = h;
|
||||||
|
this.xPosition = x;
|
||||||
|
this.yPosition = y;
|
||||||
|
syncGuiTextFieldBounds(w, h);
|
||||||
|
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
|
@Override
|
||||||
public void setText(String text) {
|
public void setText(String text) {
|
||||||
super.setText(text);
|
super.setText(text);
|
||||||
@@ -69,10 +99,82 @@ public class GuiNpcTextArea extends GuiNpcTextField {
|
|||||||
public boolean textboxKeyTyped(char c, int i) {
|
public boolean textboxKeyTyped(char c, int i) {
|
||||||
if (isFocused() && canEdit) {
|
if (isFocused() && canEdit) {
|
||||||
String originalText = getText();
|
String originalText = getText();
|
||||||
this.setText(originalText);
|
|
||||||
|
// Handle Ctrl+A (Select All) - char code 1
|
||||||
|
if (GuiScreen.isCtrlKeyDown() && (i == Keyboard.KEY_A || c == 1)) {
|
||||||
|
cursorPosition = originalText.length();
|
||||||
|
setSelectionPos(0);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Handle Ctrl+C (Copy) - char code 3
|
||||||
|
if (GuiScreen.isCtrlKeyDown() && (i == Keyboard.KEY_C || c == 3)) {
|
||||||
|
String selected = getSelectedText();
|
||||||
|
if (selected != null && !selected.isEmpty()) {
|
||||||
|
GuiScreen.setClipboardString(selected);
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Handle Ctrl+V (Paste) - char code 22
|
||||||
|
if (GuiScreen.isCtrlKeyDown() && (i == Keyboard.KEY_V || c == 22)) {
|
||||||
|
String clipboard = GuiScreen.getClipboardString();
|
||||||
|
if (clipboard != null && !clipboard.isEmpty()) {
|
||||||
|
// Delete selected text first if any
|
||||||
|
String selected = getSelectedText();
|
||||||
|
int selStart = getSelectionEnd();
|
||||||
|
int selEnd = cursorPosition;
|
||||||
|
if (selStart > selEnd) {
|
||||||
|
int tmp = selStart;
|
||||||
|
selStart = selEnd;
|
||||||
|
selEnd = tmp;
|
||||||
|
}
|
||||||
|
if (selected != null && !selected.isEmpty()) {
|
||||||
|
String before = originalText.substring(0, selStart);
|
||||||
|
String after = originalText.substring(selEnd);
|
||||||
|
this.setText(before + clipboard + after);
|
||||||
|
cursorPosition = selStart + clipboard.length();
|
||||||
|
} else {
|
||||||
|
String before = originalText.substring(0, cursorPosition);
|
||||||
|
String after = originalText.substring(cursorPosition);
|
||||||
|
this.setText(before + clipboard + after);
|
||||||
|
cursorPosition += clipboard.length();
|
||||||
|
}
|
||||||
|
updateLineList();
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Handle Ctrl+X (Cut) - char code 24
|
||||||
|
if (GuiScreen.isCtrlKeyDown() && (i == Keyboard.KEY_X || c == 24)) {
|
||||||
|
String selected = getSelectedText();
|
||||||
|
if (selected != null && !selected.isEmpty()) {
|
||||||
|
GuiScreen.setClipboardString(selected);
|
||||||
|
// Delete selected text
|
||||||
|
int selStart = getSelectionEnd();
|
||||||
|
int selEnd = cursorPosition;
|
||||||
|
if (selStart > selEnd) {
|
||||||
|
int tmp = selStart;
|
||||||
|
selStart = selEnd;
|
||||||
|
selEnd = tmp;
|
||||||
|
}
|
||||||
|
String before = originalText.substring(0, selStart);
|
||||||
|
String after = originalText.substring(selEnd);
|
||||||
|
this.setText(before + after);
|
||||||
|
cursorPosition = selStart;
|
||||||
|
updateLineList();
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Handle newline specially - insert and return immediately
|
||||||
if (c == '\r' || c == '\n') {
|
if (c == '\r' || c == '\n') {
|
||||||
this.setText(originalText.substring(0, cursorPosition) + c + originalText.substring(cursorPosition));
|
this.setText(originalText.substring(0, cursorPosition) + c + originalText.substring(cursorPosition));
|
||||||
|
cursorPosition++;
|
||||||
|
updateLineList();
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
// For all other characters, let parent handle
|
||||||
this.setCursorPositionZero();
|
this.setCursorPositionZero();
|
||||||
this.moveCursorBy(cursorPosition);
|
this.moveCursorBy(cursorPosition);
|
||||||
boolean bo = super.textboxKeyTyped(c, i);
|
boolean bo = super.textboxKeyTyped(c, i);
|
||||||
@@ -85,7 +187,6 @@ public class GuiNpcTextArea extends GuiNpcTextField {
|
|||||||
if (i == Keyboard.KEY_RIGHT && cursorPosition < newText.length())
|
if (i == Keyboard.KEY_RIGHT && cursorPosition < newText.length())
|
||||||
cursorPosition++;
|
cursorPosition++;
|
||||||
return bo;
|
return bo;
|
||||||
|
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@@ -322,4 +423,25 @@ public class GuiNpcTextArea extends GuiNpcTextField {
|
|||||||
}
|
}
|
||||||
drawTexturedModalRect(x, y, width, 11, 5, 1);
|
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);
|
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() {
|
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) {
|
public void drawTextBox(int mousX, int mousY) {
|
||||||
drawTextBox();
|
drawTextBox();
|
||||||
}
|
}
|
||||||
@@ -361,4 +385,13 @@ public class GuiNpcTextField extends GuiTextField {
|
|||||||
GL11.glEnable(GL11.GL_ALPHA_TEST);
|
GL11.glEnable(GL11.GL_ALPHA_TEST);
|
||||||
GL11.glEnable(GL11.GL_TEXTURE_2D);
|
GL11.glEnable(GL11.GL_TEXTURE_2D);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sync GuiTextField.width/height for subclasses that shadow these fields.
|
||||||
|
* Since GuiNpcTextField does NOT shadow width/height, this.width writes to GuiTextField.width.
|
||||||
|
*/
|
||||||
|
protected void syncGuiTextFieldBounds(int w, int h) {
|
||||||
|
this.width = w;
|
||||||
|
this.height = h;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -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);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,10 +1,21 @@
|
|||||||
package noppes.npcs.client.gui.util;
|
package noppes.npcs.client.gui.util;
|
||||||
|
|
||||||
|
import net.minecraft.client.gui.Gui;
|
||||||
import net.minecraft.client.gui.GuiScreen;
|
import net.minecraft.client.gui.GuiScreen;
|
||||||
|
|
||||||
public class SubGuiInterface extends GuiNPCInterface {
|
public class SubGuiInterface extends GuiNPCInterface {
|
||||||
public GuiScreen parent;
|
public GuiScreen parent;
|
||||||
|
|
||||||
|
// === Modern Style Option ===
|
||||||
|
protected boolean useModernStyle = false;
|
||||||
|
protected int modernOverlayColor = 0x80000000;
|
||||||
|
protected int modernPanelBg = 0xFF1E1E2E;
|
||||||
|
protected int modernPanelBorder = 0xFF4488CC;
|
||||||
|
protected int modernHeaderBg = 0xFF2A2A3A;
|
||||||
|
protected int modernHeaderText = 0xFFFFFF;
|
||||||
|
protected String modernHeaderTitle = null;
|
||||||
|
protected int modernHeaderHeight = 20;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void save() {
|
public void save() {
|
||||||
|
|
||||||
@@ -34,6 +45,105 @@ public class SubGuiInterface extends GuiNPCInterface {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void drawScreen(int i, int j, float f) {
|
public void drawScreen(int i, int j, float f) {
|
||||||
super.drawScreen(i, j, f);
|
if (useModernStyle) {
|
||||||
|
drawModernStyle(i, j, f);
|
||||||
|
} else {
|
||||||
|
super.drawScreen(i, j, f);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Draw with modern styling - dark overlay, modern panel, accent border.
|
||||||
|
*/
|
||||||
|
protected void drawModernStyle(int mouseX, int mouseY, float partialTicks) {
|
||||||
|
// Draw semi-transparent overlay behind panel
|
||||||
|
int margin = 20;
|
||||||
|
int overlayLeft = Math.max(0, guiLeft - margin);
|
||||||
|
int overlayTop = Math.max(0, guiTop - margin);
|
||||||
|
int overlayRight = Math.min(width, guiLeft + xSize + margin);
|
||||||
|
int overlayBottom = Math.min(height, guiTop + ySize + margin);
|
||||||
|
Gui.drawRect(overlayLeft, overlayTop, overlayRight, overlayBottom, modernOverlayColor);
|
||||||
|
|
||||||
|
// Draw panel border
|
||||||
|
Gui.drawRect(guiLeft - 1, guiTop - 1, guiLeft + xSize + 1, guiTop + ySize + 1, modernPanelBorder);
|
||||||
|
|
||||||
|
// Draw panel background
|
||||||
|
Gui.drawRect(guiLeft, guiTop, guiLeft + xSize, guiTop + ySize, modernPanelBg);
|
||||||
|
|
||||||
|
// Draw header if set
|
||||||
|
if (modernHeaderTitle != null) {
|
||||||
|
Gui.drawRect(guiLeft, guiTop, guiLeft + xSize, guiTop + modernHeaderHeight, modernHeaderBg);
|
||||||
|
int textW = fontRendererObj.getStringWidth(modernHeaderTitle);
|
||||||
|
int textX = guiLeft + (xSize - textW) / 2;
|
||||||
|
int textY = guiTop + (modernHeaderHeight - fontRendererObj.FONT_HEIGHT) / 2;
|
||||||
|
fontRendererObj.drawString(modernHeaderTitle, textX, textY, modernHeaderText);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Draw buttons, labels, textfields, scrolls from parent
|
||||||
|
for (Object obj : buttonList) {
|
||||||
|
if (obj instanceof net.minecraft.client.gui.GuiButton) {
|
||||||
|
((net.minecraft.client.gui.GuiButton) obj).drawButton(mc, mouseX, mouseY);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
for (GuiNpcLabel label : labels.values()) {
|
||||||
|
label.drawLabel(this, fontRendererObj);
|
||||||
|
}
|
||||||
|
for (GuiNpcTextField tf : textfields.values()) {
|
||||||
|
tf.drawTextBox(mouseX, mouseY);
|
||||||
|
}
|
||||||
|
for (GuiCustomScroll scroll : scrolls.values()) {
|
||||||
|
scroll.drawScreen(mouseX, mouseY, 0, scroll.isMouseOver(mouseX, mouseY) ? org.lwjgl.input.Mouse.getDWheel() : 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Allow subclasses to draw custom content
|
||||||
|
drawModernContent(mouseX, mouseY, partialTicks);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Override to draw custom content in modern style.
|
||||||
|
*/
|
||||||
|
protected void drawModernContent(int mouseX, int mouseY, float partialTicks) {
|
||||||
|
// Override in subclasses
|
||||||
|
}
|
||||||
|
|
||||||
|
// === Modern Style Configuration ===
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Enable modern styling for this SubGui.
|
||||||
|
*/
|
||||||
|
public void setUseModernStyle(boolean modern) {
|
||||||
|
this.useModernStyle = modern;
|
||||||
|
if (modern) {
|
||||||
|
drawDefaultBackground = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set the header title for modern style. Pass null to disable header.
|
||||||
|
*/
|
||||||
|
public void setModernHeaderTitle(String title) {
|
||||||
|
this.modernHeaderTitle = title;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set panel colors for modern style.
|
||||||
|
*/
|
||||||
|
public void setModernPanelColors(int background, int border) {
|
||||||
|
this.modernPanelBg = background;
|
||||||
|
this.modernPanelBorder = border;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get content area Y start (after header if present).
|
||||||
|
*/
|
||||||
|
protected int getModernContentY() {
|
||||||
|
return guiTop + (modernHeaderTitle != null ? modernHeaderHeight : 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get content area height (excluding header if present).
|
||||||
|
*/
|
||||||
|
protected int getModernContentHeight() {
|
||||||
|
return ySize - (modernHeaderTitle != null ? modernHeaderHeight : 0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -70,6 +70,7 @@ gui.none=None
|
|||||||
gui.time=Time
|
gui.time=Time
|
||||||
gui.title=Title
|
gui.title=Title
|
||||||
gui.categories=Categories
|
gui.categories=Categories
|
||||||
|
gui.back=Back
|
||||||
gui.close=Close
|
gui.close=Close
|
||||||
gui.disabled=Disabled
|
gui.disabled=Disabled
|
||||||
gui.increase=Increase
|
gui.increase=Increase
|
||||||
@@ -119,6 +120,8 @@ gui.sync=Sync
|
|||||||
gui.range=Range
|
gui.range=Range
|
||||||
gui.partly=Partially
|
gui.partly=Partially
|
||||||
gui.copy=Copy
|
gui.copy=Copy
|
||||||
|
gui.graph=Graph
|
||||||
|
gui.graphone=Solo
|
||||||
gui.clear=Clear
|
gui.clear=Clear
|
||||||
gui.builtin=Built-in
|
gui.builtin=Built-in
|
||||||
gui.custom=Custom
|
gui.custom=Custom
|
||||||
|
|||||||
Reference in new issue
Block a user