CHEWY: Remove the IOGame class and simplify the save game slot code

This commit is contained in:
Filippos Karapetis 2022-03-26 00:47:07 +02:00
parent c75fab7142
commit ba353bc58c
9 changed files with 24 additions and 118 deletions

View File

@ -49,12 +49,12 @@ static const Common::Rect fileHotspots[] = {
};
int16 Files::execute(bool isInGame) {
bool Files::execute(bool isInGame) {
int16 key = 0;
Common::Point pt[8];
int16 mode[9];
bool visibility[8];
int16 ret = 0;
bool ret = false;
bool flag = false;
if (!ConfMan.getBool("original_menus")) {
@ -70,7 +70,6 @@ int16 Files::execute(bool isInGame) {
_G(out)->map_spr2screen(_G(ablage)[_G(room_blk).AkAblage], 0, 0);
_G(out)->setPointer(_G(screen0));
_G(room)->set_ak_pal(&_G(room_blk));
Common::StringArray &fnames = _G(iog)->io_init();
_G(fx)->blende1(_G(workptr), _G(screen0), _G(pal), 150, 0, 0);
_G(out)->setPointer(_G(workptr));
@ -93,6 +92,7 @@ int16 Files::execute(bool isInGame) {
int16 text_off = 0; // Top visible save slot
int16 active_slot = 0; // Currently selected slot
SaveStateList saveList = g_engine->listSaves();
while (key != Common::KEYCODE_ESCAPE && !SHOULD_QUIT) {
// Draw the dialog background
@ -113,16 +113,24 @@ int16 Files::execute(bool isInGame) {
}
}
// Write the list of savegame slots
// Write the list of savegame slots
for (int16 i = 0; i < NUM_VISIBLE_SLOTS; i++) {
if (i + text_off >= saveList.size())
break;
// TODO: This implementation disallows gaps in the save list
if (saveList[i + text_off].getSaveSlot() != i + text_off)
continue;
Common::String slot = Common::String::format("%2d.", text_off + i);
Common::String saveName = saveList[i + text_off].getDescription();
if (i != active_slot) {
_G(out)->printxy(40, 68 + (i * 10), 14, 300, 0, slot.c_str());
_G(out)->printxy(70, 68 + (i * 10), 14, 300, 0, fnames[i + text_off].c_str());
_G(out)->printxy(70, 68 + (i * 10), 14, 300, 0, saveName.c_str());
} else {
_G(out)->boxFill(40, 68 + (i * 10), 308, 68 + 8 + (i * 10), 42);
_G(out)->printxy(40, 68 + (i * 10), 255, 300, 0, slot.c_str());
_G(out)->printxy(70, 68 + (i * 10), 255, 300, 0, fnames[i + text_off].c_str());
_G(out)->printxy(70, 68 + (i * 10), 255, 300, 0, saveName.c_str());
}
}
@ -146,7 +154,7 @@ int16 Files::execute(bool isInGame) {
key = getch();
if (key == 'j' || key == 'J' || key == 'y' || key == 'Y' || key == 'z' || key == 'Z') {
ret = 1;
ret = true;
key = Common::KEYCODE_ESCAPE;
} else {
key = 0;
@ -259,7 +267,6 @@ int16 Files::execute(bool isInGame) {
enter:
if (mode[LOAD]) {
const int16 slotNum = text_off + active_slot;
SaveStateList saveList = g_engine->listSaves();
for (uint j = 0; j < saveList.size(); ++j) {
if (saveList[j].getSaveSlot() == slotNum) {
_G(currentSong) = -1;
@ -272,15 +279,15 @@ enter:
} else if (mode[SAVE]) {
_G(out)->back2screen(_G(workpage));
_G(out)->setPointer(_G(screen0));
char tmp[81];
tmp[0] = '\0';
char slotName[81];
slotName[0] = '\0';
key = _G(out)->scanxy(70, 68 + (active_slot * 10),
255, 42, 14, 0, "%36s36", tmp);
fnames[text_off + active_slot] = tmp;
255, 42, 14, 0, "%36s36", slotName);
_G(out)->setPointer(_G(workptr));
if (key != Common::KEYCODE_ESCAPE) {
_G(iog)->save_entry(text_off + active_slot);
g_engine->saveGameState(text_off + active_slot, slotName);
saveList = g_engine->listSaves();
}
key = Common::KEYCODE_ESCAPE;
}

View File

@ -33,9 +33,9 @@ public:
* Shows the file dialog
* @param isInGame True when called in-game,
* false when called from the main menu
* @returns Returns 1 if quit was selected
* @returns Returns true if quit was selected
*/
static int16 execute(bool isInGame);
static bool execute(bool isInGame);
};
} // namespace Dialogs

View File

@ -46,7 +46,6 @@ class ChewyFont;
class Cursor;
class FontMgr;
class InputMgr;
class IOGame;
class McgaGraphics;
class Memory;
@ -239,7 +238,6 @@ public:
int16 _TmpFrameSpeed = 0;
InputMgr *_in = nullptr;
Memory *_mem = nullptr;
IOGame *_iog = nullptr;
McgaGraphics *_out = nullptr;
Cursor *_cur = nullptr;
ChewyFont *_font6 = nullptr;

View File

@ -61,7 +61,6 @@ void standard_init() {
_G(cur) = new Cursor(&_G(curblk));
_G(cur)->set_cur_ani(&_G(curani));
_G(iog) = new IOGame();
alloc_buffers();
_G(pal)[765] = 63;
_G(pal)[766] = 63;
@ -252,7 +251,6 @@ void tidy() {
free_buffers();
_G(obj)->free_inv_spr(&_G(inv_spr)[0]);
delete _G(iog);
delete _G(cur);
delete _G(mov);
delete _G(atds);
@ -267,7 +265,6 @@ void tidy() {
delete _G(out);
delete _G(mem);
_G(iog) = nullptr;
_G(cur) = nullptr;
_G(mov) = nullptr;
_G(atds) = nullptr;

View File

@ -1,54 +0,0 @@
/* ScummVM - Graphic Adventure Engine
*
* ScummVM is the legal property of its developers, whose names
* are too numerous to list here. Please refer to the COPYRIGHT
* file distributed with this source distribution.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/
#include "chewy/chewy.h"
#include "chewy/events.h"
#include "chewy/globals.h"
#include "chewy/io_game.h"
namespace Chewy {
Common::StringArray &IOGame::io_init() {
SaveStateList saveList = g_engine->listSaves();
_fileFind.resize(1000);
for (uint i = 0; i < saveList.size(); i++) {
_fileFind[i] = "";
for (uint j = 0; j < saveList.size(); ++j) {
if (saveList[j].getSaveSlot() == (int)i) {
Common::String name = saveList[j].getDescription();
_fileFind[i] = name;
break;
}
}
}
return _fileFind;
}
void IOGame::save_entry(int16 slotNum) {
Common::String desc = _fileFind[slotNum];
g_engine->saveGameState(slotNum, desc);
}
} // namespace Chewy

View File

@ -1,40 +0,0 @@
/* ScummVM - Graphic Adventure Engine
*
* ScummVM is the legal property of its developers, whose names
* are too numerous to list here. Please refer to the COPYRIGHT
* file distributed with this source distribution.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/
#ifndef CHEWY_IO_GAME_H
#define CHEWY_IO_GAME_H
namespace Chewy {
#define IOG_END 1
#define USER_NAME 36
class IOGame {
Common::StringArray _fileFind;
public:
Common::StringArray &io_init();
void save_entry(int16 nr);
};
} // namespace Chewy
#endif

View File

@ -377,8 +377,8 @@ bool mainLoop(int16 mode) {
_G(out)->setPointer(_G(screen0));
cursorChoice(CUR_SAVE);
int16 ret = Dialogs::Files::execute(true);
if (ret == IOG_END) {
bool ret = Dialogs::Files::execute(true);
if (ret) {
retValue = true;
_G(fx_blend) = BLEND4;
}

View File

@ -12,7 +12,6 @@ MODULE_OBJS = \
gedclass.o \
globals.o \
inits.o \
io_game.o \
m_event.o \
main.o \
mouse.o \

View File

@ -25,7 +25,6 @@
#include "chewy/memory.h"
#include "chewy/mcga.h"
#include "chewy/mouse.h"
#include "chewy/io_game.h"
#include "chewy/cursor.h"
#endif