mirror of
https://github.com/KAMKEEL/CustomNPC-Plus.git
synced 2026-11-12 17:47:32 +00:00
Better Texture Browsing for Ability Icons
This commit is contained in:
1 parent
e57fab9160
commit
27ea836f71
4 files changed
+44
-14
No files matched your search
@@ -968,7 +968,7 @@ public abstract class Ability implements IAbility, IAbilityAction {
|
||||
java.util.function.BooleanSupplier visible) {
|
||||
String sectionLabel = StatCollector.translateToLocal("ability.icon.layer") + " " + (layerIndex + 1);
|
||||
defs.add(FieldDef.section(sectionLabel).tab("Effects").visibleWhen(visible));
|
||||
defs.add(FieldDef.stringField("gui.texture",
|
||||
defs.add(FieldDef.textureSubGui("gui.texture",
|
||||
() -> icon.getLayer(layerIndex).texture,
|
||||
t -> icon.setLayerTexture(layerIndex, t))
|
||||
.tab("Effects").visibleWhen(visible));
|
||||
|
||||
@@ -177,17 +177,15 @@ public class FieldDef {
|
||||
}
|
||||
|
||||
public static FieldDef textureSubGui(String label, Supplier<String> getter, Consumer<String> setter) {
|
||||
return subGuiField(label,
|
||||
() -> new GuiTexturePathSelection(getter.get()),
|
||||
gui -> {
|
||||
GuiTexturePathSelection t = (GuiTexturePathSelection) gui;
|
||||
if (t.selectedResource != null) setter.accept(t.selectedResource.toString());
|
||||
})
|
||||
.buttonLabel(() -> {
|
||||
String s = getter.get();
|
||||
return s == null || s.isEmpty() ? "gui.none" : s;
|
||||
})
|
||||
.clearable(() -> setter.accept(""));
|
||||
FieldDef def = new FieldDef(label, FieldType.STRING_BROWSE);
|
||||
def.getter = () -> getter.get();
|
||||
def.setter = v -> setter.accept(v != null ? v.toString() : "");
|
||||
def.subGuiFactory = () -> new GuiTexturePathSelection(getter.get());
|
||||
def.subGuiResultHandler = gui -> {
|
||||
GuiTexturePathSelection t = (GuiTexturePathSelection) gui;
|
||||
if (t.selectedResource != null) setter.accept(t.selectedResource.toString());
|
||||
};
|
||||
return def;
|
||||
}
|
||||
|
||||
public static FieldDef animSubGui(String label,
|
||||
|
||||
@@ -17,5 +17,6 @@ public enum FieldType {
|
||||
EFFECTS_LIST,
|
||||
CUSTOM_EFFECTS_LIST,
|
||||
EFFECT_ACTIONS_LIST,
|
||||
ROW
|
||||
ROW,
|
||||
STRING_BROWSE
|
||||
}
|
||||
@@ -334,6 +334,25 @@ public class GuiFieldBuilder {
|
||||
clearId++;
|
||||
break;
|
||||
}
|
||||
case STRING_BROWSE: {
|
||||
// Text field for manual input (URLs, paths) + browse button
|
||||
int btnW = 20;
|
||||
int tfW = fieldW - btnW - 2;
|
||||
String sVal = def.getValue() != null ? def.getValue().toString() : "";
|
||||
GuiNpcTextField tf = new GuiNpcTextField(widgetId, parent, fontRenderer, fieldX, y, tfW, 20, sVal);
|
||||
if (!def.isEnabled()) tf.setEnabled(false);
|
||||
if (hover != null) tf.setHoverText(hover);
|
||||
sw.addTextField(tf);
|
||||
textFieldMap.put(widgetId, def);
|
||||
widgetId++;
|
||||
// Browse button
|
||||
GuiNpcButton browseBtn = new GuiNpcButton(clearId, fieldX + tfW + 2, y, btnW, 20, "...");
|
||||
if (!def.isEnabled()) browseBtn.setEnabled(false);
|
||||
sw.addButton(browseBtn);
|
||||
buttonFieldMap.put(clearId, def);
|
||||
clearId++;
|
||||
break;
|
||||
}
|
||||
default:
|
||||
// Unknown type — skip, incrementing IDs to stay in sync
|
||||
widgetId++;
|
||||
@@ -349,7 +368,7 @@ public class GuiFieldBuilder {
|
||||
int fieldX = colLLabel + labelW + labelPadding;
|
||||
// Available width before the scrollbar
|
||||
int maxW = contentRight - fieldX - 15;
|
||||
if (def.getType() == FieldType.SUB_GUI && maxW > 0) {
|
||||
if ((def.getType() == FieldType.SUB_GUI || def.getType() == FieldType.STRING_BROWSE) && maxW > 0) {
|
||||
// SUB_GUI fields fill all available width up to the scrollbar
|
||||
fieldW = maxW;
|
||||
} else if (maxW > 0 && fieldW > maxW) {
|
||||
@@ -374,6 +393,8 @@ public class GuiFieldBuilder {
|
||||
return 120;
|
||||
case SUB_GUI:
|
||||
return def.hasClearAction() ? 175 : 200;
|
||||
case STRING_BROWSE:
|
||||
return 200;
|
||||
default:
|
||||
return 80;
|
||||
}
|
||||
@@ -434,6 +455,15 @@ public class GuiFieldBuilder {
|
||||
});
|
||||
}
|
||||
return true;
|
||||
case STRING_BROWSE:
|
||||
if (def.getSubGuiFactory() != null) {
|
||||
parent.setSubGuiWithResult(def.getSubGuiFactory().get(), sub -> {
|
||||
if (def.getSubGuiResultHandler() != null) {
|
||||
def.getSubGuiResultHandler().accept(sub);
|
||||
}
|
||||
});
|
||||
}
|
||||
return true;
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
@@ -473,6 +503,7 @@ public class GuiFieldBuilder {
|
||||
}
|
||||
return false;
|
||||
case STRING:
|
||||
case STRING_BROWSE:
|
||||
String newVal = field.getText();
|
||||
Object old = def.getValue();
|
||||
String oldVal = old != null ? old.toString() : "";
|
||||
|
||||
Reference in new issue
Block a user