static InputManager() { AddKeybind(new Keybind("Up", Keys.W)); AddKeybind(new Keybind("Left", Keys.A)); AddKeybind(new Keybind("Down", Keys.S)); AddKeybind(new Keybind("Right", Keys.D)); AddKeybind(new Keybind("Slow", Keys.LeftShift)); AddKeybind(new Keybind("Inventory", Keys.E, (oldType, newType) => { if (newType == PressType.Pressed) { if (InterfaceManager.CurrentInterface == null) { InterfaceManager.SetInterface(new Inventory(GameImpl.Instance.Player)); } else if (InterfaceManager.CurrentInterface is ItemInterface) { InterfaceManager.SetInterface(null); } return(true); } return(false); })); AddKeybind(new Keybind("Escape", Keys.Escape, (oldType, newType) => { if (newType == PressType.Pressed && InterfaceManager.CurrentInterface != null) { InterfaceManager.SetInterface(null); return(true); } return(false); })); AddKeybind(new Keybind("CheatItems", Keys.F1, (oldType, newType) => { if (newType == PressType.Pressed) { var i = 0; foreach (var type in Registry.ItemTypes.Values) { GameImpl.Instance.Player.Inventory[i++] = type.Instance(); } return(true); } return(false); })); AddKeybind(new Keybind("Debug", Keys.F2, (oldType, newType) => { if (newType == PressType.Pressed) { MapRenderer.DisplayBounds = !MapRenderer.DisplayBounds; return(true); } return(false); })); }
protected override void Draw(GameTime gameTime) { var view = this.GraphicsDevice.Viewport; if (this.CurrentMap != null) { this.GraphicsDevice.Clear(this.CurrentMap.IsInside ? new Color(36, 39, 51) : Color.Aqua); MapRenderer.RenderMap(this.SpriteBatch, this.CurrentMap, view, this.Camera); } else { this.GraphicsDevice.Clear(Color.Black); } InterfaceManager.Draw(this.SpriteBatch, view, this.Camera); CutsceneManager.Draw(this.SpriteBatch, view); }
protected override void Update(GameTime gameTime) { InterfaceManager.Update(gameTime); InputManager.Update(this.CurrentMap, this.Camera); CutsceneManager.Update(); foreach (var map in this.Maps.Values) { map.Update(gameTime, map == this.CurrentMap); } if ((CurrentTime - this.lastRealTimeUpdate).Minutes >= 10) { this.ForceRealTimeUpdate(); } this.Camera.Update(this.CurrentMap); }
public static void Update(Map map, Camera camera) { var mouse = Mouse.GetState(); for (var i = 1; i >= 0; i--) { var button = i == 0 ? mouse.LeftButton : mouse.RightButton; if (button == ButtonState.Pressed) { if (MousePressTypes[i] < PressType.Down) { MousePressTypes[i]++; } } else { MousePressTypes[i] = PressType.Nothing; } var mouseButton = (MouseButton)i; var type = MousePressTypes[i]; if (!InterfaceManager.HandleMouse(mouseButton, type)) { if (map != null && InterfaceManager.CurrentInterface == null) { var pos = camera.ToWorldPos(mouse.Position.ToVector2()); foreach (var obj in map.Objects) { var bounds = obj.HighlightBounds.Move(obj.Position); if (bounds != RectangleF.Empty && bounds.Contains(pos)) { if (obj.OnMouse(pos, mouseButton, type)) { break; } } } } } } var delta = mouse.ScrollWheelValue - lastScroll; if (delta != 0) { InterfaceManager.HandleScroll(delta); lastScroll = mouse.ScrollWheelValue; } var keyboard = Keyboard.GetState(); foreach (var bind in Keybinds.Values) { var newType = bind.Type; if (keyboard.IsKeyDown(bind.Key)) { if (bind.Type < PressType.Down) { newType = bind.Type + 1; } } else { newType = PressType.Nothing; } if (newType != bind.Type) { var old = bind.Type; bind.Type = newType; if (bind.OnChange != null) { if (bind.OnChange(old, newType)) { continue; } } } InterfaceManager.HandleKeyboard(bind.Name, newType); } }
private void OnWindowSizeChange(object window, EventArgs args) { this.Camera.FixPosition(this.CurrentMap); InterfaceManager.OnWindowSizeChange(this.GraphicsDevice.Viewport); }