1 /* src/client/misc.c */
4 #include <ncurses.h> /* delwin(), getmaxy(), getmaxx(), newpad() */
5 #include <stdint.h> /* uint8_t, uint16_t, uint32_t */
6 #include "../common/rexit.h" /* exit_err() */
7 #include "cleanup.h" /* for set_cleanup_flag() */
8 #include "keybindings.h" /* init_keybindings(), free_keybindings(),
11 #include "wincontrol.h" /* init_winconfs(), init_wins(),
12 * sorted_wintoggle_and_activate()
14 #include "windows.h" /* suspend_win() */
15 #include "world.h" /* global world */
19 extern void save_interface_conf()
21 save_keybindings("confclient/keybindings_global", &world.kb_global);
22 save_keybindings("confclient/keybindings_wingeom", &world.kb_wingeom);
23 save_keybindings("confclient/keybindings_winkeys", &world.kb_winkeys);
29 extern void load_interface_conf()
31 init_keybindings("confclient/keybindings_global", &world.kb_global);
32 init_keybindings("confclient/keybindings_wingeom", &world.kb_wingeom);
33 init_keybindings("confclient/keybindings_winkeys", &world.kb_winkeys);
35 char * err_s = "load_interface_conf() makes illegaly large virtual screen.";
36 char * err_m = "load_interface_conf(): memory alloc error via newpad().";
37 uint32_t maxy_test = getmaxy(world.wmeta.screen);
38 uint32_t maxx_test = getmaxx(world.wmeta.screen);
39 exit_err(maxy_test > UINT16_MAX || maxx_test > UINT16_MAX, err_s);
40 world.wmeta.padsize.y = maxy_test;
41 world.wmeta.padsize.x = maxx_test;
42 world.wmeta.pad = newpad(world.wmeta.padsize.y, 1);
43 exit_err(NULL == world.wmeta.pad, err_m);
45 sorted_wintoggle_and_activate();
46 set_cleanup_flag(CLEANUP_INTERFACE);
51 extern void unload_interface_conf()
53 free_keybindings(world.kb_global.kbs);
54 free_keybindings(world.kb_wingeom.kbs);
55 free_keybindings(world.kb_winkeys.kbs);
56 while (0 != world.wmeta.active)
58 suspend_win(world.wmeta.active);
61 delwin(world.wmeta.pad);
66 extern void reload_interface_conf()
68 unload_interface_conf();
69 load_interface_conf();
74 extern uint16_t center_offset(uint16_t position, uint16_t mapsize,
78 if (mapsize > framesize)
80 if (position > framesize / 2)
82 if (position < mapsize - (framesize / 2))
84 offset = position - (framesize / 2);
88 offset = mapsize - framesize;
97 extern void nav_inventory(char dir)
101 world.player_inventory_select = world.player_inventory_select
102 - (world.player_inventory_select > 0);
107 for (i = 0; '\0' != world.player_inventory[i]; i++)
109 n_elems = n_elems + ('\n' == world.player_inventory[i]);
111 world.player_inventory_select = world.player_inventory_select
112 + (world.player_inventory_select < n_elems);