From b39f4179ce53e9e98c4e3d80cc0f075dabd8d8f6 Mon Sep 17 00:00:00 2001 From: Paul Gilbert Date: Thu, 5 Feb 2015 20:47:15 -0500 Subject: XEEN: Merged confirmation and yes/no dialogs into single source file --- engines/xeen/character.cpp | 13 +++- engines/xeen/dialogs_confirm.cpp | 85 --------------------- engines/xeen/dialogs_confirm.h | 43 ----------- engines/xeen/dialogs_query.cpp | 159 +++++++++++++++++++++++++++++++++++++++ engines/xeen/dialogs_query.h | 54 +++++++++++++ engines/xeen/dialogs_spells.cpp | 4 +- engines/xeen/dialogs_yesno.cpp | 96 ----------------------- engines/xeen/dialogs_yesno.h | 43 ----------- engines/xeen/module.mk | 3 +- engines/xeen/resources.cpp | 2 + engines/xeen/resources.h | 2 + engines/xeen/scripts.cpp | 2 +- engines/xeen/town.cpp | 2 +- 13 files changed, 232 insertions(+), 276 deletions(-) delete mode 100644 engines/xeen/dialogs_confirm.cpp delete mode 100644 engines/xeen/dialogs_confirm.h create mode 100644 engines/xeen/dialogs_query.cpp create mode 100644 engines/xeen/dialogs_query.h delete mode 100644 engines/xeen/dialogs_yesno.cpp delete mode 100644 engines/xeen/dialogs_yesno.h (limited to 'engines') diff --git a/engines/xeen/character.cpp b/engines/xeen/character.cpp index 20cbfbd0fc..8fd7a35c5f 100644 --- a/engines/xeen/character.cpp +++ b/engines/xeen/character.cpp @@ -21,6 +21,7 @@ */ #include "xeen/character.h" +#include "xeen/dialogs_query.h" #include "xeen/dialogs_error.h" #include "xeen/resources.h" #include "xeen/xeen.h" @@ -128,13 +129,19 @@ bool InventoryItems::discardItem(int itemIndex) { if (item._bonusFlags & ITEMFLAG_CURSED) { ErrorScroll::show(vm, CANNOT_DISCARD_CURSED_ITEM); - return false; } else { Common::String itemDesc = getFullDescription(itemIndex, 4); + Common::String msg = Common::String::format(PERMANENTLY_DISCARD, itemDesc.c_str()); + + if (Confirm::show(vm, msg)) { + operator[](itemIndex).clear(); + sort(); - error("TODO: discardItem - %s", itemDesc.c_str()); + return true; + } } - error("TODO"); + + return true; } /** diff --git a/engines/xeen/dialogs_confirm.cpp b/engines/xeen/dialogs_confirm.cpp deleted file mode 100644 index 13a41e76ca..0000000000 --- a/engines/xeen/dialogs_confirm.cpp +++ /dev/null @@ -1,85 +0,0 @@ -/* ScummVM - Graphic Adventure Engine - * - * ScummVM is the legal property of its developers, whose names - * are too numerous to list here. Please refer to the COPYRIGHT - * file distributed with this source distribution. - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - * - */ - -#include "xeen/dialogs_confirm.h" -#include "xeen/xeen.h" - -namespace Xeen { - -bool ConfirmDialog::show(XeenEngine *vm, const Common::String &msg, int v2) { - ConfirmDialog *dlg = new ConfirmDialog(vm); - bool result = dlg->execute(msg, v2); - delete dlg; - - return result; -} - -bool ConfirmDialog::execute(const Common::String &msg, int v2) { - Screen &screen = *_vm->_screen; - EventsManager &events = *_vm->_events; - SpriteResource confirmSprites; - confirmSprites.load("confirm.icn"); - - addButton(Common::Rect(129, 112, 153, 132), Common::KEYCODE_y, &confirmSprites); - addButton(Common::Rect(185, 112, 209, 132), Common::KEYCODE_n, &confirmSprites); - - Window &w = screen._windows[v2 ? 21 : 22]; - w.open(); - - if (v2) { - confirmSprites.draw(screen._windows[21], 0, Common::Point(129, 112)); - confirmSprites.draw(screen._windows[21], 2, Common::Point(185, 112)); - - _buttons[0]._bounds.moveTo(129, 112); - _buttons[1]._bounds.moveTo(185, 112); - } else if (v2 & 0x80) { - clearButtons(); - } else { - confirmSprites.draw(screen._windows[22], 0, Common::Point(120, 133)); - confirmSprites.draw(screen._windows[22], 2, Common::Point(176, 133)); - - _buttons[0]._bounds.moveTo(120, 133); - _buttons[1]._bounds.moveTo(176, 133); - } - - w.writeString(msg); - w.update(); - - bool result = false; - while (!_vm->shouldQuit()) { - while (!events.isKeyMousePressed()) - events.pollEventsAndWait(); - - if ((v2 & 0x80) || _buttonValue == Common::KEYCODE_ESCAPE || - _buttonValue == Common::KEYCODE_y) - break; - else if (_buttonValue == Common::KEYCODE_y) { - result = true; - break; - } - } - - w.close(); - return result; -} - -} // End of namespace Xeen diff --git a/engines/xeen/dialogs_confirm.h b/engines/xeen/dialogs_confirm.h deleted file mode 100644 index 825be5e764..0000000000 --- a/engines/xeen/dialogs_confirm.h +++ /dev/null @@ -1,43 +0,0 @@ -/* ScummVM - Graphic Adventure Engine - * - * ScummVM is the legal property of its developers, whose names - * are too numerous to list here. Please refer to the COPYRIGHT - * file distributed with this source distribution. - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - * - */ - -#ifndef XEEN_DIALOGS_CONFIRM_H -#define XEEN_DIALOGS_CONFIRM_H - -#include "xeen/dialogs.h" - -namespace Xeen { - -class ConfirmDialog : public ButtonContainer { -private: - XeenEngine *_vm; - - ConfirmDialog(XeenEngine *vm) : ButtonContainer(), _vm(vm) {} - - bool execute(const Common::String &msg, int v2); -public: - static bool show(XeenEngine *vm, const Common::String &msg, int v2); -}; - -} // End of namespace Xeen - -#endif /* XEEN_DIALOGS_CONFIRM_H */ diff --git a/engines/xeen/dialogs_query.cpp b/engines/xeen/dialogs_query.cpp new file mode 100644 index 0000000000..f226521a94 --- /dev/null +++ b/engines/xeen/dialogs_query.cpp @@ -0,0 +1,159 @@ +/* ScummVM - Graphic Adventure Engine + * + * ScummVM is the legal property of its developers, whose names + * are too numerous to list here. Please refer to the COPYRIGHT + * file distributed with this source distribution. + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * + */ + +#include "xeen/dialogs_query.h" +#include "xeen/xeen.h" + +namespace Xeen { + +bool Confirm::show(XeenEngine *vm, const Common::String &msg, int mode) { + Confirm *dlg = new Confirm(vm); + bool result = dlg->execute(msg, mode); + delete dlg; + + return result; +} + +bool Confirm::execute(const Common::String &msg, int mode) { + Screen &screen = *_vm->_screen; + EventsManager &events = *_vm->_events; + SpriteResource confirmSprites; + bool result = false; + + confirmSprites.load("confirm.icn"); + addButton(Common::Rect(129, 112, 153, 122), Common::KEYCODE_y, &confirmSprites); + addButton(Common::Rect(185, 112, 209, 122), Common::KEYCODE_n, &confirmSprites); + + Window &w = screen._windows[mode ? 22 : 21]; + w.open(); + + if (!mode) { + confirmSprites.draw(w, 0, Common::Point(129, 112)); + confirmSprites.draw(w, 2, Common::Point(185, 112)); + _buttons[0]._bounds.moveTo(129, 112); + _buttons[1]._bounds.moveTo(185, 112); + } else { + if (mode & 0x80) { + clearButtons(); + } else { + confirmSprites.draw(w, 0, Common::Point(120, 133)); + confirmSprites.draw(w, 2, Common::Point(176, 133)); + _buttons[0]._bounds.moveTo(120, 133); + _buttons[1]._bounds.moveTo(176, 133); + } + } + + w.writeString(msg); + w.update(); + + events.clearEvents(); + while (!_vm->shouldQuit()) { + while (!_vm->shouldQuit() && !_buttonValue) { + events.pollEvents(); + checkEvents(_vm); + } + + if ((mode & 0x80) || _buttonValue == Common::KEYCODE_ESCAPE + || _buttonValue == Common::KEYCODE_n) + break; + + if (_buttonValue == Common::KEYCODE_y) { + result = true; + break; + } + } + + w.close(); + return result; +} + +/*------------------------------------------------------------------------*/ + +bool YesNo::show(XeenEngine *vm, bool type, bool townFlag) { + YesNo *dlg = new YesNo(vm); + bool result = dlg->execute(type, townFlag); + delete dlg; + + return result; +} + +bool YesNo::execute(bool type, bool townFlag) { + Screen &screen = *_vm->_screen; + EventsManager &events = *_vm->_events; + Interface &intf = *_vm->_interface; + Map &map = *_vm->_map; + Party &party = *_vm->_party; + Town &town = *_vm->_town; + SpriteResource confirmSprites; + int numFrames; + bool result = false; + + Mode oldMode = _vm->_mode; + _vm->_mode = oldMode == MODE_7 ? MODE_8 : MODE_7; + + if (!type) { + confirmSprites.load("confirm.icn"); + intf._globalSprites.draw(screen, 7, Common::Point(232, 74)); + confirmSprites.draw(screen, 0, Common::Point(235, 75)); + confirmSprites.draw(screen, 2, Common::Point(260, 75)); + screen._windows[34].update(); + + addButton(Common::Rect(235, 75, 259, 95), Common::KEYCODE_y, &confirmSprites); + addButton(Common::Rect(260, 75, 284, 95), Common::KEYCODE_n, &confirmSprites); + + intf._face1State = map._headData[party._mazePosition.y][party._mazePosition.x]._left; + intf._face2State = map._headData[party._mazePosition.y][party._mazePosition.x]._right; + } + + while (!_vm->shouldQuit()) { + events.updateGameCounter(); + + if (town.isActive()) { + town.drawTownAnim(townFlag); + numFrames = 3; + } else { + intf.draw3d(true); + numFrames = 1; + } + + events.wait(3, true); + checkEvents(_vm); + if (!_buttonValue) + continue; + + if (type || _buttonValue == Common::KEYCODE_y) { + result = true; + break; + } else if (_buttonValue == Common::KEYCODE_n || _buttonValue == Common::KEYCODE_ESCAPE) + break; + } + + intf._face1State = intf._face2State = 2; + _vm->_mode = oldMode; + + if (!type) + intf.mainIconsPrint(); + + return result; +} + +} // End of namespace Xeen diff --git a/engines/xeen/dialogs_query.h b/engines/xeen/dialogs_query.h new file mode 100644 index 0000000000..96ae488b97 --- /dev/null +++ b/engines/xeen/dialogs_query.h @@ -0,0 +1,54 @@ +/* ScummVM - Graphic Adventure Engine + * + * ScummVM is the legal property of its developers, whose names + * are too numerous to list here. Please refer to the COPYRIGHT + * file distributed with this source distribution. + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * + */ + +#ifndef XEEN_DIALOGS_QUERY_H +#define XEEN_DIALOGS_QUERY_H + +#include "xeen/dialogs.h" + +namespace Xeen { + +class Confirm : public ButtonContainer { +private: + XeenEngine *_vm; + + Confirm(XeenEngine *vm) : ButtonContainer(), _vm(vm) {} + + bool execute(const Common::String &msg, int mode); +public: + static bool show(XeenEngine *vm, const Common::String &msg, int mode = 0); +}; + +class YesNo : public ButtonContainer { +private: + XeenEngine *_vm; + + YesNo(XeenEngine *vm) : ButtonContainer(), _vm(vm) {} + + bool execute(bool type, bool townFlag); +public: + static bool show(XeenEngine *vm, bool type, bool townFlag = false); +}; + +} // End of namespace Xeen + +#endif /* XEEN_DIALOGS_QUERY_H */ diff --git a/engines/xeen/dialogs_spells.cpp b/engines/xeen/dialogs_spells.cpp index 714e881128..4f86707554 100644 --- a/engines/xeen/dialogs_spells.cpp +++ b/engines/xeen/dialogs_spells.cpp @@ -21,7 +21,7 @@ */ #include "xeen/dialogs_spells.h" -#include "xeen/dialogs_confirm.h" +#include "xeen/dialogs_query.h" #include "xeen/resources.h" #include "xeen/spells.h" #include "xeen/sprites.h" @@ -216,7 +216,7 @@ Character *SpellsScroll::execute(Character *c, int v2) { Common::String::format(SPELLS_PRESS_A_KEY, msg.c_str()) : Common::String::format(SPELLS_PURCHASE, msg.c_str(), spellCost); - if (ConfirmDialog::show(_vm, msg, v2Copy + 1)) { + if (Confirm::show(_vm, msg, v2Copy + 1)) { if (party.subtract(0, spellCost, 0, WT_FREEZE_WAIT)) { ++c->_spells[spellIndex]; sound.playSample(nullptr, 0); diff --git a/engines/xeen/dialogs_yesno.cpp b/engines/xeen/dialogs_yesno.cpp deleted file mode 100644 index 17ca9a0c3e..0000000000 --- a/engines/xeen/dialogs_yesno.cpp +++ /dev/null @@ -1,96 +0,0 @@ -/* ScummVM - Graphic Adventure Engine - * - * ScummVM is the legal property of its developers, whose names - * are too numerous to list here. Please refer to the COPYRIGHT - * file distributed with this source distribution. - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - * - */ - -#include "xeen/dialogs_yesno.h" -#include "xeen/xeen.h" - -namespace Xeen { - -bool YesNo::show(XeenEngine *vm, bool type, bool townFlag) { - YesNo *dlg = new YesNo(vm); - bool result = dlg->execute(type, townFlag); - delete dlg; - - return result; -} - -bool YesNo::execute(bool type, bool townFlag) { - Screen &screen = *_vm->_screen; - EventsManager &events = *_vm->_events; - Interface &intf = *_vm->_interface; - Map &map = *_vm->_map; - Party &party = *_vm->_party; - Town &town = *_vm->_town; - SpriteResource confirmSprites; - int numFrames; - bool result = false; - - Mode oldMode = _vm->_mode; - _vm->_mode = oldMode == MODE_7 ? MODE_8 : MODE_7; - - if (!type) { - confirmSprites.load("confirm.icn"); - intf._globalSprites.draw(screen, 7, Common::Point(232, 74)); - confirmSprites.draw(screen, 0, Common::Point(235, 75)); - confirmSprites.draw(screen, 2, Common::Point(260, 75)); - screen._windows[34].update(); - - addButton(Common::Rect(235, 75, 259, 95), Common::KEYCODE_y, &confirmSprites); - addButton(Common::Rect(260, 75, 284, 95), Common::KEYCODE_n, &confirmSprites); - - intf._face1State = map._headData[party._mazePosition.y][party._mazePosition.x]._left; - intf._face2State = map._headData[party._mazePosition.y][party._mazePosition.x]._right; - } - - while (!_vm->shouldQuit()) { - events.updateGameCounter(); - - if (town.isActive()) { - town.drawTownAnim(townFlag); - numFrames = 3; - } else { - intf.draw3d(true); - numFrames = 1; - } - - events.wait(3, true); - checkEvents(_vm); - if (!_buttonValue) - continue; - - if (type || _buttonValue == Common::KEYCODE_y) { - result = true; - break; - } else if (_buttonValue == Common::KEYCODE_n || _buttonValue == Common::KEYCODE_ESCAPE) - break; - } - - intf._face1State = intf._face2State = 2; - _vm->_mode = oldMode; - - if (!type) - intf.mainIconsPrint(); - - return result; -} - -} // End of namespace Xeen diff --git a/engines/xeen/dialogs_yesno.h b/engines/xeen/dialogs_yesno.h deleted file mode 100644 index 96c3592d9d..0000000000 --- a/engines/xeen/dialogs_yesno.h +++ /dev/null @@ -1,43 +0,0 @@ -/* ScummVM - Graphic Adventure Engine - * - * ScummVM is the legal property of its developers, whose names - * are too numerous to list here. Please refer to the COPYRIGHT - * file distributed with this source distribution. - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - * - */ - -#ifndef XEEN_DIALOGS_YESNO_H -#define XEEN_DIALOGS_YESNO_H - -#include "xeen/dialogs.h" - -namespace Xeen { - -class YesNo : public ButtonContainer { -private: - XeenEngine *_vm; - - YesNo(XeenEngine *vm) : ButtonContainer(), _vm(vm) {} - - bool execute(bool type, bool townFlag); -public: - static bool show(XeenEngine *vm, bool type, bool townFlag = false); -}; - -} // End of namespace Xeen - -#endif /* XEEN_DIALOGS_YESNO_H */ diff --git a/engines/xeen/module.mk b/engines/xeen/module.mk index 25568523cd..6a36f91bf8 100644 --- a/engines/xeen/module.mk +++ b/engines/xeen/module.mk @@ -12,17 +12,16 @@ MODULE_OBJS := \ automap.o \ dialogs_automap.o \ dialogs_char_info.o \ - dialogs_confirm.o \ dialogs_error.o \ dialogs_exchange.o \ dialogs_options.o \ dialogs_info.o \ dialogs_input.o \ dialogs_items.o \ + dialogs_query.o \ dialogs_quick_ref.o \ dialogs_spells.o \ dialogs_whowill.o \ - dialogs_yesno.o \ events.o \ files.o \ font.o \ diff --git a/engines/xeen/resources.cpp b/engines/xeen/resources.cpp index 5cd09cf422..0f6588af9a 100644 --- a/engines/xeen/resources.cpp +++ b/engines/xeen/resources.cpp @@ -1144,4 +1144,6 @@ const char *const CANNOT_REMOVE_CURSED_ITEM = "\x3""You cannot remove a cursed i const char *const CANNOT_DISCARD_CURSED_ITEM = "\3x""cYou cannot discard a cursed item!"; +const char *const PERMANENTLY_DISCARD = "\v000\t000\x03lPermanently discard %s\fd?"; + } // End of namespace Xeen diff --git a/engines/xeen/resources.h b/engines/xeen/resources.h index 8be195f34e..87b9468064 100644 --- a/engines/xeen/resources.h +++ b/engines/xeen/resources.h @@ -418,6 +418,8 @@ extern const char *const CANNOT_REMOVE_CURSED_ITEM; extern const char *const CANNOT_DISCARD_CURSED_ITEM; +extern const char *const PERMANENTLY_DISCARD; + } // End of namespace Xeen #endif /* XEEN_RESOURCES_H */ diff --git a/engines/xeen/scripts.cpp b/engines/xeen/scripts.cpp index 12fe2f1257..4859e93405 100644 --- a/engines/xeen/scripts.cpp +++ b/engines/xeen/scripts.cpp @@ -23,7 +23,7 @@ #include "xeen/scripts.h" #include "xeen/dialogs_input.h" #include "xeen/dialogs_whowill.h" -#include "xeen/dialogs_yesno.h" +#include "xeen/dialogs_query.h" #include "xeen/party.h" #include "xeen/resources.h" #include "xeen/xeen.h" diff --git a/engines/xeen/town.cpp b/engines/xeen/town.cpp index 3df26859d4..3a07d2a9e0 100644 --- a/engines/xeen/town.cpp +++ b/engines/xeen/town.cpp @@ -23,7 +23,7 @@ #include "xeen/town.h" #include "xeen/dialogs_input.h" #include "xeen/dialogs_items.h" -#include "xeen/dialogs_yesno.h" +#include "xeen/dialogs_query.h" #include "xeen/dialogs_spells.h" #include "xeen/resources.h" #include "xeen/xeen.h" -- cgit v1.2.3