Files
Bubberstation/code/modules/client/preferences/middleware/keybindings.dm
SkyratBot 124ddd7cca [MIRROR] tgui Preferences Menu + total rewrite of the preferences backend (#8153)
* tgui Preferences Menu + total rewrite of the preferences backend

* nah, we dont need to ping those people

* trying to remove the funny stuff

* unmodularizing this

* prefs reset

* this may need to be reverted, who knows

* okay, this part

* perhaps

* EEEEEEEEE

* unsanitary

* E

* Stage 1 + loadout system

* more fixes

* E

* I mean, it launches?

* More fixes and reorganisation

* E

* customisation code is spaget.

* disable ERP prefs

* Update erp_preferences.dm

* Update erp_preferences.dm

* E

* Slowly getting there

* It may be time for help :)

* tri...colors... help

* preferences now pass preferences

* Update dna.dm

* Fuck this man

* missing savefile return, set_species works, removed dumb stuff from updateappearance

* https://github.com/Skyrat-SS13/Skyrat-tg/pull/8199

* https://github.com/Skyrat-SS13/Skyrat-tg/pull/8224

* https://github.com/tgstation/tgstation/pull/61519

* https://github.com/Skyrat-SS13/Skyrat-tg/pull/8278

* e

* le butonAZARAK HELLO

* hhh

* Proper recognition where it's due, MrMelbert!

* EEEE

* examine block

* Better gen hit sounds from whitedream

* final loadout touches, more bug fixes im sure to come

* i said there would be bugfixes

* Update LoadoutManager.js

* Missing preferences in the html menu

* LIVE TESTING PHASE BABY

* Update LoadoutManager.js

* EEE

* LAUNCH TEST FIRE

* Update job.dm

* Update new_player.dm

* 50gb DAY ONE PATCH

* EEE

* Update preferences.dm

* buggle fixes

* Update examine.dm

* >LOOC starts on

Co-authored-by: Mothblocks <35135081+Mothblocks@users.noreply.github.com>
Co-authored-by: jjpark-kb <55967837+jjpark-kb@users.noreply.github.com>
Co-authored-by: Gandalf <jzo123@hotmail.com>
Co-authored-by: Azarak <azarak10@gmail.com>
2021-09-23 00:40:37 +01:00

90 lines
2.5 KiB
Plaintext

#define MAX_HOTKEY_SLOTS 3
/// Middleware to handle keybindings
/datum/preference_middleware/keybindings
action_delegations = list(
"reset_keybinds_to_defaults" = .proc/reset_keybinds_to_defaults,
"set_keybindings" = .proc/set_keybindings,
)
/datum/preference_middleware/keybindings/get_ui_static_data(mob/user)
if (preferences.current_window == PREFERENCE_TAB_CHARACTER_PREFERENCES)
return list()
var/list/keybindings = preferences.key_bindings
return list(
"keybindings" = keybindings,
)
/datum/preference_middleware/keybindings/get_ui_assets()
return list(
get_asset_datum(/datum/asset/json/keybindings)
)
/datum/preference_middleware/keybindings/proc/reset_keybinds_to_defaults(list/params, mob/user)
var/keybind_name = params["keybind_name"]
var/datum/keybinding/keybinding = GLOB.keybindings_by_name[keybind_name]
if (isnull(keybinding))
return FALSE
preferences.key_bindings[keybind_name] = preferences.parent.hotkeys ? keybinding.hotkey_keys : keybinding.classic_keys
preferences.key_bindings_by_key = preferences.get_key_bindings_by_key(preferences.key_bindings)
preferences.update_static_data(user)
return TRUE
/datum/preference_middleware/keybindings/proc/set_keybindings(list/params)
var/keybind_name = params["keybind_name"]
if (isnull(GLOB.keybindings_by_name[keybind_name]))
return FALSE
var/list/raw_hotkeys = params["hotkeys"]
if (!istype(raw_hotkeys))
return FALSE
if (raw_hotkeys.len > MAX_HOTKEY_SLOTS)
return FALSE
// There's no optimal, easy way to check if something is an array
// and not an object in BYOND, so just sanitize it to make sure.
var/list/hotkeys = list()
for (var/hotkey in raw_hotkeys)
if (!istext(hotkey))
return FALSE
// Fairly arbitrary number, it's just so you don't save enormous fake keybinds.
if (length(hotkey) > 100)
return FALSE
hotkeys += hotkey
preferences.key_bindings[keybind_name] = hotkeys
preferences.key_bindings_by_key = preferences.get_key_bindings_by_key(preferences.key_bindings)
return TRUE
/datum/asset/json/keybindings
name = "keybindings"
/datum/asset/json/keybindings/generate()
var/list/keybindings = list()
for (var/name in GLOB.keybindings_by_name)
var/datum/keybinding/keybinding = GLOB.keybindings_by_name[name]
if (!(keybinding.category in keybindings))
keybindings[keybinding.category] = list()
keybindings[keybinding.category][keybinding.name] = list(
"name" = keybinding.full_name,
"description" = keybinding.description,
)
return keybindings
#undef MAX_HOTKEY_SLOTS