Add toggle option for walk speed modifiers (#1783)

* Add toggle option for walk speed modifiers

* Preserve toggle status between scene transitions

* Apply suggestions from code review

renaming from `gSpeedToggle` to `gWalkSpeedToggle`

Co-authored-by: briaguya <70942617+briaguya-ai@users.noreply.github.com>
This commit is contained in:
Josh Bodner 2022-10-20 20:55:15 -07:00 committed by GitHub
parent 262e036c22
commit 4fb78f9caa
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 58 additions and 18 deletions

View File

@ -166,6 +166,8 @@ extern "C"
extern s32 gSystemArenaLogSeverity;
extern u8 __osPfsInodeCacheBank;
extern s32 __osPfsLastChannel;
extern u8 gWalkSpeedToggle1;
extern u8 gWalkSpeedToggle2;
extern const s16 D_8014A6C0[];
#define gTatumsPerBeat (D_8014A6C0[1])
@ -211,16 +213,16 @@ extern "C"
extern volatile OSTime gRDPTotalTime;
extern FaultThreadStruct gFaultStruct;
extern ActiveSound gActiveSounds[7][MAX_CHANNELS_PER_BANK]; // total size = 0xA8
extern u8 gSoundBankMuted[];
extern u8 D_801333F0;
extern u8 gAudioSfxSwapOff;
extern u16 gAudioSfxSwapSource[10];
extern u16 gAudioSfxSwapTarget[10];
extern u8 gAudioSfxSwapMode[10];
extern unk_D_8016E750 D_8016E750[4];
extern AudioContext gAudioContext;
extern void(*D_801755D0)(void);
extern ActiveSound gActiveSounds[7][MAX_CHANNELS_PER_BANK]; // total size = 0xA8
extern u8 gSoundBankMuted[];
extern u8 D_801333F0;
extern u8 gAudioSfxSwapOff;
extern u16 gAudioSfxSwapSource[10];
extern u16 gAudioSfxSwapTarget[10];
extern u8 gAudioSfxSwapMode[10];
extern unk_D_8016E750 D_8016E750[4];
extern AudioContext gAudioContext;
extern void(*D_801755D0)(void);
extern u32 __osMalloc_FreeBlockTest_Enable;
extern Arena gSystemArena;

View File

@ -764,6 +764,7 @@ namespace GameMenuBar {
UIWidgets::PaddedEnhancementCheckbox("Enable walk speed modifiers", "gEnableWalkModify", true, false);
UIWidgets::Tooltip("Hold the assigned button to change the maximum walking speed\nTo change the assigned button, click Customize Game Controls");
if (CVar_GetS32("gEnableWalkModify", 0)) {
UIWidgets::PaddedEnhancementCheckbox("Toggle modifier instead of holding", "gWalkSpeedToggle", true, false);
UIWidgets::EnhancementSliderFloat("Modifier 1: %d %%", "##WalkMod1", "gWalkModifierOne", 0.0f, 5.0f, "", 1.0f, true);
UIWidgets::EnhancementSliderFloat("Modifier 2: %d %%", "##WalkMod2", "gWalkModifierTwo", 0.0f, 5.0f, "", 1.0f, true);
}

View File

@ -1053,6 +1053,8 @@ static s8 sItemActionParams[] = {
};
static u8 sMaskMemory;
u8 gWalkSpeedToggle1;
u8 gWalkSpeedToggle2;
// Used to map action params to update functions
static s32 (*D_80853EDC[])(Player* this, GlobalContext* globalCtx) = {
@ -6033,10 +6035,22 @@ void func_8083DFE0(Player* this, f32* arg1, s16* arg2) {
if (CVar_GetS32("gMMBunnyHood", 0) && this->currentMask == PLAYER_MASK_BUNNY) {
maxSpeed *= 1.5f;
} else if (CVar_GetS32("gEnableWalkModify", 0) && CHECK_BTN_ALL(sControlInput->cur.button, BTN_MODIFIER1)) {
maxSpeed *= CVar_GetFloat("gWalkModifierOne", 1.0f);
} else if (CVar_GetS32("gEnableWalkModify", 0) && CHECK_BTN_ALL(sControlInput->cur.button, BTN_MODIFIER2)) {
maxSpeed *= CVar_GetFloat("gWalkModifierTwo", 1.0f);
}
if (CVar_GetS32("gEnableWalkModify", 0)) {
if (CVar_GetS32("gWalkSpeedToggle", 0)) {
if (gWalkSpeedToggle1) {
maxSpeed *= CVar_GetFloat("gWalkModifierOne", 1.0f);
} else if (gWalkSpeedToggle2) {
maxSpeed *= CVar_GetFloat("gWalkModifierTwo", 1.0f);
}
} else {
if (CHECK_BTN_ALL(sControlInput->cur.button, BTN_MODIFIER1)) {
maxSpeed *= CVar_GetFloat("gWalkModifierOne", 1.0f);
} else if (CHECK_BTN_ALL(sControlInput->cur.button, BTN_MODIFIER2)) {
maxSpeed *= CVar_GetFloat("gWalkModifierTwo", 1.0f);
}
}
}
this->linearVelocity = CLAMP(this->linearVelocity, -maxSpeed, maxSpeed);
@ -7662,10 +7676,22 @@ void func_80842180(Player* this, GlobalContext* globalCtx) {
if (CVar_GetS32("gMMBunnyHood", 0) && this->currentMask == PLAYER_MASK_BUNNY) {
sp2C *= 1.5f;
} else if (CVar_GetS32("gEnableWalkModify", 0) && CHECK_BTN_ALL(sControlInput->cur.button, BTN_MODIFIER1)) {
sp2C *= CVar_GetFloat("gWalkModifierOne", 1.0f);
} else if (CVar_GetS32("gEnableWalkModify", 0) && CHECK_BTN_ALL(sControlInput->cur.button, BTN_MODIFIER2)) {
sp2C *= CVar_GetFloat("gWalkModifierTwo", 1.0f);
}
if (CVar_GetS32("gEnableWalkModify", 0)) {
if (CVar_GetS32("gWalkSpeedToggle", 0)) {
if (gWalkSpeedToggle1) {
sp2C *= CVar_GetFloat("gWalkModifierOne", 1.0f);
} else if (gWalkSpeedToggle2) {
sp2C *= CVar_GetFloat("gWalkModifierTwo", 1.0f);
}
} else {
if (CHECK_BTN_ALL(sControlInput->cur.button, BTN_MODIFIER1)) {
sp2C *= CVar_GetFloat("gWalkModifierOne", 1.0f);
} else if (CHECK_BTN_ALL(sControlInput->cur.button, BTN_MODIFIER2)) {
sp2C *= CVar_GetFloat("gWalkModifierTwo", 1.0f);
}
}
}
func_8083DF68(this, sp2C, sp2A);
@ -10956,6 +10982,15 @@ void Player_Update(Actor* thisx, GlobalContext* globalCtx) {
if (chaosEffectGravityLevel == GRAVITY_LEVEL_LIGHT) {
this->actor.gravity = -0.3f;
}
if (CVar_GetS32("gEnableWalkModify", 0) && CVar_GetS32("gWalkSpeedToggle", 0)) {
if (CHECK_BTN_ALL(sControlInput->press.button, BTN_MODIFIER1)) {
gWalkSpeedToggle1 = !gWalkSpeedToggle1;
}
if (CHECK_BTN_ALL(sControlInput->press.button, BTN_MODIFIER2)) {
gWalkSpeedToggle2 = !gWalkSpeedToggle2;
}
}
}
static struct_80858AC8 D_80858AC8;

View File

@ -11,6 +11,8 @@ void Opening_SetupTitleScreen(OpeningContext* this) {
this->state.running = false;
gSaveContext.linkAge = 0;
gSaveContext.fileNum = 0xFF;
gWalkSpeedToggle1 = 0;
gWalkSpeedToggle2 = 0;
Sram_InitDebugSave();
gSaveContext.cutsceneIndex = 0xFFF3;
gSaveContext.sceneSetupIndex = 7;