Merge pull request #522 from hackgrid/fix-level-numbering

Fix new game menu displaying yet unsolved chapters
This commit is contained in:
lambertjamesd 2023-12-01 19:52:25 -07:00 committed by GitHub
commit 09ca3b5385
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
11 changed files with 52 additions and 63 deletions

View file

@ -222,7 +222,7 @@ struct Location* levelGetLocation(short index) {
return &gCurrentLevel->locations[index];
}
int levelGetChamberNumber(int levelIndex, int roomIndex){
int getChamberDisplayNumberFromLevelIndex(int levelIndex, int roomIndex){
switch(levelIndex){
case 0:
if (roomIndex <= 2)
@ -260,8 +260,8 @@ int levelGetChamberNumber(int levelIndex, int roomIndex){
}
}
int chamberNumberGetLevel(int chamberIndex) {
switch (chamberIndex) {
int getLevelIndexFromChamberDisplayNumber(int chamberNumber) {
switch (chamberNumber) {
case 0:
case 1:
return 0;

View file

@ -30,9 +30,9 @@ Gfx* levelMaterialRevert(int index);
int levelQuadIndex(struct CollisionObject* pointer);
int levelGetChamberNumber(int levelIndex, int roomIndex);
int getChamberDisplayNumberFromLevelIndex(int levelIndex, int roomIndex);
void levelClearQueuedLevel();
int chamberNumberGetLevel(int chamberIndex);
int getLevelIndexFromChamberDisplayNumber(int chamberNumber);
struct Location* levelGetLocation(short index);

View file

@ -22,7 +22,7 @@ void loadGamePopulate(struct LoadGameMenu* loadGame) {
for (int i = 0; i < numberOfSaves; ++i) {
savefileInfo[i].slotIndex = saveSlots[i].saveSlot;
savefileInfo[i].testchamberIndex = saveSlots[i].testChamber;
savefileInfo[i].testchamberDisplayNumber = saveSlots[i].testChamber;
savefileInfo[i].savefileName = saveSlots[i].saveSlot == 0 ? translationsGet(GAMEUI_AUTOSAVE) : NULL;
savefileInfo[i].screenshot = (u16*)SCREEN_SHOT_SRAM(saveSlots[i].saveSlot);
}
@ -38,7 +38,7 @@ enum InputCapture loadGameUpdate(struct LoadGameMenu* loadGame) {
savefileLoadGame(savefileGetSlot(loadGame->savefileList), save, &testChamber, &testSubject);
gCurrentTestSubject = testSubject;
levelQueueLoad(chamberNumberGetLevel(testChamber), NULL, NULL);
levelQueueLoad(getLevelIndexFromChamberDisplayNumber(testChamber), NULL, NULL);
checkpointUse(save);
stackMallocFree(save);

View file

@ -39,16 +39,6 @@ struct Chapter gChapters[] = {
#define MAX_CHAPTER_COUNT ((sizeof(gChapters) / sizeof(*gChapters)) - 1)
struct Chapter* chapterFindForChamber(int chamberIndex) {
for (int i = 1; i < MAX_CHAPTER_COUNT; ++i) {
if (gChapters[i].testChamberNumber > chamberIndex) {
return &gChapters[i - 1];
}
}
return &gChapters[MAX_CHAPTER_COUNT - 1];
}
void chapterMenuInit(struct ChapterMenu* chapterMenu, int x, int y) {
chapterMenu->chapterText = NULL;
chapterMenu->testChamberText = NULL;
@ -110,11 +100,11 @@ void newGameInit(struct NewGameMenu* newGameMenu) {
newGameMenu->topLine = menuBuildHorizontalLine(52, 64, 214);
chapterMenuInit(&newGameMenu->chapter0, 55, 76);
chapterMenuInit(&newGameMenu->chapter1, 163, 76);
chapterMenuInit(&newGameMenu->displayedChapter0_left, 55, 76);
chapterMenuInit(&newGameMenu->displayedChapter1_right, 163, 76);
chapterMenuSetChapter(&newGameMenu->chapter0, &gChapters[0], 0);
chapterMenuSetChapter(&newGameMenu->chapter1, &gChapters[1], 1);
chapterMenuSetChapter(&newGameMenu->displayedChapter0_left, &gChapters[0], 0);
chapterMenuSetChapter(&newGameMenu->displayedChapter1_right, &gChapters[1], 1);
newGameMenu->chapterOffset = 0;
newGameMenu->selectedChapter = 0;
@ -122,8 +112,8 @@ void newGameInit(struct NewGameMenu* newGameMenu) {
}
void newGameRebuildText(struct NewGameMenu* newGameMenu) {
chapterMenuSetChapter(&newGameMenu->chapter0, &gChapters[newGameMenu->chapterOffset], newGameMenu->chapterOffset);
chapterMenuSetChapter(&newGameMenu->chapter1, &gChapters[newGameMenu->chapterOffset + 1], newGameMenu->chapterOffset + 1);
chapterMenuSetChapter(&newGameMenu->displayedChapter0_left, &gChapters[newGameMenu->chapterOffset], newGameMenu->chapterOffset);
chapterMenuSetChapter(&newGameMenu->displayedChapter1_right, &gChapters[newGameMenu->chapterOffset + 1], newGameMenu->chapterOffset + 1);
prerenderedTextFree(newGameMenu->newGameText);
newGameMenu->newGameText = menuBuildPrerenderedText(&gDejaVuSansFont, translationsGet(GAMEUI_NEWGAME), 48, 48, SCREEN_WD);
@ -132,7 +122,8 @@ void newGameRebuildText(struct NewGameMenu* newGameMenu) {
enum InputCapture newGameUpdate(struct NewGameMenu* newGameMenu) {
// this is done on update so if the unlock menu cheat is used it shows up right away
while (newGameMenu->chapterCount < MAX_CHAPTER_COUNT &&
gChapters[newGameMenu->chapterCount].testChamberNumber <= gSaveData.header.chapterProgress) {
gChapters[newGameMenu->chapterCount].testChamberLevelIndex <= gSaveData.header.chapterProgressLevelIndex &&
gChapters[newGameMenu->chapterCount].testChamberLevelIndex > 0) {
++newGameMenu->chapterCount;
}
@ -140,10 +131,10 @@ enum InputCapture newGameUpdate(struct NewGameMenu* newGameMenu) {
return InputCaptureExit;
}
if (controllerGetButtonDown(0, A_BUTTON) && gChapters[newGameMenu->selectedChapter].testChamberNumber >= 0) {
if (controllerGetButtonDown(0, A_BUTTON) && gChapters[newGameMenu->selectedChapter].testChamberLevelIndex >= 0) {
gCurrentTestSubject = savefileNextTestSubject();
soundPlayerPlay(SOUNDS_BUTTONCLICKRELEASE, 1.0f, 0.5f, NULL, NULL, SoundTypeAll);
levelQueueLoad(gChapters[newGameMenu->selectedChapter].testChamberNumber, NULL, NULL);
levelQueueLoad(gChapters[newGameMenu->selectedChapter].testChamberLevelIndex, NULL, NULL);
}
if ((controllerGetDirectionDown(0) & ControllerDirectionRight) != 0 &&
@ -164,8 +155,8 @@ enum InputCapture newGameUpdate(struct NewGameMenu* newGameMenu) {
if (nextChapterOffset != newGameMenu->chapterOffset) {
newGameMenu->chapterOffset = nextChapterOffset;
chapterMenuSetChapter(&newGameMenu->chapter0, &gChapters[newGameMenu->chapterOffset], newGameMenu->chapterOffset);
chapterMenuSetChapter(&newGameMenu->chapter1, &gChapters[newGameMenu->chapterOffset + 1], newGameMenu->chapterOffset + 1);
chapterMenuSetChapter(&newGameMenu->displayedChapter0_left, &gChapters[newGameMenu->chapterOffset], newGameMenu->chapterOffset);
chapterMenuSetChapter(&newGameMenu->displayedChapter1_right, &gChapters[newGameMenu->chapterOffset + 1], newGameMenu->chapterOffset + 1);
}
return InputCapturePass;
@ -187,14 +178,14 @@ void newGameRender(struct NewGameMenu* newGameMenu, struct RenderState* renderSt
gDPPipeSync(renderState->dl++);
menuSetRenderColor(renderState, newGameMenu->selectedChapter == newGameMenu->chapterOffset, &gSelectionOrange, &gColorBlack);
gSPDisplayList(renderState->dl++, newGameMenu->chapter0.border);
gSPDisplayList(renderState->dl++, newGameMenu->displayedChapter0_left.border);
int showSecondChapter = newGameMenu->chapter1.chapter->imageData && newGameMenu->chapter1.chapter->testChamberNumber <= gSaveData.header.chapterProgress;
int showSecondChapter = newGameMenu->displayedChapter1_right.chapter->imageData && newGameMenu->displayedChapter1_right.chapter->testChamberLevelIndex <= gSaveData.header.chapterProgressLevelIndex && newGameMenu->displayedChapter1_right.chapter->testChamberLevelIndex > 0;
if (showSecondChapter) {
gDPPipeSync(renderState->dl++);
menuSetRenderColor(renderState, newGameMenu->selectedChapter != newGameMenu->chapterOffset, &gSelectionOrange, &gColorBlack);
gSPDisplayList(renderState->dl++, newGameMenu->chapter1.border);
gSPDisplayList(renderState->dl++, newGameMenu->displayedChapter1_right.border);
}
gSPDisplayList(renderState->dl++, ui_material_revert_list[SOLID_ENV_INDEX]);
@ -203,12 +194,12 @@ void newGameRender(struct NewGameMenu* newGameMenu, struct RenderState* renderSt
prerenderedBatchAdd(batch, newGameMenu->newGameText, NULL);
prerenderedBatchAdd(batch, newGameMenu->chapter0.chapterText, newGameMenu->selectedChapter == newGameMenu->chapterOffset ? &gSelectionOrange : &gColorWhite);
prerenderedBatchAdd(batch, newGameMenu->chapter0.testChamberText, newGameMenu->selectedChapter == newGameMenu->chapterOffset ? &gSelectionOrange : &gColorWhite);
prerenderedBatchAdd(batch, newGameMenu->displayedChapter0_left.chapterText, newGameMenu->selectedChapter == newGameMenu->chapterOffset ? &gSelectionOrange : &gColorWhite);
prerenderedBatchAdd(batch, newGameMenu->displayedChapter0_left.testChamberText, newGameMenu->selectedChapter == newGameMenu->chapterOffset ? &gSelectionOrange : &gColorWhite);
if (showSecondChapter) {
prerenderedBatchAdd(batch, newGameMenu->chapter1.chapterText, newGameMenu->selectedChapter != newGameMenu->chapterOffset ? &gSelectionOrange : &gColorWhite);
prerenderedBatchAdd(batch, newGameMenu->chapter1.testChamberText, newGameMenu->selectedChapter != newGameMenu->chapterOffset ? &gSelectionOrange : &gColorWhite);
prerenderedBatchAdd(batch, newGameMenu->displayedChapter1_right.chapterText, newGameMenu->selectedChapter != newGameMenu->chapterOffset ? &gSelectionOrange : &gColorWhite);
prerenderedBatchAdd(batch, newGameMenu->displayedChapter1_right.testChamberText, newGameMenu->selectedChapter != newGameMenu->chapterOffset ? &gSelectionOrange : &gColorWhite);
}
renderState->dl = prerenderedBatchFinish(batch, gDejaVuSansImages, renderState->dl);
@ -216,22 +207,22 @@ void newGameRender(struct NewGameMenu* newGameMenu, struct RenderState* renderSt
gSPDisplayList(renderState->dl++, ui_material_revert_list[DEJAVU_SANS_0_INDEX]);
graphicsCopyImage(
renderState, newGameMenu->chapter0.imageBuffer,
renderState, newGameMenu->displayedChapter0_left.imageBuffer,
84, 48,
0, 0,
newGameMenu->chapter0.x + 5,
newGameMenu->chapter0.testChamberText->y + newGameMenu->chapter0.testChamberText->height + 9,
newGameMenu->displayedChapter0_left.x + 5,
newGameMenu->displayedChapter0_left.testChamberText->y + newGameMenu->displayedChapter0_left.testChamberText->height + 9,
84, 48,
gColorWhite
);
if (showSecondChapter) {
graphicsCopyImage(
renderState, newGameMenu->chapter1.imageBuffer,
renderState, newGameMenu->displayedChapter1_right.imageBuffer,
84, 48,
0, 0,
newGameMenu->chapter1.x + 5,
newGameMenu->chapter1.testChamberText->y + newGameMenu->chapter1.testChamberText->height + 9,
newGameMenu->displayedChapter1_right.x + 5,
newGameMenu->displayedChapter1_right.testChamberText->y + newGameMenu->displayedChapter1_right.testChamberText->height + 9,
84, 48,
gColorWhite
);

View file

@ -11,7 +11,7 @@
struct Chapter {
void* imageData;
short testChamberNumber;
short testChamberLevelIndex;
short testChamberDisplayNumber;
};
@ -25,8 +25,6 @@ struct ChapterMenu {
int y;
};
struct Chapter* chapterFindForChamber(int chamberIndex);
void chapterMenuInit(struct ChapterMenu* chapterMenu, int x, int y);
struct NewGameMenu {
@ -34,8 +32,8 @@ struct NewGameMenu {
struct PrerenderedText* newGameText;
Gfx* topLine;
struct ChapterMenu chapter0;
struct ChapterMenu chapter1;
struct ChapterMenu displayedChapter0_left;
struct ChapterMenu displayedChapter1_right;
short selectedChapter;
short chapterOffset;

View file

@ -25,7 +25,7 @@ void saveGamePopulate(struct SaveGameMenu* saveGame, int includeNew) {
for (int i = 0; i < numberOfSaves; ++i) {
savefileInfo[i].slotIndex = saveSlots[i].saveSlot;
savefileInfo[i].testchamberIndex = saveSlots[i].testChamber;
savefileInfo[i].testchamberDisplayNumber = saveSlots[i].testChamber;
savefileInfo[i].savefileName = NULL;
savefileInfo[i].screenshot = (u16*)SCREEN_SHOT_SRAM(saveSlots[i].saveSlot);
@ -39,7 +39,7 @@ void saveGamePopulate(struct SaveGameMenu* saveGame, int includeNew) {
if (includeNew && freeSlot != SAVEFILE_NO_SLOT) {
savefileInfo[numberOfSaves].slotIndex = freeSlot;
savefileInfo[numberOfSaves].savefileName = translationsGet(GAMEUI_NEWSAVEGAME);
savefileInfo[numberOfSaves].testchamberIndex = levelGetChamberNumber(gCurrentLevelIndex, gScene.player.body.currentRoom);
savefileInfo[numberOfSaves].testchamberDisplayNumber = getChamberDisplayNumberFromLevelIndex(gCurrentLevelIndex, gScene.player.body.currentRoom);
savefileInfo[numberOfSaves].screenshot = gScreenGrabBuffer;
if (suggestedSlot == 0) {
@ -62,7 +62,7 @@ enum InputCapture saveGameUpdate(struct SaveGameMenu* saveGame) {
if (controllerGetButtonDown(0, A_BUTTON) && saveGame->savefileList->numberOfSaves) {
Checkpoint* save = stackMalloc(MAX_CHECKPOINT_SIZE);
if (checkpointSaveInto(&gScene, save)) {
savefileSaveGame(save, gScreenGrabBuffer, levelGetChamberNumber(gCurrentLevelIndex, gScene.player.body.currentRoom), gCurrentTestSubject, savefileGetSlot(saveGame->savefileList));
savefileSaveGame(save, gScreenGrabBuffer, getChamberDisplayNumberFromLevelIndex(gCurrentLevelIndex, gScene.player.body.currentRoom), gCurrentTestSubject, savefileGetSlot(saveGame->savefileList));
saveGamePopulate(saveGame, 0);
soundPlayerPlay(SOUNDS_BUTTONCLICKRELEASE, 1.0f, 0.5f, NULL, NULL, SoundTypeAll);
}else{

View file

@ -32,7 +32,7 @@ void savefileListSlotUseInfo(struct SavefileListSlot* savefileListSlot, struct S
}
char message[64];
textManipTestChamberMessage(message, savefileInfo->testchamberIndex);
textManipTestChamberMessage(message, savefileInfo->testchamberDisplayNumber);
savefileListSlot->testChamberText = menuBuildPrerenderedText(&gDejaVuSansFont, message, x + BORDER_WIDTH + 8, y, 120);
if (savefileInfo->savefileName) {
@ -67,7 +67,7 @@ void savefileListSlotInit(struct SavefileListSlot* savefileListSlot, int x, int
savefileListSlot->x = x;
savefileListSlot->y = y;
savefileListSlot->imageData = malloc(THUMBANIL_IMAGE_SIZE);
savefileListSlot->imageData = malloc(THUMBNAIL_IMAGE_SIZE);
savefileListSlot->slotIndex = -1;
}

View file

@ -9,7 +9,7 @@
struct SavefileInfo {
short slotIndex;
short testchamberIndex;
short testchamberDisplayNumber;
char* savefileName;
u16* screenshot;
};

View file

@ -52,7 +52,7 @@ void checkpointSave(struct Scene* scene) {
savefileGrabScreenshot();
gHasCheckpoint = checkpointSaveInto(scene, gCheckpoint);
// slot 0 is the autosave slot
savefileSaveGame(gCheckpoint, gScreenGrabBuffer, levelGetChamberNumber(gCurrentLevelIndex, gScene.player.body.currentRoom), gCurrentTestSubject, 0);
savefileSaveGame(gCheckpoint, gScreenGrabBuffer, getChamberDisplayNumberFromLevelIndex(gCurrentLevelIndex, gScene.player.body.currentRoom), gCurrentTestSubject, 0);
}
void checkpointLoadLast(struct Scene* scene) {

View file

@ -154,9 +154,9 @@ void savefileSave() {
#define SAVE_SLOT_SRAM_ADDRESS(index) (SRAM_ADDR + (1 + (index)) * SAVE_SLOT_SIZE)
void savefileSaveGame(Checkpoint checkpoint, u16* screenshot, int testChamberIndex, int subjectNumber, int slotIndex) {
void savefileSaveGame(Checkpoint checkpoint, u16* screenshot, int testChamberDisplayNumber, int subjectNumber, int slotIndex) {
savefileSramSave((void*)SAVE_SLOT_SRAM_ADDRESS(slotIndex), checkpoint, MAX_CHECKPOINT_SIZE);
savefileSramSave((void*)SCREEN_SHOT_SRAM(slotIndex), screenshot, THUMBANIL_IMAGE_SIZE);
savefileSramSave((void*)SCREEN_SHOT_SRAM(slotIndex), screenshot, THUMBNAIL_IMAGE_SIZE);
unsigned char prevSortOrder = gSaveData.saveSlotMetadata[slotIndex].saveSlotOrder;
@ -167,7 +167,7 @@ void savefileSaveGame(Checkpoint checkpoint, u16* screenshot, int testChamberInd
}
}
gSaveData.saveSlotMetadata[slotIndex].testChamber = testChamberIndex;
gSaveData.saveSlotMetadata[slotIndex].testChamber = testChamberDisplayNumber;
gSaveData.saveSlotMetadata[slotIndex].testSubjectNumber = subjectNumber;
gSaveData.saveSlotMetadata[slotIndex].saveSlotOrder = 0;
@ -291,9 +291,9 @@ int savefileOldestSlot() {
return result;
}
void savefileMarkChapterProgress(int chamberNumber) {
if (chamberNumber > gSaveData.header.chapterProgress) {
gSaveData.header.chapterProgress = chamberNumber;
void savefileMarkChapterProgress(int levelIndex) {
if (levelIndex > gSaveData.header.chapterProgressLevelIndex) {
gSaveData.header.chapterProgressLevelIndex = levelIndex;
savefileSave();
}
}
@ -316,9 +316,9 @@ void savefileLoadGame(int slot, Checkpoint checkpoint, int* testChamberIndex, in
void savefileLoadScreenshot(u16* target, u16* location) {
if ((int)location >= SRAM_START_ADDR && (int)location <= (SRAM_START_ADDR + SRAM_SIZE)) {
savefileSramLoad(location, target, THUMBANIL_IMAGE_SIZE);
savefileSramLoad(location, target, THUMBNAIL_IMAGE_SIZE);
} else {
memCopy(target, location, THUMBANIL_IMAGE_SIZE);
memCopy(target, location, THUMBNAIL_IMAGE_SIZE);
}
}

View file

@ -12,7 +12,7 @@
#define SAVE_SLOT_IMAGE_W 36
#define SAVE_SLOT_IMAGE_H 27
#define THUMBANIL_IMAGE_SIZE (SAVE_SLOT_IMAGE_W * SAVE_SLOT_IMAGE_H * sizeof(u16))
#define THUMBNAIL_IMAGE_SIZE (SAVE_SLOT_IMAGE_W * SAVE_SLOT_IMAGE_H * sizeof(u16))
#define THUMBNAIL_IMAGE_SPACE 2048
@ -28,7 +28,7 @@
struct SaveHeader {
unsigned header;
unsigned char chapterProgress;
unsigned char chapterProgressLevelIndex;
unsigned char flags;
unsigned char nextTestSubject;
};