diff options
-rw-r--r-- | engines/sherlock/tattoo/widget_files.cpp | 171 |
1 files changed, 170 insertions, 1 deletions
diff --git a/engines/sherlock/tattoo/widget_files.cpp b/engines/sherlock/tattoo/widget_files.cpp index 620c25224d..1743bcd09e 100644 --- a/engines/sherlock/tattoo/widget_files.cpp +++ b/engines/sherlock/tattoo/widget_files.cpp @@ -246,7 +246,176 @@ void WidgetFiles::handleEvents() { } bool WidgetFiles::getFilename() { - return false; + Events &events = *_vm->_events; + TattooScene &scene = *(TattooScene *)_vm->_scene; + Talk &talk = *_vm->_talk; + int index = 0; + int done = 0; + bool flag = false; + int width; + int cursorColor = 192; + byte color, textColor; + bool insert = true; + + assert(_selector != -1); + Common::Point pt(_surface.stringWidth("00.") + _surface.widestChar() + 5, + _surface.fontHeight() + 14 + (_selector - _savegameIndex) * (_surface.fontHeight() + 1)); + + Common::String str = Common::String::format("%d.", _selector + 1); + _surface.writeString(str, Common::Point(_surface.widestChar(), pt.y), COMMAND_HIGHLIGHTED); + + Common::String saveFile = _savegames[_selector]; + Common::String filename = _savegames[_selector]; + _savegames[_selector] = ""; + + if (isSlotEmpty(_selector)) { + index = 0; + _surface.fillRect(Common::Rect(pt.x, pt.y, _bounds.right - BUTTON_SIZE - 9, pt.y + _surface.fontHeight() - 1), TRANSPARENCY); + } else { + index = saveFile.size(); + _surface.writeString(saveFile, pt, COMMAND_HIGHLIGHTED); + pt.x = _surface.stringWidth("00.") + _surface.stringWidth(saveFile) + _surface.widestChar() + 5; + + //filename[index] = 32; + } + + do { + scene.doBgAnim(); + + if (talk._talkToAbort) + return false; + + if (filename[index]) { + str = Common::String::format("%c", filename[index]); + width = _surface.charWidth(filename[index]); + } else { + width = 7; + } + + while (!events.kbHit()) { + events.pollEventsAndWait(); + events.setButtonState(); + + scene.doBgAnim(); + + if (talk._talkToAbort) + return false; + + flag = !flag; + if (flag) { + textColor = 236; + color = cursorColor; + } else { + textColor = COMMAND_HIGHLIGHTED; + color = TRANSPARENCY; + } + + _surface.fillRect(Common::Rect(pt.x, pt.y, pt.x + width, pt.y + _surface.fontHeight()), color); + if (filename[index]) + _surface.writeString(str, pt, textColor); + + if (_vm->shouldQuit()) + return false; + } + + Common::KeyState keyState = events.getKey(); + if (keyState.keycode == Common::KEYCODE_BACKSPACE && index > 0) { + pt.x -= _surface.charWidth(filename[index - 1]); + + if (insert) { + filename.deleteChar(index); + } else { + filename.setChar(' ', index - 1); + } + + --index; + _surface.fillRect(Common::Rect(pt.x, pt.y, _surface.w() - BUTTON_SIZE - 9, pt.y + _surface.fontHeight() - 1), TRANSPARENCY); + _surface.writeString(filename.c_str() + index, pt, COMMAND_HIGHLIGHTED); + + } else if ((keyState.keycode == Common::KEYCODE_LEFT && index > 0) + || (keyState.keycode == Common::KEYCODE_RIGHT && index < 49 && pt.x < (_bounds.right - BUTTON_SIZE - 20)) + || (keyState.keycode == Common::KEYCODE_HOME && index > 0) + || (keyState.keycode == Common::KEYCODE_END)) { + _surface.fillRect(Common::Rect(pt.x, pt.y, pt.x + width, pt.y + _surface.fontHeight()), TRANSPARENCY); + if (filename[index]) + _surface.writeString(str, pt, COMMAND_HIGHLIGHTED); + + switch (keyState.keycode) { + case Common::KEYCODE_LEFT: + pt.x -= _surface.charWidth(filename[index - 1]); + --index; + break; + + case Common::KEYCODE_RIGHT: + pt.x += _surface.charWidth(filename[index]); + ++index; + break; + + case Common::KEYCODE_HOME: + pt.x = _surface.stringWidth("00.") + _surface.widestChar() + 5; + index = 0; + break; + + case Common::KEYCODE_END: + pt.x = _surface.stringWidth("00.") + _surface.stringWidth(filename) + _surface.widestChar() + 5; + index = filename.size(); + + while (filename[index - 1] == ' ' && index > 0) { + pt.x -= _surface.charWidth(filename[index - 1]); + --index; + } + break; + } + } else if (keyState.keycode == Common::KEYCODE_INSERT) { + insert = !insert; + if (insert) + cursorColor = 192; + else + cursorColor = 200; + + } else if (keyState.keycode == Common::KEYCODE_DELETE) { + filename.deleteChar(index); + + _surface.fillRect(Common::Rect(pt.x, pt.y, _bounds.right - BUTTON_SIZE - 9, pt.y + _surface.fontHeight() - 1), TRANSPARENCY); + _surface.writeString(filename + index, pt, COMMAND_HIGHLIGHTED); + + } else if (keyState.keycode == Common::KEYCODE_RETURN) { + done = 1; + + } else if (keyState.keycode == Common::KEYCODE_ESCAPE) { + filename = saveFile; + _selector = -1; + render(RENDER_NAMES_AND_SCROLLBAR); + done = -1; + } + + if ((keyState.keycode >= ' ') && ((keyState.keycode <= 168) || (keyState.keycode == 225)) && (index < 50)) { + if (pt.x + _surface.charWidth(keyState.keycode) < _surface.w() - BUTTON_SIZE - 20) { + if (insert) { + int temp = strlen(filename.c_str() + index) - 1; + if (temp) + filename.deleteChar(index); + } + + filename.insertChar(keyState.ascii, index); + _surface.fillRect(Common::Rect(pt.x, pt.y, _bounds.width() - BUTTON_SIZE - 9, + pt.y + _surface.fontHeight() - 1), TRANSPARENCY); + _surface.writeString(filename.c_str() + index, pt, COMMAND_HIGHLIGHTED); + pt.x += _surface.charWidth(keyState.keycode); + ++index; + } + } + } while (!done && !_vm->shouldQuit()); + + scene.doBgAnim(); + + if (talk._talkToAbort) + return false; + + if (done == 1) + _savegames[_selector] = saveFile; + + return done == 1; } Common::Rect WidgetFiles::getScrollBarBounds() const { |