XEEN: Implemented Window functionality

This commit is contained in:
Paul Gilbert 2014-12-30 22:50:24 -10:00
parent fb47ec9627
commit 9506635bad
8 changed files with 197 additions and 57 deletions

View File

@ -176,4 +176,9 @@ void EventsManager::nextFrame() {
_vm->_screen->update();
}
/*------------------------------------------------------------------------*/
GameEvent::GameEvent() {
}
} // End of namespace Xeen

View File

@ -79,6 +79,11 @@ public:
uint32 timeElapsed();
};
class GameEvent {
public:
GameEvent();
};
} // End of namespace Xeen
#endif /* XEEN_EVENTS_H */

View File

@ -43,6 +43,10 @@ void Dialog::restoreButtons() {
_buttons = _savedButtons.pop();
}
void Dialog::addButton(const Common::Rect &bounds, char c, SpriteResource *sprites, bool d) {
_buttons.push_back(DialogButton(bounds, c, sprites, d));
}
/*------------------------------------------------------------------------*/
void OptionsMenu::show(XeenEngine *vm) {
@ -77,8 +81,9 @@ void OptionsMenu::execute() {
screen._windows[28].setBounds(Common::Rect(72, 25, 248, 175));
Common::String title1, title2;
startup(title1, title2);
Common::String title1, buttonsName;
startup(title1, buttonsName);
SpriteResource buttonSprites(buttonsName);
bool firstTime = true;
while (!_vm->shouldQuit()) {
@ -91,10 +96,17 @@ void OptionsMenu::execute() {
}
for (;;) {
clearButtons();
showTitles1(title1);
showTitles2();
reopen:
clearButtons();
setupButtons(&buttonSprites);
openWindow();
while (!_vm->shouldQuit()) {
}
}
}
}
@ -108,9 +120,9 @@ void OptionsMenu::showTitles1(const Common::String &title) {
while (!_vm->shouldQuit() && !events.isKeyMousePressed()) {
events.updateGameCounter();
frame = frame % (_vm->getGameID() == GType_WorldOfXeen ? 5 : 10);
frame = ++frame % (_vm->getGameID() == GType_WorldOfXeen ? 5 : 10);
screen.restoreBackground();
titleSprites.draw(screen, 0);
titleSprites.draw(screen, frame);
while (events.timeElapsed() == 0)
events.pollEventsAndWait();
@ -153,6 +165,20 @@ void OptionsMenu::showTitles2() {
screen._windows[0].update();
}
void OptionsMenu::setupButtons(SpriteResource *buttons) {
addButton(Common::Rect(124, 87, 124 + 53, 87 + 10), 'S', buttons, true);
addButton(Common::Rect(126, 98, 126 + 47, 98 + 10), 'L', buttons, true);
addButton(Common::Rect(91, 110, 91 + 118, 110 + 10), 'C', buttons, true);
addButton(Common::Rect(85, 121, 85 + 131, 121 + 10), 'O', buttons, true);
}
void WorldOptionsMenu::setupButtons(SpriteResource *buttons) {
addButton(Common::Rect(93, 53, 93 + 134, 53 + 20), 'S', buttons, false);
addButton(Common::Rect(93, 78, 93 + 134, 78 + 20), 'L', buttons, false);
addButton(Common::Rect(93, 103, 93 + 134, 103 + 20), 'C', buttons, false);
addButton(Common::Rect(93, 128, 93 + 134, 128 + 20), 'O', buttons, false);
}
/*------------------------------------------------------------------------*/
void CloudsOptionsMenu::startup(Common::String &title1, Common::String &title2) {
@ -289,4 +315,9 @@ void WorldOptionsMenu::setBackground() {
screen.fadeIn(4);
}
void WorldOptionsMenu::openWindow() {
_vm->_screen->_windows[28].open();
}
} // End of namespace Xeen

View File

@ -33,8 +33,14 @@ namespace Xeen {
class DialogButton {
public:
Common::Rect _bounds;
int _d;
int _i;
SpriteResource *_sprites;
char _c;
bool _d;
DialogButton(const Common::Rect &bounds, char c, SpriteResource *sprites, bool d) :
_bounds(bounds), _c(c), _sprites(sprites), _d(d) {}
DialogButton() : _c('\0'), _sprites(nullptr), _d(false) {}
};
class Dialog {
@ -53,6 +59,8 @@ public:
void clearButtons();
void restoreButtons();
void addButton(const Common::Rect &bounds, char c, SpriteResource *sprites, bool d);
};
class OptionsMenu: public Dialog {
@ -68,6 +76,10 @@ protected:
virtual void showTitles1(const Common::String &title);
virtual void showTitles2();
virtual void setupButtons(SpriteResource *buttons);
virtual void openWindow() {}
public:
static void show(XeenEngine *vm);
};
@ -97,6 +109,10 @@ protected:
virtual void setBackground();
virtual void showTitles2() {}
virtual void setupButtons(SpriteResource *buttons);
virtual void openWindow();
public:
WorldOptionsMenu(XeenEngine *vm) : DarkSideOptionsMenu(vm) {}
};

View File

@ -22,25 +22,76 @@
#include "common/system.h"
#include "graphics/palette.h"
#include "graphics/surface.h"
#include "xeen/screen.h"
#include "xeen/resources.h"
#include "xeen/xeen.h"
namespace Xeen {
Window::Window() : _screen(nullptr), _enabled(false), _a(0), _border(0),
Window::Window() : _vm(nullptr), _enabled(false), _a(0), _border(0),
_xLo(0), _xHi(0), _ycL(0), _ycH(0) {
}
Window::Window(Screen *screen, const Common::Rect &bounds, int a, int border,
Window::Window(XeenEngine *vm, const Common::Rect &bounds, int a, int border,
int xLo, int ycL, int xHi, int ycH):
_screen(screen), _enabled(false), _bounds(bounds), _a(a), _border(border),
_xLo(xLo), _ycL(ycL), _xHi(xHi), _ycH(ycH) {
_vm(vm), _enabled(false), _a(a), _border(border),
_xLo(xLo), _ycL(ycL), _xHi(xHi), _ycH(ycH) {
setBounds(bounds);
}
void Window::setBounds(const Common::Rect &r) {
_bounds = r;
_innerBounds = r;
_innerBounds.grow(-_border);
}
void Window::open() {
if (!_enabled) {
_vm->_screen->_windowStack.push_back(this);
open2();
}
if (_vm->_mode == MODE_9) {
warning("TODO: copyFileToMemory");
}
}
void Window::open2() {
create(_bounds.width(), _bounds.height());
copyRectToSurface(*_vm->_screen, 0, 0, _bounds);
_dirtyRects.push(_bounds);
}
void Window::close() {
if (_enabled) {
// Update any remaining pending changes to the screen and free
// the window's internal surface storage
update();
free();
// Remove the window from the stack and flag it as now disabled
for (uint i = 0; i < _vm->_screen->_windowStack.size(); ++i) {
if (_vm->_screen->_windowStack[i] == this)
_vm->_screen->_windowStack.remove_at(i);
}
_enabled = false;
}
if (_vm->_mode == MODE_9) {
warning("TODO: copyFileToMemory");
}
}
/**
* Pushes any pending changes for the window to the screen
*/
void Window::update() {
// Window updates are not specifically necessary since all drawing
// automatically gets added to the screen's dirty rect list
while (!_dirtyRects.empty()) {
Common::Rect r = _dirtyRects.pop();
blitTo(*_vm->_screen, Common::Point(_bounds.left, _bounds.top));
}
}
/*------------------------------------------------------------------------*/
@ -56,50 +107,56 @@ Screen::Screen(XeenEngine *vm) : _vm(vm) {
void Screen::setupWindows() {
Window windows[40] = {
Window(this, Common::Rect(0, 0, 320, 200), 0, 0, 0, 0, 320, 200),
Window(this, Common::Rect(237, 9, 317, 74), 0, 0, 237, 12, 307, 68),
Window(this, Common::Rect(225, 1, 319, 73), 1, 8, 225, 1, 319, 73),
Window(this, Common::Rect(0, 0, 230, 149), 0, 0, 9, 8, 216, 140),
Window(this, Common::Rect(235, 148, 309, 189), 2, 8, 0, 0, 0, 0),
Window(this, Common::Rect(70, 20, 250, 183), 3, 8, 80, 38, 240, 166),
Window(this, Common::Rect(52, 149, 268, 197), 4, 8, 0, 0, 0, 0),
Window(this, Common::Rect(108, 0, 200, 200), 5, 0, 0, 0, 0, 0),
Window(this, Common::Rect(232, 9, 312, 74), 0, 0, 0, 0, 0, 0),
Window(this, Common::Rect(103, 156, 217, 186), 6, 8, 0, 0, 0, 0),
Window(this, Common::Rect(226, 0, 319, 146), 7, 8, 0, 0, 0, 0),
Window(this, Common::Rect(8, 8, 224, 140), 8, 8, 8, 8, 224, 200),
Window(this, Common::Rect(0, 143, 320, 199), 9, 8, 0, 0, 0, 0),
Window(this, Common::Rect(50, 103, 266, 139), 10, 8, 0, 0, 0, 0),
Window(this, Common::Rect(0, 7, 320, 138), 11, 8, 0, 0, 0, 0),
Window(this, Common::Rect(50, 71, 182, 129), 12, 8, 0, 0, 0, 0),
Window(this, Common::Rect(228, 106, 319, 146), 13, 8, 0, 0, 0, 0),
Window(this, Common::Rect(20, 142, 290, 199), 14, 8, 0, 0, 0, 0),
Window(this, Common::Rect(0, 20, 320, 180), 15, 8, 0, 0, 0, 0),
Window(this, Common::Rect(231, 48, 317, 141), 16, 8, 0, 0, 0, 0),
Window(this, Common::Rect(72, 37, 248, 163), 17, 8, 0, 0, 0, 0),
Window(this, Common::Rect(99, 59, 237, 141), 18, 8, 99, 59, 237, 0),
Window(this, Common::Rect(65, 23, 250, 163), 19, 8, 75, 36, 245, 141),
Window(this, Common::Rect(80, 28, 256, 148), 20, 8, 80, 28, 256, 172),
Window(this, Common::Rect(0, 0, 320, 146), 21, 8, 0, 0, 320, 148),
Window(this, Common::Rect(27, 6, 207, 142), 22, 8, 0, 0, 0, 146),
Window(this, Common::Rect(15, 15, 161, 91), 23, 8, 0, 0, 0, 0),
Window(this, Common::Rect(90, 45, 220, 157), 24, 8, 0, 0, 0, 0),
Window(this, Common::Rect(0, 0, 320, 200), 25, 8, 0, 0, 0, 0),
Window(this, Common::Rect(0, 101, 320, 146), 26, 8, 0, 101, 320, 0),
Window(this, Common::Rect(0, 0, 320, 108), 27, 8, 0, 0, 0, 45),
Window(this, Common::Rect(50, 112, 266, 148), 28, 8, 0, 0, 0, 0),
Window(this, Common::Rect(12, 11, 164, 94), 0, 0, 0, 0, 52, 0),
Window(this, Common::Rect(8, 147, 224, 192), 0, 8, 0, 0, 0, 94),
Window(this, Common::Rect(232, 74, 312, 138), 29, 8, 0, 0, 0, 0),
Window(this, Common::Rect(226, 26, 319, 146), 30, 8, 0, 0, 0, 0),
Window(this, Common::Rect(225, 74, 319, 154), 31, 8, 0, 0, 0, 0),
Window(this, Common::Rect(27, 6, 195, 142), 0, 8, 0, 0, 0, 0),
Window(this, Common::Rect(225, 140, 319, 199), 0, 8, 0, 0, 0, 0)
Window(_vm, Common::Rect(0, 0, 320, 200), 0, 0, 0, 0, 320, 200),
Window(_vm, Common::Rect(237, 9, 317, 74), 0, 0, 237, 12, 307, 68),
Window(_vm, Common::Rect(225, 1, 319, 73), 1, 8, 225, 1, 319, 73),
Window(_vm, Common::Rect(0, 0, 230, 149), 0, 0, 9, 8, 216, 140),
Window(_vm, Common::Rect(235, 148, 309, 189), 2, 8, 0, 0, 0, 0),
Window(_vm, Common::Rect(70, 20, 250, 183), 3, 8, 80, 38, 240, 166),
Window(_vm, Common::Rect(52, 149, 268, 197), 4, 8, 0, 0, 0, 0),
Window(_vm, Common::Rect(108, 0, 200, 200), 5, 0, 0, 0, 0, 0),
Window(_vm, Common::Rect(232, 9, 312, 74), 0, 0, 0, 0, 0, 0),
Window(_vm, Common::Rect(103, 156, 217, 186), 6, 8, 0, 0, 0, 0),
Window(_vm, Common::Rect(226, 0, 319, 146), 7, 8, 0, 0, 0, 0),
Window(_vm, Common::Rect(8, 8, 224, 140), 8, 8, 8, 8, 224, 200),
Window(_vm, Common::Rect(0, 143, 320, 199), 9, 8, 0, 0, 0, 0),
Window(_vm, Common::Rect(50, 103, 266, 139), 10, 8, 0, 0, 0, 0),
Window(_vm, Common::Rect(0, 7, 320, 138), 11, 8, 0, 0, 0, 0),
Window(_vm, Common::Rect(50, 71, 182, 129), 12, 8, 0, 0, 0, 0),
Window(_vm, Common::Rect(228, 106, 319, 146), 13, 8, 0, 0, 0, 0),
Window(_vm, Common::Rect(20, 142, 290, 199), 14, 8, 0, 0, 0, 0),
Window(_vm, Common::Rect(0, 20, 320, 180), 15, 8, 0, 0, 0, 0),
Window(_vm, Common::Rect(231, 48, 317, 141), 16, 8, 0, 0, 0, 0),
Window(_vm, Common::Rect(72, 37, 248, 163), 17, 8, 0, 0, 0, 0),
Window(_vm, Common::Rect(99, 59, 237, 141), 18, 8, 99, 59, 237, 0),
Window(_vm, Common::Rect(65, 23, 250, 163), 19, 8, 75, 36, 245, 141),
Window(_vm, Common::Rect(80, 28, 256, 148), 20, 8, 80, 28, 256, 172),
Window(_vm, Common::Rect(0, 0, 320, 146), 21, 8, 0, 0, 320, 148),
Window(_vm, Common::Rect(27, 6, 207, 142), 22, 8, 0, 0, 0, 146),
Window(_vm, Common::Rect(15, 15, 161, 91), 23, 8, 0, 0, 0, 0),
Window(_vm, Common::Rect(90, 45, 220, 157), 24, 8, 0, 0, 0, 0),
Window(_vm, Common::Rect(0, 0, 320, 200), 25, 8, 0, 0, 0, 0),
Window(_vm, Common::Rect(0, 101, 320, 146), 26, 8, 0, 101, 320, 0),
Window(_vm, Common::Rect(0, 0, 320, 108), 27, 8, 0, 0, 0, 45),
Window(_vm, Common::Rect(50, 112, 266, 148), 28, 8, 0, 0, 0, 0),
Window(_vm, Common::Rect(12, 11, 164, 94), 0, 0, 0, 0, 52, 0),
Window(_vm, Common::Rect(8, 147, 224, 192), 0, 8, 0, 0, 0, 94),
Window(_vm, Common::Rect(232, 74, 312, 138), 29, 8, 0, 0, 0, 0),
Window(_vm, Common::Rect(226, 26, 319, 146), 30, 8, 0, 0, 0, 0),
Window(_vm, Common::Rect(225, 74, 319, 154), 31, 8, 0, 0, 0, 0),
Window(_vm, Common::Rect(27, 6, 195, 142), 0, 8, 0, 0, 0, 0),
Window(_vm, Common::Rect(225, 140, 319, 199), 0, 8, 0, 0, 0, 0)
};
_windows = Common::Array<Window>(windows, 40);
}
void Screen::closeWindows() {
for (int i = (int)_windowStack.size() - 1; i >= 0; --i)
_windowStack[i]->close();
assert(_windowStack.size() == 0);
}
void Screen::update() {
// Merge the dirty rects
mergeDirtyRects();

View File

@ -26,6 +26,7 @@
#include "common/scummsys.h"
#include "common/system.h"
#include "common/array.h"
#include "common/queue.h"
#include "common/rect.h"
#include "xeen/xsurface.h"
@ -39,22 +40,30 @@ namespace Xeen {
class XeenEngine;
class Screen;
class Window {
class Window: public XSurface {
private:
Screen *_screen;
XeenEngine *_vm;
Common::Rect _bounds;
Common::Rect _innerBounds;
int _a;
int _border;
int _xLo, _xHi;
int _ycL, _ycH;
bool _enabled;
Common::Queue<Common::Rect> _dirtyRects;
void open2();
public:
Window();
Window(Screen *screen, const Common::Rect &bounds, int a, int border,
Window(XeenEngine *vm, const Common::Rect &bounds, int a, int border,
int xLo, int ycL, int xHi, int ycH);
void setBounds(const Common::Rect &r) { _bounds = r; }
void setBounds(const Common::Rect &r);
void open();
void close();
void update();
};
@ -86,9 +95,13 @@ public:
virtual void addDirtyRect(const Common::Rect &r);
public:
Common::Array<Window> _windows;
Common::Array<Window *> _windowStack;
public:
Screen(XeenEngine *vm);
void closeWindows();
void update();
void loadPalette(const Common::String &name);

View File

@ -38,6 +38,7 @@ XeenEngine::XeenEngine(OSystem *syst, const XeenGameDescription *gameDesc)
_events = nullptr;
_screen = nullptr;
_sound = nullptr;
_eventData = nullptr;
}
XeenEngine::~XeenEngine() {
@ -45,6 +46,7 @@ XeenEngine::~XeenEngine() {
delete _events;
delete _screen;
delete _sound;
delete _eventData;
}
void XeenEngine::initialize() {
@ -61,6 +63,9 @@ void XeenEngine::initialize() {
_screen = new Screen(this);
_sound = new SoundManager(this);
File f("029.obj");
_eventData = f.readStream(f.size());
// Set graphics mode
initGraphics(320, 200, false);

View File

@ -64,6 +64,11 @@ enum XeenDebugChannels {
kDebugSound = 1 << 3
};
enum Mode {
MODE_0 = 0,
MODE_9 = 9
};
struct XeenGameDescription;
#define XEEN_SAVEGAME_VERSION 1
@ -110,6 +115,9 @@ public:
EventsManager *_events;
Screen *_screen;
SoundManager *_sound;
Mode _mode;
GameEvent _gameEvent;
Common::SeekableReadStream *_eventData;
public:
XeenEngine(OSystem *syst, const XeenGameDescription *gameDesc);
virtual ~XeenEngine();