Review lsgLoadGame

* Add missing cleanup
* Fixes double click handling
* Rename variables
This commit is contained in:
Alexander Batalov 2022-10-07 11:28:42 +03:00
parent 266c727870
commit a52fd4e70a
1 changed files with 306 additions and 323 deletions

View File

@ -98,6 +98,12 @@ typedef enum LoadSaveSlotState {
SLOT_STATE_UNSUPPORTED_VERSION, SLOT_STATE_UNSUPPORTED_VERSION,
} LoadSaveSlotState; } LoadSaveSlotState;
typedef enum LoadSaveScrollDirection {
LOAD_SAVE_SCROLL_DIRECTION_NONE,
LOAD_SAVE_SCROLL_DIRECTION_UP,
LOAD_SAVE_SCROLL_DIRECTION_DOWN,
} LoadSaveScrollDirection;
typedef int LoadGameHandler(File* stream); typedef int LoadGameHandler(File* stream);
typedef int SaveGameHandler(File* stream); typedef int SaveGameHandler(File* stream);
@ -742,7 +748,6 @@ static int _QuickSnapShot()
int lsgLoadGame(int mode) int lsgLoadGame(int mode)
{ {
MessageListItem messageListItem; MessageListItem messageListItem;
const char* messageListItemText;
const char* body[] = { const char* body[] = {
_str1, _str1,
@ -791,23 +796,17 @@ int lsgLoadGame(int mode)
gameMouseSetCursor(MOUSE_CURSOR_ARROW); gameMouseSetCursor(MOUSE_CURSOR_ARROW);
soundPlayFile("iisxxxx1"); soundPlayFile("iisxxxx1");
strcpy(_str0, getmsg(&gLoadSaveMessageList, &messageListItem, 134));
messageListItemText = getmsg(&gLoadSaveMessageList, &messageListItem, 134); strcpy(_str1, getmsg(&gLoadSaveMessageList, &messageListItem, 135));
strcpy(_str0, messageListItemText);
messageListItemText = getmsg(&gLoadSaveMessageList, &messageListItem, 135);
strcpy(_str1, messageListItemText);
showDialogBox(_str0, body, 1, 169, 116, _colorTable[32328], 0, _colorTable[32328], DIALOG_BOX_LARGE); showDialogBox(_str0, body, 1, 169, 116, _colorTable[32328], 0, _colorTable[32328], DIALOG_BOX_LARGE);
messageListFree(&gLoadSaveMessageList); messageListFree(&gLoadSaveMessageList);
mapNewMap(); mapNewMap();
_game_user_wants_to_quit = 2; _game_user_wants_to_quit = 2;
return -1; return -1;
} else { }
_quick_done = false; _quick_done = false;
int windowType; int windowType;
@ -834,31 +833,34 @@ int lsgLoadGame(int mode)
gameMouseSetCursor(MOUSE_CURSOR_ARROW); gameMouseSetCursor(MOUSE_CURSOR_ARROW);
windowRefresh(gLoadSaveWindow); windowRefresh(gLoadSaveWindow);
soundPlayFile("iisxxxx1"); soundPlayFile("iisxxxx1");
strcpy(_str0, getmsg(&gLoadSaveMessageList, &gLoadSaveMessageListItem, 106));
const char* text1 = getmsg(&gLoadSaveMessageList, &gLoadSaveMessageListItem, 106); strcpy(_str1, getmsg(&gLoadSaveMessageList, &gLoadSaveMessageListItem, 107));
strcpy(_str0, text1);
const char* text2 = getmsg(&gLoadSaveMessageList, &gLoadSaveMessageListItem, 107);
strcpy(_str1, text1);
sprintf(_str2, "\"%s\\\"", "SAVEGAME"); sprintf(_str2, "\"%s\\\"", "SAVEGAME");
showDialogBox(_str0, body, 2, 169, 116, _colorTable[32328], 0, _colorTable[32328], DIALOG_BOX_LARGE); showDialogBox(_str0, body, 2, 169, 116, _colorTable[32328], 0, _colorTable[32328], DIALOG_BOX_LARGE);
lsgWindowFree(windowType);
return -1; return -1;
} }
int v36 = _LSstatus[_slot_cursor]; switch (_LSstatus[_slot_cursor]) {
if (v36 != 0 && v36 != 2 && v36 != 3) { case SLOT_STATE_EMPTY:
_LoadTumbSlot(_slot_cursor); case SLOT_STATE_ERROR:
blitBufferToBuffer(_thumbnail_image, 223, 132, LS_PREVIEW_WIDTH, gLoadSaveWindowBuffer + LS_WINDOW_WIDTH * 58 + 366, LS_WINDOW_WIDTH); case SLOT_STATE_UNSUPPORTED_VERSION:
} else {
blitBufferToBuffer(_loadsaveFrmImages[LOAD_SAVE_FRM_PREVIEW_COVER].getData(), blitBufferToBuffer(_loadsaveFrmImages[LOAD_SAVE_FRM_PREVIEW_COVER].getData(),
_loadsaveFrmImages[LOAD_SAVE_FRM_PREVIEW_COVER].getWidth(), _loadsaveFrmImages[LOAD_SAVE_FRM_PREVIEW_COVER].getWidth(),
_loadsaveFrmImages[LOAD_SAVE_FRM_PREVIEW_COVER].getHeight(), _loadsaveFrmImages[LOAD_SAVE_FRM_PREVIEW_COVER].getHeight(),
_loadsaveFrmImages[LOAD_SAVE_FRM_PREVIEW_COVER].getWidth(), _loadsaveFrmImages[LOAD_SAVE_FRM_PREVIEW_COVER].getWidth(),
gLoadSaveWindowBuffer + LS_WINDOW_WIDTH * 39 + 340, gLoadSaveWindowBuffer + LS_WINDOW_WIDTH * 39 + 340,
LS_WINDOW_WIDTH); LS_WINDOW_WIDTH);
break;
default:
_LoadTumbSlot(_slot_cursor);
blitBufferToBuffer(_thumbnail_image,
LS_PREVIEW_WIDTH - 1,
LS_PREVIEW_HEIGHT - 1,
LS_PREVIEW_WIDTH,
gLoadSaveWindowBuffer + LS_WINDOW_WIDTH * 58 + 366,
LS_WINDOW_WIDTH);
break;
} }
_ShowSlotList(2); _ShowSlotList(2);
@ -867,13 +869,12 @@ int lsgLoadGame(int mode)
_dbleclkcntr = 24; _dbleclkcntr = 24;
int rc = -1; int rc = -1;
int doubleClickSlot = -1;
while (rc == -1) { while (rc == -1) {
while (rc == -1) { unsigned int time = getTicks();
int v37 = getTicks();
int keyCode = inputGetInput(); int keyCode = inputGetInput();
int v39 = 0; bool selectionChanged = false;
int v107 = 0; int scrollDirection = LOAD_SAVE_SCROLL_DIRECTION_NONE;
int v108 = -1;
convertMouseWheelToArrowKey(&keyCode); convertMouseWheelToArrowKey(&keyCode);
@ -882,56 +883,60 @@ int lsgLoadGame(int mode)
} else { } else {
switch (keyCode) { switch (keyCode) {
case KEY_ARROW_UP: case KEY_ARROW_UP:
if (--_slot_cursor < 0) { _slot_cursor--;
if (_slot_cursor < 0) {
_slot_cursor = 0; _slot_cursor = 0;
} }
v39 = 1; selectionChanged = true;
v108 = -1; doubleClickSlot = -1;
break; break;
case KEY_ARROW_DOWN: case KEY_ARROW_DOWN:
if (++_slot_cursor > 9) { _slot_cursor++;
if (_slot_cursor > 9) {
_slot_cursor = 9; _slot_cursor = 9;
} }
v39 = 1; selectionChanged = true;
v108 = -1; doubleClickSlot = -1;
break; break;
case KEY_HOME: case KEY_HOME:
_slot_cursor = 0; _slot_cursor = 0;
v108 = -1; selectionChanged = true;
v39 = 1; doubleClickSlot = -1;
break; break;
case KEY_END: case KEY_END:
v39 = 1;
v108 = -1;
_slot_cursor = 9; _slot_cursor = 9;
selectionChanged = true;
doubleClickSlot = -1;
break; break;
case 506: case 506:
v107 = 1; scrollDirection = LOAD_SAVE_SCROLL_DIRECTION_UP;
break; break;
case 504: case 504:
v107 = 2; scrollDirection = LOAD_SAVE_SCROLL_DIRECTION_DOWN;
break; break;
case 502: case 502:
do { if (1) {
int mouseX; int mouseX;
int mouseY; int mouseY;
mouseGetPositionInWindow(gLoadSaveWindow, &mouseX, &mouseY); mouseGetPositionInWindow(gLoadSaveWindow, &mouseX, &mouseY);
int v41 = (mouseY - 79) / (3 * fontGetLineHeight() + 4);
if (v41 < 0) { int clickedSlot = (mouseY - 79) / (3 * fontGetLineHeight() + 4);
v41 = 0; if (clickedSlot < 0) {
} else if (v41 > 9) { clickedSlot = 0;
v41 = 9; } else if (clickedSlot > 9) {
clickedSlot = 9;
} }
_slot_cursor = v41; _slot_cursor = clickedSlot;
if (v41 == v108) { if (clickedSlot == doubleClickSlot) {
keyCode = 500;
soundPlayFile("ib1p1xx1"); soundPlayFile("ib1p1xx1");
} }
v39 = 1; selectionChanged = true;
v107 = 0; scrollDirection = LOAD_SAVE_SCROLL_DIRECTION_NONE;
v108 = _slot_cursor; doubleClickSlot = _slot_cursor;
} while (0); }
break; break;
case KEY_MINUS: case KEY_MINUS:
case KEY_UNDERSCORE: case KEY_UNDERSCORE:
@ -956,35 +961,35 @@ int lsgLoadGame(int mode)
} }
if (keyCode == 500) { if (keyCode == 500) {
if (_LSstatus[_slot_cursor]) { if (_LSstatus[_slot_cursor] != SLOT_STATE_EMPTY) {
rc = 1; rc = 1;
} else { } else {
rc = -1; rc = -1;
} }
v39 = 1; selectionChanged = true;
v107 = 0; scrollDirection = LOAD_SAVE_SCROLL_DIRECTION_NONE;
} }
if (v107) { if (scrollDirection != LOAD_SAVE_SCROLL_DIRECTION_NONE) {
unsigned int v42 = 4; unsigned int scrollVelocity = 4;
int v106 = 0; bool isScrolling = false;
int v109 = 0; int scrollCounter = 0;
do { do {
int v45 = getTicks(); unsigned int start = getTicks();
int v44 = v109 + 1; scrollCounter += 1;
if ((v106 == 0 && v44 == 1) || (v106 == 1 && v109 > 14.4)) { if ((!isScrolling && scrollCounter == 1) || (isScrolling && scrollCounter > 14.4)) {
v106 = 1; isScrolling = true;
if (v109 > 14.4) { if (scrollCounter > 14.4) {
v42 += 1; scrollVelocity += 1;
if (v42 > 24) { if (scrollVelocity > 24) {
v42 = 24; scrollVelocity = 24;
} }
} }
if (v107 == 1) { if (scrollDirection == LOAD_SAVE_SCROLL_DIRECTION_UP) {
_slot_cursor -= 1; _slot_cursor -= 1;
if (_slot_cursor < 0) { if (_slot_cursor < 0) {
_slot_cursor = 0; _slot_cursor = 0;
@ -996,30 +1001,32 @@ int lsgLoadGame(int mode)
} }
} }
int v46 = _LSstatus[_slot_cursor]; switch (_LSstatus[_slot_cursor]) {
if (v46 != 0 && v46 != 2 && v46 != 3) { case SLOT_STATE_EMPTY:
_LoadTumbSlot(_slot_cursor); case SLOT_STATE_ERROR:
case SLOT_STATE_UNSUPPORTED_VERSION:
blitBufferToBuffer(_loadsaveFrmImages[LOAD_SAVE_FRM_BACKGROUND].getData() + LS_WINDOW_WIDTH * 39 + 340,
_loadsaveFrmImages[LOAD_SAVE_FRM_PREVIEW_COVER].getWidth(),
_loadsaveFrmImages[LOAD_SAVE_FRM_PREVIEW_COVER].getHeight(),
LS_WINDOW_WIDTH,
gLoadSaveWindowBuffer + LS_WINDOW_WIDTH * 39 + 340,
LS_WINDOW_WIDTH);
blitBufferToBuffer(_thumbnail_image,
223,
132,
LS_PREVIEW_WIDTH,
gLoadSaveWindowBuffer + LS_WINDOW_WIDTH * 58 + 366,
LS_WINDOW_WIDTH);
} else {
blitBufferToBuffer(_loadsaveFrmImages[LOAD_SAVE_FRM_PREVIEW_COVER].getData(), blitBufferToBuffer(_loadsaveFrmImages[LOAD_SAVE_FRM_PREVIEW_COVER].getData(),
_loadsaveFrmImages[LOAD_SAVE_FRM_PREVIEW_COVER].getWidth(), _loadsaveFrmImages[LOAD_SAVE_FRM_PREVIEW_COVER].getWidth(),
_loadsaveFrmImages[LOAD_SAVE_FRM_PREVIEW_COVER].getHeight(), _loadsaveFrmImages[LOAD_SAVE_FRM_PREVIEW_COVER].getHeight(),
_loadsaveFrmImages[LOAD_SAVE_FRM_PREVIEW_COVER].getWidth(), _loadsaveFrmImages[LOAD_SAVE_FRM_PREVIEW_COVER].getWidth(),
gLoadSaveWindowBuffer + LS_WINDOW_WIDTH * 39 + 340, gLoadSaveWindowBuffer + LS_WINDOW_WIDTH * 39 + 340,
LS_WINDOW_WIDTH); LS_WINDOW_WIDTH);
break;
default:
_LoadTumbSlot(_slot_cursor);
blitBufferToBuffer(_loadsaveFrmImages[LOAD_SAVE_FRM_BACKGROUND].getData() + LS_WINDOW_WIDTH * 39 + 340,
_loadsaveFrmImages[LOAD_SAVE_FRM_PREVIEW_COVER].getWidth(),
_loadsaveFrmImages[LOAD_SAVE_FRM_PREVIEW_COVER].getHeight(),
LS_WINDOW_WIDTH,
gLoadSaveWindowBuffer + LS_WINDOW_WIDTH * 39 + 340,
LS_WINDOW_WIDTH);
blitBufferToBuffer(_thumbnail_image,
LS_PREVIEW_WIDTH - 1,
LS_PREVIEW_HEIGHT - 1,
LS_PREVIEW_WIDTH,
gLoadSaveWindowBuffer + LS_WINDOW_WIDTH * 58 + 366,
LS_WINDOW_WIDTH);
break;
} }
_ShowSlotList(2); _ShowSlotList(2);
@ -1027,41 +1034,44 @@ int lsgLoadGame(int mode)
windowRefresh(gLoadSaveWindow); windowRefresh(gLoadSaveWindow);
} }
if (v109 > 14.4) { if (scrollCounter > 14.4) {
while (getTicksSince(v45) < 1000 / v42) { } while (getTicksSince(start) < 1000 / scrollVelocity) { }
} else { } else {
while (getTicksSince(v45) < 1000 / 24) { } while (getTicksSince(start) < 1000 / 24) { }
} }
keyCode = inputGetInput(); keyCode = inputGetInput();
} while (keyCode != 505 && keyCode != 503); } while (keyCode != 505 && keyCode != 503);
} else { } else {
if (v39 != 0) { if (selectionChanged) {
int v48 = _LSstatus[_slot_cursor]; switch (_LSstatus[_slot_cursor]) {
if (v48 != 0 && v48 != 2 && v48 != 3) { case SLOT_STATE_EMPTY:
_LoadTumbSlot(_slot_cursor); case SLOT_STATE_ERROR:
case SLOT_STATE_UNSUPPORTED_VERSION:
blitBufferToBuffer(_loadsaveFrmImages[LOAD_SAVE_FRM_BACKGROUND].getData() + LS_WINDOW_WIDTH * 39 + 340,
_loadsaveFrmImages[LOAD_SAVE_FRM_PREVIEW_COVER].getWidth(),
_loadsaveFrmImages[LOAD_SAVE_FRM_PREVIEW_COVER].getHeight(),
LS_WINDOW_WIDTH,
gLoadSaveWindowBuffer + LS_WINDOW_WIDTH * 39 + 340,
LS_WINDOW_WIDTH);
blitBufferToBuffer(_thumbnail_image,
223,
132,
LS_PREVIEW_WIDTH,
gLoadSaveWindowBuffer + LS_WINDOW_WIDTH * 58 + 366,
LS_WINDOW_WIDTH);
} else {
blitBufferToBuffer(_loadsaveFrmImages[LOAD_SAVE_FRM_PREVIEW_COVER].getData(), blitBufferToBuffer(_loadsaveFrmImages[LOAD_SAVE_FRM_PREVIEW_COVER].getData(),
_loadsaveFrmImages[LOAD_SAVE_FRM_PREVIEW_COVER].getWidth(), _loadsaveFrmImages[LOAD_SAVE_FRM_PREVIEW_COVER].getWidth(),
_loadsaveFrmImages[LOAD_SAVE_FRM_PREVIEW_COVER].getHeight(), _loadsaveFrmImages[LOAD_SAVE_FRM_PREVIEW_COVER].getHeight(),
_loadsaveFrmImages[LOAD_SAVE_FRM_PREVIEW_COVER].getWidth(), _loadsaveFrmImages[LOAD_SAVE_FRM_PREVIEW_COVER].getWidth(),
gLoadSaveWindowBuffer + LS_WINDOW_WIDTH * 39 + 340, gLoadSaveWindowBuffer + LS_WINDOW_WIDTH * 39 + 340,
LS_WINDOW_WIDTH); LS_WINDOW_WIDTH);
break;
default:
_LoadTumbSlot(_slot_cursor);
blitBufferToBuffer(_loadsaveFrmImages[LOAD_SAVE_FRM_BACKGROUND].getData() + LS_WINDOW_WIDTH * 39 + 340,
_loadsaveFrmImages[LOAD_SAVE_FRM_PREVIEW_COVER].getWidth(),
_loadsaveFrmImages[LOAD_SAVE_FRM_PREVIEW_COVER].getHeight(),
LS_WINDOW_WIDTH,
gLoadSaveWindowBuffer + LS_WINDOW_WIDTH * 39 + 340,
LS_WINDOW_WIDTH);
blitBufferToBuffer(_thumbnail_image,
LS_PREVIEW_WIDTH - 1,
LS_PREVIEW_HEIGHT - 1,
LS_PREVIEW_WIDTH,
gLoadSaveWindowBuffer + LS_WINDOW_WIDTH * 58 + 366,
LS_WINDOW_WIDTH);
break;
} }
_DrawInfoBox(_slot_cursor); _DrawInfoBox(_slot_cursor);
_ShowSlotList(2); _ShowSlotList(2);
} }
@ -1071,67 +1081,41 @@ int lsgLoadGame(int mode)
_dbleclkcntr -= 1; _dbleclkcntr -= 1;
if (_dbleclkcntr == 0) { if (_dbleclkcntr == 0) {
_dbleclkcntr = 24; _dbleclkcntr = 24;
v108 = -1; doubleClickSlot = -1;
} }
while (getTicksSince(v37) < 1000 / 24) { } while (getTicksSince(time) < 1000 / 24) { }
}
} }
if (rc == 1) { if (rc == 1) {
int v50 = _LSstatus[_slot_cursor]; switch (_LSstatus[_slot_cursor]) {
if (v50 == 3) { case SLOT_STATE_UNSUPPORTED_VERSION:
const char* text;
soundPlayFile("iisxxxx1"); soundPlayFile("iisxxxx1");
strcpy(_str0, getmsg(&gLoadSaveMessageList, &gLoadSaveMessageListItem, 134));
text = getmsg(&gLoadSaveMessageList, &gLoadSaveMessageListItem, 134); strcpy(_str1, getmsg(&gLoadSaveMessageList, &gLoadSaveMessageListItem, 136));
strcpy(_str0, text); strcpy(_str2, getmsg(&gLoadSaveMessageList, &gLoadSaveMessageListItem, 135));
text = getmsg(&gLoadSaveMessageList, &gLoadSaveMessageListItem, 136);
strcpy(_str1, text);
text = getmsg(&gLoadSaveMessageList, &gLoadSaveMessageListItem, 135);
strcpy(_str2, text);
showDialogBox(_str0, body, 2, 169, 116, _colorTable[32328], 0, _colorTable[32328], DIALOG_BOX_LARGE); showDialogBox(_str0, body, 2, 169, 116, _colorTable[32328], 0, _colorTable[32328], DIALOG_BOX_LARGE);
rc = -1; rc = -1;
} else if (v50 == 2) { break;
const char* text; case SLOT_STATE_ERROR:
soundPlayFile("iisxxxx1"); soundPlayFile("iisxxxx1");
strcpy(_str0, getmsg(&gLoadSaveMessageList, &gLoadSaveMessageListItem, 134));
text = getmsg(&gLoadSaveMessageList, &gLoadSaveMessageListItem, 134); strcpy(_str1, getmsg(&gLoadSaveMessageList, &gLoadSaveMessageListItem, 136));
strcpy(_str0, text);
text = getmsg(&gLoadSaveMessageList, &gLoadSaveMessageListItem, 136);
strcpy(_str1, text);
showDialogBox(_str0, body, 1, 169, 116, _colorTable[32328], 0, _colorTable[32328], DIALOG_BOX_LARGE); showDialogBox(_str0, body, 1, 169, 116, _colorTable[32328], 0, _colorTable[32328], DIALOG_BOX_LARGE);
rc = -1; rc = -1;
} else { break;
default:
if (lsgLoadGameInSlot(_slot_cursor) == -1) { if (lsgLoadGameInSlot(_slot_cursor) == -1) {
const char* text;
gameMouseSetCursor(MOUSE_CURSOR_ARROW); gameMouseSetCursor(MOUSE_CURSOR_ARROW);
soundPlayFile("iisxxxx1"); soundPlayFile("iisxxxx1");
strcpy(_str0, getmsg(&gLoadSaveMessageList, &gLoadSaveMessageListItem, 134));
text = getmsg(&gLoadSaveMessageList, &gLoadSaveMessageListItem, 134); strcpy(_str1, getmsg(&gLoadSaveMessageList, &gLoadSaveMessageListItem, 135));
strcpy(_str0, text);
text = getmsg(&gLoadSaveMessageList, &gLoadSaveMessageListItem, 135);
strcpy(_str1, text);
showDialogBox(_str0, body, 1, 169, 116, _colorTable[32328], 0, _colorTable[32328], DIALOG_BOX_LARGE); showDialogBox(_str0, body, 1, 169, 116, _colorTable[32328], 0, _colorTable[32328], DIALOG_BOX_LARGE);
mapNewMap(); mapNewMap();
_game_user_wants_to_quit = 2; _game_user_wants_to_quit = 2;
rc = -1; rc = -1;
} }
break;
} }
} }
} }
@ -1147,7 +1131,6 @@ int lsgLoadGame(int mode)
} }
return rc; return rc;
}
} }
// 0x47D2E4 // 0x47D2E4