diff --git a/SpriteFontPlus.FNA.Core.csproj b/SpriteFontPlus.FNA.Core.csproj
--- a/SpriteFontPlus.FNA.Core.csproj
+++ b/SpriteFontPlus.FNA.Core.csproj
@@ -33,4 +33,8 @@
+
+
+
+
diff --git a/isometric-park-fna/Components/Dialog.cs b/isometric-park-fna/Components/Dialog.cs
--- a/isometric-park-fna/Components/Dialog.cs
+++ b/isometric-park-fna/Components/Dialog.cs
@@ -1,3 +1,4 @@
+using System.Collections.Generic;
using Microsoft.Xna.Framework;
@@ -9,7 +10,13 @@
namespace isometricparkfna.Components {
- public struct DialogComponent : IComponent {
- public Node Dialog;
+ public struct DialogComponent : IComponent/*, IHasEntity*/ {
+ public string Knot;
+ public string CurrentDialog;
+ public string CurrentSpeaker;
+ public List Options;
+ public bool Hydrated { get {
+ return (this.CurrentDialog != null)
+ && (this.CurrentSpeaker != null); }}
}
}
diff --git a/isometric-park-fna/Content/dialog.ink b/isometric-park-fna/Content/dialog.ink
new file mode 100644
--- /dev/null
+++ b/isometric-park-fna/Content/dialog.ink
@@ -0,0 +1,55 @@
+
+VAR GovernorOpinion = 0
+
+//This is needed to make both including and for jumpting to dialog sections work:
+=== placeholder ===
+
+-> END
+
+=== Once ===
+
+Once upon a time...
+
+ * There were two choices.
+ * There were four lines of content.
+
+- They lived happily ever after.
+ -> END
+
+
+=== IntroGovernor ===
+
+Governor: Welcome to your new park, director! You can use the mouse or arrow keys to move around, and the plus and minus keys to zoom in and out. B opens the budget and F lets you adjust Forest Policy.
+
+ * [Okay]
+
+ Governor: Make sure that you keep visitors happy and the budget in the black! You're currently getting an annual grant out of my budget—it'd sure be nice if you park were self-sufficient so we could drop that expense!
+
+ * * [And I need to keep the forest healthy, too, right?]
+ ~ GovernorOpinion = GovernorOpinion - 1
+
+
+ Governor: Ummm, yeah
+ * * * [\...]
+ -> END
+ * * [Sounds good!]
+ ~ GovernorOpinion = GovernorOpinion + 1
+
+
+ Governor: I'll check in soon.
+
+
+-> END
+
+
+=== IntroAssistant ===
+
+\#assistantName\#: \#whatever\#
+ * [Hi]
+
+ \#assistantName\#: Bye
+ -> END
+ * [How are you?]
+
+ \#assistantName\#: \#howdoing\#
+ -> END
\ No newline at end of file
diff --git a/isometric-park-fna/Content/dialog.json b/isometric-park-fna/Content/dialog.json
new file mode 100644
--- /dev/null
+++ b/isometric-park-fna/Content/dialog.json
@@ -0,0 +1,1 @@
+{"inkVersion":20,"root":[[["done",{"#f":5,"#n":"g-0"}],null],"done",{"placeholder":["end",{"#f":1}],"Once":[["^Once upon a time...","\n",["ev",{"^->":"Once.0.2.$r1"},{"temp=":"$r"},"str",{"->":".^.s"},[{"#n":"$r1"}],"/str","/ev",{"*":".^.^.c-0","flg":18},{"s":["^There were two choices.",{"->":"$r","var":true},null]}],["ev",{"^->":"Once.0.3.$r1"},{"temp=":"$r"},"str",{"->":".^.s"},[{"#n":"$r1"}],"/str","/ev",{"*":".^.^.c-1","flg":18},{"s":["^There were four lines of content.",{"->":"$r","var":true},null]}],{"c-0":["ev",{"^->":"Once.0.c-0.$r2"},"/ev",{"temp=":"$r"},{"->":".^.^.2.s"},[{"#n":"$r2"}],"\n",{"->":".^.^.g-0"},{"#f":5}],"c-1":["ev",{"^->":"Once.0.c-1.$r2"},"/ev",{"temp=":"$r"},{"->":".^.^.3.s"},[{"#n":"$r2"}],"\n",{"->":".^.^.g-0"},{"#f":5}],"g-0":["^They lived happily ever after.","\n","end",{"#f":5}]}],{"#f":1}],"IntroGovernor":[["^Governor: Welcome to your new park, director! You can use the mouse or arrow keys to move around, and the plus and minus keys to zoom in and out. B opens the budget and F lets you adjust Forest Policy.","\n","ev","str","^Okay","/str","/ev",{"*":".^.c-0","flg":20},{"c-0":["\n","^Governor: Make sure that you keep visitors happy and the budget in the black! You're currently getting an annual grant out of my budget—it'd sure be nice if you park were self-sufficient so we could drop that expense!","\n",["ev","str","^And I need to keep the forest healthy, too, right?","/str","/ev",{"*":".^.c-0","flg":20},"ev","str","^Sounds good!","/str","/ev",{"*":".^.c-1","flg":20},{"c-0":["^ ","\n","ev",{"VAR?":"GovernorOpinion"},1,"-","/ev",{"VAR=":"GovernorOpinion","re":true},"^Governor: Ummm, yeah","\n",["ev","str","^...","/str","/ev",{"*":".^.c-0","flg":20},{"c-0":["\n","end",{"#f":5}]}],{"#f":5}],"c-1":["\n","ev",{"VAR?":"GovernorOpinion"},1,"+","/ev",{"VAR=":"GovernorOpinion","re":true},"^Governor: I'll check in soon.","\n","end",{"#f":5}]}],{"#f":5}]}],{"#f":1}],"IntroAssistant":[["^#assistantName#: #whatever#","\n","ev","str","^Hi","/str","/ev",{"*":".^.c-0","flg":20},"ev","str","^How are you?","/str","/ev",{"*":".^.c-1","flg":20},{"c-0":["\n","^#assistantName#: Bye","\n","end",{"#f":5}],"c-1":["\n","^#assistantName#: #howdoing#","\n","end",{"#f":5}]}],{"#f":1}],"global decl":["ev",0,{"VAR=":"GovernorOpinion"},"/ev","end",null],"#f":1}],"listDefs":{}}
\ No newline at end of file
diff --git a/isometric-park-fna/Engines/DialogEngine.cs b/isometric-park-fna/Engines/DialogEngine.cs
new file mode 100644
--- /dev/null
+++ b/isometric-park-fna/Engines/DialogEngine.cs
@@ -0,0 +1,122 @@
+using System;
+using System.Text.RegularExpressions;
+using System.Linq;
+
+using Encompass;
+using Ink.Runtime;
+using TraceryNet;
+
+using isometricparkfna.Messages;
+using isometricparkfna.Components;
+
+namespace isometricparkfna.Engines
+{
+
+ [Receives(typeof(SetDialogMessage),
+ typeof(DialogChoiceMessage))]
+ [Reads(typeof(DialogComponent)) ]
+ [Writes( typeof(DialogComponent))]
+ class DialogEngine : Engine
+ {
+ public Story Story;
+ public Grammar Grammar;
+
+ public DialogEngine(Story story, Grammar grammar)
+ {
+ this.Story = story;
+ this.Grammar = grammar;
+ }
+
+ public override void Update(double dt)
+ {
+
+ foreach (ref readonly var dialogMessage in ReadMessages())
+ {
+ if (dialogMessage.newOption != null)
+ {
+ // SetComponent(dialogMessage.Entity,
+ // new DialogComponent {CurrentDialog = dialogMessage.newOption
+ // });
+ }
+ else
+ {
+ Destroy(dialogMessage.Entity);
+
+ }
+ }
+
+ foreach (ref readonly var choiceMessage in ReadMessages())
+ {
+
+ if (Story.currentChoices.Count > 0)
+ {
+ //Advance the story
+ Logging.Debug("Advancing story.");
+ Story.ChooseChoiceIndex(choiceMessage.Choice);
+
+ //Update the dialog component with the new speaker, dialog, and options:
+ var continuation = this.Grammar.Flatten(this.Story.ContinueMaximally());
+ var parts = Regex.Split(continuation, ":", 0);
+ var speaker = (parts.Length == 2) ? this.Grammar.Flatten(parts[0]) : "Dialog";
+ var dialog = (parts.Length == 2) ? this.Grammar.Flatten(parts[1]) : continuation;
+
+ SetComponent(choiceMessage.Entity, new DialogComponent {
+ CurrentDialog = dialog,
+ CurrentSpeaker = speaker,
+ Options = this.Story.currentChoices
+ .Select(option => option.text)
+ .ToList()});}
+ else
+ {
+ Logging.Debug(String.Format("Destroying Dialog (Entity ID {0}).", choiceMessage.Entity.ID));
+ Destroy(choiceMessage.Entity);
+
+ var lowestID = Int32.MaxValue;
+ Entity lowestEntity = default;
+
+
+ foreach(ref var entity in ReadEntities())
+ {
+ if ((entity.ID < lowestID)
+ //Don't try to use entity we just destroyed:
+ && (entity.ID != choiceMessage.Entity.ID)
+
+ && (!GetComponent(entity).Hydrated))
+ {
+ lowestID = entity.ID;
+ lowestEntity = entity;
+ Logging.Spy(lowestID, "ID");
+ }
+ }
+
+ if (lowestID != Int32.MaxValue
+ && EntityExists(lowestEntity))
+ {
+ Logging.Debug("Hydrating Dialog.");
+
+
+ var Knot = GetComponent(lowestEntity).Knot;
+
+ Story.ChoosePathString(Knot);
+ var continuation = this.Story.ContinueMaximally();
+ var parts = Regex.Split(continuation, ":", 0);
+ var speaker = (parts.Length == 2) ? this.Grammar.Flatten(parts[0]) : "Dialog";
+ var dialog = (parts.Length == 2) ? this.Grammar.Flatten(parts[1]) : continuation;
+ SetComponent(lowestEntity, new DialogComponent {
+ Knot = Knot,
+ CurrentDialog = dialog,
+ CurrentSpeaker = speaker,
+ Options = this.Story.currentChoices
+ .Select(option => option.text)
+ .ToList()});
+
+ }
+ }
+
+
+
+
+ }
+ }
+ }
+}
diff --git a/isometric-park-fna/Engines/ImGuiWindowBridgeEngine.cs b/isometric-park-fna/Engines/ImGuiWindowBridgeEngine.cs
--- a/isometric-park-fna/Engines/ImGuiWindowBridgeEngine.cs
+++ b/isometric-park-fna/Engines/ImGuiWindowBridgeEngine.cs
@@ -1,5 +1,6 @@
using System;
using System.Collections.Generic;
+using Encompass;
using System.Linq;
using Encompass;
@@ -23,13 +24,16 @@
typeof(SetTrespassingPolicyMessage),
typeof(SpawnGameMessage),
typeof(SetTextVariableMessage),
- typeof(SetDialogMessage))]
+ typeof(SetDialogMessage),
+ typeof(DialogChoiceMessage))]
[Reads(typeof(VisibilityComponent),
typeof(WindowTypeComponent),
typeof(TrespassingPolicyComponent),
typeof(ContractStatusComponent),
typeof(RelatedOrganizationComponent),
- typeof(NameAndDescriptionComponent))]
+ typeof(NameAndDescriptionComponent)
+ )]
+ // [Writes(typeof(SelectedComponent))]
public class ImGuiWindowBridgeEngine : Engine
{
@@ -45,6 +49,7 @@
public List spawnGameMessages;
public List setTextVariableMessages;
public List setDialogMessages;
+ public List dialogChoiceMessages;
bool showBudget {get;}
bool showForest {get;}
@@ -83,6 +88,7 @@
this.spawnGameMessages = new List();
this.setTextVariableMessages = new List();
this.setDialogMessages = new List();
+ this.dialogChoiceMessages = new List();
this.windowStatuses = new Dictionary();
this.showContractIndicator = false;
@@ -172,6 +178,10 @@
{
SendMessage(message);
}
+ foreach (var message in this.dialogChoiceMessages)
+ {
+ SendMessage(message);
+ }
@@ -220,6 +230,7 @@
this.spawnGameMessages.Clear();
this.setTextVariableMessages.Clear();
this.setDialogMessages.Clear();
+ this.dialogChoiceMessages.Clear();
}
}
}
diff --git a/isometric-park-fna/Engines/Spawners/DialogSpawner.cs b/isometric-park-fna/Engines/Spawners/DialogSpawner.cs
new file mode 100644
--- /dev/null
+++ b/isometric-park-fna/Engines/Spawners/DialogSpawner.cs
@@ -0,0 +1,85 @@
+
+
+using System;
+using System.Collections.Generic;
+using System.Text.RegularExpressions;
+using System.Linq;
+
+using Microsoft.Xna.Framework;
+
+using isometricparkfna.Messages;
+using isometricparkfna.Components;
+using static isometricparkfna.CellMap;
+using isometricparkfna.UI;
+
+using Encompass;
+using TraceryNet;
+using Ink.Runtime;
+
+
+namespace isometricparkfna.Spawners {
+
+ [Reads(typeof(DialogComponent))]
+ [Receives(typeof(SpawnDialogMessage))]
+ class DialogSpawner : Spawner
+
+ {
+ Story Story;
+ Grammar Grammar;
+
+ public DialogSpawner(Story story, Grammar grammar)
+ {
+ this.Story = story;
+ this.Grammar = grammar;
+ }
+
+ protected override void Spawn(in SpawnDialogMessage message)
+ {
+ Logging.Spy(this.Story.currentChoices.Count(), "Count");
+ Logging.Spy(this.Story.canContinue, "CanContinue");
+ //If there are no existing dialog:
+ if(ReadEntities().Length == 0
+ && this.Story.currentChoices.Count() == 0
+ && !this.Story.canContinue)
+ {
+ Logging.Debug("Creating and hydrating new Dialog.");
+ //Jump to the specified part of the story:
+ Story.ChoosePathString(message.Path);
+
+ var newDialog = CreateEntity();
+ var continuation = this.Story.ContinueMaximally();
+
+ var parts = Regex.Split(continuation, ":", 0);
+ var speaker = (parts.Length == 2) ? parts[0] : "";
+ var dialog = (parts.Length == 2) ? parts[1] : continuation;
+
+ AddComponent(newDialog, new DialogComponent {
+ Knot = message.Path,
+ CurrentDialog = this.Grammar.Flatten(dialog),
+ CurrentSpeaker = this.Grammar.Flatten(speaker),
+ Options = this.Story.currentChoices
+ .Select(option => option.text)
+ .ToList()});
+
+ AddComponent(newDialog, new WindowTypeComponent {
+ type = Window.Dialog});
+ AddComponent(newDialog,
+ new VisibilityComponent{ visible = true});
+
+ Logging.Success("Spawned new dialog.");
+ }
+ else
+ {
+
+ Logging.Debug("Creating new Dialog without hydrating.");
+ var newDialog = CreateEntity();
+ AddComponent(newDialog, new DialogComponent {
+ Knot = message.Path});
+ AddComponent(newDialog, new WindowTypeComponent {
+ type = Window.Dialog});
+ AddComponent(newDialog,
+ new VisibilityComponent{ visible = true});
+ }
+ }
+ }
+}
diff --git a/isometric-park-fna/Engines/Spawners/GameSpawner.cs b/isometric-park-fna/Engines/Spawners/GameSpawner.cs
--- a/isometric-park-fna/Engines/Spawners/GameSpawner.cs
+++ b/isometric-park-fna/Engines/Spawners/GameSpawner.cs
@@ -17,10 +17,11 @@
[Receives(typeof(SpawnGameMessage))]
[Sends(typeof(SpawnContractMessage),
typeof(SpawnOrganizationtMessage),
- typeof(ToggleWindowMessage))]
+ typeof(ToggleWindowMessage),
+ typeof(SpawnDialogMessage))]
[Writes(typeof(WindowTypeComponent)
//, typeof(DialogComponent)
- )]
+)]
class GameSpawner : Spawner
{
@@ -111,34 +112,9 @@
#endregion
#region dialog
- // this.game.enqueueDialog(DialogTrees.flatten(DialogTrees.testTree, this.grammar));
- //
-
- var dialogInitial = CreateEntity();
- // SetComponent(dialogInitial, new VisibilityComponent { visible = true });
- AddComponent(dialogInitial, new WindowTypeComponent { type = isometricparkfna.Messages.Window.Dialog });
- AddComponent(dialogInitial,
- new DialogComponent {Dialog = DialogTrees.introTree });
- AddComponent(dialogInitial,
- new VisibilityComponent{ visible = true});
- // SendMessage(new SetWindowVisibilityMessage {
- // Entity = dialogInitial,
- // Visibility = true });
-
-
- var dialogTest = CreateEntity();
- // SetComponent(dialogTest, new VisibilityComponent { visible = true });
- AddComponent(dialogTest, new WindowTypeComponent { type = isometricparkfna.Messages.Window.Dialog });
- AddComponent(dialogTest,
- new DialogComponent {Dialog = DialogTrees.flatten(DialogTrees.testTree, this.grammar)});
- // SendMessage(new SetWindowVisibilityMessage {
- // Entity = dialogTest,
- // Visibility = true
- // });
- AddComponent(dialogTest,
- new VisibilityComponent{ visible = true});
-
-
+ SendMessage(new SpawnDialogMessage { Path = "IntroGovernor"});
+ // SendMessage(new SpawnDialogMessage { Path = "Once"});
+ SendMessage(new SpawnDialogMessage { Path = "IntroAssistant"});
#endregion
this.simulation.Subsidy = message.Difficulty switch {
DifficultyLevel.Hard => 0M,
diff --git a/isometric-park-fna/Engines/UIEngine.cs b/isometric-park-fna/Engines/UIEngine.cs
--- a/isometric-park-fna/Engines/UIEngine.cs
+++ b/isometric-park-fna/Engines/UIEngine.cs
@@ -1,6 +1,12 @@
+using System;
+using System.Text.RegularExpressions;
+using System.Linq;
+
using Microsoft.Xna.Framework.Input;
using Encompass;
+using Ink.Runtime;
+using TraceryNet;
using isometricparkfna.Messages;
using isometricparkfna.Components;
@@ -13,15 +19,23 @@
typeof(ToggleVisibilityMessage),
typeof(SetWindowVisibilityMessage),
typeof(SelectMessage),
- typeof(SetDialogMessage))]
- [Reads(typeof(WindowTypeComponent),
+ typeof(SetDialogMessage),
+ typeof(DialogChoiceMessage))]
+ [Reads(typeof(DialogComponent),
+ typeof(WindowTypeComponent),
typeof(VisibilityComponent),
typeof(SelectedComponent))]
- [Writes(typeof(VisibilityComponent),
- typeof(SelectedComponent),
- typeof(DialogComponent))]
+ [Writes(typeof(VisibilityComponent),
+ typeof(SelectedComponent))]
class UIEngine : Engine
{
+ public Story Story;
+
+ public UIEngine(Story story)
+ {
+ this.Story = story;
+ }
+
public override void Update(double dt)
{
foreach (var entity in ReadEntities())
@@ -31,31 +45,43 @@
foreach (ref readonly var windowMessage in ReadMessages())
{
+ Logging.Spy(windowMessage, "message");
+ Logging.Spy(windowMessage.Entity, "message.Entity");
+ Logging.Spy(windowMessage.Entity.ID, "message.Entity.ID");
+ Logging.Spy(windowMessage.Visibility, "message.Visibility");
foreach (ref readonly var entity in ReadEntities())
{
+ Logging.Spy(entity.ID, "ID");
if (EntityExists(windowMessage.Entity) && entity.ID == windowMessage.Entity.ID)
{
- SetComponent(entity, new VisibilityComponent { visible = windowMessage.Visibility });
+ AddComponent(entity, new VisibilityComponent { visible = windowMessage.Visibility });
Logging.Success("Set Visibility.");
+
}
}
}
foreach (ref readonly var windowMessage in ReadMessages())
{
+ Logging.Spy(windowMessage, "message");
+ Logging.Spy(windowMessage.Window, "message.Window");
+ Logging.Spy(windowMessage.Entity, "message.Entity");
foreach (ref readonly var entity in ReadEntities())
{
if (EntityExists(windowMessage.Entity) && entity.ID == windowMessage.Entity.ID)
{
var visibilityComponent = GetComponent(entity);
- SetComponent(entity, new VisibilityComponent { visible = !visibilityComponent.visible });
+ AddComponent(entity, new VisibilityComponent { visible = !visibilityComponent.visible });
}
}
}
foreach (ref readonly var windowMessage in ReadMessages())
{
+ Logging.Spy(windowMessage, "message");
+ Logging.Spy(windowMessage.Window, "message.Window");
foreach (ref readonly var entity in ReadEntities())
{
+
var window_type = GetComponent(entity).type;
if (window_type == windowMessage.Window)
{
@@ -72,19 +98,7 @@
new SelectedComponent { selected = true });
}
- foreach (ref readonly var dialogMessage in ReadMessages())
- {
- if (dialogMessage.newOption != null)
- {
- SetComponent(dialogMessage.Entity,
- new DialogComponent {Dialog = dialogMessage.newOption
- });
- }
- else
- {
- Destroy(dialogMessage.Entity);
- }
- }
+
}
}
}
diff --git a/isometric-park-fna/FNAGame.cs b/isometric-park-fna/FNAGame.cs
--- a/isometric-park-fna/FNAGame.cs
+++ b/isometric-park-fna/FNAGame.cs
@@ -12,8 +12,8 @@
using System.Collections.Generic;
using System.Linq;
using SpriteFontPlus;
+
using isometricparkfna;
-
using static isometricparkfna.CellMap;
using isometricparkfna.Utils;
using isometricparkfna.UI;
@@ -28,6 +28,7 @@
using ImGuiNET;
using TraceryNet;
using Encompass;
+using Ink.Runtime;
//Let's let core builds be deterministic
#if NETCOREAPP
@@ -86,6 +87,8 @@
private bool showInitial;
int messageIndex;
+ public Story Story;
+
//buggy
private static bool enableCulling = false;
@@ -110,6 +113,8 @@
private ImGuiWindowBridgeEngine imGuiWindowBridgeEngine;
+
+
private static void Main(string[] args)
{
#if NETCOREAPP
@@ -246,8 +251,13 @@
//Has to happen after Grammar initialization.
NewGameWindow.Initialize(this.grammar);
+ this.Story = new Story(File.ReadAllText(@"Content/dialog.json"));
+
+ Logging.Debug(this.Story.ContinueMaximally());
+
WorldBuilder.AddEngine(new InputEngine(Menu.MENU_BAR_HEIGHT, this.camera, gdm));
- WorldBuilder.AddEngine(new UIEngine());
+ WorldBuilder.AddEngine(new UIEngine(this.Story));
+ WorldBuilder.AddEngine(new DialogEngine(this.Story, this.grammar));
var gameBridgeEngine = new GameBridgeEngine(this);
@@ -262,6 +272,7 @@
WorldBuilder.AddEngine(new ContractSpawner(simulation.map.MapWidth, simulation.map.MapHeight, this.simulation, this.grammar));
WorldBuilder.AddEngine(new GameSpawner(this.simulation, this, this.grammar));
WorldBuilder.AddEngine(new OrganizationSpawner(this.simulation, this.grammar));
+ WorldBuilder.AddEngine(new DialogSpawner(this.Story, this.grammar));
WorldBuilder.AddEngine(new PolicyEngine());
WorldBuilder.AddEngine(new TraceryBridgeEngine(this.grammar));
diff --git a/isometric-park-fna/Messages/DialogChoiceMessage.cs b/isometric-park-fna/Messages/DialogChoiceMessage.cs
new file mode 100644
--- /dev/null
+++ b/isometric-park-fna/Messages/DialogChoiceMessage.cs
@@ -0,0 +1,17 @@
+
+using Encompass;
+
+using isometricparkfna.Utils;
+using isometricparkfna.UI;
+
+namespace isometricparkfna.Messages
+{
+
+ //You must specify both or you get 0 for a window, which is the default window :(
+ public struct DialogChoiceMessage : IMessage, IHasEntity
+ {
+
+ public Entity Entity { set; get; }
+ public int Choice;
+ }
+}
diff --git a/isometric-park-fna/Messages/SpawnDialog.cs b/isometric-park-fna/Messages/SpawnDialog.cs
new file mode 100644
--- /dev/null
+++ b/isometric-park-fna/Messages/SpawnDialog.cs
@@ -0,0 +1,15 @@
+
+
+using Microsoft.Xna.Framework;
+using Encompass;
+
+using isometricparkfna.Spawners;
+
+#nullable enable
+
+namespace isometricparkfna.Messages {
+ public struct SpawnDialogMessage : IMessage
+ {
+ public string Path;
+ }
+}
diff --git a/isometric-park-fna/Renderers/ImGuiWindowRenderer.cs b/isometric-park-fna/Renderers/ImGuiWindowRenderer.cs
--- a/isometric-park-fna/Renderers/ImGuiWindowRenderer.cs
+++ b/isometric-park-fna/Renderers/ImGuiWindowRenderer.cs
@@ -86,7 +86,7 @@
var width = gdm.PreferredBackBufferWidth;
Entity dialogEntity = default;
- Node dialogNode = default;
+ DialogComponent dialogNode = default;
@@ -134,7 +134,7 @@
break;
case Window.Dialog:
- var dialog = GetComponent(entity).Dialog;
+ var dialog = GetComponent(entity);
if ((dialogEntity == null)
|| (dialogEntity.ID == 0)
@@ -151,7 +151,7 @@
}
}
- if (dialogNode != null)
+ if (dialogNode.Hydrated)
{
var show = true;
var paused = true;
diff --git a/isometric-park-fna/UI/Dialog.cs b/isometric-park-fna/UI/Dialog.cs
--- a/isometric-park-fna/UI/Dialog.cs
+++ b/isometric-park-fna/UI/Dialog.cs
@@ -8,6 +8,7 @@
using Encompass;
using isometricparkfna.Engines;
+using isometricparkfna.Components;
using isometricparkfna.Messages;
#nullable enable
@@ -111,10 +112,10 @@
{
public static bool hadFocus = false;
- public static Node RenderDialog(Entity entity,
- ImGuiWindowBridgeEngine bridgeEngine, ref bool show, ref bool paused, ImFontPtr font, Node currentNode)
+ public static void RenderDialog(Entity entity,
+ ImGuiWindowBridgeEngine bridgeEngine, ref bool show, ref bool paused, ImFontPtr font, DialogComponent dialogComponent)
{
- Node new_child = currentNode;
+ Node new_child = default;
if (show)
{
ImGui.PushFont(font);
@@ -127,7 +128,8 @@
{
ImGui.PushStyleColor(ImGuiCol.Text, StyleSets.white);
}
- ImGui.Begin(currentNode.data.speaker, ref show, ImGuiWindowFlags.NoResize | ImGuiWindowFlags.NoCollapse | ImGuiWindowFlags.AlwaysAutoResize | ImGuiWindowFlags.NoSavedSettings);
+
+ ImGui.Begin(dialogComponent.CurrentSpeaker, ref show, ImGuiWindowFlags.NoResize | ImGuiWindowFlags.NoCollapse | ImGuiWindowFlags.AlwaysAutoResize | ImGuiWindowFlags.NoSavedSettings);
if (DialogInterface.hadFocus)
{
ImGui.PopStyleColor();
@@ -135,21 +137,24 @@
DialogInterface.hadFocus = ImGui.IsWindowFocused();
- if (currentNode.data.response != null)
+ if (dialogComponent.CurrentDialog != null)
{
- string messageText = currentNode.data.response;
+ string messageText = dialogComponent.CurrentDialog;
ImGui.TextWrapped(messageText);
}
- if ((currentNode.children != null) && currentNode.children.Length > 0)
+ if ((dialogComponent.Options != null) && dialogComponent.Options.Count > 0)
{
- //Filter out nulls
- foreach ((Node child, string choice) in currentNode.children.Select((child) => (child, child.data.choice)).Where( (pair, choice) => pair.choice != null))
+ for(int i = 0; i < dialogComponent.Options.Count; i++)
{
- string buttonText = choice;
+ string buttonText = dialogComponent.Options[i];
if (ImGui.Button(buttonText))
{
- new_child = child;
+ bridgeEngine.dialogChoiceMessages.Add(new DialogChoiceMessage {
+
+ Entity = entity,
+ Choice = i });
+
}
}
}
@@ -159,14 +164,14 @@
{
show = false;
paused = false;
- bridgeEngine.setDialogMessages.Add(new SetDialogMessage {
+ bridgeEngine.dialogChoiceMessages.Add(new DialogChoiceMessage {
Entity = entity,
- newOption = null });
+ Choice = -1 });
}
}
- if (currentNode.data.response == null)
+ if (dialogComponent.CurrentDialog == null)
{
show = false;
paused = false;
@@ -177,11 +182,6 @@
StyleSets.defaultSet.pop();
ImGui.PopFont();
}
- bridgeEngine.setDialogMessages.Add(new SetDialogMessage {
-
- Entity = entity,
- newOption = new_child });
- return new_child;
}
}
}
diff --git a/isometric-park-fna/isometric-park-fna-core.csproj b/isometric-park-fna/isometric-park-fna-core.csproj
--- a/isometric-park-fna/isometric-park-fna-core.csproj
+++ b/isometric-park-fna/isometric-park-fna-core.csproj
@@ -46,6 +46,7 @@
+
diff --git a/isometric-park-fna/isometric-park-fna.csproj b/isometric-park-fna/isometric-park-fna.csproj
--- a/isometric-park-fna/isometric-park-fna.csproj
+++ b/isometric-park-fna/isometric-park-fna.csproj
@@ -148,6 +148,9 @@
PreserveNewest
+
+ PreserveNewest
+
PreserveNewest
@@ -228,6 +231,9 @@
+
+
+