diff options
Diffstat (limited to 'NET/worlds/scape/EnumPropertyEditor.java')
| -rw-r--r-- | NET/worlds/scape/EnumPropertyEditor.java | 47 |
1 files changed, 47 insertions, 0 deletions
diff --git a/NET/worlds/scape/EnumPropertyEditor.java b/NET/worlds/scape/EnumPropertyEditor.java new file mode 100644 index 0000000..07a363a --- /dev/null +++ b/NET/worlds/scape/EnumPropertyEditor.java @@ -0,0 +1,47 @@ +package NET.worlds.scape; + +import NET.worlds.console.PolledDialog; + +public class EnumPropertyEditor extends PropEditor { + private String[] choices; + private int[] numbers; + + private EnumPropertyEditor(Property property, String[] names, int[] values) { + super(property); + + assert names != null; + + assert values != null; + + int len = Math.max(names.length, values.length); + + assert len > 1; + + this.choices = new String[len]; + this.numbers = new int[len]; + + for (int i = 0; i < len; i++) { + if (i < names.length) { + this.choices[i] = names[i]; + } else { + this.choices[i] = names[names.length - 1] + i; + } + + if (i < values.length) { + this.numbers[i] = values[i]; + } else { + this.numbers[i] = values[values.length - 1] + i - values.length; + } + } + } + + @Override + public PolledDialog edit(EditTile parent, String title) { + return new EnumFieldEditorDialog(parent, title, this.property, this.choices, this.numbers); + } + + public static Property make(Property property, String[] names, int[] values) { + property.setPropertyType(5); + return property.setEditor(new EnumPropertyEditor(property, names, values)); + } +} |