diff --git a/Assets/Scenes/test.unity b/Assets/Scenes/test.unity index 58314fe..9a452b8 100644 --- a/Assets/Scenes/test.unity +++ b/Assets/Scenes/test.unity @@ -16088,8 +16088,8 @@ MonoBehaviour: m_Script: {fileID: 11500000, guid: 53999f937d6643b42949d28bcda1a943, type: 3} m_Name: m_EditorClassIdentifier: - character: {fileID: 11400000, guid: 2ce6ded48f42c8e46b99a9a665a8efda, type: 2} - team: {fileID: 11400000, guid: edbd6fc84edad7749b2192b14449f153, type: 2} + character: {fileID: 0} + team: {fileID: 0} --- !u!114 &494325675 MonoBehaviour: m_ObjectHideFlags: 0 @@ -20933,8 +20933,8 @@ MonoBehaviour: m_Script: {fileID: 11500000, guid: 53999f937d6643b42949d28bcda1a943, type: 3} m_Name: m_EditorClassIdentifier: - character: {fileID: 11400000, guid: 75942776545ea02418c221a9273f406b, type: 2} - team: {fileID: 11400000, guid: edbd6fc84edad7749b2192b14449f153, type: 2} + character: {fileID: 0} + team: {fileID: 0} --- !u!114 &651502395 MonoBehaviour: m_ObjectHideFlags: 0 @@ -34782,8 +34782,8 @@ MonoBehaviour: m_Script: {fileID: 11500000, guid: 53999f937d6643b42949d28bcda1a943, type: 3} m_Name: m_EditorClassIdentifier: - character: {fileID: 11400000, guid: 496024b31fb8d604ba8b12317f0d4762, type: 2} - team: {fileID: 11400000, guid: edbd6fc84edad7749b2192b14449f153, type: 2} + character: {fileID: 0} + team: {fileID: 0} --- !u!114 &909185162 MonoBehaviour: m_ObjectHideFlags: 0 @@ -38924,8 +38924,8 @@ MonoBehaviour: m_Script: {fileID: 11500000, guid: 53999f937d6643b42949d28bcda1a943, type: 3} m_Name: m_EditorClassIdentifier: - character: {fileID: 11400000, guid: 36a63a88f336fee4fbee3ca4e3812861, type: 2} - team: {fileID: 11400000, guid: 15bb40f2e1f0dd04a8ec14b3c2bb0cc4, type: 2} + character: {fileID: 0} + team: {fileID: 0} --- !u!114 &1054756145 MonoBehaviour: m_ObjectHideFlags: 0 @@ -41551,8 +41551,8 @@ MonoBehaviour: m_Script: {fileID: 11500000, guid: 53999f937d6643b42949d28bcda1a943, type: 3} m_Name: m_EditorClassIdentifier: - character: {fileID: 11400000, guid: bac31a58c9f786c4a9d5b67034ba5482, type: 2} - team: {fileID: 11400000, guid: edbd6fc84edad7749b2192b14449f153, type: 2} + character: {fileID: 0} + team: {fileID: 0} --- !u!114 &1140926019 MonoBehaviour: m_ObjectHideFlags: 0 @@ -56883,8 +56883,8 @@ MonoBehaviour: m_Script: {fileID: 11500000, guid: 53999f937d6643b42949d28bcda1a943, type: 3} m_Name: m_EditorClassIdentifier: - character: {fileID: 11400000, guid: 47430d8af55fb254dbd2af8d116d196d, type: 2} - team: {fileID: 11400000, guid: 15bb40f2e1f0dd04a8ec14b3c2bb0cc4, type: 2} + character: {fileID: 0} + team: {fileID: 0} --- !u!114 &1573021072 MonoBehaviour: m_ObjectHideFlags: 0 diff --git a/Assets/TRPGMaker/Database/Items/Axe.asset b/Assets/TRPGMaker/Database/Items/Axe.asset index dd0ea66..0d9371a 100644 --- a/Assets/TRPGMaker/Database/Items/Axe.asset +++ b/Assets/TRPGMaker/Database/Items/Axe.asset @@ -16,9 +16,6 @@ MonoBehaviour: tags: [] _formulas: - attributeID: HP - formula: HP + 15 + formula: HP + 20 icon: {fileID: 2800000, guid: c0470fcd9b1259b4c972a2f119f22e43, type: 3} - SlotType: - - slotsOcupped: - - Left hand - - Right hand + SlotType: [] diff --git a/Assets/TRPGMaker/Database/Items/Rod.asset b/Assets/TRPGMaker/Database/Items/Rod.asset index f846130..fbdb3cb 100644 --- a/Assets/TRPGMaker/Database/Items/Rod.asset +++ b/Assets/TRPGMaker/Database/Items/Rod.asset @@ -18,4 +18,4 @@ MonoBehaviour: icon: {fileID: 0} SlotType: - slotsOcupped: - - Right hand + - slotName: diff --git a/Assets/TRPGMaker/Database/Items/Sword.asset b/Assets/TRPGMaker/Database/Items/Sword.asset index a2ec6d7..c9784c7 100644 --- a/Assets/TRPGMaker/Database/Items/Sword.asset +++ b/Assets/TRPGMaker/Database/Items/Sword.asset @@ -16,8 +16,4 @@ MonoBehaviour: tags: [] _formulas: [] icon: {fileID: 2800000, guid: c547d731c4e32864b989aab9fe59d085, type: 3} - SlotType: - - slotsOcupped: - - Right hand - - slotsOcupped: - - Left hand + SlotType: [] diff --git a/Assets/TRPGMaker/Editor/CharacterEditor.cs b/Assets/TRPGMaker/Editor/CharacterEditor.cs index e0fec69..e911def 100644 --- a/Assets/TRPGMaker/Editor/CharacterEditor.cs +++ b/Assets/TRPGMaker/Editor/CharacterEditor.cs @@ -45,9 +45,6 @@ private void OnEnable() { // Remove button removeTexture = (Texture2D)Resources.Load("Buttons/remove", typeof(Texture2D)); - removeStyle = new GUIStyle("Button"); - removeStyle.padding = new RectOffset(2, 2, 2, 2); - reloadAttributes(); // Get Slots @@ -80,17 +77,17 @@ private void OnEnable() (Rect rect, int index, bool isActive, bool isFocused) => { rect.y += 2; - slotTypeSelected = Database.Instance.slotTypes.IndexOf(character.Slots[index].slotType); + slotTypeSelected = character.Slots.IndexOf(character.Slots[index]); slotItemSelected = Database.Instance.items.IndexOf(character.Slots[index].modifier); EditorGUI.BeginChangeCheck(); EditorGUI.LabelField(new Rect(rect.x, rect.y, 60, EditorGUIUtility.singleLineHeight), "Slot type:"); - slotTypeSelected = EditorGUI.Popup(new Rect(rect.x + 63, rect.y, 100, EditorGUIUtility.singleLineHeight), slotTypeSelected, Database.Instance.slotTypes.ToArray()); + slotTypeSelected = EditorGUI.Popup(new Rect(rect.x + 63, rect.y, 100, EditorGUIUtility.singleLineHeight), slotTypeSelected, Database.Instance.slotTypes.Select(x => x.slotName).ToArray()); EditorGUI.LabelField(new Rect(rect.x + 170, rect.y, 35, EditorGUIUtility.singleLineHeight), "Item:"); slotItemSelected = EditorGUI.Popup(new Rect(rect.x + 208, rect.y, rect.width - 238, EditorGUIUtility.singleLineHeight), slotItemSelected, Database.Instance.items.Select(s => (string)s.name).ToArray()); if (EditorGUI.EndChangeCheck()) { - if(slotTypeSelected != -1) + if(slotTypeSelected != 0) character.Slots[index].slotType = Database.Instance.slotTypes[slotTypeSelected]; if(slotItemSelected != -1) character.Slots[index].modifier = Database.Instance.items[slotItemSelected]; @@ -159,33 +156,54 @@ private void OnEnable() listAttributes.drawElementCallback = (Rect rectL, int index, bool isActive, bool isFocused) => { var element = listAttributes.serializedProperty.GetArrayElementAtIndex(index); - var textDimensions = GUI.skin.label.CalcSize(new GUIContent(character.attributes[index].attribute.name)); - rectL.y += 2; - - foldout[index] = EditorGUI.Foldout(new Rect(rectL.x, rectL.y, textDimensions.x + 5, rectL.height), foldout[index], character.attributes[index].attribute.name); - if (foldout[index]) + // For update problem + if (index < character.attributes.Count) { - rectL.height = EditorGUIUtility.singleLineHeight; - rectL.x += 15; - rectL.y += EditorGUIUtility.singleLineHeight; - EditorGUI.PropertyField(rectL, element.FindPropertyRelative("value")); - rectL.y += EditorGUIUtility.singleLineHeight; - EditorGUI.PropertyField(rectL, element.FindPropertyRelative("minValue")); - rectL.y += EditorGUIUtility.singleLineHeight; - EditorGUI.PropertyField(rectL, element.FindPropertyRelative("maxValue")); - listAttributes.elementHeight = EditorGUIUtility.singleLineHeight * 4.0f + 4.0f; + var textDimensions = GUI.skin.label.CalcSize(new GUIContent(character.attributes[index].attribute.name)); + + rectL.y += 2; + + foldout[index] = EditorGUI.Foldout(new Rect(rectL.x, rectL.y, textDimensions.x + 5, rectL.height), foldout[index], character.attributes[index].attribute.name); + if (!character.attributes[index].attribute.isCore && !character.specializedClasses.Any(x => x.attributes.Find(y => y.attribute.id == character.attributes[index].attribute.id) != null) && GUI.Button(new Rect(rectL.width - 14, rectL.y, 16, 16), new GUIContent("", removeTexture), removeStyle)) + { + character.attributes.RemoveAt(index); + } + if (foldout[index]) + { + rectL.height = EditorGUIUtility.singleLineHeight; + rectL.x += 15; + rectL.y += EditorGUIUtility.singleLineHeight; + GUI.SetNextControlName("Value"); + EditorGUI.PropertyField(rectL, element.FindPropertyRelative("value")); + if (GUI.GetNameOfFocusedControl() != "Value" && character.attributes[index].value > character.attributes[index].maxValue) + { + if (EditorUtility.DisplayDialog("Value error!", + "The value introduced is greater than the max value", "Ok")) + { + character.attributes[index].value = 0; + } + } + rectL.y += EditorGUIUtility.singleLineHeight; + GUI.SetNextControlName("MinValue"); + EditorGUI.PropertyField(rectL, element.FindPropertyRelative("minValue")); + if (GUI.GetNameOfFocusedControl() != "MinValue" && character.attributes[index].minValue > character.attributes[index].maxValue) + { + if (EditorUtility.DisplayDialog("Value error!", + "The min value introduced is greater than the max value", "Ok")) + { + character.attributes[index].minValue = 0; + } + } + rectL.y += EditorGUIUtility.singleLineHeight; + EditorGUI.PropertyField(rectL, element.FindPropertyRelative("maxValue")); + listAttributes.elementHeight = EditorGUIUtility.singleLineHeight * 4.0f + 4.0f; + } + else + { + listAttributes.elementHeight = EditorGUIUtility.singleLineHeight + 4.0f; + } } - else - { - - listAttributes.elementHeight = EditorGUIUtility.singleLineHeight + 4.0f; - } - - if (!character.attributes[index].attribute.isCore && !character.specializedClasses.Any(x => x.attributes.Find(y => y.attribute.id == character.attributes[index].attribute.id) != null) && GUI.Button(new Rect(rectL.width - 14, rectL.y, 16, 16), new GUIContent("", removeTexture), removeStyle)) - { - character.attributes.RemoveAt(index); - } - }; + }; listAttributes.elementHeightCallback += (idx) => { if (foldout[idx]) return EditorGUIUtility.singleLineHeight * 4.0f + 4.0f; @@ -195,13 +213,16 @@ private void OnEnable() // Draw attributes with formulas listAttributesFormulas.drawElementCallback = (Rect rectL, int index, bool isActive, bool isFocused) => { - var element = character.attributesWithFormulas[index]; - var textDimensions = GUI.skin.label.CalcSize(new GUIContent(element.attribute.name)); - rectL.y += 2; + if (index < character.attributesWithFormulas.Count) + { + var element = character.attributesWithFormulas[index]; + var textDimensions = GUI.skin.label.CalcSize(new GUIContent(element.attribute.name)); + rectL.y += 2; - EditorGUI.LabelField(new Rect(rectL.x, rectL.y, textDimensions.x, rectL.height), element.attribute.name); - EditorGUI.LabelField(new Rect(rectL.x + textDimensions.x - 5, rectL.y, 10, rectL.height), " = "); - EditorGUI.LabelField(new Rect(rectL.x + textDimensions.x + 5, rectL.y, rectL.width - textDimensions.x - 5, rectL.height), element.value.ToString()); + EditorGUI.LabelField(new Rect(rectL.x, rectL.y, textDimensions.x, rectL.height), element.attribute.name); + EditorGUI.LabelField(new Rect(rectL.x + textDimensions.x - 5, rectL.y, 10, rectL.height), " = "); + EditorGUI.LabelField(new Rect(rectL.x + textDimensions.x + 5, rectL.y, rectL.width - textDimensions.x - 5, rectL.height), element.value.ToString()); + } }; // Slots header @@ -274,6 +295,9 @@ private void OnEnable() public override void OnInspectorGUI() { + removeStyle = new GUIStyle("Button"); + removeStyle.padding = new RectOffset(2, 2, 2, 2); + serializedObject.Update(); // Check if slots changed @@ -282,7 +306,6 @@ public override void OnInspectorGUI() var calculate = false; if (s.modifier != null && !s.calculatedFormula) { - Debug.Log(s.modifier.name); calculate = true; s.calculatedFormula = true; } diff --git a/Assets/TRPGMaker/Editor/DatabaseEditor.cs b/Assets/TRPGMaker/Editor/DatabaseEditor.cs index 79c3cfd..abe09cf 100644 --- a/Assets/TRPGMaker/Editor/DatabaseEditor.cs +++ b/Assets/TRPGMaker/Editor/DatabaseEditor.cs @@ -43,7 +43,7 @@ public override void OnInspectorGUI() GUI.Label(new Rect(EditorGUILayout.GetControlRect().x, EditorGUILayout.GetControlRect().y, EditorGUILayout.GetControlRect().width, 30), "Tags:", titleStyle); for (int i = 0; i < Database.Instance.tags.Count; i++) { - string tag = Database.Instance.tags[i]; + string tag = Database.Instance.tags[i].tagName; // Changing line color if (i % 2 == 0) GUILayout.BeginHorizontal(gsLinePair); @@ -60,14 +60,14 @@ public override void OnInspectorGUI() GUI.Label(new Rect(EditorGUILayout.GetControlRect().x, EditorGUILayout.GetControlRect().y, EditorGUILayout.GetControlRect().width, 30), "Slot types:", titleStyle); for (int i = 0; i < Database.Instance.slotTypes.Count; i++) { - string slotType = Database.Instance.slotTypes[i]; + SlotType slotType = Database.Instance.slotTypes[i]; // Changing line color if (i % 2 == 0) GUILayout.BeginHorizontal(gsLinePair); else GUILayout.BeginHorizontal(gsLineOdd); Rect rect = EditorGUILayout.GetControlRect(); - GUI.Label(rect, slotType); + GUI.Label(rect, slotType.slotName); GUILayout.EndHorizontal(); } GUILayout.EndVertical(); diff --git a/Assets/TRPGMaker/Editor/ItemEditor.cs b/Assets/TRPGMaker/Editor/ItemEditor.cs index 7e20431..569078f 100644 --- a/Assets/TRPGMaker/Editor/ItemEditor.cs +++ b/Assets/TRPGMaker/Editor/ItemEditor.cs @@ -37,8 +37,6 @@ private void OnEnable() { // Remove button removeTexture = (Texture2D)Resources.Load("Buttons/remove", typeof(Texture2D)); - removeStyle = new GUIStyle("Button"); - removeStyle.padding = new RectOffset(2, 2, 2, 2); // Get Formulas listFormulas = new ReorderableList(serializedObject, @@ -48,7 +46,7 @@ private void OnEnable() // Draw formulas listFormulas.drawElementCallback = (Rect rect, int index, bool isActive, bool isFocused) => { - var element = listFormulas.serializedProperty.GetArrayElementAtIndex(index); + //var element = listFormulas.serializedProperty.GetArrayElementAtIndex(index); var formula = item.formulas[index]; rect.y += 2; @@ -101,6 +99,9 @@ private void OnEnable() public override void OnInspectorGUI() { + removeStyle = new GUIStyle("Button"); + removeStyle.padding = new RectOffset(2, 2, 2, 2); + if (dropDown == null) Init(); @@ -158,13 +159,12 @@ public override void OnInspectorGUI() { for (int j = 0; j < item.SlotType[i].slotsOcupped.Count; j++) { - SerializedProperty property = serializedObject.FindProperty("SlotType").GetArrayElementAtIndex(i).FindPropertyRelative("slotsOcupped").GetArrayElementAtIndex(j); - + //SerializedProperty property = serializedObject.FindProperty("SlotType").GetArrayElementAtIndex(i).FindPropertyRelative("slotsOcupped").GetArrayElementAtIndex(j); EditorGUI.BeginChangeCheck(); GUILayout.BeginHorizontal(); - int selectedIndex = Database.Instance.slotTypes.IndexOf(property.stringValue); + int selectedIndex = Database.Instance.slotTypes.IndexOf(item.SlotType[i].slotsOcupped[j]); Rect rectPopup = EditorGUILayout.GetControlRect(); - selectedIndex = EditorGUI.Popup(rectPopup, selectedIndex, Database.Instance.slotTypes.ToArray()); + selectedIndex = EditorGUI.Popup(rectPopup, selectedIndex, Database.Instance.slotTypes.Select(x => x.slotName).ToArray()); if (GUILayout.Button(new GUIContent("", removeTexture), removeStyle, GUILayout.MaxHeight(16), GUILayout.MaxWidth(16))) { @@ -173,7 +173,7 @@ public override void OnInspectorGUI() GUILayout.EndHorizontal(); if (EditorGUI.EndChangeCheck() && selectedIndex != -1) { - property.stringValue = Database.Instance.slotTypes[selectedIndex]; + item.SlotType[i].slotsOcupped[j] = Database.Instance.slotTypes[selectedIndex]; } if (j != item.SlotType[i].slotsOcupped.Count - 1) GUILayout.Label("AND", centeredStyle); @@ -182,7 +182,7 @@ public override void OnInspectorGUI() GUILayout.BeginHorizontal(); if (GUILayout.Button(new GUIContent("", addTexture), removeStyle, GUILayout.MaxHeight(16), GUILayout.MaxWidth(16))) { - item.SlotType[i].slotsOcupped.Add(""); + item.SlotType[i].slotsOcupped.Add(new SlotType("")); serializedObject.Update(); } GUILayout.EndHorizontal(); @@ -249,8 +249,8 @@ void dropDownSearch() if (tag.LastIndexOf(',') != -1) tag = tag.Substring(tag.LastIndexOf(',') + 1, tag.Length - tag.LastIndexOf(',') - 1); // Search in Database - if (tag.Trim() != "" && r.ToLower().Contains(tag.ToLower())) - dropDownList.Add(r); + if (tag.Trim() != "" && r.tagName.ToLower().Contains(tag.ToLower())) + dropDownList.Add(r.tagName); } } dropDown.Elements = dropDownList; @@ -261,11 +261,11 @@ void drawTags() dropDown.Value = ""; for(int i = 0; i < item.tags.Count; i++) { - string s = item.tags[i]; + Tag s = item.tags[i]; // If tag removed from database: if (!Database.Instance.tags.Contains(s)) item.tags.Remove(s); - dropDown.Value += s + ","; + dropDown.Value += s.tagName + ","; } if (dropDown.Value.Length > 0) dropDown.Value = dropDown.Value.Substring(0, dropDown.Value.Length - 1); // Remove last , @@ -274,7 +274,7 @@ void drawTags() void saveTagsInDatabase() { string tagsTemp = dropDown.Value; - item.tags = new List(); + item.tags = new List(); if (tagsTemp.Trim() != "") { if (tagsTemp.IndexOf(',') != -1) @@ -293,18 +293,20 @@ void saveTagsInDatabase() void checkTagExistsInDatabaseAndStore(string tagName) { - if (!Database.Instance.tags.Contains(tagName)) + Tag tag = Database.Instance.tags.Find(x => x.tagName == tagName); + if (tag == null) { if (EditorUtility.DisplayDialog("Create new tag \'" + tagName + "\'?", "The tag \'" + tagName + "\' doesn't exists in Databes, you want to create this tag or remove froms tags assigned?", "Create", "Remove")) { - Database.Instance.tags.Add(tagName); - item.tags.Add(tagName); + tag = new Tag(tagName); + Database.Instance.tags.Add(tag); + item.tags.Add(tag); } } else { - item.tags.Add(tagName); + item.tags.Add(tag); } } } \ No newline at end of file diff --git a/Assets/TRPGMaker/Editor/SpecializedClassEditor.cs b/Assets/TRPGMaker/Editor/SpecializedClassEditor.cs index b3a6937..826e267 100644 --- a/Assets/TRPGMaker/Editor/SpecializedClassEditor.cs +++ b/Assets/TRPGMaker/Editor/SpecializedClassEditor.cs @@ -44,9 +44,7 @@ private void OnEnable() { // Remove button removeTexture = (Texture2D)Resources.Load("Buttons/remove", typeof(Texture2D)); - removeStyle = new GUIStyle("Button"); - removeStyle.padding = new RectOffset(2, 2, 2, 2); - + // Get tags listTags = new ReorderableList(serializedObject, serializedObject.FindProperty("tags"), @@ -81,7 +79,7 @@ private void OnEnable() rect.y += 2; EditorGUI.LabelField( new Rect(rect.x, rect.y, rect.width, EditorGUIUtility.singleLineHeight), - specializedClass.tags[index]); + specializedClass.tags[index].tagName); if (GUI.Button(new Rect(rect.width, rect.y, 16, 16), new GUIContent("", removeTexture), removeStyle)) { @@ -94,17 +92,17 @@ private void OnEnable() (Rect rect, int index, bool isActive, bool isFocused) => { rect.y += 2; - slotTypeSelected = Database.Instance.slotTypes.IndexOf(specializedClass.slots[index].slotType); + slotTypeSelected = specializedClass.slots.IndexOf(specializedClass.slots[index]); slotItemSelected = Database.Instance.items.IndexOf(specializedClass.slots[index].modifier); EditorGUI.BeginChangeCheck(); EditorGUI.LabelField(new Rect(rect.x, rect.y, 60, EditorGUIUtility.singleLineHeight), "Slot type:"); - slotTypeSelected = EditorGUI.Popup(new Rect(rect.x + 63, rect.y, 100, EditorGUIUtility.singleLineHeight), slotTypeSelected, Database.Instance.slotTypes.ToArray()); + slotTypeSelected = EditorGUI.Popup(new Rect(rect.x + 63, rect.y, 100, EditorGUIUtility.singleLineHeight), slotTypeSelected, Database.Instance.slotTypes.Select(x => x.slotName).ToArray()); EditorGUI.LabelField(new Rect(rect.x + 170, rect.y, 35, EditorGUIUtility.singleLineHeight), "Item:"); slotItemSelected = EditorGUI.Popup(new Rect(rect.x + 208, rect.y, rect.width - 238, EditorGUIUtility.singleLineHeight), slotItemSelected, Database.Instance.items.Select(s => (string)s.name).ToArray()); if (EditorGUI.EndChangeCheck()) { - if(slotTypeSelected != -1) + if(slotTypeSelected != 0) specializedClass.slots[index].slotType = Database.Instance.slotTypes[slotTypeSelected]; if(slotItemSelected != -1) specializedClass.slots[index].modifier = Database.Instance.items[slotItemSelected]; @@ -129,9 +127,27 @@ private void OnEnable() rectL.height = EditorGUIUtility.singleLineHeight; rectL.x += 15; rectL.y += EditorGUIUtility.singleLineHeight; + GUI.SetNextControlName("Value"); EditorGUI.PropertyField(rectL, element.FindPropertyRelative("value")); + if (GUI.GetNameOfFocusedControl() != "Value" && specializedClass.attributes[index].value > specializedClass.attributes[index].maxValue) + { + if (EditorUtility.DisplayDialog("Value error!", + "The value introduced is greater than the max value", "Ok")) + { + specializedClass.attributes[index].value = 0; + } + } rectL.y += EditorGUIUtility.singleLineHeight; + GUI.SetNextControlName("MinValue"); EditorGUI.PropertyField(rectL, element.FindPropertyRelative("minValue")); + if (GUI.GetNameOfFocusedControl() != "MinValue" && specializedClass.attributes[index].minValue > specializedClass.attributes[index].maxValue) + { + if (EditorUtility.DisplayDialog("Value error!", + "The min value introduced is greater than the max value", "Ok")) + { + specializedClass.attributes[index].minValue = 0; + } + } rectL.y += EditorGUIUtility.singleLineHeight; EditorGUI.PropertyField(rectL, element.FindPropertyRelative("maxValue")); listAttributes.elementHeight = EditorGUIUtility.singleLineHeight * 4.0f + 4.0f; @@ -215,9 +231,9 @@ private void OnEnable() // Add tags listTags.onAddDropdownCallback = (Rect buttonRect, ReorderableList l) => { var menu = new GenericMenu(); - foreach (string tag in Database.Instance.tags) + foreach (Tag tag in Database.Instance.tags) { - menu.AddItem(new GUIContent(tag), + menu.AddItem(new GUIContent(tag.tagName), false, clickHandlerTags, tag); @@ -276,6 +292,9 @@ private void OnEnable() public override void OnInspectorGUI() { + removeStyle = new GUIStyle("Button"); + removeStyle.padding = new RectOffset(2, 2, 2, 2); + serializedObject.Update(); var customStyle = new GUIStyle(); @@ -330,7 +349,7 @@ private void clickHandlerAttributes(object target) private void clickHandlerTags(object target) { var data = (string) target; - specializedClass.tags.Add (data); + specializedClass.tags.Add (Database.Instance.tags.Find(x => x.tagName == data)); serializedObject.ApplyModifiedProperties(); } diff --git a/Assets/TRPGMaker/Editor/TeamEditor.cs b/Assets/TRPGMaker/Editor/TeamEditor.cs index 9638d20..58fa003 100644 --- a/Assets/TRPGMaker/Editor/TeamEditor.cs +++ b/Assets/TRPGMaker/Editor/TeamEditor.cs @@ -16,8 +16,6 @@ private void OnEnable() { // Remove button removeTexture = (Texture2D)Resources.Load("Buttons/remove", typeof(Texture2D)); - removeStyle = new GUIStyle("Button"); - removeStyle.padding = new RectOffset(2, 2, 2, 2); // Get characters listCharacters = new ReorderableList(serializedObject, @@ -68,6 +66,9 @@ private void OnEnable() public override void OnInspectorGUI() { + removeStyle = new GUIStyle("Button"); + removeStyle.padding = new RectOffset(2, 2, 2, 2); + Team team = (Team)target; // Clean array if there are null objects for (int i = 0; i < team.characters.Count; i++) diff --git a/Assets/TRPGMaker/Editor/Windows/Database/AttributesWindow.cs b/Assets/TRPGMaker/Editor/Windows/Database/AttributesWindow.cs index d9b291b..a8411d8 100644 --- a/Assets/TRPGMaker/Editor/Windows/Database/AttributesWindow.cs +++ b/Assets/TRPGMaker/Editor/Windows/Database/AttributesWindow.cs @@ -17,12 +17,13 @@ public override void Init() // Remove button removeTexture = (Texture2D)Resources.Load("Buttons/remove", typeof(Texture2D)); - removeStyle = new GUIStyle("Button"); - removeStyle.padding = new RectOffset(2, 2, 2, 2); } public override void Draw(Rect rect) - { + { + removeStyle = new GUIStyle("Button"); + removeStyle.padding = new RectOffset(2, 2, 2, 2); + editor.serializedObject.Update(); GUILayout.BeginVertical(); @@ -86,7 +87,7 @@ private void createReorderableList() // Add attributes listAttributes.onAddDropdownCallback = (Rect buttonRect, ReorderableList l) => { - Database.Instance.attributes.Add(new Attribute("New Attribute " + Database.Instance.attributes.Count.ToString("D3"), Database.Instance.attributes.Count.ToString("D3"), "", false)); + Database.Instance.attributes.Add(new Attribute("New Attribute " + Database.Instance.attributes.Count.ToString("D3"), "X" + Database.Instance.attributes.Count.ToString("D2"), "", false)); }; } diff --git a/Assets/TRPGMaker/Editor/Windows/Database/CharacterWindow.cs b/Assets/TRPGMaker/Editor/Windows/Database/CharacterWindow.cs index 62d470a..a275678 100644 --- a/Assets/TRPGMaker/Editor/Windows/Database/CharacterWindow.cs +++ b/Assets/TRPGMaker/Editor/Windows/Database/CharacterWindow.cs @@ -48,11 +48,17 @@ public void DrawMainView() GUILayout.BeginHorizontal(gsLinePair); else GUILayout.BeginHorizontal(gsLineOdd); - Rect rect = EditorGUILayout.GetControlRect(); + Rect rect = EditorGUILayout.GetControlRect(); GUI.Label(rect, character.name); + if (Event.current.type == EventType.MouseUp && rect.Contains(Event.current.mousePosition)) + { + editor = Editor.CreateEditor(character); + listCharacters.index = Database.Instance.characters.IndexOf(character); + } if (GUILayout.Button(new GUIContent("Edit"), GUILayout.Width(50))) { editor = Editor.CreateEditor(character); + listCharacters.index = Database.Instance.characters.IndexOf(character); } else if (GUILayout.Button(new GUIContent("Remove"), GUILayout.Width(90))) { diff --git a/Assets/TRPGMaker/Editor/Windows/Database/ItemWindow.cs b/Assets/TRPGMaker/Editor/Windows/Database/ItemWindow.cs index 79e13f2..977c0e3 100644 --- a/Assets/TRPGMaker/Editor/Windows/Database/ItemWindow.cs +++ b/Assets/TRPGMaker/Editor/Windows/Database/ItemWindow.cs @@ -50,8 +50,14 @@ public void DrawMainView() GUILayout.BeginHorizontal(gsLineOdd); Rect rect = EditorGUILayout.GetControlRect(); GUI.Label(rect, item.name); + if (Event.current.type == EventType.MouseUp && rect.Contains(Event.current.mousePosition)) + { + editor = Editor.CreateEditor(item); + listItems.index = Database.Instance.items.IndexOf(item); + } if (GUILayout.Button(new GUIContent("Edit"), GUILayout.Width(50))){ editor = Editor.CreateEditor(item); + listItems.index = Database.Instance.items.IndexOf(item); } else if (GUILayout.Button(new GUIContent("Remove"), GUILayout.Width(90))){ removeItem(item); diff --git a/Assets/TRPGMaker/Editor/Windows/Database/SkillsWindow.cs b/Assets/TRPGMaker/Editor/Windows/Database/SkillsWindow.cs index fe9da24..be6fad0 100644 --- a/Assets/TRPGMaker/Editor/Windows/Database/SkillsWindow.cs +++ b/Assets/TRPGMaker/Editor/Windows/Database/SkillsWindow.cs @@ -50,9 +50,15 @@ public void DrawMainView() GUILayout.BeginHorizontal(gsLineOdd); Rect rect = EditorGUILayout.GetControlRect(); GUI.Label(rect, skill.name); + if (Event.current.type == EventType.MouseUp && rect.Contains(Event.current.mousePosition)) + { + editor = Editor.CreateEditor(skill); + listSkills.index = Database.Instance.skills.IndexOf(skill); + } if (GUILayout.Button(new GUIContent("Edit"), GUILayout.Width(50))) { editor = Editor.CreateEditor(skill); + listSkills.index = Database.Instance.skills.IndexOf(skill); } else if (GUILayout.Button(new GUIContent("Remove"), GUILayout.Width(90))) { diff --git a/Assets/TRPGMaker/Editor/Windows/Database/SlotTypeWindow.cs b/Assets/TRPGMaker/Editor/Windows/Database/SlotTypeWindow.cs index 69d4e51..c300624 100644 --- a/Assets/TRPGMaker/Editor/Windows/Database/SlotTypeWindow.cs +++ b/Assets/TRPGMaker/Editor/Windows/Database/SlotTypeWindow.cs @@ -17,12 +17,13 @@ public override void Init() // Remove button removeTexture = (Texture2D)Resources.Load("Buttons/remove", typeof(Texture2D)); - removeStyle = new GUIStyle("Button"); - removeStyle.padding = new RectOffset(2, 2, 2, 2); } public override void Draw(Rect rect) - { + { + removeStyle = new GUIStyle("Button"); + removeStyle.padding = new RectOffset(2, 2, 2, 2); + editor.serializedObject.Update(); GUILayout.BeginVertical(); @@ -43,6 +44,7 @@ public override void Draw(Rect rect) EditorGUILayout.EndVertical(); editor.serializedObject.ApplyModifiedProperties(); + EditorUtility.SetDirty(Database.Instance); } private void createReorderableList() @@ -57,10 +59,11 @@ private void createReorderableList() // Draw slot types listSlotTypes.drawElementCallback = (Rect rect, int index, bool isActive, bool isFocused) => { - var element = listSlotTypes.serializedProperty.GetArrayElementAtIndex(index); - var textDimensions = GUI.skin.label.CalcSize(new GUIContent(element.stringValue)); - if (isActive) EditorGUI.PropertyField(new Rect(rect.x, rect.y, textDimensions.x + 5, rect.height), element, GUIContent.none, true); - else EditorGUI.LabelField(rect, element.stringValue); + //var element = listSlotTypes.serializedProperty.GetArrayElementAtIndex(index); + SlotType slotType = Database.Instance.slotTypes[index]; + var textDimensions = GUI.skin.label.CalcSize(new GUIContent(slotType.slotName)); + if (isActive) Database.Instance.slotTypes[index].slotName = EditorGUI.TextField(new Rect(rect.x, rect.y, textDimensions.x + 5, rect.height), slotType.slotName); + else EditorGUI.LabelField(rect, slotType.slotName); if (GUI.Button(new Rect(rect.width, rect.y, 16, 16), new GUIContent("", removeTexture), removeStyle)) { @@ -70,7 +73,7 @@ private void createReorderableList() // On new slot type listSlotTypes.onAddDropdownCallback = (Rect buttonRect, ReorderableList l) => { - Database.Instance.slotTypes.Add("New slot type"); + Database.Instance.slotTypes.Add(new SlotType("New slot type")); }; // listSlotType header diff --git a/Assets/TRPGMaker/Editor/Windows/Database/SpecializedClassWindow.cs b/Assets/TRPGMaker/Editor/Windows/Database/SpecializedClassWindow.cs index de9d537..6ce4a9f 100644 --- a/Assets/TRPGMaker/Editor/Windows/Database/SpecializedClassWindow.cs +++ b/Assets/TRPGMaker/Editor/Windows/Database/SpecializedClassWindow.cs @@ -50,9 +50,15 @@ public void DrawMainView() GUILayout.BeginHorizontal(gsLineOdd); Rect rect = EditorGUILayout.GetControlRect(); GUI.Label(rect, specializedClass.name); + if (Event.current.type == EventType.MouseUp && rect.Contains(Event.current.mousePosition)) + { + editor = Editor.CreateEditor(specializedClass); + listSpecializedClass.index = Database.Instance.specializedClasses.IndexOf(specializedClass); + } if (GUILayout.Button(new GUIContent("Edit"), GUILayout.Width(50))) { editor = Editor.CreateEditor(specializedClass); + listSpecializedClass.index = Database.Instance.specializedClasses.IndexOf(specializedClass); } else if (GUILayout.Button(new GUIContent("Remove"), GUILayout.Width(90))) { diff --git a/Assets/TRPGMaker/Editor/Windows/Database/TagWindow.cs b/Assets/TRPGMaker/Editor/Windows/Database/TagWindow.cs index 3c3c244..eeda7a4 100644 --- a/Assets/TRPGMaker/Editor/Windows/Database/TagWindow.cs +++ b/Assets/TRPGMaker/Editor/Windows/Database/TagWindow.cs @@ -17,12 +17,13 @@ public override void Init() // Remove button removeTexture = (Texture2D)Resources.Load("Buttons/remove", typeof(Texture2D)); - removeStyle = new GUIStyle("Button"); - removeStyle.padding = new RectOffset(2, 2, 2, 2); } public override void Draw(Rect rect) - { + { + removeStyle = new GUIStyle("Button"); + removeStyle.padding = new RectOffset(2, 2, 2, 2); + editor.serializedObject.Update(); GUILayout.BeginVertical(); @@ -34,7 +35,7 @@ public override void Draw(Rect rect) EditorGUILayout.BeginVertical(); scrollPosition = EditorGUILayout.BeginScrollView(scrollPosition); - + listTags.DoLayoutList(); GUILayout.EndVertical(); @@ -47,7 +48,7 @@ public override void Draw(Rect rect) private void createReorderableList() { - editor = Editor.CreateEditor(Database.Instance); + editor = Editor.CreateEditor(Database.Instance); // Get tags listTags = new ReorderableList(editor.serializedObject, @@ -57,10 +58,11 @@ private void createReorderableList() // Draw tags listTags.drawElementCallback = (Rect rect, int index, bool isActive, bool isFocused) => { - var element = listTags.serializedProperty.GetArrayElementAtIndex(index); - var textDimensions = GUI.skin.label.CalcSize(new GUIContent(element.stringValue)); - if (isActive) EditorGUI.PropertyField(new Rect(rect.x, rect.y, textDimensions.x + 5, rect.height), element, GUIContent.none, true); - else EditorGUI.LabelField(rect, element.stringValue); + //var element = listTags.serializedProperty.GetArrayElementAtIndex(index); + Tag tag = Database.Instance.tags[index]; + var textDimensions = GUI.skin.label.CalcSize(new GUIContent(tag.tagName)); + if (isActive) Database.Instance.tags[index].tagName = EditorGUI.TextField(new Rect(rect.x, rect.y, textDimensions.x + 5, rect.height), tag.tagName); + else EditorGUI.LabelField(rect, tag.tagName); if (GUI.Button(new Rect(rect.width, rect.y, 16, 16), new GUIContent("", removeTexture), removeStyle)) { @@ -70,7 +72,7 @@ private void createReorderableList() // On new tag listTags.onAddDropdownCallback = (Rect buttonRect, ReorderableList l) => { - Database.Instance.tags.Add("New tag"); + Database.Instance.tags.Add(new Tag("New tag")); }; // listTags header diff --git a/Assets/TRPGMaker/Editor/Windows/Database/TeamsWindow.cs b/Assets/TRPGMaker/Editor/Windows/Database/TeamsWindow.cs index 67ceefd..142511d 100644 --- a/Assets/TRPGMaker/Editor/Windows/Database/TeamsWindow.cs +++ b/Assets/TRPGMaker/Editor/Windows/Database/TeamsWindow.cs @@ -49,9 +49,15 @@ public void DrawMainView() GUILayout.BeginHorizontal(gsLineOdd); Rect rect = EditorGUILayout.GetControlRect(); GUI.Label(rect, team.id + ": " + team.name); + if (Event.current.type == EventType.MouseUp && rect.Contains(Event.current.mousePosition)) + { + editor = Editor.CreateEditor(team); + listTeams.index = Database.Instance.teams.IndexOf(team); + } if (GUILayout.Button(new GUIContent("Edit"), GUILayout.Width(50))) { editor = Editor.CreateEditor(team); + listTeams.index = Database.Instance.teams.IndexOf(team); } else if (GUILayout.Button(new GUIContent("Remove"), GUILayout.Width(90))) { diff --git a/Assets/TRPGMaker/Scripts/Database/Character.cs b/Assets/TRPGMaker/Scripts/Database/Character.cs index f721a04..cbf7809 100644 --- a/Assets/TRPGMaker/Scripts/Database/Character.cs +++ b/Assets/TRPGMaker/Scripts/Database/Character.cs @@ -64,9 +64,14 @@ public void calculateFormulas() { foreach(Formula formula in slot.modifier.formulas) { - f.formula = formula.formula; - var r = f.FormulaParser.Evaluate(attributes); - attributesWithFormulas.Find(x => x.attribute.id == formula.attributeID).value += (int) r; + f.formula = formula.formula; + if (f.FormulaParser.IsValidExpression) + { + var r = f.FormulaParser.Evaluate(attributes); + AttributeValue attrbValue = attributesWithFormulas.Find(x => x.attribute.id == formula.attributeID); + if(attrbValue != null) + attributesWithFormulas.Find(x => x.attribute.id == formula.attributeID).value += (int)r; + } } } // Formulas in slots of specialized classes @@ -76,9 +81,12 @@ public void calculateFormulas() { foreach (Formula formula in slot.modifier.formulas) { - f.formula = formula.formula; - var r = f.FormulaParser.Evaluate(attributes); - attributesWithFormulas.Find(x => x.attribute.id == formula.attributeID).value += (int)r; + if (f.FormulaParser.IsValidExpression) + { + f.formula = formula.formula; + var r = f.FormulaParser.Evaluate(attributes); + attributesWithFormulas.Find(x => x.attribute.id == formula.attributeID).value += (int)r; + } } } } diff --git a/Assets/TRPGMaker/Scripts/Database/Database.cs b/Assets/TRPGMaker/Scripts/Database/Database.cs index ea6b238..cd9d615 100644 --- a/Assets/TRPGMaker/Scripts/Database/Database.cs +++ b/Assets/TRPGMaker/Scripts/Database/Database.cs @@ -8,8 +8,8 @@ public class Database : ScriptableObject { private static Database _instance; public List attributes; - public List tags; - public List slotTypes; + public List tags; + public List slotTypes; public List items; public List specializedClasses; public List characters; @@ -32,8 +32,8 @@ public TRPGOptions battleOptions public Database() { attributes = new List(); - tags = new List(); - slotTypes = new List(); + tags = new List(); + slotTypes = new List(); items = new List(); specializedClasses = new List(); characters = new List(); diff --git a/Assets/TRPGMaker/Scripts/Database/ItemSlot.cs b/Assets/TRPGMaker/Scripts/Database/ItemSlot.cs index 9f1f396..93d5031 100644 --- a/Assets/TRPGMaker/Scripts/Database/ItemSlot.cs +++ b/Assets/TRPGMaker/Scripts/Database/ItemSlot.cs @@ -22,7 +22,7 @@ public class ItemSlot : Slot { for (int i = 0; i < modifier.SlotType.Count; i++) { int pos = modifier.SlotType[i].slotsOcupped.FindIndex( - delegate (string slotType) + delegate (SlotType slotType) { return slotType == this.slotType; }); @@ -93,7 +93,7 @@ public class ItemSlot : Slot { for (int i = 0; i < modifier.SlotType.Count; i++) { int pos = modifier.SlotType[i].slotsOcupped.FindIndex( - delegate (string slotType) + delegate (SlotType slotType) { return slotType == this.slotType; }); diff --git a/Assets/TRPGMaker/Scripts/Database/Modifier.cs b/Assets/TRPGMaker/Scripts/Database/Modifier.cs index ad5e947..1e4d7f4 100644 --- a/Assets/TRPGMaker/Scripts/Database/Modifier.cs +++ b/Assets/TRPGMaker/Scripts/Database/Modifier.cs @@ -14,7 +14,7 @@ public class Modifier: ScriptableObject { public new string name = "Enter item name"; public string description = "Enter item description"; - public List tags = new List(); + public List tags = new List(); [SerializeField] private List _formulas = new List(); public List formulas @@ -37,10 +37,10 @@ public class SlotsOcupped { public SlotsOcupped() { - slotsOcupped = new List(); + slotsOcupped = new List(); } - public List slotsOcupped; + public List slotsOcupped; } public List SlotType = new List(1); diff --git a/Assets/TRPGMaker/Scripts/Database/Slot.cs b/Assets/TRPGMaker/Scripts/Database/Slot.cs index 05819a6..07cc0d2 100644 --- a/Assets/TRPGMaker/Scripts/Database/Slot.cs +++ b/Assets/TRPGMaker/Scripts/Database/Slot.cs @@ -6,7 +6,7 @@ [Serializable] public class Slot{ - public string slotType; + public SlotType slotType; public Modifier _modifier; public Modifier modifier @@ -35,7 +35,7 @@ public void setModifier(Modifier modifier) { for (int i = 0; i < modifier.SlotType.Count; i++) { int pos = modifier.SlotType[i].slotsOcupped.FindIndex( - delegate (string slotType) + delegate (SlotType slotType) { return slotType == this.slotType; }); @@ -106,7 +106,7 @@ public Boolean canEquip(Modifier modifier) for (int i = 0; i < modifier.SlotType.Count; i++) { int pos = modifier.SlotType[i].slotsOcupped.FindIndex( - delegate (string slotType) + delegate (SlotType slotType) { return slotType == this.slotType; }); diff --git a/Assets/TRPGMaker/Scripts/Database/SlotType.cs b/Assets/TRPGMaker/Scripts/Database/SlotType.cs index 5687047..c0ebc07 100644 --- a/Assets/TRPGMaker/Scripts/Database/SlotType.cs +++ b/Assets/TRPGMaker/Scripts/Database/SlotType.cs @@ -4,7 +4,12 @@ using UnityEngine; [Serializable] -public class SlotType : ScriptableObject { +public class SlotType { - public string Name = "Enter slot type"; + public string slotName = "Enter slot type"; + + public SlotType(string name) + { + this.slotName = name; + } } diff --git a/Assets/TRPGMaker/Scripts/Database/SpecializedClass.cs b/Assets/TRPGMaker/Scripts/Database/SpecializedClass.cs index 1e1413d..34de106 100644 --- a/Assets/TRPGMaker/Scripts/Database/SpecializedClass.cs +++ b/Assets/TRPGMaker/Scripts/Database/SpecializedClass.cs @@ -10,7 +10,7 @@ public class SpecializedClass : ScriptableObject { public new string name; - public List tags; + public List tags; public List slots; public List attributes = null; public FormulaScript formula; @@ -18,7 +18,7 @@ public class SpecializedClass : ScriptableObject public void Init() { - tags = new List(); + tags = new List(); slots = new List(); formula = ScriptableObject.CreateInstance(); } diff --git a/Assets/TRPGMaker/Scripts/Database/Tag.cs b/Assets/TRPGMaker/Scripts/Database/Tag.cs new file mode 100644 index 0000000..24347cf --- /dev/null +++ b/Assets/TRPGMaker/Scripts/Database/Tag.cs @@ -0,0 +1,15 @@ +using System; +using System.Collections; +using System.Collections.Generic; +using UnityEngine; + +[Serializable] +public class Tag { + + public string tagName; + + public Tag(string name) + { + tagName = name; + } +} diff --git a/Assets/TRPGMaker/Scripts/Database/Tag.cs.meta b/Assets/TRPGMaker/Scripts/Database/Tag.cs.meta new file mode 100644 index 0000000..e15bfbd --- /dev/null +++ b/Assets/TRPGMaker/Scripts/Database/Tag.cs.meta @@ -0,0 +1,13 @@ +fileFormatVersion: 2 +guid: 147c564703a1b8248a927feba9863e7b +timeCreated: 1525618381 +licenseType: Free +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/TRPGMaker/Scripts/Game/CharacterScript.cs b/Assets/TRPGMaker/Scripts/Game/CharacterScript.cs index 0e1d41a..b7a4bb1 100644 --- a/Assets/TRPGMaker/Scripts/Game/CharacterScript.cs +++ b/Assets/TRPGMaker/Scripts/Game/CharacterScript.cs @@ -49,7 +49,6 @@ void Update() var calculate = false; if (s.modifier != null && !s.calculatedFormula) { - Debug.Log(s.modifier.name); calculate = true; s.calculatedFormula = true; } @@ -86,7 +85,11 @@ public override void OnInspectorGUI() EditorGUILayout.BeginHorizontal(); EditorGUILayout.LabelField("Team"); - if(characterScript.character != null) index = EditorGUILayout.Popup(index, Database.Instance.teams.Where(x => x.characters.Exists(y => y.name == characterScript.character.name)).Select(item => item.name).ToArray()); + if (characterScript.character != null) + { + //index = characters. + index = EditorGUILayout.Popup(index, Database.Instance.teams.Where(x => x.characters.Exists(y => y.name == characterScript.character.name)).Select(item => item.name).ToArray()); + } EditorGUILayout.EndHorizontal(); if (EditorGUI.EndChangeCheck()) { diff --git a/Assets/TRPGMaker/Scripts/Utils/FormulaParser.cs b/Assets/TRPGMaker/Scripts/Utils/FormulaParser.cs index 314515f..06e574a 100644 --- a/Assets/TRPGMaker/Scripts/Utils/FormulaParser.cs +++ b/Assets/TRPGMaker/Scripts/Utils/FormulaParser.cs @@ -96,7 +96,11 @@ private void CheckParameter(string param, ParameterArgs args) if (Database.Instance.attributes.Any(x => x.id == param)) { args.HasResult = true; - args.Result = attributes.Find(x => x.attribute.id == param).value; + AttributeValue attrValue = attributes.Find(x => x.attribute.id == param); + if (attrValue != null) + args.Result = attrValue.value; + else + args.Result = 0; } else {