Skip to content

Commit

Permalink
WAGE: Draw gameover dialog
Browse files Browse the repository at this point in the history
  • Loading branch information
sev- committed Feb 14, 2016
1 parent 750e442 commit efdf51d
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 18 deletions.
29 changes: 18 additions & 11 deletions engines/wage/dialog.cpp
Expand Up @@ -56,8 +56,8 @@
namespace Wage {

enum {
kDialogWidth = 292,
kDialogHeight = 114
kDialogWidth = 199,
kDialogHeight = 113
};

Dialog::Dialog(Gui *gui, const char *text, DialogButtonArray *buttons) : _gui(gui), _text(text), _buttons(buttons) {
Expand All @@ -73,10 +73,17 @@ Dialog::Dialog(Gui *gui, const char *text, DialogButtonArray *buttons) : _gui(gu
_bbox.right = (_gui->_screen.w + kDialogWidth) / 2;
_bbox.bottom = (_gui->_screen.h + kDialogHeight) / 2;

_defaultButton = NULL;
_pressedButton = NULL;
_defaultButton = -1;
_pressedButton = -1;

_mouseOverPressedButton = false;

// Adjust button positions
for (int i = 0; i < _buttons->size(); i++)
_buttons->operator[](i)->bounds.translate(_bbox.left, _bbox.top);

if (_buttons->size() == 1)
_defaultButton = 0;
}

Dialog::~Dialog() {
Expand All @@ -88,7 +95,7 @@ const Graphics::Font *Dialog::getDialogFont() {

void Dialog::paint() {
Design::drawFilledRect(&_gui->_screen, _bbox, kColorWhite, _gui->_patterns, kPatternSolid);
_font->drawString(&_gui->_screen, _text, _bbox.left + 24, _bbox.right + 32, _bbox.width(), kColorBlack);
_font->drawString(&_gui->_screen, _text, _bbox.left + 24, _bbox.top + 16, _bbox.width(), kColorBlack);

static int boxOutline[] = { 1, 0, 0, 1, 1 };
drawOutline(_bbox, boxOutline, ARRAYSIZE(boxOutline));
Expand All @@ -97,15 +104,15 @@ void Dialog::paint() {
DialogButton *button = _buttons->operator[](i);
static int buttonOutline[] = { 0, 0, 0, 0, 1 };

if (button == _defaultButton) {
if (i == _defaultButton) {
buttonOutline[0] = buttonOutline[1] = 1;
} else {
buttonOutline[0] = buttonOutline[1] = 0;
}

int color = kColorBlack;

if (_pressedButton == button && _mouseOverPressedButton) {
if (i == _pressedButton && _mouseOverPressedButton) {
Common::Rect bb(button->bounds.left + 5, button->bounds.top + 5,
button->bounds.right - 5, button->bounds.bottom - 5);

Expand All @@ -115,21 +122,21 @@ void Dialog::paint() {
}
int w = _font->getStringWidth(button->text);
int x = button->bounds.left + (button->bounds.width() - w) / 2;
int y = button->bounds.top + 19;
int y = button->bounds.top + 6;

_font->drawString(&_gui->_screen, button->text, _bbox.left + x, _bbox.right + y, _bbox.width(), color);
_font->drawString(&_gui->_screen, button->text, x, y, _bbox.width(), color);

drawOutline(button->bounds, buttonOutline, ARRAYSIZE(buttonOutline));
}

g_system->copyRectToScreen(_gui->_screen.getBasePtr(_bbox.left, _bbox.top), _gui->_screen.pitch,
_bbox.left, _bbox.top, _bbox.width(), _bbox.height());
_bbox.left, _bbox.top, _bbox.width() + 1, _bbox.height() + 1);
}

void Dialog::drawOutline(Common::Rect &bounds, int *spec, int speclen) {
for (int i = 0; i < speclen; i++)
if (spec[i] != 0)
Design::drawRect(&_gui->_screen, bounds.left + i, bounds.top + i, bounds.right - 1 - 2*i, bounds.bottom - 1 - 2*i,
Design::drawRect(&_gui->_screen, bounds.left + i, bounds.top + i, bounds.right - i, bounds.bottom - i,
1, kColorBlack, _gui->_patterns, kPatternSolid);
}

Expand Down
10 changes: 5 additions & 5 deletions engines/wage/dialog.h
Expand Up @@ -54,12 +54,12 @@ struct DialogButton {
Common::String text;
Common::Rect bounds;

DialogButton(const char *t, int x1, int y1, int x2, int y2) {
DialogButton(const char *t, int x1, int y1, int w, int h) {
text = t;
bounds.left = x1;
bounds.top = y1;
bounds.right = x2;
bounds.bottom = y2;
bounds.right = x1 + w - 1;
bounds.bottom = y1 + h - 1;
}
};

Expand All @@ -80,8 +80,8 @@ class Dialog {

const Graphics::Font *_font;
DialogButtonArray *_buttons;
DialogButton *_pressedButton;
DialogButton *_defaultButton;
int _pressedButton;
int _defaultButton;
bool _mouseOverPressedButton;

private:
Expand Down
3 changes: 1 addition & 2 deletions engines/wage/wage.cpp
Expand Up @@ -140,7 +140,6 @@ void WageEngine::processEvents() {
while (_eventMan->pollEvent(event)) {
switch (event.type) {
case Common::EVENT_QUIT:
gameOver();
_shouldQuit = true;
break;
case Common::EVENT_MOUSEMOVE:
Expand Down Expand Up @@ -221,7 +220,7 @@ void WageEngine::appendText(char *str) {
void WageEngine::gameOver() {
DialogButtonArray buttons;

buttons.push_back(new DialogButton("OK", 112, 67, 68, 28));
buttons.push_back(new DialogButton("OK", 66, 67, 68, 28));

Dialog gameOver(_gui, _world->_gameOverMessage->c_str(), &buttons);

Expand Down

0 comments on commit efdf51d

Please sign in to comment.