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(), save_keybindings(),
9 * move_keyb_mod_selection(), mod_selected_keyb()
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(), reload_win_config()
16 * toggle_winconfig(), save_win_configs(),
17 * toggle_win_height_type(), toggle_win_width_type()
19 #include "map_object_actions.h" /* for player_wait(), move_player() */
20 #include "command_db.h" /* for is_command_id_shortdsc() */
24 extern uint16_t get_available_keycode_to_action(struct World * world,
27 uint16_t keycode = get_keycode_to_action(world->kb_global.kbs, name);
28 if (0 != keycode || 0 == world->wmeta->active)
32 struct WinConf * wc = get_winconf_by_win(world, world->wmeta->active);
35 keycode = get_keycode_to_action(wc->kb.kbs, name);
37 else if (1 == wc->view)
39 keycode = get_keycode_to_action(world->kb_wingeom.kbs, name);
41 else if (2 == wc->view)
43 keycode = get_keycode_to_action(world->kb_winkeys.kbs, name);
50 extern void record_control(int action, struct World * world)
52 if (is_command_id_shortdsc(world, action, "wait"))
56 else if (is_command_id_shortdsc(world, action, "player_u"))
58 move_player(world, NORTH);
60 else if (is_command_id_shortdsc(world, action, "player_r"))
62 move_player(world, EAST);
64 else if (is_command_id_shortdsc(world, action, "player_d"))
66 move_player(world, SOUTH);
68 else if (is_command_id_shortdsc(world, action, "player_l"))
70 move_player(world, WEST);
76 extern uint8_t player_control(int key, struct World * world)
78 if (key == get_available_keycode_to_action(world, "player_u"))
80 move_player(world, NORTH);
82 else if (key == get_available_keycode_to_action(world, "player_r"))
84 move_player(world, EAST);
86 else if (key == get_available_keycode_to_action(world, "player_d"))
88 move_player(world, SOUTH);
90 else if (key == get_available_keycode_to_action(world, "player_l"))
92 move_player(world, WEST);
94 else if (key == get_available_keycode_to_action(world, "wait"))
107 extern uint8_t wingeom_control(int key, struct World * world)
109 char * err_shift = "Trouble with shift_active_win() in wingeom_control().";
110 char * err_resize = "Trouble with growshrink_active_window() in "
111 "wingeom_control().";
112 if (key == get_available_keycode_to_action(world, "to_height_t"))
114 toggle_win_height_type(world, world->wmeta->active);
116 else if (key == get_available_keycode_to_action(world, "to_width_t"))
118 toggle_win_width_type(world, world->wmeta->active);
120 else if (key == get_available_keycode_to_action(world, "grow_h"))
122 exit_err(growshrink_active_window(world, '*'), world, err_resize);
124 else if (key == get_available_keycode_to_action(world, "shri_h"))
126 exit_err(growshrink_active_window(world, '_'), world, err_resize);
128 else if (key == get_available_keycode_to_action(world, "grow_v"))
130 exit_err(growshrink_active_window(world, '+'), world, err_resize);
132 else if (key == get_available_keycode_to_action(world, "shri_v"))
134 exit_err(growshrink_active_window(world, '-'), world, err_resize);
136 else if (key == get_available_keycode_to_action(world, "shift_f"))
138 exit_err(shift_active_win(world->wmeta, 'f'), world, err_shift);
140 else if (key == get_available_keycode_to_action(world, "shift_b"))
142 exit_err(shift_active_win(world->wmeta, 'b'), world, err_shift);
153 extern uint8_t winkeyb_control(int key, struct World * world)
155 struct WinConf * wc = get_winconf_by_win(world, world->wmeta->active);
156 if (key == get_available_keycode_to_action(world, "w_keys_u"))
158 move_keyb_mod_selection(&wc->kb, 'u');
160 else if (key == get_available_keycode_to_action(world, "w_keys_d"))
162 move_keyb_mod_selection(&wc->kb, 'd');
164 else if (key == get_available_keycode_to_action(world, "w_keys_m"))
166 mod_selected_keyb(world, &wc->kb);
177 extern uint8_t meta_control(int key, struct World * world)
179 struct WinMeta * win_meta = world->wmeta;
180 struct Win * win_keys = get_win_by_id(world, '0'); /* Bad hardcoding. */
181 struct Win * win_map = get_win_by_id(world, 'm'); /* TODO: Replace. */
182 struct Win * win_info = get_win_by_id(world, 'i'); /* */
183 struct Win * win_log = get_win_by_id(world, 'l'); /* */
184 char * err_toggle = "Trouble with toggle_window() in meta_control().";
185 if (key == get_available_keycode_to_action(world, "quit"))
189 else if (key == get_available_keycode_to_action(world, "winconf"))
191 toggle_winconfig(world, world->wmeta->active);
193 else if (key == get_available_keycode_to_action(world, "cyc_win_f"))
195 cycle_active_win(world->wmeta, 'f');
197 else if (key == get_available_keycode_to_action(world, "cyc_win_b"))
199 cycle_active_win(world->wmeta, 'b');
201 else if (key == get_available_keycode_to_action(world, "scrl_r"))
203 scroll_pad(win_meta, '+');
205 else if (key == get_available_keycode_to_action(world, "scrl_l"))
207 scroll_pad(win_meta, '-');
209 else if (key == get_available_keycode_to_action(world, "to_a_keywin"))
211 uint8_t test = toggle_window(win_meta, get_win_by_id(world, 'k'));
212 exit_err(test, world, err_toggle);
214 else if (key == get_available_keycode_to_action(world, "to_g_keywin"))
216 exit_err(toggle_window(win_meta, win_keys), world, err_toggle);
218 else if (key == get_available_keycode_to_action(world, "to_wg_keywin"))
220 uint8_t test = toggle_window(win_meta, get_win_by_id(world, '1'));
221 exit_err(test, world, err_toggle);
223 else if (key == get_available_keycode_to_action(world, "to_wk_keywin"))
225 uint8_t test = toggle_window(win_meta, get_win_by_id(world, '2'));
226 exit_err(test, world, err_toggle);
228 else if (key == get_available_keycode_to_action(world, "to_mapwin"))
230 exit_err(toggle_window(win_meta, win_map), world, err_toggle);
232 else if (key == get_available_keycode_to_action(world, "to_infowin"))
234 exit_err(toggle_window(win_meta, win_info), world, err_toggle);
236 else if (key == get_available_keycode_to_action(world, "to_logwin"))
238 exit_err(toggle_window(win_meta, win_log), world, err_toggle);
240 else if (key == get_available_keycode_to_action(world, "save_keys"))
242 save_keybindings(world, "config/keybindings_global",
244 save_keybindings(world, "config/keybindings_wingeom",
246 save_keybindings(world, "config/keybindings_winkeys",
249 else if (key == get_available_keycode_to_action(world, "g_keys_u"))
251 move_keyb_mod_selection(&world->kb_global, 'u');
253 else if (key == get_available_keycode_to_action(world, "g_keys_d"))
255 move_keyb_mod_selection(&world->kb_global, 'd');
257 else if (key == get_available_keycode_to_action(world, "g_keys_m"))
259 mod_selected_keyb(world, &world->kb_global);
261 else if (key == get_available_keycode_to_action(world, "wg_keys_u"))
263 move_keyb_mod_selection(&world->kb_wingeom, 'u');
265 else if (key == get_available_keycode_to_action(world, "wg_keys_d"))
267 move_keyb_mod_selection(&world->kb_wingeom, 'd');
269 else if (key == get_available_keycode_to_action(world, "wg_keys_m"))
271 mod_selected_keyb(world, &world->kb_wingeom);
273 else if (key == get_available_keycode_to_action(world, "wk_keys_u"))
275 move_keyb_mod_selection(&world->kb_winkeys, 'u');
277 else if (key == get_available_keycode_to_action(world, "wk_keys_d"))
279 move_keyb_mod_selection(&world->kb_winkeys, 'd');
281 else if (key == get_available_keycode_to_action(world, "wk_keys_m"))
283 mod_selected_keyb(world, &world->kb_winkeys);
285 else if (key == get_available_keycode_to_action(world, "map_u"))
287 map_scroll(world->map, NORTH, win_map->frame.size);
289 else if (key == get_available_keycode_to_action(world, "map_d"))
291 map_scroll(world->map, SOUTH, win_map->frame.size);
293 else if (key == get_available_keycode_to_action(world, "map_r"))
295 map_scroll(world->map, EAST, win_map->frame.size);
297 else if (key == get_available_keycode_to_action(world, "map_l"))
299 map_scroll(world->map, WEST, win_map->frame.size);
301 else if (key == get_available_keycode_to_action(world, "map_c"))
303 map_center_player(world->map, world->player, win_map->frame.size);
305 else if (key == get_available_keycode_to_action(world, "reload_wins"))
307 reload_win_config(world);
309 else if (key == get_available_keycode_to_action(world, "winconf"))
311 toggle_winconfig(world, world->wmeta->active);
313 else if (key == get_available_keycode_to_action(world, "save_winconf"))
315 save_win_configs(world);