static void FillSavegameDesc(bool save) { uint8 i; for (i = 0; i < 5; i++) { char *desc = g_savegameDesc[i]; char *filename; uint8 fileId; *desc = '\0'; if (s_savegameIndexBase - i < 0) continue; if (s_savegameIndexBase - i == s_savegameCountOnDisk) { if (!save) continue; strncpy(desc, String_Get_ByIndex(STR_EMPTY_SLOT_), 50); continue; } filename = GenerateSavegameFilename(s_savegameIndexBase - i); if (!File_Exists(filename)) continue; fileId = ChunkFile_Open(filename); ChunkFile_Read(fileId, HTOBE32(CC_NAME), desc, 50); ChunkFile_Close(fileId); continue; } }
static uint16 GetSavegameCount(void) { uint16 i; for (i = 0;; i++) { if (!File_Exists(GenerateSavegameFilename(i))) return i; } }
/** * Handles Click event for "Save Game" or "Load Game" button. * * @param save Wether to save or load. * @return True if a game has been saved or loaded, False otherwise. */ bool GUI_Widget_SaveLoad_Click(bool save) { WindowDesc *desc = &g_saveLoadWindowDesc; bool loop; s_savegameCountOnDisk = GetSavegameCount(); s_savegameIndexBase = max(0, s_savegameCountOnDisk - (save ? 0 : 1)); FillSavegameDesc(save); desc->stringID = save ? STR_SELECT_A_POSITION_TO_SAVE_TO : STR_SELECT_A_SAVED_GAME_TO_LOAD; GUI_Window_BackupScreen(desc); GUI_Window_Create(desc); UpdateArrows(save, true); for (loop = true; loop; sleepIdle()) { Widget *w = g_widgetLinkedListTail; uint16 key = GUI_Widget_HandleEvents(w); UpdateArrows(save, false); if ((key & 0x8000) != 0) { Widget *w2; key &= 0x7FFF; w2 = GUI_Widget_Get_ByIndex(w, key); switch (key) { case 0x25: s_savegameIndexBase = min(s_savegameCountOnDisk - (save ? 0 : 1), s_savegameIndexBase + 1); FillSavegameDesc(save); GUI_Widget_DrawAll(w); break; case 0x26: s_savegameIndexBase = max(0, s_savegameIndexBase - 1); FillSavegameDesc(save); GUI_Widget_DrawAll(w); break; case 0x23: loop = false; break; default: { GUI_Window_RestoreScreen(desc); key -= 0x1E; if (!save) { LoadFile(GenerateSavegameFilename(s_savegameIndexBase - key)); return true; } if (GUI_Widget_Savegame_Click(key)) return true; GUI_Window_BackupScreen(desc); UpdateArrows(save, true); GUI_Window_Create(desc); UpdateArrows(save, true); } break; } GUI_Widget_MakeNormal(w2, false); } GUI_PaletteAnimate(); } GUI_Window_RestoreScreen(desc); return false; }
/** * Handles Click event for savegame button. * * @param key The index of the clicked button. * @return True if a game has been saved, False otherwise. */ static bool GUI_Widget_Savegame_Click(uint16 key) { WindowDesc *desc = &g_savegameNameWindowDesc; bool loop; char *saveDesc = g_savegameDesc[key]; uint16 loc08; uint16 loc0A; bool ret; if (*saveDesc == '[') *saveDesc = 0; GUI_Window_BackupScreen(desc); GUI_Window_Create(desc); ret = false; loc08 = 1; if (*saveDesc == '[') key = s_savegameCountOnDisk; GFX_Screen_SetActive(SCREEN_0); Widget_SetCurrentWidget(15); GUI_Mouse_Hide_Safe(); GUI_DrawBorder((g_curWidgetXBase << 3) - 1, g_curWidgetYBase - 1, (g_curWidgetWidth << 3) + 2, g_curWidgetHeight + 2, 4, false); GUI_Mouse_Show_Safe(); for (loop = true; loop; sleepIdle()) { Widget *w = g_widgetLinkedListTail; GUI_DrawText_Wrapper(NULL, 0, 0, 232, 235, 0x22); loc0A = GUI_EditBox(saveDesc, 50, 15, g_widgetLinkedListTail, NULL, loc08); loc08 = 2; if ((loc0A & 0x8000) == 0) continue; GUI_Widget_MakeNormal(GUI_Widget_Get_ByIndex(w, loc0A & 0x7FFF), false); switch (loc0A & 0x7FFF) { case 0x1E: if (*saveDesc == 0) break; SaveFile(GenerateSavegameFilename(s_savegameIndexBase - key), saveDesc); loop = false; ret = true; break; case 0x1F: loop = false; ret = false; FillSavegameDesc(true); break; default: break; } } GUI_Window_RestoreScreen(desc); return ret; }
/** * Handles Click event for savegame button. * * @param index The index of the clicked button. * @return True if a game has been saved, False otherwise. */ static bool GUI_Widget_Savegame_Click(uint16 index) { WindowDesc *desc = &g_savegameNameWindowDesc; bool loop; char *saveDesc = g_savegameDesc[index]; bool widgetPaint; bool ret; if (*saveDesc == '[') *saveDesc = 0; GUI_Window_BackupScreen(desc); GUI_Window_Create(desc); ret = false; widgetPaint = true; if (*saveDesc == '[') index = s_savegameCountOnDisk; GFX_Screen_SetActive(SCREEN_0); Widget_SetCurrentWidget(15); GUI_Mouse_Hide_Safe(); GUI_DrawBorder((g_curWidgetXBase << 3) - 1, g_curWidgetYBase - 1, (g_curWidgetWidth << 3) + 2, g_curWidgetHeight + 2, 4, false); GUI_Mouse_Show_Safe(); for (loop = true; loop; sleepIdle()) { uint16 eventKey; Widget *w = g_widgetLinkedListTail; GUI_DrawText_Wrapper(NULL, 0, 0, 232, 235, 0x22); eventKey = GUI_EditBox(saveDesc, 50, 15, g_widgetLinkedListTail, NULL, widgetPaint); widgetPaint = false; if ((eventKey & 0x8000) == 0) continue; GUI_Widget_MakeNormal(GUI_Widget_Get_ByIndex(w, eventKey & 0x7FFF), false); switch (eventKey & 0x7FFF) { case 0x1E: /* RETURN / Save Button */ if (*saveDesc == 0) break; SaveGame_SaveFile(GenerateSavegameFilename(s_savegameIndexBase - index), saveDesc); loop = false; ret = true; break; case 0x1F: /* ESCAPE / Cancel Button */ loop = false; ret = false; FillSavegameDesc(true); break; default: break; } } GUI_Window_RestoreScreen(desc); return ret; }