Added modifyVisibility to FieldDef

AbilityGuard tweaks
This commit is contained in:
Vidal committed 2026-02-03 07:45:02 -03:00
1 parent fd85215592
commit c5822023a0
4 files changed
+42 -18

No files matched your search

@@ -9,6 +9,7 @@ import noppes.npcs.client.gui.select.GuiAnimationSelection;
import noppes.npcs.client.gui.select.GuiSoundSelection;
import noppes.npcs.client.gui.util.SubGuiInterface;
import java.util.List;
import java.util.function.BooleanSupplier;
import java.util.function.Consumer;
import java.util.function.Supplier;
@@ -329,7 +330,7 @@ public class FieldDef {
* @param newField The field to insert
* @return true if the target was found and the field was inserted
*/
public static boolean insertAfter(java.util.List<FieldDef> fields, String targetLabel, FieldDef newField) {
public static boolean insertAfter(List<FieldDef> fields, String targetLabel, FieldDef newField) {
for (int i = 0; i < fields.size(); i++) {
if (matchesLabel(fields.get(i), targetLabel)) {
fields.add(i + 1, newField);
@@ -339,6 +340,25 @@ public class FieldDef {
return false;
}
/**
* Modify the visibility condition of a field.
* Searches top-level labels and ROW children.
*
* @param fields The field list to modify
* @param targetLabel The label of the field to modify
* @param condition The condition to replace
* @return true if the target was found and the condition was modified
*/
public static boolean modifyVisibility(List<FieldDef> fields, String targetLabel, BooleanSupplier condition) {
for (FieldDef field : fields) {
if (matchesLabel(field, targetLabel)) {
field.visibleWhen(condition);
return true;
}
}
return false;
}
private static boolean matchesLabel(FieldDef def, String targetLabel) {
if (targetLabel.equals(def.label)) return true;
if (def.type == FieldType.ROW) {