veloren_voxygen/hud/
controller_icons.rs1use super::img_ids::Imgs;
2use crate::{Settings, game_input::GameInput, settings::Button, window::ControllerType};
3use conrod_core::image::Id as ConrodImageId;
4use gilrs::Button as GilButton;
5
6pub fn fetch_skillbar_gamepad_left(ctrl_type: ControllerType, imgs: &Imgs) -> ConrodImageId {
8 match ctrl_type {
9 ControllerType::Xbox => imgs.left_trigger_xbox_dark,
10 ControllerType::Nintendo => imgs.left_trigger_nin_dark,
11 ControllerType::Playstation => imgs.left_trigger_ps_dark,
12 _ => imgs.m1_ico,
13 }
14}
15
16pub fn fetch_skillbar_gamepad_right(ctrl_type: ControllerType, imgs: &Imgs) -> ConrodImageId {
18 match ctrl_type {
19 ControllerType::Xbox => imgs.right_trigger_xbox_dark,
20 ControllerType::Nintendo => imgs.right_trigger_nin_dark,
21 ControllerType::Playstation => imgs.right_trigger_ps_dark,
22 _ => imgs.m2_ico,
23 }
24}
25
26pub const UNBOUND_KEY: &str = ":none:";
28
29pub fn get_controller_input_string(
33 input: GameInput,
34 settings: &Settings,
35 ctrl: ControllerType,
36) -> Option<String> {
37 let mut icon_tags = Vec::new();
38 let unknown = Button::Simple(GilButton::Unknown);
39
40 let get_tag = |b: Button| {
42 let mut name = match b {
43 Button::Simple(inner) => format!("{:?}", inner),
44 _ => format!("{:?}", b),
45 };
46 match ctrl {
47 ControllerType::Xbox => name.push_str("_x"),
48 ControllerType::Nintendo => name.push_str("_n"),
49 ControllerType::Playstation => name.push_str("_p"),
50 _ => {},
51 }
52 format!(":{}:", name)
53 };
54
55 if let Some(layer) = settings.controller.get_layer_button_binding(input) {
57 if layer.mod2 != unknown {
59 icon_tags.push(get_tag(layer.mod2));
60 }
61 if layer.mod1 != unknown {
62 icon_tags.push(get_tag(layer.mod1));
63 }
64
65 icon_tags.push(get_tag(layer.button));
67 } else if let Some(button) = settings.controller.get_game_button_binding(input) {
68 icon_tags.push(get_tag(button));
69 }
70
71 if icon_tags.is_empty() {
72 None
73 } else {
74 Some(icon_tags.join(" + ").to_lowercase())
75 }
76}
77
78pub fn get_controller_icon_id_from_string(name: &str, imgs: &Imgs) -> ConrodImageId {
80 match name {
83 "south" | "south_x" | "south_n" => imgs.south_button_a,
84 "south_p" => imgs.south_button_ps_cross,
85 "east" | "east_x" | "east_n" => imgs.east_button_b,
86 "east_p" => imgs.east_button_ps_circle,
87 "west" | "west_x" | "west_n" => imgs.west_button_x,
88 "west_p" => imgs.west_button_ps_square,
89 "north" | "north_x" | "north_n" => imgs.north_button_y,
90 "north_p" => imgs.north_button_ps_triangle,
91 "leftaxis" | "leftaxis_x" | "leftaxis_n" | "leftaxis_p" => imgs.left_axis,
92 "rightaxis" | "rightaxis_x" | "rightaxis_n" | "rightaxis_p" => imgs.right_axis,
93 "leftthumb" | "leftthumb_x" | "leftthumb_n" | "leftthumb_p" => imgs.left_axis_button,
94 "rightthumb" | "rightthumb_x" | "rightthumb_n" | "rightthumb_p" => imgs.right_axis_button,
95 "lefttrigger" | "lefttrigger_x" => imgs.left_shoulder_xbox_lb,
97 "lefttrigger_n" => imgs.left_shoulder_nin_l,
98 "lefttrigger_p" => imgs.left_shoulder_ps_l1,
99 "righttrigger" | "righttrigger_x" => imgs.right_shoulder_xbox_rb,
100 "righttrigger_n" => imgs.right_shoulder_nin_r,
101 "righttrigger_p" => imgs.right_shoulder_ps_r1,
102 "lefttrigger2" | "lefttrigger2_x" => imgs.left_trigger_xbox_lt,
104 "lefttrigger2_n" => imgs.left_trigger_nin_zl,
105 "lefttrigger2_p" => imgs.left_trigger_ps_l2,
106 "righttrigger2" | "righttrigger2_x" => imgs.right_trigger_xbox_rt,
107 "righttrigger2_n" => imgs.right_trigger_nin_zr,
108 "righttrigger2_p" => imgs.right_trigger_ps_r2,
109 "dpaddown" | "dpaddown_x" | "dpaddown_n" => imgs.dpad_down,
110 "dpaddown_p" => imgs.dpad_down_ps,
111 "dpadleft" | "dpadleft_x" | "dpadleft_n" => imgs.dpad_left,
112 "dpadleft_p" => imgs.dpad_left_ps,
113 "dpadright" | "dpadright_x" | "dpadright_n" => imgs.dpad_right,
114 "dpadright_p" => imgs.dpad_right_ps,
115 "dpadup" | "dpadup_x" | "dpadup_n" => imgs.dpad_up,
116 "dpadup_p" => imgs.dpad_up_ps,
117 "start" | "start_x" => imgs.start_button_xbox,
118 "start_n" => imgs.start_button_nin,
119 "start_p" => imgs.start_button_ps,
120 "select" | "select_x" => imgs.select_button_xbox,
121 "select_n" => imgs.select_button_nin,
122 "select_p" => imgs.select_button_ps,
123 "mode" => imgs.start_button_xbox, "c" => imgs.south_button_a,
126 "z" => imgs.east_button_b,
127 _ => imgs.no_button,
128 }
129}