diff options
author | Marisa-Chan | 2014-11-12 16:05:48 +0600 |
---|---|---|
committer | Marisa-Chan | 2014-11-12 16:05:48 +0600 |
commit | e970d121ff1acbe426e652a4ac17deebaf351821 (patch) | |
tree | 8c015c82e3885f98b26b4655d007d0f806e597cc | |
parent | 960bbe53b2160de3747678bd877c532d49c7d147 (diff) | |
download | scummvm-rg350-e970d121ff1acbe426e652a4ac17deebaf351821.tar.gz scummvm-rg350-e970d121ff1acbe426e652a4ac17deebaf351821.tar.bz2 scummvm-rg350-e970d121ff1acbe426e652a4ac17deebaf351821.zip |
ZVISION: Lead code of all controls to the same style
8 files changed, 161 insertions, 104 deletions
diff --git a/engines/zvision/scripting/controls/fist_control.cpp b/engines/zvision/scripting/controls/fist_control.cpp index 89aeb53be6..4779c5db74 100644 --- a/engines/zvision/scripting/controls/fist_control.cpp +++ b/engines/zvision/scripting/controls/fist_control.cpp @@ -187,54 +187,58 @@ void FistControl::readDescFile(const Common::String &fileName) { } Common::String line; + Common::String param; + Common::String values; while (!file.eos()) { line = file.readLine(); + getFistParams(line, param, values); - for (int i = line.size() - 1; i >= 0; i--) - if (line[i] == '~') - line.deleteChar(i); - - if (line.matchString("*animation_id*", true)) { + if (param.matchString("animation_id", true)) { // Not used - } else if (line.matchString("*animation*", true)) { - char filename[64]; - sscanf(line.c_str(), "animation:%s", filename); - _animation = new MetaAnimation(Common::String(filename), _engine); - } else if (line.matchString("*anim_rect*", true)) { + } else if (param.matchString("animation", true)) { + _animation = new MetaAnimation(values, _engine); + } else if (param.matchString("anim_rect", true)) { int left, top, right, bottom; - sscanf(line.c_str(), "anim_rect:%d %d %d %d", &left, &top, &right, &bottom); + sscanf(values.c_str(), "%d %d %d %d", &left, &top, &right, &bottom); _anmRect = Common::Rect(left, top, right, bottom); - } else if (line.matchString("*num_fingers*", true)) { - sscanf(line.c_str(), "num_fingers:%d", &_fistnum); + } else if (param.matchString("num_fingers", true)) { + sscanf(values.c_str(), "%d", &_fistnum); _fistsUp.resize(_fistnum); _fistsDwn.resize(_fistnum); - } else if (line.matchString("*entries*", true)) { - sscanf(line.c_str(), "entries:%d", &_numEntries); + } else if (param.matchString("entries", true)) { + sscanf(values.c_str(), "%d", &_numEntries); _entries.resize(_numEntries); - } else if (line.matchString("*eval_order_ascending*", true)) { - sscanf(line.c_str(), "eval_order_ascending:%d", &_order); - } else if (line.matchString("*up_hs_num_*", true)) { + } else if (param.matchString("eval_order_ascending", true)) { + sscanf(values.c_str(), "%d", &_order); + } else if (param.matchString("up_hs_num_*", true)) { int fist, num; - sscanf(line.c_str(), "up_hs_num_%d:%d", &fist, &num); + num = atoi(values.c_str()); + + sscanf(param.c_str(), "up_hs_num_%d", &fist); _fistsUp[fist].resize(num); - } else if (line.matchString("*up_hs_*", true)) { + } else if (param.matchString("up_hs_*", true)) { int16 fist, box, x1, y1, x2, y2; - sscanf(line.c_str(), "up_hs_%hd_%hd:%hd %hd %hd %hd", &fist, &box, &x1, &y1, &x2, &y2); + sscanf(param.c_str(), "up_hs_%hd_%hd", &fist, &box); + sscanf(values.c_str(), "%hd %hd %hd %hd", &x1, &y1, &x2, &y2); (_fistsUp[fist])[box] = Common::Rect(x1, y1, x2, y2); - } else if (line.matchString("*down_hs_num_*", true)) { + } else if (param.matchString("down_hs_num_*", true)) { int fist, num; - sscanf(line.c_str(), "down_hs_num_%d:%d", &fist, &num); + num = atoi(values.c_str()); + + sscanf(param.c_str(), "down_hs_num_%d", &fist); _fistsDwn[fist].resize(num); - } else if (line.matchString("*down_hs_*", true)) { + } else if (param.matchString("down_hs_*", true)) { int16 fist, box, x1, y1, x2, y2; - sscanf(line.c_str(), "down_hs_%hd_%hd:%hd %hd %hd %hd", &fist, &box, &x1, &y1, &x2, &y2); + sscanf(param.c_str(), "down_hs_%hd_%hd", &fist, &box); + sscanf(values.c_str(), "%hd %hd %hd %hd", &x1, &y1, &x2, &y2); (_fistsDwn[fist])[box] = Common::Rect(x1, y1, x2, y2); } else { int entry, start, end, sound; char bits_start[33]; char bits_end[33]; - if (sscanf(line.c_str(), "%d:%s %s %d %d (%d)", &entry, bits_start, bits_end, &start, &end, &sound) == 6) { + entry = atoi(param.c_str()); + if (sscanf(values.c_str(), "%s %s %d %d (%d)", bits_start, bits_end, &start, &end, &sound) == 5) { _entries[entry]._bitsStrt = readBits(bits_start); _entries[entry]._bitsEnd = readBits(bits_end); _entries[entry]._anmStrt = start; @@ -291,4 +295,28 @@ int FistControl::mouseIn(const Common::Point &screenSpacePos, const Common::Poin return -1; } +void FistControl::getFistParams(const Common::String &input_str, Common::String ¶meter, Common::String &values) { + const char *chrs = input_str.c_str(); + uint lbr; + + for (lbr = 0; lbr < input_str.size(); lbr++) + if (chrs[lbr] == ':') + break; + + if (lbr >= input_str.size()) + return; + + uint rbr; + + for (rbr = lbr + 1; rbr < input_str.size(); rbr++) + if (chrs[rbr] == '~') + break; + + if (rbr >= input_str.size()) + return; + + parameter = Common::String(chrs, chrs + lbr); + values = Common::String(chrs + lbr + 1, chrs + rbr); +} + } // End of namespace ZVision diff --git a/engines/zvision/scripting/controls/fist_control.h b/engines/zvision/scripting/controls/fist_control.h index 940bc96d69..8b229f964a 100644 --- a/engines/zvision/scripting/controls/fist_control.h +++ b/engines/zvision/scripting/controls/fist_control.h @@ -79,6 +79,7 @@ private: void clearFistArray(Common::Array< Common::Array<Common::Rect> > &arr); uint32 readBits(const char *str); int mouseIn(const Common::Point &screenSpacePos, const Common::Point &backgroundImageSpacePos); + void getFistParams(const Common::String &input_str, Common::String ¶meter, Common::String &values); }; } // End of namespace ZVision diff --git a/engines/zvision/scripting/controls/input_control.cpp b/engines/zvision/scripting/controls/input_control.cpp index e35b300cb9..f8acdbda73 100644 --- a/engines/zvision/scripting/controls/input_control.cpp +++ b/engines/zvision/scripting/controls/input_control.cpp @@ -51,59 +51,63 @@ InputControl::InputControl(ZVision *engine, uint32 key, Common::SeekableReadStre // Loop until we find the closing brace Common::String line = stream.readLine(); trimCommentsAndWhiteSpace(&line); + Common::String param; + Common::String values; + getParams(line, param, values); while (!stream.eos() && !line.contains('}')) { - if (line.matchString("*rectangle*", true)) { + if (param.matchString("rectangle", true)) { int x1; int y1; int x2; int y2; - sscanf(line.c_str(), "%*[^(](%d %d %d %d)", &x1, &y1, &x2, &y2); + sscanf(values.c_str(), "%d %d %d %d", &x1, &y1, &x2, &y2); _textRectangle = Common::Rect(x1, y1, x2, y2); - } else if (line.matchString("*aux_hotspot*", true)) { + } else if (param.matchString("aux_hotspot", true)) { int x1; int y1; int x2; int y2; - sscanf(line.c_str(), "%*[^(](%d %d %d %d)", &x1, &y1, &x2, &y2); + sscanf(values.c_str(), "%d %d %d %d", &x1, &y1, &x2, &y2); _headerRectangle = Common::Rect(x1, y1, x2, y2); - } else if (line.matchString("*string_init*", true)) { + } else if (param.matchString("string_init", true)) { uint fontFormatNumber; - sscanf(line.c_str(), "%*[^(](%u)", &fontFormatNumber); + sscanf(values.c_str(), "%u", &fontFormatNumber); _string_init.readAllStyle(_engine->getStringManager()->getTextLine(fontFormatNumber)); - } else if (line.matchString("*chooser_init_string*", true)) { + } else if (param.matchString("chooser_init_string", true)) { uint fontFormatNumber; - sscanf(line.c_str(), "%*[^(](%u)", &fontFormatNumber); + sscanf(values.c_str(), "%u", &fontFormatNumber); _string_chooser_init.readAllStyle(_engine->getStringManager()->getTextLine(fontFormatNumber)); - } else if (line.matchString("*next_tabstop*", true)) { - sscanf(line.c_str(), "%*[^(](%u)", &_nextTabstop); - } else if (line.matchString("*cursor_dimensions*", true)) { + } else if (param.matchString("next_tabstop", true)) { + sscanf(values.c_str(), "%u", &_nextTabstop); + } else if (param.matchString("cursor_dimensions", true)) { // Ignore, use the dimensions in the animation file - } else if (line.matchString("*cursor_animation_frames*", true)) { + } else if (param.matchString("cursor_animation_frames", true)) { // Ignore, use the frame count in the animation file - } else if (line.matchString("*cursor_animation*", true)) { + } else if (param.matchString("cursor_animation", true)) { char fileName[25]; - sscanf(line.c_str(), "%*[^(](%25s %*u)", fileName); + sscanf(values.c_str(), "%25s %*u", fileName); _animation = new MetaAnimation(fileName, _engine); _frame = -1; _frameDelay = 0; - } else if (line.matchString("*focus*", true)) { + } else if (param.matchString("focus", true)) { _focused = true; _engine->getScriptManager()->setFocusControlKey(_key); } line = stream.readLine(); trimCommentsAndWhiteSpace(&line); + getParams(line, param, values); } } diff --git a/engines/zvision/scripting/controls/lever_control.cpp b/engines/zvision/scripting/controls/lever_control.cpp index 84cd6fa598..9b665ff033 100644 --- a/engines/zvision/scripting/controls/lever_control.cpp +++ b/engines/zvision/scripting/controls/lever_control.cpp @@ -57,21 +57,26 @@ LeverControl::LeverControl(ZVision *engine, uint32 key, Common::SeekableReadStre Common::String line = stream.readLine(); trimCommentsAndWhiteSpace(&line); + Common::String param; + Common::String values; + getParams(line, param, values); + while (!stream.eos() && !line.contains('}')) { - if (line.matchString("*descfile*", true)) { + if (param.matchString("descfile", true)) { char levFileName[25]; - sscanf(line.c_str(), "%*[^(](%25[^)])", levFileName); + sscanf(values.c_str(), "%25s", levFileName); parseLevFile(levFileName); - } else if (line.matchString("*cursor*", true)) { + } else if (param.matchString("cursor", true)) { char cursorName[25]; - sscanf(line.c_str(), "%*[^(](%25[^)])", cursorName); + sscanf(values.c_str(), "%25s", cursorName); - _cursorName = Common::String(cursorName); + _cursor = _engine->getCursorManager()->getCursorId(Common::String(cursorName)); } line = stream.readLine(); trimCommentsAndWhiteSpace(&line); + getParams(line, param, values); } renderFrame(_currentFrame); @@ -92,50 +97,47 @@ void LeverControl::parseLevFile(const Common::String &fileName) { } Common::String line; + Common::String param; + Common::String values; while (!file.eos()) { line = file.readLine(); + getLevParams(line, param, values); - if (line.matchString("*animation_id*", true)) { + if (param.matchString("animation_id", true)) { // Not used - } else if (line.matchString("*filename*", true)) { - char fileNameBuffer[25]; - sscanf(line.c_str(), "%*[^:]:%25[^~]~", fileNameBuffer); - - Common::String animationFileName(fileNameBuffer); - - _animation = new MetaAnimation(animationFileName, _engine); - - } else if (line.matchString("*skipcolor*", true)) { + } else if (param.matchString("filename", true)) { + _animation = new MetaAnimation(values, _engine); + } else if (param.matchString("skipcolor", true)) { // Not used - } else if (line.matchString("*anim_coords*", true)) { + } else if (param.matchString("anim_coords", true)) { int left, top, right, bottom; - sscanf(line.c_str(), "%*[^:]:%d %d %d %d~", &left, &top, &right, &bottom); + sscanf(values.c_str(), "%d %d %d %d", &left, &top, &right, &bottom); _animationCoords.left = left; _animationCoords.top = top; _animationCoords.right = right; _animationCoords.bottom = bottom; - } else if (line.matchString("*mirrored*", true)) { + } else if (param.matchString("mirrored", true)) { uint mirrored; - sscanf(line.c_str(), "%*[^:]:%u~", &mirrored); + sscanf(values.c_str(), "%u", &mirrored); _mirrored = mirrored == 0 ? false : true; - } else if (line.matchString("*frames*", true)) { - sscanf(line.c_str(), "%*[^:]:%u~", &_frameCount); + } else if (param.matchString("frames", true)) { + sscanf(values.c_str(), "%u", &_frameCount); _frameInfo = new FrameInfo[_frameCount]; - } else if (line.matchString("*elsewhere*", true)) { + } else if (param.matchString("elsewhere", true)) { // Not used - } else if (line.matchString("*out_of_control*", true)) { + } else if (param.matchString("out_of_control", true)) { // Not used - } else if (line.matchString("*start_pos*", true)) { - sscanf(line.c_str(), "%*[^:]:%u~", &_startFrame); + } else if (param.matchString("start_pos", true)) { + sscanf(values.c_str(), "%u", &_startFrame); _currentFrame = _startFrame; - } else if (line.matchString("*hotspot_deltas*", true)) { + } else if (param.matchString("hotspot_deltas", true)) { uint x; uint y; - sscanf(line.c_str(), "%*[^:]:%u %u~", &x, &y); + sscanf(values.c_str(), "%u %u", &x, &y); _hotspotDelta.x = x; _hotspotDelta.y = y; @@ -233,7 +235,7 @@ bool LeverControl::onMouseMove(const Common::Point &screenSpacePos, const Common } } } else if (_frameInfo[_currentFrame].hotspot.contains(backgroundImageSpacePos)) { - _engine->getCursorManager()->changeCursor(_engine->getCursorManager()->getCursorId(_cursorName)); + _engine->getCursorManager()->changeCursor(_cursor); cursorWasChanged = true; } @@ -376,4 +378,28 @@ void LeverControl::renderFrame(uint frameNumber) { _engine->getRenderManager()->blitSurfaceToBkgScaled(*frameData, _animationCoords); } +void LeverControl::getLevParams(const Common::String &input_str, Common::String ¶meter, Common::String &values) { + const char *chrs = input_str.c_str(); + uint lbr; + + for (lbr = 0; lbr < input_str.size(); lbr++) + if (chrs[lbr] == ':') + break; + + if (lbr >= input_str.size()) + return; + + uint rbr; + + for (rbr = lbr + 1; rbr < input_str.size(); rbr++) + if (chrs[rbr] == '~') + break; + + if (rbr >= input_str.size()) + return; + + parameter = Common::String(chrs, chrs + lbr); + values = Common::String(chrs + lbr + 1, chrs + rbr); +} + } // End of namespace ZVision diff --git a/engines/zvision/scripting/controls/lever_control.h b/engines/zvision/scripting/controls/lever_control.h index 712d688523..22789f777b 100644 --- a/engines/zvision/scripting/controls/lever_control.h +++ b/engines/zvision/scripting/controls/lever_control.h @@ -62,7 +62,7 @@ private: private: MetaAnimation *_animation; - Common::String _cursorName; + int _cursor; Common::Rect _animationCoords; bool _mirrored; uint _frameCount; @@ -112,6 +112,7 @@ private: */ static int calculateVectorAngle(const Common::Point &pointOne, const Common::Point &pointTwo); void renderFrame(uint frameNumber); + void getLevParams(const Common::String &input_str, Common::String ¶meter, Common::String &values); }; } // End of namespace ZVision diff --git a/engines/zvision/scripting/controls/push_toggle_control.cpp b/engines/zvision/scripting/controls/push_toggle_control.cpp index bf74a22051..03df4b722e 100644 --- a/engines/zvision/scripting/controls/push_toggle_control.cpp +++ b/engines/zvision/scripting/controls/push_toggle_control.cpp @@ -38,56 +38,52 @@ PushToggleControl::PushToggleControl(ZVision *engine, uint32 key, Common::Seekab : Control(engine, key, CONTROL_PUSHTGL), _countTo(2), _event(Common::EVENT_LBUTTONUP) { + + _hotspots.clear(); + // Loop until we find the closing brace Common::String line = stream.readLine(); trimCommentsAndWhiteSpace(&line); - line.toLowercase(); - _hotspots.clear(); + Common::String param; + Common::String values; + getParams(line, param, values); while (!stream.eos() && !line.contains('}')) { - if (line.matchString("*_hotspot*", true)) { + if (param.matchString("*_hotspot", true)) { uint x; uint y; uint width; uint height; - sscanf(line.c_str(), "%*[^(](%u,%u,%u,%u)", &x, &y, &width, &height); + sscanf(values.c_str(), "%u,%u,%u,%u", &x, &y, &width, &height); _hotspots.push_back(Common::Rect(x, y, x + width + 1, y + height + 1)); - } else if (line.matchString("cursor*", true)) { - char nameBuffer[25]; - - sscanf(line.c_str(), "%*[^(](%25[^)])", nameBuffer); - - _hoverCursor = Common::String(nameBuffer); - } else if (line.matchString("animation*", true)) { + } else if (param.matchString("cursor", true)) { + _cursor = _engine->getCursorManager()->getCursorId(values); + } else if (param.matchString("animation", true)) { // Not used - } else if (line.matchString("sound*", true)) { + } else if (param.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")) { + } else if (param.matchString("count_to", true)) { + sscanf(values.c_str(), "%u", &_countTo); + } else if (param.matchString("mouse_event", true)) { + if (values.equalsIgnoreCase("up")) { _event = Common::EVENT_LBUTTONUP; - } else if (evntStr.equalsIgnoreCase("down")) { + } else if (values.equalsIgnoreCase("down")) { _event = Common::EVENT_LBUTTONDOWN; - } else if (evntStr.equalsIgnoreCase("double")) { + } else if (values.equalsIgnoreCase("double")) { // Not used } - } else if (line.matchString("venus_id*", true)) { + } else if (param.matchString("venus_id*", true)) { // Not used } line = stream.readLine(); trimCommentsAndWhiteSpace(&line); + getParams(line, param, values); } - if (_hotspots.size() == 0 || _hoverCursor.empty()) { + if (_hotspots.size() == 0) { warning("Push_toggle %u was parsed incorrectly", key); } } @@ -133,7 +129,7 @@ bool PushToggleControl::onMouseMove(const Common::Point &screenSpacePos, const C return false; if (contain(backgroundImageSpacePos)) { - _engine->getCursorManager()->changeCursor(_engine->getCursorManager()->getCursorId(_hoverCursor)); + _engine->getCursorManager()->changeCursor(_cursor); return true; } diff --git a/engines/zvision/scripting/controls/push_toggle_control.h b/engines/zvision/scripting/controls/push_toggle_control.h index 7b45fb4831..6d68b8f162 100644 --- a/engines/zvision/scripting/controls/push_toggle_control.h +++ b/engines/zvision/scripting/controls/push_toggle_control.h @@ -68,7 +68,7 @@ private: */ Common::Array<Common::Rect> _hotspots; /** The cursor to use when hovering over _hotspot */ - Common::String _hoverCursor; + int _cursor; /** Button maximal values count */ uint _countTo; diff --git a/engines/zvision/scripting/controls/save_control.cpp b/engines/zvision/scripting/controls/save_control.cpp index fda8a70114..a0b19db513 100644 --- a/engines/zvision/scripting/controls/save_control.cpp +++ b/engines/zvision/scripting/controls/save_control.cpp @@ -44,23 +44,23 @@ SaveControl::SaveControl(ZVision *engine, uint32 key, Common::SeekableReadStream // Loop until we find the closing brace Common::String line = stream.readLine(); trimCommentsAndWhiteSpace(&line); + Common::String param; + Common::String values; + getParams(line, param, values); while (!stream.eos() && !line.contains('}')) { - if (line.matchString("*savebox*", true)) { + if (param.matchString("savebox", true)) { int save_id; int input_id; - sscanf(line.c_str(), "%*[^(](%d %d)", &save_id, &input_id); + sscanf(values.c_str(), "%d %d", &save_id, &input_id); save_elmnt elmnt; elmnt.input_key = input_id; elmnt.save_id = save_id; elmnt.exist = false; _inputs.push_back(elmnt); - } else if (line.matchString("*control_type*", true)) { - char buf[32]; - - sscanf(line.c_str(), "%*[^(](%s)", buf); - if (Common::String(buf).contains("save")) + } else if (param.matchString("control_type", true)) { + if (values.contains("save")) _saveControl = true; else _saveControl = false; @@ -68,6 +68,7 @@ SaveControl::SaveControl(ZVision *engine, uint32 key, Common::SeekableReadStream line = stream.readLine(); trimCommentsAndWhiteSpace(&line); + getParams(line, param, values); } for (saveElmntList::iterator iter = _inputs.begin(); iter != _inputs.end(); ++iter) { |