public void SetKeyMap(KeyMap map = null) { Scene.AssertSceneThread(this.Scene); map = map ?? new KeyMap(); this.KeyMap = map; this.KeyMap.SubscribeForLifetime(ObservableObject.AnyProperty, () => { Scene.QueueAction(() => { SetKeyMap(map); }); }, GetPropertyValueLifetime(nameof(this.KeyMap)).LifetimeManager); keyboardMap.Clear(); altKeyboardMap.Clear(); shiftKeyboardMap.Clear(); // manage keyboardMap.Add(map.TogglePauseKey, () => { Scene.TogglePause(); }); keyboardMap.Add(map.MenuKey, () => { App.ShowMenu(); }); // move and aim keyboardMap.Add(map.MoveUpKey, () => { MainCharacter.Current.MoveUp(); }); keyboardMap.Add(map.MoveDownKey, () => { MainCharacter.Current.MoveDown(); }); keyboardMap.Add(map.MoveLeftKey, () => { MainCharacter.Current.MoveLeft(); }); keyboardMap.Add(map.MoveRightKey, () => { MainCharacter.Current.MoveRight(); }); keyboardMap.Add(map.AimToggleKey, () => { MainCharacter.Current.ToggleFreeAim(); }); // fire weapons keyboardMap.Add(map.PrimaryWeaponKey, () => { MainCharacter.Current?.Inventory?.PrimaryWeapon?.TryFire(); }); keyboardMap.Add(map.ExplosiveWeaponKey, () => { MainCharacter.Current?.Inventory?.ExplosiveWeapon?.TryFire(); }); // doors keyboardMap.Add(map.InteractKey, () => { MainCharacter.Current.TryInteract(); }); UpdateKeyboardMappings(); }
public KeyMapEditor(KeyMap map) { var stackPanel = Add(new StackPanel() { Margin = 1 }).Fill(); this.Width = 50; foreach (var prop in map.GetType().GetProperties().Where(p => p.PropertyType == typeof(ConsoleKey))) { var myProp = prop; var fieldPanel = stackPanel.Add(new ConsolePanel() { Height = 1 }).FillHoriontally(); var fieldLabel = fieldPanel.Add(new Label() { Text = prop.Name.ToYellow() }); var fieldValue = fieldPanel.Add(new Label() { X = 30, CanFocus = true, Text = ((ConsoleKey)myProp.GetValue(map)).ToString().ToYellow() }); fieldValue.KeyInputReceived.SubscribeForLifetime((key) => { myProp.SetValue(map, key.Key); fieldValue.Text = ((ConsoleKey)myProp.GetValue(map)).ToString().ToYellow(); }, this.LifetimeManager); this.Height += 2; } }
public GameInputManager(Scene scene, GameApp app) { this.Scene = scene; this.App = app; this.keyboardMap = new Dictionary <ConsoleKey, Action>(); this.shiftKeyboardMap = new Dictionary <ConsoleKey, Action>(); this.altKeyboardMap = new Dictionary <ConsoleKey, Action>(); this.KeyMap = new KeyMap(); }