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 @@ -9,240 +9,248 @@ using isometricparkfna.Components; using isometricparkfna.UI; -namespace isometricparkfna.Engines { +namespace isometricparkfna.Engines +{ - [Sends(typeof(ToggleWindowMessage), - typeof(ToggleWindowTypeMessage), - typeof(ChangeContractStatusMessage), - typeof(SelectMessage), - typeof(JumpCameraMessage), - typeof(GameStateMessage), - typeof(GameStateMessage), - typeof(SetResolutionMessage), - typeof(SetFontMessage), - typeof(SetTrespassingPolicyMessage), - typeof(SpawnGameMessage), - typeof(SetTextVariableMessage), - typeof(SetDialogMessage), - typeof(DialogChoiceMessage), - typeof(SetOptionMessage))] - [Reads(typeof(VisibilityComponent), - typeof(WindowTypeComponent), - typeof(TrespassingPolicyComponent), - typeof(ContractStatusComponent), - typeof(RelatedOrganizationComponent), - typeof(NameAndDescriptionComponent), - typeof(OptionsComponent))] - [Writes(typeof(OptionsComponent))] - public class ImGuiWindowBridgeEngine : Engine - { - public List messages; - public List typeMessages; - public List contractStatusMessages; - public List selectedMessages; - public List jumpCameraMessages; - public List gameStateMessages; - public List resolutionMessages; - public List fontMessages; - public List trespassingPolicyMessages; - public List spawnGameMessages; - public List setTextVariableMessages; - public List setDialogMessages; - public List dialogChoiceMessages; - public List setOptionMessages; + [Sends(typeof(ToggleWindowMessage), + typeof(ToggleWindowTypeMessage), + typeof(ChangeContractStatusMessage), + typeof(SelectMessage), + typeof(JumpCameraMessage), + typeof(GameStateMessage), + typeof(GameStateMessage), + typeof(SetResolutionMessage), + typeof(SetFontMessage), + typeof(SetTrespassingPolicyMessage), + typeof(SpawnGameMessage), + typeof(SetTextVariableMessage), + typeof(SetDialogMessage), + typeof(DialogChoiceMessage), + typeof(SetOptionMessage))] + [Reads(typeof(VisibilityComponent), + typeof(WindowTypeComponent), + typeof(TrespassingPolicyComponent), + typeof(ContractStatusComponent), + typeof(RelatedOrganizationComponent), + typeof(NameAndDescriptionComponent), + typeof(OptionsComponent))] + [Writes(typeof(OptionsComponent))] + public class ImGuiWindowBridgeEngine : Engine + { + public List messages; + public List typeMessages; + public List contractStatusMessages; + public List selectedMessages; + public List jumpCameraMessages; + public List gameStateMessages; + public List resolutionMessages; + public List fontMessages; + public List trespassingPolicyMessages; + public List spawnGameMessages; + public List setTextVariableMessages; + public List setDialogMessages; + public List dialogChoiceMessages; + public List setOptionMessages; - bool showBudget {get;} - bool showForest {get;} - bool showNews {get;} - bool showGrid {get;} - bool showTrees {get;} + bool showBudget { get; } + bool showForest { get; } + bool showNews { get; } + bool showGrid { get; } + bool showTrees { get; } - public Dictionary windowStatuses {get;} + public Dictionary windowStatuses { get; } + + public bool showContractIndicator; + public List contracts; - public bool showContractIndicator; - public List contracts; + public ImFontPtr font; + public ImFontPtr italicFont; + private DebugWindow debugWindow; + + private Simulation Simulation; - public ImFontPtr font; - public ImFontPtr italicFont; - private DebugWindow debugWindow; - - private Simulation Simulation; - - public DateTime DateTime { get { - return this.Simulation.DateTime; - }} + public DateTime DateTime + { + get + { + return this.Simulation.DateTime; + } + } - public ImGuiWindowBridgeEngine(DebugWindow debugWindow, - ImFontPtr font, ImFontPtr italicFont, - Simulation simulation) - { - this.messages = new List(); - this.typeMessages = new List(); - this.contractStatusMessages = new List(); - this.selectedMessages = new List(); - this.jumpCameraMessages = new List(); - this.gameStateMessages = new List(); - this.resolutionMessages = new List(); - this.fontMessages = new List(); - this.trespassingPolicyMessages = new List(); - this.spawnGameMessages = new List(); - this.setTextVariableMessages = new List(); - this.setDialogMessages = new List(); - this.dialogChoiceMessages = new List(); - this.setOptionMessages = new List(); - this.windowStatuses = new Dictionary(); + public ImGuiWindowBridgeEngine(DebugWindow debugWindow, + ImFontPtr font, ImFontPtr italicFont, + Simulation simulation) + { + this.messages = new List(); + this.typeMessages = new List(); + this.contractStatusMessages = new List(); + this.selectedMessages = new List(); + this.jumpCameraMessages = new List(); + this.gameStateMessages = new List(); + this.resolutionMessages = new List(); + this.fontMessages = new List(); + this.trespassingPolicyMessages = new List(); + this.spawnGameMessages = new List(); + this.setTextVariableMessages = new List(); + this.setDialogMessages = new List(); + this.dialogChoiceMessages = new List(); + this.setOptionMessages = new List(); + this.windowStatuses = new Dictionary(); - this.showContractIndicator = false; + this.showContractIndicator = false; - this.font = font; - this.italicFont = italicFont; - this.debugWindow = debugWindow; - this.Simulation = simulation; + this.font = font; + this.italicFont = italicFont; + this.debugWindow = debugWindow; + this.Simulation = simulation; - this.contracts = new List(); + this.contracts = new List(); - //Prepopulate: - foreach(var type in System.Enum.GetValues(typeof(Window))) - { - windowStatuses.Add((Window)type, false); - } - } + //Prepopulate: + foreach (var type in System.Enum.GetValues(typeof(Window))) + { + windowStatuses.Add((Window)type, false); + } + } - public override void Update(double dt) - { - foreach(var message in this.messages) - { - SendMessage(message); - } - foreach(var message in this.typeMessages) - { - SendMessage(message); - } - foreach(var message in this.contractStatusMessages) - { - SendMessage(message); - } - foreach(var message in this.selectedMessages) - { - SendMessage(message); - // SetComponent(message.Entity, new SelectedComponent { selected = true}); - } - foreach(var message in this.jumpCameraMessages) - { - SendMessage(message); - } + public override void Update(double dt) + { + foreach (var message in this.messages) + { + SendMessage(message); + } + foreach (var message in this.typeMessages) + { + SendMessage(message); + } + foreach (var message in this.contractStatusMessages) + { + SendMessage(message); + } + foreach (var message in this.selectedMessages) + { + SendMessage(message); + // SetComponent(message.Entity, new SelectedComponent { selected = true}); + } + foreach (var message in this.jumpCameraMessages) + { + SendMessage(message); + } - // - foreach (var message in this.setTextVariableMessages) - { - SendMessage(message); - } - foreach(var message in this.gameStateMessages) - { - SendMessage(message); - } - foreach(var message in this.resolutionMessages) - { - SendMessage(message); - } - foreach(var message in this.fontMessages) - { - this.font = debugWindow.addFont(message.fontName, - message.fontSize, false); + // + foreach (var message in this.setTextVariableMessages) + { + SendMessage(message); + } + foreach (var message in this.gameStateMessages) + { + SendMessage(message); + } + foreach (var message in this.resolutionMessages) + { + SendMessage(message); + } + foreach (var message in this.fontMessages) + { + this.font = debugWindow.addFont(message.fontName, + message.fontSize, false); - debugWindow.setMonoFont(this.font); + debugWindow.setMonoFont(this.font); - this.italicFont = debugWindow.addFont(message.fontName, - message.fontSize, true); + this.italicFont = debugWindow.addFont(message.fontName, + message.fontSize, true); - debugWindow.setItalicFont(this.italicFont); - SendMessage(message); + debugWindow.setItalicFont(this.italicFont); + SendMessage(message); - OptionsWindow.setFont(message.fontName, - message.fontSize); - } + OptionsWindow.setFont(message.fontName, + message.fontSize); + } - foreach (var message in this.trespassingPolicyMessages) - { - SendMessage(message); - } + foreach (var message in this.trespassingPolicyMessages) + { + SendMessage(message); + } - foreach (var message in this.spawnGameMessages) - { - SendMessage(message); - } + foreach (var message in this.spawnGameMessages) + { + SendMessage(message); + } - foreach (var message in this.setDialogMessages) - { - SendMessage(message); - } - foreach (var message in this.dialogChoiceMessages) - { - SendMessage(message); - } + foreach (var message in this.setDialogMessages) + { + SendMessage(message); + } + foreach (var message in this.dialogChoiceMessages) + { + SendMessage(message); + } + + foreach (var message in this.setOptionMessages) + { + foreach (var entity in ReadEntities()) + { - foreach(var message in this.setOptionMessages) - { - foreach(var entity in ReadEntities()) - { - - SetComponent(entity, new OptionsComponent { - ProfanitySetting = message.NewProfanitySetting}); - } + SetComponent(entity, new OptionsComponent + { + ProfanitySetting = message.NewProfanitySetting + }); + } - } + } - foreach(var entity in ReadEntities()) - { - var type = GetComponent(entity).type; - var visibility = HasComponent(entity) ? GetComponent(entity).visible : false; - windowStatuses[type] = visibility; - } + foreach (var entity in ReadEntities()) + { + var type = GetComponent(entity).type; + var visibility = HasComponent(entity) ? GetComponent(entity).visible : false; + windowStatuses[type] = visibility; + } - //reset - this.showContractIndicator = false; - this.contracts.Clear(); - foreach(var entity in ReadEntities()) - { - var contractStatus = GetComponent(entity); - var age = this.Simulation.DateTime - contractStatus.date; - if((age.TotalDays > (5*30) ) - && (contractStatus.status == ContractStatus.Proposed)) - { - try { - this.showContractIndicator = true; - if (HasComponent(entity)) - { - var organizationEntity = GetComponent(entity).Entity; - var name = GetComponent(organizationEntity).DisplayName; - this.contracts.Add(name); + //reset + this.showContractIndicator = false; + this.contracts.Clear(); + foreach (var entity in ReadEntities()) + { + var contractStatus = GetComponent(entity); + var age = this.Simulation.DateTime - contractStatus.date; + if ((age.TotalDays > (5 * 30)) + && (contractStatus.status == ContractStatus.Proposed)) + { + try + { + this.showContractIndicator = true; + if (HasComponent(entity)) + { + var organizationEntity = GetComponent(entity).Entity; + var name = GetComponent(organizationEntity).DisplayName; + this.contracts.Add(name); - } - } - catch (Exception e) - { - Logging.Error(string.Format("Exception: {0}", e.ToString())); - } - } - } + } + } + catch (Exception e) + { + Logging.Error(string.Format("Exception: {0}", e.ToString())); + } + } + } - this.messages.Clear(); - this.typeMessages.Clear(); - this.contractStatusMessages.Clear(); - this.selectedMessages.Clear(); - this.jumpCameraMessages.Clear(); - this.gameStateMessages.Clear(); - this.resolutionMessages.Clear(); - this.fontMessages.Clear(); - this.trespassingPolicyMessages.Clear(); - this.spawnGameMessages.Clear(); - this.setTextVariableMessages.Clear(); - this.setDialogMessages.Clear(); - this.dialogChoiceMessages.Clear(); - this.setOptionMessages.Clear(); - } - } + this.messages.Clear(); + this.typeMessages.Clear(); + this.contractStatusMessages.Clear(); + this.selectedMessages.Clear(); + this.jumpCameraMessages.Clear(); + this.gameStateMessages.Clear(); + this.resolutionMessages.Clear(); + this.fontMessages.Clear(); + this.trespassingPolicyMessages.Clear(); + this.spawnGameMessages.Clear(); + this.setTextVariableMessages.Clear(); + this.setDialogMessages.Clear(); + this.dialogChoiceMessages.Clear(); + this.setOptionMessages.Clear(); + } + } } diff --git a/isometric-park-fna/Engines/PolicyEngine.cs b/isometric-park-fna/Engines/PolicyEngine.cs --- a/isometric-park-fna/Engines/PolicyEngine.cs +++ b/isometric-park-fna/Engines/PolicyEngine.cs @@ -20,37 +20,38 @@ } - public override void Update(double dt) - { - foreach (ref readonly var message - in ReadMessages()) - { - foreach (ref readonly var entity - in ReadEntities()) - { + public override void Update(double dt) + { + foreach (ref readonly var message + in ReadMessages()) + { + foreach (ref readonly var entity + in ReadEntities()) + { - SetComponent(entity, - new TrespassingPolicyComponent {tresspassingPolicy - = message.newEnforcementLevel }); + SetComponent(entity, + new TrespassingPolicyComponent + { + tresspassingPolicy + = message.newEnforcementLevel + }); - var newCost =message.newEnforcementLevel switch { - EnforcementLevel.NoEnforcement => 0, - EnforcementLevel.EnforcedWithWarnings => 100, - EnforcementLevel.EnforcedWithFines => 100, - - - }; - + var newCost = message.newEnforcementLevel switch { + EnforcementLevel.NoEnforcement => 0, + EnforcementLevel.EnforcedWithWarnings => 100, + EnforcementLevel.EnforcedWithFines => 100 + }; - SetComponent(entity, - new BudgetLineComponent {category = "Enforcement", - amount = newCost - }); + SetComponent(entity, + new BudgetLineComponent + { + category = "Enforcement", + amount = newCost + }); + } + } - } - } - - } + } } } 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 @@ -15,21 +15,21 @@ { [Receives(typeof(ToggleWindowMessage), - typeof(ToggleWindowTypeMessage), - typeof(ToggleVisibilityMessage), - typeof(SetWindowVisibilityMessage), - typeof(SelectMessage), - typeof(SetDialogMessage), - typeof(DialogChoiceMessage))] + typeof(ToggleWindowTypeMessage), + typeof(ToggleVisibilityMessage), + typeof(SetWindowVisibilityMessage), + typeof(SelectMessage), + typeof(SetDialogMessage), + typeof(DialogChoiceMessage))] [Reads(typeof(DialogComponent), - typeof(WindowTypeComponent), - typeof(VisibilityComponent), - typeof(SelectedComponent))] - [Writes(typeof(VisibilityComponent), - typeof(SelectedComponent))] + typeof(WindowTypeComponent), + typeof(VisibilityComponent), + typeof(SelectedComponent))] + [Writes(typeof(VisibilityComponent), + typeof(SelectedComponent))] class UIEngine : Engine { - public Story Story; + public Story Story; public UIEngine(Story story) { 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 @@ -23,7 +23,7 @@ { public String? choice; public String response; - public String speaker; + public String speaker; } @@ -31,177 +31,187 @@ { public static Node introTree = new Node( - new DialogOption{response = "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.", - speaker = "The Governor" - }, - new Node(new DialogOption { choice = "Okay", - response = "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!", - speaker = "The Governor" - }, - new Node[]{ + new DialogOption + { + response = "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.", + speaker = "The Governor" + }, + new Node(new DialogOption + { + choice = "Okay", + response = "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!", + speaker = "The Governor" + }, + new Node[]{ new Node(new DialogOption {choice="And I need to keep the forest healthy, too, right?", response="Uhh yeah.", speaker = "The Governor" }, new Node(new DialogOption {choice="...", speaker = "The Governor"})), new Node(new DialogOption {choice="Sounds good!", response="I'll check in soon.", speaker = "The Governor" }) }) - ); + ); - public static Node testTree = new Node( - new DialogOption - { - response = "#addressGreetingFormal#", - speaker = "#assistantName#" - }, - new Node[]{ - new Node(new DialogOption {choice="Call me #playerCasual#", response="Sure", - speaker = "#assistantName#" }), - new Node(new DialogOption {choice="Hi.", response="Bye!", - speaker = "#assistantName#" }), - new Node(new DialogOption {choice="How are you?", response="#howdoing#", - speaker = "#assistantName#" }) + public static Node testTree = new Node( + new DialogOption + { + response = "#addressGreetingFormal#", + speaker = "#assistantName#" + }, + new Node[]{ + new Node(new DialogOption {choice="Call me #playerCasual#", response="Sure", + speaker = "#assistantName#" }), + new Node(new DialogOption {choice="Hi.", response="Bye!", + speaker = "#assistantName#" }), + new Node(new DialogOption {choice="How are you?", response="#howdoing#", + speaker = "#assistantName#" }) - } - ); + } + ); - public static Node testTree2 = new Node( - new DialogOption - { - response = "#whatever#", - speaker = "#assistantName#" - }, + public static Node testTree2 = new Node( + new DialogOption + { + response = "#whatever#", + speaker = "#assistantName#" + }, - new Node[]{ - new Node(new DialogOption {choice="Hi.", response="Bye!", - speaker = "#assistantName#" }), - new Node(new DialogOption {choice="How are you?", response="#howdoing#", - speaker = "#assistantName#" }) + new Node[]{ + new Node(new DialogOption {choice="Hi.", response="Bye!", + speaker = "#assistantName#" }), + new Node(new DialogOption {choice="How are you?", response="#howdoing#", + speaker = "#assistantName#" }) - } - ); + } + ); - public static Node flatten (Node node, Grammar grammar) { + public static Node flatten(Node node, Grammar grammar) + { - DialogOption new_data = new DialogOption - { - choice = node.data.choice != null ? grammar.Flatten(node.data.choice) : node.data.choice, - response = grammar.Flatten(node.data.response), - speaker = grammar.Flatten(node.data.speaker) - }; + DialogOption new_data = new DialogOption + { + choice = node.data.choice != null ? grammar.Flatten(node.data.choice) : node.data.choice, + response = grammar.Flatten(node.data.response), + speaker = grammar.Flatten(node.data.speaker) + }; - if (node.children != null) { - List> new_children = new List>(); - foreach (Node child in node.children) - { - new_children.Add(flatten(child, grammar)); - } + if (node.children != null) + { + List> new_children = new List>(); + foreach (Node child in node.children) + { + new_children.Add(flatten(child, grammar)); + } - return new Node(new_data, new_children.ToArray()); - } - else + return new Node(new_data, new_children.ToArray()); + } + else { - return new Node(new_data); + return new Node(new_data); - } + } - } + } - } + } public static class DialogInterface { - public static bool hadFocus = false; + public static bool hadFocus = false; public static ImGuiImageMap map; private static IntPtr _imGuiTexture; - public static void LoadContent(ImGuiRenderer _imGuiRenderer, + public static void LoadContent(ImGuiRenderer _imGuiRenderer, ImGuiImageMap map) { - DialogInterface.map = map; - var _xnaTexture = map.ImageMapTexture; - DialogInterface._imGuiTexture = _imGuiRenderer.BindTexture(_xnaTexture); + DialogInterface.map = map; + var _xnaTexture = map.ImageMapTexture; + DialogInterface._imGuiTexture = _imGuiRenderer.BindTexture(_xnaTexture); } public static void RenderDialog(Entity entity, ImGuiWindowBridgeEngine bridgeEngine, ref bool show, ref bool paused, ImFontPtr font, DialogComponent dialogComponent) { - if (show) - { - ImGui.PushFont(font); - ImGui.GetStyle().WindowMenuButtonPosition = ImGuiDir.None; + if (show) + { + ImGui.PushFont(font); + ImGui.GetStyle().WindowMenuButtonPosition = ImGuiDir.None; - StyleSets.defaultSet.push(); + StyleSets.defaultSet.push(); - ImGui.SetNextWindowSize(new Num.Vector2(400, 200)); - if(DialogInterface.hadFocus) - { - ImGui.PushStyleColor(ImGuiCol.Text, StyleSets.white); - } + ImGui.SetNextWindowSize(new Num.Vector2(400, 200)); + if (DialogInterface.hadFocus) + { + ImGui.PushStyleColor(ImGuiCol.Text, StyleSets.white); + } - ImGui.Begin(dialogComponent.CurrentSpeaker, ref show, ImGuiWindowFlags.NoResize | ImGuiWindowFlags.NoCollapse | ImGuiWindowFlags.AlwaysAutoResize | ImGuiWindowFlags.NoSavedSettings); - if (DialogInterface.hadFocus) - { - ImGui.PopStyleColor(); - } - DialogInterface.hadFocus = ImGui.IsWindowFocused(); + ImGui.Begin(dialogComponent.CurrentSpeaker, ref show, ImGuiWindowFlags.NoResize | ImGuiWindowFlags.NoCollapse | ImGuiWindowFlags.AlwaysAutoResize | ImGuiWindowFlags.NoSavedSettings); + if (DialogInterface.hadFocus) + { + ImGui.PopStyleColor(); + } + DialogInterface.hadFocus = ImGui.IsWindowFocused(); - ImGui.Columns(2); + ImGui.Columns(2); - Widgets.MapImage(DialogInterface.map, new Num.Vector2(150, 100), 1); + Widgets.MapImage(DialogInterface.map, new Num.Vector2(150, 100), 1); - ImGui.NextColumn(); + ImGui.NextColumn(); - if (dialogComponent.CurrentDialog != null) + if (dialogComponent.CurrentDialog != null) { - string messageText = dialogComponent.CurrentDialog; - ImGui.TextWrapped(messageText); - } + string messageText = dialogComponent.CurrentDialog; + ImGui.TextWrapped(messageText); + } - ImGui.Columns(1); + ImGui.Columns(1); - if ((dialogComponent.Options != null) && dialogComponent.Options.Count > 0) - { - for(int i = 0; i < dialogComponent.Options.Count; i++) - { - string buttonText = dialogComponent.Options[i]; - if (ImGui.Button(buttonText)) - { - bridgeEngine.dialogChoiceMessages.Add(new DialogChoiceMessage { + if ((dialogComponent.Options != null) && dialogComponent.Options.Count > 0) + { + for (int i = 0; i < dialogComponent.Options.Count; i++) + { + string buttonText = dialogComponent.Options[i]; + if (ImGui.Button(buttonText)) + { + bridgeEngine.dialogChoiceMessages.Add(new DialogChoiceMessage + { - Entity = entity, - Choice = i }); + Entity = entity, + Choice = i + }); - } - } - } - else - { - if (ImGui.Button("Okay")) - { - show = false; - paused = false; - bridgeEngine.dialogChoiceMessages.Add(new DialogChoiceMessage { + } + } + } + else + { + if (ImGui.Button("Okay")) + { + show = false; + paused = false; + bridgeEngine.dialogChoiceMessages.Add(new DialogChoiceMessage + { - Entity = entity, - Choice = -1 }); - } - } - - if (dialogComponent.CurrentDialog == null) - { - show = false; - paused = false; + Entity = entity, + Choice = -1 + }); + } + } - } - ImGui.End(); - ImGui.GetStyle().WindowMenuButtonPosition = ImGuiDir.Left; - StyleSets.defaultSet.pop(); - ImGui.PopFont(); - } - } - } + if (dialogComponent.CurrentDialog == null) + { + show = false; + paused = false; + + } + ImGui.End(); + ImGui.GetStyle().WindowMenuButtonPosition = ImGuiDir.Left; + StyleSets.defaultSet.pop(); + ImGui.PopFont(); + } + } + } }