Commit 5fbeae0c authored by Dino Bollinger's avatar Dino Bollinger Committed by Richard Gobeille
Browse files

Duke3D: Introduce modern default keybind ordering

Can be changed with the cvar cl_keybindorder. Settings the value
to 0 restores the original classic keybind order, 1 uses the
modern ordering. Either mode is overridden by custom keybind orders.
parent 8982a256
......@@ -118,8 +118,7 @@ char gamefunctions[NUMGAMEFUNCTIONS][MAXGAMEFUNCLEN] =
"Toggle_Crouch",
};
// Note: ordering of gamefunctions is important, must not be changed
// note: internal ordering is important, must not be changed
const char internal_gamefunction_names[NUMGAMEFUNCTIONS][MAXGAMEFUNCLEN] =
{
"gamefunc_Move_Forward",
......@@ -203,6 +202,86 @@ const char internal_gamefunction_names[NUMGAMEFUNCTIONS][MAXGAMEFUNCLEN] =
"gamefunc_Toggle_Crouch",
};
// classic key order is just integer indices ascending, not listed
const int32_t keybind_order_modern[NUMGAMEFUNCTIONS] =
{
// WASD
gamefunc_Move_Forward,
gamefunc_Move_Backward,
gamefunc_Strafe_Left,
gamefunc_Strafe_Right,
// attacks
gamefunc_Fire,
gamefunc_Alt_Fire,
gamefunc_Quick_Kick,
// interact
gamefunc_Open,
gamefunc_Jump,
gamefunc_Crouch,
gamefunc_Toggle_Crouch,
// inventory
gamefunc_Inventory,
gamefunc_Inventory_Left,
gamefunc_Inventory_Right,
gamefunc_Holo_Duke,
gamefunc_Jetpack,
gamefunc_NightVision,
gamefunc_MedKit,
gamefunc_Steroids,
// weapon selection
gamefunc_Next_Weapon,
gamefunc_Previous_Weapon,
gamefunc_Last_Weapon,
gamefunc_Alt_Weapon,
gamefunc_Holster_Weapon,
gamefunc_Weapon_1,
gamefunc_Weapon_2,
gamefunc_Weapon_3,
gamefunc_Weapon_4,
gamefunc_Weapon_5,
gamefunc_Weapon_6,
gamefunc_Weapon_7,
gamefunc_Weapon_8,
gamefunc_Weapon_9,
gamefunc_Weapon_10,
// important utilities
gamefunc_Map,
gamefunc_Map_Follow_Mode,
gamefunc_Third_Person_View,
gamefunc_Shrink_Screen,
gamefunc_Enlarge_Screen,
gamefunc_Quick_Save,
gamefunc_Quick_Load,
gamefunc_Show_Console,
// rarely used or usually replaced
gamefunc_Run,
gamefunc_Strafe,
gamefunc_Aim_Up,
gamefunc_Aim_Down,
gamefunc_Center_View,
gamefunc_Turn_Left,
gamefunc_Turn_Right,
gamefunc_Look_Up,
gamefunc_Look_Down,
gamefunc_Look_Left,
gamefunc_Look_Right,
gamefunc_TurnAround,
gamefunc_Dpad_Select,
gamefunc_Dpad_Aiming,
// toggles that have corresponding menu options
gamefunc_Mouse_Aiming,
gamefunc_Toggle_Crosshair,
gamefunc_AutoRun,
// multiplayer
gamefunc_SendMessage,
gamefunc_Show_Opponents_Weapon,
gamefunc_See_Coop_View,
gamefunc_Show_DukeMatch_Scores,
};
int32_t keybind_order_custom[NUMGAMEFUNCTIONS] = {-1};
#ifdef __SETUP__
const char keydefaults[NUMGAMEFUNCTIONS*2][MAXGAMEFUNCLEN] =
......
......@@ -105,10 +105,15 @@ enum GameFunction_t
};
extern char gamefunctions[NUMGAMEFUNCTIONS][MAXGAMEFUNCLEN];
extern const char internal_gamefunctions[NUMGAMEFUNCTIONS][MAXGAMEFUNCLEN];
extern const char internal_gamefunction_names[NUMGAMEFUNCTIONS][MAXGAMEFUNCLEN];
extern const char keydefaults[NUMGAMEFUNCTIONS*2][MAXGAMEFUNCLEN];
extern const char oldkeydefaults[NUMGAMEFUNCTIONS*2][MAXGAMEFUNCLEN];
// classic order is just integers ascending, hence omitted
#define keybind_order_classic NULL
extern const int32_t keybind_order_modern[NUMGAMEFUNCTIONS];
extern int32_t keybind_order_custom[NUMGAMEFUNCTIONS];
#ifdef __cplusplus
}
#endif
......
......@@ -5841,7 +5841,7 @@ static int parsedefinitions_game(scriptfile *pScript, int firstPass)
continue;
}
g_keyEntryOrder[currSlot] = keyIndex;
keybind_order_custom[currSlot] = keyIndex;
gamefunc_bitmap |= (1ULL << keyIndex);
currSlot++;
}
......@@ -5849,7 +5849,7 @@ static int parsedefinitions_game(scriptfile *pScript, int firstPass)
// fill up remaining slots
while(currSlot < NUMGAMEFUNCTIONS)
{
g_keyEntryOrder[currSlot] = -1;
keybind_order_custom[currSlot] = -1;
currSlot++;
}
......
......@@ -210,8 +210,6 @@ they effectively stand in for curly braces as struct initializers.
MenuGameplayEntry g_MenuGameplayEntries[MAXMENUGAMEPLAYENTRIES];
int32_t g_keyEntryOrder[NUMGAMEFUNCTIONS] = {-1};
// common font types
// tilenums are set after namesdyn runs
......@@ -289,13 +287,14 @@ static MenuOptionSet_t MEOS_NoYes = MAKE_MENUOPTIONSET( MEOSN_NoYes, NULL, 0x3 )
static char const *MEOSN_YesNo[] = { "Yes", "No", };
static MenuOptionSet_t MEOS_YesNo = MAKE_MENUOPTIONSET( MEOSN_YesNo, NULL, 0x3 );
static char MenuGameFuncs[NUMGAMEFUNCTIONS][MAXGAMEFUNCLEN];
static char const *MenuGameFuncNone = " -None-";
static char const *MEOSN_Gamefuncs[NUMGAMEFUNCTIONS+1];
static int32_t MEOSV_Gamefuncs[NUMGAMEFUNCTIONS+1];
static MenuOptionSet_t MEOS_Gamefuncs = MAKE_MENUOPTIONSET( MEOSN_Gamefuncs, MEOSV_Gamefuncs, 0x1 );
int32_t kbo_type_cvar = 1;
static int g_lookAxis = -1;
static int g_turnAxis = -1;
......@@ -1933,6 +1932,21 @@ It also initializes some data in loops rather than statically at compile time.
void Menu_Init(void)
{
int32_t i, j, k;
int32_t const *init_keybind_order = NULL;
// always prefer custom order, defined by DEF script
if (keybind_order_custom[0] >= 0)
init_keybind_order = keybind_order_custom;
else
{
// else, change based on cvar
if (kbo_type_cvar == 1)
init_keybind_order = keybind_order_modern;
else
init_keybind_order = keybind_order_classic;
}
bool do_reorder_keys = (init_keybind_order && init_keybind_order[0] >= 0);
if (FURY)
{
......@@ -1954,9 +1968,8 @@ void Menu_Init(void)
// prepare gamefuncs and keys
MEOSN_Gamefuncs[0] = MenuGameFuncNone;
MEOSV_Gamefuncs[0] = -1;
k = 1;
bool customKeyOrder = (g_keyEntryOrder[0] >= 0);
k = 1;
for (i = 0; i < NUMGAMEFUNCTIONS; ++i)
{
Bstrcpy(MenuGameFuncs[i], gamefunctions[i]);
......@@ -1965,7 +1978,7 @@ void Menu_Init(void)
if (MenuGameFuncs[i][j] == '_')
MenuGameFuncs[i][j] = ' ';
j = customKeyOrder ? g_keyEntryOrder[i] : i;
j = (do_reorder_keys) ? init_keybind_order[i] : i;
if (j >= 0 && gamefunctions[j][0] != '\0')
{
......@@ -1974,8 +1987,9 @@ void Menu_Init(void)
++k;
}
}
// 4 -- unsorted list
MEOS_Gamefuncs.features |= customKeyOrder ? 4 : 0;
MEOS_Gamefuncs.features |= (do_reorder_keys) ? 4 : 0;
MEOS_Gamefuncs.numOptions = k;
for (i = 1; i < NUMKEYS-1; ++i)
......@@ -2210,13 +2224,13 @@ void Menu_Init(void)
}
//reorder entries if defined
if (g_keyEntryOrder[0] != -1)
if (do_reorder_keys)
{
MenuEntry_t* tempkeyboardfuncs[NUMGAMEFUNCTIONS];
for (i = 0; i < NUMGAMEFUNCTIONS; ++i)
{
if (g_keyEntryOrder[i] >= 0)
tempkeyboardfuncs[i] = MEL_KEYBOARDSETUPFUNCS[g_keyEntryOrder[i]];
if (init_keybind_order[i] >= 0)
tempkeyboardfuncs[i] = MEL_KEYBOARDSETUPFUNCS[init_keybind_order[i]];
else
tempkeyboardfuncs[i] = NULL;
}
......
......@@ -38,6 +38,8 @@ extern "C" {
# define EDUKE32_ANDROID_MENU
#endif
extern int32_t kbo_type_cvar;
// #define EDUKE32_SIMPLE_MENU
enum MenuIndex_t {
......@@ -536,8 +538,6 @@ extern MenuEntry_t ME_NEWGAMECUSTOMENTRIES[MAXMENUGAMEPLAYENTRIES];
extern MenuEntry_t ME_NEWGAMECUSTOMSUBENTRIES[MAXMENUGAMEPLAYENTRIES][MAXMENUGAMEPLAYENTRIES];
extern MenuEntry_t ME_NEWGAMECUSTOML3ENTRIES[MAXMENUGAMEPLAYENTRIES][MAXMENUGAMEPLAYENTRIES][MAXMENUGAMEPLAYENTRIES];
extern int32_t g_keyEntryOrder[NUMGAMEFUNCTIONS];
#ifdef __cplusplus
}
#endif
......
......@@ -1607,6 +1607,8 @@ int32_t registerosdcommands(void)
{ "cl_weaponsway", "weapon sways when moving" CVAR_BOOL_OPTSTR, (void *)&ud.weaponsway, CVAR_BOOL, 0, 1 },
{ "cl_weaponswitch", "bitmask controlling switching weapon when out of ammo or a new weapon is picked up:\n 0: disabled\n 1: if new\n 2: if empty\n 4: determined by wchoice", (void *)&ud.weaponswitch, CVAR_INT|CVAR_MULTI, 0, 7 },
{ "cl_keybindorder", "default order for the keybind menu (overridden by custom order, requires a restart):\n 0: classic\n 1: modern", (void *)&kbo_type_cvar, CVAR_BOOL, 0, 1 },
{ "color", "player palette", (void *)&ud.color, CVAR_INT|CVAR_MULTI, 0, MAXPALOOKUPS-1 },
{ "crosshairscale","crosshair size", (void *)&ud.crosshairscale, CVAR_INT, 10, 100 },
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment