home · contact · privacy
MAJOR re-write. Split plomrogue into a server and a client. Re-wrote large parts
[plomrogue] / src / client / misc.c
1 /* src/client/misc.c */
2
3 #include "misc.h"
4 #include <stdint.h> /* uint8_t, uint16_t */
5 #include "cleanup.h" /* for set_cleanup_flag() */
6 #include "keybindings.h" /* init_keybindings(), free_keybindings(),
7                           * save_keybindings()
8                           */
9 #include "wincontrol.h" /* init_winconfs(), init_wins(),
10                          * sorted_wintoggle_and_activate()
11                          */
12 #include "windows.h" /* suspend_win() */
13 #include "world.h" /* global world */
14
15
16
17 extern void save_interface_conf()
18 {
19     save_keybindings("confclient/keybindings_global", &world.kb_global);
20     save_keybindings("confclient/keybindings_wingeom", &world.kb_wingeom);
21     save_keybindings("confclient/keybindings_winkeys", &world.kb_winkeys);
22     save_win_configs();
23 }
24
25
26
27 extern void load_interface_conf()
28 {
29     init_keybindings("confclient/keybindings_global",  &world.kb_global);
30     init_keybindings("confclient/keybindings_wingeom", &world.kb_wingeom);
31     init_keybindings("confclient/keybindings_winkeys", &world.kb_winkeys);
32     init_winconfs();
33     init_wins();
34     sorted_wintoggle_and_activate();
35     set_cleanup_flag(CLEANUP_INTERFACE);
36 }
37
38
39
40 extern void unload_interface_conf()
41 {
42     free_keybindings(world.kb_global.kbs);
43     free_keybindings(world.kb_wingeom.kbs);
44     free_keybindings(world.kb_winkeys.kbs);
45     while (0 != world.wmeta.active)
46     {
47         suspend_win(world.wmeta.active);
48     }
49     free_winconfs();
50 }
51
52
53
54 extern void reload_interface_conf()
55 {
56     unload_interface_conf();
57     load_interface_conf();
58 }
59
60
61
62 extern uint16_t center_offset(uint16_t position, uint16_t mapsize,
63                               uint16_t framesize)
64 {
65     uint16_t offset = 0;
66     if (mapsize > framesize)
67     {
68         if (position > framesize / 2)
69         {
70             if (position < mapsize - (framesize / 2))
71             {
72                 offset = position - (framesize / 2);
73             }
74             else
75             {
76                 offset = mapsize - framesize;
77             }
78         }
79     }
80     return offset;
81 }
82
83
84
85 extern void nav_inventory(char dir)
86 {
87     if ('u' == dir)
88     {
89         world.player_inventory_select = world.player_inventory_select
90                                         - (world.player_inventory_select > 0);
91         return;
92     }
93     uint8_t n_elems = 0;
94     uint8_t i;
95     for (i = 0; '\0' != world.player_inventory[i]; i++)
96     {
97         n_elems = n_elems + ('\n' == world.player_inventory[i]);
98     }
99     world.player_inventory_select = world.player_inventory_select
100                                     + (world.player_inventory_select < n_elems);
101 }
102