[Scummvm-git-logs] scummvm master -> 037f6e2e6ece0e4239b681f0da931a7629587d26
bluegr
noreply at scummvm.org
Fri Nov 6 02:12:03 UTC 2026
This automated email contains information about 39 new commits which have been
pushed to the 'scummvm' repo located at https://api.github.com/repos/scummvm/scummvm .
Summary:
2617b7dc4e NANCY: NANCY22: Move the blend stages of Transformers to their own class
8d9494a1da NANCY: NANCY26: Add the new vector, matrix and rect functions
3b3595a65e NANCY: NANCY26: Add an initial v5 subengine, and read the boot scripts
c6a07514e4 NANCY: NANCY26: Give every cursor a picture of its own
ecc0fe83a7 NANCY: NANCY26: Make every record a node of a tree
a844e11dc6 NANCY: NANCY26: Let Transformers clip output from attached records
4e3be74944 NANCY: NANCY26: Give every record blend stages and an alpha
1e1aa2d8fd NANCY: NANCY26: Let records and streams exchange messages
0cc2b6199b NANCY: NANCY26: Draw the streams and records in the order of their tree
6c10a49be6 NANCY: NANCY26: Draw the texts with fonts made of pictures
0ad49eac1c NANCY: NANCY26: Hand the player's input to the records
0b8e8edd75 NANCY: NANCY19: Give every record a type
d0ab1a548c NANCY: NANCY26: Add the Button, CheckBox, RadioButton and Slider records
ffa1c2c5db NANCY: NANCY26: Add the EditBox record
4c0111f8f7 NANCY: NANCY26: Start the UI streams when the game starts
794178c2fc NANCY: NANCY26: Add the functions that Nancy26's scripts call
fc5298bcc2 NANCY: NANCY26: Add the inventory functions of Nancy26
24f3e8fbac NANCY: NANCY26: Add the Nancy26 inventory functionality to the console
a678c7cc5a NANCY: NANCY26: Show the subtitles of sounds
413be9daa3 NANCY: NANCY26: Add detection entry
da3feb0e2f NANCY: Rename _type field in SpecialEffect class. PVS-Studio V703
7b3c5f5c83 NANCY: Remove unused field in MouseFollowObject class. PVS-Studio V703
1fe7ca6418 NANCY: Rename _isActive field in WhackItPuzzle class. PVS-Studio V703
e2e59ec3f0 NANCY: Rename unused field in NancyEngine class. PVS-Studio V703
dff20c75a7 NANCY: Initialize all members of INV class. PVS-Studio V1077
61948aac7f NANCY: Remove checks for always true expression. PVS-Studio V547
b5feed9545 NANCY: Remove expression that is always true. PVS-Studio V560
297f3bdbe7 NANCY: Remove redundant assignment. PVS-Studio V1048
ad8f5e53d4 NANCY: Initialize members of struct SoundChannelInfo. PVS-Studio V730
fd3ebc9f32 NANCY: Merge duplicate case branches. PVS-Studio V1037
fc97cdd418 NANCY: Initialize class members. PVS-Studio V730
525c4d5390 NANCY: Remove redundant assignment. PVS-Studio V1048
531a2b031d NANCY: Init class members of RaycastLevelBuilder. PVS-Studio V1077
3ce5d6493a NANCY: Remove always false expressions. PVS-Studio V560
c502130d67 NANCY: Merge duplicate case branches. PVS-Studio V1037
3d4df8a8af NANCY: Remove redundant assignment. PVS-Studio V1048
6ebdc76986 NANCY: Merge duplicate case branches. PVS-Studio V1037
6262be9dcb NANCY: Add sanity check for the EVNT engine data. PVS-Studio V522
037f6e2e6e NANCY: NANCY 11: Add French Steam variant detection entry
Commit: 2617b7dc4eb8ce1f64d03fb8c3078b233b9fd97f
https://github.com/scummvm/scummvm/commit/2617b7dc4eb8ce1f64d03fb8c3078b233b9fd97f
Author: Filippos Karapetis (bluegr at gmail.com)
Date: 2026-11-06T04:10:28+02:00
Commit Message:
NANCY: NANCY22: Move the blend stages of Transformers to their own class
The stages that move, turn and resize a Transformer (PushTranslation,
Blend and the like) are now a class of their own, which any record can
have. Transformers work as before; Nancy26 gives the stages to every
record.
Changed paths:
engines/nancy/script/record.cpp
engines/nancy/script/record.h
engines/nancy/script/transformer.cpp
engines/nancy/script/transformer.h
diff --git a/engines/nancy/script/record.cpp b/engines/nancy/script/record.cpp
index 9f4556a6c3e..0385cec8fb5 100644
--- a/engines/nancy/script/record.cpp
+++ b/engines/nancy/script/record.cpp
@@ -28,6 +28,7 @@
#include "engines/nancy/script/record.h"
#include "engines/nancy/script/records.h"
#include "engines/nancy/script/scenecontext.h"
+#include "engines/nancy/script/transformer.h"
#include "engines/nancy/script/types.h"
namespace Nancy {
@@ -40,7 +41,28 @@ Record::Record(SceneContext &context, const char *typeName) :
_context(context),
_typeName(typeName) {}
-Record::~Record() {}
+Record::~Record() {
+ delete _stages;
+}
+
+void Record::onStagesChanged() {
+}
+
+BlendStages &Record::getStages() {
+ if (!_stages) {
+ _stages = new BlendStages(*this);
+ }
+
+ return *_stages;
+}
+
+ScriptMatrix Record::getLocalTransform() const {
+ if (_stages && !_stages->isEmpty()) {
+ return _stages->getTransform();
+ }
+
+ return _transform;
+}
lua_State *Record::getLua() const {
return _context.getLua();
diff --git a/engines/nancy/script/record.h b/engines/nancy/script/record.h
index 18352c3d7dc..050768ec57e 100644
--- a/engines/nancy/script/record.h
+++ b/engines/nancy/script/record.h
@@ -35,6 +35,7 @@ struct NancyInput;
namespace Script {
+class BlendStages;
class GraphNode;
class SceneContext;
@@ -163,6 +164,14 @@ public:
// after the nodes it is under moved it
ScriptMatrix getTransform() const;
+ // The record's own, before the nodes it is under: the product of its blend
+ // stages when it has any
+ ScriptMatrix getLocalTransform() const;
+
+ // The blend stages of the record, which Nancy22 has in Transformers
+ BlendStages &getStages();
+ virtual void onStagesChanged();
+
// Nancy21: puts the record under a node; null for none
GraphNode *getParentNode() const { return _parentNode; }
void setParentNode(GraphNode *node);
@@ -257,6 +266,8 @@ private:
bool _isScriptOwned = false;
uint _numObjects = 0; // the objects standing for the record that Lua still has
bool _isDropped = false;
+
+ BlendStages *_stages = nullptr;
};
// Makes the "AR" object, and the types of the records
diff --git a/engines/nancy/script/transformer.cpp b/engines/nancy/script/transformer.cpp
index 00749f40370..3a91105640b 100644
--- a/engines/nancy/script/transformer.cpp
+++ b/engines/nancy/script/transformer.cpp
@@ -31,26 +31,9 @@ namespace Script {
static const double kMinBlendTime = 0.001;
-TransformerRecord::TransformerRecord(SceneContext &context) :
- Record(context, "ND.TransformerAR"),
- _node(context.createGraphNode()) {}
-
-void TransformerRecord::readTable(int tableIndex) {
- readField(getLua(), tableIndex, "sinLerp", _isSineLerp);
- readField(getLua(), tableIndex, "timeMultiplier", _timeMultiplier);
- _node->setZ(getLocalZ());
-}
+// BlendStages
-// The node goes wherever the record gets attached to
-void TransformerRecord::onZChanged() {
- if (_node->getParent() != getParentNode()) {
- _node->setParent(getParentNode());
- }
-
- _node->setZ(getLocalZ());
-}
-
-TransformerRecord::Stage *TransformerRecord::findStage(const Common::String &name) {
+BlendStages::Stage *BlendStages::findStage(const Common::String &name) {
for (Stage &stage : _stages) {
if (stage.name == name) {
return &stage;
@@ -60,18 +43,18 @@ TransformerRecord::Stage *TransformerRecord::findStage(const Common::String &nam
return nullptr;
}
-TransformerRecord::Stage &TransformerRecord::checkStage(lua_State *L, int index) {
+BlendStages::Stage &BlendStages::checkStage(lua_State *L, int index) {
const char *name = luaL_checkstring(L, index);
Stage *stage = findStage(name);
if (!stage) {
- luaL_argerror(L, index, Common::String::format("Transformer AR does not have a stage by the name '%s'", name).c_str());
+ luaL_argerror(L, index, Common::String::format("AR does not have a stage by the name '%s'", name).c_str());
}
return *stage;
}
// An angle, or x and y: a vector, a point, or two numbers
-void TransformerRecord::readValue(lua_State *L, int index, StageKind kind, double value[2]) {
+void BlendStages::readValue(lua_State *L, int index, StageKind kind, double value[2]) {
if (kind == kRotation) {
value[0] = luaL_checknumber(L, index);
return;
@@ -94,7 +77,7 @@ void TransformerRecord::readValue(lua_State *L, int index, StageKind kind, doubl
lua_pop(L, 2);
}
-ScriptMatrix TransformerRecord::makeMatrix(StageKind kind, const double value[2]) {
+ScriptMatrix BlendStages::makeMatrix(StageKind kind, const double value[2]) {
ScriptMatrix matrix;
switch (kind) {
@@ -118,9 +101,7 @@ ScriptMatrix TransformerRecord::makeMatrix(StageKind kind, const double value[2]
return matrix;
}
-void TransformerRecord::pushValue(const Stage &stage) {
- lua_State *L = getLua();
-
+void BlendStages::pushValue(lua_State *L, const Stage &stage) {
if (stage.kind == kRotation) {
lua_pushnumber(L, stage.current[0]);
return;
@@ -131,7 +112,7 @@ void TransformerRecord::pushValue(const Stage &stage) {
Script::pushVector(L, vector);
}
-void TransformerRecord::setStage(Stage &stage, const double value[2]) {
+void BlendStages::setStage(Stage &stage, const double value[2]) {
for (int i = 0; i < 2; ++i) {
stage.start[i] = stage.current[i] = stage.target[i] = value[i];
}
@@ -139,7 +120,7 @@ void TransformerRecord::setStage(Stage &stage, const double value[2]) {
stage.matrix = stage.blended = makeMatrix(stage.kind, value);
}
-void TransformerRecord::applyProgress(Stage &stage, double progress) {
+void BlendStages::applyProgress(Stage &stage, double progress) {
for (int i = 0; i < 2; ++i) {
stage.current[i] = stage.start[i] + (stage.target[i] - stage.start[i]) * progress;
}
@@ -147,20 +128,20 @@ void TransformerRecord::applyProgress(Stage &stage, double progress) {
stage.matrix = makeMatrix(stage.kind, stage.current);
}
-bool TransformerRecord::advanceStage(Stage &stage, double seconds) {
+bool BlendStages::advanceStage(Stage &stage, double seconds) {
if (!stage.isBlending()) {
return false;
}
- lua_State *L = getLua();
+ lua_State *L = _owner.getContext().getLua();
stage.time += seconds;
double progress = CLIP(stage.time / stage.duration, 0.0, 1.0);
// The scripts can bend the progress; otherwise it slows down towards the end
lua_pushnumber(L, progress);
- if (callFunction((stage.name + "AffectLerp").c_str(), 1, 1)) {
+ if (_owner.callFunction((stage.name + "AffectLerp").c_str(), 1, 1)) {
if (!lua_isnumber(L, -1)) {
- warning("TransformerAR::AffectLerp: Value returned was not a number");
+ warning("AR::AffectLerp: Value returned was not a number");
}
progress = lua_tonumber(L, -1);
@@ -180,14 +161,15 @@ bool TransformerRecord::advanceStage(Stage &stage, double seconds) {
// The stage may go away along with the record in there
const Common::String doneName = stage.name + "Done";
- callFunction(doneName.c_str());
+ update();
+ _owner.callFunction(doneName.c_str());
}
return true;
}
// The stages make the transform in the order they were pushed in
-void TransformerRecord::updateTransform() {
+void BlendStages::update() {
ScriptMatrix transform;
ScriptMatrix blendedTransform;
for (const Stage &stage : _stages) {
@@ -195,43 +177,47 @@ void TransformerRecord::updateTransform() {
blendedTransform = blendedTransform * stage.blended;
}
+ _transform = transform;
_blendedTransform = blendedTransform;
- _node->setTransform(transform);
+
+ _owner.onStagesChanged();
}
-void TransformerRecord::run(double sceneTime, double elapsedTime) {
+bool BlendStages::advance(double seconds) {
bool hasChanged = false;
for (uint i = 0; i < _stages.size(); ++i) {
- hasChanged |= advanceStage(_stages[i], elapsedTime * _timeMultiplier);
+ hasChanged |= advanceStage(_stages[i], seconds * _timeMultiplier);
}
if (hasChanged) {
- updateTransform();
+ update();
}
+
+ return hasChanged;
}
-// transformer:Push<Translation|Rotation|Scale>(name, value)
-int TransformerRecord::pushStage(lua_State *L, StageKind kind) {
+// ar:Push<Translation|Rotation|Scale>(name, value)
+int BlendStages::push(lua_State *L, StageKind kind) {
const char *name = luaL_checkstring(L, 2);
if (findStage(name)) {
- return luaL_argerror(L, 2, Common::String::format("Transformer AR already has a stage by the name '%s'", name).c_str());
+ return luaL_argerror(L, 2, Common::String::format("AR already has a stage by the name '%s'", name).c_str());
}
Stage stage;
stage.name = name;
stage.kind = kind;
- double value[2];
+ double value[2] = { 0.0, 0.0 };
readValue(L, 3, kind, value);
setStage(stage, value);
_stages.push_back(stage);
- updateTransform();
+ update();
return 0;
}
-// transformer:Blend(name, seconds, value)
-int TransformerRecord::blend(lua_State *L) {
+// ar:Blend(name, seconds, value)
+int BlendStages::blend(lua_State *L) {
Stage &stage = checkStage(L, 2);
const double duration = luaL_checknumber(L, 3);
@@ -244,13 +230,12 @@ int TransformerRecord::blend(lua_State *L) {
stage.duration = MAX(kMinBlendTime, duration);
stage.time = 0.0;
- updateTransform();
+ update();
return 0;
}
-// transformer:FinishBlend([name]) puts a stage where it is going right away, or
-// all of them
-int TransformerRecord::finishBlend(lua_State *L) {
+// ar:FinishBlend([name]) puts a stage where it is going right away, or all of them
+int BlendStages::finishBlend(lua_State *L) {
Common::String name;
if (lua_gettop(L) > 1) {
name = checkStage(L, 2).name;
@@ -262,139 +247,199 @@ int TransformerRecord::finishBlend(lua_State *L) {
}
}
- updateTransform();
+ update();
return 0;
}
-// transformer:RemoveAllStages(), Nancy24
-int TransformerRecord::removeAllStages(lua_State *L) {
+// ar:RemoveAllStages(), Nancy24
+int BlendStages::removeAll(lua_State *L) {
_stages.clear();
- updateTransform();
+ update();
return 0;
}
-// transformer:IsBlending(name)
-int TransformerRecord::isBlending(lua_State *L) {
+// ar:IsBlending(name)
+int BlendStages::isBlending(lua_State *L) {
lua_pushboolean(L, checkStage(L, 2).isBlending());
return 1;
}
-// transformer:Attach(record, ...)
-int TransformerRecord::attach(lua_State *L) {
- for (int i = 2; i <= lua_gettop(L); ++i) {
- GraphNode *node = testGraphNode(L, i);
- if (node) {
- node->setParent(_node);
- } else {
- checkRecord(L, i)->setParentNode(_node);
- }
+bool BlendStages::getField(lua_State *L, const Common::String &key) {
+ const Stage *stage = findStage(key);
+ if (stage) {
+ pushValue(L, *stage);
+ return true;
}
- return 0;
+ return false;
}
-static TransformerRecord *checkTransformer(lua_State *L) {
- TransformerRecord *transformer = dynamic_cast<TransformerRecord *>(checkRecord(L, 1));
- if (!transformer) {
- luaL_typerror(L, 1, "ND.TransformerAR");
+// Setting a stage puts it at the value at once
+bool BlendStages::setField(lua_State *L, const Common::String &key) {
+ Stage *stage = findStage(key);
+ if (!stage) {
+ return false;
}
- return transformer;
+ if (stage->isBlending()) {
+ luaL_error(L, "Stage %s is in the midst of blending. It cannot be overridden.", key.c_str());
+ }
+
+ double value[2] = { 0.0, 0.0 };
+ readValue(L, 3, stage->kind, value);
+ setStage(*stage, value);
+ update();
+ return true;
}
-static int transformerPushTranslation(lua_State *L) {
- return checkTransformer(L)->pushStage(L, TransformerRecord::kTranslation);
+static BlendStages &checkStages(lua_State *L) {
+ return checkRecord(L, 1)->getStages();
}
-static int transformerPushRotation(lua_State *L) {
- return checkTransformer(L)->pushStage(L, TransformerRecord::kRotation);
+static int stagesPushTranslation(lua_State *L) {
+ return checkStages(L).push(L, BlendStages::kTranslation);
}
-static int transformerPushScale(lua_State *L) {
- return checkTransformer(L)->pushStage(L, TransformerRecord::kScale);
+static int stagesPushRotation(lua_State *L) {
+ return checkStages(L).push(L, BlendStages::kRotation);
}
-static int transformerBlend(lua_State *L) {
- return checkTransformer(L)->blend(L);
+static int stagesPushScale(lua_State *L) {
+ return checkStages(L).push(L, BlendStages::kScale);
}
-static int transformerFinishBlend(lua_State *L) {
- return checkTransformer(L)->finishBlend(L);
+static int stagesBlend(lua_State *L) {
+ return checkStages(L).blend(L);
}
-static int transformerIsBlending(lua_State *L) {
- return checkTransformer(L)->isBlending(L);
+static int stagesFinishBlend(lua_State *L) {
+ return checkStages(L).finishBlend(L);
}
-static int transformerAttach(lua_State *L) {
- return checkTransformer(L)->attach(L);
+static int stagesIsBlending(lua_State *L) {
+ return checkStages(L).isBlending(L);
}
-static int transformerRemoveAllStages(lua_State *L) {
- return checkTransformer(L)->removeAllStages(L);
+static int stagesRemoveAll(lua_State *L) {
+ return checkStages(L).removeAll(L);
}
-static const luaL_Reg kTransformerFunctions[] = {
- { "Attach", transformerAttach },
- { "Blend", transformerBlend },
- { "FinishBlend", transformerFinishBlend },
- { "IsBlending", transformerIsBlending },
- { "PushTranslation", transformerPushTranslation },
- { "PushRotation", transformerPushRotation },
- { "PushScale", transformerPushScale },
- { "RemoveAllStages", transformerRemoveAllStages },
+static const luaL_Reg kStageFunctions[] = {
+ { "Blend", stagesBlend },
+ { "FinishBlend", stagesFinishBlend },
+ { "IsBlending", stagesIsBlending },
+ { "PushTranslation", stagesPushTranslation },
+ { "PushRotation", stagesPushRotation },
+ { "PushScale", stagesPushScale },
+ { "RemoveAllStages", stagesRemoveAll },
{ nullptr, nullptr }
};
+bool BlendStages::pushFunction(lua_State *L, const Common::String &key) {
+ for (const luaL_Reg *function = kStageFunctions; function->name; ++function) {
+ if (key == function->name) {
+ lua_pushcfunction(L, function->func);
+ return true;
+ }
+ }
+
+ return false;
+}
+
+// TransformerRecord
+
+TransformerRecord::TransformerRecord(SceneContext &context, const char *typeName) :
+ Record(context, typeName),
+ _node(context.createGraphNode()) {}
+
+void TransformerRecord::readTable(int tableIndex) {
+ lua_State *L = getLua();
+
+ bool isSineLerp = true;
+ readField(L, tableIndex, "sinLerp", isSineLerp);
+ getStages().setSineLerp(isSineLerp);
+
+ double timeMultiplier = 1.0;
+ readField(L, tableIndex, "timeMultiplier", timeMultiplier);
+ getStages().setTimeMultiplier(timeMultiplier);
+
+ _node->setZ(getLocalZ());
+}
+
+// The node goes wherever the record gets attached to
+void TransformerRecord::onZChanged() {
+ if (_node->getParent() != getParentNode()) {
+ _node->setParent(getParentNode());
+ }
+
+ _node->setZ(getLocalZ());
+}
+
+// The stages move the node
+void TransformerRecord::onStagesChanged() {
+ _node->setTransform(getLocalTransform());
+}
+
+void TransformerRecord::run(double sceneTime, double elapsedTime) {
+ getStages().advance(elapsedTime);
+}
+
+// transformer:Attach(record, ...)
+int TransformerRecord::attach(lua_State *L) {
+ for (int i = 2; i <= lua_gettop(L); ++i) {
+ GraphNode *node = testGraphNode(L, i);
+ if (node) {
+ node->setParent(_node);
+ } else {
+ checkRecord(L, i)->setParentNode(_node);
+ }
+ }
+
+ return 0;
+}
+
+static int transformerAttach(lua_State *L) {
+ TransformerRecord *transformer = dynamic_cast<TransformerRecord *>(checkRecord(L, 1));
+ if (!transformer) {
+ luaL_typerror(L, 1, "ND.TransformerAR");
+ }
+
+ return transformer->attach(L);
+}
+
bool TransformerRecord::getField(const Common::String &key) {
lua_State *L = getLua();
- if (key == "transform") {
+ if (key == "Attach") {
+ lua_pushcfunction(L, transformerAttach);
+ return true;
+ } else if (key == "transform") {
pushMatrix(L, _node->getTransform());
return true;
} else if (key == "blendedTransform") {
- pushMatrix(L, _blendedTransform);
+ pushMatrix(L, getStages().getBlendedTransform());
return true;
} else if (key == "timeMultiplier") {
- lua_pushnumber(L, _timeMultiplier);
+ lua_pushnumber(L, getStages().getTimeMultiplier());
return true;
}
- for (const luaL_Reg *function = kTransformerFunctions; function->name; ++function) {
- if (key == function->name) {
- lua_pushcfunction(L, function->func);
- return true;
- }
- }
-
- const Stage *stage = findStage(key);
- if (stage) {
- pushValue(*stage);
+ if (BlendStages::pushFunction(L, key)) {
return true;
}
- return false;
+ return getStages().getField(L, key);
}
-// Setting a stage puts it at the value at once
bool TransformerRecord::setField(const Common::String &key) {
lua_State *L = getLua();
- Stage *stage = findStage(key);
- if (stage) {
- if (stage->isBlending()) {
- luaL_error(L, "Stage %s is in the midst of blending. It cannot be overridden.", key.c_str());
- }
-
- double value[2];
- readValue(L, 3, stage->kind, value);
- setStage(*stage, value);
- updateTransform();
+ if (getStages().setField(L, key)) {
return true;
}
if (key == "timeMultiplier") {
- _timeMultiplier = luaL_checknumber(L, 3);
+ getStages().setTimeMultiplier(luaL_checknumber(L, 3));
return true;
}
diff --git a/engines/nancy/script/transformer.h b/engines/nancy/script/transformer.h
index 01be191e198..5965c3af4f7 100644
--- a/engines/nancy/script/transformer.h
+++ b/engines/nancy/script/transformer.h
@@ -32,47 +32,56 @@ namespace Script {
class GraphNode;
-// Nancy22 moves, turns and resizes what a scene shows with Transformer records.
-// The records a Transformer gets with Attach() are moved by its transform on top
-// of their own, and so are other Transformers attached to it:
+// The named stages a transform is made of, in the order they were pushed:
//
-// piece = AR:Transformer({})
// piece:PushTranslation("t", Vector:New(100, 50))
// piece:PushRotation("r", 0)
-// piece:Attach(pieceOVL)
// piece:Blend("r", 0.5, math.pi) -- turns it half around in half a second
//
-// The transform is made of named stages, in the order they were pushed. Setting
-// the field of a stage's name puts it at a value right away; Blend() takes it
-// there over a time, slowly at the end unless the table said sinLerp = false.
-// While a stage blends, a function "<stage>AffectLerp" of the record can bend
-// the progress from 0 to 1, and "<stage>Done" gets called once it is there.
-class TransformerRecord : public Record {
+// Setting the field of a stage's name puts it at a value right away; Blend() takes
+// it there over a time, slowly at the end unless the record said sinLerp = false.
+// While a stage blends, a function "<stage>AffectLerp" of the record can bend the
+// progress from 0 to 1, and "<stage>Done" gets called once it is there.
+// Nancy22 has them in Transformer records.
+class BlendStages {
public:
- TransformerRecord(SceneContext &context);
-
- GraphNode *getNode() const { return _node; }
-
enum StageKind {
kTranslation,
kRotation,
kScale
};
- // The functions of the scripts, which return their number of results
- int pushStage(lua_State *L, StageKind kind);
+ BlendStages(Record &owner) : _owner(owner) {}
+
+ bool isEmpty() const { return _stages.empty(); }
+
+ // The product of the stages, and where they are going
+ const ScriptMatrix &getTransform() const { return _transform; }
+ const ScriptMatrix &getBlendedTransform() const { return _blendedTransform; }
+
+ void setSineLerp(bool isSineLerp) { _isSineLerp = isSineLerp; }
+ bool isSineLerp() const { return _isSineLerp; }
+
+ double getTimeMultiplier() const { return _timeMultiplier; }
+ void setTimeMultiplier(double multiplier) { _timeMultiplier = multiplier; }
+
+ // Moves the blends on. Returns whether anything changed.
+ bool advance(double seconds);
+
+ // The functions of the scripts, which return their number of results. The
+ // record is at stack index 1.
+ int push(lua_State *L, StageKind kind);
int blend(lua_State *L);
int finishBlend(lua_State *L);
int isBlending(lua_State *L);
- int attach(lua_State *L);
- int removeAllStages(lua_State *L);
+ int removeAll(lua_State *L);
-protected:
- void readTable(int tableIndex) override;
- void run(double sceneTime, double elapsedTime) override;
- void onZChanged() override;
- bool getField(const Common::String &key) override;
- bool setField(const Common::String &key) override;
+ // The value of a stage, by its name
+ bool getField(lua_State *L, const Common::String &key);
+ bool setField(lua_State *L, const Common::String &key);
+
+ // The functions above, for the records that have them
+ static bool pushFunction(lua_State *L, const Common::String &key);
private:
struct Stage {
@@ -98,7 +107,7 @@ private:
static void readValue(lua_State *L, int index, StageKind kind, double value[2]);
static ScriptMatrix makeMatrix(StageKind kind, const double value[2]);
- void pushValue(const Stage &stage);
+ void pushValue(lua_State *L, const Stage &stage);
// Puts a stage at a value at once
void setStage(Stage &stage, const double value[2]);
@@ -107,12 +116,38 @@ private:
// Moves a stage on in its blend. Returns whether it was blending.
bool advanceStage(Stage &stage, double seconds);
- void updateTransform();
+ // Works out the product of the stages, and tells the record
+ void update();
+ Record &_owner;
Common::Array<Stage> _stages;
bool _isSineLerp = true;
double _timeMultiplier = 1.0; // Nancy24: how much faster the blends go
- ScriptMatrix _blendedTransform; // where the stages are going
+ ScriptMatrix _transform;
+ ScriptMatrix _blendedTransform;
+};
+
+// Nancy22 moves, turns and resizes what a scene shows with Transformer records.
+// The records a Transformer gets with Attach() are moved by its transform on top
+// of their own, and so are other Transformers attached to it.
+class TransformerRecord : public Record {
+public:
+ TransformerRecord(SceneContext &context, const char *typeName = "ND.TransformerAR");
+
+ GraphNode *getNode() const { return _node; }
+
+ int attach(lua_State *L);
+
+ void onStagesChanged() override;
+
+protected:
+ void readTable(int tableIndex) override;
+ void run(double sceneTime, double elapsedTime) override;
+ void onZChanged() override;
+ bool getField(const Common::String &key) override;
+ bool setField(const Common::String &key) override;
+
+private:
GraphNode *_node;
};
Commit: 8d9494a1da0f9982c606115f17051167372fa4ea
https://github.com/scummvm/scummvm/commit/8d9494a1da0f9982c606115f17051167372fa4ea
Author: Filippos Karapetis (bluegr at gmail.com)
Date: 2026-11-06T04:10:30+02:00
Commit Message:
NANCY: NANCY26: Add the new vector, matrix and rect functions
Vector:TransformCoord() and TransformNormal(), and the same functions of
Matrix, move a vector, a point or two numbers by a matrix. A Rect now
prints as "R(left, top, right, bottom)", and Rects and Points can be
joined to texts with "..", which the scripts use in their messages.
Changed paths:
engines/nancy/script/mathtypes.cpp
engines/nancy/script/types.cpp
diff --git a/engines/nancy/script/mathtypes.cpp b/engines/nancy/script/mathtypes.cpp
index 056a4f820d3..71de6d55ef4 100644
--- a/engines/nancy/script/mathtypes.cpp
+++ b/engines/nancy/script/mathtypes.cpp
@@ -29,6 +29,7 @@
#include "engines/nancy/script/luabind.h"
#include "engines/nancy/script/mathtypes.h"
+#include "engines/nancy/script/types.h"
namespace Nancy {
namespace Script {
@@ -467,10 +468,36 @@ static int pushTransformedVector(lua_State *L, const ScriptVector &vector, const
return 1;
}
+// The vector at no depth, for the transforms of Nancy26
+static ScriptVector getFlatVector(const ScriptVector &vector) {
+ ScriptVector place = vector;
+ if (place.size < 3) {
+ place.v[2] = 0.0;
+ }
+
+ place.size = 3;
+ return place;
+}
+
+// vector:TransformCoord(matrix) and vector:TransformNormal(matrix), Nancy26
+static int vectorTransformCoord(lua_State *L) {
+ return pushTransformedVector(L, getFlatVector(checkVector(L, 1)), checkMatrix(L, 2), "coord");
+}
+
+static int vectorTransformNormal(lua_State *L) {
+ return pushTransformedVector(L, getFlatVector(checkVector(L, 1)), checkMatrix(L, 2), "normal");
+}
+
// vector:Transform(kind, matrix). Nancy22 moves any vector by its x, y and z,
// with no z for a 2D one, and gives a 3D vector back.
static int vectorTransform(lua_State *L) {
const ScriptVector &vector = checkVector(L, 1);
+
+ // Nancy26 leaves out what kind of transform it is
+ if (testMatrix(L, 2)) {
+ return vectorTransformCoord(L);
+ }
+
const char *kind = luaL_checkstring(L, 2);
if (g_nancy->getGameType() >= kGameTypeNancy22) {
@@ -501,6 +528,8 @@ static const luaL_Reg kVectorFunctions[] = {
{ "Lerp", vectorLerp },
{ "Reflect", vectorReflect },
{ "Transform", vectorTransform },
+ { "TransformCoord", vectorTransformCoord },
+ { "TransformNormal", vectorTransformNormal },
{ nullptr, nullptr }
};
@@ -792,6 +821,34 @@ static int matrixTransform(lua_State *L) {
return pushTransformedVector(L, checkVector(L, 3), matrix, kind);
}
+// What Nancy26's matrix:TransformCoord and TransformNormal take: a vector, a
+// point, a table with x and y, or two numbers
+static ScriptVector readTransformInput(lua_State *L, int index) {
+ if (lua_isnumber(L, index)) {
+ return ScriptVector(luaL_checknumber(L, index), luaL_checknumber(L, index + 1), 0.0);
+ }
+
+ const ScriptVector *vector = testVector(L, index);
+ if (vector) {
+ return getFlatVector(*vector);
+ }
+
+ ScriptPoint point;
+ if (!readPoint(L, index, point)) {
+ luaL_argerror(L, index, "Expected a Vector, a Point, a table with x and y, or two numbers");
+ }
+
+ return ScriptVector(point.x, point.y, 0.0);
+}
+
+static int matrixTransformCoord(lua_State *L) {
+ return pushTransformedVector(L, readTransformInput(L, 2), checkMatrix(L, 1), "coord");
+}
+
+static int matrixTransformNormal(lua_State *L) {
+ return pushTransformedVector(L, readTransformInput(L, 2), checkMatrix(L, 1), "normal");
+}
+
static const luaL_Reg kMatrixFunctions[] = {
{ "__index", matrixIndex },
{ "__newindex", matrixNewIndex },
@@ -800,6 +857,8 @@ static const luaL_Reg kMatrixFunctions[] = {
{ "Inverse", matrixInverse },
{ "Transpose", matrixTranspose },
{ "Transform", matrixTransform },
+ { "TransformCoord", matrixTransformCoord },
+ { "TransformNormal", matrixTransformNormal },
{ nullptr, nullptr }
};
diff --git a/engines/nancy/script/types.cpp b/engines/nancy/script/types.cpp
index 71a2616620e..8d598019d83 100644
--- a/engines/nancy/script/types.cpp
+++ b/engines/nancy/script/types.cpp
@@ -278,8 +278,32 @@ static int rectRightBottomSet(lua_State *L) {
return 1;
}
+static int rectToString(lua_State *L) {
+ const ScriptRect &rect = checkRect(L, 1);
+ lua_pushstring(L, Common::String::format("R(%d, %d, %d, %d)", rect.left, rect.top, rect.right, rect.bottom).c_str());
+ return 1;
+}
+
+// rect .. text and point .. text, Nancy26, joins what both print as
+static int concatToStrings(lua_State *L) {
+ for (int i = 1; i <= 2; ++i) {
+ if (!luaL_callmeta(L, i, "__tostring")) {
+ lua_pushvalue(L, i);
+ }
+
+ if (!lua_isstring(L, -1)) {
+ return luaL_error(L, "attempt to concatenate a %s value", luaL_typename(L, i));
+ }
+ }
+
+ lua_concat(L, 2);
+ return 1;
+}
+
static const luaL_Reg kRectFunctions[] = {
{ "__index", rectIndex },
+ { "__tostring", rectToString },
+ { "__concat", concatToStrings },
{ "__newindex", rectNewIndex },
{ "__eq", rectEquals },
{ "Contains", rectContains },
@@ -438,6 +462,7 @@ static const luaL_Reg kPointFunctions[] = {
{ "__sub", pointSubtract },
{ "__unm", pointNegate },
{ "__tostring", pointToString },
+ { "__concat", concatToStrings },
{ nullptr, nullptr }
};
Commit: 3b3595a65eb47375d46b57177a59d49dcc76394d
https://github.com/scummvm/scummvm/commit/3b3595a65eb47375d46b57177a59d49dcc76394d
Author: Filippos Karapetis (bluegr at gmail.com)
Date: 2026-11-06T04:10:31+02:00
Commit Message:
NANCY: NANCY26: Add an initial v5 subengine, and read the boot scripts
Nancy26 and newer construct their whole UI with script records. The
new subengine is placed within script/v5, which is built along v4.
Nancy26 boots from other scripts than the earlier games: fonts made of
pictures, items that name the scene that shows them, a picture for
every cursor, and environments that only name their ambient scripts.
The screen is 1024x768, with the viewport at the top, and there are no
player characters to choose from.
Changed paths:
A engines/nancy/script/bootapi.h
A engines/nancy/script/v5/bootobjects.cpp
A engines/nancy/script/v5/bootobjects.h
engines/nancy/configure.engine
engines/nancy/enginedata.h
engines/nancy/graphics.cpp
engines/nancy/metaengine.cpp
engines/nancy/module.mk
engines/nancy/nancy.cpp
engines/nancy/nancy.h
engines/nancy/script/api.h
engines/nancy/script/bootapi.cpp
engines/nancy/state/scene.cpp
diff --git a/engines/nancy/configure.engine b/engines/nancy/configure.engine
index c290e1ee04b..3f1d9f7fd08 100644
--- a/engines/nancy/configure.engine
+++ b/engines/nancy/configure.engine
@@ -1,5 +1,7 @@
# This file is included from the main "configure" script
# add_engine [name] [desc] [build-by-default] [subengines] [base games] [deps] [components]
-add_engine nancy "Nancy Drew" yes "nancy_v3a nancy_v4" "The Vampire Diaries, Nancy Drew 1-17" "16bit highres vorbis bink"
+add_engine nancy "Nancy Drew" yes "nancy_v3a nancy_v4 nancy_v5" "The Vampire Diaries, Nancy Drew 1-17" "16bit highres vorbis bink"
add_engine nancy_v3a "Nancy Drew 18" yes "" "" "png"
add_engine nancy_v4 "Nancy Drew 19 and newer" yes "" "" "png lua"
+# Built only along with nancy_v4, whose scripts it adds to
+add_engine nancy_v5 "Nancy Drew 26 and newer" yes "" "" "png lua"
diff --git a/engines/nancy/enginedata.h b/engines/nancy/enginedata.h
index e7d7a76781e..8e8525bdf77 100644
--- a/engines/nancy/enginedata.h
+++ b/engines/nancy/enginedata.h
@@ -1100,6 +1100,31 @@ struct ScriptBootData : public EngineData {
Common::Rect sources[kNumCursorVariants];
Common::Point hotspots[kNumCursorVariants];
bool overridesItem = false; // shown even while an item is held
+ Common::Path imageName; // Nancy26: every cursor names its own picture
+ };
+
+ // Nancy26 draws all its texts with fonts made of pictures. A font comes in
+ // four styles, each a picture holding the letters and a table of where they are.
+ struct BitmapFont {
+ enum Style { kRegular = 0, kBold = 1, kItalic = 2, kBoldItalic = 3, kNumStyles = 4 };
+
+ struct Glyph {
+ Common::Rect source; // in the picture
+ int16 xOffset = 0; // where it goes from the pen
+ int16 yOffset = 0;
+ int16 xAdvance = 0; // how far the pen moves on
+ };
+
+ struct Face {
+ Common::Path imageName;
+ int height = 0; // of a line
+ Common::HashMap<uint32, Glyph> glyphs;
+ Common::HashMap<uint32, int> kerning; // by (first << 16) | second
+ };
+
+ int id = 0;
+ Common::String name;
+ Face faces[kNumStyles];
};
struct SystemFont {
@@ -1164,6 +1189,12 @@ struct ScriptBootData : public EngineData {
Common::Array<SystemFont> fonts;
Common::Array<FontColor> fontColors;
+ Common::Array<BitmapFont> bitmapFonts; // Nancy26
+
+ // Nancy26: where an item's picture goes from the mouse while it is held
+ Common::Point itemCursorOffset;
+
+ Common::String buildNumber; // Nancy26
// Nancy23: font files of the game folder, which the fonts named like them
// use in place of a Windows font
diff --git a/engines/nancy/graphics.cpp b/engines/nancy/graphics.cpp
index 0b7992f8943..80a82ad94eb 100644
--- a/engines/nancy/graphics.cpp
+++ b/engines/nancy/graphics.cpp
@@ -778,6 +778,10 @@ const Graphics::PixelFormat &GraphicsManager::getInputPixelFormat(uint bpp) {
}
Common::Rect GraphicsManager::getScreenBounds() {
+ if (g_nancy->getGameType() >= kGameTypeNancy26) {
+ return Common::Rect(1024, 768);
+ }
+
return (g_nancy->getGameType() >= kGameTypeNancy16) ? Common::Rect(800, 600) : Common::Rect(640, 480);
}
diff --git a/engines/nancy/metaengine.cpp b/engines/nancy/metaengine.cpp
index 48f915eb4a4..fbf33cf5350 100644
--- a/engines/nancy/metaengine.cpp
+++ b/engines/nancy/metaengine.cpp
@@ -179,6 +179,13 @@ Common::Error NancyMetaEngine::createInstance(OSystem *syst, Engine **engine, co
}
#endif
+ // Nancy26 needs the scripts of Nancy19 as well
+#if !defined(ENABLE_NANCY_V4) || !defined(ENABLE_NANCY_V5)
+ if (gameType >= Nancy::kGameTypeNancy26) {
+ return Common::Error(Common::kUnsupportedGameidError, _s("Support for Nancy Drew 26 and newer is not compiled in"));
+ }
+#endif
+
if (gd) {
*engine = Nancy::NancyEngine::create(gameType, syst, gd);
}
diff --git a/engines/nancy/module.mk b/engines/nancy/module.mk
index 35bce2f5187..ce4d37e2f0b 100644
--- a/engines/nancy/module.mk
+++ b/engines/nancy/module.mk
@@ -236,6 +236,12 @@ MODULE_OBJS += \
script/types.o \
script/uiapi.o \
script/xsheet.o
+
+# Nancy26 and newer, whose UI is made of records as well
+ifdef ENABLE_NANCY_V5
+MODULE_OBJS += \
+ script/v5/bootobjects.o
+endif
endif
# This module can be built as a plugin
diff --git a/engines/nancy/nancy.cpp b/engines/nancy/nancy.cpp
index d8ef7749287..31f4226cfc5 100644
--- a/engines/nancy/nancy.cpp
+++ b/engines/nancy/nancy.cpp
@@ -959,6 +959,51 @@ void NancyEngine::bootScriptedGameEngine() {
_engineData.setVal("BSUM", bootSummary);
_engineData.setVal("ScriptBootData", boot);
+ // Nancy26 can't be started without its scripts, which the metaengine checks
+ if (getGameType() < kGameTypeNancy26) {
+ bootScriptedGameData(boot, flags, inventory, environments, players, viewport, autotext, convo);
+#ifdef ENABLE_NANCY_V5
+ } else {
+ bootNancy26Data(boot, flags, inventory, environments, viewport, autotext);
+#endif
+ }
+
+ _staticData.numItems = inventory->items.size();
+ _staticData.numEventFlags = (uint16)(kNumGenericEventFlags + flags->numRecords);
+
+ // Saved games get matched against the name of the game
+ const Common::String &saveName = boot->saveFolderName.empty() ? boot->defaultSaveName : boot->saveFolderName;
+ Common::strlcpy((char *)bootSummary->header, saveName.c_str(), sizeof(bootSummary->header));
+ bootSummary->firstScene.sceneID = 0;
+
+ // The clock of the game runs a little faster than a real one
+ if (boot->playerTimeScale > 0.0) {
+ bootSummary->playerTimeMinuteLength = (uint16)(60000.0 / boot->playerTimeScale);
+ }
+
+ _cursor->init(*boot);
+
+ _graphics->init();
+ _graphics->loadSystemFonts(*boot);
+
+ _sound->initSoundChannels();
+
+ // Nancy26 has no player characters to pick from
+ if (players->characters.empty()) {
+ return;
+ }
+
+ uint startCharacter = 0;
+ for (uint i = 0; i < players->characters.size(); ++i) {
+ if (players->characters[i].name.equalsIgnoreCase(players->startCharacterName)) {
+ startCharacter = i;
+ }
+ }
+
+ setPlayerCharacter(startCharacter);
+}
+
+void NancyEngine::bootScriptedGameData(ScriptBootData *boot, EVNT *flags, INVD *inventory, ENVS *environments, PCUI *players, VIEW *viewport, CVTX *autotext, CVTX *convo) {
// The order matters: the cursors of the inventory go by item
Script::BootTables fontTables;
fontTables.boot = boot;
@@ -1006,35 +1051,6 @@ void NancyEngine::bootScriptedGameEngine() {
error("Failed to load text file %s", name.c_str());
}
}
-
- _staticData.numItems = inventory->items.size();
- _staticData.numEventFlags = (uint16)(kNumGenericEventFlags + flags->numRecords);
-
- // Saved games get matched against the name of the game
- const Common::String &saveName = boot->saveFolderName.empty() ? boot->defaultSaveName : boot->saveFolderName;
- Common::strlcpy((char *)bootSummary->header, saveName.c_str(), sizeof(bootSummary->header));
- bootSummary->firstScene.sceneID = 0;
-
- // The clock of the game runs a little faster than a real one
- if (boot->playerTimeScale > 0.0) {
- bootSummary->playerTimeMinuteLength = (uint16)(60000.0 / boot->playerTimeScale);
- }
-
- _cursor->init(*boot);
-
- _graphics->init();
- _graphics->loadSystemFonts(*boot);
-
- _sound->initSoundChannels();
-
- uint startCharacter = 0;
- for (uint i = 0; i < players->characters.size(); ++i) {
- if (players->characters[i].name.equalsIgnoreCase(players->startCharacterName)) {
- startCharacter = i;
- }
- }
-
- setPlayerCharacter(startCharacter);
}
#endif
diff --git a/engines/nancy/nancy.h b/engines/nancy/nancy.h
index ba3b3e3f6d2..042006c5292 100644
--- a/engines/nancy/nancy.h
+++ b/engines/nancy/nancy.h
@@ -83,6 +83,14 @@ namespace Nancy {
// protagonists each carry their own cell phone
static const int kSavegameVersion = 12;
+struct CVTX;
+struct ENVS;
+struct EVNT;
+struct INVD;
+struct PCUI;
+struct VIEW;
+struct ScriptBootData;
+
class ResourceManager;
class IFF;
class InputManager;
@@ -204,6 +212,10 @@ private:
void bootGameEngine();
#ifdef ENABLE_NANCY_V4
void bootScriptedGameEngine(); // Nancy19+
+ void bootScriptedGameData(ScriptBootData *boot, EVNT *flags, INVD *inventory, ENVS *environments, PCUI *players, VIEW *viewport, CVTX *autotext, CVTX *convo);
+#endif
+#ifdef ENABLE_NANCY_V5
+ void bootNancy26Data(ScriptBootData *boot, EVNT *flags, INVD *inventory, ENVS *environments, VIEW *viewport, CVTX *autotext); // Nancy26+
#endif
State::State *getStateObject(NancyState::NancyState state) const;
diff --git a/engines/nancy/script/api.h b/engines/nancy/script/api.h
index 80fda505ded..82162a5dc10 100644
--- a/engines/nancy/script/api.h
+++ b/engines/nancy/script/api.h
@@ -26,6 +26,8 @@
#include "common/scummsys.h"
#include "common/str.h"
+#include "engines/nancy/enginedata.h"
+
struct lua_State;
namespace Common {
@@ -58,6 +60,11 @@ struct BootTables {
CVTX *texts = nullptr;
ScriptBootData *boot = nullptr;
int playerIndex = -1; // the character whose own boot script is running
+
+#ifdef ENABLE_NANCY_V5
+ // Nancy26: the font whose file is running, which FontsInit:Create fills
+ ScriptBootData::BitmapFont *font = nullptr;
+#endif
};
// Runs one of the boot scripts. Returns false when there is no such script.
diff --git a/engines/nancy/script/bootapi.cpp b/engines/nancy/script/bootapi.cpp
index bf69bc454d0..e7df9d871a0 100644
--- a/engines/nancy/script/bootapi.cpp
+++ b/engines/nancy/script/bootapi.cpp
@@ -25,12 +25,17 @@
#include "engines/nancy/nancy.h"
#include "engines/nancy/script/api.h"
+#include "engines/nancy/script/bootapi.h"
#include "engines/nancy/script/luabind.h"
#include "engines/nancy/script/luastate.h"
#include "engines/nancy/script/types.h"
#include "engines/nancy/ui/ndui/button.h"
+#ifdef ENABLE_NANCY_V5
+#include "engines/nancy/script/v5/bootobjects.h"
+#endif
+
namespace Nancy {
namespace Script {
@@ -45,18 +50,24 @@ namespace Script {
static const BootTables *s_tables = nullptr;
+const BootTables *getBootTables() {
+ return s_tables;
+}
+
bool runBootScript(const char *name, const BootTables &tables) {
LuaState state;
+ // Nancy26's font list runs the file of every font from within itself
+ const BootTables *outerTables = s_tables;
s_tables = &tables;
bool result = state.runScript(name);
- s_tables = nullptr;
+ s_tables = outerTables;
return result;
}
// Every Create function takes the object itself and one table
-static void checkCreateArguments(lua_State *L, const char *typeName, bool hasTable) {
+void checkCreateArguments(lua_State *L, const char *typeName, bool hasTable) {
checkUserData(L, 1, typeName);
luaL_checktype(L, 2, LUA_TTABLE);
@@ -86,7 +97,7 @@ static bool compareNames(const Common::String &a, const Common::String &b) {
}
// The keys of a table that are strings, in alphabetical order
-static void getSortedKeys(lua_State *L, int tableIndex, Common::Array<Common::String> &keys) {
+void getSortedKeys(lua_State *L, int tableIndex, Common::Array<Common::String> &keys) {
lua_pushnil(L);
while (lua_next(L, tableIndex)) {
if (lua_type(L, -2) == LUA_TSTRING) {
@@ -210,12 +221,24 @@ static int envCreate(lua_State *L) {
for (const Common::String &code : codes) {
lua_getfield(L, 2, code.c_str());
- luaL_checktype(L, -1, LUA_TTABLE);
+ if (!lua_isstring(L, -1)) {
+ luaL_checktype(L, -1, LUA_TTABLE);
+ }
+
int env = lua_gettop(L);
ENVS::Environment environment;
environment.code = code;
+ // Nancy26 only names the ambient script of each environment
+ if (lua_isstring(L, env)) {
+ environment.name = code;
+ environment.ambientScriptName = Common::Path(lua_tostring(L, env));
+ envs.environments.push_back(environment);
+ lua_pop(L, 1);
+ continue;
+ }
+
if (!readField(L, env, "fullName", environment.name)) {
luaL_error(L, "Environments must specify the 'fullName' field");
}
@@ -315,6 +338,12 @@ static int inventoryCreate(lua_State *L) {
checkCreateArguments(L, "ND.InventoryInit", s_tables && s_tables->inventory && s_tables->boot);
INVD &inventory = *s_tables->inventory;
+#ifdef ENABLE_NANCY_V5
+ if (g_nancy->getGameType() >= kGameTypeNancy26) {
+ return createNancy26Inventory(L, inventory);
+ }
+#endif
+
Common::String imageName;
if (!readField(L, 2, "ovl", imageName)) {
luaL_error(L, "InventoryInit:Create fed with table that has no 'ovl' field");
@@ -407,13 +436,13 @@ static void readCursor(lua_State *L, int cursorTable, ScriptBootData::Cursor &cu
readField(L, cursorTable, "overrideInv", cursor.overridesItem);
}
-static void requireCursorField(lua_State *L, const char *name, Common::String &value) {
+void requireCursorField(lua_State *L, const char *name, Common::String &value) {
if (!readField(L, 2, name, value)) {
luaL_error(L, "CursorInit:Create fed with table that has no '%s' field", name);
}
}
-static bool hasCursor(const ScriptBootData &boot, const Common::String &name) {
+bool hasCursor(const ScriptBootData &boot, const Common::String &name) {
for (const ScriptBootData::Cursor &cursor : boot.cursors) {
if (cursor.name.equalsIgnoreCase(name)) {
return true;
@@ -427,6 +456,12 @@ static int cursorCreate(lua_State *L) {
checkCreateArguments(L, "ND.CursorInit", s_tables && s_tables->boot);
ScriptBootData &boot = *s_tables->boot;
+#ifdef ENABLE_NANCY_V5
+ if (g_nancy->getGameType() >= kGameTypeNancy26) {
+ return createNancy26Cursors(L, boot);
+ }
+#endif
+
Common::String imageName;
requireCursorField(L, "ovl", imageName);
boot.cursorImageName = Common::Path(imageName);
@@ -491,6 +526,13 @@ static int cursorCreateInv(lua_State *L) {
// FontsInit and ColorsInit, whose tables go by number
static int fontsCreate(lua_State *L) {
+#ifdef ENABLE_NANCY_V5
+ // Nancy26: the file of a font made of pictures describes it
+ if (s_tables && s_tables->font) {
+ return createBitmapFont(L, *s_tables->font);
+ }
+#endif
+
checkCreateArguments(L, "ND.FontsInit", s_tables && s_tables->boot);
ScriptBootData &boot = *s_tables->boot;
@@ -663,6 +705,12 @@ void registerBootAPI(lua_State *L) {
};
registerGlobal(L, "FontsInit", "ND.FontsInit", kFontsInitFunctions);
+
+#ifdef ENABLE_NANCY_V5
+ if (g_nancy->getGameType() >= kGameTypeNancy26) {
+ registerNancy26BootAPI(L);
+ }
+#endif
}
} // End of namespace Script
diff --git a/engines/nancy/script/bootapi.h b/engines/nancy/script/bootapi.h
new file mode 100644
index 00000000000..f7d068ec93e
--- /dev/null
+++ b/engines/nancy/script/bootapi.h
@@ -0,0 +1,54 @@
+/* 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 NANCY_SCRIPT_BOOTAPI_H
+#define NANCY_SCRIPT_BOOTAPI_H
+
+#include "common/array.h"
+#include "common/str.h"
+
+#include "engines/nancy/script/api.h"
+
+struct lua_State;
+
+namespace Nancy {
+namespace Script {
+
+// What the "Init" objects of the boot scripts share
+
+// The tables the boot script that runs fills; null while none runs
+const BootTables *getBootTables();
+
+// Every Create function takes the object itself and one table. A script that
+// may not use the object gets an error.
+void checkCreateArguments(lua_State *L, const char *typeName, bool hasTable);
+
+// The keys of a table that are strings, in alphabetical order
+void getSortedKeys(lua_State *L, int tableIndex, Common::Array<Common::String> &keys);
+
+// A field of the table of CursorInit:Create that must be there
+void requireCursorField(lua_State *L, const char *name, Common::String &value);
+bool hasCursor(const ScriptBootData &boot, const Common::String &name);
+
+} // End of namespace Script
+} // End of namespace Nancy
+
+#endif // NANCY_SCRIPT_BOOTAPI_H
diff --git a/engines/nancy/script/v5/bootobjects.cpp b/engines/nancy/script/v5/bootobjects.cpp
new file mode 100644
index 00000000000..02ac09e38da
--- /dev/null
+++ b/engines/nancy/script/v5/bootobjects.cpp
@@ -0,0 +1,353 @@
+/* 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 "engines/nancy/nancy.h"
+
+#include "engines/nancy/script/api.h"
+#include "engines/nancy/script/bootapi.h"
+#include "engines/nancy/script/luabind.h"
+#include "engines/nancy/script/types.h"
+
+#include "engines/nancy/script/v5/bootobjects.h"
+
+#include "engines/nancy/ui/ndui/button.h"
+
+namespace Nancy {
+namespace Script {
+
+// Nancy26 gives every item the scene that shows it, or nothing. The pictures
+// of the items are cursors.
+int createNancy26Inventory(lua_State *L, INVD &inventory) {
+ Common::Array<Common::String> names;
+ getSortedKeys(L, 2, names);
+
+ for (const Common::String &name : names) {
+ INVD::Item item;
+ item.id = (int16)inventory.items.size();
+ item.name = name;
+
+ Common::String sceneName;
+ readField(L, 2, name.c_str(), sceneName);
+ item.sceneName = Common::Path(sceneName);
+ item.kind = sceneName.empty() ? UI::NDUI::InvButton::kItemPickUp : UI::NDUI::InvButton::kItemView;
+
+ inventory.items.push_back(item);
+ }
+
+ return 0;
+}
+
+// Nancy26: every cursor is a single picture, with its own image. What used to be
+// the variant for hovering something is a cursor of its own ("MagGlassHot"), and
+// the items are cursors named like them.
+static void readNancy26Cursor(lua_State *L, int cursorTable, ScriptBootData::Cursor &cursor) {
+ Common::String imageName;
+ if (!readField(L, cursorTable, "ovl", imageName) || !pushField(L, cursorTable, "source")) {
+ luaL_error(L, "Cursor %s needs the fields ovl, source and activePt", cursor.name.c_str());
+ }
+
+ cursor.imageName = Common::Path(imageName);
+ cursor.sources[0] = cursor.sources[1] = checkRect(L, -1).toRect();
+ lua_pop(L, 1);
+
+ ScriptPoint hotspot;
+ if (pushField(L, cursorTable, "activePt")) {
+ readPoint(L, -1, hotspot);
+ lua_pop(L, 1);
+ }
+
+ cursor.hotspots[0] = cursor.hotspots[1] = hotspot.toPoint();
+}
+
+int createNancy26Cursors(lua_State *L, ScriptBootData &boot) {
+ requireCursorField(L, "default", boot.defaultCursorName);
+ readField(L, 2, "rightNode", boot.rightNodeCursorName);
+ readField(L, 2, "leftNode", boot.leftNodeCursorName);
+ readField(L, 2, "uturnNode", boot.uturnNodeCursorName);
+
+ ScriptPoint offset;
+ if (pushField(L, 2, "invOffset")) {
+ readPoint(L, -1, offset);
+ lua_pop(L, 1);
+ }
+
+ boot.itemCursorOffset = offset.toPoint();
+
+ Common::Array<Common::String> names;
+ getSortedKeys(L, 2, names);
+
+ for (const Common::String &name : names) {
+ lua_getfield(L, 2, name.c_str());
+ if (lua_istable(L, -1)) {
+ ScriptBootData::Cursor cursor;
+ cursor.name = name;
+ readNancy26Cursor(L, lua_gettop(L), cursor);
+ boot.cursors.push_back(cursor);
+ }
+
+ lua_pop(L, 1);
+ }
+
+ if (!hasCursor(boot, boot.defaultCursorName)) {
+ luaL_error(L, "CursorInit:Create specified default as %s but there's no cursor by that name", boot.defaultCursorName.c_str());
+ }
+
+ return 0;
+}
+
+// One style of a font made of pictures, as a BMFont file describes it:
+// { ovl = picture, height = line height, [char] = { x, y, width, height, xoffset,
+// yoffset, xadvance }, kerning = { { first, second, amount }, ... } }
+static void readFontFace(lua_State *L, int faceTable, ScriptBootData::BitmapFont::Face &face) {
+ Common::String imageName;
+ if (!readField(L, faceTable, "ovl", imageName)) {
+ luaL_error(L, "A style of a font has no 'ovl' field");
+ }
+
+ face.imageName = Common::Path(imageName);
+ readField(L, faceTable, "height", face.height);
+
+ lua_pushnil(L);
+ while (lua_next(L, faceTable)) {
+ if (lua_type(L, -2) == LUA_TNUMBER && lua_istable(L, -1)) {
+ const int glyphTable = lua_gettop(L);
+ int x = 0, y = 0, width = 0, height = 0, xOffset = 0, yOffset = 0, xAdvance = 0;
+ readField(L, glyphTable, "x", x);
+ readField(L, glyphTable, "y", y);
+ readField(L, glyphTable, "width", width);
+ readField(L, glyphTable, "height", height);
+ readField(L, glyphTable, "xoffset", xOffset);
+ readField(L, glyphTable, "yoffset", yOffset);
+ readField(L, glyphTable, "xadvance", xAdvance);
+
+ ScriptBootData::BitmapFont::Glyph glyph;
+ glyph.source = Common::Rect(x, y, x + width, y + height);
+ glyph.xOffset = (int16)xOffset;
+ glyph.yOffset = (int16)yOffset;
+ glyph.xAdvance = (int16)xAdvance;
+ face.glyphs.setVal((uint32)lua_tointeger(L, -2), glyph);
+ }
+
+ lua_pop(L, 1);
+ }
+
+ if (pushField(L, faceTable, "kerning")) {
+ const int kerningTable = lua_gettop(L);
+ for (int i = 1; i <= (int)lua_objlen(L, kerningTable); ++i) {
+ lua_rawgeti(L, kerningTable, i);
+ if (lua_istable(L, -1)) {
+ const int pairTable = lua_gettop(L);
+ int first = 0, second = 0, amount = 0;
+ readField(L, pairTable, "first", first);
+ readField(L, pairTable, "second", second);
+ readField(L, pairTable, "amount", amount);
+ face.kerning.setVal(((uint32)first << 16) | (uint32)(second & 0xFFFF), amount);
+ }
+
+ lua_pop(L, 1);
+ }
+
+ lua_pop(L, 1);
+ }
+}
+
+// FontsInit:Create in the file of a font: its four styles
+int createBitmapFont(lua_State *L, ScriptBootData::BitmapFont &font) {
+ checkCreateArguments(L, "ND.FontsInit", true);
+
+ static const char *const kStyleNames[ScriptBootData::BitmapFont::kNumStyles] = {
+ "regular", "bold", "italic", "boldItalic"
+ };
+
+ for (int i = 0; i < ScriptBootData::BitmapFont::kNumStyles; ++i) {
+ if (pushField(L, 2, kStyleNames[i])) {
+ luaL_checktype(L, -1, LUA_TTABLE);
+ readFontFace(L, lua_gettop(L), font.faces[i]);
+ lua_pop(L, 1);
+ }
+ }
+
+ if (font.faces[ScriptBootData::BitmapFont::kRegular].imageName.empty()) {
+ luaL_error(L, "Font %s has no regular style", font.name.c_str());
+ }
+
+ return 0;
+}
+
+// FontsBoot:Init({ { name, number, file }, ... }): the fonts of the
+// game, each described by a script file of its own
+static int fontsBootInit(lua_State *L) {
+ checkCreateArguments(L, "ND.FontsBoot", getBootTables() && getBootTables()->boot);
+ ScriptBootData &boot = *getBootTables()->boot;
+
+ for (int i = 1; i <= (int)lua_objlen(L, 2); ++i) {
+ lua_rawgeti(L, 2, i);
+ luaL_checktype(L, -1, LUA_TTABLE);
+ const int entry = lua_gettop(L);
+
+ ScriptBootData::BitmapFont font;
+ Common::String fileName;
+ readField(L, entry, "name", font.name);
+ readField(L, entry, "number", font.id);
+ if (!readField(L, entry, "file", fileName)) {
+ luaL_error(L, "Font %s names no file", font.name.c_str());
+ }
+
+ lua_pop(L, 1);
+
+ BootTables fontTables;
+ fontTables.font = &font;
+ if (!runBootScript(fileName.c_str(), fontTables)) {
+ luaL_error(L, "Could not load the font file %s", fileName.c_str());
+ }
+
+ boot.bitmapFonts.push_back(font);
+ }
+
+ return 0;
+}
+
+// FontColorsInit:Create({ [number] = Color, ... })
+static int fontColorsCreate(lua_State *L) {
+ checkCreateArguments(L, "ND.FontColorsInit", getBootTables() && getBootTables()->boot);
+ ScriptBootData &boot = *getBootTables()->boot;
+
+ lua_pushnil(L);
+ while (lua_next(L, 2)) {
+ ScriptBootData::FontColor color;
+ color.id = luaL_checkint(L, -2);
+ color.normal = color.disabled = color.mouseOver = color.pressed = checkColor(L, -1);
+ boot.fontColors.push_back(color);
+ lua_pop(L, 1);
+ }
+
+ return 0;
+}
+
+// AutotextBoot:Load({ file, ... }): the files of texts
+static int autotextBootLoad(lua_State *L) {
+ checkCreateArguments(L, "ND.AutotextBoot", getBootTables() && getBootTables()->boot);
+ readStringList(L, 2, getBootTables()->boot->textFileNames);
+ return 0;
+}
+
+// BuildNumberInit:Define(text)
+static int buildNumberDefine(lua_State *L) {
+ checkUserData(L, 1, "ND.BuildNumberBoot");
+ if (!getBootTables() || !getBootTables()->boot) {
+ luaL_error(L, "ND.BuildNumberBoot cannot be used by this script");
+ }
+
+ getBootTables()->boot->buildNumber = luaL_checkstring(L, 2);
+ return 0;
+}
+
+void registerNancy26BootAPI(lua_State *L) {
+ struct NamedFunction {
+ const char *globalName;
+ const char *typeName;
+ const char *functionName;
+ lua_CFunction function;
+ };
+
+ static const NamedFunction kObjects[] = {
+ { "FontsBoot", "ND.FontsBoot", "Init", fontsBootInit },
+ { "FontColorsInit", "ND.FontColorsInit", "Create", fontColorsCreate },
+ { "AutotextBoot", "ND.AutotextBoot", "Load", autotextBootLoad },
+ { "BuildNumberInit", "ND.BuildNumberBoot", "Define", buildNumberDefine }
+ };
+
+ for (const NamedFunction &object : kObjects) {
+ const luaL_Reg functions[] = {
+ { "__index", indexFunctions },
+ { object.functionName, object.function },
+ { nullptr, nullptr }
+ };
+
+ registerGlobal(L, object.globalName, object.typeName, functions);
+ }
+}
+
+} // End of namespace Script
+
+static void runRequiredScript(const char *name, const Script::BootTables &tables) {
+ const Common::String scriptName = Common::String(name) + "_SC";
+ if (!Script::runBootScript(scriptName.c_str(), tables)) {
+ error("Failed to load boot script %s", scriptName.c_str());
+ }
+}
+
+// Nancy26 reads a different set of boot scripts, in this order. Its BOOT_SC
+// is left over from the earlier games; the exe never runs it. What it set
+// is fixed in the exe instead.
+void NancyEngine::bootNancy26Data(ScriptBootData *boot, EVNT *flags, INVD *inventory, ENVS *environments, VIEW *viewport, CVTX *autotext) {
+ Script::BootTables flagTables;
+ flagTables.flags = flags;
+ runRequiredScript("Flags", flagTables);
+
+ Script::BootTables bootTables;
+ bootTables.boot = boot;
+ runRequiredScript("Vars", bootTables);
+ runRequiredScript("Strs", bootTables);
+ runRequiredScript("Fonts", bootTables);
+
+ Script::BootTables inventoryTables;
+ inventoryTables.inventory = inventory;
+ inventoryTables.boot = boot;
+ runRequiredScript("InventoryInit", inventoryTables);
+ runRequiredScript("Cursors", inventoryTables);
+
+ Script::BootTables envTables;
+ envTables.environments = environments;
+ runRequiredScript("Envs", envTables);
+
+ runRequiredScript("AutotextBoot", bootTables);
+ runRequiredScript("BuildNumber", bootTables);
+
+ Script::BootTables textTables;
+ textTables.texts = autotext;
+ for (const Common::String &name : boot->textFileNames) {
+ if (!Script::runBootScript(name.c_str(), textTables)) {
+ error("Failed to load text file %s", name.c_str());
+ }
+ }
+
+ // The window is 1024x768, and the viewport the 1024x690 at the top of it
+ viewport->screenPosition = Common::Rect(0, 0, 1024, 690);
+ viewport->bounds = Common::Rect(0, 0, 1024, 768);
+
+ // The sides of a node turn it, and the strip along the bottom turns it around
+ const int width = viewport->screenPosition.width();
+ const int height = viewport->screenPosition.height();
+ boot->leftNodeHotspot = Common::Rect(0, 0, 47, height - 80);
+ boot->rightNodeHotspot = Common::Rect(width - 47, 0, width, height - 80);
+ boot->uturnNodeHotspot = Common::Rect(0, height - 80, width, height);
+
+ boot->defaultSaveName = "Tomb";
+
+ // The scripts every scene starts with
+ static const char *const kIncludeFiles[] = { "Math_SC", "Fader_SC", "string_SC", "ScriptingShortcuts_SC" };
+ for (const char *name : kIncludeFiles) {
+ boot->includeFileNames.push_back(name);
+ }
+}
+
+} // End of namespace Nancy
diff --git a/engines/nancy/script/v5/bootobjects.h b/engines/nancy/script/v5/bootobjects.h
new file mode 100644
index 00000000000..046fdd8583b
--- /dev/null
+++ b/engines/nancy/script/v5/bootobjects.h
@@ -0,0 +1,45 @@
+/* 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 NANCY_SCRIPT_V5_BOOTOBJECTS_H
+#define NANCY_SCRIPT_V5_BOOTOBJECTS_H
+
+#include "engines/nancy/enginedata.h"
+
+struct lua_State;
+
+namespace Nancy {
+namespace Script {
+
+// Nancy26's forms of InventoryInit:Create and CursorInit:Create, and the
+// FontsInit:Create the file of a font made of pictures calls
+int createNancy26Inventory(lua_State *L, INVD &inventory);
+int createNancy26Cursors(lua_State *L, ScriptBootData &boot);
+int createBitmapFont(lua_State *L, ScriptBootData::BitmapFont &font);
+
+// The "Init" objects only Nancy26's boot scripts have: FontsBoot,
+// FontColorsInit, AutotextBoot and BuildNumberInit
+void registerNancy26BootAPI(lua_State *L);
+
+} // End of namespace Script
+} // End of namespace Nancy
+
+#endif // NANCY_SCRIPT_V5_BOOTOBJECTS_H
diff --git a/engines/nancy/state/scene.cpp b/engines/nancy/state/scene.cpp
index 3a7f3dbf8b9..7dbc7007de4 100644
--- a/engines/nancy/state/scene.cpp
+++ b/engines/nancy/state/scene.cpp
@@ -2015,7 +2015,9 @@ UI::Clock *Scene::getClock() {
void Scene::init() {
// A design may have been picked before the game itself started, so refresh
// the engine data the widgets below are built from
- if (g_nancy->getGameType() >= kGameTypeNancy15) {
+ // Nancy26 has no player characters to pick from
+ const PCUI *pcui = GetEngineData(PCUI);
+ if (g_nancy->getGameType() >= kGameTypeNancy15 && (!pcui || !pcui->characters.empty())) {
g_nancy->setPlayerCharacter(g_nancy->getPlayerCharacter());
}
Commit: c6a07514e4f250fd4939dab5ac1351d841a6636c
https://github.com/scummvm/scummvm/commit/c6a07514e4f250fd4939dab5ac1351d841a6636c
Author: Filippos Karapetis (bluegr at gmail.com)
Date: 2026-11-06T04:10:32+02:00
Commit Message:
NANCY: NANCY26: Give every cursor a picture of its own
Nancy26 names a picture for every cursor instead of one sheet for all
of them, and its rects leave out their last row and column. An item
held by the mouse shows the cursor that has the name of the item.
Changed paths:
engines/nancy/cursor.cpp
engines/nancy/cursor.h
diff --git a/engines/nancy/cursor.cpp b/engines/nancy/cursor.cpp
index 3d88a90d523..1411f342b0b 100644
--- a/engines/nancy/cursor.cpp
+++ b/engines/nancy/cursor.cpp
@@ -154,8 +154,17 @@ void CursorManager::init(const ScriptBootData &boot) {
_defaultCursorType = MAX(getCursorTypeByName(boot.defaultCursorName), 0);
- g_nancy->_resource->loadImage(boot.cursorImageName, _uiCursorsSurface);
- g_nancy->_resource->loadImage(boot.itemCursorImageName, _invCursorsSurface);
+ if (g_nancy->getGameType() >= kGameTypeNancy26) {
+ // The cursor of an item is the one named like it
+ const INVD *inventory = GetEngineData(INVD);
+ _itemCursorTypes.clear();
+ for (uint i = 0; inventory && i < inventory->items.size(); ++i) {
+ _itemCursorTypes.push_back(getCursorTypeByName(inventory->items[i].name));
+ }
+ } else {
+ g_nancy->_resource->loadImage(boot.cursorImageName, _uiCursorsSurface);
+ g_nancy->_resource->loadImage(boot.itemCursorImageName, _invCursorsSurface);
+ }
_isInitialized = true;
@@ -170,17 +179,36 @@ void CursorManager::addScriptedCursors(const Common::Array<ScriptBootData::Curso
slot.bounds = cursor.sources[i];
slot.hotspot = cursor.hotspots[i];
- // The rects of the cursor sheet include their last row and column
- if (!slot.bounds.isEmpty()) {
+ // The rects of the cursor sheet include their last row and column.
+ // Nancy26's are exclusive, like all its other rects.
+ if (!slot.bounds.isEmpty() && cursor.imageName.empty()) {
++slot.bounds.right;
++slot.bounds.bottom;
}
+ if (!cursor.imageName.empty()) {
+ slot.image = getScriptedCursorImage(cursor.imageName);
+ }
+
_cursors.push_back(slot);
}
}
}
+int CursorManager::getScriptedCursorImage(const Common::Path &name) {
+ for (uint i = 0; i < _scriptedCursorImageNames.size(); ++i) {
+ if (_scriptedCursorImageNames[i] == name) {
+ return i;
+ }
+ }
+
+ Common::SharedPtr<Graphics::ManagedSurface> image(new Graphics::ManagedSurface());
+ g_nancy->_resource->loadImage(name, *image);
+ _scriptedCursorImageNames.push_back(name);
+ _scriptedCursorImages.push_back(image);
+ return _scriptedCursorImages.size() - 1;
+}
+
int CursorManager::getCursorTypeByName(const Common::String &name) const {
for (uint i = 0; i < _cursorNames.size(); ++i) {
if (_cursorNames[i].equalsIgnoreCase(name)) {
@@ -207,7 +235,13 @@ uint CursorManager::resolveScriptedCursorID(CursorType type, int16 itemID, bool
const uint variant = hotspotVariant ? ScriptBootData::kCursorHot : ScriptBootData::kCursorRegular;
// A held item replaces every cursor that doesn't ask to be kept
- const uint itemSlot = ((uint)_numCursorTypes + (uint)itemID) * ScriptBootData::kNumCursorVariants + variant;
+ uint itemSlot = ((uint)_numCursorTypes + (uint)itemID) * ScriptBootData::kNumCursorVariants + variant;
+ if (!_itemCursorTypes.empty()) {
+ // Nancy26: the cursor named like the item
+ const int itemType = itemID >= 0 && (uint)itemID < _itemCursorTypes.size() ? _itemCursorTypes[itemID] : -1;
+ itemSlot = itemType >= 0 ? (uint)itemType * ScriptBootData::kNumCursorVariants + variant : _cursors.size();
+ }
+
const bool keepsCursor = cursorType < _cursorOverridesItem.size() && _cursorOverridesItem[cursorType];
if (itemID != -1 && !keepsCursor && itemSlot < _cursors.size() && !_cursors[itemSlot].bounds.isEmpty()) {
_hasItem = true;
@@ -514,7 +548,9 @@ void CursorManager::applyCursor() {
Common::Rect bounds = _cursors[_curCursorID].bounds;
Common::Point hotspot = _cursors[_curCursorID].hotspot;
- if (_hasItem)
+ if (_cursors[_curCursorID].image >= 0)
+ surf = _scriptedCursorImages[_cursors[_curCursorID].image].get();
+ else if (_hasItem)
surf = &_invCursorsSurface;
else
surf = !isNancy13 ? &g_nancy->_graphics->_object0 : &_uiCursorsSurface;
diff --git a/engines/nancy/cursor.h b/engines/nancy/cursor.h
index 348a2d6b100..e316ac319f6 100644
--- a/engines/nancy/cursor.h
+++ b/engines/nancy/cursor.h
@@ -23,6 +23,7 @@
#define NANCY_CURSOR_H
#include "common/array.h"
+#include "common/ptr.h"
#include "common/stream.h"
#include "graphics/managed_surface.h"
@@ -159,6 +160,7 @@ public:
void setCursor(CursorType type, int16 itemID, bool setFromScript, bool hotspotVariant = true);
void setCursorType(CursorType type, bool setFromScript = false, bool hotspotVariant = true);
void setCursorItemID(int16 itemID);
+ bool isHoldingItem() const { return _curItemID != -1; }
void showCursor(bool shouldShow);
void warpCursor(const Common::Point &pos);
@@ -186,10 +188,12 @@ private:
uint resolveScriptedCursorID(CursorType type, int16 itemID, bool setFromScript, bool hotspotVariant);
void addScriptedCursors(const Common::Array<ScriptBootData::Cursor> &cursors);
+ int getScriptedCursorImage(const Common::Path &name);
struct Cursor {
Common::Rect bounds;
Common::Point hotspot;
+ int image = -1; // Nancy26: the one of _scriptedCursorImages it is in
};
// CURS data
@@ -206,6 +210,12 @@ private:
Graphics::ManagedSurface _invCursorsSurface;
Graphics::ManagedSurface _uiCursorsSurface; // Nancy13+
+ // Nancy26: every cursor names its picture, and the cursor of an item has
+ // the name of the item
+ Common::Array<Common::Path> _scriptedCursorImageNames;
+ Common::Array<Common::SharedPtr<Graphics::ManagedSurface> > _scriptedCursorImages;
+ Common::Array<int> _itemCursorTypes; // by item; -1 for none
+
Common::Point _warpedMousePos;
CursorType _curCursorType;
bool _curSetFromScript;
Commit: ecc0fe83a708262239817479049530b8fb48ec28
https://github.com/scummvm/scummvm/commit/ecc0fe83a708262239817479049530b8fb48ec28
Author: Filippos Karapetis (bluegr at gmail.com)
Date: 2026-11-06T04:10:39+02:00
Commit Message:
NANCY: NANCY26: Make every record a node of a tree
In Nancy26, a record can be enabled (gets the player's input), visible
(gets drawn) and paused (doesn't run), and "active" stands for all
three at once. The records attached to a Transformer take these on
from it. ResetInactive() starts a record over without making it active.
Changed paths:
A engines/nancy/script/v5/recordnode.cpp
A engines/nancy/script/v5/recordnode.h
engines/nancy/module.mk
engines/nancy/script/graphnode.h
engines/nancy/script/particles.cpp
engines/nancy/script/record.cpp
engines/nancy/script/record.h
engines/nancy/script/records.cpp
engines/nancy/script/scenecontext.cpp
engines/nancy/script/scenecontext.h
engines/nancy/script/transformer.cpp
engines/nancy/script/xsheet.cpp
diff --git a/engines/nancy/module.mk b/engines/nancy/module.mk
index ce4d37e2f0b..0cd60044e98 100644
--- a/engines/nancy/module.mk
+++ b/engines/nancy/module.mk
@@ -240,7 +240,8 @@ MODULE_OBJS += \
# Nancy26 and newer, whose UI is made of records as well
ifdef ENABLE_NANCY_V5
MODULE_OBJS += \
- script/v5/bootobjects.o
+ script/v5/bootobjects.o \
+ script/v5/recordnode.o
endif
endif
diff --git a/engines/nancy/script/graphnode.h b/engines/nancy/script/graphnode.h
index ac8f994bb91..92a8335e4e5 100644
--- a/engines/nancy/script/graphnode.h
+++ b/engines/nancy/script/graphnode.h
@@ -29,6 +29,7 @@ struct lua_State;
namespace Nancy {
namespace Script {
+class Record;
class SceneContext;
// Nancy21 lets a scene group its records under nodes of their own, made with
@@ -39,14 +40,24 @@ class SceneContext;
// record is such a node.
class GraphNode {
public:
- GraphNode(SceneContext &context) : _context(context) {}
+ // A Transformer record is the owner of its node
+ GraphNode(SceneContext &context, Record *owner = nullptr) : _context(context), _owner(owner) {}
SceneContext &getContext() const { return _context; }
+ Record *getOwner() const { return _owner; }
// Including those of the nodes above
double getZ() const;
ScriptMatrix getTransform() const;
+#ifdef ENABLE_NANCY_V5
+ // Nancy26: what the records under the node take on, which are the ones
+ // of the Transformer that owns it, after the nodes above it had their say
+ bool isEnabled() const;
+ bool isVisible() const;
+ bool isPaused() const;
+#endif
+
// The node's own, which Nancy22's Transformer records set
void setZ(double z);
void setTransform(const ScriptMatrix &transform);
@@ -66,6 +77,7 @@ public:
private:
SceneContext &_context;
+ Record *_owner;
double _z = 0.0;
ScriptMatrix _transform;
GraphNode *_parent = nullptr;
diff --git a/engines/nancy/script/particles.cpp b/engines/nancy/script/particles.cpp
index 0263a27bdc3..f37a7f4c021 100644
--- a/engines/nancy/script/particles.cpp
+++ b/engines/nancy/script/particles.cpp
@@ -1087,7 +1087,7 @@ void ParticleRecord::registerGraphics() {
}
void ParticleRecord::updateGraphics() {
- if (!isActive() || _count == 0) {
+ if (!isShown() || _count == 0) {
if (_canvas) {
_canvas->setVisible(false);
}
diff --git a/engines/nancy/script/record.cpp b/engines/nancy/script/record.cpp
index 0385cec8fb5..c4c34d43033 100644
--- a/engines/nancy/script/record.cpp
+++ b/engines/nancy/script/record.cpp
@@ -21,6 +21,8 @@
#include "common/algorithm.h"
+#include "engines/nancy/nancy.h"
+
#include "engines/nancy/script/api.h"
#include "engines/nancy/script/graphnode.h"
#include "engines/nancy/script/luabind.h"
@@ -31,6 +33,10 @@
#include "engines/nancy/script/transformer.h"
#include "engines/nancy/script/types.h"
+#ifdef ENABLE_NANCY_V5
+#include "engines/nancy/script/v5/recordnode.h"
+#endif
+
namespace Nancy {
namespace Script {
@@ -39,12 +45,39 @@ static const char *const kRecordMarker = "__record";
Record::Record(SceneContext &context, const char *typeName) :
_context(context),
- _typeName(typeName) {}
+ _typeName(typeName) {
+#ifdef ENABLE_NANCY_V5
+ if (g_nancy->getGameType() >= kGameTypeNancy26) {
+ createNodeState();
+ }
+#endif
+}
Record::~Record() {
+#ifdef ENABLE_NANCY_V5
+ destroyNodeState();
+#endif
+
delete _stages;
}
+bool Record::isActive() const {
+#ifdef ENABLE_NANCY_V5
+ if (_nodeState) {
+ return _nodeState->isActive();
+ }
+#endif
+
+ return _isActive && !_isDone;
+}
+
+// What the records draw with. Nancy26 has its own, in v5/recordnode.cpp.
+#ifndef ENABLE_NANCY_V5
+bool Record::isShown() const {
+ return isActive();
+}
+#endif
+
void Record::onStagesChanged() {
}
@@ -129,9 +162,20 @@ void Record::create(int tableIndex) {
readField(L, tableIndex, "z", _z);
readField(L, tableIndex, "scriptOwns", _isScriptOwned);
+#ifdef ENABLE_NANCY_V5
+ if (_nodeState) {
+ readNodeFields(tableIndex);
+ }
+#endif
+
lua_getfield(L, tableIndex, "active");
if (lua_isboolean(L, -1)) {
_isActive = lua_toboolean(L, -1) != 0;
+#ifdef ENABLE_NANCY_V5
+ if (_nodeState) {
+ setActiveFlags(_isActive);
+ }
+#endif
} else if (lua_isfunction(L, -1)) {
_hasActiveFunction = true;
}
@@ -174,6 +218,13 @@ void Record::onObjectCollected() {
}
void Record::update(double sceneTime, double elapsedTime) {
+#ifdef ENABLE_NANCY_V5
+ if (_nodeState) {
+ updateNode(sceneTime, elapsedTime);
+ return;
+ }
+#endif
+
if (_isDone) {
return;
}
@@ -264,6 +315,12 @@ void Record::limitZ(double z) {
void Record::finish() {
_isDone = true;
+#ifdef ENABLE_NANCY_V5
+ if (_nodeState) {
+ setActiveFlags(false);
+ }
+#endif
+
if (getContext().isSkipping()) {
_hasEndedInSkip = true;
}
@@ -288,6 +345,14 @@ bool Record::reset() {
_hasRunOnce = false;
_isDone = false;
_hasStarted = false;
+
+ // Nancy26's Reset makes the record active, like Restart
+#ifdef ENABLE_NANCY_V5
+ if (_nodeState) {
+ setActiveFlags(true);
+ }
+#endif
+
callFunction("OnReset");
return true;
}
@@ -344,6 +409,14 @@ int Record::getScriptField() {
lua_State *L = getLua();
const Common::String key = luaL_checkstring(L, 2);
+ // What a script stored under the name of a function for the player's input
+ // wins over the base fields of Nancy26
+#ifdef ENABLE_NANCY_V5
+ if (_nodeState && !isEventFunctionName(key)) {
+ return getNodeScriptField(key);
+ }
+#endif
+
if (key == "active") {
lua_pushboolean(L, isActive());
return 1;
@@ -392,6 +465,17 @@ int Record::setScriptField() {
lua_State *L = getLua();
const Common::String key = luaL_checkstring(L, 2);
+#ifdef ENABLE_NANCY_V5
+ if (_nodeState) {
+ if (!setNodeField(key) && !setField(key)) {
+ lua_pushvalue(L, 3);
+ storeValue(key.c_str());
+ }
+
+ return 0;
+ }
+#endif
+
if (key == "active") {
if (lua_isfunction(L, 3)) {
lua_pushvalue(L, 3);
diff --git a/engines/nancy/script/record.h b/engines/nancy/script/record.h
index 050768ec57e..2d76c0d9c0d 100644
--- a/engines/nancy/script/record.h
+++ b/engines/nancy/script/record.h
@@ -38,6 +38,7 @@ namespace Script {
class BlendStages;
class GraphNode;
class SceneContext;
+struct RecordNodeState;
// What the player does that records get told about
enum RecordEvent {
@@ -121,7 +122,7 @@ public:
// Whether messages sent to the given name are for this record
virtual bool hasMessagingName(const Common::String &name) { return false; }
- bool isActive() const { return _isActive && !_isDone; }
+ bool isActive() const;
bool isDone() const { return _isDone; }
bool hasStarted() const { return _hasStarted; }
bool hasRunOnce() const { return _hasRunOnce; }
@@ -168,10 +169,40 @@ public:
// stages when it has any
ScriptMatrix getLocalTransform() const;
+ // Whether what the record draws gets shown: while it is visible from Nancy26
+ // on, while it is active before
+ bool isShown() const;
+
// The blend stages of the record, which Nancy22 has in Transformers
BlendStages &getStages();
virtual void onStagesChanged();
+#ifdef ENABLE_NANCY_V5
+ // Nancy26: works like reset(), but leaves the record inactive
+ bool resetInactive();
+
+ // Nancy26: every record is a node of a tree, which can be enabled (gets the
+ // player's input), visible (gets drawn) and paused (doesn't run). A record is
+ // each of them when it says so itself, and the Transformers it is attached to
+ // don't say otherwise. "active" stands for all three: enabled, visible and
+ // not paused.
+ bool isNodeEnabled() const;
+ bool isNodeVisible() const;
+ bool isNodePaused() const;
+ void setLocalEnabled(bool isEnabled);
+ void setLocalVisible(bool isVisible);
+ void setLocalPaused(bool isPaused);
+ void setActiveFlags(bool isActive);
+
+ // Nancy26: the order keys go to the records in, highest first
+ double getKeyZ() const;
+
+ // Nancy26: the name the record goes by of its own, and the one its
+ // messages come from
+ const Common::String &getUniqueAlias() const;
+ const Common::String &getName() const;
+#endif
+
// Nancy21: puts the record under a node; null for none
GraphNode *getParentNode() const { return _parentNode; }
void setParentNode(GraphNode *node);
@@ -268,6 +299,20 @@ private:
bool _isDropped = false;
BlendStages *_stages = nullptr;
+
+#ifdef ENABLE_NANCY_V5
+ // Nancy26: what makes the record a node of the tree, and what goes with it.
+ // The other games have none.
+ void createNodeState();
+ void destroyNodeState();
+ void readNodeFields(int tableIndex);
+ void updateNode(double sceneTime, double elapsedTime);
+ int getNodeScriptField(const Common::String &key);
+ bool getNodeField(const Common::String &key);
+ bool setNodeField(const Common::String &key);
+
+ RecordNodeState *_nodeState = nullptr;
+#endif
};
// Makes the "AR" object, and the types of the records
diff --git a/engines/nancy/script/records.cpp b/engines/nancy/script/records.cpp
index ea901ac5a5a..1535cb0d7fa 100644
--- a/engines/nancy/script/records.cpp
+++ b/engines/nancy/script/records.cpp
@@ -1014,7 +1014,7 @@ void OverrideRecord::updateGraphics() {
const bool hasRender = lua_isfunction(L, -1);
lua_pop(L, 1);
- if (!hasRender || !isActive()) {
+ if (!hasRender || !isShown()) {
if (_canvas) {
_canvas->setVisible(false);
}
@@ -1282,7 +1282,7 @@ void OverlayRecord::registerGraphics() {
}
void OverlayRecord::updateGraphics() {
- if (_hasDestTable && isActive()) {
+ if (_hasDestTable && isShown()) {
Common::Array<ScriptRect> dests;
readDestTable(dests);
if (dests != _tableDests) {
@@ -1291,11 +1291,11 @@ void OverlayRecord::updateGraphics() {
}
}
- if (_isPlacementStale && isActive()) {
+ if (_isPlacementStale && isShown()) {
applyRects();
}
- _graphic.setVisible(isActive() && _hasPicture);
+ _graphic.setVisible(isShown() && _hasPicture);
if (_hasAttachment) {
_attachment.setVisible(_isAttachmentDrawn);
@@ -1617,7 +1617,7 @@ void AnimOverlayRecord::registerGraphics() {
}
void AnimOverlayRecord::updateGraphics() {
- _graphic.setVisible(isActive() && _isVisible && _hasPicture);
+ _graphic.setVisible(isShown() && _isVisible && _hasPicture);
}
// anim:Play() and anim:Pause(), for the records that play something
@@ -2290,6 +2290,13 @@ bool MovieRecord::isSkippable() const {
return false;
}
+#ifdef ENABLE_NANCY_V5
+ // Nancy26: not while the movie is hidden or paused with what it hangs under
+ if (g_nancy->getGameType() >= kGameTypeNancy26 && (!isNodeVisible() || isNodePaused())) {
+ return false;
+ }
+#endif
+
return !_pausesOnLastFrame || (_player.isRangePlaying() && !_hasCalledOnPause);
}
@@ -2375,7 +2382,7 @@ void MovieRecord::onZChanged() {
}
void MovieRecord::updateGraphics() {
- _graphic.setVisible(isActive() && _isVisible && !isSeeThrough());
+ _graphic.setVisible(isShown() && _isVisible && !isSeeThrough());
}
void MovieRecord::describeState(Common::Array<Common::String> &lines) const {
diff --git a/engines/nancy/script/scenecontext.cpp b/engines/nancy/script/scenecontext.cpp
index 5d8357a825c..591a453492a 100644
--- a/engines/nancy/script/scenecontext.cpp
+++ b/engines/nancy/script/scenecontext.cpp
@@ -535,8 +535,8 @@ const ViewTransform *SceneContext::getViewTransform() const {
return NancySceneState.getStreams().getViewTransform(_streamName);
}
-GraphNode *SceneContext::createGraphNode() {
- GraphNode *node = new GraphNode(*this);
+GraphNode *SceneContext::createGraphNode(Record *owner) {
+ GraphNode *node = new GraphNode(*this, owner);
_graphNodes.push_back(node);
return node;
}
diff --git a/engines/nancy/script/scenecontext.h b/engines/nancy/script/scenecontext.h
index ab06bc9d09c..6b621e093b2 100644
--- a/engines/nancy/script/scenecontext.h
+++ b/engines/nancy/script/scenecontext.h
@@ -139,8 +139,9 @@ public:
// The panels a scene adds to the UI call into its scripts, so they go when it does
void setMakesUI() { _makesUI = true; }
- // Nancy21: a new node to group records under, which lasts as long as the scene
- GraphNode *createGraphNode();
+ // Nancy21: a new node to group records under, which lasts as long as the scene.
+ // A Transformer record owns the one it is.
+ GraphNode *createGraphNode(Record *owner = nullptr);
// Lets the records under a node know that it changed its z or transform,
// once the frame is over
diff --git a/engines/nancy/script/transformer.cpp b/engines/nancy/script/transformer.cpp
index 3a91105640b..c013c979315 100644
--- a/engines/nancy/script/transformer.cpp
+++ b/engines/nancy/script/transformer.cpp
@@ -350,7 +350,7 @@ bool BlendStages::pushFunction(lua_State *L, const Common::String &key) {
TransformerRecord::TransformerRecord(SceneContext &context, const char *typeName) :
Record(context, typeName),
- _node(context.createGraphNode()) {}
+ _node(context.createGraphNode(this)) {}
void TransformerRecord::readTable(int tableIndex) {
lua_State *L = getLua();
diff --git a/engines/nancy/script/v5/recordnode.cpp b/engines/nancy/script/v5/recordnode.cpp
new file mode 100644
index 00000000000..36c0a78c4cc
--- /dev/null
+++ b/engines/nancy/script/v5/recordnode.cpp
@@ -0,0 +1,365 @@
+/* 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/>.
+ *
+ */
+
+// The parts of Record that make every record of Nancy26 a node of a tree
+
+#include "engines/nancy/script/graphnode.h"
+#include "engines/nancy/script/luabind.h"
+#include "engines/nancy/script/luastate.h"
+#include "engines/nancy/script/record.h"
+#include "engines/nancy/script/scenecontext.h"
+#include "engines/nancy/script/transformer.h"
+#include "engines/nancy/script/types.h"
+
+#include "engines/nancy/script/v5/recordnode.h"
+
+namespace Nancy {
+namespace Script {
+
+void Record::createNodeState() {
+ _nodeState = new RecordNodeState();
+
+ // Every record goes by a name of its own
+ static uint s_numRecords = 0;
+ _nodeState->uniqueAlias = Common::String::format("AR%u", ++s_numRecords);
+}
+
+void Record::destroyNodeState() {
+ if (!_nodeState) {
+ return;
+ }
+
+ delete _nodeState;
+ _nodeState = nullptr;
+}
+
+bool Record::isNodeEnabled() const {
+ if (!_nodeState->localEnabled) {
+ return false;
+ }
+
+ return !_parentNode || _parentNode->isEnabled();
+}
+
+bool Record::isNodeVisible() const {
+ if (!_nodeState->localVisible) {
+ return false;
+ }
+
+ return !_parentNode || _parentNode->isVisible();
+}
+
+bool Record::isNodePaused() const {
+ if (_nodeState->localPaused) {
+ return true;
+ }
+
+ return _parentNode && _parentNode->isPaused();
+}
+
+void Record::setLocalEnabled(bool isEnabled) {
+ _nodeState->localEnabled = isEnabled;
+}
+
+void Record::setLocalVisible(bool isVisible) {
+ _nodeState->localVisible = isVisible;
+}
+
+void Record::setLocalPaused(bool isPaused) {
+ _nodeState->localPaused = isPaused;
+}
+
+void Record::setActiveFlags(bool isActive) {
+ _nodeState->localEnabled = isActive;
+ _nodeState->localVisible = isActive;
+ _nodeState->localPaused = !isActive;
+}
+
+double Record::getKeyZ() const {
+ return _nodeState->keyZ;
+}
+
+const Common::String &Record::getUniqueAlias() const {
+ return _nodeState->uniqueAlias;
+}
+
+const Common::String &Record::getName() const {
+ return _nodeState->localName.empty() ? _nodeState->uniqueAlias : _nodeState->localName;
+}
+
+// What the records draw with. The records of the other games are shown while
+// they are active.
+
+bool Record::isShown() const {
+ return _nodeState ? isNodeVisible() : isActive();
+}
+
+static bool readOptionalBool(lua_State *L, int tableIndex, const char *name, bool &value) {
+ lua_getfield(L, tableIndex, name);
+ const bool isBool = lua_isboolean(L, -1);
+ if (isBool) {
+ value = lua_toboolean(L, -1) != 0;
+ }
+
+ lua_pop(L, 1);
+ return isBool;
+}
+
+static bool readOptionalNumber(lua_State *L, int tableIndex, const char *name, double &value) {
+ lua_getfield(L, tableIndex, name);
+ const bool isNumber = lua_type(L, -1) == LUA_TNUMBER;
+ if (isNumber) {
+ value = lua_tonumber(L, -1);
+ }
+
+ lua_pop(L, 1);
+ return isNumber;
+}
+
+void Record::readNodeFields(int tableIndex) {
+ lua_State *L = getLua();
+
+ // The exe passes over values of another type, which scripts use for
+ // their own purposes, e.g. a function as localVisible in RandomMovie_SC
+ readOptionalBool(L, tableIndex, "localEnabled", _nodeState->localEnabled);
+ readOptionalBool(L, tableIndex, "localVisible", _nodeState->localVisible);
+ readOptionalBool(L, tableIndex, "localPaused", _nodeState->localPaused);
+ readOptionalNumber(L, tableIndex, "keyZ", _nodeState->keyZ);
+
+ lua_getfield(L, tableIndex, "localName");
+ if (lua_type(L, -1) == LUA_TSTRING) {
+ _nodeState->localName = lua_tostring(L, -1);
+ }
+
+ lua_pop(L, 1);
+}
+
+// An "active" function sets all three flags every frame. The record gets
+// activated when it becomes enabled, visible and unpaused, and runs while it
+// isn't paused; a record that is done is paused until it gets reset.
+void Record::updateNode(double sceneTime, double elapsedTime) {
+ // A record that is done stays so until it gets reset, even when its "active"
+ // function says otherwise, e.g. RandomMovie_SC's pause timer
+ if (_isDone) {
+ return;
+ }
+
+ lua_State *L = getLua();
+
+ if (_hasActiveFunction) {
+ pushStoredValue("active");
+ push();
+ if (LuaState::call(L, 1, 1, "Error in AR's active function")) {
+ setActiveFlags(lua_toboolean(L, -1) != 0);
+ lua_pop(L, 1);
+ }
+ }
+
+ const bool isActiveNow = isNodeEnabled() && isNodeVisible() && !isNodePaused();
+ if (isActiveNow != _wasActive) {
+ _wasActive = isActiveNow;
+
+ // The records made of script functions call them by themselves
+ if (isActiveNow) {
+ onActivation();
+ if (!isScripted()) {
+ callFunction("OnActivation");
+ }
+ } else {
+ onDeactivation();
+ if (!isScripted()) {
+ callFunction("OnDeactivation");
+ }
+ }
+ }
+
+ if (isNodePaused() || isPaused()) {
+ return;
+ }
+
+ _hasStarted = true;
+
+ if (!_hasRunOnce) {
+ _hasRunOnce = true;
+ runOnce();
+ callFunction("RunOnce");
+ }
+
+ if (isScripted()) {
+ lua_pushnumber(L, sceneTime);
+ lua_pushnumber(L, elapsedTime);
+ callFunction("Run", 2);
+ } else {
+ run(sceneTime, elapsedTime);
+ }
+}
+
+bool Record::resetInactive() {
+ if (!prepareReset()) {
+ return false;
+ }
+
+ _hasRunOnce = false;
+ _isDone = false;
+ _hasStarted = false;
+ _hasActiveFunction = false;
+ setActiveFlags(false);
+ callFunction("OnReset");
+ return true;
+}
+
+// ar:ResetInactive()
+static int recordResetInactive(lua_State *L) {
+ if (!checkRecord(L, 1)->resetInactive()) {
+ return luaL_error(L, "Cannot reset AR");
+ }
+
+ return 0;
+}
+
+int Record::getNodeScriptField(const Common::String &key) {
+ lua_State *L = getLua();
+
+ // The kinds that can be done say so themselves
+ if (key == "done" && getField(key)) {
+ return 1;
+ }
+
+ if (getNodeField(key) || getField(key)) {
+ return 1;
+ }
+
+ pushStoredValue(key.c_str());
+ if (!lua_isnil(L, -1)) {
+ return 1;
+ }
+
+ lua_pop(L, 1);
+ return indexFunctions(L);
+}
+
+// The fields and functions every record has
+bool Record::getNodeField(const Common::String &key) {
+ lua_State *L = getLua();
+
+ if (key == "active") {
+ lua_pushboolean(L, isActive());
+ } else if (key == "done") {
+ lua_pushboolean(L, _isDone);
+ } else if (key == "z") {
+ lua_pushnumber(L, _z);
+ } else if (key == "keyZ") {
+ lua_pushnumber(L, _nodeState->keyZ);
+ } else if (key == "enabled") {
+ lua_pushboolean(L, isNodeEnabled());
+ } else if (key == "visible") {
+ lua_pushboolean(L, isNodeVisible());
+ } else if (key == "paused") {
+ lua_pushboolean(L, isNodePaused());
+ } else if (key == "localEnabled") {
+ lua_pushboolean(L, _nodeState->localEnabled);
+ } else if (key == "localVisible") {
+ lua_pushboolean(L, _nodeState->localVisible);
+ } else if (key == "localPaused") {
+ lua_pushboolean(L, _nodeState->localPaused);
+ } else if (key == "transform") {
+ pushMatrix(L, getTransform());
+ } else if (key == "invTransform") {
+ pushMatrix(L, getTransform().inverse());
+ } else if (key == "name") {
+ lua_pushstring(L, getName().c_str());
+ } else if (key == "uniqueAlias") {
+ lua_pushstring(L, _nodeState->uniqueAlias.c_str());
+ } else if (key == "ResetInactive") {
+ lua_pushcfunction(L, recordResetInactive);
+ } else {
+ return false;
+ }
+
+ return true;
+}
+
+bool Record::setNodeField(const Common::String &key) {
+ lua_State *L = getLua();
+
+ if (key == "active") {
+ if (lua_isfunction(L, 3)) {
+ lua_pushvalue(L, 3);
+ storeValue("active");
+ _hasActiveFunction = true;
+ } else {
+ setActiveFlags(lua_toboolean(L, 3) != 0);
+ _hasActiveFunction = false;
+ }
+ } else if (key == "z") {
+ const double z = luaL_checknumber(L, 3);
+ if (z != _z) {
+ _z = z;
+ onZChanged();
+ }
+ } else if (key == "keyZ") {
+ _nodeState->keyZ = luaL_checknumber(L, 3);
+ } else if (key == "localEnabled") {
+ _nodeState->localEnabled = lua_toboolean(L, 3) != 0;
+ } else if (key == "localVisible") {
+ _nodeState->localVisible = lua_toboolean(L, 3) != 0;
+ } else if (key == "localPaused") {
+ _nodeState->localPaused = lua_toboolean(L, 3) != 0;
+ } else if (key == "enabled" || key == "visible" || key == "paused" ||
+ key == "transform" || key == "invTransform" || key == "name" ||
+ key == "uniqueAlias" || key == "done") {
+ luaL_error(L, "Cannot set field '%s' of an AR", key.c_str());
+ } else {
+ return false;
+ }
+
+ return true;
+}
+
+// What the records under a node take on, which are the ones of the Transformer
+// that owns it. The owner counts the nodes above it in already.
+
+bool GraphNode::isEnabled() const {
+ if (_owner) {
+ return _owner->isNodeEnabled();
+ }
+
+ return !_parent || _parent->isEnabled();
+}
+
+bool GraphNode::isVisible() const {
+ if (_owner) {
+ return _owner->isNodeVisible();
+ }
+
+ return !_parent || _parent->isVisible();
+}
+
+bool GraphNode::isPaused() const {
+ if (_owner) {
+ return _owner->isNodePaused();
+ }
+
+ return _parent && _parent->isPaused();
+}
+
+} // End of namespace Script
+} // End of namespace Nancy
diff --git a/engines/nancy/script/v5/recordnode.h b/engines/nancy/script/v5/recordnode.h
new file mode 100644
index 00000000000..5a9d4ec4ba9
--- /dev/null
+++ b/engines/nancy/script/v5/recordnode.h
@@ -0,0 +1,49 @@
+/* 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 NANCY_SCRIPT_V5_RECORDNODE_H
+#define NANCY_SCRIPT_V5_RECORDNODE_H
+
+#include "common/str.h"
+
+namespace Nancy {
+namespace Script {
+
+// Nancy26 makes every record a node of a tree: it is enabled, visible and
+// paused by its own say and by what the Transformers above it say. Records of
+// the other games have none of this.
+struct RecordNodeState {
+ bool localEnabled = true;
+ bool localVisible = true;
+ bool localPaused = false;
+ double keyZ = 0.0;
+
+ Common::String localName;
+ Common::String uniqueAlias; // "AR<number>", which no other record has
+
+ // "active" stands for enabled, visible and not paused
+ bool isActive() const { return localEnabled && localVisible && !localPaused; }
+};
+
+} // End of namespace Script
+} // End of namespace Nancy
+
+#endif // NANCY_SCRIPT_V5_RECORDNODE_H
diff --git a/engines/nancy/script/xsheet.cpp b/engines/nancy/script/xsheet.cpp
index b8bc16b3345..231514b976c 100644
--- a/engines/nancy/script/xsheet.cpp
+++ b/engines/nancy/script/xsheet.cpp
@@ -304,7 +304,7 @@ void XsheetRecord::registerGraphics() {
void XsheetRecord::updateGraphics() {
_hasShown |= hasStarted();
- _xsheet.setVisible(isActive() && _hasShown);
+ _xsheet.setVisible(isShown() && _hasShown);
}
bool XsheetRecord::getField(const Common::String &key) {
Commit: a844e11dc6fa1035d51f7ccf7cee0ab315876325
https://github.com/scummvm/scummvm/commit/a844e11dc6fa1035d51f7ccf7cee0ab315876325
Author: Filippos Karapetis (bluegr at gmail.com)
Date: 2026-11-06T04:10:40+02:00
Commit Message:
NANCY: NANCY26: Let Transformers clip output from attached records
A Transformer can be given a "clip" rect in Nancy26. The records
attached to it are only drawn inside that rect, which is how the UI
shows a part of a longer list or text in a box.
Changed paths:
A engines/nancy/script/v5/cliptransformer.cpp
A engines/nancy/script/v5/cliptransformer.h
engines/nancy/graphics.cpp
engines/nancy/module.mk
engines/nancy/renderobject.cpp
engines/nancy/renderobject.h
engines/nancy/script/record.cpp
engines/nancy/script/record.h
engines/nancy/script/records.cpp
engines/nancy/script/v5/recordnode.cpp
diff --git a/engines/nancy/graphics.cpp b/engines/nancy/graphics.cpp
index 80a82ad94eb..a62058c40f5 100644
--- a/engines/nancy/graphics.cpp
+++ b/engines/nancy/graphics.cpp
@@ -284,6 +284,10 @@ void GraphicsManager::drawObjects(Graphics::ManagedSurface &target, const Common
DrawnObject entry;
entry.object = object;
entry.position = getDrawnPosition(*object);
+ if (!object->getClipRect().isEmpty()) {
+ entry.position.clip(object->getClipRect());
+ }
+
entry.isOpaque = !object->_drawSurface.hasTransparentColor() && object->_drawSurface.format != _transparentPixelFormat;
if (!entry.position.isEmpty()) {
drawn.push_back(entry);
diff --git a/engines/nancy/module.mk b/engines/nancy/module.mk
index 0cd60044e98..8cd54b46349 100644
--- a/engines/nancy/module.mk
+++ b/engines/nancy/module.mk
@@ -241,6 +241,7 @@ MODULE_OBJS += \
ifdef ENABLE_NANCY_V5
MODULE_OBJS += \
script/v5/bootobjects.o \
+ script/v5/cliptransformer.o \
script/v5/recordnode.o
endif
endif
diff --git a/engines/nancy/renderobject.cpp b/engines/nancy/renderobject.cpp
index 5281c06bb3c..c5e94df3cbb 100644
--- a/engines/nancy/renderobject.cpp
+++ b/engines/nancy/renderobject.cpp
@@ -99,6 +99,13 @@ void RenderObject::setTransparent(bool isTransparent) {
}
}
+void RenderObject::setClipRect(const Common::Rect &clip) {
+ if (clip != _clipRect) {
+ _clipRect = clip;
+ _needsRedraw = true;
+ }
+}
+
void RenderObject::grabPalette(byte *colors, uint paletteStart, uint paletteSize) {
if (colors) {
_drawSurface.grabPalette(colors, paletteStart, paletteSize);
diff --git a/engines/nancy/renderobject.h b/engines/nancy/renderobject.h
index 23bfdc70278..f815800b335 100644
--- a/engines/nancy/renderobject.h
+++ b/engines/nancy/renderobject.h
@@ -64,6 +64,10 @@ public:
void setTransparent(bool isTransparent);
bool isVisible() const { return _isVisible; }
+ // Nancy26: the part of the screen the object gets drawn in; empty for all of it
+ void setClipRect(const Common::Rect &clip);
+ const Common::Rect &getClipRect() const { return _clipRect; }
+
// Where on the screen the object was the last time it got drawn; empty when it
// wasn't shown. The viewport can scroll since, which moves where the object
// would be now, but not what is on the screen.
@@ -122,6 +126,7 @@ protected:
Common::Rect _drawnScreenPosition;
Common::Rect _previousScreenPosition;
Common::Rect _screenPosition;
+ Common::Rect _clipRect;
const ViewTransform *_viewTransform = nullptr;
};
diff --git a/engines/nancy/script/record.cpp b/engines/nancy/script/record.cpp
index c4c34d43033..aa3847e06c2 100644
--- a/engines/nancy/script/record.cpp
+++ b/engines/nancy/script/record.cpp
@@ -76,6 +76,10 @@ bool Record::isActive() const {
bool Record::isShown() const {
return isActive();
}
+
+Common::Rect Record::getScreenClip() const {
+ return Common::Rect();
+}
#endif
void Record::onStagesChanged() {
diff --git a/engines/nancy/script/record.h b/engines/nancy/script/record.h
index 2d76c0d9c0d..9a853f8ce02 100644
--- a/engines/nancy/script/record.h
+++ b/engines/nancy/script/record.h
@@ -173,6 +173,10 @@ public:
// on, while it is active before
bool isShown() const;
+ // Nancy26: the part of the screen the Transformers the record is under let it
+ // draw in; empty for all of it
+ Common::Rect getScreenClip() const;
+
// The blend stages of the record, which Nancy22 has in Transformers
BlendStages &getStages();
virtual void onStagesChanged();
diff --git a/engines/nancy/script/records.cpp b/engines/nancy/script/records.cpp
index 1535cb0d7fa..f4816846e3f 100644
--- a/engines/nancy/script/records.cpp
+++ b/engines/nancy/script/records.cpp
@@ -47,6 +47,10 @@
#include "engines/nancy/script/types.h"
#include "engines/nancy/script/xsheet.h"
+#ifdef ENABLE_NANCY_V5
+#include "engines/nancy/script/v5/cliptransformer.h"
+#endif
+
#include "engines/nancy/state/scene.h"
#include "engines/nancy/ui/viewport.h"
@@ -115,6 +119,12 @@ Record *makeRecord(RecordKind kind, SceneContext &context) {
case kRecordXsheet:
return new XsheetRecord(context);
case kRecordTransformer:
+#ifdef ENABLE_NANCY_V5
+ if (g_nancy->getGameType() >= kGameTypeNancy26) {
+ return new ClipTransformerRecord(context);
+ }
+#endif
+
return new TransformerRecord(context);
case kRecordTimer:
return new TimerRecord(context);
@@ -1295,6 +1305,7 @@ void OverlayRecord::updateGraphics() {
applyRects();
}
+ _graphic.setClipRect(getScreenClip());
_graphic.setVisible(isShown() && _hasPicture);
if (_hasAttachment) {
@@ -1617,6 +1628,7 @@ void AnimOverlayRecord::registerGraphics() {
}
void AnimOverlayRecord::updateGraphics() {
+ _graphic.setClipRect(getScreenClip());
_graphic.setVisible(isShown() && _isVisible && _hasPicture);
}
@@ -2382,6 +2394,7 @@ void MovieRecord::onZChanged() {
}
void MovieRecord::updateGraphics() {
+ _graphic.setClipRect(getScreenClip());
_graphic.setVisible(isShown() && _isVisible && !isSeeThrough());
}
diff --git a/engines/nancy/script/v5/cliptransformer.cpp b/engines/nancy/script/v5/cliptransformer.cpp
new file mode 100644
index 00000000000..238419f1947
--- /dev/null
+++ b/engines/nancy/script/v5/cliptransformer.cpp
@@ -0,0 +1,70 @@
+/* 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 "engines/nancy/script/graphnode.h"
+#include "engines/nancy/script/luabind.h"
+
+#include "engines/nancy/script/v5/cliptransformer.h"
+
+namespace Nancy {
+namespace Script {
+
+void ClipTransformerRecord::readTable(int tableIndex) {
+ TransformerRecord::readTable(tableIndex);
+ lua_State *L = getLua();
+
+ if (pushField(L, tableIndex, "clip")) {
+ _clip = checkRect(L, -1);
+ _hasClip = true;
+ lua_pop(L, 1);
+ }
+}
+
+bool ClipTransformerRecord::getField(const Common::String &key) {
+ if (key == "clip") {
+ if (_hasClip) {
+ pushRect(getLua(), _clip);
+ } else {
+ lua_pushnil(getLua());
+ }
+
+ return true;
+ }
+
+ return TransformerRecord::getField(key);
+}
+
+bool ClipTransformerRecord::setField(const Common::String &key) {
+ if (key != "clip") {
+ return TransformerRecord::setField(key);
+ }
+
+ lua_State *L = getLua();
+ _hasClip = !lua_isnil(L, 3);
+ if (_hasClip) {
+ _clip = checkRect(L, 3);
+ }
+
+ return true;
+}
+
+} // End of namespace Script
+} // End of namespace Nancy
diff --git a/engines/nancy/script/v5/cliptransformer.h b/engines/nancy/script/v5/cliptransformer.h
new file mode 100644
index 00000000000..367b250f6c5
--- /dev/null
+++ b/engines/nancy/script/v5/cliptransformer.h
@@ -0,0 +1,55 @@
+/* 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 NANCY_SCRIPT_V5_CLIPTRANSFORMER_H
+#define NANCY_SCRIPT_V5_CLIPTRANSFORMER_H
+
+#include "engines/nancy/script/transformer.h"
+#include "engines/nancy/script/types.h"
+
+namespace Nancy {
+namespace Script {
+
+// Nancy26's Transformer, which cuts off what is attached to it at its "clip"
+// rect, a rect in its own coordinates.
+class ClipTransformerRecord : public TransformerRecord {
+public:
+ ClipTransformerRecord(SceneContext &context, const char *typeName = "ND.TransformerAR") :
+ TransformerRecord(context, typeName) {}
+
+ // Where what is attached gets cut off, in the coordinates of the
+ // Transformer; null for nowhere
+ const ScriptRect *getClip() const { return _hasClip ? &_clip : nullptr; }
+
+protected:
+ void readTable(int tableIndex) override;
+ bool getField(const Common::String &key) override;
+ bool setField(const Common::String &key) override;
+
+private:
+ bool _hasClip = false;
+ ScriptRect _clip;
+};
+
+} // End of namespace Script
+} // End of namespace Nancy
+
+#endif // NANCY_SCRIPT_V5_CLIPTRANSFORMER_H
diff --git a/engines/nancy/script/v5/recordnode.cpp b/engines/nancy/script/v5/recordnode.cpp
index 36c0a78c4cc..2567203c536 100644
--- a/engines/nancy/script/v5/recordnode.cpp
+++ b/engines/nancy/script/v5/recordnode.cpp
@@ -29,6 +29,7 @@
#include "engines/nancy/script/transformer.h"
#include "engines/nancy/script/types.h"
+#include "engines/nancy/script/v5/cliptransformer.h"
#include "engines/nancy/script/v5/recordnode.h"
namespace Nancy {
@@ -106,12 +107,47 @@ const Common::String &Record::getName() const {
}
// What the records draw with. The records of the other games are shown while
-// they are active.
+// they are active, and whole.
bool Record::isShown() const {
return _nodeState ? isNodeVisible() : isActive();
}
+Common::Rect Record::getScreenClip() const {
+ Common::Rect clip;
+ if (!_nodeState) {
+ return clip;
+ }
+
+ bool hasClip = false;
+ for (const GraphNode *node = _parentNode; node; node = node->getParent()) {
+ const ClipTransformerRecord *transformer = dynamic_cast<const ClipTransformerRecord *>(node->getOwner());
+ const ScriptRect *nodeClip = transformer ? transformer->getClip() : nullptr;
+ if (!nodeClip) {
+ continue;
+ }
+
+ // The rect is in the coordinates of the Transformer, which moves and
+ // resizes it onto the screen. A flip swaps its corners.
+ const ScriptRect moved = transformRect(*nodeClip, node->getTransform());
+ const Common::Rect area(MIN(moved.left, moved.right), MIN(moved.top, moved.bottom), MAX(moved.left, moved.right), MAX(moved.top, moved.bottom));
+
+ if (hasClip) {
+ clip.clip(area);
+ } else {
+ clip = area;
+ hasClip = true;
+ }
+
+ // Nothing is left to draw in, which an empty rect can't say
+ if (clip.isEmpty()) {
+ return Common::Rect(-1, -1, 0, 0);
+ }
+ }
+
+ return clip;
+}
+
static bool readOptionalBool(lua_State *L, int tableIndex, const char *name, bool &value) {
lua_getfield(L, tableIndex, name);
const bool isBool = lua_isboolean(L, -1);
Commit: 4e3be749446635dee52c501f9a0aa43b2bbd6944
https://github.com/scummvm/scummvm/commit/4e3be749446635dee52c501f9a0aa43b2bbd6944
Author: Filippos Karapetis (bluegr at gmail.com)
Date: 2026-11-06T04:10:42+02:00
Commit Message:
NANCY: NANCY26: Give every record blend stages and an alpha
In Nancy26, every record has the blend stages of the Transformers, and a
transform of its own that they make. A new kind of stage, PushAlpha,
fades a record, and the records attached to a Transformer fade along
with it.
Changed paths:
engines/nancy/script/graphnode.h
engines/nancy/script/record.cpp
engines/nancy/script/record.h
engines/nancy/script/records.cpp
engines/nancy/script/transformer.cpp
engines/nancy/script/transformer.h
engines/nancy/script/v5/cliptransformer.cpp
engines/nancy/script/v5/cliptransformer.h
engines/nancy/script/v5/recordnode.cpp
engines/nancy/script/v5/recordnode.h
diff --git a/engines/nancy/script/graphnode.h b/engines/nancy/script/graphnode.h
index 92a8335e4e5..00e73bffd22 100644
--- a/engines/nancy/script/graphnode.h
+++ b/engines/nancy/script/graphnode.h
@@ -56,6 +56,7 @@ public:
bool isEnabled() const;
bool isVisible() const;
bool isPaused() const;
+ double getAlpha() const;
#endif
// The node's own, which Nancy22's Transformer records set
diff --git a/engines/nancy/script/record.cpp b/engines/nancy/script/record.cpp
index aa3847e06c2..98c9acd3e33 100644
--- a/engines/nancy/script/record.cpp
+++ b/engines/nancy/script/record.cpp
@@ -80,10 +80,22 @@ bool Record::isShown() const {
Common::Rect Record::getScreenClip() const {
return Common::Rect();
}
-#endif
+
+uint32 Record::applyAlpha(uint32 modColor) const {
+ return modColor;
+}
+
+uint32 Record::takeModColor(uint32 modColor) {
+ return modColor;
+}
+
+bool Record::hasAlphaChanged() const {
+ return false;
+}
void Record::onStagesChanged() {
}
+#endif
BlendStages &Record::getStages() {
if (!_stages) {
diff --git a/engines/nancy/script/record.h b/engines/nancy/script/record.h
index 9a853f8ce02..cb3051e9b7b 100644
--- a/engines/nancy/script/record.h
+++ b/engines/nancy/script/record.h
@@ -177,7 +177,17 @@ public:
// draw in; empty for all of it
Common::Rect getScreenClip() const;
- // The blend stages of the record, which Nancy22 has in Transformers
+ // A color what the record draws gets multiplied with, made as see-through
+ // as the record is
+ uint32 applyAlpha(uint32 modColor) const;
+
+ // The same, for a picture that gets drawn now. Nancy26 draws it again once
+ // the record is made more or less see-through.
+ uint32 takeModColor(uint32 modColor);
+ bool hasAlphaChanged() const;
+
+ // The blend stages of the record: Nancy22 has them in Transformers, and
+ // Nancy26 in every record
BlendStages &getStages();
virtual void onStagesChanged();
@@ -186,13 +196,14 @@ public:
bool resetInactive();
// Nancy26: every record is a node of a tree, which can be enabled (gets the
- // player's input), visible (gets drawn) and paused (doesn't run). A record is
- // each of them when it says so itself, and the Transformers it is attached to
- // don't say otherwise. "active" stands for all three: enabled, visible and
- // not paused.
+ // player's input), visible (gets drawn) and paused (doesn't run), and can be
+ // see-through. A record is each of them when it says so itself, and the
+ // Transformers it is attached to don't say otherwise. "active" stands for
+ // all three: enabled, visible and not paused.
bool isNodeEnabled() const;
bool isNodeVisible() const;
bool isNodePaused() const;
+ double getAlpha() const;
void setLocalEnabled(bool isEnabled);
void setLocalVisible(bool isVisible);
void setLocalPaused(bool isPaused);
@@ -201,6 +212,9 @@ public:
// Nancy26: the order keys go to the records in, highest first
double getKeyZ() const;
+ // Nancy26: the record's own transform changed, by its stages or a script
+ virtual void onLocalTransformChanged();
+
// Nancy26: the name the record goes by of its own, and the one its
// messages come from
const Common::String &getUniqueAlias() const;
diff --git a/engines/nancy/script/records.cpp b/engines/nancy/script/records.cpp
index f4816846e3f..1862fe57e88 100644
--- a/engines/nancy/script/records.cpp
+++ b/engines/nancy/script/records.cpp
@@ -1252,18 +1252,19 @@ void OverlayRecord::applyRects() {
return;
}
+ const uint32 modColor = takeModColor(_modColor);
if (!_hasDestTable) {
- placePicture(_graphic, _image, source, _dest, getTransform(), _modColor);
+ placePicture(_graphic, _image, source, _dest, getTransform(), modColor);
return;
}
// The copies of the picture are drawn into one surface that covers them all
const ScriptMatrix transform = getTransform();
- const bool isKeyed = transform.isTranslation() && _modColor == kNoModColor;
+ const bool isKeyed = transform.isTranslation() && modColor == kNoModColor;
Common::Array<RecordGraphic> pictures(_tableDests.size());
Common::Rect area;
for (uint i = 0; i < _tableDests.size(); ++i) {
- placePicture(pictures[i], _image, source, _tableDests[i], transform, _modColor);
+ placePicture(pictures[i], _image, source, _tableDests[i], transform, modColor);
if (i == 0) {
area = pictures[i].getScreenPositionRaw();
} else {
@@ -1301,7 +1302,7 @@ void OverlayRecord::updateGraphics() {
}
}
- if (_isPlacementStale && isShown()) {
+ if ((_isPlacementStale || hasAlphaChanged()) && isShown()) {
applyRects();
}
@@ -1568,7 +1569,7 @@ void AnimOverlayRecord::applyFrame() {
return;
}
- placePicture(_graphic, _image, source, _dest, getTransform(), _modColor);
+ placePicture(_graphic, _image, source, _dest, getTransform(), takeModColor(_modColor));
}
// Starts over from the first frame
@@ -1628,6 +1629,10 @@ void AnimOverlayRecord::registerGraphics() {
}
void AnimOverlayRecord::updateGraphics() {
+ if (hasAlphaChanged() && isShown() && _hasPicture) {
+ applyFrame();
+ }
+
_graphic.setClipRect(getScreenClip());
_graphic.setVisible(isShown() && _isVisible && _hasPicture);
}
@@ -2242,7 +2247,7 @@ void MovieRecord::readTable(int tableIndex) {
// Scripts hide a movie that keeps playing with a color without any alpha
bool MovieRecord::isSeeThrough() const {
- return (_modColor >> 24) == 0;
+ return (applyAlpha(_modColor) >> 24) == 0;
}
void MovieRecord::drawFrame() {
@@ -2257,8 +2262,9 @@ void MovieRecord::applyPosition() {
const ScriptMatrix transform = getTransform();
const Common::Rect source = _source.toRect();
+ const uint32 modColor = takeModColor(_modColor);
- if (transform.isTranslation() && _modColor == kNoModColor) {
+ if (transform.isTranslation() && modColor == kNoModColor) {
Graphics::ManagedSurface &surface = _graphic._drawSurface;
if (surface.w != source.width() || surface.h != source.height() || !surface.getPixels()) {
surface.create(MAX<int>(source.width(), 1), MAX<int>(source.height(), 1), g_nancy->_graphics->getScreenPixelFormat());
@@ -2286,7 +2292,7 @@ void MovieRecord::applyPosition() {
Common::Rect clipped = source;
clipped.clip(Common::Rect(_frame.w, _frame.h));
- placePicture(_graphic, _frame, clipped, _dest, transform, _modColor);
+ placePicture(_graphic, _frame, clipped, _dest, transform, modColor);
}
void MovieRecord::runOnce() {
@@ -2394,6 +2400,10 @@ void MovieRecord::onZChanged() {
}
void MovieRecord::updateGraphics() {
+ if (hasAlphaChanged() && isShown()) {
+ applyPosition();
+ }
+
_graphic.setClipRect(getScreenClip());
_graphic.setVisible(isShown() && _isVisible && !isSeeThrough());
}
diff --git a/engines/nancy/script/transformer.cpp b/engines/nancy/script/transformer.cpp
index c013c979315..d9951829cea 100644
--- a/engines/nancy/script/transformer.cpp
+++ b/engines/nancy/script/transformer.cpp
@@ -53,9 +53,9 @@ BlendStages::Stage &BlendStages::checkStage(lua_State *L, int index) {
return *stage;
}
-// An angle, or x and y: a vector, a point, or two numbers
+// An angle or an alpha, or x and y: a vector, a point, or two numbers
void BlendStages::readValue(lua_State *L, int index, StageKind kind, double value[2]) {
- if (kind == kRotation) {
+ if (kind == kRotation || kind == kAlpha) {
value[0] = luaL_checknumber(L, index);
return;
}
@@ -96,13 +96,15 @@ ScriptMatrix BlendStages::makeMatrix(StageKind kind, const double value[2]) {
matrix.m[0][0] = value[0];
matrix.m[1][1] = value[1];
break;
+ case kAlpha:
+ break;
}
return matrix;
}
void BlendStages::pushValue(lua_State *L, const Stage &stage) {
- if (stage.kind == kRotation) {
+ if (stage.kind == kRotation || stage.kind == kAlpha) {
lua_pushnumber(L, stage.current[0]);
return;
}
@@ -172,13 +174,23 @@ bool BlendStages::advanceStage(Stage &stage, double seconds) {
void BlendStages::update() {
ScriptMatrix transform;
ScriptMatrix blendedTransform;
+ double alpha = 1.0;
+ bool hasAlpha = false;
+
for (const Stage &stage : _stages) {
- transform = transform * stage.matrix;
- blendedTransform = blendedTransform * stage.blended;
+ if (stage.kind == kAlpha) {
+ alpha *= stage.current[0];
+ hasAlpha = true;
+ } else {
+ transform = transform * stage.matrix;
+ blendedTransform = blendedTransform * stage.blended;
+ }
}
_transform = transform;
_blendedTransform = blendedTransform;
+ _alpha = alpha;
+ _hasAlpha = hasAlpha;
_owner.onStagesChanged();
}
@@ -196,7 +208,7 @@ bool BlendStages::advance(double seconds) {
return hasChanged;
}
-// ar:Push<Translation|Rotation|Scale>(name, value)
+// ar:Push<Translation|Rotation|Scale|Alpha>(name, value)
int BlendStages::push(lua_State *L, StageKind kind) {
const char *name = luaL_checkstring(L, 2);
if (findStage(name)) {
@@ -308,6 +320,10 @@ static int stagesPushScale(lua_State *L) {
return checkStages(L).push(L, BlendStages::kScale);
}
+static int stagesPushAlpha(lua_State *L) {
+ return checkStages(L).push(L, BlendStages::kAlpha);
+}
+
static int stagesBlend(lua_State *L) {
return checkStages(L).blend(L);
}
@@ -331,6 +347,7 @@ static const luaL_Reg kStageFunctions[] = {
{ "PushTranslation", stagesPushTranslation },
{ "PushRotation", stagesPushRotation },
{ "PushScale", stagesPushScale },
+ { "PushAlpha", stagesPushAlpha },
{ "RemoveAllStages", stagesRemoveAll },
{ nullptr, nullptr }
};
diff --git a/engines/nancy/script/transformer.h b/engines/nancy/script/transformer.h
index 5965c3af4f7..936d3599ae1 100644
--- a/engines/nancy/script/transformer.h
+++ b/engines/nancy/script/transformer.h
@@ -42,13 +42,15 @@ class GraphNode;
// it there over a time, slowly at the end unless the record said sinLerp = false.
// While a stage blends, a function "<stage>AffectLerp" of the record can bend the
// progress from 0 to 1, and "<stage>Done" gets called once it is there.
-// Nancy22 has them in Transformer records.
+// Nancy22 has them in Transformer records only; in Nancy26 every record has them,
+// and a stage can also make the record see-through.
class BlendStages {
public:
enum StageKind {
kTranslation,
kRotation,
- kScale
+ kScale,
+ kAlpha // Nancy26
};
BlendStages(Record &owner) : _owner(owner) {}
@@ -59,6 +61,10 @@ public:
const ScriptMatrix &getTransform() const { return _transform; }
const ScriptMatrix &getBlendedTransform() const { return _blendedTransform; }
+ // The product of the alpha stages; 1 without any
+ double getAlpha() const { return _alpha; }
+ bool hasAlpha() const { return _hasAlpha; }
+
void setSineLerp(bool isSineLerp) { _isSineLerp = isSineLerp; }
bool isSineLerp() const { return _isSineLerp; }
@@ -88,7 +94,7 @@ private:
Common::String name;
StageKind kind = kTranslation;
- // x and y; a rotation has its angle in x
+ // x and y; a rotation and an alpha have their value in x
double start[2] = { 0.0, 0.0 };
double current[2] = { 0.0, 0.0 };
double target[2] = { 0.0, 0.0 };
@@ -125,6 +131,8 @@ private:
double _timeMultiplier = 1.0; // Nancy24: how much faster the blends go
ScriptMatrix _transform;
ScriptMatrix _blendedTransform;
+ double _alpha = 1.0;
+ bool _hasAlpha = false;
};
// Nancy22 moves, turns and resizes what a scene shows with Transformer records.
diff --git a/engines/nancy/script/v5/cliptransformer.cpp b/engines/nancy/script/v5/cliptransformer.cpp
index 238419f1947..53843e00b0c 100644
--- a/engines/nancy/script/v5/cliptransformer.cpp
+++ b/engines/nancy/script/v5/cliptransformer.cpp
@@ -36,10 +36,26 @@ void ClipTransformerRecord::readTable(int tableIndex) {
_hasClip = true;
lua_pop(L, 1);
}
+
+ // The table can give the record a transform of its own
+ getNode()->setTransform(getLocalTransform());
+}
+
+// The record's own transform moves the node, which the stages make when there
+// are any. Every record moves its stages on by itself.
+void ClipTransformerRecord::onStagesChanged() {
+ Record::onStagesChanged();
+}
+
+void ClipTransformerRecord::onLocalTransformChanged() {
+ getNode()->setTransform(getLocalTransform());
}
+// What else a Transformer of the earlier games has, every record has here
bool ClipTransformerRecord::getField(const Common::String &key) {
- if (key == "clip") {
+ if (key == "Attach") {
+ return TransformerRecord::getField(key);
+ } else if (key == "clip") {
if (_hasClip) {
pushRect(getLua(), _clip);
} else {
@@ -49,12 +65,12 @@ bool ClipTransformerRecord::getField(const Common::String &key) {
return true;
}
- return TransformerRecord::getField(key);
+ return false;
}
bool ClipTransformerRecord::setField(const Common::String &key) {
if (key != "clip") {
- return TransformerRecord::setField(key);
+ return false;
}
lua_State *L = getLua();
diff --git a/engines/nancy/script/v5/cliptransformer.h b/engines/nancy/script/v5/cliptransformer.h
index 367b250f6c5..e8c73da160f 100644
--- a/engines/nancy/script/v5/cliptransformer.h
+++ b/engines/nancy/script/v5/cliptransformer.h
@@ -28,8 +28,10 @@
namespace Nancy {
namespace Script {
-// Nancy26's Transformer, which cuts off what is attached to it at its "clip"
-// rect, a rect in its own coordinates.
+// Nancy26's Transformer. Every record has blend stages and a transform of its
+// own by now, so what is left to it is to be the node the records attached to
+// it hang under. They take on whether it is enabled, visible and paused, and
+// how see-through it is, and get cut off at its "clip" rect.
class ClipTransformerRecord : public TransformerRecord {
public:
ClipTransformerRecord(SceneContext &context, const char *typeName = "ND.TransformerAR") :
@@ -39,8 +41,12 @@ public:
// Transformer; null for nowhere
const ScriptRect *getClip() const { return _hasClip ? &_clip : nullptr; }
+ void onStagesChanged() override;
+ void onLocalTransformChanged() override;
+
protected:
void readTable(int tableIndex) override;
+ void run(double sceneTime, double elapsedTime) override {}
bool getField(const Common::String &key) override;
bool setField(const Common::String &key) override;
diff --git a/engines/nancy/script/v5/recordnode.cpp b/engines/nancy/script/v5/recordnode.cpp
index 2567203c536..a9926550ced 100644
--- a/engines/nancy/script/v5/recordnode.cpp
+++ b/engines/nancy/script/v5/recordnode.cpp
@@ -76,6 +76,10 @@ bool Record::isNodePaused() const {
return _parentNode && _parentNode->isPaused();
}
+double Record::getAlpha() const {
+ return _parentNode ? _nodeState->localAlpha * _parentNode->getAlpha() : _nodeState->localAlpha;
+}
+
void Record::setLocalEnabled(bool isEnabled) {
_nodeState->localEnabled = isEnabled;
}
@@ -107,7 +111,7 @@ const Common::String &Record::getName() const {
}
// What the records draw with. The records of the other games are shown while
-// they are active, and whole.
+// they are active, whole and as they are.
bool Record::isShown() const {
return _nodeState ? isNodeVisible() : isActive();
@@ -148,6 +152,52 @@ Common::Rect Record::getScreenClip() const {
return clip;
}
+uint32 Record::applyAlpha(uint32 modColor) const {
+ if (!_nodeState) {
+ return modColor;
+ }
+
+ const double alpha = getAlpha();
+ if (alpha >= 1.0) {
+ return modColor;
+ }
+
+ const uint32 a = (uint32)CLIP<double>((modColor >> 24) * alpha + 0.5, 0.0, 255.0);
+ return (a << 24) | (modColor & 0xFFFFFF);
+}
+
+uint32 Record::takeModColor(uint32 modColor) {
+ if (_nodeState) {
+ _nodeState->drawnAlpha = getAlpha();
+ }
+
+ return applyAlpha(modColor);
+}
+
+bool Record::hasAlphaChanged() const {
+ return _nodeState && getAlpha() != _nodeState->drawnAlpha;
+}
+
+// Nancy26's records take their own transform and alpha from their stages
+void Record::onStagesChanged() {
+ if (!_nodeState || !_stages) {
+ return;
+ }
+
+ _transform = _stages->getTransform();
+ if (_stages->hasAlpha()) {
+ _nodeState->localAlpha = _stages->getAlpha();
+ }
+
+ onLocalTransformChanged();
+}
+
+void Record::onLocalTransformChanged() {
+ if (hasTransform()) {
+ onTransformChanged();
+ }
+}
+
static bool readOptionalBool(lua_State *L, int tableIndex, const char *name, bool &value) {
lua_getfield(L, tableIndex, name);
const bool isBool = lua_isboolean(L, -1);
@@ -178,6 +228,7 @@ void Record::readNodeFields(int tableIndex) {
readOptionalBool(L, tableIndex, "localEnabled", _nodeState->localEnabled);
readOptionalBool(L, tableIndex, "localVisible", _nodeState->localVisible);
readOptionalBool(L, tableIndex, "localPaused", _nodeState->localPaused);
+ readOptionalNumber(L, tableIndex, "localAlpha", _nodeState->localAlpha);
readOptionalNumber(L, tableIndex, "keyZ", _nodeState->keyZ);
lua_getfield(L, tableIndex, "localName");
@@ -186,6 +237,16 @@ void Record::readNodeFields(int tableIndex) {
}
lua_pop(L, 1);
+
+ bool isSineLerp = true;
+ if (readOptionalBool(L, tableIndex, "sinLerp", isSineLerp)) {
+ getStages().setSineLerp(isSineLerp);
+ }
+
+ if (pushField(L, tableIndex, "localTransform")) {
+ _transform = checkMatrix(L, -1);
+ lua_pop(L, 1);
+ }
}
// An "active" function sets all three flags every frame. The record gets
@@ -239,6 +300,10 @@ void Record::updateNode(double sceneTime, double elapsedTime) {
callFunction("RunOnce");
}
+ if (_stages) {
+ _stages->advance(elapsedTime);
+ }
+
if (isScripted()) {
lua_pushnumber(L, sceneTime);
lua_pushnumber(L, elapsedTime);
@@ -304,6 +369,10 @@ bool Record::getNodeField(const Common::String &key) {
lua_pushnumber(L, _z);
} else if (key == "keyZ") {
lua_pushnumber(L, _nodeState->keyZ);
+ } else if (key == "alpha") {
+ lua_pushnumber(L, getAlpha());
+ } else if (key == "localAlpha") {
+ lua_pushnumber(L, _nodeState->localAlpha);
} else if (key == "enabled") {
lua_pushboolean(L, isNodeEnabled());
} else if (key == "visible") {
@@ -320,12 +389,22 @@ bool Record::getNodeField(const Common::String &key) {
pushMatrix(L, getTransform());
} else if (key == "invTransform") {
pushMatrix(L, getTransform().inverse());
+ } else if (key == "localTransform") {
+ pushMatrix(L, getLocalTransform());
+ } else if (key == "localInvTransform") {
+ pushMatrix(L, getLocalTransform().inverse());
+ } else if (key == "blendedTransform") {
+ pushMatrix(L, _stages ? _stages->getBlendedTransform() : getLocalTransform());
} else if (key == "name") {
lua_pushstring(L, getName().c_str());
} else if (key == "uniqueAlias") {
lua_pushstring(L, _nodeState->uniqueAlias.c_str());
} else if (key == "ResetInactive") {
lua_pushcfunction(L, recordResetInactive);
+ } else if (BlendStages::pushFunction(L, key)) {
+ return true;
+ } else if (_stages && _stages->getField(L, key)) {
+ return true;
} else {
return false;
}
@@ -353,15 +432,29 @@ bool Record::setNodeField(const Common::String &key) {
}
} else if (key == "keyZ") {
_nodeState->keyZ = luaL_checknumber(L, 3);
+ } else if (key == "localAlpha") {
+ _nodeState->localAlpha = luaL_checknumber(L, 3);
} else if (key == "localEnabled") {
_nodeState->localEnabled = lua_toboolean(L, 3) != 0;
} else if (key == "localVisible") {
_nodeState->localVisible = lua_toboolean(L, 3) != 0;
} else if (key == "localPaused") {
_nodeState->localPaused = lua_toboolean(L, 3) != 0;
- } else if (key == "enabled" || key == "visible" || key == "paused" ||
- key == "transform" || key == "invTransform" || key == "name" ||
- key == "uniqueAlias" || key == "done") {
+ } else if (key == "localTransform") {
+ if (_stages && !_stages->isEmpty()) {
+ luaL_error(L, "Cannot set the localTransform of an AR that has stages");
+ }
+
+ const ScriptMatrix &transform = checkMatrix(L, 3);
+ if (transform != _transform) {
+ _transform = transform;
+ onLocalTransformChanged();
+ }
+ } else if (_stages && _stages->setField(L, key)) {
+ return true;
+ } else if (key == "enabled" || key == "visible" || key == "paused" || key == "alpha" ||
+ key == "transform" || key == "invTransform" || key == "localInvTransform" ||
+ key == "blendedTransform" || key == "name" || key == "uniqueAlias" || key == "done") {
luaL_error(L, "Cannot set field '%s' of an AR", key.c_str());
} else {
return false;
@@ -397,5 +490,13 @@ bool GraphNode::isPaused() const {
return _parent && _parent->isPaused();
}
+double GraphNode::getAlpha() const {
+ if (_owner) {
+ return _owner->getAlpha();
+ }
+
+ return _parent ? _parent->getAlpha() : 1.0;
+}
+
} // End of namespace Script
} // End of namespace Nancy
diff --git a/engines/nancy/script/v5/recordnode.h b/engines/nancy/script/v5/recordnode.h
index 5a9d4ec4ba9..6e6218b94d6 100644
--- a/engines/nancy/script/v5/recordnode.h
+++ b/engines/nancy/script/v5/recordnode.h
@@ -28,12 +28,14 @@ namespace Nancy {
namespace Script {
// Nancy26 makes every record a node of a tree: it is enabled, visible and
-// paused by its own say and by what the Transformers above it say. Records of
-// the other games have none of this.
+// paused by its own say and by what the Transformers above it say, and can be
+// see-through. Records of the other games have none of this.
struct RecordNodeState {
bool localEnabled = true;
bool localVisible = true;
bool localPaused = false;
+ double localAlpha = 1.0;
+ double drawnAlpha = 1.0; // what the picture was last drawn with
double keyZ = 0.0;
Common::String localName;
Commit: 1e1aa2d8fdfff3de55fb6ff3f3ead5703cd7e361
https://github.com/scummvm/scummvm/commit/1e1aa2d8fdfff3de55fb6ff3f3ead5703cd7e361
Author: Filippos Karapetis (bluegr at gmail.com)
Date: 2026-11-06T04:10:43+02:00
Commit Message:
NANCY: NANCY26: Let records and streams exchange messages
Nancy26's records take names with RegisterAlias(), and records in any
scene send them messages with Send(), which calls their Receive()
function and returns what it returns. The values that go along are
copied from the Lua state of one scene to the one of the other.
Every record also enables, disables, shows, hides, plays and pauses
itself on a message, and a stream does the same, and can be locked,
for all the records of its scenes.
Changed paths:
A engines/nancy/script/v5/messaging.cpp
A engines/nancy/script/v5/messaging.h
A engines/nancy/script/v5/streamtree.cpp
A engines/nancy/script/v5/streamtree.h
engines/nancy/module.mk
engines/nancy/script/record.h
engines/nancy/script/scenecontext.cpp
engines/nancy/script/scenecontext.h
engines/nancy/script/v5/recordnode.cpp
engines/nancy/script/v5/recordnode.h
engines/nancy/state/scenestream.h
diff --git a/engines/nancy/module.mk b/engines/nancy/module.mk
index 8cd54b46349..daa5f942841 100644
--- a/engines/nancy/module.mk
+++ b/engines/nancy/module.mk
@@ -242,7 +242,9 @@ ifdef ENABLE_NANCY_V5
MODULE_OBJS += \
script/v5/bootobjects.o \
script/v5/cliptransformer.o \
- script/v5/recordnode.o
+ script/v5/messaging.o \
+ script/v5/recordnode.o \
+ script/v5/streamtree.o
endif
endif
diff --git a/engines/nancy/script/record.h b/engines/nancy/script/record.h
index cb3051e9b7b..0a8599fd155 100644
--- a/engines/nancy/script/record.h
+++ b/engines/nancy/script/record.h
@@ -219,6 +219,11 @@ public:
// messages come from
const Common::String &getUniqueAlias() const;
const Common::String &getName() const;
+
+ // Nancy26: a message another record sent, from the Lua state L, with numArgs
+ // arguments from firstArg on. Leaves what the record's Receive function
+ // returned on the stack of L, and returns how many values that is.
+ int receiveMessage(lua_State *L, const Common::String &sender, const Common::String &action, int firstArg, int numArgs);
#endif
// Nancy21: puts the record under a node; null for none
diff --git a/engines/nancy/script/scenecontext.cpp b/engines/nancy/script/scenecontext.cpp
index 591a453492a..7c5be5a02eb 100644
--- a/engines/nancy/script/scenecontext.cpp
+++ b/engines/nancy/script/scenecontext.cpp
@@ -52,6 +52,12 @@ SceneContext::SceneContext(const Common::String &streamName, const Common::Strin
_sceneName(sceneName),
_frame(frame),
_zOffset(zOffset) {
+#ifdef ENABLE_NANCY_V5
+ if (g_nancy->getGameType() >= kGameTypeNancy26) {
+ _streamState = NancySceneState.getStreams().getNodeState(streamName);
+ }
+#endif
+
_lua = new LuaState(this);
}
diff --git a/engines/nancy/script/scenecontext.h b/engines/nancy/script/scenecontext.h
index 6b621e093b2..dec0ba3bb0b 100644
--- a/engines/nancy/script/scenecontext.h
+++ b/engines/nancy/script/scenecontext.h
@@ -29,6 +29,10 @@
#include "engines/nancy/script/types.h"
+#ifdef ENABLE_NANCY_V5
+#include "engines/nancy/script/v5/streamtree.h"
+#endif
+
struct lua_State;
namespace Nancy {
@@ -112,6 +116,13 @@ public:
void setFrame(uint frame) { _frame = frame; }
int32 getZOffset() const { return _zOffset; }
+#ifdef ENABLE_NANCY_V5
+ // Nancy26: what the stream of the scene says about all its records
+ bool isStreamEnabled() const { return !_streamState || _streamState->isEnabled; }
+ bool isStreamVisible() const { return !_streamState || _streamState->isVisible; }
+ bool isStreamPaused() const { return _streamState && _streamState->isPaused; }
+#endif
+
// Nancy21: the zoom of the stream the scene is in
const ViewTransform *getViewTransform() const;
@@ -190,6 +201,10 @@ private:
uint _frame;
int32 _zOffset;
+#ifdef ENABLE_NANCY_V5
+ const StreamNodeState *_streamState = nullptr; // Nancy26
+#endif
+
LuaState *_lua;
Common::Array<Record *> _records;
Common::Array<Record *> _newRecords;
diff --git a/engines/nancy/script/v5/messaging.cpp b/engines/nancy/script/v5/messaging.cpp
new file mode 100644
index 00000000000..a2630d98476
--- /dev/null
+++ b/engines/nancy/script/v5/messaging.cpp
@@ -0,0 +1,204 @@
+/* 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 "common/hash-str.h"
+
+#include "engines/nancy/nancy.h"
+#include "engines/nancy/state/scene.h"
+
+#include "engines/nancy/script/luabind.h"
+#include "engines/nancy/script/mathtypes.h"
+#include "engines/nancy/script/record.h"
+#include "engines/nancy/script/scenecontext.h"
+#include "engines/nancy/script/types.h"
+
+#include "engines/nancy/script/v5/messaging.h"
+
+namespace Nancy {
+namespace Script {
+
+typedef Common::HashMap<Common::String, Record *, Common::IgnoreCase_Hash, Common::IgnoreCase_EqualTo> AliasMap;
+
+// The names are shared by the scenes of all the streams
+static AliasMap &getAliases() {
+ static AliasMap s_aliases;
+ return s_aliases;
+}
+
+bool registerAlias(const Common::String &alias, Record *record) {
+ AliasMap &aliases = getAliases();
+ AliasMap::iterator it = aliases.find(alias);
+ if (it != aliases.end() && it->_value != record) {
+ // The scene a stream goes to is loaded while the one it leaves is still
+ // around, and its records take over the names the old ones had
+ const SceneContext &holder = it->_value->getContext();
+ const SceneContext &taker = record->getContext();
+ if (&holder == &taker || !holder.getStreamName().equalsIgnoreCase(taker.getStreamName())) {
+ return false;
+ }
+ }
+
+ aliases.setVal(alias, record);
+ return true;
+}
+
+void deregisterAlias(const Common::String &alias, Record *record) {
+ AliasMap &aliases = getAliases();
+ AliasMap::iterator it = aliases.find(alias);
+ if (it != aliases.end() && it->_value == record) {
+ aliases.erase(it);
+ }
+}
+
+void deregisterAliases(Record *record) {
+ AliasMap &aliases = getAliases();
+ Common::Array<Common::String> names;
+ for (AliasMap::iterator it = aliases.begin(); it != aliases.end(); ++it) {
+ if (it->_value == record) {
+ names.push_back(it->_key);
+ }
+ }
+
+ for (const Common::String &name : names) {
+ aliases.erase(name);
+ }
+}
+
+Record *findAlias(const Common::String &alias) {
+ AliasMap &aliases = getAliases();
+ AliasMap::iterator it = aliases.find(alias);
+ return it != aliases.end() ? it->_value : nullptr;
+}
+
+// What the exe copies: numbers, texts, booleans and nil as they are, tables
+// with everything in them, and the math types. Anything else turns into nil.
+void copyValue(lua_State *from, int index, lua_State *to) {
+ index = absoluteIndex(from, index);
+
+ switch (lua_type(from, index)) {
+ case LUA_TNUMBER:
+ lua_pushnumber(to, lua_tonumber(from, index));
+ return;
+ case LUA_TSTRING: {
+ size_t length = 0;
+ const char *text = lua_tolstring(from, index, &length);
+ lua_pushlstring(to, text, length);
+ return;
+ }
+ case LUA_TBOOLEAN:
+ lua_pushboolean(to, lua_toboolean(from, index));
+ return;
+ case LUA_TTABLE:
+ lua_newtable(to);
+ lua_pushnil(from);
+ while (lua_next(from, index)) {
+ copyValue(from, -2, to);
+ copyValue(from, -1, to);
+ lua_rawset(to, -3);
+ lua_pop(from, 1);
+ }
+
+ return;
+ default:
+ break;
+ }
+
+ const ScriptRect *rect = testRect(from, index);
+ if (rect) {
+ pushRect(to, *rect);
+ return;
+ }
+
+ const uint32 *color = testColor(from, index);
+ if (color) {
+ pushColor(to, *color);
+ return;
+ }
+
+ const ScriptMatrix *matrix = testMatrix(from, index);
+ if (matrix) {
+ pushMatrix(to, *matrix);
+ return;
+ }
+
+ const ScriptVector *vector = testVector(from, index);
+ if (vector) {
+ pushVector(to, *vector);
+ return;
+ }
+
+ ScriptPoint point;
+ if (lua_isuserdata(from, index) && readPoint(from, index, point)) {
+ pushPoint(to, point);
+ return;
+ }
+
+ lua_pushnil(to);
+}
+
+int sendMessage(lua_State *L, const Common::String &sender, const Common::String &recipient,
+ const Common::String &action, int firstArg, int numArgs) {
+ Record *record = findAlias(recipient);
+ if (record) {
+ return record->receiveMessage(L, sender, action, firstArg, numArgs);
+ }
+
+ // Streams go by their names as well
+ return NancySceneState.getStreams().receiveNancy26Message(L, sender, recipient, action);
+}
+
+// ar:Send(recipient, action, ...) and ar:TrySend(...), which return what the
+// receiver returns
+int recordSend(lua_State *L) {
+ Record *record = checkRecord(L, 1);
+ const Common::String recipient = luaL_checkstring(L, 2);
+ const Common::String action = luaL_checkstring(L, 3);
+
+ const int top = lua_gettop(L);
+ const int numResults = sendMessage(L, record->getName(), recipient, action, 4, MAX(0, top - 3));
+ return numResults;
+}
+
+// ar:SendAsAlias(alias, recipient, action, ...) sends in the name of another
+int recordSendAsAlias(lua_State *L) {
+ checkRecord(L, 1);
+ const Common::String alias = luaL_checkstring(L, 2);
+ const Common::String recipient = luaL_checkstring(L, 3);
+ const Common::String action = luaL_checkstring(L, 4);
+
+ const int top = lua_gettop(L);
+ return sendMessage(L, alias, recipient, action, 5, MAX(0, top - 4));
+}
+
+// ar:RegisterAlias(name), which returns whether the name was free
+int recordRegisterAlias(lua_State *L) {
+ Record *record = checkRecord(L, 1);
+ lua_pushboolean(L, registerAlias(luaL_checkstring(L, 2), record));
+ return 1;
+}
+
+int recordDeregisterAlias(lua_State *L) {
+ deregisterAlias(luaL_checkstring(L, 2), checkRecord(L, 1));
+ return 0;
+}
+
+} // End of namespace Script
+} // End of namespace Nancy
diff --git a/engines/nancy/script/v5/messaging.h b/engines/nancy/script/v5/messaging.h
new file mode 100644
index 00000000000..863eca3a2dd
--- /dev/null
+++ b/engines/nancy/script/v5/messaging.h
@@ -0,0 +1,75 @@
+/* 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 NANCY_SCRIPT_V5_MESSAGING_H
+#define NANCY_SCRIPT_V5_MESSAGING_H
+
+#include "common/str.h"
+
+struct lua_State;
+
+namespace Nancy {
+namespace Script {
+
+class Record;
+
+// Nancy26's records talk to each other by name. A record takes names with
+// RegisterAlias(), and other records, in any scene, send it messages:
+//
+// themeManager:RegisterAlias("ThemeManager")
+// ar:Send("ThemeManager", "Stop") -- calls themeManager:Receive(sender, "Stop")
+// local photos = ar:Send("PhotoManager", "Get", "camera")
+//
+// Whatever goes along with a message, and whatever comes back from it, is copied
+// from the Lua state of one scene to the one of the other: numbers, texts,
+// booleans, tables and the math types. Every record also answers "Enable",
+// "Disable", "Show", "Hide", "Play" and "Pause" by itself, before its Receive
+// function gets them. A stream answers messages sent to its name.
+
+// Returns false when the name is taken by another record
+bool registerAlias(const Common::String &alias, Record *record);
+void deregisterAlias(const Common::String &alias, Record *record);
+
+// Every name of a record that is going away
+void deregisterAliases(Record *record);
+
+// The record that goes by a name; null for none
+Record *findAlias(const Common::String &alias);
+
+// Sends a message from the state L, whose numArgs arguments start at firstArg,
+// and leaves what the receiver returned on the stack of L. Returns the number of
+// results, which is 0 when nobody goes by the name.
+int sendMessage(lua_State *L, const Common::String &sender, const Common::String &recipient,
+ const Common::String &action, int firstArg, int numArgs);
+
+// Copies the value at an index of one state onto the stack of another
+void copyValue(lua_State *from, int index, lua_State *to);
+
+// The functions records have for messages
+int recordSend(lua_State *L);
+int recordSendAsAlias(lua_State *L);
+int recordRegisterAlias(lua_State *L);
+int recordDeregisterAlias(lua_State *L);
+
+} // End of namespace Script
+} // End of namespace Nancy
+
+#endif // NANCY_SCRIPT_V5_MESSAGING_H
diff --git a/engines/nancy/script/v5/recordnode.cpp b/engines/nancy/script/v5/recordnode.cpp
index a9926550ced..9024437aa7d 100644
--- a/engines/nancy/script/v5/recordnode.cpp
+++ b/engines/nancy/script/v5/recordnode.cpp
@@ -30,6 +30,7 @@
#include "engines/nancy/script/types.h"
#include "engines/nancy/script/v5/cliptransformer.h"
+#include "engines/nancy/script/v5/messaging.h"
#include "engines/nancy/script/v5/recordnode.h"
namespace Nancy {
@@ -48,12 +49,13 @@ void Record::destroyNodeState() {
return;
}
+ deregisterAliases(this);
delete _nodeState;
_nodeState = nullptr;
}
bool Record::isNodeEnabled() const {
- if (!_nodeState->localEnabled) {
+ if (!_nodeState->localEnabled || !_context.isStreamEnabled()) {
return false;
}
@@ -61,7 +63,7 @@ bool Record::isNodeEnabled() const {
}
bool Record::isNodeVisible() const {
- if (!_nodeState->localVisible) {
+ if (!_nodeState->localVisible || !_context.isStreamVisible()) {
return false;
}
@@ -69,7 +71,7 @@ bool Record::isNodeVisible() const {
}
bool Record::isNodePaused() const {
- if (_nodeState->localPaused) {
+ if (_nodeState->localPaused || _context.isStreamPaused()) {
return true;
}
@@ -327,6 +329,61 @@ bool Record::resetInactive() {
return true;
}
+int Record::receiveMessage(lua_State *from, const Common::String &sender, const Common::String &action, int firstArg, int numArgs) {
+ // Every record answers these by itself first
+ Common::String upperAction = action;
+ upperAction.toUppercase();
+ if (upperAction == "ENABLE") {
+ _nodeState->localEnabled = true;
+ } else if (upperAction == "DISABLE") {
+ _nodeState->localEnabled = false;
+ } else if (upperAction == "SHOW") {
+ _nodeState->localVisible = true;
+ } else if (upperAction == "HIDE") {
+ _nodeState->localVisible = false;
+ } else if (upperAction == "PLAY") {
+ _nodeState->localPaused = false;
+ } else if (upperAction == "PAUSE") {
+ _nodeState->localPaused = true;
+ }
+
+ lua_State *L = getLua();
+ firstArg = absoluteIndex(from, firstArg);
+
+ pushStoredValue("Receive");
+ if (!lua_isfunction(L, -1)) {
+ lua_pop(L, 1);
+ return 0;
+ }
+
+ const int base = lua_gettop(L) - 1;
+ push();
+ lua_pushstring(L, sender.c_str());
+ lua_pushstring(L, action.c_str());
+ for (int i = 0; i < numArgs; ++i) {
+ if (L == from) {
+ lua_pushvalue(L, firstArg + i);
+ } else {
+ copyValue(from, firstArg + i, L);
+ }
+ }
+
+ if (!LuaState::call(L, numArgs + 3, LUA_MULTRET, "Error running override 'Receive' of AR")) {
+ return 0;
+ }
+
+ const int numResults = lua_gettop(L) - base;
+ if (L != from) {
+ for (int i = 0; i < numResults; ++i) {
+ copyValue(L, base + 1 + i, from);
+ }
+
+ lua_settop(L, base);
+ }
+
+ return numResults;
+}
+
// ar:ResetInactive()
static int recordResetInactive(lua_State *L) {
if (!checkRecord(L, 1)->resetInactive()) {
@@ -399,6 +456,14 @@ bool Record::getNodeField(const Common::String &key) {
lua_pushstring(L, getName().c_str());
} else if (key == "uniqueAlias") {
lua_pushstring(L, _nodeState->uniqueAlias.c_str());
+ } else if (key == "Send" || key == "TrySend") {
+ lua_pushcfunction(L, recordSend);
+ } else if (key == "SendAsAlias" || key == "TrySendAsAlias") {
+ lua_pushcfunction(L, recordSendAsAlias);
+ } else if (key == "RegisterAlias") {
+ lua_pushcfunction(L, recordRegisterAlias);
+ } else if (key == "DeregisterAlias") {
+ lua_pushcfunction(L, recordDeregisterAlias);
} else if (key == "ResetInactive") {
lua_pushcfunction(L, recordResetInactive);
} else if (BlendStages::pushFunction(L, key)) {
diff --git a/engines/nancy/script/v5/recordnode.h b/engines/nancy/script/v5/recordnode.h
index 6e6218b94d6..488b7e412cf 100644
--- a/engines/nancy/script/v5/recordnode.h
+++ b/engines/nancy/script/v5/recordnode.h
@@ -29,7 +29,8 @@ namespace Script {
// Nancy26 makes every record a node of a tree: it is enabled, visible and
// paused by its own say and by what the Transformers above it say, and can be
-// see-through. Records of the other games have none of this.
+// see-through. Messages reach it by its names. Records of the other games
+// have none of this.
struct RecordNodeState {
bool localEnabled = true;
bool localVisible = true;
diff --git a/engines/nancy/script/v5/streamtree.cpp b/engines/nancy/script/v5/streamtree.cpp
new file mode 100644
index 00000000000..4e493972c36
--- /dev/null
+++ b/engines/nancy/script/v5/streamtree.cpp
@@ -0,0 +1,82 @@
+/* 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 "common/algorithm.h"
+#include "common/debug.h"
+
+#include "engines/nancy/nancy.h"
+
+#include "engines/nancy/script/graphnode.h"
+#include "engines/nancy/script/luabind.h"
+#include "engines/nancy/script/record.h"
+#include "engines/nancy/script/records.h"
+#include "engines/nancy/script/scenecontext.h"
+
+#include "engines/nancy/script/v5/streamtree.h"
+
+#include "engines/nancy/state/scene.h"
+#include "engines/nancy/state/scenestream.h"
+
+namespace Nancy {
+namespace State {
+
+Script::StreamNodeState *SceneStreamManager::getNodeState(const Common::String &name) {
+ if (name.equalsIgnoreCase(getMainStreamName())) {
+ return &_mainNodeState;
+ }
+
+ SceneStream *stream = find(name);
+ return stream ? &stream->getNodeState() : nullptr;
+}
+
+int SceneStreamManager::receiveNancy26Message(lua_State *L, const Common::String &sender, const Common::String &name, const Common::String &action) {
+ Script::StreamNodeState *state = getNodeState(name);
+ if (!state) {
+ return 0;
+ }
+
+ Common::String upperAction = action;
+ upperAction.toUppercase();
+ if (upperAction == "ENABLE") {
+ state->isEnabled = true;
+ } else if (upperAction == "DISABLE") {
+ state->isEnabled = false;
+ } else if (upperAction == "PLAY") {
+ state->isPaused = false;
+ } else if (upperAction == "PAUSE") {
+ state->isPaused = true;
+ } else if (upperAction == "LOCK") {
+ state->isPaused = true;
+ state->isEnabled = false;
+ } else if (upperAction == "UNLOCK") {
+ state->isPaused = false;
+ state->isEnabled = true;
+ } else if (upperAction == "ISPAUSED") {
+ lua_pushboolean(L, state->isPaused);
+ return 1;
+ }
+
+ debugC(1, kDebugScene, "%s asked stream %s to %s", sender.c_str(), name.c_str(), action.c_str());
+ return 0;
+}
+
+} // End of namespace State
+} // End of namespace Nancy
diff --git a/engines/nancy/script/v5/streamtree.h b/engines/nancy/script/v5/streamtree.h
new file mode 100644
index 00000000000..9de07d53982
--- /dev/null
+++ b/engines/nancy/script/v5/streamtree.h
@@ -0,0 +1,41 @@
+/* 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 NANCY_SCRIPT_V5_STREAMTREE_H
+#define NANCY_SCRIPT_V5_STREAMTREE_H
+
+#include "common/scummsys.h"
+
+namespace Nancy {
+namespace Script {
+
+// Nancy26: a stream is a node above the records of its scenes. Messages to its
+// name enable, disable, pause and lock it, which its records take on.
+struct StreamNodeState {
+ bool isEnabled = true;
+ bool isVisible = true;
+ bool isPaused = false;
+};
+
+} // End of namespace Script
+} // End of namespace Nancy
+
+#endif // NANCY_SCRIPT_V5_STREAMTREE_H
diff --git a/engines/nancy/state/scenestream.h b/engines/nancy/state/scenestream.h
index d0db739e5d3..488775fe99e 100644
--- a/engines/nancy/state/scenestream.h
+++ b/engines/nancy/state/scenestream.h
@@ -35,6 +35,12 @@
#include "engines/nancy/script/mathtypes.h"
#endif
+#ifdef ENABLE_NANCY_V5
+#include "engines/nancy/script/v5/streamtree.h"
+
+struct lua_State;
+#endif
+
namespace Common {
class SeekableReadStream;
}
@@ -133,6 +139,12 @@ public:
#endif
ViewTransform &getViewTransform() { return _viewTransform; }
+#ifdef ENABLE_NANCY_V5
+ // Nancy26: what the stream says about the records of its scenes
+ Script::StreamNodeState &getNodeState() { return _nodeState; }
+ const Script::StreamNodeState &getNodeState() const { return _nodeState; }
+#endif
+
Common::Array<Child> _children;
private:
@@ -160,6 +172,9 @@ private:
Script::ScriptMatrix _transform; // Nancy21
#endif
+#ifdef ENABLE_NANCY_V5
+ Script::StreamNodeState _nodeState; // Nancy26
+#endif
// The zoom of everything the stream draws
ViewTransform _viewTransform;
@@ -228,6 +243,16 @@ public:
// false when there is none.
bool receiveMessage(const Script::Message &message, bool &wasTaken);
+#ifdef ENABLE_NANCY_V5
+ // Nancy26: a message to a stream by its name, sent from the Lua state L. It
+ // enables, disables, pauses, locks or unlocks the stream, or asks whether it
+ // is paused. Returns the number of results left on the stack of L.
+ int receiveNancy26Message(lua_State *L, const Common::String &sender, const Common::String &name, const Common::String &action);
+
+ // Nancy26: what a stream says about its records; null for no such stream
+ Script::StreamNodeState *getNodeState(const Common::String &name);
+#endif
+
#ifdef ENABLE_NANCY_V4
// Enhancement: Esc skips what is being said in any of the streams, or else
// the movies they play. Returns whether there was something to skip.
@@ -271,6 +296,9 @@ private:
const Script::SceneContext *findScriptScene(const Common::String &name) const;
Script::ScriptMatrix _mainStreamTransform;
+#endif
+#ifdef ENABLE_NANCY_V5
+ Script::StreamNodeState _mainNodeState;
#endif
ViewTransform _mainStreamViewTransform;
};
Commit: 0cc2b6199b358920ddab62ac8675b8f0ebf20d56
https://github.com/scummvm/scummvm/commit/0cc2b6199b358920ddab62ac8675b8f0ebf20d56
Author: Filippos Karapetis (bluegr at gmail.com)
Date: 2026-11-06T04:10:46+02:00
Commit Message:
NANCY: NANCY26: Draw the streams and records in the order of their tree
Nancy26 draws each stream as a whole over the ones below it: the
streams of the viewport by their z, with the ones of the UI on top. In
a stream, a record's z only places it among the records attached to
the same Transformer, and a Transformer goes with everything attached
to it where its own z puts it.
Scene:BeginStream() takes the z of the stream, whether it is in the
viewport, and whether it is kept in saved games. A stream that keeps
the input goes in front of the others, and the frontmost streams run
first.
Changed paths:
engines/nancy/script/gameapi.cpp
engines/nancy/script/graphnode.h
engines/nancy/script/record.cpp
engines/nancy/script/record.h
engines/nancy/script/records.cpp
engines/nancy/script/records.h
engines/nancy/script/scenecontext.cpp
engines/nancy/script/scenecontext.h
engines/nancy/script/v5/recordnode.cpp
engines/nancy/script/v5/recordnode.h
engines/nancy/script/v5/streamtree.cpp
engines/nancy/script/v5/streamtree.h
engines/nancy/state/scene.cpp
engines/nancy/state/scene.h
engines/nancy/state/scenestream.cpp
engines/nancy/state/scenestream.h
diff --git a/engines/nancy/script/gameapi.cpp b/engines/nancy/script/gameapi.cpp
index 87645310bf7..e30d60df288 100644
--- a/engines/nancy/script/gameapi.cpp
+++ b/engines/nancy/script/gameapi.cpp
@@ -1436,7 +1436,17 @@ static int sceneBeginStream(lua_State *L) {
// From then on, a stream that keeps the input goes 10 in front of the
// frontmost stream, which is more than the z of a record spans, and any
// other one shares the z of the stream that began it.
- if (g_nancy->getGameType() < kGameTypeNancy24) {
+ if (g_nancy->getGameType() >= kGameTypeNancy26) {
+ // Nancy26 places streams by a z of their own
+#ifdef ENABLE_NANCY_V5
+ readField(L, 2, "z", flags.z);
+ readField(L, 2, "inVP", flags.isInViewport);
+ readField(L, 2, "save", flags.isSaved);
+ if (flags.capturesInput) {
+ flags.z = NancySceneState.getStreams().getCapturingZ(flags.z, flags.isInViewport);
+ }
+#endif
+ } else if (g_nancy->getGameType() < kGameTypeNancy24) {
flags.zOffset = 1;
} else if (flags.capturesInput) {
const State::SceneStreamManager &streams = NancySceneState.getStreams();
diff --git a/engines/nancy/script/graphnode.h b/engines/nancy/script/graphnode.h
index 00e73bffd22..8b3c7280364 100644
--- a/engines/nancy/script/graphnode.h
+++ b/engines/nancy/script/graphnode.h
@@ -48,6 +48,7 @@ public:
// Including those of the nodes above
double getZ() const;
+ double getLocalZ() const { return _z; }
ScriptMatrix getTransform() const;
#ifdef ENABLE_NANCY_V5
diff --git a/engines/nancy/script/record.cpp b/engines/nancy/script/record.cpp
index 98c9acd3e33..0d85f7e3462 100644
--- a/engines/nancy/script/record.cpp
+++ b/engines/nancy/script/record.cpp
@@ -35,6 +35,7 @@
#ifdef ENABLE_NANCY_V5
#include "engines/nancy/script/v5/recordnode.h"
+#include "engines/nancy/script/v5/streamtree.h"
#endif
namespace Nancy {
@@ -303,6 +304,12 @@ void Record::render() {
}
double Record::getZ() const {
+#ifdef ENABLE_NANCY_V5
+ if (_nodeState && _nodeState->drawRank >= 0) {
+ return getRankZ(_nodeState->drawRank);
+ }
+#endif
+
return _parentNode ? _z + _parentNode->getZ() : _z;
}
diff --git a/engines/nancy/script/record.h b/engines/nancy/script/record.h
index 0a8599fd155..1940a1d2fb0 100644
--- a/engines/nancy/script/record.h
+++ b/engines/nancy/script/record.h
@@ -195,6 +195,12 @@ public:
// Nancy26: works like reset(), but leaves the record inactive
bool resetInactive();
+ // Nancy26 orders records like a tree: a record's z only places it among the
+ // records under the same node, and a node with all it holds goes where its
+ // own z puts it. The scene works out the place of every record in that
+ // order, and getZ() then gives a z that keeps it.
+ void setDrawRank(int rank);
+
// Nancy26: every record is a node of a tree, which can be enabled (gets the
// player's input), visible (gets drawn) and paused (doesn't run), and can be
// see-through. A record is each of them when it says so itself, and the
diff --git a/engines/nancy/script/records.cpp b/engines/nancy/script/records.cpp
index 1862fe57e88..983be0d74a7 100644
--- a/engines/nancy/script/records.cpp
+++ b/engines/nancy/script/records.cpp
@@ -49,6 +49,7 @@
#ifdef ENABLE_NANCY_V5
#include "engines/nancy/script/v5/cliptransformer.h"
+#include "engines/nancy/script/v5/streamtree.h"
#endif
#include "engines/nancy/state/scene.h"
@@ -142,17 +143,32 @@ static const int kBackgroundZ = 6;
// Scripts tell apart z values as close as 0.001, and every stream is one step
// closer than the one that began it
static const double kStepsPerScriptZ = 1000.0;
-static const int kMaxScriptZOrder = 59000;
uint16 RecordGraphic::getScriptZOrder(double z, int32 zOffset) {
+#ifdef ENABLE_NANCY_V5
+ if (g_nancy->getGameType() >= kGameTypeNancy26) {
+ return getBandZOrder(z, zOffset);
+ }
+#endif
+
const double steps = (z - kBackgroundScriptZ + zOffset) * kStepsPerScriptZ;
return (uint16)CLIP<int>(kBackgroundZ + (int)floor(steps + 0.5), 0, kMaxScriptZOrder);
}
uint16 RecordGraphic::getBackgroundZOrder(int32 zOffset) {
+#ifdef ENABLE_NANCY_V5
+ if (g_nancy->getGameType() >= kGameTypeNancy26) {
+ return getBandBackgroundZOrder(zOffset);
+ }
+#endif
+
return getScriptZOrder(kBackgroundScriptZ, zOffset);
}
+bool RecordGraphic::isViewportRelative() const {
+ return g_nancy->getGameType() < kGameTypeNancy26;
+}
+
void RecordGraphic::setScriptZ(double z, const SceneContext &context) {
setZOrder(getScriptZOrder(z, context.getZOffset()));
setViewTransform(context.getViewTransform());
diff --git a/engines/nancy/script/records.h b/engines/nancy/script/records.h
index c419f56453c..cf650d15b09 100644
--- a/engines/nancy/script/records.h
+++ b/engines/nancy/script/records.h
@@ -94,8 +94,13 @@ public:
static uint16 getScriptZOrder(double z, int32 zOffset);
static uint16 getBackgroundZOrder(int32 zOffset);
+ // The highest z order of what the records draw
+ static const int kMaxScriptZOrder = 59000;
+
protected:
- bool isViewportRelative() const override { return true; }
+ // Nancy26 has the viewport at the top left of the screen, and lets records
+ // draw on all of it, the UI along the bottom included
+ bool isViewportRelative() const override;
};
// The first record of every scene, which names the area the scene belongs to
diff --git a/engines/nancy/script/scenecontext.cpp b/engines/nancy/script/scenecontext.cpp
index 7c5be5a02eb..02146ea4bd8 100644
--- a/engines/nancy/script/scenecontext.cpp
+++ b/engines/nancy/script/scenecontext.cpp
@@ -61,6 +61,18 @@ SceneContext::SceneContext(const Common::String &streamName, const Common::Strin
_lua = new LuaState(this);
}
+// Nancy26 draws whole streams over each other, so the z of a record only counts
+// within the band of its stream
+int32 SceneContext::getZOffset() const {
+#ifdef ENABLE_NANCY_V5
+ if (_streamState) {
+ return _streamState->band;
+ }
+#endif
+
+ return _zOffset;
+}
+
SceneContext::~SceneContext() {
// Taking the records down can have the UI send messages
_isEnding = true;
@@ -441,6 +453,12 @@ void SceneContext::run(double elapsedTime) {
renderAttachment();
applyGraphNodeChanges();
+#ifdef ENABLE_NANCY_V5
+ if (g_nancy->getGameType() >= kGameTypeNancy26) {
+ updateDrawRanks();
+ }
+#endif
+
for (Record *record : _records) {
record->updateGraphics();
}
diff --git a/engines/nancy/script/scenecontext.h b/engines/nancy/script/scenecontext.h
index dec0ba3bb0b..16d35cd1d90 100644
--- a/engines/nancy/script/scenecontext.h
+++ b/engines/nancy/script/scenecontext.h
@@ -114,9 +114,13 @@ public:
const Common::String &getSceneName() const { return _sceneName; }
uint getFrame() const { return _frame; }
void setFrame(uint frame) { _frame = frame; }
- int32 getZOffset() const { return _zOffset; }
+ int32 getZOffset() const;
#ifdef ENABLE_NANCY_V5
+ // Nancy26: the stream of the scene was put at another place among the
+ // others, so everything it draws goes elsewhere
+ void onBandChanged();
+
// Nancy26: what the stream of the scene says about all its records
bool isStreamEnabled() const { return !_streamState || _streamState->isEnabled; }
bool isStreamVisible() const { return !_streamState || _streamState->isVisible; }
@@ -187,6 +191,9 @@ private:
bool callSceneFunction(const char *name, int numArgs);
void pushMessage(const Message &message);
void runFrame(double elapsedTime);
+#ifdef ENABLE_NANCY_V5
+ void updateDrawRanks(); // Nancy26
+#endif
void deleteDroppedRecords();
void renderAttachment();
bool hasSkippableRecord() const;
diff --git a/engines/nancy/script/v5/recordnode.cpp b/engines/nancy/script/v5/recordnode.cpp
index 9024437aa7d..9eb7c7a1b12 100644
--- a/engines/nancy/script/v5/recordnode.cpp
+++ b/engines/nancy/script/v5/recordnode.cpp
@@ -112,6 +112,13 @@ const Common::String &Record::getName() const {
return _nodeState->localName.empty() ? _nodeState->uniqueAlias : _nodeState->localName;
}
+void Record::setDrawRank(int rank) {
+ if (rank != _nodeState->drawRank) {
+ _nodeState->drawRank = rank;
+ onZChanged();
+ }
+}
+
// What the records draw with. The records of the other games are shown while
// they are active, whole and as they are.
diff --git a/engines/nancy/script/v5/recordnode.h b/engines/nancy/script/v5/recordnode.h
index 488b7e412cf..3286f5f2c16 100644
--- a/engines/nancy/script/v5/recordnode.h
+++ b/engines/nancy/script/v5/recordnode.h
@@ -38,6 +38,7 @@ struct RecordNodeState {
double localAlpha = 1.0;
double drawnAlpha = 1.0; // what the picture was last drawn with
double keyZ = 0.0;
+ int drawRank = -1; // the place among the records of the scene
Common::String localName;
Common::String uniqueAlias; // "AR<number>", which no other record has
diff --git a/engines/nancy/script/v5/streamtree.cpp b/engines/nancy/script/v5/streamtree.cpp
index 4e493972c36..c47f5b7986e 100644
--- a/engines/nancy/script/v5/streamtree.cpp
+++ b/engines/nancy/script/v5/streamtree.cpp
@@ -36,8 +36,167 @@
#include "engines/nancy/state/scenestream.h"
namespace Nancy {
+namespace Script {
+
+// Each band is this many z orders, with the background at the bottom. The
+// scripts use z from -100 to 10, and tell apart z values as close as 0.05.
+static const int kBandSize = 5000;
+static const int kBandBackgroundZ = 50;
+static const double kLowestScriptZ = -100.0;
+static const double kStepsPerScriptZ = 40.0;
+
+static int getBandStart(int32 band) {
+ return CLIP<int>(band, 0, RecordGraphic::kMaxScriptZOrder / kBandSize - 1) * kBandSize;
+}
+
+uint16 getBandZOrder(double z, int32 band) {
+ const int steps = (int)floor((z - kLowestScriptZ) * kStepsPerScriptZ + 0.5);
+ return (uint16)(getBandStart(band) + CLIP<int>(kBandBackgroundZ * 2 + steps, kBandBackgroundZ + 1, kBandSize - 1));
+}
+
+uint16 getBandBackgroundZOrder(int32 band) {
+ return (uint16)(getBandStart(band) + kBandBackgroundZ);
+}
+
+double getRankZ(int rank) {
+ return kLowestScriptZ + (rank + 1) / kStepsPerScriptZ;
+}
+
+// The records of a scene
+
+void SceneContext::onBandChanged() {
+ for (Record *record : _records) {
+ record->onParentNodeChanged();
+ }
+
+ for (Record *record : _newRecords) {
+ record->onParentNodeChanged();
+ }
+}
+
+namespace {
+
+// The z values from the topmost node down to a record, which order the records
+// the way the tree does
+struct DrawKey {
+ Record *record;
+ uint index; // of creation, for records with the same place
+ Common::Array<double> path;
+};
+
+bool isDrawnBefore(const DrawKey &a, const DrawKey &b) {
+ for (uint i = 0; i < a.path.size() && i < b.path.size(); ++i) {
+ if (a.path[i] != b.path[i]) {
+ return a.path[i] < b.path[i];
+ }
+ }
+
+ if (a.path.size() != b.path.size()) {
+ return a.path.size() < b.path.size();
+ }
+
+ return a.index < b.index;
+}
+
+} // End of anonymous namespace
+
+void SceneContext::updateDrawRanks() {
+ Common::Array<DrawKey> keys;
+ keys.resize(_records.size());
+
+ for (uint i = 0; i < _records.size(); ++i) {
+ DrawKey &key = keys[i];
+ key.record = _records[i];
+ key.index = i;
+ key.path.push_back(_records[i]->getLocalZ());
+ for (const GraphNode *node = _records[i]->getParentNode(); node; node = node->getParent()) {
+ key.path.insert_at(0, node->getLocalZ());
+ }
+ }
+
+ Common::sort(keys.begin(), keys.end(), isDrawnBefore);
+
+ for (uint i = 0; i < keys.size(); ++i) {
+ keys[i].record->setDrawRank(i);
+ }
+}
+
+} // End of namespace Script
+
namespace State {
+// The streams
+
+static bool isDrawnBefore(const Script::StreamNodeState *a, const Script::StreamNodeState *b) {
+ if (a->isInViewport != b->isInViewport) {
+ return a->isInViewport;
+ }
+
+ if (a->z != b->z) {
+ return a->z < b->z;
+ }
+
+ return a->sequence < b->sequence;
+}
+
+void SceneStreamManager::getDrawOrder(Common::Array<SceneStream *> &streams) const {
+ streams.clear();
+ for (SceneStream *stream : _streams) {
+ if (stream && stream->isEnded()) {
+ continue;
+ }
+
+ const Script::StreamNodeState *state = stream ? &stream->getNodeState() : &_mainNodeState;
+
+ uint i = 0;
+ while (i < streams.size()) {
+ const Script::StreamNodeState *other = streams[i] ? &streams[i]->getNodeState() : &_mainNodeState;
+ if (isDrawnBefore(state, other)) {
+ break;
+ }
+
+ ++i;
+ }
+
+ streams.insert_at(i, stream);
+ }
+}
+
+void SceneStreamManager::updateBands() {
+ Common::Array<SceneStream *> streams;
+ getDrawOrder(streams);
+
+ for (uint i = 0; i < streams.size(); ++i) {
+ Script::StreamNodeState &state = streams[i] ? streams[i]->getNodeState() : _mainNodeState;
+ if (state.band == (int32)i) {
+ continue;
+ }
+
+ state.band = i;
+ if (streams[i]) {
+ streams[i]->onBandChanged();
+ } else {
+ NancySceneState.onMainStreamBandChanged();
+ }
+ }
+}
+
+double SceneStreamManager::getCapturingZ(double z, bool isInViewport) const {
+ // The managers and the cheat tools stay in front
+ for (SceneStream *stream : _streams) {
+ const Script::StreamNodeState &state = stream ? stream->getNodeState() : _mainNodeState;
+ if (stream && (stream->isEnded() || stream->getName().equalsIgnoreCase(getManagerStreamName()) || stream->getName().equalsIgnoreCase("CHEAT"))) {
+ continue;
+ }
+
+ if (state.isInViewport == isInViewport && state.z >= z) {
+ z = state.z + 1.0;
+ }
+ }
+
+ return z;
+}
+
Script::StreamNodeState *SceneStreamManager::getNodeState(const Common::String &name) {
if (name.equalsIgnoreCase(getMainStreamName())) {
return &_mainNodeState;
@@ -78,5 +237,27 @@ int SceneStreamManager::receiveNancy26Message(lua_State *L, const Common::String
return 0;
}
+void SceneStream::onBandChanged() {
+ if (!_scriptScene) {
+ return;
+ }
+
+ _scriptScene->onBandChanged();
+ if (_background) {
+ _background->setZOrder(Script::RecordGraphic::getBackgroundZOrder(_scriptScene->getZOffset()));
+ }
+}
+
+// The main stream, and the streams the game begins along with it
+
+void Scene::onMainStreamBandChanged() {
+ if (!_scriptScene) {
+ return;
+ }
+
+ _scriptScene->onBandChanged();
+ _viewport.setZOrder(Script::RecordGraphic::getBackgroundZOrder(_scriptScene->getZOffset()));
+}
+
} // End of namespace State
} // End of namespace Nancy
diff --git a/engines/nancy/script/v5/streamtree.h b/engines/nancy/script/v5/streamtree.h
index 9de07d53982..257295e5f15 100644
--- a/engines/nancy/script/v5/streamtree.h
+++ b/engines/nancy/script/v5/streamtree.h
@@ -29,12 +29,35 @@ namespace Script {
// Nancy26: a stream is a node above the records of its scenes. Messages to its
// name enable, disable, pause and lock it, which its records take on.
+//
+// The streams of the viewport and the ones of the UI make two trees, the UI on
+// top. In each, streams get drawn in the order of their z, the ones begun later
+// in front of the ones with the same z.
struct StreamNodeState {
bool isEnabled = true;
bool isVisible = true;
bool isPaused = false;
+
+ bool isInViewport = true;
+ double z = 0.0;
+ uint32 sequence = 0; // when it was begun
+
+ // Where the stream comes in the order all the streams get drawn in, from
+ // the bottom. Everything the stream draws goes in the range of z orders of
+ // that place, so it ends up above the streams before it.
+ int32 band = 0;
};
+// Nancy26 draws every stream as a whole over the ones before it, so each gets a
+// band of z orders of its own, with the background at the bottom. These give
+// the z order of a script z, and of the background, in a band.
+uint16 getBandZOrder(double z, int32 band);
+uint16 getBandBackgroundZOrder(int32 band);
+
+// The scene works out the place of each of its records in the order of the
+// tree they make; this is the script z that keeps a record at its place
+double getRankZ(int rank);
+
} // End of namespace Script
} // End of namespace Nancy
diff --git a/engines/nancy/state/scene.cpp b/engines/nancy/state/scene.cpp
index 7dbc7007de4..f69dcbe06e8 100644
--- a/engines/nancy/state/scene.cpp
+++ b/engines/nancy/state/scene.cpp
@@ -2345,6 +2345,11 @@ void Scene::loadScriptedScene(bool fromSaveFile) {
delete _scriptScene;
_scriptScene = scriptScene;
+ // Nancy26 puts the background at the bottom of the main stream's band
+ if (g_nancy->getGameType() >= kGameTypeNancy26) {
+ _viewport.setZOrder(Script::RecordGraphic::getBackgroundZOrder(_scriptScene->getZOffset()));
+ }
+
g_nancy->_graphics->suppressNextDraw();
debugC(0, kDebugScene, "Loading new scene %s, frame %i", sceneName.c_str(), _sceneState.nextScene.frameID);
diff --git a/engines/nancy/state/scene.h b/engines/nancy/state/scene.h
index 366324c3fb8..6588fce578b 100644
--- a/engines/nancy/state/scene.h
+++ b/engines/nancy/state/scene.h
@@ -355,6 +355,11 @@ public:
bool receiveMainSceneMessage(const Script::Message &message, bool &wasTaken);
#endif
+#ifdef ENABLE_NANCY_V5
+ // Nancy26: the main stream was put at another place among the streams
+ void onMainStreamBandChanged();
+#endif
+
// Used from nancy2 onwards
void specialEffect(byte type, uint16 fadeToBlackTime, uint16 frameTime);
void specialEffect(byte type, uint16 totalTime, uint16 fadeToBlackTime, Common::Rect rect);
diff --git a/engines/nancy/state/scenestream.cpp b/engines/nancy/state/scenestream.cpp
index 404fbe6fa0d..47053c124cd 100644
--- a/engines/nancy/state/scenestream.cpp
+++ b/engines/nancy/state/scenestream.cpp
@@ -231,7 +231,7 @@ void SceneStream::loadBackground(const Common::Path &videoFile) {
_background->setZOrder(_background->getZOrder() + _zOffset);
#ifdef ENABLE_NANCY_V4
if (_scriptScene) {
- _background->setZOrder(Script::RecordGraphic::getBackgroundZOrder(_zOffset));
+ _background->setZOrder(Script::RecordGraphic::getBackgroundZOrder(_scriptScene->getZOffset()));
}
#endif
_background->setViewTransform(&_viewTransform);
@@ -436,6 +436,16 @@ const ViewTransform *SceneStreamManager::getViewTransform(const Common::String &
double SceneStreamManager::getZ(const Common::String &name) const {
const SceneStream *stream = find(name);
+#ifdef ENABLE_NANCY_V5
+ if (g_nancy->getGameType() >= kGameTypeNancy26) {
+ if (name.equalsIgnoreCase(kMainStreamName)) {
+ return _mainNodeState.z;
+ }
+
+ return stream ? stream->getNodeState().z : 0.0;
+ }
+#endif
+
return stream ? stream->getZOffset() : 0.0;
}
@@ -490,6 +500,15 @@ void SceneStreamManager::begin(const Common::String &name, const Common::String
_streams.push_back(stream);
}
+#ifdef ENABLE_NANCY_V5
+ if (g_nancy->getGameType() >= kGameTypeNancy26) {
+ stream->getNodeState().z = flags.z;
+ stream->getNodeState().isInViewport = flags.isInViewport;
+ stream->getNodeState().sequence = ++_numBegun;
+ updateBands();
+ }
+#endif
+
// The stream that starts another one decides how long it lives
SceneStream::Child child;
child.name = name;
@@ -638,8 +657,18 @@ void SceneStreamManager::process() {
return;
}
- // Streams begin and end while the records run
- const Common::Array<SceneStream *> streams = _streams;
+ // Streams begin and end while the records run. Nancy26 runs the frontmost
+ // ones first, so the managers are ready for the scenes that call on them.
+ Common::Array<SceneStream *> streams = _streams;
+#ifdef ENABLE_NANCY_V5
+ if (g_nancy->getGameType() >= kGameTypeNancy26) {
+ getDrawOrder(streams);
+ for (uint i = 0; i < streams.size() / 2; ++i) {
+ SWAP(streams[i], streams[streams.size() - 1 - i]);
+ }
+ }
+#endif
+
for (SceneStream *stream : streams) {
if (!stream) {
NancySceneState.processMainStream();
@@ -661,6 +690,12 @@ void SceneStreamManager::process() {
returnViewedItem(_streams[i]->getName());
delete _streams[i];
_streams.remove_at(i);
+
+#ifdef ENABLE_NANCY_V5
+ if (g_nancy->getGameType() >= kGameTypeNancy26) {
+ updateBands();
+ }
+#endif
} else {
++i;
}
@@ -823,7 +858,8 @@ void SceneStreamManager::store() {
StreamData::Stream saved;
if (stream) {
- if (stream->isEnded()) {
+ // Nancy26's popups and cheat tools are left out
+ if (stream->isEnded() || !stream->getFlags().isSaved) {
continue;
}
diff --git a/engines/nancy/state/scenestream.h b/engines/nancy/state/scenestream.h
index 488775fe99e..cb29b8fede9 100644
--- a/engines/nancy/state/scenestream.h
+++ b/engines/nancy/state/scenestream.h
@@ -75,6 +75,11 @@ struct StreamFlags {
bool capturesInput = false; // the streams after this one get no input
bool runsFirst = false; // put in front of the running streams
int32 zOffset = 0; // added to the z order of everything the stream draws
+
+ // Nancy26
+ double z = 0.0; // where the stream is among the others
+ bool isInViewport = true; // false for the ones placed on the whole screen
+ bool isSaved = true; // kept in saved games
};
// Nancy17 runs several scenes side by side, each in a stream of its own. The scene
@@ -143,6 +148,9 @@ public:
// Nancy26: what the stream says about the records of its scenes
Script::StreamNodeState &getNodeState() { return _nodeState; }
const Script::StreamNodeState &getNodeState() const { return _nodeState; }
+
+ // The stream was put at another place among the others
+ void onBandChanged();
#endif
Common::Array<Child> _children;
@@ -251,6 +259,13 @@ public:
// Nancy26: what a stream says about its records; null for no such stream
Script::StreamNodeState *getNodeState(const Common::String &name);
+
+ // Nancy26: the streams in the order they get drawn in, the main one as null
+ void getDrawOrder(Common::Array<SceneStream *> &streams) const;
+
+ // Nancy26: a stream that keeps the input goes in front of the others of its
+ // tree, the managers and the cheat tools left aside; the z it gets for that
+ double getCapturingZ(double z, bool isInViewport) const;
#endif
#ifdef ENABLE_NANCY_V4
@@ -298,7 +313,11 @@ private:
Script::ScriptMatrix _mainStreamTransform;
#endif
#ifdef ENABLE_NANCY_V5
+ // Nancy26: puts every stream at its place in the order they get drawn in
+ void updateBands();
+
Script::StreamNodeState _mainNodeState;
+ uint32 _numBegun = 0;
#endif
ViewTransform _mainStreamViewTransform;
};
Commit: 6c10a49be68a9fa9944a16a38083a7ca8e5c9b22
https://github.com/scummvm/scummvm/commit/6c10a49be68a9fa9944a16a38083a7ca8e5c9b22
Author: Filippos Karapetis (bluegr at gmail.com)
Date: 2026-11-06T04:10:47+02:00
Commit Message:
NANCY: NANCY26: Draw the texts with fonts made of pictures
Like Nancy1-15, and unlike the TrueType fonts of Nancy16-25, Nancy26
draws its letters from pictures. Each font comes in four styles, each a
picture with a table of where its letters are, how far apart they go,
and their kerning, and the letters take on the color of the text.
The tags in a text pick the font, the color, bold and italic, and how
the lines line up. A text can be drawn in one color, or only in part,
and "bounds" tells the scripts where its letters ended up.
Changed paths:
A engines/nancy/script/v5/bitmaptext.cpp
A engines/nancy/script/v5/bitmaptext.h
A engines/nancy/script/v5/textrecord.cpp
A engines/nancy/script/v5/textrecord.h
engines/nancy/module.mk
engines/nancy/script/records.cpp
engines/nancy/script/records.h
diff --git a/engines/nancy/module.mk b/engines/nancy/module.mk
index daa5f942841..113e69358d7 100644
--- a/engines/nancy/module.mk
+++ b/engines/nancy/module.mk
@@ -240,11 +240,13 @@ MODULE_OBJS += \
# Nancy26 and newer, whose UI is made of records as well
ifdef ENABLE_NANCY_V5
MODULE_OBJS += \
+ script/v5/bitmaptext.o \
script/v5/bootobjects.o \
script/v5/cliptransformer.o \
script/v5/messaging.o \
script/v5/recordnode.o \
- script/v5/streamtree.o
+ script/v5/streamtree.o \
+ script/v5/textrecord.o
endif
endif
diff --git a/engines/nancy/script/records.cpp b/engines/nancy/script/records.cpp
index 983be0d74a7..04755e2618d 100644
--- a/engines/nancy/script/records.cpp
+++ b/engines/nancy/script/records.cpp
@@ -50,6 +50,7 @@
#ifdef ENABLE_NANCY_V5
#include "engines/nancy/script/v5/cliptransformer.h"
#include "engines/nancy/script/v5/streamtree.h"
+#include "engines/nancy/script/v5/textrecord.h"
#endif
#include "engines/nancy/state/scene.h"
@@ -112,6 +113,12 @@ Record *makeRecord(RecordKind kind, SceneContext &context) {
case kRecordSoundConvo:
return new ConvoRecord(context, false);
case kRecordText:
+#ifdef ENABLE_NANCY_V5
+ if (g_nancy->getGameType() >= kGameTypeNancy26) {
+ return new BitmapTextRecord(context);
+ }
+#endif
+
return new TextRecord(context);
case kRecordParticle:
return new ParticleRecord(context);
@@ -174,9 +181,7 @@ void RecordGraphic::setScriptZ(double z, const SceneContext &context) {
setViewTransform(context.getViewTransform());
}
-// Where something that was placed in the viewport ends up once the transform
-// of its record has moved it
-static Common::Rect getTransformedDest(const ScriptRect &dest, const ScriptMatrix &transform, int width, int height) {
+Common::Rect getTransformedDest(const ScriptRect &dest, const ScriptMatrix &transform, int width, int height) {
// Far enough for anything a script moves around, and safe to add a size to
const int kLimit = 16000;
diff --git a/engines/nancy/script/records.h b/engines/nancy/script/records.h
index cf650d15b09..03d420903f2 100644
--- a/engines/nancy/script/records.h
+++ b/engines/nancy/script/records.h
@@ -80,6 +80,10 @@ Graphics::ManagedSurface *getDrawTarget();
// the record that is rendering draws
int drawOverlay(lua_State *L);
+// Where something that was placed in the viewport ends up once the transform
+// of its record has moved it
+Common::Rect getTransformedDest(const ScriptRect &dest, const ScriptMatrix &transform, int width, int height);
+
// What a record draws. Records are placed in the coordinates of the viewport.
class RecordGraphic : public RenderObject {
public:
diff --git a/engines/nancy/script/v5/bitmaptext.cpp b/engines/nancy/script/v5/bitmaptext.cpp
new file mode 100644
index 00000000000..5b46ad9029f
--- /dev/null
+++ b/engines/nancy/script/v5/bitmaptext.cpp
@@ -0,0 +1,461 @@
+/* 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 "common/hashmap.h"
+#include "common/ptr.h"
+#include "common/util.h"
+
+#include "engines/nancy/graphics.h"
+#include "engines/nancy/nancy.h"
+#include "engines/nancy/resource/resource.h"
+
+#include "engines/nancy/script/v5/bitmaptext.h"
+
+namespace Nancy {
+namespace Script {
+
+static const int kDefaultFontID = 4;
+static const int kDefaultFontColor = 0;
+
+typedef ScriptBootData::BitmapFont BitmapFont;
+
+static const BitmapFont *findFont(int id) {
+ const ScriptBootData *boot = GetEngineData(ScriptBootData);
+ if (!boot) {
+ return nullptr;
+ }
+
+ for (const BitmapFont &font : boot->bitmapFonts) {
+ if (font.id == id) {
+ return &font;
+ }
+ }
+
+ return nullptr;
+}
+
+static uint32 findFontColor(int id) {
+ const ScriptBootData *boot = GetEngineData(ScriptBootData);
+ if (boot) {
+ for (const ScriptBootData::FontColor &color : boot->fontColors) {
+ if (color.id == id) {
+ return color.normal;
+ }
+ }
+ }
+
+ return 0xFFFFFFFF;
+}
+
+// The pictures of the letters, kept once loaded
+static const Graphics::ManagedSurface *getFaceImage(const Common::Path &name) {
+ typedef Common::HashMap<Common::Path, Common::SharedPtr<Graphics::ManagedSurface>, Common::Path::IgnoreCase_Hash, Common::Path::IgnoreCase_EqualTo> ImageMap;
+ static ImageMap s_images;
+
+ ImageMap::iterator it = s_images.find(name);
+ if (it != s_images.end()) {
+ return it->_value.get();
+ }
+
+ Common::SharedPtr<Graphics::ManagedSurface> image(new Graphics::ManagedSurface());
+ Graphics::ManagedSurface loaded;
+ if (g_nancy->_resource->loadImage(name, loaded)) {
+ image->copyFrom(loaded);
+ image->convertToInPlace(g_nancy->_graphics->getTransparentPixelFormat());
+ }
+
+ s_images.setVal(name, image);
+ return image.get();
+}
+
+// The face of a font for the bold and italic settings; the regular one when the
+// font has no such face
+static const BitmapFont::Face *getFace(const BitmapFont *font, bool isBold, bool isItalic) {
+ if (!font) {
+ return nullptr;
+ }
+
+ int style = BitmapFont::kRegular;
+ if (isBold && isItalic) {
+ style = BitmapFont::kBoldItalic;
+ } else if (isBold) {
+ style = BitmapFont::kBold;
+ } else if (isItalic) {
+ style = BitmapFont::kItalic;
+ }
+
+ if (font->faces[style].imageName.empty()) {
+ style = BitmapFont::kRegular;
+ }
+
+ return &font->faces[style];
+}
+
+// Reads the number of a tag like <c12>; returns false when it is something else
+static bool readTagNumber(const Common::String &text, uint &pos, char letter, int &number) {
+ if (pos + 3 > text.size() || text[pos] != '<' || text[pos + 1] != letter || !Common::isDigit(text[pos + 2])) {
+ return false;
+ }
+
+ uint end = pos + 2;
+ number = 0;
+ while (end < text.size() && Common::isDigit(text[end])) {
+ number = number * 10 + (text[end] - '0');
+ ++end;
+ }
+
+ if (end >= text.size() || text[end] != '>') {
+ return false;
+ }
+
+ pos = end + 1;
+ return true;
+}
+
+static bool readTag(const Common::String &text, uint &pos, const char *tag) {
+ const uint length = strlen(tag);
+ if (pos + length > text.size() || strncmp(text.c_str() + pos, tag, length) != 0) {
+ return false;
+ }
+
+ pos += length;
+ return true;
+}
+
+namespace {
+
+enum HorizontalAlign { kAlignLeft, kAlignCenter, kAlignRight };
+enum VerticalAlign { kAlignTop, kAlignMiddle, kAlignBottom };
+
+// What the tags have set so far
+struct TextStyle {
+ int fontID = kDefaultFontID;
+ int colorID = kDefaultFontColor;
+ bool isBold = false;
+ bool isItalic = false;
+ HorizontalAlign horizontalAlign = kAlignLeft;
+ VerticalAlign verticalAlign = kAlignTop;
+};
+
+// One letter on its way into a line
+struct PendingLetter {
+ uint32 code = 0;
+ const BitmapFont::Face *face = nullptr;
+ uint32 color = 0xFFFFFFFF;
+ int x = 0; // of the pen, from the start of the line
+ int advance = 0;
+};
+
+struct Line {
+ Common::Array<PendingLetter> letters;
+ int width = 0;
+ int height = 0;
+ HorizontalAlign align = kAlignLeft;
+};
+
+} // End of anonymous namespace
+
+// Takes a tag at pos, and returns whether there was one
+static bool readStyleTag(const Common::String &text, uint &pos, TextStyle &style, bool &isNewLine) {
+ int number = 0;
+ isNewLine = false;
+
+ if (readTagNumber(text, pos, 'f', number)) {
+ style.fontID = number;
+ } else if (readTagNumber(text, pos, 'c', number)) {
+ style.colorID = number;
+ } else if (readTag(text, pos, "<b>")) {
+ style.isBold = true;
+ } else if (readTag(text, pos, "</b>")) {
+ style.isBold = false;
+ } else if (readTag(text, pos, "<i>")) {
+ style.isItalic = true;
+ } else if (readTag(text, pos, "</i>")) {
+ style.isItalic = false;
+ } else if (readTag(text, pos, "<hl>")) {
+ style.horizontalAlign = kAlignLeft;
+ } else if (readTag(text, pos, "<hc>")) {
+ style.horizontalAlign = kAlignCenter;
+ } else if (readTag(text, pos, "<hr>")) {
+ style.horizontalAlign = kAlignRight;
+ } else if (readTag(text, pos, "<vt>")) {
+ style.verticalAlign = kAlignTop;
+ } else if (readTag(text, pos, "<vc>")) {
+ style.verticalAlign = kAlignMiddle;
+ } else if (readTag(text, pos, "<vb>")) {
+ style.verticalAlign = kAlignBottom;
+ } else if (readTag(text, pos, "<n>")) {
+ isNewLine = true;
+ } else {
+ return false;
+ }
+
+ return true;
+}
+
+void BitmapText::layout(const Common::String &text, int width, int height, int overrideColor) {
+ _letters.clear();
+ _bounds = ScriptRect();
+
+ TextStyle style;
+ Common::Array<Line> lines;
+ Line line;
+ int breakIndex = -1; // the letter after the last space of the line
+ uint32 lastCode = 0;
+
+ const BitmapFont::Face *face = getFace(findFont(style.fontID), false, false);
+ line.height = face ? face->height : 0;
+
+ uint pos = 0;
+ while (pos <= text.size()) {
+ bool isNewLine = false;
+ bool isEnd = pos == text.size();
+
+ if (!isEnd && text[pos] == '<' && readStyleTag(text, pos, style, isNewLine)) {
+ if (!isNewLine) {
+ if (line.letters.empty()) {
+ line.align = style.horizontalAlign;
+ }
+
+ continue;
+ }
+ } else if (!isEnd && (text[pos] == '\n' || text[pos] == '\r')) {
+ isNewLine = text[pos] == '\n';
+ ++pos;
+ if (!isNewLine) {
+ continue;
+ }
+ }
+
+ if (isNewLine || isEnd) {
+ lines.push_back(line);
+ if (isEnd) {
+ break;
+ }
+
+ line = Line();
+ line.align = style.horizontalAlign;
+ face = getFace(findFont(style.fontID), style.isBold, style.isItalic);
+ line.height = face ? face->height : 0;
+ breakIndex = -1;
+ lastCode = 0;
+ continue;
+ }
+
+ const uint32 code = (byte)text[pos++];
+ face = getFace(findFont(style.fontID), style.isBold, style.isItalic);
+ if (!face) {
+ continue;
+ }
+
+ PendingLetter letter;
+ letter.code = code;
+ letter.face = face;
+ letter.color = findFontColor(overrideColor >= 0 ? overrideColor : style.colorID);
+
+ int kerning = 0;
+ if (lastCode && face->kerning.contains((lastCode << 16) | code)) {
+ kerning = face->kerning.getVal((lastCode << 16) | code);
+ }
+
+ const BitmapFont::Glyph *glyph = face->glyphs.contains(code) ? &face->glyphs.getVal(code) : nullptr;
+ letter.x = line.width + kerning;
+ letter.advance = glyph ? glyph->xAdvance : 0;
+
+ // A letter that doesn't fit takes the words after the last space along
+ if (width > 0 && code != ' ' && letter.x + letter.advance > width && breakIndex > 0) {
+ Line next;
+ next.align = style.horizontalAlign;
+ next.height = face->height;
+
+ for (uint i = breakIndex; i < line.letters.size(); ++i) {
+ PendingLetter moved = line.letters[i];
+ moved.x = next.width;
+ next.width += moved.advance;
+ next.height = MAX(next.height, moved.face->height);
+ next.letters.push_back(moved);
+ }
+
+ line.letters.resize(breakIndex);
+
+ // The spaces at the end of the line take no room
+ while (!line.letters.empty() && line.letters.back().code == ' ') {
+ line.letters.pop_back();
+ }
+
+ line.width = line.letters.empty() ? 0 : line.letters.back().x + line.letters.back().advance;
+ lines.push_back(line);
+
+ line = next;
+ breakIndex = -1;
+ letter.x = line.width;
+ }
+
+ line.letters.push_back(letter);
+ line.width = letter.x + letter.advance;
+ line.height = MAX(line.height, face->height);
+ lastCode = code;
+
+ if (code == ' ') {
+ breakIndex = line.letters.size();
+ }
+ }
+
+ int totalHeight = 0;
+ for (const Line &l : lines) {
+ totalHeight += l.height;
+ }
+
+ // An area without a height or a width puts the text at its top or its left
+ int y = 0;
+ if (height != 0 && style.verticalAlign == kAlignMiddle) {
+ y = (height - totalHeight) / 2;
+ } else if (height != 0 && style.verticalAlign == kAlignBottom) {
+ y = height - totalHeight;
+ }
+
+ // The bounds go around the lines, each as high as its tallest font, which
+ // is what the scripts lay their texts out with
+ bool hasBounds = false;
+ for (const Line &l : lines) {
+ int x = 0;
+ if (width != 0 && l.align == kAlignCenter) {
+ x = (width - l.width) / 2;
+ } else if (width != 0 && l.align == kAlignRight) {
+ x = width - l.width;
+ }
+
+ if (!hasBounds) {
+ _bounds = ScriptRect(x, y, x + l.width, y + l.height);
+ hasBounds = true;
+ } else {
+ _bounds.left = MIN<int32>(_bounds.left, x);
+ _bounds.right = MAX<int32>(_bounds.right, x + l.width);
+ _bounds.bottom = y + l.height;
+ }
+
+ for (const PendingLetter &pending : l.letters) {
+ Letter letter;
+ letter.color = pending.color;
+ letter.image = getFaceImage(pending.face->imageName);
+ if (pending.face->glyphs.contains(pending.code)) {
+ letter.glyph = &pending.face->glyphs.getVal(pending.code);
+ letter.position = Common::Point(x + pending.x + letter.glyph->xOffset, y + letter.glyph->yOffset);
+ }
+
+ _letters.push_back(letter);
+ }
+
+ y += l.height;
+ }
+}
+
+Common::Rect BitmapText::getInkArea() const {
+ Common::Rect area;
+ for (const Letter &letter : _letters) {
+ if (!letter.glyph) {
+ continue;
+ }
+
+ Common::Rect glyphArea(letter.glyph->source.width(), letter.glyph->source.height());
+ glyphArea.moveTo(letter.position);
+ if (area.isEmpty()) {
+ area = glyphArea;
+ } else {
+ area.extend(glyphArea);
+ }
+ }
+
+ return area;
+}
+
+static inline uint32 multiplyColors(uint32 a, uint32 b) {
+ uint32 result = 0;
+ for (int shift = 0; shift < 32; shift += 8) {
+ const uint32 product = (((a >> shift) & 0xFF) * ((b >> shift) & 0xFF) + 127) / 255;
+ result |= product << shift;
+ }
+
+ return result;
+}
+
+void BitmapText::draw(Graphics::ManagedSurface &surface, const Common::Point &origin, uint32 modColor, int first, int count) const {
+ const Graphics::PixelFormat &format = surface.format;
+ const int last = count < 0 ? (int)_letters.size() : MIN<int>(_letters.size(), first + count);
+
+ for (int i = MAX(first, 0); i < last; ++i) {
+ const Letter &letter = _letters[i];
+ if (!letter.glyph || !letter.image || !letter.image->getPixels()) {
+ continue;
+ }
+
+ const Graphics::ManagedSurface &image = *letter.image;
+ const uint32 color = multiplyColors(letter.color, modColor);
+ const Common::Rect &source = letter.glyph->source;
+
+ for (int y = 0; y < source.height(); ++y) {
+ const int destY = origin.y + letter.position.y + y;
+ const int sourceY = source.top + y;
+ if (destY < 0 || destY >= surface.h || sourceY < 0 || sourceY >= image.h) {
+ continue;
+ }
+
+ for (int x = 0; x < source.width(); ++x) {
+ const int destX = origin.x + letter.position.x + x;
+ const int sourceX = source.left + x;
+ if (destX < 0 || destX >= surface.w || sourceX < 0 || sourceX >= image.w) {
+ continue;
+ }
+
+ uint8 a, r, g, b;
+ image.format.colorToARGB(image.getPixel(sourceX, sourceY), a, r, g, b);
+ const uint32 glyphColor = multiplyColors(((uint32)a << 24) | ((uint32)r << 16) | ((uint32)g << 8) | b, color);
+ const uint32 alpha = glyphColor >> 24;
+ if (alpha == 0) {
+ continue;
+ }
+
+ // Laid over what is there already
+ uint8 da, dr, dg, db;
+ format.colorToARGB(surface.getPixel(destX, destY), da, dr, dg, db);
+ const uint32 outAlpha = alpha + da * (255 - alpha) / 255;
+ if (outAlpha == 0) {
+ continue;
+ }
+
+ const uint32 rest = da * (255 - alpha) / 255;
+ const uint32 outR = (((glyphColor >> 16) & 0xFF) * alpha + dr * rest) / outAlpha;
+ const uint32 outG = (((glyphColor >> 8) & 0xFF) * alpha + dg * rest) / outAlpha;
+ const uint32 outB = ((glyphColor & 0xFF) * alpha + db * rest) / outAlpha;
+ surface.setPixel(destX, destY, format.ARGBToColor(outAlpha, outR, outG, outB));
+ }
+ }
+ }
+}
+
+int getBitmapTextWidth(const Common::String &text, int fontID) {
+ BitmapText layout;
+ layout.layout(Common::String::format("<f%d>", fontID) + text, 0, 0);
+ return layout.getBounds().width();
+}
+
+} // End of namespace Script
+} // End of namespace Nancy
diff --git a/engines/nancy/script/v5/bitmaptext.h b/engines/nancy/script/v5/bitmaptext.h
new file mode 100644
index 00000000000..fea18a4fd81
--- /dev/null
+++ b/engines/nancy/script/v5/bitmaptext.h
@@ -0,0 +1,85 @@
+/* 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 NANCY_SCRIPT_V5_BITMAPTEXT_H
+#define NANCY_SCRIPT_V5_BITMAPTEXT_H
+
+#include "common/array.h"
+#include "common/str.h"
+
+#include "graphics/managed_surface.h"
+
+#include "engines/nancy/enginedata.h"
+#include "engines/nancy/script/types.h"
+
+namespace Nancy {
+namespace Script {
+
+// Nancy26 writes its texts with the fonts made of pictures that Fonts_SC lists.
+// A text can switch fonts and colors along the way, and say how it lines up:
+//
+// <fN> the font of number N <cN> the font color N
+// <b> </b> bold <i> </i> italic
+// <hl> <hc> <hr> lines go left, centered or right
+// <vt> <vc> <vb> the text goes to the top, the middle or the bottom
+// <n> a new line
+//
+// A text starts in font 4 and color 0. Lines wrap between words to fit the
+// width they are given.
+class BitmapText {
+public:
+ // Lays the text out in an area of the given size. A font color of -1 lets
+ // the text pick its colors; anything else is used for all of it.
+ void layout(const Common::String &text, int width, int height, int overrideColor = -1);
+
+ // Draws the letters from first on, as many as count (-1 for all of them),
+ // at a place of the surface, with their colors multiplied by modColor
+ void draw(Graphics::ManagedSurface &surface, const Common::Point &origin, uint32 modColor, int first = 0, int count = -1) const;
+
+ // The area the letters take up, in the coordinates of the layout
+ const ScriptRect &getBounds() const { return _bounds; }
+
+ // What the letters cover when they get drawn, which can stick out of the
+ // area of the layout; empty without letters
+ Common::Rect getInkArea() const;
+
+ // The number of letters, which drawing counts in
+ uint getNumLetters() const { return _letters.size(); }
+
+private:
+ struct Letter {
+ const ScriptBootData::BitmapFont::Glyph *glyph = nullptr;
+ const Graphics::ManagedSurface *image = nullptr;
+ Common::Point position; // of the top left of the glyph
+ uint32 color = 0xFFFFFFFF;
+ };
+
+ Common::Array<Letter> _letters;
+ ScriptRect _bounds;
+};
+
+// The width a text takes in a font, for the scripts that measure texts
+int getBitmapTextWidth(const Common::String &text, int fontID);
+
+} // End of namespace Script
+} // End of namespace Nancy
+
+#endif // NANCY_SCRIPT_V5_BITMAPTEXT_H
diff --git a/engines/nancy/script/v5/textrecord.cpp b/engines/nancy/script/v5/textrecord.cpp
new file mode 100644
index 00000000000..9153f920d4b
--- /dev/null
+++ b/engines/nancy/script/v5/textrecord.cpp
@@ -0,0 +1,197 @@
+/* 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 "engines/nancy/graphics.h"
+#include "engines/nancy/nancy.h"
+
+#include "engines/nancy/script/api.h"
+#include "engines/nancy/script/luabind.h"
+#include "engines/nancy/script/scenecontext.h"
+#include "engines/nancy/script/types.h"
+
+#include "engines/nancy/script/v5/textrecord.h"
+
+namespace Nancy {
+namespace Script {
+
+void BitmapTextRecord::readTable(int tableIndex) {
+ lua_State *L = getLua();
+
+ if (pushField(L, tableIndex, "onScreen")) {
+ _dest = checkRect(L, -1);
+ lua_pop(L, 1);
+ }
+
+ _initialDest = _dest;
+ readField(L, tableIndex, "useAutotext", _usesAutotext);
+ readField(L, tableIndex, "overrideFontColor", _overrideFontColor);
+ readField(L, tableIndex, "renderStartIdx", _renderStart);
+ readField(L, tableIndex, "renderLen", _renderLength);
+
+ if (pushField(L, tableIndex, "modColor")) {
+ _modColor = checkColor(L, -1);
+ lua_pop(L, 1);
+ }
+
+ Common::String text;
+ if (!readField(L, tableIndex, "text", text)) {
+ luaL_error(L, "Text AR requires field %s", "text");
+ }
+
+ setText(text);
+
+ _graphic.init();
+ _graphic.setVisible(false);
+ applyDest();
+ onZChanged();
+ _graphic.registerGraphics();
+}
+
+// The transform moves the text, like the scrolling lists of the UI do with
+// theirs. The letters don't get cut off at the area of the text.
+void BitmapTextRecord::applyDest() {
+ const Graphics::ManagedSurface &surface = _graphic._drawSurface;
+ Common::Rect position = getTransformedDest(_dest, getTransform(), MAX<int>(surface.w, 1), MAX<int>(surface.h, 1));
+ position.translate(_inkOffset.x, _inkOffset.y);
+ _graphic.moveTo(position);
+ _graphic.setNeedsRedraw(true);
+}
+
+void BitmapTextRecord::setText(const Common::String &text) {
+ _textKey = text;
+ _text = text;
+ if (_usesAutotext && !findText(text, _text)) {
+ _text = "Missing text: " + text;
+ }
+
+ _isDirty = true;
+}
+
+void BitmapTextRecord::draw() {
+ _layout.layout(_text, _dest.width(), _dest.height(), _overrideFontColor);
+
+ // The picture goes around the letters, wherever they are
+ Common::Rect area = _layout.getInkArea();
+ if (area.isEmpty()) {
+ area = Common::Rect(1, 1);
+ }
+
+ Graphics::ManagedSurface &surface = _graphic._drawSurface;
+ if (surface.w != area.width() || surface.h != area.height() || !surface.getPixels()) {
+ surface.create(area.width(), area.height(), g_nancy->_graphics->getTransparentPixelFormat());
+ }
+
+ surface.clear(0);
+ _layout.draw(surface, Common::Point(-area.left, -area.top), takeModColor(_modColor), _renderStart, _renderLength);
+ _inkOffset = Common::Point(area.left, area.top);
+ applyDest();
+}
+
+void BitmapTextRecord::onZChanged() {
+ _graphic.setScriptZ(getZ(), getContext());
+}
+
+void BitmapTextRecord::registerGraphics() {
+ _graphic.registerGraphics();
+}
+
+void BitmapTextRecord::updateGraphics() {
+ _graphic.setClipRect(getScreenClip());
+ _graphic.setVisible(isShown());
+
+ if (_isDirty || hasAlphaChanged()) {
+ _isDirty = false;
+ draw();
+ }
+}
+
+bool BitmapTextRecord::prepareReset() {
+ _dest = _initialDest;
+ applyDest();
+ return true;
+}
+
+bool BitmapTextRecord::getField(const Common::String &key) {
+ lua_State *L = getLua();
+
+ if (key == "onScreen") {
+ pushRect(L, _dest);
+ } else if (key == "text") {
+ lua_pushstring(L, _textKey.c_str());
+ } else if (key == "useAutotext") {
+ lua_pushboolean(L, _usesAutotext);
+ } else if (key == "overrideFontColor") {
+ if (_overrideFontColor >= 0) {
+ lua_pushinteger(L, _overrideFontColor);
+ } else {
+ lua_pushnil(L);
+ }
+ } else if (key == "modColor") {
+ pushColor(L, _modColor);
+ } else if (key == "renderStartIdx") {
+ lua_pushinteger(L, _renderStart);
+ } else if (key == "renderLen") {
+ lua_pushinteger(L, _renderLength);
+ } else if (key == "bounds") {
+ // Where the letters are on the screen
+ if (_isDirty) {
+ _layout.layout(_text, _dest.width(), _dest.height(), _overrideFontColor);
+ }
+
+ ScriptRect bounds = _layout.getBounds();
+ bounds.translate(_dest.left, _dest.top);
+ pushRect(L, bounds);
+ } else {
+ return false;
+ }
+
+ return true;
+}
+
+bool BitmapTextRecord::setField(const Common::String &key) {
+ lua_State *L = getLua();
+
+ if (key == "onScreen") {
+ _dest = checkRect(L, 3);
+ applyDest();
+ } else if (key == "text") {
+ setText(luaL_checkstring(L, 3));
+ } else if (key == "useAutotext") {
+ _usesAutotext = lua_toboolean(L, 3) != 0;
+ setText(_textKey);
+ } else if (key == "overrideFontColor") {
+ _overrideFontColor = lua_isnil(L, 3) ? -1 : luaL_checkint(L, 3);
+ } else if (key == "modColor") {
+ _modColor = checkColor(L, 3);
+ } else if (key == "renderStartIdx") {
+ _renderStart = luaL_checkint(L, 3);
+ } else if (key == "renderLen") {
+ _renderLength = luaL_checkint(L, 3);
+ } else {
+ return false;
+ }
+
+ _isDirty = true;
+ return true;
+}
+
+} // End of namespace Script
+} // End of namespace Nancy
diff --git a/engines/nancy/script/v5/textrecord.h b/engines/nancy/script/v5/textrecord.h
new file mode 100644
index 00000000000..e26e7627650
--- /dev/null
+++ b/engines/nancy/script/v5/textrecord.h
@@ -0,0 +1,77 @@
+/* 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 NANCY_SCRIPT_V5_TEXTRECORD_H
+#define NANCY_SCRIPT_V5_TEXTRECORD_H
+
+#include "engines/nancy/script/records.h"
+
+#include "engines/nancy/script/v5/bitmaptext.h"
+
+namespace Nancy {
+namespace Script {
+
+// Nancy26's Text record, which writes with the fonts made of pictures. The
+// text can be drawn in a color of its own, or with a part of its letters, and
+// scripts read where the letters ended up from "bounds".
+class BitmapTextRecord : public Record {
+public:
+ BitmapTextRecord(SceneContext &context) : Record(context, "ND.TextAR") {}
+
+ void updateGraphics() override;
+ void registerGraphics() override;
+
+protected:
+ void readTable(int tableIndex) override;
+ void onZChanged() override;
+ bool hasTransform() const override { return true; }
+ void onTransformChanged() override { applyDest(); }
+ bool prepareReset() override;
+ bool getField(const Common::String &key) override;
+ bool setField(const Common::String &key) override;
+
+private:
+ void setText(const Common::String &text);
+ void applyDest();
+ void draw();
+
+ BitmapText _layout;
+ RecordGraphic _graphic;
+ bool _isDirty = true;
+
+ ScriptRect _dest;
+ ScriptRect _initialDest; // what the record goes back to when it starts over
+ Common::Point _inkOffset; // where the picture of the letters is from the area
+
+ bool _usesAutotext = true;
+ Common::String _textKey; // what the text was set to
+ Common::String _text; // what it says
+
+ uint32 _modColor = 0xFFFFFFFF;
+ int _overrideFontColor = -1;
+ int _renderStart = 0;
+ int _renderLength = -1; // -1 for all of it
+};
+
+} // End of namespace Script
+} // End of namespace Nancy
+
+#endif // NANCY_SCRIPT_V5_TEXTRECORD_H
Commit: 0ad49eac1c0d3073e79ef5df2aa413446b244d64
https://github.com/scummvm/scummvm/commit/0ad49eac1c0d3073e79ef5df2aa413446b244d64
Author: Filippos Karapetis (bluegr at gmail.com)
Date: 2026-11-06T04:10:50+02:00
Commit Message:
NANCY: NANCY26: Hand the player's input to the records
Nancy26 hands the mouse and the keys to the records of all its streams
at once, the frontmost first, down to the first stream that keeps the
input to itself. The mouse is over one Hotspot at a time, which gets
the click, changes the cursor, and can change the scene. A Sink keeps
the input away from whatever is behind it. The keys go to the records
in the order of their keyZ, and the arrow keys turn the view.
The enhancement of the earlier games is kept: Esc skips the movies and
what the characters say, and opens the menu otherwise.
Changed paths:
A engines/nancy/script/v5/scriptinput.cpp
A engines/nancy/script/v5/scriptinput.h
A engines/nancy/script/v5/widgets.cpp
A engines/nancy/script/v5/widgets.h
engines/nancy/module.mk
engines/nancy/script/record.h
engines/nancy/script/records.cpp
engines/nancy/script/records.h
engines/nancy/script/v5/recordnode.cpp
engines/nancy/state/scene.cpp
engines/nancy/state/scene.h
diff --git a/engines/nancy/module.mk b/engines/nancy/module.mk
index 113e69358d7..49cc753fab4 100644
--- a/engines/nancy/module.mk
+++ b/engines/nancy/module.mk
@@ -245,8 +245,10 @@ MODULE_OBJS += \
script/v5/cliptransformer.o \
script/v5/messaging.o \
script/v5/recordnode.o \
+ script/v5/scriptinput.o \
script/v5/streamtree.o \
- script/v5/textrecord.o
+ script/v5/textrecord.o \
+ script/v5/widgets.o
endif
endif
diff --git a/engines/nancy/script/record.h b/engines/nancy/script/record.h
index 1940a1d2fb0..e6db5420b02 100644
--- a/engines/nancy/script/record.h
+++ b/engines/nancy/script/record.h
@@ -221,6 +221,23 @@ public:
// Nancy26: the record's own transform changed, by its stages or a script
virtual void onLocalTransformChanged();
+ // Nancy26: the records the mouse can be over, which take the clicks. The
+ // point is in the coordinates of the screen. A button is 0 for the left one
+ // and 1 for the right one.
+ virtual bool isMouseRegion() const { return false; }
+ virtual bool hitTest(const ScriptPoint &point) const { return false; }
+ virtual void setMouseOver(bool isOver) {}
+ virtual bool pressRegion(int button) { return false; } // returns whether it took the click
+ virtual void releaseRegion(int button) {}
+ virtual bool getRegionCursor(uint &cursorType, bool &isHot) const { return false; }
+
+ // Nancy26: whether the keys go no further than this record
+ virtual bool capturesKeys() const { return false; }
+
+ // Nancy26: a key that went down, for the records that type; returns
+ // whether the record took it
+ virtual bool handleKey(Common::KeyCode key, uint16 ascii) { return false; }
+
// Nancy26: the name the record goes by of its own, and the one its
// messages come from
const Common::String &getUniqueAlias() const;
diff --git a/engines/nancy/script/records.cpp b/engines/nancy/script/records.cpp
index 04755e2618d..8b54661d596 100644
--- a/engines/nancy/script/records.cpp
+++ b/engines/nancy/script/records.cpp
@@ -51,6 +51,7 @@
#include "engines/nancy/script/v5/cliptransformer.h"
#include "engines/nancy/script/v5/streamtree.h"
#include "engines/nancy/script/v5/textrecord.h"
+#include "engines/nancy/script/v5/widgets.h"
#endif
#include "engines/nancy/state/scene.h"
@@ -81,7 +82,14 @@ static const RecordKindNames kRecordKindNames[kNumRecordKinds] = {
{ "Physics", "ND.PhysicsAR" },
{ "Xsheet", "ND.XsheetAR" },
{ "Transformer", "ND.TransformerAR" },
- { "Timer", "ND.TimerAR" }
+ { "Timer", "ND.TimerAR" },
+ { "Hotspot", "ND.Hotspot" },
+ { "Sink", "ND.SinkAR" },
+ { "Button", "ND.ButtonAR" },
+ { "EditBox", "ND.EditBoxAR" },
+ { "RadioButton", "ND.RadioButton" },
+ { "CheckBox", "ND.CheckBox" },
+ { "Slider", "ND.Slider" }
};
const char *getRecordKindName(RecordKind kind) {
@@ -95,7 +103,20 @@ const char *getRecordTypeName(RecordKind kind) {
Record *makeRecord(RecordKind kind, SceneContext &context) {
switch (kind) {
case kRecordNavLogic:
+#ifdef ENABLE_NANCY_V5
+ // Nancy26's NavLogic is another name for a Hotspot
+ if (g_nancy->getGameType() >= kGameTypeNancy26) {
+ return new HotspotRecord(context);
+ }
+#endif
+
return new NavLogicRecord(context);
+#ifdef ENABLE_NANCY_V5
+ case kRecordHotspot:
+ return new HotspotRecord(context);
+ case kRecordSink:
+ return new SinkRecord(context);
+#endif
case kRecordSummary:
return new SummaryRecord(context);
case kRecordOverlay:
@@ -630,6 +651,40 @@ bool SummaryRecord::onMouseEvent(RecordEvent event, const ScriptPoint &point, bo
}
}
+#ifdef ENABLE_NANCY_V5
+bool SummaryRecord::turnByKey(Common::KeyCode key) {
+ if (_numFrames <= 1 || !_canRotate) {
+ return false;
+ }
+
+ switch (key) {
+ case Common::KEYCODE_LEFT:
+ if (!canTurn(kTurnLeft)) {
+ return false;
+ }
+
+ setFrame((_frame + 1) % _numFrames);
+ return true;
+ case Common::KEYCODE_RIGHT:
+ if (!canTurn(kTurnRight)) {
+ return false;
+ }
+
+ setFrame((_frame + _numFrames - 1) % _numFrames);
+ return true;
+ case Common::KEYCODE_DOWN:
+ if (!_hasUturn) {
+ return false;
+ }
+
+ setFrame((_frame + _numFrames / 2) % _numFrames);
+ return true;
+ default:
+ return false;
+ }
+}
+#endif
+
void SummaryRecord::run(double sceneTime, double elapsedTime) {
_sceneTime = sceneTime;
updateTheme(sceneTime);
diff --git a/engines/nancy/script/records.h b/engines/nancy/script/records.h
index 03d420903f2..8078a83022d 100644
--- a/engines/nancy/script/records.h
+++ b/engines/nancy/script/records.h
@@ -61,8 +61,15 @@ enum RecordKind {
kRecordXsheet = 12, // Nancy22
kRecordTransformer = 13, // Nancy22
kRecordTimer = 14, // Nancy24
-
- kNumRecordKinds = 15
+ kRecordHotspot = 15, // Nancy26
+ kRecordSink = 16,
+ kRecordButton = 17,
+ kRecordEditBox = 18,
+ kRecordRadioButton = 19,
+ kRecordCheckBox = 20,
+ kRecordSlider = 21,
+
+ kNumRecordKinds = 22
};
// What scripts call the kind ("NavLogic"), and the type of its objects ("ND.NavLogic")
@@ -123,6 +130,12 @@ public:
// The viewport that shows the background, once it has been loaded
void setBackground(UI::Viewport *background);
+#ifdef ENABLE_NANCY_V5
+ // Nancy26: the left and right arrow keys turn the view, and the down
+ // arrow turns it around. Returns whether the key did something.
+ bool turnByKey(Common::KeyCode key);
+#endif
+
void registerGraphics() override;
protected:
diff --git a/engines/nancy/script/v5/recordnode.cpp b/engines/nancy/script/v5/recordnode.cpp
index 9eb7c7a1b12..21e29acdcc5 100644
--- a/engines/nancy/script/v5/recordnode.cpp
+++ b/engines/nancy/script/v5/recordnode.cpp
@@ -32,6 +32,7 @@
#include "engines/nancy/script/v5/cliptransformer.h"
#include "engines/nancy/script/v5/messaging.h"
#include "engines/nancy/script/v5/recordnode.h"
+#include "engines/nancy/script/v5/scriptinput.h"
namespace Nancy {
namespace Script {
@@ -50,6 +51,7 @@ void Record::destroyNodeState() {
}
deregisterAliases(this);
+ forgetInputRecord(this);
delete _nodeState;
_nodeState = nullptr;
}
diff --git a/engines/nancy/script/v5/scriptinput.cpp b/engines/nancy/script/v5/scriptinput.cpp
new file mode 100644
index 00000000000..7899e7c6eea
--- /dev/null
+++ b/engines/nancy/script/v5/scriptinput.cpp
@@ -0,0 +1,497 @@
+/* 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 "common/algorithm.h"
+#include "common/system.h"
+
+#include "engines/nancy/cursor.h"
+#include "engines/nancy/input.h"
+#include "engines/nancy/nancy.h"
+
+#include "engines/nancy/script/api.h"
+#include "engines/nancy/script/luabind.h"
+#include "engines/nancy/script/records.h"
+#include "engines/nancy/script/scenecontext.h"
+
+#include "engines/nancy/script/v5/scriptinput.h"
+#include "engines/nancy/script/v5/widgets.h"
+
+#include "engines/nancy/state/scene.h"
+
+namespace Nancy {
+namespace Script {
+
+static const uint32 kDoubleClickTime = 500; // milliseconds
+static const int kDoubleClickDistance = 4;
+
+struct InputState {
+ ScriptPoint mouse;
+ bool hasMouse = false;
+ Record *hovered = nullptr;
+ Record *pressed[2] = { nullptr, nullptr };
+
+ uint32 lastClickTime[2] = { 0, 0 };
+ ScriptPoint lastClickPoint[2];
+ bool isDoubleClick[2] = { false, false };
+
+ uint16 heldMoveKeys = 0;
+ bool isEscHeld = false;
+ Common::Array<Common::KeyCode> keysToRelease;
+};
+
+static InputState &getState() {
+ static InputState s_state;
+ return s_state;
+}
+
+const ScriptPoint &getScriptMousePoint() {
+ return getState().mouse;
+}
+
+bool isDoubleClick(int button) {
+ return getState().isDoubleClick[button];
+}
+
+void forgetInputRecord(Record *record) {
+ InputState &state = getState();
+ if (state.hovered == record) {
+ state.hovered = nullptr;
+ }
+
+ for (int i = 0; i < 2; ++i) {
+ if (state.pressed[i] == record) {
+ state.pressed[i] = nullptr;
+ }
+ }
+}
+
+static bool isFrontmost(const Record *a, const Record *b) {
+ return a->getZ() > b->getZ();
+}
+
+// The enabled records of every stream that gets input, the frontmost first
+static void collectRecords(Common::Array<Record *> &records) {
+ records.clear();
+
+ Common::Array<State::SceneStream *> streams;
+ NancySceneState.getStreams().getDrawOrder(streams);
+
+ // A stream that keeps the input does so from the streams below it in its
+ // own tree; the UI's tree is in front of the viewport's
+ bool isTreeCaptured[2] = { false, false };
+
+ for (int i = (int)streams.size() - 1; i >= 0; --i) {
+ const Script::StreamNodeState &state = streams[i] ? streams[i]->getNodeState() : *NancySceneState.getStreams().getNodeState(State::SceneStreamManager::getMainStreamName());
+ bool &isCaptured = isTreeCaptured[state.isInViewport ? 1 : 0];
+ if (isCaptured) {
+ continue;
+ }
+
+ const SceneContext *context = streams[i] ? streams[i]->getScriptScene() : NancySceneState.getScriptScene();
+ if (context) {
+ // Of two records at the same z, the one made later is in front
+ Common::Array<Record *> streamRecords;
+ const Common::Array<Record *> &contextRecords = context->getRecords();
+ for (int j = (int)contextRecords.size() - 1; j >= 0; --j) {
+ if (contextRecords[j]->isNodeEnabled()) {
+ streamRecords.push_back(contextRecords[j]);
+ }
+ }
+
+ Common::sort(streamRecords.begin(), streamRecords.end(), isFrontmost);
+ for (Record *record : streamRecords) {
+ records.push_back(record);
+ }
+ }
+
+ if (streams[i] && streams[i]->getFlags().capturesInput) {
+ isCaptured = true;
+ }
+ }
+}
+
+// Calls a function an Override has for the input, and returns whether it took it
+static bool callInputFunction(Record *record, const char *name, int numArgs = 0) {
+ lua_State *L = record->getContext().getLua();
+ if (!record->callFunction(name, numArgs, 1)) {
+ return false;
+ }
+
+ const bool isTaken = lua_toboolean(L, -1) != 0;
+ lua_pop(L, 1);
+ return isTaken;
+}
+
+static bool isOverride(Record *record) {
+ return dynamic_cast<OverrideRecord *>(record) != nullptr;
+}
+
+static void updateHover(const Common::Array<Record *> &records) {
+ InputState &state = getState();
+
+ Record *hovered = nullptr;
+ Record *pressed = state.pressed[0] ? state.pressed[0] : state.pressed[1];
+ if (pressed) {
+ // A hotspot that is held down is the only one the mouse can be over
+ if (state.hasMouse && pressed->hitTest(state.mouse)) {
+ hovered = pressed;
+ }
+ } else if (state.hasMouse) {
+ for (Record *record : records) {
+ if (record->isMouseRegion() && record->hitTest(state.mouse)) {
+ hovered = record;
+ break;
+ }
+ }
+ }
+
+ if (hovered == state.hovered) {
+ return;
+ }
+
+ Record *left = state.hovered;
+ state.hovered = hovered;
+ if (left) {
+ left->setMouseOver(false);
+ }
+
+ if (hovered) {
+ hovered->setMouseOver(true);
+ }
+}
+
+static void updateCursor(const Common::Array<Record *> &records) {
+ InputState &state = getState();
+ CursorManager &cursor = *g_nancy->_cursor;
+
+ // A hotspot that is held down picks the cursor wherever the mouse is
+ Record *pressed = state.pressed[0] ? state.pressed[0] : state.pressed[1];
+ uint pressedType = 0;
+ bool isPressedHot = false;
+ if (pressed && pressed->getRegionCursor(pressedType, isPressedHot)) {
+ cursor.setCursorType((CursorManager::CursorType)pressedType, true, isPressedHot);
+ return;
+ }
+
+ for (Record *record : records) {
+ uint cursorType = 0;
+ bool isHot = false;
+
+ if (record == state.hovered) {
+ if (record->getRegionCursor(cursorType, isHot)) {
+ cursor.setCursorType((CursorManager::CursorType)cursorType, true, isHot);
+ return;
+ }
+
+ break;
+ }
+
+ if (isOverride(record)) {
+ lua_State *L = record->getContext().getLua();
+ if (!record->callFunction("ChangeCursor", 0, 1)) {
+ continue;
+ }
+
+ bool hasCursor = false;
+ if (lua_type(L, -1) == LUA_TSTRING) {
+ const int type = cursor.getCursorTypeByName(lua_tostring(L, -1));
+ hasCursor = type >= 0;
+ cursorType = MAX(type, 0);
+ } else {
+ hasCursor = testCursor(L, -1, cursorType, isHot);
+ }
+
+ lua_pop(L, 1);
+ if (hasCursor) {
+ cursor.setCursorType((CursorManager::CursorType)cursorType, true, isHot);
+ return;
+ }
+
+ continue;
+ }
+
+ SummaryRecord *summary = dynamic_cast<SummaryRecord *>(record);
+ if (summary && state.hasMouse && summary->sendChangeCursor(state.mouse, true, cursorType, isHot)) {
+ cursor.setCursorType((CursorManager::CursorType)cursorType, true, isHot);
+ return;
+ }
+ }
+
+ cursor.setCursorType(CursorManager::kNormal);
+}
+
+static void pressButton(const Common::Array<Record *> &records, int button) {
+ InputState &state = getState();
+
+ // Two clicks close together in time and place are a double click
+ const uint32 now = g_system->getMillis();
+ state.isDoubleClick[button] = now - state.lastClickTime[button] < kDoubleClickTime &&
+ ABS(state.mouse.x - state.lastClickPoint[button].x) <= kDoubleClickDistance &&
+ ABS(state.mouse.y - state.lastClickPoint[button].y) <= kDoubleClickDistance;
+ state.lastClickTime[button] = state.isDoubleClick[button] ? 0 : now;
+ state.lastClickPoint[button] = state.mouse;
+
+ for (Record *record : records) {
+ if (record == state.hovered) {
+ if (record->pressRegion(button)) {
+ state.pressed[button] = record;
+ return;
+ }
+
+ continue;
+ }
+
+ if (isOverride(record)) {
+ if (callInputFunction(record, button == 0 ? "OnLeftDown" : "OnRightDown")) {
+ return;
+ }
+
+ continue;
+ }
+
+ SummaryRecord *summary = dynamic_cast<SummaryRecord *>(record);
+ if (summary && summary->sendMouseEvent(button == 0 ? kEventLeftDown : kEventRightDown, state.mouse, true)) {
+ return;
+ }
+ }
+}
+
+static void releaseButton(const Common::Array<Record *> &records, int button) {
+ InputState &state = getState();
+
+ Record *pressed = state.pressed[button];
+ if (pressed) {
+ state.pressed[button] = nullptr;
+ pressed->releaseRegion(button);
+ return;
+ }
+
+ for (Record *record : records) {
+ if (isOverride(record)) {
+ if (callInputFunction(record, button == 0 ? "OnLeftUp" : "OnRightUp")) {
+ return;
+ }
+
+ continue;
+ }
+
+ SummaryRecord *summary = dynamic_cast<SummaryRecord *>(record);
+ if (summary) {
+ summary->sendMouseEvent(button == 0 ? kEventLeftUp : kEventRightUp, state.mouse, true);
+ if (button == 0 && summary->sendMouseEvent(kEventLeftClick, state.mouse, true)) {
+ return;
+ }
+ }
+ }
+}
+
+static void scrollWheel(const Common::Array<Record *> &records, int notches) {
+ InputState &state = getState();
+
+ for (Record *record : records) {
+ if (isOverride(record)) {
+ lua_pushinteger(record->getContext().getLua(), notches);
+ if (callInputFunction(record, "OnMouseScroll", 1)) {
+ return;
+ }
+ }
+ }
+}
+
+static bool isKeyFrontmost(const Record *a, const Record *b) {
+ return a->getKeyZ() > b->getKeyZ();
+}
+
+static bool isMoveKey(Common::KeyCode key) {
+ return key == Common::KEYCODE_LEFT || key == Common::KEYCODE_RIGHT ||
+ key == Common::KEYCODE_UP || key == Common::KEYCODE_DOWN;
+}
+
+// A key goes to the records by their keyZ; ones at the same keyZ in the order
+// the mouse goes by
+static void sendKey(const Common::Array<Record *> &records, Common::KeyCode key, bool isDown, uint16 ascii) {
+ Common::Array<Record *> keyOrder = records;
+ Common::sort(keyOrder.begin(), keyOrder.end(), isKeyFrontmost);
+
+ for (Record *record : keyOrder) {
+ if (record->capturesKeys() || (isDown && record->handleKey(key, ascii))) {
+ return;
+ }
+
+ if (isOverride(record)) {
+ pushKey(record->getContext().getLua(), key);
+ if (callInputFunction(record, isDown ? "OnKeyDown" : "OnKeyUp", 1)) {
+ return;
+ }
+
+ // A typed letter comes as text as well
+ if (isDown && ascii >= 32 && ascii < 127) {
+ const char text[2] = { (char)ascii, '\0' };
+ lua_pushstring(record->getContext().getLua(), text);
+ if (callInputFunction(record, "OnChar", 1)) {
+ return;
+ }
+ }
+
+ // The scripts can keep the arrow keys from turning the view
+ if (isDown && isMoveKey(key) && callInputFunction(record, "OnKeyMove")) {
+ return;
+ }
+
+ continue;
+ }
+
+ SummaryRecord *summary = dynamic_cast<SummaryRecord *>(record);
+ if (summary && isDown && summary->turnByKey(key)) {
+ return;
+ }
+ }
+}
+
+struct MoveKey {
+ uint16 input;
+ Common::KeyCode key;
+};
+
+// The arrow keys are bound to moving around, and Esc to the menu
+static const MoveKey kMoveKeys[] = {
+ { NancyInput::kMoveLeft, Common::KEYCODE_LEFT },
+ { NancyInput::kMoveRight, Common::KEYCODE_RIGHT },
+ { NancyInput::kMoveUp, Common::KEYCODE_UP },
+ { NancyInput::kMoveDown, Common::KEYCODE_DOWN }
+};
+
+void handleNancy26Input(NancyInput &input) {
+ InputState &state = getState();
+
+ const ScriptPoint oldMouse = state.mouse;
+ state.hasMouse = input.mousePos.x >= 0;
+ if (state.hasMouse) {
+ state.mouse = ScriptPoint(input.mousePos);
+ }
+
+ state.isDoubleClick[0] = state.isDoubleClick[1] = false;
+
+ Common::Array<Record *> records;
+ collectRecords(records);
+
+ updateHover(records);
+
+ // Overrides follow the mouse with OnMouseMove and get OnNewFrame every frame
+ const bool hasMoved = state.mouse.x != oldMouse.x || state.mouse.y != oldMouse.y;
+ for (Record *record : records) {
+ if (isOverride(record)) {
+ if (hasMoved) {
+ record->callFunction("OnMouseMove");
+ }
+
+ record->callFunction("OnNewFrame");
+ } else if (hasMoved && dynamic_cast<SummaryRecord *>(record)) {
+ record->sendMouseMove(state.mouse, true);
+ }
+ }
+
+ if (input.input & NancyInput::kLeftMouseButtonDown) {
+ pressButton(records, 0);
+ }
+
+ if (input.input & NancyInput::kRightMouseButtonDown) {
+ pressButton(records, 1);
+ }
+
+ if (input.input & NancyInput::kLeftMouseButtonUp) {
+ releaseButton(records, 0);
+ }
+
+ if (input.input & NancyInput::kRightMouseButtonUp) {
+ releaseButton(records, 1);
+ }
+
+ if (input.input & NancyInput::kMouseWheel) {
+ scrollWheel(records, (input.input & NancyInput::kMouseWheelUp) ? 1 : -1);
+ }
+
+ // What the clicks did can move the mouse onto something else
+ collectRecords(records);
+ updateHover(records);
+ updateCursor(records);
+
+ // The keys that went down last frame have no release of their own
+ const Common::Array<Common::KeyCode> keysToRelease = state.keysToRelease;
+ state.keysToRelease.clear();
+ for (Common::KeyCode key : keysToRelease) {
+ sendKey(records, key, false, 0);
+ }
+
+ for (const MoveKey &moveKey : kMoveKeys) {
+ const bool isHeld = (input.input & moveKey.input) != 0;
+ const bool wasHeld = (state.heldMoveKeys & moveKey.input) != 0;
+ if (isHeld != wasHeld) {
+ sendKey(records, moveKey.key, isHeld, 0);
+ }
+ }
+
+ state.heldMoveKeys = input.input;
+
+ const bool isEscHeld = (input.input & NancyInput::kOpenMainMenu) != 0;
+ if (isEscHeld != state.isEscHeld) {
+ sendKey(records, Common::KEYCODE_ESCAPE, isEscHeld, 0);
+ state.isEscHeld = isEscHeld;
+ }
+
+ for (const Common::KeyState &key : input.otherKbdInput) {
+ sendKey(records, key.keycode, true, key.ascii);
+ state.keysToRelease.push_back(key.keycode);
+ }
+}
+
+} // End of namespace Script
+
+namespace State {
+
+// Nancy26's records take care of all the input themselves. Esc opens the menu
+// through them, unless it skips the movies that play or what the characters
+// say; that press then stays away from them until it is let go.
+void Scene::handleNancy26Input(NancyInput &input) {
+ const bool escPressed = (input.input & NancyInput::kOpenMainMenu) != 0;
+ if (escPressed && !_escHeld && _scriptScene) {
+ bool hasSkipped = _scriptScene->skipMovies();
+ hasSkipped |= _streams.skipMovies();
+ if (!hasSkipped) {
+ hasSkipped = _scriptScene->skipSpeech();
+ hasSkipped |= _streams.skipSpeech();
+ }
+
+ _isEscSkipping = hasSkipped;
+ } else if (!escPressed) {
+ _isEscSkipping = false;
+ }
+
+ _escHeld = escPressed;
+ if (_isEscSkipping) {
+ input.input &= ~NancyInput::kOpenMainMenu;
+ }
+
+ Script::handleNancy26Input(input);
+}
+
+} // End of namespace State
+} // End of namespace Nancy
diff --git a/engines/nancy/script/v5/scriptinput.h b/engines/nancy/script/v5/scriptinput.h
new file mode 100644
index 00000000000..8d465dfa1c9
--- /dev/null
+++ b/engines/nancy/script/v5/scriptinput.h
@@ -0,0 +1,55 @@
+/* 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 NANCY_SCRIPT_V5_SCRIPTINPUT_H
+#define NANCY_SCRIPT_V5_SCRIPTINPUT_H
+
+#include "engines/nancy/script/types.h"
+
+namespace Nancy {
+
+struct NancyInput;
+
+namespace Script {
+
+class Record;
+
+// Nancy26 hands the player's input to the records of all the streams at once,
+// the frontmost first, as far down as the first stream that keeps the input to
+// itself. The mouse is over the frontmost hotspot it is on, which gets a click;
+// while a button is down, the mouse stays with the hotspot it went down on.
+// The functions Overrides have for the mouse and the keys get called in the
+// same order, until one of them returns true; the keys go by keyZ, though.
+void handleNancy26Input(NancyInput &input);
+
+// Where the mouse is, in screen coordinates
+const ScriptPoint &getScriptMousePoint();
+
+// Whether a button was just clicked twice in a row; 0 is the left one
+bool isDoubleClick(int button);
+
+// A record that goes away can't keep the mouse
+void forgetInputRecord(Record *record);
+
+} // End of namespace Script
+} // End of namespace Nancy
+
+#endif // NANCY_SCRIPT_V5_SCRIPTINPUT_H
diff --git a/engines/nancy/script/v5/widgets.cpp b/engines/nancy/script/v5/widgets.cpp
new file mode 100644
index 00000000000..b859477b5af
--- /dev/null
+++ b/engines/nancy/script/v5/widgets.cpp
@@ -0,0 +1,378 @@
+/* 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 "common/events.h"
+#include "common/system.h"
+
+#include "engines/nancy/cursor.h"
+#include "engines/nancy/graphics.h"
+#include "engines/nancy/nancy.h"
+
+#include "engines/nancy/script/api.h"
+#include "engines/nancy/script/graphnode.h"
+#include "engines/nancy/script/luabind.h"
+#include "engines/nancy/script/luastate.h"
+#include "engines/nancy/script/mathtypes.h"
+#include "engines/nancy/script/ref.h"
+#include "engines/nancy/script/scenecontext.h"
+
+#include "engines/nancy/script/v5/scriptinput.h"
+#include "engines/nancy/script/v5/widgets.h"
+
+namespace Nancy {
+namespace Script {
+
+// Nancy26 names its cursors with strings ("MenuHot")
+static bool readCursorValue(lua_State *L, int index, uint &cursorType, bool &isHot) {
+ if (lua_type(L, index) == LUA_TSTRING) {
+ const int type = g_nancy->_cursor->getCursorTypeByName(lua_tostring(L, index));
+ if (type < 0) {
+ return false;
+ }
+
+ cursorType = type;
+ isHot = false;
+ return true;
+ }
+
+ return testCursor(L, index, cursorType, isHot);
+}
+
+// HotspotRecord
+
+void HotspotRecord::readCursorField(int valueIndex, Cursor &cursor) {
+ cursor.isSet = readCursorValue(getLua(), valueIndex, cursor.type, cursor.isHot);
+}
+
+void HotspotRecord::pushCursorField(const Cursor &cursor) {
+ if (cursor.isSet) {
+ pushCursor(getLua(), cursor.type, cursor.isHot);
+ } else {
+ lua_pushnil(getLua());
+ }
+}
+
+void HotspotRecord::readTable(int tableIndex) {
+ lua_State *L = getLua();
+
+ if (pushField(L, tableIndex, "onScreen")) {
+ _onScreen = checkRect(L, -1);
+ lua_pop(L, 1);
+ }
+
+ readField(L, tableIndex, "scene", _sceneName);
+ readField(L, tableIndex, "frame", _frame);
+ readField(L, tableIndex, "stream", _streamName);
+ readField(L, tableIndex, "watchLeft", _watchesLeft);
+ readField(L, tableIndex, "watchRight", _watchesRight);
+
+ static const char *const kCursorNames[] = { "cursor", "startCursor", "downCursor", "dragOnCursor", "dragOffCursor" };
+ Cursor *const cursors[] = { &_cursor, &_startCursor, &_downCursor, &_dragOnCursor, &_dragOffCursor };
+ for (uint i = 0; i < ARRAYSIZE(kCursorNames); ++i) {
+ if (pushField(L, tableIndex, kCursorNames[i])) {
+ readCursorField(-1, *cursors[i]);
+ lua_pop(L, 1);
+ }
+ }
+
+ Common::String refName;
+ if (readField(L, tableIndex, "ref", refName) && !refName.empty()) {
+ _ref = getContext().loadRef(refName);
+ }
+
+ if (pushField(L, tableIndex, "refColor")) {
+ _refColor = checkColor(L, -1);
+ _hasRefColor = true;
+ lua_pop(L, 1);
+ }
+
+ if (pushField(L, tableIndex, "source")) {
+ _source = checkRect(L, -1);
+ lua_pop(L, 1);
+ }
+}
+
+bool HotspotRecord::hitTest(const ScriptPoint &point) const {
+ double x = point.x;
+ double y = point.y;
+ getTransform().inverse().transformPoint(x, y);
+
+ int refX = (int)floor(x);
+ int refY = (int)floor(y);
+ if (!_ref) {
+ return _onScreen.contains(refX, refY);
+ }
+
+ if (!_source.isEmpty() || !_onScreen.isEmpty()) {
+ if (!_onScreen.contains(refX, refY)) {
+ return false;
+ }
+
+ refX += _source.left - _onScreen.left;
+ refY += _source.top - _onScreen.top;
+ }
+
+ uint32 pixel;
+ if (!_ref->getPixel(refX, refY, pixel)) {
+ return false;
+ }
+
+ return _hasRefColor ? pixel == _refColor : (pixel >> 24) != 0;
+}
+
+void HotspotRecord::setMouseOver(bool isOver) {
+ if (isOver == _isMouseOver) {
+ return;
+ }
+
+ _isMouseOver = isOver;
+ callFunction(isOver ? "OnMouseOver" : "OnMouseLeave");
+}
+
+bool HotspotRecord::pressRegion(int button) {
+ if (!(button == 0 ? _watchesLeft : _watchesRight)) {
+ return false;
+ }
+
+ _pressedButton = button;
+ callFunction(button == 0 ? "OnLeftDown" : "OnRightDown");
+
+ return true;
+}
+
+// A button that comes up over the hotspot clicks it; anywhere else, the
+// hotspot only lets go of the mouse
+void HotspotRecord::releaseRegion(int button) {
+ if (_pressedButton != button) {
+ return;
+ }
+
+ _pressedButton = -1;
+
+ if (!_isMouseOver) {
+ callFunction("OnLoseMouseFocus");
+
+ return;
+ }
+
+ callFunction(button == 0 ? "OnLeftUp" : "OnRightUp");
+ fire();
+}
+
+void HotspotRecord::fire() {
+ if (!_sceneName.empty()) {
+ getContext().changeScene(_streamName, _sceneName, (uint16)_frame);
+ }
+
+ finish();
+}
+
+bool HotspotRecord::getRegionCursor(uint &cursorType, bool &isHot) const {
+ const Cursor *cursor = &_cursor;
+ if (_pressedButton >= 0) {
+ cursor = _isMouseOver ? &_downCursor : &_dragOffCursor;
+ } else if (g_nancy->_cursor->isHoldingItem() && _startCursor.isSet) {
+ cursor = &_startCursor;
+ }
+
+ if (!cursor->isSet) {
+ cursor = &_cursor;
+ }
+
+ if (!cursor->isSet) {
+ return false;
+ }
+
+ cursorType = cursor->type;
+ isHot = cursor->isHot;
+ return true;
+}
+
+bool HotspotRecord::prepareReset() {
+ _pressedButton = -1;
+ return true;
+}
+
+bool HotspotRecord::getField(const Common::String &key) {
+ lua_State *L = getLua();
+
+ if (key == "onScreen") {
+ pushRect(L, _onScreen);
+ } else if (key == "scene") {
+ lua_pushstring(L, _sceneName.c_str());
+ } else if (key == "stream") {
+ lua_pushstring(L, _streamName.c_str());
+ } else if (key == "frame") {
+ lua_pushinteger(L, _frame);
+ } else if (key == "watchLeft") {
+ lua_pushboolean(L, _watchesLeft);
+ } else if (key == "watchRight") {
+ lua_pushboolean(L, _watchesRight);
+ } else if (key == "down") {
+ lua_pushboolean(L, isDown());
+ } else if (key == "mouseOver") {
+ lua_pushboolean(L, _isMouseOver);
+ } else if (key == "cursor") {
+ pushCursorField(_cursor);
+ } else if (key == "startCursor") {
+ pushCursorField(_startCursor);
+ } else if (key == "downCursor") {
+ pushCursorField(_downCursor);
+ } else if (key == "dragOnCursor") {
+ pushCursorField(_dragOnCursor);
+ } else if (key == "dragOffCursor") {
+ pushCursorField(_dragOffCursor);
+ } else if (key == "refColor" && _hasRefColor) {
+ pushColor(L, _refColor);
+ } else if (key == "source") {
+ pushRect(L, _source);
+ } else {
+ return false;
+ }
+
+ return true;
+}
+
+bool HotspotRecord::setField(const Common::String &key) {
+ lua_State *L = getLua();
+
+ if (key == "onScreen") {
+ _onScreen = checkRect(L, 3);
+ } else if (key == "scene") {
+ _sceneName = luaL_checkstring(L, 3);
+ } else if (key == "stream") {
+ _streamName = luaL_checkstring(L, 3);
+ } else if (key == "frame") {
+ _frame = luaL_checkint(L, 3);
+ } else if (key == "watchLeft") {
+ _watchesLeft = lua_toboolean(L, 3) != 0;
+ } else if (key == "watchRight") {
+ _watchesRight = lua_toboolean(L, 3) != 0;
+ } else if (key == "cursor") {
+ readCursorField(3, _cursor);
+ } else if (key == "startCursor") {
+ readCursorField(3, _startCursor);
+ } else if (key == "downCursor") {
+ readCursorField(3, _downCursor);
+ } else if (key == "dragOnCursor") {
+ readCursorField(3, _dragOnCursor);
+ } else if (key == "dragOffCursor") {
+ readCursorField(3, _dragOffCursor);
+ } else if (key == "ref") {
+ _ref = lua_isnil(L, 3) ? nullptr : getContext().loadRef(luaL_checkstring(L, 3));
+ } else if (key == "refColor") {
+ _hasRefColor = !lua_isnil(L, 3);
+ if (_hasRefColor) {
+ _refColor = checkColor(L, 3);
+ }
+ } else if (key == "source") {
+ _source = checkRect(L, 3);
+ } else {
+ return false;
+ }
+
+ return true;
+}
+
+// SinkRecord
+
+void SinkRecord::readTable(int tableIndex) {
+ lua_State *L = getLua();
+
+ // The whole viewport, unless the table says otherwise
+ const VIEW *viewport = GetEngineData(VIEW);
+ if (viewport) {
+ _onScreen = ScriptRect(0, 0, viewport->screenPosition.width(), viewport->screenPosition.height());
+ }
+
+ if (pushField(L, tableIndex, "onScreen")) {
+ _onScreen = checkRect(L, -1);
+ lua_pop(L, 1);
+ }
+
+ readField(L, tableIndex, "handleKeys", _handlesKeys);
+ readField(L, tableIndex, "handleMouse", _handlesMouse);
+
+ if (pushField(L, tableIndex, "cursor")) {
+ _hasCursor = readCursorValue(L, -1, _cursorType, _cursorIsHot);
+ lua_pop(L, 1);
+ }
+}
+
+bool SinkRecord::hitTest(const ScriptPoint &point) const {
+ double x = point.x;
+ double y = point.y;
+ getTransform().inverse().transformPoint(x, y);
+ return _onScreen.contains((int)floor(x), (int)floor(y));
+}
+
+bool SinkRecord::getRegionCursor(uint &cursorType, bool &isHot) const {
+ if (!_hasCursor) {
+ return false;
+ }
+
+ cursorType = _cursorType;
+ isHot = _cursorIsHot;
+ return true;
+}
+
+bool SinkRecord::getField(const Common::String &key) {
+ lua_State *L = getLua();
+
+ if (key == "onScreen") {
+ pushRect(L, _onScreen);
+ } else if (key == "handleKeys") {
+ lua_pushboolean(L, _handlesKeys);
+ } else if (key == "handleMouse") {
+ lua_pushboolean(L, _handlesMouse);
+ } else if (key == "cursor") {
+ if (_hasCursor) {
+ pushCursor(L, _cursorType, _cursorIsHot);
+ } else {
+ lua_pushnil(L);
+ }
+ } else {
+ return false;
+ }
+
+ return true;
+}
+
+bool SinkRecord::setField(const Common::String &key) {
+ lua_State *L = getLua();
+
+ if (key == "onScreen") {
+ _onScreen = checkRect(L, 3);
+ } else if (key == "handleKeys") {
+ _handlesKeys = lua_toboolean(L, 3) != 0;
+ } else if (key == "handleMouse") {
+ _handlesMouse = lua_toboolean(L, 3) != 0;
+ } else if (key == "cursor") {
+ _hasCursor = readCursorValue(L, 3, _cursorType, _cursorIsHot);
+ } else {
+ return false;
+ }
+
+ return true;
+}
+
+} // End of namespace Script
+} // End of namespace Nancy
diff --git a/engines/nancy/script/v5/widgets.h b/engines/nancy/script/v5/widgets.h
new file mode 100644
index 00000000000..0686d0d6fda
--- /dev/null
+++ b/engines/nancy/script/v5/widgets.h
@@ -0,0 +1,127 @@
+/* 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 NANCY_SCRIPT_V5_WIDGETS_H
+#define NANCY_SCRIPT_V5_WIDGETS_H
+
+#include "engines/nancy/script/records.h"
+#include "engines/nancy/script/types.h"
+
+namespace Nancy {
+namespace Script {
+
+struct RefImage;
+
+// Nancy26's place on the screen the mouse can be over and click, which NavLogic
+// records are as well. The player's input goes to the hotspot the mouse is over
+// that is closest; while a button is down, it stays with the one it went down on.
+// A hotspot calls OnLeftDown and OnLeftUp (or the right ones) of its scripts,
+// and OnMouseOver, OnMouseLeave and OnLoseMouseFocus. Once it was clicked, it
+// changes the scene when it has one, and is done.
+// The shape is a rect, or the part of a Ref image that isn't see-through or has
+// a color; the rect and the source then lay the image over the screen.
+class HotspotRecord : public Record {
+public:
+ HotspotRecord(SceneContext &context) : Record(context, "ND.Hotspot") {}
+
+ bool isMouseRegion() const override { return true; }
+ bool hitTest(const ScriptPoint &point) const override;
+ void setMouseOver(bool isOver) override;
+ bool pressRegion(int button) override;
+ void releaseRegion(int button) override;
+ bool getRegionCursor(uint &cursorType, bool &isHot) const override;
+
+ bool isMouseOver() const { return _isMouseOver; }
+ bool isDown() const { return _pressedButton >= 0; }
+ const ScriptRect &getOnScreen() const { return _onScreen; }
+
+protected:
+ void readTable(int tableIndex) override;
+ bool prepareReset() override;
+ bool hasTransform() const override { return true; }
+ bool getField(const Common::String &key) override;
+ bool setField(const Common::String &key) override;
+
+private:
+ struct Cursor {
+ bool isSet = false;
+ uint type = 0;
+ bool isHot = false;
+ };
+
+ void readCursorField(int valueIndex, Cursor &cursor);
+ void pushCursorField(const Cursor &cursor);
+ void fire();
+
+ ScriptRect _onScreen;
+ Common::String _sceneName;
+ Common::String _streamName;
+ int _frame = 0;
+ bool _watchesLeft = true;
+ bool _watchesRight = false;
+
+ Cursor _cursor; // while the mouse is over it
+ Cursor _startCursor; // while it is over it with an item
+ Cursor _downCursor; // while it is down and the mouse is over it
+ Cursor _dragOnCursor;
+ Cursor _dragOffCursor; // while it is down and the mouse left it
+
+ const RefImage *_ref = nullptr;
+ bool _hasRefColor = false;
+ uint32 _refColor = 0;
+ ScriptRect _source;
+
+ bool _isMouseOver = false;
+ int _pressedButton = -1; // 0 for the left one, 1 for the right one
+};
+
+// Nancy26: catches the player's input in a part of the screen, so whatever is
+// behind it gets none. It can let the keys through, or the mouse.
+class SinkRecord : public Record {
+public:
+ SinkRecord(SceneContext &context) : Record(context, "ND.SinkAR") {}
+
+ bool isMouseRegion() const override { return _handlesMouse; }
+ bool hitTest(const ScriptPoint &point) const override;
+ bool pressRegion(int button) override { return true; }
+ bool getRegionCursor(uint &cursorType, bool &isHot) const override;
+ bool capturesKeys() const override { return _handlesKeys; }
+
+protected:
+ void readTable(int tableIndex) override;
+ bool prepareReset() override { return true; }
+ bool hasTransform() const override { return true; }
+ bool getField(const Common::String &key) override;
+ bool setField(const Common::String &key) override;
+
+private:
+ ScriptRect _onScreen;
+ bool _handlesKeys = true;
+ bool _handlesMouse = true;
+ bool _hasCursor = false;
+ uint _cursorType = 0;
+ bool _cursorIsHot = false;
+};
+
+} // End of namespace Script
+} // End of namespace Nancy
+
+#endif // NANCY_SCRIPT_V5_WIDGETS_H
diff --git a/engines/nancy/state/scene.cpp b/engines/nancy/state/scene.cpp
index f69dcbe06e8..f755b87603f 100644
--- a/engines/nancy/state/scene.cpp
+++ b/engines/nancy/state/scene.cpp
@@ -2797,6 +2797,13 @@ void Scene::handleInput() {
NancyInput input = g_nancy->_input->getInput();
+#ifdef ENABLE_NANCY_V5
+ if (g_nancy->getGameType() >= kGameTypeNancy26) {
+ handleNancy26Input(input);
+ return;
+ }
+#endif
+
// Warp the mouse below the inactive zone during dialogue scenes
if (_activeConversation != nullptr) {
const Common::Rect &inactiveZone = g_nancy->_cursor->getPrimaryVideoInactiveZone();
diff --git a/engines/nancy/state/scene.h b/engines/nancy/state/scene.h
index 6588fce578b..c6c1e3cf2f6 100644
--- a/engines/nancy/state/scene.h
+++ b/engines/nancy/state/scene.h
@@ -51,6 +51,7 @@ namespace Nancy {
class NancyEngine;
class NancyConsole;
+struct NancyInput;
struct SceneChangeDescription;
namespace Action {
@@ -568,6 +569,12 @@ private:
// Whether esc was already down last frame, so a held key only skips once
bool _escHeld = false;
+#ifdef ENABLE_NANCY_V5
+ // Nancy26 hands its records all the input
+ void handleNancy26Input(NancyInput &input);
+
+ bool _isEscSkipping = false; // the press that skipped stays away from the scripts
+#endif
// Set when esc skipped a cinematic this frame
bool _hasSkippedMovie = false;
Commit: 0b8e8edd7524537108e803e39d0c7424e9cad1a0
https://github.com/scummvm/scummvm/commit/0b8e8edd7524537108e803e39d0c7424e9cad1a0
Author: Filippos Karapetis (bluegr at gmail.com)
Date: 2026-11-06T04:10:53+02:00
Commit Message:
NANCY: NANCY19: Give every record a type
Every record now tells its type with getType(), one of the RecordType
enum that the factory makes the records by. The loops over the records
of a scene check the type, instead of doing a dynamic_cast on each.
Changed paths:
engines/nancy/script/convo.h
engines/nancy/script/particles.h
engines/nancy/script/physics.h
engines/nancy/script/record.cpp
engines/nancy/script/record.h
engines/nancy/script/records.cpp
engines/nancy/script/records.h
engines/nancy/script/scenecontext.cpp
engines/nancy/script/timer.h
engines/nancy/script/transformer.h
engines/nancy/script/v5/recordnode.cpp
engines/nancy/script/v5/scriptinput.cpp
engines/nancy/script/v5/textrecord.h
engines/nancy/script/v5/widgets.h
engines/nancy/script/xsheet.h
diff --git a/engines/nancy/script/convo.h b/engines/nancy/script/convo.h
index b3906f26b44..eb9c69b502a 100644
--- a/engines/nancy/script/convo.h
+++ b/engines/nancy/script/convo.h
@@ -59,6 +59,8 @@ public:
ConvoRecord(SceneContext &context, bool isVideo);
virtual ~ConvoRecord();
+ RecordType getType() const override { return _isVideo ? kRecordVideoConvo : kRecordSoundConvo; }
+
void updateGraphics() override;
void registerGraphics() override;
diff --git a/engines/nancy/script/particles.h b/engines/nancy/script/particles.h
index 7a6cf4c76ba..a9755b89ce3 100644
--- a/engines/nancy/script/particles.h
+++ b/engines/nancy/script/particles.h
@@ -78,6 +78,8 @@ struct Particle {
class ParticleRecord : public Record {
public:
ParticleRecord(SceneContext &context) : Record(context, "ND.ParticleAR") {}
+
+ RecordType getType() const override { return kRecordParticle; }
~ParticleRecord() override;
void updateGraphics() override;
diff --git a/engines/nancy/script/physics.h b/engines/nancy/script/physics.h
index 2868a70a133..41fa41361c7 100644
--- a/engines/nancy/script/physics.h
+++ b/engines/nancy/script/physics.h
@@ -78,6 +78,8 @@ private:
class PhysicsRecord : public Record {
public:
PhysicsRecord(SceneContext &context);
+
+ RecordType getType() const override { return kRecordPhysics; }
~PhysicsRecord() override;
b2World *getWorld() const { return _world; }
diff --git a/engines/nancy/script/record.cpp b/engines/nancy/script/record.cpp
index 0d85f7e3462..82313fa047c 100644
--- a/engines/nancy/script/record.cpp
+++ b/engines/nancy/script/record.cpp
@@ -884,7 +884,7 @@ static const luaL_Reg kRecordFunctions[] = {
// AR:<kind>(table)
static int createRecord(lua_State *L) {
- const RecordKind kind = (RecordKind)lua_tointeger(L, lua_upvalueindex(1));
+ const RecordType type = (RecordType)lua_tointeger(L, lua_upvalueindex(1));
const char *kindName = lua_tostring(L, lua_upvalueindex(2));
SceneContext *context = LuaState::getContext(L);
@@ -899,11 +899,11 @@ static int createRecord(lua_State *L) {
return luaL_argerror(L, 1, "Expected a table as the parameter");
}
- if (kind != kRecordSummary && !context->hasRecords()) {
+ if (type != kRecordSummary && !context->hasRecords()) {
return luaL_error(L, "Summary AR must be the first AR in the scene");
}
- Record *record = makeRecord(kind, *context);
+ Record *record = makeRecord(type, *context);
if (!record) {
return luaL_error(L, "AR:%s is not supported yet", kindName);
}
@@ -922,8 +922,8 @@ static int recordGetActualField(lua_State *L) {
}
void registerRecordAPI(lua_State *L) {
- for (uint i = 0; i < kNumRecordKinds; ++i) {
- const char *typeName = getRecordTypeName((RecordKind)i);
+ for (uint i = 0; i < kNumRecordTypes; ++i) {
+ const char *typeName = getRecordTypeName((RecordType)i);
if (luaL_newmetatable(L, typeName)) {
luaL_register(L, nullptr, kRecordFunctions);
@@ -953,11 +953,11 @@ void registerRecordAPI(lua_State *L) {
// One function for every kind, which knows the kind it makes
luaL_getmetatable(L, "ND.AR");
- for (uint i = 0; i < kNumRecordKinds; ++i) {
+ for (uint i = 0; i < kNumRecordTypes; ++i) {
lua_pushinteger(L, i);
- lua_pushstring(L, getRecordKindName((RecordKind)i));
+ lua_pushstring(L, getRecordKindName((RecordType)i));
lua_pushcclosure(L, createRecord, 2);
- lua_setfield(L, -2, getRecordKindName((RecordKind)i));
+ lua_setfield(L, -2, getRecordKindName((RecordType)i));
}
lua_pop(L, 1);
diff --git a/engines/nancy/script/record.h b/engines/nancy/script/record.h
index e6db5420b02..5cbc569bc72 100644
--- a/engines/nancy/script/record.h
+++ b/engines/nancy/script/record.h
@@ -40,6 +40,34 @@ class GraphNode;
class SceneContext;
struct RecordNodeState;
+// The types of records a script can make, in the order of their names
+enum RecordType {
+ kRecordNavLogic = 0,
+ kRecordSummary = 1,
+ kRecordOverlay = 2,
+ kRecordMovie = 3,
+ kRecordSound = 4,
+ kRecordVideoConvo = 5,
+ kRecordSoundConvo = 6,
+ kRecordText = 7,
+ kRecordOverride = 8,
+ kRecordParticle = 9,
+ kRecordAnimOverlay = 10,
+ kRecordPhysics = 11, // Nancy21
+ kRecordXsheet = 12, // Nancy22
+ kRecordTransformer = 13, // Nancy22
+ kRecordTimer = 14, // Nancy24
+ kRecordHotspot = 15, // Nancy26
+ kRecordSink = 16,
+ kRecordButton = 17,
+ kRecordEditBox = 18,
+ kRecordRadioButton = 19,
+ kRecordCheckBox = 20,
+ kRecordSlider = 21,
+
+ kNumRecordTypes = 22
+};
+
// What the player does that records get told about
enum RecordEvent {
kEventLeftClick = 0,
@@ -77,6 +105,10 @@ public:
virtual ~Record();
const char *getTypeName() const { return _typeName; }
+
+ // Which of the types above the record is
+ virtual RecordType getType() const = 0;
+
SceneContext &getContext() const { return _context; }
// Takes over the fields of the table that made the record
diff --git a/engines/nancy/script/records.cpp b/engines/nancy/script/records.cpp
index 8b54661d596..9d013ba7d98 100644
--- a/engines/nancy/script/records.cpp
+++ b/engines/nancy/script/records.cpp
@@ -67,7 +67,7 @@ struct RecordKindNames {
const char *typeName;
};
-static const RecordKindNames kRecordKindNames[kNumRecordKinds] = {
+static const RecordKindNames kRecordKindNames[kNumRecordTypes] = {
{ "NavLogic", "ND.NavLogic" },
{ "Summary", "ND.Summary" },
{ "Overlay", "ND.Overlay" },
@@ -92,16 +92,16 @@ static const RecordKindNames kRecordKindNames[kNumRecordKinds] = {
{ "Slider", "ND.Slider" }
};
-const char *getRecordKindName(RecordKind kind) {
- return kRecordKindNames[kind].kindName;
+const char *getRecordKindName(RecordType type) {
+ return kRecordKindNames[type].kindName;
}
-const char *getRecordTypeName(RecordKind kind) {
- return kRecordKindNames[kind].typeName;
+const char *getRecordTypeName(RecordType type) {
+ return kRecordKindNames[type].typeName;
}
-Record *makeRecord(RecordKind kind, SceneContext &context) {
- switch (kind) {
+Record *makeRecord(RecordType type, SceneContext &context) {
+ switch (type) {
case kRecordNavLogic:
#ifdef ENABLE_NANCY_V5
// Nancy26's NavLogic is another name for a Hotspot
diff --git a/engines/nancy/script/records.h b/engines/nancy/script/records.h
index 8078a83022d..899e64d20ec 100644
--- a/engines/nancy/script/records.h
+++ b/engines/nancy/script/records.h
@@ -44,40 +44,12 @@ namespace Script {
struct RefImage;
-// The kinds of records a script can make, in the order of the names below
-enum RecordKind {
- kRecordNavLogic = 0,
- kRecordSummary = 1,
- kRecordOverlay = 2,
- kRecordMovie = 3,
- kRecordSound = 4,
- kRecordVideoConvo = 5,
- kRecordSoundConvo = 6,
- kRecordText = 7,
- kRecordOverride = 8,
- kRecordParticle = 9,
- kRecordAnimOverlay = 10,
- kRecordPhysics = 11, // Nancy21
- kRecordXsheet = 12, // Nancy22
- kRecordTransformer = 13, // Nancy22
- kRecordTimer = 14, // Nancy24
- kRecordHotspot = 15, // Nancy26
- kRecordSink = 16,
- kRecordButton = 17,
- kRecordEditBox = 18,
- kRecordRadioButton = 19,
- kRecordCheckBox = 20,
- kRecordSlider = 21,
-
- kNumRecordKinds = 22
-};
-
-// What scripts call the kind ("NavLogic"), and the type of its objects ("ND.NavLogic")
-const char *getRecordKindName(RecordKind kind);
-const char *getRecordTypeName(RecordKind kind);
+// What scripts call the type ("NavLogic"), and the Lua type of its objects ("ND.NavLogic")
+const char *getRecordKindName(RecordType type);
+const char *getRecordTypeName(RecordType type);
-// Returns null for the kinds that are not supported
-Record *makeRecord(RecordKind kind, SceneContext &context);
+// Returns null for the types that are not supported
+Record *makeRecord(RecordType type, SceneContext &context);
// What the "Draw" object of the scripts draws on: the record whose "Render"
// function is running. Null at any other time.
@@ -124,6 +96,8 @@ class SummaryRecord : public Record {
public:
SummaryRecord(SceneContext &context) : Record(context, "ND.Summary") {}
+ RecordType getType() const override { return kRecordSummary; }
+
const Common::String &getEnvironment() const { return _environment; }
const Common::String &getBackgroundName() const { return _backgroundName; }
@@ -185,11 +159,18 @@ private:
RecordGraphic _facade;
};
+// The record as a summary, or null for a record of another type
+inline SummaryRecord *toSummaryRecord(Record *record) {
+ return record && record->getType() == kRecordSummary ? static_cast<SummaryRecord *>(record) : nullptr;
+}
+
// Changes the scene and sets flags, either right away or when its hotspot gets clicked
class NavLogicRecord : public Record {
public:
NavLogicRecord(SceneContext &context) : Record(context, "ND.NavLogic") {}
+ RecordType getType() const override { return kRecordNavLogic; }
+
protected:
void readTable(int tableIndex) override;
void run(double sceneTime, double elapsedTime) override;
@@ -245,6 +226,8 @@ private:
class OverrideRecord : public Record {
public:
OverrideRecord(SceneContext &context) : Record(context, "ND.OverrideAR") {}
+
+ RecordType getType() const override { return kRecordOverride; }
virtual ~OverrideRecord();
void updateGraphics() override;
@@ -281,6 +264,8 @@ class OverlayRecord : public Record {
public:
OverlayRecord(SceneContext &context) : Record(context, "ND.Overlay") {}
+ RecordType getType() const override { return kRecordOverlay; }
+
void updateGraphics() override;
void registerGraphics() override;
@@ -325,6 +310,8 @@ class AnimOverlayRecord : public Record {
public:
AnimOverlayRecord(SceneContext &context) : Record(context, "ND.AnimOvlAR") {}
+ RecordType getType() const override { return kRecordAnimOverlay; }
+
void updateGraphics() override;
void registerGraphics() override;
@@ -376,6 +363,8 @@ class SoundRecord : public Record {
public:
SoundRecord(SceneContext &context);
+ RecordType getType() const override { return kRecordSound; }
+
void onSkip() override;
bool skipSpeech() override;
void stopIfPlaying();
@@ -417,6 +406,8 @@ class TextRecord : public Record {
public:
TextRecord(SceneContext &context) : Record(context, "ND.TextAR") {}
+ RecordType getType() const override { return kRecordText; }
+
void updateGraphics() override;
void registerGraphics() override;
@@ -463,6 +454,8 @@ class MovieRecord : public Record {
public:
MovieRecord(SceneContext &context) : Record(context, "ND.Movie") {}
+ RecordType getType() const override { return kRecordMovie; }
+
void updateGraphics() override;
void registerGraphics() override;
void describeState(Common::Array<Common::String> &lines) const override;
diff --git a/engines/nancy/script/scenecontext.cpp b/engines/nancy/script/scenecontext.cpp
index 02146ea4bd8..f6da1be9a72 100644
--- a/engines/nancy/script/scenecontext.cpp
+++ b/engines/nancy/script/scenecontext.cpp
@@ -146,9 +146,9 @@ bool SceneContext::load() {
// Nothing can be made before there is a summary. A scene can go on to make
// more of them, and so can the scripts it includes; the last one that names
// a background is the one that shows.
- _summary = _newRecords.empty() ? nullptr : dynamic_cast<SummaryRecord *>(_newRecords[0]);
+ _summary = _newRecords.empty() ? nullptr : toSummaryRecord(_newRecords[0]);
for (Record *record : _newRecords) {
- SummaryRecord *summary = dynamic_cast<SummaryRecord *>(record);
+ SummaryRecord *summary = toSummaryRecord(record);
if (_summary && summary && !summary->getBackgroundName().empty()) {
_summary = summary;
}
diff --git a/engines/nancy/script/timer.h b/engines/nancy/script/timer.h
index e2ad3af4cba..3d793c86b99 100644
--- a/engines/nancy/script/timer.h
+++ b/engines/nancy/script/timer.h
@@ -88,6 +88,8 @@ class TimerRecord : public Record {
public:
TimerRecord(SceneContext &context);
+ RecordType getType() const override { return kRecordTimer; }
+
protected:
void readTable(int tableIndex) override;
void run(double sceneTime, double elapsedTime) override;
diff --git a/engines/nancy/script/transformer.h b/engines/nancy/script/transformer.h
index 936d3599ae1..ec277be3a4d 100644
--- a/engines/nancy/script/transformer.h
+++ b/engines/nancy/script/transformer.h
@@ -142,6 +142,8 @@ class TransformerRecord : public Record {
public:
TransformerRecord(SceneContext &context, const char *typeName = "ND.TransformerAR");
+ RecordType getType() const override { return kRecordTransformer; }
+
GraphNode *getNode() const { return _node; }
int attach(lua_State *L);
diff --git a/engines/nancy/script/v5/recordnode.cpp b/engines/nancy/script/v5/recordnode.cpp
index 21e29acdcc5..411d5f671aa 100644
--- a/engines/nancy/script/v5/recordnode.cpp
+++ b/engines/nancy/script/v5/recordnode.cpp
@@ -128,6 +128,24 @@ bool Record::isShown() const {
return _nodeState ? isNodeVisible() : isActive();
}
+// The owner of a node, which in Nancy26 is a Transformer or a widget made of one
+static const ClipTransformerRecord *toClipTransformer(const Record *owner) {
+ if (!owner) {
+ return nullptr;
+ }
+
+ switch (owner->getType()) {
+ case kRecordTransformer:
+ case kRecordButton:
+ case kRecordCheckBox:
+ case kRecordRadioButton:
+ case kRecordSlider:
+ return static_cast<const ClipTransformerRecord *>(owner);
+ default:
+ return nullptr;
+ }
+}
+
Common::Rect Record::getScreenClip() const {
Common::Rect clip;
if (!_nodeState) {
@@ -136,7 +154,7 @@ Common::Rect Record::getScreenClip() const {
bool hasClip = false;
for (const GraphNode *node = _parentNode; node; node = node->getParent()) {
- const ClipTransformerRecord *transformer = dynamic_cast<const ClipTransformerRecord *>(node->getOwner());
+ const ClipTransformerRecord *transformer = toClipTransformer(node->getOwner());
const ScriptRect *nodeClip = transformer ? transformer->getClip() : nullptr;
if (!nodeClip) {
continue;
diff --git a/engines/nancy/script/v5/scriptinput.cpp b/engines/nancy/script/v5/scriptinput.cpp
index 7899e7c6eea..5aba9555b21 100644
--- a/engines/nancy/script/v5/scriptinput.cpp
+++ b/engines/nancy/script/v5/scriptinput.cpp
@@ -141,7 +141,7 @@ static bool callInputFunction(Record *record, const char *name, int numArgs = 0)
}
static bool isOverride(Record *record) {
- return dynamic_cast<OverrideRecord *>(record) != nullptr;
+ return record->getType() == kRecordOverride;
}
static void updateHover(const Common::Array<Record *> &records) {
@@ -228,7 +228,7 @@ static void updateCursor(const Common::Array<Record *> &records) {
continue;
}
- SummaryRecord *summary = dynamic_cast<SummaryRecord *>(record);
+ SummaryRecord *summary = toSummaryRecord(record);
if (summary && state.hasMouse && summary->sendChangeCursor(state.mouse, true, cursorType, isHot)) {
cursor.setCursorType((CursorManager::CursorType)cursorType, true, isHot);
return;
@@ -267,7 +267,7 @@ static void pressButton(const Common::Array<Record *> &records, int button) {
continue;
}
- SummaryRecord *summary = dynamic_cast<SummaryRecord *>(record);
+ SummaryRecord *summary = toSummaryRecord(record);
if (summary && summary->sendMouseEvent(button == 0 ? kEventLeftDown : kEventRightDown, state.mouse, true)) {
return;
}
@@ -293,7 +293,7 @@ static void releaseButton(const Common::Array<Record *> &records, int button) {
continue;
}
- SummaryRecord *summary = dynamic_cast<SummaryRecord *>(record);
+ SummaryRecord *summary = toSummaryRecord(record);
if (summary) {
summary->sendMouseEvent(button == 0 ? kEventLeftUp : kEventRightUp, state.mouse, true);
if (button == 0 && summary->sendMouseEvent(kEventLeftClick, state.mouse, true)) {
@@ -359,7 +359,7 @@ static void sendKey(const Common::Array<Record *> &records, Common::KeyCode key,
continue;
}
- SummaryRecord *summary = dynamic_cast<SummaryRecord *>(record);
+ SummaryRecord *summary = toSummaryRecord(record);
if (summary && isDown && summary->turnByKey(key)) {
return;
}
@@ -404,7 +404,7 @@ void handleNancy26Input(NancyInput &input) {
}
record->callFunction("OnNewFrame");
- } else if (hasMoved && dynamic_cast<SummaryRecord *>(record)) {
+ } else if (hasMoved && record->getType() == kRecordSummary) {
record->sendMouseMove(state.mouse, true);
}
}
diff --git a/engines/nancy/script/v5/textrecord.h b/engines/nancy/script/v5/textrecord.h
index e26e7627650..7725b39c014 100644
--- a/engines/nancy/script/v5/textrecord.h
+++ b/engines/nancy/script/v5/textrecord.h
@@ -36,6 +36,8 @@ class BitmapTextRecord : public Record {
public:
BitmapTextRecord(SceneContext &context) : Record(context, "ND.TextAR") {}
+ RecordType getType() const override { return kRecordText; }
+
void updateGraphics() override;
void registerGraphics() override;
diff --git a/engines/nancy/script/v5/widgets.h b/engines/nancy/script/v5/widgets.h
index 0686d0d6fda..7379167b72d 100644
--- a/engines/nancy/script/v5/widgets.h
+++ b/engines/nancy/script/v5/widgets.h
@@ -42,6 +42,8 @@ class HotspotRecord : public Record {
public:
HotspotRecord(SceneContext &context) : Record(context, "ND.Hotspot") {}
+ RecordType getType() const override { return kRecordHotspot; }
+
bool isMouseRegion() const override { return true; }
bool hitTest(const ScriptPoint &point) const override;
void setMouseOver(bool isOver) override;
@@ -99,6 +101,8 @@ class SinkRecord : public Record {
public:
SinkRecord(SceneContext &context) : Record(context, "ND.SinkAR") {}
+ RecordType getType() const override { return kRecordSink; }
+
bool isMouseRegion() const override { return _handlesMouse; }
bool hitTest(const ScriptPoint &point) const override;
bool pressRegion(int button) override { return true; }
diff --git a/engines/nancy/script/xsheet.h b/engines/nancy/script/xsheet.h
index 1a6727d2553..669e26f4ea9 100644
--- a/engines/nancy/script/xsheet.h
+++ b/engines/nancy/script/xsheet.h
@@ -98,6 +98,8 @@ class XsheetRecord : public Record {
public:
XsheetRecord(SceneContext &context) : Record(context, "ND.XsheetAR") {}
+ RecordType getType() const override { return kRecordXsheet; }
+
void updateGraphics() override;
void registerGraphics() override;
Commit: d0ab1a548c3cf08b3ccc1f748b90ea6902bc8632
https://github.com/scummvm/scummvm/commit/d0ab1a548c3cf08b3ccc1f748b90ea6902bc8632
Author: Filippos Karapetis (bluegr at gmail.com)
Date: 2026-11-06T04:10:54+02:00
Commit Message:
NANCY: NANCY26: Add the Button, CheckBox, RadioButton and Slider records
The buttons of Nancy26 are made of a Hotspot and overlays for the
states they can be in, which hang under them, so they show, hide and
move together. A CheckBox goes on and off when clicked, and a
RadioButton deselects the others of its group. The knob of a Slider is
dragged with the mouse, or moved by the mouse wheel.
Changed paths:
engines/nancy/script/record.h
engines/nancy/script/records.cpp
engines/nancy/script/v5/scriptinput.cpp
engines/nancy/script/v5/widgets.cpp
engines/nancy/script/v5/widgets.h
diff --git a/engines/nancy/script/record.h b/engines/nancy/script/record.h
index 5cbc569bc72..dcd93396f1e 100644
--- a/engines/nancy/script/record.h
+++ b/engines/nancy/script/record.h
@@ -263,6 +263,10 @@ public:
virtual void releaseRegion(int button) {}
virtual bool getRegionCursor(uint &cursorType, bool &isHot) const { return false; }
+ // Nancy26: the mouse wheel turned while the mouse was at the point, in the
+ // coordinates of the screen. Returns whether the record took it.
+ virtual bool scrollRegion(const ScriptPoint &point, int notches) { return false; }
+
// Nancy26: whether the keys go no further than this record
virtual bool capturesKeys() const { return false; }
diff --git a/engines/nancy/script/records.cpp b/engines/nancy/script/records.cpp
index 9d013ba7d98..4ecd2773bf4 100644
--- a/engines/nancy/script/records.cpp
+++ b/engines/nancy/script/records.cpp
@@ -116,6 +116,14 @@ Record *makeRecord(RecordType type, SceneContext &context) {
return new HotspotRecord(context);
case kRecordSink:
return new SinkRecord(context);
+ case kRecordButton:
+ return new WidgetRecord(context, kRecordButton);
+ case kRecordRadioButton:
+ return new WidgetRecord(context, kRecordRadioButton);
+ case kRecordCheckBox:
+ return new WidgetRecord(context, kRecordCheckBox);
+ case kRecordSlider:
+ return new SliderRecord(context);
#endif
case kRecordSummary:
return new SummaryRecord(context);
diff --git a/engines/nancy/script/v5/scriptinput.cpp b/engines/nancy/script/v5/scriptinput.cpp
index 5aba9555b21..4277c5130ef 100644
--- a/engines/nancy/script/v5/scriptinput.cpp
+++ b/engines/nancy/script/v5/scriptinput.cpp
@@ -307,6 +307,10 @@ static void scrollWheel(const Common::Array<Record *> &records, int notches) {
InputState &state = getState();
for (Record *record : records) {
+ if (record->scrollRegion(state.mouse, notches)) {
+ return;
+ }
+
if (isOverride(record)) {
lua_pushinteger(record->getContext().getLua(), notches);
if (callInputFunction(record, "OnMouseScroll", 1)) {
diff --git a/engines/nancy/script/v5/widgets.cpp b/engines/nancy/script/v5/widgets.cpp
index b859477b5af..d99a9cf26e6 100644
--- a/engines/nancy/script/v5/widgets.cpp
+++ b/engines/nancy/script/v5/widgets.cpp
@@ -56,6 +56,24 @@ static bool readCursorValue(lua_State *L, int index, uint &cursorType, bool &isH
return testCursor(L, index, cursorType, isHot);
}
+static int setTableField(lua_State *L) {
+ lua_settable(L, 1);
+ return 0;
+}
+
+// Sets a field of another record the way a script would, with the value at the
+// top of the stack, which gets popped
+static void setRecordField(Record *record, const char *key) {
+ lua_State *L = record->getContext().getLua();
+ lua_pushcfunction(L, setTableField);
+ lua_insert(L, -2);
+ record->push();
+ lua_insert(L, -2);
+ lua_pushstring(L, key);
+ lua_insert(L, -2);
+ LuaState::call(L, 3, 0, "Error setting a field of an AR");
+}
+
// HotspotRecord
void HotspotRecord::readCursorField(int valueIndex, Cursor &cursor) {
@@ -145,6 +163,9 @@ void HotspotRecord::setMouseOver(bool isOver) {
_isMouseOver = isOver;
callFunction(isOver ? "OnMouseOver" : "OnMouseLeave");
+ if (_widget) {
+ _widget->onHotspotOver(isOver);
+ }
}
bool HotspotRecord::pressRegion(int button) {
@@ -154,6 +175,9 @@ bool HotspotRecord::pressRegion(int button) {
_pressedButton = button;
callFunction(button == 0 ? "OnLeftDown" : "OnRightDown");
+ if (_widget) {
+ _widget->onHotspotDown(button);
+ }
return true;
}
@@ -169,12 +193,19 @@ void HotspotRecord::releaseRegion(int button) {
if (!_isMouseOver) {
callFunction("OnLoseMouseFocus");
+ if (_widget) {
+ _widget->onHotspotUp(button, false);
+ }
return;
}
callFunction(button == 0 ? "OnLeftUp" : "OnRightUp");
- fire();
+ if (_widget) {
+ _widget->onHotspotUp(button, true);
+ } else {
+ fire();
+ }
}
void HotspotRecord::fire() {
@@ -374,5 +405,426 @@ bool SinkRecord::setField(const Common::String &key) {
return true;
}
+// WidgetRecord
+
+WidgetRecord::WidgetRecord(SceneContext &context, RecordType type) :
+ ClipTransformerRecord(context, getRecordTypeName(type)),
+ _type(type) {}
+
+// A record the table holds, which then hangs under the widget
+Record *WidgetRecord::readRecordField(int tableIndex, const char *name) {
+ lua_State *L = getLua();
+
+ if (!pushField(L, tableIndex, name)) {
+ return nullptr;
+ }
+
+ Record *record = toRecord(L, -1);
+ lua_pop(L, 1);
+
+ if (record) {
+ record->setParentNode(getNode());
+ }
+
+ return record;
+}
+
+void WidgetRecord::readTable(int tableIndex) {
+ ClipTransformerRecord::readTable(tableIndex);
+ lua_State *L = getLua();
+
+ _hotspot = dynamic_cast<HotspotRecord *>(readRecordField(tableIndex, "hs"));
+ if (_hotspot) {
+ _hotspot->setWidget(this);
+ }
+
+ _baseOverlay = readRecordField(tableIndex, "baseOvl");
+ _upOverlay = readRecordField(tableIndex, "upOvl");
+ _downOverlay = readRecordField(tableIndex, "downOvl");
+ _overOverlay = readRecordField(tableIndex, "overOvl");
+ _selectedOverlay = readRecordField(tableIndex, "selectedOvl");
+ _text = readRecordField(tableIndex, "text");
+
+ if (pushField(L, tableIndex, "baseColor")) {
+ _baseColor = checkColor(L, -1);
+ lua_pop(L, 1);
+ }
+
+ if (pushField(L, tableIndex, "disabledColor")) {
+ _disabledColor = checkColor(L, -1);
+ lua_pop(L, 1);
+ }
+
+ readField(L, tableIndex, "isSelected", _isSelected);
+ readField(L, tableIndex, "groupName", _groupName);
+
+ bool isInitiallySelected = false;
+ if (readField(L, tableIndex, "initiallySelected", isInitiallySelected) && isInitiallySelected) {
+ setSelected(true, false);
+ }
+
+ _wasEnabled = !isNodeEnabled();
+ updateState();
+}
+
+void WidgetRecord::showOverlay(Record *overlay, bool isShown, bool isEnabled) {
+ if (!overlay) {
+ return;
+ }
+
+ overlay->setLocalVisible(isShown);
+
+ if (isEnabled != _wasEnabled) {
+ pushColor(overlay->getContext().getLua(), isEnabled ? _baseColor : _disabledColor);
+ setRecordField(overlay, "modColor");
+ }
+}
+
+void WidgetRecord::updateState() {
+ const bool isEnabled = isNodeEnabled();
+ const bool isOver = _hotspot && _hotspot->isMouseOver() && isEnabled;
+ const bool isDown = _hotspot && _hotspot->isDown() && isEnabled;
+
+ showOverlay(_baseOverlay, true, isEnabled);
+ showOverlay(_selectedOverlay, _isSelected, isEnabled);
+ showOverlay(_downOverlay, isDown && isOver, isEnabled);
+ showOverlay(_overOverlay, isOver && !isDown, isEnabled);
+ showOverlay(_upOverlay, !(isOver && !isDown) && !(isDown && isOver) && !(_isSelected && _selectedOverlay), isEnabled);
+
+ if (_text && isEnabled != _wasEnabled) {
+ pushColor(getLua(), isEnabled ? _baseColor : _disabledColor);
+ setRecordField(_text, "modColor");
+ }
+
+ _wasEnabled = isEnabled;
+}
+
+void WidgetRecord::updateGraphics() {
+ // The overlays show what the widget is up to even while it is paused
+ updateState();
+}
+
+void WidgetRecord::onHotspotOver(bool isOver) {
+ callFunction(isOver ? "OnMouseOver" : "OnMouseLeave");
+ updateState();
+}
+
+void WidgetRecord::onHotspotDown(int button) {
+ if (button != 0) {
+ return;
+ }
+
+ switch (_type) {
+ case kRecordCheckBox:
+ setSelected(!_isSelected, true);
+ break;
+ case kRecordRadioButton:
+ setSelected(true, true);
+ break;
+ default:
+ break;
+ }
+
+ callFunction("OnDown");
+ updateState();
+}
+
+void WidgetRecord::onHotspotUp(int button, bool isOver) {
+ if (button != 0) {
+ return;
+ }
+
+ callFunction(isOver ? "OnUp" : "OnLoseMouseFocus");
+ updateState();
+}
+
+// A radio button that gets selected deselects the others of its group
+void WidgetRecord::setSelected(bool isSelected, bool callsScripts) {
+ if (isSelected == _isSelected) {
+ return;
+ }
+
+ _isSelected = isSelected;
+
+ if (isSelected && _type == kRecordRadioButton) {
+ for (Record *record : getContext().getRecords()) {
+ if (record == this || record->getType() != kRecordRadioButton) {
+ continue;
+ }
+
+ WidgetRecord *other = static_cast<WidgetRecord *>(record);
+ if (other->_groupName.equalsIgnoreCase(_groupName)) {
+ other->setSelected(false, callsScripts);
+ }
+ }
+ }
+
+ if (callsScripts) {
+ callFunction(isSelected ? "OnSelect" : "OnDeselect");
+ }
+
+ updateState();
+}
+
+bool WidgetRecord::getField(const Common::String &key) {
+ lua_State *L = getLua();
+
+ Record *record = nullptr;
+ if (key == "hs") {
+ record = _hotspot;
+ } else if (key == "baseOvl") {
+ record = _baseOverlay;
+ } else if (key == "upOvl") {
+ record = _upOverlay;
+ } else if (key == "downOvl") {
+ record = _downOverlay;
+ } else if (key == "overOvl") {
+ record = _overOverlay;
+ } else if (key == "selectedOvl") {
+ record = _selectedOverlay;
+ } else if (key == "text") {
+ record = _text;
+ } else if (key == "baseColor") {
+ pushColor(L, _baseColor);
+ return true;
+ } else if (key == "disabledColor") {
+ pushColor(L, _disabledColor);
+ return true;
+ } else if (key == "isSelected") {
+ lua_pushboolean(L, _isSelected);
+ return true;
+ } else if (key == "groupName") {
+ lua_pushstring(L, _groupName.c_str());
+ return true;
+ } else {
+ return ClipTransformerRecord::getField(key);
+ }
+
+ if (record) {
+ record->push();
+ } else {
+ lua_pushnil(L);
+ }
+
+ return true;
+}
+
+bool WidgetRecord::setField(const Common::String &key) {
+ lua_State *L = getLua();
+
+ if (key == "baseColor") {
+ _baseColor = checkColor(L, 3);
+ _wasEnabled = !isNodeEnabled();
+ } else if (key == "disabledColor") {
+ _disabledColor = checkColor(L, 3);
+ _wasEnabled = !isNodeEnabled();
+ } else if (key == "isSelected") {
+ setSelected(lua_toboolean(L, 3) != 0, false);
+ } else {
+ return ClipTransformerRecord::setField(key);
+ }
+
+ updateState();
+ return true;
+}
+
+// SliderRecord
+
+void SliderRecord::readTable(int tableIndex) {
+ WidgetRecord::readTable(tableIndex);
+ lua_State *L = getLua();
+
+ _knobOverlay = readRecordField(tableIndex, "knobOvl");
+
+ if (pushField(L, tableIndex, "knobArea")) {
+ _knobArea = checkRect(L, -1);
+ lua_pop(L, 1);
+ }
+
+ // Without one, the knob goes along the hotspot
+ if (_knobArea.isEmpty() && _hotspot) {
+ _knobArea = _hotspot->getOnScreen();
+ }
+
+ if (pushField(L, tableIndex, "scrollArea")) {
+ _scrollArea = checkRect(L, -1);
+ lua_pop(L, 1);
+ }
+
+ if (pushField(L, tableIndex, "scrollAmount")) {
+ readPoint(L, -1, _scrollAmount);
+ lua_pop(L, 1);
+ }
+
+ if (pushField(L, tableIndex, "knobPos")) {
+ readPoint(L, -1, _knobPos);
+ lua_pop(L, 1);
+ }
+
+ setKnobPos(_knobPos, false);
+}
+
+// The knob is as large as the part of the picture it shows
+static ScriptPoint getOverlaySize(Record *overlay) {
+ ScriptPoint size;
+ if (!overlay) {
+ return size;
+ }
+
+ lua_State *L = overlay->getContext().getLua();
+ overlay->push();
+ lua_getfield(L, -1, "source");
+ const ScriptRect *source = testRect(L, -1);
+ if (source) {
+ size = ScriptPoint(source->width(), source->height());
+ }
+
+ lua_pop(L, 2);
+ return size;
+}
+
+ScriptPoint SliderRecord::getKnobMax() const {
+ const ScriptPoint knobSize = getOverlaySize(_knobOverlay);
+ return ScriptPoint(MAX<int>(0, _knobArea.width() - knobSize.x), MAX<int>(0, _knobArea.height() - knobSize.y));
+}
+
+void SliderRecord::setKnobPos(const ScriptPoint &pos, bool callsScripts) {
+ const ScriptPoint knobMax = getKnobMax();
+ const ScriptPoint newPos(CLIP<int>(pos.x, 0, knobMax.x), CLIP<int>(pos.y, 0, knobMax.y));
+
+ const bool hasMoved = newPos.x != _knobPos.x || newPos.y != _knobPos.y;
+ _knobPos = newPos;
+ placeKnob();
+
+ if (hasMoved && callsScripts) {
+ callFunction("OnKnobMoved");
+ }
+}
+
+void SliderRecord::placeKnob() {
+ if (!_knobOverlay) {
+ return;
+ }
+
+ const ScriptPoint knobSize = getOverlaySize(_knobOverlay);
+ ScriptRect dest(0, 0, knobSize.x, knobSize.y);
+ dest.translate(_knobArea.left + _knobPos.x, _knobArea.top + _knobPos.y);
+
+ pushRect(_knobOverlay->getContext().getLua(), dest);
+ setRecordField(_knobOverlay, "onScreen");
+}
+
+// A click on the knob drags it from where it was taken; anywhere else on the
+// bar, the knob jumps there first
+void SliderRecord::onHotspotDown(int button) {
+ if (button != 0) {
+ return;
+ }
+
+ const ScriptPoint mouse = getScriptMousePoint();
+ const ScriptPoint knobSize = getOverlaySize(_knobOverlay);
+ const ScriptRect knob(_knobArea.left + _knobPos.x, _knobArea.top + _knobPos.y,
+ _knobArea.left + _knobPos.x + knobSize.x, _knobArea.top + _knobPos.y + knobSize.y);
+
+ if (knob.contains(mouse.x, mouse.y)) {
+ _dragOffset = ScriptPoint(mouse.x - knob.left, mouse.y - knob.top);
+ } else {
+ _dragOffset = ScriptPoint(knobSize.x / 2, knobSize.y / 2);
+ setKnobPos(ScriptPoint(mouse.x - _knobArea.left - _dragOffset.x, mouse.y - _knobArea.top - _dragOffset.y), true);
+ }
+
+ _isDragging = true;
+ WidgetRecord::onHotspotDown(button);
+}
+
+void SliderRecord::onHotspotUp(int button, bool isOver) {
+ if (button == 0) {
+ _isDragging = false;
+ }
+
+ WidgetRecord::onHotspotUp(button, isOver);
+}
+
+void SliderRecord::run(double sceneTime, double elapsedTime) {
+ ClipTransformerRecord::run(sceneTime, elapsedTime);
+
+ if (_isDragging) {
+ const ScriptPoint mouse = getScriptMousePoint();
+ setKnobPos(ScriptPoint(mouse.x - _knobArea.left - _dragOffset.x, mouse.y - _knobArea.top - _dragOffset.y), true);
+ }
+}
+
+bool SliderRecord::scrollRegion(const ScriptPoint &point, int notches) {
+ if (!isNodeEnabled() || (_scrollAmount.x == 0 && _scrollAmount.y == 0)) {
+ return false;
+ }
+
+ if (!_scrollArea.contains(point.x, point.y) && !_knobArea.contains(point.x, point.y)) {
+ return false;
+ }
+
+ setKnobPos(ScriptPoint(_knobPos.x - notches * _scrollAmount.x, _knobPos.y - notches * _scrollAmount.y), true);
+ return true;
+}
+
+void SliderRecord::updateState() {
+ WidgetRecord::updateState();
+
+ if (_knobOverlay) {
+ _knobOverlay->setLocalVisible(true);
+ }
+}
+
+bool SliderRecord::getField(const Common::String &key) {
+ lua_State *L = getLua();
+
+ if (key == "knobOvl") {
+ if (_knobOverlay) {
+ _knobOverlay->push();
+ } else {
+ lua_pushnil(L);
+ }
+ } else if (key == "knobArea") {
+ pushRect(L, _knobArea);
+ } else if (key == "scrollArea") {
+ pushRect(L, _scrollArea);
+ } else if (key == "scrollAmount") {
+ pushPoint(L, _scrollAmount);
+ } else if (key == "knobPos") {
+ pushPoint(L, _knobPos);
+ } else if (key == "knobMax") {
+ pushPoint(L, getKnobMax());
+ } else if (key == "percent") {
+ const ScriptPoint knobMax = getKnobMax();
+ pushVector(L, ScriptVector(knobMax.x > 0 ? (double)_knobPos.x / knobMax.x : 0.0,
+ knobMax.y > 0 ? (double)_knobPos.y / knobMax.y : 0.0, 0.0));
+ } else {
+ return WidgetRecord::getField(key);
+ }
+
+ return true;
+}
+
+bool SliderRecord::setField(const Common::String &key) {
+ lua_State *L = getLua();
+
+ if (key == "knobPos") {
+ ScriptPoint pos;
+ readPoint(L, 3, pos);
+ setKnobPos(pos, false);
+ } else if (key == "scrollArea") {
+ _scrollArea = checkRect(L, 3);
+ } else if (key == "scrollAmount") {
+ readPoint(L, 3, _scrollAmount);
+ } else if (key == "knobArea") {
+ _knobArea = checkRect(L, 3);
+ setKnobPos(_knobPos, false);
+ } else {
+ return WidgetRecord::setField(key);
+ }
+
+ return true;
+}
+
} // End of namespace Script
} // End of namespace Nancy
diff --git a/engines/nancy/script/v5/widgets.h b/engines/nancy/script/v5/widgets.h
index 7379167b72d..844b5af687f 100644
--- a/engines/nancy/script/v5/widgets.h
+++ b/engines/nancy/script/v5/widgets.h
@@ -25,10 +25,13 @@
#include "engines/nancy/script/records.h"
#include "engines/nancy/script/types.h"
+#include "engines/nancy/script/v5/cliptransformer.h"
+
namespace Nancy {
namespace Script {
struct RefImage;
+class WidgetRecord;
// Nancy26's place on the screen the mouse can be over and click, which NavLogic
// records are as well. The player's input goes to the hotspot the mouse is over
@@ -44,6 +47,9 @@ public:
RecordType getType() const override { return kRecordHotspot; }
+ // A button or another widget takes over what the hotspot does
+ void setWidget(WidgetRecord *widget) { _widget = widget; }
+
bool isMouseRegion() const override { return true; }
bool hitTest(const ScriptPoint &point) const override;
void setMouseOver(bool isOver) override;
@@ -93,6 +99,7 @@ private:
bool _isMouseOver = false;
int _pressedButton = -1; // 0 for the left one, 1 for the right one
+ WidgetRecord *_widget = nullptr;
};
// Nancy26: catches the player's input in a part of the screen, so whatever is
@@ -125,6 +132,90 @@ private:
bool _cursorIsHot = false;
};
+// Nancy26's buttons, check boxes and radio buttons: a hotspot and overlays,
+// shown one at a time for the state the widget is in. The records the widget
+// is made of hang under it, so it hides, shows and moves them all.
+class WidgetRecord : public ClipTransformerRecord {
+public:
+ WidgetRecord(SceneContext &context, RecordType type);
+
+ RecordType getType() const override { return _type; }
+
+ // What its hotspot tells it
+ virtual void onHotspotOver(bool isOver);
+ virtual void onHotspotDown(int button);
+ virtual void onHotspotUp(int button, bool isOver);
+
+ bool isSelected() const { return _isSelected; }
+ void setSelected(bool isSelected, bool callsScripts);
+ const Common::String &getGroupName() const { return _groupName; }
+
+ void updateGraphics() override;
+
+protected:
+ void readTable(int tableIndex) override;
+ bool prepareReset() override { return true; }
+ bool getField(const Common::String &key) override;
+ bool setField(const Common::String &key) override;
+
+ // Picks the overlay for the state of the widget
+ virtual void updateState();
+
+ Record *readRecordField(int tableIndex, const char *name);
+ void showOverlay(Record *overlay, bool isShown, bool isEnabled);
+
+ RecordType _type;
+ HotspotRecord *_hotspot = nullptr;
+ Record *_baseOverlay = nullptr;
+ Record *_upOverlay = nullptr;
+ Record *_downOverlay = nullptr;
+ Record *_overOverlay = nullptr;
+ Record *_selectedOverlay = nullptr;
+ Record *_text = nullptr;
+
+ uint32 _baseColor = 0xFFFFFFFF;
+ uint32 _disabledColor = 0xFF7F7F7F;
+
+ bool _isSelected = false;
+ Common::String _groupName; // of a radio button
+ bool _wasEnabled = true;
+};
+
+// Nancy26: a knob that the mouse drags around the knob area, or the wheel moves
+// while the mouse is in the scroll area. "percent" is where the knob is, from
+// 0 to 1 across and down.
+class SliderRecord : public WidgetRecord {
+public:
+ SliderRecord(SceneContext &context) : WidgetRecord(context, kRecordSlider) {}
+
+ void onHotspotDown(int button) override;
+ void onHotspotUp(int button, bool isOver) override;
+
+ // The wheel moves the knob while the mouse is in the scroll area
+ bool scrollRegion(const ScriptPoint &point, int notches) override;
+
+protected:
+ void readTable(int tableIndex) override;
+ void run(double sceneTime, double elapsedTime) override;
+ bool getField(const Common::String &key) override;
+ bool setField(const Common::String &key) override;
+ void updateState() override;
+
+private:
+ // How far the knob can go across and down
+ ScriptPoint getKnobMax() const;
+ void setKnobPos(const ScriptPoint &pos, bool callsScripts);
+ void placeKnob();
+
+ Record *_knobOverlay = nullptr;
+ ScriptRect _knobArea;
+ ScriptRect _scrollArea;
+ ScriptPoint _scrollAmount;
+ ScriptPoint _knobPos;
+ ScriptPoint _dragOffset; // from the knob to the mouse, while dragged
+ bool _isDragging = false;
+};
+
} // End of namespace Script
} // End of namespace Nancy
Commit: ffa1c2c5dbb5f9760b80456eceb09c772f8ba55e
https://github.com/scummvm/scummvm/commit/ffa1c2c5dbb5f9760b80456eceb09c772f8ba55e
Author: Filippos Karapetis (bluegr at gmail.com)
Date: 2026-11-06T04:10:55+02:00
Commit Message:
NANCY: NANCY26: Add the EditBox record
The EditBox is the text field of Nancy26's UI, where the player types
the name of a saved game. Clicking it lets the player type in it, and
its scripts are told when the text changes, and when Enter or Tab is
pressed. A letter that wouldn't fit in the field isn't added.
Changed paths:
engines/nancy/script/records.cpp
engines/nancy/script/v5/widgets.cpp
engines/nancy/script/v5/widgets.h
diff --git a/engines/nancy/script/records.cpp b/engines/nancy/script/records.cpp
index 4ecd2773bf4..69494f01e14 100644
--- a/engines/nancy/script/records.cpp
+++ b/engines/nancy/script/records.cpp
@@ -124,6 +124,8 @@ Record *makeRecord(RecordType type, SceneContext &context) {
return new WidgetRecord(context, kRecordCheckBox);
case kRecordSlider:
return new SliderRecord(context);
+ case kRecordEditBox:
+ return new EditBoxRecord(context);
#endif
case kRecordSummary:
return new SummaryRecord(context);
diff --git a/engines/nancy/script/v5/widgets.cpp b/engines/nancy/script/v5/widgets.cpp
index d99a9cf26e6..21413b3a386 100644
--- a/engines/nancy/script/v5/widgets.cpp
+++ b/engines/nancy/script/v5/widgets.cpp
@@ -826,5 +826,306 @@ bool SliderRecord::setField(const Common::String &key) {
return true;
}
+// EditBoxRecord
+
+// The edit box that has the keyboard
+static EditBoxRecord *s_focusedEditBox = nullptr;
+
+EditBoxRecord::EditBoxRecord(SceneContext &context) : Record(context, "ND.EditBoxAR") {}
+
+EditBoxRecord::~EditBoxRecord() {
+ if (s_focusedEditBox == this) {
+ s_focusedEditBox = nullptr;
+ }
+}
+
+void EditBoxRecord::readTable(int tableIndex) {
+ lua_State *L = getLua();
+
+ if (pushField(L, tableIndex, "onScreen")) {
+ _dest = checkRect(L, -1);
+ lua_pop(L, 1);
+ }
+
+ readField(L, tableIndex, "fontIdx", _fontID);
+ readField(L, tableIndex, "selectedColor", _selectedColor);
+ readField(L, tableIndex, "unselectedColor", _unselectedColor);
+ readField(L, tableIndex, "disabledSelectedColor", _disabledSelectedColor);
+ readField(L, tableIndex, "disabledUnselectedColor", _disabledUnselectedColor);
+ readField(L, tableIndex, "enteredString", _text);
+
+ if (pushField(L, tableIndex, "caretColor")) {
+ _caretColor = checkColor(L, -1);
+ lua_pop(L, 1);
+ }
+
+ if (pushField(L, tableIndex, "selectionBgColor")) {
+ _selectionColor = checkColor(L, -1);
+ lua_pop(L, 1);
+ }
+
+ if (pushField(L, tableIndex, "cursor")) {
+ _hasCursor = readCursorValue(L, -1, _cursorType, _cursorIsHot);
+ lua_pop(L, 1);
+ }
+
+ // The picture behind the text hangs where the box does
+ if (pushField(L, tableIndex, "baseOvl")) {
+ Record *overlay = toRecord(L, -1);
+ lua_pop(L, 1);
+ if (overlay) {
+ overlay->setParentNode(getParentNode());
+ }
+ }
+
+ _graphic.init();
+ _graphic.setVisible(false);
+ applyDest();
+ onZChanged();
+ _graphic.registerGraphics();
+}
+
+bool EditBoxRecord::hasFocus() const {
+ return s_focusedEditBox == this && isNodeEnabled();
+}
+
+void EditBoxRecord::applyDest() {
+ const int width = MAX<int>(_dest.width(), 1);
+ const int height = MAX<int>(_dest.height(), 1);
+ if (_graphic._drawSurface.w != width || _graphic._drawSurface.h != height) {
+ _graphic._drawSurface.create(width, height, g_nancy->_graphics->getTransparentPixelFormat());
+ }
+
+ double x = _dest.left;
+ double y = _dest.top;
+ getTransform().transformPoint(x, y);
+ _graphic.moveTo(Common::Rect((int)x, (int)y, (int)x + width, (int)y + height));
+ _isDirty = true;
+}
+
+void EditBoxRecord::onZChanged() {
+ _graphic.setScriptZ(getZ(), getContext());
+}
+
+void EditBoxRecord::registerGraphics() {
+ _graphic.registerGraphics();
+}
+
+bool EditBoxRecord::hitTest(const ScriptPoint &point) const {
+ double x = point.x;
+ double y = point.y;
+ getTransform().inverse().transformPoint(x, y);
+ return _dest.contains((int)floor(x), (int)floor(y));
+}
+
+bool EditBoxRecord::pressRegion(int button) {
+ if (button != 0) {
+ return false;
+ }
+
+ s_focusedEditBox = this;
+ _isDirty = true;
+ callFunction("OnClicked");
+ return true;
+}
+
+bool EditBoxRecord::getRegionCursor(uint &cursorType, bool &isHot) const {
+ if (!_hasCursor) {
+ return false;
+ }
+
+ cursorType = _cursorType;
+ isHot = _cursorIsHot;
+ return true;
+}
+
+void EditBoxRecord::setString(const Common::String &text, bool callsScripts) {
+ if (text == _text) {
+ return;
+ }
+
+ _text = text;
+ _isDirty = true;
+ if (callsScripts) {
+ callFunction("OnEdit");
+ }
+}
+
+void EditBoxRecord::selectAll() {
+ s_focusedEditBox = this;
+ _isAllSelected = true;
+ _isDirty = true;
+}
+
+void EditBoxRecord::endSelection() {
+ _isAllSelected = false;
+ _isDirty = true;
+}
+
+bool EditBoxRecord::handleKey(Common::KeyCode key, uint16 ascii) {
+ if (!hasFocus()) {
+ return false;
+ }
+
+ switch (key) {
+ case Common::KEYCODE_RETURN:
+ case Common::KEYCODE_KP_ENTER:
+ callFunction("OnEditComplete");
+ return true;
+ case Common::KEYCODE_TAB:
+ if (g_system->getEventManager()->getModifierState() & Common::KBD_SHIFT) {
+ callFunction("OnShiftTabPressed");
+ } else {
+ callFunction("OnTabPressed");
+ }
+
+ return true;
+ case Common::KEYCODE_BACKSPACE:
+ if (_isAllSelected) {
+ _isAllSelected = false;
+ setString("", true);
+ } else if (!_text.empty()) {
+ Common::String text = _text;
+ text.deleteLastChar();
+ setString(text, true);
+ }
+
+ return true;
+ default:
+ break;
+ }
+
+ if (ascii < 32 || ascii >= 127) {
+ return false;
+ }
+
+ Common::String text = _isAllSelected ? Common::String() : _text;
+ text += (char)ascii;
+
+ // A letter there is no room for stays out
+ if (getBitmapTextWidth(text, _fontID) > _dest.width()) {
+ callFunction("OnTooWide");
+ return true;
+ }
+
+ _isAllSelected = false;
+ setString(text, true);
+ return true;
+}
+
+static uint32 toSurfaceColor(const Graphics::ManagedSurface &surface, uint32 argb) {
+ return surface.format.ARGBToColor(argb >> 24, (argb >> 16) & 0xFF, (argb >> 8) & 0xFF, argb & 0xFF);
+}
+
+void EditBoxRecord::updateGraphics() {
+ _graphic.setClipRect(getScreenClip());
+ _graphic.setVisible(isShown());
+
+ const bool isFocused = hasFocus();
+ if (isFocused != _hadFocus) {
+ _hadFocus = isFocused;
+ _isDirty = true;
+ }
+
+ if (!_isDirty && !hasAlphaChanged()) {
+ return;
+ }
+
+ _isDirty = false;
+
+ Graphics::ManagedSurface &surface = _graphic._drawSurface;
+ surface.clear(0);
+
+ int colorID = isFocused ? _selectedColor : _unselectedColor;
+ if (!isNodeEnabled()) {
+ colorID = isFocused ? _disabledSelectedColor : _disabledUnselectedColor;
+ }
+
+ _layout.layout(Common::String::format("<f%d><vc>", _fontID) + _text, surface.w, surface.h, colorID);
+ const ScriptRect &bounds = _layout.getBounds();
+
+ if (_isAllSelected && !_text.empty()) {
+ const Common::Rect area(MAX<int>(bounds.left, 0), 0, MIN<int>(bounds.right, surface.w), surface.h);
+ if (!area.isEmpty()) {
+ surface.fillRect(area, toSurfaceColor(surface, applyAlpha(_selectionColor)));
+ }
+ }
+
+ _layout.draw(surface, Common::Point(0, 0), takeModColor(0xFFFFFFFF));
+
+ // The caret goes after the text while the box has the keyboard
+ if (isFocused) {
+ const int x = CLIP<int>(_text.empty() ? 1 : bounds.right + 1, 0, surface.w - 1);
+ surface.vLine(x, 2, surface.h - 3, toSurfaceColor(surface, applyAlpha(_caretColor)));
+ }
+
+ _graphic.setNeedsRedraw(true);
+}
+
+static int editBoxSelectAll(lua_State *L) {
+ EditBoxRecord *editBox = dynamic_cast<EditBoxRecord *>(checkRecord(L, 1));
+ if (editBox) {
+ editBox->selectAll();
+ }
+
+ return 0;
+}
+
+static int editBoxEndSelection(lua_State *L) {
+ EditBoxRecord *editBox = dynamic_cast<EditBoxRecord *>(checkRecord(L, 1));
+ if (editBox) {
+ editBox->endSelection();
+ }
+
+ return 0;
+}
+
+bool EditBoxRecord::getField(const Common::String &key) {
+ lua_State *L = getLua();
+
+ if (key == "onScreen") {
+ pushRect(L, _dest);
+ } else if (key == "enteredString") {
+ lua_pushstring(L, _text.c_str());
+ } else if (key == "fontIdx") {
+ lua_pushinteger(L, _fontID);
+ } else if (key == "selectedColor") {
+ lua_pushinteger(L, _selectedColor);
+ } else if (key == "unselectedColor") {
+ lua_pushinteger(L, _unselectedColor);
+ } else if (key == "disabledSelectedColor") {
+ lua_pushinteger(L, _disabledSelectedColor);
+ } else if (key == "disabledUnselectedColor") {
+ lua_pushinteger(L, _disabledUnselectedColor);
+ } else if (key == "caretColor") {
+ pushColor(L, _caretColor);
+ } else if (key == "selectionBgColor" || key == "disabledSelectionBgColor") {
+ pushColor(L, _selectionColor);
+ } else if (key == "SelectAll") {
+ lua_pushcfunction(L, editBoxSelectAll);
+ } else if (key == "EndSelection") {
+ lua_pushcfunction(L, editBoxEndSelection);
+ } else {
+ return false;
+ }
+
+ return true;
+}
+
+bool EditBoxRecord::setField(const Common::String &key) {
+ lua_State *L = getLua();
+
+ if (key == "onScreen") {
+ _dest = checkRect(L, 3);
+ applyDest();
+ } else if (key == "enteredString") {
+ setString(luaL_checkstring(L, 3), false);
+ } else {
+ return false;
+ }
+
+ return true;
+}
+
} // End of namespace Script
} // End of namespace Nancy
diff --git a/engines/nancy/script/v5/widgets.h b/engines/nancy/script/v5/widgets.h
index 844b5af687f..56f3542e21a 100644
--- a/engines/nancy/script/v5/widgets.h
+++ b/engines/nancy/script/v5/widgets.h
@@ -25,6 +25,7 @@
#include "engines/nancy/script/records.h"
#include "engines/nancy/script/types.h"
+#include "engines/nancy/script/v5/bitmaptext.h"
#include "engines/nancy/script/v5/cliptransformer.h"
namespace Nancy {
@@ -216,6 +217,65 @@ private:
bool _isDragging = false;
};
+// Nancy26: a line of text the player types in, like the name of a saved game.
+// A click gives it the keyboard; its scripts hear of every change (OnEdit), of
+// Enter (OnEditComplete), of Tab, and of a letter that didn't fit (OnTooWide).
+// What is selected gets replaced by what is typed next.
+class EditBoxRecord : public Record {
+public:
+ EditBoxRecord(SceneContext &context);
+
+ RecordType getType() const override { return kRecordEditBox; }
+ ~EditBoxRecord() override;
+
+ bool isMouseRegion() const override { return true; }
+ bool hitTest(const ScriptPoint &point) const override;
+ bool pressRegion(int button) override;
+ bool getRegionCursor(uint &cursorType, bool &isHot) const override;
+ bool handleKey(Common::KeyCode key, uint16 ascii) override;
+
+ void updateGraphics() override;
+ void registerGraphics() override;
+
+ void selectAll();
+ void endSelection();
+
+protected:
+ void readTable(int tableIndex) override;
+ bool prepareReset() override { return true; }
+ void onZChanged() override;
+ bool hasTransform() const override { return true; }
+ void onTransformChanged() override { applyDest(); }
+ bool getField(const Common::String &key) override;
+ bool setField(const Common::String &key) override;
+
+private:
+ bool hasFocus() const;
+ void applyDest();
+ void setString(const Common::String &text, bool callsScripts);
+
+ ScriptRect _dest;
+ Common::String _text;
+ bool _isAllSelected = false;
+
+ int _fontID = 0;
+ int _selectedColor = 0; // font colors, while it has the keyboard and while not
+ int _unselectedColor = 0;
+ int _disabledSelectedColor = 0;
+ int _disabledUnselectedColor = 0;
+ uint32 _caretColor = 0xFFFFFFFF;
+ uint32 _selectionColor = 0xFF3F3F3F;
+
+ bool _hasCursor = false;
+ uint _cursorType = 0;
+ bool _cursorIsHot = false;
+
+ RecordGraphic _graphic;
+ BitmapText _layout;
+ bool _isDirty = true;
+ bool _hadFocus = false;
+};
+
} // End of namespace Script
} // End of namespace Nancy
Commit: 4c0111f8f7e2ca894b0d12c4667cfb908dcc79be
https://github.com/scummvm/scummvm/commit/4c0111f8f7e2ca894b0d12c4667cfb908dcc79be
Author: Filippos Karapetis (bluegr at gmail.com)
Date: 2026-11-06T04:10:57+02:00
Commit Message:
NANCY: NANCY26: Start the UI streams when the game starts
Nancy26's UI, its managers and its cheat tools are scripted scenes that
run in streams of their own. The engine now starts these streams when
the game starts, under the names the scripts use for them ("MAIN",
"UI", "MANAGER").
The scripts that a scene includes may now create records before the
scene's summary. A movie with an empty source rect, as Nancy26's
scripts give it, now shows the whole of each frame instead of nothing.
Changed paths:
engines/nancy/script/record.cpp
engines/nancy/script/records.cpp
engines/nancy/script/scenecontext.cpp
engines/nancy/script/v5/streamtree.cpp
engines/nancy/state/scene.cpp
engines/nancy/state/scene.h
engines/nancy/state/scenestream.cpp
diff --git a/engines/nancy/script/record.cpp b/engines/nancy/script/record.cpp
index 82313fa047c..70156dafa78 100644
--- a/engines/nancy/script/record.cpp
+++ b/engines/nancy/script/record.cpp
@@ -899,7 +899,8 @@ static int createRecord(lua_State *L) {
return luaL_argerror(L, 1, "Expected a table as the parameter");
}
- if (type != kRecordSummary && !context->hasRecords()) {
+ // Nancy26's scenes include scripts that make records before the summary
+ if (type != kRecordSummary && !context->hasRecords() && g_nancy->getGameType() < kGameTypeNancy26) {
return luaL_error(L, "Summary AR must be the first AR in the scene");
}
diff --git a/engines/nancy/script/records.cpp b/engines/nancy/script/records.cpp
index 69494f01e14..c1e9b5551eb 100644
--- a/engines/nancy/script/records.cpp
+++ b/engines/nancy/script/records.cpp
@@ -2295,9 +2295,13 @@ void MovieRecord::readTable(int tableIndex) {
readField(L, tableIndex, "visible", _isVisible);
// The whole of every frame, unless a part of it is asked for
+ // An empty source, like Nancy26's (-1, -1, -1, -1), shows the whole movie
_source = ScriptRect(0, 0, _player.getWidth(), _player.getHeight());
if (pushField(L, tableIndex, "source")) {
- _source = checkRect(L, -1);
+ if (!checkRect(L, -1).isEmpty()) {
+ _source = checkRect(L, -1);
+ }
+
lua_pop(L, 1);
}
diff --git a/engines/nancy/script/scenecontext.cpp b/engines/nancy/script/scenecontext.cpp
index f6da1be9a72..5cb2e9afd63 100644
--- a/engines/nancy/script/scenecontext.cpp
+++ b/engines/nancy/script/scenecontext.cpp
@@ -147,6 +147,12 @@ bool SceneContext::load() {
// more of them, and so can the scripts it includes; the last one that names
// a background is the one that shows.
_summary = _newRecords.empty() ? nullptr : toSummaryRecord(_newRecords[0]);
+
+ // Nancy26's included scripts make records first, and a scene has only one summary
+ for (uint i = 0; !_summary && i < _newRecords.size() && g_nancy->getGameType() >= kGameTypeNancy26; ++i) {
+ _summary = toSummaryRecord(_newRecords[i]);
+ }
+
for (Record *record : _newRecords) {
SummaryRecord *summary = toSummaryRecord(record);
if (_summary && summary && !summary->getBackgroundName().empty()) {
diff --git a/engines/nancy/script/v5/streamtree.cpp b/engines/nancy/script/v5/streamtree.cpp
index c47f5b7986e..0344aef3089 100644
--- a/engines/nancy/script/v5/streamtree.cpp
+++ b/engines/nancy/script/v5/streamtree.cpp
@@ -259,5 +259,22 @@ void Scene::onMainStreamBandChanged() {
_viewport.setZOrder(Script::RecordGraphic::getBackgroundZOrder(_scriptScene->getZOffset()));
}
+// Nancy26 makes its UI of records like any other scene, which the exe puts
+// over the whole screen. The stream of the cheat tools comes with it.
+void Scene::initNancy26UI() {
+ // The exe begins the managers first, which the scripts of the UI call on
+ beginManagers();
+
+ StreamFlags uiFlags;
+ uiFlags.isInViewport = false;
+ _streams.begin(SceneStreamManager::getUIStreamName(), "UI_MAIN_SC", 0, uiFlags);
+ _streams.loadNow(SceneStreamManager::getUIStreamName());
+
+ StreamFlags cheatFlags;
+ cheatFlags.z = 10.0;
+ cheatFlags.isInViewport = false;
+ _streams.begin("CHEAT", "CHEAT_MAIN_SC", 0, cheatFlags);
+}
+
} // End of namespace State
} // End of namespace Nancy
diff --git a/engines/nancy/state/scene.cpp b/engines/nancy/state/scene.cpp
index f755b87603f..d119034303b 100644
--- a/engines/nancy/state/scene.cpp
+++ b/engines/nancy/state/scene.cpp
@@ -2320,7 +2320,7 @@ void Scene::loadScriptedScene(bool fromSaveFile) {
const Common::String sceneName = _nextScriptSceneName.empty() ?
Common::String::format("s%u", _sceneState.nextScene.sceneID) : _nextScriptSceneName;
- Script::SceneContext *scriptScene = new Script::SceneContext("MainStream", sceneName, _sceneState.nextScene.frameID, 0);
+ Script::SceneContext *scriptScene = new Script::SceneContext(SceneStreamManager::getMainStreamName(), sceneName, _sceneState.nextScene.frameID, 0);
if (!scriptScene->load()) {
// A scene that can't be loaded leaves the player where they are
warning("Failed to load scene %s", sceneName.c_str());
@@ -3186,6 +3186,13 @@ void Scene::initUI() {
delete _ndui;
_ndui = new UI::NDUI::Manager();
+#ifdef ENABLE_NANCY_V5
+ if (g_nancy->getGameType() >= kGameTypeNancy26) {
+ initNancy26UI();
+ return;
+ }
+#endif
+
// The UI of Nancy19 is made by the scripts of a stream of its own, which
// gets back to the scene once the panels are there
if (g_nancy->getGameType() >= kGameTypeNancy19) {
@@ -3233,7 +3240,14 @@ void Scene::initUI() {
// Nancy22 begins the stream of the managers along with the game. They keep what
// the scripts of every scene ask them for, and send each other messages.
void Scene::beginManagers() {
- _streams.begin(SceneStreamManager::getManagerStreamName(), "ManagerMain_SC", 0, StreamFlags());
+ // Nancy26's are in front of everything
+ StreamFlags flags;
+ if (g_nancy->getGameType() >= kGameTypeNancy26) {
+ flags.z = 10.0;
+ }
+
+ const char *sceneName = g_nancy->getGameType() >= kGameTypeNancy26 ? "MANAGER_MAIN_SC" : "ManagerMain_SC";
+ _streams.begin(SceneStreamManager::getManagerStreamName(), sceneName, 0, flags);
_streams.loadNow(SceneStreamManager::getManagerStreamName());
}
diff --git a/engines/nancy/state/scene.h b/engines/nancy/state/scene.h
index c6c1e3cf2f6..7acdfe4acf0 100644
--- a/engines/nancy/state/scene.h
+++ b/engines/nancy/state/scene.h
@@ -570,7 +570,8 @@ private:
// Whether esc was already down last frame, so a held key only skips once
bool _escHeld = false;
#ifdef ENABLE_NANCY_V5
- // Nancy26 hands its records all the input
+ // Nancy26 makes its UI of records, and hands its records all the input
+ void initNancy26UI();
void handleNancy26Input(NancyInput &input);
bool _isEscSkipping = false; // the press that skipped stays away from the scripts
diff --git a/engines/nancy/state/scenestream.cpp b/engines/nancy/state/scenestream.cpp
index 47053c124cd..87978036f1f 100644
--- a/engines/nancy/state/scenestream.cpp
+++ b/engines/nancy/state/scenestream.cpp
@@ -346,21 +346,32 @@ static const char *const kUIStreamName = "UIStream";
static const char *const kEnvStreamName = "EnvStream";
static const char *const kManagerStreamName = "ManagerStream";
+// Nancy26 calls the streams the exe begins by itself by other names, which the
+// scripts use too
+static const char *const kNancy26MainStreamName = "MAIN";
+static const char *const kNancy26UIStreamName = "UI";
+static const char *const kNancy26EnvStreamName = "ENV";
+static const char *const kNancy26ManagerStreamName = "MANAGER";
+
const char *SceneStreamManager::getMainStreamName() {
- return kMainStreamName;
+ return g_nancy->getGameType() >= kGameTypeNancy26 ? kNancy26MainStreamName : kMainStreamName;
}
const char *SceneStreamManager::getUIStreamName() {
- return kUIStreamName;
+ return g_nancy->getGameType() >= kGameTypeNancy26 ? kNancy26UIStreamName : kUIStreamName;
}
const char *SceneStreamManager::getManagerStreamName() {
- return kManagerStreamName;
+ return g_nancy->getGameType() >= kGameTypeNancy26 ? kNancy26ManagerStreamName : kManagerStreamName;
+}
+
+static const char *getEnvStreamName() {
+ return g_nancy->getGameType() >= kGameTypeNancy26 ? kNancy26EnvStreamName : kEnvStreamName;
}
#ifdef ENABLE_NANCY_V4
const Script::ScriptMatrix *SceneStreamManager::getTransform(const Common::String &name) {
- if (name.equalsIgnoreCase(kMainStreamName)) {
+ if (name.equalsIgnoreCase(getMainStreamName())) {
return &_mainStreamTransform;
}
@@ -372,7 +383,7 @@ void SceneStreamManager::setTransform(const Common::String &name, const Script::
Script::ScriptMatrix *matrix = nullptr;
ViewTransform *view = nullptr;
- if (name.equalsIgnoreCase(kMainStreamName)) {
+ if (name.equalsIgnoreCase(getMainStreamName())) {
matrix = &_mainStreamTransform;
view = &_mainStreamViewTransform;
} else {
@@ -426,7 +437,7 @@ bool SceneStreamManager::skipMovies() {
#endif
const ViewTransform *SceneStreamManager::getViewTransform(const Common::String &name) {
- if (name.equalsIgnoreCase(kMainStreamName)) {
+ if (name.equalsIgnoreCase(getMainStreamName())) {
return &_mainStreamViewTransform;
}
@@ -438,7 +449,7 @@ double SceneStreamManager::getZ(const Common::String &name) const {
const SceneStream *stream = find(name);
#ifdef ENABLE_NANCY_V5
if (g_nancy->getGameType() >= kGameTypeNancy26) {
- if (name.equalsIgnoreCase(kMainStreamName)) {
+ if (name.equalsIgnoreCase(getMainStreamName())) {
return _mainNodeState.z;
}
@@ -461,14 +472,14 @@ int32 SceneStreamManager::getFrontZOffset() const {
}
void SceneStreamManager::getStreamNames(Common::Array<Common::String> &names, bool withUI) const {
- if (withUI && find(kUIStreamName)) {
- names.push_back(kUIStreamName);
+ if (withUI && find(getUIStreamName())) {
+ names.push_back(getUIStreamName());
}
for (const SceneStream *stream : _streams) {
if (!stream) {
- names.push_back(kMainStreamName);
- } else if (!stream->isEnded() && !stream->getName().equalsIgnoreCase(kUIStreamName)) {
+ names.push_back(getMainStreamName());
+ } else if (!stream->isEnded() && !stream->getName().equalsIgnoreCase(getUIStreamName())) {
names.push_back(stream->getName());
}
}
@@ -565,7 +576,7 @@ void SceneStreamManager::changeScene(const Common::String &name, const SceneChan
return;
}
- if (name.empty() || name.equalsIgnoreCase(kMainStreamName)) {
+ if (name.empty() || name.equalsIgnoreCase(getMainStreamName())) {
SceneStream *running = _running;
_running = nullptr;
NancySceneState.changeScene(sceneDescription);
@@ -580,7 +591,7 @@ void SceneStreamManager::changeScene(const Common::String &name, const Common::S
if (stream) {
stream->changeScene(sceneName, frameID);
#ifdef ENABLE_NANCY_V4
- } else if (name.empty() || name.equalsIgnoreCase(kMainStreamName)) {
+ } else if (name.empty() || name.equalsIgnoreCase(getMainStreamName())) {
// Nancy20 has scenes of the main stream that go by name
SceneStream *running = _running;
_running = nullptr;
@@ -593,7 +604,7 @@ void SceneStreamManager::changeScene(const Common::String &name, const Common::S
}
Common::String SceneStreamManager::getSceneName(const Common::String &name) const {
- if (name.equalsIgnoreCase(kMainStreamName)) {
+ if (name.equalsIgnoreCase(getMainStreamName())) {
return NancySceneState.getMainSceneName();
}
@@ -603,7 +614,7 @@ Common::String SceneStreamManager::getSceneName(const Common::String &name) cons
#ifdef ENABLE_NANCY_V4
const Script::SceneContext *SceneStreamManager::findScriptScene(const Common::String &name) const {
- if (name.equalsIgnoreCase(kMainStreamName)) {
+ if (name.equalsIgnoreCase(getMainStreamName())) {
return NancySceneState.getScriptScene();
}
@@ -818,11 +829,11 @@ void SceneStreamManager::changeEnvironmentStream(const ENVS &envs, const Common:
}
if (sceneName.empty()) {
- end(kEnvStreamName);
- } else if (find(kEnvStreamName)) {
- changeScene(kEnvStreamName, sceneName, 0);
+ end(getEnvStreamName());
+ } else if (find(getEnvStreamName())) {
+ changeScene(getEnvStreamName(), sceneName, 0);
} else {
- begin(kEnvStreamName, sceneName, 0, StreamFlags());
+ begin(getEnvStreamName(), sceneName, 0, StreamFlags());
}
}
Commit: 794178c2fcc1b40be0d065e15153c91f96a6252d
https://github.com/scummvm/scummvm/commit/794178c2fcc1b40be0d065e15153c91f96a6252d
Author: Filippos Karapetis (bluegr at gmail.com)
Date: 2026-11-06T04:10:59+02:00
Commit Message:
NANCY: NANCY26: Add the functions that Nancy26's scripts call
Nancy26's menus are made of scripts, which save, load and start games,
quit, and change the volume and the settings through new functions of
Game, Sound and the other script objects.
Changed paths:
A engines/nancy/script/v5/gamefunctions.cpp
A engines/nancy/script/v5/gamefunctions.h
engines/nancy/module.mk
engines/nancy/script/api.cpp
engines/nancy/script/api.h
engines/nancy/script/gameapi.cpp
engines/nancy/script/records.cpp
engines/nancy/script/scenecontext.cpp
engines/nancy/ui/ndui/manager.h
engines/nancy/ui/ndui/saveload.cpp
diff --git a/engines/nancy/module.mk b/engines/nancy/module.mk
index 49cc753fab4..5e27336fde8 100644
--- a/engines/nancy/module.mk
+++ b/engines/nancy/module.mk
@@ -243,6 +243,7 @@ MODULE_OBJS += \
script/v5/bitmaptext.o \
script/v5/bootobjects.o \
script/v5/cliptransformer.o \
+ script/v5/gamefunctions.o \
script/v5/messaging.o \
script/v5/recordnode.o \
script/v5/scriptinput.o \
diff --git a/engines/nancy/script/api.cpp b/engines/nancy/script/api.cpp
index cbedf48ff89..43c54590c35 100644
--- a/engines/nancy/script/api.cpp
+++ b/engines/nancy/script/api.cpp
@@ -32,6 +32,10 @@
#include "engines/nancy/script/record.h"
#include "engines/nancy/script/types.h"
+#ifdef ENABLE_NANCY_V5
+#include "engines/nancy/script/v5/gamefunctions.h"
+#endif
+
namespace Nancy {
namespace Script {
@@ -90,6 +94,12 @@ void registerAPI(lua_State *L) {
registerUIAPI(L);
registerConvoAPI(L);
registerRecordAPI(L);
+
+#ifdef ENABLE_NANCY_V5
+ if (g_nancy->getGameType() >= kGameTypeNancy26) {
+ registerNancy26GameAPI(L);
+ }
+#endif
}
} // End of namespace Script
diff --git a/engines/nancy/script/api.h b/engines/nancy/script/api.h
index 82162a5dc10..35fe6c70cd6 100644
--- a/engines/nancy/script/api.h
+++ b/engines/nancy/script/api.h
@@ -114,6 +114,12 @@ Common::KeyCode checkKey(lua_State *L, int index);
// Returns false when there is none.
bool findText(const Common::String &key, Common::String &text);
+#ifdef ENABLE_NANCY_V5
+// Nancy26: the functions an Override draws with in its Render function
+// ("DrawRect", "DrawLine", "DrawTri", "DrawCircle"). Returns false for others.
+bool pushRecordDrawFunction(lua_State *L, const Common::String &name);
+#endif
+
// The panels and controls scripts build the UI out of
void registerUIAPI(lua_State *L);
diff --git a/engines/nancy/script/gameapi.cpp b/engines/nancy/script/gameapi.cpp
index e30d60df288..09ef5cc76ad 100644
--- a/engines/nancy/script/gameapi.cpp
+++ b/engines/nancy/script/gameapi.cpp
@@ -721,6 +721,25 @@ static const luaL_Reg kDrawFunctions[] = {
{ nullptr, nullptr }
};
+#ifdef ENABLE_NANCY_V5
+bool pushRecordDrawFunction(lua_State *L, const Common::String &name) {
+ // Nancy26's Overrides draw by themselves: this:DrawRect(rect, color)
+ if (!name.hasPrefix("Draw")) {
+ return false;
+ }
+
+ const Common::String shape = name.substr(4);
+ for (const luaL_Reg *function = kDrawFunctions; function->name; ++function) {
+ if (shape == function->name && shape != "OVL") {
+ lua_pushcfunction(L, function->func);
+ return true;
+ }
+ }
+
+ return false;
+}
+#endif
+
// Save and Load, which keep what a script hands them in the saved game
enum SavedValueTag {
@@ -1134,7 +1153,15 @@ void pushSoundChannel(lua_State *L, uint16 channel) {
pushValue(L, kSoundChannelType, channel);
}
+static bool findSoundChannel(const char *name, uint16 &result);
+
+// Nancy26 also names channels with strings ("UIFX")
uint16 checkSoundChannel(lua_State *L, int index) {
+ uint16 channel = 0;
+ if (lua_type(L, index) == LUA_TSTRING && findSoundChannel(lua_tostring(L, index), channel)) {
+ return channel;
+ }
+
return *(const uint16 *)checkUserData(L, index, kSoundChannelType);
}
@@ -1154,38 +1181,46 @@ bool isVoicePlaying() {
return false;
}
-static int soundChannelIndex(lua_State *L) {
- const char *name = luaL_checkstring(L, 2);
-
+static bool findSoundChannel(const char *name, uint16 &result) {
if (g_nancy->getGameType() >= kGameTypeNancy24) {
for (const SoundChannelName &channel : kNancy24SoundChannelNames) {
if (scumm_stricmp(channel.name, name) == 0) {
- pushSoundChannel(L, channel.channel);
- return 1;
+ result = channel.channel;
+ return true;
}
}
} else if (g_nancy->getGameType() >= kGameTypeNancy22) {
for (const SoundChannelName &channel : kNancy22SoundChannelNames) {
if (scumm_stricmp(channel.name, name) == 0) {
- pushSoundChannel(L, channel.channel);
- return 1;
+ result = channel.channel;
+ return true;
}
}
} else {
for (const SoundChannelName &channel : kSoundChannelNames) {
if (scumm_stricmp(channel.name, name) == 0) {
- pushSoundChannel(L, channel.channel);
- return 1;
+ result = channel.channel;
+ return true;
}
}
if (g_nancy->getGameType() >= kGameTypeNancy21 && scumm_stricmp(name, "AllExceptTheme") == 0) {
- pushSoundChannel(L, kChannelAllExceptTheme);
- return 1;
+ result = kChannelAllExceptTheme;
+ return true;
}
}
- lua_pushnil(L);
+ return false;
+}
+
+static int soundChannelIndex(lua_State *L) {
+ uint16 channel = 0;
+ if (findSoundChannel(luaL_checkstring(L, 2), channel)) {
+ pushSoundChannel(L, channel);
+ } else {
+ lua_pushnil(L);
+ }
+
return 1;
}
@@ -1377,12 +1412,30 @@ static int sceneInclude(lua_State *L) {
}
// Scene:ChangeScene(stream, scene), which goes to the first frame of the scene
+// Nancy26 also takes Scene:ChangeScene(scene), (scene, frame) and
+// (stream, scene, frame); no stream stands for the one of the scene
static int sceneChangeScene(lua_State *L) {
SceneContext *context = checkContext(L);
- const char *streamName = luaL_checkstring(L, 2);
- const char *sceneName = luaL_checkstring(L, 3);
+ const int top = lua_gettop(L);
- context->changeScene(streamName, sceneName, 0);
+ Common::String streamName;
+ Common::String sceneName;
+ int frame = 0;
+
+ if (top == 2 && g_nancy->getGameType() >= kGameTypeNancy26) {
+ sceneName = luaL_checkstring(L, 2);
+ } else if (top == 3 && lua_type(L, 3) == LUA_TNUMBER) {
+ sceneName = luaL_checkstring(L, 2);
+ frame = luaL_checkint(L, 3);
+ } else {
+ streamName = luaL_checkstring(L, 2);
+ sceneName = luaL_checkstring(L, 3);
+ if (top >= 4) {
+ frame = luaL_checkint(L, 4);
+ }
+ }
+
+ context->changeScene(streamName, sceneName, (uint16)frame);
lua_pushboolean(L, true);
return 1;
}
@@ -1591,7 +1644,8 @@ static int streamsGetFrame(lua_State *L) {
// Streams:GetStreams(withUI), Nancy21: the names of the running streams, the
// main stream among them. The one of the UI is only in there when asked for.
static int streamsGetStreams(lua_State *L) {
- const bool withUI = lua_toboolean(L, 2) != 0;
+ // Nancy26 lists them all
+ const bool withUI = lua_toboolean(L, 2) != 0 || g_nancy->getGameType() >= kGameTypeNancy26;
Common::Array<Common::String> names;
NancySceneState.getStreams().getStreamNames(names, withUI);
@@ -2233,9 +2287,14 @@ static const luaL_Reg kViewportFunctions[] = {
{ nullptr, nullptr }
};
-// Log:Write(text)
+// Log:Write(text), or from Nancy26 on, Log:Write(location, text)
static int logWrite(lua_State *L) {
- debugC(1, kDebugScene, "Script: %s", luaL_checkstring(L, 2));
+ if (lua_gettop(L) >= 3) {
+ debugC(1, kDebugScene, "Script: %s: %s", luaL_checkstring(L, 2), luaL_checkstring(L, 3));
+ } else {
+ debugC(1, kDebugScene, "Script: %s", luaL_checkstring(L, 2));
+ }
+
return 0;
}
diff --git a/engines/nancy/script/records.cpp b/engines/nancy/script/records.cpp
index c1e9b5551eb..5dfac0b892d 100644
--- a/engines/nancy/script/records.cpp
+++ b/engines/nancy/script/records.cpp
@@ -1172,6 +1172,12 @@ bool OverrideRecord::getField(const Common::String &key) {
return true;
}
+#ifdef ENABLE_NANCY_V5
+ if (g_nancy->getGameType() >= kGameTypeNancy26) {
+ return pushRecordDrawFunction(getLua(), key);
+ }
+#endif
+
return false;
}
diff --git a/engines/nancy/script/scenecontext.cpp b/engines/nancy/script/scenecontext.cpp
index 5cb2e9afd63..ff253ceb374 100644
--- a/engines/nancy/script/scenecontext.cpp
+++ b/engines/nancy/script/scenecontext.cpp
@@ -728,9 +728,13 @@ void SceneContext::handleInput(NancyInput &input) {
}
}
-void SceneContext::changeScene(const Common::String &streamName, const Common::String &sceneName, uint16 frame) {
+void SceneContext::changeScene(const Common::String &name, const Common::String &sceneName, uint16 frame) {
State::SceneStreamManager &streams = NancySceneState.getStreams();
+ // No name stands for the stream of this scene, which isn't always the one
+ // that runs: Nancy26 hands the input to the records of all streams at once
+ const Common::String &streamName = name.empty() ? _streamName : name;
+
_hasChangedScene = true;
// The scenes of the main stream mostly go by number
diff --git a/engines/nancy/script/v5/gamefunctions.cpp b/engines/nancy/script/v5/gamefunctions.cpp
new file mode 100644
index 00000000000..3c7c4c75adf
--- /dev/null
+++ b/engines/nancy/script/v5/gamefunctions.cpp
@@ -0,0 +1,513 @@
+/* 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 "common/config-manager.h"
+#include "common/debug.h"
+#include "common/events.h"
+#include "common/system.h"
+
+#include "audio/mixer.h"
+
+#include "engines/nancy/enginedata.h"
+#include "engines/nancy/graphics.h"
+#include "engines/nancy/nancy.h"
+
+#include "engines/nancy/script/api.h"
+#include "engines/nancy/script/luabind.h"
+#include "engines/nancy/script/types.h"
+
+#include "engines/nancy/script/v5/gamefunctions.h"
+#include "engines/nancy/script/v5/scriptinput.h"
+
+#include "engines/nancy/state/scene.h"
+
+#include "engines/nancy/ui/ndui/manager.h"
+
+namespace Nancy {
+namespace Script {
+
+// Puts a function in front of an entry of the metatable of a type, such as its
+// __index. What was there becomes the upvalue of the function, which hands the
+// call on to it with callReplaced() for what it doesn't handle itself.
+static void replaceFunction(lua_State *L, const char *typeName, const char *name, lua_CFunction function) {
+ luaL_getmetatable(L, typeName);
+ lua_getfield(L, -1, name);
+ lua_pushcclosure(L, function, 1);
+ lua_setfield(L, -2, name);
+ lua_pop(L, 1);
+}
+
+static int callReplaced(lua_State *L) {
+ lua_pushvalue(L, lua_upvalueindex(1));
+ lua_insert(L, 1);
+ lua_call(L, lua_gettop(L) - 1, LUA_MULTRET);
+ return lua_gettop(L);
+}
+
+// Adds functions to the metatable of a type
+static void addFunctions(lua_State *L, const char *typeName, const luaL_Reg *functions) {
+ luaL_getmetatable(L, typeName);
+ luaL_register(L, nullptr, functions);
+ lua_pop(L, 1);
+}
+
+// Flags and VarTable
+
+// Flags:All() and VarTable:All(): the names of all of them, for the cheat tools
+static void pushNameList(lua_State *L, const Common::Array<Common::String> &names) {
+ lua_createtable(L, names.size(), 0);
+ for (uint i = 0; i < names.size(); ++i) {
+ lua_pushstring(L, names[i].c_str());
+ lua_rawseti(L, -2, i + 1);
+ }
+}
+
+static int flagsAll(lua_State *L) {
+ const EVNT *flags = GetEngineData(EVNT);
+ pushNameList(L, flags ? flags->eventFlagNames : Common::Array<Common::String>());
+ return 1;
+}
+
+static int varTableAll(lua_State *L) {
+ Common::Array<Common::String> names;
+ const ScriptBootData *boot = GetEngineData(ScriptBootData);
+ for (ScriptBootData::NameSet::const_iterator it = boot->valueNames.begin(); it != boot->valueNames.end(); ++it) {
+ names.push_back(it->_key);
+ }
+
+ pushNameList(L, names);
+ return 1;
+}
+
+static int flagsIndex(lua_State *L) {
+ if (strcmp(luaL_checkstring(L, 2), "All") == 0) {
+ lua_pushcfunction(L, flagsAll);
+ return 1;
+ }
+
+ return callReplaced(L);
+}
+
+static int varTableIndex(lua_State *L) {
+ if (strcmp(luaL_checkstring(L, 2), "All") == 0) {
+ lua_pushcfunction(L, varTableAll);
+ return 1;
+ }
+
+ return callReplaced(L);
+}
+
+// Cursor: where the mouse is on the screen, and whether it was just clicked twice
+static int cursorIndex(lua_State *L) {
+ const Common::String key = luaL_checkstring(L, 2);
+
+ if (key == "activePoint") {
+ pushPoint(L, getScriptMousePoint());
+ return 1;
+ } else if (key == "leftDouble" || key == "rightDouble") {
+ lua_pushboolean(L, isDoubleClick(key == "leftDouble" ? 0 : 1));
+ return 1;
+ }
+
+ return callReplaced(L);
+}
+
+// Key
+
+// Key:IsDown(key). Only the modifier keys can be told apart while they
+// are held; the others come one press at a time.
+static int keyIsDown(lua_State *L) {
+ const int modifiers = g_system->getEventManager()->getModifierState();
+
+ bool isDown = false;
+ switch (checkKey(L, 2)) {
+ case Common::KEYCODE_LCTRL:
+ isDown = (modifiers & Common::KBD_CTRL) != 0;
+ break;
+ case Common::KEYCODE_LSHIFT:
+ isDown = (modifiers & Common::KBD_SHIFT) != 0;
+ break;
+ default:
+ break;
+ }
+
+ lua_pushboolean(L, isDown);
+ return 1;
+}
+
+// Key.F1 to Key.F12, and Key:IsDown()
+static int keyIndex(lua_State *L) {
+ const char *name = luaL_checkstring(L, 2);
+
+ if (strcmp(name, "IsDown") == 0) {
+ lua_pushcfunction(L, keyIsDown);
+ return 1;
+ }
+
+ for (int i = 0; i < 12; ++i) {
+ if (Common::String::format("F%d", i + 1).equalsIgnoreCase(name)) {
+ pushKey(L, (Common::KeyCode)(Common::KEYCODE_F1 + i));
+ return 1;
+ }
+ }
+
+ return callReplaced(L);
+}
+
+// Game
+
+// What the cheat tools switch on
+static bool s_isCheatMode = false;
+static bool s_isFastConvo = false;
+
+// How many times a new game began since the game was started
+static uint s_numRestarts = 0;
+
+// The saved games the scripts made by themselves, the second chances, which
+// the dialog for loading leaves out. ScummVM's saves have no place for that, so
+// their names are kept with the settings of the game.
+static const char *const kContinueSavesKey = "continue_saves";
+
+static Common::Array<Common::String> getContinueSaves() {
+ Common::Array<Common::String> names;
+ if (ConfMan.hasKey(kContinueSavesKey, ConfMan.getActiveDomainName())) {
+ Common::String list = ConfMan.get(kContinueSavesKey, ConfMan.getActiveDomainName());
+ for (Common::String::size_type start = 0; start < list.size(); ) {
+ Common::String::size_type end = list.findFirstOf('|', start);
+ if (end == Common::String::npos) {
+ end = list.size();
+ }
+
+ names.push_back(list.substr(start, end - start));
+ start = end + 1;
+ }
+ }
+
+ return names;
+}
+
+static void setContinueSave(const Common::String &name, bool isContinue) {
+ Common::Array<Common::String> names = getContinueSaves();
+ Common::String list;
+ for (const Common::String &other : names) {
+ if (!other.equalsIgnoreCase(name)) {
+ list += (list.empty() ? "" : "|") + other;
+ }
+ }
+
+ if (isContinue) {
+ list += (list.empty() ? "" : "|") + name;
+ }
+
+ ConfMan.set(kContinueSavesKey, list, ConfMan.getActiveDomainName());
+ ConfMan.flushToDisk();
+}
+
+// The name of a saved game, from a table { name, useAutotext }
+static Common::String readSaveName(lua_State *L, int index) {
+ Common::String name;
+ if (lua_isstring(L, index)) {
+ return lua_tostring(L, index);
+ }
+
+ luaL_checktype(L, index, LUA_TTABLE);
+ readField(L, index, "name", name);
+
+ bool usesAutotext = true;
+ readField(L, index, "useAutotext", usesAutotext);
+ if (usesAutotext) {
+ Common::String text;
+ if (findText(name, text)) {
+ name = text;
+ }
+ }
+
+ return name;
+}
+
+static UI::NDUI::Manager &getSaveManager(lua_State *L) {
+ UI::NDUI::Manager *ui = NancySceneState.getNDUI();
+ if (!ui) {
+ luaL_error(L, "There is no game to save or load");
+ }
+
+ return *ui;
+}
+
+// Game:Save({ name, useAutotext, isContinue }); the scripts' own saves are
+// second chances unless they say otherwise
+static int gameSave(lua_State *L) {
+ const Common::String name = readSaveName(L, 2);
+
+ bool isContinue = true;
+ if (lua_istable(L, 2)) {
+ readField(L, 2, "isContinue", isContinue);
+ }
+
+ getSaveManager(L).requestSave(name);
+ setContinueSave(name, isContinue);
+ return 0;
+}
+
+static int gameLoad(lua_State *L) {
+ getSaveManager(L).requestLoad(readSaveName(L, 2));
+ return 0;
+}
+
+static int gameIsContinue(lua_State *L) {
+ const Common::String name = readSaveName(L, 2);
+
+ bool isContinue = false;
+ for (const Common::String &other : getContinueSaves()) {
+ isContinue |= other.equalsIgnoreCase(name);
+ }
+
+ lua_pushboolean(L, isContinue);
+ return 1;
+}
+
+static int gameSaveExists(lua_State *L) {
+ lua_pushboolean(L, getSaveManager(L).hasSave(readSaveName(L, 2)));
+ return 1;
+}
+
+static int gameAllSaves(lua_State *L) {
+ Common::Array<Common::String> names;
+ getSaveManager(L).getSaveNames(names);
+
+ lua_createtable(L, names.size(), 0);
+ for (uint i = 0; i < names.size(); ++i) {
+ lua_pushstring(L, names[i].c_str());
+ lua_rawseti(L, -2, i + 1);
+ }
+
+ return 1;
+}
+
+static int gameNew(lua_State *L) {
+ ++s_numRestarts;
+ getSaveManager(L).requestNewGame();
+ return 0;
+}
+
+static int gameExit(lua_State *L) {
+ getSaveManager(L).requestQuit();
+ return 0;
+}
+
+static int gameSetWindowed(lua_State *L) {
+ g_system->beginGFXTransaction();
+ g_system->setFeatureState(OSystem::kFeatureFullscreenMode, !lua_toboolean(L, 2));
+ g_system->endGFXTransaction();
+ return 0;
+}
+
+static const luaL_Reg kGameFunctions[] = {
+ { "Save", gameSave },
+ { "Load", gameLoad },
+ { "IsContinue", gameIsContinue },
+ { "SaveExists", gameSaveExists },
+ { "AllSaves", gameAllSaves },
+ { "New", gameNew },
+ { "Exit", gameExit },
+ { "SetWindowed", gameSetWindowed },
+ { nullptr, nullptr }
+};
+
+static bool pushGameField(lua_State *L, const Common::String &key) {
+ for (const luaL_Reg *function = kGameFunctions; function->name; ++function) {
+ if (key == function->name) {
+ lua_pushcfunction(L, function->func);
+ return true;
+ }
+ }
+
+ if (key == "isWindowed") {
+ lua_pushboolean(L, !g_system->getFeatureState(OSystem::kFeatureFullscreenMode));
+ } else if (key == "time") {
+ lua_pushnumber(L, NancySceneState._timers.lastTotalTime.getTotalMilliseconds() / 1000.0);
+ } else if (key == "buildNumber") {
+ const ScriptBootData *boot = GetEngineData(ScriptBootData);
+ lua_pushstring(L, boot ? boot->buildNumber.c_str() : "");
+ } else if (key == "fastConvo") {
+ lua_pushboolean(L, s_isFastConvo);
+ } else if (key == "cheatMode") {
+ lua_pushboolean(L, s_isCheatMode);
+ } else if (key == "needsSave") {
+ lua_pushboolean(L, true);
+ } else if (key == "restarts") {
+ lua_pushinteger(L, s_numRestarts);
+ } else {
+ return false;
+ }
+
+ return true;
+}
+
+static int gameIndex(lua_State *L) {
+ if (pushGameField(L, luaL_checkstring(L, 2))) {
+ return 1;
+ }
+
+ return callReplaced(L);
+}
+
+// Only the settings of the cheat tools can be set
+static int gameNewIndex(lua_State *L) {
+ const Common::String key = luaL_checkstring(L, 2);
+
+ if (key == "cheatMode") {
+ s_isCheatMode = lua_toboolean(L, 3) != 0;
+ } else if (key == "fastConvo") {
+ s_isFastConvo = lua_toboolean(L, 3) != 0;
+ } else {
+ return luaL_error(L, "Field %s is not settable on Game ", key.c_str());
+ }
+
+ return 0;
+}
+
+// Viewport: the whole screen, which the UI is placed on
+static int viewportIndex(lua_State *L) {
+ const Common::String key = luaL_checkstring(L, 2);
+
+ if (key == "uiSize" || key == "uiLocation" || key == "windowSize") {
+ pushRect(L, ScriptRect(g_nancy->_graphics->getScreenBounds()));
+ return 1;
+ }
+
+ return callReplaced(L);
+}
+
+// Save, Sound, Scene and Log
+
+// Save:IsNameAcceptable(name): whether a saved game can go by the name
+static int saveIsNameAcceptable(lua_State *L) {
+ const Common::String name = luaL_checkstring(L, 2);
+
+ bool isAcceptable = !name.empty() && !name.hasPrefix(" ") && !name.hasSuffix(" ") && !name.hasSuffix(".");
+ for (uint i = 0; i < name.size() && isAcceptable; ++i) {
+ isAcceptable = (byte)name[i] >= 32 && !strchr("\\/:*?\"<>|", name[i]);
+ }
+
+ lua_pushboolean(L, isAcceptable);
+ return 1;
+}
+
+// Sound:GetGroupVolume(group) and Sound:SetGroupVolume(group, volume):
+// the volume of the voices, the music or the effects, from 0 to 1, which are
+// ScummVM's volumes of speech, music and sound effects
+static Audio::Mixer::SoundType checkSoundGroup(lua_State *L, int index) {
+ const char *group = luaL_checkstring(L, index);
+ if (scumm_stricmp(group, "voice") == 0) {
+ return Audio::Mixer::kSpeechSoundType;
+ } else if (scumm_stricmp(group, "music") == 0) {
+ return Audio::Mixer::kMusicSoundType;
+ } else if (scumm_stricmp(group, "effects") == 0) {
+ return Audio::Mixer::kSFXSoundType;
+ }
+
+ luaL_argerror(L, index, "the group must be \"voice\", \"music\" or \"effects\"");
+ return Audio::Mixer::kPlainSoundType;
+}
+
+static int soundGetGroupVolume(lua_State *L) {
+ const int volume = g_system->getMixer()->getVolumeForSoundType(checkSoundGroup(L, 2));
+ lua_pushnumber(L, (double)volume / Audio::Mixer::kMaxMixerVolume);
+ return 1;
+}
+
+static int soundSetGroupVolume(lua_State *L) {
+ const Audio::Mixer::SoundType type = checkSoundGroup(L, 2);
+ const int volume = (int)(CLIP<double>(luaL_checknumber(L, 3), 0.0, 1.0) * Audio::Mixer::kMaxMixerVolume + 0.5);
+ g_system->getMixer()->setVolumeForSoundType(type, volume);
+
+ static const char *const kVolumeKeys[] = { "speech_volume", "music_volume", "sfx_volume" };
+ const uint key = type == Audio::Mixer::kSpeechSoundType ? 0 : (type == Audio::Mixer::kMusicSoundType ? 1 : 2);
+ ConfMan.setInt(kVolumeKeys[key], volume);
+ return 0;
+}
+
+// Scene:IsStreamRunning(stream)
+static int sceneIsStreamRunning(lua_State *L) {
+ const char *streamName = luaL_checkstring(L, 2);
+ const State::SceneStreamManager &streams = NancySceneState.getStreams();
+ const bool isRunning = streams.isRunning(streamName) ||
+ scumm_stricmp(streamName, State::SceneStreamManager::getMainStreamName()) == 0;
+
+ lua_pushboolean(L, isRunning);
+ return 1;
+}
+
+// Log:Warn(text) and Log:Warn(location, text)
+static int logWarn(lua_State *L) {
+ if (lua_gettop(L) >= 3) {
+ debugC(1, kDebugScene, "Script warning: %s: %s", luaL_checkstring(L, 2), luaL_checkstring(L, 3));
+ } else {
+ debugC(1, kDebugScene, "Script warning: %s", luaL_checkstring(L, 2));
+ }
+
+ return 0;
+}
+
+void registerNancy26GameAPI(lua_State *L) {
+ replaceFunction(L, "ND.Flags", "__index", flagsIndex);
+ replaceFunction(L, "ND.VarTable", "__index", varTableIndex);
+ replaceFunction(L, "ND.Cursor", "__index", cursorIndex);
+ replaceFunction(L, "ND.KeyHelper", "__index", keyIndex);
+ replaceFunction(L, "ND.Game", "__index", gameIndex);
+ replaceFunction(L, "ND.Viewport", "__index", viewportIndex);
+
+ static const luaL_Reg kGameSetters[] = {
+ { "__newindex", gameNewIndex },
+ { nullptr, nullptr }
+ };
+
+ static const luaL_Reg kSaveFunctions[] = {
+ { "IsNameAcceptable", saveIsNameAcceptable },
+ { nullptr, nullptr }
+ };
+
+ static const luaL_Reg kSoundFunctions[] = {
+ { "GetGroupVolume", soundGetGroupVolume },
+ { "SetGroupVolume", soundSetGroupVolume },
+ { nullptr, nullptr }
+ };
+
+ static const luaL_Reg kSceneFunctions[] = {
+ { "IsStreamRunning", sceneIsStreamRunning },
+ { nullptr, nullptr }
+ };
+
+ static const luaL_Reg kLogFunctions[] = {
+ { "Warn", logWarn },
+ { nullptr, nullptr }
+ };
+
+ addFunctions(L, "ND.Game", kGameSetters);
+ addFunctions(L, "ND.Save", kSaveFunctions);
+ addFunctions(L, "ND.Sound", kSoundFunctions);
+ addFunctions(L, "ND.Scene", kSceneFunctions);
+ addFunctions(L, "ND.Log", kLogFunctions);
+}
+
+} // End of namespace Script
+} // End of namespace Nancy
diff --git a/engines/nancy/script/v5/gamefunctions.h b/engines/nancy/script/v5/gamefunctions.h
new file mode 100644
index 00000000000..60e0041fd85
--- /dev/null
+++ b/engines/nancy/script/v5/gamefunctions.h
@@ -0,0 +1,40 @@
+/* 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 NANCY_SCRIPT_V5_GAMEFUNCTIONS_H
+#define NANCY_SCRIPT_V5_GAMEFUNCTIONS_H
+
+struct lua_State;
+
+namespace Nancy {
+namespace Script {
+
+// What Nancy26 adds to the objects of the earlier games: the saved games and
+// settings in Game, Flags:All(), Key:IsDown(), the volume of the groups
+// of sounds and more. Fields that mean
+// something else from Nancy26 on are read here before the earlier games' code
+// gets them. Called once the objects of the earlier games are there.
+void registerNancy26GameAPI(lua_State *L);
+
+} // End of namespace Script
+} // End of namespace Nancy
+
+#endif // NANCY_SCRIPT_V5_GAMEFUNCTIONS_H
diff --git a/engines/nancy/ui/ndui/manager.h b/engines/nancy/ui/ndui/manager.h
index 2950a14fca8..8813745f1fd 100644
--- a/engines/nancy/ui/ndui/manager.h
+++ b/engines/nancy/ui/ndui/manager.h
@@ -96,6 +96,16 @@ public:
void requestSave(const Common::String &name);
void requestLoad(const Common::String &name);
+ // Nancy26's scripts start new games and quit by themselves
+ void requestNewGame() { _request.type = kRequestNewGame; }
+ void requestQuit() { _request.type = kRequestQuit; }
+
+ // Whether there is a saved game of that name
+ bool hasSave(const Common::String &name) const { return findSaveSlot(name) != -1; }
+
+ // The names of the saved games
+ void getSaveNames(Common::Array<Common::String> &names) const;
+
// Goes on with the quit or load that was put off to ask whether to save first
void runPendingAction();
diff --git a/engines/nancy/ui/ndui/saveload.cpp b/engines/nancy/ui/ndui/saveload.cpp
index dfce3541fb3..a8fba638497 100644
--- a/engines/nancy/ui/ndui/saveload.cpp
+++ b/engines/nancy/ui/ndui/saveload.cpp
@@ -167,6 +167,15 @@ int Manager::findSaveSlot(const Common::String &name) const {
return -1;
}
+void Manager::getSaveNames(Common::Array<Common::String> &names) const {
+ SaveStateList saves = g_nancy->getMetaEngine()->listSaves(ConfMan.getActiveDomainName().c_str());
+ for (const SaveStateDescriptor &save : saves) {
+ if (save.getSaveSlot() != g_nancy->getMetaEngine()->getMaximumSaveSlot() && save.getSaveSlot() != g_nancy->getAutosaveSlot()) {
+ names.push_back(save.getDescription());
+ }
+ }
+}
+
// The dialogs show a scaled down picture of the game
void Manager::setSaveScreenshot(const Graphics::ManagedSurface &image, const Common::Rect &src) {
Graphics::ManagedSurface *texture = _textures.getValOrDefault(kScreenshotTexture, nullptr);
Commit: fc5298bcc2a0f60aa08f4488295e9b4f3108fbda
https://github.com/scummvm/scummvm/commit/fc5298bcc2a0f60aa08f4488295e9b4f3108fbda
Author: Filippos Karapetis (bluegr at gmail.com)
Date: 2026-11-06T04:11:01+02:00
Commit Message:
NANCY: NANCY26: Add the inventory functions of Nancy26
Nancy26's scripts add and remove items by name, put one in the player's
hand, and show the inventory themselves. The scene counts the changes
of the inventory, which the scripts check to know when to show it anew.
Changed paths:
engines/nancy/script/v5/gamefunctions.cpp
engines/nancy/script/v5/gamefunctions.h
engines/nancy/state/scene.cpp
engines/nancy/state/scene.h
diff --git a/engines/nancy/script/v5/gamefunctions.cpp b/engines/nancy/script/v5/gamefunctions.cpp
index 3c7c4c75adf..a8f34f151b7 100644
--- a/engines/nancy/script/v5/gamefunctions.cpp
+++ b/engines/nancy/script/v5/gamefunctions.cpp
@@ -397,6 +397,156 @@ static int viewportIndex(lua_State *L) {
return callReplaced(L);
}
+// Inventory
+
+// The inventory goes by the names of the items, and the item in the player's
+// hand stays in it
+
+static const INVD::Item *findItem(const Common::String &name) {
+ const INVD *inventory = GetEngineData(INVD);
+ if (inventory) {
+ for (const INVD::Item &item : inventory->items) {
+ if (item.name.equalsIgnoreCase(name)) {
+ return &item;
+ }
+ }
+ }
+
+ return nullptr;
+}
+
+static const INVD::Item &checkItem(lua_State *L, int index) {
+ const char *name = luaL_checkstring(L, index);
+ const INVD::Item *item = findItem(name);
+ if (!item) {
+ luaL_error(L, "There is no inventory item %s", name);
+ }
+
+ return *item;
+}
+
+static int inventoryAdd(lua_State *L) {
+ const INVD::Item &item = checkItem(L, 2);
+ if (!NancySceneState.hasItem(item.id)) {
+ NancySceneState.addItemToInventory(item.id);
+ }
+
+ return 0;
+}
+
+static int inventoryRemove(lua_State *L) {
+ const INVD::Item &item = checkItem(L, 2);
+ if (NancySceneState.getHeldItem() == item.id) {
+ NancySceneState.setHeldItem(-1);
+ }
+
+ if (NancySceneState.hasItem(item.id)) {
+ NancySceneState.removeItemFromInventory(item.id, false);
+ }
+
+ return 0;
+}
+
+static int inventoryContains(lua_State *L) {
+ lua_pushboolean(L, NancySceneState.hasItem(checkItem(L, 2).id) == g_nancy->_true);
+ return 1;
+}
+
+static int inventoryExists(lua_State *L) {
+ lua_pushboolean(L, findItem(luaL_checkstring(L, 2)) != nullptr);
+ return 1;
+}
+
+static int inventoryIsViewable(lua_State *L) {
+ const INVD::Item *item = findItem(luaL_checkstring(L, 2));
+ lua_pushboolean(L, item && !item->sceneName.empty());
+ return 1;
+}
+
+static int inventoryScene(lua_State *L) {
+ const INVD::Item *item = findItem(luaL_checkstring(L, 2));
+ lua_pushstring(L, item ? item->sceneName.toString().c_str() : "");
+ return 1;
+}
+
+// Every item there is
+static int inventoryAll(lua_State *L) {
+ const INVD *inventory = GetEngineData(INVD);
+ lua_newtable(L);
+ for (uint i = 0; inventory && i < inventory->items.size(); ++i) {
+ lua_pushstring(L, inventory->items[i].name.c_str());
+ lua_rawseti(L, -2, i + 1);
+ }
+
+ return 1;
+}
+
+static const luaL_Reg kInventoryFunctions[] = {
+ { "Add", inventoryAdd },
+ { "Remove", inventoryRemove },
+ { "Contains", inventoryContains },
+ { "Exists", inventoryExists },
+ { "IsViewable", inventoryIsViewable },
+ { "Scene", inventoryScene },
+ { "All", inventoryAll },
+ { nullptr, nullptr }
+};
+
+static bool pushInventoryField(lua_State *L, const Common::String &key) {
+ for (const luaL_Reg *function = kInventoryFunctions; function->name; ++function) {
+ if (key == function->name) {
+ lua_pushcfunction(L, function->func);
+ return true;
+ }
+ }
+
+ const INVD *inventory = GetEngineData(INVD);
+ if (key == "current") {
+ // The items in the order they came into the inventory
+ const Common::Array<int16> &order = NancySceneState.getInventoryOrder();
+ lua_createtable(L, order.size(), 0);
+ for (uint i = 0; inventory && i < order.size(); ++i) {
+ lua_pushstring(L, inventory->items[order[i]].name.c_str());
+ lua_rawseti(L, -2, i + 1);
+ }
+ } else if (key == "inHand") {
+ const int16 heldItem = NancySceneState.getHeldItem();
+ lua_pushstring(L, inventory && heldItem >= 0 && (uint)heldItem < inventory->items.size() ? inventory->items[heldItem].name.c_str() : "");
+ } else if (key == "currentChangeCount") {
+ lua_pushinteger(L, NancySceneState.getInventoryChangeCount());
+ } else if (key == "inHandChangeCount") {
+ lua_pushinteger(L, NancySceneState.getHeldItemChangeCount());
+ } else {
+ return false;
+ }
+
+ return true;
+}
+
+// Inventory.inHand = name, or "" to put it away
+static int inventoryNewIndex(lua_State *L) {
+ const Common::String key = luaL_checkstring(L, 2);
+ if (key != "inHand") {
+ return luaL_error(L, "Inventory does not have a settable field %s", key.c_str());
+ }
+
+ const Common::String name = luaL_checkstring(L, 3);
+ const int16 heldItem = name.empty() ? -1 : checkItem(L, 3).id;
+ if (heldItem != NancySceneState.getHeldItem()) {
+ NancySceneState.setHeldItem(heldItem);
+ }
+
+ return 0;
+}
+
+static int inventoryIndex(lua_State *L) {
+ if (pushInventoryField(L, luaL_checkstring(L, 2))) {
+ return 1;
+ }
+
+ return callReplaced(L);
+}
+
// Save, Sound, Scene and Log
// Save:IsNameAcceptable(name): whether a saved game can go by the name
@@ -475,12 +625,18 @@ void registerNancy26GameAPI(lua_State *L) {
replaceFunction(L, "ND.KeyHelper", "__index", keyIndex);
replaceFunction(L, "ND.Game", "__index", gameIndex);
replaceFunction(L, "ND.Viewport", "__index", viewportIndex);
+ replaceFunction(L, "ND.Inventory", "__index", inventoryIndex);
static const luaL_Reg kGameSetters[] = {
{ "__newindex", gameNewIndex },
{ nullptr, nullptr }
};
+ static const luaL_Reg kInventorySetters[] = {
+ { "__newindex", inventoryNewIndex },
+ { nullptr, nullptr }
+ };
+
static const luaL_Reg kSaveFunctions[] = {
{ "IsNameAcceptable", saveIsNameAcceptable },
{ nullptr, nullptr }
@@ -503,6 +659,7 @@ void registerNancy26GameAPI(lua_State *L) {
};
addFunctions(L, "ND.Game", kGameSetters);
+ addFunctions(L, "ND.Inventory", kInventorySetters);
addFunctions(L, "ND.Save", kSaveFunctions);
addFunctions(L, "ND.Sound", kSoundFunctions);
addFunctions(L, "ND.Scene", kSceneFunctions);
diff --git a/engines/nancy/script/v5/gamefunctions.h b/engines/nancy/script/v5/gamefunctions.h
index 60e0041fd85..5206ea8805c 100644
--- a/engines/nancy/script/v5/gamefunctions.h
+++ b/engines/nancy/script/v5/gamefunctions.h
@@ -28,8 +28,8 @@ namespace Nancy {
namespace Script {
// What Nancy26 adds to the objects of the earlier games: the saved games and
-// settings in Game, Flags:All(), Key:IsDown(), the volume of the groups
-// of sounds and more. Fields that mean
+// settings in Game, the inventory by the names of the items, Flags:All(),
+// Key:IsDown(), the volume of the groups of sounds and more. Fields that mean
// something else from Nancy26 on are read here before the earlier games' code
// gets them. Called once the objects of the earlier games are there.
void registerNancy26GameAPI(lua_State *L);
diff --git a/engines/nancy/state/scene.cpp b/engines/nancy/state/scene.cpp
index d119034303b..c35af11c350 100644
--- a/engines/nancy/state/scene.cpp
+++ b/engines/nancy/state/scene.cpp
@@ -529,14 +529,18 @@ void Scene::addItemToInventory(int16 id) {
if (_flags.items[id] == g_nancy->_false) {
_flags.items[id] = g_nancy->_true;
+ ++_inventoryChangeCount;
if (_flags.heldItem == id) {
setHeldItem(-1);
}
- g_nancy->_sound->playSound("BUOK");
+ // Nancy26's scripts play their own sounds and show the items themselves
+ if (g_nancy->getGameType() < kGameTypeNancy26) {
+ g_nancy->_sound->playSound("BUOK");
- if (_ndui) {
- _ndui->showInventoryItem(id, true);
+ if (_ndui) {
+ _ndui->showInventoryItem(id, true);
+ }
}
if (g_nancy->getGameType() <= kGameTypeNancy9) {
@@ -547,7 +551,7 @@ void Scene::addItemToInventory(int16 id) {
// inserted at the front, except that when the UIIV chunk opts in
// (appendItemsWhileOpen) an item added while the popup is open goes
// to the end. That's how the most recently dropped item ends up last.
- bool addToBack = false;
+ bool addToBack = g_nancy->getGameType() >= kGameTypeNancy26;
if (_inventoryPopup.isOpen()) {
const UIIV *uiivData = GetEngineData(UIIV);
addToBack = uiivData && uiivData->appendItemsWhileOpen;
@@ -582,6 +586,7 @@ void Scene::removeItemFromInventory(int16 id, bool pickUp) {
if (_flags.items[id] == g_nancy->_true || getHeldItem() == id) {
_flags.items[id] = g_nancy->_false;
+ ++_inventoryChangeCount;
// Unlike adding an item, this is silent: the inventory UI plays the
// click itself when the player takes an item out
@@ -591,7 +596,7 @@ void Scene::removeItemFromInventory(int16 id, bool pickUp) {
setHeldItem(-1);
}
- if (_ndui) {
+ if (_ndui && g_nancy->getGameType() < kGameTypeNancy26) {
_ndui->showInventoryItem(id, false);
}
@@ -796,6 +801,10 @@ void Scene::setCharacterItemDisabledState(uint characterIndex, int16 id, byte st
}
void Scene::setHeldItem(int16 id) {
+ if (id != _flags.heldItem) {
+ ++_heldItemChangeCount;
+ }
+
_flags.heldItem = id; g_nancy->_cursor->setCursorItemID(id);
}
diff --git a/engines/nancy/state/scene.h b/engines/nancy/state/scene.h
index 7acdfe4acf0..53a04e21d2c 100644
--- a/engines/nancy/state/scene.h
+++ b/engines/nancy/state/scene.h
@@ -196,6 +196,15 @@ public:
void setPlayerDay(int16 day);
void addItemToInventory(int16 id);
+
+ // Nancy10 and up: the items, in the order the inventory shows them
+ const Common::Array<int16> &getInventoryOrder() { return _inventoryBox.getOrder(); }
+
+ // How many times an item came into the inventory or left it, and how many
+ // times the item in the hand changed. Nancy26's scripts check these to know
+ // when to show the inventory anew.
+ uint getInventoryChangeCount() const { return _inventoryChangeCount; }
+ uint getHeldItemChangeCount() const { return _heldItemChangeCount; }
void removeItemFromInventory(int16 id, bool pickUp = true);
// Nancy15+ inventory action records and dependencies pick the character to
@@ -577,6 +586,9 @@ private:
bool _isEscSkipping = false; // the press that skipped stays away from the scripts
#endif
+ uint _inventoryChangeCount = 0;
+ uint _heldItemChangeCount = 0;
+
// Set when esc skipped a cinematic this frame
bool _hasSkippedMovie = false;
Commit: 24f3e8fbac06ae6aff3f4d1281d0d2a9edf0fde5
https://github.com/scummvm/scummvm/commit/24f3e8fbac06ae6aff3f4d1281d0d2a9edf0fde5
Author: Filippos Karapetis (bluegr at gmail.com)
Date: 2026-11-06T04:11:01+02:00
Commit Message:
NANCY: NANCY26: Add the Nancy26 inventory functionality to the console
- get_inventory and set_inventory take item names as well as numbers,
and show the item in the player's hand and, in Nancy26, the scene that
shows each item
- The new hold_item command puts an item in the hand, or takes it away.
A game without player characters has one inventory.
Changed paths:
engines/nancy/console.cpp
engines/nancy/console.h
diff --git a/engines/nancy/console.cpp b/engines/nancy/console.cpp
index bc0342058bf..efeba20d83c 100644
--- a/engines/nancy/console.cpp
+++ b/engines/nancy/console.cpp
@@ -80,6 +80,7 @@ NancyConsole::NancyConsole() : GUI::Debugger() {
registerCmd("set_eventflags", WRAP_METHOD(NancyConsole, Cmd_setEventFlags));
registerCmd("get_inventory", WRAP_METHOD(NancyConsole, Cmd_getInventory));
registerCmd("set_inventory", WRAP_METHOD(NancyConsole, Cmd_setInventory));
+ registerCmd("hold_item", WRAP_METHOD(NancyConsole, Cmd_holdItem));
registerCmd("get_money", WRAP_METHOD(NancyConsole, Cmd_getMoney));
registerCmd("set_money", WRAP_METHOD(NancyConsole, Cmd_setMoney));
registerCmd("get_player_time", WRAP_METHOD(NancyConsole, Cmd_getPlayerTime));
@@ -541,8 +542,9 @@ static uint numPlayerCharacters() {
return 1;
}
+ // Nancy26 has no characters to pick from, and a single inventory
const PCUI *pcui = GetEngineData(PCUI);
- return pcui ? MIN<uint>(pcui->characters.size(), kMaxPlayerCharacters) : 1;
+ return pcui && !pcui->characters.empty() ? MIN<uint>(pcui->characters.size(), kMaxPlayerCharacters) : 1;
}
// The name of an inventory item, from wherever the game keeps it: the inventory
@@ -1377,9 +1379,47 @@ bool NancyConsole::Cmd_setEventFlags(int argc, const char **argv) {
return cmdExit(0, nullptr);
}
+// An item by its number, or by its name; -1 for none
+static int findInventoryItem(const char *arg) {
+ const uint numItems = g_nancy->getStaticData().numItems;
+
+ const Common::String text = arg;
+ bool isNumber = !text.empty();
+ for (uint i = 0; i < text.size(); ++i) {
+ isNumber &= Common::isDigit(text[i]);
+ }
+
+ if (isNumber) {
+ const int itemID = atoi(arg);
+ return itemID < (int)numItems ? itemID : -1;
+ }
+
+ for (uint i = 0; i < numItems; ++i) {
+ if (inventoryItemName(i).equalsIgnoreCase(text)) {
+ return i;
+ }
+ }
+
+ return -1;
+}
+
void NancyConsole::printInventoryItem(uint itemID) {
debugPrintf("\nItem %u, %s", itemID, inventoryItemName(itemID).c_str());
+ // Nancy26 names the scene that shows an item
+ const INVD *itemTable = GetEngineData(INVD);
+ if (itemTable && g_nancy->getGameType() >= kGameTypeNancy26) {
+ for (const INVD::Item &item : itemTable->items) {
+ if (item.id == (int16)itemID && !item.sceneName.empty()) {
+ debugPrintf(", shown by %s", item.sceneName.toString().c_str());
+ }
+ }
+ }
+
+ if (NancySceneState.getHeldItem() == (int16)itemID) {
+ debugPrintf(", in hand");
+ }
+
// Only the games with inventory data say what happens to a used item
auto *inventoryData = GetEngineData(INV);
if (inventoryData) {
@@ -1416,14 +1456,19 @@ bool NancyConsole::Cmd_getInventory(int argc, const char **argv) {
debugPrintf("Playing as %s\n", playerCharacterName(g_nancy->getPlayerCharacter()).c_str());
}
+ const int16 heldItem = NancySceneState.getHeldItem();
+ if (heldItem >= 0) {
+ debugPrintf("In hand: item %d, %s\n", heldItem, inventoryItemName(heldItem).c_str());
+ }
+
if (argc == 1) {
for (uint i = 0; i < numItems; ++i) {
printInventoryItem(i);
}
} else {
for (int i = 1; i < argc; ++i) {
- int itemID = atoi(argv[i]);
- if (itemID < 0 || itemID >= (int)numItems) {
+ int itemID = findInventoryItem(argv[i]);
+ if (itemID < 0) {
debugPrintf("\nInvalid item %s", argv[i]);
continue;
}
@@ -1466,7 +1511,7 @@ bool NancyConsole::Cmd_setInventory(int argc, const char **argv) {
if (argc < firstItemArg + 2 || (argc - firstItemArg) % 2 != 0) {
debugPrintf("Sets one or more inventory items to the provided value.\n");
- debugPrintf("Usage: %s [-c <characterIndex>] <itemID> <true/false>...\n", argv[0]);
+ debugPrintf("Usage: %s [-c <characterIndex>] <itemID or name> <true/false>...\n", argv[0]);
debugPrintf("-c picks the player character to give the items to (Nancy15+); the character being played is the default.\n");
return true;
}
@@ -1476,8 +1521,8 @@ bool NancyConsole::Cmd_setInventory(int argc, const char **argv) {
Common::String("inventory");
for (int i = firstItemArg; i < argc; i += 2) {
- int itemID = atoi(argv[i]);
- if (itemID < 0 || itemID >= (int)g_nancy->getStaticData().numItems) {
+ int itemID = findInventoryItem(argv[i]);
+ if (itemID < 0) {
debugPrintf("Invalid item %s\n", argv[i]);
continue;
}
@@ -1503,6 +1548,58 @@ bool NancyConsole::Cmd_setInventory(int argc, const char **argv) {
return cmdExit(0, nullptr);
}
+bool NancyConsole::Cmd_holdItem(int argc, const char **argv) {
+ if (g_nancy->getState() != NancyState::kScene) {
+ debugPrintf("Not in the kScene state\n");
+ return true;
+ }
+
+ if (argc != 2) {
+ debugPrintf("Puts an inventory item in the player's hand, or puts the one there away.\n");
+ debugPrintf("Usage: %s <itemID or name>|none\n", argv[0]);
+ return true;
+ }
+
+ // Nancy26 keeps the item in the hand in the inventory as well, and puts
+ // it away by letting go of it. The earlier games take it out.
+ const bool keepsHeldItem = g_nancy->getGameType() >= kGameTypeNancy26;
+
+ if (Common::String(argv[1]).equalsIgnoreCase("none")) {
+ if (keepsHeldItem) {
+ NancySceneState.setHeldItem(-1);
+ } else {
+ NancySceneState.setNoHeldItem();
+ }
+
+ debugPrintf("The hand is empty\n");
+ return cmdExit(0, nullptr);
+ }
+
+ const int itemID = findInventoryItem(argv[1]);
+ if (itemID < 0) {
+ debugPrintf("Invalid item %s\n", argv[1]);
+ return true;
+ }
+
+ if (keepsHeldItem) {
+ if (NancySceneState.hasItem(itemID) == g_nancy->_false) {
+ NancySceneState.addItemToInventory(itemID);
+ }
+
+ NancySceneState.setHeldItem(itemID);
+ } else if (NancySceneState.getHeldItem() != itemID) {
+ NancySceneState.setNoHeldItem();
+ if (NancySceneState.hasItem(itemID) == g_nancy->_true) {
+ NancySceneState.removeItemFromInventory(itemID, true);
+ } else {
+ NancySceneState.setHeldItem(itemID);
+ }
+ }
+
+ debugPrintf("Holding item %d, %s\n", itemID, inventoryItemName(itemID).c_str());
+ return cmdExit(0, nullptr);
+}
+
bool NancyConsole::Cmd_getMoney(int argc, const char **argv) {
if (g_nancy->getState() != NancyState::kScene) {
debugPrintf("Not in the kScene state\n");
diff --git a/engines/nancy/console.h b/engines/nancy/console.h
index 066926c575e..5e2a92705cc 100644
--- a/engines/nancy/console.h
+++ b/engines/nancy/console.h
@@ -70,6 +70,7 @@ private:
bool Cmd_setEventFlags(int argc, const char **argv);
bool Cmd_getInventory(int argc, const char **argv);
bool Cmd_setInventory(int argc, const char **argv);
+ bool Cmd_holdItem(int argc, const char **argv);
bool Cmd_getMoney(int argc, const char **argv);
bool Cmd_setMoney(int argc, const char **argv);
bool Cmd_getPlayerTime(int argc, const char **argv);
Commit: a678c7cc5aea5e52f3d116e8ab947b552cd0d60d
https://github.com/scummvm/scummvm/commit/a678c7cc5aea5e52f3d116e8ab947b552cd0d60d
Author: Filippos Karapetis (bluegr at gmail.com)
Date: 2026-11-06T04:11:03+02:00
Commit Message:
NANCY: NANCY26: Show the subtitles of sounds
In Nancy26, the subtitles are shown by the scripted UI rather than the
engine. When a sound that has a subtitle starts playing, the engine now
tells the UI to show it, and tells it to remove it when the sound ends.
Changed paths:
engines/nancy/script/records.cpp
engines/nancy/script/records.h
engines/nancy/ui/ndui/enginehandlers.cpp
diff --git a/engines/nancy/script/records.cpp b/engines/nancy/script/records.cpp
index 5dfac0b892d..458b00fd4c7 100644
--- a/engines/nancy/script/records.cpp
+++ b/engines/nancy/script/records.cpp
@@ -49,6 +49,7 @@
#ifdef ENABLE_NANCY_V5
#include "engines/nancy/script/v5/cliptransformer.h"
+#include "engines/nancy/script/v5/messaging.h"
#include "engines/nancy/script/v5/streamtree.h"
#include "engines/nancy/script/v5/textrecord.h"
#include "engines/nancy/script/v5/widgets.h"
@@ -1936,6 +1937,16 @@ void SoundRecord::runOnce() {
_duration = _isPlaying ? g_nancy->_sound->getLength(_sound).msecs() / 1000.0 : 0.0;
_endTime = getContext().getTime() + _duration;
+#ifdef ENABLE_NANCY_V5
+ if (g_nancy->getGameType() >= kGameTypeNancy26) {
+ if (_isPlaying && _usesCaption) {
+ sendCaption(true);
+ }
+
+ return;
+ }
+#endif
+
// What the sound says is kept under its name
UI::NDUI::Manager *ui = NancySceneState.getNDUI();
_caption.clear();
@@ -1944,6 +1955,23 @@ void SoundRecord::runOnce() {
}
}
+#ifdef ENABLE_NANCY_V5
+void SoundRecord::sendCaption(bool isShown) {
+ lua_State *L = getLua();
+ const int top = lua_gettop(L);
+
+ if (isShown) {
+ lua_pushstring(L, _sound.name.c_str());
+ sendMessage(L, getName(), "CC", "SetIfExists", top + 1, 1);
+ } else {
+ sendMessage(L, getName(), "CC", "Clear", top + 1, 0);
+ }
+
+ lua_settop(L, top);
+ _hasSentCaption = isShown;
+}
+#endif
+
void SoundRecord::run(double sceneTime, double elapsedTime) {
// The sound is cut off when another sound starts on its channel, or the
// channel is stopped. Ending a little before its length doesn't count.
@@ -1962,6 +1990,12 @@ void SoundRecord::run(double sceneTime, double elapsedTime) {
}
_caption.clear();
+#ifdef ENABLE_NANCY_V5
+ if (_hasSentCaption) {
+ sendCaption(false);
+ }
+#endif
+
finish();
}
}
diff --git a/engines/nancy/script/records.h b/engines/nancy/script/records.h
index 899e64d20ec..d89cf171a9b 100644
--- a/engines/nancy/script/records.h
+++ b/engines/nancy/script/records.h
@@ -380,6 +380,12 @@ protected:
private:
// Nancy24: "VOICE", "MUSIC" or "EFFECTS", the volume the sound goes by
void readChannelType(int index);
+
+#ifdef ENABLE_NANCY_V5
+ // Nancy26 has the UI show what a sound says through messages to "CC": its
+ // text, if the sound has one, and taking it down again once the sound is over
+ void sendCaption(bool isShown);
+#endif
const char *getChannelType() const;
Common::Array<Common::String> _names;
@@ -391,6 +397,7 @@ private:
SoundDescription _sound;
Common::String _caption; // what the sound says, while it is the one on screen
+ bool _hasSentCaption = false; // Nancy26: told the UI to show it
bool _isPlaying = false;
bool _wasPreempted = false;
uint32 _channelSerial = 0; // of the channel, once the sound started
diff --git a/engines/nancy/ui/ndui/enginehandlers.cpp b/engines/nancy/ui/ndui/enginehandlers.cpp
index 5be299f5590..6e5b605b6b3 100644
--- a/engines/nancy/ui/ndui/enginehandlers.cpp
+++ b/engines/nancy/ui/ndui/enginehandlers.cpp
@@ -627,6 +627,12 @@ void Manager::endConversation() {
void Manager::setCaption(const Common::String &text) {
_caption = text;
+
+ // Nancy26's UI is made of records, which get the captions through messages
+ if (g_nancy->getGameType() >= kGameTypeNancy26) {
+ return;
+ }
+
takeAction(kActionSetText, "CCText", text);
}
Commit: 413be9daa359a1642709b44ff4e8735de0bc88b6
https://github.com/scummvm/scummvm/commit/413be9daa359a1642709b44ff4e8735de0bc88b6
Author: Filippos Karapetis (bluegr at gmail.com)
Date: 2026-11-06T04:11:03+02:00
Commit Message:
NANCY: NANCY26: Add detection entry
Set to unstable, as the game starts
Changed paths:
engines/nancy/detection_tables.h
diff --git a/engines/nancy/detection_tables.h b/engines/nancy/detection_tables.h
index c49c62422af..b38ab5b7382 100644
--- a/engines/nancy/detection_tables.h
+++ b/engines/nancy/detection_tables.h
@@ -900,6 +900,14 @@ static const ADGameDescription gameDescriptions[] = {
ADGF_UNSTABLE | ADGF_DROPPLATFORM,
NANCY_GUIOPTIONS
},
+ { // MD5 by bluegr
+ "nancy26", nullptr,
+ AD_ENTRY1s("ciftree.dat", "a3ee96dab1e23c0ed0279cbf17826aca", 187384114),
+ Common::EN_ANY,
+ Common::kPlatformWindows,
+ ADGF_UNSTABLE | ADGF_DROPPLATFORM,
+ NANCY_GUIOPTIONS
+ },
// Do not delete
AD_TABLE_END_MARKER
Commit: da3feb0e2f6230a7817118ce1565223f05ea0447
https://github.com/scummvm/scummvm/commit/da3feb0e2f6230a7817118ce1565223f05ea0447
Author: Filippos Karapetis (bluegr at gmail.com)
Date: 2026-11-06T04:11:05+02:00
Commit Message:
NANCY: Rename _type field in SpecialEffect class. PVS-Studio V703
Changed paths:
engines/nancy/action/miscrecords.cpp
engines/nancy/action/miscrecords.h
diff --git a/engines/nancy/action/miscrecords.cpp b/engines/nancy/action/miscrecords.cpp
index 1a92523978f..3bd758b9411 100644
--- a/engines/nancy/action/miscrecords.cpp
+++ b/engines/nancy/action/miscrecords.cpp
@@ -87,11 +87,11 @@ void LightningOn::readData(Common::SeekableReadStream &stream) {
void SpecialEffect::readData(Common::SeekableReadStream &stream) {
if (g_nancy->getGameType() <= kGameTypeNancy6) {
- _type = stream.readByte();
+ _effectType = stream.readByte();
_fadeToBlackTime = stream.readUint16LE();
_frameTime = stream.readUint16LE();
} else {
- _type = stream.readByte();
+ _effectType = stream.readByte();
_totalTime = stream.readUint16LE();
_fadeToBlackTime = stream.readUint16LE();
readRect(stream, _rect);
@@ -100,9 +100,9 @@ void SpecialEffect::readData(Common::SeekableReadStream &stream) {
void SpecialEffect::execute() {
if (g_nancy->getGameType() <= kGameTypeNancy6) {
- NancySceneState.specialEffect(_type, _fadeToBlackTime, _frameTime);
+ NancySceneState.specialEffect(_effectType, _fadeToBlackTime, _frameTime);
} else {
- NancySceneState.specialEffect(_type, _totalTime, _fadeToBlackTime, _rect);
+ NancySceneState.specialEffect(_effectType, _totalTime, _fadeToBlackTime, _rect);
}
_isDone = true;
diff --git a/engines/nancy/action/miscrecords.h b/engines/nancy/action/miscrecords.h
index 76c54569245..92d8feac1a4 100644
--- a/engines/nancy/action/miscrecords.h
+++ b/engines/nancy/action/miscrecords.h
@@ -79,7 +79,7 @@ public:
void readData(Common::SeekableReadStream &stream) override;
void execute() override;
- byte _type = 1;
+ byte _effectType = 1;
uint16 _fadeToBlackTime = 0;
uint16 _frameTime = 0;
uint16 _totalTime = 0;
Commit: 7b3c5f5c83934b4c86d2a0cc9a41960bc0695f00
https://github.com/scummvm/scummvm/commit/7b3c5f5c83934b4c86d2a0cc9a41960bc0695f00
Author: Filippos Karapetis (bluegr at gmail.com)
Date: 2026-11-06T04:11:05+02:00
Commit Message:
NANCY: Remove unused field in MouseFollowObject class. PVS-Studio V703
Changed paths:
engines/nancy/action/mousefollow.h
diff --git a/engines/nancy/action/mousefollow.h b/engines/nancy/action/mousefollow.h
index ba99700bed8..8e7344ff352 100644
--- a/engines/nancy/action/mousefollow.h
+++ b/engines/nancy/action/mousefollow.h
@@ -63,7 +63,6 @@ public:
protected:
bool _isPickedUp = false;
- byte _rotation = 0;
const VIEW *_viewportData = nullptr;
};
Commit: 1fe7ca64186e72cd1c2b09c09a2a1f0c419ff916
https://github.com/scummvm/scummvm/commit/1fe7ca64186e72cd1c2b09c09a2a1f0c419ff916
Author: Filippos Karapetis (bluegr at gmail.com)
Date: 2026-11-06T04:11:06+02:00
Commit Message:
NANCY: Rename _isActive field in WhackItPuzzle class. PVS-Studio V703
Changed paths:
engines/nancy/action/puzzle/whackitpuzzle.cpp
engines/nancy/action/puzzle/whackitpuzzle.h
diff --git a/engines/nancy/action/puzzle/whackitpuzzle.cpp b/engines/nancy/action/puzzle/whackitpuzzle.cpp
index 039d94fc1ca..e5ddd6d6703 100644
--- a/engines/nancy/action/puzzle/whackitpuzzle.cpp
+++ b/engines/nancy/action/puzzle/whackitpuzzle.cpp
@@ -220,14 +220,14 @@ void WhackItPuzzle::updateBee(Bee &bee, uint32 numTicks) {
switch (bee.state) {
case kDown:
// A bee that is down doesn't move its wings
- if (_isActive && now > bee.stateEndTime) {
+ if (_isPlaying && now > bee.stateEndTime) {
bee.state = kReviving;
bee.stateEndTime = getRandomTime(_revivingTime[0], _revivingTime[1]);
}
return;
case kReviving:
- if (!_isActive) {
+ if (!_isPlaying) {
return;
}
@@ -316,7 +316,7 @@ void WhackItPuzzle::redraw() {
_drawSurface.blitFrom(_image, puff.animation.getSrc(), puff.animation.getDest(puff.pos).origin());
}
- if (_isActive && _isMouseInside) {
+ if (_isPlaying && _isMouseInside) {
_drawSurface.blitFrom(_image, _canSrc, _mousePos + _canOffset);
}
@@ -378,7 +378,7 @@ void WhackItPuzzle::execute() {
bool isAllDown = numFlying + numAngry == 0;
NancySceneState.setEventFlag(_allDownFlag.label, isAllDown ? g_nancy->_true : g_nancy->_false);
if (isAllDown && _stopsWhenAllDown) {
- _isActive = false;
+ _isPlaying = false;
}
// A puff knocks down every flying bee it touches while it lasts
@@ -461,7 +461,7 @@ void WhackItPuzzle::handleInput(NancyInput &input) {
_mousePos = mouseRect.origin();
_isMouseInside = true;
- if (!_isActive) {
+ if (!_isPlaying) {
return;
}
diff --git a/engines/nancy/action/puzzle/whackitpuzzle.h b/engines/nancy/action/puzzle/whackitpuzzle.h
index ea84b9188a4..311ec9fcbe4 100644
--- a/engines/nancy/action/puzzle/whackitpuzzle.h
+++ b/engines/nancy/action/puzzle/whackitpuzzle.h
@@ -145,7 +145,7 @@ protected:
// -- Runtime --
Common::Array<Bee> _bees;
Common::Array<Puff> _puffs;
- bool _isActive = true;
+ bool _isPlaying = true;
int32 _numStings = 0;
uint32 _lastStingTime = 0;
bool _hasStung = false;
Commit: e2e59ec3f0f640a02f65132742cee04513ab4075
https://github.com/scummvm/scummvm/commit/e2e59ec3f0f640a02f65132742cee04513ab4075
Author: Filippos Karapetis (bluegr at gmail.com)
Date: 2026-11-06T04:11:06+02:00
Commit Message:
NANCY: Rename unused field in NancyEngine class. PVS-Studio V703
Changed paths:
engines/nancy/nancy.h
diff --git a/engines/nancy/nancy.h b/engines/nancy/nancy.h
index 042006c5292..6f72d545792 100644
--- a/engines/nancy/nancy.h
+++ b/engines/nancy/nancy.h
@@ -242,7 +242,6 @@ private:
const byte _datFileMinorVersion;
GameFlow _gameFlow;
- OSystem *_system;
const ADGameDescription *_gameDescription;
const GameType _gameType;
Commit: dff20c75a7782f2139801f0575f5bfbadea21564
https://github.com/scummvm/scummvm/commit/dff20c75a7782f2139801f0575f5bfbadea21564
Author: Filippos Karapetis (bluegr at gmail.com)
Date: 2026-11-06T04:11:07+02:00
Commit Message:
NANCY: Initialize all members of INV class. PVS-Studio V1077
Changed paths:
engines/nancy/enginedata.h
diff --git a/engines/nancy/enginedata.h b/engines/nancy/enginedata.h
index 8e8525bdf77..23edc766dba 100644
--- a/engines/nancy/enginedata.h
+++ b/engines/nancy/enginedata.h
@@ -159,14 +159,14 @@ struct INV : public EngineData {
Common::Rect scrollbarSrcBounds;
Common::Point scrollbarDefaultPos;
- uint16 scrollbarMaxScroll;
+ uint16 scrollbarMaxScroll = 0;
Common::Array<Common::Rect> ornamentSrcs;
Common::Array<Common::Rect> ornamentDests;
Common::Array<Common::Rect> curtainAnimationSrcs;
Common::Rect curtainsScreenPosition;
- uint16 curtainsFrameTime;
+ uint16 curtainsFrameTime = 0;
uint16 captionAutoClearTime = 3000;
Commit: 61948aac7fa3c69c59619ee23e990c8b08325283
https://github.com/scummvm/scummvm/commit/61948aac7fa3c69c59619ee23e990c8b08325283
Author: Filippos Karapetis (bluegr at gmail.com)
Date: 2026-11-06T04:11:13+02:00
Commit Message:
NANCY: Remove checks for always true expression. PVS-Studio V547
Changed paths:
engines/nancy/metaengine.cpp
diff --git a/engines/nancy/metaengine.cpp b/engines/nancy/metaengine.cpp
index fbf33cf5350..edc4bd4e782 100644
--- a/engines/nancy/metaengine.cpp
+++ b/engines/nancy/metaengine.cpp
@@ -186,15 +186,8 @@ Common::Error NancyMetaEngine::createInstance(OSystem *syst, Engine **engine, co
}
#endif
- if (gd) {
- *engine = Nancy::NancyEngine::create(gameType, syst, gd);
- }
-
- if (gd) {
- return Common::kNoError;
- } else {
- return Common::Error();
- }
+ *engine = Nancy::NancyEngine::create(gameType, syst, gd);
+ return Common::kNoError;
}
int NancyMetaEngine::getMaximumSaveSlot() const { int r = ConfMan.getInt("nancy_max_saves"); return r ? r : AdvancedMetaEngine::getMaximumSaveSlot(); }
Commit: b5feed9545ce945752a652a9c09e8a92bfdd2b15
https://github.com/scummvm/scummvm/commit/b5feed9545ce945752a652a9c09e8a92bfdd2b15
Author: Filippos Karapetis (bluegr at gmail.com)
Date: 2026-11-06T04:11:14+02:00
Commit Message:
NANCY: Remove expression that is always true. PVS-Studio V560
Changed paths:
engines/nancy/state/scene.cpp
diff --git a/engines/nancy/state/scene.cpp b/engines/nancy/state/scene.cpp
index c35af11c350..ea961a9a796 100644
--- a/engines/nancy/state/scene.cpp
+++ b/engines/nancy/state/scene.cpp
@@ -1336,7 +1336,7 @@ void Scene::setLogicCondition(int16 label, byte flag) {
label -= 2000;
}
- if (label > kEvNoEvent && (uint)label < 30) {
+ if ((uint)label < 30) {
_flags.logicConditions[label].flag = flag;
_flags.logicConditions[label].timestamp = g_nancy->getTotalPlayTime();
}
Commit: 297f3bdbe7dfee5864feea9ebf3b9e0df06d1919
https://github.com/scummvm/scummvm/commit/297f3bdbe7dfee5864feea9ebf3b9e0df06d1919
Author: Filippos Karapetis (bluegr at gmail.com)
Date: 2026-11-06T04:11:15+02:00
Commit Message:
NANCY: Remove redundant assignment. PVS-Studio V1048
Changed paths:
engines/nancy/state/setupmenu.cpp
diff --git a/engines/nancy/state/setupmenu.cpp b/engines/nancy/state/setupmenu.cpp
index 17ae46316bf..19c9d79e50a 100644
--- a/engines/nancy/state/setupmenu.cpp
+++ b/engines/nancy/state/setupmenu.cpp
@@ -220,7 +220,6 @@ void SetupMenu::run() {
Audio::Mixer::SoundType type = Audio::Mixer::SoundType::kSpeechSoundType;
switch (i) {
case 0 :
- type = Audio::Mixer::SoundType::kSpeechSoundType;
ConfMan.setInt("speech_volume", endPos * 255, ConfMan.getActiveDomainName());
break;
case 1 :
Commit: ad8f5e53d4be8b304bc84fc7161bde48e602a440
https://github.com/scummvm/scummvm/commit/ad8f5e53d4be8b304bc84fc7161bde48e602a440
Author: Filippos Karapetis (bluegr at gmail.com)
Date: 2026-11-06T04:11:15+02:00
Commit Message:
NANCY: Initialize members of struct SoundChannelInfo. PVS-Studio V730
Changed paths:
engines/nancy/commontypes.h
diff --git a/engines/nancy/commontypes.h b/engines/nancy/commontypes.h
index 9239a7a1e04..a93a94477ac 100644
--- a/engines/nancy/commontypes.h
+++ b/engines/nancy/commontypes.h
@@ -378,8 +378,8 @@ struct Hint {
};
struct SoundChannelInfo {
- byte numChannels;
- byte numSceneSpecificChannels;
+ byte numChannels = 0;
+ byte numSceneSpecificChannels = 0;
Common::Array<byte> speechChannels;
Common::Array<byte> musicChannels;
Common::Array<byte> sfxChannels;
Commit: fd3ebc9f3263dbdcb0bda894d6979c052f1a55da
https://github.com/scummvm/scummvm/commit/fd3ebc9f3263dbdcb0bda894d6979c052f1a55da
Author: Filippos Karapetis (bluegr at gmail.com)
Date: 2026-11-06T04:11:16+02:00
Commit Message:
NANCY: Merge duplicate case branches. PVS-Studio V1037
Changed paths:
engines/nancy/action/puzzle/collisionpuzzle.cpp
diff --git a/engines/nancy/action/puzzle/collisionpuzzle.cpp b/engines/nancy/action/puzzle/collisionpuzzle.cpp
index b7bbe6005e8..1b0c5012668 100644
--- a/engines/nancy/action/puzzle/collisionpuzzle.cpp
+++ b/engines/nancy/action/puzzle/collisionpuzzle.cpp
@@ -63,6 +63,7 @@ void CollisionPuzzle::init() {
switch (id) {
case 1 :
+ case 6 :
newPiece._w = 2;
break;
case 2 :
@@ -78,9 +79,6 @@ void CollisionPuzzle::init() {
newPiece._w = 2;
newPiece._h = 2;
break;
- case 6 :
- newPiece._w = 2;
- break;
default :
continue;
}
Commit: fc97cdd418454505e1bb14751da2337e9020d434
https://github.com/scummvm/scummvm/commit/fc97cdd418454505e1bb14751da2337e9020d434
Author: Filippos Karapetis (bluegr at gmail.com)
Date: 2026-11-06T04:11:17+02:00
Commit Message:
NANCY: Initialize class members. PVS-Studio V730
Changed paths:
engines/nancy/action/puzzle/memorypuzzle.h
diff --git a/engines/nancy/action/puzzle/memorypuzzle.h b/engines/nancy/action/puzzle/memorypuzzle.h
index 0b41b29be7c..806f8329126 100644
--- a/engines/nancy/action/puzzle/memorypuzzle.h
+++ b/engines/nancy/action/puzzle/memorypuzzle.h
@@ -91,7 +91,7 @@ protected:
// _cards[tab * kCardsPerTab + i] = state of card i on tab `tab`
CardState _cards[kNumTabs * kCardsPerTab];
- bool _typeUsed[kMaxTypes]; // faces already handed out while filling _cards
+ bool _typeUsed[kMaxTypes] = {}; // faces already handed out while filling _cards
int _currentTab = 0;
int _firstFlip = -1; // absolute card index of first face-up unmatched card
Commit: 525c4d5390981ca6f9f0778f9485a37705afcaa4
https://github.com/scummvm/scummvm/commit/525c4d5390981ca6f9f0778f9485a37705afcaa4
Author: Filippos Karapetis (bluegr at gmail.com)
Date: 2026-11-06T04:11:18+02:00
Commit Message:
NANCY: Remove redundant assignment. PVS-Studio V1048
Changed paths:
engines/nancy/action/puzzle/orderingpuzzle.cpp
diff --git a/engines/nancy/action/puzzle/orderingpuzzle.cpp b/engines/nancy/action/puzzle/orderingpuzzle.cpp
index 482e96cacfc..c8c7af62cb4 100644
--- a/engines/nancy/action/puzzle/orderingpuzzle.cpp
+++ b/engines/nancy/action/puzzle/orderingpuzzle.cpp
@@ -93,7 +93,7 @@ void OrderingPuzzle::readData(Common::SeekableReadStream &stream) {
uint16 maxNumElements = 15;
if (ser.getVersion() == kGameTypeVampire) {
// Hardcoded in The Vampire Diaries
- numElements = maxNumElements = 5;
+ maxNumElements = 5;
} else {
ser.syncAsUint16LE(numElements);
}
Commit: 531a2b031d445b0944257c32125e9881ec8e0cc6
https://github.com/scummvm/scummvm/commit/531a2b031d445b0944257c32125e9881ec8e0cc6
Author: Filippos Karapetis (bluegr at gmail.com)
Date: 2026-11-06T04:11:18+02:00
Commit Message:
NANCY: Init class members of RaycastLevelBuilder. PVS-Studio V1077
Changed paths:
engines/nancy/action/puzzle/raycastpuzzle.cpp
diff --git a/engines/nancy/action/puzzle/raycastpuzzle.cpp b/engines/nancy/action/puzzle/raycastpuzzle.cpp
index f8fd447ef6f..26ef10d370a 100644
--- a/engines/nancy/action/puzzle/raycastpuzzle.cpp
+++ b/engines/nancy/action/puzzle/raycastpuzzle.cpp
@@ -97,7 +97,7 @@ public:
uint _verticalHeight;
float _objectsBaseDensity;
- uint _startX, _startY;
+ uint _startX = 0, _startY = 0;
Common::Array<uint16> _cells;
Common::Array<byte> _walls;
Commit: 3ce5d6493aa256908a47e25988b23cd4900ace6a
https://github.com/scummvm/scummvm/commit/3ce5d6493aa256908a47e25988b23cd4900ace6a
Author: Filippos Karapetis (bluegr at gmail.com)
Date: 2026-11-06T04:11:19+02:00
Commit Message:
NANCY: Remove always false expressions. PVS-Studio V560
Changed paths:
engines/nancy/action/puzzle/arcadepuzzle.cpp
diff --git a/engines/nancy/action/puzzle/arcadepuzzle.cpp b/engines/nancy/action/puzzle/arcadepuzzle.cpp
index ebd1d5db1aa..4a1c3cc1372 100644
--- a/engines/nancy/action/puzzle/arcadepuzzle.cpp
+++ b/engines/nancy/action/puzzle/arcadepuzzle.cpp
@@ -662,8 +662,8 @@ void ArcadePuzzle::paddleMovement() {
_paddleRight = _paddleLeft + _paddleWidth - 1;
}
- if (_paddleLeft != _paddlePrevLeft || _paddleRight != _paddlePrevRight ||
- _paddleTop != _paddlePrevTop || _paddleBottom!= _paddlePrevBottom) {
+ // The paddle only moves horizontally
+ if (_paddleLeft != _paddlePrevLeft || _paddleRight != _paddlePrevRight) {
_paddleNeedsRedraw = true;
}
}
Commit: c502130d67279c2aa2b956c98680c8da2f5be286
https://github.com/scummvm/scummvm/commit/c502130d67279c2aa2b956c98680c8da2f5be286
Author: Filippos Karapetis (bluegr at gmail.com)
Date: 2026-11-06T04:11:20+02:00
Commit Message:
NANCY: Merge duplicate case branches. PVS-Studio V1037
Changed paths:
engines/nancy/action/puzzle/arcadepuzzle.cpp
diff --git a/engines/nancy/action/puzzle/arcadepuzzle.cpp b/engines/nancy/action/puzzle/arcadepuzzle.cpp
index 4a1c3cc1372..4254485dd64 100644
--- a/engines/nancy/action/puzzle/arcadepuzzle.cpp
+++ b/engines/nancy/action/puzzle/arcadepuzzle.cpp
@@ -1081,7 +1081,8 @@ void ArcadePuzzle::applyCollision() {
}
case 1: case 2:
- // Paddle edge: negate both components
+ case 0x10:
+ // Paddle edge or catch-all out-of-bounds: negate both components
_ballDX = -_ballDX;
_ballDY = -_ballDY;
break;
@@ -1125,12 +1126,6 @@ void ArcadePuzzle::applyCollision() {
playBrickHitSound();
break;
- case 0x10:
- // Catch-all out-of-bounds: negate
- _ballDX = -_ballDX;
- _ballDY = -_ballDY;
- break;
-
case -1:
// Ball died â handled in ballAndCollision
break;
Commit: 3d4df8a8affde071f06f7949e6ffb1c163fc96fc
https://github.com/scummvm/scummvm/commit/3d4df8a8affde071f06f7949e6ffb1c163fc96fc
Author: Filippos Karapetis (bluegr at gmail.com)
Date: 2026-11-06T04:11:21+02:00
Commit Message:
NANCY: Remove redundant assignment. PVS-Studio V1048
Changed paths:
engines/nancy/action/puzzle/whalesurvivorpuzzle.cpp
diff --git a/engines/nancy/action/puzzle/whalesurvivorpuzzle.cpp b/engines/nancy/action/puzzle/whalesurvivorpuzzle.cpp
index d21e1f80cf4..b90ea2e6b8b 100644
--- a/engines/nancy/action/puzzle/whalesurvivorpuzzle.cpp
+++ b/engines/nancy/action/puzzle/whalesurvivorpuzzle.cpp
@@ -757,9 +757,6 @@ void WhaleSurvivorPuzzle::checkCollisions() {
--_fishCount;
int divisor = _scoreDivisor > 0 ? (int)_scoreDivisor : 500;
_score += (int)((float)divisor * _underwaterMultiplier);
- if (_prevScore != _score)
- _needsRedraw = true;
-
_porpoiseAnim = kPorpoiseEat;
if (_eatSound.name != "NO SOUND")
Commit: 6ebdc7698604e20d884c249e3df5193cb4d46ab3
https://github.com/scummvm/scummvm/commit/6ebdc7698604e20d884c249e3df5193cb4d46ab3
Author: Filippos Karapetis (bluegr at gmail.com)
Date: 2026-11-06T04:11:22+02:00
Commit Message:
NANCY: Merge duplicate case branches. PVS-Studio V1037
Changed paths:
engines/nancy/action/puzzle/whalesurvivorpuzzle.cpp
diff --git a/engines/nancy/action/puzzle/whalesurvivorpuzzle.cpp b/engines/nancy/action/puzzle/whalesurvivorpuzzle.cpp
index b90ea2e6b8b..4b7d5829943 100644
--- a/engines/nancy/action/puzzle/whalesurvivorpuzzle.cpp
+++ b/engines/nancy/action/puzzle/whalesurvivorpuzzle.cpp
@@ -401,7 +401,10 @@ void WhaleSurvivorPuzzle::execute() {
switch (_gameState) {
case kStartScreen:
- // Waiting for the player to click â keep start screen visible.
+ case kHitAnimation:
+ // Keep the start screen or the "Oh no! Try again" overlay visible
+ // until the player clicks Start (full restart via kTryAgain) or
+ // Quit (loss scene). Both are handled in handleInput().
redraw();
break;
@@ -419,13 +422,6 @@ void WhaleSurvivorPuzzle::execute() {
redraw();
break;
- case kHitAnimation:
- // Show the "Oh no! Try again" overlay and wait for the player
- // to click Start (full restart via kTryAgain) or Quit (loss
- // scene). Both transitions are handled in handleInput().
- redraw();
- break;
-
case kTryAgain:
_score = 0;
_prevScore = -1;
Commit: 6262be9dcb382d7ed73c691a636b1ad2a5940287
https://github.com/scummvm/scummvm/commit/6262be9dcb382d7ed73c691a636b1ad2a5940287
Author: Filippos Karapetis (bluegr at gmail.com)
Date: 2026-11-06T04:11:22+02:00
Commit Message:
NANCY: Add sanity check for the EVNT engine data. PVS-Studio V522
Changed paths:
engines/nancy/nancy.cpp
diff --git a/engines/nancy/nancy.cpp b/engines/nancy/nancy.cpp
index 31f4226cfc5..64ed8dca884 100644
--- a/engines/nancy/nancy.cpp
+++ b/engines/nancy/nancy.cpp
@@ -65,7 +65,6 @@ NancyEngine::NancyEngine(GameType type, OSystem *syst, const ADGameDescription *
Engine(syst),
_gameDescription(gd),
_gameType(type),
- _system(syst),
_datFileMajorVersion(1),
_datFileMinorVersion(0),
_false(type <= kGameTypeNancy2 ? 1 : 0),
@@ -454,8 +453,8 @@ const Common::String NancyEngine::getEventFlagName(uint flagID) const {
if (flagID >= 2000) {
flagID -= 2000;
- const Common::Array<Common::String> &flagNames = dynamic_cast<const EVNT *>(getEngineData("EVNT"))->eventFlagNames;
- return (flagID < flagNames.size()) ? flagNames[flagID] : "";
+ const EVNT *evnt = dynamic_cast<const EVNT *>(getEngineData("EVNT"));
+ return evnt && flagID < evnt->eventFlagNames.size() ? evnt->eventFlagNames[flagID] : "";
}
const GenericEventFlagCategory *categories = kGenericEventFlagCategories;
Commit: 037f6e2e6ece0e4239b681f0da931a7629587d26
https://github.com/scummvm/scummvm/commit/037f6e2e6ece0e4239b681f0da931a7629587d26
Author: Filippos Karapetis (bluegr at gmail.com)
Date: 2026-11-06T04:11:24+02:00
Commit Message:
NANCY: NANCY 11: Add French Steam variant detection entry
Fix #17426
Changed paths:
engines/nancy/detection_tables.h
diff --git a/engines/nancy/detection_tables.h b/engines/nancy/detection_tables.h
index b38ab5b7382..6caa8ad4fd6 100644
--- a/engines/nancy/detection_tables.h
+++ b/engines/nancy/detection_tables.h
@@ -668,6 +668,18 @@ static const ADGameDescription gameDescriptions[] = {
ADGF_TESTING | ADGF_DROPPLATFORM,
NANCY_GUIOPTIONS
},
+ { // French Steam version from cedricl31 in bug #17426
+ "nancy11", nullptr,
+ {
+ { "ciftree.dat", 0, "822cdaa603871a1786824cffd0b7bca8", 56370839 },
+ { "gre_oil_cinematic.bik", 0, "28a2b6f939f1c7795e47a99337d7343a", 21514180 },
+ AD_LISTEND
+ },
+ Common::FR_FRA,
+ Common::kPlatformWindows,
+ ADGF_TESTING | ADGF_DROPPLATFORM,
+ NANCY_GUIOPTIONS
+ },
{
"nancy11", nullptr,
{
More information about the Scummvm-git-logs
mailing list