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_g_keywin"))
211 exit_err(toggle_window(win_meta, win_keys), world, err_toggle);
213 else if (key == get_available_keycode_to_action(world, "to_wg_keywin"))
215 uint8_t test = toggle_window(win_meta, get_win_by_id(world, '1'));
216 exit_err(test, world, err_toggle);
218 else if (key == get_available_keycode_to_action(world, "to_wk_keywin"))
220 uint8_t test = toggle_window(win_meta, get_win_by_id(world, '2'));
221 exit_err(test, world, err_toggle);
223 else if (key == get_available_keycode_to_action(world, "to_mapwin"))
225 exit_err(toggle_window(win_meta, win_map), world, err_toggle);
227 else if (key == get_available_keycode_to_action(world, "to_infowin"))
229 exit_err(toggle_window(win_meta, win_info), world, err_toggle);
231 else if (key == get_available_keycode_to_action(world, "to_logwin"))
233 exit_err(toggle_window(win_meta, win_log), world, err_toggle);
235 else if (key == get_available_keycode_to_action(world, "save_keys"))
237 save_keybindings(world, "config/keybindings_global",
239 save_keybindings(world, "config/keybindings_wingeom",
241 save_keybindings(world, "config/keybindings_winkeys",
244 else if (key == get_available_keycode_to_action(world, "g_keys_u"))
246 move_keyb_mod_selection(&world->kb_global, 'u');
248 else if (key == get_available_keycode_to_action(world, "g_keys_d"))
250 move_keyb_mod_selection(&world->kb_global, 'd');
252 else if (key == get_available_keycode_to_action(world, "g_keys_m"))
254 mod_selected_keyb(world, &world->kb_global);
256 else if (key == get_available_keycode_to_action(world, "wg_keys_u"))
258 move_keyb_mod_selection(&world->kb_wingeom, 'u');
260 else if (key == get_available_keycode_to_action(world, "wg_keys_d"))
262 move_keyb_mod_selection(&world->kb_wingeom, 'd');
264 else if (key == get_available_keycode_to_action(world, "wg_keys_m"))
266 mod_selected_keyb(world, &world->kb_wingeom);
268 else if (key == get_available_keycode_to_action(world, "wk_keys_u"))
270 move_keyb_mod_selection(&world->kb_winkeys, 'u');
272 else if (key == get_available_keycode_to_action(world, "wk_keys_d"))
274 move_keyb_mod_selection(&world->kb_winkeys, 'd');
276 else if (key == get_available_keycode_to_action(world, "wk_keys_m"))
278 mod_selected_keyb(world, &world->kb_winkeys);
280 else if (key == get_available_keycode_to_action(world, "map_u"))
282 map_scroll(world->map, NORTH, win_map->frame.size);
284 else if (key == get_available_keycode_to_action(world, "map_d"))
286 map_scroll(world->map, SOUTH, win_map->frame.size);
288 else if (key == get_available_keycode_to_action(world, "map_r"))
290 map_scroll(world->map, EAST, win_map->frame.size);
292 else if (key == get_available_keycode_to_action(world, "map_l"))
294 map_scroll(world->map, WEST, win_map->frame.size);
296 else if (key == get_available_keycode_to_action(world, "map_c"))
298 map_center_player(world->map, world->player, win_map->frame.size);
300 else if (key == get_available_keycode_to_action(world, "reload_wins"))
302 reload_win_config(world);
304 else if (key == get_available_keycode_to_action(world, "winconf"))
306 toggle_winconfig(world, world->wmeta->active);
308 else if (key == get_available_keycode_to_action(world, "save_winconf"))
310 save_win_configs(world);