home · contact · privacy
Client: Moved pad creation/sizing/deletion into (un)load_interface(), so that
[plomrogue] / src / client / misc.c
1 /* src/client/misc.c */
2
3 #include "misc.h"
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(),
9                           * save_keybindings()
10                           */
11 #include "wincontrol.h" /* init_winconfs(), init_wins(),
12                          * sorted_wintoggle_and_activate()
13                          */
14 #include "windows.h" /* suspend_win() */
15 #include "world.h" /* global world */
16
17
18
19 extern void save_interface_conf()
20 {
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);
24     save_win_configs();
25 }
26
27
28
29 extern void load_interface_conf()
30 {
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);
34     init_winconfs();
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);
44     init_wins();
45     sorted_wintoggle_and_activate();
46     set_cleanup_flag(CLEANUP_INTERFACE);
47 }
48
49
50
51 extern void unload_interface_conf()
52 {
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)
57     {
58         suspend_win(world.wmeta.active);
59     }
60     free_winconfs();
61     delwin(world.wmeta.pad);
62 }
63
64
65
66 extern void reload_interface_conf()
67 {
68     unload_interface_conf();
69     load_interface_conf();
70 }
71
72
73
74 extern uint16_t center_offset(uint16_t position, uint16_t mapsize,
75                               uint16_t framesize)
76 {
77     uint16_t offset = 0;
78     if (mapsize > framesize)
79     {
80         if (position > framesize / 2)
81         {
82             if (position < mapsize - (framesize / 2))
83             {
84                 offset = position - (framesize / 2);
85             }
86             else
87             {
88                 offset = mapsize - framesize;
89             }
90         }
91     }
92     return offset;
93 }
94
95
96
97 extern void nav_inventory(char dir)
98 {
99     if ('u' == dir)
100     {
101         world.player_inventory_select = world.player_inventory_select
102                                         - (world.player_inventory_select > 0);
103         return;
104     }
105     uint8_t n_elems = 0;
106     uint8_t i;
107     for (i = 0; '\0' != world.player_inventory[i]; i++)
108     {
109         n_elems = n_elems + ('\n' == world.player_inventory[i]);
110     }
111     world.player_inventory_select = world.player_inventory_select
112                                     + (world.player_inventory_select < n_elems);
113 }
114