Description:
Loads more porting.
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; |
@@ -196,9 +196,10 | |||
|
196 | 196 | |
|
197 | 197 | |
|
198 | 198 | // WorldBuilder.AddGeneralRenderer(new BudgetWindowRenderer(this.batch, this.monoFont)); |
|
199 | WorldBuilder.AddEngine(new InputEngine()); | |
|
199 | WorldBuilder.AddEngine(new InputEngine(Menu.MENU_BAR_HEIGHT)); | |
|
200 | 200 | WorldBuilder.AddEngine(new GameBridgeEngine(this)); |
|
201 | 201 | WorldBuilder.AddEngine(new SimulationBridgeEngine(this.simulation)); |
|
202 | WorldBuilder.AddEngine(new CameraBridgeEngine(this.camera)); | |
|
202 | 203 | |
|
203 | 204 | // var budgetWindow = WorldBuilder.CreateEntity(); |
|
204 | 205 | // WorldBuilder.SetComponent(budgetWindow, new VisibilityComponent{visible = true}); |
@@ -353,43 +354,8 | |||
|
353 | 354 | KeyboardState keyboardCur = Keyboard.GetState(); |
|
354 | 355 | |
|
355 | 356 | #region input |
|
356 | #region camera_movement_keys | |
|
357 | if (keyboardCur.IsKeyDown(Keys.Down)) | |
|
358 | { | |
|
359 | this.camera.Move(new Vector2(0, 2)); | |
|
360 | } | |
|
361 | else if (keyboardCur.IsKeyDown(Keys.Up)) | |
|
362 | { | |
|
363 | this.camera.Move(new Vector2(0, -2)); | |
|
364 | ||
|
365 | } | |
|
366 | else if (keyboardCur.IsKeyDown(Keys.Left)) | |
|
367 | { | |
|
368 | this.camera.Move(new Vector2(-2, 0)); | |
|
369 | ||
|
370 | } | |
|
371 | else if (keyboardCur.IsKeyDown(Keys.Right)) | |
|
372 | { | |
|
373 | this.camera.Move(new Vector2(2, 0)); | |
|
374 | ||
|
375 | } | |
|
376 | else if (keyboardCur.IsKeyDown(Keys.Subtract) && keyboardPrev.IsKeyUp(Keys.Subtract)) | |
|
377 | { | |
|
378 | this.camera.ZoomOut(); | |
|
379 | } | |
|
380 | else if (keyboardCur.IsKeyDown(Keys.Add) && keyboardPrev.IsKeyUp(Keys.Add)) | |
|
381 | { | |
|
382 | ||
|
383 | this.camera.ZoomIn(); | |
|
384 | } | |
|
385 | #endregion camera_movement_keys | |
|
386 | ||
|
357 | // | |
|
387 | 358 | #region misc_keys |
|
388 | if (keyboardCur.IsKeyDown(Keys.Q) && keyboardPrev.IsKeyUp(Keys.Q)) | |
|
389 | { | |
|
390 | System.Console.WriteLine("Quitting"); | |
|
391 | Environment.Exit(0); | |
|
392 | } | |
|
393 | 359 | if (keyboardCur.IsKeyDown(Keys.C) && keyboardPrev.IsKeyUp(Keys.C)) |
|
394 | 360 | { |
|
395 | 361 | this.camera.Jump(Vector2.Zero); |
@@ -400,53 +366,12 | |||
|
400 | 366 | sound.Play(volume, pitch, pan); |
|
401 | 367 | } |
|
402 | 368 | #endregion misc_keys |
|
403 | ||
|
404 | ||
|
405 | #region gamerate_keys | |
|
406 | if (keyboardCur.IsKeyDown(Keys.P) && keyboardPrev.IsKeyUp(Keys.P) ) | |
|
407 | { | |
|
408 | this.simulation.paused = !this.simulation.paused; | |
|
409 | ||
|
410 | } | |
|
411 | if (keyboardCur.IsKeyDown(Keys.D0) && keyboardPrev.IsKeyUp(Keys.D0) ) | |
|
412 | { | |
|
413 | this.simulation.paused = !this.simulation.paused; | |
|
414 | ||
|
415 | } | |
|
416 | if (keyboardCur.IsKeyDown(Keys.D1) && keyboardPrev.IsKeyUp(Keys.D1) ) | |
|
417 | { | |
|
418 | this.simulation.paused = false; | |
|
419 | this.simulation.setRate(0); | |
|
420 | } | |
|
421 | if (keyboardCur.IsKeyDown(Keys.D2) && keyboardPrev.IsKeyUp(Keys.D2) ) | |
|
422 | { | |
|
423 | this.simulation.paused = false; | |
|
424 | this.simulation.setRate(1); | |
|
425 | } | |
|
426 | if (keyboardCur.IsKeyDown(Keys.D3) && keyboardPrev.IsKeyUp(Keys.D3) ) | |
|
427 | { | |
|
428 | this.simulation.paused = false; | |
|
429 | this.simulation.setRate(2); | |
|
430 | } | |
|
431 | if (keyboardCur.IsKeyDown(Keys.D4) && keyboardPrev.IsKeyUp(Keys.D4) ) | |
|
432 | { | |
|
433 | this.simulation.paused = false; | |
|
434 | this.simulation.setRate(3); | |
|
435 | } | |
|
436 | #if DEBUG | |
|
437 | if (keyboardCur.IsKeyDown(Keys.D5) && keyboardPrev.IsKeyUp(Keys.D5) ) | |
|
438 | { | |
|
439 | this.simulation.paused = false; | |
|
440 | this.simulation.setRate(4); | |
|
441 | } | |
|
442 | #endif | |
|
443 | #endregion gamerate_keys | |
|
444 | ||
|
445 | ||
|
369 | // | |
|
446 | 370 | MouseState mouseCur = Mouse.GetState(); |
|
447 | 371 | this.original_point = Vector2.Transform(new Vector2(mouseCur.X, mouseCur.Y), Matrix.Invert(camera.get_transformation(GraphicsDevice))); |
|
448 | 372 | |
|
449 | int menuBarHeight = 20; | |
|
373 | var menuBarHeight = Menu.MENU_BAR_HEIGHT; | |
|
374 | ||
|
450 | 375 | |
|
451 | 376 | if (MathUtils.Between(mouseCur.X, 0, 50)) |
|
452 | 377 | { |
You need to be logged in to leave comments.
Login now