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

Duke3D: Implement reordering of keyboard menu entries via DEF command

List the gamefunc names (or corresponding indices) separated by whitespace.
This will define the order of gamefuncs on the keyboard configuration menu.
Any omitted gamefuncs will not be listed in the menu.

Usage:
```
keyconfig
{
    gamefunc_Move_Forward
    gamefunc_Move_Backward
    gamefunc_Strafe_Left
    gamefunc_Strafe_Right
    ...
}
```
parent 9107b896
......@@ -413,6 +413,7 @@ static int32_t defsparser(scriptfile *script)
{ "newgamechoices", T_STUB_BRACES },
{ "animsounds", T_STUB_STRING_BRACES },
{ "cutscene", T_STUB_STRING_BRACES },
{ "keyconfig", T_STUB_BRACES },
};
while (1)
......
......@@ -118,6 +118,91 @@ char gamefunctions[NUMGAMEFUNCTIONS][MAXGAMEFUNCLEN] =
"Toggle_Crouch",
};
// Note: ordering of gamefunctions is important, must not be changed
const char internal_gamefunction_names[NUMGAMEFUNCTIONS][MAXGAMEFUNCLEN] =
{
"gamefunc_Move_Forward",
"gamefunc_Move_Backward",
"gamefunc_Turn_Left",
"gamefunc_Turn_Right",
"gamefunc_Strafe",
"gamefunc_Fire",
"gamefunc_Open",
"gamefunc_Run",
"gamefunc_Alt_Fire",
"gamefunc_Jump",
"gamefunc_Crouch",
"gamefunc_Look_Up",
"gamefunc_Look_Down",
"gamefunc_Look_Left",
"gamefunc_Look_Right",
"gamefunc_Strafe_Left",
"gamefunc_Strafe_Right",
"gamefunc_Aim_Up",
"gamefunc_Aim_Down",
"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",
"gamefunc_Inventory",
"gamefunc_Inventory_Left",
"gamefunc_Inventory_Right",
#ifndef EDUKE32_STANDALONE
"gamefunc_Holo_Duke",
"gamefunc_Jetpack",
"gamefunc_NightVision",
"gamefunc_MedKit",
#else
"gamefunc_Inventory_Hotkey_1",
"gamefunc_Inventory_Hotkey_2",
"gamefunc_Inventory_Hotkey_3",
"gamefunc_Inventory_Hotkey_4",
#endif
"gamefunc_TurnAround",
"gamefunc_SendMessage",
"gamefunc_Map",
"gamefunc_Shrink_Screen",
"gamefunc_Enlarge_Screen",
"gamefunc_Center_View",
"gamefunc_Holster_Weapon",
"gamefunc_Show_Opponents_Weapon",
"gamefunc_Map_Follow_Mode",
"gamefunc_See_Coop_View",
"gamefunc_Mouse_Aiming",
"gamefunc_Toggle_Crosshair",
#ifndef EDUKE32_STANDALONE
"gamefunc_Steroids",
"gamefunc_Quick_Kick",
#else
"gamefunc_Inventory_Hotkey_5",
"gamefunc_Melee_Hotkey",
#endif
"gamefunc_Next_Weapon",
"gamefunc_Previous_Weapon",
"gamefunc_Show_Console",
#ifndef EDUKE32_STANDALONE
"gamefunc_Show_DukeMatch_Scores",
#else
"gamefunc_Show_Multiplayer_Scores",
#endif
"gamefunc_Dpad_Select",
"gamefunc_Dpad_Aiming",
"gamefunc_AutoRun",
"gamefunc_Last_Weapon",
"gamefunc_Quick_Save",
"gamefunc_Quick_Load",
"gamefunc_Alt_Weapon",
"gamefunc_Third_Person_View",
"gamefunc_Toggle_Crouch",
};
#ifdef __SETUP__
const char keydefaults[NUMGAMEFUNCTIONS*2][MAXGAMEFUNCLEN] =
......
......@@ -105,6 +105,7 @@ enum GameFunction_t
};
extern char gamefunctions[NUMGAMEFUNCTIONS][MAXGAMEFUNCLEN];
extern const char internal_gamefunctions[NUMGAMEFUNCTIONS][MAXGAMEFUNCLEN];
extern const char keydefaults[NUMGAMEFUNCTIONS*2][MAXGAMEFUNCLEN];
extern const char oldkeydefaults[NUMGAMEFUNCTIONS*2][MAXGAMEFUNCLEN];
......
......@@ -185,6 +185,7 @@ enum gametokens
T_HIDDEN,
T_USERCONTENT,
T_LOCALIZATION,
T_KEYCONFIG,
};
static void gameTimerHandler(void)
......@@ -5411,6 +5412,7 @@ static int parsedefinitions_game(scriptfile *pScript, int firstPass)
{ "globalgameflags", T_GLOBALGAMEFLAGS },
{ "newgamechoices", T_NEWGAMECHOICES },
{ "localization" , T_LOCALIZATION },
{ "keyconfig" , T_KEYCONFIG },
};
static const tokenlist soundTokens[] =
......@@ -5435,6 +5437,10 @@ static int parsedefinitions_game(scriptfile *pScript, int firstPass)
{ "texturefilter", T_TEXTUREFILTER },
};
for (int f = 0; f < NUMGAMEFUNCTIONS; f++)
scriptfile_addsymbolvalue(internal_gamefunction_names[f], f);
do
{
token = getatoken(pScript, tokens, ARRAY_SIZE(tokens));
......@@ -5789,6 +5795,77 @@ static int parsedefinitions_game(scriptfile *pScript, int firstPass)
break;
}
case T_KEYCONFIG:
{
char *keyRemapEnd;
int32_t currSlot = 0, keyIndex;
// will require a longer bitmap if additional gamefuncs are added
uint64_t gamefunc_bitmap = 0ULL;
Bassert(NUMGAMEFUNCTIONS <= 64);
if (scriptfile_getbraces(pScript, &keyRemapEnd))
break;
if (firstPass)
{
pScript->textptr = keyRemapEnd+1;
break;
}
while (pScript->textptr < keyRemapEnd - 1)
{
char * mapPtr = pScript->ltextptr;
if (currSlot >= NUMGAMEFUNCTIONS)
{
initprintf("Error: Key remap exceeds number of valid gamefunctions %d near line %s:%d\n",
NUMGAMEFUNCTIONS, pScript->filename, scriptfile_getlinum(pScript, mapPtr));
pScript->textptr = keyRemapEnd+1;
break;
}
if (scriptfile_getsymbol(pScript, &keyIndex))
continue;
if (keyIndex < 0 || keyIndex >= NUMGAMEFUNCTIONS)
{
initprintf("Error: Invalid key index %d near line %s:%d\n",
keyIndex, pScript->filename, scriptfile_getlinum(pScript, mapPtr));
continue;
}
else if (gamefunc_bitmap & (1ULL << keyIndex))
{
initprintf("Warning: Duplicate listing of key \"%s\" near line %s:%d\n",
internal_gamefunction_names[keyIndex], pScript->filename, scriptfile_getlinum(pScript, mapPtr));
continue;
}
g_keyEntryOrder[currSlot] = keyIndex;
gamefunc_bitmap |= (1ULL << keyIndex);
currSlot++;
}
// fill up remaining slots
while(currSlot < NUMGAMEFUNCTIONS)
{
g_keyEntryOrder[currSlot] = -1;
currSlot++;
}
// undefine gamefuncs that are no longer listed
for(keyIndex = 0; keyIndex < NUMGAMEFUNCTIONS; keyIndex++)
{
if (!(gamefunc_bitmap & (1ULL << keyIndex)))
{
hash_delete(&h_gamefuncs, gamefunctions[keyIndex]);
gamefunctions[keyIndex][0] = '\0';
}
}
break;
}
case T_EOF: return 0;
default: break;
}
......
......@@ -202,6 +202,8 @@ extern int32_t g_gametypeFlags[MAXGAMETYPES];
extern int32_t g_volumeFlags[MAXVOLUMES];
extern const char *s_buildDate;
extern const char* g_internalFuncNameTokens[];
#endif
enum
......
......@@ -210,6 +210,8 @@ 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
......@@ -2200,6 +2202,21 @@ void Menu_Init(void)
MEO_KEYBOARDSETUPFUNCS[i].column[1] = &ud.config.KeyboardKeys[i][1];
MEO_KEYBOARDSETUPFUNCS[i].linkIndex = i;
}
//reorder entries if defined
if (g_keyEntryOrder[0] != -1)
{
MenuEntry_t* tempkeyboardfuncs[NUMGAMEFUNCTIONS];
for (i = 0; i < NUMGAMEFUNCTIONS; ++i)
{
if (g_keyEntryOrder[i] >= 0)
tempkeyboardfuncs[i] = MEL_KEYBOARDSETUPFUNCS[g_keyEntryOrder[i]];
else
tempkeyboardfuncs[i] = NULL;
}
Bmemcpy(MEL_KEYBOARDSETUPFUNCS, tempkeyboardfuncs, NUMGAMEFUNCTIONS * sizeof(MenuEntry_t*));
}
M_KEYBOARDKEYS.numEntries = NUMGAMEFUNCTIONS;
for (i = 0; i < ARRAY_SSIZE(MenuMouseData); ++i)
{
......
......@@ -27,6 +27,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
#include "compat.h"
#include "pragmas.h"
#include "vfs.h"
#include "function.h"
#ifdef __cplusplus
extern "C" {
......@@ -535,6 +536,8 @@ 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
......
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