Don't Starve Together

Don't Starve Together

Configs Extended
 이 토론은 고정되었습니다. 중요해서 그렇겠죠?
Remi  [개발자] 2024년 8월 30일 오전 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 님이 마지막으로 수정; 2025년 5월 29일 오후 11시 01분
< >
전체 댓글 8개 중 1~8개 표시 중
冰冰羊 2024년 8월 30일 오후 11시 53분 
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?
冰冰羊 2024년 8월 30일 오후 11시 58분 
冰冰羊 님이 먼저 게시:
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  [개발자] 2024년 8월 31일 오전 2시 55분 
Sure, I can implement this format. Several widely popular mods use it as well.
Remi  [개발자] 2024년 8월 31일 오전 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 님이 마지막으로 수정; 2024년 8월 31일 오전 10시 09분
冰冰羊 2024년 8월 31일 오전 9시 57분 
Remi 님이 먼저 게시:
Sure, I can implement this format. Several widely popular mods use it as well.
:steamthumbsup:
vaalstrum 2025년 3월 1일 오전 12시 24분 
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 님이 마지막으로 수정; 2025년 3월 1일 오전 12시 40분
Remi  [개발자] 2025년 3월 1일 오전 12시 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!
vaalstrum 2025년 3월 1일 오전 12시 40분 
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 님이 마지막으로 수정; 2025년 3월 1일 오전 12시 43분
< >
전체 댓글 8개 중 1~8개 표시 중
페이지당 표시 개수: 1530 50