Description:
Refactor out more code into InputEngine.
Commit status:
[Not Reviewed]
References:
Comments:
0 Commit comments 0 Inline Comments
Unresolved TODOs:
There are no unresolved TODOs
Add another comment

r296:297de4636cac -

@@ -1,6 +1,7
1 1
2 2 using System;
3 3 using Microsoft.Xna.Framework;
4 using Microsoft.Xna.Framework.Graphics;
4 5 using Microsoft.Xna.Framework.Input;
5 6
6 7 using Encompass;
@@ -25,6 +26,10
25 26 public class InputEngine : Engine
26 27 {
27 28 private KeyboardState keyboardPrev;
29 private MouseState mousePrev;
30
31 private GraphicsDevice graphicsDevice;
32 private Camera camera;
28 33
29 34 //Area to ignore:
30 35 private int menuBarHeight;
@@ -32,18 +37,23
32 37 private int viewWidth;
33 38 private int viewHeight;
34 39
35 public InputEngine(int menuBarHeight, int viewWidth, int viewHeight) {
40 public InputEngine(int menuBarHeight, int viewWidth, int viewHeight, Camera camera,
41 GraphicsDevice graphicsDevice) {
36 42 //initialize to blank for now
37 43 this.keyboardPrev = new KeyboardState();
38 44 this.menuBarHeight = menuBarHeight;
39 45 this.viewWidth = viewWidth;
40 46 this.viewHeight = viewHeight;
47 this.camera = camera;
48 this.graphicsDevice = graphicsDevice;
41 49 }
42 50
43 51 public override void Update(double dt) {
44 52
45 53 var keyboardCur = Keyboard.GetState();
46 54 var mouseCur = Mouse.GetState();
55 var original_point = Vector2.Transform(new Vector2(mouseCur.X, mouseCur.Y),
56 Matrix.Invert(this.camera.get_transformation(this.graphicsDevice)));
47 57
48 58 #region camera_movement_keys
49 59 if (keyboardCur.IsKeyDown(Keys.Down))
@@ -188,8 +198,17
188 198 SendMessage(new MoveCameraMessage {Movement = new Vector2(4, 0)});
189 199 }
190 200 #endregion
201 #region mouse_click
191 202
192 this.keyboardPrev = keyboardCur;
203 if (mouseCur.RightButton == ButtonState.Pressed && mousePrev.RightButton == ButtonState.Released)
204 {
205 // this.camera.Jump(this.original_point);
206 SendMessage(new JumpCameraMessage{Movement = original_point});
207 }
208
209 #endregion
210 this.keyboardPrev = keyboardCur;
211 this.mousePrev = mouseCur;
193 212 }
194 213 }
195 214 }
@@ -209,7 +209,7
209 209 this.grammar = new TraceryNet.Grammar(json2);
210 210
211 211
212 WorldBuilder.AddEngine(new InputEngine(Menu.MENU_BAR_HEIGHT, FNAGame.width, FNAGame.height));
212 WorldBuilder.AddEngine(new InputEngine(Menu.MENU_BAR_HEIGHT, FNAGame.width, FNAGame.height, this.camera, GraphicsDevice));
213 213 WorldBuilder.AddEngine(new UIEngine());
214 214
215 215 WorldBuilder.AddEngine(new GameBridgeEngine(this));
@@ -434,6 +434,7
434 434 float pan = 0.0f;
435 435
436 436 KeyboardState keyboardCur = Keyboard.GetState();
437 MouseState mouseCur = Mouse.GetState();
437 438
438 439 #region input
439 440 //
@@ -444,16 +445,6
444 445 }
445 446 #endregion misc_keys
446 447 //
447 MouseState mouseCur = Mouse.GetState();
448 this.original_point = Vector2.Transform(new Vector2(mouseCur.X, mouseCur.Y), Matrix.Invert(camera.get_transformation(GraphicsDevice)));
449
450
451 #if DEBUG
452 if (mouseCur.RightButton == ButtonState.Pressed && mousePrev.RightButton == ButtonState.Released)
453 {
454 this.camera.Jump(this.original_point);
455 }
456 #endif
457 448
458 449 #endregion input
459 450
You need to be logged in to leave comments. Login now