[Scummvm-git-logs] scummvm master -> 195b04c9cf5ba743a371db0c9685b9f96f4950dd

somaen noreply at scummvm.org
Thu May 26 20:29:56 UTC 2022


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

Summary:
10cce703dc TINSEL: Implement polygon-handling for Notebook
195b04c9cf TINSEL: Implement pointer handling for Notebook


Commit: 10cce703dcda251eef6af5ca550206a3c4bdff8a
    https://github.com/scummvm/scummvm/commit/10cce703dcda251eef6af5ca550206a3c4bdff8a
Author: Einar Johan Trøan Sømåen (einarjohants at gmail.com)
Date: 2022-05-26T22:29:22+02:00

Commit Message:
TINSEL: Implement polygon-handling for Notebook

Changed paths:
    engines/tinsel/noir/notebook.cpp
    engines/tinsel/noir/notebook.h
    engines/tinsel/polygons.cpp
    engines/tinsel/polygons.h


diff --git a/engines/tinsel/noir/notebook.cpp b/engines/tinsel/noir/notebook.cpp
index 43af61c59bb..1a030dc09bc 100644
--- a/engines/tinsel/noir/notebook.cpp
+++ b/engines/tinsel/noir/notebook.cpp
@@ -28,10 +28,19 @@
 #include "tinsel/multiobj.h"
 #include "tinsel/noir/sysreel.h"
 #include "tinsel/pdisplay.h"
+#include "tinsel/polygons.h"
 #include "tinsel/timers.h"
 
 namespace Tinsel {
 
+Notebook::Notebook() {
+	_polygons = instantiateNoteBookPolygons();
+}
+
+Notebook::~Notebook() {
+	delete _polygons;
+}
+
 void Notebook::AddHyperlink(int32 id1, int32 id2) {
 	auto *invObject = _vm->_dialogs->GetInvObjectT3(id1);
 
diff --git a/engines/tinsel/noir/notebook.h b/engines/tinsel/noir/notebook.h
index 6797ffad712..4b1f06f580a 100644
--- a/engines/tinsel/noir/notebook.h
+++ b/engines/tinsel/noir/notebook.h
@@ -54,11 +54,13 @@ enum class BOOKSTATE {
 	PAGEFLIP = 4
 };
 
+class NoteBookPolygons;
 class InventoryObjectT3;
 
 class Notebook {
 public:
-	Notebook() = default;
+	Notebook();
+	~Notebook();
 
 	// Adds a connection between a clue/title
 	void AddHyperlink(int32 id1, int32 id2);
@@ -76,6 +78,8 @@ public:
 	bool HandleEvent(PLR_EVENT pEvent, const Common::Point &coOrds);
 	void StepAnimScripts();
 	void Refresh();
+
+	NoteBookPolygons *_polygons = nullptr;
 private:
 	int AddTitle(const InventoryObjectT3 &invObject);
 	void AddClue(const InventoryObjectT3 &invObject);
diff --git a/engines/tinsel/polygons.cpp b/engines/tinsel/polygons.cpp
index 93bd2358372..c615e284adb 100644
--- a/engines/tinsel/polygons.cpp
+++ b/engines/tinsel/polygons.cpp
@@ -25,6 +25,7 @@
 #include "tinsel/pid.h"
 #include "tinsel/polygons.h"
 #include "tinsel/movers.h"
+#include "tinsel/noir/notebook.h"
 #include "tinsel/sched.h"
 #include "common/serializer.h"
 #include "tinsel/tinsel.h"
@@ -109,6 +110,10 @@ struct POLYGON {
 	 */
 	POLYGON *adjpaths[MAXADJ];
 
+	void setPoint(int index, const Common::Point &point) {
+		cx[index] = point.x;
+		cy[index] = point.y;
+	}
 	bool containsPoint(const Common::Point &point) const;
 };
 
@@ -2483,17 +2488,95 @@ void UpdateGroundPlane() {
 	//...
 }
 
+class NoteBookPolygonsImpl : public NoteBookPolygons {
+public:
+	NoteBookPolygonsImpl() {
+		setPolygon(NoteBookPoly::MAIN,
+				   Common::Point(220, 0),
+				   Common::Point(446, 0),
+				   Common::Point(553, 425),
+				   Common::Point(164, 410));
+	}
+
+	void setPolygon(NoteBookPoly polyKind, const Common::Point &c0, const Common::Point &c1, const Common::Point &c2, const Common::Point &c3) override {
+		POLYGON *poly = nullptr;
+		switch(polyKind) {
+		case NoteBookPoly::MAIN:
+			poly = &_main;
+			break;
+		case NoteBookPoly::NEXT:
+			poly = &_next;
+			break;
+		case NoteBookPoly::PREV:
+			poly = &_prev;
+			break;
+		default:
+			poly = _cluePoly + static_cast<int>(polyKind);
+			break;
+		}
+		poly->polyType = SHAPE;
+		poly->setPoint(0, c0);
+		poly->setPoint(1, c1);
+		poly->setPoint(2, c2);
+		poly->setPoint(3, c3);
+		FiddlyBit(poly);
+	}
+
+	void pushPolygon(const Common::Point &c0, const Common::Point &c1, const Common::Point &c2, const Common::Point &c3) override {
+		assert(_polyIndex < MAX_CLUE_POLYS);
+		setPolygon(static_cast<NoteBookPoly>(_polyIndex), c0, c1, c2, c3);
+		_polyIndex++;
+	}
+
+	bool isInsideNotebook(const Common::Point &point) const override {
+		return _main.containsPoint(point);
+	}
+
+	int lineHit(const Common::Point &point) const override {
+		for (int i = 0; i < MAX_CLUE_POLYS; i++) {
+			if (_cluePoly[i].containsPoint(point)) {
+				return i;
+			}
+		}
+		return -1;
+	}
+
+	NoteBookPoly mostSpecificHit(const Common::Point &point) const override {
+		auto line = lineHit(point);
+		if (line != -1) {
+			return static_cast<NoteBookPoly>(line);
+		}
+		if (_next.containsPoint(point)) {
+			return NoteBookPoly::NEXT;
+		} else if (_prev.containsPoint(point)) {
+			return NoteBookPoly::PREV;
+		} else if (_main.containsPoint(point)) {
+			return NoteBookPoly::MAIN;
+		}
+		return NoteBookPoly::NONE;
+	}
+private:
+	static const int MAX_CLUE_POLYS = 8;
+	int _polyIndex = 0;
+	POLYGON _main, _prev, _next;
+	POLYGON _cluePoly[MAX_CLUE_POLYS];
+};
+
+NoteBookPolygons *instantiateNoteBookPolygons() {
+	return new NoteBookPolygonsImpl;
+}
+
 // Notebook (Tinsel)
 void NotebookPolyEntry(Common::Point c0, Common::Point c1, Common::Point c2, Common::Point c3) {
-	warning("TODO: Finish implementation of NotebookPolyEntry(%d, %d, %d, %d, %d, %d, %d, %d)", c0.x, c0.y, c1.x, c1.y, c2.x, c2.y, c3.x, c3.y);
+	_vm->_notebook->_polygons->pushPolygon(c0, c1, c2, c3);
 }
 
 void NotebookPolyNextPage(Common::Point c0, Common::Point c1, Common::Point c2, Common::Point c3) {
-	warning("TODO: Finish implementation of NotebookPolyNextPage(%d, %d, %d, %d, %d, %d, %d, %d)", c0.x, c0.y, c1.x, c1.y, c2.x, c2.y, c3.x, c3.y);
+	_vm->_notebook->_polygons->setPolygon(NoteBookPoly::NEXT, c0, c1, c2, c3);
 }
 
 void NotebookPolyPrevPage(Common::Point c0, Common::Point c1, Common::Point c2, Common::Point c3) {
-	warning("TODO: Finish implementation of NotebookPolyPrevPage(%d, %d, %d, %d, %d, %d, %d, %d)", c0.x, c0.y, c1.x, c1.y, c2.x, c2.y, c3.x, c3.y);
+	_vm->_notebook->_polygons->setPolygon(NoteBookPoly::PREV, c0, c1, c2, c3);
 }
 
 } // End of namespace Tinsel
diff --git a/engines/tinsel/polygons.h b/engines/tinsel/polygons.h
index 31f5a1f8cb6..da767caf363 100644
--- a/engines/tinsel/polygons.h
+++ b/engines/tinsel/polygons.h
@@ -38,7 +38,7 @@ enum PTYPE {
 	// Extra polygon types from Tinsel v1
 	EXIT, EX_EXIT,
 	// Extra polygon types from Tinsel v3
-	SCALE, EX_SCALE
+	SCALE, EX_SCALE, SHAPE
 };
 
 // subtype
@@ -160,6 +160,34 @@ void NotebookPolyPrevPage(Common::Point c0, Common::Point c1, Common::Point c2,
 
 void UpdateGroundPlane();
 
+enum class NoteBookPoly {
+	CLUE_0 = 0,
+	CLUE_1 = 1,
+	CLUE_2 = 2,
+	CLUE_3 = 3,
+	CLUE_4 = 4,
+	CLUE_5 = 5,
+	CLUE_6 = 6,
+	CLUE_7 = 7,
+	MAIN,
+	NEXT,
+	PREV,
+	NONE
+};
+
+class NoteBookPolygons {
+public:
+	virtual ~NoteBookPolygons() {}
+	virtual void setPolygon(NoteBookPoly polyKind, const Common::Point &c0, const Common::Point &c1, const Common::Point &c2, const Common::Point &c3) = 0;
+	virtual void pushPolygon(const Common::Point &c0, const Common::Point &c1, const Common::Point &c2, const Common::Point &c3) = 0;
+
+	virtual NoteBookPoly mostSpecificHit(const Common::Point &point) const = 0;
+	virtual int lineHit(const Common::Point &point) const = 0;
+	virtual bool isInsideNotebook(const Common::Point &point) const = 0;
+};
+
+NoteBookPolygons *instantiateNoteBookPolygons();
+
 } // End of namespace Tinsel
 
 #endif		/* TINSEL_POLYGONS_H */


Commit: 195b04c9cf5ba743a371db0c9685b9f96f4950dd
    https://github.com/scummvm/scummvm/commit/195b04c9cf5ba743a371db0c9685b9f96f4950dd
Author: Einar Johan Trøan Sømåen (einarjohants at gmail.com)
Date: 2022-05-26T22:29:36+02:00

Commit Message:
TINSEL: Implement pointer handling for Notebook

Changed paths:
    engines/tinsel/dialogs.cpp
    engines/tinsel/dialogs.h
    engines/tinsel/noir/notebook.cpp
    engines/tinsel/noir/notebook.h
    engines/tinsel/noir/notebook_page.cpp
    engines/tinsel/noir/notebook_page.h


diff --git a/engines/tinsel/dialogs.cpp b/engines/tinsel/dialogs.cpp
index ffd11801a83..756d0b77678 100644
--- a/engines/tinsel/dialogs.cpp
+++ b/engines/tinsel/dialogs.cpp
@@ -2202,6 +2202,10 @@ void Dialogs::InvLabels(bool InBody, int aniX, int aniY) {
 	}
 }
 
+void Dialogs::InvPointEvent(const InventoryObject *invObj, int index) {
+	InvTinselEvent(invObj, POINTED, PLR_NOEVENT, index);
+}
+
 /**************************************************************************/
 /***/
 /**************************************************************************/
diff --git a/engines/tinsel/dialogs.h b/engines/tinsel/dialogs.h
index 018d51084be..b08e4b197f5 100644
--- a/engines/tinsel/dialogs.h
+++ b/engines/tinsel/dialogs.h
@@ -355,6 +355,7 @@ public:
 	void InvCursor(InvCursorFN fn, int CurX, int CurY);
 	const InventoryObject *GetInvObject(int id);
 	const InventoryObjectT3 *GetInvObjectT3(int id);
+	void InvPointEvent(const InventoryObject *invObj, int index);
 	bool UpdateString(const Common::KeyState &kbd);
 	bool InventoryIsActive() { return _inventoryState == ACTIVE_INV; }
 	bool IsMixingDeskControl() { return _invDragging == ID_MDCONT; }
diff --git a/engines/tinsel/noir/notebook.cpp b/engines/tinsel/noir/notebook.cpp
index 1a030dc09bc..2fe64ec9a93 100644
--- a/engines/tinsel/noir/notebook.cpp
+++ b/engines/tinsel/noir/notebook.cpp
@@ -243,11 +243,23 @@ void Notebook::StepAnimScripts() {
 	}
 }
 
+int Notebook::GetPointedClue(const Common::Point &point) const {
+	if (_currentPage == 0 || _currentPage > _numPages) {
+		return 0;
+	}
+	return _pages[_currentPage].GetClueForLine(_polygons->lineHit(point));
+}
+
 bool Notebook::HandlePointer(const Common::Point &point) {
 	if (!IsOpen()) {
 		return 0;
 	}
-	warning("TODO: Implement pointer handling");
+	auto inside  = _polygons->isInsideNotebook(point);
+	if (inside) {
+		auto hit = _polygons->lineHit(point);
+		_pages[_currentPage].HandlePointAtLine(hit);
+		return true; // We handled the pointer
+	}
 	return false;
 }
 
@@ -255,7 +267,36 @@ bool Notebook::HandleEvent(PLR_EVENT pEvent, const Common::Point &coOrds) {
 	if (!IsOpen()) { // TODO: Clicking outside should close the notebook
 		return false;
 	}
+	auto inside  = _polygons->isInsideNotebook(coOrds);
 	switch(pEvent) {
+	case PLR_ACTION:
+		if (inside) {
+			return true;
+		}
+		return false;
+	case PLR_LOOK:
+		if (inside) {
+			return true;
+		}
+		return false;
+	case PLR_WALKTO: {
+		// Handle clue-clicks
+		auto poly = _polygons->mostSpecificHit(coOrds);
+		switch (poly) {
+		case NoteBookPoly::NEXT:
+			HandleEvent(PLR_PGUP, coOrds);
+			return true;
+		case NoteBookPoly::PREV:
+			HandleEvent(PLR_PGDN, coOrds);
+			return true;
+		case NoteBookPoly::NONE:
+			HandleEvent(PLR_ESCAPE, coOrds);
+			return true;
+		default:
+			return true;
+		}
+	}
+
 	case PLR_ESCAPE:
 		Close();
 		return true;
diff --git a/engines/tinsel/noir/notebook.h b/engines/tinsel/noir/notebook.h
index 4b1f06f580a..445301980a6 100644
--- a/engines/tinsel/noir/notebook.h
+++ b/engines/tinsel/noir/notebook.h
@@ -87,6 +87,8 @@ private:
 
 	void PageFlip(bool up);
 
+	int32 GetPointedClue(const Common::Point &point) const;
+
 	void ClearNotebookPage();
 
 	void SetNextPage(int pageIndex);
diff --git a/engines/tinsel/noir/notebook_page.cpp b/engines/tinsel/noir/notebook_page.cpp
index 848f1866823..620088173c6 100644
--- a/engines/tinsel/noir/notebook_page.cpp
+++ b/engines/tinsel/noir/notebook_page.cpp
@@ -93,6 +93,15 @@ void NotebookLine::CrossOut() {
 	_crossedOut = true;
 }
 
+void NotebookPage::HandlePointAtLine(int line) {
+	auto objId = GetClueForLine(line);
+	if (objId != 0 && objId != _pointedClue) {
+		auto obj = _vm->_dialogs->GetInvObject(objId);
+		_vm->_dialogs->InvPointEvent(obj, -1);
+		_pointedClue = objId;
+	}
+}
+
 int NotebookPage::IndexOfClue(int id) const {
 	for (int i = 0; i < _numLines; i++) {
 		if (_lines[i]._id == id) {
@@ -140,6 +149,14 @@ void NotebookPage::Clear() {
 	for (int i = 0; i < _numLines; i++) {
 		_lines[i].Clear();
 	}
+	_pointedClue = -1;
+}
+
+int NotebookPage::GetClueForLine(int line) const {
+	if (line >= _numLines) {
+		return 0;
+	}
+	return _lines[line]._id;
 }
 
 } // End of namespace Tinsel
diff --git a/engines/tinsel/noir/notebook_page.h b/engines/tinsel/noir/notebook_page.h
index 17b5bfc80a4..1a1a01b3191 100644
--- a/engines/tinsel/noir/notebook_page.h
+++ b/engines/tinsel/noir/notebook_page.h
@@ -52,8 +52,13 @@ public:
 	int32 GetTitle() const;
 	void FillIn();
 	void Clear();
+	int GetPointedClue(const Common::Point &point) const;
+	int GetClueForLine(int line) const;
+	void HandlePointAtLine(int line);
 private:
 	int IndexOfClue(int id) const;
+
+	int _pointedClue = -1;
 	const static uint32 MAX_ENTRIES_PER_PAGE = 8;
 	NotebookLine _lines[MAX_ENTRIES_PER_PAGE] = {};
 	uint32 _numLines = 0;




More information about the Scummvm-git-logs mailing list