[Scummvm-git-logs] scummvm master -> 54b5771c1be6e9edfca2cde9a34dec3a7eabd83e

dreammaster paulfgilbert at gmail.com
Sun May 3 04:54:41 UTC 2020


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

Summary:
bfe395bbcf ULTIMA4: Shift mouse button -> interact to GameController
c5f6fb5f9a ULTIMA4: Adding title skipping from mouse clicks
54b5771c1b ULTIMA4: Allow intro menu options mouse clicks


Commit: bfe395bbcf0514b0f4b8d6ff1b61b9ae3917a955
    https://github.com/scummvm/scummvm/commit/bfe395bbcf0514b0f4b8d6ff1b61b9ae3917a955
Author: Paul Gilbert (dreammaster at scummvm.org)
Date: 2020-05-02T21:54:24-07:00

Commit Message:
ULTIMA4: Shift mouse button -> interact to GameController

Changed paths:
    engines/ultima/ultima4/controllers/controller.cpp
    engines/ultima/ultima4/controllers/controller.h
    engines/ultima/ultima4/controllers/game_controller.cpp
    engines/ultima/ultima4/controllers/game_controller.h
    engines/ultima/ultima4/events/event_handler.cpp


diff --git a/engines/ultima/ultima4/controllers/controller.cpp b/engines/ultima/ultima4/controllers/controller.cpp
index c42cfefecc..248eabaa89 100644
--- a/engines/ultima/ultima4/controllers/controller.cpp
+++ b/engines/ultima/ultima4/controllers/controller.cpp
@@ -42,6 +42,11 @@ bool Controller::notifyKeyPressed(int key) {
 	return processed;
 }
 
+bool Controller::notifyMousePress(const Common::Point &mousePos) {
+	return mousePressed(mousePos);
+}
+
+
 int Controller::getTimerInterval() {
 	return _timerInterval;
 }
diff --git a/engines/ultima/ultima4/controllers/controller.h b/engines/ultima/ultima4/controllers/controller.h
index b33de36928..96715872ac 100644
--- a/engines/ultima/ultima4/controllers/controller.h
+++ b/engines/ultima/ultima4/controllers/controller.h
@@ -50,6 +50,12 @@ public:
 	 */
 	bool notifyKeyPressed(int key);
 
+	/**
+	 * The event manager will call this method to notify that
+	 * the left button was clicked
+	 */
+	bool notifyMousePress(const Common::Point &mousePos);
+
 	int getTimerInterval();
 
 	/**
@@ -72,6 +78,13 @@ public:
 		return false;
 	}
 
+	/**
+	 * Mouse button was pressed
+	 */
+	virtual bool mousePressed(const Common::Point &mousePos) {
+		return false;
+	}
+
 	/**
 	 * Handles keybinder actions
 	 */
diff --git a/engines/ultima/ultima4/controllers/game_controller.cpp b/engines/ultima/ultima4/controllers/game_controller.cpp
index 0a8a1581cf..79e63f3f8c 100644
--- a/engines/ultima/ultima4/controllers/game_controller.cpp
+++ b/engines/ultima/ultima4/controllers/game_controller.cpp
@@ -343,11 +343,15 @@ void GameController::keybinder(KeybindingAction action) {
 	MetaEngine::executeAction(action);
 }
 
-bool GameController::keyPressed(int key) {
-	// Manually redraw the text prompt
-	g_screen->screenPrompt();
+bool GameController::mousePressed(const Common::Point &mousePos) {
+	const MouseArea *area = eventHandler->mouseAreaForPoint(mousePos.x, mousePos.y);
 
-	return KeyHandler::defaultHandler(key, nullptr);
+	if (area) {
+		keybinder(KEYBIND_INTERACT);
+		return true;
+	}
+
+	return false;
 }
 
 void GameController::initMoons() {
diff --git a/engines/ultima/ultima4/controllers/game_controller.h b/engines/ultima/ultima4/controllers/game_controller.h
index afc0571a13..12d889e465 100644
--- a/engines/ultima/ultima4/controllers/game_controller.h
+++ b/engines/ultima/ultima4/controllers/game_controller.h
@@ -122,10 +122,9 @@ public:
 	void keybinder(KeybindingAction action) override;
 
 	/**
-	 * The main key handler for the game.  Interpretes each key as a
-	 * command - 'a' for attack, 't' for talk, etc.
+	 * Mouse button was pressed
 	 */
-	bool keyPressed(int key) override;
+	bool mousePressed(const Common::Point &mousePos) override;
 
 	/**
 	 * This function is called every quarter second.
diff --git a/engines/ultima/ultima4/events/event_handler.cpp b/engines/ultima/ultima4/events/event_handler.cpp
index 6724cf0b24..b54931a47a 100644
--- a/engines/ultima/ultima4/events/event_handler.cpp
+++ b/engines/ultima/ultima4/events/event_handler.cpp
@@ -271,10 +271,15 @@ void EventHandler::handleMouseButtonDownEvent(const Common::Event &event, Contro
 		return;
 
 	if (event.type == Common::EVENT_LBUTTONDOWN) {
-		const MouseArea *area = eventHandler->mouseAreaForPoint(event.mouse.x, event.mouse.y);
-		if (!area)
-			return;
-		controller->keybinder(KEYBIND_INTERACT);
+		// handle the keypress
+		bool processed = controller->notifyMousePress(event.mouse);
+
+		if (processed) {
+			if (updateScreen)
+				(*updateScreen)();
+			g_screen->update();
+		}
+
 	} else if (event.type == Common::EVENT_RBUTTONDOWN) {
 		_isRightButtonDown = true;
 		handleMouseMotionEvent(event);


Commit: c5f6fb5f9a3ed24eb0b31c2290fd2748bfb5792a
    https://github.com/scummvm/scummvm/commit/c5f6fb5f9a3ed24eb0b31c2290fd2748bfb5792a
Author: Paul Gilbert (dreammaster at scummvm.org)
Date: 2020-05-02T21:54:24-07:00

Commit Message:
ULTIMA4: Adding title skipping from mouse clicks

Changed paths:
    engines/ultima/ultima4/controllers/controller.h
    engines/ultima/ultima4/controllers/intro_controller.cpp
    engines/ultima/ultima4/controllers/intro_controller.h


diff --git a/engines/ultima/ultima4/controllers/controller.h b/engines/ultima/ultima4/controllers/controller.h
index 96715872ac..bcbd141010 100644
--- a/engines/ultima/ultima4/controllers/controller.h
+++ b/engines/ultima/ultima4/controllers/controller.h
@@ -139,6 +139,16 @@ public:
 		Controller_startWait();
 		return getValue();
 	}
+
+	/**
+	 * Mouse button was pressed
+	 */
+	virtual bool mousePressed(const Common::Point &mousePos) {
+		// Treat mouse clicks as an abort
+		doneWaiting();
+		return true;
+	}
+
 };
 
 class TurnCompleter {
diff --git a/engines/ultima/ultima4/controllers/intro_controller.cpp b/engines/ultima/ultima4/controllers/intro_controller.cpp
index c51c5bc4f1..8b1bb81419 100644
--- a/engines/ultima/ultima4/controllers/intro_controller.cpp
+++ b/engines/ultima/ultima4/controllers/intro_controller.cpp
@@ -360,7 +360,6 @@ bool IntroController::keyPressed(int key) {
 	bool valid = true;
 
 	switch (_mode) {
-
 	case INTRO_TITLES:
 		// the user pressed a key to abort the sequence
 		skipTitles();
@@ -428,6 +427,25 @@ bool IntroController::keyPressed(int key) {
 	return valid || KeyHandler::defaultHandler(key, nullptr);
 }
 
+bool IntroController::mousePressed(const Common::Point &mousePos) {
+	switch (_mode) {
+	case INTRO_TITLES:
+		// Finish the title sequence
+		skipTitles();
+		break;
+
+	case INTRO_MAP:
+		_mode = INTRO_MENU;
+		updateScreen();
+		break;
+
+	default:
+		break;
+	}
+
+	return true;
+}
+
 void IntroController::drawMap() {
 	if (0 && _sleepCycles > 0) {
 		drawMapStatic();
diff --git a/engines/ultima/ultima4/controllers/intro_controller.h b/engines/ultima/ultima4/controllers/intro_controller.h
index 98e275a7d5..f3cdfde7f2 100644
--- a/engines/ultima/ultima4/controllers/intro_controller.h
+++ b/engines/ultima/ultima4/controllers/intro_controller.h
@@ -99,6 +99,12 @@ public:
 	 * Handles keystrokes during the introduction.
 	 */
 	bool keyPressed(int key);
+
+	/**
+	 * Mouse button was pressed
+	 */
+	bool mousePressed(const Common::Point &mousePos) override;
+
 	byte *getSigData();
 
 	/**


Commit: 54b5771c1be6e9edfca2cde9a34dec3a7eabd83e
    https://github.com/scummvm/scummvm/commit/54b5771c1be6e9edfca2cde9a34dec3a7eabd83e
Author: Paul Gilbert (dreammaster at scummvm.org)
Date: 2020-05-02T21:54:24-07:00

Commit Message:
ULTIMA4: Allow intro menu options mouse clicks

Changed paths:
    engines/ultima/ultima4/controllers/controller.h
    engines/ultima/ultima4/controllers/intro_controller.cpp
    engines/ultima/ultima4/controllers/intro_controller.h
    engines/ultima/ultima4/game/textview.cpp
    engines/ultima/ultima4/game/textview.h


diff --git a/engines/ultima/ultima4/controllers/controller.h b/engines/ultima/ultima4/controllers/controller.h
index bcbd141010..6b8d5927a2 100644
--- a/engines/ultima/ultima4/controllers/controller.h
+++ b/engines/ultima/ultima4/controllers/controller.h
@@ -146,9 +146,9 @@ public:
 	virtual bool mousePressed(const Common::Point &mousePos) {
 		// Treat mouse clicks as an abort
 		doneWaiting();
+		_value = _defaultValue;
 		return true;
 	}
-
 };
 
 class TurnCompleter {
diff --git a/engines/ultima/ultima4/controllers/intro_controller.cpp b/engines/ultima/ultima4/controllers/intro_controller.cpp
index 8b1bb81419..377e905ad0 100644
--- a/engines/ultima/ultima4/controllers/intro_controller.cpp
+++ b/engines/ultima/ultima4/controllers/intro_controller.cpp
@@ -366,6 +366,7 @@ bool IntroController::keyPressed(int key) {
 		break;
 
 	case INTRO_MAP:
+	case INTRO_ABOUT:
 		_mode = INTRO_MENU;
 		updateScreen();
 		break;
@@ -435,10 +436,17 @@ bool IntroController::mousePressed(const Common::Point &mousePos) {
 		break;
 
 	case INTRO_MAP:
+	case INTRO_ABOUT:
 		_mode = INTRO_MENU;
 		updateScreen();
 		break;
 
+	case INTRO_MENU: {
+		char key = _menuArea.getOptionAt(mousePos);
+		if (key)
+			keyPressed(key);
+	}
+
 	default:
 		break;
 	}
@@ -598,6 +606,7 @@ void IntroController::drawAbacusBeads(int row, int selectedVirtue, int rejectedV
 
 void IntroController::updateScreen() {
 	g_screen->screenHideCursor();
+	_menuArea.clearOptions();
 
 	switch (_mode) {
 	case INTRO_MAP:
@@ -629,11 +638,11 @@ void IntroController::updateScreen() {
 
 		_menuArea.textAt(1,  1, "In another world, in a time to come.");
 		_menuArea.textAt(14, 3, "Options:");
-		_menuArea.textAt(10, 5, "%s", _menuArea.colorizeString("Return to the view", FG_YELLOW, 0, 1).c_str());
-		_menuArea.textAt(10, 6, "%s", _menuArea.colorizeString("Journey Onward",     FG_YELLOW, 0, 1).c_str());
-		_menuArea.textAt(10, 7, "%s", _menuArea.colorizeString("Initiate New Game",  FG_YELLOW, 0, 1).c_str());
-		_menuArea.textAt(10, 8, "%s", _menuArea.colorizeString("Configure",          FG_YELLOW, 0, 1).c_str());
-		_menuArea.textAt(10, 9, "%s", _menuArea.colorizeString("About",              FG_YELLOW, 0, 1).c_str());
+		_menuArea.optionAt(10, 5, 'r', "%s", _menuArea.colorizeString("Return to the view", FG_YELLOW, 0, 1).c_str());
+		_menuArea.optionAt(10, 6, 'j', "%s", _menuArea.colorizeString("Journey Onward",     FG_YELLOW, 0, 1).c_str());
+		_menuArea.optionAt(10, 7, 'i', "%s", _menuArea.colorizeString("Initiate New Game",  FG_YELLOW, 0, 1).c_str());
+		_menuArea.optionAt(10, 8, 'c', "%s", _menuArea.colorizeString("Configure",          FG_YELLOW, 0, 1).c_str());
+		_menuArea.optionAt(10, 9, 'a', "%s", _menuArea.colorizeString("About",              FG_YELLOW, 0, 1).c_str());
 		drawBeasties();
 
 		// draw the cursor last
@@ -652,6 +661,7 @@ void IntroController::updateScreen() {
 void IntroController::initiateNewGame() {
 	// disable the screen cursor because a text cursor will now be used
 	g_screen->screenDisableCursor();
+	_menuArea.clear();
 
 	// draw the extended background for all option screens
 	_backgroundArea.draw(BKGD_INTRO);
@@ -837,11 +847,14 @@ void IntroController::startQuestions() {
 		U4IOS::switchU4IntroControllerToABButtons();
 #endif
 		// wait for an answer
-		eventHandler->pushController(&questionController);
-		int choice = questionController.waitFor();
+		int choice;
+		do {
+			eventHandler->pushController(&questionController);
+			choice = questionController.waitFor();
+		} while (!shouldQuit() && choice == -1);
 
 		// update the question tree
-		if (doQuestion(choice == 'a' ? 0 : 1)) {
+		if (shouldQuit() || doQuestion(choice == 'a' ? 0 : 1)) {
 			return;
 		}
 	}
@@ -898,10 +911,7 @@ void IntroController::about() {
 	_menuArea.textAt(1, 3, "Based on the xu4 project");
 	drawBeasties();
 
-	ReadChoiceController::get("");
-
-	g_screen->screenShowCursor();
-	updateScreen();
+	_mode = INTRO_ABOUT;
 }
 
 void IntroController::showText(const Common::String &text) {
diff --git a/engines/ultima/ultima4/controllers/intro_controller.h b/engines/ultima/ultima4/controllers/intro_controller.h
index f3cdfde7f2..570dbfdbdd 100644
--- a/engines/ultima/ultima4/controllers/intro_controller.h
+++ b/engines/ultima/ultima4/controllers/intro_controller.h
@@ -269,7 +269,8 @@ private:
 	enum {
 		INTRO_TITLES,                       // displaying the animated intro titles
 		INTRO_MAP,                          // displaying the animated intro map
-		INTRO_MENU                          // displaying the main menu: journey onward, etc.
+		INTRO_MENU,                         // displaying the main menu: journey onward, etc.
+		INTRO_ABOUT
 	} _mode;
 
 	enum MenuConstants {
diff --git a/engines/ultima/ultima4/game/textview.cpp b/engines/ultima/ultima4/game/textview.cpp
index edd2f0083c..845ec802eb 100644
--- a/engines/ultima/ultima4/game/textview.cpp
+++ b/engines/ultima/ultima4/game/textview.cpp
@@ -165,6 +165,16 @@ void TextView::setFontColorBG(ColorBG bg) {
 }
 
 void TextView::textAt(int x, int y, const char *fmt, ...) {
+	char buffer[1024];
+	va_list args;
+	va_start(args, fmt);
+	vsnprintf(buffer, sizeof(buffer), fmt, args);
+	va_end(args);
+
+	optionAt(x, y, '\0', "%s", buffer);
+}
+
+void TextView::optionAt(int x, int y, char key, const char *fmt, ...) {
 	char buffer[1024];
 	uint i;
 	uint offset = 0;
@@ -201,6 +211,17 @@ void TextView::textAt(int x, int y, const char *fmt, ...) {
 		setCursorPos(x + i, y, true);
 	if (reenableCursor)
 		enableCursor();
+
+	if (key) {
+		Common::Rect r(
+			SCALED(_x + (x * CHAR_WIDTH)),
+			SCALED(_y + (y * CHAR_HEIGHT)),
+			SCALED(_x + (x + strlen(buffer) - offset) * CHAR_WIDTH),
+			SCALED(_y + (y + 1) * CHAR_HEIGHT)
+		);
+
+		_options.push_back(Option(r, key));
+	}
 }
 
 void TextView::scroll() {
@@ -266,5 +287,18 @@ void TextView::cursorTimer(void *data) {
 	thiz->drawCursor();
 }
 
+char TextView::getOptionAt(const Common::Point &mousePos) {
+	for (uint idx = 0; idx < _options.size(); ++idx) {
+		if (_options[idx].contains(mousePos))
+			return _options[idx]._key;
+	}
+
+	return '\0';
+}
+
+void TextView::clearOptions() {
+	_options.clear();
+}
+
 } // End of namespace Ultima4
 } // End of namespace Ultima
diff --git a/engines/ultima/ultima4/game/textview.h b/engines/ultima/ultima4/game/textview.h
index 5649e976c7..0adcecb05b 100644
--- a/engines/ultima/ultima4/game/textview.h
+++ b/engines/ultima/ultima4/game/textview.h
@@ -25,6 +25,8 @@
 
 #include "ultima/ultima4/game/view.h"
 #include "ultima/ultima4/gfx/image.h"
+#include "common/array.h"
+#include "common/rect.h"
 
 namespace Ultima {
 namespace Ultima4 {
@@ -38,6 +40,19 @@ namespace Ultima4 {
  * A view of a text area.  Keeps track of the cursor position.
  */
 class TextView : public View {
+	struct Option : public Common::Rect {
+		char _key;
+		Option() : Common::Rect(), _key('\0') {}
+		Option(const Common::Rect &r, char key) : Common::Rect(r), _key(key) {}
+	};
+protected:
+	int _columns, _rows;         /**< size of the view in character cells  */
+	bool _cursorEnabled;         /**< whether the cursor is enabled */
+	bool _cursorFollowsText;     /**< whether the cursor is moved past the last character written */
+	int _cursorX, _cursorY;      /**< current position of cursor */
+	int _cursorPhase;            /**< the rotation state of the cursor */
+	static Image *_charset;      /**< image containing font */
+	Common::Array<Option> _options;
 public:
 	TextView(int x, int y, int columns, int rows);
 	virtual ~TextView();
@@ -69,7 +84,17 @@ public:
 	 * which the player is not an avatar.
 	 */
 	void drawCharMasked(int chr, int x, int y, byte mask);
-	void textAt(int x, int y, const char *fmt, ...) PRINTF_LIKE(4, 5);
+
+	/**
+	 * Draw text at the given position
+	 */
+	void textAt(int x, int y, const char *fmt, ...);
+
+	/**
+	 * Draw an option at
+	 */
+	void optionAt(int x, int y, char key, const char *fmt, ...);
+
 	void scroll();
 
 	void setCursorFollowsText(bool follows) {
@@ -102,13 +127,15 @@ public:
 	 */
 	Common::String colorizeString(Common::String input, ColorFG color, uint colorstart, uint colorlength = 0);
 
-protected:
-	int _columns, _rows;         /**< size of the view in character cells  */
-	bool _cursorEnabled;         /**< whether the cursor is enabled */
-	bool _cursorFollowsText;     /**< whether the cursor is moved past the last character written */
-	int _cursorX, _cursorY;      /**< current position of cursor */
-	int _cursorPhase;            /**< the rotation state of the cursor */
-	static Image *_charset;      /**< image containing font */
+	/**
+	 * Checks if a given position has an option
+	 */
+	char getOptionAt(const Common::Point &mousePos);
+
+	/**
+	 * Clear the options list
+	 */
+	void clearOptions();
 };
 
 } // End of namespace Ultima4




More information about the Scummvm-git-logs mailing list