Skip to content

Commit

Permalink
- Added else actions to OnInput
Browse files Browse the repository at this point in the history
- Else actions on OnCondition weren't displaying warnings/errors
  • Loading branch information
DiogoDeAndrade committed Jan 27, 2024
1 parent 1b0c0ee commit 7c507a4
Show file tree
Hide file tree
Showing 10 changed files with 144 additions and 15 deletions.
4 changes: 2 additions & 2 deletions Assets/OkapiKit/Scripts/Editor/TriggerEditor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ protected void StdEditor(bool useOriginalEditor = true, bool allowConditions = t

}

protected void ActionPanel()
protected void ActionPanel(string title = "Actions")
{
serializedObject.ApplyModifiedProperties();
serializedObject.Update();
Expand All @@ -80,7 +80,7 @@ protected void ActionPanel()

TryDragActionToActionDelayList(actionsRect, propActions);

EditorGUILayout.PropertyField(propActions, new GUIContent("Actions", "These actions will be performed when this trigger is executed."), true);
EditorGUILayout.PropertyField(propActions, new GUIContent(title, "These actions will be performed when this trigger is executed."), true);

serializedObject.ApplyModifiedProperties();
(target as Trigger).UpdateExplanation();
Expand Down
35 changes: 34 additions & 1 deletion Assets/OkapiKit/Scripts/Editor/TriggerOnInputEditor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ public class TriggerOnInputEditor : TriggerEditor
SerializedProperty propNegate;
SerializedProperty propUseCooldown;
SerializedProperty propCooldown;
SerializedProperty propElseActions;

protected override void OnEnable()
{
Expand All @@ -31,6 +32,7 @@ protected override void OnEnable()
propNegate = serializedObject.FindProperty("negate");
propUseCooldown = serializedObject.FindProperty("useCooldown");
propCooldown = serializedObject.FindProperty("cooldown");
propElseActions = serializedObject.FindProperty("elseActions");
}

protected override Texture2D GetIcon()
Expand All @@ -54,17 +56,32 @@ public override void OnInspectorGUI()

TriggerOnInput.InputType inputType = (TriggerOnInput.InputType)propInputType.enumValueIndex;

string actionsName = "Actions when pressed";
string elseActionsName = "Actions when released";

EditorGUI.BeginChangeCheck();
EditorGUILayout.PropertyField(propInputType, new GUIContent("Input Type", "What kind of input we're detecting?"));
if (inputType == TriggerOnInput.InputType.Button)
{
EditorGUILayout.PropertyField(propButtonName, new GUIContent("Button Name", "Button name"));
EditorGUILayout.PropertyField(propContinuous, new GUIContent("Continuous", "If active, this triggers when the button is pressed, if not this trigger only executes when the key was just pressed."));

if (propContinuous.boolValue)
{
actionsName = "Actions while pressed";
elseActionsName = "Actions while released";
}
}
else if (inputType == TriggerOnInput.InputType.Key)
{
EditorGUILayout.PropertyField(propKey, new GUIContent("Key", "Key name"));
EditorGUILayout.PropertyField(propContinuous, new GUIContent("Continuous", "If active, this triggers when the button is pressed, if not this trigger only executes when the key was just pressed."));

if (propContinuous.boolValue)
{
actionsName = "Actions while pressed";
elseActionsName = "Actions while released";
}
}
else if (inputType == TriggerOnInput.InputType.Axis)
{
Expand All @@ -74,6 +91,11 @@ public override void OnInspectorGUI()
if ((propContinuous.boolValue) || (inputType == TriggerOnInput.InputType.Axis))
{
EditorGUILayout.PropertyField(propNegate, new GUIContent("Negate", "Do we want to trigger this when the input DOESN'T happen, instead of the other way around?"));
if (propNegate.boolValue)
{
actionsName = "Actions while not pressed";
elseActionsName = "Actions while pressed";
}
}

EditorGUILayout.PropertyField(propUseCooldown, new GUIContent("Use Cooldown", "Should we have a cooldown for this trigger?"));
Expand All @@ -84,7 +106,18 @@ public override void OnInspectorGUI()

EditorGUI.EndChangeCheck();

ActionPanel();
ActionPanel(actionsName);

var actionsRect = GUILayoutUtility.GetLastRect();
actionsRect = new Rect(actionsRect.xMin, actionsRect.yMax, actionsRect.width, 20.0f);

TryDragActionToActionDelayList(actionsRect, propElseActions);

EditorGUILayout.PropertyField(propElseActions, new GUIContent(elseActionsName, "What actions do we want while the input is not triggered"), true);

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

}
}
}
Expand Down
22 changes: 22 additions & 0 deletions Assets/OkapiKit/Scripts/Triggers/TriggerOnCondition.cs
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,28 @@ protected override void CheckErrors()
index++;
}
}

if ((elseActions != null) && (elseActions.Length > 0))
{
int index = 0;
foreach (var action in elseActions)
{
if (action.action == null)
{
_logs.Add(new LogEntry(LogEntry.Type.Warning, $"Else action {index} in not defined on else action list!", "Empty actions don't do anything, so either remove it or fill it in."));
}
else
{
action.action.ForceCheckErrors();
var actionLogs = action.action.logs;
foreach (var log in actionLogs)
{
_logs.Add(new LogEntry(log.type, $"On else action {index}: " + log.text, log.tooltip));
}
}
index++;
}
}
}

private void Update()
Expand Down
83 changes: 76 additions & 7 deletions Assets/OkapiKit/Scripts/Triggers/TriggerOnInput.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ public enum InputType { Button = 0, Key = 1, Axis = 2 };
private bool useCooldown = false;
[SerializeField]
private float cooldown = 1.0f;
[SerializeField]
protected ActionTrigger[] elseActions;

float cooldownTimer = 0.0f;

Expand Down Expand Up @@ -59,6 +61,18 @@ public override string GetRawDescription(string ident, GameObject refObject)
return desc;
}

protected override string Internal_UpdateExplanation()
{
base.Internal_UpdateExplanation();

if ((elseActions != null) && (elseActions.Length > 0))
{
_explanation += "else\n" + GetDescriptionActions(elseActions);
}

return _explanation;
}

void Update()
{
if (!isTriggerEnabled) return;
Expand All @@ -75,36 +89,91 @@ void Update()
}

bool isTrigger = false;
bool elseTrigger = false;
bool c = continuous;

if (inputType == InputType.Button)
{
isTrigger = (continuous) ? (Input.GetButton(buttonName)) : (Input.GetButtonDown(buttonName));
elseTrigger = (continuous) ? !(Input.GetButton(buttonName)) : (Input.GetButtonUp(buttonName));
}
else if (inputType == InputType.Key)
{
isTrigger = (continuous) ? (Input.GetKey(key)) : (Input.GetKeyDown(key));
elseTrigger = (continuous) ? (!Input.GetKey(key)) : (Input.GetKeyUp(key));
}
else if (inputType == InputType.Axis)
{
float a = Input.GetAxis(axis);
isTrigger = (a < deadArea.x) || (a > deadArea.y);
if (isTrigger)
{
int ba = 10;
ba++;
}
elseTrigger = !isTrigger;
c = true;
}

if ((c) && (negate)) isTrigger = !isTrigger;
if ((c) && (negate))
{
isTrigger = !isTrigger;
elseTrigger = !elseTrigger;
}

if (isTrigger)
{
ExecuteTrigger();

if (useCooldown) cooldownTimer = cooldown;
}
if (elseTrigger)
{
ExecuteElseTrigger();
}
}

public virtual void ExecuteElseTrigger()
{
if (!enableTrigger) return;

foreach (var action in elseActions)
{
if (action.action.isActionEnabled)
{
if (action.delay > 0)
{
StartCoroutine(ExecuteTriggerCR(action));
}
else
{
action.action.Execute();
}
}
}
}

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

if ((elseActions != null) && (elseActions.Length > 0))
{
int index = 0;
foreach (var action in elseActions)
{
if (action.action == null)
{
_logs.Add(new LogEntry(LogEntry.Type.Warning, $"Else action {index} in not defined on else action list!", "Empty actions don't do anything, so either remove it or fill it in."));
}
else
{
action.action.ForceCheckErrors();
var actionLogs = action.action.logs;
foreach (var log in actionLogs)
{
_logs.Add(new LogEntry(log.type, $"On else action {index}: " + log.text, log.tooltip));
}
}
index++;
}
}
}

}
}
}
4 changes: 2 additions & 2 deletions Assets/OkapiKit/package.json
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
{
"name": "com.videojogoslusofona.okapikit",
"displayName": "OkapiKit",
"version": "1.9.0",
"version": "1.9.1",
"unity": "2022.3",
"description": "OkapiKit is a toolkit for creation of simple games without code.",
"keywords": [ "kit" ],
"category": "kit",
"dependencies": {},
"author": {
"name": "Diogo de Andrade",
"name": "Diogo de Andrade - ULHT",
"url": "https://github.com/VideojogosLusofona"
}
}
Binary file modified Assets/OkapiKitSamples/Assets/Images/acid_drop.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 2 additions & 2 deletions Assets/OkapiKitSamples/package.json
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
{
"name": "com.videojogoslusofona.okapikit.samples",
"displayName": "OkapiKit Samples",
"version": "1.9.0",
"version": "1.9.1",
"unity": "2022.3",
"description": "OkapiKit is a toolkit for creation of simple games without code. This package is just the samples for OkapiKit, they are not required to use Okapi Kit, and requires the Okapi Kit package.",
"keywords": [ "okapi", "samples" ],
"category": "samples",
"dependencies": {},
"relatedPackages": {
"com.videojogoslusofona.okapikit": "1.9.0"
"com.videojogoslusofona.okapikit": "1.9.1"
},
"author": {
"name": "Diogo de Andrade - ULHT",
Expand Down
5 changes: 5 additions & 0 deletions ReleaseNotes.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
# Release Notes

## V1.9.1

- Added else actions to OnInput
- Else actions on OnCondition weren't displaying warnings/errors

## V1.9.0

- Added target tag and target object direction option to probe, to allow for maximum distance
Expand Down
Binary file modified Screenshots/platformer.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion Todo.txt
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
Features:
---------

- Unify ValueHandler/Value with single selector that can take any of them
- Movement targets should be redefinable
- Replace ranges used for random number generation with a "ValueSelector", which allows a literal, a range and a ValueHandler/Variable. The range can also use ValueHandler/Variable for the limits.
- Change numbers in most definitions (conditions, for example) by something that can be either a ValueHandler, a Variable, a literal, or a function, with a property drawer, etc
- Unify ValueHandler/Value with single selector that can take any of them
- Add HueShift/Outline effect for sprites
- Added debug system to Okapi
- Enable debug system for nodes
Expand Down

0 comments on commit 7c507a4

Please sign in to comment.