simplify options menu definitions

This commit is contained in:
fgsfds 2020-05-16 15:00:35 +03:00
parent dbca0c413d
commit 92c75fb21b

View File

@ -132,6 +132,23 @@ struct SubMenu {
s32 scroll; s32 scroll;
}; };
/* helper macros */
#define DEF_OPT_TOGGLE(lbl, bv) \
{ .type = OPT_TOGGLE, .label = lbl, .bval = bv }
#define DEF_OPT_SCROLL(lbl, uv, min, max, st) \
{ .type = OPT_SCROLL, .label = lbl, .uval = uv, .scrMin = min, .scrMax = max, .scrStep = st }
#define DEF_OPT_CHOICE(lbl, uv, ch) \
{ .type = OPT_CHOICE, .label = lbl, .uval = uv, .choices = ch, .numChoices = sizeof(ch) / sizeof(ch[0]) }
#define DEF_OPT_SUBMENU(lbl, nm) \
{ .type = OPT_SUBMENU, .label = lbl, .nextMenu = nm }
#define DEF_OPT_BIND(lbl, uv) \
{ .type = OPT_BIND, .label = lbl, .uval = uv }
#define DEF_OPT_BUTTON(lbl, act) \
{ .type = OPT_BUTTON, .label = lbl, .actionFn = act }
#define DEF_SUBMENU(lbl, opt) \
{ .label = lbl, .opts = opt, .numOpts = sizeof(opt) / sizeof(opt[0]) }
/* button action functions */ /* button action functions */
static void optmenu_act_exit(UNUSED struct Option *self, s32 arg) { static void optmenu_act_exit(UNUSED struct Option *self, s32 arg) {
@ -141,72 +158,54 @@ static void optmenu_act_exit(UNUSED struct Option *self, s32 arg) {
/* submenu option lists */ /* submenu option lists */
static struct Option optsCamera[] = { static struct Option optsCamera[] = {
{ .type = OPT_TOGGLE, .label = optsCameraStr[6], .bval = &configEnableCamera, }, DEF_OPT_TOGGLE( optsCameraStr[6], &configEnableCamera ),
{ .type = OPT_TOGGLE, .label = optsCameraStr[7], .bval = &configCameraMouse, }, DEF_OPT_TOGGLE( optsCameraStr[7], &configCameraMouse ),
{ .type = OPT_TOGGLE, .label = optsCameraStr[2], .bval = &configCameraInvertX, }, DEF_OPT_TOGGLE( optsCameraStr[2], &configCameraInvertX ),
{ .type = OPT_TOGGLE, .label = optsCameraStr[3], .bval = &configCameraInvertY, }, DEF_OPT_TOGGLE( optsCameraStr[3], &configCameraInvertY ),
{ .type = OPT_SCROLL, .label = optsCameraStr[0], .uval = &configCameraXSens, .scrMin = 10, .scrMax = 250, .scrStep = 1 }, DEF_OPT_SCROLL( optsCameraStr[0], &configCameraXSens, 10, 250, 1 ),
{ .type = OPT_SCROLL, .label = optsCameraStr[1], .uval = &configCameraYSens, .scrMin = 10, .scrMax = 250, .scrStep = 1 }, DEF_OPT_SCROLL( optsCameraStr[1], &configCameraYSens, 10, 250, 1 ),
{ .type = OPT_SCROLL, .label = optsCameraStr[4], .uval = &configCameraAggr, .scrMin = 0, .scrMax = 100, .scrStep = 1 }, DEF_OPT_SCROLL( optsCameraStr[4], &configCameraAggr, 0, 100, 1 ),
{ .type = OPT_SCROLL, .label = optsCameraStr[5], .uval = &configCameraPan, .scrMin = 0, .scrMax = 100, .scrStep = 1 }, DEF_OPT_SCROLL( optsCameraStr[5], &configCameraPan, 0, 100, 1 ),
}; };
static struct Option optsControls[] = { static struct Option optsControls[] = {
{ .type = OPT_BIND, .label = bindStr[2], .uval = configKeyA, }, DEF_OPT_BIND( bindStr[ 2], configKeyA ),
{ .type = OPT_BIND, .label = bindStr[3], .uval = configKeyB, }, DEF_OPT_BIND( bindStr[ 3], configKeyB ),
{ .type = OPT_BIND, .label = bindStr[4], .uval = configKeyStart, }, DEF_OPT_BIND( bindStr[ 4], configKeyStart ),
{ .type = OPT_BIND, .label = bindStr[5], .uval = configKeyL, }, DEF_OPT_BIND( bindStr[ 5], configKeyL ),
{ .type = OPT_BIND, .label = bindStr[6], .uval = configKeyR, }, DEF_OPT_BIND( bindStr[ 6], configKeyR ),
{ .type = OPT_BIND, .label = bindStr[7], .uval = configKeyZ, }, DEF_OPT_BIND( bindStr[ 7], configKeyZ ),
{ .type = OPT_BIND, .label = bindStr[8], .uval = configKeyCUp, }, DEF_OPT_BIND( bindStr[ 8], configKeyCUp ),
{ .type = OPT_BIND, .label = bindStr[9], .uval = configKeyCDown, }, DEF_OPT_BIND( bindStr[ 9], configKeyCDown ),
{ .type = OPT_BIND, .label = bindStr[10], .uval = configKeyCLeft, }, DEF_OPT_BIND( bindStr[10], configKeyCLeft ),
{ .type = OPT_BIND, .label = bindStr[11], .uval = configKeyCRight, }, DEF_OPT_BIND( bindStr[11], configKeyCRight ),
{ .type = OPT_BIND, .label = bindStr[12], .uval = configKeyStickUp, }, DEF_OPT_BIND( bindStr[12], configKeyStickUp ),
{ .type = OPT_BIND, .label = bindStr[13], .uval = configKeyStickDown, }, DEF_OPT_BIND( bindStr[13], configKeyStickDown ),
{ .type = OPT_BIND, .label = bindStr[14], .uval = configKeyStickLeft, }, DEF_OPT_BIND( bindStr[14], configKeyStickLeft ),
{ .type = OPT_BIND, .label = bindStr[15], .uval = configKeyStickRight, }, DEF_OPT_BIND( bindStr[15], configKeyStickRight ),
}; };
static struct Option optsVideo[] = { static struct Option optsVideo[] = {
{ .type = OPT_TOGGLE, .label = optsVideoStr[0], .bval = &configFullscreen, }, DEF_OPT_TOGGLE( optsVideoStr[0], &configFullscreen ),
{ .type = OPT_CHOICE, .label = optsVideoStr[1], .uval = &configFiltering, .choices = filterChoices, .numChoices = 2 }, DEF_OPT_CHOICE( optsVideoStr[1], &configFiltering, filterChoices ),
}; };
/* submenu definitions */ /* submenu definitions */
static struct SubMenu menuCamera = { static struct SubMenu menuCamera = DEF_SUBMENU( menuStr[4], optsCamera );
.label = menuStr[4], static struct SubMenu menuControls = DEF_SUBMENU( menuStr[5], optsControls );
.opts = optsCamera, static struct SubMenu menuVideo = DEF_SUBMENU( menuStr[6], optsVideo );
.numOpts = sizeof(optsCamera) / sizeof(optsCamera[0]),
};
static struct SubMenu menuControls = {
.label = menuStr[5],
.opts = optsControls,
.numOpts = sizeof(optsControls) / sizeof(optsControls[0]),
};
static struct SubMenu menuVideo = {
.label = menuStr[6],
.opts = optsVideo,
.numOpts = sizeof(optsVideo) / sizeof(optsVideo[0]),
};
/* main options menu definition */ /* main options menu definition */
static struct Option optsMain[] = { static struct Option optsMain[] = {
{ .type = OPT_SUBMENU, .label = menuStr[4], .nextMenu = &menuCamera, }, DEF_OPT_SUBMENU( menuStr[4], &menuCamera ),
{ .type = OPT_SUBMENU, .label = menuStr[5], .nextMenu = &menuControls, }, DEF_OPT_SUBMENU( menuStr[5], &menuControls ),
{ .type = OPT_SUBMENU, .label = menuStr[6], .nextMenu = &menuVideo, }, DEF_OPT_SUBMENU( menuStr[6], &menuVideo ),
{ .type = OPT_BUTTON, .label = menuStr[7], .actionFn = optmenu_act_exit, }, DEF_OPT_BUTTON ( menuStr[7], optmenu_act_exit ),
}; };
static struct SubMenu menuMain = { static struct SubMenu menuMain = DEF_SUBMENU( menuStr[3], optsMain );
.label = menuStr[3],
.opts = optsMain,
.numOpts = sizeof(optsMain) / sizeof(optsMain[0]),
};
/* implementation */ /* implementation */