From: Christian Heller Date: Sat, 31 Aug 2013 03:24:32 +0000 (+0200) Subject: New command: type Z to reload default window configuration from window config files. X-Git-Tag: tce~987 X-Git-Url: https://plomlompom.com/repos/ledger?a=commitdiff_plain;h=e505542d10413b5cf94edda90bdc793a48db9385;p=plomrogue New command: type Z to reload default window configuration from window config files. --- diff --git a/README b/README index 3c8e054..6ad1207 100644 --- a/README +++ b/README @@ -45,6 +45,7 @@ Y shift window backwards _ shrink window horizontally + grow window vertically - shrink window vertically +Z reload window configuration w scroll map up x scroll map down diff --git a/config/commands b/config/commands index f946af0..e4e9824 100644 --- a/config/commands +++ b/config/commands @@ -27,3 +27,4 @@ 27 player_l player left 28 player_r player right 29 wait wait / next turn +30 reload_wins reload windows configuration diff --git a/config/keybindings b/config/keybindings index 704fed9..009a8b7 100644 --- a/config/keybindings +++ b/config/keybindings @@ -27,3 +27,4 @@ 65 player_l 68 player_r 83 wait +90 reload_wins diff --git a/src/control.c b/src/control.c index 0c782ab..b9ebbe1 100644 --- a/src/control.c +++ b/src/control.c @@ -12,7 +12,7 @@ #include "main.h" /* for World struct */ #include "rexit.h" /* for exit_err() */ #include "wincontrol.h" /* for scroll_pad(), toggle_window(), - * growshrink_active_window() + * growshrink_active_window(), reload_win_config() */ #include "map_object_actions.h" /* for player_wait(), move_player() */ #include "command_db.h" /* for is_command_id_shortdsc() */ @@ -181,7 +181,11 @@ extern uint8_t meta_control(int key, struct World * world) } else if (key == get_action_key(world->keybindings, "map_c")) { - map_center_player (world->map, world->player, win_map->frame.size); + map_center_player(world->map, world->player, win_map->frame.size); + } + else if (key == get_action_key(world->keybindings, "reload_wins")) + { + reload_win_config(world); } return 0; } diff --git a/src/wincontrol.c b/src/wincontrol.c index db144d1..0417852 100644 --- a/src/wincontrol.c +++ b/src/wincontrol.c @@ -5,27 +5,49 @@ #include /* for strlen() */ #include /* for uint8_t, uint16_t */ #include "windows.h" /* for suspend_win(), append_win(), reset_pad_offset(), - * resize_active_win(), init_win(), structs Win, WinMeta + * resize_active_win(), init_win(), free_win(), + * structs Win, WinMeta */ #include "yx_uint16.h" /* for yx_uint16 struct */ #include "main.h" /* for Wins struct */ #include "misc.h" /* for textfile_sizes() */ #include "rexit.h" /* for exit_err() */ #include "main.h" /* for World, Wins structs */ +#include "draw_wins.h" /* for draw_keys_win(), draw_info_win(), draw_log_win(), + * draw_map_win + */ + + + +extern void reload_win_config(struct World * world) +{ + while (0 != world->wins.meta->active) + { + suspend_win(world->wins.meta, world->wins.meta->active); + } + free_win(world->wins.info); + free_win(world->wins.keys); + free_win(world->wins.map); + free_win(world->wins.log); + world->wins.keys = init_win_from_file(world, "Keys", draw_keys_win); + world->wins.info = init_win_from_file(world, "Info", draw_info_win); + world->wins.log = init_win_from_file(world, "Log", draw_log_win); + world->wins.map = init_win_from_file(world, "Map", draw_map_win); + sorted_wintoggle(world); +} extern struct Win * init_win_from_file(struct World * world, char * w_name, void (* f) (struct Win *)) { - char * err = "Trouble in init_win_from_file() with malloc()."; + char * err_m = "Trouble in init_win_from_file() with malloc()."; char * prefix = "config/windows/"; uint8_t size = strlen(prefix) + strlen(w_name) + 1; char * path = malloc(size); - exit_err(NULL == path, world, err); + exit_err(NULL == path, world, err_m); sprintf(path, "%s%s", prefix, w_name); - - err = "Trouble in init_win_from_file() with fopen()."; + char * err = "Trouble in init_win_from_file() with fopen()."; FILE * file = fopen(path, "r"); free(path); exit_err(NULL == file, world, err); @@ -33,9 +55,11 @@ extern struct Win * init_win_from_file(struct World * world, char * w_name, err = "Trouble in init_win_from_file() with textfile_sizes()."; exit_err(textfile_sizes(file, &linemax, NULL), world, err); char * line = malloc(linemax); + exit_err(NULL == line, world, err_m); err = "Trouble in init_win_from_file() with fgets()."; exit_err(NULL == fgets(line, linemax, file), world, err); char * title = malloc(strlen(line)); + exit_err(NULL == title, world, err_m); memcpy(title, line, strlen(line) - 1); /* Eliminate newline char at end */ title[strlen(line) - 1] = '\0'; /* of string. */ exit_err(NULL == fgets(line, linemax, file), world, err); @@ -45,7 +69,6 @@ extern struct Win * init_win_from_file(struct World * world, char * w_name, free(line); err = "Trouble in init_win_from_file() with fclose()."; exit_err(fclose(file), world, err); - struct WinMeta * wmeta = world->wins.meta; struct Win * wp; err = "Trouble in init_win_from_file() with init_win()."; @@ -150,4 +173,3 @@ extern uint8_t growshrink_active_window(struct WinMeta * win_meta, char change) } return 0; } - diff --git a/src/wincontrol.h b/src/wincontrol.h index 29a6ddf..404ae1b 100644 --- a/src/wincontrol.h +++ b/src/wincontrol.h @@ -16,6 +16,11 @@ struct World; +/* Reload windows in order and sizes defined in win config. */ +extern void reload_win_config(struct World * world); + + + /* Wrapper around init_win() that reads the desired window size and title from a * file at the path prefixing the provided win name "w_name" with * "config/windows/". "f"() is the window drawing function (Win._draw()).