]> git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blobdiff - qcsrc/client/hud.qh
Merge branch 'master' into matthiaskrgr/quad_blue
[xonotic/xonotic-data.pk3dir.git] / qcsrc / client / hud.qh
diff --git a/qcsrc/client/hud.qh b/qcsrc/client/hud.qh
deleted file mode 100644 (file)
index d30eea1..0000000
+++ /dev/null
@@ -1,418 +0,0 @@
-#ifndef HUD_H
-#define HUD_H
-
-#include "../common/weapons/all.qh"
-
-const int HUD_PANEL_MAX = 24;
-entity hud_panel[HUD_PANEL_MAX];
-const int HUD_PANEL_FIRST = 0;
-int HUD_PANEL_NUM;
-int HUD_PANEL_LAST;
-
-int panel_order[HUD_PANEL_MAX];
-string hud_panelorder_prev;
-
-bool hud_draw_maximized;
-bool hud_panel_radar_maximized;
-bool hud_panel_radar_mouse;
-float hud_panel_radar_bottom;
-bool hud_panel_radar_temp_hidden;
-bool chat_panel_modified;
-bool radar_panel_modified;
-
-void HUD_Radar_Hide_Maximized();
-
-void HUD_Reset (void);
-void HUD_Main (void);
-
-int vote_yescount;
-int vote_nocount;
-int vote_needed;
-int vote_highlighted; // currently selected vote
-
-int vote_active; // is there an active vote?
-int vote_prev; // previous state of vote_active to check for a change
-float vote_alpha;
-float vote_change; // "time" when vote_active changed
-
-float hud_panel_quickmenu;
-
-vector mousepos;
-vector panel_click_distance; // mouse cursor distance from the top left corner of the panel (saved only upon a click)
-vector panel_click_resizeorigin; // coordinates for opposite point when resizing
-float resizeCorner; // 1 = topleft, 2 = topright, 3 = bottomleft, 4 = bottomright
-entity highlightedPanel;
-float highlightedAction; // 0 = nothing, 1 = move, 2 = resize
-
-const float BORDER_MULTIPLIER = 0.25;
-float scoreboard_bottom;
-int weapon_accuracy[WEP_MAXCOUNT];
-
-int complain_weapon;
-string complain_weapon_name;
-float complain_weapon_type;
-float complain_weapon_time;
-
-int ps_primary, ps_secondary;
-int ts_primary, ts_secondary;
-
-int last_switchweapon;
-int last_activeweapon;
-float weapontime;
-float weaponprevtime;
-
-float teamnagger;
-
-float hud_configure_checkcollisions;
-float hud_configure_prev;
-vector hud_configure_gridSize;
-vector hud_configure_realGridSize;
-
-int hudShiftState;
-const int S_SHIFT = 1;
-const int S_CTRL = 2;
-const int S_ALT = 4;
-
-float menu_enabled; // 1 showing the entire HUD, 2 showing only the clicked panel
-
-float hud_fade_alpha;
-
-string hud_skin_path;
-string hud_skin_prev;
-
-vector myteamcolors;
-
-entity highlightedPanel_backup;
-vector panel_pos_backup;
-vector panel_size_backup;
-
-vector panel_size_copied;
-
-entity panel;
-entityclass(HUDPanel);
-class(HUDPanel) .string panel_name;
-class(HUDPanel) .int panel_id;
-class(HUDPanel) .vector current_panel_pos;
-class(HUDPanel) .vector current_panel_size;
-class(HUDPanel) .string current_panel_bg;
-class(HUDPanel) .float current_panel_bg_alpha;
-class(HUDPanel) .float current_panel_bg_border;
-class(HUDPanel) .vector current_panel_bg_color;
-class(HUDPanel) .float current_panel_bg_color_team;
-class(HUDPanel) .float current_panel_bg_padding;
-class(HUDPanel) .float current_panel_fg_alpha;
-class(HUDPanel) .float update_time;
-float panel_enabled;
-vector panel_pos;
-vector panel_size;
-string panel_bg_str; // "_str" vars contain the raw value of the cvar, non-"_str" contains what hud.qc code should use
-vector panel_bg_color;
-string panel_bg_color_str;
-float panel_bg_color_team;
-string panel_bg_color_team_str;
-float panel_fg_alpha;
-float panel_bg_alpha;
-string panel_bg_alpha_str;
-float panel_bg_border;
-string panel_bg_border_str;
-float panel_bg_padding;
-string panel_bg_padding_str;
-
-class(HUDPanel) .void() panel_draw;
-
-// chat panel can be reduced / moved while the mapvote is active
-// let know the mapvote panel about chat pos and size
-float chat_posy;
-float chat_sizey;
-
-float current_player;
-
-float stringwidth_colors(string s, vector theSize);
-float stringwidth_nocolors(string s, vector theSize);
-float GetPlayerColorForce(int i);
-int GetPlayerColor(int i);
-string GetPlayerName(int i);
-void HUD_Panel_DrawProgressBar(vector theOrigin, vector theSize, string pic, float length_ratio, bool vertical, float baralign, vector theColor, float theAlpha, int drawflag);
-
-.int panel_showflags;
-const int PANEL_SHOW_NEVER    = 0x00;
-const int PANEL_SHOW_MAINGAME = 0x01;
-const int PANEL_SHOW_MINIGAME = 0x02;
-const int PANEL_SHOW_ALWAYS   = 0xff;
-bool HUD_Panel_CheckFlags(int showflags);
-
-
-// prev_* vars contain the health/armor at the previous FRAME
-// set to -1 when player is dead or was not playing
-int prev_health, prev_armor;
-float health_damagetime, armor_damagetime;
-int health_beforedamage, armor_beforedamage;
-// old_p_* vars keep track of previous values when smoothing value changes of the progressbar
-int old_p_health, old_p_armor;
-float old_p_healthtime, old_p_armortime;
-// prev_p_* vars contain the health/armor progressbar value at the previous FRAME
-// set to -1 to forcedly stop effects when we switch spectated player (e.g. from playerX: 70h to playerY: 50h)
-int prev_p_health, prev_p_armor;
-
-void HUD_ItemsTime();
-
-#define HUD_PANELS(HUD_PANEL) \
-       HUD_PANEL(WEAPONS      , HUD_Weapons      , weapons,        PANEL_SHOW_MAINGAME ) \
-       HUD_PANEL(AMMO         , HUD_Ammo         , ammo,           PANEL_SHOW_MAINGAME ) \
-       HUD_PANEL(POWERUPS     , HUD_Powerups     , powerups,       PANEL_SHOW_MAINGAME ) \
-       HUD_PANEL(HEALTHARMOR  , HUD_HealthArmor  , healtharmor,    PANEL_SHOW_MAINGAME ) \
-       HUD_PANEL(NOTIFY       , HUD_Notify       , notify,         PANEL_SHOW_ALWAYS   ) \
-       HUD_PANEL(TIMER        , HUD_Timer        , timer,          PANEL_SHOW_ALWAYS   ) \
-       HUD_PANEL(RADAR        , HUD_Radar        , radar,          PANEL_SHOW_MAINGAME ) \
-       HUD_PANEL(SCORE        , HUD_Score        , score,          PANEL_SHOW_ALWAYS   ) \
-       HUD_PANEL(RACETIMER    , HUD_RaceTimer    , racetimer,      PANEL_SHOW_MAINGAME ) \
-       HUD_PANEL(VOTE         , HUD_Vote         , vote,           PANEL_SHOW_ALWAYS   ) \
-       HUD_PANEL(MODICONS     , HUD_ModIcons     , modicons,       PANEL_SHOW_MAINGAME ) \
-       HUD_PANEL(PRESSEDKEYS  , HUD_PressedKeys  , pressedkeys,    PANEL_SHOW_MAINGAME ) \
-       HUD_PANEL(CHAT         , HUD_Chat         , chat,           PANEL_SHOW_ALWAYS   ) \
-       HUD_PANEL(ENGINEINFO   , HUD_EngineInfo   , engineinfo,     PANEL_SHOW_ALWAYS   ) \
-       HUD_PANEL(INFOMESSAGES , HUD_InfoMessages , infomessages,   PANEL_SHOW_MAINGAME ) \
-       HUD_PANEL(PHYSICS      , HUD_Physics      , physics,        PANEL_SHOW_MAINGAME ) \
-       HUD_PANEL(CENTERPRINT  , HUD_CenterPrint  , centerprint,    PANEL_SHOW_MAINGAME ) \
-       HUD_PANEL(MINIGAME_BOARD, HUD_MinigameBoard ,minigameboard, PANEL_SHOW_MINIGAME ) \
-       HUD_PANEL(MINIGAME_STATUS,HUD_MinigameStatus,minigamestatus,PANEL_SHOW_MINIGAME ) \
-       HUD_PANEL(MINIGAME_HELP,  HUD_MinigameHelp  ,minigamehelp,  PANEL_SHOW_MINIGAME ) \
-       HUD_PANEL(MINIGAME_MENU,  HUD_MinigameMenu  ,minigamemenu,  PANEL_SHOW_ALWAYS   ) \
-       HUD_PANEL(MAPVOTE      ,  MapVote_Draw      ,mapvote,       PANEL_SHOW_ALWAYS   ) \
-       HUD_PANEL(ITEMSTIME    ,  HUD_ItemsTime     ,itemstime,     PANEL_SHOW_MAINGAME ) \
-       HUD_PANEL(QUICKMENU    , HUD_QuickMenu    , quickmenu,      PANEL_SHOW_MAINGAME ) \
-       // always add new panels to the end of list
-
-
-#define HUD_PANEL(NAME, draw_func, name, showflags)                                                                                                                                                    \
-       int HUD_PANEL_##NAME;                                                                                                                                                                                   \
-       void draw_func(void);                                                                                                                                                                                   \
-       void RegisterHUD_Panel_##NAME() {                                                                                                                                                               \
-               HUD_PANEL_LAST = HUD_PANEL_##NAME = HUD_PANEL_NUM;                                                                                                                      \
-               entity hud_panelent = spawn();                                                                                                                                                          \
-               hud_panel[HUD_PANEL_##NAME] = hud_panelent;                                                                                                                             \
-               hud_panelent.classname = "hud_panel";                                                                                                                                           \
-               hud_panelent.panel_name = #name;                                                                                                                                                        \
-               hud_panelent.panel_id = HUD_PANEL_##NAME;                                                                                                                                       \
-               hud_panelent.panel_draw = draw_func;                                                                                                                                            \
-               hud_panelent.panel_showflags = showflags;                                                                                                                                       \
-               HUD_PANEL_NUM++;                                                                                                                                                                                        \
-       }                                                                                                                                                                                                                               \
-       ACCUMULATE_FUNCTION(RegisterHUD_Panels, RegisterHUD_Panel_##NAME);
-
-HUD_PANELS(HUD_PANEL)
-#undef HUD_PANEL
-
-#define HUD_PANEL(NAME) hud_panel[HUD_PANEL_##NAME]
-
-
-// Because calling lots of functions in QC apparently cuts fps in half on many machines:
-// ----------------------
-// MACRO HELL STARTS HERE
-// ----------------------
-// Little help for the poor people who have to make sense of this: Start from the bottom ;)
-
-// Get value for panel.current_panel_bg: if "" fetch default, else use panel_bg_str
-// comment on last line of macro: // we probably want to see a background in config mode at all times...
-#define HUD_Panel_GetBg() do {                                                                                      \
-       string panel_bg;                                                                                                \
-       if (!autocvar__hud_configure && panel_bg_str == "0") {                                                          \
-               panel_bg = "0";                                                                                             \
-       } else {                                                                                                        \
-               if (panel_bg_str == "") {                                                                                   \
-                       panel_bg_str = autocvar_hud_panel_bg;                                                                   \
-               }                                                                                                           \
-               if (panel_bg_str == "0" && !autocvar__hud_configure) {                                                      \
-                       panel_bg = "0";                                                                                         \
-               } else {                                                                                                    \
-                       if (panel_bg_str == "0" && autocvar__hud_configure)                                                     \
-                               panel_bg_alpha_str = "0";                                                                           \
-                       panel_bg = strcat(hud_skin_path, "/", panel_bg_str);                                                    \
-                       if (precache_pic(panel_bg) == "") {                                                                     \
-                               panel_bg = strcat(hud_skin_path, "/", "border_default");                                            \
-                               if (precache_pic(panel_bg) == "") {                                                                 \
-                                       panel_bg = strcat("gfx/hud/default/", "border_default");                                        \
-                               }                                                                                                   \
-                       }                                                                                                       \
-               }                                                                                                           \
-       }                                                                                                               \
-       if (panel.current_panel_bg)                                                                                     \
-               strunzone(panel.current_panel_bg);                                                                          \
-       panel.current_panel_bg = strzone(panel_bg);                                                                     \
-} while(0)
-
-// Get value for panel_bg_color: if "" fetch default, else use panel_bg_color. Convert pants, shirt or teamcolor into a vector.
-#define HUD_Panel_GetColor() do {                                                                                   \
-       if ((teamplay) && panel_bg_color_team) {                                                                        \
-               if (autocvar__hud_configure && myteam == NUM_SPECTATOR)                                                     \
-                       panel_bg_color = '1 0 0' * panel_bg_color_team;                                                         \
-               else                                                                                                        \
-                       panel_bg_color = myteamcolors * panel_bg_color_team;                                                    \
-       } else if (autocvar_hud_configure_teamcolorforced && autocvar__hud_configure && panel_bg_color_team) {          \
-               panel_bg_color = '1 0 0' * panel_bg_color_team;                                                             \
-       } else {                                                                                                        \
-               if (panel_bg_color_str == "") {                                                                             \
-                       panel_bg_color = autocvar_hud_panel_bg_color;                                                           \
-               } else {                                                                                                    \
-                       if (panel_bg_color_str == "shirt") {                                                                    \
-                               panel_bg_color = colormapPaletteColor(floor(stof(getplayerkeyvalue(current_player, "colors")) / 16), 0); \
-                       } else if (panel_bg_color_str == "pants") {                                                             \
-                               panel_bg_color = colormapPaletteColor(stof(getplayerkeyvalue(current_player, "colors")) % 16, 1); \
-                       } else {                                                                                                \
-                               panel_bg_color = stov(panel_bg_color_str);                                                          \
-                       }                                                                                                       \
-               }                                                                                                           \
-       }                                                                                                               \
-} while(0)
-
-// Get value for panel_bg_color_team: if "" fetch default, else use panel_bg_color_team_str
-#define HUD_Panel_GetColorTeam() do {                                                                               \
-       if (panel_bg_color_team_str == "") {                                                                            \
-               panel_bg_color_team = autocvar_hud_panel_bg_color_team;                                                     \
-       } else {                                                                                                        \
-               panel_bg_color_team = stof(panel_bg_color_team_str);                                                        \
-       }                                                                                                               \
-} while(0)
-
-// Get value for panel_bg_alpha: if "" fetch default, else use panel_bg_alpha. Also do various menu dialog fadeout/in checks, and minalpha checks
-// comment on line 3 of macro: // do not set a minalpha cap when showing the config dialog for this panel
-#define HUD_Panel_GetBgAlpha() do {                                                                                 \
-       if (panel_bg_alpha_str == "") {                                                                                 \
-               panel_bg_alpha_str = ftos(autocvar_hud_panel_bg_alpha);                                                     \
-       }                                                                                                               \
-       panel_bg_alpha = stof(panel_bg_alpha_str);                                                                      \
-       if (autocvar__hud_configure) {                                                                                  \
-               if (!panel_enabled)                                                                                         \
-                       panel_bg_alpha = 0.25;                                                                                  \
-               else if (menu_enabled == 2 && panel == highlightedPanel)                                                    \
-                       panel_bg_alpha = (1 - autocvar__menu_alpha) * max(cvar("hud_configure_bg_minalpha"), panel_bg_alpha) + autocvar__menu_alpha * panel_bg_alpha;\
-               else                                                                                                        \
-                       panel_bg_alpha = max(cvar("hud_configure_bg_minalpha"), panel_bg_alpha);                                \
-       }                                                                                                               \
-} while(0)
-
-// Get value for panel_fg_alpha. Also do various minalpha checks
-// comment on line 2 of macro: // ALWAYS show disabled panels at 0.25 alpha when in config mode
-#define HUD_Panel_GetFgAlpha() do {                                                                                 \
-       panel_fg_alpha = autocvar_hud_panel_fg_alpha;                                                                   \
-       if (autocvar__hud_configure && !panel_enabled)                                                                  \
-               panel_fg_alpha = 0.25;                                                                                      \
-} while(0)
-
-// Get border. See comments above, it's similar.
-#define HUD_Panel_GetBorder() do {                                                                                  \
-       if (panel_bg_border_str == "") {                                                                                \
-               panel_bg_border = autocvar_hud_panel_bg_border;                                                             \
-       } else {                                                                                                        \
-               panel_bg_border = stof(panel_bg_border_str);                                                                \
-       }                                                                                                               \
-} while(0)
-
-// Get padding. See comments above, it's similar.
-// last line is a port of the old function, basically always make sure the panel contents are at least 5 pixels tall/wide, to disallow extreme padding values
-#define HUD_Panel_GetPadding() do {                                                                                 \
-       if (panel_bg_padding_str == "") {                                                                               \
-               panel_bg_padding = autocvar_hud_panel_bg_padding;                                                           \
-       } else {                                                                                                        \
-               panel_bg_padding = stof(panel_bg_padding_str);                                                              \
-       }                                                                                                               \
-       panel_bg_padding = min(min(panel_size.x, panel_size.y)/2 - 5, panel_bg_padding);                                \
-} while(0)
-
-// return smoothly faded pos and size of given panel when a dialog is active
-// don't center too wide panels, it doesn't work with different resolutions
-#define HUD_Panel_UpdatePosSize_ForMenu() do { \
-       vector menu_enable_size = panel_size; \
-       float max_panel_width = 0.52 * vid_conwidth; \
-       if(panel_size.x > max_panel_width) \
-       { \
-               menu_enable_size.x = max_panel_width; \
-               menu_enable_size.y = panel_size.y * (menu_enable_size.x / panel_size.x); \
-       } \
-       vector menu_enable_pos = eX * (panel_bg_border + 0.5 * max_panel_width) + eY * 0.5 * vid_conheight - 0.5 * menu_enable_size; \
-       panel_pos = (1 - autocvar__menu_alpha) * panel_pos + (autocvar__menu_alpha) * menu_enable_pos; \
-       panel_size = (1 - autocvar__menu_alpha) * panel_size + (autocvar__menu_alpha) * menu_enable_size; \
-} while(0)
-
-// Scale the pos and size vectors to absolute coordinates
-#define HUD_Panel_ScalePosSize() do {                                                                               \
-       panel_pos.x *= vid_conwidth;  panel_pos.y *= vid_conheight;                                                     \
-       panel_size.x *= vid_conwidth; panel_size.y *= vid_conheight;                                                    \
-} while(0)
-
-// NOTE: in hud_configure mode cvars must be reloaded every frame
-#define HUD_Panel_UpdateCvars() do {                                                                                \
-       if (panel.update_time <= time) {                                                                                \
-               if (autocvar__hud_configure) panel_enabled = cvar(strcat("hud_panel_", panel.panel_name));                  \
-               panel_pos = stov(cvar_string(strcat("hud_panel_", panel.panel_name, "_pos")));                              \
-               panel_size = stov(cvar_string(strcat("hud_panel_", panel.panel_name, "_size")));                            \
-               HUD_Panel_ScalePosSize();                                                                                   \
-               panel_bg_str = cvar_string(strcat("hud_panel_", panel.panel_name, "_bg"));                                  \
-               panel_bg_color_str = cvar_string(strcat("hud_panel_", panel.panel_name, "_bg_color"));                      \
-               panel_bg_color_team_str = cvar_string(strcat("hud_panel_", panel.panel_name, "_bg_color_team"));            \
-               panel_bg_alpha_str = cvar_string(strcat("hud_panel_", panel.panel_name, "_bg_alpha"));                      \
-               panel_bg_border_str = cvar_string(strcat("hud_panel_", panel.panel_name, "_bg_border"));                    \
-               panel_bg_padding_str = cvar_string(strcat("hud_panel_", panel.panel_name, "_bg_padding"));                  \
-               HUD_Panel_GetBg();                                                                                          \
-               if (panel.current_panel_bg != "0") {                                                                        \
-                       HUD_Panel_GetColorTeam();                                                                               \
-                       HUD_Panel_GetColor();                                                                                   \
-                       HUD_Panel_GetBgAlpha();                                                                                 \
-                       HUD_Panel_GetBorder();                                                                                  \
-               }                                                                                                           \
-               HUD_Panel_GetFgAlpha();                                                                                     \
-               HUD_Panel_GetPadding();                                                                                     \
-               panel.current_panel_bg_alpha = panel_bg_alpha;                                                              \
-               panel.current_panel_fg_alpha = panel_fg_alpha;                                                              \
-               if (menu_enabled == 2 && panel == highlightedPanel) {                                                       \
-                       HUD_Panel_UpdatePosSize_ForMenu();                                                                      \
-               } else {                                                                                                    \
-                       panel_bg_alpha *= hud_fade_alpha;                                                                       \
-                       panel_fg_alpha *= hud_fade_alpha;                                                                       \
-               }                                                                                                           \
-               panel.current_panel_pos = panel_pos;                                                                        \
-               panel.current_panel_size = panel_size;                                                                      \
-               panel.current_panel_bg_border = panel_bg_border;                                                            \
-               panel.current_panel_bg_color = panel_bg_color;                                                              \
-               panel.current_panel_bg_color_team = panel_bg_color_team;                                                    \
-               panel.current_panel_bg_padding = panel_bg_padding;                                                          \
-               panel.update_time = (autocvar__hud_configure) ? time : time + autocvar_hud_panel_update_interval;           \
-       } else {                                                                                                        \
-               panel_pos = panel.current_panel_pos;                                                                        \
-               panel_size = panel.current_panel_size;                                                                      \
-               panel_bg_alpha = panel.current_panel_bg_alpha * hud_fade_alpha;                                             \
-               panel_bg_border = panel.current_panel_bg_border;                                                            \
-               panel_bg_color = panel.current_panel_bg_color;                                                              \
-               panel_bg_color_team = panel.current_panel_bg_color_team;                                                    \
-               panel_bg_padding = panel.current_panel_bg_padding;                                                          \
-               panel_fg_alpha = panel.current_panel_fg_alpha * hud_fade_alpha;                                             \
-       }                                                                                                               \
-} while(0)
-
-#define HUD_Panel_UpdatePosSize() do {                                                                              \
-       panel_enabled = cvar(strcat("hud_panel_", panel.panel_name));                                                   \
-       panel_pos = stov(cvar_string(strcat("hud_panel_", panel.panel_name, "_pos")));                                  \
-       panel_size = stov(cvar_string(strcat("hud_panel_", panel.panel_name, "_size")));                                \
-       HUD_Panel_ScalePosSize();                                                                                       \
-       if (menu_enabled == 2 && panel == highlightedPanel) {                                                           \
-               HUD_Panel_UpdatePosSize_ForMenu();                                                                          \
-       }                                                                                                               \
-       panel_bg_border_str = cvar_string(strcat("hud_panel_", panel.panel_name, "_bg_border"));                        \
-       HUD_Panel_GetBorder();                                                                                          \
-} while(0)
-
-const int NOTIFY_MAX_ENTRIES = 10;
-const float NOTIFY_ICON_MARGIN = 0.02;
-
-int notify_index;
-int notify_count;
-float notify_times[NOTIFY_MAX_ENTRIES];
-string notify_attackers[NOTIFY_MAX_ENTRIES];
-string notify_victims[NOTIFY_MAX_ENTRIES];
-string notify_icons[NOTIFY_MAX_ENTRIES];
-
-void HUD_Notify_Push(string icon, string attacker, string victim);
-
-var void HUD_ModIcons_GameType(vector pos, vector size);
-void HUD_ModIcons_SetFunc();
-#endif