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_player(), dir enum */
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()
26 extern uint16_t get_available_keycode_to_action(struct World * world,
29 uint16_t keycode = get_keycode_to_action(world->kb_global.kbs, name);
30 if (0 != keycode || 0 == world->wmeta->active)
34 struct WinConf * wc = get_winconf_by_win(world, world->wmeta->active);
37 keycode = get_keycode_to_action(wc->kb.kbs, name);
39 else if (1 == wc->view)
41 keycode = get_keycode_to_action(world->kb_wingeom.kbs, name);
43 else if (2 == wc->view)
45 keycode = get_keycode_to_action(world->kb_winkeys.kbs, name);
52 extern void record_control(int action, struct World * world)
54 if (is_command_id_shortdsc(world, action, "wait"))
58 else if (is_command_id_shortdsc(world, action, "player_u"))
60 move_player(world, NORTH);
62 else if (is_command_id_shortdsc(world, action, "player_r"))
64 move_player(world, EAST);
66 else if (is_command_id_shortdsc(world, action, "player_d"))
68 move_player(world, SOUTH);
70 else if (is_command_id_shortdsc(world, action, "player_l"))
72 move_player(world, WEST);
78 extern uint8_t player_control(int key, struct World * world)
80 if (key == get_available_keycode_to_action(world, "player_u"))
82 move_player(world, NORTH);
84 else if (key == get_available_keycode_to_action(world, "player_r"))
86 move_player(world, EAST);
88 else if (key == get_available_keycode_to_action(world, "player_d"))
90 move_player(world, SOUTH);
92 else if (key == get_available_keycode_to_action(world, "player_l"))
94 move_player(world, WEST);
96 else if (key == get_available_keycode_to_action(world, "wait"))
109 extern uint8_t wingeom_control(int key, struct World * world)
111 char * err_shift = "Trouble with shift_active_win() in wingeom_control().";
112 char * err_resize = "Trouble with growshrink_active_window() in "
113 "wingeom_control().";
114 if (key == get_available_keycode_to_action(world, "to_height_t"))
116 toggle_win_height_type(world, world->wmeta->active);
118 else if (key == get_available_keycode_to_action(world, "to_width_t"))
120 toggle_win_width_type(world, world->wmeta->active);
122 else if (key == get_available_keycode_to_action(world, "grow_h"))
124 exit_err(growshrink_active_window(world, '*'), world, err_resize);
126 else if (key == get_available_keycode_to_action(world, "shri_h"))
128 exit_err(growshrink_active_window(world, '_'), world, err_resize);
130 else if (key == get_available_keycode_to_action(world, "grow_v"))
132 exit_err(growshrink_active_window(world, '+'), world, err_resize);
134 else if (key == get_available_keycode_to_action(world, "shri_v"))
136 exit_err(growshrink_active_window(world, '-'), world, err_resize);
138 else if (key == get_available_keycode_to_action(world, "shift_f"))
140 exit_err(shift_active_win(world->wmeta, 'f'), world, err_shift);
142 else if (key == get_available_keycode_to_action(world, "shift_b"))
144 exit_err(shift_active_win(world->wmeta, 'b'), world, err_shift);
155 extern uint8_t winkeyb_control(int key, struct World * world)
157 struct WinConf * wc = get_winconf_by_win(world, world->wmeta->active);
158 if (key == get_available_keycode_to_action(world, "w_keys_u"))
160 move_keyb_mod_selection(&wc->kb, 'u');
162 else if (key == get_available_keycode_to_action(world, "w_keys_d"))
164 move_keyb_mod_selection(&wc->kb, 'd');
166 else if (key == get_available_keycode_to_action(world, "w_keys_m"))
168 mod_selected_keyb(world, &wc->kb);
179 extern uint8_t meta_control(int key, struct World * world)
181 struct WinMeta * win_meta = world->wmeta;
182 struct Win * win_keys = get_win_by_id(world, '0'); /* Bad hardcoding. */
183 struct Win * win_map = get_win_by_id(world, 'm'); /* TODO: Replace. */
184 struct Win * win_info = get_win_by_id(world, 'i'); /* */
185 struct Win * win_log = get_win_by_id(world, 'l'); /* */
186 char * err_toggle = "Trouble with toggle_window() in meta_control().";
187 if (key == get_available_keycode_to_action(world, "quit"))
191 else if (key == get_available_keycode_to_action(world, "winconf"))
193 toggle_winconfig(world, world->wmeta->active);
195 else if (key == get_available_keycode_to_action(world, "cyc_win_f"))
197 cycle_active_win(world->wmeta, 'f');
199 else if (key == get_available_keycode_to_action(world, "cyc_win_b"))
201 cycle_active_win(world->wmeta, 'b');
203 else if (key == get_available_keycode_to_action(world, "scrl_r"))
205 scroll_pad(win_meta, '+');
207 else if (key == get_available_keycode_to_action(world, "scrl_l"))
209 scroll_pad(win_meta, '-');
211 else if (key == get_available_keycode_to_action(world, "to_a_keywin"))
213 uint8_t test = toggle_window(win_meta, get_win_by_id(world, 'k'));
214 exit_err(test, world, err_toggle);
216 else if (key == get_available_keycode_to_action(world, "to_g_keywin"))
218 exit_err(toggle_window(win_meta, win_keys), 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 exit_err(toggle_window(win_meta, win_info), world, err_toggle);
238 else if (key == get_available_keycode_to_action(world, "to_inv"))
240 uint8_t test = toggle_window(win_meta, get_win_by_id(world, 'c'));
241 exit_err(test, world, err_toggle);
243 else if (key == get_available_keycode_to_action(world, "to_logwin"))
245 exit_err(toggle_window(win_meta, win_log), world, err_toggle);
247 else if (key == get_available_keycode_to_action(world, "save_conf"))
249 save_interface_conf(world);
251 else if (key == get_available_keycode_to_action(world, "g_keys_u"))
253 move_keyb_mod_selection(&world->kb_global, 'u');
255 else if (key == get_available_keycode_to_action(world, "g_keys_d"))
257 move_keyb_mod_selection(&world->kb_global, 'd');
259 else if (key == get_available_keycode_to_action(world, "g_keys_m"))
261 mod_selected_keyb(world, &world->kb_global);
263 else if (key == get_available_keycode_to_action(world, "wg_keys_u"))
265 move_keyb_mod_selection(&world->kb_wingeom, 'u');
267 else if (key == get_available_keycode_to_action(world, "wg_keys_d"))
269 move_keyb_mod_selection(&world->kb_wingeom, 'd');
271 else if (key == get_available_keycode_to_action(world, "wg_keys_m"))
273 mod_selected_keyb(world, &world->kb_wingeom);
275 else if (key == get_available_keycode_to_action(world, "wk_keys_u"))
277 move_keyb_mod_selection(&world->kb_winkeys, 'u');
279 else if (key == get_available_keycode_to_action(world, "wk_keys_d"))
281 move_keyb_mod_selection(&world->kb_winkeys, 'd');
283 else if (key == get_available_keycode_to_action(world, "wk_keys_m"))
285 mod_selected_keyb(world, &world->kb_winkeys);
287 else if (key == get_available_keycode_to_action(world, "map_u"))
289 map_scroll(world->map, NORTH, win_map->frame.size);
291 else if (key == get_available_keycode_to_action(world, "map_d"))
293 map_scroll(world->map, SOUTH, win_map->frame.size);
295 else if (key == get_available_keycode_to_action(world, "map_r"))
297 map_scroll(world->map, EAST, win_map->frame.size);
299 else if (key == get_available_keycode_to_action(world, "map_l"))
301 map_scroll(world->map, WEST, win_map->frame.size);
303 else if (key == get_available_keycode_to_action(world, "map_c"))
305 map_center_player(world->map, world->player, win_map->frame.size);
307 else if (key == get_available_keycode_to_action(world, "reload_conf"))
309 unload_interface_conf(world);
310 load_interface_conf(world);
312 else if (key == get_available_keycode_to_action(world, "winconf"))
314 toggle_winconfig(world, world->wmeta->active);