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 struct */
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(struct World * world,
33 uint16_t keycode = get_keycode_to_action(world->kb_global.kbs, name);
34 if (0 != keycode || 0 == world->wmeta->active)
38 struct WinConf * wc = get_winconf_by_win(world, world->wmeta->active);
41 keycode = get_keycode_to_action(wc->kb.kbs, name);
43 else if (1 == wc->view)
45 keycode = get_keycode_to_action(world->kb_wingeom.kbs, name);
47 else if (2 == wc->view)
49 keycode = get_keycode_to_action(world->kb_winkeys.kbs, name);
56 extern void record_control(int action, struct World * world)
58 if (is_command_id_shortdsc(world, action, "wait"))
62 else if (is_command_id_shortdsc(world, action, "player_u"))
64 move_player(world, NORTH);
66 else if (is_command_id_shortdsc(world, action, "player_r"))
68 move_player(world, EAST);
70 else if (is_command_id_shortdsc(world, action, "player_d"))
72 move_player(world, SOUTH);
74 else if (is_command_id_shortdsc(world, action, "player_l"))
76 move_player(world, WEST);
78 else if (is_command_id_shortdsc(world, action, "drop"))
82 else if (is_command_id_shortdsc(world, action, "pick"))
90 extern uint8_t player_control(int key, struct World * world)
92 if (key == get_available_keycode_to_action(world, "wait"))
96 else if (key == get_available_keycode_to_action(world, "player_u"))
98 move_player(world, NORTH);
100 else if (key == get_available_keycode_to_action(world, "player_r"))
102 move_player(world, EAST);
104 else if (key == get_available_keycode_to_action(world, "player_d"))
106 move_player(world, SOUTH);
108 else if (key == get_available_keycode_to_action(world, "player_l"))
110 move_player(world, WEST);
112 else if (key == get_available_keycode_to_action(world, "drop"))
116 else if (key == get_available_keycode_to_action(world, "pick"))
129 extern uint8_t wingeom_control(int key, struct World * world)
131 char * err_shift = "Trouble with shift_active_win() in wingeom_control().";
132 char * err_resize = "Trouble with growshrink_active_window() in "
133 "wingeom_control().";
134 if (key == get_available_keycode_to_action(world, "to_height_t"))
136 toggle_win_height_type(world, world->wmeta->active);
138 else if (key == get_available_keycode_to_action(world, "to_width_t"))
140 toggle_win_width_type(world, world->wmeta->active);
142 else if (key == get_available_keycode_to_action(world, "grow_h"))
144 exit_err(growshrink_active_window(world, '*'), world, err_resize);
146 else if (key == get_available_keycode_to_action(world, "shri_h"))
148 exit_err(growshrink_active_window(world, '_'), world, err_resize);
150 else if (key == get_available_keycode_to_action(world, "grow_v"))
152 exit_err(growshrink_active_window(world, '+'), world, err_resize);
154 else if (key == get_available_keycode_to_action(world, "shri_v"))
156 exit_err(growshrink_active_window(world, '-'), world, err_resize);
158 else if (key == get_available_keycode_to_action(world, "shift_f"))
160 exit_err(shift_active_win(world->wmeta, 'f'), world, err_shift);
162 else if (key == get_available_keycode_to_action(world, "shift_b"))
164 exit_err(shift_active_win(world->wmeta, 'b'), world, err_shift);
175 extern uint8_t winkeyb_control(int key, struct World * world)
177 struct WinConf * wc = get_winconf_by_win(world, world->wmeta->active);
178 if (key == get_available_keycode_to_action(world, "w_keys_u"))
180 move_keyb_mod_selection(&wc->kb, 'u');
182 else if (key == get_available_keycode_to_action(world, "w_keys_d"))
184 move_keyb_mod_selection(&wc->kb, 'd');
186 else if (key == get_available_keycode_to_action(world, "w_keys_m"))
188 mod_selected_keyb(world, &wc->kb);
199 extern uint8_t meta_control(int key, struct World * world)
201 struct WinMeta * win_meta = world->wmeta;
202 struct Win * win_map = get_win_by_id(world, 'm');
203 char * err_toggle = "Trouble with toggle_window() in meta_control().";
204 if (key == get_available_keycode_to_action(world, "quit"))
208 else if (key == get_available_keycode_to_action(world, "winconf"))
210 toggle_winconfig(world, world->wmeta->active);
212 else if (key == get_available_keycode_to_action(world, "cyc_win_f"))
214 cycle_active_win(world->wmeta, 'f');
216 else if (key == get_available_keycode_to_action(world, "cyc_win_b"))
218 cycle_active_win(world->wmeta, 'b');
220 else if (key == get_available_keycode_to_action(world, "scrl_r"))
222 scroll_pad(win_meta, '+');
224 else if (key == get_available_keycode_to_action(world, "scrl_l"))
226 scroll_pad(win_meta, '-');
228 else if (key == get_available_keycode_to_action(world, "to_a_keywin"))
230 uint8_t test = toggle_window(win_meta, get_win_by_id(world, 'k'));
231 exit_err(test, world, err_toggle);
233 else if (key == get_available_keycode_to_action(world, "to_g_keywin"))
235 uint8_t test = toggle_window(win_meta, get_win_by_id(world, '0'));
236 exit_err(test, world, err_toggle);
238 else if (key == get_available_keycode_to_action(world, "to_wg_keywin"))
240 uint8_t test = toggle_window(win_meta, get_win_by_id(world, '1'));
241 exit_err(test, world, err_toggle);
243 else if (key == get_available_keycode_to_action(world, "to_wk_keywin"))
245 uint8_t test = toggle_window(win_meta, get_win_by_id(world, '2'));
246 exit_err(test, world, err_toggle);
248 else if (key == get_available_keycode_to_action(world, "to_mapwin"))
250 exit_err(toggle_window(win_meta, win_map), world, err_toggle);
252 else if (key == get_available_keycode_to_action(world, "to_infowin"))
254 uint8_t test = toggle_window(win_meta, get_win_by_id(world, 'i'));
255 exit_err(test, world, err_toggle);
257 else if (key == get_available_keycode_to_action(world, "to_inv"))
259 uint8_t test = toggle_window(win_meta, get_win_by_id(world, 'c'));
260 exit_err(test, world, err_toggle);
262 else if (key == get_available_keycode_to_action(world, "to_logwin"))
264 uint8_t test = toggle_window(win_meta, get_win_by_id(world, 'l'));
265 exit_err(test, world, err_toggle);
267 else if (key == get_available_keycode_to_action(world, "save_conf"))
269 save_interface_conf(world);
271 else if (key == get_available_keycode_to_action(world, "g_keys_u"))
273 move_keyb_mod_selection(&world->kb_global, 'u');
275 else if (key == get_available_keycode_to_action(world, "g_keys_d"))
277 move_keyb_mod_selection(&world->kb_global, 'd');
279 else if (key == get_available_keycode_to_action(world, "g_keys_m"))
281 mod_selected_keyb(world, &world->kb_global);
283 else if (key == get_available_keycode_to_action(world, "wg_keys_u"))
285 move_keyb_mod_selection(&world->kb_wingeom, 'u');
287 else if (key == get_available_keycode_to_action(world, "wg_keys_d"))
289 move_keyb_mod_selection(&world->kb_wingeom, 'd');
291 else if (key == get_available_keycode_to_action(world, "wg_keys_m"))
293 mod_selected_keyb(world, &world->kb_wingeom);
295 else if (key == get_available_keycode_to_action(world, "wk_keys_u"))
297 move_keyb_mod_selection(&world->kb_winkeys, 'u');
299 else if (key == get_available_keycode_to_action(world, "wk_keys_d"))
301 move_keyb_mod_selection(&world->kb_winkeys, 'd');
303 else if (key == get_available_keycode_to_action(world, "wk_keys_m"))
305 mod_selected_keyb(world, &world->kb_winkeys);
307 else if (key == get_available_keycode_to_action(world, "map_u"))
309 map_scroll(win_map, world->map->size, NORTH);
311 else if (key == get_available_keycode_to_action(world, "map_d"))
313 map_scroll(win_map, world->map->size, SOUTH);
315 else if (key == get_available_keycode_to_action(world, "map_r"))
317 map_scroll(win_map, world->map->size, EAST);
319 else if (key == get_available_keycode_to_action(world, "map_l"))
321 map_scroll(win_map, world->map->size, WEST);
323 else if (key == get_available_keycode_to_action(world, "map_c"))
325 struct MapObj * player = get_player(world);
326 win_map->center = player->pos;
328 else if (key == get_available_keycode_to_action(world, "inv_u"))
330 nav_inventory(world, 'u');
332 else if (key == get_available_keycode_to_action(world, "inv_d"))
334 nav_inventory(world, 'd');
336 else if (key == get_available_keycode_to_action(world, "reload_conf"))
338 unload_interface_conf(world);
339 load_interface_conf(world);
341 else if (key == get_available_keycode_to_action(world, "winconf"))
343 toggle_winconfig(world, world->wmeta->active);