Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

'Search by key' button for the Keybind menu #6070

Merged
merged 2 commits into from
Apr 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion code/modules/client/tgui_macro.dm
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,12 @@ GLOBAL_LIST_EMPTY(ui_data_keybindings)

/datum/tgui_macro/ui_data(mob/user)
. = list()
.["keybinds"] = prefs.key_bindings
.["player_keybinds"] = prefs.key_bindings

/datum/tgui_macro/ui_static_data(mob/user)
. = list()
.["glob_keybinds"] = GLOB.ui_data_keybindings
.["byond_keymap"] = GLOB._kbMap

/datum/tgui_macro/ui_state(mob/user)
return GLOB.always_state
Expand Down
47 changes: 36 additions & 11 deletions tgui/packages/tgui/interfaces/KeyBinds.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ const getAllKeybinds = (glob_keybinds) => {

export const KeyBinds = (props) => {
const { act, data } = useBackend();
const { glob_keybinds } = data;
const { player_keybinds, glob_keybinds, byond_keymap } = data;

const [selectedTab, setSelectedTab] = useLocalState('progress', 'ALL');

Expand Down Expand Up @@ -52,13 +52,38 @@ export const KeyBinds = (props) => {
}>
<Flex direction="column">
<Flex.Item>
<Box height="5px" />
<Input
value={searchTerm}
onInput={(_, value) => setSearchTerm(value)}
placeholder="Search..."
fluid
/>
<Flex align="baseline" mt="5px">
<Flex.Item grow>
<Input
value={searchTerm}
onInput={(_, value) => setSearchTerm(value)}
placeholder="Search..."
fluid
/>
</Flex.Item>
<Flex.Item>
<ButtonKeybind
tooltip="Search by key"
tooltipPosition="bottom-start"
icon="keyboard"
onFinish={(keysDown) => {
// The key(s) pressed by the user, byond-ified.
const targetKey = keysDown
.map((k) => byond_keymap[k] || k)
.join('+');
// targetKey's entry in player_keybinds.
const targetEntry = player_keybinds[targetKey];
if (!targetEntry) {
return;
}
// If a keybind was found, scroll to the first match.
document
.getElementById(targetEntry[0])
.scrollIntoView();
}}
/>
</Flex.Item>
</Flex>
</Flex.Item>
<Flex.Item>
<Box height="5px" />
Expand Down Expand Up @@ -129,11 +154,11 @@ const KeybindsDropdown = (props) => {
export const KeybindElement = (props) => {
const { act, data } = useBackend();
const { keybind } = props;
const { keybinds } = data;
const { player_keybinds } = data;

const currentBoundKeys = [];

for (const [key, value] of Object.entries(keybinds)) {
for (const [key, value] of Object.entries(player_keybinds)) {
for (let i = 0; i < value.length; i++) {
if (value[i] === keybind.name) {
currentBoundKeys.push(key);
Expand All @@ -143,7 +168,7 @@ export const KeybindElement = (props) => {
}

return (
<Flex mt={1}>
<Flex id={keybind.name} mt={1}>
<Flex.Item basis="30%">
<Box fontSize="115%" color="label" textAlign="center">
{keybind.full_name}
Expand Down
Loading