From 90e9cc709a565a63ab7fec3dde7f509a25e4330f Mon Sep 17 00:00:00 2001 From: "theastropath@gmail.com" Date: Thu, 6 Jul 2023 21:26:18 -0400 Subject: [PATCH] Modify key customization screen so that we can add new entries, like a hotkey to open your bingo screen --- GUI/DeusEx/Classes/MenuScreenCustomizeKeys.uc | 783 ++++++++++++++++++ 1 file changed, 783 insertions(+) create mode 100644 GUI/DeusEx/Classes/MenuScreenCustomizeKeys.uc diff --git a/GUI/DeusEx/Classes/MenuScreenCustomizeKeys.uc b/GUI/DeusEx/Classes/MenuScreenCustomizeKeys.uc new file mode 100644 index 000000000..da12bbe42 --- /dev/null +++ b/GUI/DeusEx/Classes/MenuScreenCustomizeKeys.uc @@ -0,0 +1,783 @@ +//============================================================================= +// MenuScreenCustomizeKeys +// Duped for DXRando - Make sure this file name doesn't change. +// We rely on this overwriting the vanilla file +//============================================================================= + +class MenuScreenCustomizeKeys expands MenuUIScreenWindow; + +var MenuUIListHeaderButtonWindow btnHeaderAction; +var MenuUIListHeaderButtonWindow btnHeaderAssigned; +var MenuUIListWindow lstKeys; +var MenuUIScrollAreaWindow winScroll; + +struct S_KeyDisplayItem +{ + var EInputKey inputKey; + var localized String DisplayName; +}; + +//Make sure to update all four of these when you add a new binding +var localized string FunctionText[62]; +var string MenuValues1[62]; +var string MenuValues2[62]; +var string AliasNames[62]; + + +var string PendingCommands[100]; +var localized S_KeyDisplayItem keyDisplayNames[71]; +var localized string NoneText; +var int Pending; +var int selection; +var Bool bWaitingForInput; + +var localized string strHeaderActionLabel; +var localized string strHeaderAssignedLabel; +var localized string WaitingHelpText; +var localized string InputHelpText; +var localized string ReassignedFromLabel; + +// ---------------------------------------------------------------------- +// InitWindow() +// +// Initialize the Window +// ---------------------------------------------------------------------- + +event InitWindow() +{ + Super.InitWindow(); + + Pending = 0; + Selection = -1; + bWaitingForInput = False; + BuildKeyBindings(); + + CreateKeyList(); + CreateHeaderButtons(); + PopulateKeyList(); + ShowHelp(WaitingHelpText); +} + +// ---------------------------------------------------------------------- +// VirtualKeyPressed() +// ---------------------------------------------------------------------- + +event bool VirtualKeyPressed(EInputKey key, bool bRepeat) +{ + if ( !bWaitingForInput ) + { + // If the user presses [Delete] or [Backspace], then + // clear this setting + if ((key == IK_Delete) || (key == IK_Backspace)) + { + ClearFunction(); + return True; + } + else + { + return Super.VirtualKeyPressed(key, bRepeat); + } + } + + // First check to see if we're waiting for the user to select a + // keyboard or mouse/joystick button to override. + WaitingForInput(False); + + ProcessKeySelection( key, mid(string(GetEnum(enum'EInputKey',key)),3), GetKeyDisplayName(key) ); + + return True; +} + +// ---------------------------------------------------------------------- +// RawMouseButtonPressed() +// ---------------------------------------------------------------------- + +event bool RawMouseButtonPressed(float pointX, float pointY, + EInputKey button, EInputState iState) +{ + if ( !bWaitingForInput ) + return False; + + if ( iState != IST_Release ) + return True; + + // First check to see if we're waiting for the user to select a + // keyboard or mouse/joystick button to override. + // + // Ignore everything but mouse button and wheel presses + switch( button ) + { + case IK_MouseWheelUp: + case IK_MouseWheelDown: + case IK_LeftMouse: + case IK_RightMouse: + case IK_MiddleMouse: + ProcessKeySelection( button, mid(string(GetEnum(enum'EInputKey',button)),3), GetKeyDisplayName(button )); + WaitingForInput(False); + break; + } + + return True; +} + +// ---------------------------------------------------------------------- +// ListRowActivated() +// +// User double-clicked on one of the rows, meaning he/she/it wants +// to redefine one of the functions +// ---------------------------------------------------------------------- + +event bool ListRowActivated(window list, int rowId) +{ + // Show help + ShowHelp(InputHelpText); + + selection = lstKeys.RowIdToIndex(rowId); + + WaitingForInput(True); + + return True; +} + +// ---------------------------------------------------------------------- +// WaitingForInput() +// ---------------------------------------------------------------------- + +function WaitingForInput(bool bWaiting) +{ + if ( bWaiting ) + { + ShowHelp(InputHelpText); + + SetSelectability(True); + SetFocusWindow(Self); + GrabMouse(); + + root.LockMouse(True, False); + root.ShowCursor(False); + } + else + { + ShowHelp(WaitingHelpText); + + SetSelectability(False); + UngrabMouse(); + + root.LockMouse(False, False); + root.ShowCursor(True); + + // Set the focus back to the list + SetFocusWindow(lstKeys); + } + + bWaitingForInput = bWaiting; +} + +// ---------------------------------------------------------------------- +// SaveSettings() +// ---------------------------------------------------------------------- + +function SaveSettings() +{ + ProcessPending(); +} + +// ---------------------------------------------------------------------- +// ClearFunction() +// ---------------------------------------------------------------------- + +function ClearFunction() +{ + local int rowID; + local int rowIndex; + + rowID = lstKeys.GetSelectedRow(); + + if (rowID != 0) + { + rowIndex = lstKeys.RowIdToIndex(rowID); + + if (MenuValues2[rowIndex] != "") + { + if (CanRemapKey(MenuValues2[rowIndex])) + { + AddPending("SET InputExt " $ GetKeyFromDisplayName(MenuValues2[rowIndex])); + MenuValues2[rowIndex] = ""; + } + } + + if (MenuValues1[rowIndex] != "") + { + if (CanRemapKey(MenuValues1[rowIndex])) + { + AddPending("SET InputExt " $ GetKeyFromDisplayName(MenuValues1[rowIndex])); + MenuValues1[rowIndex] = MenuValues2[rowIndex]; + MenuValues2[rowIndex] = ""; + } + } + + // Update the buttons + RefreshKeyBindings(); + } +} + +// ---------------------------------------------------------------------- +// BuildKeyBindings() +// ---------------------------------------------------------------------- + +function BuildKeyBindings() +{ + local int i, j, pos; + local string KeyName; + local string Alias; + + // First, clear all the existing keybinding display + // strings in the MenuValues[1|2] arrays + + for(i=0; i= 0x70 ) && (KeyNo <= 0x81)) || // Function keys + ((KeyNo >= 48) && (KeyNo <= 57)) || // 0 - 9 + (KeyName == "Tilde") || // Tilde + (KeyName == "PrintScrn") || // Print Screen + (KeyName == "Pause") ) // Pause + { + return; + } + + // Don't waste our time if this key is already assigned here + if (( MenuValues1[Selection] == keyDisplayName ) || + ( MenuValues2[Selection] == keyDisplayName )) + return; + + // Now check to make sure there are no overlapping + // assignments. + + for ( i=0; i