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 "map_window.h" /* for map_center() */
12 #include "wincontrol.h" /* init_winconfs(), init_wins(),
13 * sorted_wintoggle_and_activate()
15 #include "windows.h" /* suspend_win() */
16 #include "world.h" /* global world */
20 extern void save_interface_conf()
22 save_keybindings("confclient/keybindings_global", &world.kb_global);
23 save_keybindings("confclient/keybindings_wingeom", &world.kb_wingeom);
24 save_keybindings("confclient/keybindings_winkeys", &world.kb_winkeys);
30 extern void load_interface_conf()
32 init_keybindings("confclient/keybindings_global", &world.kb_global);
33 init_keybindings("confclient/keybindings_wingeom", &world.kb_wingeom);
34 init_keybindings("confclient/keybindings_winkeys", &world.kb_winkeys);
36 char * err_s = "load_interface_conf() makes illegaly large virtual screen.";
37 char * err_m = "load_interface_conf(): memory alloc error via newpad().";
38 uint32_t maxy_test = getmaxy(world.wmeta.screen);
39 uint32_t maxx_test = getmaxx(world.wmeta.screen);
40 exit_err(maxy_test > UINT16_MAX || maxx_test > UINT16_MAX, err_s);
41 world.wmeta.padsize.y = maxy_test;
42 world.wmeta.padsize.x = maxx_test;
43 world.wmeta.pad = newpad(world.wmeta.padsize.y, 1);
44 exit_err(NULL == world.wmeta.pad, err_m);
46 sorted_wintoggle_and_activate();
47 set_cleanup_flag(CLEANUP_INTERFACE);
52 extern void unload_interface_conf()
54 free_keybindings(world.kb_global.kbs);
55 free_keybindings(world.kb_wingeom.kbs);
56 free_keybindings(world.kb_winkeys.kbs);
57 while (0 != world.wmeta.active)
59 suspend_win(world.wmeta.active);
62 delwin(world.wmeta.pad);
67 extern void reload_interface_conf()
69 unload_interface_conf();
70 load_interface_conf();
76 extern uint16_t center_offset(uint16_t position, uint16_t mapsize,
80 if (mapsize > framesize)
82 if (position > framesize / 2)
84 if (position < mapsize - (framesize / 2))
86 offset = position - (framesize / 2);
90 offset = mapsize - framesize;
99 extern void nav_inventory(char dir)
103 world.player_inventory_select = world.player_inventory_select
104 - (world.player_inventory_select > 0);
109 for (i = 0; '\0' != world.player_inventory[i]; i++)
111 n_elems = n_elems + ('\n' == world.player_inventory[i]);
113 world.player_inventory_select = world.player_inventory_select
114 + (world.player_inventory_select < n_elems);