home · contact · privacy
New command: type Z to reload default window configuration from window config files.
[plomrogue] / src / control.c
1 /* control.c */
2
3 #include "control.h"
4 #include <stdint.h> /* for uint8_t */
5 #include "windows.h" /* for cycle_active_win(), shift_active_win(), struct Win,
6                       *  struct WinMeta
7                       */
8 #include "keybindings.h" /* for get_action_key(), save_keybindings(),
9                           * keyswin_move_selection(), keyswin_mod_key()
10                           */
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                          */
17 #include "map_object_actions.h" /* for player_wait(), move_player() */
18 #include "command_db.h" /* for is_command_id_shortdsc() */
19
20
21
22 extern void record_control(int action, struct World * world)
23 {
24     if      (is_command_id_shortdsc(world, action, "wait"))
25     {
26         player_wait(world);
27     }
28     else if (is_command_id_shortdsc(world, action, "player_u"))
29     {
30         move_player(world, NORTH);
31     }
32     else if (is_command_id_shortdsc(world, action, "player_r"))
33     {
34         move_player(world, EAST);
35     }
36     else if (is_command_id_shortdsc(world, action, "player_d"))
37     {
38         move_player(world, SOUTH);
39     }
40     else if (is_command_id_shortdsc(world, action, "player_l"))
41     {
42         move_player(world, WEST);
43     }
44 }
45
46
47
48 extern uint8_t player_control(int key, struct World * world)
49 {
50     if      (key == get_action_key(world->keybindings, "player_u"))
51     {
52         move_player(world, NORTH);
53     }
54     else if (key == get_action_key(world->keybindings, "player_r"))
55     {
56         move_player(world, EAST);
57     }
58     else if (key == get_action_key(world->keybindings, "player_d"))
59     {
60         move_player(world, SOUTH);
61     }
62     else if (key == get_action_key(world->keybindings, "player_l"))
63     {
64         move_player(world, WEST);
65     }
66     else if (key == get_action_key(world->keybindings, "wait"))
67     {
68         player_wait(world);
69     }
70     else
71     {
72         return 1;
73     }
74     return 0;
75 }
76
77
78
79 extern uint8_t meta_control(int key, struct World * world)
80 {
81     struct WinMeta * win_meta = world->wins.meta;
82     struct Win * win_keys     = world->wins.keys;
83     struct Win * win_map      = world->wins.map;
84     struct Win * win_info     = world->wins.info;
85     struct Win * win_log      = world->wins.log;
86     char * err_toggle = "Trouble with toggle_window() in meta_keys().";
87     char * err_shift  = "Trouble with shift_active_win() in meta_keys().";
88     char * err_resize = "Trouble with growshrink_active_window() in "
89                         "meta_keys().";
90     if (key == get_action_key(world->keybindings, "quit"))
91     {
92         return 1;
93     }
94     else if (key == get_action_key(world->keybindings, "scrl_r"))
95     {
96         scroll_pad(win_meta, '+');
97     }
98     else if (key == get_action_key(world->keybindings, "scrl_l"))
99     {
100         scroll_pad(win_meta, '-');
101     }
102     else if (key == get_action_key(world->keybindings, "to_keywin"))
103     {
104         exit_err(toggle_window(win_meta, win_keys), world, err_toggle);
105     }
106     else if (key == get_action_key(world->keybindings, "to_mapwin"))
107     {
108         exit_err(toggle_window(win_meta, win_map), world, err_toggle);
109     }
110     else if (key == get_action_key(world->keybindings, "to_infowin"))
111     {
112         exit_err(toggle_window(win_meta, win_info), world, err_toggle);
113     }
114     else if (key == get_action_key(world->keybindings, "to_logwin"))
115     {
116         exit_err(toggle_window(win_meta, win_log), world, err_toggle);
117     }
118     else if (key == get_action_key(world->keybindings, "cyc_win_f"))
119     {
120         cycle_active_win(win_meta, 'f');
121     }
122     else if (key == get_action_key(world->keybindings, "cyc_win_b"))
123     {
124         cycle_active_win(win_meta, 'b');
125     }
126     else if (key == get_action_key(world->keybindings, "shift_f"))
127     {
128         exit_err(shift_active_win(win_meta, 'f'), world, err_shift);
129     }
130     else if (key == get_action_key(world->keybindings, "shift_b"))
131     {
132         exit_err(shift_active_win(win_meta, 'b'), world, err_shift);
133     }
134     else if (key == get_action_key(world->keybindings, "grow_h"))
135     {
136         exit_err(growshrink_active_window(win_meta, '*'), world, err_resize);
137     }
138     else if (key == get_action_key(world->keybindings, "shri_h"))
139     {
140         exit_err(growshrink_active_window(win_meta, '_'), world, err_resize);
141     }
142     else if (key == get_action_key(world->keybindings, "grow_v"))
143     {
144         exit_err(growshrink_active_window(win_meta, '+'), world, err_resize);
145     }
146     else if (key == get_action_key(world->keybindings, "shri_v"))
147     {
148         exit_err(growshrink_active_window(win_meta, '-'), world, err_resize);
149     }
150     else if (key == get_action_key(world->keybindings, "save_keys"))
151     {
152         save_keybindings(world);
153     }
154     else if (key == get_action_key(world->keybindings, "keys_u"))
155     {
156         keyswin_move_selection(world, 'u');
157     }
158     else if (key == get_action_key(world->keybindings, "keys_d"))
159     {
160         keyswin_move_selection(world, 'd');
161     }
162     else if (key == get_action_key(world->keybindings, "keys_m"))
163     {
164         keyswin_mod_key(world, win_meta);
165     }
166     else if (key == get_action_key(world->keybindings, "map_u"))
167     {
168         map_scroll(world->map, NORTH, win_map->frame.size);
169      }
170     else if (key == get_action_key(world->keybindings, "map_d"))
171     {
172         map_scroll(world->map, SOUTH, win_map->frame.size);
173     }
174     else if (key == get_action_key(world->keybindings, "map_r"))
175     {
176         map_scroll(world->map, EAST, win_map->frame.size);
177     }
178     else if (key == get_action_key(world->keybindings, "map_l"))
179     {
180         map_scroll(world->map, WEST, win_map->frame.size);
181     }
182     else if (key == get_action_key(world->keybindings, "map_c"))
183     {
184         map_center_player(world->map, world->player, win_map->frame.size);
185     }
186     else if (key == get_action_key(world->keybindings, "reload_wins"))
187     {
188         reload_win_config(world);
189     }
190     return 0;
191 }