# HG changeset patch # User Alys Brooks # Date 2021-08-04 07:10:24 # Node ID 82c352fd371d044b20dc3fd387bb7883bccb1c21 # Parent 697754113206455a6b880ae6bd3a9f1fafbf693d Refactor dialog into Encompass. diff --git a/isometric-park-fna/Components/Dialog.cs b/isometric-park-fna/Components/Dialog.cs new file mode 100644 --- /dev/null +++ b/isometric-park-fna/Components/Dialog.cs @@ -0,0 +1,15 @@ + + +using Microsoft.Xna.Framework; + +using Encompass; +using isometricparkfna.Utils; +using isometricparkfna.UI; +using isometricparkfna.Engines; + +namespace isometricparkfna.Components { + + public struct DialogComponent : IComponent { + public Node Dialog; + } +} 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 @@ -21,7 +21,8 @@ typeof(SetFontMessage), typeof(SetTrespassingPolicyMessage), typeof(SpawnGameMessage), - typeof(SetTextVariableMessage))] + typeof(SetTextVariableMessage), + typeof(SetDialogMessage))] [Reads(typeof(VisibilityComponent), typeof(WindowTypeComponent), typeof(TrespassingPolicyComponent) @@ -42,6 +43,7 @@ public List trespassingPolicyMessages; public List spawnGameMessages; public List setTextVariableMessages; + public List setDialogMessages; bool showBudget {get;} bool showForest {get;} @@ -70,6 +72,7 @@ this.trespassingPolicyMessages = new List(); this.spawnGameMessages = new List(); this.setTextVariableMessages = new List(); + this.setDialogMessages = new List(); this.windowStatuses = new Dictionary(); @@ -109,6 +112,11 @@ SendMessage(message); } + // + foreach (var message in this.setTextVariableMessages) + { + SendMessage(message); + } foreach(var message in this.gameStateMessages) { SendMessage(message); @@ -144,8 +152,8 @@ SendMessage(message); } - //This may need to be moved up. - foreach (var message in this.setTextVariableMessages) + + foreach (var message in this.setDialogMessages) { SendMessage(message); } @@ -157,11 +165,12 @@ foreach(var entity in ReadEntities()) { var type = GetComponent(entity).type; - var visibility = GetComponent(entity).visible; + var visibility = HasComponent(entity) ? GetComponent(entity).visible : false; windowStatuses[type] = visibility; } + this.messages.Clear(); this.typeMessages.Clear(); this.contractStatusMessages.Clear(); @@ -173,6 +182,7 @@ this.trespassingPolicyMessages.Clear(); this.spawnGameMessages.Clear(); this.setTextVariableMessages.Clear(); + this.setDialogMessages.Clear(); } } } 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 @@ -5,6 +5,7 @@ using Microsoft.Xna.Framework; using isometricparkfna.Messages; +using isometricparkfna.Components; using static isometricparkfna.CellMap; using isometricparkfna.UI; @@ -15,7 +16,11 @@ [Receives(typeof(SpawnGameMessage))] [Sends(typeof(SpawnContractMessage), - typeof(SpawnOrganizationtMessage))] + typeof(SpawnOrganizationtMessage), + typeof(ToggleWindowMessage))] + [Writes(typeof(WindowTypeComponent) + //, typeof(DialogComponent) + )] class GameSpawner : Spawner { @@ -106,7 +111,34 @@ #endregion #region dialog - this.game.enqueueDialog(DialogTrees.flatten(DialogTrees.testTree, this.grammar)); + // 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}); + + #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 @@ -8,11 +8,18 @@ namespace isometricparkfna.Engines { - [Receives(typeof(ToggleWindowMessage), typeof(ToggleWindowTypeMessage), typeof(ToggleVisibilityMessage), - typeof(SelectMessage))] - [Reads(typeof(WindowTypeComponent), typeof(VisibilityComponent), - typeof(SelectedComponent))] - [Writes(typeof(VisibilityComponent), typeof(SelectedComponent))] + [Receives(typeof(ToggleWindowMessage), + typeof(ToggleWindowTypeMessage), + typeof(ToggleVisibilityMessage), + typeof(SetWindowVisibilityMessage), + typeof(SelectMessage), + typeof(SetDialogMessage))] + [Reads(typeof(WindowTypeComponent), + typeof(VisibilityComponent), + typeof(SelectedComponent))] + [Writes(typeof(VisibilityComponent), + typeof(SelectedComponent), + typeof(DialogComponent))] class UIEngine : Engine { @@ -23,6 +30,23 @@ SetComponent(entity, new SelectedComponent { selected = false }); } + 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) + { + AddComponent(entity, new VisibilityComponent { visible = windowMessage.Visibility }); + Logging.Success("Set Visibility."); + + } + } + } foreach (ref readonly var windowMessage in ReadMessages()) { Logging.Spy(windowMessage, "message"); @@ -33,7 +57,7 @@ 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 }); } } @@ -60,6 +84,21 @@ SetComponent(selectedMessage.Entity, 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 @@ -290,16 +290,16 @@ WorldBuilder.SetComponent(newGameWindow, new WindowTypeComponent { type = isometricparkfna.Messages.Window.NewGame }); + var gameEntity = WorldBuilder.CreateEntity(); - var gameEntity = WorldBuilder.CreateEntity(); - - WorldBuilder.SetComponent(gameEntity, new GameStateComponent { isPlaying = false}); + WorldBuilder.SetComponent(gameEntity, new GameStateComponent { isPlaying = false}); - var policyEntity = WorldBuilder.CreateEntity(); - WorldBuilder.SetComponent(policyEntity, - new TrespassingPolicyComponent { tresspassingPolicy = EnforcementLevel.NoEnforcement}); - WorldBuilder.SetComponent(policyEntity, - new BudgetLineComponent { }); + var policyEntity = WorldBuilder.CreateEntity(); + WorldBuilder.SetComponent(policyEntity, + new TrespassingPolicyComponent { tresspassingPolicy = EnforcementLevel.NoEnforcement}); + WorldBuilder.SetComponent(policyEntity, + new BudgetLineComponent { }); + try { var options = Options.readOptions(); @@ -821,8 +821,8 @@ #region window if (this.currentNode != null) { - this.currentNode = DialogInterface.RenderDialog(ref this.showInitial, - ref this.simulation.paused, debugWindow.monoFont, this.currentNode); + // this.currentNode = DialogInterface.RenderDialog(ref this.showInitial, + // ref this.simulation.paused, debugWindow.monoFont, this.currentNode); } if (this.showForest) diff --git a/isometric-park-fna/Messages/SetDialogMessage.cs b/isometric-park-fna/Messages/SetDialogMessage.cs new file mode 100644 --- /dev/null +++ b/isometric-park-fna/Messages/SetDialogMessage.cs @@ -0,0 +1,16 @@ +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 SetDialogMessage : IMessage, IHasEntity + { + + public Entity Entity { set; get; } + public Node newOption; + } +} diff --git a/isometric-park-fna/Messages/SetWindowVisibiityMessage.cs b/isometric-park-fna/Messages/SetWindowVisibiityMessage.cs new file mode 100644 --- /dev/null +++ b/isometric-park-fna/Messages/SetWindowVisibiityMessage.cs @@ -0,0 +1,14 @@ + +using Encompass; + +namespace isometricparkfna.Messages +{ + + //You must specify both or you get 0 for a window, which is the default window :( + public struct SetWindowVisibilityMessage : IMessage, IHasEntity + { + + public Entity Entity { set; get; } + public bool Visibility; + } +} diff --git a/isometric-park-fna/Messages/ToggleWindowTypeMessage.cs b/isometric-park-fna/Messages/ToggleWindowTypeMessage.cs --- a/isometric-park-fna/Messages/ToggleWindowTypeMessage.cs +++ b/isometric-park-fna/Messages/ToggleWindowTypeMessage.cs @@ -15,7 +15,8 @@ MainMenu, InGameMenu, Options, - NewGame + NewGame, + Dialog } 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 @@ -69,7 +69,7 @@ foreach (ref readonly var entity in ReadEntities()) { var window_type = GetComponent(entity).type; - var visible = GetComponent(entity).visible; + var visible = HasComponent(entity) ? GetComponent(entity).visible : false; if (visible) { @@ -110,6 +110,13 @@ case Window.NewGame: NewGameWindow.Render(this.BridgeEngine.font, this.BridgeEngine.italicFont, this.BridgeEngine); break; + case Window.Dialog: + + var dialog = GetComponent(entity).Dialog; + var show = true; + var paused = true; + DialogInterface.RenderDialog(entity, this.BridgeEngine, ref show, ref paused, this.BridgeEngine.font, dialog); + break; default: // Logging.Error(String.Format("Unknown window type {0} ", window_type)); break; 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 @@ -5,6 +5,10 @@ using isometricparkfna.Utils; using TraceryNet; using Num = System.Numerics; +using Encompass; + +using isometricparkfna.Engines; +using isometricparkfna.Messages; #nullable enable @@ -107,7 +111,8 @@ { public static bool hadFocus = false; - public static Node RenderDialog(ref bool show, ref bool paused, ImFontPtr font, Node currentNode) + public static Node RenderDialog(Entity entity, + ImGuiWindowBridgeEngine bridgeEngine, ref bool show, ref bool paused, ImFontPtr font, Node currentNode) { Node new_child = currentNode; if (show) @@ -154,7 +159,11 @@ { show = false; paused = false; - } + bridgeEngine.setDialogMessages.Add(new SetDialogMessage { + + Entity = entity, + newOption = null }); + } } if (currentNode.data.response == null) @@ -168,10 +177,11 @@ 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 @@ -35,8 +35,8 @@ - - + + ..\packages\Newtonsoft.Json.12.0.3\lib\netstandard2.0\Newtonsoft.Json.dll ..\packages\Tracery.Net.1.0.0\lib\net452\Tracery.Net.dll