X-Git-Url: http://git.xonotic.org/?a=blobdiff_plain;f=qcsrc%2Fcommon%2Fminigames%2Fcl_minigames.qh;fp=qcsrc%2Fcommon%2Fminigames%2Fcl_minigames.qh;h=cc24d4bf0c69256717525a81ced1e28360ac5941;hb=e2fd71a5add1338f211d84d6b1de8c3a552b76ad;hp=0000000000000000000000000000000000000000;hpb=33f268f100a4fb570ba5143195376b704079fdbd;p=xonotic%2Fxonotic-data.pk3dir.git diff --git a/qcsrc/common/minigames/cl_minigames.qh b/qcsrc/common/minigames/cl_minigames.qh new file mode 100644 index 000000000..cc24d4bf0 --- /dev/null +++ b/qcsrc/common/minigames/cl_minigames.qh @@ -0,0 +1,132 @@ +#ifndef CL_MINIGAMES_H +#define CL_MINIGAMES_H + +// Get a square in the center of the avaliable area +// \note macro to pass by reference pos and mySize +#define minigame_hud_fitsqare(pos, mySize) \ + if ( mySize##_x > mySize##_y ) \ + { \ + pos##_x += (mySize##_x-mySize##_y)/2; \ + mySize##_x = mySize##_y; \ + } \ + else \ + { \ + pos##_y += (mySize##_y-mySize##_x)/2; \ + mySize##_x = mySize##_x; \ + } \ + if(panel_bg_padding) \ + { \ + pos += '1 1 0' * panel_bg_padding; \ + mySize -= '2 2 0' * panel_bg_padding; \ + } + +// Get position and size of a panel +// \note macro to pass by reference pos and mySize +#define minigame_hud_panelarea(pos, mySize, panelID) \ + pos = stov(cvar_string(strcat("hud_panel_", HUD_PANEL(panelID).panel_name, "_pos"))); \ + mySize = stov(cvar_string(strcat("hud_panel_", HUD_PANEL(panelID).panel_name, "_size"))); \ + pos##_x *= vid_conwidth; pos##_y *= vid_conheight; \ + mySize##_x *= vid_conwidth; mySize##_y *= vid_conheight; + +// draw a panel border and the given texture +void minigame_hud_simpleboard(vector pos, vector mySize, string board_texture); + +// Normalize (2D vector) v to relative coordinate inside pos mySize +vector minigame_hud_normalize(vector v, vector pos, vector mySize); + +// De-normalize (2D vector) v from relative coordinate inside pos mySize +vector minigame_hud_denormalize(vector v, vector pos, vector mySize); + +// De-normalize (2D vector) v from relative size inside pos mySize +vector minigame_hud_denormalize_size(vector v, vector pos, vector mySize); + +// Check if the mouse is inside the given area +bool minigame_hud_mouse_in(vector pos, vector sz); + +// Like drawstring, but wrapping words to fit maxwidth +// returns the size of the drawn area +// align selects the string alignment (0 = left, 0.5 = center, 1 = right) +vector minigame_drawstring_wrapped( float maxwidth, vector pos, string text, + vector fontsize, vector color, float theAlpha, int drawflags, float align ); + +// Like drawcolorcodedstring, but wrapping words to fit maxwidth +// returns the size of the drawn area +// align selects the string alignment (0 = left, 0.5 = center, 1 = right) +vector minigame_drawcolorcodedstring_wrapped( float maxwidth, vector pos, + string text, vector fontsize, float theAlpha, int drawflags, float align ); + +// Like drawstring but truncates the text to fit maxwidth +void minigame_drawstring_trunc(float maxwidth, vector pos, string text, + vector fontsize, vector color, float theAlpha, int drawflags ); + +// Like drawcolorcodedstring but truncates the text to fit maxwidth +void minigame_drawcolorcodedstring_trunc(float maxwidth, vector pos, string text, + vector fontsize, float theAlpha, int drawflags ); + +// like drawpic but pos represent the center rather than the topleft corner +void minigame_drawpic_centered( vector pos, string texture, vector sz, + vector color, float thealpha, int drawflags ); + +// Get full path of a minigame texture +string minigame_texture(string name); + +// For minigame descriptors: hud function for the game board +.void(vector pos, vector size) minigame_hud_board; +// For minigame descriptors: hud function for the game status +.void(vector pos, vector size) minigame_hud_status; +// For minigame_player: player server slot, don't use for anything else +.float minigame_playerslot; + +// client-side minigame session cleanup +void deactivate_minigame(); + +// Currently active minigame session +entity active_minigame; +// minigame_player representing this client +entity minigame_self; + +// Whethere there's an active minigame +float minigame_isactive() +{ + return active_minigame != NULL; +} + +// Execute a minigame command +#define minigame_cmd(...) minigame_cmd_workaround(0,__VA_ARGS__) +void minigame_cmd_workaround(float dummy, string...cmdargc); + +// Prompt the player to play in the current minigame +// (ie: it's their turn and they should get back to the minigame) +void minigame_prompt(); + +float HUD_MinigameMenu_IsOpened(); +void HUD_MinigameMenu_Close(entity this, entity actor, entity trigger); +float HUD_Minigame_Showpanels(); +// Adds a game-specific entry to the menu +void HUD_MinigameMenu_CustomEntry(entity parent, string message, string event_arg); + + +#define FOREACH_MINIGAME_ENTITY(entityvar) \ + entityvar=NULL; \ + while( (entityvar = findentity(entityvar,owner,active_minigame)) ) + + +REGISTRY(Minigames, BITS(4)) +#define Minigames_from(i) _Minigames_from(i, NULL) +REGISTER_REGISTRY(Minigames) +REGISTRY_CHECK(Minigames) +#define REGISTER_MINIGAME(name,nicename) \ + REGISTER(Minigames, MINIGAME_##name, m_id, new_pure(minigame_descriptor)); \ + void name##_hud_board(vector, vector); \ + void name##_hud_status(vector, vector); \ + int name##_client_event(entity, string, ...); \ + REGISTER_INIT(MINIGAME_##name) { \ + this.netname = strzone(strtolower(#name)); \ + this.message = nicename; \ + this.minigame_hud_board = name##_hud_board; \ + this.minigame_hud_status = name##_hud_status; \ + this.minigame_event = name##_client_event; \ + } \ + REGISTER_INIT(MINIGAME_##name) + +#endif