private void HandleSaveKey(ScummInputState kbd) { if (_selectedSavegame < 255) { var saveName = new StringBuilder(_saveNames[_selectedSavegame]); byte len = (byte)_saveNames[_selectedSavegame].Length; if (kbd.IsKeyDown(KeyCode.Backspace) && len != 0) // backspace saveName.Remove(saveName.Length - 1, 1); else { var key = kbd.GetKeys().Select(k => (char?)k).LastOrDefault(); if (key.HasValue && keyAccepted(key.Value) && (len < 31)) { saveName.Append(key.Value); } } _saveNames[_selectedSavegame] = saveName.ToString(); ShowSavegameNames(); } }
private void HandleKeyPress(ScummInputState kbd, StringBuilder textBuf) { if (kbd.IsKeyDown(KeyCode.Backspace)) { // backspace if (textBuf.Length > 0) textBuf.Remove(textBuf.Length - 1, 1); } else { // TODO: do this in ScummInputState ? var key = (char?)kbd.GetKeys().Where(k => k >= (KeyCode)32 && k <= (KeyCode)126).Select(k => (KeyCode?)k).FirstOrDefault(); if (!key.HasValue) return; // Cannot enter text wider than the save/load panel if (_enteredTextWidth >= PanLineWidth - 10) return; // Cannot enter text longer than MaxTextLen-1 chars, since // the storage is only so big. Note: The code used to incorrectly // allow up to MaxTextLen, which caused an out of bounds access, // overwriting the next entry in the list of savegames partially. // This could be triggered by e.g. entering lots of periods ".". if (textBuf.Length >= MaxTextLen - 1) return; // Allow the key only if is a letter, a digit, or one of a selected // list of extra characters if (char.IsLetterOrDigit(key.Value) || " ,().='-&+!?\"".Contains(key.Value.ToString())) { textBuf.Append(key); } } }
private void Delay(int msecs) { var now = Environment.TickCount; var endTime = now + msecs; _keyPressed = new ScummInputState(); _mouseState = 0; do { _keyPressed = _system.InputManager.GetState(); if (_keyPressed.GetKeys().Count > 0) { // we skip the rest of the delay and return immediately // to handle keyboard input return; } _mouseCoord = _system.InputManager.GetMousePosition(); _mouseDown = _keyPressed.IsLeftButtonDown; _mouseState |= (ushort)(_mouseDown ? Mouse.BS1L_BUTTON_DOWN : Mouse.BS1L_BUTTON_UP); _system.GraphicsManager.UpdateScreen(); ServiceLocator.Platform.Sleep(10); } while (Environment.TickCount < endTime); }