[Scummvm-git-logs] scummvm master -> ff5672d16cc36d004f7db2fc5e5e36f0838a8d6a

sev- noreply at scummvm.org
Sat Nov 28 13:18:48 UTC 2026


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

Summary:
8d906595e5 NGI: Bind Android walking movements to the scene motion graph
35241f18e8 NGI: Match Android walk graph link selection and projection
715f0da0fb NGI: Show and handle the Android intro skip buttons
886bf8917e NGI: Route Android scene controls through the GUI manager
a41b1ac7de NGI: Rename GUI manager source files
c92d013e79 NGI: Stub the remaining Android GUI widget tags
be1725cf47 NGI: Run Android scenes through the shared loader and frame loop
fab7eaf59a NGI: Select engine behavior by dated game revision
c3b10d7246 NGI: Restore Android room one state on entry
eb19973299 NGI: Dispatch room one tutorial skip through the inventory GUI
327f10c945 NGI: Resolve inventory cursor pictures and bound item removal
5eee8808aa NGI: Hit test XML objects and play motion graph walk queues
8a24e09cfd NGI: Resolve and place roaming XML animation copies on scene entry
ca8c21b6c5 NGI: Run room one exits and egg exchanges from XML interactions
507429913e NGI: Share localized game text loading between XML dialogs
fc214685fe NGI: Play the first-room tutorial and open its notebook task
ff5672d16c NGI: Furhter work on Scene01


Commit: 8d906595e598ccbb75ef861ecf39d725a87dbd1f
    https://github.com/scummvm/scummvm/commit/8d906595e598ccbb75ef861ecf39d725a87dbd1f
Author: Eugene Sandulenko (sev at scummvm.org)
Date: 2026-11-28T14:18:25+01:00

Commit Message:
NGI: Bind Android walking movements to the scene motion graph

Changed paths:
    engines/ngi/android.cpp
    engines/ngi/motion.cpp
    engines/ngi/motion.h
    engines/ngi/objects.h
    engines/ngi/statics.cpp
    engines/ngi/statics.h


diff --git a/engines/ngi/android.cpp b/engines/ngi/android.cpp
index 7ffdf974242..e919900a85c 100644
--- a/engines/ngi/android.cpp
+++ b/engines/ngi/android.cpp
@@ -81,8 +81,58 @@ bool ObjectIdList::findId(const Common::String &symbol, uint32 &id) const {
 	return true;
 }
 
+Common::String ObjectIdList::findName(uint32 id) const {
+	// CIDList searches its symbol table in name order when IDs have aliases.
+	Common::String name;
+	for (const auto &entry : _ids) {
+		if (entry._value == id && (name.empty() || entry._key < name))
+			name = entry._key;
+	}
+	return name;
+}
+
 namespace {
 
+class XMLWalkParser : public Common::XMLParser {
+public:
+	explicit XMLWalkParser(GameVar &walkData) : _walkData(walkData) {}
+
+private:
+	GameVar &_walkData;
+	GameVar *_object = nullptr;
+
+	CUSTOM_XML_PARSER(XMLWalkParser) {
+		XML_KEY(DATA)
+		KEY_END()
+	} PARSER_END()
+
+	bool parserCallback_DATA(ParserNode *) { return true; }
+
+	bool handleUnknownKey(ParserNode *node) override {
+		const ParserNode *parent = getParentNode(node);
+		if (!parent)
+			return false;
+		node->layout = parent->layout;
+		node->ignore = parent->ignore;
+		if (node->ignore || node->depth == 1)
+			return true;
+
+		if (node->depth == 2 && node->name == "Test_walk") {
+			_object = _walkData.addSubVarAsInt(parent->name, 0);
+			return _object != nullptr;
+		}
+		if (node->depth == 3 && parent->name == "Test_walk") {
+			GameVar *direction = _object->addSubVarAsInt(node->name, 0);
+			if (!direction)
+				return false;
+			for (const auto &attr : node->values)
+				direction->setSubVarAsInt(attr._key, atoi(attr._value.c_str()));
+		}
+		node->ignore = true;
+		return true;
+	}
+};
+
 class XMLProjectParser : public Common::XMLParser {
 public:
 	explicit XMLProjectParser(GameProject &project) : _project(project) {
@@ -983,6 +1033,10 @@ Common::Error NGIEngine::enterAndroidScene1() {
 		_currSoundList1[_currSoundListCount++] = common->_soundList.get();
 
 	_currentScene = room;
+	if (room->_motionController) {
+		room->_motionController->attachObject(_aniMan);
+		room->_motionController->activate();
+	}
 	addMessageHandlerByIndex(global_messageHandler4, 0, 4);
 	addMessageHandler(sceneHandler01, 2);
 	// CStateManager::SetStartStates starts a new game with the egg uncracked.
@@ -1033,6 +1087,11 @@ Common::Error NGIEngine::runAndroid() {
 	Scene *common = intro ? project.findScene(SC_COMMON) : nullptr;
 	if (intro && !common)
 		return Common::Error(Common::kNoGameDataFoundError, "Could not load the shared Full Pipe Android resources");
+	if (intro) {
+		XMLWalkParser walkParser(project._walkData);
+		if (!walkParser.loadFile("data/data.xml") || !walkParser.parse())
+			return Common::Error(Common::kNoGameDataFoundError, "Could not read the Full Pipe Android walking movements");
+	}
 
 	_isSaveAllowed = false;
 	initGraphics(parser.width(), parser.height(), nullptr);
diff --git a/engines/ngi/motion.cpp b/engines/ngi/motion.cpp
index f75074baf3e..13a8e180d3a 100644
--- a/engines/ngi/motion.cpp
+++ b/engines/ngi/motion.cpp
@@ -1683,21 +1683,22 @@ int MctlGraph::getObjIndex(int objectId) {
 	return -1;
 }
 
-int MctlGraph::getDirByStatics(int idx, int staticsId) {
-	for (int i = 0; i < 4; i++)
-		if (_aniData[idx]._directions[i]._prevStaticId == staticsId || _aniData[idx]._directions[i]._nextStaticId == staticsId)
+int MctlGraph::getDirByStatics(int idx, int staticsId, bool mirror) {
+	for (int i = 0; i < 4; i++) {
+		const MctlAniSub &dir = _aniData[idx]._directions[i];
+		if (dir._walk[0]._mirror == mirror && (dir._prevStaticId == staticsId || dir._nextStaticId == staticsId))
 			return i;
-
+	}
 	return -1;
 }
 
-int MctlGraph::getDirByMovement(int idx, int movId) {
-	for (int i = 0; i < 4; i++)
-		if (_aniData[idx]._directions[i]._walk[0]._movementId == movId
-		 || _aniData[idx]._directions[i]._walk[1]._movementId == movId
-		 || _aniData[idx]._directions[i]._walk[2]._movementId == movId)
-			return i;
-
+int MctlGraph::getDirByMovement(int idx, int movId, bool mirror) {
+	for (int i = 0; i < 4; i++) {
+		for (const MG2I &walk : _aniData[idx]._directions[i]._walk) {
+			if (walk._movementId == movId && walk._mirror == mirror)
+				return i;
+		}
+	}
 	return -1;
 }
 
@@ -1722,141 +1723,80 @@ int MctlGraph::getDirByPoint(int index, AniObject *ani) {
 	return -1;
 }
 
+bool MG2I::setMovement(AniObject *ani, int id, const ObjectIdList *ids) {
+	_mirror = false;
+	_deltaX = _deltaY = 0;
+	if (ids && id) {
+		const Common::String name = ids->findName(id);
+		if (name.hasPrefix("r")) {
+			uint32 baseId;
+			if (!ids->findId(name.substr(1), baseId))
+				return false;
+			id = baseId;
+			_mirror = true;
+		}
+	}
+	_movementId = ids ? static_cast<int16>(id) : id;
+	_movement = ani->getMovement(_movementId);
+	if (!_movement)
+		return !ids || !id;
+
+	if (ids) {
+		if (!_movement->getPhase(1))
+			return false;
+		_movement->getCenterDisplacement(_deltaX, _deltaY);
+		if (_mirror)
+			_deltaX = -_deltaX;
+	} else {
+		const Common::Point delta = _movement->getMovementSize(0, -1);
+		_deltaX = delta.x;
+		_deltaY = delta.y;
+	}
+	return true;
+}
+
 bool MctlGraph::fillData(AniObject *obj, GmctlAni &item) {
-	debugC(4, kDebugPathfinding, "MovGraph::fillData(%d, ...)", obj->_id);
+	debugC(4, kDebugPathfinding, "MctlGraph::fillData(%d, ...)", obj->_id);
 
 	item._ani = obj;
 	item._objectId = obj->_id;
 
-	GameVar *var = g_nmi->getGameLoaderGameVar()->getSubVarByName(obj->_title);
-	if (!var)
-		return false;
-
-	var = var->getSubVarByName("Test_walk");
-
-	if (!var)
+	const ObjectIdList *ids = nullptr;
+	GameVar *walkData;
+	if (g_nmi->getPlatform() == Common::kPlatformAndroid) {
+		ids = &g_nmi->_gameProject->_objectIds;
+		walkData = g_nmi->_gameProject->_walkData.getSubVarByName(ids->findName(static_cast<uint16>(obj->_id)));
+	} else {
+		GameVar *var = g_nmi->getGameLoaderGameVar()->getSubVarByName(obj->_title);
+		walkData = var ? var->getSubVarByName("Test_walk") : nullptr;
+	}
+	if (!walkData)
 		return false;
 
-	GameVar *varD = nullptr;
-	Common::Point point;
-
-	for (int dir = 0; dir < 4; dir++) {
-		switch (dir) {
-		case 0:
-			varD = var->getSubVarByName("Right");
-			break;
-		case 1:
-			varD = var->getSubVarByName("Left");
-			break;
-		case 2:
-			varD = var->getSubVarByName("Up");
-			break;
-		case 3:
-			varD = var->getSubVarByName("Down");
-			break;
-		default:
-			break;
-		}
-
-		if (!varD)
+	static const char *const directions[] = { "Right", "Left", "Up", "Down" };
+	static const char *const walk[] = { "Start", "Go", "Stop" };
+	static const char *const turn[] = { "TurnR", "TurnL", "TurnU", "TurnD" };
+	static const char *const turnS[] = { "TurnSR", "TurnSL", "TurnSU", "TurnSD" };
+	for (uint dir = 0; dir < ARRAYSIZE(directions); ++dir) {
+		GameVar *var = walkData->getSubVarByName(directions[dir]);
+		if (!var)
 			return false;
 
-		for (int act = 0; act < 3; act++) {
-			int idx = 0;
-
-			switch(act) {
-			case 0:
-				idx = varD->getSubVarAsInt("Start");
-				break;
-			case 1:
-				idx = varD->getSubVarAsInt("Go");
-				break;
-			case 2:
-				idx = varD->getSubVarAsInt("Stop");
-				break;
-			default:
-				break;
-			}
-
-			item._directions[dir]._walk[act]._movementId = idx;
-
-			Movement *mov = obj->getMovement(idx);
-
-			item._directions[dir]._walk[act]._movement = mov;
-			if (mov) {
-				point = mov->getMovementSize(0, -1);
-				item._directions[dir]._walk[act]._deltaX = point.x;
-				item._directions[dir]._walk[act]._deltaY = point.y;
-			}
-		}
-
-		for (int act = 0; act < 4; act++) {
-			int idx = 0;
-
-			switch(act) {
-			case 0:
-				idx = varD->getSubVarAsInt("TurnR");
-				break;
-			case 1:
-				idx = varD->getSubVarAsInt("TurnL");
-				break;
-			case 2:
-				idx = varD->getSubVarAsInt("TurnU");
-				break;
-			case 3:
-				idx = varD->getSubVarAsInt("TurnD");
-				break;
-			default:
-				break;
-			}
-
-			item._directions[dir]._turn[act]._movementId = idx;
-
-			Movement *mov = obj->getMovement(idx);
-
-			item._directions[dir]._turn[act]._movement = mov;
-			if (mov) {
-				point = mov->getMovementSize(0, -1);
-				item._directions[dir]._turn[act]._deltaX = point.x;
-				item._directions[dir]._turn[act]._deltaY = point.y;
-			}
+		MctlAniSub &data = item._directions[dir];
+		for (uint i = 0; i < ARRAYSIZE(walk); ++i) {
+			if (!data._walk[i].setMovement(obj, var->getSubVarAsInt(walk[i]), ids))
+				return false;
 		}
-
-		for (int act = 0; act < 4; act++) {
-			int idx = 0;
-
-			switch(act) {
-			case 0:
-				idx = varD->getSubVarAsInt("TurnSR");
-				break;
-			case 1:
-				idx = varD->getSubVarAsInt("TurnSL");
-				break;
-			case 2:
-				idx = varD->getSubVarAsInt("TurnSU");
-				break;
-			case 3:
-				idx = varD->getSubVarAsInt("TurnSD");
-				break;
-			default:
-				break;
-			}
-
-			item._directions[dir]._turnS[act]._movementId = idx;
-
-			Movement *mov = obj->getMovement(idx);
-
-			item._directions[dir]._turnS[act]._movement = mov;
-			if (mov) {
-				point = mov->getMovementSize(0, -1);
-				item._directions[dir]._turnS[act]._deltaX = point.x;
-				item._directions[dir]._turnS[act]._deltaY = point.y;
-			}
+		for (uint i = 0; i < ARRAYSIZE(turn); ++i) {
+			if (!data._turn[i].setMovement(obj, var->getSubVarAsInt(turn[i]), ids) ||
+					!data._turnS[i].setMovement(obj, var->getSubVarAsInt(turnS[i]), ids))
+				return false;
 		}
-
-		item._directions[dir]._prevStaticId = item._directions[dir]._walk[0]._movement->_prevStatic->_staticsId;
-		item._directions[dir]._nextStaticId = item._directions[dir]._walk[0]._movement->_nextStatic->_staticsId;
-
+		Movement *start = data._walk[0]._movement;
+		if (!start)
+			return false;
+		data._prevStaticId = start->_prevStatic->_staticsId;
+		data._nextStaticId = start->_nextStatic->_staticsId;
 	}
 	return true;
 }
@@ -2191,11 +2131,12 @@ MessageQueue *MctlGraph::makeQueue(AniObject *obj, int xpos, int ypos, int fuzzy
 	obj->getPicAniInfo(picAniInfo);
 
 	int idxsub;
+	const bool mirror = g_nmi->getPlatform() == Common::kPlatformAndroid && (obj->_flags & 8);
 
 	if (obj->_movement)
-		idxsub = getDirByMovement(idx, obj->_movement->_id);
+		idxsub = getDirByMovement(idx, obj->_movement->_id, mirror);
 	else
-		idxsub = getDirByStatics(idx, obj->_statics->_staticsId);
+		idxsub = getDirByStatics(idx, obj->_statics->_staticsId, mirror);
 
 	bool subMgm = false;
 
diff --git a/engines/ngi/motion.h b/engines/ngi/motion.h
index 923642e23e8..508b1e8b01a 100644
--- a/engines/ngi/motion.h
+++ b/engines/ngi/motion.h
@@ -326,12 +326,16 @@ public:
 };
 
 class Movement;
+class ObjectIdList;
 
 struct MG2I {
 	int _movementId;
 	Movement *_movement;
-	int _deltaX;
-	int _deltaY;
+	float _deltaX;
+	float _deltaY;
+	bool _mirror;
+
+	bool setMovement(AniObject *ani, int id, const ObjectIdList *ids);
 };
 
 struct MctlAniSub {
@@ -388,8 +392,8 @@ public:
 	MessageQueue *makeQueue(AniObject *subj, int xpos, int ypos, int fuzzyMatch, int staticsId) override;
 
 	int getObjIndex(int objectId);
-	int getDirByStatics(int index, int staticsId);
-	int getDirByMovement(int index, int movId);
+	int getDirByStatics(int index, int staticsId, bool mirror = false);
+	int getDirByMovement(int index, int movId, bool mirror = false);
 	int getDirByPoint(int idx, AniObject *ani);
 
 	int getDirBySize(MovGraphLink *lnk, int x, int y);
diff --git a/engines/ngi/objects.h b/engines/ngi/objects.h
index 7605fbb7f0a..b8bea5ffe05 100644
--- a/engines/ngi/objects.h
+++ b/engines/ngi/objects.h
@@ -36,26 +36,12 @@ class ObjectIdList {
 public:
 	bool load(const Common::Path &path);
 	bool findId(const Common::String &symbol, uint32 &id) const;
+	Common::String findName(uint32 id) const;
 
 private:
 	Common::HashMap<Common::String, uint32> _ids;
 };
 
-class GameProject : public CObject {
- public:
-	int _field_4;
-	Common::String _headerFilename;
-	Common::ScopedPtr<SceneTagList> _sceneTagList;
-	ObjectIdList _objectIds;
-	Common::HashMap<Common::Path, Common::Point, Common::Path::Hash> _textureSizes;
-	int _field_10;
-
- public:
-	GameProject();
-	bool load(MfcArchive &file) override;
-	Scene *findScene(int sceneId);
-};
-
 struct PicAniInfo {
 	uint32 type;
 	int16 objectId;
@@ -113,6 +99,22 @@ class GameVar : public CObject {
 	GameVar *getSubVarByIndex(int idx);
 };
 
+class GameProject : public CObject {
+ public:
+	int _field_4;
+	Common::String _headerFilename;
+	Common::ScopedPtr<SceneTagList> _sceneTagList;
+	ObjectIdList _objectIds;
+	GameVar _walkData;
+	Common::HashMap<Common::Path, Common::Point, Common::Path::Hash> _textureSizes;
+	int _field_10;
+
+ public:
+	GameProject();
+	bool load(MfcArchive &file) override;
+	Scene *findScene(int sceneId);
+};
+
 } // End of namespace NGI
 
 #endif /* NGI_OBJECTS_H */
diff --git a/engines/ngi/statics.cpp b/engines/ngi/statics.cpp
index c433807e60c..2c674efc877 100644
--- a/engines/ngi/statics.cpp
+++ b/engines/ngi/statics.cpp
@@ -1732,6 +1732,20 @@ Common::Point Movement::getMovementSize(int idx, int dynidx) {
 	return p;
 }
 
+void Movement::getCenterDisplacement(float &dx, float &dy) const {
+	// XML steps move texture origins. The Android motion graph measures center to center.
+	const Dims prev = _prevStatic->getDimensions();
+	const Dims next = _nextStatic->getDimensions();
+	dx = _prevStepX + (next.x - prev.x) * 0.5f;
+	dy = _prevStepY + (next.y - prev.y) * 0.5f;
+	// Starting the movement uses the previous step in place of frame zero's offset.
+	// The last offset in the engine's phase list is the step into the ending statics.
+	for (uint i = 1; i < _framePosOffsets.size(); ++i) {
+		dx += _framePosOffsets[i].x;
+		dy += _framePosOffsets[i].y;
+	}
+}
+
 void Movement::setAlpha(int alpha) {
 	if (_currMovement)
 		for (uint i = 0; i < _currMovement->_phases.size(); i++) {
diff --git a/engines/ngi/statics.h b/engines/ngi/statics.h
index 46abfe79e15..9ccb44242ca 100644
--- a/engines/ngi/statics.h
+++ b/engines/ngi/statics.h
@@ -154,6 +154,7 @@ class Movement : public GameObject {
 	Dims getPhaseSize(int phaseIndex) const;
 
 	Common::Point getMovementSize(int idx, int dynidx);
+	void getCenterDisplacement(float &dx, float &dy) const;
 
 	void initStatics(AniObject *ani);
 	void updateCurrDynamicPhase();


Commit: 35241f18e86a081a71c1e17608b752868b30bc4d
    https://github.com/scummvm/scummvm/commit/35241f18e86a081a71c1e17608b752868b30bc4d
Author: Eugene Sandulenko (sev at scummvm.org)
Date: 2026-11-28T14:18:25+01:00

Commit Message:
NGI: Match Android walk graph link selection and projection

Changed paths:
    engines/ngi/motion.cpp


diff --git a/engines/ngi/motion.cpp b/engines/ngi/motion.cpp
index 13a8e180d3a..2bd8159a46b 100644
--- a/engines/ngi/motion.cpp
+++ b/engines/ngi/motion.cpp
@@ -1353,12 +1353,28 @@ double MovGraph::putToLink(Common::Point *point, MovGraphLink *link, int fuzzyMa
 	double dist1y = (double)(n1y - point->y);
 	double dist2x = (double)(n2x - n1x);
 	double dist2y = (double)(n1y - n2y);
-	double dist1 = sqrt(dist1x * dist1x + dist1y * dist1y);
-	double dist2 = (dist2y * dist1y + dist2x * dist1x) / link->_length / dist1;
+	const bool android = g_nmi->getPlatform() == Common::kPlatformAndroid;
+	double length = link->_length;
+	double radiusSquared = dist1x * dist1x + dist1y * dist1y;
+	double dist1 = android ? sqrtf(radiusSquared) : sqrt(radiusSquared);
+	double dot = dist2y * dist1y + dist2x * dist1x;
+	if (android) {
+		// The XML length bounds the segment, but PutToLink normalizes by the node separation.
+		length = sqrtf(dist2x * dist2x + dist2y * dist2y);
+		dot = static_cast<float>(dot);
+		if (!length || !dist1)
+			return -1.0;
+	}
+	double dist2 = dot / length / dist1;
 	double distm = dist2 * dist1;
-	double res = sqrt(1.0 - dist2 * dist2) * dist1;
+	double sinSquared = 1.0 - dist2 * dist2;
+	double res = sqrt(android ? fabs(sinSquared) : sinSquared) * dist1;
+
+	// Android accepts the perpendicular through the source within one link length.
+	if (android && dist2 == 0.0 && res <= link->_length)
+		return 0.0;
 
-	if (dist2 <= 0.0 || distm >= link->_length) {
+	if (dist2 <= 0.0 || (android ? distm > link->_length : distm >= link->_length)) {
 		if (fuzzyMatch) {
 			if (dist2 > 0.0) {
 				if (distm >= link->_length) {
@@ -1373,8 +1389,8 @@ double MovGraph::putToLink(Common::Point *point, MovGraphLink *link, int fuzzyMa
 			return -1.0;
 		}
 	} else {
-		point->x = n1x + (int)((double)(n2x - n1x) * distm / link->_length);
-		point->y = n1y + (int)((double)(n2y - n1y) * distm / link->_length);
+		point->x = n1x + (int)((double)(n2x - n1x) * distm / length);
+		point->y = n1y + (int)((double)(n2y - n1y) * distm / length);
 	}
 
 	return res;
@@ -2640,6 +2656,7 @@ MovGraphLink *MctlGraph::getHitLink(int x, int y, int idx, int fuzzyMatch) {
 	debugC(4, kDebugPathfinding, "MctlGraph::getHitLink(...)");
 
 	Common::Point point;
+	const double tolerance = g_nmi->getPlatform() == Common::kPlatformAndroid ? 3.0 : 2.0;
 	MovGraphLink *res = nullptr;
 
 	for (LinkList::iterator i = _links.begin(); i != _links.end(); ++i) {
@@ -2652,7 +2669,7 @@ MovGraphLink *MctlGraph::getHitLink(int x, int y, int idx, int fuzzyMatch) {
 			point.y = y;
 			double dst = putToLink(&point, lnk, 0);
 
-			if (dst >= 0.0 && dst < 2.0)
+			if (dst >= 0.0 && dst < tolerance)
 				return lnk;
 		} else if (!(lnk->_flags & 0x20000000)) {
 			if (lnk->_movGraphReact->hitTest(x, y)) {
@@ -2675,7 +2692,8 @@ MovGraphLink *MctlGraph::getHitLink(int x, int y, int idx, int fuzzyMatch) {
 MovGraphLink *MctlGraph::getNearestLink(int x, int y) {
 	debugC(4, kDebugPathfinding, "MctlGraph::getNearestLink(...)");
 
-	double mindist = 1.0e20;
+	const bool android = g_nmi->getPlatform() == Common::kPlatformAndroid;
+	double mindist = android ? 70.0 : 1.0e20;
 	MovGraphLink *res = nullptr;
 
 	for (LinkList::iterator i = _links.begin(); i != _links.end(); ++i) {
@@ -2690,8 +2708,15 @@ MovGraphLink *MctlGraph::getNearestLink(int x, int y) {
 			double n2y = lnk->_graphDst->_y;
 			double n1dx = x - n1x;
 			double n1dy = n1y - y;
-			double dst1 = sqrt(n1dy * n1dy + n1dx * n1dx);
-			double coeff1 = ((n1y - n2y) * n1dy + (n2x - n1x) * n1dx) / lnk->_length / dst1;
+			double radiusSquared = n1dy * n1dy + n1dx * n1dx;
+			double dst1 = android ? sqrtf(radiusSquared) : sqrt(radiusSquared);
+			double dot = (n1y - n2y) * n1dy + (n2x - n1x) * n1dx;
+			if (android) {
+				dot = static_cast<float>(dot);
+				if (!dst1 || !lnk->_length)
+					continue;
+			}
+			double coeff1 = dot / lnk->_length / dst1;
 			double dst3 = coeff1 * dst1;
 			double dst2 = sqrt(1.0 - coeff1 * coeff1) * dst1;
 
@@ -2710,10 +2735,7 @@ MovGraphLink *MctlGraph::getNearestLink(int x, int y) {
 		}
 	}
 
-	if (mindist < 1.0e20)
-		return res;
-	else
-		return nullptr;
+	return res;
 }
 
 double MctlGraph::iterate(LinkOrNode *linkInfoSource, LinkOrNode *linkInfoDest, MovGraphLinkList *listObj) {


Commit: 715f0da0fbe9916cbf34d0d16c8017eec665f6c9
    https://github.com/scummvm/scummvm/commit/715f0da0fbe9916cbf34d0d16c8017eec665f6c9
Author: Eugene Sandulenko (sev at scummvm.org)
Date: 2026-11-28T14:18:25+01:00

Commit Message:
NGI: Show and handle the Android intro skip buttons

Changed paths:
    engines/ngi/android.cpp
    engines/ngi/fullpipe/sceneIntro.cpp
    engines/ngi/scene.h
    engines/ngi/scenes.h


diff --git a/engines/ngi/android.cpp b/engines/ngi/android.cpp
index e919900a85c..a54ae00afab 100644
--- a/engines/ngi/android.cpp
+++ b/engines/ngi/android.cpp
@@ -923,8 +923,20 @@ private:
 	}
 
 	bool handleUnknownKey(ParserNode *node) override {
-		if (!getParentNode(node))
+		const ParserNode *parent = getParentNode(node);
+		if (!parent)
 			return false;
+		if (node->depth == 2 && parent->name == "GUIMNGR" && node->name == "BUTTON" &&
+				((_scene._sceneId == SC_INTRO1 && node->values.getValOrDefault("id") == "BTN_SC_INTRO_SKIP_1") ||
+				 (_scene._sceneId == SC_INTRO2 && node->values.getValOrDefault("id") == "BTN_SC_INTRO_SKIP_2"))) {
+			IntroSkipButton &button = _scene._introSkip;
+			if (!readId(node->values["scene"], button.sceneId) || !readId(node->values["texture"], button.pictureId) ||
+					!readId(node->values["press"], button.pressSound))
+				return parserError("Unknown intro skip button resource");
+			button.bounds.top = atoi(node->values["y"].c_str());
+			button.visible = boolProperty(*node, "visible");
+			button.active = boolProperty(*node, "active");
+		}
 		// Scene nodes outside the supported object types are ignored for now.
 		node->ignore = true;
 		node->layout = _XMLkeys;
@@ -968,6 +980,8 @@ void Scene::drawAndroid(Graphics::ManagedSurface &target) const {
 			phase->blitTo(target, position - anchor, mirror);
 		}
 	}
+	if (_introSkip.visible && _introSkip.texture)
+		_introSkip.texture->blitTo(target, Common::Point(_introSkip.bounds.left, _introSkip.bounds.top));
 }
 
 const char *NGIEngine::getAndroidResourceLocale() const {
@@ -1088,6 +1102,20 @@ Common::Error NGIEngine::runAndroid() {
 	if (intro && !common)
 		return Common::Error(Common::kNoGameDataFoundError, "Could not load the shared Full Pipe Android resources");
 	if (intro) {
+		for (Scene *scene : { startScene, intro2 }) {
+			IntroSkipButton &button = scene->_introSkip;
+			if (!button.pictureId)
+				continue;
+			Scene *source = project.findScene(button.sceneId);
+			PictureObject *pic = source ? source->findPictureObjectById(button.pictureId, 0) : nullptr;
+			if (!pic)
+				return Common::Error(Common::kNoGameDataFoundError, "Missing Full Pipe intro skip button picture");
+			button.texture = pic->_picture;
+			const Dims size = button.texture->getDimensions();
+			button.bounds.right = parser.width();
+			button.bounds.left = button.bounds.right - size.x;
+			button.bounds.bottom = button.bounds.top + size.y;
+		}
 		XMLWalkParser walkParser(project._walkData);
 		if (!walkParser.loadFile("data/data.xml") || !walkParser.parse())
 			return Common::Error(Common::kNoGameDataFoundError, "Could not read the Full Pipe Android walking movements");
@@ -1148,6 +1176,23 @@ Common::Error NGIEngine::runAndroid() {
 					cmd._param = back ? kActionCloseDialog : 0;
 					_modalObject->handleMessage(&cmd);
 				}
+			} else if (intro && g_vars->sceneIntro_playing &&
+					(event.type == Common::EVENT_LBUTTONDOWN || event.type == Common::EVENT_LBUTTONUP)) {
+				const IntroSkipButton &button = _currentScene->_introSkip;
+				if (button.hit(event.mouse)) {
+					if (event.type == Common::EVENT_LBUTTONDOWN) {
+						playSound(button.pressSound, 0);
+					} else {
+						debugC(2, kDebugEvents, "Skipping Android intro from scene %d", _currentScene->_sceneId);
+						startScene->_introSkip.visible = intro2->_introSkip.visible = false;
+						startScene->_introSkip.active = intro2->_introSkip.active = false;
+						clearGlobalMessageQueueList1();
+						if (_currentScene->_soundList)
+							_currentScene->stopAllSounds();
+						stopAllSounds(Sound::kSpeech);
+						sceneIntro_end();
+					}
+				}
 			}
 		}
 		if (shouldQuit())
@@ -1184,7 +1229,7 @@ Common::Error NGIEngine::runAndroid() {
 			debugC(2, kDebugDrawing, "Switched Android scene from %d to %d", scene->_sceneId, _currentScene->_sceneId);
 			redraw = true;
 		}
-		if (!_modalObject && _currentScene->_sceneId == SC_INTRO1 && !g_vars->sceneIntro_playing) {
+		if (intro && !g_vars->sceneIntro_playing && !_modalObject && (_currentScene == startScene || _currentScene == intro2)) {
 			result = enterAndroidScene1();
 			if (result.getCode() != Common::kNoError)
 				break;
diff --git a/engines/ngi/fullpipe/sceneIntro.cpp b/engines/ngi/fullpipe/sceneIntro.cpp
index 8b32673b9d4..36e5e001f17 100644
--- a/engines/ngi/fullpipe/sceneIntro.cpp
+++ b/engines/ngi/fullpipe/sceneIntro.cpp
@@ -62,8 +62,10 @@ bool sceneIntro_updateAndroid(uint32 elapsed, byte &brightness) {
 		fader.update(elapsed);
 		const bool changed = brightness != fader.brightness();
 		brightness = fader.brightness();
-		if (!fader.active())
+		if (!fader.active()) {
+			g_nmi->_currentScene->_introSkip.visible = g_nmi->_currentScene->_introSkip.active = true;
 			runQueue(QU_INTR_STARTINTRO, 0);
+		}
 		return changed;
 	}
 
@@ -98,6 +100,12 @@ void sceneHandlerIntro_part2() {
 	runQueue(QU_IN2_DO, 0);
 }
 
+void sceneIntro_end() {
+	if (g_vars->sceneIntro_playing && g_nmi->getPlatform() == Common::kPlatformAndroid)
+		sceneChapter_show("CHAPTER_1");
+	g_vars->sceneIntro_playing = false;
+}
+
 int sceneHandlerIntro(Command *ex) {
 	if (ex->_cmd != 17)
 		return 0;
@@ -113,9 +121,7 @@ int sceneHandlerIntro(Command *ex) {
 
 	switch (ex->_messageNum) {
 	case MSG_INTR_ENDINTRO:
-		if (g_vars->sceneIntro_playing && g_nmi->getPlatform() == Common::kPlatformAndroid)
-			sceneChapter_show("CHAPTER_1");
-		g_vars->sceneIntro_playing = 0;
+		sceneIntro_end();
 		return 0;
 
 	case MSG_INTR_SWITCHTO1:
diff --git a/engines/ngi/scene.h b/engines/ngi/scene.h
index 8b03d82bfaa..0e8aec7594b 100644
--- a/engines/ngi/scene.h
+++ b/engines/ngi/scene.h
@@ -34,6 +34,18 @@ class GameProject;
 class BehaviorController;
 class MctlCompound;
 
+struct IntroSkipButton {
+	int16 sceneId = 0, pictureId = 0;
+	uint16 pressSound = 0;
+	Common::Rect bounds;
+	const Texture *texture = nullptr;
+	bool visible = false, active = false;
+
+	bool hit(const Common::Point &pos) const {
+		return visible && active && pos.x > bounds.left && pos.x < bounds.right && pos.y > bounds.top && pos.y < bounds.bottom;
+	}
+};
+
 class Scene : public Background {
  public:
 	/** list items are owned */
@@ -44,6 +56,7 @@ class Scene : public Background {
 	PicAniInfoList _roamingObjects;
 	Common::Array<Entrance> _entrances;
 	int16 _heroId = 0;
+	IntroSkipButton _introSkip;
 	Common::Array<MessageQueue *> _messageQueues;
 	// XML queue templates are cloned when run and can be shared between scenes.
 	Scene *_commonQueueScene = nullptr;
diff --git a/engines/ngi/scenes.h b/engines/ngi/scenes.h
index a40f58e1374..2fce4c16469 100644
--- a/engines/ngi/scenes.h
+++ b/engines/ngi/scenes.h
@@ -57,6 +57,7 @@ int sceneIntro_updateCursor();
 void sceneIntro_initScene(Scene *sc);
 void sceneIntro_initMan(Scene &scene);
 bool sceneIntro_updateAndroid(uint32 elapsed, byte &brightness);
+void sceneIntro_end();
 int sceneHandlerIntro(Command *cmd);
 
 int sceneIntroDemo_updateCursor();


Commit: 886bf8917e454c8c6aeadaf188b89e48e3d75e3d
    https://github.com/scummvm/scummvm/commit/886bf8917e454c8c6aeadaf188b89e48e3d75e3d
Author: Eugene Sandulenko (sev at scummvm.org)
Date: 2026-11-28T14:18:25+01:00

Commit Message:
NGI: Route Android scene controls through the GUI manager

Changed paths:
  A engines/ngi/gui.cpp
  A engines/ngi/gui.h
    engines/ngi/android.cpp
    engines/ngi/fullpipe/sceneIntro.cpp
    engines/ngi/module.mk
    engines/ngi/scene.cpp
    engines/ngi/scene.h
    engines/ngi/scenes.h


diff --git a/engines/ngi/android.cpp b/engines/ngi/android.cpp
index a54ae00afab..d8da866c451 100644
--- a/engines/ngi/android.cpp
+++ b/engines/ngi/android.cpp
@@ -305,6 +305,8 @@ private:
 			XML_PROP(putPrev, false)
 			XML_PROP(scrollX, false)
 			XML_PROP(scrollY, false)
+			XML_KEY(GUIMNGR)
+			KEY_END()
 			XML_KEY(MCTL_COMPOUND)
 				XML_KEY(MCTL_ITEM)
 					XML_PROP(ofsX, false)
@@ -521,6 +523,11 @@ private:
 		return atoi(node.values.getValOrDefault(key).c_str());
 	}
 
+	bool parserCallback_GUIMNGR(ParserNode *) {
+		_scene._guiManager.reset(new GuiManager(_scene));
+		return true;
+	}
+
 	bool parserCallback_MCTL_COMPOUND(ParserNode *) {
 		_scene._motionController.reset(new MctlCompound());
 		return true;
@@ -926,17 +933,8 @@ private:
 		const ParserNode *parent = getParentNode(node);
 		if (!parent)
 			return false;
-		if (node->depth == 2 && parent->name == "GUIMNGR" && node->name == "BUTTON" &&
-				((_scene._sceneId == SC_INTRO1 && node->values.getValOrDefault("id") == "BTN_SC_INTRO_SKIP_1") ||
-				 (_scene._sceneId == SC_INTRO2 && node->values.getValOrDefault("id") == "BTN_SC_INTRO_SKIP_2"))) {
-			IntroSkipButton &button = _scene._introSkip;
-			if (!readId(node->values["scene"], button.sceneId) || !readId(node->values["texture"], button.pictureId) ||
-					!readId(node->values["press"], button.pressSound))
-				return parserError("Unknown intro skip button resource");
-			button.bounds.top = atoi(node->values["y"].c_str());
-			button.visible = boolProperty(*node, "visible");
-			button.active = boolProperty(*node, "active");
-		}
+		if (node->depth == 2 && parent->name == "GUIMNGR" && _scene._guiManager)
+			_scene._guiManager->createElement(node->name, node->values, _project._objectIds);
 		// Scene nodes outside the supported object types are ignored for now.
 		node->ignore = true;
 		node->layout = _XMLkeys;
@@ -980,8 +978,8 @@ void Scene::drawAndroid(Graphics::ManagedSurface &target) const {
 			phase->blitTo(target, position - anchor, mirror);
 		}
 	}
-	if (_introSkip.visible && _introSkip.texture)
-		_introSkip.texture->blitTo(target, Common::Point(_introSkip.bounds.left, _introSkip.bounds.top));
+	if (_guiManager)
+		_guiManager->render(target);
 }
 
 const char *NGIEngine::getAndroidResourceLocale() const {
@@ -1046,6 +1044,8 @@ Common::Error NGIEngine::enterAndroidScene1() {
 	if (common->_soundList)
 		_currSoundList1[_currSoundListCount++] = common->_soundList.get();
 
+	if (_currentScene && _currentScene->_guiManager)
+		_currentScene->_guiManager->onHide();
 	_currentScene = room;
 	if (room->_motionController) {
 		room->_motionController->attachObject(_aniMan);
@@ -1102,20 +1102,6 @@ Common::Error NGIEngine::runAndroid() {
 	if (intro && !common)
 		return Common::Error(Common::kNoGameDataFoundError, "Could not load the shared Full Pipe Android resources");
 	if (intro) {
-		for (Scene *scene : { startScene, intro2 }) {
-			IntroSkipButton &button = scene->_introSkip;
-			if (!button.pictureId)
-				continue;
-			Scene *source = project.findScene(button.sceneId);
-			PictureObject *pic = source ? source->findPictureObjectById(button.pictureId, 0) : nullptr;
-			if (!pic)
-				return Common::Error(Common::kNoGameDataFoundError, "Missing Full Pipe intro skip button picture");
-			button.texture = pic->_picture;
-			const Dims size = button.texture->getDimensions();
-			button.bounds.right = parser.width();
-			button.bounds.left = button.bounds.right - size.x;
-			button.bounds.bottom = button.bounds.top + size.y;
-		}
 		XMLWalkParser walkParser(project._walkData);
 		if (!walkParser.loadFile("data/data.xml") || !walkParser.parse())
 			return Common::Error(Common::kNoGameDataFoundError, "Could not read the Full Pipe Android walking movements");
@@ -1136,6 +1122,7 @@ Common::Error NGIEngine::runAndroid() {
 		startScene->_behaviorController->onShow(*startScene);
 	addMessageHandlerByIndex(global_messageHandler4, 0, 4);
 	if (intro) {
+		sceneIntro_initGui(*startScene, *intro2, parser.width());
 		sceneIntro_initMan(*startScene);
 		addMessageHandler(sceneHandlerIntro, 2);
 	}
@@ -1162,6 +1149,7 @@ Common::Error NGIEngine::runAndroid() {
 	uint32 lastUpdate = _system->getMillis();
 	while (!shouldQuit()) {
 		bool screenChanged = false;
+		bool redraw = false;
 		while (eventManager->pollEvent(event)) {
 			if (event.type == Common::EVENT_SCREEN_CHANGED) {
 				screenChanged = true;
@@ -1176,22 +1164,35 @@ Common::Error NGIEngine::runAndroid() {
 					cmd._param = back ? kActionCloseDialog : 0;
 					_modalObject->handleMessage(&cmd);
 				}
-			} else if (intro && g_vars->sceneIntro_playing &&
-					(event.type == Common::EVENT_LBUTTONDOWN || event.type == Common::EVENT_LBUTTONUP)) {
-				const IntroSkipButton &button = _currentScene->_introSkip;
-				if (button.hit(event.mouse)) {
-					if (event.type == Common::EVENT_LBUTTONDOWN) {
-						playSound(button.pressSound, 0);
-					} else {
-						debugC(2, kDebugEvents, "Skipping Android intro from scene %d", _currentScene->_sceneId);
-						startScene->_introSkip.visible = intro2->_introSkip.visible = false;
-						startScene->_introSkip.active = intro2->_introSkip.active = false;
-						clearGlobalMessageQueueList1();
-						if (_currentScene->_soundList)
-							_currentScene->stopAllSounds();
-						stopAllSounds(Sound::kSpeech);
-						sceneIntro_end();
-					}
+			} else if (_currentScene->_guiManager) {
+				GuiManager &gui = *_currentScene->_guiManager;
+				switch (event.type) {
+				case Common::EVENT_KEYDOWN:
+					gui.onKeyDown(event.kbd.keycode);
+					if (event.kbd.ascii)
+						gui.onChar(event.kbd.ascii);
+					break;
+				case Common::EVENT_KEYUP:
+					gui.onKeyUp(event.kbd.keycode);
+					break;
+				case Common::EVENT_MOUSEMOVE:
+				case Common::EVENT_LBUTTONDOWN:
+				case Common::EVENT_LBUTTONUP:
+				case Common::EVENT_RBUTTONDOWN:
+				case Common::EVENT_RBUTTONUP:
+					gui.onMouseMove(event.mouse);
+					if (event.type == Common::EVENT_LBUTTONDOWN)
+						gui.onMouseLKeyDown(event.mouse);
+					else if (event.type == Common::EVENT_LBUTTONUP)
+						gui.onMouseLKeyUp(event.mouse);
+					else if (event.type == Common::EVENT_RBUTTONDOWN)
+						gui.onMouseRKeyDown(event.mouse);
+					else if (event.type == Common::EVENT_RBUTTONUP)
+						gui.onMouseRKeyUp(event.mouse);
+					redraw = true;
+					break;
+				default:
+					break;
 				}
 			}
 		}
@@ -1201,7 +1202,6 @@ Common::Error NGIEngine::runAndroid() {
 		const uint32 now = _system->getMillis();
 		const uint32 elapsed = now - lastUpdate;
 		lastUpdate = now;
-		bool redraw = false;
 		Scene *scene = _currentScene;
 		if (_modalObject) {
 			if (!_modalObject->init(elapsed))
@@ -1222,6 +1222,8 @@ Common::Error NGIEngine::runAndroid() {
 		}
 
 		if (scene != _currentScene) {
+			if (scene->_guiManager)
+				scene->_guiManager->onHide();
 			stopAllSounds(Sound::kSpeech);
 			stopAllSounds(Sound::kEffect);
 			if (_currentScene->_behaviorController)
diff --git a/engines/ngi/fullpipe/sceneIntro.cpp b/engines/ngi/fullpipe/sceneIntro.cpp
index 36e5e001f17..589d16a9c80 100644
--- a/engines/ngi/fullpipe/sceneIntro.cpp
+++ b/engines/ngi/fullpipe/sceneIntro.cpp
@@ -31,6 +31,36 @@
 
 namespace NGI {
 
+static GuiElement *skipButton(Scene &scene) {
+	return scene._guiManager ? scene._guiManager->getElement(scene._sceneId == SC_INTRO1 ? "BTN_SC_INTRO_SKIP_1" : "BTN_SC_INTRO_SKIP_2") : nullptr;
+}
+
+static void sceneIntro_onGuiEvent(Scene &scene, const Common::String &id, const Common::String &event) {
+	if (!g_vars->sceneIntro_playing || event != "unpress" || (id != "BTN_SC_INTRO_SKIP_1" && id != "BTN_SC_INTRO_SKIP_2"))
+		return;
+	debugC(2, kDebugEvents, "Skipping Android intro from scene %d", scene._sceneId);
+	for (int sceneId : {SC_INTRO1, SC_INTRO2}) {
+		if (GuiElement *button = skipButton(*g_nmi->findScene(sceneId)))
+			button->hideAndDeactivate();
+	}
+	clearGlobalMessageQueueList1();
+	if (scene._soundList)
+		scene.stopAllSounds();
+	g_nmi->stopAllSounds(Sound::kSpeech);
+	sceneIntro_end();
+}
+
+void sceneIntro_initGui(Scene &first, Scene &second, int width) {
+	first._guiEventHandler = second._guiEventHandler = sceneIntro_onGuiEvent;
+	GuiElement *button = skipButton(first);
+	if (!button)
+		return;
+	Common::Point pos(width - button->_size.x, button->_pos.y);
+	button->setPos(pos);
+	if (GuiElement *other = skipButton(second))
+		other->setPos(pos);
+}
+
 void sceneIntro_initMan(Scene &scene) {
 	g_vars->sceneIntro_aniin1man = scene.findAniObjectById(ANI_IN1MAN, -1);
 	g_vars->sceneIntro_needSleep = true;
@@ -63,7 +93,8 @@ bool sceneIntro_updateAndroid(uint32 elapsed, byte &brightness) {
 		const bool changed = brightness != fader.brightness();
 		brightness = fader.brightness();
 		if (!fader.active()) {
-			g_nmi->_currentScene->_introSkip.visible = g_nmi->_currentScene->_introSkip.active = true;
+			if (GuiElement *button = skipButton(*g_nmi->_currentScene))
+				button->showAndActivate();
 			runQueue(QU_INTR_STARTINTRO, 0);
 		}
 		return changed;
@@ -98,6 +129,10 @@ void sceneHandlerIntro_part1() {
 void sceneHandlerIntro_part2() {
 	g_nmi->_currentScene = g_nmi->findScene(SC_INTRO2);
 	runQueue(QU_IN2_DO, 0);
+	if (g_nmi->getPlatform() == Common::kPlatformAndroid) {
+		if (GuiElement *button = skipButton(*g_nmi->_currentScene))
+			button->showAndActivate();
+	}
 }
 
 void sceneIntro_end() {
diff --git a/engines/ngi/gui.cpp b/engines/ngi/gui.cpp
new file mode 100644
index 00000000000..a044585ceb2
--- /dev/null
+++ b/engines/ngi/gui.cpp
@@ -0,0 +1,354 @@
+/* ScummVM - Graphic Adventure Engine
+ *
+ * ScummVM is the legal property of its developers, whose names
+ * are too numerous to list here. Please refer to the COPYRIGHT
+ * file distributed with this source distribution.
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ *
+ */
+
+#include "ngi/gui.h"
+#include "ngi/ngi.h"
+#include "ngi/scene.h"
+
+namespace NGI {
+
+static int resourceId(const Common::StringMap &attrs, const char *key, const ObjectIdList &ids) {
+	uint32 id;
+	return ids.findId(attrs.getValOrDefault(key), id) ? static_cast<int16>(id) : 0;
+}
+
+static bool guiFlag(const Common::StringMap &attrs, const char *key, bool fallback) {
+	const Common::String value = attrs.getValOrDefault(key, fallback ? "1" : "0");
+	return value == "1" || value == "true" || value == "yes";
+}
+
+GuiElement::GuiElement(Scene &scene, const Common::StringMap &attrs, const ObjectIdList &ids) :
+		_scene(scene) {
+	_id = attrs.getValOrDefault("id", "error");
+	_pos = Common::Point(atoi(attrs.getValOrDefault("x").c_str()), atoi(attrs.getValOrDefault("y").c_str()));
+	_hasX = attrs.contains("x");
+	_hasY = attrs.contains("y");
+	_cursor = atoi(attrs.getValOrDefault("cursor", "1").c_str());
+	_z = atoi(attrs.getValOrDefault("z").c_str());
+	_active = guiFlag(attrs, "active", true);
+	_visible = guiFlag(attrs, "visible", false);
+	_scrolling = guiFlag(attrs, "scrolling", false);
+	_sourceScene = attrs.contains("scene") ? resourceId(attrs, "scene", ids) : scene._sceneId;
+	_pictureId = resourceId(attrs, "texture", ids);
+}
+
+void GuiElement::load(GameProject &project) {
+	Scene *source = project.findScene(_sourceScene);
+	_picture = source && _pictureId ? source->findPictureObjectById(_pictureId, 0) : nullptr;
+	if (_picture) {
+		if (!_hasX)
+			_pos.x = _picture->_x;
+		if (!_hasY)
+			_pos.y = _picture->_y;
+		_size = _picture->getFullSize();
+	}
+}
+
+Common::Point GuiElement::screenPos() const {
+	return _scrolling ? _pos - Common::Point(_scene._x, _scene._y) : _pos;
+}
+
+class GuiPicture : public GuiElement {
+public:
+	using GuiElement::GuiElement;
+	void render(Graphics::ManagedSurface &target) const override {
+		if (_visible && _picture)
+			_picture->_picture->blitTo(target, screenPos());
+	}
+};
+
+class GuiButton : public GuiElement {
+public:
+	GuiButton(Scene &scene, const Common::StringMap &attrs, const ObjectIdList &ids);
+	void load(GameProject &project) override;
+	void unload() override;
+	void activate() override;
+	void render(Graphics::ManagedSurface &target) const override;
+	bool hit(Common::Point pos) const override;
+	bool onMouseMove(Common::Point pos) override;
+	bool onMouseLKeyDown(Common::Point pos) override;
+	bool onMouseLKeyUp(Common::Point pos) override;
+
+private:
+	enum State { kDisabled, kPressed, kSelected, kNumStates };
+	int _pictureIds[kNumStates];
+	PictureObject *_pictures[kNumStates] = {};
+	Common::Point _offsets[kNumStates];
+	bool _useOffsets;
+	int _pressSound, _inactiveSound, _selectSound;
+};
+
+GuiButton::GuiButton(Scene &scene, const Common::StringMap &attrs, const ObjectIdList &ids) :
+		GuiElement(scene, attrs, ids) {
+	_pictureIds[kDisabled] = resourceId(attrs, "tex_disable", ids);
+	_pictureIds[kPressed] = resourceId(attrs, "tex_pressed", ids);
+	_pictureIds[kSelected] = resourceId(attrs, "tex_selected", ids);
+	_useOffsets = attrs.getValOrDefault("offset") != "0";
+	_pressSound = resourceId(attrs, "press", ids);
+	_inactiveSound = resourceId(attrs, "deactive_press", ids);
+	_selectSound = resourceId(attrs, "select", ids);
+}
+
+void GuiButton::load(GameProject &project) {
+	GuiElement::load(project);
+	Scene *source = project.findScene(_sourceScene);
+	PictureObject *first = _picture;
+	for (int i = 0; source && i < kNumStates; ++i) {
+		if (_pictureIds[i])
+			_pictures[i] = source->findPictureObjectById(_pictureIds[i], 0);
+		if (!first)
+			first = _pictures[i];
+	}
+	if (first) {
+		if (!_hasX)
+			_pos.x = first->_x;
+		if (!_hasY)
+			_pos.y = first->_y;
+		_size = first->getFullSize();
+	}
+	for (int i = kPressed; _useOffsets && i < kNumStates; ++i) {
+		if (_pictures[i])
+			_offsets[i] = Common::Point(_pictures[i]->_x, _pictures[i]->_y) - _pos;
+	}
+}
+
+void GuiButton::unload() {
+	GuiElement::unload();
+	for (PictureObject *&picture : _pictures)
+		picture = nullptr;
+}
+
+void GuiButton::activate() {
+	GuiElement::activate();
+	onMouseMove(g_system->getEventManager()->getMousePos());
+}
+
+void GuiButton::render(Graphics::ManagedSurface &target) const {
+	if (!_visible)
+		return;
+	int state = !_active ? kDisabled : _pressed ? kPressed : _selected ? kSelected : kNumStates;
+	if (state != kNumStates && _pictures[state])
+		_pictures[state]->_picture->blitTo(target, screenPos() + _offsets[state]);
+	else if (_picture)
+		_picture->_picture->blitTo(target, screenPos());
+}
+
+bool GuiButton::hit(Common::Point pos) const {
+	pos -= screenPos();
+	return _visible && pos.x > 0 && pos.y > 0 && pos.x < _size.x && pos.y < _size.y;
+}
+
+bool GuiButton::onMouseMove(Common::Point pos) {
+	bool inside = hit(pos);
+	if (inside != _selected) {
+		if (inside && _active && _selectSound)
+			g_nmi->playSound(_selectSound, 0);
+		const char *event = inside ? (_active ? "select" : "select_unactive") : (_active ? "deselect" : "deselect_unactive");
+		_scene.onGuiEvent(_id, event);
+		_selected = inside;
+	}
+	return inside && _active;
+}
+
+bool GuiButton::onMouseLKeyDown(Common::Point pos) {
+	if (!_visible || !_selected)
+		return false;
+	int sound = _active ? _pressSound : _inactiveSound;
+	if (sound)
+		g_nmi->playSound(sound, 0);
+	const bool handled = _active;
+	_scene.onGuiEvent(_id, handled ? "press" : "press_unactive");
+	if (handled)
+		_pressed = true;
+	return handled;
+}
+
+bool GuiButton::onMouseLKeyUp(Common::Point pos) {
+	bool handled = _visible && _selected && _active;
+	if (_visible && _selected) {
+		if (_active)
+			_selected = false;
+		_scene.onGuiEvent(_id, handled ? "unpress" : "unpress_unactive");
+	}
+	_pressed = false;
+	return handled;
+}
+
+GuiManager::~GuiManager() {
+	for (GuiElement *element : _renderables)
+		delete element;
+}
+
+void GuiManager::createElement(const Common::String &type, const Common::StringMap &attrs, const ObjectIdList &ids) {
+	if (type == "BUTTON")
+		addGuiElement(new GuiButton(_scene, attrs, ids));
+	else if (type == "PICTURE")
+		addGuiElement(new GuiPicture(_scene, attrs, ids));
+	else
+		debugC(2, kDebugXML, "GUI element %s (%s) not implemented", type.c_str(), attrs.getValOrDefault("id").c_str());
+}
+
+void GuiManager::addGuiElement(GuiElement *element) {
+	if (_elements.find(element->_id) == _elements.end())
+		_elements[element->_id] = element;
+	_renderables.push_back(element);
+}
+
+GuiElement *GuiManager::getElement(const Common::String &id) const {
+	auto it = _elements.find(id);
+	return it == _elements.end() ? nullptr : it->second;
+}
+
+void GuiManager::removeElement(GuiElement *element) {
+	_elements.erase(element->_id);
+	for (uint i = 0; i < _renderables.size(); ++i) {
+		if (_renderables[i] == element) {
+			_renderables.remove_at(i);
+			break;
+		}
+	}
+}
+
+void GuiManager::load(GameProject &project) {
+	for (const auto &entry : _elements)
+		entry.second->load(project);
+	sortRenderables();
+}
+
+void GuiManager::sortRenderables() {
+	// Equal z values retain their XML order.
+	for (uint i = 1; i < _renderables.size(); ++i) {
+		for (uint j = i; j && _renderables[j - 1]->_z < _renderables[j]->_z; --j)
+			SWAP(_renderables[j - 1], _renderables[j]);
+	}
+}
+
+void GuiManager::render(Graphics::ManagedSurface &target) {
+	sortRenderables();
+	for (GuiElement *element : _renderables)
+		element->render(target);
+}
+
+bool GuiManager::onMouseMove(Common::Point pos) {
+	for (uint i = _renderables.size(); i > 0; --i) {
+		if (_renderables[i - 1]->onMouseMove(pos)) {
+			while (--i)
+				_renderables[i - 1]->_selected = false;
+			return true;
+		}
+	}
+	return false;
+}
+
+bool GuiManager::dispatchMouse(MouseHandler handler, Common::Point pos) {
+	for (uint i = _renderables.size(); i > 0; --i) {
+		if ((_renderables[i - 1]->*handler)(pos))
+			return true;
+	}
+	return false;
+}
+
+bool GuiManager::onMouseLKeyDown(Common::Point pos) {
+	return dispatchMouse(&GuiElement::onMouseLKeyDown, pos);
+}
+
+bool GuiManager::onMouseLKeyUp(Common::Point pos) {
+	return dispatchMouse(&GuiElement::onMouseLKeyUp, pos);
+}
+
+bool GuiManager::onMouseRKeyDown(Common::Point pos) {
+	return dispatchMouse(&GuiElement::onMouseRKeyDown, pos);
+}
+
+bool GuiManager::onMouseRKeyUp(Common::Point pos) {
+	return dispatchMouse(&GuiElement::onMouseRKeyUp, pos);
+}
+
+void GuiManager::onKeyDown(Common::KeyCode key) {
+	for (const auto &entry : _elements)
+		entry.second->onKeyDown(key);
+}
+
+void GuiManager::onKeyUp(Common::KeyCode key) {
+	for (const auto &entry : _elements)
+		entry.second->onKeyUp(key);
+}
+
+void GuiManager::onChar(uint16 ch) {
+	for (const auto &entry : _elements)
+		entry.second->onChar(ch);
+}
+
+void GuiManager::unload() {
+	for (const auto &entry : _elements)
+		entry.second->unload();
+}
+
+bool GuiManager::update(uint32 elapsed) {
+	bool changed = false;
+	for (const auto &entry : _elements)
+		changed |= entry.second->update(elapsed);
+	return changed;
+}
+
+bool GuiManager::hit(Common::Point pos) const {
+	for (const auto &entry : _elements) {
+		if (entry.second->hit(pos))
+			return true;
+	}
+	return false;
+}
+
+int GuiManager::getCursorType(Common::Point pos) const {
+	int cursor = -1;
+	for (const auto &entry : _elements) {
+		const GuiElement &e = *entry.second;
+		if (e._visible && e._selected && e.hit(pos))
+			cursor = MAX(cursor, e._cursor);
+	}
+	return cursor;
+}
+
+bool GuiManager::isCursorObjectRender(Common::Point pos) const {
+	for (const auto &entry : _elements) {
+		const GuiElement &e = *entry.second;
+		if (e._visible && e._selected && e.hit(pos))
+			return false;
+	}
+	return true;
+}
+
+void GuiManager::deselectAll() {
+	for (const auto &entry : _elements)
+		entry.second->_selected = false;
+}
+
+void GuiManager::unpressAll() {
+	for (const auto &entry : _elements)
+		entry.second->_pressed = false;
+}
+
+void GuiManager::onHide() {
+	deselectAll();
+	unpressAll();
+}
+
+} // End of namespace NGI
diff --git a/engines/ngi/gui.h b/engines/ngi/gui.h
new file mode 100644
index 00000000000..3acd1f6ef26
--- /dev/null
+++ b/engines/ngi/gui.h
@@ -0,0 +1,113 @@
+/* ScummVM - Graphic Adventure Engine
+ *
+ * ScummVM is the legal property of its developers, whose names
+ * are too numerous to list here. Please refer to the COPYRIGHT
+ * file distributed with this source distribution.
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ *
+ */
+
+#ifndef NGI_GUI_H
+#define NGI_GUI_H
+
+#include "common/array.h"
+#include "common/events.h"
+#include "common/hash-str.h"
+#include "common/rect.h"
+#include "common/stablemap.h"
+
+namespace Graphics { class ManagedSurface; }
+
+namespace NGI {
+
+class Scene;
+class GameProject;
+class ObjectIdList;
+class PictureObject;
+
+class GuiElement {
+public:
+	GuiElement(Scene &scene, const Common::StringMap &attrs, const ObjectIdList &ids);
+	virtual ~GuiElement() {}
+	virtual void load(GameProject &project);
+	virtual void unload() { _picture = nullptr; }
+	virtual bool update(uint32 elapsed) { return false; }
+	virtual void onKeyDown(Common::KeyCode key) {}
+	virtual void onKeyUp(Common::KeyCode key) {}
+	virtual void onChar(uint16 ch) {}
+	virtual bool onMouseRKeyDown(Common::Point pos) { return false; }
+	virtual bool onMouseRKeyUp(Common::Point pos) { return false; }
+	virtual void render(Graphics::ManagedSurface &target) const = 0;
+	virtual bool hit(Common::Point pos) const { return false; }
+	virtual bool onMouseMove(Common::Point pos) { return false; }
+	virtual bool onMouseLKeyDown(Common::Point pos) { return false; }
+	virtual bool onMouseLKeyUp(Common::Point pos) { return false; }
+
+	virtual void activate() { _active = true; }
+	void showAndActivate() { _visible = true; activate(); }
+	void hideAndDeactivate() { _visible = _active = _selected = false; }
+	void setPos(Common::Point pos) { _pos = pos; }
+
+	Common::String _id;
+	Common::Point _pos, _size;
+	int _z, _cursor;
+	bool _active, _visible, _selected = false, _pressed = false;
+
+protected:
+	Scene &_scene;
+	bool _scrolling, _hasX, _hasY;
+	int _sourceScene, _pictureId;
+	PictureObject *_picture = nullptr;
+	Common::Point screenPos() const;
+};
+
+class GuiManager {
+public:
+	explicit GuiManager(Scene &scene) : _scene(scene) {}
+	~GuiManager();
+	void createElement(const Common::String &type, const Common::StringMap &attrs, const ObjectIdList &ids);
+	// Takes ownership until removeElement() or destruction.
+	void addGuiElement(GuiElement *element);
+	void removeElement(GuiElement *element);
+	GuiElement *getElement(const Common::String &id) const;
+	void load(GameProject &project);
+	void render(Graphics::ManagedSurface &target);
+	bool onMouseMove(Common::Point pos);
+	bool onMouseLKeyDown(Common::Point pos);
+	bool onMouseLKeyUp(Common::Point pos);
+	bool onMouseRKeyDown(Common::Point pos);
+	bool onMouseRKeyUp(Common::Point pos);
+	void onKeyDown(Common::KeyCode key);
+	void onKeyUp(Common::KeyCode key);
+	void onChar(uint16 ch);
+	bool update(uint32 elapsed);
+	void unload();
+	bool hit(Common::Point pos) const;
+	int getCursorType(Common::Point pos) const;
+	bool isCursorObjectRender(Common::Point pos) const;
+	void deselectAll();
+	void unpressAll();
+	void onHide();
+private:
+	Scene &_scene;
+	Common::Array<GuiElement *> _renderables;
+	Common::StableMap<Common::String, GuiElement *> _elements;
+	typedef bool (GuiElement::*MouseHandler)(Common::Point);
+	bool dispatchMouse(MouseHandler handler, Common::Point pos);
+	void sortRenderables();
+};
+
+} // End of namespace NGI
+#endif
diff --git a/engines/ngi/module.mk b/engines/ngi/module.mk
index cc897ee9e74..e422f768ea9 100644
--- a/engines/ngi/module.mk
+++ b/engines/ngi/module.mk
@@ -9,6 +9,7 @@ MODULE_OBJS = \
 	font.o \
 	gameloader.o \
 	gfx.o \
+	gui.o \
 	init.o \
 	input.o \
 	interaction.o \
diff --git a/engines/ngi/scene.cpp b/engines/ngi/scene.cpp
index 068b31a0805..4df8eb088be 100644
--- a/engines/ngi/scene.cpp
+++ b/engines/ngi/scene.cpp
@@ -45,10 +45,13 @@ Scene *GameProject::findScene(int sceneId) {
 		if (tag._sceneId != sceneId)
 			continue;
 		if (!tag._scene) {
-			if (g_nmi->getPlatform() == Common::kPlatformAndroid)
+			if (g_nmi->getPlatform() == Common::kPlatformAndroid) {
 				tag.loadSceneXML(*this);
-			else
+				if (tag._scene && tag._scene->_guiManager)
+					tag._scene->_guiManager->load(*this);
+			} else {
 				tag.loadScene();
+			}
 		}
 		return tag._scene;
 	}
@@ -112,7 +115,15 @@ void SceneTag::loadScene() {
 
 Scene::Scene() : _sceneId(0), _field_BC(0) {}
 
+void Scene::onGuiEvent(const Common::String &id, const Common::String &event) {
+	if (_guiEventHandler)
+		_guiEventHandler(*this, id, event);
+}
+
 Scene::~Scene() {
+	if (_guiManager)
+		_guiManager->unload();
+
 	// _faObjlist is not used
 
 	for (uint i = 0; i < _messageQueues.size(); i++)
@@ -653,7 +664,7 @@ int Scene::getPictureObjectIdAtPos(int x, int y) {
 bool Scene::update(int counterdiff) {
 	debugC(6, kDebugDrawing, "Scene::update(%d)", counterdiff);
 
-	bool changed = false;
+	bool changed = _guiManager && _guiManager->update(counterdiff);
 	for (uint i = 0; i < _renderableAnis.size(); i++)
 		changed |= _renderableAnis[i]->update(counterdiff);
 	return changed;
diff --git a/engines/ngi/scene.h b/engines/ngi/scene.h
index 0e8aec7594b..bc4e481b82d 100644
--- a/engines/ngi/scene.h
+++ b/engines/ngi/scene.h
@@ -25,6 +25,7 @@
 #include "common/ptr.h"
 #include "ngi/objects.h"
 #include "ngi/gfx.h"
+#include "ngi/gui.h"
 #include "ngi/interaction.h"
 
 namespace NGI {
@@ -34,18 +35,6 @@ class GameProject;
 class BehaviorController;
 class MctlCompound;
 
-struct IntroSkipButton {
-	int16 sceneId = 0, pictureId = 0;
-	uint16 pressSound = 0;
-	Common::Rect bounds;
-	const Texture *texture = nullptr;
-	bool visible = false, active = false;
-
-	bool hit(const Common::Point &pos) const {
-		return visible && active && pos.x > bounds.left && pos.x < bounds.right && pos.y > bounds.top && pos.y < bounds.bottom;
-	}
-};
-
 class Scene : public Background {
  public:
 	/** list items are owned */
@@ -56,7 +45,9 @@ class Scene : public Background {
 	PicAniInfoList _roamingObjects;
 	Common::Array<Entrance> _entrances;
 	int16 _heroId = 0;
-	IntroSkipButton _introSkip;
+	Common::ScopedPtr<GuiManager> _guiManager;
+	void (*_guiEventHandler)(Scene &, const Common::String &, const Common::String &) = nullptr;
+	void onGuiEvent(const Common::String &id, const Common::String &event);
 	Common::Array<MessageQueue *> _messageQueues;
 	// XML queue templates are cloned when run and can be shared between scenes.
 	Scene *_commonQueueScene = nullptr;
diff --git a/engines/ngi/scenes.h b/engines/ngi/scenes.h
index 2fce4c16469..e51ea0afda6 100644
--- a/engines/ngi/scenes.h
+++ b/engines/ngi/scenes.h
@@ -58,6 +58,7 @@ void sceneIntro_initScene(Scene *sc);
 void sceneIntro_initMan(Scene &scene);
 bool sceneIntro_updateAndroid(uint32 elapsed, byte &brightness);
 void sceneIntro_end();
+void sceneIntro_initGui(Scene &first, Scene &second, int width);
 int sceneHandlerIntro(Command *cmd);
 
 int sceneIntroDemo_updateCursor();


Commit: a41b1ac7ded9d1904704aecd5f32111340e0fe0f
    https://github.com/scummvm/scummvm/commit/a41b1ac7ded9d1904704aecd5f32111340e0fe0f
Author: Eugene Sandulenko (sev at scummvm.org)
Date: 2026-11-28T14:18:25+01:00

Commit Message:
NGI: Rename GUI manager source files

Changed paths:
  A engines/ngi/guimanager.cpp
  A engines/ngi/guimanager.h
  R engines/ngi/gui.cpp
  R engines/ngi/gui.h
    engines/ngi/module.mk
    engines/ngi/scene.h


diff --git a/engines/ngi/gui.cpp b/engines/ngi/guimanager.cpp
similarity index 99%
rename from engines/ngi/gui.cpp
rename to engines/ngi/guimanager.cpp
index a044585ceb2..a4c23dd3746 100644
--- a/engines/ngi/gui.cpp
+++ b/engines/ngi/guimanager.cpp
@@ -19,7 +19,7 @@
  *
  */
 
-#include "ngi/gui.h"
+#include "ngi/guimanager.h"
 #include "ngi/ngi.h"
 #include "ngi/scene.h"
 
diff --git a/engines/ngi/gui.h b/engines/ngi/guimanager.h
similarity index 98%
rename from engines/ngi/gui.h
rename to engines/ngi/guimanager.h
index 3acd1f6ef26..cd2bd2b62d1 100644
--- a/engines/ngi/gui.h
+++ b/engines/ngi/guimanager.h
@@ -19,8 +19,8 @@
  *
  */
 
-#ifndef NGI_GUI_H
-#define NGI_GUI_H
+#ifndef NGI_GUIMANAGER_H
+#define NGI_GUIMANAGER_H
 
 #include "common/array.h"
 #include "common/events.h"
diff --git a/engines/ngi/module.mk b/engines/ngi/module.mk
index e422f768ea9..af235e56df7 100644
--- a/engines/ngi/module.mk
+++ b/engines/ngi/module.mk
@@ -9,7 +9,7 @@ MODULE_OBJS = \
 	font.o \
 	gameloader.o \
 	gfx.o \
-	gui.o \
+	guimanager.o \
 	init.o \
 	input.o \
 	interaction.o \
diff --git a/engines/ngi/scene.h b/engines/ngi/scene.h
index bc4e481b82d..19a3e6850e2 100644
--- a/engines/ngi/scene.h
+++ b/engines/ngi/scene.h
@@ -25,7 +25,7 @@
 #include "common/ptr.h"
 #include "ngi/objects.h"
 #include "ngi/gfx.h"
-#include "ngi/gui.h"
+#include "ngi/guimanager.h"
 #include "ngi/interaction.h"
 
 namespace NGI {


Commit: c92d013e79a80a66cd28b88ec52609c544814930
    https://github.com/scummvm/scummvm/commit/c92d013e79a80a66cd28b88ec52609c544814930
Author: Eugene Sandulenko (sev at scummvm.org)
Date: 2026-11-28T14:18:25+01:00

Commit Message:
NGI: Stub the remaining Android GUI widget tags

Changed paths:
    engines/ngi/guimanager.cpp


diff --git a/engines/ngi/guimanager.cpp b/engines/ngi/guimanager.cpp
index a4c23dd3746..43515cda3f9 100644
--- a/engines/ngi/guimanager.cpp
+++ b/engines/ngi/guimanager.cpp
@@ -66,6 +66,13 @@ Common::Point GuiElement::screenPos() const {
 	return _scrolling ? _pos - Common::Point(_scene._x, _scene._y) : _pos;
 }
 
+class GuiElementStub : public GuiElement {
+public:
+	using GuiElement::GuiElement;
+	void load(GameProject &project) override {}
+	void render(Graphics::ManagedSurface &target) const override {}
+};
+
 class GuiPicture : public GuiElement {
 public:
 	using GuiElement::GuiElement;
@@ -202,7 +209,11 @@ void GuiManager::createElement(const Common::String &type, const Common::StringM
 		addGuiElement(new GuiButton(_scene, attrs, ids));
 	else if (type == "PICTURE")
 		addGuiElement(new GuiPicture(_scene, attrs, ids));
-	else
+	else if (type == "TEXT" || type == "TEXTBUTTON" || type == "SLIDER" ||
+			type == "CHECKBOX" || type == "PROGRESSBAR") {
+		warning("STUB: %s", type.c_str());
+		addGuiElement(new GuiElementStub(_scene, attrs, ids));
+	} else
 		debugC(2, kDebugXML, "GUI element %s (%s) not implemented", type.c_str(), attrs.getValOrDefault("id").c_str());
 }
 


Commit: be1725cf471d833c444365afd29e90ac738ec229
    https://github.com/scummvm/scummvm/commit/be1725cf471d833c444365afd29e90ac738ec229
Author: Eugene Sandulenko (sev at scummvm.org)
Date: 2026-11-28T14:18:25+01:00

Commit Message:
NGI: Run Android scenes through the shared loader and frame loop

Changed paths:
    engines/ngi/android.cpp
    engines/ngi/behavior.cpp
    engines/ngi/behavior.h
    engines/ngi/fullpipe/sceneChapter.cpp
    engines/ngi/fullpipe/sceneIntro.cpp
    engines/ngi/gameloader.cpp
    engines/ngi/gameloader.h
    engines/ngi/gfx.cpp
    engines/ngi/gfx.h
    engines/ngi/ngi.cpp
    engines/ngi/ngi.h
    engines/ngi/scene.cpp
    engines/ngi/scene.h
    engines/ngi/scenes.cpp
    engines/ngi/statics.cpp
    engines/ngi/statics.h


diff --git a/engines/ngi/android.cpp b/engines/ngi/android.cpp
index d8da866c451..6debdbbd5e8 100644
--- a/engines/ngi/android.cpp
+++ b/engines/ngi/android.cpp
@@ -19,31 +19,25 @@
  *
  */
 
-#include "common/algorithm.h"
 #include "common/archive.h"
 #include "common/compression/unzip.h"
 #include "common/config-manager.h"
 #include "common/debug-channels.h"
-#include "common/events.h"
 #include "common/file.h"
 #include "common/formats/xmlparser.h"
 
-#include "backends/keymapper/keymapper.h"
-#include "engines/util.h"
 #include "ngi/ngi.h"
+#include "ngi/gameloader.h"
 #include "ngi/behavior.h"
 #include "ngi/constants.h"
 #include "ngi/detection.h"
 #include "ngi/messages.h"
-#include "ngi/modal.h"
 #include "ngi/motion.h"
 #include "ngi/ngiarchive.h"
 #include "ngi/objects.h"
 #include "ngi/utils.h"
 #include "ngi/scene.h"
 #include "ngi/statics.h"
-#include "ngi/anihandler.h"
-#include "ngi/scenes.h"
 
 namespace NGI {
 
@@ -946,42 +940,6 @@ private:
 
 } // End of anonymous namespace
 
-void Scene::drawAndroid(Graphics::ManagedSurface &target) const {
-	Common::Array<const GameObject *> visibleObjects;
-	for (const PictureObject *picture : _pictureObjects) {
-		if (picture->_flags & 4)
-			visibleObjects.push_back(picture);
-	}
-	for (const AniObject *animation : _renderableAnis) {
-		if (animation->_flags & 4)
-			visibleObjects.push_back(animation);
-	}
-
-	// The Android renderer draws higher z values first and preserves XML order at equal z.
-	Common::sort(visibleObjects.begin(), visibleObjects.end(), [](const GameObject *left, const GameObject *right) {
-		if (left->_z == right->_z)
-			return left->_cnum < right->_cnum;
-		return left->_z > right->_z;
-	});
-
-	for (const GameObject *object : visibleObjects) {
-		Common::Point position(object->_x - _x, object->_y - _y);
-		if (object->_objtype == kObjTypePictureObject) {
-			static_cast<const PictureObject *>(object)->_picture->blitTo(target, position);
-		} else {
-			const AniObject &animation = *static_cast<const AniObject *>(object);
-			const Phase *phase = animation._movement ? animation._movement->_curPhase : animation._statics;
-			Common::Point anchor = animation.getSomeXY();
-			const bool mirror = (animation._flags & 8) != 0;
-			if (mirror)
-				anchor.x = phase->getDimensions().x - anchor.x;
-			phase->blitTo(target, position - anchor, mirror);
-		}
-	}
-	if (_guiManager)
-		_guiManager->render(target);
-}
-
 const char *NGIEngine::getAndroidResourceLocale() const {
 	Common::Language language = Common::parseLanguage(ConfMan.get("language"));
 	if (language == Common::UNK_LANG)
@@ -1013,59 +971,8 @@ void SceneTag::loadSceneXML(const GameProject &project) {
 	_scene = scene.release();
 }
 
-Common::Error NGIEngine::enterAndroidScene1() {
-	Scene *room = findScene(SC_1);
-	Scene *common = findScene(SC_COMMON);
-	if (!room || !common)
-		return Common::Error(Common::kNoGameDataFoundError, "Could not load the first Full Pipe Android room");
-	room->_commonQueueScene = common;
-	for (const PicAniInfo &ref : room->_roamingObjects) {
-		Scene *source = findScene(ref.sceneId);
-		AniObject *actor = source ? source->findAniObjectById(ref.objectId, ref.copyId) : nullptr;
-		if (!actor)
-			return Common::Error(Common::kNoGameDataFoundError, "Missing roaming animation for the first Android room");
-		if (!room->findAniObjectById(ref.objectId, ref.copyId))
-			room->_renderableAnis.push_back(actor);
-	}
-	_aniMan = room->findAniObjectById(room->_heroId, 0);
-	_aniMan2 = _aniMan;
-	if (!_aniMan)
-		return Common::Error(Common::kNoGameDataFoundError, "Missing hero for the first Android room");
-
-	clearGlobalMessageQueueList1();
-	clearMessageHandlers();
-	stopAllSounds(Sound::kSpeech);
-	stopAllSounds(Sound::kEffect);
-	if (room->_behaviorController)
-		room->_behaviorController->onShow(*room);
-	_currSoundListCount = 0;
-	if (room->_soundList)
-		_currSoundList1[_currSoundListCount++] = room->_soundList.get();
-	if (common->_soundList)
-		_currSoundList1[_currSoundListCount++] = common->_soundList.get();
-
-	if (_currentScene && _currentScene->_guiManager)
-		_currentScene->_guiManager->onHide();
-	_currentScene = room;
-	if (room->_motionController) {
-		room->_motionController->attachObject(_aniMan);
-		room->_motionController->activate();
-	}
-	addMessageHandlerByIndex(global_messageHandler4, 0, 4);
-	addMessageHandler(sceneHandler01, 2);
-	// CStateManager::SetStartStates starts a new game with the egg uncracked.
-	scene01_initObjects(room, TrubaLeft, true);
-	for (const Entrance &entrance : room->_entrances) {
-		if (entrance._id == TrubaLeft && entrance._sceneId == room->_sceneId && runQueue(entrance._queueId, 0)) {
-			debugC(1, kDebugSceneLogic, "Entered Android scene %d through entrance %d, queue %d", room->_sceneId, entrance._id, entrance._queueId);
-			return Common::kNoError;
-		}
-	}
-	return Common::Error(Common::kNoGameDataFoundError, "Could not start the TrubaLeft entrance queue");
-}
-
-Common::Error NGIEngine::runAndroid() {
-	const auto &files = _gameDescription->desc.filesDescriptions;
+Common::Error GameLoader::loadXML(const SceneTag *&start, int &width, int &height) {
+	const auto &files = g_nmi->_gameDescription->desc.filesDescriptions;
 	const Common::FSNode gameDirectory(ConfMan.getPath("path"));
 	Common::ScopedPtr<Common::Archive> apk(Common::makeZipArchive(gameDirectory.getChild(files[0].fileName)));
 	Common::ScopedPtr<Common::Archive> obb(Common::makeZipArchive(gameDirectory.getChild(files[1].fileName)));
@@ -1075,7 +982,8 @@ Common::Error NGIEngine::runAndroid() {
 	SearchMan.add("ngi-android-obb", obb.release());
 	SearchMan.add("ngi-android-apk", apk.release());
 
-	GameProject project;
+	_gameProject.reset(new GameProject());
+	GameProject &project = *_gameProject;
 	XMLTextureSizeParser(project).loadSizes();
 	if (!project._objectIds.load("data/obj.h"))
 		return Common::Error(Common::kNoGameDataFoundError, "Could not read the Full Pipe Android object IDs");
@@ -1085,188 +993,20 @@ Common::Error NGIEngine::runAndroid() {
 	if (!parser.loadStream(SearchMan.createReadStreamForMember(projectPath), projectPath.toString()) || !parser.parse())
 		return Common::Error(Common::kNoGameDataFoundError, "Could not read the Full Pipe Android project");
 
-	const SceneTag *start = parser.startScene();
+	start = parser.startScene();
 	if (!start)
 		return Common::Error(Common::kNoGameDataFoundError, "Could not find the Full Pipe Android start scene");
 	debugC(1, kDebugXML, "Loaded Full Pipe Android project, start scene %s (%hu)",
 		start->_tag.c_str(), static_cast<uint16>(start->_sceneId));
-	Scene *startScene = project.findScene(start->_sceneId);
-	if (!startScene)
-		return Common::Error(Common::kNoGameDataFoundError, "Could not load the Full Pipe Android start scene");
-
-	const bool intro = start->_sceneId == SC_INTRO1;
-	Scene *intro2 = intro ? project.findScene(SC_INTRO2) : nullptr;
-	if (intro && !intro2)
-		return Common::Error(Common::kNoGameDataFoundError, "Could not load the second Full Pipe Android intro scene");
-	Scene *common = intro ? project.findScene(SC_COMMON) : nullptr;
-	if (intro && !common)
-		return Common::Error(Common::kNoGameDataFoundError, "Could not load the shared Full Pipe Android resources");
-	if (intro) {
+	if (start->_sceneId == SC_INTRO1) {
 		XMLWalkParser walkParser(project._walkData);
 		if (!walkParser.loadFile("data/data.xml") || !walkParser.parse())
 			return Common::Error(Common::kNoGameDataFoundError, "Could not read the Full Pipe Android walking movements");
 	}
 
-	_isSaveAllowed = false;
-	initGraphics(parser.width(), parser.height(), nullptr);
-	const Graphics::PixelFormat format = _system->getScreenFormat();
-	if (format.isCLUT8())
-		return Common::kUnsupportedColorMode;
-
-	Common::Keymapper *mapper = _system->getEventManager()->getKeymapper();
-	mapper->disableAllGameKeymaps();
-	mapper->setGameKeymapState("ngi-default", true);
-	_gameProject = &project;
-	_currentScene = startScene;
-	if (startScene->_behaviorController)
-		startScene->_behaviorController->onShow(*startScene);
-	addMessageHandlerByIndex(global_messageHandler4, 0, 4);
-	if (intro) {
-		sceneIntro_initGui(*startScene, *intro2, parser.width());
-		sceneIntro_initMan(*startScene);
-		addMessageHandler(sceneHandlerIntro, 2);
-	}
-	if (startScene->_soundList)
-		_currSoundList1[_currSoundListCount++] = startScene->_soundList.get();
-	if (intro2 && intro2->_soundList)
-		_currSoundList1[_currSoundListCount++] = intro2->_soundList.get();
-	if (common && common->_soundList)
-		_currSoundList1[_currSoundListCount++] = common->_soundList.get();
-
-	Graphics::ManagedSurface &frame = _backgroundSurface;
-	frame.create(parser.width(), parser.height(), format);
-	byte brightness = intro ? 0 : 255;
-	frame.clear(format.RGBToColor(0, 0, 0));
-	if (brightness)
-		_currentScene->drawAndroid(frame);
-	_system->copyRectToScreen(frame.getPixels(), frame.pitch, 0, 0, frame.w, frame.h);
-	_system->updateScreen();
-	debugC(1, kDebugDrawing, "Presented first Full Pipe Android frame for %s", start->_tag.c_str());
-
-	Common::Event event;
-	Common::EventManager *eventManager = _system->getEventManager();
-	Common::Error result = Common::kNoError;
-	uint32 lastUpdate = _system->getMillis();
-	while (!shouldQuit()) {
-		bool screenChanged = false;
-		bool redraw = false;
-		while (eventManager->pollEvent(event)) {
-			if (event.type == Common::EVENT_SCREEN_CHANGED) {
-				screenChanged = true;
-			} else if (_modalObject) {
-				const bool back = (event.type == Common::EVENT_KEYUP &&
-						(event.kbd.keycode == Common::KEYCODE_ESCAPE || event.kbd.keycode == Common::KEYCODE_AC_BACK)) ||
-					(event.type == Common::EVENT_CUSTOM_ENGINE_ACTION_END && event.customType == kActionCloseDialog);
-				if (event.type == Common::EVENT_LBUTTONUP || back) {
-					Command cmd;
-					cmd._cmd = 17;
-					cmd._messageNum = back ? 37 : 30;
-					cmd._param = back ? kActionCloseDialog : 0;
-					_modalObject->handleMessage(&cmd);
-				}
-			} else if (_currentScene->_guiManager) {
-				GuiManager &gui = *_currentScene->_guiManager;
-				switch (event.type) {
-				case Common::EVENT_KEYDOWN:
-					gui.onKeyDown(event.kbd.keycode);
-					if (event.kbd.ascii)
-						gui.onChar(event.kbd.ascii);
-					break;
-				case Common::EVENT_KEYUP:
-					gui.onKeyUp(event.kbd.keycode);
-					break;
-				case Common::EVENT_MOUSEMOVE:
-				case Common::EVENT_LBUTTONDOWN:
-				case Common::EVENT_LBUTTONUP:
-				case Common::EVENT_RBUTTONDOWN:
-				case Common::EVENT_RBUTTONUP:
-					gui.onMouseMove(event.mouse);
-					if (event.type == Common::EVENT_LBUTTONDOWN)
-						gui.onMouseLKeyDown(event.mouse);
-					else if (event.type == Common::EVENT_LBUTTONUP)
-						gui.onMouseLKeyUp(event.mouse);
-					else if (event.type == Common::EVENT_RBUTTONDOWN)
-						gui.onMouseRKeyDown(event.mouse);
-					else if (event.type == Common::EVENT_RBUTTONUP)
-						gui.onMouseRKeyUp(event.mouse);
-					redraw = true;
-					break;
-				default:
-					break;
-				}
-			}
-		}
-		if (shouldQuit())
-			break;
-
-		const uint32 now = _system->getMillis();
-		const uint32 elapsed = now - lastUpdate;
-		lastUpdate = now;
-		Scene *scene = _currentScene;
-		if (_modalObject) {
-			if (!_modalObject->init(elapsed))
-				deleteModalObject();
-			redraw = true;
-		} else {
-			if (scene->_behaviorController)
-				redraw |= scene->_behaviorController->update(elapsed);
-			for (MessageQueue *queue : *_globalMessageQueueList)
-				redraw |= queue->updatePause(elapsed);
-			processMessages();
-			if (!_modalObject && scene == _currentScene)
-				redraw |= scene->update(elapsed);
-			if (!_modalObject && scene == _currentScene && scene->_sceneId == SC_INTRO1)
-				redraw |= sceneIntro_updateAndroid(elapsed, brightness);
-			processMessages();
-			redraw |= _modalObject != nullptr;
-		}
-
-		if (scene != _currentScene) {
-			if (scene->_guiManager)
-				scene->_guiManager->onHide();
-			stopAllSounds(Sound::kSpeech);
-			stopAllSounds(Sound::kEffect);
-			if (_currentScene->_behaviorController)
-				_currentScene->_behaviorController->onShow(*_currentScene);
-			debugC(2, kDebugDrawing, "Switched Android scene from %d to %d", scene->_sceneId, _currentScene->_sceneId);
-			redraw = true;
-		}
-		if (intro && !g_vars->sceneIntro_playing && !_modalObject && (_currentScene == startScene || _currentScene == intro2)) {
-			result = enterAndroidScene1();
-			if (result.getCode() != Common::kNoError)
-				break;
-			lastUpdate = _system->getMillis();
-			brightness = 255;
-			redraw = true;
-		}
-		if (redraw) {
-			frame.clear(format.RGBToColor(0, 0, 0));
-			if (_modalObject) {
-				_modalObject->update();
-			} else {
-				_currentScene->drawAndroid(frame);
-				if (brightness < 255)
-					drawAlphaRectangle(0, 0, frame.w, frame.h, brightness);
-			}
-		}
-		if (redraw || screenChanged)
-			_system->copyRectToScreen(frame.getPixels(), frame.pitch, 0, 0, frame.w, frame.h);
-		_system->updateScreen();
-		_system->delayMillis(10);
-	}
-	deleteModalObject();
-	clearMessages();
-	clearGlobalMessageQueueList();
-	clearMessageHandlers();
-	while (_currSoundListCount)
-		_currSoundList1[--_currSoundListCount] = nullptr;
-	g_vars->sceneIntro_aniin1man = nullptr;
-	g_vars->scene01_picSc01Osk = nullptr;
-	g_vars->scene01_picSc01Osk2 = nullptr;
-	_aniMan = _aniMan2 = nullptr;
-	_currentScene = nullptr;
-	_gameProject = nullptr;
-	return result;
+	width = parser.width();
+	height = parser.height();
+	return Common::kNoError;
 }
 
 } // End of namespace NGI
diff --git a/engines/ngi/behavior.cpp b/engines/ngi/behavior.cpp
index 48e11472f01..1bac2d034ee 100644
--- a/engines/ngi/behavior.cpp
+++ b/engines/ngi/behavior.cpp
@@ -98,7 +98,11 @@ void BehaviorController::onShow(Scene &scene) {
 	}
 }
 
-bool BehaviorAni::updateIdle(uint32 elapsed) {
+bool BehaviorMove::canStart(uint32 elapsed, uint32 randomMax) const {
+	return !(_flags & 1) && (_delay <= 0 || elapsed >= (uint32)_delay) && _percent && g_nmi->_rnd.getRandomNumber(randomMax) <= _percent;
+}
+
+bool BehaviorAni::update(uint32 elapsed) {
 	if (!_ani)
 		return false;
 	if (_activeMove) {
@@ -126,8 +130,7 @@ bool BehaviorAni::updateIdle(uint32 elapsed) {
 		if (anim._staticsId != _ani->_statics->_staticsId)
 			continue;
 		for (const BehaviorMove &move : anim._behaviorMoves) {
-			if ((move._flags & 1) || move._mirror != ((_ani->_flags & 8) != 0) ||
-					_elapsed < (uint32)move._delay || !move._percent || g_nmi->_rnd.getRandomNumber(99) > move._percent)
+			if (move._mirror != ((_ani->_flags & 8) != 0) || !move.canStart(_elapsed, 99))
 				continue;
 			const bool started = move._movementId ? _ani->startMovement(move._movementId, 0, -1) :
 					runQueueByIdWithAni(_ani, move._queueId, kBehaviorQueue);
@@ -141,14 +144,6 @@ bool BehaviorAni::updateIdle(uint32 elapsed) {
 	return false;
 }
 
-bool BehaviorController::update(uint32 elapsed) {
-	bool changed = false;
-	for (BehaviorAni &behavior : _behaviors)
-		changed |= behavior.updateIdle(elapsed);
-	updateSounds(elapsed);
-	return changed;
-}
-
 bool BehaviorSound::update(uint32 elapsed) {
 	Sound *sound = g_nmi->findSound(_soundId);
 	if (!sound)
@@ -217,13 +212,18 @@ void BehaviorController::initBehavior(Scene *sc, GameVar *var) {
 	}
 }
 
-void BehaviorController::update() {
+bool BehaviorController::update(uint32 elapsed) {
 	if (!_isActive)
-		return;
+		return false;
+	const bool android = g_nmi->getPlatform() == Common::kPlatformAndroid;
+	bool changed = false;
 
 	debugC(6, kDebugBehavior, "BehaviorController::update()");
-	for (uint i = 0; i < _behaviors.size(); i++) {
-		BehaviorAni &beh = _behaviors[i];
+	for (BehaviorAni &beh : _behaviors) {
+		if (android) {
+			changed |= beh.update(elapsed);
+			continue;
+		}
 
 		if (!beh._ani) {
 			beh._counter++;
@@ -259,6 +259,9 @@ void BehaviorController::update() {
 
 		}
 	}
+	if (android)
+		updateSounds(elapsed);
+	return changed;
 }
 
 void BehaviorController::updateBehavior(BehaviorAni &behaviorInfo, BehaviorAnim &entry) {
@@ -301,14 +304,10 @@ void BehaviorController::updateStaticAniBehavior(AniObject &ani, int delay, cons
 			}
 		}
 	} else {
-		for (uint i = 0; i < beh._behaviorMoves.size(); i++) {
-			if (!(beh._behaviorMoves[i]._flags & 1) && delay >= beh._behaviorMoves[i]._delay) {
-				if (beh._behaviorMoves[i]._percent) {
-					if (g_nmi->_rnd.getRandomNumber(32767) <= beh._behaviorMoves[i]._percent) {
-						mq = new MessageQueue(beh._behaviorMoves[i]._messageQueue, 0, 1);
-						break;
-					}
-				}
+		for (const BehaviorMove &move : beh._behaviorMoves) {
+			if (move.canStart(delay, 32767)) {
+				mq = new MessageQueue(move._messageQueue, 0, 1);
+				break;
 			}
 		}
 	}
diff --git a/engines/ngi/behavior.h b/engines/ngi/behavior.h
index 44fdd32af21..fa60f7ba195 100644
--- a/engines/ngi/behavior.h
+++ b/engines/ngi/behavior.h
@@ -40,6 +40,7 @@ struct BehaviorMove {
 	int16 _queueId = 0;
 	bool _mirror = false;
 
+	bool canStart(uint32 elapsed, uint32 randomMax) const;
 	BehaviorMove() = default;
 	BehaviorMove(GameVar *subvar, Scene *sc, int *delay);
 };
@@ -71,7 +72,7 @@ struct BehaviorAni {
 
 	void clear();
 	BehaviorMove &addMove(int16 staticsId);
-	bool updateIdle(uint32 elapsed);
+	bool update(uint32 elapsed);
 	void initAmbientBehavior(GameVar *var, Scene *sc);
 	void initObjectBehavior(GameVar *var, Scene *sc, AniObject *ani);
 };
@@ -104,12 +105,11 @@ class BehaviorController : public CObject {
 
 	void initBehavior(Scene *scene, GameVar *var);
 
-	void update();
 	void addSound(const BehaviorSound &sound, bool music);
 	void enableAllMusic();
 	BehaviorAni &addAni(int16 objectId, int16 sceneId, int flags);
 	void onShow(Scene &scene);
-	bool update(uint32 elapsed);
+	bool update(uint32 elapsed = 1);
 	void updateBehavior(BehaviorAni &behaviorInfo, BehaviorAnim &entry);
 	void updateStaticAniBehavior(AniObject &ani, int delay, const BehaviorAnim &beh);
 
diff --git a/engines/ngi/fullpipe/sceneChapter.cpp b/engines/ngi/fullpipe/sceneChapter.cpp
index 222532cd1b1..bc644c0c252 100644
--- a/engines/ngi/fullpipe/sceneChapter.cpp
+++ b/engines/ngi/fullpipe/sceneChapter.cpp
@@ -239,7 +239,7 @@ public:
 
 	void update() override {
 		Graphics::ManagedSurface &frame = g_nmi->_backgroundSurface;
-		_scene.drawAndroid(frame);
+		_scene.render();
 		if (_fader.brightness() < 255)
 			g_nmi->drawAlphaRectangle(0, 0, frame.w, frame.h, _fader.brightness());
 		const BitmapFont &titleFont = _titleFont ? *_titleFont : _font;
diff --git a/engines/ngi/fullpipe/sceneIntro.cpp b/engines/ngi/fullpipe/sceneIntro.cpp
index 589d16a9c80..b1ca4b9f557 100644
--- a/engines/ngi/fullpipe/sceneIntro.cpp
+++ b/engines/ngi/fullpipe/sceneIntro.cpp
@@ -136,8 +136,10 @@ void sceneHandlerIntro_part2() {
 }
 
 void sceneIntro_end() {
-	if (g_vars->sceneIntro_playing && g_nmi->getPlatform() == Common::kPlatformAndroid)
+	if (g_vars->sceneIntro_playing && g_nmi->getPlatform() == Common::kPlatformAndroid) {
+		g_nmi->_gameLoader->preloadScene(SC_1, TrubaLeft);
 		sceneChapter_show("CHAPTER_1");
+	}
 	g_vars->sceneIntro_playing = false;
 }
 
diff --git a/engines/ngi/gameloader.cpp b/engines/ngi/gameloader.cpp
index 711681eee3b..73d53fe726a 100644
--- a/engines/ngi/gameloader.cpp
+++ b/engines/ngi/gameloader.cpp
@@ -77,9 +77,13 @@ GameLoader::GameLoader() {
 	_interactionController = new InteractionController();
 	_inputController = new CursorController();
 
-	addMessageHandlerByIndex(global_messageHandler2, 0, 0);
-	insertMessageHandler(global_messageHandler3, 0, 128);
-	insertMessageHandler(global_messageHandler4, 0, 1);
+	if (g_nmi->getPlatform() == Common::kPlatformAndroid) {
+		addMessageHandlerByIndex(global_messageHandler4, 0, 4);
+	} else {
+		addMessageHandlerByIndex(global_messageHandler2, 0, 0);
+		insertMessageHandler(global_messageHandler3, 0, 128);
+		insertMessageHandler(global_messageHandler4, 0, 1);
+	}
 
 	_heroId = 0;
 	_field_F8 = 0;
@@ -181,46 +185,63 @@ bool GameLoader::loadScene(int sceneId) {
 }
 
 bool GameLoader::setScene(int sceneId, int entranceId) {
-	SceneTag *st;
-
-	int sc2idx = getSceneTagBySceneId(sceneId, &st);
-
-	if (sc2idx < 0)
-		return false;
+	const bool android = g_nmi->getPlatform() == Common::kPlatformAndroid;
+	Scene *scene;
+	const Common::Array<Entrance> *entrances;
+	if (android) {
+		scene = _gameProject->findScene(sceneId);
+		if (!scene)
+			return false;
+		entrances = &scene->_entrances;
+	} else {
+		SceneTag *tag;
+		int index = getSceneTagBySceneId(sceneId, &tag);
+		if (index < 0 || !_sc2array[index]._isLoaded)
+			return false;
+		scene = tag->_scene;
+		entrances = &_sc2array[index]._entranceData;
+		if (entrances->empty()) {
+			g_nmi->_currentScene = scene;
+			return true;
+		}
+	}
 
-	if (!_sc2array[sc2idx]._isLoaded)
+	// XML projects may name a start scene without specifying an entrance.
+	const Entrance defaultEntrance = {sceneId, 0, 0, 0};
+	const Entrance *entrance = android && !entranceId ? &defaultEntrance : nullptr;
+	for (const Entrance &entry : *entrances) {
+		// The original desktop workaround uses the first entrance in scene 726.
+		if ((!android && sceneId == 726) || (entry._id == entranceId && (!android || entry._sceneId == sceneId))) {
+			entrance = &entry;
+			break;
+		}
+	}
+	if (!entrance)
 		return false;
 
-	if (_sc2array[sc2idx]._entranceData.size() < 1) {
-		g_nmi->_currentScene = st->_scene;
-		return true;
+	if (_gameVar) {
+		GameVar *states = _gameVar->getSubVarByName("OBJSTATES");
+		GameVar *sg = states->getSubVarByName("SAVEGAME");
+		if (sg || (sg = states->addSubVarAsInt("SAVEGAME", 0)) != nullptr)
+			sg->setSubVarAsInt("Entrance", entranceId);
 	}
 
-	if (!_sc2array[sc2idx]._entranceData.size())
+	if (!g_nmi->doSetScene(*entrance))
 		return false;
 
-	uint entranceIdx = 0;
-	if (sceneId != 726) // WORKAROUND
-		for (entranceIdx = 0; _sc2array[sc2idx]._entranceData[entranceIdx]._id != entranceId; entranceIdx++) {
-			if (entranceIdx >= _sc2array[sc2idx]._entranceData.size())
-				return false;
-		}
-
-	GameVar *sg = _gameVar->getSubVarByName("OBJSTATES")->getSubVarByName("SAVEGAME");
-
-	if (sg || (sg = _gameVar->getSubVarByName("OBJSTATES")->addSubVarAsInt("SAVEGAME", 0)) != nullptr)
-		sg->setSubVarAsInt("Entrance", entranceId);
-
-	if (!g_nmi->doSetScene(_sc2array[sc2idx]._entranceData[entranceIdx]))
-		return false;
+	g_nmi->_currentScene = scene;
+	if (android) {
+		if (entrance->_queueId && !runQueue(entrance->_queueId, 0))
+			return false;
+		debugC(1, kDebugSceneLogic, "Entered Android scene %d through entrance %d, queue %d", sceneId, entranceId, entrance->_queueId);
+		return true;
+	}
 
 	g_nmi->_msgObjectId2 = 0;
 	g_nmi->_msgY = -1;
 	g_nmi->_msgX = -1;
 
-	g_nmi->_currentScene = st->_scene;
-
-	MessageQueue *mq1 = g_nmi->_currentScene->findMessageQueue(_sc2array[sc2idx]._entranceData[entranceIdx]._queueId);
+	MessageQueue *mq1 = scene->findMessageQueue(entrance->_queueId);
 	if (mq1) {
 		MessageQueue *mq = new MessageQueue(mq1, 0, 0);
 
@@ -358,7 +379,9 @@ void GameLoader::addPreloadItem(const PreloadItem &item) {
 bool GameLoader::preloadScene(int sceneId, int entranceId) {
 	debugC(0, kDebugLoading, "preloadScene(%d, %d), ", sceneId, entranceId);
 
-	if (_preloadSceneId != sceneId || _preloadEntranceId != entranceId) {
+	// XML entrances identify their destination directly. The frame loop commits
+	// the pending change once the current dialog has closed.
+	if (g_nmi->getPlatform() == Common::kPlatformAndroid || _preloadSceneId != sceneId || _preloadEntranceId != entranceId) {
 		_preloadSceneId = sceneId;
 		_preloadEntranceId = entranceId;
 		return true;
@@ -558,9 +581,11 @@ PicAniInfoList GameLoader::savePicAniInfos(Scene *sc, int flag1, int flag2) {
 	return res;
 }
 
-void GameLoader::updateContent(int counterdiff) {
+bool GameLoader::updateContent(int counterdiff) {
 	if (g_nmi->_currentScene) {
-		g_nmi->_currentScene->update(counterdiff);
+		bool changed = g_nmi->_currentScene->update(counterdiff);
+		if (g_nmi->getPlatform() == Common::kPlatformAndroid)
+			return changed;
 
 		_exCommand._cmd = 17;
 		_updateCounter++;
@@ -575,6 +600,7 @@ void GameLoader::updateContent(int counterdiff) {
 		processMessages();
 		preloadScene(_preloadSceneId, _preloadEntranceId);
 	}
+	return true;
 }
 
 Sc2::Sc2() :
diff --git a/engines/ngi/gameloader.h b/engines/ngi/gameloader.h
index 5484320ebe4..f19fde744c7 100644
--- a/engines/ngi/gameloader.h
+++ b/engines/ngi/gameloader.h
@@ -91,13 +91,14 @@ class GameLoader : public CObject {
 
 	bool load(MfcArchive &file) override;
 	bool loadScene(int sceneId);
+	Common::Error loadXML(const SceneTag *&start, int &width, int &height);
 	bool setScene(int sceneId, int entranceId);
 	bool preloadScene(int sceneId, int entranceId);
 	bool unloadScene(int sceneId);
 
 	void addPreloadItem(const PreloadItem &item);
 
-	void updateContent(int counterdiff);
+	bool updateContent(int counterdiff);
 
 	int getSceneTagBySceneId(int sceneId, SceneTag **st);
 	void applyPicAniInfos(Scene *sc, const PicAniInfoList &picAniInfo);
diff --git a/engines/ngi/gfx.cpp b/engines/ngi/gfx.cpp
index 3b71eb7b1b7..0a5758933b7 100644
--- a/engines/ngi/gfx.cpp
+++ b/engines/ngi/gfx.cpp
@@ -142,7 +142,12 @@ bool PictureObject::load(MfcArchive &file, bool bigPicture) {
 	return true;
 }
 
-void PictureObject::render() {
+void PictureObject::render(Common::Point scroll) {
+	if (g_nmi->getPlatform() == Common::kPlatformAndroid) {
+		_picture->blitTo(g_nmi->_backgroundSurface, Common::Point(_x, _y) - scroll);
+		return;
+	}
+
 	if (_flags & 1)
 		_picture->render(_x, _y, 2, 0);
 	else
diff --git a/engines/ngi/gfx.h b/engines/ngi/gfx.h
index c2a415050df..a7b814c1118 100644
--- a/engines/ngi/gfx.h
+++ b/engines/ngi/gfx.h
@@ -180,7 +180,7 @@ public:
 	bool load(MfcArchive &file) override { assert(0); return false; } // Disable base class
 
 	Dims getFullSize() const { return _picture->getDimensions(); }
-	void render();
+	void render(Common::Point scroll = Common::Point());
 	void renderAtPos(int x, int y);
 
 	bool setPicAniInfo(const PicAniInfo &picAniInfo);
diff --git a/engines/ngi/ngi.cpp b/engines/ngi/ngi.cpp
index 6956d625dbd..e8b5a17e9da 100644
--- a/engines/ngi/ngi.cpp
+++ b/engines/ngi/ngi.cpp
@@ -20,6 +20,7 @@
  */
 
 #include "base/plugins.h"
+#include "backends/keymapper/keymapper.h"
 
 #include "common/archive.h"
 #include "common/config-manager.h"
@@ -175,6 +176,7 @@ NGIEngine::NGIEngine(OSystem *syst, const NGIGameDescription *gameDesc) :
 }
 
 NGIEngine::~NGIEngine() {
+	clearMessageHandlers();
 	delete g_vars;
 	g_vars = nullptr;
 }
@@ -239,22 +241,7 @@ Common::String NGIEngine::getSaveStateName(int slot) const {
 	return Common::String::format("%s.s%02d", getGameId(), slot);
 }
 
-Common::Error NGIEngine::run() {
-	_globalMessageQueueList.reset(new GlobalMessageQueueList);
-	_aniHandler.reset(new AniHandler);
-
-	if (getPlatform() == Common::kPlatformAndroid)
-		return runAndroid();
-
-	// Initialize backend
-	initGraphics(800, 600, nullptr);
-
-	const Graphics::PixelFormat format = g_system->getScreenFormat();
-	if (format.isCLUT8())
-		return Common::kUnsupportedColorMode;
-
-	_backgroundSurface.create(800, 600, format);
-
+Common::Error NGIEngine::initGame() {
 	_behaviorManager.reset(new BehaviorController);
 
 	_sceneRect.left = 0;
@@ -265,8 +252,6 @@ Common::Error NGIEngine::run() {
 	_floaters.reset(new FlyPack);
 	_globalPalette = &_defaultPalette;
 
-	_isSaveAllowed = false;
-
 	if (debugChannelSet(-1, kDebugXML))
 		loadGameObjH();
 
@@ -299,26 +284,121 @@ Common::Error NGIEngine::run() {
 	loadAllScenes();
 #endif
 
-	int time1 = g_nmi->_system->getMillis();
-
-	// Center mouse
 	_system->warpMouse(400, 300);
+	return Common::kNoError;
+}
 
-	for (;;) {
-		updateEvents();
-		if (shouldQuit()) {
+bool NGIEngine::handleGuiEvent(const Common::Event &event) {
+	if (event.type == Common::EVENT_SCREEN_CHANGED) {
+		return true;
+	} else if (_modalObject) {
+		const bool back = (event.type == Common::EVENT_KEYUP &&
+				(event.kbd.keycode == Common::KEYCODE_ESCAPE || event.kbd.keycode == Common::KEYCODE_AC_BACK)) ||
+			(event.type == Common::EVENT_CUSTOM_ENGINE_ACTION_END && event.customType == kActionCloseDialog);
+		if (event.type == Common::EVENT_LBUTTONUP || back) {
+			Command cmd;
+			cmd._cmd = 17;
+			cmd._messageNum = back ? 37 : 30;
+			cmd._param = back ? kActionCloseDialog : 0;
+			_modalObject->handleMessage(&cmd);
+		}
+	} else if (_currentScene->_guiManager) {
+		GuiManager &gui = *_currentScene->_guiManager;
+		switch (event.type) {
+		case Common::EVENT_KEYDOWN:
+			gui.onKeyDown(event.kbd.keycode);
+			if (event.kbd.ascii)
+				gui.onChar(event.kbd.ascii);
+			break;
+		case Common::EVENT_KEYUP:
+			gui.onKeyUp(event.kbd.keycode);
+			break;
+		case Common::EVENT_MOUSEMOVE:
+		case Common::EVENT_LBUTTONDOWN:
+		case Common::EVENT_LBUTTONUP:
+		case Common::EVENT_RBUTTONDOWN:
+		case Common::EVENT_RBUTTONUP:
+			gui.onMouseMove(event.mouse);
+			if (event.type == Common::EVENT_LBUTTONDOWN)
+				gui.onMouseLKeyDown(event.mouse);
+			else if (event.type == Common::EVENT_LBUTTONUP)
+				gui.onMouseLKeyUp(event.mouse);
+			else if (event.type == Common::EVENT_RBUTTONDOWN)
+				gui.onMouseRKeyDown(event.mouse);
+			else if (event.type == Common::EVENT_RBUTTONUP)
+				gui.onMouseRKeyUp(event.mouse);
+			return true;
+		default:
 			break;
 		}
+	}
+	return false;
+}
 
-		int time2 = g_nmi->_system->getMillis();
+Common::Error NGIEngine::run() {
+	_globalMessageQueueList.reset(new GlobalMessageQueueList);
+	_aniHandler.reset(new AniHandler);
+	const bool android = getPlatform() == Common::kPlatformAndroid;
+	const SceneTag *start = nullptr;
+	int width = 800, height = 600;
+	Common::Error result = Common::kNoError;
+	if (android) {
+		_gameLoader.reset(new GameLoader());
+		result = _gameLoader->loadXML(start, width, height);
+		if (result.getCode() != Common::kNoError)
+			return result;
+		_gameProject = _gameLoader->_gameProject.get();
+	}
 
-		// 30fps
-		if (time2 - time1 >= 33 || !_normalSpeed) {
-			time1 = time2;
-			updateScreen();
-		}
+	initGraphics(width, height, nullptr);
+	const Graphics::PixelFormat format = _system->getScreenFormat();
+	if (format.isCLUT8())
+		return Common::kUnsupportedColorMode;
+	_backgroundSurface.create(width, height, format);
+	_isSaveAllowed = false;
+
+	if (android) {
+		Common::Keymapper *mapper = _system->getEventManager()->getKeymapper();
+		mapper->disableAllGameKeymaps();
+		mapper->setGameKeymapState("ngi-default", true);
+		if (!_gameLoader->setScene(start->_sceneId, 0))
+			return Common::Error(Common::kNoGameDataFoundError, "Could not load the Full Pipe Android start scene");
+	} else {
+		result = initGame();
+		if (result.getCode() != Common::kNoError)
+			return result;
+	}
+
+	const bool intro = android && start->_sceneId == SC_INTRO1;
+	byte brightness = intro ? 0 : 255;
+	if (android) {
+		if (brightness)
+			_currentScene->render();
+		else
+			_backgroundSurface.clear(0);
+		_system->copyRectToScreen(_backgroundSurface.getPixels(), _backgroundSurface.pitch, 0, 0, width, height);
+		_system->updateScreen();
+		debugC(1, kDebugDrawing, "Presented first Full Pipe Android frame for %s", start->_tag.c_str());
+	}
 
-		if (_needRestart) {
+	uint32 lastUpdate = _system->getMillis();
+	while (!shouldQuit()) {
+		const bool redraw = updateEvents();
+		if (shouldQuit())
+			break;
+		const uint32 now = _system->getMillis();
+		const uint32 elapsed = now - lastUpdate;
+		if (android || elapsed >= 33 || !_normalSpeed) {
+			lastUpdate = now;
+			// CGame::Update discounts long stalls on Android.
+			uint32 step = 42;
+			if (android)
+				step = elapsed > 350 ? 15 : elapsed;
+			result = updateScreen(step, brightness, redraw);
+			if (result.getCode() != Common::kNoError)
+				break;
+		}
+		if (!android && _needRestart) {
 			delete _modalObject;
 			freeGameLoader();
 			_currentScene = nullptr;
@@ -329,25 +409,44 @@ Common::Error NGIEngine::run() {
 			_needRestart = false;
 		}
 
-		_system->delayMillis(5);
 		_system->updateScreen();
+		_system->delayMillis(android ? 10 : 5);
 	}
 
-	delete _modalObject;
-	freeGameLoader();
-
-	cleanup();
+	if (android) {
+		deleteModalObject();
+		clearMessages();
+		clearGlobalMessageQueueList();
+		clearMessageHandlers();
+		while (_currSoundListCount)
+			_currSoundList1[--_currSoundListCount] = nullptr;
+		g_vars->sceneIntro_aniin1man = nullptr;
+		g_vars->scene01_picSc01Osk = nullptr;
+		g_vars->scene01_picSc01Osk2 = nullptr;
+		_aniMan = _aniMan2 = nullptr;
+		_currentScene = nullptr;
+		_gameProject = nullptr;
+		_gameLoader.reset();
+	} else {
+		delete _modalObject;
+		freeGameLoader();
+		cleanup();
+	}
 	_backgroundSurface.free();
-
-	return Common::kNoError;
+	return result;
 }
 
-void NGIEngine::updateEvents() {
+bool NGIEngine::updateEvents() {
 	Common::Event event;
 	Common::EventManager *eventMan = _system->getEventManager();
 	Command *ex;
+	bool redraw = false;
 
 	while (eventMan->pollEvent(event)) {
+		if (getPlatform() == Common::kPlatformAndroid) {
+			redraw |= handleGuiEvent(event);
+			continue;
+		}
 		switch (event.type) {
 		case Common::EVENT_CUSTOM_ENGINE_ACTION_START:
 			ex = new Command(0, 17, 36, 0, 0, 0, 1, 0, 0, 0);
@@ -370,7 +469,7 @@ void NGIEngine::updateEvents() {
 					} else {
 						_gameLoader->updateContent(42);
 					}
-					return;
+					return redraw;
 				}
 
 				ex = new Command(0, 17, 36, 0, 0, 0, 1, 0, 0, 0);
@@ -382,7 +481,7 @@ void NGIEngine::updateEvents() {
 				if (_gamePaused) {
 					_gamePaused = 0;
 					_flgGameIsRunning = true;
-					return;
+					return redraw;
 				}
 
 				ex = new Command(0, 17, 36, 0, 0, 0, 1, 0, 0, 0);
@@ -391,7 +490,7 @@ void NGIEngine::updateEvents() {
 				ex->handle();
 				break;
 			case Common::KEYCODE_q:
-				return;
+				return redraw;
 				break;
 			default:
 				ex = new Command(0, 17, 36, 0, 0, 0, 1, 0, 0, 0);
@@ -419,7 +518,7 @@ void NGIEngine::updateEvents() {
 			_mouseScreenPos = event.mouse;
 			break;
 		case Common::EVENT_QUIT:
-			return;
+			return redraw;
 		case Common::EVENT_RBUTTONDOWN:
 			if (!_inputArFlag && (_updateTicks - _lastInputTicks) >= 2) {
 				ex = new Command(0, 17, 107, event.mouse.x, event.mouse.y, 0, 1, 0, 0, 0);
@@ -460,6 +559,7 @@ void NGIEngine::updateEvents() {
 	//if (event.kbd.keycode == MSG_SC11_SHOWSWING && _modalObject) {
 	//	_modalObject->pollEvent();
 	//}
+	return redraw;
 }
 
 void NGIEngine::freeGameLoader() {
@@ -495,42 +595,67 @@ void NGIEngine::deleteModalObject() {
 	_modalObject = tmp;
 }
 
-void NGIEngine::updateScreen() {
-	debugC(4, kDebugDrawing, "NGIEngine::updateScreen()");
-
+Common::Error NGIEngine::updateScreen(uint32 elapsed, byte &brightness, bool redraw) {
+	const bool android = getPlatform() == Common::kPlatformAndroid;
 	_mouseVirtX = _mouseScreenPos.x + _sceneRect.left;
 	_mouseVirtY = _mouseScreenPos.y + _sceneRect.top;
 
-	//if (inputArFlag)
-	//	updateGame_inputArFlag();
+	Scene *scene = _currentScene;
+	const bool hadModal = _modalObject != nullptr;
+	if (!hadModal && (android || _flgGameIsRunning)) {
+		redraw |= _gameLoader->updateContent(elapsed);
+		if (android && !_modalObject && scene == _currentScene && scene->_sceneId == SC_INTRO1)
+			redraw |= sceneIntro_updateAndroid(elapsed, brightness);
+		if (android)
+			processMessages();
+	}
+	const bool renderScene = !_modalObject;
+	if (_modalObject && (android || _flgGameIsRunning)) {
+		// Android begins updating a newly opened dialog on the following tick.
+		if ((!android || hadModal) && !_modalObject->init(elapsed))
+			deleteModalObject();
+		redraw = true;
+	}
 
-	if (_modalObject || (_flgGameIsRunning && (_gameLoader->updateContent(42), _modalObject != nullptr))) {
-		if (_flgGameIsRunning) {
-			if (_modalObject->init(42)) {
-				_modalObject->update();
-			} else {
-				deleteModalObject();
-			}
-		}
-	} else if (_currentScene) {
-		_currentScene->render();
+	if (android && scene != _currentScene) {
+		if (scene->_guiManager)
+			scene->_guiManager->onHide();
+		stopAllSounds(Sound::kSpeech);
+		stopAllSounds(Sound::kEffect);
+		if (_currentScene->_behaviorController)
+			_currentScene->_behaviorController->onShow(*_currentScene);
+		debugC(2, kDebugDrawing, "Switched Android scene from %d to %d", scene->_sceneId, _currentScene->_sceneId);
+		redraw = true;
+	}
+	if (android && !_modalObject && _gameLoader->_preloadSceneId) {
+		if (!_gameLoader->setScene(_gameLoader->_preloadSceneId, _gameLoader->_preloadEntranceId))
+			return Common::Error(Common::kNoGameDataFoundError, "Could not enter the requested Android scene");
+		_gameLoader->_preloadSceneId = _gameLoader->_preloadEntranceId = 0;
+		brightness = 255;
+		redraw = true;
+	}
 
+	if (_modalObject) {
+		if (android || _flgGameIsRunning)
+			_modalObject->update();
+	} else if (_currentScene && (android ? redraw : renderScene)) {
+		_currentScene->render();
 		if (_inventoryScene)
 			_inventory->render();
-
 		if (_updateScreenCallback)
 			_updateScreenCallback();
+		if (brightness < 255)
+			drawAlphaRectangle(0, 0, _backgroundSurface.w, _backgroundSurface.h, brightness);
+	}
 
-		//if (inputArFlag && _currentScene) {
-		//	vrtTextOut(*(_DWORD *)g_vrtHandle, smallNftData, "DEMO", 4, 380, 580);
-		//	vrtTextOut(*(_DWORD *)g_vrtHandle, smallNftData, "Alt+F4 - exit", 14, 695, 580);
-		//}
+	if (android) {
+		if (redraw)
+			_system->copyRectToScreen(_backgroundSurface.getPixels(), _backgroundSurface.pitch, 0, 0, _backgroundSurface.w, _backgroundSurface.h);
 	} else {
-		//vrtRectangle(*(_DWORD *)g_vrtHandle, 0, 0, 0, 800, 600);
+		_inputController->render(_mouseScreenPos.x, _mouseScreenPos.y);
 	}
-	_inputController->render(_mouseScreenPos.x, _mouseScreenPos.y);
-
 	++_updateTicks;
+	return Common::kNoError;
 }
 
 int NGIEngine::getStateValue(const Common::String &name, const char *state) {
diff --git a/engines/ngi/ngi.h b/engines/ngi/ngi.h
index 303ec532599..271563da54a 100644
--- a/engines/ngi/ngi.h
+++ b/engines/ngi/ngi.h
@@ -129,8 +129,8 @@ class NGIEngine : public ::Engine {
 protected:
 
 	Common::Error run() override;
-	Common::Error runAndroid();
-	Common::Error enterAndroidScene1();
+	Common::Error initGame();
+	bool handleGuiEvent(const Common::Event &event);
 
 public:
 	NGIEngine(OSystem *syst, const NGIGameDescription *gameDesc);
@@ -157,7 +157,7 @@ public:
 	Common::KeyCode _keyState;
 	uint16 _buttonState;
 
-	void updateEvents();
+	bool updateEvents();
 
 	Graphics::ManagedSurface _backgroundSurface;
 
@@ -265,7 +265,7 @@ public:
 	void initMap();
 	void updateMap(PreloadItem *pre);
 	void updateMapPiece(int mapId, int update);
-	void updateScreen();
+	Common::Error updateScreen(uint32 elapsed, byte &brightness, bool redraw);
 
 	void freeGameLoader();
 	void cleanup();
diff --git a/engines/ngi/scene.cpp b/engines/ngi/scene.cpp
index 4df8eb088be..0ed82d73325 100644
--- a/engines/ngi/scene.cpp
+++ b/engines/ngi/scene.cpp
@@ -455,73 +455,58 @@ void Scene::initObjectCursors(const char *varname) {
 	}
 }
 
-#if 0
-bool Scene::compareObjPriority(const void *p1, const void *p2) {
-	if (((const GameObject *)p1)->_z > ((const GameObject *)p2)->_z)
-		return true;
-
-	if (((const GameObject *)p1)->_z == ((const GameObject *)p2)->_z)
-		if (((const GameObject *)p1)->_cnum > ((const GameObject *)p2)->_cnum)
-			return true;
-
-	return false;
-}
-
-void Scene::sortRenderables(Common::Array<AniObject *> &list, bool skipFirst) {
-	if (skipFirst) {
-		Common::Array<AniObject *>::iterator s = list.begin();
-
-		++s;
-
-		Common::sort(s, list.end(), Scene::compareObjPriority);
-	} else {
-		Common::sort(list.begin(), list.end(), Scene::compareObjPriority);
+template<typename T>
+void Scene::sortRenderables(Common::Array<T *> &list, uint startIndex) {
+	// The XML loader saves the declaration order across pictures and animations.
+	// Binary scenes retain their current list order at equal priority.
+	const bool xml = g_nmi->getPlatform() == Common::kPlatformAndroid;
+	for (uint i = startIndex + 1; i < list.size(); ++i) {
+		T *object = list[i];
+		uint j = i;
+		while (j > startIndex) {
+			T *previous = list[j - 1];
+			if (previous->_z > object->_z || (previous->_z == object->_z && (!xml || previous->_cnum <= object->_cnum)))
+				break;
+			list[j--] = previous;
+		}
+		list[j] = object;
 	}
 }
 
-void Scene::sortRenderables(Common::Array<PictureObject *> &list, bool skipFirst) {
-	if (skipFirst) {
-		Common::Array<PictureObject *>::iterator s = list.begin();
+void Scene::render() {
+	debugC(6, kDebugDrawing, ">>>>> Scene::render()");
+	g_nmi->_backgroundSurface.clear(0);
+	if (g_nmi->getPlatform() == Common::kPlatformAndroid) {
+		Common::Array<GameObject *> visibleObjects;
+		for (PictureObject *picture : _pictureObjects) {
+			if (picture->_flags & 4)
+				visibleObjects.push_back(picture);
+		}
+		for (AniObject *animation : _renderableAnis) {
+			if (animation->_flags & 4)
+				visibleObjects.push_back(animation);
+		}
 
-		++s;
+		sortRenderables(visibleObjects);
 
-		Common::sort(s, list.end(), Scene::compareObjPriority);
-	} else {
-		Common::sort(list.begin(), list.end(), Scene::compareObjPriority);
-	}
-}
-#else
-template<typename T>
-void Scene::sortRenderables(Common::Array<T *> &list, uint startIndex) {
-	if (list.size() > startIndex) {
-		int lastIndex = list.size() - 1;
-		bool changed;
-		do {
-			changed = false;
-			T *refElement = list[startIndex];
-			for (int i = startIndex; i < lastIndex; i++) {
-				T *curElement = list[i + 1];
-				if (curElement->_z > refElement->_z) {
-					// Push refElement down the list
-					list.remove_at(i);
-					list.insert_at(i + 1, refElement);
-					changed = true;
-				} else
-					refElement = curElement;
+		bool renderedGui = false;
+		for (GameObject *object : visibleObjects) {
+			if (!renderedGui && _guiManager && object->_z < 0) {
+				_guiManager->render(g_nmi->_backgroundSurface);
+				renderedGui = true;
 			}
-			lastIndex--;
-		} while (changed);
+			if (object->_objtype == kObjTypePictureObject)
+				static_cast<PictureObject *>(object)->render(Common::Point(_x, _y));
+			else
+				static_cast<AniObject *>(object)->render(Common::Point(_x, _y));
+		}
+		if (_guiManager && !renderedGui)
+			_guiManager->render(g_nmi->_backgroundSurface);
+		return;
 	}
-}
-#endif
 
-void Scene::render() {
-	debugC(6, kDebugDrawing, ">>>>> Scene::render()");
 	updateScrolling();
 
-	// Clean previous stuff
-	g_nmi->_backgroundSurface.fillRect(Common::Rect(0, 0, 800, 600), 0);
-
 	drawContent(60000, 0, true);
 
 	sortRenderables(_renderableAnis);
@@ -664,7 +649,18 @@ int Scene::getPictureObjectIdAtPos(int x, int y) {
 bool Scene::update(int counterdiff) {
 	debugC(6, kDebugDrawing, "Scene::update(%d)", counterdiff);
 
-	bool changed = _guiManager && _guiManager->update(counterdiff);
+	bool changed = false;
+	if (g_nmi->getPlatform() == Common::kPlatformAndroid) {
+		if (_behaviorController)
+			changed |= _behaviorController->update(counterdiff);
+		for (MessageQueue *queue : *g_nmi->_globalMessageQueueList)
+			changed |= queue->updatePause(counterdiff);
+		processMessages();
+		if (g_nmi->_modalObject || this != g_nmi->_currentScene)
+			return true;
+	}
+	if (_guiManager)
+		changed |= _guiManager->update(counterdiff);
 	for (uint i = 0; i < _renderableAnis.size(); i++)
 		changed |= _renderableAnis[i]->update(counterdiff);
 	return changed;
@@ -680,13 +676,7 @@ void Scene::drawContent(int minPri, int maxPri, bool drawBg) {
 
 	debugC(1, kDebugDrawing, "Scene::drawContent(>%d, <%d, %d)", minPri, maxPri, drawBg);
 
-#if 0
-	if (_pictureObjects.size() > 2) { // We need to z-sort them
-		sortRenderables(_pictureObjects, true);
-	}
-#else
 	sortRenderables(_pictureObjects, 1);
-#endif
 
 	if (minPri == -1 && _pictureObjects.size())
 		minPri = _pictureObjects.back()->_z - 1;
diff --git a/engines/ngi/scene.h b/engines/ngi/scene.h
index 19a3e6850e2..745d1479e15 100644
--- a/engines/ngi/scene.h
+++ b/engines/ngi/scene.h
@@ -70,7 +70,6 @@ class Scene : public Background {
 	void initStaticANIObjects();
 	void init();
 	void render();
-	void drawAndroid(Graphics::ManagedSurface &target) const;
 	void drawContent(int minPri, int maxPri, bool drawBG);
 	void updateScrolling();
 	void updateScrolling2();
@@ -103,14 +102,8 @@ class Scene : public Background {
 	void stopAllSounds();
 
   private:
-#if 0
-	static bool compareObjPriority(const void *p1, const void *p2);
-	void sortRenderables(Common::Array<AniObject *> &list, bool skipFirst = false);
-	void sortRenderables(Common::Array<PictureObject *> &list, bool skipFirst = false);
-#else
 	template<typename T>
 	void sortRenderables(Common::Array<T*> &list, uint startIndex = 0);
-#endif
 };
 
 class SceneTag : public CObject {
diff --git a/engines/ngi/scenes.cpp b/engines/ngi/scenes.cpp
index 80c0c106565..1699119f9c6 100644
--- a/engines/ngi/scenes.cpp
+++ b/engines/ngi/scenes.cpp
@@ -575,6 +575,57 @@ bool NGIEngine::doSetScene(const Entrance &entrance) {
 	if (!scene)
 		return 0;
 
+	if (getPlatform() == Common::kPlatformAndroid) {
+		Scene *common = findScene(SC_COMMON);
+		Scene *intro2 = scene->_sceneId == SC_INTRO1 ? findScene(SC_INTRO2) : nullptr;
+		if (scene->_sceneId == SC_INTRO1 && (!common || !intro2))
+			return false;
+		scene->_commonQueueScene = common == scene ? nullptr : common;
+		for (const PicAniInfo &ref : scene->_roamingObjects) {
+			Scene *source = findScene(ref.sceneId);
+			AniObject *actor = source ? source->findAniObjectById(ref.objectId, ref.copyId) : nullptr;
+			if (!actor)
+				return false;
+			if (!scene->findAniObjectById(ref.objectId, ref.copyId))
+				scene->_renderableAnis.push_back(actor);
+		}
+		_aniMan = scene->findAniObjectById(scene->_heroId, 0);
+		_aniMan2 = _aniMan;
+		if (scene->_heroId && !_aniMan)
+			return false;
+
+		clearGlobalMessageQueueList1();
+		removeMessageHandler(2, -1);
+		stopAllSounds(Sound::kSpeech);
+		stopAllSounds(Sound::kEffect);
+		if (scene->_behaviorController)
+			scene->_behaviorController->onShow(*scene);
+		_currSoundListCount = 0;
+		if (scene->_soundList)
+			_currSoundList1[_currSoundListCount++] = scene->_soundList.get();
+		if (intro2 && intro2->_soundList)
+			_currSoundList1[_currSoundListCount++] = intro2->_soundList.get();
+		if (scene->_commonQueueScene && common->_soundList)
+			_currSoundList1[_currSoundListCount++] = common->_soundList.get();
+
+		if (_currentScene && _currentScene->_guiManager)
+			_currentScene->_guiManager->onHide();
+		_currentScene = scene;
+		if (_aniMan && scene->_motionController) {
+			scene->_motionController->attachObject(_aniMan);
+			scene->_motionController->activate();
+		}
+		if (intro2) {
+			sceneIntro_initGui(*scene, *intro2, _backgroundSurface.w);
+			sceneIntro_initMan(*scene);
+			addMessageHandler(sceneHandlerIntro, 2);
+		} else if (scene->_sceneId == SC_1) {
+			scene01_initObjects(scene, entrance._id, true);
+			addMessageHandler(sceneHandler01, 2);
+		}
+		return true;
+	}
+
 	sceneDim = scene->_pictureObjects.front()->getFullSize();
 	_sceneWidth = sceneDim.x;
 	_sceneHeight = sceneDim.y;
diff --git a/engines/ngi/statics.cpp b/engines/ngi/statics.cpp
index 2c674efc877..43e884fb3c9 100644
--- a/engines/ngi/statics.cpp
+++ b/engines/ngi/statics.cpp
@@ -550,7 +550,19 @@ Statics *AniObject::addReverseStatics(Statics *st) {
 	return res;
 }
 
-void AniObject::render() {
+void AniObject::render(Common::Point scroll) {
+	if (g_nmi->getPlatform() == Common::kPlatformAndroid) {
+		const Phase *phase = _movement ? _movement->_curPhase : _statics;
+		if (phase && (_flags & 4)) {
+			Common::Point anchor = getSomeXY();
+			const bool mirror = (_flags & 8) != 0;
+			if (mirror)
+				anchor.x = phase->getDimensions().x - anchor.x;
+			phase->blitTo(g_nmi->_backgroundSurface, Common::Point(_x, _y) - scroll - anchor, mirror);
+		}
+		return;
+	}
+
 	if ((_flags & 4) == 0)
 		return;
 
diff --git a/engines/ngi/statics.h b/engines/ngi/statics.h
index 9ccb44242ca..b03f443e05f 100644
--- a/engines/ngi/statics.h
+++ b/engines/ngi/statics.h
@@ -253,7 +253,7 @@ public:
 	bool update(int counterdiff);
 
 	Statics *addReverseStatics(Statics *ani);
-	void render();
+	void render(Common::Point scroll = Common::Point());
 	void draw2();
 
 	/** ownership of returned object is transferred to caller */


Commit: fab7eaf59a68eab1a0b09cd1bfeea1eebbb4290e
    https://github.com/scummvm/scummvm/commit/fab7eaf59a68eab1a0b09cd1bfeea1eebbb4290e
Author: Eugene Sandulenko (sev at scummvm.org)
Date: 2026-11-28T14:18:26+01:00

Commit Message:
NGI: Select engine behavior by dated game revision

Changed paths:
  A engines/ngi/xmlproject.cpp
  R engines/ngi/android.cpp
    engines/ngi/behavior.cpp
    engines/ngi/detection.cpp
    engines/ngi/detection.h
    engines/ngi/fullpipe/sceneChapter.cpp
    engines/ngi/fullpipe/sceneIntro.cpp
    engines/ngi/gameloader.cpp
    engines/ngi/gameloader.h
    engines/ngi/gfx.cpp
    engines/ngi/messagehandlers.cpp
    engines/ngi/messages.cpp
    engines/ngi/metaengine.cpp
    engines/ngi/module.mk
    engines/ngi/motion.cpp
    engines/ngi/ngi.cpp
    engines/ngi/ngi.h
    engines/ngi/scene.cpp
    engines/ngi/scenes.cpp
    engines/ngi/sound.cpp
    engines/ngi/statics.cpp


diff --git a/engines/ngi/behavior.cpp b/engines/ngi/behavior.cpp
index 1bac2d034ee..3565d172ce2 100644
--- a/engines/ngi/behavior.cpp
+++ b/engines/ngi/behavior.cpp
@@ -215,12 +215,12 @@ void BehaviorController::initBehavior(Scene *sc, GameVar *var) {
 bool BehaviorController::update(uint32 elapsed) {
 	if (!_isActive)
 		return false;
-	const bool android = g_nmi->getPlatform() == Common::kPlatformAndroid;
+	const bool timedBehaviors = g_nmi->_gameVersion >= 201509;
 	bool changed = false;
 
 	debugC(6, kDebugBehavior, "BehaviorController::update()");
 	for (BehaviorAni &beh : _behaviors) {
-		if (android) {
+		if (timedBehaviors) {
 			changed |= beh.update(elapsed);
 			continue;
 		}
@@ -259,7 +259,7 @@ bool BehaviorController::update(uint32 elapsed) {
 
 		}
 	}
-	if (android)
+	if (timedBehaviors)
 		updateSounds(elapsed);
 	return changed;
 }
diff --git a/engines/ngi/detection.cpp b/engines/ngi/detection.cpp
index 09ba1d36572..aa03da1646b 100644
--- a/engines/ngi/detection.cpp
+++ b/engines/ngi/detection.cpp
@@ -104,10 +104,10 @@ static const PlainGameDescriptor ngiGames[] = {
 namespace NGI {
 
 // Catalog placeholders until detection signatures are available.
-#define NGI_STUB(id) { \
+#define NGI_STUB(id, version) { \
 	{ id, nullptr, AD_ENTRY1s(id "stub.gam", "00000000000000000000000000000000", 0), \
 	  Common::RU_RUS, Common::kPlatformWindows, ADGF_UNSUPPORTED | ADGF_DROPPLATFORM, GUIO1(GUIO_NOMIDI) }, \
-	0 \
+	0, version \
 }
 
 static const NGIGameDescription gameDescriptions[] = {
@@ -123,7 +123,7 @@ static const NGIGameDescription gameDescriptions[] = {
 			ADGF_DROPPLATFORM,
 			GUIO1(GUIO_NOMIDI)
 		},
-		GID_MDREAM
+		GID_MDREAM, 0
 	},
 
 	// Full Pipe Russian version
@@ -139,7 +139,7 @@ static const NGIGameDescription gameDescriptions[] = {
 			ADGF_DROPPLATFORM,
 			GUIO1(GUIO_NOMIDI)
 		},
-		GID_FULLPIPE
+		GID_FULLPIPE, 200311
 	},
 
 	// Full Pipe German version
@@ -153,7 +153,7 @@ static const NGIGameDescription gameDescriptions[] = {
 			ADGF_DROPPLATFORM,
 			GUIO1(GUIO_NOMIDI)
 		},
-		GID_FULLPIPE
+		GID_FULLPIPE, 200311
 	},
 
 	// Full Pipe Estonian version
@@ -167,7 +167,7 @@ static const NGIGameDescription gameDescriptions[] = {
 			ADGF_DROPPLATFORM,
 			GUIO1(GUIO_NOMIDI)
 		},
-		GID_FULLPIPE
+		GID_FULLPIPE, 200311
 	},
 
 	// Full Pipe Lithuanian version
@@ -181,7 +181,7 @@ static const NGIGameDescription gameDescriptions[] = {
 			ADGF_DROPPLATFORM,
 			GUIO1(GUIO_NOMIDI)
 		},
-		GID_FULLPIPE
+		GID_FULLPIPE, 200311
 	},
 
 	// Full Pipe English version
@@ -195,7 +195,7 @@ static const NGIGameDescription gameDescriptions[] = {
 			ADGF_DROPPLATFORM,
 			GUIO1(GUIO_NOMIDI)
 		},
-		GID_FULLPIPE
+		GID_FULLPIPE, 200311
 	},
 
 	// Full Pipe English Steam version
@@ -209,7 +209,7 @@ static const NGIGameDescription gameDescriptions[] = {
 			ADGF_DROPPLATFORM,
 			GUIO1(GUIO_NOMIDI)
 		},
-		GID_FULLPIPE
+		GID_FULLPIPE, 200311
 	},
 
 	// Full Pipe Russian Demo version
@@ -223,7 +223,7 @@ static const NGIGameDescription gameDescriptions[] = {
 			ADGF_DROPPLATFORM | ADGF_DEMO,
 			GUIO1(GUIO_NOMIDI)
 		},
-		GID_FULLPIPE
+		GID_FULLPIPE, 200311
 	},
 
 	// Full Pipe Russian 1997 Demo version
@@ -238,7 +238,7 @@ static const NGIGameDescription gameDescriptions[] = {
 			ADGF_DROPPLATFORM | ADGF_DEMO,
 			nullptr
 		},
-		GID_FULLPIPE
+		GID_FULLPIPE, 200311
 	},
 
 	// Full Pipe German Demo version
@@ -252,7 +252,7 @@ static const NGIGameDescription gameDescriptions[] = {
 			ADGF_DROPPLATFORM | ADGF_DEMO,
 			GUIO1(GUIO_NOMIDI)
 		},
-		GID_FULLPIPE
+		GID_FULLPIPE, 200311
 	},
 
 	// Full Pipe Android version
@@ -267,7 +267,7 @@ static const NGIGameDescription gameDescriptions[] = {
 			ADGF_UNSTABLE,
 			GUIO1(GUIO_NOMIDI)
 		},
-		GID_FULLPIPE
+		GID_FULLPIPE, 201509
 	},
 
 	// Братья Пилоты. Обратная сторона Земли
@@ -276,67 +276,67 @@ static const NGIGameDescription gameDescriptions[] = {
 
 	// Братья Пилоты. Олимпиада
 	// 2004/08. Pipe Studio
-	NGI_STUB("pilot7"),
+	NGI_STUB("pilot7", 200408),
 
 	// 3 богатыря. Алеша Попович и Тугарин Змей
 	// 2005/02. Pipe Studio
-	NGI_STUB("popovich"),
+	NGI_STUB("popovich", 200502),
 
 	// Братья Пилоты. Загадка атлантической сельди
 	// 2006/01. Pipe Studio
-	NGI_STUB("lostpilots"),
+	NGI_STUB("lostpilots", 200601),
 
 	// 3 богатыря. Добрыня Никитич и Змей Горыныч
 	// 2006/03. Pipe Studio
-	NGI_STUB("dobrynya"),
+	NGI_STUB("dobrynya", 200603),
 
 	// Князь Владимир
 	// 2006/05. Pipe Studio
-	NGI_STUB("vladimir"),
+	NGI_STUB("vladimir", 200605),
 
 	// Лунтик. Подготовка к школе
 	// 2006/11. Pipe Studio
-	NGI_STUB("luntik"),
+	NGI_STUB("luntik", 200611),
 
 	// Лунтик. Математика для малышей
 	// 2007/03. Pipe Studio
-	NGI_STUB("luntik2"),
+	NGI_STUB("luntik2", 200703),
 
 	// Лунтик. Русский язык для малышей
 	// 2007/06. Pipe Studio
-	NGI_STUB("luntik3"),
+	NGI_STUB("luntik3", 200706),
 
 	// Лунтик. Английский язык для малышей
 	// 2007/09. Pipe Studio
-	NGI_STUB("luntik4"),
+	NGI_STUB("luntik4", 200709),
 
 	// 38 попугаев. Подготовка к школе
 	// 2007/09. Pipe Studio
-	NGI_STUB("38_parrots"),
+	NGI_STUB("38_parrots", 200709),
 
 	// Лунтик. Развивающие задания для малышей
 	// 2007/10. Pipe Studio
-	NGI_STUB("luntik5"),
+	NGI_STUB("luntik5", 200710),
 
 	// 38 попугаев. Математика
 	// 2007/11. Pipe Studio
-	NGI_STUB("38_parrots2"),
+	NGI_STUB("38_parrots2", 200711),
 
 	// UmaNetto. Полный превед!
 	// 2007/12. Pipe Studio
-	NGI_STUB("fullkatya"),
+	NGI_STUB("fullkatya", 200712),
 
 	// 3 богатыря. Илья Муромец и Соловей-разбойник
 	// 2007/12. Pipe Studio
-	NGI_STUB("muromets"),
+	NGI_STUB("muromets", 200712),
 
 	// Лунтик учит буквы
 	// 2008/08. Pipe Studio
-	NGI_STUB("luntik6"),
+	NGI_STUB("luntik6", 200808),
 
 	// Лунтик учит цифры
 	// 2008/10. Pipe Studio
-	NGI_STUB("luntik7"),
+	NGI_STUB("luntik7", 200810),
 
 	// Ранетки
 	// 2008/11. Pipe Studio
@@ -348,101 +348,101 @@ static const NGIGameDescription gameDescriptions[] = {
 
 	// Лунтик познает мир
 	// 2009/01. Pipe Studio
-	NGI_STUB("luntik8"),
+	NGI_STUB("luntik8", 200901),
 
 	// Лунтик учится рисовать
 	// 2009/04. Pipe Studio
-	NGI_STUB("luntik9"),
+	NGI_STUB("luntik9", 200904),
 
 	// Лунтик учит правила
 	// 2009/08. Pipe Studio
-	NGI_STUB("luntik10"),
+	NGI_STUB("luntik10", 200908),
 
 	// Книга мастеров
 	// 2009/10. Pipe Studio
-	NGI_STUB("masterbook"),
+	NGI_STUB("masterbook", 200910),
 
 	// 38 попугаев. Звездный десант
 	// 2009/11. Pipe Studio
-	NGI_STUB("38_parrots3"),
+	NGI_STUB("38_parrots3", 200911),
 
 	// Лунтик. Хочу всё знать
 	// 2010/02. Pipe Studio
-	NGI_STUB("luntik11"),
+	NGI_STUB("luntik11", 201002),
 
 	// Лунтик. Тренируем память и внимание
 	// 2010/04. Pipe Studio
-	NGI_STUB("luntik12"),
+	NGI_STUB("luntik12", 201004),
 
 	// Лунтик. География для малышей
 	// 2010/08. Pipe Studio
-	NGI_STUB("luntik13"),
+	NGI_STUB("luntik13", 201008),
 
 	// Winx Club. Свидание Стеллы
 	// 2010/11. Pipe Studio
-	NGI_STUB("winx2"),
+	NGI_STUB("winx2", 201011),
 
 	// Маша и медведь. Подготовка к школе
 	// 2010/12. Pipe Studio
-	NGI_STUB("masha01"),
+	NGI_STUB("masha01", 201012),
 
 	// 3 богатыря и Шамаханская царица
 	// 2010/12. Pipe Studio
-	NGI_STUB("trybog"),
+	NGI_STUB("trybog", 201012),
 
 	// Winx Club. День рождения Блум
 	// 2011/03. Pipe Studio
-	NGI_STUB("winx4"),
+	NGI_STUB("winx4", 201103),
 
 	// Маша и медведь. Развивающие задания для малышей
 	// 2011/04. Pipe Studio
-	NGI_STUB("masha02"),
+	NGI_STUB("masha02", 201104),
 
 	// Winx Club. Флора и ее питомцы
 	// 2011/08. Pipe Studio
-	NGI_STUB("winx_pets"),
+	NGI_STUB("winx_pets", 201108),
 
 	// Winx Club. Переполох в виртуальности
 	// 2011/10. Pipe Studio
-	NGI_STUB("winx_turmoil"),
+	NGI_STUB("winx_turmoil", 201110),
 
 	// Winx Club. Вечеринка
 	// 2011/10. Pipe Studio
-	NGI_STUB("winx_party"),
+	NGI_STUB("winx_party", 201110),
 
 	// Иван Царевич и серый волк
 	// 2011/12. Pipe Studio
-	NGI_STUB("vasilisa"),
+	NGI_STUB("vasilisa", 201112),
 
 	// Иван Царевич. Свадьба Василисы
 	// 2011/12. Pipe Studio
-	NGI_STUB("vasilisa2"),
+	NGI_STUB("vasilisa2", 201112),
 
 	// Барбоскины. Первое знакомство
 	// 2012/05. Pipe Studio
-	NGI_STUB("barboskins_1"),
+	NGI_STUB("barboskins_1", 201205),
 
 	// Маша и медведь. Прятки
 	// 2012/08. Pipe Studio
-	NGI_STUB("masha03"),
+	NGI_STUB("masha03", 201208),
 
 	// Барбоскины. Заметая следы
 	// 2012/10. Pipe Studio
-	NGI_STUB("barboskins_2"),
+	NGI_STUB("barboskins_2", 201210),
 
 	// Маша и медведь. Давайте дружить
 	// 2012/12. Pipe Studio
-	NGI_STUB("masha04"),
+	NGI_STUB("masha04", 201212),
 
 	// Финес и Ферб. Новые изобретения
 	// 2012/12. Pipe Studio
-	NGI_STUB("phineasferb"),
+	NGI_STUB("phineasferb", 201212),
 
 	// Маша и Медведь. Активные игры
 	// 2013/04. Pipe Studio
-	NGI_STUB("masha05"),
+	NGI_STUB("masha05", 201304),
 
-	{ AD_TABLE_END_MARKER, 0 }
+	{ AD_TABLE_END_MARKER, 0, 0 }
 };
 
 #undef NGI_STUB
diff --git a/engines/ngi/detection.h b/engines/ngi/detection.h
index 04a1fc1eab1..ccdead8f473 100644
--- a/engines/ngi/detection.h
+++ b/engines/ngi/detection.h
@@ -37,6 +37,7 @@ struct NGIGameDescription {
 	ADGameDescription desc;
 
 	int gameId;
+	uint32 gameVersion; // Engine revision (YYYYMM), or 0 when undated.
 };
 
 } // End of namespace NGI
diff --git a/engines/ngi/fullpipe/sceneChapter.cpp b/engines/ngi/fullpipe/sceneChapter.cpp
index bc644c0c252..e41ae9bd7e6 100644
--- a/engines/ngi/fullpipe/sceneChapter.cpp
+++ b/engines/ngi/fullpipe/sceneChapter.cpp
@@ -175,7 +175,7 @@ public:
 	}
 
 	bool open() {
-		const Common::String locale = g_nmi->getAndroidResourceLocale();
+		const Common::String locale = g_nmi->getResourceLocale();
 		const Common::Path directory("data/res_" + locale);
 		const Common::Path fonts = directory.join("Fonts");
 		if (!_settings.load(directory)) {
diff --git a/engines/ngi/fullpipe/sceneIntro.cpp b/engines/ngi/fullpipe/sceneIntro.cpp
index b1ca4b9f557..f54cc5e6bc7 100644
--- a/engines/ngi/fullpipe/sceneIntro.cpp
+++ b/engines/ngi/fullpipe/sceneIntro.cpp
@@ -129,14 +129,14 @@ void sceneHandlerIntro_part1() {
 void sceneHandlerIntro_part2() {
 	g_nmi->_currentScene = g_nmi->findScene(SC_INTRO2);
 	runQueue(QU_IN2_DO, 0);
-	if (g_nmi->getPlatform() == Common::kPlatformAndroid) {
+	if (g_nmi->isAndroidFullPipe()) {
 		if (GuiElement *button = skipButton(*g_nmi->_currentScene))
 			button->showAndActivate();
 	}
 }
 
 void sceneIntro_end() {
-	if (g_vars->sceneIntro_playing && g_nmi->getPlatform() == Common::kPlatformAndroid) {
+	if (g_vars->sceneIntro_playing && g_nmi->isAndroidFullPipe()) {
 		g_nmi->_gameLoader->preloadScene(SC_1, TrubaLeft);
 		sceneChapter_show("CHAPTER_1");
 	}
@@ -147,7 +147,7 @@ int sceneHandlerIntro(Command *ex) {
 	if (ex->_cmd != 17)
 		return 0;
 
-	if (g_nmi->getPlatform() == Common::kPlatformAndroid && !ex->_messageName.empty()) {
+	if (g_nmi->isAndroidFullPipe() && !ex->_messageName.empty()) {
 		debugC(3, kDebugEvents, "Android intro message %s", ex->_messageName.c_str());
 		if (ex->_messageName == "MSG_ENABLE_BHV_SOUND") {
 			if (g_nmi->_currentScene->_behaviorController)
diff --git a/engines/ngi/gameloader.cpp b/engines/ngi/gameloader.cpp
index 73d53fe726a..18e15970dcb 100644
--- a/engines/ngi/gameloader.cpp
+++ b/engines/ngi/gameloader.cpp
@@ -38,7 +38,7 @@ Inventory *getGameLoaderInventory() {
 }
 
 static MotionController *getMotionControllerBySceneId(int16 sceneId) {
-	if (g_nmi->getPlatform() == Common::kPlatformAndroid) {
+	if (g_nmi->_gameVersion >= 201509) {
 		Scene *scene = g_nmi->findScene(sceneId);
 		return scene ? scene->_motionController.get() : nullptr;
 	}
@@ -77,7 +77,7 @@ GameLoader::GameLoader() {
 	_interactionController = new InteractionController();
 	_inputController = new CursorController();
 
-	if (g_nmi->getPlatform() == Common::kPlatformAndroid) {
+	if (g_nmi->_gameVersion >= 201509) {
 		addMessageHandlerByIndex(global_messageHandler4, 0, 4);
 	} else {
 		addMessageHandlerByIndex(global_messageHandler2, 0, 0);
@@ -185,10 +185,10 @@ bool GameLoader::loadScene(int sceneId) {
 }
 
 bool GameLoader::setScene(int sceneId, int entranceId) {
-	const bool android = g_nmi->getPlatform() == Common::kPlatformAndroid;
+	const bool xmlEntrances = g_nmi->usesXMLProject();
 	Scene *scene;
 	const Common::Array<Entrance> *entrances;
-	if (android) {
+	if (xmlEntrances) {
 		scene = _gameProject->findScene(sceneId);
 		if (!scene)
 			return false;
@@ -208,10 +208,10 @@ bool GameLoader::setScene(int sceneId, int entranceId) {
 
 	// XML projects may name a start scene without specifying an entrance.
 	const Entrance defaultEntrance = {sceneId, 0, 0, 0};
-	const Entrance *entrance = android && !entranceId ? &defaultEntrance : nullptr;
+	const Entrance *entrance = xmlEntrances && !entranceId ? &defaultEntrance : nullptr;
 	for (const Entrance &entry : *entrances) {
 		// The original desktop workaround uses the first entrance in scene 726.
-		if ((!android && sceneId == 726) || (entry._id == entranceId && (!android || entry._sceneId == sceneId))) {
+		if ((!xmlEntrances && sceneId == 726) || (entry._id == entranceId && (!xmlEntrances || entry._sceneId == sceneId))) {
 			entrance = &entry;
 			break;
 		}
@@ -230,7 +230,7 @@ bool GameLoader::setScene(int sceneId, int entranceId) {
 		return false;
 
 	g_nmi->_currentScene = scene;
-	if (android) {
+	if (xmlEntrances) {
 		if (entrance->_queueId && !runQueue(entrance->_queueId, 0))
 			return false;
 		debugC(1, kDebugSceneLogic, "Entered Android scene %d through entrance %d, queue %d", sceneId, entranceId, entrance->_queueId);
@@ -381,7 +381,7 @@ bool GameLoader::preloadScene(int sceneId, int entranceId) {
 
 	// XML entrances identify their destination directly. The frame loop commits
 	// the pending change once the current dialog has closed.
-	if (g_nmi->getPlatform() == Common::kPlatformAndroid || _preloadSceneId != sceneId || _preloadEntranceId != entranceId) {
+	if (g_nmi->_gameVersion >= 201509 || _preloadSceneId != sceneId || _preloadEntranceId != entranceId) {
 		_preloadSceneId = sceneId;
 		_preloadEntranceId = entranceId;
 		return true;
@@ -584,7 +584,7 @@ PicAniInfoList GameLoader::savePicAniInfos(Scene *sc, int flag1, int flag2) {
 bool GameLoader::updateContent(int counterdiff) {
 	if (g_nmi->_currentScene) {
 		bool changed = g_nmi->_currentScene->update(counterdiff);
-		if (g_nmi->getPlatform() == Common::kPlatformAndroid)
+		if (g_nmi->_gameVersion >= 201509)
 			return changed;
 
 		_exCommand._cmd = 17;
diff --git a/engines/ngi/gameloader.h b/engines/ngi/gameloader.h
index f19fde744c7..f4dca09bdc3 100644
--- a/engines/ngi/gameloader.h
+++ b/engines/ngi/gameloader.h
@@ -91,7 +91,7 @@ class GameLoader : public CObject {
 
 	bool load(MfcArchive &file) override;
 	bool loadScene(int sceneId);
-	Common::Error loadXML(const SceneTag *&start, int &width, int &height);
+	Common::Error loadXML(const Common::Path &projectPath, const SceneTag *&start, int &width, int &height);
 	bool setScene(int sceneId, int entranceId);
 	bool preloadScene(int sceneId, int entranceId);
 	bool unloadScene(int sceneId);
diff --git a/engines/ngi/gfx.cpp b/engines/ngi/gfx.cpp
index 0a5758933b7..17834f2caba 100644
--- a/engines/ngi/gfx.cpp
+++ b/engines/ngi/gfx.cpp
@@ -143,7 +143,7 @@ bool PictureObject::load(MfcArchive &file, bool bigPicture) {
 }
 
 void PictureObject::render(Common::Point scroll) {
-	if (g_nmi->getPlatform() == Common::kPlatformAndroid) {
+	if (g_nmi->_gameVersion >= 201509) {
 		_picture->blitTo(g_nmi->_backgroundSurface, Common::Point(_x, _y) - scroll);
 		return;
 	}
diff --git a/engines/ngi/messagehandlers.cpp b/engines/ngi/messagehandlers.cpp
index 6433cbb66d2..13020bb53f1 100644
--- a/engines/ngi/messagehandlers.cpp
+++ b/engines/ngi/messagehandlers.cpp
@@ -531,7 +531,7 @@ int global_messageHandler4(Command *cmd) {
 			break;
 		}
 		int parent = cmd->_parId;
-		if (g_nmi->getPlatform() == Common::kPlatformAndroid && !cmd->_wait)
+		if (g_nmi->_gameVersion >= 201509 && !cmd->_wait)
 			parent = 0;
 		MessageQueue *mq = new MessageQueue(source, parent, 0);
 
@@ -686,7 +686,7 @@ int global_messageHandler4(Command *cmd) {
 		if (cmd->_z >= 0)
 			ani->_z = cmd->_z;
 
-		if (g_nmi->getPlatform() == Common::kPlatformAndroid) {
+		if (g_nmi->_gameVersion >= 201509) {
 			const bool mirror = cmd->_auxParam < 0 ? (ani->_flags & 8) != 0 : cmd->_auxParam != 0;
 			ani->show1(cmd->_x == -1 ? ani->_x : cmd->_x, cmd->_y == -1 ? ani->_y : cmd->_y, cmd->_messageNum, 0);
 			ani->_flags = (ani->_flags & ~8) | (mirror ? 8 : 0);
@@ -750,7 +750,7 @@ int global_messageHandler4(Command *cmd) {
 		break;
 
 	case 63:
-		if (g_nmi->getPlatform() != Common::kPlatformAndroid)
+		if (g_nmi->_gameVersion < 201509)
 			return 0;
 		warning("Android command %s not implemented", cmd->_messageName.c_str());
 		break;
diff --git a/engines/ngi/messages.cpp b/engines/ngi/messages.cpp
index e6dd95a7539..9de446ba421 100644
--- a/engines/ngi/messages.cpp
+++ b/engines/ngi/messages.cpp
@@ -456,7 +456,7 @@ void MessageQueue::next() {
 		ex->_excFlags |= (ex->_wait == 0 ? 1 : 0) | (ex->_field_3C != 0 ? 2 : 0);
 
 		_flags |= 4;
-		if (ex->_cmd == Command::kCmdPause && ex->_wait && g_nmi->getPlatform() == Common::kPlatformAndroid)
+		if (ex->_cmd == Command::kCmdPause && ex->_wait && g_nmi->_gameVersion >= 201509)
 			_pauseCommand.reset(ex);
 		else
 			ex->sendMessage();
diff --git a/engines/ngi/metaengine.cpp b/engines/ngi/metaengine.cpp
index 0ffbeba46dc..9ae18380dfc 100644
--- a/engines/ngi/metaengine.cpp
+++ b/engines/ngi/metaengine.cpp
@@ -51,6 +51,10 @@ Common::Language NGIEngine::getLanguage() const {
 	return _gameDescription->desc.language;
 }
 
+bool NGIEngine::isAndroidFullPipe() const {
+	return getGameGID() == GID_FULLPIPE && getPlatform() == Common::kPlatformAndroid;
+}
+
 Common::Platform NGIEngine::getPlatform() const {
 	return _gameDescription->desc.platform;
 }
diff --git a/engines/ngi/module.mk b/engines/ngi/module.mk
index af235e56df7..cfa87b12a7a 100644
--- a/engines/ngi/module.mk
+++ b/engines/ngi/module.mk
@@ -1,7 +1,6 @@
 MODULE := engines/ngi
 
 MODULE_OBJS = \
-	android.o \
 	anihandler.o \
 	behavior.o \
 	console.o \
@@ -27,6 +26,7 @@ MODULE_OBJS = \
 	sound.o \
 	stateloader.o \
 	statesaver.o \
+	xmlproject.o \
 	statics.o \
 	utils.o \
 	fullpipe/sceneChapter.o \
diff --git a/engines/ngi/motion.cpp b/engines/ngi/motion.cpp
index 2bd8159a46b..1cab2db3c76 100644
--- a/engines/ngi/motion.cpp
+++ b/engines/ngi/motion.cpp
@@ -789,7 +789,7 @@ GrPathDesc *getPreferredPath(AniObject *ani, Common::Array<PathDesc *> *items, s
 MovGraph::MovGraph() {
 	_selFunc = getPreferredPath;
 	_linkItemOffset = 0;
-	if (g_nmi->getPlatform() != Common::kPlatformAndroid)
+	if (g_nmi->_gameVersion < 201509)
 		insertMessageHandler(MovGraph::messageHandler, getMessageHandlersCount() - 1, 129);
 
 	_objtype = kObjTypeMovGraph;
@@ -1353,12 +1353,12 @@ double MovGraph::putToLink(Common::Point *point, MovGraphLink *link, int fuzzyMa
 	double dist1y = (double)(n1y - point->y);
 	double dist2x = (double)(n2x - n1x);
 	double dist2y = (double)(n1y - n2y);
-	const bool android = g_nmi->getPlatform() == Common::kPlatformAndroid;
+	const bool revisedGraph = g_nmi->_gameVersion >= 201509;
 	double length = link->_length;
 	double radiusSquared = dist1x * dist1x + dist1y * dist1y;
-	double dist1 = android ? sqrtf(radiusSquared) : sqrt(radiusSquared);
+	double dist1 = revisedGraph ? sqrtf(radiusSquared) : sqrt(radiusSquared);
 	double dot = dist2y * dist1y + dist2x * dist1x;
-	if (android) {
+	if (revisedGraph) {
 		// The XML length bounds the segment, but PutToLink normalizes by the node separation.
 		length = sqrtf(dist2x * dist2x + dist2y * dist2y);
 		dot = static_cast<float>(dot);
@@ -1368,13 +1368,13 @@ double MovGraph::putToLink(Common::Point *point, MovGraphLink *link, int fuzzyMa
 	double dist2 = dot / length / dist1;
 	double distm = dist2 * dist1;
 	double sinSquared = 1.0 - dist2 * dist2;
-	double res = sqrt(android ? fabs(sinSquared) : sinSquared) * dist1;
+	double res = sqrt(revisedGraph ? fabs(sinSquared) : sinSquared) * dist1;
 
 	// Android accepts the perpendicular through the source within one link length.
-	if (android && dist2 == 0.0 && res <= link->_length)
+	if (revisedGraph && dist2 == 0.0 && res <= link->_length)
 		return 0.0;
 
-	if (dist2 <= 0.0 || (android ? distm > link->_length : distm >= link->_length)) {
+	if (dist2 <= 0.0 || (revisedGraph ? distm > link->_length : distm >= link->_length)) {
 		if (fuzzyMatch) {
 			if (dist2 > 0.0) {
 				if (distm >= link->_length) {
@@ -1779,7 +1779,7 @@ bool MctlGraph::fillData(AniObject *obj, GmctlAni &item) {
 
 	const ObjectIdList *ids = nullptr;
 	GameVar *walkData;
-	if (g_nmi->getPlatform() == Common::kPlatformAndroid) {
+	if (g_nmi->_gameVersion >= 201509) {
 		ids = &g_nmi->_gameProject->_objectIds;
 		walkData = g_nmi->_gameProject->_walkData.getSubVarByName(ids->findName(static_cast<uint16>(obj->_id)));
 	} else {
@@ -2147,7 +2147,7 @@ MessageQueue *MctlGraph::makeQueue(AniObject *obj, int xpos, int ypos, int fuzzy
 	obj->getPicAniInfo(picAniInfo);
 
 	int idxsub;
-	const bool mirror = g_nmi->getPlatform() == Common::kPlatformAndroid && (obj->_flags & 8);
+	const bool mirror = g_nmi->_gameVersion >= 201509 && (obj->_flags & 8);
 
 	if (obj->_movement)
 		idxsub = getDirByMovement(idx, obj->_movement->_id, mirror);
@@ -2656,7 +2656,7 @@ MovGraphLink *MctlGraph::getHitLink(int x, int y, int idx, int fuzzyMatch) {
 	debugC(4, kDebugPathfinding, "MctlGraph::getHitLink(...)");
 
 	Common::Point point;
-	const double tolerance = g_nmi->getPlatform() == Common::kPlatformAndroid ? 3.0 : 2.0;
+	const double tolerance = g_nmi->_gameVersion >= 201509 ? 3.0 : 2.0;
 	MovGraphLink *res = nullptr;
 
 	for (LinkList::iterator i = _links.begin(); i != _links.end(); ++i) {
@@ -2692,8 +2692,8 @@ MovGraphLink *MctlGraph::getHitLink(int x, int y, int idx, int fuzzyMatch) {
 MovGraphLink *MctlGraph::getNearestLink(int x, int y) {
 	debugC(4, kDebugPathfinding, "MctlGraph::getNearestLink(...)");
 
-	const bool android = g_nmi->getPlatform() == Common::kPlatformAndroid;
-	double mindist = android ? 70.0 : 1.0e20;
+	const bool revisedGraph = g_nmi->_gameVersion >= 201509;
+	double mindist = revisedGraph ? 70.0 : 1.0e20;
 	MovGraphLink *res = nullptr;
 
 	for (LinkList::iterator i = _links.begin(); i != _links.end(); ++i) {
@@ -2709,9 +2709,9 @@ MovGraphLink *MctlGraph::getNearestLink(int x, int y) {
 			double n1dx = x - n1x;
 			double n1dy = n1y - y;
 			double radiusSquared = n1dy * n1dy + n1dx * n1dx;
-			double dst1 = android ? sqrtf(radiusSquared) : sqrt(radiusSquared);
+			double dst1 = revisedGraph ? sqrtf(radiusSquared) : sqrt(radiusSquared);
 			double dot = (n1y - n2y) * n1dy + (n2x - n1x) * n1dx;
-			if (android) {
+			if (revisedGraph) {
 				dot = static_cast<float>(dot);
 				if (!dst1 || !lnk->_length)
 					continue;
@@ -2925,14 +2925,14 @@ bool ReactParallel::load(MfcArchive &file) {
 void ReactParallel::create() {
 	_points.resize(4);
 
-	const bool android = g_nmi->getPlatform() == Common::kPlatformAndroid;
-	double angle = android ? atan2f(_y1 - _y2, _x1 - _x2) : atan2((double)(_y1 - _y2), (double)(_x1 - _x2));
+	const bool revisedGraph = g_nmi->_gameVersion >= 201509;
+	double angle = revisedGraph ? atan2f(_y1 - _y2, _x1 - _x2) : atan2((double)(_y1 - _y2), (double)(_x1 - _x2));
 	double at = angle + 1.570796; // pi/2
 	double sn = sin(at);
 	double cs = cos(at);
 	double lx = _left * cs, ly = _left * sn;
 	double rx = _right * cs, ry = _right * sn;
-	if (android) {
+	if (revisedGraph) {
 		// The XML engine truncates the offsets before adding them to each endpoint.
 		lx = (int)lx;
 		ly = (int)ly;
@@ -3031,7 +3031,7 @@ Common::Rect ReactPolygonal::getBBox() {
 
 
 bool MovGraphReact::hitTest(int x, int y) {
-	if (g_nmi->getPlatform() == Common::kPlatformAndroid) {
+	if (g_nmi->_gameVersion >= 201509) {
 		if (_points.size() <= 1)
 			return !_points.empty() && _points[0] == Common::Point(x, y);
 		bool inside = false;
diff --git a/engines/ngi/ngi.cpp b/engines/ngi/ngi.cpp
index e8b5a17e9da..00c289a5cd9 100644
--- a/engines/ngi/ngi.cpp
+++ b/engines/ngi/ngi.cpp
@@ -52,6 +52,7 @@ Vars *g_vars = nullptr;
 NGIEngine::NGIEngine(OSystem *syst, const NGIGameDescription *gameDesc) :
 	Engine(syst),
 	_gameDescription(gameDesc),
+	_gameVersion(gameDesc->gameVersion),
 	_rnd("ngi"),
 	_gameProject(nullptr),
 	_modalObject(nullptr),
@@ -338,13 +339,15 @@ bool NGIEngine::handleGuiEvent(const Common::Event &event) {
 Common::Error NGIEngine::run() {
 	_globalMessageQueueList.reset(new GlobalMessageQueueList);
 	_aniHandler.reset(new AniHandler);
-	const bool android = getPlatform() == Common::kPlatformAndroid;
+	const bool timedUpdates = _gameVersion >= 201509;
 	const SceneTag *start = nullptr;
 	int width = 800, height = 600;
 	Common::Error result = Common::kNoError;
-	if (android) {
+	if (usesXMLProject()) {
+		if (getGameGID() != GID_FULLPIPE)
+			return Common::kUnsupportedGameidError;
 		_gameLoader.reset(new GameLoader());
-		result = _gameLoader->loadXML(start, width, height);
+		result = _gameLoader->loadXML("data/FullPipe.xml", start, width, height);
 		if (result.getCode() != Common::kNoError)
 			return result;
 		_gameProject = _gameLoader->_gameProject.get();
@@ -357,7 +360,7 @@ Common::Error NGIEngine::run() {
 	_backgroundSurface.create(width, height, format);
 	_isSaveAllowed = false;
 
-	if (android) {
+	if (usesXMLProject()) {
 		Common::Keymapper *mapper = _system->getEventManager()->getKeymapper();
 		mapper->disableAllGameKeymaps();
 		mapper->setGameKeymapState("ngi-default", true);
@@ -369,9 +372,9 @@ Common::Error NGIEngine::run() {
 			return result;
 	}
 
-	const bool intro = android && start->_sceneId == SC_INTRO1;
+	const bool intro = start && isAndroidFullPipe() && start->_sceneId == SC_INTRO1;
 	byte brightness = intro ? 0 : 255;
-	if (android) {
+	if (usesXMLProject()) {
 		if (brightness)
 			_currentScene->render();
 		else
@@ -388,17 +391,17 @@ Common::Error NGIEngine::run() {
 			break;
 		const uint32 now = _system->getMillis();
 		const uint32 elapsed = now - lastUpdate;
-		if (android || elapsed >= 33 || !_normalSpeed) {
+		if (timedUpdates || elapsed >= 33 || !_normalSpeed) {
 			lastUpdate = now;
 			// CGame::Update discounts long stalls on Android.
 			uint32 step = 42;
-			if (android)
+			if (timedUpdates)
 				step = elapsed > 350 ? 15 : elapsed;
 			result = updateScreen(step, brightness, redraw);
 			if (result.getCode() != Common::kNoError)
 				break;
 		}
-		if (!android && _needRestart) {
+		if (!timedUpdates && _needRestart) {
 			delete _modalObject;
 			freeGameLoader();
 			_currentScene = nullptr;
@@ -410,10 +413,10 @@ Common::Error NGIEngine::run() {
 		}
 
 		_system->updateScreen();
-		_system->delayMillis(android ? 10 : 5);
+		_system->delayMillis(timedUpdates ? 10 : 5);
 	}
 
-	if (android) {
+	if (usesXMLProject()) {
 		deleteModalObject();
 		clearMessages();
 		clearGlobalMessageQueueList();
@@ -443,7 +446,7 @@ bool NGIEngine::updateEvents() {
 	bool redraw = false;
 
 	while (eventMan->pollEvent(event)) {
-		if (getPlatform() == Common::kPlatformAndroid) {
+		if (_gameVersion >= 201509) {
 			redraw |= handleGuiEvent(event);
 			continue;
 		}
@@ -596,28 +599,28 @@ void NGIEngine::deleteModalObject() {
 }
 
 Common::Error NGIEngine::updateScreen(uint32 elapsed, byte &brightness, bool redraw) {
-	const bool android = getPlatform() == Common::kPlatformAndroid;
+	const bool timedUpdates = _gameVersion >= 201509;
 	_mouseVirtX = _mouseScreenPos.x + _sceneRect.left;
 	_mouseVirtY = _mouseScreenPos.y + _sceneRect.top;
 
 	Scene *scene = _currentScene;
 	const bool hadModal = _modalObject != nullptr;
-	if (!hadModal && (android || _flgGameIsRunning)) {
+	if (!hadModal && (timedUpdates || _flgGameIsRunning)) {
 		redraw |= _gameLoader->updateContent(elapsed);
-		if (android && !_modalObject && scene == _currentScene && scene->_sceneId == SC_INTRO1)
+		if (isAndroidFullPipe() && !_modalObject && scene == _currentScene && scene->_sceneId == SC_INTRO1)
 			redraw |= sceneIntro_updateAndroid(elapsed, brightness);
-		if (android)
+		if (timedUpdates)
 			processMessages();
 	}
 	const bool renderScene = !_modalObject;
-	if (_modalObject && (android || _flgGameIsRunning)) {
+	if (_modalObject && (timedUpdates || _flgGameIsRunning)) {
 		// Android begins updating a newly opened dialog on the following tick.
-		if ((!android || hadModal) && !_modalObject->init(elapsed))
+		if ((!timedUpdates || hadModal) && !_modalObject->init(elapsed))
 			deleteModalObject();
 		redraw = true;
 	}
 
-	if (android && scene != _currentScene) {
+	if (timedUpdates && scene != _currentScene) {
 		if (scene->_guiManager)
 			scene->_guiManager->onHide();
 		stopAllSounds(Sound::kSpeech);
@@ -627,7 +630,7 @@ Common::Error NGIEngine::updateScreen(uint32 elapsed, byte &brightness, bool red
 		debugC(2, kDebugDrawing, "Switched Android scene from %d to %d", scene->_sceneId, _currentScene->_sceneId);
 		redraw = true;
 	}
-	if (android && !_modalObject && _gameLoader->_preloadSceneId) {
+	if (timedUpdates && !_modalObject && _gameLoader->_preloadSceneId) {
 		if (!_gameLoader->setScene(_gameLoader->_preloadSceneId, _gameLoader->_preloadEntranceId))
 			return Common::Error(Common::kNoGameDataFoundError, "Could not enter the requested Android scene");
 		_gameLoader->_preloadSceneId = _gameLoader->_preloadEntranceId = 0;
@@ -636,9 +639,9 @@ Common::Error NGIEngine::updateScreen(uint32 elapsed, byte &brightness, bool red
 	}
 
 	if (_modalObject) {
-		if (android || _flgGameIsRunning)
+		if (timedUpdates || _flgGameIsRunning)
 			_modalObject->update();
-	} else if (_currentScene && (android ? redraw : renderScene)) {
+	} else if (_currentScene && (timedUpdates ? redraw : renderScene)) {
 		_currentScene->render();
 		if (_inventoryScene)
 			_inventory->render();
@@ -648,7 +651,7 @@ Common::Error NGIEngine::updateScreen(uint32 elapsed, byte &brightness, bool red
 			drawAlphaRectangle(0, 0, _backgroundSurface.w, _backgroundSurface.h, brightness);
 	}
 
-	if (android) {
+	if (timedUpdates) {
 		if (redraw)
 			_system->copyRectToScreen(_backgroundSurface.getPixels(), _backgroundSurface.pitch, 0, 0, _backgroundSurface.w, _backgroundSurface.h);
 	} else {
diff --git a/engines/ngi/ngi.h b/engines/ngi/ngi.h
index 271563da54a..feb50974d19 100644
--- a/engines/ngi/ngi.h
+++ b/engines/ngi/ngi.h
@@ -144,10 +144,13 @@ public:
 
 	// Detection related functions
 	const NGIGameDescription *_gameDescription;
+	const uint32 _gameVersion;
+	bool usesXMLProject() const { return _gameVersion >= 200502; }
+	bool isAndroidFullPipe() const;
 	uint32 getFeatures() const;
 	bool isDemo();
 	Common::Language getLanguage() const;
-	const char *getAndroidResourceLocale() const;
+	const char *getResourceLocale() const;
 	Common::Platform getPlatform() const;
 	const char *getGameId() const;
 	int getGameGID() const;
@@ -391,7 +394,7 @@ public:
 	Common::Error saveGameState(int slot, const Common::String &description, bool isAutosave = false) override;
 	Common::String getSaveStateName(int slot) const override;
 
-	bool canLoadGameStateCurrently(Common::U32String *msg = nullptr) override { return getPlatform() != Common::kPlatformAndroid; }
+	bool canLoadGameStateCurrently(Common::U32String *msg = nullptr) override { return !usesXMLProject(); }
 	bool canSaveGameStateCurrently(Common::U32String *msg = nullptr) override { return _isSaveAllowed; }
 	bool hasFeature(EngineFeature f) const override;
 
diff --git a/engines/ngi/scene.cpp b/engines/ngi/scene.cpp
index 0ed82d73325..177b026938b 100644
--- a/engines/ngi/scene.cpp
+++ b/engines/ngi/scene.cpp
@@ -45,7 +45,7 @@ Scene *GameProject::findScene(int sceneId) {
 		if (tag._sceneId != sceneId)
 			continue;
 		if (!tag._scene) {
-			if (g_nmi->getPlatform() == Common::kPlatformAndroid) {
+			if (g_nmi->usesXMLProject()) {
 				tag.loadSceneXML(*this);
 				if (tag._scene && tag._scene->_guiManager)
 					tag._scene->_guiManager->load(*this);
@@ -348,7 +348,7 @@ void Scene::stopAllSounds() {
 }
 
 PictureObject *Scene::findPictureObjectById(int objId, int flags) {
-	for (uint i = g_nmi->getPlatform() == Common::kPlatformAndroid ? 0 : 1; i < _pictureObjects.size(); i++) {
+	for (uint i = g_nmi->_gameVersion >= 201509 ? 0 : 1; i < _pictureObjects.size(); i++) {
 		if (_pictureObjects[i]->_id == objId && _pictureObjects[i]->_copyId == flags)
 			return _pictureObjects[i];
 	}
@@ -459,7 +459,7 @@ template<typename T>
 void Scene::sortRenderables(Common::Array<T *> &list, uint startIndex) {
 	// The XML loader saves the declaration order across pictures and animations.
 	// Binary scenes retain their current list order at equal priority.
-	const bool xml = g_nmi->getPlatform() == Common::kPlatformAndroid;
+	const bool xml = g_nmi->_gameVersion >= 201509;
 	for (uint i = startIndex + 1; i < list.size(); ++i) {
 		T *object = list[i];
 		uint j = i;
@@ -476,7 +476,7 @@ void Scene::sortRenderables(Common::Array<T *> &list, uint startIndex) {
 void Scene::render() {
 	debugC(6, kDebugDrawing, ">>>>> Scene::render()");
 	g_nmi->_backgroundSurface.clear(0);
-	if (g_nmi->getPlatform() == Common::kPlatformAndroid) {
+	if (g_nmi->_gameVersion >= 201509) {
 		Common::Array<GameObject *> visibleObjects;
 		for (PictureObject *picture : _pictureObjects) {
 			if (picture->_flags & 4)
@@ -650,7 +650,7 @@ bool Scene::update(int counterdiff) {
 	debugC(6, kDebugDrawing, "Scene::update(%d)", counterdiff);
 
 	bool changed = false;
-	if (g_nmi->getPlatform() == Common::kPlatformAndroid) {
+	if (g_nmi->_gameVersion >= 201509) {
 		if (_behaviorController)
 			changed |= _behaviorController->update(counterdiff);
 		for (MessageQueue *queue : *g_nmi->_globalMessageQueueList)
diff --git a/engines/ngi/scenes.cpp b/engines/ngi/scenes.cpp
index 1699119f9c6..c197d29c025 100644
--- a/engines/ngi/scenes.cpp
+++ b/engines/ngi/scenes.cpp
@@ -575,10 +575,10 @@ bool NGIEngine::doSetScene(const Entrance &entrance) {
 	if (!scene)
 		return 0;
 
-	if (getPlatform() == Common::kPlatformAndroid) {
+	if (usesXMLProject()) {
 		Scene *common = findScene(SC_COMMON);
-		Scene *intro2 = scene->_sceneId == SC_INTRO1 ? findScene(SC_INTRO2) : nullptr;
-		if (scene->_sceneId == SC_INTRO1 && (!common || !intro2))
+		Scene *intro2 = isAndroidFullPipe() && scene->_sceneId == SC_INTRO1 ? findScene(SC_INTRO2) : nullptr;
+		if (isAndroidFullPipe() && scene->_sceneId == SC_INTRO1 && (!common || !intro2))
 			return false;
 		scene->_commonQueueScene = common == scene ? nullptr : common;
 		for (const PicAniInfo &ref : scene->_roamingObjects) {
@@ -619,7 +619,7 @@ bool NGIEngine::doSetScene(const Entrance &entrance) {
 			sceneIntro_initGui(*scene, *intro2, _backgroundSurface.w);
 			sceneIntro_initMan(*scene);
 			addMessageHandler(sceneHandlerIntro, 2);
-		} else if (scene->_sceneId == SC_1) {
+		} else if (isAndroidFullPipe() && scene->_sceneId == SC_1) {
 			scene01_initObjects(scene, entrance._id, true);
 			addMessageHandler(sceneHandler01, 2);
 		}
diff --git a/engines/ngi/sound.cpp b/engines/ngi/sound.cpp
index fe08e564ab5..6d5e5c09f7a 100644
--- a/engines/ngi/sound.cpp
+++ b/engines/ngi/sound.cpp
@@ -214,8 +214,8 @@ void Sound::play(int loop, int creator) {
 	Audio::SoundHandle *handle = getHandle();
 
 	Audio::RewindableAudioStream *stream = nullptr;
-	const bool android = g_nmi->getPlatform() == Common::kPlatformAndroid;
-	if (android) {
+	const bool streamedSound = g_nmi->_gameVersion >= 201509;
+	if (streamedSound) {
 #ifdef USE_VORBIS
 		Common::SeekableReadStream *data = SearchMan.createReadStreamForMember(_memfilename);
 		if (data)
@@ -232,7 +232,7 @@ void Sound::play(int loop, int creator) {
 	}
 	Audio::AudioStream *audioStream = new Audio::LoopingAudioStream(stream, (loop == 1) ? 0 : 1);
 
-	if (android) {
+	if (streamedSound) {
 		// The last creator stops all instances of a non-looping phase sound.
 		_objectId = loop ? 0 : creator;
 		for (uint i = _overlappingHandles.size(); i > 0; --i) {
@@ -244,7 +244,7 @@ void Sound::play(int loop, int creator) {
 	} else {
 		g_nmi->_mixer->stopHandle(*handle);
 	}
-	const Audio::Mixer::SoundType type = android && _flags == kMusic ? Audio::Mixer::kMusicSoundType : Audio::Mixer::kSFXSoundType;
+	const Audio::Mixer::SoundType type = streamedSound && _flags == kMusic ? Audio::Mixer::kMusicSoundType : Audio::Mixer::kSFXSoundType;
 	g_nmi->_mixer->playStream(type, handle, audioStream);
 	debugC(3, kDebugEvents, "Playing sound %d (%s), loop %d", _id, _memfilename.toString().c_str(), loop);
 }
@@ -520,7 +520,7 @@ void global_messageHandler_handleSound(Command *cmd) {
 		return;
 
 	if (cmd->_z & 1) {
-		if (g_nmi->getPlatform() == Common::kPlatformAndroid) {
+		if (g_nmi->_gameVersion >= 201509) {
 			snd->play(cmd->_param);
 			return;
 		}
diff --git a/engines/ngi/statics.cpp b/engines/ngi/statics.cpp
index 43e884fb3c9..98d15e352fc 100644
--- a/engines/ngi/statics.cpp
+++ b/engines/ngi/statics.cpp
@@ -551,7 +551,7 @@ Statics *AniObject::addReverseStatics(Statics *st) {
 }
 
 void AniObject::render(Common::Point scroll) {
-	if (g_nmi->getPlatform() == Common::kPlatformAndroid) {
+	if (g_nmi->_gameVersion >= 201509) {
 		const Phase *phase = _movement ? _movement->_curPhase : _statics;
 		if (phase && (_flags & 4)) {
 			Common::Point anchor = getSomeXY();
@@ -756,8 +756,8 @@ bool AniObject::update(int counterdiff) {
 	if (_movement) {
 		_movement->_counter += counterdiff;
 
-		const bool android = g_nmi->getPlatform() == Common::kPlatformAndroid;
-		if (android) {
+		const bool timedMovement = g_nmi->_gameVersion >= 201509;
+		if (timedMovement) {
 			const Phase &phase = *_movement->_curPhase;
 			const int delay = _movement->_loopDelay * (1 + phase._delayRelative) + phase._delayMs;
 			if (_movement->_counter <= delay)
@@ -776,7 +776,7 @@ bool AniObject::update(int counterdiff) {
 			}
 
 			Phase *dyn = _movement->_curPhase;
-			if (!android && dyn->_delay == dyn->_countdown) {
+			if (!timedMovement && dyn->_delay == dyn->_countdown) {
 
 				ex = dyn->getCommand();
 				if (ex && ex->_cmd != 35) {
@@ -804,13 +804,13 @@ bool AniObject::update(int counterdiff) {
 			}
 
 			// Android ends the movement as soon as the next statics takes over.
-			if (!_movement->setNext(_callback1, _callback2, android && (_flags & 8)) || (android && _movement->_curPhase == _movement->_nextStatic)) {
+			if (!_movement->setNext(_callback1, _callback2, timedMovement && (_flags & 8)) || (timedMovement && _movement->_curPhase == _movement->_nextStatic)) {
 				stopMovement();
 			} else {
 				setPos(_movement->_x, _movement->_y);
 				_counter = _initialCounter;
 
-				if (android) {
+				if (timedMovement) {
 					_movement->_curPhase->enter(_id);
 				} else if (dyn->_delay == dyn->_countdown) {
 					ex = dyn->getCommand();
@@ -966,7 +966,7 @@ L12:
 		_statics->_x = _x - point.x;
 		_statics->_y = _y - point.y;
 		oid = _movement->_id;
-		if (g_nmi->getPlatform() == Common::kPlatformAndroid) {
+		if (g_nmi->_gameVersion >= 201509) {
 			_movement->unload();
 			for (int i = 0; i < g_nmi->_currSoundListCount; ++i)
 				g_nmi->_currSoundList1[i]->stopByCreator(_id);
@@ -1261,10 +1261,10 @@ bool AniObject::startMovement(int movementId, int messageQueueId, int dynPhaseId
 		return false;
 	}
 
-	const bool android = g_nmi->getPlatform() == Common::kPlatformAndroid;
+	const bool timedMovement = g_nmi->_gameVersion >= 201509;
 	Movement *mov = getMovement(movementId);
 	// An XML movement without any PHASE elements contains only its end pose.
-	if (!mov || (android && !mov->getPhase(1))) {
+	if (!mov || (timedMovement && !mov->getPhase(1))) {
 		updateGlobalMessageQueue(messageQueueId, _id);
 		return false;
 	}
@@ -1280,7 +1280,7 @@ bool AniObject::startMovement(int movementId, int messageQueueId, int dynPhaseId
 	int newy = _y;
 	Common::Point point;
 
-	if (android && !_movement) {
+	if (timedMovement && !_movement) {
 		// SetStatic reflects a change of facing about the old texture's center.
 		const bool prevMirror = mirror != mov->_mirrorPrev;
 		if (_statics && prevMirror != ((_flags & 8) != 0)) {
@@ -1325,7 +1325,7 @@ bool AniObject::startMovement(int movementId, int messageQueueId, int dynPhaseId
 			_stepArray.gotoNextPoint();
 
 			Command *ex = _movement->_curPhase->getCommand();
-			if (ex && !android) {
+			if (ex && !timedMovement) {
 				if (ex->_cmd == 35) {
 					Command *newex = ex->createClone();
 					newex->_excFlags |= 2;
@@ -1339,7 +1339,7 @@ bool AniObject::startMovement(int movementId, int messageQueueId, int dynPhaseId
 	newx += point.x;
 	setPos(mirror ? -newx : newx, point.y + newy);
 
-	if (mirror || (!android && (_movement->_nextStatic->_staticsId & 0x4000)))
+	if (mirror || (!timedMovement && (_movement->_nextStatic->_staticsId & 0x4000)))
 		_flags |= 8;
 	else
 		_flags &= 0xFFF7;
@@ -1362,7 +1362,7 @@ bool AniObject::startMovement(int movementId, int messageQueueId, int dynPhaseId
 
 	newex->postMessage();
 
-	if (android)
+	if (timedMovement)
 		mov->_curPhase->enter(_id);
 
 	return true;
@@ -1905,7 +1905,7 @@ void Movement::load() {
 }
 
 void Movement::unload() {
-	if (g_nmi->getPlatform() == Common::kPlatformAndroid) {
+	if (g_nmi->_gameVersion >= 201509) {
 		// XML movements borrow their last phase from the actor's statics.
 		for (uint i = 0; i + 1 < _phases.size(); ++i)
 			_phases[i]->unload();
diff --git a/engines/ngi/android.cpp b/engines/ngi/xmlproject.cpp
similarity index 97%
rename from engines/ngi/android.cpp
rename to engines/ngi/xmlproject.cpp
index 6debdbbd5e8..3004944e5e8 100644
--- a/engines/ngi/android.cpp
+++ b/engines/ngi/xmlproject.cpp
@@ -940,7 +940,7 @@ private:
 
 } // End of anonymous namespace
 
-const char *NGIEngine::getAndroidResourceLocale() const {
+const char *NGIEngine::getResourceLocale() const {
 	Common::Language language = Common::parseLanguage(ConfMan.get("language"));
 	if (language == Common::UNK_LANG)
 		language = Common::parseLanguageFromLocale(g_system->getSystemLanguage().c_str());
@@ -959,7 +959,7 @@ void SceneTag::loadSceneXML(const GameProject &project) {
 	Common::ScopedPtr<Scene> scene(new Scene());
 	scene->_sceneId = _sceneId;
 	const Common::Path path = Common::Path("data/res").join(_tag);
-	XMLSceneParser parser(project, *scene, g_nmi->getAndroidResourceLocale());
+	XMLSceneParser parser(project, *scene, g_nmi->getResourceLocale());
 	if (!parser.loadStream(SearchMan.createReadStreamForMember(path), path.toString()) || !parser.parse()) {
 		warning("Could not load Full Pipe Android scene %s", _tag.c_str());
 		return;
@@ -971,16 +971,18 @@ void SceneTag::loadSceneXML(const GameProject &project) {
 	_scene = scene.release();
 }
 
-Common::Error GameLoader::loadXML(const SceneTag *&start, int &width, int &height) {
-	const auto &files = g_nmi->_gameDescription->desc.filesDescriptions;
-	const Common::FSNode gameDirectory(ConfMan.getPath("path"));
-	Common::ScopedPtr<Common::Archive> apk(Common::makeZipArchive(gameDirectory.getChild(files[0].fileName)));
-	Common::ScopedPtr<Common::Archive> obb(Common::makeZipArchive(gameDirectory.getChild(files[1].fileName)));
-	if (!apk || !obb)
-		return Common::Error(Common::kNoGameDataFoundError, "Could not open the Full Pipe APK and OBB archives");
+Common::Error GameLoader::loadXML(const Common::Path &projectPath, const SceneTag *&start, int &width, int &height) {
+	if (g_nmi->getPlatform() == Common::kPlatformAndroid) {
+		const auto &files = g_nmi->_gameDescription->desc.filesDescriptions;
+		const Common::FSNode gameDirectory(ConfMan.getPath("path"));
+		Common::ScopedPtr<Common::Archive> apk(Common::makeZipArchive(gameDirectory.getChild(files[0].fileName)));
+		Common::ScopedPtr<Common::Archive> obb(Common::makeZipArchive(gameDirectory.getChild(files[1].fileName)));
+		if (!apk || !obb)
+			return Common::Error(Common::kNoGameDataFoundError, "Could not open the Full Pipe APK and OBB archives");
 
-	SearchMan.add("ngi-android-obb", obb.release());
-	SearchMan.add("ngi-android-apk", apk.release());
+		SearchMan.add("ngi-android-obb", obb.release());
+		SearchMan.add("ngi-android-apk", apk.release());
+	}
 
 	_gameProject.reset(new GameProject());
 	GameProject &project = *_gameProject;
@@ -988,7 +990,6 @@ Common::Error GameLoader::loadXML(const SceneTag *&start, int &width, int &heigh
 	if (!project._objectIds.load("data/obj.h"))
 		return Common::Error(Common::kNoGameDataFoundError, "Could not read the Full Pipe Android object IDs");
 
-	const Common::Path projectPath("data/FullPipe.xml");
 	XMLProjectParser parser(project);
 	if (!parser.loadStream(SearchMan.createReadStreamForMember(projectPath), projectPath.toString()) || !parser.parse())
 		return Common::Error(Common::kNoGameDataFoundError, "Could not read the Full Pipe Android project");
@@ -998,7 +999,7 @@ Common::Error GameLoader::loadXML(const SceneTag *&start, int &width, int &heigh
 		return Common::Error(Common::kNoGameDataFoundError, "Could not find the Full Pipe Android start scene");
 	debugC(1, kDebugXML, "Loaded Full Pipe Android project, start scene %s (%hu)",
 		start->_tag.c_str(), static_cast<uint16>(start->_sceneId));
-	if (start->_sceneId == SC_INTRO1) {
+	if (g_nmi->isAndroidFullPipe() && start->_sceneId == SC_INTRO1) {
 		XMLWalkParser walkParser(project._walkData);
 		if (!walkParser.loadFile("data/data.xml") || !walkParser.parse())
 			return Common::Error(Common::kNoGameDataFoundError, "Could not read the Full Pipe Android walking movements");


Commit: c3b10d7246f9dffa1a1fb5952a81579d5c348df1
    https://github.com/scummvm/scummvm/commit/c3b10d7246f9dffa1a1fb5952a81579d5c348df1
Author: Eugene Sandulenko (sev at scummvm.org)
Date: 2026-11-28T14:18:26+01:00

Commit Message:
NGI: Restore Android room one state on entry

Changed paths:
    engines/ngi/fullpipe/scene01.cpp
    engines/ngi/fullpipe/sceneChapter.cpp
    engines/ngi/scenes.cpp
    engines/ngi/xmlproject.cpp


diff --git a/engines/ngi/fullpipe/scene01.cpp b/engines/ngi/fullpipe/scene01.cpp
index 908829b9305..4600a607c91 100644
--- a/engines/ngi/fullpipe/scene01.cpp
+++ b/engines/ngi/fullpipe/scene01.cpp
@@ -48,10 +48,14 @@ void scene01_initObjects(Scene *sc, int entrance, bool eggUncracked) {
 	g_vars->scene01_picSc01Osk2 = sc->findPictureObjectById(PIC_SC1_OSK2, 0);
 	g_vars->scene01_picSc01Osk2->_flags &= 0xFFFB;
 
-	if (eggUncracked) {
+	if (eggUncracked || g_nmi->isAndroidFullPipe()) {
 		PictureObject *pic = sc->findPictureObjectById(PIC_SC1_KUCHKA, 0);
-		if (pic)
-			pic->_flags &= 0xFFFB;
+		if (pic) {
+			if (eggUncracked)
+				pic->_flags &= ~4;
+			else
+				pic->_flags |= 4;
+		}
 	}
 
 	if (entrance != TrubaLeft) {
@@ -63,7 +67,20 @@ void scene01_initObjects(Scene *sc, int entrance, bool eggUncracked) {
 
 void scene01_initScene(Scene *sc, int entrance) {
 	scene01_initObjects(sc, entrance, g_nmi->getStateId(sO_EggCracker) == g_nmi->getStateValue(sO_EggCracker, sO_DidNotCrackEgg));
-	g_nmi->lift_setButton(sO_Level2, ST_LBN_2N);
+	if (g_nmi->isAndroidFullPipe()) {
+		uint32 buttonId;
+		if (g_nmi->_gameProject->_objectIds.findId("ST_LBN_2N", buttonId))
+			g_nmi->lift_setButton(sO_Level2, buttonId);
+		GameVar *root = g_nmi->getGameLoaderGameVar();
+		GameVar *visited = root->getSubVarByName("VISITED");
+		if (!visited->getSubVarAsInt("SC_1")) {
+			sceneChapter_show("CHAPTER_1");
+			root->getSubVarByName("TASKS")->setSubVarAsInt("FIND_BOOT_SC4", 1);
+			visited->setSubVarAsInt("SC_1", 1);
+		}
+	} else {
+		g_nmi->lift_setButton(sO_Level2, ST_LBN_2N);
+	}
 }
 
 int sceneHandler01(Command *cmd) {
@@ -72,14 +89,25 @@ int sceneHandler01(Command *cmd) {
 	if (cmd->_cmd != 17)
 		return 0;
 
-	if (!cmd->_messageNum && !cmd->_messageName.empty()) {
+	if (g_nmi->isAndroidFullPipe() && !cmd->_messageName.empty()) {
 		if (cmd->_messageName == "MSG_ENABLE_BHV_SOUND") {
 			if (g_nmi->_currentScene->_behaviorController)
 				g_nmi->_currentScene->_behaviorController->enableAllMusic();
 			return 0;
 		}
-		warning("Android scene 1 message %s not implemented", cmd->_messageName.c_str());
-		return 0;
+		if (cmd->_messageName == "MSG_DEACT_OBJ_SC1") {
+			Inventory *inventory = getGameLoaderInventory();
+			uint32 blackEgg, coinEgg;
+			const ObjectIdList &ids = g_nmi->_gameProject->_objectIds;
+			if (ids.findId("ANI_INV_EGGBLACK", blackEgg) && ids.findId("ANI_INV_EGGCOIN", coinEgg) &&
+					!inventory->getCountItemsWithId(blackEgg) && !inventory->getCountItemsWithId(coinEgg))
+				g_nmi->getGameLoaderGameVar()->getSubVarByName("TASKS")->setSubVarAsInt("GET_OBJECT_SC1", 0);
+			return 0;
+		}
+		if (!cmd->_messageNum) {
+			warning("STUB: %s", cmd->_messageName.c_str());
+			return 0;
+		}
 	}
 
 	if (cmd->_messageNum > MSG_SC1_SHOWOSK) {
@@ -110,6 +138,9 @@ int sceneHandler01(Command *cmd) {
 		return 0;
 	}
 
+	if (g_nmi->isAndroidFullPipe())
+		return 0; // Scene::update drives timed behavior and audio.
+
 	if (g_nmi->_aniMan2) {
 		if (g_nmi->_aniMan2->_x < g_nmi->_sceneRect.left + 200) {
 			g_nmi->_currentScene->_x = g_nmi->_aniMan2->_x - g_nmi->_sceneRect.left - 300;
diff --git a/engines/ngi/fullpipe/sceneChapter.cpp b/engines/ngi/fullpipe/sceneChapter.cpp
index e41ae9bd7e6..b0c87284c03 100644
--- a/engines/ngi/fullpipe/sceneChapter.cpp
+++ b/engines/ngi/fullpipe/sceneChapter.cpp
@@ -275,11 +275,15 @@ private:
 } // End of anonymous namespace
 
 void sceneChapter_show(const char *chapterId) {
+	GameVar *shown = g_nmi->getGameLoaderGameVar()->getSubVarByName("CHAPTERS");
+	if (shown->getSubVarAsInt(chapterId))
+		return;
 	Scene *scene = g_nmi->findScene(SC_CHAPTER);
 	if (!scene)
 		return;
 	Common::ScopedPtr<ModalChapter> dialog(new ModalChapter(*scene, chapterId));
 	if (dialog->open()) {
+		shown->setSubVarAsInt(chapterId, 1);
 		dialog->_parentObj = g_nmi->_modalObject;
 		g_nmi->_modalObject = dialog.release();
 	}
diff --git a/engines/ngi/scenes.cpp b/engines/ngi/scenes.cpp
index c197d29c025..7485b0af290 100644
--- a/engines/ngi/scenes.cpp
+++ b/engines/ngi/scenes.cpp
@@ -620,7 +620,7 @@ bool NGIEngine::doSetScene(const Entrance &entrance) {
 			sceneIntro_initMan(*scene);
 			addMessageHandler(sceneHandlerIntro, 2);
 		} else if (isAndroidFullPipe() && scene->_sceneId == SC_1) {
-			scene01_initObjects(scene, entrance._id, true);
+			scene01_initScene(scene, entrance._id);
 			addMessageHandler(sceneHandler01, 2);
 		}
 		return true;
diff --git a/engines/ngi/xmlproject.cpp b/engines/ngi/xmlproject.cpp
index 3004944e5e8..d24e7673e83 100644
--- a/engines/ngi/xmlproject.cpp
+++ b/engines/ngi/xmlproject.cpp
@@ -27,6 +27,7 @@
 #include "common/formats/xmlparser.h"
 
 #include "ngi/ngi.h"
+#include "ngi/objectnames.h"
 #include "ngi/gameloader.h"
 #include "ngi/behavior.h"
 #include "ngi/constants.h"
@@ -127,6 +128,33 @@ private:
 	}
 };
 
+class XMLObjectStateParser : public Common::XMLParser {
+public:
+	explicit XMLObjectStateParser(GameVar &states) : _states(states) {}
+
+private:
+	GameVar &_states;
+	GameVar *_values = nullptr;
+	CUSTOM_XML_PARSER(XMLObjectStateParser) {
+		XML_KEY(OBJSTATES)
+		KEY_END()
+	} PARSER_END()
+
+	bool parserCallback_OBJSTATES(ParserNode *) { return true; }
+	bool handleUnknownKey(ParserNode *node) override {
+		node->layout = _XMLkeys;
+		if (node->depth == 1 && node->name == "OBJECT") {
+			GameVar *object = _states.addSubVarAsInt(node->values.getValOrDefault("title"), 0);
+			_values = object ? object->addSubVarAsInt("ENUMSTATES", 0) : nullptr;
+		} else if (node->depth == 2 && node->name == "STATE" && _values) {
+			_values->setSubVarAsInt(node->values.getValOrDefault("title"), atoi(node->values.getValOrDefault("num").c_str()));
+		} else {
+			node->ignore = true;
+		}
+		return true;
+	}
+};
+
 class XMLProjectParser : public Common::XMLParser {
 public:
 	explicit XMLProjectParser(GameProject &project) : _project(project) {
@@ -1005,6 +1033,15 @@ Common::Error GameLoader::loadXML(const Common::Path &projectPath, const SceneTa
 			return Common::Error(Common::kNoGameDataFoundError, "Could not read the Full Pipe Android walking movements");
 	}
 
+	_gameVar = new GameVar();
+	GameVar *states = _gameVar->addSubVarAsInt("OBJSTATES", 0);
+	XMLObjectStateParser stateParser(*states);
+	if (!stateParser.loadFile("data/objstates.xml") || !stateParser.parse())
+		return Common::Error(Common::kNoGameDataFoundError, "Could not read the object states");
+	g_nmi->setState(sO_EggCracker, g_nmi->getStateValue(sO_EggCracker, sO_DidNotCrackEgg));
+	_gameVar->addSubVarAsInt("TASKS", 0);
+	_gameVar->addSubVarAsInt("VISITED", 0);
+	_gameVar->addSubVarAsInt("CHAPTERS", 0);
 	width = parser.width();
 	height = parser.height();
 	return Common::kNoError;


Commit: eb1997329916fed04b5a48a06cc70c86dac48eb7
    https://github.com/scummvm/scummvm/commit/eb1997329916fed04b5a48a06cc70c86dac48eb7
Author: Eugene Sandulenko (sev at scummvm.org)
Date: 2026-11-28T14:18:26+01:00

Commit Message:
NGI: Dispatch room one tutorial skip through the inventory GUI

Changed paths:
    engines/ngi/constants.h
    engines/ngi/fullpipe/scene01.cpp
    engines/ngi/inventory.h
    engines/ngi/ngi.cpp
    engines/ngi/scenes.cpp
    engines/ngi/xmlproject.cpp


diff --git a/engines/ngi/constants.h b/engines/ngi/constants.h
index 9f2ea3bce88..ac8244ba358 100644
--- a/engines/ngi/constants.h
+++ b/engines/ngi/constants.h
@@ -395,6 +395,7 @@ namespace NGI {
 #define MSG_SC1_SHOWOSK2 468
 #define MSG_SC1_UTRUBACLICK 1100
 #define PIC_SC1_KUCHKA 1321
+#define QU_SC1_ENTER 320
 #define PIC_SC1_LADDER 1091
 #define PIC_SC1_OSK 1018
 #define PIC_SC1_OSK2 2932
diff --git a/engines/ngi/fullpipe/scene01.cpp b/engines/ngi/fullpipe/scene01.cpp
index 4600a607c91..f68b47b5dd3 100644
--- a/engines/ngi/fullpipe/scene01.cpp
+++ b/engines/ngi/fullpipe/scene01.cpp
@@ -65,9 +65,25 @@ void scene01_initObjects(Scene *sc, int entrance, bool eggUncracked) {
 	}
 }
 
+static void scene01_onGuiEvent(Scene &inventory, const Common::String &id, const Common::String &event) {
+	if (event != "unpress")
+		return;
+	if (id == "BTN_SKIP") {
+		GameVar *root = g_nmi->getGameLoaderGameVar();
+		root->setSubVarAsInt("TutorialDisabled", 1);
+		root->setSubVarAsInt("Scene1ExitsDisabled", 0);
+		inventory._guiManager->getElement(id)->hideAndDeactivate();
+	} else {
+		warning("STUB: Inventory::onGuiEvent(%s, %s)", id.c_str(), event.c_str());
+	}
+}
+
 void scene01_initScene(Scene *sc, int entrance) {
 	scene01_initObjects(sc, entrance, g_nmi->getStateId(sO_EggCracker) == g_nmi->getStateValue(sO_EggCracker, sO_DidNotCrackEgg));
 	if (g_nmi->isAndroidFullPipe()) {
+		g_nmi->_inventoryScene = g_nmi->findScene(SC_INV);
+		if (g_nmi->_inventoryScene)
+			g_nmi->_inventoryScene->_guiEventHandler = scene01_onGuiEvent;
 		uint32 buttonId;
 		if (g_nmi->_gameProject->_objectIds.findId("ST_LBN_2N", buttonId))
 			g_nmi->lift_setButton(sO_Level2, buttonId);
@@ -95,6 +111,15 @@ int sceneHandler01(Command *cmd) {
 				g_nmi->_currentScene->_behaviorController->enableAllMusic();
 			return 0;
 		}
+		if (cmd->_messageName == "MSG_DISABLE_EXIT_MANAGER") {
+			g_nmi->getGameLoaderGameVar()->setSubVarAsInt("Scene1ExitsDisabled", 1);
+			Scene *inventory = g_nmi->_inventoryScene;
+			if (inventory && inventory->_guiManager) {
+				if (GuiElement *skip = inventory->_guiManager->getElement("BTN_SKIP"))
+					skip->showAndActivate();
+			}
+			return 0;
+		}
 		if (cmd->_messageName == "MSG_DEACT_OBJ_SC1") {
 			Inventory *inventory = getGameLoaderInventory();
 			uint32 blackEgg, coinEgg;
diff --git a/engines/ngi/inventory.h b/engines/ngi/inventory.h
index ea1095b3af7..fd3155dc1eb 100644
--- a/engines/ngi/inventory.h
+++ b/engines/ngi/inventory.h
@@ -94,6 +94,7 @@ class Inventory : public InventoryData {
 	Inventory();
 	~Inventory() override;
 
+	void addPoolItem(const InventoryPoolItem &item) { _itemsPool.push_back(item); }
 	bool loadPartial(MfcArchive &file);
 	bool savePartial(MfcArchive &file);
 	void addItem(int itemId, int count);
diff --git a/engines/ngi/ngi.cpp b/engines/ngi/ngi.cpp
index 00c289a5cd9..0a4982fd314 100644
--- a/engines/ngi/ngi.cpp
+++ b/engines/ngi/ngi.cpp
@@ -303,8 +303,21 @@ bool NGIEngine::handleGuiEvent(const Common::Event &event) {
 			cmd._param = back ? kActionCloseDialog : 0;
 			_modalObject->handleMessage(&cmd);
 		}
-	} else if (_currentScene->_guiManager) {
-		GuiManager &gui = *_currentScene->_guiManager;
+	} else {
+		GuiManager *manager = _currentScene->_guiManager.get();
+		if (_inventoryScene && _inventoryScene->_guiManager && _inventoryScene->_guiManager->hit(event.mouse)) {
+			manager = _inventoryScene->_guiManager.get();
+			for (const MessageQueue *queue : *_globalMessageQueueList) {
+				if (queue->_queueId == QU_SC1_ENTER && !queue->_isFinished) {
+					GuiElement *skip = manager->getElement("BTN_SKIP");
+					if (!skip || !skip->hit(event.mouse))
+						return false;
+				}
+			}
+		}
+		if (!manager)
+			return false;
+		GuiManager &gui = *manager;
 		switch (event.type) {
 		case Common::EVENT_KEYDOWN:
 			gui.onKeyDown(event.kbd.keycode);
@@ -643,8 +656,14 @@ Common::Error NGIEngine::updateScreen(uint32 elapsed, byte &brightness, bool red
 			_modalObject->update();
 	} else if (_currentScene && (timedUpdates ? redraw : renderScene)) {
 		_currentScene->render();
-		if (_inventoryScene)
-			_inventory->render();
+		if (_inventoryScene) {
+			if (isAndroidFullPipe()) {
+				if (_inventoryScene->_guiManager)
+					_inventoryScene->_guiManager->render(_backgroundSurface);
+			} else {
+				_inventory->render();
+			}
+		}
 		if (_updateScreenCallback)
 			_updateScreenCallback();
 		if (brightness < 255)
diff --git a/engines/ngi/scenes.cpp b/engines/ngi/scenes.cpp
index 7485b0af290..b6f2d69a09d 100644
--- a/engines/ngi/scenes.cpp
+++ b/engines/ngi/scenes.cpp
@@ -576,6 +576,7 @@ bool NGIEngine::doSetScene(const Entrance &entrance) {
 		return 0;
 
 	if (usesXMLProject()) {
+		_inventoryScene = nullptr;
 		Scene *common = findScene(SC_COMMON);
 		Scene *intro2 = isAndroidFullPipe() && scene->_sceneId == SC_INTRO1 ? findScene(SC_INTRO2) : nullptr;
 		if (isAndroidFullPipe() && scene->_sceneId == SC_INTRO1 && (!common || !intro2))
diff --git a/engines/ngi/xmlproject.cpp b/engines/ngi/xmlproject.cpp
index d24e7673e83..69c86bd1a19 100644
--- a/engines/ngi/xmlproject.cpp
+++ b/engines/ngi/xmlproject.cpp
@@ -449,6 +449,7 @@ private:
 				KEY_END()
 			KEY_END()
 			XML_KEY(PICTURE)
+				XML_PROP(hitAlpha, false)
 				XML_PROP(filter, false)
 				XML_PROP(serializable, false)
 				XML_PROP(id, true)
@@ -508,6 +509,13 @@ private:
 				KEY_END()
 			KEY_END()
 		KEY_END()
+		XML_KEY(INVENTORY)
+			XML_PROP(interval, false)
+			XML_PROP(cursorOfs, false)
+			XML_PROP(mode, false)
+			XML_PROP(fitTo, false)
+			XML_PROP(waitscreen, false)
+		KEY_END()
 	} PARSER_END()
 
 	bool parserCallback_SCENE(ParserNode *node) {
@@ -522,6 +530,8 @@ private:
 		return true;
 	}
 
+	bool parserCallback_INVENTORY(ParserNode *) { return true; }
+
 	bool parserCallback_ADDANI(ParserNode *node) {
 		PicAniInfo ref;
 		if (!readId(node->values["id"], ref.objectId) || !readId(node->values["scene"], ref.sceneId))
@@ -955,6 +965,18 @@ private:
 		const ParserNode *parent = getParentNode(node);
 		if (!parent)
 			return false;
+		if (parent->name == "INVENTORY") {
+			node->layout = _XMLkeys;
+			if (node->name == "GUIMNGR")
+				return parserCallback_GUIMNGR(node);
+			if (node->name == "PICTURE")
+				return parserCallback_PICTURE(node);
+			if (node->name == "ITEM") {
+				InventoryPoolItem item = {};
+				if (readId(node->values.getValOrDefault("id"), item.id) && readId(node->values.getValOrDefault("vis"), item.pictureObjectNormal))
+					getGameLoaderInventory()->addPoolItem(item);
+			}
+		}
 		if (node->depth == 2 && parent->name == "GUIMNGR" && _scene._guiManager)
 			_scene._guiManager->createElement(node->name, node->values, _project._objectIds);
 		// Scene nodes outside the supported object types are ignored for now.
@@ -993,6 +1015,12 @@ void SceneTag::loadSceneXML(const GameProject &project) {
 		return;
 	}
 
+	if (_sceneId == SC_INV) {
+		parser.close();
+		if (!parser.loadFile("data/res/inventory.xml") || !parser.parse())
+			return;
+	}
+
 	debugC(1, kDebugXML, "Loaded Full Pipe Android scene %s with %u pictures and %u animations",
 		_tag.c_str(), scene->_pictureObjects.size(), scene->_aniObjects.size());
 	delete _scene;


Commit: 327f10c94597e280f996f3e39b93e573bb5ecf09
    https://github.com/scummvm/scummvm/commit/327f10c94597e280f996f3e39b93e573bb5ecf09
Author: Eugene Sandulenko (sev at scummvm.org)
Date: 2026-11-28T14:18:26+01:00

Commit Message:
NGI: Resolve inventory cursor pictures and bound item removal

Changed paths:
    engines/ngi/inventory.cpp
    engines/ngi/inventory.h


diff --git a/engines/ngi/inventory.cpp b/engines/ngi/inventory.cpp
index 8a1fa51f582..e580f2e0739 100644
--- a/engines/ngi/inventory.cpp
+++ b/engines/ngi/inventory.cpp
@@ -52,15 +52,17 @@ bool InventoryData::load(MfcArchive &file) {
 }
 
 int InventoryData::getInventoryPoolItemIndexById(int itemId) {
-	if (_itemsPool.size() <= 0)
-		return -1;
-
 	for (uint i = 0; i < _itemsPool.size(); i++) {
 		if (_itemsPool[i].id == itemId)
 			return i;
 	}
 
-	return 0;
+	return -1;
+}
+
+int Inventory::getCursorPictureId() {
+	int index = getInventoryPoolItemIndexById(getSelectedItemId());
+	return index >= 0 ? _itemsPool[index].pictureObjectNormal : 0;
 }
 
 bool InventoryData::setItemFlags(int itemId, int flags) {
@@ -128,7 +130,7 @@ void Inventory::addItem2(AniObject *obj) {
 void Inventory::removeItem(int itemId, int count) {
 	debugC(2, kDebugInventory, "Inventory::removeItem(%d, %d)", itemId, count);
 
-	while (count) {
+	while (count > 0) {
 		int i;
 		for (i = _inventoryItems.size() - 1; i >= 0; i--) {
 			InventoryItem &item = _inventoryItems[i];
@@ -138,6 +140,7 @@ void Inventory::removeItem(int itemId, int count) {
 
 				if (item.count > count) {
 					item.count -= count;
+					return;
 				} else {
 					count -= item.count;
 					_inventoryItems.remove_at(i);
@@ -149,6 +152,8 @@ void Inventory::removeItem(int itemId, int count) {
 				break;
 			}
 		}
+		if (i < 0)
+			break;
 	}
 }
 
diff --git a/engines/ngi/inventory.h b/engines/ngi/inventory.h
index fd3155dc1eb..fa90b62dd61 100644
--- a/engines/ngi/inventory.h
+++ b/engines/ngi/inventory.h
@@ -115,6 +115,7 @@ class Inventory : public InventoryData {
 	void setIsLocked(bool val) { _isLocked = val; }
 	bool getIsInventoryOut() { return _isInventoryOut; }
 
+	int getCursorPictureId();
 	int getSelectedItemId() { return _selectedId < 0 ? 0 : _selectedId; }
 	int getItemAtPos(Common::Point *point);
 	void slideIn();


Commit: 5eee8808aa53e7b777bc241e47fb852bac778da6
    https://github.com/scummvm/scummvm/commit/5eee8808aa53e7b777bc241e47fb852bac778da6
Author: Eugene Sandulenko (sev at scummvm.org)
Date: 2026-11-28T14:18:26+01:00

Commit Message:
NGI: Hit test XML objects and play motion graph walk queues

Changed paths:
    engines/ngi/gfx.cpp
    engines/ngi/gfx.h
    engines/ngi/messagehandlers.cpp
    engines/ngi/motion.cpp
    engines/ngi/scene.cpp
    engines/ngi/statics.cpp
    engines/ngi/statics.h


diff --git a/engines/ngi/gfx.cpp b/engines/ngi/gfx.cpp
index 17834f2caba..70f6ce747cd 100644
--- a/engines/ngi/gfx.cpp
+++ b/engines/ngi/gfx.cpp
@@ -204,6 +204,8 @@ bool PictureObject::isPointInside(int x, int y) {
 }
 
 bool PictureObject::hit(int x, int y) {
+	if (!_hitRegion.isEmpty())
+		return _hitRegion.contains(x - _x, y - _y);
 	int oldx = _picture->_x;
 	int oldy = _picture->_y;
 
@@ -712,6 +714,15 @@ bool Texture::hit(int x, int y) {
 	if (x < _x || y < _y || x >= _x + _width || y >= _y + _height)
 		return false;
 
+	if (g_nmi->usesXMLProject()) {
+		if (!_bitmap || !_bitmap->_surface)
+			return false;
+		const Graphics::ManagedSurface &surface = *_bitmap->_surface;
+		const uint32 color = surface.getPixel(x - _x, y - _y);
+		return (!surface.hasTransparentColor() || color != surface.getTransparentColor()) &&
+			(!surface.format.aBits() || ((color >> surface.format.aShift) & surface.format.aMax()));
+	}
+
 	if (!_bitmap)
 		init();
 
diff --git a/engines/ngi/gfx.h b/engines/ngi/gfx.h
index a7b814c1118..ede2b1fa570 100644
--- a/engines/ngi/gfx.h
+++ b/engines/ngi/gfx.h
@@ -184,6 +184,7 @@ public:
 	void renderAtPos(int x, int y);
 
 	bool setPicAniInfo(const PicAniInfo &picAniInfo);
+	Common::Rect _hitRegion; // XML region in picture coordinates.
 	bool isPointInside(int x, int y);
 	bool hit(int x, int y);
 	void setOXY2();
diff --git a/engines/ngi/messagehandlers.cpp b/engines/ngi/messagehandlers.cpp
index 13020bb53f1..90d39bd6c64 100644
--- a/engines/ngi/messagehandlers.cpp
+++ b/engines/ngi/messagehandlers.cpp
@@ -597,9 +597,9 @@ int global_messageHandler4(Command *cmd) {
 			ExCommand2 *cmd2 = static_cast<ExCommand2 *>(cmd);
 
 			if (cmd->_excFlags & 1) {
-				ani->startSliding(cmd->_messageNum, 0, cmd->_x, cmd->_y, cmd2->_points, flags);
+				ani->startSliding(cmd->_messageNum, 0, cmd->_x, cmd->_y, cmd2->_points, flags, cmd->_mirror);
 			} else {
-				ani->startSliding(cmd->_messageNum, cmd->_parId, cmd->_x, cmd->_y, cmd2->_points, flags);
+				ani->startSliding(cmd->_messageNum, cmd->_parId, cmd->_x, cmd->_y, cmd2->_points, flags, cmd->_mirror);
 			}
 		}
 		break;
@@ -688,7 +688,7 @@ int global_messageHandler4(Command *cmd) {
 
 		if (g_nmi->_gameVersion >= 201509) {
 			const bool mirror = cmd->_auxParam < 0 ? (ani->_flags & 8) != 0 : cmd->_auxParam != 0;
-			ani->show1(cmd->_x == -1 ? ani->_x : cmd->_x, cmd->_y == -1 ? ani->_y : cmd->_y, cmd->_messageNum, 0);
+			ani->show1(cmd->_x == -1 ? ani->_x : cmd->_x, cmd->_y == -1 ? ani->_y : cmd->_y, cmd->_messageNum, (cmd->_excFlags & 1) ? 0 : cmd->_parId);
 			ani->_flags = (ani->_flags & ~8) | (mirror ? 8 : 0);
 		} else {
 			ani->show1(cmd->_x, cmd->_y, cmd->_messageNum, cmd->_parId);
diff --git a/engines/ngi/motion.cpp b/engines/ngi/motion.cpp
index 1cab2db3c76..1217edf22c5 100644
--- a/engines/ngi/motion.cpp
+++ b/engines/ngi/motion.cpp
@@ -1970,6 +1970,7 @@ MessageQueue *MctlGraph::makeWholeQueue(GmctlMqStruct &mctlMQ) {
 				Command *ex = new Command(_aniData[mctlMQ.objectIndex]._objectId, 1, mg2i->_movementId, 0, 0, 0, 1, 0, 0, 0);
 
 				ex->_excFlags |= 2;
+				ex->_mirror = mg2i->_mirror;
 				ex->_param = _aniData[mctlMQ.objectIndex]._ani->_copyId;
 				ex->_wait = 1;
 				ex->_z = -1;
@@ -2318,7 +2319,7 @@ MessageQueue *MctlGraph::makeQueue(AniObject *obj, int xpos, int ypos, int fuzzy
 		mctlMQ1.destDir = getLinkDir(&tempLinkList, tempLinkList.size() - 1, nullptr, nullptr);
 	}
 
-	mctlMQ1.flags = fuzzyMatch != 0;
+	mctlMQ1.flags = fuzzyMatch != 0 || g_nmi->_gameVersion >= 201509;
 
 	if (_aniData[idx]._directions[idxsub]._prevStaticId != obj->_statics->_staticsId)
 		mctlMQ1.flags |= 2;
@@ -2475,7 +2476,10 @@ MessageQueue *MctlGraph::makeLineQueue(GmctlMqStruct *info) {
 	int a2 = 0;
 	int mgmLen;
 
-	point = _aniHandler.getNumCycles(_aniData[info->objectIndex]._directions[info->sourceDir]._walk[1]._movement, x, y, &mgmLen, &a2, info->flags & 1);
+	const MG2I *walk = _aniData[info->objectIndex]._directions[info->sourceDir]._walk;
+	point = _aniHandler.getNumCycles(walk[1]._movement, walk[1]._mirror ? -x : x, y, &mgmLen, &a2, info->flags & 1);
+	if (walk[1]._mirror)
+		point.x = -point.x;
 
 	int x1 = point.x;
 	int y1 = point.y;
@@ -2598,6 +2602,7 @@ MessageQueue *MctlGraph::makeLineQueue(GmctlMqStruct *info) {
 								  x2,
 								  y2,
 								  -1);
+		ex->_mirror = walk[0]._mirror;
 		ex->_parId = mq->_id;
 		ex->_param = _aniData[info->objectIndex]._ani->_copyId;
 	}
@@ -2620,6 +2625,7 @@ MessageQueue *MctlGraph::makeLineQueue(GmctlMqStruct *info) {
 								  x2,
 								  y2,
 								  par);
+		ex->_mirror = walk[1]._mirror;
 		ex->_parId = mq->_id;
 		ex->_param = _aniData[info->objectIndex]._ani->_copyId;
 		mq->addCommandToEnd(ex);
@@ -2634,6 +2640,7 @@ MessageQueue *MctlGraph::makeLineQueue(GmctlMqStruct *info) {
 								  x2,
 								  y2,
 								  -1);
+		ex->_mirror = walk[2]._mirror;
 		ex->_parId = mq->_id;
 		ex->_param = _aniData[info->objectIndex]._ani->_copyId;
 
diff --git a/engines/ngi/scene.cpp b/engines/ngi/scene.cpp
index 177b026938b..cf832e4215e 100644
--- a/engines/ngi/scene.cpp
+++ b/engines/ngi/scene.cpp
@@ -606,7 +606,7 @@ AniObject *Scene::findAniObjectAtPos(int x, int y) {
 	for (uint i = 0; i < _aniObjects.size(); i++) {
 		AniObject *p = _aniObjects[i];
 
-		if ((p->_objectFlags & 0x100) && (p->_flags & 4) &&
+		if ((p->_objectFlags & (g_nmi->usesXMLProject() ? 2 : 0x100)) && (p->_flags & 4) &&
 				p->hit(x, y) &&
 				(!res || res->_z > p->_z))
 			res = p;
@@ -620,7 +620,7 @@ PictureObject *Scene::findPictureObjectAtPos(int x, int y) {
 
 	for (uint i = 0; i < _pictureObjects.size(); i++) {
 		PictureObject *p = _pictureObjects[i];
-		if ((p->_objectFlags & 0x100) && (p->_flags & 4) &&
+		if ((p->_objectFlags & (g_nmi->usesXMLProject() ? 2 : 0x100)) && (p->_flags & 4) &&
 				p->hit(x, y) &&
 				(!res || res->_z >= p->_z))
 			res = p;
@@ -635,7 +635,7 @@ int Scene::getPictureObjectIdAtPos(int x, int y) {
 
 	for (uint i = 0; i < _pictureObjects.size(); i++) {
 		PictureObject *p = _pictureObjects[i];
-		if ((p->_objectFlags & 0x100) && (p->_flags & 4) &&
+		if ((p->_objectFlags & (g_nmi->usesXMLProject() ? 2 : 0x100)) && (p->_flags & 4) &&
 				p->hit(x, y) &&
 				(!res || resp->_z >= p->_z)) {
 			resp = p;
diff --git a/engines/ngi/statics.cpp b/engines/ngi/statics.cpp
index 98d15e352fc..7ed2c7e4837 100644
--- a/engines/ngi/statics.cpp
+++ b/engines/ngi/statics.cpp
@@ -412,6 +412,14 @@ Movement *AniObject::getMovementByName(const Common::String &name) {
 }
 
 bool AniObject::hit(int x, int y) {
+	if (g_nmi->usesXMLProject()) {
+		Phase *phase = _movement ? _movement->_curPhase : _statics;
+		if (!phase)
+			return false;
+		Common::Point anchor = getSomeXY();
+		int localX = (_flags & 8) ? _x - x - 1 + anchor.x : x - _x + anchor.x;
+		return phase->hit(phase->_x + localX, phase->_y + y - _y + anchor.y);
+	}
 	return getPixelAtPos(x, y, nullptr, true);
 }
 
@@ -1161,7 +1169,17 @@ void AniObject::playIdle() {
 		adjustSomeXY();
 }
 
-void AniObject::startSliding(int movementId, int messageQueueId, int x, int y, const PointList &points, int someDynamicPhaseIndex) {
+void AniObject::startSliding(int movementId, int messageQueueId, int x, int y, const PointList &points, int someDynamicPhaseIndex, bool mirror) {
+	if (g_nmi->_gameVersion >= 201509) {
+		if (startMovement(movementId, messageQueueId, someDynamicPhaseIndex, mirror)) {
+			_stepArray.insertPoints(points);
+			const Common::Point offset = _stepArray.getCurrPoint();
+			setPos(_x + offset.x, _y + offset.y);
+			_stepArray.gotoNextPoint();
+		}
+		return;
+	}
+
 	Movement *mov = nullptr;
 
 	if (!(_flags & 0x80)) {
diff --git a/engines/ngi/statics.h b/engines/ngi/statics.h
index b03f443e05f..d4d623e301b 100644
--- a/engines/ngi/statics.h
+++ b/engines/ngi/statics.h
@@ -244,7 +244,7 @@ public:
 
 	bool startMovement(int movementId, int messageQueueId, int dynPhaseIdx, bool mirror = false);
 	bool startAnimEx(int movid, int parId, int flag1, int flag2);
-	void startSliding(int movementId, int messageQueueId, int x, int y, const PointList &points, int someDynamicPhaseIndex);
+	void startSliding(int movementId, int messageQueueId, int x, int y, const PointList &points, int someDynamicPhaseIndex, bool mirror);
 
 	void hide();
 	void show1(int x, int y, int movementId, int mqId);


Commit: 8a24e09cfd1838fc57e955a242d8dc0776e1af34
    https://github.com/scummvm/scummvm/commit/8a24e09cfd1838fc57e955a242d8dc0776e1af34
Author: Eugene Sandulenko (sev at scummvm.org)
Date: 2026-11-28T14:18:26+01:00

Commit Message:
NGI: Resolve and place roaming XML animation copies on scene entry

Changed paths:
    engines/ngi/scenes.cpp
    engines/ngi/xmlproject.cpp


diff --git a/engines/ngi/scenes.cpp b/engines/ngi/scenes.cpp
index b6f2d69a09d..2901080796a 100644
--- a/engines/ngi/scenes.cpp
+++ b/engines/ngi/scenes.cpp
@@ -584,11 +584,36 @@ bool NGIEngine::doSetScene(const Entrance &entrance) {
 		scene->_commonQueueScene = common == scene ? nullptr : common;
 		for (const PicAniInfo &ref : scene->_roamingObjects) {
 			Scene *source = findScene(ref.sceneId);
-			AniObject *actor = source ? source->findAniObjectById(ref.objectId, ref.copyId) : nullptr;
+			if (!source)
+				return false;
+			AniObject *actor = nullptr;
+			for (AniObject *owned : source->_aniObjects) {
+				if (owned->_id == ref.objectId && owned->_copyId == ref.copyId)
+					actor = owned;
+			}
+			if (!actor && ref.copyId) {
+				AniObject *original = source->findAniObjectById(ref.objectId, 0);
+				if (original) {
+					actor = new AniObject(original);
+					source->addAni(actor, false);
+					actor->_copyId = ref.copyId;
+				}
+			}
 			if (!actor)
 				return false;
 			if (!scene->findAniObjectById(ref.objectId, ref.copyId))
 				scene->_renderableAnis.push_back(actor);
+			if (ref.staticsId)
+				actor->_statics = actor->getStatic(ref.staticsId);
+			actor->setPos(ref.ox == -1 ? actor->_x : ref.ox, ref.oy == -1 ? actor->_y : ref.oy);
+			if (ref.priority != -1)
+				actor->_z = ref.priority;
+			if (ref.objectFlags != -1) {
+				actor->_objectFlags = ref.objectFlags;
+				actor->_flags = (actor->_flags & ~4) | ((ref.objectFlags & 1) << 2);
+			}
+			if (ref.flags != -1)
+				actor->_flags = (actor->_flags & ~8) | (ref.flags ? 8 : 0);
 		}
 		_aniMan = scene->findAniObjectById(scene->_heroId, 0);
 		_aniMan2 = _aniMan;
diff --git a/engines/ngi/xmlproject.cpp b/engines/ngi/xmlproject.cpp
index 69c86bd1a19..89eb142a653 100644
--- a/engines/ngi/xmlproject.cpp
+++ b/engines/ngi/xmlproject.cpp
@@ -380,6 +380,12 @@ private:
 				KEY_END()
 			KEY_END()
 			XML_KEY(ADDANI)
+				XML_PROP(static, false)
+				XML_PROP(x, false)
+				XML_PROP(y, false)
+				XML_PROP(z, false)
+				XML_PROP(flags, false)
+				XML_PROP(mirror, false)
 				XML_PROP(id, true)
 				XML_PROP(scene, true)
 				XML_PROP(copy, false)
@@ -472,6 +478,7 @@ private:
 				XML_PROP(locale, false)
 				XML_PROP(static, false)
 				XML_KEY(STATICS)
+					XML_PROP(delayRelative, false)
 					XML_PROP(id, true)
 					XML_PROP(title, false)
 					XML_PROP(x, false)
@@ -537,6 +544,13 @@ private:
 		if (!readId(node->values["id"], ref.objectId) || !readId(node->values["scene"], ref.sceneId))
 			return parserError("Unknown roaming animation or scene");
 		ref.copyId = atoi(node->values.getValOrDefault("copy").c_str());
+		ref.ox = atoi(node->values.getValOrDefault("x", "-1").c_str());
+		ref.oy = atoi(node->values.getValOrDefault("y", "-1").c_str());
+		ref.priority = atoi(node->values.getValOrDefault("z", "-1").c_str());
+		ref.objectFlags = atoi(node->values.getValOrDefault("flags", "-1").c_str());
+		ref.flags = node->values.contains("mirror") ? boolProperty(*node, "mirror") : -1;
+		if (node->values.contains("static") && !readId(node->values["static"], ref.staticsId))
+			return parserError("Unknown roaming static");
 		_scene._roamingObjects.push_back(ref);
 		return true;
 	}
@@ -853,6 +867,7 @@ private:
 		if (!readId(node->values["id"], pose->_staticsId))
 			return parserError("Unknown statics ID '" + node->values["id"] + "'");
 
+		pose->_delayRelative = intProperty(*node, "delayRelative");
 		pose->_staticsName = node->values.getValOrDefault("title");
 		// AniObject subtracts the anchor when drawing a pose. XML stores the texture offset.
 		pose->_someX = -strtod(node->values.getValOrDefault("x").c_str(), nullptr);


Commit: ca8c21b6c5bd82b17142ae0ee3c3ba115867be29
    https://github.com/scummvm/scummvm/commit/ca8c21b6c5bd82b17142ae0ee3c3ba115867be29
Author: Eugene Sandulenko (sev at scummvm.org)
Date: 2026-11-28T14:18:26+01:00

Commit Message:
NGI: Run room one exits and egg exchanges from XML interactions

Changed paths:
    engines/ngi/fullpipe/scene01.cpp
    engines/ngi/interaction.cpp
    engines/ngi/interaction.h
    engines/ngi/inventory.cpp
    engines/ngi/inventory.h
    engines/ngi/messagehandlers.cpp
    engines/ngi/messages.h
    engines/ngi/ngi.cpp
    engines/ngi/scenes.h
    engines/ngi/xmlproject.cpp


diff --git a/engines/ngi/fullpipe/scene01.cpp b/engines/ngi/fullpipe/scene01.cpp
index f68b47b5dd3..63427cf7f09 100644
--- a/engines/ngi/fullpipe/scene01.cpp
+++ b/engines/ngi/fullpipe/scene01.cpp
@@ -82,8 +82,10 @@ void scene01_initScene(Scene *sc, int entrance) {
 	scene01_initObjects(sc, entrance, g_nmi->getStateId(sO_EggCracker) == g_nmi->getStateValue(sO_EggCracker, sO_DidNotCrackEgg));
 	if (g_nmi->isAndroidFullPipe()) {
 		g_nmi->_inventoryScene = g_nmi->findScene(SC_INV);
-		if (g_nmi->_inventoryScene)
+		if (g_nmi->_inventoryScene) {
 			g_nmi->_inventoryScene->_guiEventHandler = scene01_onGuiEvent;
+			getGameLoaderInventory()->recalcItemPos();
+		}
 		uint32 buttonId;
 		if (g_nmi->_gameProject->_objectIds.findId("ST_LBN_2N", buttonId))
 			g_nmi->lift_setButton(sO_Level2, buttonId);
@@ -99,6 +101,34 @@ void scene01_initScene(Scene *sc, int entrance) {
 	}
 }
 
+bool scene01_click(Common::Point pos) {
+	Scene &scene = *g_nmi->_currentScene;
+	AniObject *hero = g_nmi->_aniMan;
+	if (!hero || hero->_messageQueueId || !scene._motionController)
+		return false;
+	for (const MessageQueue *queue : *g_nmi->_globalMessageQueueList)
+		if (queue->_queueId == QU_SC1_ENTER && !queue->_isFinished)
+			return false;
+	pos += Common::Point(scene._x, scene._y);
+	PictureObject *picture = scene.findPictureObjectAtPos(pos.x, pos.y);
+	AniObject *actor = scene.findAniObjectAtPos(pos.x, pos.y);
+	GameObject *target = picture;
+	if (actor && (!picture || actor->_z < picture->_z))
+		target = actor;
+	if (target) {
+		uint32 upperPipe;
+		if (g_nmi->_gameProject->_objectIds.findId("PIC_SC1_UTRUBA", upperPipe) && upperPipe == (uint16)target->_id)
+			target = scene.findPictureObjectById(PIC_SC1_LADDER, 0);
+		const int item = getGameLoaderInventory()->getCursorPictureId();
+		if (target && canInteractAny(hero, target, item)) {
+			if (target->_objtype == kObjTypePictureObject && g_nmi->getGameLoaderGameVar()->getSubVarAsInt("Scene1ExitsDisabled"))
+				return false;
+			return handleObjectInteraction(hero, target, item);
+		}
+	}
+	return scene._motionController->startMove(hero, pos.x, pos.y, 0, 0) != nullptr;
+}
+
 int sceneHandler01(Command *cmd) {
 	int res = 0;
 
diff --git a/engines/ngi/interaction.cpp b/engines/ngi/interaction.cpp
index f0a3b7dfbe2..e447f3dabd2 100644
--- a/engines/ngi/interaction.cpp
+++ b/engines/ngi/interaction.cpp
@@ -97,6 +97,48 @@ void InteractionController::sortInteractions(int sceneId) {
 }
 
 bool InteractionController::handleInteraction(AniObject *subj, GameObject *obj, int invId) {
+	if (g_nmi->usesXMLProject()) {
+		if (!_enabled || !subj || !obj || subj->_messageQueueId)
+			return false;
+		Interact *action = nullptr;
+		for (Interact *candidate : _interactions) {
+			if (candidate->canRun(subj, obj, invId) && (!action || candidate->_field_28 > action->_field_28))
+				action = candidate;
+		}
+		if (!action)
+			return false;
+		Common::ScopedPtr<MessageQueue> queue;
+		if (action->_heroId) {
+			int x = obj->_x + action->_heroOffsetX;
+			int y = obj->_y + action->_heroOffsetY;
+			if (obj->_objtype == kObjTypeStaticANIObject) {
+				const AniObject *actor = static_cast<AniObject *>(obj);
+				const Dims size = actor->getFullSize();
+				const Common::Point anchor = actor->getSomeXY();
+				x += (actor->_flags & 8 ? -1 : 1) * (size.x / 2 - anchor.x);
+				y += size.y / 2 - anchor.y;
+			}
+			if (x != subj->_x || y != subj->_y) {
+				queue.reset(getCurrSceneSc2MotionController()->makeQueue(subj, x, y, 0, action->_heroStaticId));
+				if (!queue)
+					return false;
+			}
+		}
+		if (!queue)
+			queue.reset(new MessageQueue(0));
+		if (action->_heroId) {
+			Command *mirror = new Command(subj->_id, 34, action->_heroMirror ? 8 : 0, 0, 0, 0, 1, 0, 0, 0);
+			mirror->_z = 8;
+			mirror->_excFlags = 3;
+			queue->addCommandToEnd(mirror);
+		}
+		for (uint i = 0; i < action->_messageQueue->getCount(); ++i)
+			queue->addCommandToEnd(action->_messageQueue->getCommandByIndex(i)->createClone());
+		if (!queue->run(action->_heroId ? subj : nullptr))
+			return false;
+		queue.release();
+		return true;
+	}
 	if (subj) {
 		if (!subj->isIdle() || (subj->_flags & 0x100))
 			return false;
diff --git a/engines/ngi/interaction.h b/engines/ngi/interaction.h
index fca5c53fe19..336e5307c17 100644
--- a/engines/ngi/interaction.h
+++ b/engines/ngi/interaction.h
@@ -45,6 +45,7 @@ class Interact : public CObject {
 	int _objectState2;
 	int _heroOffsetX;
 	int _heroOffsetY;
+	bool _heroMirror = false;
 	MessageQueue *_messageQueue;
 	int _sceneId;
 	int _field_28;
@@ -77,6 +78,7 @@ public:
 
 	bool load(MfcArchive &file) override;
 
+	void addInteraction(Interact *interaction) { _interactions.push_back(interaction); }
 	void enable() { _enabled = true; }
 	void disable() { _enabled = false; }
 
diff --git a/engines/ngi/inventory.cpp b/engines/ngi/inventory.cpp
index e580f2e0739..56567bc6f2e 100644
--- a/engines/ngi/inventory.cpp
+++ b/engines/ngi/inventory.cpp
@@ -223,6 +223,12 @@ int Inventory::getItemFlags(int itemId) {
 	return _itemsPool[idx].flags;
 }
 
+void Inventory::setItemArea(int16 sceneId, const Common::Rect &area, int interval) {
+	_sceneId = sceneId;
+	_itemArea = area;
+	_itemInterval = interval;
+}
+
 void Inventory::recalcItemPos() {
 	debugC(2, kDebugInventory, "recalcItemPos()");
 
@@ -233,6 +239,30 @@ void Inventory::recalcItemPos() {
 
 	_inventoryIcons.clear();
 
+	if (g_nmi->usesXMLProject()) {
+		for (const InventoryItem &item : _inventoryItems) {
+			const int idx = getInventoryPoolItemIndexById(item.itemId);
+			if (idx < 0)
+				continue;
+			const InventoryPoolItem &pool = _itemsPool[idx];
+			InventoryIcon icon = {};
+			icon.pictureObjectNormal = _scene->findPictureObjectById(pool.pictureObjectNormal, 0);
+			if (!icon.pictureObjectNormal)
+				continue;
+			icon.pictureObjectSelected = _scene->findPictureObjectById(pool.pictureObjectSelected, 0);
+			const Dims size = icon.pictureObjectNormal->getFullSize();
+			icon.x1 = _itemArea.left + _inventoryIcons.size() * (size.x + _itemInterval);
+			icon.y1 = _itemArea.top;
+			icon.x2 = icon.x1 + size.x;
+			icon.y2 = icon.y1 + size.y;
+			if (icon.x2 >= _itemArea.right)
+				break;
+			icon.inventoryItemId = item.itemId;
+			_inventoryIcons.push_back(icon);
+		}
+		return;
+	}
+
 	_picture = _scene->getBigPicture(0, 0);
 	_picture->setAlpha(50);
 
@@ -290,6 +320,15 @@ void Inventory::render() {
 	if (!_scene)
 		return;
 
+	if (g_nmi->usesXMLProject()) {
+		for (const InventoryIcon &icon : _inventoryIcons) {
+			PictureObject *picture = icon.inventoryItemId == _selectedId && icon.pictureObjectSelected ?
+				icon.pictureObjectSelected : icon.pictureObjectNormal;
+			picture->_picture->blitTo(g_nmi->_backgroundSurface, Common::Point(icon.x1, icon.y1));
+		}
+		return;
+	}
+
 	int oldScLeft = g_nmi->_sceneRect.left;
 	int oldScTop = g_nmi->_sceneRect.top;
 
@@ -426,7 +465,7 @@ int Inventory::putOnCursor(int itemId) {
 
 	_selectedId = itemId;
 
-	if (_scene) {
+	if (_scene && !g_nmi->usesXMLProject()) {
 		int idx = getInventoryPoolItemIndexById(itemId);
 
 		Texture *pic = _scene->findPictureObjectById(_itemsPool[idx].pictureObjectId1, 0)->_picture;
@@ -453,6 +492,12 @@ bool Inventory::unselectItem(bool flag) {
 }
 
 int Inventory::getItemAtPos(Common::Point *point) {
+	if (g_nmi->usesXMLProject()) {
+		for (const InventoryIcon &icon : _inventoryIcons)
+			if (Common::Rect(icon.x1, icon.y1, icon.x2, icon.y2).contains(*point))
+				return icon.inventoryItemId;
+		return 0;
+	}
 	int selId = getSelectedItemId();
 
 	if (point->y <= 20 && !_isInventoryOut && !_isLocked)
diff --git a/engines/ngi/inventory.h b/engines/ngi/inventory.h
index fa90b62dd61..805cb5bf254 100644
--- a/engines/ngi/inventory.h
+++ b/engines/ngi/inventory.h
@@ -89,6 +89,8 @@ class Inventory : public InventoryData {
 	int _topOffset;
 	Scene *_scene;
 	BigPicture *_picture;
+	Common::Rect _itemArea;
+	int _itemInterval = 10;
 
  public:
 	Inventory();
@@ -108,6 +110,7 @@ class Inventory : public InventoryData {
 	int getCountItemsWithId(int itemId);
 	int getItemFlags(int itemId);
 
+	void setItemArea(int16 sceneId, const Common::Rect &area, int interval);
 	void recalcItemPos();
 
 	Scene *getScene() { return _scene; }
diff --git a/engines/ngi/messagehandlers.cpp b/engines/ngi/messagehandlers.cpp
index 90d39bd6c64..1b635a171ed 100644
--- a/engines/ngi/messagehandlers.cpp
+++ b/engines/ngi/messagehandlers.cpp
@@ -633,6 +633,12 @@ int global_messageHandler4(Command *cmd) {
 		if (!ani)
 			break;
 
+		if (g_nmi->usesXMLProject()) {
+			if (cmd->_auxParam)
+				ani->_flags |= 4;
+			if (!cmd->_messageNum)
+				break;
+		}
 		MessageQueue *mq = ani->getMessageQueue();
 		MessageQueue *mq2 = ani->moveToStatic(cmd->_messageNum);
 
@@ -749,6 +755,22 @@ int global_messageHandler4(Command *cmd) {
 		global_messageHandler_handleSound(cmd);
 		break;
 
+	case Command::kCmdSetScene:
+		g_nmi->_gameLoader->preloadScene(cmd->_parentId, cmd->_messageNum);
+		break;
+	case Command::kCmdSetLogic:
+		g_nmi->setState(cmd->_messageName, cmd->_messageNum);
+		break;
+	case 56:
+	case 57:
+		if (!g_nmi->usesXMLProject())
+			return 0;
+		if (cmd->_cmd == 56)
+			getGameLoaderInventory()->addItem(cmd->_parentId, 1);
+		else if (getGameLoaderInventory()->getCountItemsWithId(cmd->_parentId))
+			getGameLoaderInventory()->removeItem(cmd->_parentId, 1);
+		getGameLoaderInventory()->recalcItemPos();
+		break;
 	case 63:
 		if (g_nmi->_gameVersion < 201509)
 			return 0;
diff --git a/engines/ngi/messages.h b/engines/ngi/messages.h
index d01fa6e197d..a67e2108dde 100644
--- a/engines/ngi/messages.h
+++ b/engines/ngi/messages.h
@@ -59,7 +59,7 @@ class Message : public CObject {
 
 class Command : public Message {
  public:
-	enum { kCmdPause = 64 }; // Timed pause in XML queues.
+	enum { kCmdPause = 64, kCmdSetScene, kCmdSetLogic }; // Timed pause in XML queues.
 	Common::String _messageName;
 	bool _mirror = false;
 	int _messageNum;
diff --git a/engines/ngi/ngi.cpp b/engines/ngi/ngi.cpp
index 0a4982fd314..b9092559291 100644
--- a/engines/ngi/ngi.cpp
+++ b/engines/ngi/ngi.cpp
@@ -305,6 +305,19 @@ bool NGIEngine::handleGuiEvent(const Common::Event &event) {
 		}
 	} else {
 		GuiManager *manager = _currentScene->_guiManager.get();
+		if (_inventoryScene && (event.type == Common::EVENT_LBUTTONDOWN || event.type == Common::EVENT_LBUTTONUP)) {
+			Common::Point pos = event.mouse;
+			Inventory *inventory = getGameLoaderInventory();
+			const int item = inventory->getItemAtPos(&pos);
+			if (item) {
+				for (const MessageQueue *queue : *_globalMessageQueueList)
+					if (queue->_queueId == QU_SC1_ENTER && !queue->_isFinished)
+						return false;
+				if (event.type == Common::EVENT_LBUTTONDOWN)
+					inventory->putOnCursor(item);
+				return true;
+			}
+		}
 		if (_inventoryScene && _inventoryScene->_guiManager && _inventoryScene->_guiManager->hit(event.mouse)) {
 			manager = _inventoryScene->_guiManager.get();
 			for (const MessageQueue *queue : *_globalMessageQueueList) {
@@ -315,6 +328,9 @@ bool NGIEngine::handleGuiEvent(const Common::Event &event) {
 				}
 			}
 		}
+		if (event.type == Common::EVENT_LBUTTONUP && (!manager || !manager->hit(event.mouse)) &&
+				isAndroidFullPipe() && _currentScene->_sceneId == SC_1)
+			return scene01_click(event.mouse);
 		if (!manager)
 			return false;
 		GuiManager &gui = *manager;
@@ -658,6 +674,7 @@ Common::Error NGIEngine::updateScreen(uint32 elapsed, byte &brightness, bool red
 		_currentScene->render();
 		if (_inventoryScene) {
 			if (isAndroidFullPipe()) {
+				getGameLoaderInventory()->render();
 				if (_inventoryScene->_guiManager)
 					_inventoryScene->_guiManager->render(_backgroundSurface);
 			} else {
diff --git a/engines/ngi/scenes.h b/engines/ngi/scenes.h
index e51ea0afda6..1b7269343b9 100644
--- a/engines/ngi/scenes.h
+++ b/engines/ngi/scenes.h
@@ -65,6 +65,7 @@ int sceneIntroDemo_updateCursor();
 void sceneIntroDemo_initScene(Scene *sc);
 int sceneHandlerIntroDemo(Command *cmd);
 
+bool scene01_click(Common::Point pos);
 void scene01_fixEntrance();
 void scene01_initScene(Scene *sc, int entrance);
 void scene01_initObjects(Scene *sc, int entrance, bool eggUncracked);
diff --git a/engines/ngi/xmlproject.cpp b/engines/ngi/xmlproject.cpp
index 89eb142a653..74d86387a3c 100644
--- a/engines/ngi/xmlproject.cpp
+++ b/engines/ngi/xmlproject.cpp
@@ -290,13 +290,26 @@ public:
 		setAllowText();
 	}
 
+	~XMLSceneParser() override {
+		for (Interact *action : _actions)
+			delete action;
+	}
+
+	void registerInteractions() {
+		for (Interact *action : _actions)
+			getGameLoaderInteractionController()->addInteraction(action);
+		_actions.clear();
+	}
+
 private:
+	Common::Array<Interact *> _actions;
 	const GameProject &_project;
 	Scene &_scene;
 	const char *_locale;
 	uint _objectOrder = 0;
 	bool _hasInitialStatics = false;
 	int16 _initialStaticsId = 0;
+	Interact *_interaction = nullptr;
 	BehaviorAni *_behaviorAni = nullptr;
 	MctlItem *_motionItem = nullptr;
 	MctlGraph *_graph = nullptr;
@@ -432,6 +445,10 @@ private:
 				XML_KEY(COMMAND)
 					commandLayout = layout.top();
 					XML_PROP(cmd, true)
+					XML_PROP(interupt, false)
+					XML_PROP(scene, false)
+					XML_PROP(entr, false)
+					XML_PROP(needShow, false)
 					XML_PROP(wait, false)
 					XML_PROP(id, false)
 					XML_PROP(ani, false)
@@ -516,7 +533,13 @@ private:
 				KEY_END()
 			KEY_END()
 		KEY_END()
+		XML_KEY(INTERACTIONS)
+		KEY_END()
 		XML_KEY(INVENTORY)
+			XML_PROP(x, false)
+			XML_PROP(y, false)
+			XML_PROP(w, false)
+			XML_PROP(h, false)
 			XML_PROP(interval, false)
 			XML_PROP(cursorOfs, false)
 			XML_PROP(mode, false)
@@ -537,7 +560,15 @@ private:
 		return true;
 	}
 
-	bool parserCallback_INVENTORY(ParserNode *) { return true; }
+	bool parserCallback_INTERACTIONS(ParserNode *) { return true; }
+
+	bool parserCallback_INVENTORY(ParserNode *node) {
+		Common::Rect area(atoi(node->values.getValOrDefault("w", "1024").c_str()),
+			atoi(node->values.getValOrDefault("h", "100").c_str()));
+		area.translate(intProperty(*node, "x"), intProperty(*node, "y"));
+		getGameLoaderInventory()->setItemArea(_scene._sceneId, area, atoi(node->values.getValOrDefault("interval", "10").c_str()));
+		return true;
+	}
 
 	bool parserCallback_ADDANI(ParserNode *node) {
 		PicAniInfo ref;
@@ -776,6 +807,26 @@ private:
 			cmd->_y = atoi(node->values.getValOrDefault("y", "-1").c_str());
 			cmd->_z = atoi(node->values.getValOrDefault("z", "-1").c_str());
 			cmd->_auxParam = node->values.contains("mirror") ? (int)boolProperty(*node, "mirror") : -1;
+		} else if (kind == "SETSCENE") {
+			cmd->_cmd = Command::kCmdSetScene;
+			if (!readId(node->values.getValOrDefault("scene"), cmd->_parentId))
+				return parserError("Unknown destination scene");
+			idProperty = "entr";
+		} else if (kind == "ADD_INV_ITEM" || kind == "REMOVE_INV_ITEM") {
+			cmd->_cmd = kind == "ADD_INV_ITEM" ? 56 : 57;
+			if (!readId(node->values.getValOrDefault("id"), cmd->_parentId))
+				return parserError("Unknown inventory item");
+		} else if (kind == "USER" && node->values.getValOrDefault("type") == "SET_LOGIC") {
+			cmd->_cmd = Command::kCmdSetLogic;
+			cmd->_messageName = node->values.getValOrDefault("title");
+			cmd->_messageNum = intProperty(*node, "state");
+		} else if (kind == "USER" && node->values.getValOrDefault("type") == "MOVE_TO_STATIC") {
+			cmd->_cmd = 19;
+			cmd->_auxParam = !node->values.contains("needShow") || boolProperty(*node, "needShow");
+			if (!readId(node->values.getValOrDefault("ani"), cmd->_parentId))
+				return parserError("Unknown object in MOVE_TO_STATIC");
+			if (!node->values.getValOrDefault("static").empty())
+				idProperty = "static";
 		} else if (kind == "USER" || kind == "12" || kind == "SET_STATIC" || kind == "25") {
 			cmd->_cmd = 63;
 			cmd->_messageName = node->values.getValOrDefault("type", kind);
@@ -820,7 +871,9 @@ private:
 				return parserError("Unknown " + Common::String(idProperty) + " in " + kind);
 			cmd->_messageNum = id;
 		}
-		if (getParentNode(node)->name == "QUEUE") {
+		if (getParentNode(node)->name == "INTERACTION") {
+			_interaction->_messageQueue->addCommandToEnd(cmd.release());
+		} else if (getParentNode(node)->name == "QUEUE") {
 			_scene._messageQueues.back()->addCommandToEnd(cmd.release());
 		} else {
 			Movement &movement = *_scene._aniObjects.back()->_movements.back();
@@ -980,6 +1033,48 @@ private:
 		const ParserNode *parent = getParentNode(node);
 		if (!parent)
 			return false;
+		if (parent->name == "PICTURE" && node->name == "HITREGION" && node->values.getValOrDefault("type") == "rect") {
+			int16 id;
+			if (!readId(parent->values["id"], id))
+				return parserError("Unknown hit region owner");
+			PictureObject *picture = _scene.findPictureObjectById(id, 0);
+			const Dims size = picture->getFullSize();
+			picture->_hitRegion = Common::Rect(intProperty(*node, "left"), intProperty(*node, "top"),
+				size.x + intProperty(*node, "right"), size.y + intProperty(*node, "bottom"));
+			node->layout = _XMLkeys;
+			return true;
+		}
+		if (parent->name == "INTERACTIONS") {
+			node->layout = _XMLkeys;
+			_interaction = nullptr;
+			int16 sceneId;
+			if (node->name != "INTERACTION" || !readId(node->values.getValOrDefault("scene"), sceneId) || sceneId != _scene._sceneId)
+				return true;
+			Common::ScopedPtr<Interact> action(new Interact());
+			if (!readId(node->values.getValOrDefault("object"), action->_objectId))
+				return parserError("Unknown interaction object");
+			action->_sceneId = sceneId;
+			action->_actionName = node->values.getValOrDefault("id");
+			readId(node->values.getValOrDefault("hero"), action->_heroId);
+			readId(node->values.getValOrDefault("heroStatic"), action->_heroStaticId);
+			action->_heroOffsetX = intProperty(*node, "x");
+			action->_heroOffsetY = intProperty(*node, "y");
+			action->_heroMirror = boolProperty(*node, "heroMirror");
+			action->_field_28 = intProperty(*node, "ves");
+			const Common::String item = node->values.getValOrDefault("curor_obj_id");
+			if (item == "ANY_OBJECT")
+				action->_cursorObjectId = -2;
+			else if (!item.empty() && item != "0")
+				readId(item, action->_cursorObjectId);
+			action->_messageQueue = new MessageQueue();
+			_interaction = action.release();
+			_actions.push_back(_interaction);
+			return true;
+		}
+		if (parent->name == "INTERACTION") {
+			node->layout = _XMLkeys;
+			return !_interaction || node->name != "COMMAND" || parserCallback_COMMAND(node);
+		}
 		if (parent->name == "INVENTORY") {
 			node->layout = _XMLkeys;
 			if (node->name == "GUIMNGR")
@@ -988,6 +1083,7 @@ private:
 				return parserCallback_PICTURE(node);
 			if (node->name == "ITEM") {
 				InventoryPoolItem item = {};
+				readId(node->values.getValOrDefault("visSel"), item.pictureObjectSelected);
 				if (readId(node->values.getValOrDefault("id"), item.id) && readId(node->values.getValOrDefault("vis"), item.pictureObjectNormal))
 					getGameLoaderInventory()->addPoolItem(item);
 			}
@@ -1030,6 +1126,12 @@ void SceneTag::loadSceneXML(const GameProject &project) {
 		return;
 	}
 
+	if (_sceneId == SC_1) {
+		parser.close();
+		if (!parser.loadFile("data/interactions.xml") || !parser.parse())
+			return;
+		parser.registerInteractions();
+	}
 	if (_sceneId == SC_INV) {
 		parser.close();
 		if (!parser.loadFile("data/res/inventory.xml") || !parser.parse())


Commit: 507429913e3f3f120ae042427e23c5550c87a7b0
    https://github.com/scummvm/scummvm/commit/507429913e3f3f120ae042427e23c5550c87a7b0
Author: Eugene Sandulenko (sev at scummvm.org)
Date: 2026-11-28T14:18:26+01:00

Commit Message:
NGI: Share localized game text loading between XML dialogs

Changed paths:
    engines/ngi/font.cpp
    engines/ngi/font.h
    engines/ngi/fullpipe/sceneChapter.cpp


diff --git a/engines/ngi/font.cpp b/engines/ngi/font.cpp
index 110b24ed7c9..c42876eb8d5 100644
--- a/engines/ngi/font.cpp
+++ b/engines/ngi/font.cpp
@@ -23,10 +23,72 @@
 #include "ngi/font.h"
 #include "ngi/objects.h"
 #include "ngi/gfx.h"
+#include "common/file.h"
 #include "common/formats/xmlparser.h"
 
 namespace NGI {
 
+class TextContainer::Loader : public Common::XMLParser {
+public:
+	explicit Loader(Common::StringMap &strings) : _strings(strings) {}
+
+private:
+	Common::StringMap &_strings;
+	CUSTOM_XML_PARSER(Loader) {
+		XML_KEY(TEXTCONTAINER)
+			XML_KEY(TEXT)
+				XML_PROP(id, true)
+				XML_PROP(text, true)
+			KEY_END()
+		KEY_END()
+	} PARSER_END()
+	bool handleUnknownKey(ParserNode *node) override {
+		if (!getParentNode(node))
+			return false;
+		node->ignore = true;
+		node->layout = _XMLkeys;
+		return true;
+	}
+	bool parserCallback_TEXTCONTAINER(ParserNode *) { return true; }
+	bool parserCallback_TEXT(ParserNode *node) {
+		_strings[node->values["id"]] = node->values["text"];
+		return true;
+	}
+};
+
+bool TextContainer::load(const Common::Path &directory) {
+	Common::File encoding, texts;
+	if (!encoding.open(directory.join("enc.dat")) || encoding.size() < 2 || (encoding.size() & 1) ||
+			!texts.open(directory.join("texts.xml")) || texts.readUint16LE() != 0xfeff)
+		return false;
+
+	Common::HashMap<uint16, byte> codes;
+	for (int i = 128; encoding.pos() + 2 < encoding.size(); ++i) {
+		const uint16 c = encoding.readUint16LE();
+		if (!codes.contains(c))
+			codes[c] = i;
+	}
+	const uint16 first = encoding.readUint16LE();
+	const int base = codes.size() + 1 - 128 - first;
+	// The UTF-16 resource starts with a code page line and ends with </TEXTCONTAINER>.
+	const int64 size = texts.size();
+	while (texts.pos() + 2 <= size) {
+		if (texts.readUint16LE() == '\n')
+			break;
+	}
+	Common::String xml("<?xml version=\"1.0\"?><TEXTCONTAINER>");
+	while (texts.pos() + 2 <= size) {
+		const uint16 c = texts.readUint16LE();
+		xml += c < 128 ? (byte)c : codes.getValOrDefault(c, (byte)(base + c));
+	}
+	Common::StringMap strings;
+	Loader parser(strings);
+	if (!parser.loadBuffer((const byte *)xml.c_str(), xml.size()) || !parser.parse())
+		return false;
+	_strings = strings;
+	return true;
+}
+
 class BitmapFont::Loader : public Common::XMLParser {
 public:
 	Loader(BitmapFont &font, const Common::Path &path) : _font(font), _directory(path.getParent()) {}
diff --git a/engines/ngi/font.h b/engines/ngi/font.h
index 990dd14b563..bf4f74a9aea 100644
--- a/engines/ngi/font.h
+++ b/engines/ngi/font.h
@@ -25,6 +25,8 @@
 #include "common/array.h"
 #include "common/hashmap.h"
 #include "common/path.h"
+#include "common/str.h"
+#include "common/hash-str.h"
 #include "common/ptr.h"
 #include "graphics/font.h"
 
@@ -32,6 +34,16 @@ namespace NGI {
 
 class Texture;
 
+class TextContainer {
+public:
+	bool load(const Common::Path &directory);
+	Common::String getText(const Common::String &id) const { return _strings.getValOrDefault(id); }
+
+private:
+	class Loader;
+	Common::StringMap _strings;
+};
+
 class BitmapFont : public Graphics::Font {
 public:
 	bool load(const Common::Path &path);
diff --git a/engines/ngi/fullpipe/sceneChapter.cpp b/engines/ngi/fullpipe/sceneChapter.cpp
index b0c87284c03..4013321937e 100644
--- a/engines/ngi/fullpipe/sceneChapter.cpp
+++ b/engines/ngi/fullpipe/sceneChapter.cpp
@@ -43,33 +43,11 @@ public:
 			return false;
 		close();
 
-		Common::File encoding, texts;
-		if (!encoding.open(directory.join("enc.dat")) || encoding.size() < 2 || (encoding.size() & 1) ||
-				!texts.open(directory.join("texts.xml")) || texts.readUint16LE() != 0xfeff)
+		TextContainer texts;
+		if (!texts.load(directory))
 			return false;
-
-		Common::HashMap<uint16, byte> codes;
-		for (int i = 128; encoding.pos() + 2 < encoding.size(); ++i) {
-			const uint16 c = encoding.readUint16LE();
-			if (!codes.contains(c))
-				codes[c] = i;
-		}
-		const uint16 first = encoding.readUint16LE();
-		const int base = codes.size() + 1 - 128 - first;
-		// The UTF-16 resource starts with a code page line and ends with </TEXTCONTAINER>.
-		const int64 size = texts.size();
-		while (texts.pos() + 2 <= size) {
-			if (texts.readUint16LE() == '\n')
-				break;
-		}
-		Common::String xml("<?xml version=\"1.0\"?><TEXTCONTAINER>");
-		while (texts.pos() + 2 <= size) {
-			const uint16 c = texts.readUint16LE();
-			xml += c < 128 ? (byte)c : codes.getValOrDefault(c, (byte)(base + c));
-		}
-		if (!loadBuffer((const byte *)xml.c_str(), xml.size()) || !parse())
-			return false;
-		close();
+		_title = texts.getText("STR_CHAPTER");
+		_text = texts.getText(_textId);
 		if (_title.empty() || _text.empty())
 			return false;
 		_title += Common::String::format("%d", _number);
@@ -102,16 +80,9 @@ private:
 			XML_PROP(fadeout_delay, false)
 			XML_PROP(sound_delay, false)
 		KEY_END()
-		XML_KEY(TEXTCONTAINER)
-			XML_KEY(TEXT)
-				XML_PROP(id, true)
-				XML_PROP(text, true)
-			KEY_END()
-		KEY_END()
 	} PARSER_END()
 
 	bool parserCallback_CHAPTERS(ParserNode *) { return true; }
-	bool parserCallback_TEXTCONTAINER(ParserNode *) { return true; }
 
 	bool parserCallback_CHAPTER(ParserNode *node) {
 		++_chapterIndex;
@@ -144,15 +115,6 @@ private:
 		return true;
 	}
 
-	bool parserCallback_TEXT(ParserNode *node) {
-		const Common::String &id = node->values["id"];
-		if (id == "STR_CHAPTER")
-			_title = node->values["text"];
-		if (id == _textId)
-			_text = node->values["text"];
-		return true;
-	}
-
 	bool handleUnknownKey(ParserNode *node) override {
 		if (!getParentNode(node))
 			return false;


Commit: fc214685fe0feec8601d78254db0963500216dad
    https://github.com/scummvm/scummvm/commit/fc214685fe0feec8601d78254db0963500216dad
Author: Eugene Sandulenko (sev at scummvm.org)
Date: 2026-11-28T14:18:26+01:00

Commit Message:
NGI: Play the first-room tutorial and open its notebook task

Changed paths:
  A engines/ngi/fullpipe/sceneTutorial.cpp
    engines/ngi/fullpipe/scene01.cpp
    engines/ngi/gfx.cpp
    engines/ngi/gfx.h
    engines/ngi/module.mk
    engines/ngi/ngi.cpp
    engines/ngi/scene.cpp
    engines/ngi/scene.h
    engines/ngi/scenes.h
    engines/ngi/statics.cpp
    engines/ngi/xmlproject.cpp


diff --git a/engines/ngi/fullpipe/scene01.cpp b/engines/ngi/fullpipe/scene01.cpp
index 63427cf7f09..50392312c45 100644
--- a/engines/ngi/fullpipe/scene01.cpp
+++ b/engines/ngi/fullpipe/scene01.cpp
@@ -73,6 +73,8 @@ static void scene01_onGuiEvent(Scene &inventory, const Common::String &id, const
 		root->setSubVarAsInt("TutorialDisabled", 1);
 		root->setSubVarAsInt("Scene1ExitsDisabled", 0);
 		inventory._guiManager->getElement(id)->hideAndDeactivate();
+	} else if (id == "PIC_INV_TASK") {
+		sceneNotebook_show();
 	} else {
 		warning("STUB: Inventory::onGuiEvent(%s, %s)", id.c_str(), event.c_str());
 	}
diff --git a/engines/ngi/fullpipe/sceneTutorial.cpp b/engines/ngi/fullpipe/sceneTutorial.cpp
new file mode 100644
index 00000000000..18a85faa94e
--- /dev/null
+++ b/engines/ngi/fullpipe/sceneTutorial.cpp
@@ -0,0 +1,327 @@
+/* ScummVM - Graphic Adventure Engine
+ *
+ * ScummVM is the legal property of its developers, whose names
+ * are too numerous to list here. Please refer to the COPYRIGHT
+ * file distributed with this source distribution.
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ *
+ */
+
+#include "ngi/ngi.h"
+#include "ngi/constants.h"
+#include "ngi/font.h"
+#include "ngi/gameloader.h"
+#include "ngi/modal.h"
+#include "ngi/motion.h"
+#include "ngi/scenes.h"
+#include "ngi/statics.h"
+#include "common/formats/xmlparser.h"
+
+namespace NGI {
+
+namespace {
+
+enum TutorialStep { kFirst, kMoveMan, kSeeTask, kUseTask, kUseTransition, kLast, kDone };
+const char *const tutorialIds[] = { "TUTORIAL_FIRST", "TUTORIAL_MOVE_MAN", "TUTORIAL_SEE_TASK", "TUTORIAL_USE_TASK", "TUTORIAL_USE_TRANSITION", "TUTORIAL_LAST" };
+
+int resourceId(const Common::String &name) {
+	uint32 id;
+	return g_nmi->_gameProject->_objectIds.findId(name, id) ? id : 0;
+}
+
+class Tutorial : public Common::XMLParser {
+public:
+	explicit Tutorial(const char *id) : _id(id) {}
+	Common::String _text;
+	Common::Point _bearded, _arrow;
+	int _angle = 0, _cloud = 0, _button = 0, _left = 0, _top = 0, _right = 0, _bottom = 0;
+	bool _mirror = false, _hasArrow = false;
+
+private:
+	Common::String _id;
+
+	CUSTOM_XML_PARSER(Tutorial) {
+		XML_KEY(TUTORIALS)
+		KEY_END()
+	} PARSER_END()
+
+	bool parserCallback_TUTORIALS(ParserNode *) { return true; }
+	bool handleUnknownKey(ParserNode *node) override {
+		node->layout = _XMLkeys;
+		const auto &attrs = node->values;
+		if (node->name == "TUTORIAL") {
+			node->ignore = attrs.getValOrDefault("id") != _id;
+			if (!node->ignore)
+				_text = attrs.getValOrDefault("text_id");
+		} else if (!getParentNode(node) || getParentNode(node)->values.getValOrDefault("id") != _id) {
+			node->ignore = true;
+		} else if (node->name == "BEARDED") {
+			_bearded = Common::Point(number(node, "posX"), number(node, "posY"));
+			_mirror = attrs.getValOrDefault("isMirror") == "true";
+		} else if (node->name == "CLOUD") {
+			_cloud = number(node, "view");
+			_button = attrs.getValOrDefault("isButton") == "true" ? number(node, "viewButton") : 0;
+		} else if (node->name == "TEXT") {
+			_left = number(node, "left_offset");
+			_right = number(node, "right_offset");
+			_top = number(node, "top_offset");
+			_bottom = number(node, "bottom_offset");
+		} else if (node->name == "ARROW") {
+			_angle = number(node, "angle");
+			_hasArrow = attrs.getValOrDefault("is") == "true";
+			_arrow = Common::Point(number(node, "posX"), number(node, "posY"));
+		} else {
+			node->ignore = true;
+		}
+		return true;
+	}
+
+	static int number(ParserNode *node, const char *name) {
+		return atoi(node->values.getValOrDefault(name).c_str());
+	}
+};
+
+class ModalTutorial : public BaseModalObject {
+public:
+	ModalTutorial(Scene &scene, TutorialStep step) : _scene(scene), _step(step), _layout(tutorialIds[step]) {}
+
+	bool open() {
+		const Common::Path directory(Common::String("data/res_") + g_nmi->getResourceLocale());
+		TextContainer strings;
+		if (!_layout.loadFile("data/tutorials.xml") || !_layout.parse() || !strings.load(directory) ||
+			!_font.load(directory.join("Fonts/task_dlg_19.fnt")))
+			return false;
+		_text = strings.getText(_layout._text);
+		_cloud = _scene.findPictureObjectById(resourceId(Common::String::format("PIC_SC_TUTORIAL_CLOUD_%d", _layout._cloud)), 0);
+		_man = _scene.findAniObjectById(resourceId("ANI_SC_TUTORIAL_BEARDED"), 0);
+		if (!_cloud || !_man || !_scene._guiManager || _text.empty())
+			return false;
+		for (const char *id : {"BTN_SC_TUTORIAL_CONTINUE", "BTN_SC_TUTORIAL_OK"}) {
+			if (GuiElement *element = _scene._guiManager->getElement(id))
+				element->hideAndDeactivate();
+		}
+		_button = _layout._button ? _scene._guiManager->getElement(_layout._button == 2 ? "BTN_SC_TUTORIAL_OK" : "BTN_SC_TUTORIAL_CONTINUE") : nullptr;
+		_man->setPos(_layout._bearded.x, _layout._bearded.y);
+		_man->_statics = _man->getStatic(resourceId("ST_SC_TUTORIAL_BEARDED_UP"));
+		_man->_flags = 4 | (_layout._mirror ? 8 : 0);
+		_man->startMovement(resourceId("MOV_SC_TUTORIAL_BEARDED_FALL"), 0, -1, _layout._mirror);
+		debugC(1, kDebugSceneLogic, "Started %s", tutorialIds[_step]);
+		return true;
+	}
+
+	bool init(int elapsed) override {
+		if (_finished)
+			return false;
+		_man->update(elapsed);
+		if (_arrow) {
+			if (!_arrow->_movement)
+				_arrow->startMovement(resourceId("MV_SC_TUTORIAL_ARROW"), 0, -1);
+			_arrow->update(elapsed);
+		}
+		if (!_man->_movement && !_shown) {
+			const Dims man = _man->getFullSize();
+			const Dims cloud = _cloud->getFullSize();
+			_pos = Common::Point(_man->_x + (_layout._mirror ? man.x - 50 : 50 - cloud.x),
+				_man->_y + man.y - cloud.y - 50);
+			const int buttonY = _pos.y + (cloud.y - (_button ? _button->_size.y : 0)) / 2 + (_layout._cloud == 2 ? 40 : 50);
+			if (_button) {
+				_button->setPos(Common::Point(_pos.x + (cloud.x - _button->_size.x) / 2, buttonY));
+				_button->showAndActivate();
+			}
+			_bounds = Common::Rect(_pos.x + _layout._left, _pos.y + _layout._top,
+				_pos.x + cloud.x + _layout._right, buttonY + _layout._bottom);
+			if (_layout._hasArrow) {
+				_arrow = _scene.findAniObjectById(resourceId("ANI_SC_TUTORIAL_ARROW"), 0);
+				if (_arrow) {
+					_arrow->setPos(_layout._arrow.x, _layout._arrow.y);
+					_arrow->_encodedRotation = _layout._angle;
+					_arrow->_flags |= 4;
+				}
+			}
+			_shown = true;
+			debugC(2, kDebugSceneLogic, "Showing %s cloud %d at %d,%d", tutorialIds[_step], _layout._cloud, _pos.x, _pos.y);
+		}
+		return true;
+	}
+
+	void update() override {
+		g_nmi->_currentScene->render();
+		if (g_nmi->_inventoryScene && g_nmi->_inventoryScene->_guiManager)
+			g_nmi->_inventoryScene->_guiManager->render(g_nmi->_backgroundSurface);
+		if (_step == kUseTask && _parentObj)
+			_parentObj->update();
+		_man->render();
+		if (!_shown)
+			return;
+		_cloud->_picture->blitTo(g_nmi->_backgroundSurface, _pos);
+		_font.drawCentered(g_nmi->_backgroundSurface, _bounds, _text);
+		if (_arrow)
+			_arrow->render();
+		_scene._guiManager->render(g_nmi->_backgroundSurface);
+	}
+
+	bool handleMessage(Command *cmd) override {
+		if (cmd->_cmd != 17 || cmd->_messageNum != 30)
+			return false;
+		const Common::Point pos(cmd->_x, cmd->_y);
+		GameVar *root = g_nmi->getGameLoaderGameVar();
+		if (g_nmi->_inventoryScene) {
+			GuiManager *hud = g_nmi->_inventoryScene->_guiManager.get();
+			GuiElement *skip = hud ? hud->getElement("BTN_SKIP") : nullptr;
+			if (skip && skip->hit(pos)) {
+				hud->onMouseMove(pos);
+				hud->onMouseLKeyUp(pos);
+				_finished = true;
+				return true;
+			}
+		}
+		if (!_shown)
+			return false;
+		if (_button) {
+			if (!_button->hit(pos))
+				return false;
+			_scene._guiManager->onMouseMove(pos);
+			_scene._guiManager->onMouseLKeyUp(pos);
+		} else if (_step == kMoveMan) {
+			Scene &room = *g_nmi->_currentScene;
+			if (!room._motionController || !room._motionController->startMove(g_nmi->_aniMan, pos.x + room._x, pos.y + room._y, 0, 0))
+				return false;
+		} else if (_step == kSeeTask) {
+			GuiElement *task = g_nmi->_inventoryScene->_guiManager->getElement("PIC_INV_TASK");
+			if (!task || !task->hit(pos))
+				return false;
+		} else if (_step == kUseTransition) {
+			const int pipe = resourceId("PIC_SC1_RTRUBA");
+			PictureObject *picture = g_nmi->_currentScene->findPictureObjectAtPos(pos.x, pos.y);
+			if (!picture || picture->_id != pipe)
+				return false;
+			root->setSubVarAsInt("Scene1ExitsDisabled", 0);
+			if (!scene01_click(pos)) {
+				root->setSubVarAsInt("Scene1ExitsDisabled", 1);
+				return false;
+			}
+		}
+		root->setSubVarAsInt("TutorialStep", _step + 1);
+		_finished = true;
+		debugC(1, kDebugSceneLogic, "Finished %s", tutorialIds[_step]);
+		return true;
+	}
+	bool pollEvent() override { return true; }
+	void saveload() override {}
+
+private:
+	Scene &_scene;
+	TutorialStep _step;
+	Tutorial _layout;
+	BitmapFont _font;
+	Common::String _text;
+	AniObject *_man = nullptr, *_arrow = nullptr;
+	PictureObject *_cloud = nullptr;
+	GuiElement *_button = nullptr;
+	Common::Point _pos;
+	Common::Rect _bounds;
+	bool _finished = false, _shown = false;
+};
+
+class ModalNotebook : public BaseModalObject {
+public:
+	explicit ModalNotebook(Scene &scene) : _scene(scene) {}
+	bool open() {
+		const Common::Path directory(Common::String("data/res_") + g_nmi->getResourceLocale());
+		TextContainer strings;
+		if (!strings.load(directory) || !_font.load(directory.join("Fonts/task_dlg_19.fnt")))
+			return false;
+		_title = strings.getText("STR_FIND_BOOT_SC4_TITLE");
+		return !_title.empty() && _scene._guiManager;
+	}
+
+	bool pollEvent() override { return true; }
+	void saveload() override {}
+	bool init(int) override { return !_closed; }
+	void update() override {
+		g_nmi->_currentScene->render();
+		_scene.render(false);
+		_font.drawCentered(g_nmi->_backgroundSurface, Common::Rect(130, 240, 380, 360), _title);
+	}
+	bool handleMessage(Command *cmd) override {
+		if (cmd->_cmd != 17)
+			return false;
+		GuiElement *close = _scene._guiManager->getElement("BTN_SC_NOTEBOOK_CLOSE");
+		if ((cmd->_messageNum == 30 && close && close->hit(Common::Point(cmd->_x, cmd->_y))) ||
+				cmd->_messageNum == 37) {
+			_closed = true;
+			return true;
+		}
+		return false;
+	}
+private:
+	Scene &_scene;
+	BitmapFont _font;
+	Common::String _title;
+	bool _closed = false;
+};
+
+void showTutorial(TutorialStep step) {
+	Scene *scene = g_nmi->findScene(resourceId("SC_TUTORIAL"));
+	if (scene) {
+		Common::ScopedPtr<ModalTutorial> dialog(new ModalTutorial(*scene, step));
+		if (dialog->open()) {
+			dialog->_parentObj = g_nmi->_modalObject;
+			g_nmi->_modalObject = dialog.release();
+			return;
+		}
+	}
+	warning("Could not open tutorial %s", tutorialIds[step]);
+	g_nmi->getGameLoaderGameVar()->setSubVarAsInt("TutorialDisabled", 1);
+	g_nmi->getGameLoaderGameVar()->setSubVarAsInt("Scene1ExitsDisabled", 0);
+}
+
+} // End of anonymous namespace
+
+void sceneNotebook_show() {
+	Scene *scene = g_nmi->findScene(resourceId("SC_NOTEBOOK"));
+	if (!scene)
+		return;
+	Common::ScopedPtr<ModalNotebook> notebook(new ModalNotebook(*scene));
+	if (notebook->open()) {
+		notebook->_parentObj = g_nmi->_modalObject;
+		g_nmi->_modalObject = notebook.release();
+		if (g_nmi->getGameLoaderGameVar()->getSubVarAsInt("TutorialStep") == kUseTask)
+			showTutorial(kUseTask);
+	}
+}
+
+void sceneTutorial_check() {
+	const int scene = g_nmi->_currentScene->_sceneId;
+	if (scene != SC_1 && scene != SC_3)
+		return;
+	GameVar *root = g_nmi->getGameLoaderGameVar();
+	if (root->getSubVarAsInt("TutorialDisabled"))
+		return;
+	const int step = root->getSubVarAsInt("TutorialStep");
+	if (step >= kDone || ((scene == SC_3) != (step == kLast)))
+		return;
+	if (!g_nmi->_aniMan || g_nmi->_aniMan->_messageQueueId || g_nmi->_aniMan->_movement)
+		return;
+	for (const MessageQueue *queue : *g_nmi->_globalMessageQueueList)
+		if (queue->_queueId == QU_SC1_ENTER && !queue->_isFinished)
+			return;
+	if (step == kUseTask)
+		sceneNotebook_show();
+	else
+		showTutorial(static_cast<TutorialStep>(step));
+}
+
+} // End of namespace NGI
diff --git a/engines/ngi/gfx.cpp b/engines/ngi/gfx.cpp
index 70f6ce747cd..6768cd925ae 100644
--- a/engines/ngi/gfx.cpp
+++ b/engines/ngi/gfx.cpp
@@ -33,6 +33,7 @@
 #include "graphics/managed_surface.h"
 
 #include "image/png.h"
+#include "graphics/transform_struct.h"
 
 namespace NGI {
 
@@ -453,10 +454,17 @@ void Texture::loadPNG(const Common::Path &path, const Dims &sizeHint) {
 	debugC(2, kDebugLoading, "Loaded scene texture %s (%d x %d)", path.toString().c_str(), _width, _height);
 }
 
-void Texture::blitTo(Graphics::ManagedSurface &target, const Common::Point &position, bool mirror) const {
+void Texture::blitTo(Graphics::ManagedSurface &target, const Common::Point &position, bool mirror, int angle) const {
 	if (!_bitmap || !_bitmap->_surface)
 		return;
-	if (mirror)
+	if (angle) {
+		const Graphics::ManagedSurface &surface = *_bitmap->_surface;
+		Graphics::TransformStruct transform;
+		transform._angle = angle;
+		transform._hotspot = Common::Point(surface.w / 2, surface.h / 2);
+		Common::ScopedPtr<Graphics::ManagedSurface> rotated(surface.rotoscale(transform));
+		target.blitFrom(*rotated, position + transform._hotspot - Common::Point(rotated->w / 2, rotated->h / 2));
+	} else if (mirror)
 		target.simpleBlitFrom(*_bitmap->_surface, position, Graphics::FLIP_H, true);
 	else
 		target.blitFrom(*_bitmap->_surface, position);
diff --git a/engines/ngi/gfx.h b/engines/ngi/gfx.h
index ede2b1fa570..fec82fc32d5 100644
--- a/engines/ngi/gfx.h
+++ b/engines/ngi/gfx.h
@@ -90,7 +90,7 @@ public:
 
 	bool load(MfcArchive &file) override;
 	void loadPNG(const Common::Path &path, const Dims &sizeHint);
-	void blitTo(Graphics::ManagedSurface &target, const Common::Point &position, bool mirror = false) const;
+	void blitTo(Graphics::ManagedSurface &target, const Common::Point &position, bool mirror = false, int angle = 0) const;
 	void blitTo(Graphics::ManagedSurface &target, const Common::Rect &source, const Common::Point &position) const;
 	void setAOIDs();
 	virtual void init();
diff --git a/engines/ngi/module.mk b/engines/ngi/module.mk
index cfa87b12a7a..f60f2cc9b8d 100644
--- a/engines/ngi/module.mk
+++ b/engines/ngi/module.mk
@@ -29,6 +29,7 @@ MODULE_OBJS = \
 	xmlproject.o \
 	statics.o \
 	utils.o \
+	fullpipe/sceneTutorial.o \
 	fullpipe/sceneChapter.o \
 	fullpipe/sceneIntro.o \
 	fullpipe/sceneIntroDemo.o \
diff --git a/engines/ngi/ngi.cpp b/engines/ngi/ngi.cpp
index b9092559291..2d4efbcc88d 100644
--- a/engines/ngi/ngi.cpp
+++ b/engines/ngi/ngi.cpp
@@ -300,6 +300,8 @@ bool NGIEngine::handleGuiEvent(const Common::Event &event) {
 			Command cmd;
 			cmd._cmd = 17;
 			cmd._messageNum = back ? 37 : 30;
+			cmd._x = event.mouse.x;
+			cmd._y = event.mouse.y;
 			cmd._param = back ? kActionCloseDialog : 0;
 			_modalObject->handleMessage(&cmd);
 		}
@@ -640,6 +642,8 @@ Common::Error NGIEngine::updateScreen(uint32 elapsed, byte &brightness, bool red
 			redraw |= sceneIntro_updateAndroid(elapsed, brightness);
 		if (timedUpdates)
 			processMessages();
+		if (isAndroidFullPipe() && !_modalObject && !_gameLoader->_preloadSceneId)
+			sceneTutorial_check();
 	}
 	const bool renderScene = !_modalObject;
 	if (_modalObject && (timedUpdates || _flgGameIsRunning)) {
diff --git a/engines/ngi/scene.cpp b/engines/ngi/scene.cpp
index cf832e4215e..bafc0eac1f0 100644
--- a/engines/ngi/scene.cpp
+++ b/engines/ngi/scene.cpp
@@ -473,9 +473,10 @@ void Scene::sortRenderables(Common::Array<T *> &list, uint startIndex) {
 	}
 }
 
-void Scene::render() {
+void Scene::render(bool clear) {
 	debugC(6, kDebugDrawing, ">>>>> Scene::render()");
-	g_nmi->_backgroundSurface.clear(0);
+	if (clear)
+		g_nmi->_backgroundSurface.clear(0);
 	if (g_nmi->_gameVersion >= 201509) {
 		Common::Array<GameObject *> visibleObjects;
 		for (PictureObject *picture : _pictureObjects) {
diff --git a/engines/ngi/scene.h b/engines/ngi/scene.h
index 745d1479e15..86fa79c2b45 100644
--- a/engines/ngi/scene.h
+++ b/engines/ngi/scene.h
@@ -69,7 +69,7 @@ class Scene : public Background {
 
 	void initStaticANIObjects();
 	void init();
-	void render();
+	void render(bool clear = true);
 	void drawContent(int minPri, int maxPri, bool drawBG);
 	void updateScrolling();
 	void updateScrolling2();
diff --git a/engines/ngi/scenes.h b/engines/ngi/scenes.h
index 1b7269343b9..b29073b2e80 100644
--- a/engines/ngi/scenes.h
+++ b/engines/ngi/scenes.h
@@ -51,6 +51,8 @@ private:
 };
 
 int defaultUpdateCursor();
+void sceneTutorial_check();
+void sceneNotebook_show();
 void sceneChapter_show(const char *chapterId);
 
 int sceneIntro_updateCursor();
diff --git a/engines/ngi/statics.cpp b/engines/ngi/statics.cpp
index 7ed2c7e4837..67e7b3ebad7 100644
--- a/engines/ngi/statics.cpp
+++ b/engines/ngi/statics.cpp
@@ -566,7 +566,7 @@ void AniObject::render(Common::Point scroll) {
 			const bool mirror = (_flags & 8) != 0;
 			if (mirror)
 				anchor.x = phase->getDimensions().x - anchor.x;
-			phase->blitTo(g_nmi->_backgroundSurface, Common::Point(_x, _y) - scroll - anchor, mirror);
+			phase->blitTo(g_nmi->_backgroundSurface, Common::Point(_x, _y) - scroll - anchor, mirror, _encodedRotation);
 		}
 		return;
 	}
diff --git a/engines/ngi/xmlproject.cpp b/engines/ngi/xmlproject.cpp
index 74d86387a3c..9a04eb22bb4 100644
--- a/engines/ngi/xmlproject.cpp
+++ b/engines/ngi/xmlproject.cpp
@@ -449,6 +449,7 @@ private:
 					XML_PROP(scene, false)
 					XML_PROP(entr, false)
 					XML_PROP(needShow, false)
+					XML_PROP(reverse, false)
 					XML_PROP(wait, false)
 					XML_PROP(id, false)
 					XML_PROP(ani, false)
@@ -484,6 +485,7 @@ private:
 				XML_PROP(locale, false)
 			KEY_END()
 			XML_KEY(OLDANI)
+				XML_PROP(filter, false)
 				XML_PROP(mirror, false)
 				XML_PROP(serializable, false)
 				XML_PROP(id, true)
@@ -532,6 +534,7 @@ private:
 					KEY_END()
 				KEY_END()
 			KEY_END()
+			layout.top()->children["ANI"] = layout.top()->children["OLDANI"];
 		KEY_END()
 		XML_KEY(INTERACTIONS)
 		KEY_END()
@@ -703,7 +706,7 @@ private:
 
 		picture->_picture = new Texture();
 		const Common::String resource = Common::String::format("%08hu/%08hu",
-			static_cast<uint16>(_scene._sceneId), static_cast<uint16>(picture->_id));
+			getParentNode(node)->name == "INVENTORY" ? 0 : static_cast<uint16>(_scene._sceneId), static_cast<uint16>(picture->_id));
 		loadTexture(*picture->_picture, resource, isLocalized(*node));
 		picture->setOXY2();
 		_scene.addPicture(picture.release());


Commit: ff5672d16cc36d004f7db2fc5e5e36f0838a8d6a
    https://github.com/scummvm/scummvm/commit/ff5672d16cc36d004f7db2fc5e5e36f0838a8d6a
Author: Eugene Sandulenko (sev at scummvm.org)
Date: 2026-11-28T14:18:26+01:00

Commit Message:
NGI: Furhter work on Scene01

Changed paths:
    engines/ngi/fullpipe/scene01.cpp
    engines/ngi/fullpipe/sceneTutorial.cpp
    engines/ngi/gfx.cpp
    engines/ngi/gfx.h
    engines/ngi/ngi.cpp
    engines/ngi/scene.cpp
    engines/ngi/scene.h
    engines/ngi/scenes.cpp
    engines/ngi/xmlproject.cpp


diff --git a/engines/ngi/fullpipe/scene01.cpp b/engines/ngi/fullpipe/scene01.cpp
index 50392312c45..9284a5551b3 100644
--- a/engines/ngi/fullpipe/scene01.cpp
+++ b/engines/ngi/fullpipe/scene01.cpp
@@ -72,6 +72,7 @@ static void scene01_onGuiEvent(Scene &inventory, const Common::String &id, const
 		GameVar *root = g_nmi->getGameLoaderGameVar();
 		root->setSubVarAsInt("TutorialDisabled", 1);
 		root->setSubVarAsInt("Scene1ExitsDisabled", 0);
+		g_nmi->_currentScene->setExitState(0, 1);
 		inventory._guiManager->getElement(id)->hideAndDeactivate();
 	} else if (id == "PIC_INV_TASK") {
 		sceneNotebook_show();
@@ -145,6 +146,7 @@ int sceneHandler01(Command *cmd) {
 		}
 		if (cmd->_messageName == "MSG_DISABLE_EXIT_MANAGER") {
 			g_nmi->getGameLoaderGameVar()->setSubVarAsInt("Scene1ExitsDisabled", 1);
+			g_nmi->_currentScene->setExitState(0, 0);
 			Scene *inventory = g_nmi->_inventoryScene;
 			if (inventory && inventory->_guiManager) {
 				if (GuiElement *skip = inventory->_guiManager->getElement("BTN_SKIP"))
diff --git a/engines/ngi/fullpipe/sceneTutorial.cpp b/engines/ngi/fullpipe/sceneTutorial.cpp
index 18a85faa94e..9a536eb347e 100644
--- a/engines/ngi/fullpipe/sceneTutorial.cpp
+++ b/engines/ngi/fullpipe/sceneTutorial.cpp
@@ -117,6 +117,9 @@ public:
 		_man->_statics = _man->getStatic(resourceId("ST_SC_TUTORIAL_BEARDED_UP"));
 		_man->_flags = 4 | (_layout._mirror ? 8 : 0);
 		_man->startMovement(resourceId("MOV_SC_TUTORIAL_BEARDED_FALL"), 0, -1, _layout._mirror);
+		g_nmi->_currentScene->setExitState(0, 0);
+		if (_step == kUseTransition)
+			g_nmi->_currentScene->setExitState(resourceId("PIC_SC1_RTRUBA"), 1);
 		debugC(1, kDebugSceneLogic, "Started %s", tutorialIds[_step]);
 		return true;
 	}
@@ -214,6 +217,7 @@ public:
 			}
 		}
 		root->setSubVarAsInt("TutorialStep", _step + 1);
+		g_nmi->_currentScene->setExitState(0, 1);
 		_finished = true;
 		debugC(1, kDebugSceneLogic, "Finished %s", tutorialIds[_step]);
 		return true;
diff --git a/engines/ngi/gfx.cpp b/engines/ngi/gfx.cpp
index 6768cd925ae..1f62b334d32 100644
--- a/engines/ngi/gfx.cpp
+++ b/engines/ngi/gfx.cpp
@@ -105,6 +105,9 @@ PictureObject::PictureObject() {
 
 PictureObject::PictureObject(PictureObject *src) : GameObject(src) {
 	_picture = src->_picture;
+	_ownsTexture = false;
+	_hitRegion = src->_hitRegion;
+	_angle = src->_angle;
 	_ox2 = _x;
 	_oy2 = _y;
 	_pictureObject2List = src->_pictureObject2List;
@@ -112,7 +115,8 @@ PictureObject::PictureObject(PictureObject *src) : GameObject(src) {
 }
 
 PictureObject::~PictureObject() {
-	delete _picture;
+	if (_ownsTexture)
+		delete _picture;
 }
 
 bool PictureObject::load(MfcArchive &file, bool bigPicture) {
@@ -145,7 +149,7 @@ bool PictureObject::load(MfcArchive &file, bool bigPicture) {
 
 void PictureObject::render(Common::Point scroll) {
 	if (g_nmi->_gameVersion >= 201509) {
-		_picture->blitTo(g_nmi->_backgroundSurface, Common::Point(_x, _y) - scroll);
+		_picture->blitTo(g_nmi->_backgroundSurface, Common::Point(_x, _y) - scroll, false, _angle);
 		return;
 	}
 
diff --git a/engines/ngi/gfx.h b/engines/ngi/gfx.h
index fec82fc32d5..3cf32a00c4d 100644
--- a/engines/ngi/gfx.h
+++ b/engines/ngi/gfx.h
@@ -184,6 +184,7 @@ public:
 	void renderAtPos(int x, int y);
 
 	bool setPicAniInfo(const PicAniInfo &picAniInfo);
+	int _angle = 0;
 	Common::Rect _hitRegion; // XML region in picture coordinates.
 	bool isPointInside(int x, int y);
 	bool hit(int x, int y);
@@ -192,6 +193,7 @@ public:
 	Texture *_picture;
 
 private:
+	bool _ownsTexture = true;
 	Common::Array<GameObject> _pictureObject2List;
 	int _ox2;
 	int _oy2;
diff --git a/engines/ngi/ngi.cpp b/engines/ngi/ngi.cpp
index 2d4efbcc88d..f7f8b4f81d1 100644
--- a/engines/ngi/ngi.cpp
+++ b/engines/ngi/ngi.cpp
@@ -306,6 +306,8 @@ bool NGIEngine::handleGuiEvent(const Common::Event &event) {
 			_modalObject->handleMessage(&cmd);
 		}
 	} else {
+		if (event.type == Common::EVENT_LBUTTONUP || event.type == Common::EVENT_LBUTTONDOWN || event.type == Common::EVENT_MOUSEMOVE)
+			_currentScene->updateExitInput(event.mouse, event.type);
 		GuiManager *manager = _currentScene->_guiManager.get();
 		if (_inventoryScene && (event.type == Common::EVENT_LBUTTONDOWN || event.type == Common::EVENT_LBUTTONUP)) {
 			Common::Point pos = event.mouse;
diff --git a/engines/ngi/scene.cpp b/engines/ngi/scene.cpp
index bafc0eac1f0..a9d640e0f5f 100644
--- a/engines/ngi/scene.cpp
+++ b/engines/ngi/scene.cpp
@@ -115,6 +115,78 @@ void SceneTag::loadScene() {
 
 Scene::Scene() : _sceneId(0), _field_BC(0) {}
 
+void Exit::setState(int newState) {
+	state = newState;
+	releaseTime = -1;
+	if (!arrow)
+		return;
+	if (state == 1) {
+		arrow->_flags |= 4;
+		pressed->_flags &= ~4;
+		if (!arrow->_movement)
+			arrow->startMovement(movementId, 0, -1);
+	} else {
+		arrow->_flags &= ~4;
+		if (state == 2)
+			pressed->_flags |= 4;
+		else
+			pressed->_flags &= ~4;
+	}
+}
+
+void Scene::initExits(Scene &common) {
+	for (Exit &exit : _exits) {
+		if (!exit.arrow) {
+			AniObject *animation = common.findAniObjectById(23234, 0); // ANI_ARROW
+			PictureObject *picture = common.findPictureObjectById(23237, 0); // PIC_ARROW_RED
+			if (!animation || !picture) {
+				warning("Missing Full Pipe exit artwork");
+				continue;
+			}
+			exit.arrow = new AniObject(animation);
+			addAni(exit.arrow, true);
+			exit.arrow->_statics = exit.arrow->getStatic(animation->_statics->_staticsId);
+			exit.pressed = new PictureObject(picture);
+			addPicture(exit.pressed);
+			exit.movementId = 23236; // MOV_ARROW_UP
+			const Dims size = exit.destination->getFullSize();
+			Common::Rect area = exit.destination->_hitRegion;
+			if (area.isEmpty())
+				area = Common::Rect(size.x, size.y);
+			const Common::Point center = area.center() + exit.offset + Common::Point(exit.destination->_x, exit.destination->_y);
+			const Dims pressedSize = exit.pressed->getFullSize();
+			const Dims arrowSize = exit.arrow->getFullSize();
+			exit.arrow->setPos(center.x - arrowSize.x / 2, center.y - arrowSize.y / 2);
+			exit.pressed->setPos(center.x - pressedSize.x / 2, center.y - pressedSize.y / 2);
+			exit.arrow->_encodedRotation = exit.pressed->_angle = exit.angle;
+			exit.arrow->_objectFlags = exit.pressed->_objectFlags = 0;
+		}
+		exit.setState(exit.state);
+	}
+}
+
+void Scene::setExitState(int pictureId, int state) {
+	for (Exit &exit : _exits)
+		if (!pictureId || exit.destination->_id == pictureId)
+			exit.setState(state);
+}
+
+void Scene::updateExitInput(Common::Point pos, Common::EventType type) {
+	for (Exit &exit : _exits) {
+		if (!exit.arrow || !exit.state)
+			continue;
+		const bool hit = exit.destination->hit(pos.x + _x, pos.y + _y);
+		if (type == Common::EVENT_LBUTTONUP && exit.state == 2)
+			exit.releaseTime = 0;
+		else if (hit && (type == Common::EVENT_LBUTTONDOWN || type == Common::EVENT_MOUSEMOVE)) {
+			exit.setState(2);
+			if (type == Common::EVENT_LBUTTONDOWN)
+				g_nmi->playSound(0x5ac6, 0);
+		} else if (!hit && type == Common::EVENT_MOUSEMOVE && exit.state == 2)
+			exit.setState(1);
+	}
+}
+
 void Scene::onGuiEvent(const Common::String &id, const Common::String &event) {
 	if (_guiEventHandler)
 		_guiEventHandler(*this, id, event);
@@ -652,6 +724,16 @@ bool Scene::update(int counterdiff) {
 
 	bool changed = false;
 	if (g_nmi->_gameVersion >= 201509) {
+		for (Exit &exit : _exits) {
+			if (!exit.arrow)
+				continue;
+			if (exit.releaseTime >= 0 && (exit.releaseTime += counterdiff) > 82)
+				exit.setState(1);
+			if (exit.state == 1 && !exit.arrow->_movement)
+				exit.arrow->startMovement(exit.movementId, 0, -1);
+			const int z = g_nmi->_aniMan ? g_nmi->_aniMan->_z + 1 : exit.destination->_z - 1;
+			exit.arrow->_z = exit.pressed->_z = z;
+		}
 		if (_behaviorController)
 			changed |= _behaviorController->update(counterdiff);
 		for (MessageQueue *queue : *g_nmi->_globalMessageQueueList)
diff --git a/engines/ngi/scene.h b/engines/ngi/scene.h
index 86fa79c2b45..3d86de333d0 100644
--- a/engines/ngi/scene.h
+++ b/engines/ngi/scene.h
@@ -22,6 +22,8 @@
 #ifndef NGI_SCENE_H
 #define NGI_SCENE_H
 
+#include "common/events.h"
+
 #include "common/ptr.h"
 #include "ngi/objects.h"
 #include "ngi/gfx.h"
@@ -35,6 +37,16 @@ class GameProject;
 class BehaviorController;
 class MctlCompound;
 
+struct Exit {
+	PictureObject *destination = nullptr;
+	AniObject *arrow = nullptr;
+	PictureObject *pressed = nullptr;
+	Common::Point offset;
+	int angle = 0, state = 1, releaseTime = -1;
+	int movementId = 0;
+	void setState(int newState);
+};
+
 class Scene : public Background {
  public:
 	/** list items are owned */
@@ -44,6 +56,10 @@ class Scene : public Background {
 	Common::Array<AniObject *> _renderableAnis;
 	PicAniInfoList _roamingObjects;
 	Common::Array<Entrance> _entrances;
+	Common::Array<Exit> _exits;
+	void initExits(Scene &common);
+	void setExitState(int pictureId, int state);
+	void updateExitInput(Common::Point pos, Common::EventType type);
 	int16 _heroId = 0;
 	Common::ScopedPtr<GuiManager> _guiManager;
 	void (*_guiEventHandler)(Scene &, const Common::String &, const Common::String &) = nullptr;
diff --git a/engines/ngi/scenes.cpp b/engines/ngi/scenes.cpp
index 2901080796a..619d67e828e 100644
--- a/engines/ngi/scenes.cpp
+++ b/engines/ngi/scenes.cpp
@@ -641,6 +641,8 @@ bool NGIEngine::doSetScene(const Entrance &entrance) {
 			scene->_motionController->attachObject(_aniMan);
 			scene->_motionController->activate();
 		}
+		if (common && !scene->_exits.empty())
+			scene->initExits(*common);
 		if (intro2) {
 			sceneIntro_initGui(*scene, *intro2, _backgroundSurface.w);
 			sceneIntro_initMan(*scene);
diff --git a/engines/ngi/xmlproject.cpp b/engines/ngi/xmlproject.cpp
index 9a04eb22bb4..2ab389878dd 100644
--- a/engines/ngi/xmlproject.cpp
+++ b/engines/ngi/xmlproject.cpp
@@ -536,6 +536,8 @@ private:
 			KEY_END()
 			layout.top()->children["ANI"] = layout.top()->children["OLDANI"];
 		KEY_END()
+		XML_KEY(EXITMANAGER)
+		KEY_END()
 		XML_KEY(INTERACTIONS)
 		KEY_END()
 		XML_KEY(INVENTORY)
@@ -563,6 +565,8 @@ private:
 		return true;
 	}
 
+	bool parserCallback_EXITMANAGER(ParserNode *) { return true; }
+
 	bool parserCallback_INTERACTIONS(ParserNode *) { return true; }
 
 	bool parserCallback_INVENTORY(ParserNode *node) {
@@ -1047,6 +1051,21 @@ private:
 			node->layout = _XMLkeys;
 			return true;
 		}
+		if (parent->name == "EXITMANAGER") {
+			node->layout = _XMLkeys;
+			int16 id;
+			if (node->name == "EXIT" && readId(node->values.getValOrDefault("vis_dst"), id)) {
+				if (PictureObject *object = _scene.findPictureObjectById(id, 0)) {
+					Exit exit;
+					exit.destination = object;
+					exit.angle = intProperty(*node, "angle");
+					exit.offset = Common::Point(intProperty(*node, "offsetX"), intProperty(*node, "offsetY"));
+					exit.state = atoi(node->values.getValOrDefault("state", "1").c_str());
+					_scene._exits.push_back(exit);
+				}
+			}
+			return true;
+		}
 		if (parent->name == "INTERACTIONS") {
 			node->layout = _XMLkeys;
 			_interaction = nullptr;
@@ -1129,6 +1148,11 @@ void SceneTag::loadSceneXML(const GameProject &project) {
 		return;
 	}
 
+	if (g_nmi->isAndroidFullPipe() && (_sceneId == SC_1 || _sceneId == SC_2 || _sceneId == SC_3)) {
+		parser.close();
+		if (!parser.loadFile("data/exits.xml") || !parser.parse())
+			return;
+	}
 	if (_sceneId == SC_1) {
 		parser.close();
 		if (!parser.loadFile("data/interactions.xml") || !parser.parse())




More information about the Scummvm-git-logs mailing list