From 89c89c02091512a7960bde3ccaa2d84b6c012bbf Mon Sep 17 00:00:00 2001 From: Travis Howell Date: Thu, 13 Apr 2006 14:26:46 +0000 Subject: Add code for save game interface in FF svn-id: r21843 --- engines/simon/charset.cpp | 6 +- engines/simon/items.cpp | 7 ++ engines/simon/oracle.cpp | 220 +++++++++++++++++++++++++++++++-------------- engines/simon/saveload.cpp | 18 ++-- engines/simon/simon.cpp | 2 +- engines/simon/simon.h | 9 +- engines/simon/verb.cpp | 2 +- 7 files changed, 183 insertions(+), 81 deletions(-) diff --git a/engines/simon/charset.cpp b/engines/simon/charset.cpp index 8e8e431dc6..73f4fe699d 100644 --- a/engines/simon/charset.cpp +++ b/engines/simon/charset.cpp @@ -283,6 +283,10 @@ static const byte feebleFontSize[208] = { 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, }; +uint SimonEngine::getFeebleFontSize(byte chr) { + return feebleFontSize[chr - 32]; +} + void SimonEngine::showMessageFormat(const char *s, ...) { char buf[STRINGBUFLEN]; char *str; @@ -382,7 +386,7 @@ void SimonEngine::showmessage_helper_3(uint a, uint b) { _newLines = 0; } -void SimonEngine::videoPutchar(WindowBlock *window, byte c, byte b) { +void SimonEngine::windowPutChar(WindowBlock *window, byte c, byte b) { byte width = 6; if (c == 12) { diff --git a/engines/simon/items.cpp b/engines/simon/items.cpp index 7cb18b7912..f2cda580a1 100644 --- a/engines/simon/items.cpp +++ b/engines/simon/items.cpp @@ -321,6 +321,7 @@ void SimonEngine::setupOpcodes() { opcode_table[124] = &SimonEngine::o3_ifTime; opcode_table[127] = &SimonEngine::o3_playTune; opcode_table[131] = &SimonEngine::o3_setTime; + opcode_table[132] = &SimonEngine::o3_saveUserGame, opcode_table[133] = &SimonEngine::o3_loadUserGame; opcode_table[134] = &SimonEngine::o3_listSaveGames; opcode_table[135] = &SimonEngine::o3_checkCD; @@ -1823,6 +1824,12 @@ void SimonEngine::o3_setTime() { _timeStore -= _gameStoppedClock; } +void SimonEngine::o3_saveUserGame() { + // 132: save game + _noOracleScroll = 0; + saveUserGame(countSaveGames() + 1 - readVariable(55)); +} + void SimonEngine::o3_loadUserGame() { // 133: load game loadGame(readVariable(55)); diff --git a/engines/simon/oracle.cpp b/engines/simon/oracle.cpp index 48ae045a32..19d0715fdc 100644 --- a/engines/simon/oracle.cpp +++ b/engines/simon/oracle.cpp @@ -154,73 +154,6 @@ void SimonEngine::oracleTextDown() { } } -void SimonEngine::listSaveGames(int n) { - char b[108]; - Common::InSaveFile *in; - uint16 j, k, z, maxFiles; - int OK; - memset(b, 0, 108); - - maxFiles = countSaveGames() - 1; - j = maxFiles - n + 1; - k = maxFiles - j + 1; - z = maxFiles; - if (getBitFlag(95)) { - j++; - z++; - } - - while(1) { - OK=1; - if (getBitFlag(93) || getBitFlag(94)) { - OK = 0; - if(j > z) - break; - } - - if (getBitFlag(93)) { - if (((_newLines + 1) >= _textWindow->scrollY) && ((_newLines + 1) < (_textWindow->scrollY + 3))) - OK = 1; - } - - if (getBitFlag(94)) { - if ((_newLines + 1) == (_textWindow->scrollY + 7)) - OK = 1; - } - - - if (OK == 1) { - if (j == maxFiles + 1) { - showMessageFormat("\n"); - hyperLinkOn(j + 400); - setTextColor(116); - showMessageFormat(" %d. ",1); - hyperLinkOff(); - setTextColor(113); - k++; - j--; - } - - if (!(in = _saveFileMan->openForLoading(gen_savename(j)))) - break; - in->read(b, 100); - delete in; - } - - showMessageFormat("\n"); - hyperLinkOn(j + 400); - setTextColor(116); - if (k < 10) - showMessageFormat(" "); - showMessageFormat("%d. ",k); - setTextColor(113); - showMessageFormat("%s ",b); - hyperLinkOff(); - j--; - k++; - } -} - void SimonEngine::scrollOracleUp() { byte *src, *dst; uint16 w, h; @@ -360,4 +293,157 @@ void SimonEngine::swapCharacterLogo() { } } +void SimonEngine::listSaveGames(int n) { + char b[108]; + Common::InSaveFile *in; + uint16 j, k, z, maxFiles; + int OK; + memset(b, 0, 108); + + maxFiles = countSaveGames() - 1; + j = maxFiles - n + 1; + k = maxFiles - j + 1; + z = maxFiles; + if (getBitFlag(95)) { + j++; + z++; + } + + while(1) { + OK=1; + if (getBitFlag(93) || getBitFlag(94)) { + OK = 0; + if(j > z) + break; + } + + if (getBitFlag(93)) { + if (((_newLines + 1) >= _textWindow->scrollY) && ((_newLines + 1) < (_textWindow->scrollY + 3))) + OK = 1; + } + + if (getBitFlag(94)) { + if ((_newLines + 1) == (_textWindow->scrollY + 7)) + OK = 1; + } + + + if (OK == 1) { + if (j == maxFiles + 1) { + showMessageFormat("\n"); + hyperLinkOn(j + 400); + setTextColor(116); + showMessageFormat(" %d. ",1); + hyperLinkOff(); + setTextColor(113); + k++; + j--; + } + + if (!(in = _saveFileMan->openForLoading(gen_savename(j)))) + break; + in->read(b, 100); + delete in; + } + + showMessageFormat("\n"); + hyperLinkOn(j + 400); + setTextColor(116); + if (k < 10) + showMessageFormat(" "); + showMessageFormat("%d. ",k); + setTextColor(113); + showMessageFormat("%s ",b); + hyperLinkOff(); + j--; + k++; + } +} + +void SimonEngine::saveUserGame(int slot) { + WindowBlock *window; + Common::InSaveFile *in; + char name[108]; + int len; + memset(name, 0, 108); + + window = _windowArray[3]; + + window->textRow = (slot + 1 - window->scrollY) * 15; + window->textColumn = 26; + + if ((in = _saveFileMan->openForLoading(gen_savename(readVariable(55))))) { + in->read(name, 100); + delete in; + } + + len = 0; + while (name[len]) { + byte chr = name[len - 32]; + window->textColumn += getFeebleFontSize(chr); + len++; + } + + windowPutChar(window, 0x7f); + for (;;) { + _keyPressed = 0; + delay(1); + + if (_keyPressed == 0 || _keyPressed >= 127) + continue; + + window->textColumn -= getFeebleFontSize(127); + name[len] = 0; + windowBackSpace(_windowArray[3]); + + if (_keyPressed == 27) { + writeVariable(55, _keyPressed); + break; + } + + if (_keyPressed == 10 || _keyPressed == 13) { + if (!saveGame(readVariable(55), name)) + writeVariable(55, 0xFFFF); + else + writeVariable(55, 0); + break; + } + if (_keyPressed == 8 && len != 0) { + len--; + byte chr = name[len]; + window->textColumn -= getFeebleFontSize(chr); + name[len] = 0; + windowBackSpace(_windowArray[3]); + windowPutChar(window, 0x7f); + } + if (_keyPressed >= 32 && window->textColumn + 26 <= window->width) { + name[len++] = _keyPressed; + windowPutChar(_windowArray[3], _keyPressed); + windowPutChar(window, 0x7f); + } + } +} + +void SimonEngine::windowBackSpace(WindowBlock *window) { + byte *dst; + uint x, y, h, w; + + _lockWord |= 0x8000; + + x = window->x + window->textColumn; + y = window->y + window->textRow; + + dst = getFrontBuf() + _dxSurfacePitch * y + x; + + for (h = 0; h < 13; h++) { + for (w = 0; w < 8; w++) { + if (dst[w] == 113 || dst[w] == 116 || dst[w] == 252) + dst[w] = 0; + } + dst += _screenWidth; + } + + _lockWord &= ~0x8000; +} + } // End of namespace Simon diff --git a/engines/simon/saveload.cpp b/engines/simon/saveload.cpp index 6ac7c6899c..bdd161bf6c 100644 --- a/engines/simon/saveload.cpp +++ b/engines/simon/saveload.cpp @@ -263,7 +263,7 @@ restart:; // do_3_start for (;;) { - videoPutchar(window, 0x7f); + windowPutChar(window, 0x7f); _saveLoadFlag = true; @@ -314,7 +314,7 @@ restart:; } else if (i >= 32 && name_len != 17) { name[name_len++] = i; - videoPutchar(_windowArray[5], i); + windowPutChar(_windowArray[5], i); } } @@ -410,7 +410,7 @@ void SimonEngine::unk_132_helper_3() { void SimonEngine::clearCharacter(WindowBlock *window, int x, byte b) { byte old_text; - videoPutchar(window, x, b); + windowPutChar(window, x, b); old_text = window->text_color; window->text_color = window->fill_color; @@ -423,10 +423,10 @@ void SimonEngine::clearCharacter(WindowBlock *window, int x, byte b) { } - videoPutchar(window, x); + windowPutChar(window, x); window->text_color = old_text; - videoPutchar(window, 8); + windowPutChar(window, 8); } void SimonEngine::fileError(WindowBlock *window, bool save_error) { @@ -441,11 +441,11 @@ void SimonEngine::fileError(WindowBlock *window, bool save_error) { string2 = "\r File not found."; } - videoPutchar(window, 0xC); + windowPutChar(window, 0xC); for (; *string; string++) - videoPutchar(window, *string); + windowPutChar(window, *string); for (; *string2; string2++) - videoPutchar(window, *string2); + windowPutChar(window, *string2); window->textColumn = (window->width / 2) - 3; window->textRow = window->height - 1; @@ -453,7 +453,7 @@ void SimonEngine::fileError(WindowBlock *window, bool save_error) { string = "[ OK ]"; for (; *string; string++) - videoPutchar(window, *string); + windowPutChar(window, *string); ha = findEmptyHitArea(); ha->x = ((window->width >> 1) + (window->x - 3)) * 8; diff --git a/engines/simon/simon.cpp b/engines/simon/simon.cpp index 4327adb713..76af76b783 100644 --- a/engines/simon/simon.cpp +++ b/engines/simon/simon.cpp @@ -2886,7 +2886,7 @@ void SimonEngine::delete_hitarea_by_index(uint index) { void SimonEngine::windowPutChar(uint a) { if (_textWindow != _windowArray[0]) - videoPutchar(_textWindow, a); + windowPutChar(_textWindow, a); } void SimonEngine::clearWindow(WindowBlock *window) { diff --git a/engines/simon/simon.h b/engines/simon/simon.h index 81cc400a63..e2795a99ec 100644 --- a/engines/simon/simon.h +++ b/engines/simon/simon.h @@ -592,9 +592,11 @@ protected: void hyperLinkOff(); void linksUp(); void linksDown(); - void listSaveGames(int n); void oracleTextUp(); void oracleTextDown(); + void listSaveGames(int n); + void saveUserGame(int slot); + void windowBackSpace(WindowBlock *window); void bltOracleText(); void oracleLogo(); @@ -636,7 +638,7 @@ protected: HitArea *findHitAreaByID(uint hitarea_id); void showActionString(const byte *string); - void videoPutchar(WindowBlock *window, byte c, byte b = 0); + void windowPutChar(WindowBlock *window, byte c, byte b = 0); void clearWindow(WindowBlock *window); void video_toggle_colors(HitArea * ha, byte a, byte b, byte c, byte d); @@ -671,6 +673,8 @@ protected: void hitarea_stuff_helper(); void permitInput(); + + uint getFeebleFontSize(byte chr); void showmessage_helper_3(uint a, uint b); void showmessage_print_char(byte chr); @@ -958,6 +962,7 @@ public: void o3_ifTime(); void o3_playTune(); void o3_setTime(); + void o3_saveUserGame(); void o3_loadUserGame(); void o3_listSaveGames(); void o3_checkCD(); diff --git a/engines/simon/verb.cpp b/engines/simon/verb.cpp index 6c389480a6..b3e77bc6b6 100644 --- a/engines/simon/verb.cpp +++ b/engines/simon/verb.cpp @@ -301,7 +301,7 @@ void SimonEngine::showActionString(const byte *string) { window->textColumnOffset = x & 7; for (; *string; string++) - videoPutchar(window, *string); + windowPutChar(window, *string); } void SimonEngine::resetNameWindow() { -- cgit v1.2.3