RingRacers/src/menus/transient/cup-select.c
James R b26cd786ec Move all specialized code out of k_menufunc.c
Adds new files:

- menus/extras-statistics.c
- menus/play-online-room-select.c
- menus/transient/cup-select.c
- menus/transient/explosions.c
- menus/transient/gametype.c
- menus/transient/message-box.c
- menus/transient/virtual-keyboard.c
2023-01-12 20:31:31 -08:00

195 lines
4 KiB
C

/// \file menus/transient/cup-select.c
/// \brief Cup Select
#include "../../k_menu.h"
#include "../../s_sound.h"
#include "../../f_finale.h" // F_WipeStartScreen
#include "../../v_video.h"
#include "../../k_grandprix.h"
#include "../../r_local.h" // SplitScreen_OnChange
menuitem_t PLAY_CupSelect[] =
{
{IT_NOTHING | IT_KEYHANDLER, NULL, NULL, NULL, {.routine = M_CupSelectHandler}, 0, 0},
};
menu_t PLAY_CupSelectDef = {
sizeof(PLAY_CupSelect) / sizeof(menuitem_t),
&PLAY_RaceGamemodesDef,
0,
PLAY_CupSelect,
0, 0,
0, 0,
2, 5,
M_DrawCupSelect,
M_CupSelectTick,
NULL,
NULL,
NULL
};
struct cupgrid_s cupgrid;
void M_CupSelectHandler(INT32 choice)
{
const UINT8 pid = 0;
(void)choice;
if (menucmd[pid].dpad_lr > 0)
{
cupgrid.x++;
if (cupgrid.x >= CUPMENU_COLUMNS)
{
cupgrid.x = 0;
cupgrid.pageno++;
if (cupgrid.pageno >= cupgrid.numpages)
cupgrid.pageno = 0;
}
S_StartSound(NULL, sfx_s3k5b);
M_SetMenuDelay(pid);
}
else if (menucmd[pid].dpad_lr < 0)
{
cupgrid.x--;
if (cupgrid.x < 0)
{
cupgrid.x = CUPMENU_COLUMNS-1;
if (cupgrid.pageno == 0)
cupgrid.pageno = cupgrid.numpages-1;
else
cupgrid.pageno--;
}
S_StartSound(NULL, sfx_s3k5b);
M_SetMenuDelay(pid);
}
if (menucmd[pid].dpad_ud > 0)
{
cupgrid.y++;
if (cupgrid.y >= CUPMENU_ROWS)
cupgrid.y = 0;
S_StartSound(NULL, sfx_s3k5b);
M_SetMenuDelay(pid);
}
else if (menucmd[pid].dpad_ud < 0)
{
cupgrid.y--;
if (cupgrid.y < 0)
cupgrid.y = CUPMENU_ROWS-1;
S_StartSound(NULL, sfx_s3k5b);
M_SetMenuDelay(pid);
}
if (M_MenuConfirmPressed(pid) /*|| M_MenuButtonPressed(pid, MBT_START)*/)
{
INT16 count;
cupheader_t *newcup = cupgrid.builtgrid[CUPMENU_CURSORID];
cupheader_t *oldcup = levellist.levelsearch.cup;
M_SetMenuDelay(pid);
levellist.levelsearch.cup = newcup;
count = M_CountLevelsToShowInList(&levellist.levelsearch);
if ((!newcup)
|| (count <= 0)
|| (cupgrid.grandprix == true && newcup->cachedlevels[0] == NEXTMAP_INVALID))
{
S_StartSound(NULL, sfx_s3kb2);
return;
}
if (cupgrid.grandprix == true)
{
INT32 levelNum;
UINT8 ssplayers = cv_splitplayers.value-1;
S_StartSound(NULL, sfx_s3k63);
// Early fadeout to let the sound finish playing
F_WipeStartScreen();
V_DrawFill(0, 0, BASEVIDWIDTH, BASEVIDHEIGHT, 31);
F_WipeEndScreen();
F_RunWipe(wipedefs[wipe_level_toblack], false, "FADEMAP0", false, false);
memset(&grandprixinfo, 0, sizeof(struct grandprixinfo));
if (cv_maxconnections.value < ssplayers+1)
CV_SetValue(&cv_maxconnections, ssplayers+1);
if (splitscreen != ssplayers)
{
splitscreen = ssplayers;
SplitScreen_OnChange();
}
// read our dummy cvars
grandprixinfo.gamespeed = min(KARTSPEED_HARD, cv_dummygpdifficulty.value);
grandprixinfo.masterbots = (cv_dummygpdifficulty.value == 3);
grandprixinfo.encore = (boolean)cv_dummygpencore.value;
grandprixinfo.cup = newcup;
grandprixinfo.gp = true;
grandprixinfo.roundnum = 1;
grandprixinfo.initalize = true;
paused = false;
// Don't restart the server if we're already in a game lol
if (gamestate == GS_MENU)
{
SV_StartSinglePlayerServer(levellist.newgametype, levellist.netgame);
}
levelNum = grandprixinfo.cup->cachedlevels[0];
D_MapChange(
levelNum + 1,
GT_RACE,
grandprixinfo.encore,
true,
1,
false,
false
);
M_ClearMenus(true);
}
else if (count == 1)
{
PLAY_TimeAttackDef.transitionID = currentMenu->transitionID+1;
M_LevelSelected(0);
}
else
{
// Keep cursor position if you select the same cup again, reset if it's a different cup
if (oldcup != newcup || levellist.cursor >= count)
{
levellist.cursor = 0;
}
M_LevelSelectScrollDest();
levellist.y = levellist.dest;
M_SetupNextMenu(&PLAY_LevelSelectDef, false);
S_StartSound(NULL, sfx_s3k63);
}
}
else if (M_MenuBackPressed(pid))
{
M_SetMenuDelay(pid);
if (currentMenu->prevMenu)
M_SetupNextMenu(currentMenu->prevMenu, false);
else
M_ClearMenus(true);
}
}
void M_CupSelectTick(void)
{
cupgrid.previewanim++;
}