WAGE: Draw gameover dialog

This commit is contained in:
Eugene Sandulenko 2016-01-20 22:36:36 +01:00
parent 750e44219f
commit efdf51d3dd
3 changed files with 24 additions and 18 deletions

View File

@ -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) {
@ -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() {
@ -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));
@ -97,7 +104,7 @@ 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;
@ -105,7 +112,7 @@ void Dialog::paint() {
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);
@ -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);
}

View File

@ -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;
}
};
@ -80,8 +80,8 @@ private:
const Graphics::Font *_font;
DialogButtonArray *_buttons;
DialogButton *_pressedButton;
DialogButton *_defaultButton;
int _pressedButton;
int _defaultButton;
bool _mouseOverPressedButton;
private:

View File

@ -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:
@ -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);