Skip to content

Commit

Permalink
Slots, Tags and many fixes/improvements
Browse files Browse the repository at this point in the history
- Changed new attribute id to 'X00'
- Slots types by reference
- Tags by reference
- Name labels of objects lists in editor as button
- Alert if the attribute value is greater than the max value
- Fixed: calculating formulas in item that does not have an attribute
- Fixed: don't calculate formulas if is not valid expresion
- Fixed: delete button position in character attribute
- Fixed: many issues in editor
  • Loading branch information
WyrnCael committed May 6, 2018
1 parent 60405b4 commit d35ac30
Show file tree
Hide file tree
Showing 28 changed files with 264 additions and 142 deletions.
24 changes: 12 additions & 12 deletions Assets/Scenes/test.unity
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
7 changes: 2 additions & 5 deletions Assets/TRPGMaker/Database/Items/Axe.asset
Original file line number Diff line number Diff line change
Expand Up @@ -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: []
2 changes: 1 addition & 1 deletion Assets/TRPGMaker/Database/Items/Rod.asset
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,4 @@ MonoBehaviour:
icon: {fileID: 0}
SlotType:
- slotsOcupped:
- Right hand
- slotName:
6 changes: 1 addition & 5 deletions Assets/TRPGMaker/Database/Items/Sword.asset
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,4 @@ MonoBehaviour:
tags: []
_formulas: []
icon: {fileID: 2800000, guid: c547d731c4e32864b989aab9fe59d085, type: 3}
SlotType:
- slotsOcupped:
- Right hand
- slotsOcupped:
- Left hand
SlotType: []
99 changes: 61 additions & 38 deletions Assets/TRPGMaker/Editor/CharacterEditor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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];
Expand Down Expand Up @@ -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;
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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;
}
Expand Down
6 changes: 3 additions & 3 deletions Assets/TRPGMaker/Editor/DatabaseEditor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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();
Expand Down
38 changes: 20 additions & 18 deletions Assets/TRPGMaker/Editor/ItemEditor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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;

Expand Down Expand Up @@ -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();

Expand Down Expand Up @@ -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)))
{
Expand All @@ -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);
Expand All @@ -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();
Expand Down Expand Up @@ -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;
Expand All @@ -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 ,
Expand All @@ -274,7 +274,7 @@ void drawTags()
void saveTagsInDatabase()
{
string tagsTemp = dropDown.Value;
item.tags = new List<string>();
item.tags = new List<Tag>();
if (tagsTemp.Trim() != "")
{
if (tagsTemp.IndexOf(',') != -1)
Expand All @@ -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);
}
}
}
Loading

0 comments on commit d35ac30

Please sign in to comment.