Description:
Split messages based on types apart from those based on entity.
Commit status:
[Not Reviewed]
References:
Comments:
0 Commit comments 0 Inline Comments
Unresolved TODOs:
There are no unresolved TODOs
Add another comment

r270:c8c82098fa9b -

@@ -8,7 +8,8
8
8
9 namespace isometricparkfna.Engines {
9 namespace isometricparkfna.Engines {
10
10
11 [Receives(typeof(ToggleWindowMessage), typeof(ToggleVisibilityMessage))]
11 [Receives(typeof(ToggleWindowTypeMessage), typeof(ToggleWindowMessage),
12 typeof(ToggleVisibilityMessage))]
12 [Reads(typeof(AreaComponent))]
13 [Reads(typeof(AreaComponent))]
13 class GameBridgeEngine : Engine
14 class GameBridgeEngine : Engine
14 {
15 {
@@ -22,7 +23,7
22 public override void Update(double dt)
23 public override void Update(double dt)
23 {
24 {
24
25
25 foreach (ref readonly var windowMessage in ReadMessages<ToggleWindowMessage>())
26 foreach (ref readonly var windowMessage in ReadMessages<ToggleWindowTypeMessage>())
26 {
27 {
27 switch (windowMessage.Window) {
28 switch (windowMessage.Window) {
28 case Window.Debug:
29 case Window.Debug:
@@ -8,10 +8,11
8 namespace isometricparkfna.Engines {
8 namespace isometricparkfna.Engines {
9
9
10 [Sends(typeof(ToggleWindowMessage),
10 [Sends(typeof(ToggleWindowMessage),
11 typeof(ChangeContractStatusMessage),
11 typeof(ToggleWindowTypeMessage),
12 typeof(SelectMessage))]
12 typeof(ChangeContractStatusMessage),
13 typeof(SelectMessage))]
13 [Reads(typeof(VisibilityComponent),
14 [Reads(typeof(VisibilityComponent),
14 typeof(WindowTypeComponent)
15 typeof(WindowTypeComponent)
15 //, typeof(SelectedComponent)
16 //, typeof(SelectedComponent)
16 )]
17 )]
17 // [Writes(typeof(SelectedComponent))]
18 // [Writes(typeof(SelectedComponent))]
@@ -19,6 +20,7
19 {
20 {
20
21
21 public List<ToggleWindowMessage> messages;
22 public List<ToggleWindowMessage> messages;
23 public List<ToggleWindowTypeMessage> typeMessages;
22 public List<ChangeContractStatusMessage> contractStatusMessages;
24 public List<ChangeContractStatusMessage> contractStatusMessages;
23 public List<SelectMessage> selectedMessages;
25 public List<SelectMessage> selectedMessages;
24
26
@@ -34,6 +36,7
34 public ImGuiWindowBridgeEngine()
36 public ImGuiWindowBridgeEngine()
35 {
37 {
36 this.messages = new List<ToggleWindowMessage>();
38 this.messages = new List<ToggleWindowMessage>();
39 this.typeMessages = new List<ToggleWindowTypeMessage>();
37 this.contractStatusMessages = new List<ChangeContractStatusMessage>();
40 this.contractStatusMessages = new List<ChangeContractStatusMessage>();
38 this.selectedMessages = new List<SelectMessage>();
41 this.selectedMessages = new List<SelectMessage>();
39 this.windowStatuses = new Dictionary<Window, bool>();
42 this.windowStatuses = new Dictionary<Window, bool>();
@@ -50,6 +53,10
50 {
53 {
51 SendMessage(message);
54 SendMessage(message);
52 }
55 }
56 foreach(var message in this.typeMessages)
57 {
58 SendMessage(message);
59 }
53 foreach(var message in this.contractStatusMessages)
60 foreach(var message in this.contractStatusMessages)
54 {
61 {
55 SendMessage(message);
62 SendMessage(message);
@@ -69,6 +76,7
69 }
76 }
70
77
71 this.messages.Clear();
78 this.messages.Clear();
79 this.typeMessages.Clear();
72 this.contractStatusMessages.Clear();
80 this.contractStatusMessages.Clear();
73 this.selectedMessages.Clear();
81 this.selectedMessages.Clear();
74 }
82 }
@@ -15,7 +15,8
15 [Sends( typeof(ZoomCameraMessage),
15 [Sends( typeof(ZoomCameraMessage),
16 typeof(MoveCameraMessage),
16 typeof(MoveCameraMessage),
17 typeof(JumpCameraMessage),
17 typeof(JumpCameraMessage),
18 typeof(ToggleWindowMessage),
18 typeof(ToggleWindowTypeMessage),
19 typeof(ToggleWindowMessage), //???
19 typeof(ToggleVisibilityMessage),
20 typeof(ToggleVisibilityMessage),
20 typeof(TogglePauseMessage),
21 typeof(TogglePauseMessage),
21 typeof(GameRateMessage))]
22 typeof(GameRateMessage))]
@@ -126,27 +127,28
126 #region misc_keys
127 #region misc_keys
127 if (keyboardCur.IsKeyDown(Keys.OemBackslash) && keyboardPrev.IsKeyUp(Keys.OemBackslash))
128 if (keyboardCur.IsKeyDown(Keys.OemBackslash) && keyboardPrev.IsKeyUp(Keys.OemBackslash))
128 {
129 {
129 SendMessage(new ToggleWindowMessage{Window = Window.Debug});
130 SendMessage(new ToggleWindowTypeMessage{Window = Window.Debug});
130
131
131 }
132 }
132 if (keyboardCur.IsKeyDown(Keys.B) && keyboardPrev.IsKeyUp(Keys.B))
133 if (keyboardCur.IsKeyDown(Keys.B) && keyboardPrev.IsKeyUp(Keys.B))
133 {
134 {
134 SendMessage(new ToggleWindowMessage{Window = Window.Budget});
135 SendMessage(new ToggleWindowTypeMessage{Window = Window.Budget});
135
136
136 }
137 }
137 if (keyboardCur.IsKeyDown(Keys.F) && keyboardPrev.IsKeyUp(Keys.F))
138 if (keyboardCur.IsKeyDown(Keys.F) && keyboardPrev.IsKeyUp(Keys.F))
138 {
139 {
139 SendMessage(new ToggleWindowMessage{Window = Window.Forest});
140 SendMessage(new ToggleWindowTypeMessage{Window = Window.Forest});
140
141
141 }
142 }
142 if (keyboardCur.IsKeyDown(Keys.N) && keyboardPrev.IsKeyUp(Keys.N))
143 if (keyboardCur.IsKeyDown(Keys.N) && keyboardPrev.IsKeyUp(Keys.N))
143 {
144 {
144 SendMessage(new ToggleWindowMessage{Window = Window.News});
145 SendMessage(new ToggleWindowTypeMessage{Window = Window.News});
145
146
146 }
147 }
147 if (keyboardCur.IsKeyDown(Keys.O) && keyboardPrev.IsKeyUp(Keys.O))
148 if (keyboardCur.IsKeyDown(Keys.O) && keyboardPrev.IsKeyUp(Keys.O))
148 {
149 {
149 SendMessage(new ToggleWindowMessage{Window = Window.Contracts});
150 Logging.Trace("Contracts toggled.");
151 SendMessage(new ToggleWindowTypeMessage{Window = Window.Contracts});
150 }
152 }
151 if (keyboardCur.IsKeyDown(Keys.G) && keyboardPrev.IsKeyUp(Keys.G))
153 if (keyboardCur.IsKeyDown(Keys.G) && keyboardPrev.IsKeyUp(Keys.G))
152 {
154 {
@@ -23,7 +23,8
23 private Random random_generator;
23 private Random random_generator;
24
24
25 public const int DEFAULT_MIN_SQUARES = 75;
25 public const int DEFAULT_MIN_SQUARES = 75;
26 public const int DEFAULT_SQUARES = 25;
26 // public const int DEFAULT_SQUARES = 25;
27 public const int DEFAULT_SQUARES = 100;
27 public const int CONTRACT_MINIMUM = 50;
28 public const int CONTRACT_MINIMUM = 50;
28 public const int CONTRACT_MAXIMUM = 400;
29 public const int CONTRACT_MAXIMUM = 400;
29
30
@@ -136,8 +137,19
136
137
137 var image_index = random_generator.Next(1, 7);
138 var image_index = random_generator.Next(1, 7);
138
139
139 int max_squares = (message.max_squares == 0) ? DEFAULT_SQUARES : message.max_squares;
140 // int max_squares = (message.max_squares == 0) ? DEFAULT_SQUARES : message.max_squares;
140 int min_squares = (message.min_squares == null) ? DEFAULT_MIN_SQUARES : (int)message.min_squares;
141 // int min_squares = (message.min_squares == null) ? DEFAULT_MIN_SQUARES : (int)message.min_squares;
142
143
144 int max_squares = (organization_type, message.min_squares) switch {
145 (OrganizationType.Family, null) => random_generator.Next(50, 100),
146 (OrganizationType.LargeCorporation, null) => random_generator.Next(75, 125),
147 (OrganizationType.Cooperative, null) => random_generator.Next(50, 75),
148 (_, null) => random_generator.Next(DEFAULT_MIN_SQUARES, DEFAULT_SQUARES),
149 _ => (message.max_squares == 0) ? DEFAULT_SQUARES : message.max_squares
150 };
151
152 int min_squares = (message.min_squares == null) ? (int)(max_squares*0.75f) : (int)message.min_squares;
141
153
142
154
143 var odds_to_try = new[] {0.5f, 0.75f, 1.0f, 0.5f, 0.75f, 1.0f};
155 var odds_to_try = new[] {0.5f, 0.75f, 1.0f, 0.5f, 0.75f, 1.0f};
@@ -10,9 +10,9
10
10
11 namespace isometricparkfna.Engines {
11 namespace isometricparkfna.Engines {
12
12
13 [Receives(typeof(ToggleWindowMessage), typeof(ToggleVisibilityMessage),
13 [Receives(typeof(ToggleWindowMessage), typeof(ToggleWindowTypeMessage), typeof(ToggleVisibilityMessage),
14 typeof(SelectMessage))]
14 typeof(SelectMessage))]
15 [Reads(typeof(WindowTypeComponent), typeof(VisibilityComponent),
15 [Reads(typeof(WindowTypeComponent), typeof(VisibilityComponent),
16 typeof(SelectedComponent))]
16 typeof(SelectedComponent))]
17 [Writes(typeof(VisibilityComponent), typeof(SelectedComponent))]
17 [Writes(typeof(VisibilityComponent), typeof(SelectedComponent))]
18 class UIEngine : Engine
18 class UIEngine : Engine
@@ -20,30 +20,42
20
20
21 public override void Update(double dt)
21 public override void Update(double dt)
22 {
22 {
23 foreach (var entity in ReadEntities<SelectedComponent>())
23 foreach (var entity in ReadEntities<SelectedComponent>())
24 {
24 {
25 SetComponent(entity, new SelectedComponent { selected = false});
25 SetComponent(entity, new SelectedComponent { selected = false});
26 }
26 }
27
27
28 foreach (ref readonly var windowMessage in ReadMessages<ToggleWindowMessage>())
28 foreach (ref readonly var windowMessage in ReadMessages<ToggleWindowMessage>())
29 {
29 {
30 foreach (ref readonly var entity in ReadEntities<WindowTypeComponent>())
30 Logging.Spy(windowMessage, "message");
31 Logging.Spy(windowMessage.Window, "message.Window");
32 Logging.Spy(windowMessage.Entity, "message.Entity");
33 foreach (ref readonly var entity in ReadEntities<WindowTypeComponent>())
31 {
34 {
32 var window_type = GetComponent<WindowTypeComponent>(entity).type;
35 if (EntityExists(windowMessage.Entity) && entity.ID == windowMessage.Entity.ID) {
33 if (window_type == windowMessage.Window && !EntityExists(windowMessage.Entity))
34 {
35 var visibilityComponent = GetComponent<VisibilityComponent>(entity);
36 SetComponent(entity, new VisibilityComponent{visible = !visibilityComponent.visible});
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);
36 var visibilityComponent = GetComponent<VisibilityComponent>(entity);
42 SetComponent(entity, new VisibilityComponent{visible = !visibilityComponent.visible});
37 SetComponent(entity, new VisibilityComponent{visible = !visibilityComponent.visible});
43
38
44 }
39 }
45 }
40 }
46 }
41 }
42 foreach (ref readonly var windowMessage in ReadMessages<ToggleWindowTypeMessage>())
43 {
44 Logging.Spy(windowMessage, "message");
45 Logging.Spy(windowMessage.Window, "message.Window");
46 foreach (ref readonly var entity in ReadEntities<WindowTypeComponent>())
47 {
48
49 var window_type = GetComponent<WindowTypeComponent>(entity).type;
50 if (window_type == windowMessage.Window)
51 {
52 var visibilityComponent = GetComponent<VisibilityComponent>(entity);
53 SetComponent(entity, new VisibilityComponent{visible = !visibilityComponent.visible});
54 }
55 //else if (window_type == windowMessage.Window && entity == windowMessage.Entity) {
56 // else if (entity == windowMessage.Entity) {
57 }
58 }
47
59
48 foreach (ref readonly var selectedMessage in ReadMessages<SelectMessage>())
60 foreach (ref readonly var selectedMessage in ReadMessages<SelectMessage>())
49 {
61 {
@@ -53,4 +65,4
53
65
54 }
66 }
55 }
67 }
56 } No newline at end of file
68 }
@@ -2,15 +2,6
2
2
3 namespace isometricparkfna.Messages {
3 namespace isometricparkfna.Messages {
4
4
5 public enum Window {
6 Debug,
7 Budget,
8 Forest,
9 News,
10 Contracts,
11 Contract
12 }
13
14 //You must specify both or you get 0 for a window, which is the default window :(
5 //You must specify both or you get 0 for a window, which is the default window :(
15 public struct ToggleWindowMessage : IMessage, IHasEntity
6 public struct ToggleWindowMessage : IMessage, IHasEntity
16 {
7 {
@@ -2,6 +2,7
2 using Microsoft.Xna.Framework.Graphics;
2 using Microsoft.Xna.Framework.Graphics;
3
3
4 using System.Collections.Generic;
4 using System.Collections.Generic;
5 using System.Linq;
5
6
6 using isometricparkfna.UI;
7 using isometricparkfna.UI;
7 using isometricparkfna.Engines;
8 using isometricparkfna.Engines;
@@ -79,9 +80,11
79
80
80 var data = getContractDetails(entity);
81 var data = getContractDetails(entity);
81
82
82 ContractWindow.Render(this.font, this.italicFont, this.BridgeEngine, entity, data.name, data.description, data.status, data.amount, data.delta_trees, data.image_index);
83 // var area_size = GetComponent<AreaComponent>(entity).squares.Length;
84 var area = GetComponent<AreaComponent>(entity).squares;
85 var area_size = GetComponent<AreaComponent>(entity).squares.Length;
83
86
84 //Logging.Trace(string.Format("Rendering Contract Window for {0}", data.name));
87 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);
85
88
86 break;
89 break;
87
90
@@ -95,4 +98,4
95 }
98 }
96
99
97 }
100 }
98 } No newline at end of file
101 }
@@ -144,7 +144,9
144
144
145 if (!newShow)
145 if (!newShow)
146 {
146 {
147 engine.messages.Add(new ToggleWindowMessage { Window = Window.Contracts });
147 Logging.Spy(newShow, "newShow");
148 Logging.Trace("Contracts toggled.");
149 engine.typeMessages.Add(new ToggleWindowTypeMessage { Window = Window.Contracts });
148 }
150 }
149
151
150 engine.selectedMessages.Add(new SelectMessage { Entity = selected.entity });
152 engine.selectedMessages.Add(new SelectMessage { Entity = selected.entity });
@@ -52,7 +52,7
52 }
52 }
53 if (show != newShow)
53 if (show != newShow)
54 {
54 {
55 engine.messages.Add(new ToggleWindowMessage {Window = Window.Forest });
55 engine.typeMessages.Add(new ToggleWindowTypeMessage {Window = Window.Forest });
56 }
56 }
57 }
57 }
58 }
58 }
@@ -60,22 +60,24
60
60
61 if (Menu.activeButton("\ue0c2 Contracts", bridgeEngine.windowStatuses[Window.Contracts], new Num.Vector4(0.060f, 0.590f, 0.980f, 1f)))
61 if (Menu.activeButton("\ue0c2 Contracts", bridgeEngine.windowStatuses[Window.Contracts], new Num.Vector4(0.060f, 0.590f, 0.980f, 1f)))
62 {
62 {
63 bridgeEngine.messages.Add(new ToggleWindowMessage{Window = Window.Contracts});
63 Logging.Trace("Contracts toggled.");
64 Logging.Spy(bridgeEngine.windowStatuses, "statuses");
65 bridgeEngine.typeMessages.Add(new ToggleWindowTypeMessage{Window = Window.Contracts});
64 }
66 }
65 //Budget isn't connected to an entity yet:
67 //Budget isn't connected to an entity yet:
66 if (Menu.activeButton("$ Budget", showBudget, new Num.Vector4(0.060f, 0.590f, 0.980f, 1f)))
68 if (Menu.activeButton("$ Budget", showBudget, new Num.Vector4(0.060f, 0.590f, 0.980f, 1f)))
67 {
69 {
68 bridgeEngine.messages.Add(new ToggleWindowMessage{Window = Window.Budget});
70 bridgeEngine.typeMessages.Add(new ToggleWindowTypeMessage{Window = Window.Budget});
69
71
70 }
72 }
71 if (Menu.activeButton("\ue124 Forest", bridgeEngine.windowStatuses[Window.Forest], new Num.Vector4(0.060f, 0.590f, 0.980f, 1f)))
73 if (Menu.activeButton("\ue124 Forest", bridgeEngine.windowStatuses[Window.Forest], new Num.Vector4(0.060f, 0.590f, 0.980f, 1f)))
72 {
74 {
73 bridgeEngine.messages.Add(new ToggleWindowMessage{Window = Window.Forest});
75 bridgeEngine.typeMessages.Add(new ToggleWindowTypeMessage{Window = Window.Forest});
74
76
75 }
77 }
76 if (Menu.activeButton("\ue0bf News", bridgeEngine.windowStatuses[Window.News], new Num.Vector4(0.060f, 0.590f, 0.980f, 1f)))
78 if (Menu.activeButton("\ue0bf News", bridgeEngine.windowStatuses[Window.News], new Num.Vector4(0.060f, 0.590f, 0.980f, 1f)))
77 {
79 {
78 bridgeEngine.messages.Add(new ToggleWindowMessage{Window = Window.News});
80 bridgeEngine.typeMessages.Add(new ToggleWindowTypeMessage{Window = Window.News});
79 }
81 }
80
82
81 ImGui.Text("|");
83 ImGui.Text("|");
@@ -31,8 +31,8
31 }
31 }
32 }
32 }
33
33
34 // variableString += "vars# ";
34 variableString += "vars# ";
35 // var result = grammar.Flatten(variableString);
35 var result = grammar.Flatten(variableString);
36 // Logging.Trace(String.Format("{0}: {1}", variableString, result));
36 // Logging.Trace(String.Format("{0}: {1}", variableString, result));
37
37
38 return new NewsItem {
38 return new NewsItem {
@@ -143,7 +143,7
143
143
144 if (show != newShow)
144 if (show != newShow)
145 {
145 {
146 engine.messages.Add(new ToggleWindowMessage {Window = Window.News });
146 engine.typeMessages.Add(new ToggleWindowTypeMessage {Window = Window.News });
147 }
147 }
148 }
148 }
149 }
149 }
You need to be logged in to leave comments. Login now