Skip to content

Commit

Permalink
Merge pull request #18 from Studio-23-xyz/choice-start
Browse files Browse the repository at this point in the history
Choice start
  • Loading branch information
BDeshiDev authored Apr 1, 2024
2 parents 7b33766 + 4099317 commit c515e06
Show file tree
Hide file tree
Showing 10 changed files with 1,303 additions and 258 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ private void DrawLocalizationStringHelperGUI(DialogueLineNodeBase dialogueLineNo
var defaultLocaleTable = collection.GetTable(DEFAULT_LOCALE) as StringTable;
if (defaultLocaleTable == null)
{
EditorGUILayout.HelpBox("No language Table", MessageType.Error);
EditorGUILayout.HelpBox("No Table for default locale", MessageType.Error);
return;
}
DrawCustomDialogueTextbox(defaultLocaleTable, dialogueLineNode, collection);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,12 @@ protected virtual void PrepareDialogueChoices()

protected virtual void GetAvailableChoices()
{
GetAllConnectedChoiceNodes();
FetchAllConnectedChoiceNodes();
RemoveUnavailableChoices();
}


protected virtual void GetAllConnectedChoiceNodes()
public List<DialogueChoiceNodeBase> FetchAllConnectedChoiceNodes()
{
if (_availableDialogueChoices == null)
{
Expand All @@ -55,6 +55,7 @@ protected virtual void GetAllConnectedChoiceNodes()
}

this.GetOutputNodesConnectedToPort("Choices", _availableDialogueChoices);
return _availableDialogueChoices;
}

private void SetChoiceIndices()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,19 @@
namespace Studio23.SS2.DialogueSystem.Data
{
[NodeTint("#006600"), CreateNodeMenu("DialogueStartNode")]
public class DialogueStartNode : DialogueLineNodeBase
public class DialogueStartNode : DialogueNodeBase
{
[Node.Output(typeConstraint = TypeConstraint.Strict, connectionType = ConnectionType.Override)]
public DialogueLineNodeBase Exit;
public override DialogueNodeBase GetNextNode()
{
NodePort outputPort = GetExitPort();
if (outputPort == null || outputPort.Connection == null)
{
return null;
}
return outputPort.Connection.node as DialogueNodeBase;
}
public override object GetValue(NodePort port)
{
if (port.fieldName == "Exit")
Expand All @@ -15,5 +26,25 @@ public override object GetValue(NodePort port)
}
return base.GetValue(port);
}

public override void HandleDialogueAdvance()
{
//do nothing
}

public override void HandleChoiceSelected(int choiceIndex)
{
//do nothing
}

public override UniTask Play()
{
return UniTask.CompletedTask;
}p

public override void Initialize()
{
//do nothing
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public class MustTakeAllChoicesBranch:DialogueChoicesNode

protected override void GetAvailableChoices()
{
GetAllConnectedChoiceNodes();
FetchAllConnectedChoiceNodes();
AddFinalChoiceIfAvailable();
RemoveUnavailableChoices();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,68 @@ public override void OnInspectorGUI()

EditorGUILayout.Space();

int emptyNodeNo = 0;
var prevColor = GUI.color;

// Loop through the nodes and create buttons for each
foreach (var node in startHelper.Graph.nodes)
{
if (node is DialogueStartNode startNode)
{
if (GUILayout.Button(startNode.DialogueLocalizedString.GetLocalizedStringInEditor()))
//draw button
var buttonGroup = EditorGUILayout.BeginVertical();
var buttonColor = startNode == startHelper.StartNode? Color.green: Color.grey;
GUI.color = buttonColor;

string buttonText;
//we need text desc of the start node
var nextNode = startNode.GetNextNode();
bool buttonPressed = false;
if (nextNode == null)
{
//this shouldn't happen
//but if it does just give a placeholder name
buttonText = $"<color=red>Empty StartNode{++emptyNodeNo}</color>";
buttonPressed = GUILayout.Button(buttonText);
}
else
{
//the method must work in editor
//I don't want to put unityeditor dependencies in the core
//so cast and handle it here.
if (nextNode is DialogueLineNodeBase dialogueLineNodeBase)
{
//if next node is dialogueLineNode, simply line text
buttonText = dialogueLineNodeBase.DialogueLocalizedString.GetLocalizedStringInEditor();
buttonPressed = GUILayout.Button(buttonText);

}else if(nextNode is DialogueChoicesNode dialogueChoicesNodeBase)
{
//if next node is a choice node
var choiceNodes = dialogueChoicesNodeBase.FetchAllConnectedChoiceNodes();

buttonText = $"Choices Branch with {choiceNodes.Count} choices)";
buttonPressed = GUILayout.Button(buttonText);

GUI.color = Color.yellow;
foreach (var dialogueChoiceNodeBase in choiceNodes)
{
GUILayout.Label(dialogueChoiceNodeBase.DialogueLocalizedString.GetLocalizedStringInEditor());
}
}
else
{
//unhandled case
//just put child name I guess
buttonText = $"<color=red>Empty StartNode{++emptyNodeNo} -> {nextNode.name}</color>";
buttonPressed = GUILayout.Button(buttonText);
}
}
EditorGUILayout.EndVertical();

GUI.color = prevColor;
//handle what happens when pressed
if (buttonPressed)
{
// If button is clicked, set the node and mark as dirty
Undo.RecordObject(startHelper, "Set Dialogue Node");
Expand Down
Loading

0 comments on commit c515e06

Please sign in to comment.