mirror of
https://github.com/Insality/druid.git
synced 2025-06-27 18:37:44 +02:00
98 lines
3.3 KiB
Markdown
98 lines
3.3 KiB
Markdown
# Advanced Druid Setup
|
|
|
|
## Input Bindings
|
|
|
|
By default, **Druid** uses all key names from Defold's default `/builtins/input/all.input_binding` for input bindings.
|
|
|
|
**Druid** requires the following input bindings:
|
|
|
|
- Mouse trigger: `Button 1` -> `touch` (for basic input components)
|
|
- Mouse trigger: `Wheel up` -> `mouse_wheel_up` (for Scroll component)
|
|
- Mouse trigger: `Wheel down` -> `mouse_wheel_down` (for Scroll component)
|
|
- Key trigger: `Backspace` -> `key_backspace` (for BackHandler component, input component)
|
|
- Key trigger: `Back` -> `key_back` (for BackHandler component, Android back button, input component)
|
|
- Key trigger: `Enter` -> `key_enter` (for Input component, optional)
|
|
- Key trigger: `Esc` -> `key_esc` (for Input component, optional)
|
|
- Key trigger: `Left` -> `key_left` (for Rich Input component, optional)
|
|
- Key trigger: `Right` -> `key_right` (for Rich Input component, optional)
|
|
- Key trigger: `Shift` -> `key_lshift` (for Rich Input component, optional)
|
|
- Key trigger: `Ctrl` -> `key_lctrl` (for Rich Input component, optional)
|
|
- Key trigger: `Super` -> `key_lsuper` (for Rich Input component, optional)
|
|
- Touch triggers: `Touch multi` -> `touch_multi` (for Scroll component)
|
|
|
|

|
|

|
|
|
|
|
|
## Changing Key Bindings
|
|
|
|
If you need to use your own key bindings or key names, you can modify them in your *game.project* file.
|
|
|
|
Here are the default values for key bindings:
|
|
```
|
|
[druid]
|
|
input_text = text
|
|
input_touch = touch
|
|
input_marked_text = marked_text
|
|
input_key_esc = key_esc
|
|
input_key_back = key_back
|
|
input_key_enter = key_enter
|
|
input_key_backspace = key_backspace
|
|
input_multitouch = touch_multi
|
|
input_scroll_up = mouse_wheel_up
|
|
input_scroll_down = mouse_wheel_down
|
|
input_key_left = key_left
|
|
input_key_right = key_right
|
|
input_key_lshift = key_lshift
|
|
input_key_lctrl = key_lctrl
|
|
input_key_lsuper = key_lsuper
|
|
```
|
|
|
|
|
|
## Input Capturing
|
|
|
|
By default, **Druid** automatically captures input focus if any input component is created. Therefore, you do not need to call `msg.post(".", "acquire_input_focus")`.
|
|
|
|
If you do not require this behavior, you can disable it by setting the `druid.no_auto_input` field in the _game.project_ file:
|
|
```
|
|
[druid]
|
|
no_auto_input = 1
|
|
```
|
|
|
|
|
|
## Code Bindings
|
|
|
|
Adjust **Druid** settings as needed:
|
|
```lua
|
|
local druid = require("druid.druid")
|
|
|
|
-- Used for button component and custom components
|
|
-- The callback should play the sound by name: function(sound_id) ... end
|
|
druid.set_sound_function(function(sound_id)
|
|
-- sound_system.play(sound_id)
|
|
end)
|
|
|
|
-- Used for lang_text component
|
|
-- The callback should return the localized string by locale ID: function(locale_id) ... end
|
|
druid.set_text_function(function(locale_id)
|
|
-- return lang.get(locale_id)
|
|
end)
|
|
|
|
-- Used to change the default Druid style
|
|
druid.set_default_style(your_style)
|
|
|
|
-- Call this function when the language changes in the game,
|
|
-- to retranslate all lang_text components:
|
|
local function on_language_change()
|
|
druid.on_language_change()
|
|
end
|
|
|
|
-- Call this function inside window.set_listener
|
|
-- to capture game focus lost/gained callbacks:
|
|
-- window.set_listener(function(self, event, data) druid.on_window_callback(event, data) end))
|
|
local function on_window_callback(self, event, data)
|
|
druid.on_window_callback(event)
|
|
end
|
|
window.set_listener(on_window_callback)
|
|
```
|