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 void record_control(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"))
89 extern uint8_t player_control(int key)
91 if (key == get_available_keycode_to_action("wait"))
95 else if (key == get_available_keycode_to_action("player_u"))
99 else if (key == get_available_keycode_to_action("player_r"))
103 else if (key == get_available_keycode_to_action("player_d"))
107 else if (key == get_available_keycode_to_action("player_l"))
111 else if (key == get_available_keycode_to_action("drop"))
115 else if (key == get_available_keycode_to_action("pick"))
128 extern uint8_t wingeom_control(int key)
130 char * err_shift = "Trouble with shift_active_win() in wingeom_control().";
131 char * err_resize = "Trouble with growshrink_active_window() in "
132 "wingeom_control().";
133 if (key == get_available_keycode_to_action("to_height_t"))
135 toggle_win_height_type(world.wmeta->active);
137 else if (key == get_available_keycode_to_action("to_width_t"))
139 toggle_win_width_type(world.wmeta->active);
141 else if (key == get_available_keycode_to_action("grow_h"))
143 exit_err(growshrink_active_window('*'), err_resize);
145 else if (key == get_available_keycode_to_action("shri_h"))
147 exit_err(growshrink_active_window('_'), err_resize);
149 else if (key == get_available_keycode_to_action("grow_v"))
151 exit_err(growshrink_active_window('+'), err_resize);
153 else if (key == get_available_keycode_to_action("shri_v"))
155 exit_err(growshrink_active_window('-'), err_resize);
157 else if (key == get_available_keycode_to_action("shift_f"))
159 exit_err(shift_active_win(world.wmeta, 'f'), err_shift);
161 else if (key == get_available_keycode_to_action("shift_b"))
163 exit_err(shift_active_win(world.wmeta, 'b'), err_shift);
174 extern uint8_t winkeyb_control(int key)
176 struct WinConf * wc = get_winconf_by_win(world.wmeta->active);
177 if (key == get_available_keycode_to_action("w_keys_u"))
179 move_keyb_mod_selection(&wc->kb, 'u');
181 else if (key == get_available_keycode_to_action("w_keys_d"))
183 move_keyb_mod_selection(&wc->kb, 'd');
185 else if (key == get_available_keycode_to_action("w_keys_m"))
187 mod_selected_keyb(&wc->kb);
198 extern uint8_t meta_control(int key)
200 struct WinMeta * win_meta = world.wmeta;
201 struct Win * win_map = get_win_by_id('m');
202 char * err_toggle = "Trouble with toggle_window() in meta_control().";
203 if (key == get_available_keycode_to_action("quit"))
207 else if (key == get_available_keycode_to_action("winconf"))
209 toggle_winconfig(world.wmeta->active);
211 else if (key == get_available_keycode_to_action("cyc_win_f"))
213 cycle_active_win(world.wmeta, 'f');
215 else if (key == get_available_keycode_to_action("cyc_win_b"))
217 cycle_active_win(world.wmeta, 'b');
219 else if (key == get_available_keycode_to_action("scrl_r"))
221 scroll_pad(win_meta, '+');
223 else if (key == get_available_keycode_to_action("scrl_l"))
225 scroll_pad(win_meta, '-');
227 else if (key == get_available_keycode_to_action("to_a_keywin"))
229 exit_err(toggle_window(win_meta, get_win_by_id('k')), err_toggle);
231 else if (key == get_available_keycode_to_action("to_g_keywin"))
233 exit_err(toggle_window(win_meta, get_win_by_id('0')), err_toggle);
235 else if (key == get_available_keycode_to_action("to_wg_keywin"))
237 exit_err(toggle_window(win_meta, get_win_by_id('1')), err_toggle);
239 else if (key == get_available_keycode_to_action("to_wk_keywin"))
241 exit_err(toggle_window(win_meta, get_win_by_id('2')), err_toggle);
243 else if (key == get_available_keycode_to_action("to_mapwin"))
245 exit_err(toggle_window(win_meta, win_map), err_toggle);
247 else if (key == get_available_keycode_to_action("to_infowin"))
249 exit_err(toggle_window(win_meta, get_win_by_id('i')), err_toggle);
251 else if (key == get_available_keycode_to_action("to_inv"))
253 exit_err(toggle_window(win_meta, get_win_by_id('c')), err_toggle);
255 else if (key == get_available_keycode_to_action("to_logwin"))
257 exit_err(toggle_window(win_meta, get_win_by_id('l')), err_toggle);
259 else if (key == get_available_keycode_to_action("save_conf"))
261 save_interface_conf();
263 else if (key == get_available_keycode_to_action("g_keys_u"))
265 move_keyb_mod_selection(&world.kb_global, 'u');
267 else if (key == get_available_keycode_to_action("g_keys_d"))
269 move_keyb_mod_selection(&world.kb_global, 'd');
271 else if (key == get_available_keycode_to_action("g_keys_m"))
273 mod_selected_keyb(&world.kb_global);
275 else if (key == get_available_keycode_to_action("wg_keys_u"))
277 move_keyb_mod_selection(&world.kb_wingeom, 'u');
279 else if (key == get_available_keycode_to_action("wg_keys_d"))
281 move_keyb_mod_selection(&world.kb_wingeom, 'd');
283 else if (key == get_available_keycode_to_action("wg_keys_m"))
285 mod_selected_keyb(&world.kb_wingeom);
287 else if (key == get_available_keycode_to_action("wk_keys_u"))
289 move_keyb_mod_selection(&world.kb_winkeys, 'u');
291 else if (key == get_available_keycode_to_action("wk_keys_d"))
293 move_keyb_mod_selection(&world.kb_winkeys, 'd');
295 else if (key == get_available_keycode_to_action("wk_keys_m"))
297 mod_selected_keyb(&world.kb_winkeys);
299 else if (key == get_available_keycode_to_action("map_u"))
301 map_scroll(win_map, world.map->size, NORTH);
303 else if (key == get_available_keycode_to_action("map_d"))
305 map_scroll(win_map, world.map->size, SOUTH);
307 else if (key == get_available_keycode_to_action("map_r"))
309 map_scroll(win_map, world.map->size, EAST);
311 else if (key == get_available_keycode_to_action("map_l"))
313 map_scroll(win_map, world.map->size, WEST);
315 else if (key == get_available_keycode_to_action("map_c"))
317 struct MapObj * player = get_player();
318 win_map->center = player->pos;
320 else if (key == get_available_keycode_to_action("inv_u"))
324 else if (key == get_available_keycode_to_action("inv_d"))
328 else if (key == get_available_keycode_to_action("reload_conf"))
330 unload_interface_conf();
331 load_interface_conf();
333 else if (key == get_available_keycode_to_action("winconf"))
335 toggle_winconfig(world.wmeta->active);