4 #include <stdint.h> /* for uint8_t */
5 #include <string.h> /* for strcmp() */
6 #include "windows.h" /* for cycle_active_win(), shift_active_win(), struct Win,
9 #include "keybindings.h" /* for get_keycode_to_action(), mod_selected_keyb(),
10 * move_keyb_mod_selection(), get_func_to_keycode()
12 #include "map.h" /* for map_scroll(), map_center() */
13 #include "main.h" /* for world global */
14 #include "wincontrol.h" /* for struct WinConf, scroll_pad(), toggle_window(),
15 * growshrink_active_window(),toggle_winconfig(),
18 #include "map_object_actions.h" /* for struct MapObjAct, actor_wait(),
19 * actor_move(), actor_drop(), actor_pick(),
20 * actor_pick(), get_moa_id_by_name()
22 #include "command_db.h" /* for is_command_id_shortdsc() */
23 #include "misc.h" /* for reload_interface_conf(), save_interface_conf(),
24 * nav_inventory(), turn_over()
26 #include "map_objects.h" /* for get_player() */
30 /* If "cmd" matches "match" in get_available_keycode_to_action(), execute "f"
31 * with provided char arguments and return 1; else only return 0.
33 static uint8_t try_cmd_0args(int cmd, char * match, void (* f) ());
34 static uint8_t try_cmd_1args(int cmd, char * match, void (* f) (char), char c);
35 static uint8_t try_cmd_2args(int cmd, char * match,
36 void (* f) (char, char), char c1, char c2);
38 /* If "action" is id of command named "match", set player->arg, ->command and
41 static uint8_t try_player_cmd(int action, char * match, char * command,
44 /* Return pointer to global keybindings or to keybindings for wingeometry config
45 * (c = "g") or winkeys config (c = "k") or active window's keybindings ("w").
47 static struct KeyBiData * select_keybidata_pointer(char c);
49 /* Wrappers to make some functions compatible to try_cmd_* single char args. */
50 static void wrap_mod_selected_keyb(char c);
51 static void wrap_mv_kb_mod(char c1, char c2);
55 static uint8_t try_cmd_0args(int cmd, char * match, void (* f) ())
57 if (cmd == get_available_keycode_to_action(match))
67 static uint8_t try_cmd_1args(int cmd, char * match, void (* f) (char), char c)
69 if (cmd == get_available_keycode_to_action(match))
79 static uint8_t try_cmd_2args(int cmd, char * match,
80 void (* f) (char, char), char c1, char c2)
82 if (cmd == get_available_keycode_to_action(match))
92 static uint8_t try_player_cmd(int action, char * match, char * command,
95 if (is_command_id_shortdsc(action, match))
97 struct MapObj * player = get_player();
99 player->command = get_moa_id_by_name(command);
100 turn_over(get_command_id(match));
108 static struct KeyBiData * select_keybidata_pointer(char c)
110 struct KeyBiData * kbd;
111 kbd = &world.kb_global;
114 kbd = &world.kb_wingeom;
118 kbd = &world.kb_winkeys;
122 struct WinConf * wc = get_winconf_by_win(world.wmeta->active);
130 static void wrap_mod_selected_keyb(char c)
132 mod_selected_keyb(select_keybidata_pointer(c));
137 static void wrap_mv_kb_mod(char c1, char c2)
139 move_keyb_mod_selection(select_keybidata_pointer(c1), c2);
144 extern uint16_t get_available_keycode_to_action(char * name)
146 uint16_t keycode = get_keycode_to_action(world.kb_global.kbs, name);
147 if (0 != keycode || 0 == world.wmeta->active)
151 struct WinConf * wc = get_winconf_by_win(world.wmeta->active);
154 keycode = get_keycode_to_action(wc->kb.kbs, name);
156 else if (1 == wc->view)
158 keycode = get_keycode_to_action(world.kb_wingeom.kbs, name);
160 else if (2 == wc->view)
162 keycode = get_keycode_to_action(world.kb_winkeys.kbs, name);
169 extern uint8_t player_control_by_key(int key)
171 char * action_name = get_func_to_keycode(world.kb_global.kbs, key);
172 if (NULL == action_name && 0 != world.wmeta->active)
174 struct WinConf * wc = get_winconf_by_win(world.wmeta->active);
175 action_name = get_func_to_keycode(wc->kb.kbs, key);
177 if (NULL != action_name)
179 uint8_t action_id = get_command_id(action_name);
180 return player_control_by_id(action_id);
188 extern uint8_t player_control_by_id(int action)
190 if ( try_player_cmd(action, "wait", "wait", 0)
191 || try_player_cmd(action, "drop", "drop", world.inventory_select)
192 || try_player_cmd(action, "pick", "pick_up", 0)
193 || try_player_cmd(action, "use", "use", world.inventory_select)
194 || try_player_cmd(action, "player_u", "move", 'N')
195 || try_player_cmd(action, "player_d", "move", 'S')
196 || try_player_cmd(action, "player_r", "move", 'E')
197 || try_player_cmd(action, "player_l", "move", 'W'))
206 extern uint8_t wingeom_control(int key)
208 if ( try_cmd_1args(key, "to_height_t", toggle_win_size_type, 'y')
209 || try_cmd_1args(key, "to_width_t", toggle_win_size_type, 'x')
210 || try_cmd_1args(key, "grow_h", growshrink_active_window, '*')
211 || try_cmd_1args(key, "shri_h", growshrink_active_window, '_')
212 || try_cmd_1args(key, "grow_v", growshrink_active_window, '+')
213 || try_cmd_1args(key, "shri_v", growshrink_active_window, '-')
214 || try_cmd_1args(key, "shift_f", shift_active_win, 'f')
215 || try_cmd_1args(key, "shift_b", shift_active_win, 'b'))
224 extern uint8_t winkeyb_control(int key)
226 if ( try_cmd_1args(key, "w_keys_m", wrap_mod_selected_keyb, 'w')
227 || try_cmd_2args(key, "w_keys_u", wrap_mv_kb_mod, 'w', 'u')
228 || try_cmd_2args(key, "w_keys_d", wrap_mv_kb_mod, 'w', 'd'))
237 extern uint8_t meta_control(int key)
239 uint8_t ret = (key == get_available_keycode_to_action("quit"));
241 && ( try_cmd_0args(key, "winconf", toggle_winconfig)
242 || try_cmd_0args(key, "reload_conf", reload_interface_conf)
243 || try_cmd_0args(key, "save_conf", save_interface_conf)
244 || try_cmd_0args(key, "map_c", map_center)
245 || try_cmd_1args(key, "scrl_r", scroll_pad, '+')
246 || try_cmd_1args(key, "scrl_l", scroll_pad, '-')
247 || try_cmd_1args(key, "to_a_keywin", toggle_window, 'k')
248 || try_cmd_1args(key, "to_g_keywin", toggle_window, '0')
249 || try_cmd_1args(key, "to_wg_keywin", toggle_window, '1')
250 || try_cmd_1args(key, "to_wk_keywin", toggle_window, '2')
251 || try_cmd_1args(key, "to_mapwin", toggle_window, 'm')
252 || try_cmd_1args(key, "to_infowin", toggle_window, 'i')
253 || try_cmd_1args(key, "to_inv", toggle_window, 'c')
254 || try_cmd_1args(key, "to_logwin", toggle_window, 'l')
255 || try_cmd_1args(key, "cyc_win_f", cycle_active_win, 'f')
256 || try_cmd_1args(key, "cyc_win_b", cycle_active_win, 'b')
257 || try_cmd_1args(key, "g_keys_m", wrap_mod_selected_keyb, 'G')
258 || try_cmd_1args(key, "wg_keys_m", wrap_mod_selected_keyb, 'g')
259 || try_cmd_1args(key, "wk_keys_m", wrap_mod_selected_keyb, 'k')
260 || try_cmd_1args(key, "inv_u", nav_inventory, 'u')
261 || try_cmd_1args(key, "inv_d", nav_inventory, 'd')
262 || try_cmd_1args(key, "map_u", map_scroll, 'N')
263 || try_cmd_1args(key, "map_d", map_scroll, 'S')
264 || try_cmd_1args(key, "map_r", map_scroll, 'E')
265 || try_cmd_1args(key, "map_l", map_scroll, 'W')
266 || try_cmd_2args(key, "g_keys_u", wrap_mv_kb_mod, 'G', 'u')
267 || try_cmd_2args(key, "g_keys_d", wrap_mv_kb_mod, 'G', 'd')
268 || try_cmd_2args(key, "wg_keys_u", wrap_mv_kb_mod, 'g', 'u')
269 || try_cmd_2args(key, "wg_keys_d", wrap_mv_kb_mod, 'g', 'd')
270 || try_cmd_2args(key, "wk_keys_u", wrap_mv_kb_mod, 'k', 'u')
271 || try_cmd_2args(key, "wk_keys_d", wrap_mv_kb_mod, 'k', 'd')))