# HG changeset patch # User Alys Brooks # Date 2021-08-07 07:39:13 # Node ID fa7d5e7e6a22bcdeadcb99f3fe61abfa6a559c13 # Parent 1df5074f5e1b2193925b26cfcafbf3fbd193f935 Add indicators to ContractsWindow. 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 @@ -63,6 +63,10 @@ private Simulation Simulation; + public DateTime DateTime { get { + return this.Simulation.DateTime; + }} + public ImGuiWindowBridgeEngine(DebugWindow debugWindow, ImFontPtr font, ImFontPtr italicFont, Simulation simulation) 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 @@ -41,7 +41,7 @@ Logging.Spy(entity.ID, "ID"); if (EntityExists(windowMessage.Entity) && entity.ID == windowMessage.Entity.ID) { - AddComponent(entity, new VisibilityComponent { visible = windowMessage.Visibility }); + SetComponent(entity, new VisibilityComponent { visible = windowMessage.Visibility }); Logging.Success("Set Visibility."); } @@ -57,7 +57,7 @@ if (EntityExists(windowMessage.Entity) && entity.ID == windowMessage.Entity.ID) { var visibilityComponent = GetComponent(entity); - AddComponent(entity, new VisibilityComponent { visible = !visibilityComponent.visible }); + SetComponent(entity, new VisibilityComponent { visible = !visibilityComponent.visible }); } } 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 @@ -18,6 +18,7 @@ namespace isometricparkfna.Renderers { + class ImGuiWindowRenderer : GeneralRenderer { private ImFontPtr italicFont; @@ -35,7 +36,7 @@ this.gdm = gdm; } - private (Entity entity, string name, string description, ContractStatus status, decimal amount, string delta_trees, int image_index, Vector2 square) + private ContractDetails getContractDetails(Entity entity) { @@ -43,11 +44,15 @@ var status = GetComponent(entity).status; var amount = GetComponent(entity).amount; var tree_delta = GetComponent(entity).deltaTreesName; + var date_time = GetComponent(entity).date; var image_index = GetComponent(entity).ImageIndex; var description = ""; var square = GetComponent(entity).squares[0]; + var age = (this.BridgeEngine.DateTime - date_time).TotalDays; + var area_size = GetComponent(entity).squares.Length; + if (HasComponent(entity)) { @@ -57,13 +62,25 @@ name = name_component.DisplayName; description = name_component.Description; image_index = GetComponent(related_organization).ImageIndex; + } - return (entity, name, description, status, amount, tree_delta, image_index, square); + return new ContractDetails { + entity = entity, + name = name, + description = description, + status = status, + amount = amount, + delta_trees = tree_delta, + image_index = image_index, + age = age, + area_size = area_size, + square = square + }; - } + } - public override void Render() + public override void Render() { var width = gdm.PreferredBackBufferWidth; @@ -85,7 +102,7 @@ case Window.Contracts: var contracts = ReadEntities(); - var contract_data = new List<(Entity, string, string, ContractStatus, decimal, string, int, Vector2)>(); + var contract_data = new List(); foreach (var e in contracts) { @@ -98,11 +115,9 @@ var data = getContractDetails(entity); - // var area_size = GetComponent(entity).squares.Length; - var area = GetComponent(entity).squares; - var area_size = GetComponent(entity).squares.Length; + var area = GetComponent(data.entity).squares; - ContractWindow.Render(this.BridgeEngine.font, this.italicFont, this.BridgeEngine, entity, data.name, data.description, data.status, data.amount, data.delta_trees, area_size, data.image_index, data.square); + ContractWindow.Render(this.BridgeEngine.font, this.italicFont, this.BridgeEngine, data); break; case Window.MainMenu: diff --git a/isometric-park-fna/UI/ContractWindow.cs b/isometric-park-fna/UI/ContractWindow.cs --- a/isometric-park-fna/UI/ContractWindow.cs +++ b/isometric-park-fna/UI/ContractWindow.cs @@ -16,6 +16,18 @@ namespace isometricparkfna.UI { + public struct ContractDetails { + public Entity entity; + public string name; + public string description; + public ContractStatus status; + public decimal amount; + public string delta_trees; + public double age; //in days + public int image_index; + public int area_size; + public Vector2 square; + } public static class ContractWindow { @@ -32,7 +44,7 @@ ContractWindow._imGuiTexture = _imGuiRenderer.BindTexture(_xnaTexture); } - public static void Render(ImFontPtr font, ImFontPtr italicFont, ImGuiWindowBridgeEngine engine, Entity entity, string name, string description, ContractStatus status, decimal amount, string delta_trees, int area_size, int imageIndex, Vector2 square) + public static void Render(ImFontPtr font, ImFontPtr italicFont, ImGuiWindowBridgeEngine engine, ContractDetails details /*Entity entity, string name, string description, ContractStatus status, decimal amount, string delta_trees, int area_size, int imageIndex, Vector2 square*/) { bool newShow = true; @@ -45,7 +57,7 @@ StyleSets.defaultSet.push(); ImGui.SetNextWindowSize(new Num.Vector2(320, 420)); - var title = string.Format("Contract {0} ## {1}", name, entity.ID); + var title = string.Format("Contract {0} ## {1}", details.name, details.entity.ID); if (ContractWindow.hadFocus.ContainsKey(title) && ContractWindow.hadFocus[title]) @@ -53,7 +65,7 @@ ImGui.PushStyleColor(ImGuiCol.Text, StyleSets.white); } - ImGui.Begin(name, ref newShow, + ImGui.Begin(details.name, ref newShow, ImGuiWindowFlags.NoResize | ImGuiWindowFlags.NoCollapse | ImGuiWindowFlags.NoSavedSettings); if (ContractWindow.hadFocus.ContainsKey(title) && @@ -70,21 +82,21 @@ ContractWindow.hadFocus.Add(title, ImGui.IsWindowFocused()); } - ImGui.Image(_imGuiTexture, new Num.Vector2(250, 200), map.GetSourceUVStart(imageIndex), map.GetSourceUVEnd(imageIndex), Num.Vector4.One, Num.Vector4.Zero); // Here, the previously loaded texture is used + ImGui.Image(_imGuiTexture, new Num.Vector2(250, 200), map.GetSourceUVStart(details.image_index), map.GetSourceUVEnd(details.image_index), Num.Vector4.One, Num.Vector4.Zero); // Here, the previously loaded texture is used ImGui.PushFont(italicFont); - ImGui.TextWrapped(description); + ImGui.TextWrapped(details.description); ImGui.PopFont(); ImGui.Separator(); - switch (status) + switch (details.status) { case ContractStatus.Proposed: - ImGui.TextColored(new Num.Vector4(0.25f, 0.25f, 0.95f, 1f), status.ToString()); + ImGui.TextColored(new Num.Vector4(0.25f, 0.25f, 0.95f, 1f), details.status.ToString()); break; case ContractStatus.Active: case ContractStatus.Accepted: - ImGui.TextColored(new Num.Vector4(0.25f, 0.95f, 0.25f, 1f), status.ToString()); + ImGui.TextColored(new Num.Vector4(0.25f, 0.95f, 0.25f, 1f), details.status.ToString()); break; case ContractStatus.Rejected: case ContractStatus.Broken: @@ -94,18 +106,18 @@ // ImGui.TextColored(new Num.Vector4(0.95f, 0.25f, 0.25f, 1f), contract.status.ToString()); // } - ImGui.TextColored(new Num.Vector4(0.95f, 0.25f, 0.25f, 1f), status.ToString()); + ImGui.TextColored(new Num.Vector4(0.95f, 0.25f, 0.25f, 1f), details.status.ToString()); break; case ContractStatus.Completed: - ImGui.TextColored(new Num.Vector4(0.25f, 0.25f, 0.25f, 1f), status.ToString()); + ImGui.TextColored(new Num.Vector4(0.25f, 0.25f, 0.25f, 1f), details.status.ToString()); break; default: break; } - ImGui.Text(string.Format("Amount: ${0}/mo.", amount)); - ImGui.Text(string.Format("Size: {0} acres", area_size)); + ImGui.Text(string.Format("Amount: ${0}/mo.", details.amount)); + ImGui.Text(string.Format("Size: {0} acres", details.area_size)); - if (delta_trees != null) + if (details.delta_trees != null) { ImGui.Text("Sustainability: "); ImGui.SameLine(); @@ -122,7 +134,7 @@ ImGui.SameLine(); var color = new Num.Vector4(1f, 1f, 1f, 1f); - switch (delta_trees) + switch (details.delta_trees) { case "Unsustainable": color = new Num.Vector4(0.95f, 0.25f, 0.25f, 1f); @@ -135,10 +147,10 @@ color = new Num.Vector4(0.95f, 0.65f, 0.25f, 1f); break; } - ImGui.TextColored(color, delta_trees); + ImGui.TextColored(color, details.delta_trees); } - ContractStatusButtons(engine, entity, status); + ContractStatusButtons(engine, details.entity, details.status); ImGui.Separator(); @@ -149,8 +161,8 @@ ImGui.SameLine(); if (ImGui.Button("Jump To")) { - int adjustedx = (int)square.X; - int adjustedy = (int)square.Y; + int adjustedx = (int)details.square.X; + int adjustedy = (int)details.square.Y; int screenx = (adjustedx - adjustedy) * Tile.TileSpriteWidth / 2; int screeny = (adjustedx + adjustedy) * Tile.TileSpriteHeight / 2; @@ -169,10 +181,10 @@ if (!newShow) { - engine.messages.Add(new ToggleWindowMessage {Window = Window.Contract, Entity = entity }); + engine.messages.Add(new ToggleWindowMessage {Window = Window.Contract, Entity = details.entity }); } - engine.selectedMessages.Add(new SelectMessage { Entity = entity }); + engine.selectedMessages.Add(new SelectMessage { Entity = details.entity }); } 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 @@ -20,11 +20,12 @@ public static bool show_all; public static bool had_focus = false; - private static (Entity entity, string name, string description, ContractStatus status, decimal amount, string delta_trees, int image_index, Vector2 square) selected; + // private static (Entity entity, string name, string description, ContractStatus status, decimal amount, string delta_trees, int age, int image_index, Vector2 square) selected; + private static ContractDetails selected; public static void Render(ImFontPtr font, ImGuiWindowBridgeEngine engine, -List<(Entity entity, string name, string description, ContractStatus status, decimal amount, string delta_trees, int image_index, Vector2 square)> contracts) +List contracts) { bool newShow = true; @@ -99,6 +100,21 @@ default: break; } + + if ((contract.status == ContractStatus.Proposed) + && (contract.age > (30 * 5))) + { + ImGui.SameLine(); + ImGui.TextColored(StyleSets.red, "(!)"); + + if (ImGui.IsItemHovered()) + { + ImGui.BeginTooltip(); + ImGui.Text("Offer is about to expire."); + ImGui.EndTooltip(); + } + } + } ImGui.ListBoxFooter(); @@ -128,9 +144,8 @@ break; } ImGui.TextColored(color, ContractsWindow.selected.delta_trees); - } - + } if (ImGui.Button("Open")) { System.Console.Write(string.Format("{0} opened", ContractsWindow.selected.entity)); @@ -159,9 +174,7 @@ 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/Menu.cs b/isometric-park-fna/UI/Menu.cs --- a/isometric-park-fna/UI/Menu.cs +++ b/isometric-park-fna/UI/Menu.cs @@ -72,7 +72,7 @@ { if (bridgeEngine.showContractIndicator) { - return Menu.activeButtonIndicator("\ue0c2 Contracts", bridgeEngine.windowStatuses[Window.Contracts], StyleSets.selected, StyleSets.white, "(!)", StyleSets.red, "Contracts about to expire:\n" + string.Join("\n", bridgeEngine.contracts)); + return Menu.activeButtonIndicator("\ue0c2 Contracts", bridgeEngine.windowStatuses[Window.Contracts], StyleSets.selected, StyleSets.white, "(!)", StyleSets.red, "Contract offre is about to expire:\n" + string.Join("\n", bridgeEngine.contracts)); } else {