Don't Starve Together
Configs Extended
 Αυτό το θέμα έχει επισημανθεί, οπότε πιθανώς είναι σημαντικό
Remi  [δημιουργός] 30 Αυγ 2024, 11:08
Making a keybind setting that will work with this mod
Let's say you've got a mod that has a keybind for some action, and you would like that option to use the keybind picker.

tldr:
  • keys table has input ids/variable names as data values (constants.lua is your friend)
  • be ready for -1 as the keybind value
  • put "is_keybind = true," in the config's definition
--

Step 1: correct data values
First of all, your key options table must have input IDs (defined in constants.lua) as its data values. It should look like similar to this example:
local keys = { {description = "Left Alt", data = 308}, {description = "Left Ctrl", data = 306}, {description = "A", data = 97}, {description = "B", data = 98}, {description = "C", data = 99}, -- ... }
Alternatively, you can use names of the variables (you can also find them in constants.lua) instead, like this:
local keys = { {description = "Left Alt", data = "KEY_LALT"}, {description = "Left Ctrl", data = "KEY_LCTRL"}, {description = "A", data = "KEY_A"}, {description = "B", data = "KEY_B}, {description = "C", data = "KEY_C"}, -- ... }
The mod will only allow inputs listed in the options table and ignore everything else.
(For clarity, the example table above will only accept keys Left Alt, Left Ctrl, A, B and C)

Important: the format must stay consistent throughout the entire mod. Either you use only numbers or only names. No mixing! (Why whould you ever want to mix formats though?)

Note: the keybind picker reserves Escape, Mouse Scroll Up and Mouse Scroll Down. Players won't be able to bind actions to those keys.

Step 2: no bind is always an option
The mod provides an option to disable any keybind. Internally it just sets the chosen value to -1. Make sure your mod doesn't break in that case. (For example, STRINGS.UI.CONTROLSSCREEN.INPUTS[1][-1] is nil, and will cause a crash upon attempted concatenation)
Passing -1 to TheInput:AddKeyUpHandler or TheInput:AddKeyDownHandler doesn't cause errors, by the way.

Note: the default description for an unbound setting is "- No Bind -", but if you really want you can provide your own description by adding an option with data=-1.

Note: it's too late to change -1 to false.

Step 3: the final touch
The last thing that's needed for the mod to recognize your option as a keybind setting is a simple attribulte. Add "is_keybind = true," to your option so that it looks like this:
configuration_options = { -- ... { name = "somename", label = "somelabel", options = keys, default = 69, hover = "someoptionalhovertext", is_keybind = true, } -- ... }

Aaaand that should be it. Don't forget to check the final result.
Τελευταία επεξεργασία από Remi; 29 Μαϊ, 23:01
< >
Εμφάνιση 1-8 από 8 σχόλια
Can the `data` in `local keys` only be numbers? I want to change it to something like "KEY_LALT", "KEY_LCTRL", "KEY_A", "KEY_B", "KEY_C". Could you make the `data` compatible with this format?
Αναρτήθηκε αρχικά από 冰冰羊:
Can the `data` in `local keys` only be numbers? I want to change it to something like "KEY_LALT", "KEY_LCTRL", "KEY_A", "KEY_B", "KEY_C". Could you make the `data` compatible with this format?
Because the "is_keylist" in the Lazy Controls MOD does it this way, my MOD is compatible with it using this format.
Remi  [δημιουργός] 31 Αυγ 2024, 2:55 
Sure, I can implement this format. Several widely popular mods use it as well.
Remi  [δημιουργός] 31 Αυγ 2024, 4:47 
The new version of the mod should work with variable names as data values.
Keep in mind that players can still set the selected value to -1 via the unbind button. Your mod must be able to handle that case.
Τελευταία επεξεργασία από Remi; 31 Αυγ 2024, 10:09
Αναρτήθηκε αρχικά από Remi:
Sure, I can implement this format. Several widely popular mods use it as well.
:steamthumbsup:
Can you make it so false/nil is an option for disabling keybinds in place of -1 if you have the false/nil option?
The reasoning being "if CONFIG.KEY_BIND then do something" or "local KEY_BIND = CONFIG.KEY_BIND or KEY_B". I know "if CONFIG.KEYBIND >= 0" is the same but it doesnt match my other CONFIG logic (false is always do nothing or resort to a default).
Τελευταία επεξεργασία από vaalstrum; 1 Μαρ, 0:40
Remi  [δημιουργός] 1 Μαρ, 0:39 
Hey there. Unfortunately, if I were to make the change you suggested, it would break some other mods which already rely on disabled keybinds being exactly -1. That doesn't sound like something I'd want. Sorry!
No problem. Thanks anyway. :]
Though I didn't mean for it to be false instead of -1, only if a false/nil option is present. But if it causes too much of an issue thats fine as well.
Τελευταία επεξεργασία από vaalstrum; 1 Μαρ, 0:43
< >
Εμφάνιση 1-8 από 8 σχόλια
Ανά σελίδα: 1530 50