# HG changeset patch # User alys # Date 2021-05-26 04:29:00 # Node ID c8c82098fa9b0423a27d505305b80479088f3147 # Parent 27313246ec34f54c1779cacab1b0b457c4d89f7a Split messages based on types apart from those based on entity. diff --git a/isometric-park-fna/Engines/GameBridgeEngine.cs b/isometric-park-fna/Engines/GameBridgeEngine.cs --- a/isometric-park-fna/Engines/GameBridgeEngine.cs +++ b/isometric-park-fna/Engines/GameBridgeEngine.cs @@ -8,7 +8,8 @@ namespace isometricparkfna.Engines { - [Receives(typeof(ToggleWindowMessage), typeof(ToggleVisibilityMessage))] + [Receives(typeof(ToggleWindowTypeMessage), typeof(ToggleWindowMessage), + typeof(ToggleVisibilityMessage))] [Reads(typeof(AreaComponent))] class GameBridgeEngine : Engine { @@ -22,7 +23,7 @@ public override void Update(double dt) { - foreach (ref readonly var windowMessage in ReadMessages()) + foreach (ref readonly var windowMessage in ReadMessages()) { switch (windowMessage.Window) { case Window.Debug: 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 @@ -8,10 +8,11 @@ namespace isometricparkfna.Engines { [Sends(typeof(ToggleWindowMessage), - typeof(ChangeContractStatusMessage), - typeof(SelectMessage))] + typeof(ToggleWindowTypeMessage), + typeof(ChangeContractStatusMessage), + typeof(SelectMessage))] [Reads(typeof(VisibilityComponent), - typeof(WindowTypeComponent) + typeof(WindowTypeComponent) //, typeof(SelectedComponent) )] // [Writes(typeof(SelectedComponent))] @@ -19,6 +20,7 @@ { public List messages; + public List typeMessages; public List contractStatusMessages; public List selectedMessages; @@ -34,6 +36,7 @@ public ImGuiWindowBridgeEngine() { this.messages = new List(); + this.typeMessages = new List(); this.contractStatusMessages = new List(); this.selectedMessages = new List(); this.windowStatuses = new Dictionary(); @@ -50,6 +53,10 @@ { SendMessage(message); } + foreach(var message in this.typeMessages) + { + SendMessage(message); + } foreach(var message in this.contractStatusMessages) { SendMessage(message); @@ -69,6 +76,7 @@ } this.messages.Clear(); + this.typeMessages.Clear(); this.contractStatusMessages.Clear(); this.selectedMessages.Clear(); } diff --git a/isometric-park-fna/Engines/InputEngine.cs b/isometric-park-fna/Engines/InputEngine.cs --- a/isometric-park-fna/Engines/InputEngine.cs +++ b/isometric-park-fna/Engines/InputEngine.cs @@ -15,7 +15,8 @@ [Sends( typeof(ZoomCameraMessage), typeof(MoveCameraMessage), typeof(JumpCameraMessage), - typeof(ToggleWindowMessage), + typeof(ToggleWindowTypeMessage), + typeof(ToggleWindowMessage), //??? typeof(ToggleVisibilityMessage), typeof(TogglePauseMessage), typeof(GameRateMessage))] @@ -126,27 +127,28 @@ #region misc_keys if (keyboardCur.IsKeyDown(Keys.OemBackslash) && keyboardPrev.IsKeyUp(Keys.OemBackslash)) { - SendMessage(new ToggleWindowMessage{Window = Window.Debug}); + SendMessage(new ToggleWindowTypeMessage{Window = Window.Debug}); } if (keyboardCur.IsKeyDown(Keys.B) && keyboardPrev.IsKeyUp(Keys.B)) { - SendMessage(new ToggleWindowMessage{Window = Window.Budget}); + SendMessage(new ToggleWindowTypeMessage{Window = Window.Budget}); } if (keyboardCur.IsKeyDown(Keys.F) && keyboardPrev.IsKeyUp(Keys.F)) { - SendMessage(new ToggleWindowMessage{Window = Window.Forest}); + SendMessage(new ToggleWindowTypeMessage{Window = Window.Forest}); } if (keyboardCur.IsKeyDown(Keys.N) && keyboardPrev.IsKeyUp(Keys.N)) { - SendMessage(new ToggleWindowMessage{Window = Window.News}); + SendMessage(new ToggleWindowTypeMessage{Window = Window.News}); } if (keyboardCur.IsKeyDown(Keys.O) && keyboardPrev.IsKeyUp(Keys.O)) { - SendMessage(new ToggleWindowMessage{Window = Window.Contracts}); + Logging.Trace("Contracts toggled."); + SendMessage(new ToggleWindowTypeMessage{Window = Window.Contracts}); } if (keyboardCur.IsKeyDown(Keys.G) && keyboardPrev.IsKeyUp(Keys.G)) { diff --git a/isometric-park-fna/Engines/Spawners/ContractSpawner.cs b/isometric-park-fna/Engines/Spawners/ContractSpawner.cs --- a/isometric-park-fna/Engines/Spawners/ContractSpawner.cs +++ b/isometric-park-fna/Engines/Spawners/ContractSpawner.cs @@ -23,7 +23,8 @@ private Random random_generator; public const int DEFAULT_MIN_SQUARES = 75; - public const int DEFAULT_SQUARES = 25; + // public const int DEFAULT_SQUARES = 25; + public const int DEFAULT_SQUARES = 100; public const int CONTRACT_MINIMUM = 50; public const int CONTRACT_MAXIMUM = 400; @@ -136,8 +137,19 @@ var image_index = random_generator.Next(1, 7); - int max_squares = (message.max_squares == 0) ? DEFAULT_SQUARES : message.max_squares; - int min_squares = (message.min_squares == null) ? DEFAULT_MIN_SQUARES : (int)message.min_squares; + // int max_squares = (message.max_squares == 0) ? DEFAULT_SQUARES : message.max_squares; + // int min_squares = (message.min_squares == null) ? DEFAULT_MIN_SQUARES : (int)message.min_squares; + + + int max_squares = (organization_type, message.min_squares) switch { + (OrganizationType.Family, null) => random_generator.Next(50, 100), + (OrganizationType.LargeCorporation, null) => random_generator.Next(75, 125), + (OrganizationType.Cooperative, null) => random_generator.Next(50, 75), + (_, null) => random_generator.Next(DEFAULT_MIN_SQUARES, DEFAULT_SQUARES), + _ => (message.max_squares == 0) ? DEFAULT_SQUARES : message.max_squares + }; + + int min_squares = (message.min_squares == null) ? (int)(max_squares*0.75f) : (int)message.min_squares; var odds_to_try = new[] {0.5f, 0.75f, 1.0f, 0.5f, 0.75f, 1.0f}; 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 @@ -10,9 +10,9 @@ namespace isometricparkfna.Engines { - [Receives(typeof(ToggleWindowMessage), typeof(ToggleVisibilityMessage), + [Receives(typeof(ToggleWindowMessage), typeof(ToggleWindowTypeMessage), typeof(ToggleVisibilityMessage), typeof(SelectMessage))] - [Reads(typeof(WindowTypeComponent), typeof(VisibilityComponent), + [Reads(typeof(WindowTypeComponent), typeof(VisibilityComponent), typeof(SelectedComponent))] [Writes(typeof(VisibilityComponent), typeof(SelectedComponent))] class UIEngine : Engine @@ -20,30 +20,42 @@ public override void Update(double dt) { - foreach (var entity in ReadEntities()) + foreach (var entity in ReadEntities()) { SetComponent(entity, new SelectedComponent { selected = false}); } foreach (ref readonly var windowMessage in ReadMessages()) { - foreach (ref readonly var entity in ReadEntities()) + Logging.Spy(windowMessage, "message"); + Logging.Spy(windowMessage.Window, "message.Window"); + Logging.Spy(windowMessage.Entity, "message.Entity"); + foreach (ref readonly var entity in ReadEntities()) { - var window_type = GetComponent(entity).type; - if (window_type == windowMessage.Window && !EntityExists(windowMessage.Entity)) - { - var visibilityComponent = GetComponent(entity); - SetComponent(entity, new VisibilityComponent{visible = !visibilityComponent.visible}); - } - //else if (window_type == windowMessage.Window && entity == windowMessage.Entity) { - // else if (entity == windowMessage.Entity) { - else if (EntityExists(windowMessage.Entity) && entity.ID == windowMessage.Entity.ID) { + if (EntityExists(windowMessage.Entity) && entity.ID == windowMessage.Entity.ID) { var visibilityComponent = GetComponent(entity); SetComponent(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) + { + var visibilityComponent = GetComponent(entity); + SetComponent(entity, new VisibilityComponent{visible = !visibilityComponent.visible}); + } + //else if (window_type == windowMessage.Window && entity == windowMessage.Entity) { + // else if (entity == windowMessage.Entity) { + } + } foreach (ref readonly var selectedMessage in ReadMessages()) { @@ -53,4 +65,4 @@ } } -} \ No newline at end of file +} diff --git a/isometric-park-fna/Messages/ToggleWindowMessage.cs b/isometric-park-fna/Messages/ToggleWindowMessage.cs --- a/isometric-park-fna/Messages/ToggleWindowMessage.cs +++ b/isometric-park-fna/Messages/ToggleWindowMessage.cs @@ -2,15 +2,6 @@ namespace isometricparkfna.Messages { - public enum Window { - Debug, - Budget, - Forest, - News, - Contracts, - Contract - } - //You must specify both or you get 0 for a window, which is the default window :( public struct ToggleWindowMessage : IMessage, IHasEntity { 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 @@ -2,6 +2,7 @@ using Microsoft.Xna.Framework.Graphics; using System.Collections.Generic; +using System.Linq; using isometricparkfna.UI; using isometricparkfna.Engines; @@ -79,9 +80,11 @@ var data = getContractDetails(entity); - ContractWindow.Render(this.font, this.italicFont, this.BridgeEngine, entity, data.name, data.description, data.status, data.amount, data.delta_trees, data.image_index); + // var area_size = GetComponent(entity).squares.Length; + var area = GetComponent(entity).squares; + var area_size = GetComponent(entity).squares.Length; - //Logging.Trace(string.Format("Rendering Contract Window for {0}", data.name)); + ContractWindow.Render(this.font, this.italicFont, this.BridgeEngine, entity, data.name, data.description, data.status, data.amount, data.delta_trees, area_size, data.image_index); break; @@ -95,4 +98,4 @@ } } -} \ No newline at end of file +} diff --git a/isometric-park-fna/UI/ContractsWindow.cs b/isometric-park-fna/UI/ContractsWindow.cs --- a/isometric-park-fna/UI/ContractsWindow.cs +++ b/isometric-park-fna/UI/ContractsWindow.cs @@ -144,7 +144,9 @@ if (!newShow) { - engine.messages.Add(new ToggleWindowMessage { Window = Window.Contracts }); + Logging.Spy(newShow, "newShow"); + Logging.Trace("Contracts toggled."); + engine.typeMessages.Add(new ToggleWindowTypeMessage { Window = Window.Contracts }); } engine.selectedMessages.Add(new SelectMessage { Entity = selected.entity }); diff --git a/isometric-park-fna/UI/ForestWindow.cs b/isometric-park-fna/UI/ForestWindow.cs --- a/isometric-park-fna/UI/ForestWindow.cs +++ b/isometric-park-fna/UI/ForestWindow.cs @@ -52,7 +52,7 @@ } if (show != newShow) { - engine.messages.Add(new ToggleWindowMessage {Window = Window.Forest }); + engine.typeMessages.Add(new ToggleWindowTypeMessage {Window = Window.Forest }); } } } diff --git a/isometric-park-fna/UI/Menu.cs b/isometric-park-fna/UI/Menu.cs --- a/isometric-park-fna/UI/Menu.cs +++ b/isometric-park-fna/UI/Menu.cs @@ -60,22 +60,24 @@ if (Menu.activeButton("\ue0c2 Contracts", bridgeEngine.windowStatuses[Window.Contracts], new Num.Vector4(0.060f, 0.590f, 0.980f, 1f))) { - bridgeEngine.messages.Add(new ToggleWindowMessage{Window = Window.Contracts}); + Logging.Trace("Contracts toggled."); + Logging.Spy(bridgeEngine.windowStatuses, "statuses"); + bridgeEngine.typeMessages.Add(new ToggleWindowTypeMessage{Window = Window.Contracts}); } //Budget isn't connected to an entity yet: if (Menu.activeButton("$ Budget", showBudget, new Num.Vector4(0.060f, 0.590f, 0.980f, 1f))) { - bridgeEngine.messages.Add(new ToggleWindowMessage{Window = Window.Budget}); + bridgeEngine.typeMessages.Add(new ToggleWindowTypeMessage{Window = Window.Budget}); } if (Menu.activeButton("\ue124 Forest", bridgeEngine.windowStatuses[Window.Forest], new Num.Vector4(0.060f, 0.590f, 0.980f, 1f))) { - bridgeEngine.messages.Add(new ToggleWindowMessage{Window = Window.Forest}); + bridgeEngine.typeMessages.Add(new ToggleWindowTypeMessage{Window = Window.Forest}); } if (Menu.activeButton("\ue0bf News", bridgeEngine.windowStatuses[Window.News], new Num.Vector4(0.060f, 0.590f, 0.980f, 1f))) { - bridgeEngine.messages.Add(new ToggleWindowMessage{Window = Window.News}); + bridgeEngine.typeMessages.Add(new ToggleWindowTypeMessage{Window = Window.News}); } ImGui.Text("|"); diff --git a/isometric-park-fna/UI/NewsWindow.cs b/isometric-park-fna/UI/NewsWindow.cs --- a/isometric-park-fna/UI/NewsWindow.cs +++ b/isometric-park-fna/UI/NewsWindow.cs @@ -31,8 +31,8 @@ } } - // variableString += "vars# "; - // var result = grammar.Flatten(variableString); + variableString += "vars# "; + var result = grammar.Flatten(variableString); // Logging.Trace(String.Format("{0}: {1}", variableString, result)); return new NewsItem { @@ -143,7 +143,7 @@ if (show != newShow) { - engine.messages.Add(new ToggleWindowMessage {Window = Window.News }); + engine.typeMessages.Add(new ToggleWindowTypeMessage {Window = Window.News }); } } }