X-Git-Url: https://plomlompom.com/repos/?a=blobdiff_plain;f=src%2Fcontrol.c;h=287c099c875d89f2be010012726aed34c1d687b5;hb=4b5302fe73b9aa08819ff740bbf8286352a990fb;hp=8531b4c6b8be8059e7e60641c65ffd93dbc71db2;hpb=88aa628d575ff69afba9e7d7a90873e40ded1fde;p=plomrogue diff --git a/src/control.c b/src/control.c index 8531b4c..287c099 100644 --- a/src/control.c +++ b/src/control.c @@ -5,141 +5,146 @@ #include "windows.h" /* for cycle_active_win(), shift_active_win(), struct Win, * struct WinMeta */ -#include "keybindings.h" /* for get_keycode_to_action(), save_keybindings(), - * move_keyb_mod_selection(), mod_selected_keyb() +#include "keybindings.h" /* for get_keycode_to_action(), mod_selected_keyb(), + * move_keyb_mod_selection() */ -#include "map.h" /* for map_scroll(), map_center_player(), dir enum */ -#include "main.h" /* for World struct */ +#include "map.h" /* for map_scroll() */ +#include "main.h" /* for world global */ #include "rexit.h" /* for exit_err() */ #include "wincontrol.h" /* for scroll_pad(), toggle_window(), - * growshrink_active_window(), reload_win_config() - * toggle_winconfig(), save_win_configs(), + * growshrink_active_window(), toggle_winconfig(), * toggle_win_height_type(), toggle_win_width_type() */ -#include "map_object_actions.h" /* for player_wait(), move_player() */ +#include "map_object_actions.h" /* for player_wait(), move_player(), + * player_drop(), player_pick() + */ #include "command_db.h" /* for is_command_id_shortdsc() */ +#include "misc.h" /* for load_interface_conf(), unload_interface_conf(), + * save_interface_conf(), nav_inventory() + */ +#include "yx_uint16.h" /* for dir enum */ +#include "map_objects.h" /* for get_player() */ -extern uint16_t get_available_keycode_to_action(struct World * world, - char * name) +extern uint16_t get_available_keycode_to_action(char * name) { - uint16_t keycode = get_keycode_to_action(world->kb_global.kbs, name); - if (0 != keycode || 0 == world->wmeta->active) + uint16_t keycode = get_keycode_to_action(world.kb_global.kbs, name); + if (0 != keycode || 0 == world.wmeta->active) { return keycode; } - struct WinConf * wc = get_winconf_by_win(world, world->wmeta->active); + struct WinConf * wc = get_winconf_by_win(world.wmeta->active); if (0 == wc->view) { keycode = get_keycode_to_action(wc->kb.kbs, name); } else if (1 == wc->view) { - keycode = get_keycode_to_action(world->kb_wingeom.kbs, name); + keycode = get_keycode_to_action(world.kb_wingeom.kbs, name); } else if (2 == wc->view) { - keycode = get_keycode_to_action(world->kb_winkeys.kbs, name); + keycode = get_keycode_to_action(world.kb_winkeys.kbs, name); } return keycode; } -extern void record_control(int action, struct World * world) +extern uint8_t player_control_by_id(int action) { - if (is_command_id_shortdsc(world, action, "wait")) + if (is_command_id_shortdsc(action, "wait")) { - player_wait(world); + player_wait(); } - else if (is_command_id_shortdsc(world, action, "player_u")) + else if (is_command_id_shortdsc(action, "player_u")) { - move_player(world, NORTH); + move_player(NORTH); } - else if (is_command_id_shortdsc(world, action, "player_r")) + else if (is_command_id_shortdsc(action, "player_r")) { - move_player(world, EAST); + move_player(EAST); } - else if (is_command_id_shortdsc(world, action, "player_d")) + else if (is_command_id_shortdsc(action, "player_d")) { - move_player(world, SOUTH); + move_player(SOUTH); } - else if (is_command_id_shortdsc(world, action, "player_l")) + else if (is_command_id_shortdsc(action, "player_l")) { - move_player(world, WEST); + move_player(WEST); } -} - - - -extern uint8_t player_control(int key, struct World * world) -{ - if (key == get_available_keycode_to_action(world, "player_u")) + else if (is_command_id_shortdsc(action, "drop")) { - move_player(world, NORTH); + player_drop(); } - else if (key == get_available_keycode_to_action(world, "player_r")) + else if (is_command_id_shortdsc(action, "pick")) { - move_player(world, EAST); + player_pick(); } - else if (key == get_available_keycode_to_action(world, "player_d")) - { - move_player(world, SOUTH); - } - else if (key == get_available_keycode_to_action(world, "player_l")) + else { - move_player(world, WEST); + return 0; } - else if (key == get_available_keycode_to_action(world, "wait")) + return 1; +} + + + +extern uint8_t player_control_by_key(int key) +{ + char * action_name = get_func_to_keycode(world.kb_global.kbs, key); + if (NULL == action_name && 0 != world.wmeta->active) { - player_wait(world); + struct WinConf * wc = get_winconf_by_win(world.wmeta->active); + action_name = get_func_to_keycode(wc->kb.kbs, key); } - else + if (NULL != action_name) { - return 0; + uint8_t action_id = get_command_id(action_name); + return player_control_by_id(action_id); } - return 1; + return 0; } -extern uint8_t wingeom_control(int key, struct World * world) +extern uint8_t wingeom_control(int key) { char * err_shift = "Trouble with shift_active_win() in wingeom_control()."; char * err_resize = "Trouble with growshrink_active_window() in " "wingeom_control()."; - if (key == get_available_keycode_to_action(world, "to_height_t")) + if (key == get_available_keycode_to_action("to_height_t")) { - toggle_win_height_type(world, world->wmeta->active); + toggle_win_height_type(world.wmeta->active); } - else if (key == get_available_keycode_to_action(world, "to_width_t")) + else if (key == get_available_keycode_to_action("to_width_t")) { - toggle_win_width_type(world, world->wmeta->active); + toggle_win_width_type(world.wmeta->active); } - else if (key == get_available_keycode_to_action(world, "grow_h")) + else if (key == get_available_keycode_to_action("grow_h")) { - exit_err(growshrink_active_window(world, '*'), world, err_resize); + exit_err(growshrink_active_window('*'), err_resize); } - else if (key == get_available_keycode_to_action(world, "shri_h")) + else if (key == get_available_keycode_to_action("shri_h")) { - exit_err(growshrink_active_window(world, '_'), world, err_resize); + exit_err(growshrink_active_window('_'), err_resize); } - else if (key == get_available_keycode_to_action(world, "grow_v")) + else if (key == get_available_keycode_to_action("grow_v")) { - exit_err(growshrink_active_window(world, '+'), world, err_resize); + exit_err(growshrink_active_window('+'), err_resize); } - else if (key == get_available_keycode_to_action(world, "shri_v")) + else if (key == get_available_keycode_to_action("shri_v")) { - exit_err(growshrink_active_window(world, '-'), world, err_resize); + exit_err(growshrink_active_window('-'), err_resize); } - else if (key == get_available_keycode_to_action(world, "shift_f")) + else if (key == get_available_keycode_to_action("shift_f")) { - exit_err(shift_active_win(world->wmeta, 'f'), world, err_shift); + exit_err(shift_active_win(world.wmeta, 'f'), err_shift); } - else if (key == get_available_keycode_to_action(world, "shift_b")) + else if (key == get_available_keycode_to_action("shift_b")) { - exit_err(shift_active_win(world->wmeta, 'b'), world, err_shift); + exit_err(shift_active_win(world.wmeta, 'b'), err_shift); } else { @@ -150,20 +155,20 @@ extern uint8_t wingeom_control(int key, struct World * world) -extern uint8_t winkeyb_control(int key, struct World * world) +extern uint8_t winkeyb_control(int key) { - struct WinConf * wc = get_winconf_by_win(world, world->wmeta->active); - if (key == get_available_keycode_to_action(world, "w_keys_u")) + struct WinConf * wc = get_winconf_by_win(world.wmeta->active); + if (key == get_available_keycode_to_action("w_keys_u")) { move_keyb_mod_selection(&wc->kb, 'u'); } - else if (key == get_available_keycode_to_action(world, "w_keys_d")) + else if (key == get_available_keycode_to_action("w_keys_d")) { move_keyb_mod_selection(&wc->kb, 'd'); } - else if (key == get_available_keycode_to_action(world, "w_keys_m")) + else if (key == get_available_keycode_to_action("w_keys_m")) { - mod_selected_keyb(world, &wc->kb); + mod_selected_keyb(&wc->kb); } else { @@ -174,150 +179,144 @@ extern uint8_t winkeyb_control(int key, struct World * world) -extern uint8_t meta_control(int key, struct World * world) +extern uint8_t meta_control(int key) { - struct WinMeta * win_meta = world->wmeta; - struct Win * win_keys = get_win_by_id(world, '0'); /* Bad hardcoding. */ - struct Win * win_map = get_win_by_id(world, 'm'); /* TODO: Replace. */ - struct Win * win_info = get_win_by_id(world, 'i'); /* */ - struct Win * win_log = get_win_by_id(world, 'l'); /* */ + struct WinMeta * win_meta = world.wmeta; + struct Win * win_map = get_win_by_id('m'); char * err_toggle = "Trouble with toggle_window() in meta_control()."; - if (key == get_available_keycode_to_action(world, "quit")) + if (key == get_available_keycode_to_action("quit")) { return 1; } - else if (key == get_available_keycode_to_action(world, "winconf")) + else if (key == get_available_keycode_to_action("winconf")) { - toggle_winconfig(world, world->wmeta->active); + toggle_winconfig(world.wmeta->active); } - else if (key == get_available_keycode_to_action(world, "cyc_win_f")) + else if (key == get_available_keycode_to_action("cyc_win_f")) { - cycle_active_win(world->wmeta, 'f'); + cycle_active_win(world.wmeta, 'f'); } - else if (key == get_available_keycode_to_action(world, "cyc_win_b")) + else if (key == get_available_keycode_to_action("cyc_win_b")) { - cycle_active_win(world->wmeta, 'b'); + cycle_active_win(world.wmeta, 'b'); } - else if (key == get_available_keycode_to_action(world, "scrl_r")) + else if (key == get_available_keycode_to_action("scrl_r")) { scroll_pad(win_meta, '+'); } - else if (key == get_available_keycode_to_action(world, "scrl_l")) + else if (key == get_available_keycode_to_action("scrl_l")) { scroll_pad(win_meta, '-'); } - else if (key == get_available_keycode_to_action(world, "to_a_keywin")) + else if (key == get_available_keycode_to_action("to_a_keywin")) { - uint8_t test = toggle_window(win_meta, get_win_by_id(world, 'k')); - exit_err(test, world, err_toggle); + exit_err(toggle_window(win_meta, get_win_by_id('k')), err_toggle); } - else if (key == get_available_keycode_to_action(world, "to_g_keywin")) + else if (key == get_available_keycode_to_action("to_g_keywin")) { - exit_err(toggle_window(win_meta, win_keys), world, err_toggle); + exit_err(toggle_window(win_meta, get_win_by_id('0')), err_toggle); } - else if (key == get_available_keycode_to_action(world, "to_wg_keywin")) + else if (key == get_available_keycode_to_action("to_wg_keywin")) { - uint8_t test = toggle_window(win_meta, get_win_by_id(world, '1')); - exit_err(test, world, err_toggle); + exit_err(toggle_window(win_meta, get_win_by_id('1')), err_toggle); } - else if (key == get_available_keycode_to_action(world, "to_wk_keywin")) + else if (key == get_available_keycode_to_action("to_wk_keywin")) { - uint8_t test = toggle_window(win_meta, get_win_by_id(world, '2')); - exit_err(test, world, err_toggle); + exit_err(toggle_window(win_meta, get_win_by_id('2')), err_toggle); } - else if (key == get_available_keycode_to_action(world, "to_mapwin")) + else if (key == get_available_keycode_to_action("to_mapwin")) { - exit_err(toggle_window(win_meta, win_map), world, err_toggle); + exit_err(toggle_window(win_meta, win_map), err_toggle); } - else if (key == get_available_keycode_to_action(world, "to_infowin")) + else if (key == get_available_keycode_to_action("to_infowin")) { - exit_err(toggle_window(win_meta, win_info), world, err_toggle); + exit_err(toggle_window(win_meta, get_win_by_id('i')), err_toggle); } - else if (key == get_available_keycode_to_action(world, "to_inv")) + else if (key == get_available_keycode_to_action("to_inv")) { - uint8_t test = toggle_window(win_meta, get_win_by_id(world, 'c')); - exit_err(test, world, err_toggle); + exit_err(toggle_window(win_meta, get_win_by_id('c')), err_toggle); } - else if (key == get_available_keycode_to_action(world, "to_logwin")) + else if (key == get_available_keycode_to_action("to_logwin")) { - exit_err(toggle_window(win_meta, win_log), world, err_toggle); + exit_err(toggle_window(win_meta, get_win_by_id('l')), err_toggle); } - else if (key == get_available_keycode_to_action(world, "save_keys")) + else if (key == get_available_keycode_to_action("save_conf")) { - save_keybindings(world, "config/keybindings_global", - &world->kb_global); - save_keybindings(world, "config/keybindings_wingeom", - &world->kb_wingeom); - save_keybindings(world, "config/keybindings_winkeys", - &world->kb_winkeys); + save_interface_conf(); } - else if (key == get_available_keycode_to_action(world, "g_keys_u")) + else if (key == get_available_keycode_to_action("g_keys_u")) { - move_keyb_mod_selection(&world->kb_global, 'u'); + move_keyb_mod_selection(&world.kb_global, 'u'); } - else if (key == get_available_keycode_to_action(world, "g_keys_d")) + else if (key == get_available_keycode_to_action("g_keys_d")) { - move_keyb_mod_selection(&world->kb_global, 'd'); + move_keyb_mod_selection(&world.kb_global, 'd'); } - else if (key == get_available_keycode_to_action(world, "g_keys_m")) + else if (key == get_available_keycode_to_action("g_keys_m")) { - mod_selected_keyb(world, &world->kb_global); + mod_selected_keyb(&world.kb_global); } - else if (key == get_available_keycode_to_action(world, "wg_keys_u")) + else if (key == get_available_keycode_to_action("wg_keys_u")) { - move_keyb_mod_selection(&world->kb_wingeom, 'u'); + move_keyb_mod_selection(&world.kb_wingeom, 'u'); } - else if (key == get_available_keycode_to_action(world, "wg_keys_d")) + else if (key == get_available_keycode_to_action("wg_keys_d")) { - move_keyb_mod_selection(&world->kb_wingeom, 'd'); + move_keyb_mod_selection(&world.kb_wingeom, 'd'); } - else if (key == get_available_keycode_to_action(world, "wg_keys_m")) + else if (key == get_available_keycode_to_action("wg_keys_m")) { - mod_selected_keyb(world, &world->kb_wingeom); + mod_selected_keyb(&world.kb_wingeom); } - else if (key == get_available_keycode_to_action(world, "wk_keys_u")) + else if (key == get_available_keycode_to_action("wk_keys_u")) { - move_keyb_mod_selection(&world->kb_winkeys, 'u'); + move_keyb_mod_selection(&world.kb_winkeys, 'u'); } - else if (key == get_available_keycode_to_action(world, "wk_keys_d")) + else if (key == get_available_keycode_to_action("wk_keys_d")) { - move_keyb_mod_selection(&world->kb_winkeys, 'd'); + move_keyb_mod_selection(&world.kb_winkeys, 'd'); } - else if (key == get_available_keycode_to_action(world, "wk_keys_m")) + else if (key == get_available_keycode_to_action("wk_keys_m")) { - mod_selected_keyb(world, &world->kb_winkeys); + mod_selected_keyb(&world.kb_winkeys); } - else if (key == get_available_keycode_to_action(world, "map_u")) + else if (key == get_available_keycode_to_action("map_u")) { - map_scroll(world->map, NORTH, win_map->frame.size); - } - else if (key == get_available_keycode_to_action(world, "map_d")) + map_scroll(win_map, world.map->size, NORTH); + } + else if (key == get_available_keycode_to_action("map_d")) + { + map_scroll(win_map, world.map->size, SOUTH); + } + else if (key == get_available_keycode_to_action("map_r")) { - map_scroll(world->map, SOUTH, win_map->frame.size); + map_scroll(win_map, world.map->size, EAST); } - else if (key == get_available_keycode_to_action(world, "map_r")) + else if (key == get_available_keycode_to_action("map_l")) { - map_scroll(world->map, EAST, win_map->frame.size); + map_scroll(win_map, world.map->size, WEST); } - else if (key == get_available_keycode_to_action(world, "map_l")) + else if (key == get_available_keycode_to_action("map_c")) { - map_scroll(world->map, WEST, win_map->frame.size); + struct MapObj * player = get_player(); + win_map->center = player->pos; } - else if (key == get_available_keycode_to_action(world, "map_c")) + else if (key == get_available_keycode_to_action("inv_u")) { - map_center_player(world->map, world->player, win_map->frame.size); + nav_inventory('u'); } - else if (key == get_available_keycode_to_action(world, "reload_wins")) + else if (key == get_available_keycode_to_action("inv_d")) { - reload_win_config(world); + nav_inventory('d'); } - else if (key == get_available_keycode_to_action(world, "winconf")) + else if (key == get_available_keycode_to_action("reload_conf")) { - toggle_winconfig(world, world->wmeta->active); + unload_interface_conf(); + load_interface_conf(); } - else if (key == get_available_keycode_to_action(world, "save_winconf")) + else if (key == get_available_keycode_to_action("winconf")) { - save_win_configs(world); + toggle_winconfig(world.wmeta->active); } return 0; }