Skip to content
This repository has been archived by the owner on Oct 4, 2024. It is now read-only.

Commit

Permalink
input: fix retaining default layout conflicts
Browse files Browse the repository at this point in the history
Resolves #228.
  • Loading branch information
rr- committed Sep 9, 2024
1 parent 830af45 commit 3fc7ac0
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 16 deletions.
1 change: 1 addition & 0 deletions src/decomp/decomp.c
Original file line number Diff line number Diff line change
Expand Up @@ -3037,5 +3037,6 @@ void __cdecl S_SaveSettings(void)
SetRegistryBinaryValue(
"Layout", (uint8_t *)&g_Layout[1],
sizeof(uint16_t) * INPUT_ROLE_NUMBER_OF);
Input_CheckConflictsWithDefaults();
CloseGameRegistryKey();
}
15 changes: 15 additions & 0 deletions src/game/input.c
Original file line number Diff line number Diff line change
Expand Up @@ -127,3 +127,18 @@ const char *Input_GetKeyName(const uint16_t key)
{
return m_KeyNames[key];
}

void __cdecl Input_CheckConflictsWithDefaults(void)
{
for (int32_t i = 0; i < INPUT_ROLE_NUMBER_OF; i++) {
g_ConflictLayout[i] = false;
for (int32_t j = 0; j < INPUT_ROLE_NUMBER_OF; j++) {
const uint16_t key1 = Input_GetAssignedKey(0, i);
const uint16_t key2 = Input_GetAssignedKey(1, j);
if (key1 == key2) {
g_ConflictLayout[i] = true;
break;
}
}
}
}
2 changes: 2 additions & 0 deletions src/game/input.h
Original file line number Diff line number Diff line change
Expand Up @@ -73,3 +73,5 @@ uint16_t Input_GetAssignedKey(int32_t layout, INPUT_ROLE role);
const char *Input_GetLayoutName(int32_t layout);
const char *Input_GetRoleName(INPUT_ROLE role);
const char *Input_GetKeyName(uint16_t key);

void __cdecl Input_CheckConflictsWithDefaults(void);
16 changes: 1 addition & 15 deletions src/game/option/option_controls.c
Original file line number Diff line number Diff line change
Expand Up @@ -7,25 +7,11 @@
static UI_WIDGET *m_ControlsDialog;
static UI_CONTROLS_CONTROLLER m_ControlsDialogController;

void __cdecl Option_Controls_DefaultConflict(void)
{
for (int32_t i = 0; i < INPUT_ROLE_NUMBER_OF; i++) {
g_ConflictLayout[i] = false;
for (int32_t j = 0; j < INPUT_ROLE_NUMBER_OF; j++) {
const uint16_t key1 = Input_GetAssignedKey(0, i);
const uint16_t key2 = Input_GetAssignedKey(1, j);
if (key1 == key2) {
g_ConflictLayout[i] = true;
}
}
}
}

void Option_Controls_Shutdown(void)
{
m_ControlsDialog->free(m_ControlsDialog);
m_ControlsDialog = NULL;
Option_Controls_DefaultConflict();
Input_CheckConflictsWithDefaults();
}

void __cdecl Option_Controls(INVENTORY_ITEM *const item)
Expand Down
1 change: 0 additions & 1 deletion src/inject_exec.c
Original file line number Diff line number Diff line change
Expand Up @@ -384,7 +384,6 @@ static void Inject_Option(const bool enable)
INJECT(enable, 0x0044F520, Option_Detail);
INJECT(enable, 0x0044F800, Option_Sound);
INJECT(enable, 0x0044FCA0, Option_Compass);
INJECT(enable, 0x0044FDE0, Option_Controls_DefaultConflict);
INJECT(enable, 0x0044FE20, Option_Controls);
}

Expand Down

0 comments on commit 3fc7ac0

Please sign in to comment.