Skip to content

Commit

Permalink
id_in: id_us_1: Save/Load Keyboard controls from OMNISPK.CFG (fixes #53)
Browse files Browse the repository at this point in the history
We now save and load the keyboard bindings from OMNISPK.CFG, which
includes the new options (like QuickSave and QuickLoad), which
previously weren't saved anywhere.

By default, the bindings configured in CONFIG.CKx still take preference:
Omnispeak will save and load what it can from there. This can be
controlled by the "in_preferOmnispeakKeyConfig" option:
- if "false", Omnispeak will still load from OMNISPK.CFG if no
  CONFIG.CKx is found, and will still save the "new" options to
  OMNISPK.CFG. The old options will not be saved.
- if "true", Omnispeak will load from both OMNISPK.CFG and CONFIG.CKx,
  with values from OMNISPK.CFG taking preference. All bindings will be
  saved to OMNISPK.CFG.
- if left unset, the default is "false", except all options are written
  to OMNISPK.CFG (even if the CONFIG.CKx versions will override them on
  load)

Note that the values for the different options (all starting "in_kbd_")
are the raw integer scancodes. Maybe in the future, I'll make it a more
pleasant-to-use enum. But for now, this'll do.

This fixes the issue (#53) reported by Roobar in:
https://pckf.com/viewtopic.php?p=106644#p106644
  • Loading branch information
sulix committed Dec 22, 2022
1 parent f0c35b2 commit 8de8082
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 16 deletions.
59 changes: 43 additions & 16 deletions src/id_in.c
Expand Up @@ -245,26 +245,53 @@ void IN_HandleKeyDown(IN_ScanCode sc, bool special)
}
}

static void INL_SetupKbdControls()
void IN_SetupKbdControls()
{
in_kbdControls.jump = IN_SC_Control;
in_kbdControls.pogo = IN_SC_Alt;
in_kbdControls.fire = IN_SC_Space;
in_kbdControls.jump = CFG_GetConfigInt("in_kbd_jump", IN_SC_Control);
in_kbdControls.pogo = CFG_GetConfigInt("in_kbd_pogo", IN_SC_Alt);
in_kbdControls.fire = CFG_GetConfigInt("in_kbd_fire", IN_SC_Space);
#ifdef EXTRA_KEYBOARD_OPTIONS
in_kbdControls.status = IN_SC_Enter;
in_kbdControls.status = CFG_GetConfigInt("in_kbd_status", IN_SC_Enter);
#endif
#ifdef QUICKSAVE_ENABLED
in_kbdControls.quickSave = IN_SC_F5;
in_kbdControls.quickLoad = IN_SC_F9;
in_kbdControls.quickSave = CFG_GetConfigInt("in_kbd_quickSave", IN_SC_F5);
in_kbdControls.quickLoad = CFG_GetConfigInt("in_kbd_quickLoad", IN_SC_F9);;
#endif
in_kbdControls.up = CFG_GetConfigInt("in_kbd_up", IN_SC_UpArrow);
in_kbdControls.down = CFG_GetConfigInt("in_kbd_down", IN_SC_DownArrow);
in_kbdControls.left = CFG_GetConfigInt("in_kbd_left", IN_SC_LeftArrow);
in_kbdControls.right = CFG_GetConfigInt("in_kbd_right", IN_SC_RightArrow);
in_kbdControls.upLeft = CFG_GetConfigInt("in_kbd_upLeft", IN_SC_Home);
in_kbdControls.upRight = CFG_GetConfigInt("in_kbd_upRight", IN_SC_PgUp);
in_kbdControls.downRight = CFG_GetConfigInt("in_kbd_downRight", IN_SC_PgDown);
in_kbdControls.downLeft = CFG_GetConfigInt("in_kbd_downLeft", IN_SC_End);
}

void IN_SaveKbdControls()
{
if (CFG_GetConfigBool("in_preferOmnispeakKeyConfig", true))
{
CFG_SetConfigInt("in_kbd_jump", in_kbdControls.jump);
CFG_SetConfigInt("in_kbd_pogo", in_kbdControls.pogo);
CFG_SetConfigInt("in_kbd_fire", in_kbdControls.fire);

CFG_SetConfigInt("in_kbd_up", in_kbdControls.up);
CFG_SetConfigInt("in_kbd_down", in_kbdControls.down);
CFG_SetConfigInt("in_kbd_left", in_kbdControls.left);
CFG_SetConfigInt("in_kbd_right", in_kbdControls.right);
CFG_SetConfigInt("in_kbd_upLeft", in_kbdControls.upLeft);
CFG_SetConfigInt("in_kbd_upRight", in_kbdControls.upRight);
CFG_SetConfigInt("in_kbd_downRight", in_kbdControls.downRight);
CFG_SetConfigInt("in_kbd_downLeft", in_kbdControls.downLeft);
}

#ifdef EXTRA_KEYBOARD_OPTIONS
CFG_SetConfigInt("in_kbd_status", in_kbdControls.status);
#endif
#ifdef QUICKSAVE_ENABLED
CFG_SetConfigInt("in_kbd_quickSave", in_kbdControls.quickSave);
CFG_SetConfigInt("in_kbd_quickLoad", in_kbdControls.quickLoad);;
#endif
in_kbdControls.up = IN_SC_UpArrow;
in_kbdControls.down = IN_SC_DownArrow;
in_kbdControls.left = IN_SC_LeftArrow;
in_kbdControls.right = IN_SC_RightArrow;
in_kbdControls.upLeft = IN_SC_Home;
in_kbdControls.upRight = IN_SC_PgUp;
in_kbdControls.downRight = IN_SC_PgDown;
in_kbdControls.downLeft = IN_SC_End;
}

void IN_PumpEvents()
Expand Down Expand Up @@ -378,7 +405,7 @@ void IN_Startup(void)
in_keyStates[i] = 0;

// Set the default kbd controls.
INL_SetupKbdControls();
IN_SetupKbdControls();

in_backend->startup(in_disableJoysticks);
}
Expand Down
2 changes: 2 additions & 0 deletions src/id_in.h
Expand Up @@ -276,6 +276,8 @@ typedef enum IN_JoyConfItem

void IN_PumpEvents();
void IN_WaitKey();
void IN_SetupKbdControls();
void IN_SaveKbdControls();
const char *IN_GetScanName(IN_ScanCode scan);
bool IN_GetKeyState(IN_ScanCode scanCode);
IN_ScanCode IN_GetLastScan(void);
Expand Down
4 changes: 4 additions & 0 deletions src/id_us_1.c
Expand Up @@ -749,6 +749,8 @@ void US_LoadConfig(void)
SD_SetQuietSfx(hadQuietSfx);
SD_Default(configFileLoaded && (hadAdlib == SD_IsAdlibPresent()), sd, sm);
IN_Default(configFileLoaded, inputDevice);
if (CFG_GetConfigBool("in_preferOmnispeakKeyConfig", false))
IN_SetupKbdControls();
}

void US_SaveConfig(void)
Expand Down Expand Up @@ -808,6 +810,8 @@ void US_SaveConfig(void)
FS_WriteBoolTo16LE(&ck_gamePadEnabled, 1, f);
FS_WriteInt16LE(in_gamepadButtons, 4, f);
FS_CloseFile(f);

IN_SaveKbdControls();
}

//
Expand Down

0 comments on commit 8de8082

Please sign in to comment.