Skip to content
This repository was archived by the owner on May 21, 2026. It is now read-only.

Commit 38e42d2

Browse files
committed
Custom flags feature added.
1 parent 6a03666 commit 38e42d2

10 files changed

Lines changed: 397 additions & 61 deletions
Lines changed: 107 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,107 @@
1+
using UnityEngine;
2+
using UnityEditor;
3+
using DiplomataLib;
4+
5+
namespace DiplomataEditor {
6+
7+
public class CustomFlagListMenu : EditorWindow {
8+
9+
public Vector2 scrollPos = new Vector2(0, 0);
10+
private Diplomata diplomataEditor;
11+
private string[] booleanArray = new string[] { "True", "False" };
12+
13+
[MenuItem("Diplomata/Custom Flags")]
14+
static public void Init() {
15+
Diplomata.Instantiate();
16+
17+
CustomFlagListMenu window = (CustomFlagListMenu)GetWindow(typeof(CustomFlagListMenu), false, "Custom Flags");
18+
window.minSize = new Vector2(DGUI.WINDOW_MIN_WIDTH + 80, 300);
19+
20+
window.Show();
21+
}
22+
23+
public void OnEnable() {
24+
diplomataEditor = (Diplomata)AssetHandler.Read("Diplomata.asset", "Diplomata/");
25+
}
26+
27+
public void OnGUI() {
28+
DGUI.Init();
29+
30+
scrollPos = EditorGUILayout.BeginScrollView(scrollPos);
31+
GUILayout.BeginVertical(DGUI.windowStyle);
32+
33+
if (diplomataEditor.customFlags.flags.Length <= 0) {
34+
EditorGUILayout.HelpBox("No flags yet.", MessageType.Info);
35+
}
36+
37+
for (int i = 0; i < diplomataEditor.customFlags.flags.Length; i++) {
38+
39+
var flag = diplomataEditor.customFlags.flags[i];
40+
41+
GUILayout.BeginHorizontal();
42+
43+
GUILayout.BeginHorizontal();
44+
45+
flag.name = EditorGUILayout.TextField(flag.name, GUILayout.Height(DGUI.BUTTON_HEIGHT_SMALL));
46+
47+
GUILayout.EndHorizontal();
48+
49+
GUILayout.BeginHorizontal(GUILayout.MaxWidth(Screen.width / 3));
50+
51+
string selected = flag.value.ToString();
52+
53+
EditorGUI.BeginChangeCheck();
54+
55+
selected = DGUI.Popup("Start in ", selected, booleanArray);
56+
57+
if (EditorGUI.EndChangeCheck()) {
58+
59+
if (selected == "True") {
60+
flag.value = true;
61+
}
62+
63+
else {
64+
flag.value = false;
65+
}
66+
67+
diplomataEditor.SaveCustomFlags();
68+
}
69+
70+
GUILayout.EndHorizontal();
71+
72+
GUILayout.BeginHorizontal(GUILayout.MaxWidth(Screen.width / 3));
73+
74+
75+
if (GUILayout.Button("Delete", GUILayout.Height(DGUI.BUTTON_HEIGHT_SMALL))) {
76+
if (EditorUtility.DisplayDialog("Are you sure?", "Do you really want to delete?\nThis data will be lost forever.", "Yes", "No")) {
77+
78+
diplomataEditor.customFlags.flags = ArrayHandler.Remove(diplomataEditor.customFlags.flags, flag);
79+
diplomataEditor.SaveCustomFlags();
80+
}
81+
}
82+
83+
GUILayout.EndHorizontal();
84+
GUILayout.EndHorizontal();
85+
86+
if (i < diplomataEditor.customFlags.flags.Length - 1) {
87+
DGUI.Separator();
88+
}
89+
}
90+
91+
EditorGUILayout.Separator();
92+
93+
if (GUILayout.Button("Create", GUILayout.Height(DGUI.BUTTON_HEIGHT))) {
94+
diplomataEditor.customFlags.flags = ArrayHandler.Add(diplomataEditor.customFlags.flags, new Flag("", false));
95+
diplomataEditor.SaveCustomFlags();
96+
}
97+
98+
GUILayout.EndVertical();
99+
EditorGUILayout.EndScrollView();
100+
}
101+
102+
public void OnDisable() {
103+
diplomataEditor.SaveCustomFlags();
104+
}
105+
}
106+
107+
}

Diplomata/Editor/Diplomata.cs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ public class Diplomata : ScriptableObject {
99
public List<Character> characters = new List<Character>();
1010
public DiplomataLib.Preferences preferences = new DiplomataLib.Preferences();
1111
public Inventory inventory = new Inventory();
12+
public CustomFlags customFlags = new CustomFlags();
1213

1314
private int workingContextMessagesId;
1415
private int workingContextEditId;
@@ -31,12 +32,17 @@ public static void Instantiate() {
3132
JSONHandler.Create(new Inventory(), "inventory", false, "Diplomata/");
3233
}
3334

35+
if (!JSONHandler.Exists("customFlags", "Diplomata/")) {
36+
JSONHandler.Create(new CustomFlags(), "customFlags", false, "Diplomata/");
37+
}
38+
3439
DiplomataLib.Diplomata.Restart();
3540
var diplomataEditor = CreateInstance<Diplomata>();
3641

3742
if (!AssetHandler.Exists("Diplomata.asset", "Diplomata/")) {
3843
diplomataEditor.preferences = DiplomataLib.Diplomata.preferences;
3944
diplomataEditor.inventory = DiplomataLib.Diplomata.inventory;
45+
diplomataEditor.customFlags = DiplomataLib.Diplomata.customFlags;
4046
diplomataEditor.characters = DiplomataLib.Diplomata.characters;
4147

4248
AssetHandler.Create(diplomataEditor, "Diplomata.asset", "Diplomata/");
@@ -46,6 +52,7 @@ public static void Instantiate() {
4652
diplomataEditor = (Diplomata) AssetHandler.Read("Diplomata.asset", "Diplomata/");
4753
diplomataEditor.preferences = JSONHandler.Read<DiplomataLib.Preferences>("preferences", "Diplomata/");
4854
diplomataEditor.inventory = JSONHandler.Read<Inventory>("inventory", "Diplomata/");
55+
diplomataEditor.customFlags = JSONHandler.Read<CustomFlags>("customFlags", "Diplomata/");
4956
diplomataEditor.UpdateList();
5057
}
5158
}
@@ -114,6 +121,10 @@ public void SaveInventory() {
114121
JSONHandler.Update(inventory, "inventory", preferences.jsonPrettyPrint, "Diplomata/");
115122
}
116123

124+
public void SaveCustomFlags() {
125+
JSONHandler.Update(customFlags, "customFlags", preferences.jsonPrettyPrint, "Diplomata/");
126+
}
127+
117128
public void Save(Character character) {
118129
JSONHandler.Update(character, character.name, preferences.jsonPrettyPrint, "Diplomata/Characters/");
119130
}

Diplomata/Editor/DiplomataGUI.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,7 @@ public static Texture2D UniformColorTexture(int w, int h, Color color) {
183183
}
184184
}
185185

186-
public static string Popup(string label, string choice, string[] array) {
186+
public static string Popup(string label, string choice, string[] array, params GUILayoutOption[] options) {
187187
var selected = 0;
188188
string str = choice;
189189

@@ -196,7 +196,7 @@ public static string Popup(string label, string choice, string[] array) {
196196

197197
GUILayout.BeginHorizontal();
198198
GUILayout.Label(label);
199-
selected = EditorGUILayout.Popup(selected, array);
199+
selected = EditorGUILayout.Popup(selected, array, options);
200200
GUILayout.EndHorizontal();
201201

202202
for (int i = 0; i < array.Length; i++) {

Diplomata/Editor/MessagesEditor.cs

Lines changed: 127 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ public class MessagesEditor {
1313
private static string[] characterList = new string[0];
1414
private static string[] contextList = new string[0];
1515
private static string[] itemList = new string[0];
16+
private static string[] customFlagsList = new string[0];
17+
private static string[] booleanArray = new string[] { "True", "False" };
1618
public static GUIStyle messagesWindowHeaderStyle = new GUIStyle(DGUI.windowStyle);
1719
public static GUIStyle messagesWindowMainStyle = new GUIStyle(DGUI.windowStyle);
1820
public static GUIStyle messagesWindowSidebarStyle = new GUIStyle(DGUI.windowStyle);
@@ -140,8 +142,7 @@ public static void Main() {
140142
break;
141143
}
142144
}
143-
144-
#region MESSAGE CARD
145+
145146
Rect boxRect = EditorGUILayout.BeginVertical(DGUI.boxStyle);
146147

147148
var color = currentMessage.color;
@@ -209,6 +210,17 @@ public static void Main() {
209210
}
210211
text += condition.DisplayHasItem(itemName);
211212
break;
213+
case Condition.Type.CustomFlagEqualTo:
214+
text += condition.DisplayCustomFlagEqualTo();
215+
break;
216+
case Condition.Type.ItemWasDiscarded:
217+
var itemNameDiscarded = "";
218+
if (Item.Find(diplomataEditor.inventory.items, condition.itemId) != null) {
219+
itemName = DictHandler.ContainsKey(Item.Find(diplomataEditor.inventory.items, condition.itemId).name,
220+
diplomataEditor.preferences.currentLanguage).value;
221+
}
222+
text += condition.DisplayItemWasDiscarded(itemNameDiscarded);
223+
break;
212224
}
213225

214226
if (k < currentMessage.conditions.Length - 1) {
@@ -308,6 +320,9 @@ public static void Main() {
308320
}
309321
text += effect.DisplayDiscardItem(discardItemName);
310322
break;
323+
case Effect.Type.SetCustomFlag:
324+
text += effect.DisplayCustomFlagEqualTo();
325+
break;
311326
}
312327

313328
if (k < currentMessage.effects.Length - 1) {
@@ -344,19 +359,13 @@ public static void Main() {
344359
DGUI.labelStyle.alignment = TextAnchor.UpperLeft;
345360
}
346361

347-
/*if (GUI.GetNameOfFocusedControl() == "title" + currentMessage.id ||
348-
GUI.GetNameOfFocusedControl() == "content" + currentMessage.id) {
349-
SetMessage(currentMessage);
350-
}*/
351-
352362
if (GUI.Button(boxRect, "", buttonStyle)) {
353363
SetMessage(currentMessage);
354364
EditorGUI.FocusTextInControl("");
355365
}
356366

357367
EditorGUILayout.EndVertical();
358368
EditorGUILayout.Separator();
359-
#endregion
360369
}
361370

362371
if (GUILayout.Button("Add Message", GUILayout.Height(DGUI.BUTTON_HEIGHT))) {
@@ -577,14 +586,20 @@ public static void Sidebar() {
577586
case AnimatorControllerParameterType.Bool:
578587
string selected = animatorAttribute.setBool.ToString();
579588

580-
selected = DGUI.Popup("Set boolean to ", selected, new string[] { "True", "False" });
589+
EditorGUI.BeginChangeCheck();
581590

582-
if (selected == "True") {
583-
animatorAttribute.setBool = true;
584-
}
591+
selected = DGUI.Popup("Set boolean to ", selected, booleanArray);
592+
593+
if (EditorGUI.EndChangeCheck()) {
594+
595+
if (selected == "True") {
596+
animatorAttribute.setBool = true;
597+
}
598+
599+
else {
600+
animatorAttribute.setBool = false;
601+
}
585602

586-
else {
587-
animatorAttribute.setBool = false;
588603
}
589604

590605
break;
@@ -850,6 +865,59 @@ public static void Sidebar() {
850865

851866
GUILayout.EndHorizontal();
852867
break;
868+
869+
case Condition.Type.ItemWasDiscarded:
870+
GUILayout.BeginHorizontal();
871+
UpdateItemList();
872+
873+
var discardedItemName = "";
874+
875+
if (itemList.Length > 0) {
876+
itemName = DictHandler.ContainsKey(Item.Find(diplomataEditor.inventory.items, condition.itemId).name, diplomataEditor.preferences.currentLanguage).value;
877+
}
878+
879+
EditorGUI.BeginChangeCheck();
880+
881+
discardedItemName = DGUI.Popup("Item was discarded ", discardedItemName, itemList);
882+
883+
if (EditorGUI.EndChangeCheck()) {
884+
foreach (Item item in diplomataEditor.inventory.items) {
885+
886+
if (DictHandler.ContainsKey(item.name, diplomataEditor.preferences.currentLanguage).value == discardedItemName) {
887+
condition.itemId = item.id;
888+
break;
889+
}
890+
891+
}
892+
}
893+
894+
GUILayout.EndHorizontal();
895+
break;
896+
897+
case Condition.Type.CustomFlagEqualTo:
898+
UpdateCustomFlagsList();
899+
900+
condition.customFlag.name = DGUI.Popup("Flag: ", condition.customFlag.name, customFlagsList);
901+
902+
string selected = condition.customFlag.value.ToString();
903+
904+
EditorGUI.BeginChangeCheck();
905+
906+
selected = DGUI.Popup("is ", selected, booleanArray);
907+
908+
if (EditorGUI.EndChangeCheck()) {
909+
910+
if (selected == "True") {
911+
condition.customFlag.value = true;
912+
}
913+
914+
else {
915+
condition.customFlag.value = false;
916+
}
917+
918+
}
919+
920+
break;
853921
}
854922

855923
if (GUILayout.Button("Delete Condition", GUILayout.Height(DGUI.BUTTON_HEIGHT_SMALL))) {
@@ -975,14 +1043,20 @@ public static void Sidebar() {
9751043
case AnimatorControllerParameterType.Bool:
9761044
string selected = effect.animatorAttributeSetter.setBool.ToString();
9771045

978-
selected = DGUI.Popup("Set boolean to ", selected, new string[] { "True", "False" });
1046+
EditorGUI.BeginChangeCheck();
9791047

980-
if (selected == "True") {
981-
effect.animatorAttributeSetter.setBool = true;
982-
}
1048+
selected = DGUI.Popup("Set boolean to ", selected, booleanArray);
1049+
1050+
if (EditorGUI.EndChangeCheck()) {
1051+
1052+
if (selected == "True") {
1053+
effect.animatorAttributeSetter.setBool = true;
1054+
}
1055+
1056+
else {
1057+
effect.animatorAttributeSetter.setBool = false;
1058+
}
9831059

984-
else {
985-
effect.animatorAttributeSetter.setBool = false;
9861060
}
9871061

9881062
break;
@@ -1061,6 +1135,31 @@ public static void Sidebar() {
10611135

10621136
GUILayout.EndHorizontal();
10631137
break;
1138+
1139+
case Effect.Type.SetCustomFlag:
1140+
UpdateCustomFlagsList();
1141+
1142+
effect.customFlag.name = DGUI.Popup("Flag: ", effect.customFlag.name, customFlagsList);
1143+
1144+
string effectSelected = effect.customFlag.value.ToString();
1145+
1146+
EditorGUI.BeginChangeCheck();
1147+
1148+
effectSelected = DGUI.Popup(" set to ", effectSelected, booleanArray);
1149+
1150+
if (EditorGUI.EndChangeCheck()) {
1151+
1152+
if (effectSelected == "True") {
1153+
effect.customFlag.value = true;
1154+
}
1155+
1156+
else {
1157+
effect.customFlag.value = false;
1158+
}
1159+
1160+
}
1161+
1162+
break;
10641163
}
10651164

10661165
if (GUILayout.Button("Delete Effect", GUILayout.Height(DGUI.BUTTON_HEIGHT_SMALL))) {
@@ -1155,6 +1254,14 @@ public static void UpdateContextList() {
11551254
}
11561255
}
11571256

1257+
public static void UpdateCustomFlagsList() {
1258+
customFlagsList = new string[0];
1259+
1260+
foreach(Flag flag in CharacterMessagesManager.diplomataEditor.customFlags.flags) {
1261+
customFlagsList = ArrayHandler.Add(customFlagsList, flag.name);
1262+
}
1263+
}
1264+
11581265
}
11591266

11601267
}

0 commit comments

Comments
 (0)