veloren_voxygen/settings/
gamepad.rs

1use hashbrown::HashMap;
2use serde::{Deserialize, Serialize};
3
4#[derive(Clone, Debug, Serialize, Deserialize)]
5#[serde(default)]
6pub struct GamepadSettings {
7    pub game_buttons: con_settings::GameButtons,
8    pub menu_buttons: con_settings::MenuButtons,
9    pub game_axis: con_settings::GameAxis,
10    pub menu_axis: con_settings::MenuAxis,
11    pub game_analog_buttons: con_settings::GameAnalogButton,
12    pub menu_analog_buttons: con_settings::MenuAnalogButton,
13    pub game_layer_buttons: con_settings::GameLayerEntries,
14    pub pan_sensitivity: u32,
15    pub pan_invert_y: bool,
16    pub axis_deadzones: HashMap<crate::controller::Axis, f32>,
17    pub button_deadzones: HashMap<crate::controller::AnalogButton, f32>,
18    pub mouse_emulation_sensitivity: u32,
19    pub inverted_axes: Vec<crate::controller::Axis>,
20}
21
22impl Default for GamepadSettings {
23    fn default() -> Self {
24        Self {
25            game_buttons: con_settings::GameButtons::default(),
26            menu_buttons: con_settings::MenuButtons::default(),
27            game_axis: con_settings::GameAxis::default(),
28            menu_axis: con_settings::MenuAxis::default(),
29            game_analog_buttons: con_settings::GameAnalogButton::default(),
30            menu_analog_buttons: con_settings::MenuAnalogButton::default(),
31            game_layer_buttons: con_settings::GameLayerEntries::default(),
32            pan_sensitivity: 10,
33            pan_invert_y: false,
34            axis_deadzones: HashMap::new(),
35            button_deadzones: HashMap::new(),
36            mouse_emulation_sensitivity: 12,
37            inverted_axes: Vec::new(),
38        }
39    }
40}
41
42pub mod con_settings {
43    use crate::controller::*;
44    use gilrs::{Axis as GilAxis, Button as GilButton};
45    use serde::{Deserialize, Serialize};
46
47    // represents a controller button to fire a GameInput on
48    // includes two modifier buttons to determine what layer is active
49    #[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, Serialize, Deserialize)]
50    #[serde(default)]
51    pub struct LayerEntry {
52        pub button: Button,
53        pub mod1: Button,
54        pub mod2: Button,
55    }
56
57    impl Default for LayerEntry {
58        fn default() -> Self {
59            // binding to unknown = getting skipped from processing
60            Self {
61                button: Button::Simple(GilButton::Unknown),
62                mod1: Button::Simple(GilButton::Unknown),
63                mod2: Button::Simple(GilButton::Unknown),
64            }
65        }
66    }
67
68    // struct to associate each available GameInput with a LayerEntry
69    // similar in function to the GameButtons struct
70    // nothing prevents mapping a GameInput in both GameLayerEntries and GameButtons
71    // it's likely not desirable to double map a GameInput
72    #[derive(Clone, Debug, Serialize, Deserialize)]
73    #[serde(default)]
74    pub struct GameLayerEntries {
75        pub primary: LayerEntry,
76        pub secondary: LayerEntry,
77        pub block: LayerEntry,
78        pub slot1: LayerEntry,
79        pub slot2: LayerEntry,
80        pub slot3: LayerEntry,
81        pub slot4: LayerEntry,
82        pub slot5: LayerEntry,
83        pub slot6: LayerEntry,
84        pub slot7: LayerEntry,
85        pub slot8: LayerEntry,
86        pub slot9: LayerEntry,
87        pub slot10: LayerEntry,
88        pub toggle_cursor: LayerEntry,
89        pub escape: LayerEntry,
90        pub enter: LayerEntry,
91        pub command: LayerEntry,
92        pub move_forward: LayerEntry,
93        pub move_left: LayerEntry,
94        pub move_back: LayerEntry,
95        pub move_right: LayerEntry,
96        pub jump: LayerEntry,
97        pub sit: LayerEntry,
98        pub dance: LayerEntry,
99        pub glide: LayerEntry,
100        pub climb: LayerEntry,
101        pub climb_down: LayerEntry,
102        pub swimup: LayerEntry,
103        pub swimdown: LayerEntry,
104        pub sneak: LayerEntry,
105        pub toggle_lantern: LayerEntry,
106        pub mount: LayerEntry,
107        pub map: LayerEntry,
108        pub bag: LayerEntry,
109        pub quest_log: LayerEntry,
110        pub character_window: LayerEntry,
111        pub social: LayerEntry,
112        pub crafting: LayerEntry,
113        pub diary: LayerEntry,
114        pub settings: LayerEntry,
115        pub controls: LayerEntry,
116        pub toggle_interface: LayerEntry,
117        pub toggle_debug: LayerEntry,
118        #[cfg(feature = "egui-ui")]
119        pub toggle_egui_debug: LayerEntry,
120        pub toggle_chat: LayerEntry,
121        pub fullscreen: LayerEntry,
122        pub screenshot: LayerEntry,
123        pub toggle_ingame_ui: LayerEntry,
124        pub roll: LayerEntry,
125        pub respawn: LayerEntry,
126        pub interact: LayerEntry,
127        pub toggle_wield: LayerEntry,
128        pub swap_loadout: LayerEntry,
129    }
130
131    impl Default for GameLayerEntries {
132        fn default() -> Self {
133            Self {
134                primary: LayerEntry::default(),
135                secondary: LayerEntry::default(),
136                block: LayerEntry::default(),
137                slot1: LayerEntry {
138                    button: Button::Simple(GilButton::DPadRight),
139                    mod1: Button::Simple(GilButton::RightTrigger),
140                    mod2: Button::Simple(GilButton::Unknown),
141                },
142                slot2: LayerEntry {
143                    button: Button::Simple(GilButton::DPadDown),
144                    mod1: Button::Simple(GilButton::RightTrigger),
145                    mod2: Button::Simple(GilButton::Unknown),
146                },
147                slot3: LayerEntry {
148                    button: Button::Simple(GilButton::DPadUp),
149                    mod1: Button::Simple(GilButton::LeftTrigger),
150                    mod2: Button::Simple(GilButton::Unknown),
151                },
152                slot4: LayerEntry {
153                    button: Button::Simple(GilButton::DPadLeft),
154                    mod1: Button::Simple(GilButton::LeftTrigger),
155                    mod2: Button::Simple(GilButton::Unknown),
156                },
157                slot5: LayerEntry {
158                    button: Button::Simple(GilButton::DPadRight),
159                    mod1: Button::Simple(GilButton::LeftTrigger),
160                    mod2: Button::Simple(GilButton::Unknown),
161                },
162                slot6: LayerEntry {
163                    button: Button::Simple(GilButton::DPadDown),
164                    mod1: Button::Simple(GilButton::LeftTrigger),
165                    mod2: Button::Simple(GilButton::Unknown),
166                },
167                slot7: LayerEntry {
168                    button: Button::Simple(GilButton::DPadUp),
169                    mod1: Button::Simple(GilButton::RightTrigger),
170                    mod2: Button::Simple(GilButton::LeftTrigger),
171                },
172                slot8: LayerEntry {
173                    button: Button::Simple(GilButton::DPadLeft),
174                    mod1: Button::Simple(GilButton::RightTrigger),
175                    mod2: Button::Simple(GilButton::LeftTrigger),
176                },
177                slot9: LayerEntry {
178                    button: Button::Simple(GilButton::DPadRight),
179                    mod1: Button::Simple(GilButton::RightTrigger),
180                    mod2: Button::Simple(GilButton::LeftTrigger),
181                },
182                slot10: LayerEntry {
183                    button: Button::Simple(GilButton::DPadDown),
184                    mod1: Button::Simple(GilButton::RightTrigger),
185                    mod2: Button::Simple(GilButton::LeftTrigger),
186                },
187                toggle_cursor: LayerEntry {
188                    button: Button::Simple(GilButton::Start),
189                    mod1: Button::Simple(GilButton::RightTrigger),
190                    mod2: Button::Simple(GilButton::LeftTrigger),
191                },
192                escape: LayerEntry {
193                    button: Button::Simple(GilButton::Start),
194                    mod1: Button::Simple(GilButton::Unknown),
195                    mod2: Button::Simple(GilButton::Unknown),
196                },
197                enter: LayerEntry::default(),
198                command: LayerEntry::default(),
199                move_forward: LayerEntry::default(),
200                move_left: LayerEntry::default(),
201                move_back: LayerEntry::default(),
202                move_right: LayerEntry::default(),
203                jump: LayerEntry::default(),
204                sit: LayerEntry {
205                    button: Button::Simple(GilButton::Select),
206                    mod1: Button::Simple(GilButton::RightTrigger),
207                    mod2: Button::Simple(GilButton::LeftTrigger),
208                },
209                dance: LayerEntry {
210                    button: Button::Simple(GilButton::Select),
211                    mod1: Button::Simple(GilButton::LeftTrigger),
212                    mod2: Button::Simple(GilButton::Unknown),
213                },
214                glide: LayerEntry {
215                    button: Button::Simple(GilButton::DPadUp),
216                    mod1: Button::Simple(GilButton::Unknown),
217                    mod2: Button::Simple(GilButton::Unknown),
218                },
219                climb: LayerEntry::default(),
220                climb_down: LayerEntry::default(),
221                swimup: LayerEntry::default(),
222                swimdown: LayerEntry::default(),
223                sneak: LayerEntry::default(),
224                toggle_lantern: LayerEntry {
225                    button: Button::Simple(GilButton::DPadLeft),
226                    mod1: Button::Simple(GilButton::RightTrigger),
227                    mod2: Button::Simple(GilButton::Unknown),
228                },
229                mount: LayerEntry::default(),
230                map: LayerEntry {
231                    button: Button::Simple(GilButton::DPadLeft),
232                    mod1: Button::Simple(GilButton::Unknown),
233                    mod2: Button::Simple(GilButton::Unknown),
234                },
235                bag: LayerEntry::default(),
236                quest_log: LayerEntry {
237                    button: Button::Simple(GilButton::DPadRight),
238                    mod1: Button::Simple(GilButton::Unknown),
239                    mod2: Button::Simple(GilButton::Unknown),
240                },
241                character_window: LayerEntry::default(),
242                social: LayerEntry {
243                    button: Button::Simple(GilButton::DPadUp),
244                    mod1: Button::Simple(GilButton::RightTrigger),
245                    mod2: Button::Simple(GilButton::Unknown),
246                },
247                crafting: LayerEntry {
248                    button: Button::Simple(GilButton::Select),
249                    mod1: Button::Simple(GilButton::RightTrigger),
250                    mod2: Button::Simple(GilButton::Unknown),
251                },
252                diary: LayerEntry {
253                    button: Button::Simple(GilButton::Select),
254                    mod1: Button::Simple(GilButton::Unknown),
255                    mod2: Button::Simple(GilButton::Unknown),
256                },
257                settings: LayerEntry {
258                    button: Button::Simple(GilButton::Start),
259                    mod1: Button::Simple(GilButton::RightTrigger),
260                    mod2: Button::Simple(GilButton::Unknown),
261                },
262                controls: LayerEntry {
263                    button: Button::Simple(GilButton::Start),
264                    mod1: Button::Simple(GilButton::LeftTrigger),
265                    mod2: Button::Simple(GilButton::Unknown),
266                },
267                toggle_interface: LayerEntry::default(),
268                toggle_debug: LayerEntry::default(),
269                #[cfg(feature = "egui-ui")]
270                toggle_egui_debug: LayerEntry::default(),
271                toggle_chat: LayerEntry::default(),
272                fullscreen: LayerEntry::default(),
273                screenshot: LayerEntry::default(),
274                toggle_ingame_ui: LayerEntry::default(),
275                roll: LayerEntry::default(),
276                respawn: LayerEntry::default(),
277                interact: LayerEntry::default(),
278                toggle_wield: LayerEntry::default(),
279                swap_loadout: LayerEntry {
280                    button: Button::Simple(GilButton::DPadDown),
281                    mod1: Button::Simple(GilButton::Unknown),
282                    mod2: Button::Simple(GilButton::Unknown),
283                },
284            }
285        }
286    }
287
288    #[derive(Clone, Debug, Serialize, Deserialize)]
289    #[serde(default)]
290    pub struct GameButtons {
291        pub primary: Button,
292        pub secondary: Button,
293        pub block: Button,
294        pub slot1: Button,
295        pub slot2: Button,
296        pub slot3: Button,
297        pub slot4: Button,
298        pub slot5: Button,
299        pub slot6: Button,
300        pub slot7: Button,
301        pub slot8: Button,
302        pub slot9: Button,
303        pub slot10: Button,
304        pub toggle_cursor: Button,
305        pub escape: Button,
306        pub enter: Button,
307        pub command: Button,
308        pub move_forward: Button,
309        pub move_left: Button,
310        pub move_back: Button,
311        pub move_right: Button,
312        pub jump: Button,
313        pub sit: Button,
314        pub dance: Button,
315        pub glide: Button,
316        pub climb: Button,
317        pub climb_down: Button,
318        pub swimup: Button,
319        pub swimdown: Button,
320        pub sneak: Button,
321        pub toggle_lantern: Button,
322        pub mount: Button,
323        pub stayfollow: Button,
324        pub map: Button,
325        pub bag: Button,
326        pub quest_log: Button,
327        pub character_window: Button,
328        pub social: Button,
329        pub crafting: Button,
330        pub diary: Button,
331        pub settings: Button,
332        pub controls: Button,
333        pub toggle_interface: Button,
334        pub toggle_debug: Button,
335        #[cfg(feature = "egui-ui")]
336        pub toggle_egui_debug: Button,
337        pub toggle_chat: Button,
338        pub fullscreen: Button,
339        pub screenshot: Button,
340        pub toggle_ingame_ui: Button,
341        pub roll: Button,
342        pub respawn: Button,
343        pub interact: Button,
344        pub toggle_wield: Button,
345        pub swap_loadout: Button,
346    }
347
348    #[derive(Clone, Debug, Serialize, Deserialize)]
349    #[serde(default)]
350    pub struct MenuButtons {
351        pub up: Button,
352        pub down: Button,
353        pub left: Button,
354        pub right: Button,
355        pub scroll_up: Button,
356        pub scroll_down: Button,
357        pub scroll_left: Button,
358        pub scroll_right: Button,
359        pub home: Button,
360        pub end: Button,
361        pub apply: Button,
362        pub back: Button,
363        pub exit: Button,
364    }
365
366    #[derive(Clone, Debug, Serialize, Deserialize)]
367    #[serde(default)]
368    pub struct GameAxis {
369        pub movement_x: Axis,
370        pub movement_y: Axis,
371        pub camera_x: Axis,
372        pub camera_y: Axis,
373    }
374
375    #[derive(Clone, Debug, Serialize, Deserialize)]
376    #[serde(default)]
377    pub struct MenuAxis {
378        pub move_x: Axis,
379        pub move_y: Axis,
380        pub scroll_x: Axis,
381        pub scroll_y: Axis,
382    }
383
384    #[derive(Clone, Debug, Default, Serialize, Deserialize)]
385    #[serde(default)]
386    pub struct GameAnalogButton {}
387
388    #[derive(Clone, Debug, Default, Serialize, Deserialize)]
389    #[serde(default)]
390    pub struct MenuAnalogButton {}
391
392    impl Default for GameButtons {
393        fn default() -> Self {
394            // binding to unknown = getting skipped from processing
395            Self {
396                primary: Button::Simple(GilButton::RightTrigger2),
397                secondary: Button::Simple(GilButton::LeftTrigger2),
398                block: Button::Simple(GilButton::North),
399                slot1: Button::Simple(GilButton::Unknown),
400                slot2: Button::Simple(GilButton::Unknown),
401                slot3: Button::Simple(GilButton::Unknown),
402                slot4: Button::Simple(GilButton::Unknown),
403                slot5: Button::Simple(GilButton::Unknown),
404                slot6: Button::Simple(GilButton::Unknown),
405                slot7: Button::Simple(GilButton::Unknown),
406                slot8: Button::Simple(GilButton::Unknown),
407                slot9: Button::Simple(GilButton::Unknown),
408                slot10: Button::Simple(GilButton::Unknown),
409                toggle_cursor: Button::Simple(GilButton::Unknown),
410                escape: Button::Simple(GilButton::Unknown),
411                enter: Button::Simple(GilButton::Unknown),
412                command: Button::Simple(GilButton::Unknown),
413                move_forward: Button::Simple(GilButton::Unknown),
414                move_left: Button::Simple(GilButton::Unknown),
415                move_back: Button::Simple(GilButton::Unknown),
416                move_right: Button::Simple(GilButton::Unknown),
417                jump: Button::Simple(GilButton::South),
418                sit: Button::Simple(GilButton::Unknown),
419                dance: Button::Simple(GilButton::Unknown),
420                glide: Button::Simple(GilButton::Unknown),
421                climb: Button::Simple(GilButton::South),
422                climb_down: Button::Simple(GilButton::West),
423                swimup: Button::Simple(GilButton::South),
424                swimdown: Button::Simple(GilButton::West),
425                sneak: Button::Simple(GilButton::LeftThumb),
426                toggle_lantern: Button::Simple(GilButton::Unknown),
427                mount: Button::Simple(GilButton::South),
428                stayfollow: Button::Simple(GilButton::Unknown),
429                map: Button::Simple(GilButton::Unknown),
430                bag: Button::Simple(GilButton::East),
431                quest_log: Button::Simple(GilButton::Unknown),
432                character_window: Button::Simple(GilButton::Unknown),
433                social: Button::Simple(GilButton::Unknown),
434                crafting: Button::Simple(GilButton::Unknown),
435                diary: Button::Simple(GilButton::Unknown),
436                settings: Button::Simple(GilButton::Unknown),
437                controls: Button::Simple(GilButton::Unknown),
438                toggle_interface: Button::Simple(GilButton::Unknown),
439                toggle_debug: Button::Simple(GilButton::Unknown),
440                #[cfg(feature = "egui-ui")]
441                toggle_egui_debug: Button::Simple(GilButton::Unknown),
442                toggle_chat: Button::Simple(GilButton::Unknown),
443                fullscreen: Button::Simple(GilButton::Unknown),
444                screenshot: Button::Simple(GilButton::Unknown),
445                toggle_ingame_ui: Button::Simple(GilButton::Unknown),
446                roll: Button::Simple(GilButton::RightThumb),
447                respawn: Button::Simple(GilButton::South),
448                interact: Button::Simple(GilButton::West),
449                toggle_wield: Button::Simple(GilButton::Unknown),
450                swap_loadout: Button::Simple(GilButton::Unknown),
451            }
452        }
453    }
454
455    impl Default for MenuButtons {
456        fn default() -> Self {
457            Self {
458                up: Button::Simple(GilButton::DPadUp),
459                down: Button::Simple(GilButton::DPadDown),
460                left: Button::Simple(GilButton::DPadLeft),
461                right: Button::Simple(GilButton::DPadRight),
462                scroll_up: Button::Simple(GilButton::Unknown),
463                scroll_down: Button::Simple(GilButton::Unknown),
464                scroll_left: Button::Simple(GilButton::Unknown),
465                scroll_right: Button::Simple(GilButton::Unknown),
466                home: Button::Simple(GilButton::Unknown),
467                end: Button::Simple(GilButton::Unknown),
468                apply: Button::Simple(GilButton::South),
469                back: Button::Simple(GilButton::East),
470                exit: Button::Simple(GilButton::Mode),
471            }
472        }
473    }
474
475    impl Default for GameAxis {
476        fn default() -> Self {
477            Self {
478                movement_x: Axis::Simple(GilAxis::LeftStickX),
479                movement_y: Axis::Simple(GilAxis::LeftStickY),
480                camera_x: Axis::Simple(GilAxis::RightStickX),
481                camera_y: Axis::Simple(GilAxis::RightStickY),
482            }
483        }
484    }
485
486    impl Default for MenuAxis {
487        fn default() -> Self {
488            Self {
489                move_x: Axis::Simple(GilAxis::RightStickX),
490                move_y: Axis::Simple(GilAxis::RightStickY),
491                scroll_x: Axis::Simple(GilAxis::LeftStickX),
492                scroll_y: Axis::Simple(GilAxis::LeftStickY),
493            }
494        }
495    }
496}