1 /** @file hu_menu.h  Menu widget stuff, episode selection and such.
2  *
3  * @authors Copyright © 2003-2017 Jaakko Keränen <jaakko.keranen@iki.fi>
4  * @authors Copyright © 2005-2014 Daniel Swanson <danij@dengine.net>
5  *
6  * @par License
7  * GPL: http://www.gnu.org/licenses/gpl.html
8  *
9  * <small>This program is free software; you can redistribute it and/or modify
10  * it under the terms of the GNU General Public License as published by the
11  * Free Software Foundation; either version 2 of the License, or (at your
12  * option) any later version. This program is distributed in the hope that it
13  * will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty
14  * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
15  * Public License for more details. You should have received a copy of the GNU
16  * General Public License along with this program; if not, write to the Free
17  * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
18  * 02110-1301 USA</small>
19  */
20 
21 #ifndef LIBCOMMON_HU_MENU_H
22 #define LIBCOMMON_HU_MENU_H
23 
24 typedef enum menucommand_e
25 {
26     MCMD_OPEN,          ///< Open the menu.
27     MCMD_CLOSE,         ///< Close the menu.
28     MCMD_CLOSEFAST,     ///< Instantly close the menu.
29     MCMD_NAV_OUT,       ///< Navigate "out" of the current menu/widget (up a level).
30     MCMD_NAV_LEFT,
31     MCMD_NAV_RIGHT,
32     MCMD_NAV_DOWN,
33     MCMD_NAV_UP,
34     MCMD_NAV_PAGEDOWN,
35     MCMD_NAV_PAGEUP,
36     MCMD_SELECT,        ///< Execute whatever action is attaced to the current item.
37     MCMD_DELETE
38 } menucommand_e;
39 
40 typedef enum mn_page_colorid_e
41 {
42     MENU_COLOR1,
43     MENU_COLOR2,
44     MENU_COLOR3,
45     MENU_COLOR4,
46     MENU_COLOR5,
47     MENU_COLOR6,
48     MENU_COLOR7,
49     MENU_COLOR8,
50     MENU_COLOR9,
51     MENU_COLOR10,
52     MENU_COLOR_COUNT
53 } mn_page_colorid_t;
54 
55 #define VALID_MNPAGE_COLORID(v)      ((v) >= MENU_COLOR1 && (v) < MENU_COLOR_COUNT)
56 
57 typedef enum mn_page_fontid_e
58 {
59     MENU_FONT1,
60     MENU_FONT2,
61     MENU_FONT3,
62     MENU_FONT4,
63     MENU_FONT5,
64     MENU_FONT6,
65     MENU_FONT7,
66     MENU_FONT8,
67     MENU_FONT9,
68     MENU_FONT10,
69     MENU_FONT_COUNT
70 } mn_page_fontid_t;
71 
72 #define VALID_MNPAGE_FONTID(v)      ((v) >= MENU_FONT1 && (v) < MENU_FONT_COUNT)
73 
74 #ifdef __cplusplus
75 
76 #include "dd_types.h"
77 //#include "hu_lib.h"
78 #include "menu/widgets/widget.h"
79 #include "menu/widgets/cvartogglewidget.h"
80 
81 namespace common {
82 
83 extern int menuTime;
84 extern dd_bool menuNominatingQuickSaveSlot;
85 
86 // Sounds played in the menu.
87 #if __JDOOM__ || __JDOOM64__
88 #define SFX_MENU_CLOSE      (SFX_SWTCHX)
89 #define SFX_MENU_OPEN       (SFX_SWTCHN)
90 #define SFX_MENU_CANCEL     (SFX_SWTCHN)
91 #define SFX_MENU_NAV_UP     (SFX_PSTOP)
92 #define SFX_MENU_NAV_DOWN   (SFX_PSTOP)
93 #define SFX_MENU_NAV_RIGHT  (SFX_PSTOP)
94 #define SFX_MENU_ACCEPT     (SFX_PISTOL)
95 #define SFX_MENU_CYCLE      (SFX_PISTOL) // Cycle available options.
96 #define SFX_MENU_SLIDER_MOVE (SFX_STNMOV)
97 #define SFX_QUICKSAVE_PROMPT (SFX_SWTCHN)
98 #define SFX_QUICKLOAD_PROMPT (SFX_SWTCHN)
99 #define SFX_DELETESAVEGAME_CONFIRM (SFX_SWTCHN)
100 #define SFX_REBORNLOAD_CONFIRM (SFX_SWTCHN)
101 #elif __JHERETIC__
102 #define SFX_MENU_CLOSE      (SFX_DORCLS)
103 #define SFX_MENU_OPEN       (SFX_SWITCH)
104 #define SFX_MENU_CANCEL     (SFX_SWITCH)
105 #define SFX_MENU_NAV_UP     (SFX_SWITCH)
106 #define SFX_MENU_NAV_DOWN   (SFX_SWITCH)
107 #define SFX_MENU_NAV_RIGHT  (SFX_SWITCH)
108 #define SFX_MENU_ACCEPT     (SFX_DORCLS)
109 #define SFX_MENU_CYCLE      (SFX_DORCLS) // Cycle available options.
110 #define SFX_MENU_SLIDER_MOVE (SFX_KEYUP)
111 #define SFX_QUICKSAVE_PROMPT (SFX_CHAT)
112 #define SFX_QUICKLOAD_PROMPT (SFX_CHAT)
113 #define SFX_DELETESAVEGAME_CONFIRM (SFX_CHAT)
114 #define SFX_REBORNLOAD_CONFIRM (SFX_CHAT)
115 #elif __JHEXEN__
116 #define SFX_MENU_CLOSE      (SFX_DOOR_LIGHT_CLOSE)
117 #define SFX_MENU_OPEN       (SFX_DOOR_LIGHT_CLOSE)
118 #define SFX_MENU_CANCEL     (SFX_PICKUP_KEY)
119 #define SFX_MENU_NAV_UP     (SFX_FIGHTER_HAMMER_HITWALL)
120 #define SFX_MENU_NAV_DOWN   (SFX_FIGHTER_HAMMER_HITWALL)
121 #define SFX_MENU_NAV_RIGHT  (SFX_FIGHTER_HAMMER_HITWALL)
122 #define SFX_MENU_ACCEPT     (SFX_PLATFORM_STOP)
123 #define SFX_MENU_CYCLE      (SFX_CHAT) // Cycle available options.
124 #define SFX_MENU_SLIDER_MOVE (SFX_PICKUP_KEY)
125 #define SFX_QUICKSAVE_PROMPT (SFX_CHAT)
126 #define SFX_QUICKLOAD_PROMPT (SFX_CHAT)
127 #define SFX_DELETESAVEGAME_CONFIRM (SFX_CHAT)
128 #define SFX_REBORNLOAD_CONFIRM (SFX_CHAT)
129 #endif
130 
131 #define MENU_CURSOR_REWIND_SPEED    20
132 #define MENU_CURSOR_FRAMECOUNT      2
133 #define MENU_CURSOR_TICSPERFRAME    8
134 
135 void Hu_MenuInit();
136 void Hu_MenuShutdown();
137 
138 /**
139  * Returns @c true if a current menu Page is configured.
140  */
141 bool Hu_MenuHasPage();
142 
143 /**
144  * Returns @c true if the menu contains a Page associated with @a name.
145  * @see Hu_MenuPage()
146  */
147 bool Hu_MenuHasPage(de::String name);
148 
149 /**
150  * Returns the currently configured menu Page.
151  * @see Hu_MenuHasPage()
152  */
153 menu::Page &Hu_MenuPage();
154 
Hu_MenuPagePtr()155 inline menu::Page *Hu_MenuPagePtr() {
156     return Hu_MenuHasPage()? &Hu_MenuPage() : 0;
157 }
158 
159 /**
160  * Lookup a Page with the unique identifier @a name.
161  * @see Hu_MenuHasPage()
162  */
163 menu::Page &Hu_MenuPage(de::String name);
164 
Hu_MenuPagePtr(de::String name)165 inline menu::Page *Hu_MenuPagePtr(de::String name) {
166     return Hu_MenuHasPage(name)? &Hu_MenuPage(name) : 0;
167 }
168 
169 /**
170  * Change the current menu Page to @a page.
171  * @see Hu_MenuPage(), Hu_MenuHasPage()
172  */
173 void Hu_MenuSetPage(menu::Page *page, bool allowReactivate = false);
174 
175 /**
176  * Convenient method for changing the current menu Page to that with the @a name given.
177  * @see Hu_MenuSetPage()
178  */
179 inline void Hu_MenuSetPage(de::String name, bool allowReactivate = false) {
180     Hu_MenuSetPage(Hu_MenuPagePtr(name), allowReactivate);
181 }
182 
183 /**
184  * Add a new Page to the menu. If the name of @a page is not unique, or the page
185  * has already been added - an Error will be thrown and the page will not be added.
186  *
187  * @param page  Page to add.
188  *
189  * @return  Same as @a page, for caller convenience.
190  */
191 menu::Page *Hu_MenuAddPage(menu::Page *page);
192 
193 /**
194  * Returns @c true if the menu is currently active (open).
195  */
196 bool Hu_MenuIsActive();
197 
198 /**
199  * Change the opacity of the entire menu to @a newOpacity.
200  * @see Hu_MenuOpacity()
201  */
202 void Hu_MenuSetOpacity(float newOpacity);
203 
204 /**
205  * Returns the current menu opacity.
206  * @see Hu_MenuSetOpacity()
207  */
208 float Hu_MenuOpacity();
209 
210 /**
211  * Returns @c true if the menu is presently visible.
212  */
213 bool Hu_MenuIsVisible();
214 
215 /**
216  * This is the main menu drawing routine (called every tic by the drawing loop).
217  */
218 void Hu_MenuDrawer();
219 
220 /**
221  * Updates on Game Tick.
222  */
223 void Hu_MenuTicker(timespan_t ticLength);
224 
225 /// @return  @c true if the input event @a ev was eaten.
226 int Hu_MenuPrivilegedResponder(event_t *ev);
227 
228 /// @return  @c true if the input event @a ev was eaten.
229 int Hu_MenuResponder(event_t *ev);
230 
231 /// @return  @c true if the input event @a ev was eaten.
232 int Hu_MenuFallbackResponder(event_t *ev);
233 
234 /// @return  @c true if the menu @a command was eaten.
235 void Hu_MenuCommand(menucommand_e command);
236 
237 /// Register the console commands, variables, etc..., of this module.
238 void Hu_MenuConsoleRegister();
239 
240 // ----------------------------------------------------------------------------------------
241 
242 void Hu_MenuDefaultFocusAction(menu::Widget &wi, menu::Widget::Action action);
243 
244 void Hu_MenuDrawFocusCursor(de::Vector2i const &origin, float scale, float alpha);
245 
246 void Hu_MenuDrawPageTitle(de::String titleText, de::Vector2i const &origin);
247 void Hu_MenuDrawPageHelp(de::String helpText, de::Vector2i const &origin);
248 
249 /**
250  * @defgroup menuEffectFlags  Menu Effect Flags
251  */
252 ///@{
253 #define MEF_TEXT_TYPEIN             DTF_NO_TYPEIN
254 #define MEF_TEXT_SHADOW             DTF_NO_SHADOW
255 #define MEF_TEXT_GLITTER            DTF_NO_GLITTER
256 
257 #define MEF_EVERYTHING              MEF_TEXT_TYPEIN | MEF_TEXT_SHADOW | MEF_TEXT_GLITTER
258 ///@}
259 
260 short Hu_MenuMergeEffectWithDrawTextFlags(short flags);
261 
262 } // namespace common
263 
264 #endif // __cplusplus
265 #endif  // LIBCOMMON_HU_MENU_H
266