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_action_key(), save_keybindings(),
9 * keyswin_move_selection(), keyswin_mod_key()
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 void record_control(int action, struct World * world)
26 if (is_command_id_shortdsc(world, action, "wait"))
30 else if (is_command_id_shortdsc(world, action, "player_u"))
32 move_player(world, NORTH);
34 else if (is_command_id_shortdsc(world, action, "player_r"))
36 move_player(world, EAST);
38 else if (is_command_id_shortdsc(world, action, "player_d"))
40 move_player(world, SOUTH);
42 else if (is_command_id_shortdsc(world, action, "player_l"))
44 move_player(world, WEST);
50 extern uint8_t player_control(int key, struct World * world)
52 if (key == get_action_key(world->keybindings, "player_u"))
54 move_player(world, NORTH);
56 else if (key == get_action_key(world->keybindings, "player_r"))
58 move_player(world, EAST);
60 else if (key == get_action_key(world->keybindings, "player_d"))
62 move_player(world, SOUTH);
64 else if (key == get_action_key(world->keybindings, "player_l"))
66 move_player(world, WEST);
68 else if (key == get_action_key(world->keybindings, "wait"))
81 extern uint8_t meta_control(int key, struct World * world)
83 struct WinMeta * win_meta = world->wmeta;
84 struct Win * win_keys = get_win_by_id(world, 'k'); /* Bad hardcoding. */
85 struct Win * win_map = get_win_by_id(world, 'm'); /* TODO: Replace. */
86 struct Win * win_info = get_win_by_id(world, 'i'); /* */
87 struct Win * win_log = get_win_by_id(world, 'l'); /* */
88 char * err_toggle = "Trouble with toggle_window() in meta_keys().";
89 char * err_shift = "Trouble with shift_active_win() in meta_keys().";
90 char * err_resize = "Trouble with growshrink_active_window() in "
92 if (key == get_action_key(world->keybindings, "quit"))
96 else if (key == get_action_key(world->keybindings, "scrl_r"))
98 scroll_pad(win_meta, '+');
100 else if (key == get_action_key(world->keybindings, "scrl_l"))
102 scroll_pad(win_meta, '-');
104 else if (key == get_action_key(world->keybindings, "to_keywin"))
106 exit_err(toggle_window(win_meta, win_keys), world, err_toggle);
108 else if (key == get_action_key(world->keybindings, "to_mapwin"))
110 exit_err(toggle_window(win_meta, win_map), world, err_toggle);
112 else if (key == get_action_key(world->keybindings, "to_infowin"))
114 exit_err(toggle_window(win_meta, win_info), world, err_toggle);
116 else if (key == get_action_key(world->keybindings, "to_logwin"))
118 exit_err(toggle_window(win_meta, win_log), world, err_toggle);
120 else if (key == get_action_key(world->keybindings, "cyc_win_f"))
122 cycle_active_win(win_meta, 'f');
124 else if (key == get_action_key(world->keybindings, "cyc_win_b"))
126 cycle_active_win(win_meta, 'b');
128 else if (key == get_action_key(world->keybindings, "shift_f"))
130 exit_err(shift_active_win(win_meta, 'f'), world, err_shift);
132 else if (key == get_action_key(world->keybindings, "shift_b"))
134 exit_err(shift_active_win(win_meta, 'b'), world, err_shift);
136 else if (key == get_action_key(world->keybindings, "grow_h"))
138 exit_err(growshrink_active_window(world, '*'), world, err_resize);
140 else if (key == get_action_key(world->keybindings, "shri_h"))
142 exit_err(growshrink_active_window(world, '_'), world, err_resize);
144 else if (key == get_action_key(world->keybindings, "grow_v"))
146 exit_err(growshrink_active_window(world, '+'), world, err_resize);
148 else if (key == get_action_key(world->keybindings, "shri_v"))
150 exit_err(growshrink_active_window(world, '-'), world, err_resize);
152 else if (key == get_action_key(world->keybindings, "save_keys"))
154 save_keybindings(world);
156 else if (key == get_action_key(world->keybindings, "keys_u"))
158 keyswin_move_selection(world, 'u');
160 else if (key == get_action_key(world->keybindings, "keys_d"))
162 keyswin_move_selection(world, 'd');
164 else if (key == get_action_key(world->keybindings, "keys_m"))
166 keyswin_mod_key(world, win_meta);
168 else if (key == get_action_key(world->keybindings, "map_u"))
170 map_scroll(world->map, NORTH, win_map->frame.size);
172 else if (key == get_action_key(world->keybindings, "map_d"))
174 map_scroll(world->map, SOUTH, win_map->frame.size);
176 else if (key == get_action_key(world->keybindings, "map_r"))
178 map_scroll(world->map, EAST, win_map->frame.size);
180 else if (key == get_action_key(world->keybindings, "map_l"))
182 map_scroll(world->map, WEST, win_map->frame.size);
184 else if (key == get_action_key(world->keybindings, "map_c"))
186 map_center_player(world->map, world->player, win_map->frame.size);
188 else if (key == get_action_key(world->keybindings, "reload_wins"))
190 reload_win_config(world);
192 else if (key == get_action_key(world->keybindings, "winconf"))
194 toggle_winconfig(world, world->wmeta->active);
196 else if (key == get_action_key(world->keybindings, "to_height_t"))
198 toggle_win_height_type(world, world->wmeta->active);
200 else if (key == get_action_key(world->keybindings, "to_width_t"))
202 toggle_win_width_type(world, world->wmeta->active);
204 else if (key == get_action_key(world->keybindings, "save_winconf"))
206 save_win_configs(world);