diff --git a/README.md b/README.md index 11a8286..f32ed57 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,7 @@ # Stellaris Modding Kit (WIP) General Purpose Mod Development Tool Kit for Stellaris -#### Latest Version: v0.1.14-alpha +#### Latest Version: v0.2.0-alpha ## Description This modding kit, or "Stellaris Development Kit (SDK)" is designed to: diff --git a/src/StellarisDK/FileClasses/Agenda.java b/src/StellarisDK/FileClasses/Agenda.java index c30076b..c1f0ae0 100644 --- a/src/StellarisDK/FileClasses/Agenda.java +++ b/src/StellarisDK/FileClasses/Agenda.java @@ -1,15 +1,19 @@ package StellarisDK.FileClasses; +import StellarisDK.FileClasses.Helper.DataEntry; import StellarisDK.GUI.AgendaUI; import javafx.scene.control.TreeItem; public class Agenda extends GenericData { - private String[] requiredSet = {"weight_modifier", "modifier"}; + private DataEntry[] requiredSet = { + new DataEntry("weight_modifier", false, false), + new DataEntry("modifier", false, false) + }; public Agenda() { super(); - this.type = "agenda"; + this.type = "new_agenda"; ui = new AgendaUI(this); } @@ -19,10 +23,14 @@ public Agenda(String input, String type) { } @Override - public TreeItem getRequiredTreeSet(){ - TreeItem root = new TreeItem<>("agenda"); - for(String set : requiredSet){ - root.getChildren().addAll(new TreeItem<>(set)); + public TreeItem getRequiredTreeSet() { + TreeItem root = new TreeItem<>(new DataEntry(type, true, false)); + for (DataEntry entry : requiredSet) { + TreeItem temp = new TreeItem<>(entry); + if(!entry.isSingleEntry()){ + temp.getChildren().add(new TreeItem<>("click_to_edit")); + } + root.getChildren().add(temp); } return root; } @@ -31,4 +39,4 @@ public TreeItem getRequiredTreeSet(){ public GenericData createNew() { return new Agenda(); } -} +} \ No newline at end of file diff --git a/src/StellarisDK/FileClasses/AmbientObject.java b/src/StellarisDK/FileClasses/AmbientObject.java index 04b6e07..ef6f5e2 100644 --- a/src/StellarisDK/FileClasses/AmbientObject.java +++ b/src/StellarisDK/FileClasses/AmbientObject.java @@ -24,6 +24,6 @@ public GenericData createNew() { @Override public TreeItem getRequiredTreeSet() { - return null; + return new TreeItem<>(type); } } diff --git a/src/StellarisDK/FileClasses/Anomaly/Anomaly.java b/src/StellarisDK/FileClasses/Anomaly/Anomaly.java index 0a9705f..058b2df 100644 --- a/src/StellarisDK/FileClasses/Anomaly/Anomaly.java +++ b/src/StellarisDK/FileClasses/Anomaly/Anomaly.java @@ -1,11 +1,20 @@ package StellarisDK.FileClasses.Anomaly; import StellarisDK.FileClasses.GenericData; +import StellarisDK.FileClasses.Helper.DataEntry; +import StellarisDK.FileClasses.Helper.VPair; +import StellarisDK.FileClasses.Helper.ValueTriplet; import StellarisDK.GUI.AnomalyUI; import javafx.scene.control.TreeItem; public class Anomaly extends GenericData { + private DataEntry[] requiredSet = { + new DataEntry(new ValueTriplet<>("event", new VPair<>("=", "..."), 0), true, true), + new DataEntry(new ValueTriplet<>("category", new VPair<>("=", "..."), 0), true, true), + new DataEntry("potential", false, false) + }; + public Anomaly() { super(); this.type = "anomaly"; @@ -25,6 +34,10 @@ public GenericData createNew() { @Override public TreeItem getRequiredTreeSet() { - return null; + TreeItem root = new TreeItem<>(new DataEntry(type, false, false)); + for (DataEntry entry : requiredSet) { + root.getChildren().add(entry.toNestedTree()); + } + return root; } } diff --git a/src/StellarisDK/FileClasses/Anomaly/AnomalyCategory.java b/src/StellarisDK/FileClasses/Anomaly/AnomalyCategory.java index bb83dee..2ceb5b6 100644 --- a/src/StellarisDK/FileClasses/Anomaly/AnomalyCategory.java +++ b/src/StellarisDK/FileClasses/Anomaly/AnomalyCategory.java @@ -5,6 +5,7 @@ import javafx.scene.control.TreeItem; public class AnomalyCategory extends GenericData { + public AnomalyCategory() { super(); this.type = "anomaly_category"; diff --git a/src/StellarisDK/FileClasses/Army.java b/src/StellarisDK/FileClasses/Army.java new file mode 100644 index 0000000..f8543d6 --- /dev/null +++ b/src/StellarisDK/FileClasses/Army.java @@ -0,0 +1,28 @@ +package StellarisDK.FileClasses; + +import StellarisDK.GUI.ArmyUI; +import javafx.scene.control.TreeItem; + +public class Army extends GenericData { + + public Army() { + super(); + this.type = "army"; + ui = new ArmyUI(this); + } + + public Army(String input, String type) { + super(input, type); + ui = new ArmyUI(this); + } + + @Override + public GenericData createNew() { + return new Army(); + } + + @Override + public TreeItem getRequiredTreeSet() { + return null; + } +} diff --git a/src/StellarisDK/FileClasses/DataParser.java b/src/StellarisDK/FileClasses/DataParser.java index 5313785..ff29324 100644 --- a/src/StellarisDK/FileClasses/DataParser.java +++ b/src/StellarisDK/FileClasses/DataParser.java @@ -79,34 +79,111 @@ public static ArrayList parseAll(File file) throws IOException { obj.find(); String tabby = obj.group(2).replaceAll(" {4}", "\t"); GenericData gData; - switch (obj.group(1)) { - case "agenda": + String search = file.getParent().split("\\\\")[file.getParent().split("\\\\").length-1]; + switch (search) { + case "agendas": gData = new Agenda(tabby, obj.group(1)); break; - case "country_event": - gData = new Event(tabby); - break; - case "ambient_object": + case "ambient_objects": gData = new AmbientObject(tabby); break; - case "anomaly": - gData = new Anomaly(tabby); + case "anomalies": + if(obj.group(1).equals("anomaly")){ + gData = new Anomaly(tabby); + }else{ + gData = new AnomalyCategory(tabby); + } + break; + case "armies": + gData = new Army(tabby, obj.group(1)); break; - case "anomaly_category": - gData = new AnomalyCategory(tabby); + case "ascension_perks": + gData = new Tradition(tabby, obj.group(1), false); + break; + case "attitudes": + case "bombardment_stances": + case "buildable_pops": + case "building tags": + case "buildings": + case "colors": + gData = new Component(tabby, obj.group(1)); break; - case "component_set": + case "component_sets": gData = new CompSet(tabby); break; - case "utility_component_template": - gData = new Component(tabby, 0); + case "component_templates": + gData = new Component(tabby, obj.group(1)); + break; + case "country_types": + case "defines": + case "deposits": + case "diplo_phrases": + case "edicts": + case "event_chains": + case "fallen_empires": + case "game_rules": + case "global_ship_designs": + case "governments": + case "authorities": + case "civics": + case "graphical_culture": + case "mandates": + case "map_modes": + case "megastructures": + case "name_lists": + case "notification_modifiers": + case "observation_station_missions": + case "on_actions": + case "opinion_modifiers": + case "personalities": + case "planet_classes": + case "planet_modifiers": + case "policies": + case "pop_faction_types": + case "precursor_civilizations": + case "random_names": + case "base": + case "scripted_effects": + case "scripted_loc": + case "scripted_triggers": + case "scripted_variables": + case "section_templates": + case "sector_settings": + case "sector_types": + case "ship_behaviors": + case "ship_sizes": + case "solar_system_initializers": + case "special_projects": + case "species_archetypes": + case "species_classes": + case "species_names": + case "species_rights": + case "star_classes": + case "starbase_buildings": + case "starbase_levels": + case "starbase_modules": + case "starbase_types": + case "start_screen_messages": + case "static_modifiers": + case "strategic_resources": + case "subjects": + case "system_types": + case "technology": + case "category": + case "tier": + case "terraform": + case "tile_blockers": + case "tradition_categories": + gData = new Component(tabby, obj.group(1)); break; - case "weapon_component_template": - gData = new Component(tabby, 1); + case "traditions": + gData = new Tradition(tabby, obj.group(1), true); break; - case "strike_craft_component_template": - gData = new Component(tabby, 2); + case "traits": + case "events": + gData = new Event(tabby, obj.group(1)); break; + case "localisation": default: gData = new Component(tabby, obj.group(1)); } diff --git a/src/StellarisDK/FileClasses/Event.java b/src/StellarisDK/FileClasses/Event.java index 60d25f2..949b634 100644 --- a/src/StellarisDK/FileClasses/Event.java +++ b/src/StellarisDK/FileClasses/Event.java @@ -19,6 +19,11 @@ public Event(String input) { ui = new EventUI(this); } + public Event(String input, String type) { + super(input, type); + ui = new EventUI(this); + } + @Override public GenericData createNew() { return new Event(); diff --git a/src/StellarisDK/FileClasses/GenericData.java b/src/StellarisDK/FileClasses/GenericData.java index 8e511fc..8d9a74b 100644 --- a/src/StellarisDK/FileClasses/GenericData.java +++ b/src/StellarisDK/FileClasses/GenericData.java @@ -101,11 +101,11 @@ public void setData(DataMap data) { this.data = data; } - public void setType(String type){ + public void setType(String type) { this.type = type; } - public int getSize(){ + public int getSize() { return data.getFullSize(); } @@ -191,40 +191,44 @@ public TreeItem toTreeItem() { public Object load(String input) { int size = 0; - DataMap> data = new DataMap<>(); + DataMap> data = new DataMap<>(); Matcher matcher; matcher = DataPattern.newCombine.matcher(input); while (matcher.find()) { - ArrayList temp; + PairArrayList temp; if (matcher.group(5) != null) { if (matcher.group(7).contains("{")) { ValueTriplet dat; + DataEntry entry; Matcher color = DataPattern.color.matcher(matcher.group(7)); if (color.find()) { try { dat = new ValueTriplet<>(matcher.group(6).trim(), new StellarisColor(color.group(1).trim(), color.group(2).trim(), color.group(3).trim(), color.group(4).trim(), color.group(5).trim()), size++); + entry = new DataEntry(dat, true, false); } catch (NullPointerException e) { dat = new ValueTriplet<>(matcher.group(6).trim(), new StellarisColor(color.group(1).trim(), color.group(2).trim(), color.group(3).trim(), color.group(4).trim()), size++); + entry = new DataEntry(dat, true, true); } } else { dat = new ValueTriplet<>(matcher.group(6).trim(), sLrecursion(matcher.group(7).trim()), size++); + entry = new DataEntry(dat, true, true); } if (data.containsKey(matcher.group(5))) { - data.get(matcher.group(5).trim()).add(dat); + data.get(matcher.group(5).trim()).add(entry); } else { - temp = new PairArrayList(); - temp.add(dat); + temp = new PairArrayList<>(); + temp.add(entry); data.put(matcher.group(5).trim(), temp); } } else { ValueTriplet dat = new ValueTriplet<>(matcher.group(6).trim(), matcher.group(7).trim(), size++); if (data.containsKey(matcher.group(5).trim())) { - data.get(matcher.group(5).trim()).add(dat); + data.get(matcher.group(5).trim()).add(new DataEntry(dat, true, true)); } else { - temp = new PairArrayList(); - temp.add(dat); + temp = new PairArrayList<>(); + temp.add(new DataEntry(dat, true, true)); data.put(matcher.group(5).trim(), temp); } } @@ -239,9 +243,9 @@ public Object load(String input) { secMap = (DataMap) load(matcher.group(4).replaceAll("(?m)^\t", "")); dat = new ValueTriplet<>(matcher.group(2).trim(), secMap, order); } - temp.add(dat); + temp.add(new DataEntry(dat, true, false)); if (data.containsKey(matcher.group(1).trim())) { - data.get(matcher.group(1).trim()).add(dat); + data.get(matcher.group(1).trim()).add(new DataEntry(dat, true, false)); } else { data.put(matcher.group(1).trim(), temp); } diff --git a/src/StellarisDK/FileClasses/Helper/DataCell.java b/src/StellarisDK/FileClasses/Helper/DataCell.java index 0197a2c..8428f13 100644 --- a/src/StellarisDK/FileClasses/Helper/DataCell.java +++ b/src/StellarisDK/FileClasses/Helper/DataCell.java @@ -18,11 +18,13 @@ public DataCell() { this.setOnDragDetected(event -> { TreeItem item = this.getTreeItem(); - Dragboard db = this.startDragAndDrop(TransferMode.MOVE); - ClipboardContent clipboard = new ClipboardContent(); - clipboard.putString(Integer.toString(item.getParent().getChildren().indexOf(item))); - db.setContent(clipboard); - event.consume(); + if(item.getParent() != null){ + Dragboard db = this.startDragAndDrop(TransferMode.MOVE); + ClipboardContent clipboard = new ClipboardContent(); + clipboard.putString(Integer.toString(item.getParent().getChildren().indexOf(item))); + db.setContent(clipboard); + event.consume(); + } }); this.setOnDragOver(event -> { @@ -92,25 +94,51 @@ public DataCell() { @Override public void startEdit() { + if((getItem() instanceof DataEntry)){ + if(((DataEntry) getItem()).isEditable()){ + startEditor(); + }else{ + return; + } + } + startEditor(); + } + + public void startEditor() { super.startEdit(); - if (textField == null) { - textField = new TextField(getItem().toString().replaceAll("#tabs","")); - textField.setOnKeyReleased(event -> { - if (event.getCode() == KeyCode.ENTER) { - commitEdit((T) textField.getText()); - } else if (event.getCode() == KeyCode.ESCAPE) { - cancelEdit(); - } - }); + if (getItem() instanceof DataEntry) { + ValueTriplet vT = (ValueTriplet) ((DataEntry) getItem()).getTreeEntry().getValue(); + textField = new TextField(((VPair) vT.getValue()).getValue().toString()); + } else { + textField = new TextField(getItem().toString().replaceAll("#tabs", "")); + } + textField.setOnKeyReleased(event -> { + if (event.getCode() == KeyCode.ENTER) { + commitEdit((T) textField.getText()); + } else if (event.getCode() == KeyCode.ESCAPE) { + cancelEdit(); + } + }); + if (getItem() instanceof DataEntry) { + ValueTriplet vT = (ValueTriplet) ((DataEntry) getItem()).getTreeEntry().getValue(); + setText(vT.getKey().toString() + ": "); + setContentDisplay(ContentDisplay.RIGHT); + } else { + setText(null); } - setText(null); setGraphic(textField); textField.selectAll(); } @Override public void commitEdit(T newValue) { - super.commitEdit(newValue); + if (getItem() instanceof DataEntry) { + ValueTriplet vT = (ValueTriplet)((DataEntry) getItem()).getTreeEntry().getValue(); + ((VPair) vT.getValue()).setValue(newValue); + super.commitEdit(getTreeItem().getValue()); + } else { + super.commitEdit(newValue); + } } @Override @@ -145,7 +173,12 @@ protected void updateItem(T item, boolean empty) { } private TreeItem clone(TreeItem items){ - TreeItem copy = new TreeItem<>(items.getValue()); + TreeItem copy; + if(items.getValue() instanceof DataEntry){ + copy = new TreeItem<>((T)((DataEntry) items.getValue()).getTreeEntry().getValue()); + }else{ + copy = new TreeItem<>(items.getValue()); + } for(Object item : items.getChildren()){ copy.getChildren().add(clone((TreeItem)item)); } @@ -156,7 +189,7 @@ private void setCM() { ContextMenu contextMenu = new ContextMenu(); MenuItem createNew = new MenuItem("New.."); createNew.setOnAction(event -> { - getTreeItem().getChildren().add(new TreeItem("Click to Edit..")); + getTreeItem().getChildren().add(new TreeItem("Click_to_Edit")); }); MenuItem edit = new MenuItem("Rename"); edit.setOnAction(event -> startEdit()); @@ -191,9 +224,20 @@ private void setCM() { setContextMenu(contextMenu); setOnContextMenuRequested(event ->{ + contextMenu.getItems().clear(); + contextMenu.getItems().addAll(createNew, edit, cut, copy, paste, delete); if(this.getTreeItem().getParent() == null){ contextMenu.getItems().removeAll(cut, copy, delete); } + if((getItem() instanceof DataEntry)){ + contextMenu.getItems().removeAll(cut, delete); + if(!((DataEntry) getItem()).isEditable()){ + contextMenu.getItems().removeAll(edit); + } + if(((DataEntry) getItem()).isSingleEntry()){ + contextMenu.getItems().remove(createNew); + } + } if(cellContent == null){ paste.setDisable(true); }else{ diff --git a/src/StellarisDK/FileClasses/Helper/DataEntry.java b/src/StellarisDK/FileClasses/Helper/DataEntry.java new file mode 100644 index 0000000..971f9ac --- /dev/null +++ b/src/StellarisDK/FileClasses/Helper/DataEntry.java @@ -0,0 +1,115 @@ +package StellarisDK.FileClasses.Helper; + +import javafx.scene.control.TreeItem; + +public class DataEntry { + + private boolean singleEntry = true; + private boolean editable = true; + private boolean required = false; + private ValueTriplet entry; + + public DataEntry(String entry) { + this.entry = new ValueTriplet<>("", entry, 0); + } + + public DataEntry(ValueTriplet entry) { + this.entry = entry; + } + + public DataEntry(String entry, boolean editable) { + this.editable = editable; + this.entry = new ValueTriplet<>("", entry, 0); + } + + public DataEntry(ValueTriplet entry, boolean editable) { + this.editable = editable; + this.entry = entry; + } + + public DataEntry(String entry, boolean editable, boolean singleEntry) { + this.singleEntry = singleEntry; + this.editable = editable; + this.entry = new ValueTriplet<>("", entry, 0); + } + + public DataEntry(ValueTriplet entry, boolean editable, boolean singleEntry) { + this.singleEntry = singleEntry; + this.editable = editable; + this.entry = entry; + } + + public DataEntry(String entry, boolean editable, boolean singleEntry, boolean required) { + this.singleEntry = singleEntry; + this.editable = editable; + this.required = required; + this.entry = new ValueTriplet<>("", entry, 0); + } + + public DataEntry(ValueTriplet entry, boolean editable, boolean singleEntry, boolean required) { + this.singleEntry = singleEntry; + this.editable = editable; + this.required = required; + this.entry = entry; + } + + public boolean isSingleEntry() { + return singleEntry; + } + + public void setSingleEntry(boolean singleEntry) { + this.singleEntry = singleEntry; + } + + public boolean isEditable() { + return editable; + } + + public void setEditable(boolean editable) { + this.editable = editable; + } + + public TreeItem getTreeEntry() { + return new TreeItem<>(entry); + } + + public ValueTriplet getEntry() { + return entry; + } + + public void setEntry(ValueTriplet entry) { + this.entry = entry; + } + + public boolean isRequired() { + return required; + } + + public void setRequired(boolean required) { + this.required = required; + } + + public int getBinary(){ + return (singleEntry ? 100 : 0) + (editable ? 10 : 0) + (required ? 1 : 0); + } + + public void setBinary(int binary) { + char[] group = Integer.toString(binary).toCharArray(); + this.singleEntry = group[0] == '1'; + this.editable = group[1] == '1'; + this.required = group[2] == '1'; + } + + public TreeItem toNestedTree() { + TreeItem temp = new TreeItem<>(this); + if (!singleEntry) + temp.getChildren().add(new TreeItem<>("click_to_edit")); + return temp; + } + + + @Override + public String toString() { + return entry.toString(); + } +} \ No newline at end of file diff --git a/src/StellarisDK/FileClasses/Helper/DataMap.java b/src/StellarisDK/FileClasses/Helper/DataMap.java index ec9c209..316114f 100644 --- a/src/StellarisDK/FileClasses/Helper/DataMap.java +++ b/src/StellarisDK/FileClasses/Helper/DataMap.java @@ -36,13 +36,13 @@ public ValueTriplet[] compressToPairArray() { for (Object key : keySet()) { for (Object data : ((ArrayList) get(key))) { try { - if (((ValueTriplet) data).getValue() != null){ - objs[((ValueTriplet) data).getOrder()] = new ValueTriplet<>(key, ((ValueTriplet) data).toPair(), ((ValueTriplet) data).getOrder()); + if (((DataEntry)data).getEntry().getValue() != null){ + objs[((DataEntry)data).getEntry().getOrder()] = new ValueTriplet<>(key, ((DataEntry)data).getEntry().toPair(), ((DataEntry)data).getEntry().getOrder()); } } catch (ArrayIndexOutOfBoundsException e) { System.out.println("[ERROR] StackOverFlow, FROM: DataMap"); - System.out.println("[ERROR] CAUSE: Tried " + key + " Value: " + ((ValueTriplet) data).getKey()); - System.out.println("[ERROR] SIZE: " + getFullSize() + ", Actual: " + ((ValueTriplet) data).getOrder()); + System.out.println("[ERROR] CAUSE: Tried " + key + " Value: " + ((DataEntry)data).getEntry().getKey()); + System.out.println("[ERROR] SIZE: " + getFullSize() + ", Actual: " + ((DataEntry)data).getEntry().getOrder()); } } } diff --git a/src/StellarisDK/FileClasses/Helper/PairArrayList.java b/src/StellarisDK/FileClasses/Helper/PairArrayList.java index c21e5a0..eadd7dc 100644 --- a/src/StellarisDK/FileClasses/Helper/PairArrayList.java +++ b/src/StellarisDK/FileClasses/Helper/PairArrayList.java @@ -4,7 +4,7 @@ import java.util.ArrayList; -public class PairArrayList extends ArrayList { +public class PairArrayList extends ArrayList { public TreeItem toTreeItem(String key) { TreeItem root = new TreeItem<>(key); diff --git a/src/StellarisDK/FileClasses/Tradition.java b/src/StellarisDK/FileClasses/Tradition.java new file mode 100644 index 0000000..1171d8b --- /dev/null +++ b/src/StellarisDK/FileClasses/Tradition.java @@ -0,0 +1,38 @@ +package StellarisDK.FileClasses; + +import StellarisDK.GUI.TraditionUI; +import javafx.scene.control.TreeItem; + +public class Tradition extends GenericData { + + private boolean ap; + + public Tradition(boolean ap) { + super(); + if(ap){ + this.type = "tradition"; + this.ap = ap; + ui = new TraditionUI(this, ap); + }else{ + this.type = "ascension_perk"; + this.ap = !ap; + ui = new TraditionUI(this, !ap); + } + } + + public Tradition(String input, String type, boolean ap) { + super(input, type); + this.ap = ap; + ui = new TraditionUI(this, ap); + } + + @Override + public TreeItem getRequiredTreeSet() { + return null; + } + + @Override + public GenericData createNew() { + return new Tradition(ap); + } +} diff --git a/src/StellarisDK/GUI/AbstractUI.java b/src/StellarisDK/GUI/AbstractUI.java index 153593b..1639695 100644 --- a/src/StellarisDK/GUI/AbstractUI.java +++ b/src/StellarisDK/GUI/AbstractUI.java @@ -98,7 +98,11 @@ private void setCloseButton(Button btn) { public void load() { treeView.setEditable(true); treeView.setCellFactory(param -> new DataCell()); - treeView.setRoot(obj.toTreeItem()); + if(obj.getSize() != 0){ + treeView.setRoot(obj.toTreeItem()); + }else{ + treeView.setRoot(obj.getRequiredTreeSet()); + } } public Object save() { diff --git a/src/StellarisDK/GUI/AgendaUI.java b/src/StellarisDK/GUI/AgendaUI.java index b0e6db5..29318f4 100644 --- a/src/StellarisDK/GUI/AgendaUI.java +++ b/src/StellarisDK/GUI/AgendaUI.java @@ -1,7 +1,6 @@ package StellarisDK.GUI; import StellarisDK.FileClasses.Agenda; -import StellarisDK.FileClasses.Helper.DataCell; public class AgendaUI extends AbstractUI { @@ -10,15 +9,4 @@ public AgendaUI(Agenda obj) { window.setText("Agenda Editor"); this.obj = obj; } - - @Override - public void load() { - treeView.setEditable(true); - treeView.setCellFactory(param -> new DataCell()); - if(obj.getSize() != 0){ - treeView.setRoot(obj.toTreeItem()); - }else{ - treeView.setRoot(obj.getRequiredTreeSet()); - } - } } diff --git a/src/StellarisDK/GUI/AnomalyCategoryUI.java b/src/StellarisDK/GUI/AnomalyCategoryUI.java index 39f4dac..8460da5 100644 --- a/src/StellarisDK/GUI/AnomalyCategoryUI.java +++ b/src/StellarisDK/GUI/AnomalyCategoryUI.java @@ -3,7 +3,6 @@ import StellarisDK.FileClasses.Anomaly.AnomalyCategory; public class AnomalyCategoryUI extends AbstractUI { - public AnomalyCategoryUI(AnomalyCategory obj) { init("FXML/anomalyCategoryFX.fxml"); window.setText("Anomaly Category Editor"); diff --git a/src/StellarisDK/GUI/ArmyUI.java b/src/StellarisDK/GUI/ArmyUI.java new file mode 100644 index 0000000..1e15188 --- /dev/null +++ b/src/StellarisDK/GUI/ArmyUI.java @@ -0,0 +1,11 @@ +package StellarisDK.GUI; + +import StellarisDK.FileClasses.Army; + +public class ArmyUI extends AbstractUI{ + public ArmyUI(Army obj) { + init("FXML/default.fxml"); + window.setText("Army Editor"); + this.obj = obj; + } +} diff --git a/src/StellarisDK/GUI/FXML/guiFX.fxml b/src/StellarisDK/GUI/FXML/guiFX.fxml index f409b41..14de0e1 100644 --- a/src/StellarisDK/GUI/FXML/guiFX.fxml +++ b/src/StellarisDK/GUI/FXML/guiFX.fxml @@ -2,11 +2,11 @@ - + - + diff --git a/src/StellarisDK/GUI/TraditionUI.java b/src/StellarisDK/GUI/TraditionUI.java new file mode 100644 index 0000000..94ce7be --- /dev/null +++ b/src/StellarisDK/GUI/TraditionUI.java @@ -0,0 +1,18 @@ +package StellarisDK.GUI; + +import StellarisDK.FileClasses.Tradition; + +public class TraditionUI extends AbstractUI { + + public TraditionUI(Tradition obj, boolean type) { + if(type){ + init("FXML/traditionFX.fxml"); + window.setText("Tradition Editor"); + this.obj = obj; + }else{ + init("FXML/apFX.fxml"); + window.setText("Ascension Editor"); + this.obj = obj; + } + } +} diff --git a/src/StellarisDK/GUI/guiController.java b/src/StellarisDK/GUI/guiController.java index 6317582..a6d576d 100644 --- a/src/StellarisDK/GUI/guiController.java +++ b/src/StellarisDK/GUI/guiController.java @@ -3,6 +3,7 @@ import StellarisDK.DataLoc; import StellarisDK.FileClasses.*; import StellarisDK.FileClasses.Anomaly.Anomaly; +import StellarisDK.FileClasses.Anomaly.AnomalyCategory; import StellarisDK.FileClasses.Component.CompSet; import StellarisDK.FileClasses.Component.Component; import com.sun.javafx.scene.control.skin.LabeledText; @@ -213,9 +214,19 @@ protected void updateItem(Object item, boolean empty) { return cell; } + private MenuItem createItem(TreeCell cell, String type){ + MenuItem item = new MenuItem(type); + item.setOnAction(event ->{ + cell.getTreeItem().getChildren().add(createNew(type)); + }); + return item; + } + private void setCM(TreeCell cell) { ContextMenu contextMenu = new ContextMenu(); - MenuItem createNew = new MenuItem("New.."); + Menu create = new Menu("New.."); + + MenuItem createNew = new MenuItem("New"); createNew.setOnAction(event -> { if (cell.getTreeItem().getValue() instanceof GenericData) { TreeItem newCell = new TreeItem<>(((GenericData) cell.getTreeItem().getValue()).createNew()); @@ -230,10 +241,12 @@ private void setCM(TreeCell cell) { } } }); + MenuItem edit = new MenuItem("Rename"); edit.setOnAction(event -> { cell.startEdit(); }); + MenuItem delete = new MenuItem("Delete"); delete.setOnAction(event -> { if (cell.getItem().toString().contains(".txt") || cell.getTreeItem().getParent().getValue().toString().contains(".txt")) { @@ -268,9 +281,9 @@ private void setCM(TreeCell cell) { } }); - cell.setOnContextMenuRequested(event -> { cell.getContextMenu().getItems().clear(); + create.getItems().clear(); if(cContent == null){ paste.setDisable(true); }else{ @@ -280,14 +293,19 @@ private void setCM(TreeCell cell) { if (cell.getTreeItem().getParent().getValue().equals("common") || cell.getItem().equals("events")) { cell.getContextMenu().getItems().add(createNew); } else if (cell.getItem().toString().endsWith(".txt")) { - cell.getContextMenu().getItems().addAll(createNew, edit, paste, delete); + if(cell.getTreeItem().getParent().getValue().toString().equals("anomalies")){ + cell.getContextMenu().getItems().addAll(create, edit, paste, delete); + create.getItems().addAll(createItem(cell,"anomaly"), createItem(cell, "anomaly_category")); + } else{ + cell.getContextMenu().getItems().addAll(createNew, edit, paste, delete); + } } else if (cell.getTreeItem().getParent().getValue().toString().endsWith(".txt")) { cell.getContextMenu().getItems().addAll(createNew, cut, copy, paste, delete); } } }); - contextMenu.getItems().addAll(createNew, edit, delete); + contextMenu.getItems().addAll(createNew, cut, copy, paste, delete); cell.setContextMenu(contextMenu); } @@ -300,12 +318,14 @@ private TreeItem createNew(String type) { return new TreeItem<>(new Agenda()); case "ambient_objects": return new TreeItem<>(new AmbientObject()); - case "anomalies": + case "anomaly": return new TreeItem<>(new Anomaly()); + case "anomaly_category": + return new TreeItem<>(new AnomalyCategory()); case "armies": - break; + return new TreeItem<>(new Army()); case "ascension_perks": - break; + return new TreeItem<>(new Tradition(false)); case "attitudes": break; case "bombardment_stances": @@ -383,6 +403,7 @@ private TreeItem createNew(String type) { case "tile_blockers": case "tradition_categories": case "traditions": + return new TreeItem<>(new Tradition(true)); case "traits": break; case "events":