Skip to content

Commit

Permalink
Node Unlock With Achievement Complete
Browse files Browse the repository at this point in the history
- Fixed map marking spawning and engine requirements
- Added node unlocking upon achievement completion (for stickers and normal)
- Fixed some minor issues with achievements

-Prepped the sticker postcard update for achievement and node unlocking
  • Loading branch information
Jacki3 committed Jul 22, 2024
1 parent 0d55056 commit 480d5b4
Show file tree
Hide file tree
Showing 24 changed files with 1,378 additions and 525 deletions.
35 changes: 32 additions & 3 deletions Assets/LUTE/Editor/AchievementEditor.cs
Original file line number Diff line number Diff line change
@@ -1,13 +1,18 @@
using System.Linq;
using MoreMountains.Tools;
using UnityEditor;
using UnityEngine;

[CustomEditor(typeof(Achievement))]
public class AchievementEditor : OrderEditor
{
protected SerializedProperty achievementProp;
protected SerializedProperty progressProp;
protected SerializedProperty amountProp;
protected SerializedProperty feedbackProp;
protected SerializedProperty targetEngineProp;
protected SerializedProperty nodeProp;
protected SerializedProperty startIndexProp;
protected SerializedProperty callModeProp;

protected int achievementIndex = 0;

Expand All @@ -17,6 +22,11 @@ public override void OnEnable()
achievementProp = serializedObject.FindProperty("achievementID");
progressProp = serializedObject.FindProperty("progress");
amountProp = serializedObject.FindProperty("amount");
feedbackProp = serializedObject.FindProperty("achievementFeedback");
targetEngineProp = serializedObject.FindProperty("targetEngine");
nodeProp = serializedObject.FindProperty("triggerNode");
startIndexProp = serializedObject.FindProperty("startIndex");
callModeProp = serializedObject.FindProperty("callMode");
}

public override void OnInspectorGUI()
Expand All @@ -27,7 +37,15 @@ public override void OnInspectorGUI()
public override void DrawOrderGUI()
{
Achievement t = target as Achievement;
var engine = (BasicFlowEngine)t.GetEngine();
BasicFlowEngine engine = null;
if (targetEngineProp.objectReferenceValue == null)
{
engine = (BasicFlowEngine)t.GetEngine();
}
else
{
engine = targetEngineProp.objectReferenceValue as BasicFlowEngine;
}

var achievements = engine.GetComponentInChildren<AchievementRules>().AchievementList.Achievements;

Expand All @@ -36,7 +54,7 @@ public override void DrawOrderGUI()
return;
}

if(achievements.Count == 0)
if (achievements.Count == 0)
{
return;
}
Expand All @@ -54,6 +72,17 @@ public override void DrawOrderGUI()

EditorGUILayout.PropertyField(progressProp);
EditorGUILayout.PropertyField(amountProp);
EditorGUILayout.PropertyField(feedbackProp);
EditorGUILayout.PropertyField(targetEngineProp);
if (engine != null)
{
NodeEditor.NodeField(nodeProp,
new GUIContent("Trigger Node", "Node to call when the achievement has completed"),
new GUIContent("<None>"),
engine);
EditorGUILayout.PropertyField(startIndexProp);
EditorGUILayout.PropertyField(callModeProp);
}

serializedObject.ApplyModifiedProperties();
}
Expand Down
94 changes: 94 additions & 0 deletions Assets/LUTE/Editor/PostcardAchievementEditor.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
using UnityEditor;
using UnityEngine;

namespace LoGaCulture.LUTE
{
[CustomPropertyDrawer(typeof(PostcardAchievement))]
public class PostcardAchievementEditor : PropertyDrawer
{
private const string ExcludedPropertyName = "triggerNode";
public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
{
EditorGUI.BeginProperty(position, label, property);

SerializedProperty iterator = property.Copy();
bool enterChildren = true;
float yOffset = 0;

while (iterator.NextVisible(enterChildren))
{
enterChildren = false;

if (ShouldSkipProperty(iterator))
{
// Then, find the BasicFlowEngine in the scene
BasicFlowEngine engine = UnityEngine.Object.FindObjectOfType<BasicFlowEngine>();
if (engine != null)
{
// Find all the nodes on the engine
var nodes = engine.GetComponents<Node>();
// Create a dropdown with all the nodes
string[] nodeNames = new string[nodes.Length];
for (int i = 0; i < nodes.Length; i++)
{
nodeNames[i] = nodes[i]._NodeName;
}
int index = 0;
for (int i = 0; i < nodes.Length; i++)
{
if (nodes[i]._NodeName == property.FindPropertyRelative("triggerNode").stringValue)
{
index = i;
break;
}
}
index = EditorGUI.Popup(new Rect(position.x, position.y + yOffset, position.width, EditorGUIUtility.singleLineHeight), "Trigger Node", index, nodeNames);
property.FindPropertyRelative("triggerNode").stringValue = nodes[index]._NodeName;
yOffset += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
}
continue;
}

float propertyHeight = EditorGUI.GetPropertyHeight(iterator, true);
Rect propertyRect = new Rect(position.x, position.y + yOffset, position.width, propertyHeight);

EditorGUI.PropertyField(propertyRect, iterator, true);
yOffset += propertyHeight + EditorGUIUtility.standardVerticalSpacing;
}

EditorGUI.EndProperty();
}

private bool ShouldSkipProperty(SerializedProperty property)
{
// Skip based on name
if (property.name == ExcludedPropertyName)
{
return true;
}

return false;
}

private void DrawNodeDrawer()
{

}

public override float GetPropertyHeight(SerializedProperty property, GUIContent label)
{
float totalHeight = EditorGUIUtility.singleLineHeight * 5; // Start with the height of a single line (with room for the foldout)

SerializedProperty iterator = property.Copy();
bool hasNext = iterator.NextVisible(true); // Move to the first visible property

while (hasNext)
{
totalHeight += EditorGUI.GetPropertyHeight(iterator, GUIContent.none, true); // Add the height of each property
hasNext = iterator.NextVisible(false); // Move to the next visible property
}

return totalHeight;
}
}
}
11 changes: 11 additions & 0 deletions Assets/LUTE/Editor/PostcardAchievementEditor.cs.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/LUTE/Resources/Prefabs/DialogueBox.prefab
Original file line number Diff line number Diff line change
Expand Up @@ -456,8 +456,8 @@ MonoBehaviour:
m_OnCullStateChanged:
m_PersistentCalls:
m_Calls: []
m_Sprite: {fileID: 21300000, guid: a40a8a612d16d75488b04df9b35f0d5a, type: 3}
m_Type: 0
m_Sprite: {fileID: 21300000, guid: e1a3eb9f5e3e01442b217b187003ad62, type: 3}
m_Type: 1
m_PreserveAspect: 0
m_FillCenter: 1
m_FillMethod: 4
Expand Down
6 changes: 3 additions & 3 deletions Assets/LUTE/Scripts/Orders/NextNode.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using UnityEngine;
using System;
using System.Collections.Generic;
using UnityEngine;

/// Supported modes for calling a node.
public enum CallMode
Expand Down Expand Up @@ -78,7 +78,7 @@ public override void OnEnter()
{
StopParentNode();
}
// Execute block in another Flowchart
// Execute block in another Engine
targetEngine.ExecuteNode(targetNode, index, onComplete);
}
}
Expand Down Expand Up @@ -118,7 +118,7 @@ public override string GetSummary()
return summary;
}

public override Color GetButtonColour()
public override Color GetButtonColour()
{
return new Color32(58, 185, 97, 255);
}
Expand Down
126 changes: 103 additions & 23 deletions Assets/LUTE/Scripts/Orders/UserCreated/Achievement.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
using MoreMountains.Feedbacks;
using System;
using UnityEngine;

[OrderInfo("Adventure",
Expand All @@ -6,32 +8,110 @@
[AddComponentMenu("")]
public class Achievement : Order
{
[Tooltip("The ID of the achievement or quest")]
[SerializeField] protected string achievementID;
[Tooltip("If true, will add progress to the achievement, if false, will unlock it")]
[SerializeField] protected bool progress;
[Tooltip("The amount of progress to add")]
[SerializeField] protected int amount = 1;
public override void OnEnter()
{
if (string.IsNullOrEmpty(achievementID))
[Tooltip("The ID of the achievement or quest")]
[SerializeField] protected string achievementID;
[Tooltip("If true, will add progress to the achievement, if false, will unlock it")]
[SerializeField] protected bool progress;
[Tooltip("The amount of progress to add")]
[SerializeField] protected int amount = 1;
[Tooltip("Feedback to play when the achievement is updated")]
[SerializeField] protected MMFeedbacks achievementFeedback;
[Tooltip("Engine which contains the node to execute upon achievement complete. If none is specified then the current engine is used")]
[SerializeField] protected BasicFlowEngine targetEngine;
[Tooltip("The node to trigger after the achievement is complete")]
[SerializeField] protected Node triggerNode;
[Tooltip("Order index to start executing")]
[SerializeField] protected int startIndex;
[Tooltip("Select if the calling node should stop or continue executing orders, or wait until the called node finishes.")]
[SerializeField] protected CallMode callMode;

public override void OnEnter()
{
Debug.LogError("Achievement ID is missing!");
return;
if (string.IsNullOrEmpty(achievementID))
{
Debug.LogError("Achievement ID is missing!");
return;
}

var achievementRules = GetEngine().GetComponentInChildren<AchievementRules>();

if (achievementRules == null)
{
return;
}
achievementRules.GenericEvent(achievementID, progress, amount);
achievementFeedback?.PlayFeedbacks();
if (triggerNode != null)
{
//are we calling our own parent node?
if (ParentNode != null && ParentNode.Equals(triggerNode))
{
//if so, just execute the first order and ignore the call
Continue(0);
return;
}

if (triggerNode.IsExecuting())
{
Debug.LogWarning(triggerNode._NodeName + " cannot be called/executed, it is already running.");
Continue();
return;
}

Action onComplete = null;
if (callMode == CallMode.WaitUntilFinished)
{
onComplete = delegate ()
{
Continue();
};
}

int index = startIndex;

if (targetEngine == null || targetEngine.Equals(GetEngine()))
{
if (callMode == CallMode.StopThenCall)
{
StopParentNode();
}
StartCoroutine(triggerNode.Execute(index, onComplete));
}
else
{
if (callMode == CallMode.StopThenCall)
{
StopParentNode();
}
// Execute node in another Engine
targetEngine.ExecuteNode(triggerNode, index, onComplete);
}

if (callMode == CallMode.Stop)
{
StopParentNode();
}
else if (callMode == CallMode.Continue)
{
Continue();
}
}
// If no trigger node is specified, just continue
Continue();
}

var achievementRules = GetEngine().GetComponentInChildren<AchievementRules>();
public override string GetSummary()
{
return "Achievement: " + achievementID + " " + (progress ? "Progress" : "Unlock");
}

if (achievementRules == null)
public override void GetConnectedNodes(ref System.Collections.Generic.List<Node> connectedNodes)
{
return;
if (triggerNode != null)
{
connectedNodes.Add(triggerNode);
}
}
achievementRules.GenericEvent(achievementID, progress, amount);
Continue();
}

public override string GetSummary()
{
return "Achievement: " + achievementID + " " + (progress ? "Progress" : "Unlock");
}
}
}


1 change: 0 additions & 1 deletion Assets/LUTE/Scripts/Orders/UserCreated/AddItem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ public override void OnEnter()
var inventory = item.TargetInventory("Player1");
if(inventory != null && inventory.InventoryContains(item.ItemID).Count > 0)
{
Debug.Log("Item already in inventory");
// If there is an inventory and there inventory already contains this item then move on
Continue();
return;
Expand Down
2 changes: 1 addition & 1 deletion Assets/LUTE/Scripts/Util/AchievementItem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public virtual void SetAchievement(string title, string description, Sprite imag

protected virtual void Update()
{
foreach (MMAchievement achievement in achievements)
foreach (MMAchievement achievement in MMAchievementManager.AchievementsList)
{
if (achievement.AchievementID == achievementID)
{
Expand Down
Loading

0 comments on commit 480d5b4

Please sign in to comment.