Skip to content

Commit

Permalink
Added Attitude Editor
Browse files Browse the repository at this point in the history
  • Loading branch information
rexc159 committed Mar 15, 2018
1 parent 284a7a5 commit 8872e35
Show file tree
Hide file tree
Showing 10 changed files with 248 additions and 40 deletions.
28 changes: 28 additions & 0 deletions src/StellarisDK/FileClasses/Attitude.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package StellarisDK.FileClasses;

import StellarisDK.FileClasses.Helper.DataEntry;
import StellarisDK.FileClasses.Helper.DataMap;
import StellarisDK.FileClasses.Helper.EntryArrayList;
import StellarisDK.GUI.AttitudeUI;

import java.util.Arrays;

public class Attitude extends GenericData {

public Attitude() {
super();
this.type = new DataEntry("new_attitude");
data.put("behaviour", new EntryArrayList<>(Arrays.asList(new DataMap())));
ui = new AttitudeUI(this);
}

public Attitude(String input, String type) {
super(input, type);
ui = new AttitudeUI(this);
}

@Override
public GenericData createNew() {
return new Attitude();
}
}
2 changes: 2 additions & 0 deletions src/StellarisDK/FileClasses/DataParser.java
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,8 @@ public static ArrayList<TreeItem> parseAll(File file) throws IOException {
gData = new Tradition(tabby, obj.group(1), false);
break;
case "attitudes":
gData = new Attitude(tabby, obj.group(1));
break;
case "bombardment_stances":
case "buildable_pops":
case "building tags":
Expand Down
23 changes: 14 additions & 9 deletions src/StellarisDK/FileClasses/GenericData.java
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,14 @@ private String setName() {
return name;
}

public String getFirstValue(String key) {
public Object getFirstValue(String key) {
if (getKey(key))
return ((EntryArrayList) data.get(key)).get(0);
else
return null;
}

public String getFirstString(String key) {
if (getKey(key))
return ((EntryArrayList) data.get(key)).getFirstString();
else
Expand Down Expand Up @@ -110,6 +117,12 @@ public void setValue(String key, Object value, boolean addIfAbsent, int index) t
}
}

public void removeValue(String key) {
if (data.containsKey(key)) {
data.remove(key);
}
}

public void setData(DataMap data) {
this.data = data;
}
Expand Down Expand Up @@ -219,19 +232,15 @@ public Object load(String input) {
EntryArrayList<DataEntry> 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<>(matcher.group(5).trim(), new StellarisColor(color.group(1).trim(), color.group(2).trim(), color.group(3).trim(), color.group(4).trim(), color.group(5).trim()), size++ , 1110);
} 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<>(matcher.group(5).trim(), new StellarisColor(color.group(1).trim(), color.group(2).trim(), color.group(3).trim(), color.group(4).trim()), size++ , 1110);
}
} else {
// dat = new ValueTriplet<>(matcher.group(6).trim(), sLrecursion(matcher.group(7).trim()), size++);
entry = new DataEntry<>(matcher.group(5).trim(), sLrecursion(matcher.group(7).trim()), size++, 1010);
}
if (data.containsKey(matcher.group(5))) {
Expand All @@ -242,7 +251,6 @@ public Object load(String input) {
data.put(matcher.group(5).trim(), temp);
}
} else {
// ValueTriplet dat = new ValueTriplet<>(matcher.group(6).trim(), matcher.group(7).trim(), size++);
DataEntry entry = new DataEntry<>(matcher.group(5).trim(), matcher.group(6).trim(), matcher.group(7).trim(), size++, 1110);
if (data.containsKey(matcher.group(5).trim())) {
data.get(matcher.group(5).trim()).add(entry);
Expand All @@ -256,14 +264,11 @@ public Object load(String input) {
temp = new EntryArrayList<>();
int order = size++;
DataMap secMap;
// ValueTriplet dat;
DataEntry entry;
if (!matcher.group(4).contains("=")) {
// dat = new ValueTriplet<>(matcher.group(2).trim(), sLrecursion(matcher.group(4).trim().replaceAll("[\\t\\n\\r]", " ")), order);
entry = new DataEntry<>(matcher.group(1).trim(), sLrecursion(matcher.group(4).trim().replaceAll("[\\t\\n\\r]", " ")), order, 1010);
} else {
secMap = (DataMap) load(matcher.group(4).replaceAll("(?m)^\t", ""));
// dat = new ValueTriplet<>(matcher.group(2).trim(), secMap, order);
entry = new DataEntry<>(matcher.group(1).trim(), secMap, order, 1010);
}
temp.add(entry);
Expand Down
9 changes: 3 additions & 6 deletions src/StellarisDK/FileClasses/Helper/DataCell.java
Original file line number Diff line number Diff line change
Expand Up @@ -101,8 +101,11 @@ private void startEditor() {
super.startEdit();
if (getItem() instanceof DataEntry && ((DataEntry) getItem()).getValue() != null) {
textField = new TextField(((DataEntry) getItem()).getValue().toString());
setText(((DataEntry) getItem()).getKey() + ": ");
setContentDisplay(ContentDisplay.RIGHT);
} else {
textField = new TextField(getItem().toString());
setText(null);
}
textField.setOnKeyReleased(event -> {
if (event.getCode() == KeyCode.ENTER) {
Expand All @@ -111,12 +114,6 @@ private void startEditor() {
cancelEdit();
}
});
if (getItem() instanceof DataEntry && ((DataEntry) getItem()).getValue() != null) {
setText(((DataEntry) getItem()).getKey() + ": ");
setContentDisplay(ContentDisplay.RIGHT);
} else {
setText(null);
}
setGraphic(textField);
textField.selectAll();
}
Expand Down
7 changes: 7 additions & 0 deletions src/StellarisDK/FileClasses/Helper/DataMap.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,13 @@ public int getFullSize() {
return count;
}

public Object getFirstValue(String key) {
if (get(key) != null)
return ((EntryArrayList) get(key)).get(0);
else
return null;
}

public TreeItem<DataEntry> toTreeItem(DataEntry key) {
TreeItem<DataEntry> root = new TreeItem<>(new DataEntry(key.getKey(), key.getBinary()));
DataEntry[] objs = compressToPairArray();
Expand Down
13 changes: 13 additions & 0 deletions src/StellarisDK/FileClasses/Helper/EntryArrayList.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,22 @@
import javafx.scene.control.TreeItem;

import java.util.ArrayList;
import java.util.Collection;

public class EntryArrayList<T> extends ArrayList<T> {

public EntryArrayList() {
super();
}

public EntryArrayList(T entry) {
super();
this.add(entry);
}
public EntryArrayList(Collection<? extends T> c) {
super(c);
}

public TreeItem toTreeItem(DataEntry key) {
TreeItem root = new TreeItem<>(new DataEntry(key.getKey(), key.getBinary()));
for (Object obj : this) {
Expand Down
12 changes: 6 additions & 6 deletions src/StellarisDK/GUI/AmbientObjectUI.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,16 +33,16 @@ public AmbientObjectUI(AmbientObject obj) {

@Override
public void load() {
name.setText(obj.getFirstValue(name.getId()));
tooltip.setText(obj.getFirstValue(tooltip.getId()));
description.setText(obj.getFirstValue(description.getId()));
entity.setText(obj.getFirstValue(entity.getId()));
if (obj.getFirstValue(show_name.getId()) != null && obj.getFirstValue(show_name.getId()).toLowerCase().equals("yes")) {
name.setText(obj.getFirstString(name.getId()));
tooltip.setText(obj.getFirstString(tooltip.getId()));
description.setText(obj.getFirstString(description.getId()));
entity.setText(obj.getFirstString(entity.getId()));
if (obj.getFirstString(show_name.getId()) != null && obj.getFirstString(show_name.getId()).toLowerCase().equals("yes")) {
show_name.setSelected(true);
} else {
show_name.setSelected(false);
}
if (obj.getFirstValue(selectable.getId()) != null && obj.getFirstValue(selectable.getId()).toLowerCase().equals("yes")) {
if (obj.getFirstString(selectable.getId()) != null && obj.getFirstString(selectable.getId()).toLowerCase().equals("yes")) {
selectable.setSelected(true);
} else {
selectable.setSelected(false);
Expand Down
120 changes: 120 additions & 0 deletions src/StellarisDK/GUI/AttitudeUI.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,120 @@
package StellarisDK.GUI;

import StellarisDK.FileClasses.Attitude;
import StellarisDK.FileClasses.Helper.DataEntry;
import StellarisDK.FileClasses.Helper.DataMap;
import StellarisDK.FileClasses.Helper.EntryArrayList;
import javafx.fxml.FXML;
import javafx.scene.control.CheckBox;
import javafx.scene.control.TextField;

public class AttitudeUI extends AbstractUI {

@FXML
private TextField type;

@FXML
private CheckBox attack;

@FXML
private CheckBox weaken;

@FXML
private CheckBox alliance;

@FXML
private CheckBox vassalize;

@FXML
private CheckBox trade;

@FXML
private CheckBox coexist;

public AttitudeUI(Attitude obj) {
init("FXML/attitudeFX.fxml");
window.setText("Attitude Editor");
this.obj = obj;
}

@Override
public void load() {
type.setText(obj.getFirstString(type.getId()));
DataMap temp = (DataMap)((DataEntry)obj.getFirstValue("behaviour")).getValue();
if (temp.get(attack.getId()) != null && ((DataEntry)temp.getFirstValue(attack.getId())).getValue().toString().toLowerCase().equals("yes")) {
attack.setSelected(true);
} else {
attack.setSelected(false);
}
if (temp.get(weaken.getId()) != null && ((DataEntry)temp.getFirstValue(weaken.getId())).getValue().toString().toLowerCase().equals("yes")) {
weaken.setSelected(true);
} else {
weaken.setSelected(false);
}
if (temp.get(alliance.getId()) != null && ((DataEntry)temp.getFirstValue(alliance.getId())).getValue().toString().toLowerCase().equals("yes")) {
alliance.setSelected(true);
} else {
alliance.setSelected(false);
}
if (temp.get(vassalize.getId()) != null && ((DataEntry)temp.getFirstValue(vassalize.getId())).getValue().toString().toLowerCase().equals("yes")) {
vassalize.setSelected(true);
} else {
vassalize.setSelected(false);
}
if (temp.get(trade.getId()) != null && ((DataEntry)temp.getFirstValue(trade.getId())).getValue().toString().toLowerCase().equals("yes")) {
trade.setSelected(true);
} else {
trade.setSelected(false);
}
if (temp.get(coexist.getId()) != null && ((DataEntry)temp.getFirstValue(coexist.getId())).getValue().toString().toLowerCase().equals("yes")) {
coexist.setSelected(true);
} else {
coexist.setSelected(false);
}
}

@Override
public Object save() {
DataMap temp = (DataMap)((DataEntry)obj.getFirstValue("behaviour")).getValue();
if(type.getText() == null || type.getText().equals("")){
obj.setValue(type.getId(), "Unnamed Object", true, 0);
} else {
obj.setValue(type.getId(), type.getText(), true, 0);
}
int size = 0;
if (attack.isSelected()) {
temp.put(attack.getId(), new EntryArrayList<>(new DataEntry<>(attack.getId(), "yes", size++, 1110)));
}else{
temp.remove(attack.getId());
}
if (weaken.isSelected()) {
temp.put(weaken.getId(), new EntryArrayList<>(new DataEntry<>(weaken.getId(), "yes", size++, 1110)));
}else{
temp.remove(weaken.getId());
}
if (alliance.isSelected()) {
temp.put(alliance.getId(), new EntryArrayList<>(new DataEntry<>(alliance.getId(), "yes", size++, 1110)));
}else{
temp.remove(alliance.getId());
}
if (vassalize.isSelected()) {
temp.put(vassalize.getId(), new EntryArrayList<>(new DataEntry<>(vassalize.getId(), "yes", size++, 1110)));
}else{
temp.remove(vassalize.getId());
}
if (trade.isSelected()) {
temp.put(trade.getId(), new EntryArrayList<>(new DataEntry<>(trade.getId(), "yes", size++, 1110)));
}else{
temp.remove(trade.getId());
}
if (coexist.isSelected()) {
temp.put(coexist.getId(), new EntryArrayList<>(new DataEntry<>(coexist.getId(), "yes", size++, 1110)));
}else{
temp.remove(coexist.getId());
}

System.out.println(obj.export());
itemView.refresh();
return obj;
}
}
38 changes: 38 additions & 0 deletions src/StellarisDK/GUI/FXML/attitudeFX.fxml
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
<?xml version="1.0" encoding="UTF-8"?>

<?import javafx.geometry.Insets?>
<?import javafx.scene.control.*?>
<?import javafx.scene.layout.*?>
<AnchorPane fx:id="main" xmlns="http://javafx.com/javafx/8" xmlns:fx="http://javafx.com/fxml/1">
<children>
<GridPane layoutX="10.0" layoutY="10.0" AnchorPane.leftAnchor="0.0" AnchorPane.topAnchor="0.0">
<columnConstraints>
<ColumnConstraints hgrow="SOMETIMES" minWidth="110.0" />
<ColumnConstraints hgrow="SOMETIMES" />
<ColumnConstraints hgrow="SOMETIMES" />
</columnConstraints>
<rowConstraints>
<RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES" />
<RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES" />
<RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES" />
<RowConstraints vgrow="SOMETIMES" />
<RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES" />
<RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES" />
</rowConstraints>
<children>
<Label text="Attitude Name" />
<TextField id="type" fx:id="type" GridPane.columnIndex="2" />
<CheckBox id="attack" fx:id="attack" mnemonicParsing="false" text="Attack" GridPane.rowIndex="1" />
<Button id="btn_save" fx:id="btn_save" mnemonicParsing="false" text="Save" GridPane.columnIndex="2" GridPane.halignment="RIGHT" GridPane.rowIndex="5" />
<CheckBox id="weaken" fx:id="weaken" mnemonicParsing="false" text="Weaken" GridPane.columnIndex="2" GridPane.rowIndex="1" />
<CheckBox id="alliance" fx:id="alliance" mnemonicParsing="false" text="Alliance" GridPane.rowIndex="2" />
<CheckBox id="vassalize" fx:id="vassalize" mnemonicParsing="false" text="Vassalize" GridPane.columnIndex="2" GridPane.rowIndex="2" />
<CheckBox id="trade" fx:id="trade" mnemonicParsing="false" text="Trade" GridPane.rowIndex="4" />
<CheckBox id="coexist" fx:id="coexist" mnemonicParsing="false" text="Coexist" GridPane.columnIndex="2" GridPane.rowIndex="4" />
</children>
</GridPane>
</children>
<padding>
<Insets bottom="5.0" left="5.0" right="5.0" top="5.0" />
</padding>
</AnchorPane>
Loading

0 comments on commit 8872e35

Please sign in to comment.