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