diff options
Diffstat (limited to 'engines/zvision/cursor_manager.cpp')
-rw-r--r-- | engines/zvision/cursor_manager.cpp | 163 |
1 files changed, 73 insertions, 90 deletions
diff --git a/engines/zvision/cursor_manager.cpp b/engines/zvision/cursor_manager.cpp index de229a38d8..aaf3bb8ee4 100644 --- a/engines/zvision/cursor_manager.cpp +++ b/engines/zvision/cursor_manager.cpp @@ -50,87 +50,59 @@ const char *CursorManager::_zNemCursorFileNames[NUM_CURSORS] = { "00act", "arrow CursorManager::CursorManager(ZVision *engine, const Graphics::PixelFormat *pixelFormat) : _engine(engine), _pixelFormat(pixelFormat), - _cursorIsPushed(false) { - // WARNING: The index IDLE_CURSOR_INDEX is hardcoded. If you change the order of _cursorNames/_zgiCursorFileNames/_zNemCursorFileNames, you HAVE to change the index accordingly - if (_engine->getGameId() == GID_NEMESIS) { - Common::String name(Common::String::format("%sa.zcr", _zNemCursorFileNames[IDLE_CURSOR_INDEX])); - _idleCursor = ZorkCursor(name); - } else if (_engine->getGameId() == GID_GRANDINQUISITOR) { - _idleCursor = ZorkCursor(_zgiCursorFileNames[IDLE_CURSOR_INDEX]); + _cursorIsPushed(false), + _item(0), + _lastitem(0) { + for (int i = 0; i < NUM_CURSORS; i++) { + if (_engine->getGameId() == GID_NEMESIS) { + Common::String name; + name = Common::String::format("%sa.zcr", _zNemCursorFileNames[i]); + _cursors[i][0] = ZorkCursor(name); // Up cursor + name = Common::String::format("%sb.zcr", _zNemCursorFileNames[i]); + _cursors[i][1] = ZorkCursor(name); // Down cursor + } else if (_engine->getGameId() == GID_GRANDINQUISITOR) { + _cursors[i][0] = ZorkCursor(_zgiCursorFileNames[i]); // Up cursor + char buffer[25]; + strcpy(buffer, _zgiCursorFileNames[i]); + buffer[3] += 2; + _cursors[i][1] = ZorkCursor(buffer); // Down cursor + } } } -void CursorManager::initialize() { - revertToIdle(); - CursorMan.showMouse(true); -} - -void CursorManager::changeCursor(const Common::String &cursorName) { - changeCursor(cursorName, _cursorIsPushed); -} - -void CursorManager::changeCursor(const Common::String &cursorName, bool pushed) { - if (_currentCursor.equals(cursorName) && _cursorIsPushed == pushed) - return; - - if (_cursorIsPushed != pushed) - _cursorIsPushed = pushed; - - if (cursorName == "idle" && !pushed) { - CursorMan.replaceCursor(_idleCursor.getSurface(), _idleCursor.getWidth(), _idleCursor.getHeight(), _idleCursor.getHotspotX(), _idleCursor.getHotspotY(), _idleCursor.getKeyColor(), false, _pixelFormat); - return; - } - - for (int i = 0; i < NUM_CURSORS; ++i) { - if (_engine->getGameId() == GID_NEMESIS) { - if (cursorName.equals(_cursorNames[i])) { - _currentCursor = cursorName; - - // ZNem uses a/b at the end of the file to signify not pushed/pushed respectively - Common::String pushedFlag = pushed ? "b" : "a"; - Common::String name = Common::String::format("%s%s.zcr", _zNemCursorFileNames[i], pushedFlag.c_str()); - - changeCursor(ZorkCursor(name)); - return; - } - } else if (_engine->getGameId() == GID_GRANDINQUISITOR) { - if (cursorName.equals(_cursorNames[i])) { - _currentCursor = cursorName; - - if (!pushed) { - changeCursor(ZorkCursor(_zgiCursorFileNames[i])); - } else { - // ZGI flips not pushed/pushed between a/c and b/d - // It flips the 4th character of the name - char buffer[25]; - strcpy(buffer, _zgiCursorFileNames[i]); - buffer[3] += 2; - changeCursor(ZorkCursor(buffer)); - } +void CursorManager::setItemID(int id) { + if (id != _item) { + if (id) { + Common::String file; + if (_engine->getGameId() == GID_NEMESIS) { + file = Common::String::format("%2.2d%s%c.zcr", id, "idle", 'a'); + _cursors[NUM_CURSORS][0] = ZorkCursor(file); + file = Common::String::format("%2.2d%s%c.zcr", id, "idle", 'b'); + _cursors[NUM_CURSORS][1] = ZorkCursor(file); + file = Common::String::format("%2.2d%s%c.zcr", id, "act", 'a'); + _cursors[NUM_CURSORS + 1][0] = ZorkCursor(file); + file = Common::String::format("%2.2d%s%c.zcr", id, "act", 'b'); + _cursors[NUM_CURSORS + 1][0] = ZorkCursor(file); + } else if (_engine->getGameId() == GID_GRANDINQUISITOR) { + file = Common::String::format("g0b%cc%2.2x1.zcr", 'a' , id); + _cursors[NUM_CURSORS][0] = ZorkCursor(file); + file = Common::String::format("g0b%cc%2.2x1.zcr", 'c' , id); + _cursors[NUM_CURSORS][1] = ZorkCursor(file); + file = Common::String::format("g0b%cc%2.2x1.zcr", 'b' , id); + _cursors[NUM_CURSORS + 1][0] = ZorkCursor(file); + file = Common::String::format("g0b%cc%2.2x1.zcr", 'd' , id); + _cursors[NUM_CURSORS + 1][1] = ZorkCursor(file); + } else return; - } } + _item = id; + changeCursor(CursorIndex_Idle); } - - // If we get here, something went wrong - warning("No cursor found for identifier %s", cursorName.c_str()); } -void CursorManager::changeCursor(int id, bool active, bool pushed) { - Common::String file; - if (_engine->getGameId() == GID_NEMESIS) { - file = Common::String::format("%2.2d%s%c.zcr", id, active ? "act" : "idle", pushed ? 'b' : 'a'); - } else if (_engine->getGameId() == GID_GRANDINQUISITOR) { - file = Common::String::format("g0b%cc%2.2x1.zcr", active ? (pushed ? 'd' : 'c') : (pushed ? 'b' : 'a') , id); - } else - return; - - if (_currentCursor.equals(file)) - return; - - _currentCursor = file; - - changeCursor(ZorkCursor(file)); +void CursorManager::initialize() { + changeCursor(_cursors[CursorIndex_Idle][_cursorIsPushed]); + showMouse(true); } void CursorManager::changeCursor(const ZorkCursor &cursor) { @@ -141,31 +113,42 @@ void CursorManager::cursorDown(bool pushed) { if (_cursorIsPushed == pushed) return; - changeCursor(_currentCursor, pushed); -} + _cursorIsPushed = pushed; -void CursorManager::setLeftCursor() { - changeCursor("leftarrow"); + changeCursor(_cursors[_currentCursor][_cursorIsPushed]); } -void CursorManager::setRightCursor() { - changeCursor("rightarrow"); -} +void CursorManager::changeCursor(int id) { + int _id = id; -void CursorManager::setUpCursor() { - changeCursor("zuparrow"); + if (_item && + (_id == CursorIndex_Active || + _id == CursorIndex_Idle || + _id == CursorIndex_HandPu)) { + + if (_id == CursorIndex_Idle) + _id = CursorIndex_ItemIdle; + else + _id = CursorIndex_ItemAct; + } + + if (_currentCursor != _id || + ((_id == CursorIndex_ItemAct || _id == CursorIndex_ItemIdle) && _lastitem != _item)) { + _currentCursor = _id; + _lastitem = _item; + changeCursor(_cursors[_currentCursor][_cursorIsPushed]); + } } -void CursorManager::setDownCursor() { - changeCursor("downarrow"); +int CursorManager::getCursorId(Common::String &name) { + for (int i = 0; i < NUM_CURSORS; i++) + if (name.equals(_cursorNames[i])) + return i; + return CursorIndex_Idle; } -void CursorManager::revertToIdle() { - _currentCursor = "idle"; - if (!_cursorIsPushed) - CursorMan.replaceCursor(_idleCursor.getSurface(), _idleCursor.getWidth(), _idleCursor.getHeight(), _idleCursor.getHotspotX(), _idleCursor.getHotspotY(), _idleCursor.getKeyColor(), false, _pixelFormat); - else - changeCursor(_currentCursor, _cursorIsPushed); +void CursorManager::showMouse(bool vis) { + CursorMan.showMouse(vis); } } // End of namespace ZVision |