]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blob - qcsrc/common/minigames/cl_minigames.qh
Merge branch 'terencehill/menu_fixes' into 'master'
[xonotic/xonotic-data.pk3dir.git] / qcsrc / common / minigames / cl_minigames.qh
1 #ifndef CL_MINIGAMES_H
2 #define CL_MINIGAMES_H
3
4 // Get a square in the center of the avaliable area
5 // \note macro to pass by reference pos and mySize
6 #define minigame_hud_fitsqare(pos, mySize) \
7         if ( mySize##_x > mySize##_y ) \
8         { \
9                 pos##_x += (mySize##_x-mySize##_y)/2; \
10                 mySize##_x = mySize##_y; \
11         } \
12         else \
13         { \
14                 pos##_y += (mySize##_y-mySize##_x)/2; \
15                 mySize##_x = mySize##_x; \
16         } \
17         if(panel_bg_padding) \
18         { \
19                 pos += '1 1 0' * panel_bg_padding; \
20                 mySize -= '2 2 0' * panel_bg_padding; \
21         }
22
23 // Get position and size of a panel
24 // \note macro to pass by reference pos and mySize
25 #define minigame_hud_panelarea(pos, mySize, panelID) \
26         pos = stov(cvar_string(strcat("hud_panel_", HUD_PANEL(panelID).panel_name, "_pos"))); \
27         mySize = stov(cvar_string(strcat("hud_panel_", HUD_PANEL(panelID).panel_name, "_size"))); \
28         pos##_x *= vid_conwidth; pos##_y *= vid_conheight; \
29         mySize##_x *= vid_conwidth; mySize##_y *= vid_conheight;
30
31 // draw a panel border and the given texture
32 void minigame_hud_simpleboard(vector pos, vector mySize, string board_texture);
33
34 // Normalize (2D vector) v to relative coordinate inside pos mySize
35 vector minigame_hud_normalize(vector v, vector pos, vector mySize);
36
37 // De-normalize (2D vector) v from relative coordinate inside pos mySize
38 vector minigame_hud_denormalize(vector v, vector pos, vector mySize);
39
40 // De-normalize (2D vector) v from relative size inside pos mySize
41 vector minigame_hud_denormalize_size(vector v, vector pos, vector mySize);
42
43 // Check if the mouse is inside the given area
44 bool minigame_hud_mouse_in(vector pos, vector sz);
45
46 // Like drawstring, but wrapping words to fit maxwidth
47 // returns the size of the drawn area
48 // align selects the string alignment (0 = left, 0.5 = center, 1 = right)
49 vector minigame_drawstring_wrapped( float maxwidth, vector pos, string text,
50         vector fontsize, vector color, float theAlpha, int drawflags, float align );
51
52 // Like drawcolorcodedstring, but wrapping words to fit maxwidth
53 // returns the size of the drawn area
54 // align selects the string alignment (0 = left, 0.5 = center, 1 = right)
55 vector minigame_drawcolorcodedstring_wrapped( float maxwidth, vector pos,
56         string text, vector fontsize, float theAlpha, int drawflags, float align );
57
58 // Like drawstring but truncates the text to fit maxwidth
59 void minigame_drawstring_trunc(float maxwidth, vector pos, string text,
60         vector fontsize, vector color, float theAlpha, int drawflags );
61
62 // Like drawcolorcodedstring but truncates the text to fit maxwidth
63 void minigame_drawcolorcodedstring_trunc(float maxwidth, vector pos, string text,
64         vector fontsize, float theAlpha, int drawflags );
65
66 // like drawpic but pos represent the center rather than the topleft corner
67 void minigame_drawpic_centered( vector pos, string texture, vector sz,
68         vector color, float thealpha, int drawflags );
69
70 // Get full path of a minigame texture
71 string minigame_texture(string name);
72
73 // For minigame descriptors: hud function for the game board
74 .void(vector pos, vector size) minigame_hud_board;
75 // For minigame descriptors: hud function for the game status
76 .void(vector pos, vector size) minigame_hud_status;
77 // For minigame_player: player server slot, don't use for anything else
78 .float minigame_playerslot;
79
80 // client-side minigame session cleanup
81 void deactivate_minigame();
82
83 // Currently active minigame session
84 entity active_minigame;
85 // minigame_player representing this client
86 entity minigame_self;
87
88 // Whethere there's an active minigame
89 float minigame_isactive()
90 {
91         return active_minigame != world;
92 }
93
94 // Execute a minigame command
95 #define minigame_cmd(...) minigame_cmd_workaround(0,__VA_ARGS__)
96 void minigame_cmd_workaround(float dummy, string...cmdargc);
97
98 // Prompt the player to play in the current minigame
99 // (ie: it's their turn and they should get back to the minigame)
100 void minigame_prompt();
101
102 float HUD_MinigameMenu_IsOpened();
103 void HUD_MinigameMenu_Close(entity this, entity actor, entity trigger);
104 float HUD_Minigame_Showpanels();
105 // Adds a game-specific entry to the menu
106 void HUD_MinigameMenu_CustomEntry(entity parent, string message, string event_arg);
107
108
109 #define FOREACH_MINIGAME_ENTITY(entityvar) \
110         entityvar=world; \
111         while( (entityvar = findentity(entityvar,owner,active_minigame)) )
112
113
114 REGISTRY(Minigames, BITS(4))
115 #define Minigames_from(i) _Minigames_from(i, NULL)
116 REGISTER_REGISTRY(Minigames)
117 REGISTRY_CHECK(Minigames)
118 #define REGISTER_MINIGAME(name,nicename) \
119     REGISTER(Minigames, MINIGAME_##name, m_id, new_pure(minigame_descriptor)); \
120     void name##_hud_board(vector, vector); \
121     void name##_hud_status(vector, vector); \
122     int name##_client_event(entity, string, ...); \
123     REGISTER_INIT(MINIGAME_##name) { \
124         this.netname = strzone(strtolower(#name)); \
125         this.message = nicename; \
126         this.minigame_hud_board = name##_hud_board; \
127                 this.minigame_hud_status = name##_hud_status; \
128                 this.minigame_event = name##_client_event; \
129     } \
130     REGISTER_INIT(MINIGAME_##name)
131
132 #endif