Description:
Add Contract window.
Commit status:
[Not Reviewed]
References:
Diff options:
Comments:
0 Commit comments
0 Inline Comments
Unresolved TODOs:
There are no unresolved TODOs
@@ -0,0 +1,146 | |||||
|
|
1 | using System.Collections.Generic; | ||
|
|
2 | using System.Linq; | ||
|
|
3 | |||
|
|
4 | using ImGuiNET; | ||
|
|
5 | |||
|
|
6 | using isometricparkfna.Components; | ||
|
|
7 | using isometricparkfna.Engines; | ||
|
|
8 | using isometricparkfna.Messages; | ||
|
|
9 | |||
|
|
10 | using Num = System.Numerics; | ||
|
|
11 | |||
|
|
12 | using Encompass; | ||
|
|
13 | |||
|
|
14 | namespace isometricparkfna.UI | ||
|
|
15 | { | ||
|
|
16 | public static class ContractWindow | ||
|
|
17 | { | ||
|
|
18 | |||
|
|
19 | public static void Render(ImFontPtr font, ImGuiWindowBridgeEngine engine, Entity entity, string name, ContractStatus status, decimal amount, string delta_trees) | ||
|
|
20 | |||
|
|
21 | { | ||
|
|
22 | bool newShow = true; | ||
|
|
23 | |||
|
|
24 | // Entity newSelected; | ||
|
|
25 | var grey = new Num.Vector4(0.75f, 0.75f, 0.75f, 1f); | ||
|
|
26 | var darkgrey = new Num.Vector4(0.45f, 0.45f, 0.45f, 1f); | ||
|
|
27 | var black = new Num.Vector4(0f, 0f, 0f, 1f); | ||
|
|
28 | var title_bar = new Num.Vector4(0.65f, 0.65f, 0.65f, 1f); | ||
|
|
29 | |||
|
|
30 | if (newShow) | ||
|
|
31 | { | ||
|
|
32 | ImGui.PushFont(font); | ||
|
|
33 | |||
|
|
34 | ImGui.GetStyle().WindowMenuButtonPosition = ImGuiDir.None; | ||
|
|
35 | ImGui.PushStyleVar(ImGuiStyleVar.FrameRounding, 0.0f); | ||
|
|
36 | ImGui.PushStyleVar(ImGuiStyleVar.WindowRounding, 0.0f); | ||
|
|
37 | ImGui.PushStyleVar(ImGuiStyleVar.FrameBorderSize, 1.0f); | ||
|
|
38 | ImGui.PushStyleVar(ImGuiStyleVar.TabRounding, 0.0f); | ||
|
|
39 | ImGui.PushStyleColor(ImGuiCol.WindowBg, grey); | ||
|
|
40 | ImGui.PushStyleColor(ImGuiCol.FrameBg, grey); | ||
|
|
41 | ImGui.PushStyleColor(ImGuiCol.FrameBgHovered, grey); | ||
|
|
42 | ImGui.PushStyleColor(ImGuiCol.Header, darkgrey); | ||
|
|
43 | ImGui.PushStyleColor(ImGuiCol.HeaderHovered, darkgrey); | ||
|
|
44 | ImGui.PushStyleColor(ImGuiCol.HeaderActive, darkgrey); | ||
|
|
45 | ImGui.PushStyleColor(ImGuiCol.ButtonHovered, grey); | ||
|
|
46 | ImGui.PushStyleColor(ImGuiCol.CheckMark, black); | ||
|
|
47 | |||
|
|
48 | ImGui.PushStyleColor(ImGuiCol.TitleBg, title_bar); | ||
|
|
49 | ImGui.PushStyleColor(ImGuiCol.TitleBgActive, title_bar); | ||
|
|
50 | ImGui.PushStyleColor(ImGuiCol.TitleBgCollapsed, title_bar); | ||
|
|
51 | |||
|
|
52 | ImGui.PushStyleColor(ImGuiCol.Border, black); | ||
|
|
53 | ImGui.PushStyleColor(ImGuiCol.BorderShadow, black); | ||
|
|
54 | |||
|
|
55 | |||
|
|
56 | |||
|
|
57 | ImGui.PushStyleColor(ImGuiCol.Button, grey); | ||
|
|
58 | ImGui.PushStyleColor(ImGuiCol.Text, black); | ||
|
|
59 | ImGui.SetNextWindowSize(new Num.Vector2(320, 340)); | ||
|
|
60 | ImGui.Begin(string.Format("Contract {0}" , name), ref newShow, ImGuiWindowFlags.NoResize | ImGuiWindowFlags.NoCollapse | ImGuiWindowFlags.NoSavedSettings); | ||
|
|
61 | |||
|
|
62 | |||
|
|
63 | ImGui.Separator(); | ||
|
|
64 | ImGui.Text(string.Format("Amount: ${0}/mo.", amount)); | ||
|
|
65 | |||
|
|
66 | if (delta_trees != null) | ||
|
|
67 | { | ||
|
|
68 | ImGui.Text("Sustainability: "); | ||
|
|
69 | |||
|
|
70 | |||
|
|
71 | ImGui.SameLine(); | ||
|
|
72 | var color = new Num.Vector4(1f, 1f, 1f, 1f); | ||
|
|
73 | switch (delta_trees) | ||
|
|
74 | { | ||
|
|
75 | case "Unsustainable": | ||
|
|
76 | color = new Num.Vector4(0.95f, 0.25f, 0.25f, 1f); | ||
|
|
77 | break; | ||
|
|
78 | case "Restoration": | ||
|
|
79 | color = new Num.Vector4(0.25f, 0.95f, 0.25f, 1f); | ||
|
|
80 | break; | ||
|
|
81 | case "Moderately unsustainable": | ||
|
|
82 | case "Somewhat unsustainable": | ||
|
|
83 | color = new Num.Vector4(0.95f, 0.65f, 0.25f, 1f); | ||
|
|
84 | break; | ||
|
|
85 | } | ||
|
|
86 | ImGui.TextColored(color, delta_trees); | ||
|
|
87 | } | ||
|
|
88 | |||
|
|
89 | |||
|
|
90 | |||
|
|
91 | if (status == ContractStatus.Proposed) | ||
|
|
92 | { | ||
|
|
93 | if (ImGui.Button("Accept")) | ||
|
|
94 | { | ||
|
|
95 | System.Console.Write(string.Format("{0} selected", entity)); | ||
|
|
96 | |||
|
|
97 | engine.contractStatusMessages.Add(new ChangeContractStatusMessage { Entity = entity, newStatus = ContractStatus.Accepted }); | ||
|
|
98 | |||
|
|
99 | } | ||
|
|
100 | ImGui.SameLine(); | ||
|
|
101 | if (ImGui.Button("Reject")) | ||
|
|
102 | { | ||
|
|
103 | System.Console.Write(string.Format("{0} rejected", entity)); | ||
|
|
104 | |||
|
|
105 | engine.contractStatusMessages.Add(new ChangeContractStatusMessage { Entity = entity, newStatus = ContractStatus.Rejected }); | ||
|
|
106 | |||
|
|
107 | } | ||
|
|
108 | |||
|
|
109 | } | ||
|
|
110 | else if (status == ContractStatus.Accepted) | ||
|
|
111 | { | ||
|
|
112 | if (ImGui.Button("Cancel")) | ||
|
|
113 | { | ||
|
|
114 | System.Console.Write(string.Format("{0} canceled", entity)); | ||
|
|
115 | |||
|
|
116 | engine.contractStatusMessages.Add(new ChangeContractStatusMessage { Entity = entity, newStatus = ContractStatus.Broken }); | ||
|
|
117 | } | ||
|
|
118 | |||
|
|
119 | } | ||
|
|
120 | |||
|
|
121 | ImGui.Separator(); | ||
|
|
122 | if (ImGui.Button("Okay")) | ||
|
|
123 | { | ||
|
|
124 | newShow = false; | ||
|
|
125 | } | ||
|
|
126 | // Logging.Trace("Almost done."); | ||
|
|
127 | |||
|
|
128 | ImGui.End(); | ||
|
|
129 | ImGui.GetStyle().WindowMenuButtonPosition = ImGuiDir.Left; | ||
|
|
130 | ImGui.PopStyleVar(4); | ||
|
|
131 | ImGui.PopStyleColor(15); | ||
|
|
132 | ImGui.PopFont(); | ||
|
|
133 | |||
|
|
134 | // Logging.Trace("Finished."); | ||
|
|
135 | } | ||
|
|
136 | |||
|
|
137 | if (!newShow) | ||
|
|
138 | { | ||
|
|
139 | engine.messages.Add(new ToggleWindowMessage {Window = Window.Contract, Entity = entity }); | ||
|
|
140 | } | ||
|
|
141 | |||
|
|
142 | engine.selectedMessages.Add(new SelectMessage { Entity = entity }); | ||
|
|
143 | |||
|
|
144 | } | ||
|
|
145 | } | ||
|
|
146 | } |
|
1 | NO CONTENT: modified file, binary diff hidden |
|
NO CONTENT: modified file, binary diff hidden |
@@ -128,6 +128,8 | |||||
|
128 | //Round to the nearest $5 |
|
128 | //Round to the nearest $5 |
|
129 | amount = (decimal)((contract_amount / 5) * 5) |
|
129 | amount = (decimal)((contract_amount / 5) * 5) |
|
130 | }); |
|
130 | }); |
|
|
131 | AddComponent(contract, new WindowTypeComponent { type = Window.Contract}); | ||
|
|
132 | AddComponent(contract, new VisibilityComponent { visible = false}); | ||
|
131 | } |
|
133 | } |
|
132 |
|
134 | ||
|
133 | } |
|
135 | } |
@@ -30,11 +30,18 | |||||
|
30 | foreach (ref readonly var entity in ReadEntities<WindowTypeComponent>()) |
|
30 | foreach (ref readonly var entity in ReadEntities<WindowTypeComponent>()) |
|
31 | { |
|
31 | { |
|
32 | var window_type = GetComponent<WindowTypeComponent>(entity).type; |
|
32 | var window_type = GetComponent<WindowTypeComponent>(entity).type; |
|
33 | if (window_type == windowMessage.Window) |
|
33 | if (window_type == windowMessage.Window && !EntityExists(windowMessage.Entity)) |
|
34 | { |
|
34 | { |
|
35 | var visibilityComponent = GetComponent<VisibilityComponent>(entity); |
|
35 | var visibilityComponent = GetComponent<VisibilityComponent>(entity); |
|
36 | SetComponent(entity, new VisibilityComponent{visible = !visibilityComponent.visible}); |
|
36 | SetComponent(entity, new VisibilityComponent{visible = !visibilityComponent.visible}); |
|
37 | } |
|
37 | } |
|
|
38 | //else if (window_type == windowMessage.Window && entity == windowMessage.Entity) { | ||
|
|
39 | // else if (entity == windowMessage.Entity) { | ||
|
|
40 | else if (EntityExists(windowMessage.Entity) && entity.ID == windowMessage.Entity.ID) { | ||
|
|
41 | var visibilityComponent = GetComponent<VisibilityComponent>(entity); | ||
|
|
42 | SetComponent(entity, new VisibilityComponent{visible = !visibilityComponent.visible}); | ||
|
|
43 | |||
|
|
44 | } | ||
|
38 | } |
|
45 | } |
|
39 | } |
|
46 | } |
|
40 |
|
47 |
@@ -1,4 +1,4 | |||||
|
1 | using System.Collections.Generic; |
|
1 | using System.Collections.Generic; |
|
2 | using System.Linq; |
|
2 | using System.Linq; |
|
3 | using Microsoft.Xna.Framework; |
|
3 | using Microsoft.Xna.Framework; |
|
4 | using Microsoft.Xna.Framework.Audio; |
|
4 | using Microsoft.Xna.Framework.Audio; |
@@ -848,7 +848,27 | |||||
|
848 | { |
|
848 | { |
|
849 | past_fps.Enqueue(this.frameRate); |
|
849 | past_fps.Enqueue(this.frameRate); |
|
850 |
|
850 | ||
|
|
851 | /* | ||
|
|
852 | if (this.frameRate > 60.0) | ||
|
|
853 | { | ||
|
|
854 | Logging.Warning(String.Format("Framerate is higher than limit: {0}", this.frameRate)); | ||
|
|
855 | } | ||
|
|
856 | if (this.frameRate < 30.0) | ||
|
|
857 | { | ||
|
|
858 | Logging.Warning(String.Format("Framerate is lower than desired: {0}", this.frameRate)); | ||
|
|
859 | }*/ | ||
|
851 | } |
|
860 | } |
|
|
861 | /* | ||
|
|
862 | if (this.frameRate > 120.0) | ||
|
|
863 | { | ||
|
|
864 | Logging.Error(String.Format("Framerate is much higher than limit: {0}", this.frameRate)); | ||
|
|
865 | } | ||
|
|
866 | else if (this.frameRate < 15.0) | ||
|
|
867 | { | ||
|
|
868 | Logging.Error(String.Format("Framerate is much lower than desired: {0}", this.frameRate)); | ||
|
|
869 | } | ||
|
|
870 | */ | ||
|
|
871 | |||
|
852 |
|
872 | ||
|
853 | DebugInfo debugInfo = new DebugInfo |
|
873 | DebugInfo debugInfo = new DebugInfo |
|
854 | { fps = this.frameRate, |
|
874 | { fps = this.frameRate, |
@@ -7,12 +7,15 | |||||
|
7 | Budget, |
|
7 | Budget, |
|
8 | Forest, |
|
8 | Forest, |
|
9 | News, |
|
9 | News, |
|
10 | Contracts |
|
10 | Contracts, |
|
|
11 | Contract | ||
|
11 | } |
|
12 | } |
|
12 |
|
13 | ||
|
13 | public struct ToggleWindowMessage : IMessage//, IHasEntity |
|
14 | //You must specify both or you get 0 for a window, which is the default window :( |
|
|
15 | public struct ToggleWindowMessage : IMessage, IHasEntity | ||
|
14 | { |
|
16 | { |
|
15 |
|
17 | ||
|
16 | public Window Window; |
|
18 | public Window Window; |
|
|
19 | public Entity Entity { set; get; } | ||
|
17 | } |
|
20 | } |
|
18 | } |
|
21 | } |
@@ -25,6 +25,17 | |||||
|
25 | this.BridgeEngine = engine; |
|
25 | this.BridgeEngine = engine; |
|
26 | } |
|
26 | } |
|
27 |
|
27 | ||
|
|
28 | private (Entity entity, string name, ContractStatus status, decimal amount, string delta_trees) | ||
|
|
29 | getContractDetails(Entity entity) { | ||
|
|
30 | |||
|
|
31 | var name = GetComponent<NameComponent>(entity).DisplayName; | ||
|
|
32 | var status = GetComponent<ContractStatusComponent>(entity).status; | ||
|
|
33 | var amount = GetComponent<BudgetLineComponent>(entity).amount; | ||
|
|
34 | var tree_delta = GetComponent<TreeDeltaComponent>(entity).deltaTreesName; | ||
|
|
35 | return (entity, name, status, amount, tree_delta); | ||
|
|
36 | |||
|
|
37 | } | ||
|
|
38 | |||
|
28 | public override void Render() |
|
39 | public override void Render() |
|
29 | { |
|
40 | { |
|
30 | foreach (ref readonly var entity in ReadEntities<WindowTypeComponent>()) |
|
41 | foreach (ref readonly var entity in ReadEntities<WindowTypeComponent>()) |
@@ -41,19 +52,23 | |||||
|
41 |
|
52 | ||
|
42 | var contract_data = new List<(Entity, string, ContractStatus, decimal, string)>(); |
|
53 | var contract_data = new List<(Entity, string, ContractStatus, decimal, string)>(); |
|
43 |
|
54 | ||
|
44 | // var names = contracts.Select(entity => GetComponent<NameComponent>(entity).DisplayName) |
|
||
|
45 | foreach(var e in contracts) |
|
55 | foreach(var e in contracts) |
|
46 | { |
|
56 | { |
|
47 | var name = GetComponent<NameComponent>(e).DisplayName; |
|
57 | contract_data.Add(getContractDetails(e)); |
|
48 | var status = GetComponent<ContractStatusComponent>(e).status; |
|
||
|
49 | var amount = GetComponent<BudgetLineComponent>(e).amount; |
|
||
|
50 | var tree_delta = GetComponent<TreeDeltaComponent>(e).deltaTreesName; |
|
||
|
51 | contract_data.Add((e, name, status, amount, tree_delta)); |
|
||
|
52 |
|
|||
|
53 | } |
|
58 | } |
|
54 |
|
59 | ||
|
55 | ContractsWindow.Render(this.font, this.BridgeEngine, contract_data); |
|
60 | ContractsWindow.Render(this.font, this.BridgeEngine, contract_data); |
|
56 | break; |
|
61 | break; |
|
|
62 | case Window.Contract: | ||
|
|
63 | |||
|
|
64 | var data = getContractDetails(entity); | ||
|
|
65 | |||
|
|
66 | ContractWindow.Render(this.font, this.BridgeEngine, entity, data.name, data.status, data.amount, data.delta_trees); | ||
|
|
67 | |||
|
|
68 | //Logging.Trace(string.Format("Rendering Contract Window for {0}", data.name)); | ||
|
|
69 | |||
|
|
70 | break; | ||
|
|
71 | |||
|
57 | default: |
|
72 | default: |
|
58 | break; |
|
73 | break; |
|
59 | } |
|
74 | } |
@@ -20,8 +20,8 | |||||
|
20 | private static (Entity entity, string name, ContractStatus status, decimal amount, string delta_trees) selected; |
|
20 | private static (Entity entity, string name, ContractStatus status, decimal amount, string delta_trees) selected; |
|
21 |
|
21 | ||
|
22 |
|
22 | ||
|
23 |
public static void Render(ImFontPtr font, ImGuiWindowBridgeEngine engine, |
|
23 | public static void Render(ImFontPtr font, ImGuiWindowBridgeEngine engine, |
|
24 |
|
|
24 | List<(Entity entity, string name, ContractStatus status, decimal amount, string delta_trees)> contracts) |
|
25 | { |
|
25 | { |
|
26 | bool newShow = true; |
|
26 | bool newShow = true; |
|
27 |
|
27 | ||
@@ -136,6 +136,13 | |||||
|
136 | } |
|
136 | } |
|
137 |
|
137 | ||
|
138 |
|
138 | ||
|
|
139 | if (ImGui.Button("Open")) | ||
|
|
140 | { | ||
|
|
141 | System.Console.Write(string.Format("{0} opened", ContractsWindow.selected.entity)); | ||
|
|
142 | |||
|
|
143 | engine.messages.Add(new ToggleWindowMessage { Window = Window.Contract, Entity = ContractsWindow.selected.entity}); | ||
|
|
144 | |||
|
|
145 | } | ||
|
139 |
|
146 | ||
|
140 | if (selected.status == ContractStatus.Proposed) |
|
147 | if (selected.status == ContractStatus.Proposed) |
|
141 | { |
|
148 | { |
@@ -176,7 +183,7 | |||||
|
176 | ImGui.End(); |
|
183 | ImGui.End(); |
|
177 | ImGui.GetStyle().WindowMenuButtonPosition = ImGuiDir.Left; |
|
184 | ImGui.GetStyle().WindowMenuButtonPosition = ImGuiDir.Left; |
|
178 | ImGui.PopStyleVar(4); |
|
185 | ImGui.PopStyleVar(4); |
|
179 |
ImGui.PopStyleColor(1 |
|
186 | ImGui.PopStyleColor(15); |
|
180 | ImGui.PopFont(); |
|
187 | ImGui.PopFont(); |
|
181 | } |
|
188 | } |
|
182 |
|
189 |
You need to be logged in to leave comments.
Login now