]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blobdiff - qcsrc/client/miscfunctions.qc
Merge branch 'master' into terencehill/infomessages_panel_update
[xonotic/xonotic-data.pk3dir.git] / qcsrc / client / miscfunctions.qc
index bbe0722fd7dad9464b9a8df5a3d1ceb7537d3059..d3b3e46d73526d230e87fe3da69a82f366833f18 100644 (file)
@@ -2,11 +2,11 @@
 
 #include "hud/all.qh"
 
-#include "../common/command/generic.qh"
+#include <common/command/generic.qh>
 
-#include "../common/teams.qh"
+#include <common/teams.qh>
 
-#include "../lib/csqcmodel/cl_model.qh"
+#include <lib/csqcmodel/cl_model.qh>
 
 
 void AuditLists()
@@ -79,6 +79,7 @@ void MoveToLast(entity e)
 
 float RegisterTeam(entity Team)
 {
+       assert_once(Team.team, eprint(Team));
        entity tm;
        AuditLists();
        for(tm = teams.sort_next; tm; tm = tm.sort_next)
@@ -118,13 +119,13 @@ void RemoveTeam(entity Team)
 
 entity GetTeam(int Team, bool add)
 {
+    TC(int, Team); TC(bool, add);
        int num = (Team == NUM_SPECTATOR) ? 16 : Team;
        if(teamslots[num])
                return teamslots[num];
        if (!add)
-               return world;
-       entity tm = new(team);
-       make_pure(tm);
+               return NULL;
+       entity tm = new_pure(team);
        tm.team = Team;
        teamslots[num] = tm;
        RegisterTeam(tm);
@@ -159,6 +160,7 @@ float PreviewExists(string name)
 // decolorizes and team colors the player name when needed
 string playername(string thename, float teamid)
 {
+    TC(int, teamid);
     string t;
     if (teamplay)
     {
@@ -222,6 +224,10 @@ void drawborderlines(float thickness, vector pos, vector dim, vector color, floa
 
 void drawpic_tiled(vector pos, string pic, vector sz, vector area, vector color, float theAlpha, float drawflag)
 {
+       pos = HUD_Shift(pos);
+       sz = HUD_Scale(sz);
+       area = HUD_Scale(area);
+
        vector current_pos = '0 0 0', end_pos, new_size = '0 0 0', ratio = '0 0 0';
        end_pos = pos + area;
 
@@ -256,6 +262,43 @@ void drawpic_aspect_skin_expanding_two(vector position, string pic, vector theSc
        drawpic_skin(position, pic, theScale, rgb, theAlpha * fadelerp, flag);
 }
 
+void HUD_Scale_Disable()
+{
+       hud_scale = '1 1 0';
+       hud_shift = '0 0 0';
+       drawfontscale = hud_scale;
+}
+
+void HUD_Scale_Enable()
+{
+       hud_scale = hud_scale_current;
+       hud_shift = hud_shift_current;
+       drawfontscale = hud_scale;
+}
+
+vector HUD_Scale(vector v)
+{
+       v.x = HUD_ScaleX(v.x);
+       v.y = HUD_ScaleY(v.y);
+       return v;
+}
+
+vector HUD_Shift(vector v)
+{
+       v.x = HUD_ShiftX(v.x);
+       v.y = HUD_ShiftY(v.y);
+       return v;
+}
+
+float stringwidth(string text, float handleColors, vector sz)
+{
+       vector dfs = drawfontscale;
+       drawfontscale = '1 1 0';
+       float r = stringwidth_builtin(text, handleColors, sz);
+       drawfontscale = dfs;
+       return r;
+}
+
 // drawstring wrapper to draw a string as large as possible with preserved aspect ratio into a box
 void drawstring_aspect(vector pos, string text, vector sz, vector color, float theAlpha, float drawflag) {
        SET_POS_AND_SZ_Y_ASPECT(false);
@@ -273,12 +316,16 @@ void drawstring_expanding(vector position, string text, vector theScale, vector
        float sz;
        sz = expandingbox_sizefactor_from_fadelerp(fadelerp);
 
+       drawfontscale = hud_scale * sz;
+       vector dfs = drawfontscale;
        drawfontscale = sz * '1 1 0';
-       drawstring(position + expandingbox_resize_centered_box_offset(sz, theScale, stringwidth(text, false, theScale * (sz / drawfontscale.x)) / (theScale.x * sz)), text, theScale * (sz / drawfontscale.x), rgb, theAlpha * (1 - fadelerp), flag);
+       float textaspect = stringwidth_builtin(text, false, theScale * (sz / drawfontscale.x)) / (theScale.x * sz);
+       drawfontscale = dfs;
+       drawstring(position + expandingbox_resize_centered_box_offset(sz, theScale, textaspect), text, HUD_Scale(theScale * (sz / drawfontscale.x)), rgb, theAlpha * (1 - fadelerp), flag);
        // width parameter:
-       //    (scale_x * sz / drawfontscale_x) * drawfontscale_x * SIZE1 / (scale_x * sz)
+       //    (scale_x * sz / drawfontscale.x) * drawfontscale.x * SIZE1 / (scale_x * sz)
        //    SIZE1
-       drawfontscale = '1 1 0';
+       drawfontscale = hud_scale;
 }
 
 // drawstring wrapper to draw a string as large as possible with preserved aspect ratio into a box
@@ -292,9 +339,10 @@ void drawcolorcodedstring_expanding(vector position, string text, vector theScal
        float sz;
        sz = expandingbox_sizefactor_from_fadelerp(fadelerp);
 
-       drawfontscale = sz * '1 1 0';
-       drawcolorcodedstring(position + expandingbox_resize_centered_box_offset(sz, theScale, stringwidth(text, true, theScale * (sz / drawfontscale.x)) / (theScale.x * sz)), text, theScale * (sz / drawfontscale.x), theAlpha * (1 - fadelerp), flag);
-       drawfontscale = '1 1 0';
+       drawfontscale = hud_scale * sz;
+       // eventually replace with drawcolorcodedstring
+       drawcolorcodedstring(position + expandingbox_resize_centered_box_offset(sz, theScale, stringwidth_builtin(text, true, theScale * (sz / drawfontscale.x)) / (theScale.x * sz)), text, theScale * (sz / drawfontscale.x), theAlpha * (1 - fadelerp), flag);
+       drawfontscale = hud_scale;
 }
 
 void drawcolorcodedstring_aspect_expanding(vector pos, string text, vector sz, float theAlpha, float drawflag, float fadelerp) {
@@ -482,30 +530,10 @@ void DrawCircleClippedPic(vector centre, float radi, string pic, float f, vector
        }
 }
 
-// TODO: entcs
-float getplayeralpha(int pl)
-{
-       entity e = CSQCModel_server2csqc(pl + 1);
-       return (e) ? e.alpha : 1;
-}
-
-// TODO: entcs
-vector getcsqcplayercolor(int pl)
-{
-       entity e = CSQCModel_server2csqc(pl);
-       return (e && e.colormap > 0) ? colormapPaletteColor(((e.colormap >= 1024) ? e.colormap : stof(getplayerkeyvalue(e.colormap - 1, "colors"))) & 0x0F, true) : '1 1 1';
-}
-
-// TODO: entcs
-bool getplayerisdead(int pl)
-{
-       entity e = CSQCModel_server2csqc(pl + 1);
-       return e ? e.csqcmodel_isdead : false;
-}
-
 /** engine callback */
-void URI_Get_Callback(int id, float status, string data)
+void URI_Get_Callback(int id, int status, string data)
 {
+    TC(int, id); TC(int, status);
        if(url_URI_Get_Callback(id, status, data))
        {
                // handled