From fd3a29faf3369844015cfc5d6252ccff9ce5f40c Mon Sep 17 00:00:00 2001 From: scemino Date: Sun, 28 Apr 2024 20:07:28 +0200 Subject: [PATCH] TWP: Add moveCursorTo --- engines/twp/motor.cpp | 12 ++++++++++++ engines/twp/motor.h | 13 +++++++++++++ engines/twp/syslib.cpp | 12 ++++++++++-- engines/twp/twp.cpp | 4 +++- engines/twp/twp.h | 1 + 5 files changed, 39 insertions(+), 3 deletions(-) diff --git a/engines/twp/motor.cpp b/engines/twp/motor.cpp index 977d49e5c73..5dd14b0be36 100644 --- a/engines/twp/motor.cpp +++ b/engines/twp/motor.cpp @@ -675,4 +675,16 @@ void Jiggle::onUpdate(float elapsed) { _node->setRotationOffset(_amount * sin(_jiggleTime)); } +MoveCursorTo::MoveCursorTo(const Math::Vector2d &pos, float time) + : _pos(pos), + _tween(g_twp->_cursor.pos, pos, time, intToInterpolationMethod(IK_LINEAR)) { +} + +void MoveCursorTo::onUpdate(float elapsed) { + _tween.update(elapsed); + g_twp->_cursor.pos = _tween.current(); + if (!_tween.running()) + disable(); +} + } // namespace Twp diff --git a/engines/twp/motor.h b/engines/twp/motor.h index a305001a9d1..115a5e2be6b 100644 --- a/engines/twp/motor.h +++ b/engines/twp/motor.h @@ -319,6 +319,19 @@ private: float _jiggleTime = 0.f; }; +class MoveCursorTo : public Motor { +public: + MoveCursorTo(const Math::Vector2d &pos, float time); + virtual ~MoveCursorTo() {} + +private: + virtual void onUpdate(float elapsed) override; + +private: + Tween _tween; + Math::Vector2d _pos; +}; + } // namespace Twp #endif diff --git a/engines/twp/syslib.cpp b/engines/twp/syslib.cpp index 817bda06e2d..4d51797cd07 100644 --- a/engines/twp/syslib.cpp +++ b/engines/twp/syslib.cpp @@ -715,8 +715,16 @@ static SQInteger moveCursorTo(HSQUIRRELVM v) { if (SQ_FAILED(sqget(v, 4, t))) return sq_throwerror(v, "Failed to get time"); - g_twp->_cursor.pos = Math::Vector2d(x, y); - // TODO: use time + Math::Vector2d pos; + if (g_twp->_room) { + pos = g_twp->roomToScreen(Math::Vector2d(x, y)); + } else { + pos = g_twp->screenToWin(Math::Vector2d(x, y)); + } + pos.setX(CLIP(pos.getX(), 0.f, (float)SCREEN_WIDTH)); + pos.setY(CLIP(pos.getY(), 0.f, (float)SCREEN_HEIGHT)); + pos = g_twp->screenToWin(pos); + g_twp->_moveCursorTo = Common::ScopedPtr(new MoveCursorTo(pos, t)); return 0; } diff --git a/engines/twp/twp.cpp b/engines/twp/twp.cpp index 1cfbb698fc1..65bac44dc85 100644 --- a/engines/twp/twp.cpp +++ b/engines/twp/twp.cpp @@ -455,6 +455,8 @@ void TwpEngine::update(float elapsed) { _noOverride->update(elapsed); if (_talking) _talking->update(elapsed); + if (_moveCursorTo) + _moveCursorTo->update(elapsed); // update mouse pos Math::Vector2d scrPos = winToScreen(_cursor.pos); @@ -569,7 +571,7 @@ void TwpEngine::update(float elapsed) { bool isNotInDialog = _dialog->getState() == DialogState::None; for (auto it = threads.begin(); it != threads.end(); it++) { Common::SharedPtr thread(*it); - if ((isNotInDialog || !thread->isGlobal()) && thread->update(elapsed)) { + if ((isNotInDialog || !thread->isGlobal() || !thread->_pauseable) && thread->update(elapsed)) { threadsToRemove.push_back(thread); } } diff --git a/engines/twp/twp.h b/engines/twp/twp.h index 4e73439ad53..a98ee61ed7c 100644 --- a/engines/twp/twp.h +++ b/engines/twp/twp.h @@ -267,6 +267,7 @@ public: unique_ptr _hotspotMarker; unique_ptr _fadeShader; unique_ptr _lightingNode; + unique_ptr _moveCursorTo; private: Gfx _gfx;