From e8fb9920a9cf4ccb44620d992a093205ffd98c15 Mon Sep 17 00:00:00 2001 From: Paul Gilbert Date: Sun, 3 Dec 2017 20:08:11 -0500 Subject: XEEN: Cleanup of window opening & closing --- engines/xeen/interface.cpp | 2 +- engines/xeen/party.cpp | 4 +-- engines/xeen/scripts.cpp | 2 +- engines/xeen/window.cpp | 78 ++++++++++++++++++++-------------------------- engines/xeen/window.h | 23 ++++++-------- engines/xeen/xeen.h | 2 +- 6 files changed, 49 insertions(+), 62 deletions(-) (limited to 'engines') diff --git a/engines/xeen/interface.cpp b/engines/xeen/interface.cpp index 7db7e850c0..43e859202c 100644 --- a/engines/xeen/interface.cpp +++ b/engines/xeen/interface.cpp @@ -1298,7 +1298,7 @@ void Interface::draw3d(bool updateFlag, bool skipDelay) { } party._stepped = false; - if (_vm->_mode == MODE_9) { + if (_vm->_mode == MODE_RECORD_EVENTS) { // TODO: Save current scripts data? } diff --git a/engines/xeen/party.cpp b/engines/xeen/party.cpp index 732e9fa1c0..ce30859c1f 100644 --- a/engines/xeen/party.cpp +++ b/engines/xeen/party.cpp @@ -405,7 +405,7 @@ void Party::addTime(int numMinutes) { _newDay = true; if (_newDay && _minutes >= 300) { - if (_vm->_mode != MODE_9 && _vm->_mode != MODE_17) { + if (_vm->_mode != MODE_RECORD_EVENTS && _vm->_mode != MODE_17) { resetTemps(); if (_rested || _vm->_mode == MODE_SLEEPING) { _rested = false; @@ -579,7 +579,7 @@ void Party::giveTreasure() { for (int idx = 0; idx < 26 && !monstersPresent; ++idx) monstersPresent = combat._attackMonsters[idx] != -1; - if (_vm->_mode != MODE_9 && monstersPresent) + if (_vm->_mode != MODE_RECORD_EVENTS && monstersPresent) return; Common::fill(&combat._shooting[0], &combat._shooting[MAX_PARTY_COUNT], 0); diff --git a/engines/xeen/scripts.cpp b/engines/xeen/scripts.cpp index 5c09f9f5bd..37ddd1e7b7 100644 --- a/engines/xeen/scripts.cpp +++ b/engines/xeen/scripts.cpp @@ -188,7 +188,7 @@ int Scripts::checkEvents() { if (event._position == _currentPos && party._mazeDirection != (_currentPos.x | _currentPos.y) && event._line == _lineNum) { if (event._direction == party._mazeDirection || event._direction == DIR_ALL) { - _vm->_mode = MODE_9; + _vm->_mode = MODE_RECORD_EVENTS; _scriptExecuted = true; doOpcode(event); break; diff --git a/engines/xeen/window.cpp b/engines/xeen/window.cpp index d4a798bc4b..ef3fedeec2 100644 --- a/engines/xeen/window.cpp +++ b/engines/xeen/window.cpp @@ -92,11 +92,11 @@ void Windows::closeAll() { assert(_windowStack.size() == 0); } -void Windows::addToStack(Window *win) { +void Windows::windowOpened(Window *win) { _windowStack.push_back(win); } -void Windows::removeFromStack(Window *win) { +void Windows::windowClosed(Window *win) { for (uint i = 0; i < _windowStack.size(); ++i) { if (_windowStack[i] == win) { _windowStack.remove_at(i); @@ -134,36 +134,48 @@ void Window::setBounds(const Common::Rect &r) { } void Window::open() { + Screen &screen = *g_vm->_screen; + if (!_enabled) { + // Save a copy of the area under the window + _savedArea.create(_bounds.width(), _bounds.height()); + _savedArea.copyRectToSurface(screen, 0, 0, _bounds); + + // Mark the area as dirty and fill it with a default background + addDirtyRect(_bounds); + frame(); + fill(); + + _writePos.x = _bounds.right - 8; + writeSymbol(19); + + _writePos.x = _innerBounds.left; + _writePos.y = _innerBounds.top; + _fontJustify = JUSTIFY_NONE; + _fontReduced = false; _enabled = true; - g_vm->_windows->addToStack(this); - open2(); - } - if (g_vm->_mode == MODE_9) { - warning("TODO: copyFileToMemory"); + // Signal that the window has opened + g_vm->_windows->windowOpened(this); } } -void Window::open2() { +void Window::close() { Screen &screen = *g_vm->_screen; - // Save a copy of the area under the window - _savedArea.create(_bounds.width(), _bounds.height()); - _savedArea.copyRectToSurface(screen, 0, 0, _bounds); - - // Mark the area as dirty and fill it with a default background - addDirtyRect(_bounds); - frame(); - fill(); + if (_enabled) { + // Update the window + update(); - _writePos.x = _bounds.right - 8; - writeSymbol(19); + // Restore the saved original content + screen.copyRectToSurface(_savedArea, _bounds.left, _bounds.top, + Common::Rect(0, 0, _bounds.width(), _bounds.height())); + addDirtyRect(_bounds); - _writePos.x = _innerBounds.left; - _writePos.y = _innerBounds.top; - _fontJustify = JUSTIFY_NONE; - _fontReduced = false; + // Signal that the window has closed + g_vm->_windows->windowClosed(this); + _enabled = false; + } } void Window::frame() { @@ -220,28 +232,6 @@ void Window::frame() { writeSymbol(19); } -void Window::close() { - Screen &screen = *g_vm->_screen; - - if (_enabled) { - // Update the window - update(); - - // Restore the saved original content - screen.copyRectToSurface(_savedArea, _bounds.left, _bounds.top, - Common::Rect(0, 0, _bounds.width(), _bounds.height())); - addDirtyRect(_bounds); - - // Remove the window from the stack and flag it as now disabled - g_vm->_windows->removeFromStack(this); - _enabled = false; - } - - if (g_vm->_mode == MODE_9) { - warning("TODO: copyFileToMemory"); - } -} - void Window::update() { // Since all window drawing is done on the screen surface anyway, // there's nothing that needs to be updated here diff --git a/engines/xeen/window.h b/engines/xeen/window.h index cd9a1dd2bf..0594a9946d 100644 --- a/engines/xeen/window.h +++ b/engines/xeen/window.h @@ -49,20 +49,9 @@ struct DrawStruct { }; class Windows : public FontData { - friend class Window; private: Common::Array _windows; Common::Array _windowStack; -private: - /** - * Adds a window to the stack of currently open ones - */ - void addToStack(Window *win); - - /** - * Removes a window from the currently active stack - */ - void removeFromStack(Window *win); public: Windows(); ~Windows(); @@ -76,6 +65,16 @@ public: * Close all currently open windows */ void closeAll(); + + /** + * Called when a window has been opened + */ + void windowOpened(Window *win); + + /** + * Called when a window has been closed + */ + void windowClosed(Window *win); }; class Window: public FontSurface { @@ -87,8 +86,6 @@ private: int _border; int _xLo, _xHi; int _ycL, _ycH; - - void open2(); public: bool _enabled; public: diff --git a/engines/xeen/xeen.h b/engines/xeen/xeen.h index 51845d78ce..cc187c9527 100644 --- a/engines/xeen/xeen.h +++ b/engines/xeen/xeen.h @@ -86,7 +86,7 @@ enum Mode { MODE_6 = 6, MODE_7 = 7, MODE_8 = 8, - MODE_9 = 9, + MODE_RECORD_EVENTS = 9, MODE_CHARACTER_INFO = 10, MODE_12 = 12, MODE_DIALOG_123 = 13, -- cgit v1.2.3