Dumb-ways-to-memorize
2D game
menu.h
Go to the documentation of this file.
1 #ifndef __MENU_H
2 #define __MENU_H
3 
4 #include "globals.h"
5 #include "graphics.h"
6 #include "parseobject.h"
7 
8 #define MENU_ITEM_MAX 20
9 #define MAX_MENUS 10
10 #define MENU_BACKGROUND "Background"
11 #define MENU_ITEMS "Items"
12 #define MENU_ITEM_SPRITE "sprite"
13 #define MENU_ITEM_TEXT "text"
14 #define MENU_ITEM_LINK "link"
15 #define MENU_ITEM_EXTRA "extra"
16 #define MENU_TYPE "Type"
17 #define MENU_TYPE_STR_POWER "power_select"
18 #define MENU_TYPE_STR_CHOOSE "choose_power"
19 #define MENU_TYPE_STR_H "horizontal"
20 #define MENU_TYPE_STR_V "vertical"
21 #define MENU_TYPE_STR_GRID "grid"
22 
23 /** Defines the enum for what type of menu it is */
24 typedef enum
25 {
27  MENU_TYPE_H = 0x1, /**< An enum constant representing the menu type - horizontal */
28  MENU_TYPE_V = 0x2, /**< An enum constant representing the menu type - vertical */
29  MENU_TYPE_GRID = 0x4, /**< An enum constant representing the menu type - grid */
30  MENU_TYPE_POWER = 0x8, /**< An enum constant representing the menu type - half circle for power selection*/
31  MENU_TYPE_CHOOSE = 0x10, /**< An enum constant representing the menu - same as power, but used to differ the menu operations */
33 
35 
36 
37 typedef struct menu_item_s menu_item_t;
38 typedef struct menu_s menu_t;
39 
40 /**
41  * A menu item structure, used to define the items in the menu.
42  *
43  * @author Anthony Rios
44  * @date 3/30/2016
45  */
46 
48 {
49  menu_item_state_t State; /**< The state of the menu item */
50  GameState NextState; /**< State of the next gamestate this item links to */
51  vec2_t Position; /**< The position of the item */
52  char *Name; /**< The name of the menu item */
53  sprite_t *Image; /**< The image of the menu item */
54  void *Info; /**< The information specific to this menu */
55 };
56 
57 /**
58  * A menu structure which controls updateing, drawing, and connecting menu states.
59  *
60  * @author Anthony Rios
61  * @date 3/30/2016
62  */
63 
64 struct menu_s
65 {
66  menu_item_t mItems[MENU_ITEM_MAX]; /**< The items this menu contains */
67  menu_item_t *mSelectedItem; /**< The currently selected item */
68  sprite_t *mBackground; /**< The background image for the menu */
69  GameState mCurrentState; /**< The current game state the menu is drawing in */
70  GameState mPreviousState; /**< State before this got loaded*/
71  int mItemCount; /**< Number of items in this menu */
72  void (*Update)(menu_t *self, SDL_GameControllerButton button); /**< The update function, which takes input and updates global variables*/
73  void (*Draw)(menu_t *self); /**The draw function for the menu*/
74 };
75 
76 extern menu_t *gMenus;
77 
78 /**
79  * Allocate memor for menu system, gMenus is the menu list.
80  *
81  * @author Anthony Rios
82  * @date 3/16/2016
83  */
84 int InitMenuSystem();
85 
86 /**
87  * Loads a menu.
88  *
89  * @param [in,out] object If non-null, the object menu was parsed to.
90  * @param [in,out] g_str If non-null, the string.
91  * @param curr_state State to assign the menu.
92  * @param previous_state State before this menu.
93  *
94  * @return 0 if loads correctly, -1 if it doesn't.
95  *
96  * @author Anthony Rios
97  * @date 3/16/2016
98  */
99 menu_t *LoadMenu(object_t *object, char *g_str, GameState curr_state, GameState previous_state );
100 
101 /**
102  * Searches for the first menu from game state in gMenus.
103  *
104  * @param curr_state State of the curr.
105  *
106  * @return null if it fails, else the found menu from game state.
107  *
108  * @author Anthony Rios
109  * @date 3/16/2016
110  */
111 menu_t *FindMenuFromGameState(GameState curr_state);
112 
113 /**
114  * Searches for the first free menu slot in gMenus, used for loading new menus.
115  *
116  * @return null if it fails, else the found free menu.
117  *
118  * @author Anthony Rios
119  * @date 3/30/2016
120  */
121 menu_t *FindFreeMenu();
122 
123 /**
124  * Searches for the first menu item, with name of str given.
125  *
126  * @param [in,out] menu If non-null, the menu.
127  * @param [in,out] item If non-null, the item.
128  *
129  * @return null if it fails, else the found menu item.
130  *
131  * @author Anthony Rios
132  * @date 3/30/2016
133  */
134 menu_item_t *FindMenuItem(menu_t *menu, char *item);
135 
136 #endif
GameState mPreviousState
Definition: menu.h:70
GameState NextState
Definition: menu.h:50
sprite_t * mBackground
Definition: menu.h:68
menu_item_t * mSelectedItem
Definition: menu.h:67
int mItemCount
Definition: menu.h:71
char * Name
Definition: menu.h:52
menu_item_state_t State
Definition: menu.h:49
void * Info
Definition: menu.h:54
menu_item_state_t
Definition: globals.h:61
GameState mCurrentState
Definition: menu.h:69
vec2_t Position
Definition: menu.h:51
Definition: menu.h:64
sprite_t * Image
Definition: menu.h:53
void Update()
Definition: game.c:458
GameState
Definition: globals.h:83
void Draw()
Definition: game.c:547
Definition: globals.h:19