From cb2503aa9dd5d76a12aaf0522ddea810907a97a5 Mon Sep 17 00:00:00 2001 From: Marisa-Chan Date: Fri, 7 Feb 2014 23:03:02 +0700 Subject: ZVISION: Refactor of pushtoggle code, now full functional implementation. --- engines/zvision/push_toggle_control.cpp | 51 ++++++++++++++++++++++++++++++--- engines/zvision/push_toggle_control.h | 12 ++++++++ 2 files changed, 59 insertions(+), 4 deletions(-) diff --git a/engines/zvision/push_toggle_control.cpp b/engines/zvision/push_toggle_control.cpp index 86f499739c..0ba6dd7d25 100644 --- a/engines/zvision/push_toggle_control.cpp +++ b/engines/zvision/push_toggle_control.cpp @@ -35,10 +35,13 @@ namespace ZVision { PushToggleControl::PushToggleControl(ZVision *engine, uint32 key, Common::SeekableReadStream &stream) - : Control(engine, key) { + : Control(engine, key), + _countTo(2), + _event(Common::EVENT_LBUTTONUP) { // Loop until we find the closing brace Common::String line = stream.readLine(); trimCommentsAndWhiteSpace(&line); + line.toLowercase(); while (!stream.eos() && !line.contains('}')) { if (line.matchString("*_hotspot*", true)) { @@ -56,6 +59,27 @@ PushToggleControl::PushToggleControl(ZVision *engine, uint32 key, Common::Seekab sscanf(line.c_str(), "%*[^(](%25[^)])", nameBuffer); _hoverCursor = Common::String(nameBuffer); + } else if (line.matchString("animation*", true)) { + // Not used + } else if (line.matchString("sound*", true)) { + // Not used + } else if (line.matchString("count_to*", true)) { + sscanf(line.c_str(), "%*[^(](%u)", &_countTo); + } else if (line.matchString("mouse_event*", true)) { + char nameBuffer[25]; + + sscanf(line.c_str(), "%*[^(](%25[^)])", nameBuffer); + + Common::String evntStr(nameBuffer); + if (evntStr.equalsIgnoreCase("up")) { + _event = Common::EVENT_LBUTTONUP; + } else if (evntStr.equalsIgnoreCase("down")) { + _event = Common::EVENT_LBUTTONDOWN; + } else if (evntStr.equalsIgnoreCase("double")) { + // Not used + } + } else if (line.matchString("venus_id*", true)) { + // Not used } line = stream.readLine(); @@ -68,16 +92,35 @@ PushToggleControl::PushToggleControl(ZVision *engine, uint32 key, Common::Seekab } PushToggleControl::~PushToggleControl() { - // Clear the state value back to 0 - _engine->getScriptManager()->setStateValue(_key, 0); } bool PushToggleControl::onMouseUp(const Common::Point &screenSpacePos, const Common::Point &backgroundImageSpacePos) { if (_engine->getScriptManager()->getStateFlag(_key) & Puzzle::DISABLED) return false; + if (_event != Common::EVENT_LBUTTONUP) + return false; + + if (_hotspot.contains(backgroundImageSpacePos)) { + int32 val = _engine->getScriptManager()->getStateValue(_key); + val = (val + 1) % _countTo; + _engine->getScriptManager()->setStateValue(_key, val); + return true; + } + return false; +} + +bool PushToggleControl::onMouseDown(const Common::Point &screenSpacePos, const Common::Point &backgroundImageSpacePos) { + if (_engine->getScriptManager()->getStateFlag(_key) & Puzzle::DISABLED) + return false; + + if (_event != Common::EVENT_LBUTTONDOWN) + return false; + if (_hotspot.contains(backgroundImageSpacePos)) { - _engine->getScriptManager()->setStateValue(_key, 1); + int32 val = _engine->getScriptManager()->getStateValue(_key); + val = (val + 1) % _countTo; + _engine->getScriptManager()->setStateValue(_key, val); return true; } return false; diff --git a/engines/zvision/push_toggle_control.h b/engines/zvision/push_toggle_control.h index 1de279aa08..17ff850e32 100644 --- a/engines/zvision/push_toggle_control.h +++ b/engines/zvision/push_toggle_control.h @@ -26,6 +26,7 @@ #include "zvision/control.h" #include "common/rect.h" +#include "common/events.h" namespace ZVision { @@ -35,6 +36,13 @@ public: PushToggleControl(ZVision *engine, uint32 key, Common::SeekableReadStream &stream); ~PushToggleControl(); + /** + * Called when LeftMouse is pushed. Default is NOP. + * + * @param screenSpacePos The position of the mouse in screen space + * @param backgroundImageSpacePos The position of the mouse in background image space + */ + bool onMouseDown(const Common::Point &screenSpacePos, const Common::Point &backgroundImageSpacePos); /** * Called when LeftMouse is lifted. Calls ScriptManager::setStateValue(_key, 1); * @@ -60,6 +68,10 @@ private: Common::Rect _hotspot; /** The cursor to use when hovering over _hotspot */ Common::String _hoverCursor; + /** Button maximal values count */ + uint _countTo; + + Common::EventType _event; }; } // End of namespace ZVision -- cgit v1.2.3