public void Update(KeyState _keyState) { var keyModifiers = _keyState.KeyModifiers; var downKeys = _keyState.PressedKeys; if (keyModifiers != m_keyModifiers) m_downKeys.Clear(); var pressedKeys = new List<ConsoleKey>(); var prevDownKeys = m_downKeys.ToArray(); foreach (var key in prevDownKeys) { if (downKeys.Contains(key)) continue; pressedKeys.Add(key); m_downKeys.Remove(key); } foreach (var key in downKeys) { if (m_downKeys.Contains(key)) continue; m_moveKeyHoldedSince = DateTime.Now; m_downKeys.Add(key); } m_keyModifiers = keyModifiers; if (m_downKeys.Except(KeyTranslator.MoveKeys).Any() || pressedKeys.Any()) { m_isAutoRepeateMode = false; } else { if (m_downKeys.Intersect(KeyTranslator.MoveKeys).Any()) { var totalMilliseconds = (DateTime.Now - m_moveKeyHoldedSince).TotalMilliseconds; if (m_isAutoRepeateMode) { if (totalMilliseconds > Constants.AUTO_MOVE_REPEAT_MILLISECONDS) { m_moveKeyHoldedSince = DateTime.Now; pressedKeys.AddRange(m_downKeys); } } else { if (totalMilliseconds > Constants.AUTO_MOVE_REPEAT_AFTER) { m_isAutoRepeateMode = true; } } } } foreach (var pressedKey in pressedKeys) { m_pressed.Enqueue(new Tuple<ConsoleKey, EKeyModifiers>(pressedKey, m_keyModifiers)); } if (m_pressed.Count > 0) { if (UiBlocks.Peek() != m_mainUiBlock || World.TheWorld.Avatar.NextAct == null) { var tuple = m_pressed.Dequeue(); UiBlocks.Peek().KeysPressed(tuple.Item1, tuple.Item2); MessageManager.SendMessage(this,WorldMessage.JustRedraw); } } if (UiBlocks.Peek() == m_mainUiBlock) { if (!m_mainUiBlock.NeedWait) { if (!World.TheWorld.CreatureManager.FirstActiveCreature.IsAvatar || World.TheWorld.Avatar.NextAct != null || World.TheWorld.WorldTick==0) { #if DEBUG using (new Profiler()) #endif { World.TheWorld.GameUpdated(); } } } } }
public void Update(KeyState _keyState) { var keyModifiers = _keyState.KeyModifiers; var downKeys = _keyState.PressedKeys; if (keyModifiers != m_keyModifiers) { m_downKeys.Clear(); } var pressedKeys = new List <ConsoleKey>(); var prevDownKeys = m_downKeys.ToArray(); foreach (var key in prevDownKeys) { if (downKeys.Contains(key)) { continue; } pressedKeys.Add(key); m_downKeys.Remove(key); } foreach (var key in downKeys) { if (m_downKeys.Contains(key)) { continue; } m_moveKeyHoldedSince = DateTime.Now; m_downKeys.Add(key); } m_keyModifiers = keyModifiers; if (m_downKeys.Except(KeyTranslator.MoveKeys).Any() || pressedKeys.Any()) { m_isAutoRepeateMode = false; } else { if (m_downKeys.Intersect(KeyTranslator.MoveKeys).Any()) { var totalMilliseconds = (DateTime.Now - m_moveKeyHoldedSince).TotalMilliseconds; if (m_isAutoRepeateMode) { if (totalMilliseconds > Constants.AUTO_MOVE_REPEAT_MILLISECONDS) { m_moveKeyHoldedSince = DateTime.Now; pressedKeys.AddRange(m_downKeys); } } else { if (totalMilliseconds > Constants.AUTO_MOVE_REPEAT_AFTER) { m_isAutoRepeateMode = true; } } } } foreach (var pressedKey in pressedKeys) { m_pressed.Enqueue(new Tuple <ConsoleKey, EKeyModifiers>(pressedKey, m_keyModifiers)); } if (m_pressed.Count > 0) { if (UiBlocks.Peek() != m_mainUiBlock || World.TheWorld.Avatar.NextAct == null) { var tuple = m_pressed.Dequeue(); UiBlocks.Peek().KeysPressed(tuple.Item1, tuple.Item2); MessageManager.SendMessage(this, WorldMessage.JustRedraw); } } if (UiBlocks.Peek() == m_mainUiBlock) { if (!m_mainUiBlock.NeedWait) { if (!World.TheWorld.CreatureManager.FirstActiveCreature.IsAvatar || World.TheWorld.Avatar.NextAct != null || World.TheWorld.WorldTick == 0) { #if DEBUG using (new Profiler()) #endif { World.TheWorld.GameUpdated(); } } } } }