[Scummvm-cvs-logs] scummvm master -> 550615f157a5a52932f0dc18757e00435b463b4e

sev- sev at scummvm.org
Sat Apr 16 14:09:40 CEST 2011


This automated email contains information about 1 new commit which have been
pushed to the 'scummvm' repo located at https://github.com/scummvm/scummvm .

Summary:
550615f157 HUGO: Implement prompt text box


Commit: 550615f157a5a52932f0dc18757e00435b463b4e
    https://github.com/scummvm/scummvm/commit/550615f157a5a52932f0dc18757e00435b463b4e
Author: Eugene Sandulenko (sev at scummvm.org)
Date: 2011-04-16T05:10:12-07:00

Commit Message:
HUGO: Implement prompt text box

Still it sometimes asserts with repeated dialog launches.

Changed paths:
    engines/hugo/dialogs.cpp
    engines/hugo/schedule.cpp
    engines/hugo/util.cpp



diff --git a/engines/hugo/dialogs.cpp b/engines/hugo/dialogs.cpp
index ead432c..0b08d48 100644
--- a/engines/hugo/dialogs.cpp
+++ b/engines/hugo/dialogs.cpp
@@ -26,6 +26,7 @@
 #include "common/substream.h"
 #include "graphics/imagedec.h"
 #include "gui/gui-manager.h"
+#include "gui/ThemeEval.h"
 
 #include "hugo/hugo.h"
 #include "hugo/display.h"
@@ -231,12 +232,52 @@ void TopMenu::handleMouseUp(int x, int y, int button, int clickCount) {
 }
 
 EntryDialog::EntryDialog(const Common::String &title, const Common::String &buttonLabel, const Common::String &defaultValue) : GUI::Dialog(20, 20, 100, 50) {
-	new GUI::StaticTextWidget(this, 0, 0, 10, 10, title, Graphics::kTextAlignCenter);
-	
-	_text = new GUI::EditTextWidget(this, 0, 0, 50, 10, "");
+	const int screenW = g_system->getOverlayWidth();
+	const int screenH = g_system->getOverlayHeight();
+
+	int buttonWidth = g_gui.xmlEval()->getVar("Globals.Button.Width", 0);
+	int buttonHeight = g_gui.xmlEval()->getVar("Globals.Button.Height", 0);
+
+	// First, determine the size the dialog needs. For this we have to break
+	// down the string into lines, and taking the maximum of their widths.
+	// Using this, and accounting for the space the button(s) need, we can set
+	// the real size of the dialog
+	Common::Array<Common::String> lines;
+	int lineCount, buttonPos;
+	int maxlineWidth = g_gui.getFont().wordWrapText(title, screenW - 2 * 30, lines);
+
+	// Calculate the desired dialog size (maxing out at 300*180 for now)
+	_w = MAX(maxlineWidth, buttonWidth) + 20;
+
+	lineCount = lines.size();
+
+	_h = 16 + buttonHeight + 8;
+
+	// Limit the number of lines so that the dialog still fits on the screen.
+	if (lineCount > (screenH - 20 - _h) / kLineHeight) {
+		lineCount = (screenH - 20 - _h) / kLineHeight;
+	}
+	_h += lineCount * kLineHeight;
+
+	// Center the dialog
+	_x = (screenW - _w) / 2;
+	_y = (screenH - _h) / 2;
+
+	// Each line is represented by one static text item.
+	for (int i = 0; i < lineCount; i++) {
+		new GUI::StaticTextWidget(this, 10, 10 + i * kLineHeight, maxlineWidth, kLineHeight,
+								lines[i], Graphics::kTextAlignCenter);
+	}
+
+	_text = new GUI::EditTextWidget(this, 10, 10 + lineCount * (kLineHeight + 1), _w - 20, kLineHeight, "");
 	_text->setEditString(defaultValue);
 
-	new GUI::ButtonWidget(this, 20, 20, 30, 10, buttonLabel, 0, kCmdButton);
+	_h += kLineHeight + 5;
+
+	buttonPos = (_w - buttonWidth) / 2;
+
+	new GUI::ButtonWidget(this, buttonPos, _h - buttonHeight - 8, buttonWidth, buttonHeight, buttonLabel, 0, kCmdButton, Common::ASCII_RETURN);	// Confirm dialog
+
 }
 
 EntryDialog::~EntryDialog() {
diff --git a/engines/hugo/schedule.cpp b/engines/hugo/schedule.cpp
index 45a2b77..6ce3ef2 100644
--- a/engines/hugo/schedule.cpp
+++ b/engines/hugo/schedule.cpp
@@ -1529,28 +1529,24 @@ void Scheduler_v1d::runScheduler() {
 }
 
 void Scheduler_v1d::promptAction(act *action) {
-	Utils::promptBox(_vm->_file->fetchString(action->a3.promptIndex));
+	Common::String response;
 
-	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
-#if 0
-	char response[256];
-	// TODO: Put user input in response
+	response = Utils::promptBox(_vm->_file->fetchString(action->a3.promptIndex));
+
+	response.toLowercase();
+
+	char resp[256];
+	strncpy(resp, response.c_str(), 256);
 
-	Utils::strlwr(response);
 	if (action->a3.encodedFl) {
 		warning("Encrypted flag set");
-		decodeString(response);
+		decodeString(resp);
 	}
 
-	if (strstr(response, _vm->_file->fetchString(action->a3.responsePtr[0]))
+	if (strstr(resp, _vm->_file->fetchString(action->a3.responsePtr[0])))
 		insertActionList(action->a3.actPassIndex);
 	else
 		insertActionList(action->a3.actFailIndex);
-#endif
-
-	// HACK: As the answer is not read, currently it's always considered correct
-	insertActionList(action->a3.actPassIndex);
 }
 
 /**
@@ -1578,19 +1574,22 @@ const char *Scheduler_v2d::getCypher() const {
 }
 
 void Scheduler_v2d::promptAction(act *action) {
-	Utils::promptBox(_vm->_file->fetchString(action->a3.promptIndex));
-	warning("STUB: doAction(act3), expecting answer %s", _vm->_file->fetchString(action->a3.responsePtr[0]));
+	Common::String response;
 
-	// TODO: The answer of the player is not handled currently! Once it'll be read in the messageBox, uncomment this block
-#if 0
-	char *response = Utils::Box(BOX_PROMPT, "%s", _vm->_file->fetchString(action->a3.promptIndex));
+	response = Utils::promptBox(_vm->_file->fetchString(action->a3.promptIndex));
+	response.toLowercase();
+
+	debug(1, "doAction(act3), expecting answer %s", _vm->_file->fetchString(action->a3.responsePtr[0]));
 
 	bool  found = false;
-	char *tmpStr;                                   // General purpose string ptr
+	const char *tmpStr;                                   // General purpose string ptr
+
+	char resp[256];
+	strncpy(resp, response.c_str(), 256);
 
-	for (dx = 0; !found && (action->a3.responsePtr[dx] != -1); dx++) {
+	for (int dx = 0; !found && (action->a3.responsePtr[dx] != -1); dx++) {
 		tmpStr = _vm->_file->fetchString(action->a3.responsePtr[dx]);
-		if (strstr(Utils::strlwr(response) , tmpStr))
+		if (strstr(Utils::strlwr(resp), tmpStr))
 			found = true;
 	}
 
@@ -1598,10 +1597,6 @@ void Scheduler_v2d::promptAction(act *action) {
 		insertActionList(action->a3.actPassIndex);
 	else
 		insertActionList(action->a3.actFailIndex);
-#endif
-
-	// HACK: As the answer is not read, currently it's always considered correct
-	insertActionList(action->a3.actPassIndex);
 }
 
 /**
diff --git a/engines/hugo/util.cpp b/engines/hugo/util.cpp
index 044b58e..6846bc9 100644
--- a/engines/hugo/util.cpp
+++ b/engines/hugo/util.cpp
@@ -104,6 +104,9 @@ Common::String promptBox(const Common::String &msg) {
 		return Common::String();
 
 	EntryDialog dialog(msg, "OK", "");
+
+	dialog.runModal();
+
 	return dialog.getEditString();
 }
 






More information about the Scummvm-git-logs mailing list