diff options
author | Paul Gilbert | 2015-06-23 20:11:08 -0400 |
---|---|---|
committer | Paul Gilbert | 2015-06-23 20:11:08 -0400 |
commit | a23d878934a0669c5539d6b3548d88e698d81f0a (patch) | |
tree | bb2e2078b97909cad2c3576ea333be5877b1ccfc /engines/sherlock | |
parent | f0c0fd5922fbad5cfb577abe885c9b8e1ac56174 (diff) | |
download | scummvm-rg350-a23d878934a0669c5539d6b3548d88e698d81f0a.tar.gz scummvm-rg350-a23d878934a0669c5539d6b3548d88e698d81f0a.tar.bz2 scummvm-rg350-a23d878934a0669c5539d6b3548d88e698d81f0a.zip |
SHERLOCK: RT: Create WidgetMessage class for displaying messages
Diffstat (limited to 'engines/sherlock')
-rw-r--r-- | engines/sherlock/tattoo/tattoo_talk.cpp | 16 | ||||
-rw-r--r-- | engines/sherlock/tattoo/tattoo_talk.h | 6 | ||||
-rw-r--r-- | engines/sherlock/tattoo/tattoo_user_interface.cpp | 40 | ||||
-rw-r--r-- | engines/sherlock/tattoo/tattoo_user_interface.h | 6 | ||||
-rw-r--r-- | engines/sherlock/tattoo/widget_text.cpp | 46 | ||||
-rw-r--r-- | engines/sherlock/tattoo/widget_text.h | 26 |
6 files changed, 95 insertions, 45 deletions
diff --git a/engines/sherlock/tattoo/tattoo_talk.cpp b/engines/sherlock/tattoo/tattoo_talk.cpp index 52b6b51213..1ae36eaebe 100644 --- a/engines/sherlock/tattoo/tattoo_talk.cpp +++ b/engines/sherlock/tattoo/tattoo_talk.cpp @@ -183,23 +183,25 @@ TattooTalk::TattooTalk(SherlockEngine *vm) : Talk(vm) { } void TattooTalk::talkInterface(const byte *&str) { - drawTalk((const char *)str); + TattooUserInterface &ui = *(TattooUserInterface *)_vm->_ui; + const char *s = (const char *)str; + // Move to past the end of the text string _charCount = 0; while ((*str < TATTOO_OPCODES[0] || *str == TATTOO_OPCODES[OP_NULL]) && *str) { ++_charCount; ++str; } + // Display the text window + ui.banishWindow(); + ui._textWidget.load(s); + ui._textWidget.summonWindow(); _wait = true; } -void TattooTalk::drawTalk(const char *str) { - TattooUserInterface &ui = *(TattooUserInterface *)_vm->_ui; - - ui.banishWindow(); - ui._textWidget.load(str); - ui._textWidget.summonWindow(); +void TattooTalk::openTalkWindow() { + // TODO } OpcodeReturn TattooTalk::cmdSwitchSpeaker(const byte *&str) { diff --git a/engines/sherlock/tattoo/tattoo_talk.h b/engines/sherlock/tattoo/tattoo_talk.h index 9fd6f05242..33eacd2db3 100644 --- a/engines/sherlock/tattoo/tattoo_talk.h +++ b/engines/sherlock/tattoo/tattoo_talk.h @@ -75,6 +75,12 @@ private: OpcodeReturn cmdWalkHomesAndNPCToCoords(const byte *&str); private: void drawTalk(const char *str); + + /** + * Figures out how many lines the available talk lines will take up, and opens a text window + * of appropriate size + */ + void openTalkWindow(); protected: /** * Display the talk interface window diff --git a/engines/sherlock/tattoo/tattoo_user_interface.cpp b/engines/sherlock/tattoo/tattoo_user_interface.cpp index f81ea4cffb..4005dbb89e 100644 --- a/engines/sherlock/tattoo/tattoo_user_interface.cpp +++ b/engines/sherlock/tattoo/tattoo_user_interface.cpp @@ -30,7 +30,7 @@ namespace Sherlock { namespace Tattoo { TattooUserInterface::TattooUserInterface(SherlockEngine *vm): UserInterface(vm), - _inventoryWidget(vm), _tooltipWidget(vm), _verbsWidget(vm), _textWidget(vm) { + _inventoryWidget(vm), _messageWidget(vm), _textWidget(vm), _tooltipWidget(vm), _verbsWidget(vm) { Common::fill(&_lookupTable[0], &_lookupTable[PALETTE_COUNT], 0); Common::fill(&_lookupTable1[0], &_lookupTable1[PALETTE_COUNT], 0); _menuBuffer = nullptr; @@ -261,6 +261,10 @@ void TattooUserInterface::handleInput() { if (!events.isCursorVisible()) _keyState.keycode = Common::KEYCODE_INVALID; + // If there's an active widget/window, let it do event processing + if (_widget) + _widget->handleEvents(); + // Handle input depending on what mode we're in switch (_menuMode) { case STD_MODE: @@ -281,9 +285,6 @@ void TattooUserInterface::handleInput() { case TALK_MODE: doTalkControl(); break; - case MESSAGE_MODE: - doMessageControl(); - break; case LAB_MODE: doLabControl(); break; @@ -617,25 +618,6 @@ void TattooUserInterface::doTalkControl() { warning("TODO: ui control (talk)"); } -void TattooUserInterface::doMessageControl() { - Events &events = *_vm->_events; - --_menuCounter; - - // Check if a mouse or keypress has occurred, or the display counter has expired - if (events._pressed || events._released || events._rightPressed || events._rightReleased || - _keyState.keycode || !_menuCounter) { - // Close the window - banishWindow(); - - // Reset cursor and switch back to standard mode - events.setCursor(ARROW); - events.clearEvents(); - _key = -1; - _oldBgFound = -1; - _menuMode = STD_MODE; - } -} - void TattooUserInterface::doLabControl() { warning("TODO: ui control (lab)"); } @@ -701,15 +683,9 @@ void TattooUserInterface::putMessage(const char *formatStr, ...) { Common::String str = Common::String::vformat(formatStr, args); va_end(args); - // Calculate display bounds and load a text window - Common::Rect r(screen.stringWidth(str) + screen.widestChar() * 2 + 6, screen.fontHeight() + 10); - r.moveTo(mousePos.x - r.width() / 2, mousePos.y - r.height() / 2); - _textWidget.load(str, r); - _textWidget.summonWindow(); - - _menuMode = MESSAGE_MODE; - events._pressed = events._released = events._rightReleased = false; - _menuCounter = 25; + // Open the message widget + _messageWidget.load(str, 25); + _messageWidget.summonWindow(); } void TattooUserInterface::setupBGArea(const byte cMap[PALETTE_SIZE]) { diff --git a/engines/sherlock/tattoo/tattoo_user_interface.h b/engines/sherlock/tattoo/tattoo_user_interface.h index 44ba7caf96..f21e699538 100644 --- a/engines/sherlock/tattoo/tattoo_user_interface.h +++ b/engines/sherlock/tattoo/tattoo_user_interface.h @@ -61,6 +61,7 @@ private: WidgetInventory _inventoryWidget; WidgetSceneTooltip _tooltipWidget; WidgetVerbs _verbsWidget; + WidgetMessage _messageWidget; WidgetBase *_widget; byte _lookupTable[PALETTE_COUNT]; byte _lookupTable1[PALETTE_COUNT]; @@ -100,11 +101,6 @@ private: * and handles any actions for clicking on the buttons or statements. */ void doTalkControl(); - - /** - * Handles input when a message window is open at the bottom of the screen - */ - void doMessageControl(); /** * Handles input when the player is in the Lab Table scene diff --git a/engines/sherlock/tattoo/widget_text.cpp b/engines/sherlock/tattoo/widget_text.cpp index 44680dab53..f4e4b6e9af 100644 --- a/engines/sherlock/tattoo/widget_text.cpp +++ b/engines/sherlock/tattoo/widget_text.cpp @@ -92,6 +92,52 @@ void WidgetText::load(const Common::String &str, const Common::Rect &bounds) { } } +/*----------------------------------------------------------------*/ + +WidgetMessage::WidgetMessage(SherlockEngine *vm) : WidgetBase(vm) { + _menuCounter = 0; +} + +void WidgetMessage::load(const Common::String &str, int time) { + Events &events = *_vm->_events; + Common::Point mousePos = events.mousePos(); + _menuCounter = time; + + // Set up the bounds for the dialog to be a single line + _bounds = Common::Rect(_surface.stringWidth(str) + _surface.widestChar() * 2 + 6, _surface.fontHeight() + 10); + _bounds.moveTo(mousePos.x - _bounds.width() / 2, mousePos.y - _bounds.height() / 2); + + // Allocate a surface for the window + _surface.create(_bounds.width(), _bounds.height()); + _surface.fill(TRANSPARENCY); + + // Form the background for the new window and write the line of text + makeInfoArea(); + _surface.writeString(str, Common::Point(_surface.widestChar() + 3, 5), INFO_TOP); +} + +void WidgetMessage::handleEvents() { + Events &events = *_vm->_events; + TattooUserInterface &ui = *(TattooUserInterface *)_vm->_ui; + WidgetBase::handleEvents(); + + --_menuCounter; + + // Check if a mouse or keypress has occurred, or the display counter has expired + if (events._pressed || events._released || events._rightPressed || events._rightReleased || + ui._keyState.keycode || !_menuCounter) { + // Close the window + banishWindow(); + + // Reset cursor and switch back to standard mode + events.setCursor(ARROW); + events.clearEvents(); + ui._key = -1; + ui._oldBgFound = -1; + ui._menuMode = STD_MODE; + } +} + } // End of namespace Tattoo } // End of namespace Sherlock diff --git a/engines/sherlock/tattoo/widget_text.h b/engines/sherlock/tattoo/widget_text.h index c213f2da6d..e77342531e 100644 --- a/engines/sherlock/tattoo/widget_text.h +++ b/engines/sherlock/tattoo/widget_text.h @@ -33,15 +33,39 @@ class SherlockEngine; namespace Tattoo { class WidgetText: public WidgetBase { +private: + /** + * Display the passed text in a window of the given bounds + */ + void load(const Common::String &str, const Common::Rect &bounds); public: Common::String _remainingText; public: WidgetText(SherlockEngine *vm); virtual ~WidgetText() {} + /** + * Load the data for the text window + */ void load(const Common::String &str); +}; - void load(const Common::String &str, const Common::Rect &bounds); +class WidgetMessage : public WidgetBase { +private: + int _menuCounter; +public: + WidgetMessage(SherlockEngine *vm); + virtual ~WidgetMessage() {} + + /** + * Load the data for the text window + */ + void load(const Common::String &str, int time); + + /** + * Handle event processing + */ + virtual void handleEvents(); }; } // End of namespace Tattoo |