Description:
Loads more porting.
(grafted from 383cf2eccdad5a8c72b1ee8a20ebfc67f3bbf8ac)
Commit status:
[Not Reviewed]
References:
Diff options:
Comments:
0 Commit comments
0 Inline Comments
Unresolved TODOs:
There are no unresolved TODOs
@@ -0,0 +1,42 | |||
|
1 | ||
|
2 | using Encompass; | |
|
3 | ||
|
4 | using isometricparkfna.Messages; | |
|
5 | using isometricparkfna.Components; | |
|
6 | ||
|
7 | namespace isometricparkfna.Engines { | |
|
8 | ||
|
9 | [Receives(typeof(ZoomCameraMessage), typeof(MoveCameraMessage))] | |
|
10 | class CameraBridgeEngine : Engine | |
|
11 | { | |
|
12 | private Camera Camera; | |
|
13 | ||
|
14 | public CameraBridgeEngine(Camera camera) | |
|
15 | { | |
|
16 | this.Camera = camera; | |
|
17 | } | |
|
18 | ||
|
19 | ||
|
20 | public override void Update(double dt) | |
|
21 | { | |
|
22 | foreach (ref readonly var message in ReadMessages<ZoomCameraMessage>()) | |
|
23 | { | |
|
24 | if (message.ZoomIn) | |
|
25 | { | |
|
26 | this.Camera.ZoomIn(); | |
|
27 | } | |
|
28 | else | |
|
29 | { | |
|
30 | this.Camera.ZoomOut(); | |
|
31 | } | |
|
32 | } | |
|
33 | ||
|
34 | foreach (ref readonly var message in ReadMessages<MoveCameraMessage>()) | |
|
35 | { | |
|
36 | this.Camera.Move(message.Movement); | |
|
37 | ||
|
38 | } | |
|
39 | ||
|
40 | } | |
|
41 | } | |
|
42 | } |
@@ -0,0 +1,13 | |||
|
1 | ||
|
2 | ||
|
3 | using Encompass; | |
|
4 | ||
|
5 | namespace isometricparkfna.Messages { | |
|
6 | ||
|
7 | ||
|
8 | public struct GameRateMessage : IMessage//, IHasEntity | |
|
9 | { | |
|
10 | public bool paused; | |
|
11 | public int rate; | |
|
12 | } | |
|
13 | } |
@@ -0,0 +1,10 | |||
|
1 | ||
|
2 | using Microsoft.Xna.Framework; | |
|
3 | using Encompass; | |
|
4 | ||
|
5 | namespace isometricparkfna.Messages { | |
|
6 | public struct MoveCameraMessage : IMessage//, IHasEntity | |
|
7 | { | |
|
8 | public Vector2 Movement; | |
|
9 | } | |
|
10 | } |
@@ -0,0 +1,7 | |||
|
1 | ||
|
2 | using Encompass; | |
|
3 | ||
|
4 | namespace isometricparkfna.Messages { | |
|
5 | ||
|
6 | public struct TogglePauseMessage : IMessage { } | |
|
7 | } |
@@ -0,0 +1,8 | |||
|
1 | using Encompass; | |
|
2 | ||
|
3 | namespace isometricparkfna.Messages { | |
|
4 | public struct ZoomCameraMessage : IMessage//, IHasEntity | |
|
5 | { | |
|
6 | public bool ZoomIn; | |
|
7 | } | |
|
8 | } |
|
1 | NO CONTENT: modified file, binary diff hidden |
@@ -1,4 +1,6 | |||
|
1 | 1 | |
|
2 | using System; | |
|
3 | using Microsoft.Xna.Framework; | |
|
2 | 4 | using Microsoft.Xna.Framework.Input; |
|
3 | 5 | |
|
4 | 6 | using Encompass; |
@@ -9,20 +11,104 | |||
|
9 | 11 | |
|
10 | 12 | |
|
11 | 13 | |
|
12 | [Sends(typeof(ToggleWindowMessage), typeof(ToggleVisibilityMessage))] | |
|
14 | [Sends( typeof(ZoomCameraMessage), | |
|
15 | typeof(MoveCameraMessage), | |
|
16 | typeof(ToggleWindowMessage), | |
|
17 | typeof(ToggleVisibilityMessage), | |
|
18 | typeof(TogglePauseMessage), | |
|
19 | typeof(GameRateMessage))] | |
|
13 | 20 | public class InputEngine : Engine |
|
14 | 21 | { |
|
15 | 22 | private KeyboardState keyboardPrev; |
|
16 | 23 | |
|
17 | public InputEngine() { | |
|
24 | //Area to ignore: | |
|
25 | private int menuBarHeight; | |
|
26 | ||
|
27 | public InputEngine(int menuBarHeight) { | |
|
18 | 28 | //initialize to blank for now |
|
19 | 29 | this.keyboardPrev = new KeyboardState(); |
|
30 | menuBarHeight = menuBarHeight; | |
|
20 | 31 | } |
|
21 | 32 | |
|
22 | 33 | public override void Update(double dt) { |
|
23 | 34 | |
|
24 | 35 | var keyboardCur = Keyboard.GetState(); |
|
36 | var mouseCur = Mouse.GetState(); | |
|
25 | 37 | |
|
38 | #region camera_movement_keys | |
|
39 | if (keyboardCur.IsKeyDown(Keys.Down)) | |
|
40 | { | |
|
41 | SendMessage(new MoveCameraMessage{ Movement = new Vector2(0, 2)}); | |
|
42 | } | |
|
43 | else if (keyboardCur.IsKeyDown(Keys.Up)) | |
|
44 | { | |
|
45 | SendMessage(new MoveCameraMessage{ Movement = new Vector2(0, -2)}); | |
|
46 | ||
|
47 | } | |
|
48 | else if (keyboardCur.IsKeyDown(Keys.Left)) | |
|
49 | { | |
|
50 | SendMessage(new MoveCameraMessage{ Movement = new Vector2(-2, 0)}); | |
|
51 | ||
|
52 | } | |
|
53 | else if (keyboardCur.IsKeyDown(Keys.Right)) | |
|
54 | { | |
|
55 | SendMessage(new MoveCameraMessage {Movement = new Vector2(2, 0)}); | |
|
56 | ||
|
57 | } | |
|
58 | else if (keyboardCur.IsKeyDown(Keys.Subtract) && keyboardPrev.IsKeyUp(Keys.Subtract)) | |
|
59 | { | |
|
60 | SendMessage(new ZoomCameraMessage {ZoomIn = false}); | |
|
61 | } | |
|
62 | else if (keyboardCur.IsKeyDown(Keys.Add) && keyboardPrev.IsKeyUp(Keys.Add)) | |
|
63 | { | |
|
64 | SendMessage(new ZoomCameraMessage {ZoomIn = true}); | |
|
65 | } | |
|
66 | #endregion camera_movement_keys | |
|
67 | #region gamerate_keys | |
|
68 | if (keyboardCur.IsKeyDown(Keys.P) && keyboardPrev.IsKeyUp(Keys.P) ) | |
|
69 | { | |
|
70 | ||
|
71 | SendMessage(new TogglePauseMessage()); | |
|
72 | ||
|
73 | } | |
|
74 | if (keyboardCur.IsKeyDown(Keys.D0) && keyboardPrev.IsKeyUp(Keys.D0) ) | |
|
75 | { | |
|
76 | SendMessage(new TogglePauseMessage()); | |
|
77 | ||
|
78 | } | |
|
79 | if (keyboardCur.IsKeyDown(Keys.D1) && keyboardPrev.IsKeyUp(Keys.D1) ) | |
|
80 | { | |
|
81 | SendMessage(new GameRateMessage { | |
|
82 | paused = false, | |
|
83 | rate = 0}); | |
|
84 | } | |
|
85 | if (keyboardCur.IsKeyDown(Keys.D2) && keyboardPrev.IsKeyUp(Keys.D2) ) | |
|
86 | { | |
|
87 | SendMessage(new GameRateMessage { | |
|
88 | paused = false, | |
|
89 | rate = 1}); | |
|
90 | } | |
|
91 | if (keyboardCur.IsKeyDown(Keys.D3) && keyboardPrev.IsKeyUp(Keys.D3) ) | |
|
92 | { | |
|
93 | SendMessage(new GameRateMessage { | |
|
94 | paused = false, | |
|
95 | rate = 2}); | |
|
96 | } | |
|
97 | if (keyboardCur.IsKeyDown(Keys.D4) && keyboardPrev.IsKeyUp(Keys.D4) ) | |
|
98 | { | |
|
99 | SendMessage(new GameRateMessage { | |
|
100 | paused = false, | |
|
101 | rate = 3}); | |
|
102 | } | |
|
103 | #if DEBUG | |
|
104 | if (keyboardCur.IsKeyDown(Keys.D5) && keyboardPrev.IsKeyUp(Keys.D5) ) | |
|
105 | { | |
|
106 | SendMessage(new GameRateMessage { | |
|
107 | paused = false, | |
|
108 | rate = 4}); | |
|
109 | } | |
|
110 | #endif | |
|
111 | #endregion gamerate_keys | |
|
26 | 112 | #region misc_keys |
|
27 | 113 | if (keyboardCur.IsKeyDown(Keys.OemBackslash) && keyboardPrev.IsKeyUp(Keys.OemBackslash)) |
|
28 | 114 | { |
@@ -56,6 +142,21 | |||
|
56 | 142 | |
|
57 | 143 | } |
|
58 | 144 | #endif |
|
145 | ||
|
146 | if (keyboardCur.IsKeyDown(Keys.Q) && keyboardPrev.IsKeyUp(Keys.Q)) | |
|
147 | { | |
|
148 | System.Console.WriteLine("Quitting"); | |
|
149 | Environment.Exit(0); | |
|
150 | } | |
|
151 | if (keyboardCur.IsKeyDown(Keys.C) && keyboardPrev.IsKeyUp(Keys.C)) | |
|
152 | { | |
|
153 | // this.camera.Jump(Vector2.Zero); | |
|
154 | ||
|
155 | } | |
|
156 | if (keyboardCur.IsKeyDown(Keys.OemBackslash) && keyboardPrev.IsKeyUp(Keys.OemBackslash) && keyboardCur.IsKeyDown(Keys.LeftShift)) | |
|
157 | { | |
|
158 | // sound.Play(volume, pitch, pan); | |
|
159 | } | |
|
59 | 160 | #endregion misc_keys |
|
60 | 161 | |
|
61 | 162 | this.keyboardPrev = keyboardCur; |
@@ -8,7 +8,7 | |||
|
8 | 8 | |
|
9 | 9 | namespace isometricparkfna.Engines { |
|
10 | 10 | |
|
11 | // [Receives()] | |
|
11 | [Receives(typeof(GameRateMessage), typeof(TogglePauseMessage))] | |
|
12 | 12 | [Reads(typeof(BudgetComponent))] |
|
13 | 13 | [Writes(typeof(BudgetComponent))] |
|
14 | 14 | class SimulationBridgeEngine : Engine |
@@ -31,6 +31,17 | |||
|
31 | 31 | priorBudget = this.simulation.previousBudget}); |
|
32 | 32 | } |
|
33 | 33 | |
|
34 | foreach (ref readonly var message in ReadMessages<GameRateMessage>()) | |
|
35 | { | |
|
36 | this.simulation.paused = message.paused; | |
|
37 | this.simulation.setRate(message.rate); | |
|
38 | } | |
|
39 | ||
|
40 | foreach (ref readonly var message in ReadMessages<TogglePauseMessage>()) | |
|
41 | { | |
|
42 | this.simulation.paused = !this.simulation.paused; | |
|
43 | } | |
|
44 | ||
|
34 | 45 | } |
|
35 | 46 | |
|
36 | 47 | } |
@@ -54,7 +54,7 | |||
|
54 | 54 | int squaresDown = 50; |
|
55 | 55 | // int baseOffsetX = -14; |
|
56 | 56 | // int baseOffsetY = -14; |
|
57 | ||
|
57 | ||
|
58 | 58 | Simulation simulation; |
|
59 | 59 | |
|
60 | 60 | Vector2 mouseGrid; |
@@ -184,9 +184,10 | |||
|
184 | 184 | |
|
185 | 185 | |
|
186 | 186 | // WorldBuilder.AddGeneralRenderer(new BudgetWindowRenderer(this.batch, this.monoFont)); |
|
187 | WorldBuilder.AddEngine(new InputEngine()); | |
|
187 | WorldBuilder.AddEngine(new InputEngine(Menu.MENU_BAR_HEIGHT)); | |
|
188 | 188 | WorldBuilder.AddEngine(new GameBridgeEngine(this)); |
|
189 | 189 | WorldBuilder.AddEngine(new SimulationBridgeEngine(this.simulation)); |
|
190 | WorldBuilder.AddEngine(new CameraBridgeEngine(this.camera)); | |
|
190 | 191 | |
|
191 | 192 | // var budgetWindow = WorldBuilder.CreateEntity(); |
|
192 | 193 | // WorldBuilder.SetComponent(budgetWindow, new VisibilityComponent{visible = true}); |
@@ -341,43 +342,8 | |||
|
341 | 342 | KeyboardState keyboardCur = Keyboard.GetState(); |
|
342 | 343 | |
|
343 | 344 | #region input |
|
344 | #region camera_movement_keys | |
|
345 | if (keyboardCur.IsKeyDown(Keys.Down)) | |
|
346 | { | |
|
347 | this.camera.Move(new Vector2(0, 2)); | |
|
348 | } | |
|
349 | else if (keyboardCur.IsKeyDown(Keys.Up)) | |
|
350 | { | |
|
351 | this.camera.Move(new Vector2(0, -2)); | |
|
352 | ||
|
353 | } | |
|
354 | else if (keyboardCur.IsKeyDown(Keys.Left)) | |
|
355 | { | |
|
356 | this.camera.Move(new Vector2(-2, 0)); | |
|
357 | ||
|
358 | } | |
|
359 | else if (keyboardCur.IsKeyDown(Keys.Right)) | |
|
360 | { | |
|
361 | this.camera.Move(new Vector2(2, 0)); | |
|
362 | ||
|
363 | } | |
|
364 | else if (keyboardCur.IsKeyDown(Keys.Subtract) && keyboardPrev.IsKeyUp(Keys.Subtract)) | |
|
365 | { | |
|
366 | this.camera.ZoomOut(); | |
|
367 | } | |
|
368 | else if (keyboardCur.IsKeyDown(Keys.Add) && keyboardPrev.IsKeyUp(Keys.Add)) | |
|
369 | { | |
|
370 | ||
|
371 | this.camera.ZoomIn(); | |
|
372 | } | |
|
373 | #endregion camera_movement_keys | |
|
374 | ||
|
345 | // | |
|
375 | 346 | #region misc_keys |
|
376 | if (keyboardCur.IsKeyDown(Keys.Q) && keyboardPrev.IsKeyUp(Keys.Q)) | |
|
377 | { | |
|
378 | System.Console.WriteLine("Quitting"); | |
|
379 | Environment.Exit(0); | |
|
380 | } | |
|
381 | 347 | if (keyboardCur.IsKeyDown(Keys.C) && keyboardPrev.IsKeyUp(Keys.C)) |
|
382 | 348 | { |
|
383 | 349 | this.camera.Jump(Vector2.Zero); |
@@ -388,53 +354,12 | |||
|
388 | 354 | sound.Play(volume, pitch, pan); |
|
389 | 355 | } |
|
390 | 356 | #endregion misc_keys |
|
391 | ||
|
392 | ||
|
393 | #region gamerate_keys | |
|
394 | if (keyboardCur.IsKeyDown(Keys.P) && keyboardPrev.IsKeyUp(Keys.P) ) | |
|
395 | { | |
|
396 | this.simulation.paused = !this.simulation.paused; | |
|
397 | ||
|
398 | } | |
|
399 | if (keyboardCur.IsKeyDown(Keys.D0) && keyboardPrev.IsKeyUp(Keys.D0) ) | |
|
400 | { | |
|
401 | this.simulation.paused = !this.simulation.paused; | |
|
402 | ||
|
403 | } | |
|
404 | if (keyboardCur.IsKeyDown(Keys.D1) && keyboardPrev.IsKeyUp(Keys.D1) ) | |
|
405 | { | |
|
406 | this.simulation.paused = false; | |
|
407 | this.simulation.setRate(0); | |
|
408 | } | |
|
409 | if (keyboardCur.IsKeyDown(Keys.D2) && keyboardPrev.IsKeyUp(Keys.D2) ) | |
|
410 | { | |
|
411 | this.simulation.paused = false; | |
|
412 | this.simulation.setRate(1); | |
|
413 | } | |
|
414 | if (keyboardCur.IsKeyDown(Keys.D3) && keyboardPrev.IsKeyUp(Keys.D3) ) | |
|
415 | { | |
|
416 | this.simulation.paused = false; | |
|
417 | this.simulation.setRate(2); | |
|
418 | } | |
|
419 | if (keyboardCur.IsKeyDown(Keys.D4) && keyboardPrev.IsKeyUp(Keys.D4) ) | |
|
420 | { | |
|
421 | this.simulation.paused = false; | |
|
422 | this.simulation.setRate(3); | |
|
423 | } | |
|
424 | #if DEBUG | |
|
425 | if (keyboardCur.IsKeyDown(Keys.D5) && keyboardPrev.IsKeyUp(Keys.D5) ) | |
|
426 | { | |
|
427 | this.simulation.paused = false; | |
|
428 | this.simulation.setRate(4); | |
|
429 | } | |
|
430 | #endif | |
|
431 | #endregion gamerate_keys | |
|
432 | ||
|
433 | ||
|
357 | // | |
|
434 | 358 | MouseState mouseCur = Mouse.GetState(); |
|
435 | 359 | this.original_point = Vector2.Transform(new Vector2(mouseCur.X, mouseCur.Y), Matrix.Invert(camera.get_transformation(GraphicsDevice))); |
|
436 | 360 | |
|
437 | int menuBarHeight = 20; | |
|
361 | var menuBarHeight = Menu.MENU_BAR_HEIGHT; | |
|
362 | ||
|
438 | 363 | |
|
439 | 364 | if (MathUtils.Between(mouseCur.X, 0, 50)) |
|
440 | 365 | { |
You need to be logged in to leave comments.
Login now