Description:
Limit commands to when the game is running.
Commit status:
[Not Reviewed]
References:
Diff options:
Comments:
0 Commit comments
0 Inline Comments
Unresolved TODOs:
There are no unresolved TODOs
@@ -8,8 +8,8 | |||||
|
8 |
|
8 | ||
|
9 | [Receives(typeof(GameStateMessage))] |
|
9 | [Receives(typeof(GameStateMessage))] |
|
10 | [Sends(typeof(ToggleWindowTypeMessage))] |
|
10 | [Sends(typeof(ToggleWindowTypeMessage))] |
|
11 | [Reads()] |
|
11 | [Reads(typeof(GameStateComponent))] |
|
12 | [Writes()] |
|
12 | [Writes(typeof(GameStateComponent))] |
|
13 | class GameStateEngine : Engine |
|
13 | class GameStateEngine : Engine |
|
14 | { |
|
14 | { |
|
15 |
|
15 | ||
@@ -22,7 +22,15 | |||||
|
22 | { |
|
22 | { |
|
23 | startGame(); |
|
23 | startGame(); |
|
24 | } |
|
24 | } |
|
25 | SendMessage(new ToggleWindowTypeMessage { Window = Window.MainMenu}); |
|
25 | SendMessage(new ToggleWindowTypeMessage { Window = Window.MainMenu}); |
|
|
26 | |||
|
|
27 | foreach (var entity in ReadEntities<GameStateComponent>()) | ||
|
|
28 | { | ||
|
|
29 | var state = GetComponent<GameStateComponent>(entity).isPlaying; | ||
|
|
30 | Logging.Spy(state, "state"); | ||
|
|
31 | |||
|
|
32 | SetComponent(entity, new GameStateComponent{isPlaying = message.isPlaying}); | ||
|
|
33 | } | ||
|
26 | } |
|
34 | } |
|
27 |
|
35 | ||
|
28 | } |
|
36 | } |
@@ -31,6 +39,5 | |||||
|
31 | { |
|
39 | { |
|
32 |
|
40 | ||
|
33 | } |
|
41 | } |
|
34 |
|
|||
|
35 | } |
|
42 | } |
|
36 | } |
|
43 | } |
@@ -23,6 +23,7 | |||||
|
23 | typeof(GameRateMessage), |
|
23 | typeof(GameRateMessage), |
|
24 | typeof(GameStateMessage))] |
|
24 | typeof(GameStateMessage))] |
|
25 | [Reads(typeof(WindowTypeComponent), |
|
25 | [Reads(typeof(WindowTypeComponent), |
|
|
26 | typeof(GameStateComponent), | ||
|
26 | typeof(VisibilityComponent))] |
|
27 | typeof(VisibilityComponent))] |
|
27 | public class InputEngine : Engine |
|
28 | public class InputEngine : Engine |
|
28 | { |
|
29 | { |
@@ -56,135 +57,139 | |||||
|
56 | var original_point = Vector2.Transform(new Vector2(mouseCur.X, mouseCur.Y), |
|
57 | var original_point = Vector2.Transform(new Vector2(mouseCur.X, mouseCur.Y), |
|
57 | Matrix.Invert(this.camera.get_transformation(this.graphicsDevice))); |
|
58 | Matrix.Invert(this.camera.get_transformation(this.graphicsDevice))); |
|
58 |
|
59 | ||
|
59 | #region camera_movement_keys |
|
60 | bool isPlaying = false; |
|
60 | if (keyboardCur.IsKeyDown(Keys.Down)) |
|
||
|
61 | { |
|
||
|
62 | SendMessage(new MoveCameraMessage{ Movement = new Vector2(0, 2)}); |
|
||
|
63 | } |
|
||
|
64 | if (keyboardCur.IsKeyDown(Keys.Up)) |
|
||
|
65 | { |
|
||
|
66 | SendMessage(new MoveCameraMessage{ Movement = new Vector2(0, -2)}); |
|
||
|
67 |
|
|||
|
68 | } |
|
||
|
69 | if (keyboardCur.IsKeyDown(Keys.Left)) |
|
||
|
70 | { |
|
||
|
71 | SendMessage(new MoveCameraMessage{ Movement = new Vector2(-2, 0)}); |
|
||
|
72 |
|
61 | ||
|
73 | } |
|
62 | foreach (var entity in ReadEntities<GameStateComponent>()) |
|
74 | if (keyboardCur.IsKeyDown(Keys.Right)) |
|
||
|
75 | { |
|
||
|
76 | SendMessage(new MoveCameraMessage {Movement = new Vector2(2, 0)}); |
|
||
|
77 |
|
|||
|
78 | } |
|
||
|
79 | if (keyboardCur.IsKeyDown(Keys.Subtract) && keyboardPrev.IsKeyUp(Keys.Subtract)) |
|
||
|
80 | { |
|
63 | { |
|
81 | SendMessage(new ZoomCameraMessage {ZoomIn = false}); |
|
64 | var state = GetComponent<GameStateComponent>(entity).isPlaying; |
|
82 | } |
|
65 | isPlaying = state; |
|
83 | else if (keyboardCur.IsKeyDown(Keys.Add) && keyboardPrev.IsKeyUp(Keys.Add)) |
|
||
|
84 | { |
|
||
|
85 | SendMessage(new ZoomCameraMessage {ZoomIn = true}); |
|
||
|
86 | } |
|
||
|
87 | if (keyboardCur.IsKeyDown(Keys.C) && keyboardPrev.IsKeyUp(Keys.C)) |
|
||
|
88 | { |
|
||
|
89 | SendMessage(new JumpCameraMessage {Movement = Vector2.Zero }); |
|
||
|
90 | } |
|
66 | } |
|
91 | #endregion camera_movement_keys |
|
||
|
92 | #region gamerate_keys |
|
||
|
93 | if (keyboardCur.IsKeyDown(Keys.P) && keyboardPrev.IsKeyUp(Keys.P) ) |
|
||
|
94 | { |
|
||
|
95 |
|
67 | ||
|
96 | SendMessage(new TogglePauseMessage()); |
|
68 | if (isPlaying) |
|
97 |
|
|||
|
98 | } |
|
||
|
99 | if (keyboardCur.IsKeyDown(Keys.D0) && keyboardPrev.IsKeyUp(Keys.D0) ) |
|
||
|
100 | { |
|
||
|
101 | SendMessage(new TogglePauseMessage()); |
|
||
|
102 |
|
|||
|
103 | } |
|
||
|
104 | if (keyboardCur.IsKeyDown(Keys.D1) && keyboardPrev.IsKeyUp(Keys.D1) ) |
|
||
|
105 | { |
|
||
|
106 | SendMessage(new GameRateMessage { |
|
||
|
107 | paused = false, |
|
||
|
108 | rate = 0}); |
|
||
|
109 | } |
|
||
|
110 | if (keyboardCur.IsKeyDown(Keys.D2) && keyboardPrev.IsKeyUp(Keys.D2) ) |
|
||
|
111 | { |
|
||
|
112 | SendMessage(new GameRateMessage { |
|
||
|
113 | paused = false, |
|
||
|
114 | rate = 1}); |
|
||
|
115 | } |
|
||
|
116 | if (keyboardCur.IsKeyDown(Keys.D3) && keyboardPrev.IsKeyUp(Keys.D3) ) |
|
||
|
117 | { |
|
||
|
118 | SendMessage(new GameRateMessage { |
|
||
|
119 | paused = false, |
|
||
|
120 | rate = 2}); |
|
||
|
121 | } |
|
||
|
122 | if (keyboardCur.IsKeyDown(Keys.D4) && keyboardPrev.IsKeyUp(Keys.D4) ) |
|
||
|
123 | { |
|
69 | { |
|
124 | SendMessage(new GameRateMessage { |
|
70 | #region camera_movement_keys |
|
125 | paused = false, |
|
71 | if (keyboardCur.IsKeyDown(Keys.Down)) |
|
126 | rate = 3}); |
|
72 | { |
|
127 | } |
|
73 | SendMessage(new MoveCameraMessage{ Movement = new Vector2(0, 2)}); |
|
128 | #if DEBUG |
|
74 | } |
|
129 |
if (keyboardCur.IsKeyDown(Keys. |
|
75 | if (keyboardCur.IsKeyDown(Keys.Up)) |
|
130 | { |
|
76 | { |
|
131 | SendMessage(new GameRateMessage { |
|
77 | SendMessage(new MoveCameraMessage{ Movement = new Vector2(0, -2)}); |
|
132 | paused = false, |
|
78 | |
|
133 | rate = 4}); |
|
79 | } |
|
134 | } |
|
80 | if (keyboardCur.IsKeyDown(Keys.Left)) |
|
135 | #endif |
|
81 | { |
|
136 | #endregion gamerate_keys |
|
82 | SendMessage(new MoveCameraMessage{ Movement = new Vector2(-2, 0)}); |
|
137 | #region misc_keys |
|
83 | |
|
138 | if (keyboardCur.IsKeyDown(Keys.OemBackslash) && keyboardPrev.IsKeyUp(Keys.OemBackslash)) |
|
84 | } |
|
139 | { |
|
85 | if (keyboardCur.IsKeyDown(Keys.Right)) |
|
140 | SendMessage(new ToggleWindowTypeMessage{Window = Window.Debug}); |
|
86 | { |
|
|
87 | SendMessage(new MoveCameraMessage {Movement = new Vector2(2, 0)}); | ||
|
|
88 | |||
|
|
89 | } | ||
|
|
90 | if (keyboardCur.IsKeyDown(Keys.Subtract) && keyboardPrev.IsKeyUp(Keys.Subtract)) | ||
|
|
91 | { | ||
|
|
92 | SendMessage(new ZoomCameraMessage {ZoomIn = false}); | ||
|
|
93 | } | ||
|
|
94 | else if (keyboardCur.IsKeyDown(Keys.Add) && keyboardPrev.IsKeyUp(Keys.Add)) | ||
|
|
95 | { | ||
|
|
96 | SendMessage(new ZoomCameraMessage {ZoomIn = true}); | ||
|
|
97 | } | ||
|
|
98 | if (keyboardCur.IsKeyDown(Keys.C) && keyboardPrev.IsKeyUp(Keys.C)) | ||
|
|
99 | { | ||
|
|
100 | SendMessage(new JumpCameraMessage {Movement = Vector2.Zero }); | ||
|
|
101 | } | ||
|
|
102 | #endregion camera_movement_keys | ||
|
|
103 | #region gamerate_keys | ||
|
|
104 | if (keyboardCur.IsKeyDown(Keys.P) && keyboardPrev.IsKeyUp(Keys.P) ) | ||
|
|
105 | { | ||
|
|
106 | |||
|
|
107 | SendMessage(new TogglePauseMessage()); | ||
|
|
108 | |||
|
|
109 | } | ||
|
|
110 | if (keyboardCur.IsKeyDown(Keys.D0) && keyboardPrev.IsKeyUp(Keys.D0) ) | ||
|
|
111 | { | ||
|
|
112 | SendMessage(new TogglePauseMessage()); | ||
|
141 |
|
113 | ||
|
142 | } |
|
114 | } |
|
143 |
if (keyboardCur.IsKeyDown(Keys. |
|
115 | if (keyboardCur.IsKeyDown(Keys.D1) && keyboardPrev.IsKeyUp(Keys.D1) ) |
|
144 | { |
|
116 | { |
|
145 | SendMessage(new ToggleWindowTypeMessage{Window = Window.Budget}); |
|
117 | SendMessage(new GameRateMessage { |
|
|
118 | paused = false, | ||
|
|
119 | rate = 0}); | ||
|
|
120 | } | ||
|
|
121 | if (keyboardCur.IsKeyDown(Keys.D2) && keyboardPrev.IsKeyUp(Keys.D2) ) | ||
|
|
122 | { | ||
|
|
123 | SendMessage(new GameRateMessage { | ||
|
|
124 | paused = false, | ||
|
|
125 | rate = 1}); | ||
|
|
126 | } | ||
|
|
127 | if (keyboardCur.IsKeyDown(Keys.D3) && keyboardPrev.IsKeyUp(Keys.D3) ) | ||
|
|
128 | { | ||
|
|
129 | SendMessage(new GameRateMessage { | ||
|
|
130 | paused = false, | ||
|
|
131 | rate = 2}); | ||
|
|
132 | } | ||
|
|
133 | if (keyboardCur.IsKeyDown(Keys.D4) && keyboardPrev.IsKeyUp(Keys.D4) ) | ||
|
|
134 | { | ||
|
|
135 | SendMessage(new GameRateMessage { | ||
|
|
136 | paused = false, | ||
|
|
137 | rate = 3}); | ||
|
|
138 | } | ||
|
|
139 | #if DEBUG | ||
|
|
140 | if (keyboardCur.IsKeyDown(Keys.D5) && keyboardPrev.IsKeyUp(Keys.D5) ) | ||
|
|
141 | { | ||
|
|
142 | SendMessage(new GameRateMessage { | ||
|
|
143 | paused = false, | ||
|
|
144 | rate = 4}); | ||
|
|
145 | } | ||
|
|
146 | #endif | ||
|
|
147 | #endregion gamerate_keys | ||
|
|
148 | #region misc_keys | ||
|
|
149 | if (keyboardCur.IsKeyDown(Keys.OemBackslash) && keyboardPrev.IsKeyUp(Keys.OemBackslash)) | ||
|
|
150 | { | ||
|
|
151 | SendMessage(new ToggleWindowTypeMessage{Window = Window.Debug}); | ||
|
146 |
|
152 | ||
|
147 | } |
|
153 | } |
|
148 |
if (keyboardCur.IsKeyDown(Keys. |
|
154 | if (keyboardCur.IsKeyDown(Keys.B) && keyboardPrev.IsKeyUp(Keys.B)) |
|
149 | { |
|
155 | { |
|
150 |
SendMessage(new ToggleWindowTypeMessage{Window = Window. |
|
156 | SendMessage(new ToggleWindowTypeMessage{Window = Window.Budget}); |
|
|
157 | |||
|
|
158 | } | ||
|
|
159 | if (keyboardCur.IsKeyDown(Keys.F) && keyboardPrev.IsKeyUp(Keys.F)) | ||
|
|
160 | { | ||
|
|
161 | SendMessage(new ToggleWindowTypeMessage{Window = Window.Forest}); | ||
|
|
162 | |||
|
|
163 | } | ||
|
|
164 | if (keyboardCur.IsKeyDown(Keys.N) && keyboardPrev.IsKeyUp(Keys.N)) | ||
|
|
165 | { | ||
|
|
166 | SendMessage(new ToggleWindowTypeMessage{Window = Window.News}); | ||
|
151 |
|
167 | ||
|
152 | } |
|
168 | } |
|
153 |
if (keyboardCur.IsKeyDown(Keys. |
|
169 | if (keyboardCur.IsKeyDown(Keys.O) && keyboardPrev.IsKeyUp(Keys.O)) |
|
|
170 | { | ||
|
|
171 | Logging.Trace("Contracts toggled."); | ||
|
|
172 | SendMessage(new ToggleWindowTypeMessage{Window = Window.Contracts}); | ||
|
|
173 | } | ||
|
|
174 | if (keyboardCur.IsKeyDown(Keys.G) && keyboardPrev.IsKeyUp(Keys.G)) | ||
|
|
175 | { | ||
|
|
176 | SendMessage(new ToggleVisibilityMessage{Element = Element.Grid}); | ||
|
|
177 | |||
|
|
178 | } | ||
|
|
179 | #if DEBUG | ||
|
|
180 | if (keyboardCur.IsKeyDown(Keys.T) && keyboardPrev.IsKeyUp(Keys.T)) | ||
|
|
181 | { | ||
|
|
182 | SendMessage(new ToggleVisibilityMessage{Element = Element.Trees}); | ||
|
|
183 | |||
|
|
184 | } | ||
|
|
185 | #endif | ||
|
|
186 | |||
|
|
187 | if (keyboardCur.IsKeyDown(Keys.Escape) && keyboardPrev.IsKeyUp(Keys.Escape)) | ||
|
154 | { |
|
188 | { |
|
155 |
|
|
189 | // SendMessage(new TogglePauseMessage()); |
|
156 |
|
190 | SendMessage(new ToggleWindowTypeMessage{Window = Window.InGameMenu}); | |
|
157 | } |
|
191 | SendMessage(new GameRateMessage { paused = true, rate = null }); |
|
158 | if (keyboardCur.IsKeyDown(Keys.O) && keyboardPrev.IsKeyUp(Keys.O)) |
|
||
|
159 | { |
|
||
|
160 | Logging.Trace("Contracts toggled."); |
|
||
|
161 | SendMessage(new ToggleWindowTypeMessage{Window = Window.Contracts}); |
|
||
|
162 | } |
|
||
|
163 | if (keyboardCur.IsKeyDown(Keys.G) && keyboardPrev.IsKeyUp(Keys.G)) |
|
||
|
164 | { |
|
||
|
165 | SendMessage(new ToggleVisibilityMessage{Element = Element.Grid}); |
|
||
|
166 |
|
|||
|
167 | } |
|
192 | } |
|
168 | #if DEBUG |
|
||
|
169 | if (keyboardCur.IsKeyDown(Keys.T) && keyboardPrev.IsKeyUp(Keys.T)) |
|
||
|
170 | { |
|
||
|
171 | SendMessage(new ToggleVisibilityMessage{Element = Element.Trees}); |
|
||
|
172 |
|
|||
|
173 | } |
|
||
|
174 | #endif |
|
||
|
175 |
|
|||
|
176 | #if DEBUG |
|
||
|
177 |
|
|||
|
178 | if (keyboardCur.IsKeyDown(Keys.A) && keyboardPrev.IsKeyUp(Keys.A)) |
|
||
|
179 | { |
|
||
|
180 | SendMessage(new GameStateMessage {isPlaying = false}); |
|
||
|
181 | } |
|
||
|
182 | #endif |
|
||
|
183 | if (keyboardCur.IsKeyDown(Keys.Escape) && keyboardPrev.IsKeyUp(Keys.Escape)) |
|
||
|
184 | { |
|
||
|
185 | // SendMessage(new TogglePauseMessage()); |
|
||
|
186 | SendMessage(new ToggleWindowTypeMessage{Window = Window.InGameMenu}); |
|
||
|
187 | SendMessage(new GameRateMessage { paused = true, rate = null }); |
|
||
|
188 | } |
|
193 | } |
|
189 |
|
194 | ||
|
190 | if (keyboardCur.IsKeyDown(Keys.Q) && keyboardPrev.IsKeyUp(Keys.Q)) |
|
195 | if (keyboardCur.IsKeyDown(Keys.Q) && keyboardPrev.IsKeyUp(Keys.Q)) |
@@ -262,9 +262,10 | |||||
|
262 | WorldBuilder.SetComponent(inputMenu, new WindowTypeComponent { type = isometricparkfna.Messages.Window.InGameMenu }); |
|
262 | WorldBuilder.SetComponent(inputMenu, new WindowTypeComponent { type = isometricparkfna.Messages.Window.InGameMenu }); |
|
263 |
|
263 | ||
|
264 |
|
264 | ||
|
265 |
|
|
265 | var gameEntity = WorldBuilder.CreateEntity(); |
|
266 | // WorldBuilder.SetComponent(budgetWindow, new VisibilityComponent{visible = true}); |
|
266 | |
|
267 |
|
|
267 | WorldBuilder.SetComponent(gameEntity, new GameStateComponent { isPlaying = false}); |
|
|
268 | |||
|
268 |
|
269 | ||
|
269 | var area = WorldBuilder.CreateEntity(); |
|
270 | var area = WorldBuilder.CreateEntity(); |
|
270 | // WorldBuilder.SetComponent(area, new AreaComponent{squares = new[] {new Vector2(4,4), new Vector2(5,4)}}); |
|
271 | // WorldBuilder.SetComponent(area, new AreaComponent{squares = new[] {new Vector2(4,4), new Vector2(5,4)}}); |
@@ -32,17 +32,14 | |||||
|
32 | if (ImGui.Button("New Game", button_size)) |
|
32 | if (ImGui.Button("New Game", button_size)) |
|
33 | { |
|
33 | { |
|
34 | bridgeEngine.gameStateMessages.Add(new GameStateMessage { isPlaying = true}); |
|
34 | bridgeEngine.gameStateMessages.Add(new GameStateMessage { isPlaying = true}); |
|
35 |
|
|
35 | } |
|
36 |
|
36 | ||
|
37 | } |
|
||
|
38 | if (ImGui.Button("Quit", button_size)) |
|
37 | if (ImGui.Button("Quit", button_size)) |
|
39 | { |
|
38 | { |
|
40 |
|
|||
|
41 | System.Console.WriteLine("Quitting"); |
|
39 | System.Console.WriteLine("Quitting"); |
|
42 | Environment.Exit(0); |
|
40 | Environment.Exit(0); |
|
43 | } |
|
41 | } |
|
44 |
|
42 | ||
|
45 |
|
|||
|
46 | ImGui.End(); |
|
43 | ImGui.End(); |
|
47 |
|
44 | ||
|
48 |
|
45 |
You need to be logged in to leave comments.
Login now