diff options
author | Max Horn | 2011-03-21 12:53:50 +0100 |
---|---|---|
committer | Max Horn | 2011-03-21 12:53:50 +0100 |
commit | 458ebbafd25d729da88eced603a88af9a05b79b3 (patch) | |
tree | 71154725ddf20b7fdfd5ceb942d5fcd0d5d38fb1 /engines | |
parent | c064fa5c5bb0f0fd15342e27b047dadfcbf08d56 (diff) | |
download | scummvm-rg350-458ebbafd25d729da88eced603a88af9a05b79b3.tar.gz scummvm-rg350-458ebbafd25d729da88eced603a88af9a05b79b3.tar.bz2 scummvm-rg350-458ebbafd25d729da88eced603a88af9a05b79b3.zip |
HUGO: Split Utils::Box -> new funcs Utils::yesNoBox and Utils::promptBox
This also fixes a bug in the kBoxPrompt code (it returned a pointer to
the content of a temporary string object).
Diffstat (limited to 'engines')
-rw-r--r-- | engines/hugo/hugo.h | 2 | ||||
-rw-r--r-- | engines/hugo/parser.cpp | 2 | ||||
-rw-r--r-- | engines/hugo/parser_v1d.cpp | 2 | ||||
-rw-r--r-- | engines/hugo/parser_v1w.cpp | 2 | ||||
-rw-r--r-- | engines/hugo/parser_v2d.cpp | 2 | ||||
-rw-r--r-- | engines/hugo/parser_v3d.cpp | 2 | ||||
-rw-r--r-- | engines/hugo/schedule.cpp | 6 | ||||
-rw-r--r-- | engines/hugo/util.cpp | 60 | ||||
-rw-r--r-- | engines/hugo/util.h | 8 |
9 files changed, 49 insertions, 37 deletions
diff --git a/engines/hugo/hugo.h b/engines/hugo/hugo.h index a137df786f..a6a939f366 100644 --- a/engines/hugo/hugo.h +++ b/engines/hugo/hugo.h @@ -134,7 +134,7 @@ enum HugoRegistered { /** * Ways to dismiss a text/prompt box */ -enum box_t {kBoxAny, kBoxOk, kBoxPrompt, kBoxYesNo}; +enum box_t {kBoxAny, kBoxOk}; /** * Inventory icon bar states diff --git a/engines/hugo/parser.cpp b/engines/hugo/parser.cpp index a0a3ee3350..685cbc02fa 100644 --- a/engines/hugo/parser.cpp +++ b/engines/hugo/parser.cpp @@ -288,7 +288,7 @@ void Parser::keyHandler(Common::Event event) { _vm->_file->restoreGame(-1); break; case Common::KEYCODE_n: - if (Utils::Box(kBoxYesNo, "%s", "Are you sure you want to start a new game?") != 0) + if (Utils::yesNoBox("Are you sure you want to start a new game?")) _vm->_file->restoreGame(0); break; case Common::KEYCODE_s: diff --git a/engines/hugo/parser_v1d.cpp b/engines/hugo/parser_v1d.cpp index df3a73feb8..36b56a6521 100644 --- a/engines/hugo/parser_v1d.cpp +++ b/engines/hugo/parser_v1d.cpp @@ -364,7 +364,7 @@ void Parser_v1d::lineHandler() { } if (!strcmp("exit", _vm->_line) || strstr(_vm->_line, "quit")) { - if (Utils::Box(kBoxYesNo, "%s", _vm->_text->getTextParser(kTBExit_1d)) != 0) + if (Utils::yesNoBox(_vm->_text->getTextParser(kTBExit_1d))) _vm->endGame(); return; } diff --git a/engines/hugo/parser_v1w.cpp b/engines/hugo/parser_v1w.cpp index d3424274f8..3490c437aa 100644 --- a/engines/hugo/parser_v1w.cpp +++ b/engines/hugo/parser_v1w.cpp @@ -119,7 +119,7 @@ void Parser_v1w::lineHandler() { // Special meta commands // EXIT/QUIT if (!strcmp("exit", _vm->_line) || strstr(_vm->_line, "quit")) { - if (Utils::Box(kBoxYesNo, "%s", _vm->_text->getTextParser(kTBExit_1d)) != 0) + if (Utils::yesNoBox(_vm->_text->getTextParser(kTBExit_1d))) _vm->endGame(); return; } diff --git a/engines/hugo/parser_v2d.cpp b/engines/hugo/parser_v2d.cpp index d19b8b1091..50d2e5f493 100644 --- a/engines/hugo/parser_v2d.cpp +++ b/engines/hugo/parser_v2d.cpp @@ -114,7 +114,7 @@ void Parser_v2d::lineHandler() { } if (!strcmp("exit", _vm->_line) || strstr(_vm->_line, "quit")) { - if (Utils::Box(kBoxYesNo, "%s", _vm->_text->getTextParser(kTBExit_1d)) != 0) + if (Utils::yesNoBox(_vm->_text->getTextParser(kTBExit_1d))) _vm->endGame(); return; } diff --git a/engines/hugo/parser_v3d.cpp b/engines/hugo/parser_v3d.cpp index fcd937808b..88ff980d65 100644 --- a/engines/hugo/parser_v3d.cpp +++ b/engines/hugo/parser_v3d.cpp @@ -116,7 +116,7 @@ void Parser_v3d::lineHandler() { // Special meta commands // EXIT/QUIT if (!strcmp("exit", _vm->_line) || strstr(_vm->_line, "quit")) { - if (Utils::Box(kBoxYesNo, "%s", _vm->_text->getTextParser(kTBExit_1d)) != 0) + if (Utils::yesNoBox(_vm->_text->getTextParser(kTBExit_1d))) _vm->endGame(); return; } diff --git a/engines/hugo/schedule.cpp b/engines/hugo/schedule.cpp index 1556f3a154..48427c2a92 100644 --- a/engines/hugo/schedule.cpp +++ b/engines/hugo/schedule.cpp @@ -1379,7 +1379,7 @@ event_t *Scheduler::doAction(event_t *curEvent) { Utils::Box(kBoxAny, TAKE_TEXT, _vm->_text->getNoun(_vm->_object->_objects[action->a42.objIndex].nounIndex, TAKE_NAME)); break; case YESNO: // act43: Prompt user for Yes or No - if (Utils::Box(kBoxYesNo, "%s", _vm->_file->fetchString(action->a43.promptIndex)) != 0) + if (Utils::yesNoBox(_vm->_file->fetchString(action->a43.promptIndex))) insertActionList(action->a43.actYesIndex); else insertActionList(action->a43.actNoIndex); @@ -1529,7 +1529,7 @@ void Scheduler_v1d::runScheduler() { } void Scheduler_v1d::promptAction(act *action) { - Utils::Box(kBoxPrompt, "%s", _vm->_file->fetchString(action->a3.promptIndex)); + Utils::promptBox(_vm->_file->fetchString(action->a3.promptIndex)); warning("STUB: doAction(act3)"); // TODO: The answer of the player is not handled currently! Once it'll be read in the messageBox, uncomment this block @@ -1578,7 +1578,7 @@ const char *Scheduler_v2d::getCypher() const { } void Scheduler_v2d::promptAction(act *action) { - Utils::Box(kBoxPrompt, "%s", _vm->_file->fetchString(action->a3.promptIndex)); + Utils::promptBox(_vm->_file->fetchString(action->a3.promptIndex)); warning("STUB: doAction(act3), expecting answer %s", _vm->_file->fetchString(action->a3.responsePtr[0])); // TODO: The answer of the player is not handled currently! Once it'll be read in the messageBox, uncomment this block diff --git a/engines/hugo/util.cpp b/engines/hugo/util.cpp index f36c431867..88a3be8a75 100644 --- a/engines/hugo/util.cpp +++ b/engines/hugo/util.cpp @@ -41,10 +41,17 @@ namespace Hugo { +namespace Utils { + +enum { + kMaxStrLength = 1024 +}; + + /** * Returns index (0 to 7) of first 1 in supplied byte, or 8 if not found */ -int Utils::firstBit(byte data) { +int firstBit(byte data) { if (!data) return 8; @@ -60,7 +67,7 @@ int Utils::firstBit(byte data) { /** * Returns index (0 to 7) of last 1 in supplied byte, or 8 if not found */ -int Utils::lastBit(byte data) { +int lastBit(byte data) { if (!data) return 8; @@ -76,7 +83,7 @@ int Utils::lastBit(byte data) { /** * Reverse the bit order in supplied byte */ -void Utils::reverseByte(byte *data) { +void reverseByte(byte *data) { byte maskIn = 0x80; byte maskOut = 0x01; byte result = 0; @@ -89,18 +96,18 @@ void Utils::reverseByte(byte *data) { *data = result; } -const char *Utils::Box(box_t dismiss, const char *s, ...) { +void Box(box_t dismiss, const char *s, ...) { static char buffer[kMaxStrLength + 1]; // Format text into this if (!s) - return 0; // NULL strings catered for + return; // NULL strings catered for if (s[0] == '\0') - return 0; + return; if (strlen(s) > kMaxStrLength - 100) { // Test length warning("String too long: '%s'", s); - return 0; + return; } va_list marker; @@ -109,7 +116,7 @@ const char *Utils::Box(box_t dismiss, const char *s, ...) { va_end(marker); if (buffer[0] == '\0') - return 0; + return; switch(dismiss) { case kBoxAny: @@ -118,29 +125,30 @@ const char *Utils::Box(box_t dismiss, const char *s, ...) { dialog.runModal(); break; } - case kBoxYesNo: { - GUI::MessageDialog dialog(buffer, "YES", "NO"); - if (dialog.runModal() == GUI::kMessageOK) - return buffer; - return 0; - break; - } - case kBoxPrompt: { - EntryDialog dialog(buffer, "OK", ""); - Common::String result = dialog.getEditString(); - - return result.c_str(); - - break; - } default: error("Unknown BOX Type %d", dismiss); } - return 0; + return; +} + +Common::String promptBox(const char *msg) { + if (!msg || !*msg) + return 0; + + EntryDialog dialog(msg, "OK", ""); + return dialog.getEditString(); } -char *Utils::strlwr(char *buffer) { +bool yesNoBox(const char *msg) { + if (!msg || !*msg) + return 0; + + GUI::MessageDialog dialog(msg, "YES", "NO"); + return (dialog.runModal() == GUI::kMessageOK); +} + +char *strlwr(char *buffer) { char *result = buffer; while (*buffer != '\0') { @@ -152,4 +160,6 @@ char *Utils::strlwr(char *buffer) { return result; } +} // End of namespace Utils + } // End of namespace Hugo diff --git a/engines/hugo/util.h b/engines/hugo/util.h index acead5a0c4..12ec58ff86 100644 --- a/engines/hugo/util.h +++ b/engines/hugo/util.h @@ -40,16 +40,18 @@ enum seqTextUtil { }; namespace Utils { -static const int kMaxStrLength = 1024; int firstBit(byte data); int lastBit(byte data); void reverseByte(byte *data); -const char *Box(box_t, const char *, ...) GCC_PRINTF(2, 3); +void Box(box_t, const char *, ...) GCC_PRINTF(2, 3); +Common::String promptBox(const char *msg); +bool yesNoBox(const char *msg); char *strlwr(char *buffer); -} + +} // End of namespace Utils } // End of namespace Hugo |