4 #include <stdint.h> /* for uint8_t */
5 #include "windows.h" /* for cycle_active_win(), shift_active_win(), struct Win,
8 #include "keybindings.h" /* for get_keycode_to_action(), mod_selected_keyb(),
9 * move_keyb_mod_selection()
11 #include "map.h" /* for map_scroll() */
12 #include "main.h" /* for world global */
13 #include "rexit.h" /* for exit_err() */
14 #include "wincontrol.h" /* for scroll_pad(), toggle_window(),
15 * growshrink_active_window(), toggle_winconfig(),
16 * toggle_win_height_type(), toggle_win_width_type()
18 #include "map_object_actions.h" /* for player_wait(), move_player(),
19 * player_drop(), player_pick()
21 #include "command_db.h" /* for is_command_id_shortdsc() */
22 #include "misc.h" /* for load_interface_conf(), unload_interface_conf(),
23 * save_interface_conf(), nav_inventory()
25 #include "yx_uint16.h" /* for dir enum */
26 #include "map_objects.h" /* for get_player() */
30 extern uint16_t get_available_keycode_to_action(char * name)
32 uint16_t keycode = get_keycode_to_action(world.kb_global.kbs, name);
33 if (0 != keycode || 0 == world.wmeta->active)
37 struct WinConf * wc = get_winconf_by_win(world.wmeta->active);
40 keycode = get_keycode_to_action(wc->kb.kbs, name);
42 else if (1 == wc->view)
44 keycode = get_keycode_to_action(world.kb_wingeom.kbs, name);
46 else if (2 == wc->view)
48 keycode = get_keycode_to_action(world.kb_winkeys.kbs, name);
55 extern uint8_t player_control_by_id(int action)
57 if (is_command_id_shortdsc(action, "wait"))
61 else if (is_command_id_shortdsc(action, "player_u"))
65 else if (is_command_id_shortdsc(action, "player_r"))
69 else if (is_command_id_shortdsc(action, "player_d"))
73 else if (is_command_id_shortdsc(action, "player_l"))
77 else if (is_command_id_shortdsc(action, "drop"))
81 else if (is_command_id_shortdsc(action, "pick"))
94 extern uint8_t player_control_by_key(int key)
96 char * action_name = get_func_to_keycode(world.kb_global.kbs, key);
97 if (NULL == action_name && 0 != world.wmeta->active)
99 struct WinConf * wc = get_winconf_by_win(world.wmeta->active);
100 action_name = get_func_to_keycode(wc->kb.kbs, key);
102 if (NULL != action_name)
104 uint8_t action_id = get_command_id(action_name);
105 return player_control_by_id(action_id);
112 extern uint8_t wingeom_control(int key)
114 char * err_shift = "Trouble with shift_active_win() in wingeom_control().";
115 char * err_resize = "Trouble with growshrink_active_window() in "
116 "wingeom_control().";
117 if (key == get_available_keycode_to_action("to_height_t"))
119 toggle_win_height_type(world.wmeta->active);
121 else if (key == get_available_keycode_to_action("to_width_t"))
123 toggle_win_width_type(world.wmeta->active);
125 else if (key == get_available_keycode_to_action("grow_h"))
127 exit_err(growshrink_active_window('*'), err_resize);
129 else if (key == get_available_keycode_to_action("shri_h"))
131 exit_err(growshrink_active_window('_'), err_resize);
133 else if (key == get_available_keycode_to_action("grow_v"))
135 exit_err(growshrink_active_window('+'), err_resize);
137 else if (key == get_available_keycode_to_action("shri_v"))
139 exit_err(growshrink_active_window('-'), err_resize);
141 else if (key == get_available_keycode_to_action("shift_f"))
143 exit_err(shift_active_win(world.wmeta, 'f'), err_shift);
145 else if (key == get_available_keycode_to_action("shift_b"))
147 exit_err(shift_active_win(world.wmeta, 'b'), err_shift);
158 extern uint8_t winkeyb_control(int key)
160 struct WinConf * wc = get_winconf_by_win(world.wmeta->active);
161 if (key == get_available_keycode_to_action("w_keys_u"))
163 move_keyb_mod_selection(&wc->kb, 'u');
165 else if (key == get_available_keycode_to_action("w_keys_d"))
167 move_keyb_mod_selection(&wc->kb, 'd');
169 else if (key == get_available_keycode_to_action("w_keys_m"))
171 mod_selected_keyb(&wc->kb);
182 extern uint8_t meta_control(int key)
184 struct WinMeta * win_meta = world.wmeta;
185 struct Win * win_map = get_win_by_id('m');
186 char * err_toggle = "Trouble with toggle_window() in meta_control().";
187 if (key == get_available_keycode_to_action("quit"))
191 else if (key == get_available_keycode_to_action("winconf"))
193 toggle_winconfig(world.wmeta->active);
195 else if (key == get_available_keycode_to_action("cyc_win_f"))
197 cycle_active_win(world.wmeta, 'f');
199 else if (key == get_available_keycode_to_action("cyc_win_b"))
201 cycle_active_win(world.wmeta, 'b');
203 else if (key == get_available_keycode_to_action("scrl_r"))
205 scroll_pad(win_meta, '+');
207 else if (key == get_available_keycode_to_action("scrl_l"))
209 scroll_pad(win_meta, '-');
211 else if (key == get_available_keycode_to_action("to_a_keywin"))
213 exit_err(toggle_window(win_meta, get_win_by_id('k')), err_toggle);
215 else if (key == get_available_keycode_to_action("to_g_keywin"))
217 exit_err(toggle_window(win_meta, get_win_by_id('0')), err_toggle);
219 else if (key == get_available_keycode_to_action("to_wg_keywin"))
221 exit_err(toggle_window(win_meta, get_win_by_id('1')), err_toggle);
223 else if (key == get_available_keycode_to_action("to_wk_keywin"))
225 exit_err(toggle_window(win_meta, get_win_by_id('2')), err_toggle);
227 else if (key == get_available_keycode_to_action("to_mapwin"))
229 exit_err(toggle_window(win_meta, win_map), err_toggle);
231 else if (key == get_available_keycode_to_action("to_infowin"))
233 exit_err(toggle_window(win_meta, get_win_by_id('i')), err_toggle);
235 else if (key == get_available_keycode_to_action("to_inv"))
237 exit_err(toggle_window(win_meta, get_win_by_id('c')), err_toggle);
239 else if (key == get_available_keycode_to_action("to_logwin"))
241 exit_err(toggle_window(win_meta, get_win_by_id('l')), err_toggle);
243 else if (key == get_available_keycode_to_action("save_conf"))
245 save_interface_conf();
247 else if (key == get_available_keycode_to_action("g_keys_u"))
249 move_keyb_mod_selection(&world.kb_global, 'u');
251 else if (key == get_available_keycode_to_action("g_keys_d"))
253 move_keyb_mod_selection(&world.kb_global, 'd');
255 else if (key == get_available_keycode_to_action("g_keys_m"))
257 mod_selected_keyb(&world.kb_global);
259 else if (key == get_available_keycode_to_action("wg_keys_u"))
261 move_keyb_mod_selection(&world.kb_wingeom, 'u');
263 else if (key == get_available_keycode_to_action("wg_keys_d"))
265 move_keyb_mod_selection(&world.kb_wingeom, 'd');
267 else if (key == get_available_keycode_to_action("wg_keys_m"))
269 mod_selected_keyb(&world.kb_wingeom);
271 else if (key == get_available_keycode_to_action("wk_keys_u"))
273 move_keyb_mod_selection(&world.kb_winkeys, 'u');
275 else if (key == get_available_keycode_to_action("wk_keys_d"))
277 move_keyb_mod_selection(&world.kb_winkeys, 'd');
279 else if (key == get_available_keycode_to_action("wk_keys_m"))
281 mod_selected_keyb(&world.kb_winkeys);
283 else if (key == get_available_keycode_to_action("map_u"))
285 map_scroll(win_map, world.map->size, NORTH);
287 else if (key == get_available_keycode_to_action("map_d"))
289 map_scroll(win_map, world.map->size, SOUTH);
291 else if (key == get_available_keycode_to_action("map_r"))
293 map_scroll(win_map, world.map->size, EAST);
295 else if (key == get_available_keycode_to_action("map_l"))
297 map_scroll(win_map, world.map->size, WEST);
299 else if (key == get_available_keycode_to_action("map_c"))
301 struct MapObj * player = get_player();
302 win_map->center = player->pos;
304 else if (key == get_available_keycode_to_action("inv_u"))
308 else if (key == get_available_keycode_to_action("inv_d"))
312 else if (key == get_available_keycode_to_action("reload_conf"))
314 unload_interface_conf();
315 load_interface_conf();
317 else if (key == get_available_keycode_to_action("winconf"))
319 toggle_winconfig(world.wmeta->active);