| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
|
| 27 |
|
| 28 |
|
| 29 |
|
| 30 |
|
| 31 |
|
| 32 |
|
| 33 |
|
| 34 |
|
| 35 |
|
| 36 |
|
| 37 |
|
| 38 |
|
| 39 |
|
| 40 |
|
| 41 |
|
| 42 |
|
| 43 |
|
| 44 |
|
| 45 |
|
| 46 |
|
| 47 |
|
| 48 |
|
| 49 |
#pragma once |
| 50 |
|
| 51 |
#include <cdogs/c_array.h> |
| 52 |
#include <cdogs/campaigns.h> |
| 53 |
#include <cdogs/events.h> |
| 54 |
#include <cdogs/gamedata.h> |
| 55 |
#include <cdogs/grafx.h> |
| 56 |
|
| 57 |
#include "credits.h" |
| 58 |
#include "game_loop.h" |
| 59 |
|
| 60 |
typedef enum |
| 61 |
{ |
| 62 |
MENU_TYPE_NORMAL, |
| 63 |
|
| 64 |
MENU_TYPE_OPTIONS, |
| 65 |
MENU_TYPE_BASIC, |
| 66 |
MENU_TYPE_SET_OPTION_TOGGLE, |
| 67 |
MENU_TYPE_SET_OPTION_RANGE, |
| 68 |
MENU_TYPE_SET_OPTION_SEED, |
| 69 |
MENU_TYPE_SET_OPTION_UP_DOWN_VOID_FUNC_VOID, |
| 70 |
|
| 71 |
MENU_TYPE_SET_OPTION_RANGE_GET_SET, |
| 72 |
|
| 73 |
MENU_TYPE_SET_OPTION_CHANGE_KEY, |
| 74 |
MENU_TYPE_VOID_FUNC, |
| 75 |
MENU_TYPE_BACK, |
| 76 |
MENU_TYPE_QUIT, |
| 77 |
MENU_TYPE_RETURN, |
| 78 |
MENU_TYPE_CUSTOM |
| 79 |
} menu_type_e; |
| 80 |
|
| 81 |
typedef enum |
| 82 |
{ |
| 83 |
MENU_OPTION_DISPLAY_STYLE_NONE, |
| 84 |
MENU_OPTION_DISPLAY_STYLE_STR_FUNC, |
| 85 |
MENU_OPTION_DISPLAY_STYLE_INT_TO_STR_FUNC, |
| 86 |
|
| 87 |
} menu_option_display_style_e; |
| 88 |
|
| 89 |
typedef enum |
| 90 |
{ |
| 91 |
MENU_DISPLAY_ITEMS_CREDITS = 0x01, |
| 92 |
MENU_DISPLAY_ITEMS_AUTHORS = 0x02 |
| 93 |
} menu_display_items_e; |
| 94 |
|
| 95 |
typedef struct menu menu_t; |
| 96 |
|
| 97 |
|
| 98 |
|
| 99 |
typedef void (*MenuDisplayFunc)( |
| 100 |
const menu_t *, GraphicsDevice *, const struct vec2i, const struct vec2i, |
| 101 |
const void *); |
| 102 |
|
| 103 |
|
| 104 |
|
| 105 |
typedef int (*MenuInputFunc)(int, void *); |
| 106 |
|
| 107 |
typedef void (*MenuFunc)(menu_t *, void *); |
| 108 |
|
| 109 |
|
| 110 |
typedef void (*MenuPostInputFunc)(menu_t *, int cmd, void *); |
| 111 |
|
| 112 |
typedef enum |
| 113 |
{ |
| 114 |
MENU_ALIGN_CENTER, |
| 115 |
MENU_ALIGN_LEFT |
| 116 |
} MenuAlignStyle; |
| 117 |
|
| 118 |
typedef enum |
| 119 |
{ |
| 120 |
MENU_SOUND_ENTER, |
| 121 |
MENU_SOUND_BACK, |
| 122 |
MENU_SOUND_SWITCH, |
| 123 |
MENU_SOUND_START, |
| 124 |
MENU_SOUND_ERROR |
| 125 |
} MenuSound; |
| 126 |
|
| 127 |
struct menu |
| 128 |
{ |
| 129 |
char *name; |
| 130 |
menu_type_e type; |
| 131 |
struct menu *parentMenu; |
| 132 |
bool isDisabled; |
| 133 |
color_t color; |
| 134 |
MenuFunc customPostEnterFunc; |
| 135 |
void *customPostEnterData; |
| 136 |
bool isCustomPostEnterDataDynamic; |
| 137 |
MenuFunc customPostUpdateFunc; |
| 138 |
void *customPostUpdateData; |
| 139 |
bool isCustomPostUpdateDataDynamic; |
| 140 |
MenuPostInputFunc customPostInputFunc; |
| 141 |
void *customPostInputData; |
| 142 |
MenuDisplayFunc customDisplayFunc; |
| 143 |
const void *customDisplayData; |
| 144 |
MenuSound enterSound; |
| 145 |
bool mouseHover; |
| 146 |
union { |
| 147 |
|
| 148 |
struct |
| 149 |
{ |
| 150 |
char title[64]; |
| 151 |
CArray subMenus; |
| 152 |
|
| 153 |
bool isSubmenusAlt; |
| 154 |
int index; |
| 155 |
int scroll; |
| 156 |
int maxItems; |
| 157 |
MenuAlignStyle align; |
| 158 |
int quitMenuIndex; |
| 159 |
int displayItems; |
| 160 |
int setOptions; |
| 161 |
struct menu |
| 162 |
*changeKeyMenu; |
| 163 |
} normal; |
| 164 |
|
| 165 |
struct |
| 166 |
{ |
| 167 |
union { |
| 168 |
bool *optionToggle; |
| 169 |
struct |
| 170 |
{ |
| 171 |
int *option; |
| 172 |
int low; |
| 173 |
int high; |
| 174 |
int increment; |
| 175 |
} optionRange; |
| 176 |
unsigned int *seed; |
| 177 |
|
| 178 |
struct |
| 179 |
{ |
| 180 |
void (*upFunc)(void); |
| 181 |
void (*downFunc)(void); |
| 182 |
} upDownFuncs; |
| 183 |
struct |
| 184 |
{ |
| 185 |
int (*getFunc)(void); |
| 186 |
void (*setFunc)(int); |
| 187 |
int low; |
| 188 |
int high; |
| 189 |
int increment; |
| 190 |
} optionRangeGetSet; |
| 191 |
struct |
| 192 |
{ |
| 193 |
void (*func)(void *); |
| 194 |
void *data; |
| 195 |
} voidFunc; |
| 196 |
struct |
| 197 |
{ |
| 198 |
input_device_e *device0; |
| 199 |
input_device_e *device1; |
| 200 |
} changeControl; |
| 201 |
} uHook; |
| 202 |
menu_option_display_style_e displayStyle; |
| 203 |
union { |
| 204 |
char *(*str)(void); |
| 205 |
const char *(*intToStr)(int); |
| 206 |
} uFunc; |
| 207 |
} option; |
| 208 |
|
| 209 |
struct |
| 210 |
{ |
| 211 |
key_code_e code; |
| 212 |
int playerIndex; |
| 213 |
|
| 214 |
bool isOptional; |
| 215 |
} changeKey; |
| 216 |
int returnCode; |
| 217 |
struct |
| 218 |
{ |
| 219 |
MenuDisplayFunc displayFunc; |
| 220 |
MenuInputFunc inputFunc; |
| 221 |
void *data; |
| 222 |
} customData; |
| 223 |
} u; |
| 224 |
}; |
| 225 |
|
| 226 |
typedef struct |
| 227 |
{ |
| 228 |
MenuDisplayFunc Func; |
| 229 |
void *Data; |
| 230 |
} MenuCustomDisplayFunc; |
| 231 |
typedef struct |
| 232 |
{ |
| 233 |
menu_t *root; |
| 234 |
menu_t *current; |
| 235 |
CArray exitTypes; |
| 236 |
credits_displayer_t *creditsDisplayer; |
| 237 |
EventHandlers *handlers; |
| 238 |
GraphicsDevice *graphics; |
| 239 |
struct vec2i pos; |
| 240 |
struct vec2i size; |
| 241 |
MenuAlignStyle align; |
| 242 |
|
| 243 |
bool allowAborts; |
| 244 |
bool hasAbort; |
| 245 |
CArray customDisplayFuncs; |
| 246 |
} MenuSystem; |
| 247 |
|
| 248 |
void MenuSystemInit( |
| 249 |
MenuSystem *ms, EventHandlers *handlers, GraphicsDevice *graphics, |
| 250 |
struct vec2i pos, struct vec2i size); |
| 251 |
void MenuSystemTerminate(MenuSystem *ms); |
| 252 |
void MenuSetCreditsDisplayer( |
| 253 |
MenuSystem *menu, credits_displayer_t *creditsDisplayer); |
| 254 |
void MenuAddExitType(MenuSystem *menu, menu_type_e exitType); |
| 255 |
void MenuSystemAddCustomDisplay( |
| 256 |
MenuSystem *ms, MenuDisplayFunc func, void *data); |
| 257 |
int MenuIsExit(MenuSystem *ms); |
| 258 |
bool MenuTypeHasSubMenus(const menu_type_e type); |
| 259 |
GameLoopData *MenuLoop(MenuSystem *menu); |
| 260 |
void MenuUpdateMouse(MenuSystem *ms); |
| 261 |
GameLoopResult MenuUpdate(MenuSystem *ms); |
| 262 |
void MenuDraw(const MenuSystem *ms); |
| 263 |
void MenuDisplay(const MenuSystem *ms); |
| 264 |
void MenuProcessCmd(MenuSystem *ms, int cmd); |
| 265 |
void MenuReset(MenuSystem *menu); |
| 266 |
void MenuDisableSubmenu(menu_t *menu, int index); |
| 267 |
void MenuEnableSubmenu(menu_t *menu, int index); |
| 268 |
void MenuSetDisabled(menu_t *menu, const bool isDisabled); |
| 269 |
menu_t *MenuGetSubmenuByName(menu_t *menu, const char *name); |
| 270 |
int MenuGetNumMenuItemsShown(const menu_t *menu); |
| 271 |
|
| 272 |
void ShowControls(void); |
| 273 |
struct vec2i DisplayMenuItem( |
| 274 |
GraphicsDevice *g, const Rect2i bounds, const char *s, const bool selected, |
| 275 |
const bool isDisabled, const color_t color); |
| 276 |
|
| 277 |
menu_t *MenuCreate(const char *name, menu_type_e type); |
| 278 |
menu_t *MenuCreateNormal( |
| 279 |
const char *name, const char *title, menu_type_e type, int displayItems); |
| 280 |
menu_t *MenuAddSubmenu(menu_t *menu, menu_t *subMenu); |
| 281 |
void MenuSetPostEnterFunc( |
| 282 |
menu_t *menu, MenuFunc func, void *data, const bool isDynamicData); |
| 283 |
void MenuSetPostUpdateFunc( |
| 284 |
menu_t *menu, MenuFunc func, void *data, const bool isDynamicData); |
| 285 |
void MenuSetPostInputFunc(menu_t *menu, MenuPostInputFunc func, void *data); |
| 286 |
void MenuSetCustomDisplay( |
| 287 |
menu_t *menu, MenuDisplayFunc func, const void *data); |
| 288 |
|
| 289 |
void MenuAddConfigOptionsItem(menu_t *menu, Config *c); |
| 290 |
menu_t *MenuCreateOptionToggle(const char *name, bool *config); |
| 291 |
menu_t *MenuCreateOptionRange( |
| 292 |
const char *name, int *config, int low, int high, int increment, |
| 293 |
menu_option_display_style_e style, void (*func)(void)); |
| 294 |
menu_t *MenuCreateOptionSeed(const char *name, unsigned int *seed); |
| 295 |
menu_t *MenuCreateOptionUpDownFunc( |
| 296 |
const char *name, void (*upFunc)(void), void (*downFunc)(void), |
| 297 |
menu_option_display_style_e style, char *(*strFunc)(void)); |
| 298 |
menu_t *MenuCreateVoidFunc(const char *name, void (*func)(void *), void *data); |
| 299 |
menu_t *MenuCreateOptionRangeGetSet( |
| 300 |
const char *name, int (*getFunc)(void), void (*setFunc)(int), int low, |
| 301 |
int high, int increment, menu_option_display_style_e style, |
| 302 |
void (*func)(void)); |
| 303 |
menu_t *MenuCreateSeparator(const char *name); |
| 304 |
menu_t *MenuCreateBack(const char *name); |
| 305 |
|
| 306 |
|
| 307 |
|
| 308 |
menu_t *MenuCreateReturn(const char *name, int returnCode); |
| 309 |
menu_t *MenuCreateCustom( |
| 310 |
const char *name, MenuDisplayFunc displayFunc, MenuInputFunc inputFunc, |
| 311 |
void *data); |
| 312 |
|
| 313 |
void MenuPlaySound(MenuSound s); |
| 314 |
|
| 315 |
void MenuClearSubmenus(menu_t *menu); |