[Scummvm-git-logs] scummvm master -> 761d1447090063f9906080e95c96dbdaf70ce78a

mduggan noreply at scummvm.org
Wed Jul 10 12:33:36 UTC 2024


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:
761d144709 DGDS: Keyboard navigation for dialogs


Commit: 761d1447090063f9906080e95c96dbdaf70ce78a
    https://github.com/scummvm/scummvm/commit/761d1447090063f9906080e95c96dbdaf70ce78a
Author: Matthew Duggan (mgithub at guarana.org)
Date: 2024-07-10T22:32:17+10:00

Commit Message:
DGDS: Keyboard navigation for dialogs

Changed paths:
    engines/dgds/dgds.cpp
    engines/dgds/dialog.cpp
    engines/dgds/menu.cpp
    engines/dgds/menu.h
    engines/dgds/scene.cpp
    engines/dgds/scene.h


diff --git a/engines/dgds/dgds.cpp b/engines/dgds/dgds.cpp
index d29f9982e6e..2d87a9b4796 100644
--- a/engines/dgds/dgds.cpp
+++ b/engines/dgds/dgds.cpp
@@ -418,10 +418,16 @@ Common::Error DgdsEngine::run() {
 					_clock.toggleVisibleUser();
 					break;
 				case kDgdsKeyNextChoice:
-					warning("TODO: Implement kDgdsKeyNextChoice");
+					if (_menu->menuShown())
+						_menu->nextChoice();
+					else if (_scene->hasVisibleDialog())
+						_scene->nextChoice();
 					break;
 				case kDgdsKeyPrevChoice:
-					warning("TODO: Implement kDgdsKeyPrevChoice");
+					if (_menu->menuShown())
+						_menu->prevChoice();
+					else if (_scene->hasVisibleDialog())
+						_scene->prevChoice();
 					break;
 				case kDgdsKeyNextItem:
 					warning("TODO: Implement kDgdsKeyNextItem");
diff --git a/engines/dgds/dialog.cpp b/engines/dgds/dialog.cpp
index bb82e283fd4..7ce84c7e11b 100644
--- a/engines/dgds/dialog.cpp
+++ b/engines/dgds/dialog.cpp
@@ -346,7 +346,7 @@ void Dialog::drawFindSelectionXY() {
 		if (hasFlag(kDlgFlagLeftJust)) {
 			x = x + (_state->_loc.width - maxWidth - 1) / 2;
 			_state->_lastMouseX = x;
-			y = y + (_state->_loc.height - (lines.size() * _state->_charHeight) - 1) / 2;
+			y = y + (_state->_loc.height - ((int)lines.size() * _state->_charHeight) - 1) / 2;
 			_state->_lastMouseY = y;
 		}
 
@@ -358,7 +358,7 @@ void Dialog::drawFindSelectionXY() {
 		for (uint lineno = 0; lineno < lines.size(); lineno++) {
 			// +1 char for the space or CR that caused the wrap.
 			int nexttotalchars = totalchars + lines[lineno].size() + 1;
-			if (nexttotalchars > _state->_strMouseLoc)
+			if (nexttotalchars >= _state->_strMouseLoc)
 				break;
 			totalchars = nexttotalchars;
 			y += _state->_charHeight;
@@ -439,8 +439,7 @@ void Dialog::drawFindSelectionTxtOffset() {
 		dlgy += lineHeight;
 	}
 
-	int startx = dlgx;
-	while (lineno < lines.size()) {
+	if (lineno < lines.size()) {
 		const Common::String &line = lines[lineno];
 		for (uint charno = 0; charno < line.size(); charno++) {
 			int charwidth = font->getCharWidth(line[charno]);
@@ -450,9 +449,10 @@ void Dialog::drawFindSelectionTxtOffset() {
 			}
 			dlgx += charwidth;
 		}
-		dlgx = startx;
+		// Mouse is off the end of the line
 		totalchars += line.size() + 1;
-		lineno++;
+		_state->_strMouseLoc = totalchars;
+		return;
 	}
 
 	_state->_strMouseLoc = _str.size();
@@ -537,14 +537,14 @@ void Dialog::clear() {
 }
 
 void Dialog::updateSelectedAction(int delta) {
-	if (!_lastDialogSelectionChangedFor)
-		_lastDialogSelectionChangedFor = this;
-	else
-		_lastSelectedDialogItemNum = 0;
-
 	if (!_state)
 		return;
 
+	if (_lastDialogSelectionChangedFor != this) {
+		_lastDialogSelectionChangedFor = this;
+		_lastSelectedDialogItemNum = 0;
+	}
+
 	if (_state->_selectedAction) {
 		for (uint i = 0; i < _action.size(); i++) {
 			if (_state->_selectedAction == &_action[i]) {
@@ -553,13 +553,13 @@ void Dialog::updateSelectedAction(int delta) {
 			}
 		}
 	}
+
 	_lastSelectedDialogItemNum += delta;
 	if (!_action.empty()) {
 		while (_lastSelectedDialogItemNum < 0)
 			_lastSelectedDialogItemNum += _action.size();
 		_lastSelectedDialogItemNum = _lastSelectedDialogItemNum % _action.size();
 	}
-	_lastDialogSelectionChangedFor = this;
 
 	int mouseX = _state->_loc.x + _state->_loc.width;
 	int mouseY = _state->_loc.y + _state->_loc.height - 2;
@@ -571,6 +571,7 @@ void Dialog::updateSelectedAction(int delta) {
 	}
 
 	if (_action.size() > 1 || !delta) {
+		debug("Dialog: update mouse to %d, %d (mouseloc %d, selnum %d)", mouseX, mouseY, _state->_strMouseLoc, _lastSelectedDialogItemNum);
 		g_system->warpMouse(mouseX, mouseY);
 	}
 }
diff --git a/engines/dgds/menu.cpp b/engines/dgds/menu.cpp
index 460664761b1..b402af9b0e8 100644
--- a/engines/dgds/menu.cpp
+++ b/engines/dgds/menu.cpp
@@ -548,4 +548,13 @@ void Menu::toggleGadget(int16 gadgetId, bool enable) {
 	}
 }
 
+void Menu::prevChoice() {
+	warning("TODO: Implement Menu::prevChoice");
+}
+
+void Menu::nextChoice() {
+	warning("TODO: Implement Menu::nextChoice");
+}
+
+
 } // End of namespace Dgds
diff --git a/engines/dgds/menu.h b/engines/dgds/menu.h
index 7e5b1962075..acb057b24f6 100644
--- a/engines/dgds/menu.h
+++ b/engines/dgds/menu.h
@@ -88,6 +88,8 @@ public:
 	void hideMenu() { _curMenu = kMenuNone; }
 
 	void setRequestData(const REQFileData &data);
+	void prevChoice();
+	void nextChoice();
 
 private:
 	Gadget *getClickedMenuItem(const Common::Point &mouseClick);
diff --git a/engines/dgds/scene.cpp b/engines/dgds/scene.cpp
index 292c694c91d..89dd0a59400 100644
--- a/engines/dgds/scene.cpp
+++ b/engines/dgds/scene.cpp
@@ -204,7 +204,7 @@ Common::String ObjectInteraction::dump(const Common::String &indent) const {
 
 
 Common::String SceneTrigger::dump(const Common::String &indent) const {
-	Common::String str = Common::String::format("%sSceneTrigger<num %d %s %d", indent.c_str(), _num, _enabled ? "enabled" : "disabled", _unk);
+	Common::String str = Common::String::format("%sSceneTrigger<num %d %s %d", indent.c_str(), _num, _enabled ? "enabled" : "disabled", _timesToCheckBeforeRunning);
 	str += _dumpStructList(indent, "conditionList", conditionList);
 	str += _dumpStructList(indent, "opList", sceneOpList);
 	str += "\n";
@@ -456,7 +456,7 @@ bool Scene::readTriggerList(Common::SeekableReadStream *s, Common::Array<SceneTr
 	for (uint16 i = 0; i < num; i++) {
 		list.push_back(SceneTrigger(s->readUint16LE()));
 		if (isVersionOver(" 1.219"))
-			list.back()._unk = s->readUint16LE();
+			list.back()._timesToCheckBeforeRunning = s->readUint16LE();
 		readConditionList(s, list.back().conditionList);
 		readOpList(s, list.back().sceneOpList);
 	}
@@ -1008,6 +1008,11 @@ void SDSScene::checkTriggers() {
 		if (!trigger._enabled)
 			continue;
 
+		if (trigger._timesToCheckBeforeRunning) {
+			trigger._timesToCheckBeforeRunning--;
+			continue;
+		}
+
 		if (!checkConditions(trigger.conditionList))
 			continue;
 
@@ -1793,6 +1798,21 @@ Common::Error SDSScene::syncState(Common::Serializer &s) {
 	return Common::kNoError;
 }
 
+void SDSScene::prevChoice() {
+	Dialog *dlg = getVisibleDialog();
+	if (!dlg)
+		return;
+	dlg->updateSelectedAction(-1);
+}
+
+void SDSScene::nextChoice() {
+	Dialog *dlg = getVisibleDialog();
+	if (!dlg)
+		return;
+	dlg->updateSelectedAction(1);
+}
+
+
 GDSScene::GDSScene() : _field38(0), _field3a(0), _field3c(0), _field3e(0), _field40(0) {
 }
 
diff --git a/engines/dgds/scene.h b/engines/dgds/scene.h
index 75665e1ab2a..9954ce56e1a 100644
--- a/engines/dgds/scene.h
+++ b/engines/dgds/scene.h
@@ -202,13 +202,13 @@ private:
 
 class SceneTrigger {
 public:
-	SceneTrigger(uint16 num) : _num(num), _enabled(false), _unk(0) {}
+	SceneTrigger(uint16 num) : _num(num), _enabled(false), _timesToCheckBeforeRunning(0) {}
 	Common::String dump(const Common::String &indent) const;
 
 	Common::Array<SceneConditions> conditionList;
 	Common::Array<SceneOp> sceneOpList;
 
-	uint16 _unk; // Only used in Beamish.
+	uint16 _timesToCheckBeforeRunning; // Only used in Beamish.
 	bool _enabled;
 	uint16 getNum() const { return _num; }
 
@@ -457,6 +457,8 @@ public:
 	void addAndShowTiredDialog();
 	void sceneOpUpdatePasscodeGlobal();
 
+	void prevChoice();
+	void nextChoice();
 
 protected:
 	HotArea *findAreaUnderMouse(const Common::Point &pt);




More information about the Scummvm-git-logs mailing list