Pass a pointer to the MenuData structure to MenuActions
This commit is contained in:
parent
f06d101399
commit
149b62c37c
14 changed files with 59 additions and 69 deletions
|
@ -9,11 +9,11 @@
|
|||
#include "options.h"
|
||||
#include "global.h"
|
||||
|
||||
void set_player(void *p) {
|
||||
void set_player(MenuData *m, void *p) {
|
||||
global.plr.cha = (Character) (uintptr_t) p;
|
||||
}
|
||||
|
||||
void set_shotmode(void *p) {
|
||||
void set_shotmode(MenuData *m, void *p) {
|
||||
global.plr.shot = (ShotMode) (uintptr_t) p;
|
||||
}
|
||||
|
||||
|
@ -147,7 +147,7 @@ void char_menu_input_event(EventType type, int state, void *arg) {
|
|||
close_menu(menu);
|
||||
|
||||
// XXX: This needs a better fix
|
||||
set_shotmode(mod->entries[mod->selected].arg);
|
||||
set_shotmode(mod, mod->entries[mod->selected].arg);
|
||||
} else if(type == E_MenuAbort) {
|
||||
play_ui_sound("hit");
|
||||
close_menu(menu);
|
||||
|
|
|
@ -13,7 +13,7 @@
|
|||
#include "ending.h"
|
||||
#include "credits.h"
|
||||
|
||||
void start_game(void *arg) {
|
||||
void start_game(MenuData *menu, void *arg) {
|
||||
MenuData m;
|
||||
|
||||
init_player(&global.plr);
|
||||
|
@ -58,7 +58,7 @@ troll2:
|
|||
case 0: break;
|
||||
|
||||
case 1: {
|
||||
save_rpy(NULL);
|
||||
save_rpy(menu, NULL);
|
||||
break;
|
||||
}
|
||||
|
||||
|
@ -144,3 +144,7 @@ void animate_menu_list(MenuData *m) {
|
|||
m->drawdata[1] += (w*2 - m->drawdata[1])/10.0;
|
||||
m->drawdata[2] += (20*m->cursor - m->drawdata[2])/10.0;
|
||||
}
|
||||
|
||||
void menu_commonaction_close(MenuData *menu, void *arg) {
|
||||
kill_menu(menu);
|
||||
}
|
||||
|
|
|
@ -10,10 +10,11 @@
|
|||
|
||||
#include "menu.h"
|
||||
|
||||
void start_game(void *arg);
|
||||
void start_game(MenuData *m, void *arg);
|
||||
void draw_menu_selector(float x, float y, float w, float h, float t);
|
||||
void draw_menu_title(MenuData *m, char *title);
|
||||
void draw_menu_list(MenuData *m, float x, float y, void (*draw)(void*, int, int));
|
||||
void animate_menu_list(MenuData *m);
|
||||
void menu_commonaction_close(MenuData *menu, void *arg);
|
||||
|
||||
#endif
|
||||
|
|
|
@ -9,7 +9,7 @@
|
|||
#include "options.h"
|
||||
#include "global.h"
|
||||
|
||||
void set_difficulty(void *d) {
|
||||
void set_difficulty(MenuData *m, void *d) {
|
||||
global.diff = (Difficulty) (uintptr_t) d;
|
||||
}
|
||||
|
||||
|
|
|
@ -10,7 +10,7 @@
|
|||
#include "gameovermenu.h"
|
||||
#include "global.h"
|
||||
|
||||
void continue_game(void *arg)
|
||||
void continue_game(MenuData *m, void *arg)
|
||||
{
|
||||
printf("The game is being continued...\n");
|
||||
|
||||
|
@ -28,11 +28,11 @@ void continue_game(void *arg)
|
|||
delete_projectiles(&global.particles);
|
||||
}
|
||||
|
||||
void give_up(void *arg) {
|
||||
void give_up(MenuData *m, void *arg) {
|
||||
global.game_over = (MAX_CONTINUES - global.plr.continues)? GAMEOVER_ABORT : GAMEOVER_DEFEAT;
|
||||
}
|
||||
|
||||
void restart_game(void *arg);
|
||||
void restart_game(MenuData *m, void *arg);
|
||||
|
||||
void create_gameover_menu(MenuData *m) {
|
||||
create_menu(m);
|
||||
|
|
|
@ -11,14 +11,14 @@
|
|||
#include "global.h"
|
||||
#include "stage.h"
|
||||
|
||||
void return_to_game(void *arg) {
|
||||
void return_to_game(MenuData *m, void *arg) {
|
||||
}
|
||||
|
||||
void return_to_title(void *arg) {
|
||||
void return_to_title(MenuData *m, void *arg) {
|
||||
global.game_over = GAMEOVER_ABORT;
|
||||
}
|
||||
|
||||
void restart_game(void *arg) {
|
||||
void restart_game(MenuData *m, void *arg) {
|
||||
global.game_over = GAMEOVER_RESTART;
|
||||
}
|
||||
|
||||
|
|
|
@ -18,19 +18,19 @@
|
|||
#include "stage.h"
|
||||
#include "paths/native.h"
|
||||
|
||||
void enter_options(void *arg) {
|
||||
void enter_options(MenuData *menu, void *arg) {
|
||||
MenuData m;
|
||||
create_options_menu(&m);
|
||||
options_menu_loop(&m);
|
||||
}
|
||||
|
||||
void enter_stagemenu(void *arg) {
|
||||
void enter_stagemenu(MenuData *menu, void *arg) {
|
||||
MenuData m;
|
||||
create_stage_menu(&m);
|
||||
stage_menu_loop(&m);
|
||||
}
|
||||
|
||||
void enter_replayview(void *arg) {
|
||||
void enter_replayview(MenuData *menu, void *arg) {
|
||||
MenuData m;
|
||||
create_replayview_menu(&m);
|
||||
replayview_menu_loop(&m);
|
||||
|
|
|
@ -135,7 +135,7 @@ void menu_logic(MenuData *menu) {
|
|||
menu->quitframe = 0;
|
||||
}
|
||||
|
||||
menu->entries[menu->selected].action(menu->entries[menu->selected].arg);
|
||||
menu->entries[menu->selected].action(menu, menu->entries[menu->selected].arg);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -19,7 +19,10 @@ enum {
|
|||
FADE_TIME = 15
|
||||
};
|
||||
|
||||
typedef void (*MenuAction)(void*);
|
||||
typedef struct MenuData MenuData;
|
||||
|
||||
typedef void (*MenuAction)(MenuData*, void*);
|
||||
typedef bool (*MenuCallback)(MenuData*);
|
||||
|
||||
typedef struct {
|
||||
char *name;
|
||||
|
@ -45,7 +48,7 @@ enum MenuFlag {
|
|||
MF_AlwaysProcessInput = 16 // the menu will process input even during fadeouts
|
||||
};
|
||||
|
||||
enum MenuState{
|
||||
enum MenuState {
|
||||
MS_Normal = 0,
|
||||
MS_FadeOut,
|
||||
MS_Dead
|
||||
|
|
|
@ -336,7 +336,7 @@ void destroy_options_menu(MenuData *m) {
|
|||
//config_save(CONFIG_FILE);
|
||||
}
|
||||
|
||||
void do_nothing(void *arg) { }
|
||||
static void do_nothing(MenuData *menu, void *arg) { }
|
||||
|
||||
void create_options_sub(MenuData *m, char *s) {
|
||||
create_menu(m);
|
||||
|
@ -346,7 +346,7 @@ void create_options_sub(MenuData *m, char *s) {
|
|||
|
||||
#define bind_onoff(b) bind_addvalue(b, "on"); bind_addvalue(b, "off")
|
||||
|
||||
void options_sub_video(void *arg) {
|
||||
void options_sub_video(MenuData *parent, void *arg) {
|
||||
MenuData menu, *m;
|
||||
OptionBinding *b;
|
||||
m = &menu;
|
||||
|
@ -386,10 +386,10 @@ void options_sub_video(void *arg) {
|
|||
bind_setdependence(b, bind_stagebg_fpslimit_dependence);
|
||||
|
||||
add_menu_separator(m);
|
||||
add_menu_entry(m, "Back", (MenuAction)kill_menu, m);
|
||||
add_menu_entry(m, "Back", menu_commonaction_close, NULL);
|
||||
|
||||
options_menu_loop(m);
|
||||
((MenuData*)arg)->frames = 0;
|
||||
parent->frames = 0;
|
||||
}
|
||||
|
||||
void bind_setvaluerange_fancy(OptionBinding *b, int ma) {
|
||||
|
@ -404,7 +404,7 @@ bool gamepad_sens_depencence(void) {
|
|||
return tconfig.intval[GAMEPAD_AXIS_FREE];
|
||||
}
|
||||
|
||||
void options_sub_gamepad_controls(void *arg) {
|
||||
void options_sub_gamepad_controls(MenuData *parent, void *arg) {
|
||||
MenuData menu, *m;
|
||||
m = &menu;
|
||||
|
||||
|
@ -451,14 +451,14 @@ void options_sub_gamepad_controls(void *arg) {
|
|||
);
|
||||
|
||||
add_menu_separator(m);
|
||||
add_menu_entry(m, "Back", (MenuAction)kill_menu, m);
|
||||
add_menu_entry(m, "Back", menu_commonaction_close, NULL);
|
||||
|
||||
options_menu_loop(m);
|
||||
((MenuData*)arg)->frames = 0;
|
||||
parent->frames = 0;
|
||||
gamepad_restart();
|
||||
}
|
||||
|
||||
void options_sub_gamepad(void *arg) {
|
||||
void options_sub_gamepad(MenuData *parent, void *arg) {
|
||||
MenuData menu, *m;
|
||||
OptionBinding *b;
|
||||
m = &menu;
|
||||
|
@ -474,7 +474,7 @@ void options_sub_gamepad(void *arg) {
|
|||
); b->displaysingle = true;
|
||||
|
||||
add_menu_separator(m);
|
||||
add_menu_entry(m, "Customize controls...", options_sub_gamepad_controls, m);
|
||||
add_menu_entry(m, "Customize controls...", options_sub_gamepad_controls, NULL);
|
||||
|
||||
gamepad_init_bare();
|
||||
int cnt = gamepad_devicecount();
|
||||
|
@ -518,14 +518,14 @@ void options_sub_gamepad(void *arg) {
|
|||
);
|
||||
|
||||
add_menu_separator(m);
|
||||
add_menu_entry(m, "Back", (MenuAction)kill_menu, m);
|
||||
add_menu_entry(m, "Back", menu_commonaction_close, NULL);
|
||||
|
||||
options_menu_loop(m);
|
||||
((MenuData*)arg)->frames = 0;
|
||||
parent->frames = 0;
|
||||
gamepad_restart();
|
||||
}
|
||||
|
||||
void options_sub_controls(void *arg) {
|
||||
void options_sub_controls(MenuData *parent, void *arg) {
|
||||
MenuData menu, *m;
|
||||
m = &menu;
|
||||
|
||||
|
@ -588,10 +588,10 @@ void options_sub_controls(void *arg) {
|
|||
#endif
|
||||
|
||||
add_menu_separator(m);
|
||||
add_menu_entry(m, "Back", (MenuAction)kill_menu, m);
|
||||
add_menu_entry(m, "Back", menu_commonaction_close, NULL);
|
||||
|
||||
options_menu_loop(m);
|
||||
((MenuData*)arg)->frames = 0;
|
||||
parent->frames = 0;
|
||||
}
|
||||
|
||||
void create_options_menu(MenuData *m) {
|
||||
|
@ -635,12 +635,12 @@ void create_options_menu(MenuData *m) {
|
|||
);
|
||||
|
||||
add_menu_separator(m);
|
||||
add_menu_entry(m, "Video options...", options_sub_video, m);
|
||||
add_menu_entry(m, "Customize controls...", options_sub_controls, m);
|
||||
add_menu_entry(m, "Gamepad & Joystick options...", options_sub_gamepad, m);
|
||||
add_menu_entry(m, "Video options...", options_sub_video, NULL);
|
||||
add_menu_entry(m, "Customize controls...", options_sub_controls, NULL);
|
||||
add_menu_entry(m, "Gamepad & Joystick options...", options_sub_gamepad, NULL);
|
||||
add_menu_separator(m);
|
||||
|
||||
add_menu_entry(m, "Back", (MenuAction)kill_menu, m);
|
||||
add_menu_entry(m, "Back", menu_commonaction_close, NULL);
|
||||
}
|
||||
|
||||
// --- Drawing the menu --- //
|
||||
|
|
|
@ -23,21 +23,19 @@ typedef struct ReplayviewItemContext ReplayviewItemContext;
|
|||
|
||||
// Type of MenuData.context
|
||||
typedef struct ReplayviewContext {
|
||||
ReplayviewItemContext *commonictx;
|
||||
MenuData *submenu;
|
||||
int pickedstage;
|
||||
} ReplayviewContext;
|
||||
|
||||
// Type of MenuEntry.arg (which should be renamed to context, probably...)
|
||||
typedef struct ReplayviewItemContext {
|
||||
MenuData *menu;
|
||||
Replay *replay;
|
||||
char *replayname;
|
||||
} ReplayviewItemContext;
|
||||
|
||||
void start_replay(void *arg) {
|
||||
void start_replay(MenuData *menu, void *arg) {
|
||||
ReplayviewItemContext *ictx = arg;
|
||||
ReplayviewContext *mctx = ictx->menu->context;
|
||||
ReplayviewContext *mctx = menu->context;
|
||||
|
||||
Replay *rpy = ictx->replay;
|
||||
|
||||
|
@ -77,12 +75,12 @@ void start_replay(void *arg) {
|
|||
global.replay_stage = NULL;
|
||||
}
|
||||
|
||||
MenuData* replayview_sub_stageselect(ReplayviewItemContext *ictx) {
|
||||
MenuData* replayview_sub_stageselect(MenuData *menu, ReplayviewItemContext *ictx) {
|
||||
MenuData *m = malloc(sizeof(MenuData));
|
||||
Replay *rpy = ictx->replay;
|
||||
|
||||
create_menu(m);
|
||||
m->context = ictx->menu->context;
|
||||
m->context = menu->context;
|
||||
m->flags = MF_Transient | MF_Abortable;
|
||||
m->transition = 0;
|
||||
|
||||
|
@ -93,15 +91,15 @@ MenuData* replayview_sub_stageselect(ReplayviewItemContext *ictx) {
|
|||
return m;
|
||||
}
|
||||
|
||||
void replayview_run(void *arg) {
|
||||
void replayview_run(MenuData *menu, void *arg) {
|
||||
ReplayviewItemContext *ctx = arg;
|
||||
ReplayviewContext *menuctx = ctx->menu->context;
|
||||
ReplayviewContext *menuctx = menu->context;
|
||||
Replay *rpy = ctx->replay;
|
||||
|
||||
if(rpy->numstages > 1) {
|
||||
menuctx->submenu = replayview_sub_stageselect(ctx);
|
||||
menuctx->submenu = replayview_sub_stageselect(menu, ctx);
|
||||
} else {
|
||||
start_replay(ctx);
|
||||
start_replay(menu, ctx);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -302,7 +300,6 @@ int fill_replayview_menu(MenuData *m) {
|
|||
ReplayviewItemContext *ictx = malloc(sizeof(ReplayviewItemContext));
|
||||
memset(ictx, 0, sizeof(ReplayviewItemContext));
|
||||
|
||||
ictx->menu = m;
|
||||
ictx->replay = rpy;
|
||||
ictx->replayname = malloc(strlen(e->d_name) + 1);
|
||||
strcpy(ictx->replayname, e->d_name);
|
||||
|
@ -316,32 +313,24 @@ int fill_replayview_menu(MenuData *m) {
|
|||
return rpys;
|
||||
}
|
||||
|
||||
void replayview_abort(void *a) {
|
||||
kill_menu(((ReplayviewItemContext*)a)->menu);
|
||||
}
|
||||
|
||||
void create_replayview_menu(MenuData *m) {
|
||||
create_menu(m);
|
||||
|
||||
ReplayviewContext *ctx = malloc(sizeof(ReplayviewContext));
|
||||
memset(ctx, 0, sizeof(ReplayviewContext));
|
||||
|
||||
ctx->commonictx = malloc(sizeof(ReplayviewItemContext));
|
||||
memset(ctx->commonictx, 0, sizeof(ReplayviewItemContext));
|
||||
ctx->commonictx->menu = m;
|
||||
|
||||
m->context = ctx;
|
||||
m->flags = MF_Abortable;
|
||||
|
||||
int r = fill_replayview_menu(m);
|
||||
|
||||
if(!r) {
|
||||
add_menu_entry(m, "No replays available. Play the game and record some!", replayview_abort, ctx->commonictx);
|
||||
add_menu_entry(m, "No replays available. Play the game and record some!", menu_commonaction_close, NULL);
|
||||
} else if(r < 0) {
|
||||
add_menu_entry(m, "There was a problem getting the replay list :(", replayview_abort, ctx->commonictx);
|
||||
add_menu_entry(m, "There was a problem getting the replay list :(", menu_commonaction_close, NULL);
|
||||
} else {
|
||||
add_menu_separator(m);
|
||||
add_menu_entry(m, "Back", replayview_abort, ctx->commonictx);
|
||||
add_menu_entry(m, "Back", menu_commonaction_close, NULL);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -352,13 +341,6 @@ void replayview_menu_input(MenuData *m) {
|
|||
|
||||
void replayview_free(MenuData *m) {
|
||||
if(m->context) {
|
||||
ReplayviewContext *ctx = m->context;
|
||||
|
||||
if(ctx) {
|
||||
replayview_freearg(ctx->commonictx);
|
||||
ctx->commonictx = NULL;
|
||||
}
|
||||
|
||||
free(m->context);
|
||||
m->context = NULL;
|
||||
}
|
||||
|
|
|
@ -14,7 +14,7 @@
|
|||
#include "plrmodes.h"
|
||||
#include "common.h"
|
||||
|
||||
void save_rpy(void *a) {
|
||||
void save_rpy(MenuData *menu, void *a) {
|
||||
Replay *rpy = &global.replay;
|
||||
char strtime[128], name[128];
|
||||
time_t rawtime;
|
||||
|
|
|
@ -11,7 +11,7 @@
|
|||
|
||||
#include "menu.h"
|
||||
|
||||
void save_rpy(void*);
|
||||
void save_rpy(MenuData *menu, void*);
|
||||
void create_saverpy_menu(MenuData*);
|
||||
int saverpy_menu_loop(MenuData*);
|
||||
|
||||
|
|
|
@ -26,7 +26,7 @@ void create_stage_menu(MenuData *m) {
|
|||
}
|
||||
|
||||
add_menu_separator(m);
|
||||
add_menu_entry(m, "Back", (MenuAction)kill_menu, m);
|
||||
add_menu_entry(m, "Back", menu_commonaction_close, NULL);
|
||||
}
|
||||
|
||||
void draw_stage_menu(MenuData *m) {
|
||||
|
|
Loading…
Reference in a new issue