Skip to content

Commit

Permalink
Entrance display
Browse files Browse the repository at this point in the history
add a way to display/change entrance and cutscene number without warping, by holding R in the entrances menu;
add more alert popups;
  • Loading branch information
HylianFreddy committed Dec 25, 2021
1 parent 8d903f4 commit 39611d5
Show file tree
Hide file tree
Showing 4 changed files with 79 additions and 31 deletions.
1 change: 1 addition & 0 deletions include/common.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ extern MemInfo query_memory_permissions(u32 address);
extern bool is_valid_memory_read(const MemInfo* info);
extern bool isInGame();
extern void drawAlert();
extern void pauseDisplay();

extern u32 alertFrames;
extern char* alertMessage;
Expand Down
28 changes: 19 additions & 9 deletions src/commands.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
#include "common.h"
#include "z3D/z3D.h"
#include "draw.h"
#include "advance.h"

u32 pauseUnpause = 0; //tells main to pause/unpause
u32 frameAdvance = 0; //tells main to frame advance
Expand Down Expand Up @@ -41,6 +42,8 @@ static void Command_Break(void){

PLAYER->stateFlags1 = 0x0;
PLAYER->stateFlags2 = 0x0;
alertMessage = "Break";
alertFrames = 20;
}
}

Expand All @@ -65,9 +68,9 @@ static void Command_Reset(void){
static void Command_ReloadScene(void){
if (isInGame()) {
if(gGlobalContext->nextEntranceIndex != -1)
EntranceWarp(gGlobalContext->nextEntranceIndex, gSaveContext.linkAge, -1, 0);
EntranceWarp(gGlobalContext->nextEntranceIndex, gGlobalContext->linkAgeOnLoad, -1, 0);
else
EntranceWarp(gSaveContext.entranceIndex, gSaveContext.linkAge, -1, 0);
EntranceWarp(gSaveContext.entranceIndex, gGlobalContext->linkAgeOnLoad, -1, 0);
}
}

Expand All @@ -77,13 +80,15 @@ static void Command_VoidOut(void){
gSaveContext.respawn[RESPAWN_MODE_DOWN].tempCollectFlags = gGlobalContext->actorCtx.flags.tempCollect;
gSaveContext.respawnFlag = 1;
if (gGlobalContext->sceneLoadFlag == 0 || gGlobalContext->sceneLoadFlag == -20) {
EntranceWarp(gSaveContext.respawn[RESPAWN_MODE_DOWN].entranceIndex, gSaveContext.linkAge, -1, 0);
EntranceWarp(gSaveContext.respawn[RESPAWN_MODE_DOWN].entranceIndex, gGlobalContext->linkAgeOnLoad, -1, 0);
}
}
}

static void Command_ToggleAge(void){
gGlobalContext->linkAgeOnLoad = 1 - gSaveContext.linkAge;
gGlobalContext->linkAgeOnLoad = 1 - gGlobalContext->linkAgeOnLoad;
alertMessage = gGlobalContext->linkAgeOnLoad ? "Child on next load" : "Adult on next load";
alertFrames = menuOpen ? 10 : 75;
}

// static void Command_SaveState(void);
Expand All @@ -96,7 +101,7 @@ static void Command_StorePos(void){

alertMessage = "Stored position X";
alertMessage[16] = storedPosIndex + 48; //ASCII digit
alertFrames = 90;
alertFrames = menuOpen ? 10 : 90;
}
}

Expand All @@ -110,15 +115,14 @@ static void Command_LoadPos(void){

alertMessage = "Loaded position X";
alertMessage[16] = storedPosIndex + 48; //ASCII digit
alertFrames = 90;
alertFrames = menuOpen ? 10 : 90;
}
}


static void AlertPosIndex(void) {
alertMessage = "Position X";
alertMessage[9] = storedPosIndex + 48; //ASCII digit
alertFrames = 75;
alertFrames = menuOpen ? 10 : 75;
}

static void Command_PreviousPos(void) {
Expand All @@ -132,10 +136,16 @@ static void Command_NextPos(void) {

static void Command_PauseUnpause(void){
pauseUnpause = 1;
if (advance_ctx.advance_state == NORMAL) {
pauseDisplay(); // appear when triggered from menu
}
}

static void Command_FrameAdvance(void){
frameAdvance = 1;
if (advance_ctx.advance_state == NORMAL) {
pauseDisplay(); // appear when triggered from menu
}
}

// static void Command_RecordMacro(void);
Expand All @@ -157,7 +167,7 @@ static Command commandList[] = {
{"Reset", 0, 0, { 0 }, Command_Reset, COMMAND_PRESS_ONCE_TYPE, 0, 0},
{"Reload Scene", 0, 0, { 0 }, Command_ReloadScene, COMMAND_PRESS_ONCE_TYPE, 0, 0},
{"Void Out", 0, 0, { 0 }, Command_VoidOut, COMMAND_PRESS_ONCE_TYPE, 0, 0},
{"Toggle Age", 0, 0, { 0 }, Command_ToggleAge, COMMAND_PRESS_ONCE_TYPE, 0, 0},
{"Toggle Age", 0, 0, { 0 }, Command_ToggleAge, COMMAND_PRESS_TYPE, 0, 0},
{"Store Position", 0, 0, { 0 }, Command_StorePos, COMMAND_HOLD_TYPE, 0, 0},
{"Load Position", 0, 0, { 0 }, Command_LoadPos, COMMAND_HOLD_TYPE, 0, 0},
{"Previous Position", 0, 0, { 0 }, Command_PreviousPos, COMMAND_PRESS_TYPE, 0, 0},
Expand Down
69 changes: 49 additions & 20 deletions src/entrances.c
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
#include "draw.h"
#include "menu.h"
#include "input.h"
#include "common.h"
#include "menus/commands.h"
#include "z3D/z3D.h"
#include "utils.h"
Expand Down Expand Up @@ -36,16 +37,15 @@ void EntranceWarp(u16 EntranceIndex, s32 chosenAge, s32 cutsceneIndex, u32 chose
if (chosenTimeIndex != 0){
gSaveContext.dayTime = EntranceTimes[chosenTimeIndex];
}
gSaveContext.entranceIndex = EntranceIndex;
gGlobalContext->nextEntranceIndex = EntranceIndex;
gGlobalContext->fadeOutTransition = 2;
gGlobalContext->linkAgeOnLoad = chosenAge;
if (cutsceneIndex < 0){
if (cutsceneIndex == -1){ //this prevents crashes because warping with CS 0xFFEF ("None") would keep the previous CS number
gSaveContext.cutsceneIndex = 0;
}
else {
gSaveContext.nextCutsceneIndex = (cutsceneIndex += 0xFFF0);
}

gSaveContext.nextCutsceneIndex = (cutsceneIndex == -2) ? 0 : (cutsceneIndex + 0xFFF0);

gGlobalContext->sceneLoadFlag = 0x14;
}

Expand Down Expand Up @@ -78,14 +78,18 @@ void EntranceSelectMenuShow(const EntrancesByScene* entrances, const u8 manualSe
Draw_DrawFormattedString(30, 30 + SPACING_Y * Entrance_Select_Menu_Time, COLOR_WHITE, "Time of Day: %s", TimeNames[chosenTime]);
Draw_DrawCharacter(10, 30 + SPACING_Y * Entrance_Select_Menu_Time, COLOR_TITLE, selected == Entrance_Select_Menu_Time ? '>' : ' ');

if (cutsceneIndex < 0){
cutsceneIndex = -1;
if (cutsceneIndex < -1){
cutsceneIndex = -2;
Draw_DrawString(30, 30 + SPACING_Y * Entrance_Select_Menu_CsIdx,
(selected == Entrance_Select_Menu_CsIdx) ? curColor : COLOR_WHITE, "Cutscene Number on Load: Forced Cleared (BiT)");
}
else if (cutsceneIndex == -1){
Draw_DrawString(30, 30 + SPACING_Y * Entrance_Select_Menu_CsIdx,
(selected == Entrance_Select_Menu_CsIdx) ? curColor : COLOR_WHITE, "Cutscene Number on Load: None");
(selected == Entrance_Select_Menu_CsIdx) ? curColor : COLOR_WHITE, "Cutscene Number on Load: None ");
}
else {
Draw_DrawFormattedString(30, 30 + SPACING_Y * Entrance_Select_Menu_CsIdx,
(selected == Entrance_Select_Menu_CsIdx) ? curColor : COLOR_WHITE, "Cutscene Number on Load: %02d ", cutsceneIndex);
(selected == Entrance_Select_Menu_CsIdx) ? curColor : COLOR_WHITE, "Cutscene Number on Load: %02d ", cutsceneIndex);
}
Draw_DrawCharacter(10, 30 + SPACING_Y * Entrance_Select_Menu_CsIdx, COLOR_TITLE, selected == Entrance_Select_Menu_CsIdx ? '>' : ' ');

Expand Down Expand Up @@ -114,6 +118,12 @@ void EntranceSelectMenuShow(const EntrancesByScene* entrances, const u8 manualSe
{
curColor = COLOR_WHITE;
chosen = 0;
if (ADDITIONAL_FLAG_BUTTON && selected == Entrance_Select_Menu_CsIdx) {
gSaveContext.nextCutsceneIndex = (cutsceneIndex == -2) ? 0 : (cutsceneIndex + 0xFFF0);
}
else if (ADDITIONAL_FLAG_BUTTON && selected == Entrance_Select_Menu_Etcs) {
gGlobalContext->nextEntranceIndex = chosenEntranceIndex;
}
}
else if (pressed & (BUTTON_UP | BUTTON_DOWN | BUTTON_LEFT | BUTTON_RIGHT | BUTTON_X | BUTTON_Y)) // change selected value
{
Expand All @@ -127,10 +137,18 @@ void EntranceSelectMenuShow(const EntrancesByScene* entrances, const u8 manualSe
case (BUTTON_X): increment = 256; break;
case (BUTTON_Y): increment = -256; break;
}
if (selected == Entrance_Select_Menu_CsIdx)
cutsceneIndex += increment;
else if (selected == Entrance_Select_Menu_Etcs)
if (selected == Entrance_Select_Menu_Etcs)
chosenEntranceIndex += increment;
else if (selected == Entrance_Select_Menu_CsIdx) {
cutsceneIndex += increment;
// keep cutsceneIndex within the correct values
if(cutsceneIndex > 15){
cutsceneIndex = (ADDITIONAL_FLAG_BUTTON ? -2 : -1);
}
if(cutsceneIndex < (ADDITIONAL_FLAG_BUTTON ? -2 : -1)) {
cutsceneIndex = 15;
}
}
}
} else { // not chosen
if(pressed & BUTTON_B) // close entrances menu
Expand All @@ -154,7 +172,7 @@ void EntranceSelectMenuShow(const EntrancesByScene* entrances, const u8 manualSe
else if(selected >= Entrance_Select_Menu_Etcs){
s32 age;
switch(chosenAge) {
case 2: age = gSaveContext.linkAge; break;
case 2: age = gGlobalContext->linkAgeOnLoad; break;
default: age = chosenAge; break;
}
u16 entranceIndex = manualSelection ? chosenEntranceIndex : entrances->items[selected - Entrance_Select_Menu_Etcs].entranceIndex;
Expand All @@ -172,13 +190,6 @@ void EntranceSelectMenuShow(const EntrancesByScene* entrances, const u8 manualSe
}
}

if(cutsceneIndex > 15){
cutsceneIndex = -1;
}
if(cutsceneIndex < -1) {
cutsceneIndex = 15;
}

if(selected < 0) {
selected = (manualSelection ? Entrance_Select_Menu_Go : (Entrance_Select_Menu_Etcs + entrances->nbItems - 1));
}
Expand All @@ -187,6 +198,24 @@ void EntranceSelectMenuShow(const EntrancesByScene* entrances, const u8 manualSe
}
pagePrev = page;
page = selected >= ENTRANCE_MENU_MAX_SHOW + Entrance_Select_Menu_Etcs ? 1 : 0;

if(ADDITIONAL_FLAG_BUTTON) {
Draw_DrawFormattedStringTop(60, 190, COLOR_WHITE, "Current Entrance: %04X", (u16)gSaveContext.entranceIndex);
Draw_DrawFormattedStringTop(60, 200, COLOR_WHITE, "Current Cutscene: %04X", (u16)gSaveContext.cutsceneIndex);
Draw_DrawFormattedStringTop(60, 210, COLOR_WHITE, "Next Entrance: %04X", (u16)gGlobalContext->nextEntranceIndex);
Draw_DrawFormattedStringTop(60, 220, COLOR_WHITE, "Next Cutscene: %04X", (u16)gSaveContext.nextCutsceneIndex);

// this would print the cutscene number formatted like in the options, but I think the hex value is better
/*if (gSaveContext.nextCutsceneIndex >= 0xFFF0) {
Draw_DrawFormattedStringTop(60, 220, COLOR_WHITE, "Next Cutscene: %02d ", gSaveContext.nextCutsceneIndex - 0xFFF0);
}
else if (gSaveContext.nextCutsceneIndex == 0) {
Draw_DrawStringTop(60, 220, COLOR_WHITE, "Next Cutscene: Forced Cleared (BiT)");
}
else { // 0xFFEF, default
Draw_DrawStringTop(60, 220, COLOR_WHITE, "Next Cutscene: None ");
}*/
}
} while(menuOpen);
}

Expand Down
12 changes: 10 additions & 2 deletions src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ advance_ctx_t advance_ctx = {};
uint8_t framebuffers_init = 0;
static bool isAsleep = false;
u32 alertFrames = 0;
char* alertMessage;
char* alertMessage = "";

GlobalContext* gGlobalContext;

Expand Down Expand Up @@ -135,7 +135,7 @@ static void titleScreenDisplay(void){
Draw_FlushFramebuffer();
}

static void pauseDisplay(void) {
void pauseDisplay(void) {
Draw_DrawFormattedStringTop(20, 20, COLOR_WHITE, "Paused");
Draw_FlushFramebufferTop();
}
Expand All @@ -157,6 +157,10 @@ void advance_main(void) {

if(menuOpen) {
menuShow();
Draw_Lock();
Draw_ClearFramebuffer();
Draw_FlushFramebuffer();
Draw_Unlock();
}
applyCheats();

Expand All @@ -179,6 +183,10 @@ void advance_main(void) {
Command_UpdateCommands(rInputCtx.cur.val);
if(menuOpen) {
menuShow();
Draw_Lock();
Draw_ClearFramebuffer();
Draw_FlushFramebuffer();
Draw_Unlock();
}
applyCheats();
toggle_advance();
Expand Down

0 comments on commit 39611d5

Please sign in to comment.