Skip to content

Commit

Permalink
- Added multi-variable text display (you can now use as a formatter s…
Browse files Browse the repository at this point in the history
…omething like 'XP {0}/{1}', and use a MultiValueDisplayText component to provide multiple variables)

- Created structure to allow for in the future variables, literals or functions to be used as values for most things (internals)
- Added deprecated directories for scripts that will eventually be phased out
  • Loading branch information
DiogoDeAndrade committed Feb 26, 2024
1 parent 664e45c commit 6fd951a
Show file tree
Hide file tree
Showing 22 changed files with 633 additions and 2 deletions.
89 changes: 89 additions & 0 deletions Assets/OkapiKit/Scripts/Base/OkapiValue.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

namespace OkapiKit
{
[System.Serializable]
public struct OkapiValue
{
public enum Type { Float = 0, Integer = 1, VariableInstance = 2, Variable = 3 };

[SerializeField] private bool init;
[SerializeField] private Type type;
[SerializeField] private VariableInstance variableInstance;
[SerializeField] private Variable variable;
[SerializeField] private float floatValue;
[SerializeField] private int intValue;

public object GetRawValue()
{
switch (type)
{
case Type.Float:
return floatValue;
case Type.Integer:
return intValue;
case Type.VariableInstance:
return (variableInstance) ? (variableInstance.GetRawValue()) : (null);
case Type.Variable:
return (variable) ? (variable.GetRawValue()) : (null);
}

return null;
}

public string GetName()
{
switch (type)
{
case Type.Float:
break;
case Type.Integer:
break;
case Type.VariableInstance:
if (variableInstance != null) return variableInstance.name;
break;
case Type.Variable:
if (variable != null) return variable.name;
break;
default:
break;
}

return "unnamed";
}
}


[AttributeUsage(AttributeTargets.Field, Inherited = true, AllowMultiple = false)]
public class OVNoLabelAttribute : PropertyAttribute
{
}

[AttributeUsage(AttributeTargets.Field, Inherited = true, AllowMultiple = false)]
public class OVNoFloatAttribute : PropertyAttribute
{
}

[AttributeUsage(AttributeTargets.Field, Inherited = true, AllowMultiple = false)]
public class OVNoIntegerAttribute : PropertyAttribute
{
}

[AttributeUsage(AttributeTargets.Field, Inherited = true, AllowMultiple = false)]
public class OVNoVariableInstanceAttribute : PropertyAttribute
{
}

[AttributeUsage(AttributeTargets.Field, Inherited = true, AllowMultiple = false)]
public class OVNoVariableAttribute : PropertyAttribute
{
}

[AttributeUsage(AttributeTargets.Field, Inherited = true, AllowMultiple = false)]
public class OVNoFunctionAttribute : PropertyAttribute
{
}
}
11 changes: 11 additions & 0 deletions Assets/OkapiKit/Scripts/Base/OkapiValue.cs.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions Assets/OkapiKit/Scripts/Deprecated.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions Assets/OkapiKit/Scripts/Editor/ConditionDrawer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -231,9 +231,9 @@ public override void OnGUI(Rect position, SerializedProperty property, GUIConten
var r1 = propValueRect;
r1.height = r1.height / 3;
var r2 = r1;
r2.y = r1.bottom;
r2.y = r1.yMax;
var r3 = r1;
r3.y = r2.bottom;
r3.y = r2.yMax;

EditorGUI.PropertyField(r1, propComparisonValueHandler, GUIContent.none);
EditorGUI.PropertyField(r2, propComparisonVariable, GUIContent.none);
Expand Down
8 changes: 8 additions & 0 deletions Assets/OkapiKit/Scripts/Editor/Deprecated.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

87 changes: 87 additions & 0 deletions Assets/OkapiKit/Scripts/Editor/MultiValueDisplayEditor.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
using UnityEngine;
using UnityEditor;

namespace OkapiKit.Editor
{
[CustomEditor(typeof(MultiValueDisplay))]
public class MultiValueDisplayEditor : OkapiBaseEditor
{
protected SerializedProperty propValues;

protected virtual string typeOfDisplay { get; }

protected override void OnEnable()
{
base.OnEnable();

propValues = serializedObject.FindProperty("values");
}

public override void OnInspectorGUI()
{
serializedObject.Update();

if (WriteTitle())
{
StdEditor(false);
}
}

protected virtual void StdEditor(bool useOriginalEditor = true, bool isFinal = true)
{
EditorGUI.BeginChangeCheck();

EditorGUILayout.PropertyField(propValues, new GUIContent("Values", "Values to display.\nFirst of these will replace {0} on the format string, the second will replace {1} and so forth."), true);

if (isFinal)
{
EditorGUILayout.PropertyField(propDescription, new GUIContent("Description", "This is for you to leave a comment for yourself or others."), true);

EditorGUI.EndChangeCheck();

serializedObject.ApplyModifiedProperties();
(target as OkapiElement).UpdateExplanation();

// Draw old editor, need it for now
if (useOriginalEditor)
{
base.OnInspectorGUI();
}
}
}

protected override GUIStyle GetTitleSyle()
{
return GUIUtils.GetActionTitleStyle();
}

protected override GUIStyle GetExplanationStyle()
{
return GUIUtils.GetActionExplanationStyle();
}

protected override string GetTitle()
{
string varNames = "[UNDEFINED]";

// Get all var names
var t = target as MultiValueDisplay;
if (t != null)
{
varNames = t.GetVariableNames();
}

return $"Display {varNames} as {typeOfDisplay}";
}

protected override Texture2D GetIcon()
{
var varTexture = GUIUtils.GetTexture("VarDisplay");

return varTexture;
}

protected override (Color, Color, Color) GetColors() => (GUIUtils.ColorFromHex("#fffaa7"), GUIUtils.ColorFromHex("#2f4858"), GUIUtils.ColorFromHex("#ffdf6e"));

}
}
11 changes: 11 additions & 0 deletions Assets/OkapiKit/Scripts/Editor/MultiValueDisplayEditor.cs.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

22 changes: 22 additions & 0 deletions Assets/OkapiKit/Scripts/Editor/MultiValueDisplayTextEditor.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
using UnityEngine;
using UnityEditor;

namespace OkapiKit.Editor
{
[CustomEditor(typeof(MultiValueDisplayText))]
public class MultiValueDisplayTextEditor : MultiValueDisplayEditor
{
protected override string typeOfDisplay { get => "text"; }

protected override void OnEnable()
{
base.OnEnable();
}

protected override void StdEditor(bool useOriginalEditor = true, bool isFinal = true)
{
base.StdEditor(useOriginalEditor, true);
}

}
}
11 changes: 11 additions & 0 deletions Assets/OkapiKit/Scripts/Editor/MultiValueDisplayTextEditor.cs.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 6fd951a

Please sign in to comment.