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(), map_center_object() */
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 #include "command_db.h" /* for is_command_id_shortdsc() */
20 #include "misc.h" /* for load_interface_conf(), unload_interface_conf(),
21 * save_interface_conf()
23 #include "yx_uint16.h" /* for dir enum */
24 #include "map_objects.h" /* for get_player() */
28 extern uint16_t get_available_keycode_to_action(struct World * world,
31 uint16_t keycode = get_keycode_to_action(world->kb_global.kbs, name);
32 if (0 != keycode || 0 == world->wmeta->active)
36 struct WinConf * wc = get_winconf_by_win(world, world->wmeta->active);
39 keycode = get_keycode_to_action(wc->kb.kbs, name);
41 else if (1 == wc->view)
43 keycode = get_keycode_to_action(world->kb_wingeom.kbs, name);
45 else if (2 == wc->view)
47 keycode = get_keycode_to_action(world->kb_winkeys.kbs, name);
54 extern void record_control(int action, struct World * world)
56 if (is_command_id_shortdsc(world, action, "wait"))
60 else if (is_command_id_shortdsc(world, action, "player_u"))
62 move_player(world, NORTH);
64 else if (is_command_id_shortdsc(world, action, "player_r"))
66 move_player(world, EAST);
68 else if (is_command_id_shortdsc(world, action, "player_d"))
70 move_player(world, SOUTH);
72 else if (is_command_id_shortdsc(world, action, "player_l"))
74 move_player(world, WEST);
80 extern uint8_t player_control(int key, struct World * world)
82 if (key == get_available_keycode_to_action(world, "player_u"))
84 move_player(world, NORTH);
86 else if (key == get_available_keycode_to_action(world, "player_r"))
88 move_player(world, EAST);
90 else if (key == get_available_keycode_to_action(world, "player_d"))
92 move_player(world, SOUTH);
94 else if (key == get_available_keycode_to_action(world, "player_l"))
96 move_player(world, WEST);
98 else if (key == get_available_keycode_to_action(world, "wait"))
111 extern uint8_t wingeom_control(int key, struct World * world)
113 char * err_shift = "Trouble with shift_active_win() in wingeom_control().";
114 char * err_resize = "Trouble with growshrink_active_window() in "
115 "wingeom_control().";
116 if (key == get_available_keycode_to_action(world, "to_height_t"))
118 toggle_win_height_type(world, world->wmeta->active);
120 else if (key == get_available_keycode_to_action(world, "to_width_t"))
122 toggle_win_width_type(world, world->wmeta->active);
124 else if (key == get_available_keycode_to_action(world, "grow_h"))
126 exit_err(growshrink_active_window(world, '*'), world, err_resize);
128 else if (key == get_available_keycode_to_action(world, "shri_h"))
130 exit_err(growshrink_active_window(world, '_'), world, err_resize);
132 else if (key == get_available_keycode_to_action(world, "grow_v"))
134 exit_err(growshrink_active_window(world, '+'), world, err_resize);
136 else if (key == get_available_keycode_to_action(world, "shri_v"))
138 exit_err(growshrink_active_window(world, '-'), world, err_resize);
140 else if (key == get_available_keycode_to_action(world, "shift_f"))
142 exit_err(shift_active_win(world->wmeta, 'f'), world, err_shift);
144 else if (key == get_available_keycode_to_action(world, "shift_b"))
146 exit_err(shift_active_win(world->wmeta, 'b'), world, err_shift);
157 extern uint8_t winkeyb_control(int key, struct World * world)
159 struct WinConf * wc = get_winconf_by_win(world, world->wmeta->active);
160 if (key == get_available_keycode_to_action(world, "w_keys_u"))
162 move_keyb_mod_selection(&wc->kb, 'u');
164 else if (key == get_available_keycode_to_action(world, "w_keys_d"))
166 move_keyb_mod_selection(&wc->kb, 'd');
168 else if (key == get_available_keycode_to_action(world, "w_keys_m"))
170 mod_selected_keyb(world, &wc->kb);
181 extern uint8_t meta_control(int key, struct World * world)
183 struct WinMeta * win_meta = world->wmeta;
184 struct Win * win_map = get_win_by_id(world, 'm');
185 char * err_toggle = "Trouble with toggle_window() in meta_control().";
186 if (key == get_available_keycode_to_action(world, "quit"))
190 else if (key == get_available_keycode_to_action(world, "winconf"))
192 toggle_winconfig(world, world->wmeta->active);
194 else if (key == get_available_keycode_to_action(world, "cyc_win_f"))
196 cycle_active_win(world->wmeta, 'f');
198 else if (key == get_available_keycode_to_action(world, "cyc_win_b"))
200 cycle_active_win(world->wmeta, 'b');
202 else if (key == get_available_keycode_to_action(world, "scrl_r"))
204 scroll_pad(win_meta, '+');
206 else if (key == get_available_keycode_to_action(world, "scrl_l"))
208 scroll_pad(win_meta, '-');
210 else if (key == get_available_keycode_to_action(world, "to_a_keywin"))
212 uint8_t test = toggle_window(win_meta, get_win_by_id(world, 'k'));
213 exit_err(test, world, err_toggle);
215 else if (key == get_available_keycode_to_action(world, "to_g_keywin"))
217 uint8_t test = toggle_window(win_meta, get_win_by_id(world, '0'));
218 exit_err(test, world, err_toggle);
220 else if (key == get_available_keycode_to_action(world, "to_wg_keywin"))
222 uint8_t test = toggle_window(win_meta, get_win_by_id(world, '1'));
223 exit_err(test, world, err_toggle);
225 else if (key == get_available_keycode_to_action(world, "to_wk_keywin"))
227 uint8_t test = toggle_window(win_meta, get_win_by_id(world, '2'));
228 exit_err(test, world, err_toggle);
230 else if (key == get_available_keycode_to_action(world, "to_mapwin"))
232 exit_err(toggle_window(win_meta, win_map), world, err_toggle);
234 else if (key == get_available_keycode_to_action(world, "to_infowin"))
236 uint8_t test = toggle_window(win_meta, get_win_by_id(world, 'i'));
237 exit_err(test, world, err_toggle);
239 else if (key == get_available_keycode_to_action(world, "to_inv"))
241 uint8_t test = toggle_window(win_meta, get_win_by_id(world, 'c'));
242 exit_err(test, world, err_toggle);
244 else if (key == get_available_keycode_to_action(world, "to_logwin"))
246 uint8_t test = toggle_window(win_meta, get_win_by_id(world, 'l'));
247 exit_err(test, world, err_toggle);
249 else if (key == get_available_keycode_to_action(world, "save_conf"))
251 save_interface_conf(world);
253 else if (key == get_available_keycode_to_action(world, "g_keys_u"))
255 move_keyb_mod_selection(&world->kb_global, 'u');
257 else if (key == get_available_keycode_to_action(world, "g_keys_d"))
259 move_keyb_mod_selection(&world->kb_global, 'd');
261 else if (key == get_available_keycode_to_action(world, "g_keys_m"))
263 mod_selected_keyb(world, &world->kb_global);
265 else if (key == get_available_keycode_to_action(world, "wg_keys_u"))
267 move_keyb_mod_selection(&world->kb_wingeom, 'u');
269 else if (key == get_available_keycode_to_action(world, "wg_keys_d"))
271 move_keyb_mod_selection(&world->kb_wingeom, 'd');
273 else if (key == get_available_keycode_to_action(world, "wg_keys_m"))
275 mod_selected_keyb(world, &world->kb_wingeom);
277 else if (key == get_available_keycode_to_action(world, "wk_keys_u"))
279 move_keyb_mod_selection(&world->kb_winkeys, 'u');
281 else if (key == get_available_keycode_to_action(world, "wk_keys_d"))
283 move_keyb_mod_selection(&world->kb_winkeys, 'd');
285 else if (key == get_available_keycode_to_action(world, "wk_keys_m"))
287 mod_selected_keyb(world, &world->kb_winkeys);
289 else if (key == get_available_keycode_to_action(world, "map_u"))
291 map_scroll(world->map, NORTH, win_map->frame.size);
293 else if (key == get_available_keycode_to_action(world, "map_d"))
295 map_scroll(world->map, SOUTH, win_map->frame.size);
297 else if (key == get_available_keycode_to_action(world, "map_r"))
299 map_scroll(world->map, EAST, win_map->frame.size);
301 else if (key == get_available_keycode_to_action(world, "map_l"))
303 map_scroll(world->map, WEST, win_map->frame.size);
305 else if (key == get_available_keycode_to_action(world, "map_c"))
307 map_center_object(world->map, get_player(world), win_map->frame.size);
309 else if (key == get_available_keycode_to_action(world, "reload_conf"))
311 unload_interface_conf(world);
312 load_interface_conf(world);
314 else if (key == get_available_keycode_to_action(world, "winconf"))
316 toggle_winconfig(world, world->wmeta->active);