bring back vanilla demos (#221)

* Bring back the demos from vanilla

the demo will activate if you are on the level that demo was meant to be from, and the default amount of time has passed

* clean up a bit and check a few things

* reset the demo input table

* config option/prevent demos playing on player menu

* update demo playing

- keep playing level music after demo finishes
- stop the demo if the player changes main menu level
This commit is contained in:
Isaac0-dev 2023-03-03 16:47:03 +10:00 committed by GitHub
parent a939ddc07b
commit bd2bd7c498
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 121 additions and 16 deletions

View File

@ -63,6 +63,10 @@ s16 gChangeLevelTransition = -1;
s16 gChangeActNum = -1;
static bool sFirstCastleGroundsMenu = true;
bool isDemoActive = false;
bool inPlayerMenu = false;
static u16 gDemoCountdown = 0;
int demoNumber = -1;
// TODO: Make these ifdefs better
const char *credits01[] = { "1GAME DIRECTOR", "SHIGERU MIYAMOTO" };
@ -821,10 +825,8 @@ s16 level_trigger_warp(struct MarioState *m, s32 warpOp) {
switch (warpOp) {
case WARP_OP_DEMO_NEXT:
case WARP_OP_DEMO_END: sDelayedWarpTimer = 20; // Must be one line to match on -O2
sSourceWarpNodeId = WARP_NODE_F0;
gSavedCourseNum = COURSE_NONE;
val04 = FALSE;
play_transition(WARP_TRANSITION_FADE_INTO_STAR, 0x14, 0x00, 0x00, 0x00);
stop_demo(NULL);
break;
case WARP_OP_CREDITS_END:
@ -972,7 +974,6 @@ void initiate_delayed_warp(void) {
break;
case WARP_OP_DEMO_NEXT:
warp_special(-2);
break;
case WARP_OP_CREDITS_START:
@ -1105,21 +1106,92 @@ void basic_update(UNUSED s16 *arg) {
}
}
bool find_demo_number(void) {
bool changeLevel = false;
switch (gCurrLevelNum) {
case LEVEL_BOWSER_1:
changeLevel = true;
demoNumber = 0;
break;
case LEVEL_WF:
changeLevel = true;
demoNumber = 1;
break;
case LEVEL_CCM:
changeLevel = true;
demoNumber = 2;
break;
case LEVEL_BBH:
changeLevel = true;
demoNumber = 3;
break;
case LEVEL_JRB:
changeLevel = true;
demoNumber = 4;
break;
case LEVEL_HMC:
changeLevel = true;
demoNumber = 5;
break;
case LEVEL_PSS:
changeLevel = true;
demoNumber = 6;
break;
default:
changeLevel = false;
demoNumber = -1;
}
return changeLevel;
}
static void start_demo(void) {
if (isDemoActive) {
isDemoActive = false;
} else {
isDemoActive = true;
if (find_demo_number()) {
gChangeLevel = gCurrLevelNum;
}
if (demoNumber <= 6 || demoNumber > -1) {
gCurrDemoInput = NULL;
func_80278A78(&gDemo, gDemoInputs, D_80339CF4);
load_patchable_table(&gDemo, demoNumber);
gCurrDemoInput = ((struct DemoInput *) gDemo.targetAnim);
} else {
isDemoActive = false;
}
}
}
void stop_demo(UNUSED struct DjuiBase* caller) {
if (isDemoActive) {
isDemoActive = false;
gCurrDemoInput = NULL;
gChangeLevel = gCurrLevelNum;
gDemoCountdown = 0;
if (gDjuiInMainMenu || gNetworkType == NT_NONE) {
update_menu_level();
}
}
}
int gPressedStart = 0;
s32 play_mode_normal(void) {
if (gCurrDemoInput != NULL) {
print_intro_text();
if (gPlayer1Controller->buttonPressed & END_DEMO) {
level_trigger_warp(gMarioState,
gCurrLevelNum == LEVEL_PSS ? WARP_OP_DEMO_END : WARP_OP_DEMO_NEXT);
} else if (!gWarpTransition.isActive && sDelayedWarpOp == WARP_OP_NONE
&& (gPlayer1Controller->buttonPressed & START_BUTTON)) {
gPressedStart = 1;
level_trigger_warp(gMarioState, WARP_OP_DEMO_NEXT);
if (gDjuiInMainMenu && gCurrDemoInput == NULL && configMenuDemos && !inPlayerMenu) {
find_demo_number();
if ((++gDemoCountdown) == PRESS_START_DEMO_TIMER && (demoNumber <= 6 || demoNumber > -1)) {
start_demo();
}
}
if (((gCurrDemoInput != NULL) && (gPlayer1Controller->buttonPressed & END_DEMO || !isDemoActive || !gDjuiInMainMenu || gNetworkType != NT_NONE || inPlayerMenu)) || (gCurrDemoInput == NULL && isDemoActive)) {
gPlayer1Controller->buttonPressed &= ~END_DEMO;
stop_demo(NULL);
}
warp_area();
check_instant_warp();
@ -1344,6 +1416,9 @@ void update_menu_level(void) {
// warp to level, this feels buggy
if (gCurrLevelNum != curLevel) {
if (isDemoActive) {
stop_demo(NULL);
}
if (curLevel == LEVEL_JRB) {
gChangeLevel = curLevel;
gChangeActNum = 2;
@ -1353,6 +1428,10 @@ void update_menu_level(void) {
gChangeLevel = curLevel;
gChangeActNum = 6;
}
gDemoCountdown = 0;
}
if (isDemoActive) {
return;
}
if (gCurrAreaIndex != 2 && gCurrLevelNum == LEVEL_THI) {

View File

@ -5,6 +5,7 @@
#include "types.h"
#include "pc/djui/djui.h"
#define TIMER_CONTROL_SHOW 0
#define TIMER_CONTROL_START 1
@ -56,6 +57,8 @@
#define WARP_TYPE_CHANGE_AREA 2
#define WARP_TYPE_SAME_AREA 3
#define PRESS_START_DEMO_TIMER 800
struct CreditsEntry
{
/*0x00*/ u8 levelNum;
@ -125,6 +128,8 @@ extern s8 gNeverEnteredCastle;
extern u32 gControlTimerStartNat;
extern u32 gControlTimerStopNat;
extern bool inPlayerMenu;
enum HUDDisplayFlag {
HUD_DISPLAY_FLAG_LIVES = 0x0001,
HUD_DISPLAY_FLAG_COIN_COUNT = 0x0002,
@ -163,4 +168,7 @@ s32 lvl_exiting_credits(UNUSED s16 arg0, UNUSED s32 arg1);
void fake_lvl_init_from_save_file(void);
void lvl_skip_credits(void);
void update_menu_level(void);
void stop_demo(UNUSED struct DjuiBase* caller);
#endif // LEVEL_UPDATE_H

View File

@ -17,8 +17,6 @@
#include "pc/lua/utils/smlua_level_utils.h"
#include "menu/intro_geo.h"
#define PRESS_START_DEMO_TIMER 800
#define STUB_LEVEL(textname, _1, _2, _3, _4, _5, _6, _7, _8) textname,
#define DEFINE_LEVEL(textname, _1, _2, _3, _4, _5, _6, _7, _8, _9, _10) textname,

View File

@ -136,6 +136,7 @@ unsigned int configPlayerModel = 0;
unsigned int configMenuLevel = 0;
bool configMenuSound = false;
bool configMenuRandom = false;
bool configMenuDemos = false;
struct PlayerPalette configPlayerPalette = {{{ 0x00, 0x00, 0xff }, { 0xff, 0x00, 0x00 }, { 0xff, 0xff, 0xff }, { 0x72, 0x1c, 0x0e }, { 0x73, 0x06, 0x00 }, { 0xfe, 0xc1, 0x79 }, { 0xff, 0x00, 0x00 }}};
struct PlayerPalette configCustomPalette = {{{ 0x00, 0x00, 0xff }, { 0xff, 0x00, 0x00 }, { 0xff, 0xff, 0xff }, { 0x72, 0x1c, 0x0e }, { 0x73, 0x06, 0x00 }, { 0xfe, 0xc1, 0x79 }, { 0xff, 0x00, 0x00 }}};
bool configUncappedFramerate = true;
@ -228,6 +229,7 @@ static const struct ConfigOption options[] = {
{.name = "coop_menu_level", .type = CONFIG_TYPE_UINT , .uintValue = &configMenuLevel},
{.name = "coop_menu_sound", .type = CONFIG_TYPE_BOOL , .boolValue = &configMenuSound},
{.name = "coop_menu_random", .type = CONFIG_TYPE_BOOL , .boolValue = &configMenuRandom},
{.name = "coop_menu_demos", .type = CONFIG_TYPE_BOOL , .boolValue = &configMenuDemos},
{.name = "coop_player_palette_pants", .type = CONFIG_TYPE_COLOR , .colorValue = &configPlayerPalette.parts[PANTS]},
{.name = "coop_player_palette_shirt", .type = CONFIG_TYPE_COLOR , .colorValue = &configPlayerPalette.parts[SHIRT]},
{.name = "coop_player_palette_gloves", .type = CONFIG_TYPE_COLOR , .colorValue = &configPlayerPalette.parts[GLOVES]},

View File

@ -93,6 +93,7 @@ extern unsigned int configPlayerModel;
extern unsigned int configMenuLevel;
extern bool configMenuSound;
extern bool configMenuRandom;
extern bool configMenuDemos;
extern struct PlayerPalette configPlayerPalette;
extern struct PlayerPalette configCustomPalette;
extern bool configUncappedFramerate;

View File

@ -1,6 +1,7 @@
#include "djui.h"
#include "src/pc/utils/misc.h"
#include "src/pc/configfile.h"
#include "src/game/level_update.h"
static struct DjuiSelectionbox* sLevelBox = NULL;
@ -51,6 +52,11 @@ void djui_panel_main_menu_create(struct DjuiBase* caller) {
djui_base_set_size(&checkbox2->base, 1.0f, 32);
djui_interactable_hook_value_change(&checkbox2->base, djui_panel_random_menu);
struct DjuiCheckbox* checkbox3 = djui_checkbox_create(&body->base, "Play Vanilla Demos", &configMenuDemos);
djui_base_set_size_type(&checkbox3->base, DJUI_SVT_RELATIVE, DJUI_SVT_ABSOLUTE);
djui_base_set_size(&checkbox3->base, 1.0f, 32);
djui_interactable_hook_value_change(&checkbox3->base, stop_demo);
struct DjuiButton* button1 = djui_button_create(&body->base, "Back");
djui_base_set_size_type(&button1->base, DJUI_SVT_RELATIVE, DJUI_SVT_ABSOLUTE);
djui_base_set_size(&button1->base, 1.0f, 64);

View File

@ -240,9 +240,20 @@ static void djui_panel_player_value_changed(UNUSED struct DjuiBase* caller) {
}
}
static void djui_panel_player_prevent_demo(UNUSED struct DjuiBase* caller) {
if (inPlayerMenu) {
inPlayerMenu = false;
djui_panel_menu_back(NULL);
} else {
inPlayerMenu = true;
}
}
void djui_panel_player_create(struct DjuiBase* caller) {
f32 bodyHeight = 32 * 3 + 64 * 2 + 16 * 5;
djui_panel_player_prevent_demo(NULL);
struct DjuiBase* defaultBase = NULL;
struct DjuiThreePanel* panel = djui_panel_menu_create(bodyHeight, "\\#ff0800\\P\\#1be700\\L\\#00b3ff\\A\\#ffef00\\Y\\#ff0800\\E\\#1be700\\R");
struct DjuiFlowLayout* body = (struct DjuiFlowLayout*)djui_three_panel_get_body(panel);
@ -338,7 +349,7 @@ void djui_panel_player_create(struct DjuiBase* caller) {
djui_base_set_size_type(&button6->base, DJUI_SVT_RELATIVE, DJUI_SVT_ABSOLUTE);
djui_base_set_size(&button6->base, 1.0f, 64);
djui_button_set_style(button6, 1);
djui_interactable_hook_click(&button6->base, djui_panel_menu_back);
djui_interactable_hook_click(&button6->base, djui_panel_player_prevent_demo);
}
djui_panel_add(caller, &panel->base, defaultBase);