diff options
author | Marisa-Chan | 2014-02-07 23:03:02 +0700 |
---|---|---|
committer | Marisa-Chan | 2014-02-07 23:03:02 +0700 |
commit | cb2503aa9dd5d76a12aaf0522ddea810907a97a5 (patch) | |
tree | 437cce8fe57dbce63e8a09f2049386b4d7c4f089 /engines | |
parent | 00337400010efc1012e95ec0c14a77423bb3a0ee (diff) | |
download | scummvm-rg350-cb2503aa9dd5d76a12aaf0522ddea810907a97a5.tar.gz scummvm-rg350-cb2503aa9dd5d76a12aaf0522ddea810907a97a5.tar.bz2 scummvm-rg350-cb2503aa9dd5d76a12aaf0522ddea810907a97a5.zip |
ZVISION: Refactor of pushtoggle code, now full functional implementation.
Diffstat (limited to 'engines')
-rw-r--r-- | engines/zvision/push_toggle_control.cpp | 51 | ||||
-rw-r--r-- | 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 { @@ -36,6 +37,13 @@ public: ~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); * * @param screenSpacePos The position of the mouse in screen space @@ -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 |