]> git.rm.cloudns.org Git - xonotic/xonotic-data.pk3dir.git/commitdiff
Move itemstime hud drawing into the mutator
authorTimePath <andrew.hardaker1995@gmail.com>
Mon, 24 Aug 2015 02:34:56 +0000 (12:34 +1000)
committerTimePath <andrew.hardaker1995@gmail.com>
Mon, 24 Aug 2015 02:35:11 +0000 (12:35 +1000)
qcsrc/client/hud.qc
qcsrc/client/hud.qh
qcsrc/common/mutators/mutator/itemstime.qc
qcsrc/server/t_items.qh

index 4310efbe982dfae6b83e5fdf9ca3880b8dd2d3c6..3482a62bf06faf9cb266cccb9efcd55046463198 100644 (file)
@@ -4813,240 +4813,6 @@ void HUD_CenterPrint (void)
        }
 }
 
-// ItemsTime (#XX)
-//
-const float ITEMSTIME_MAXITEMS = 10;
-float ItemsTime_time[ITEMSTIME_MAXITEMS];
-float ItemsTime_availableTime[ITEMSTIME_MAXITEMS];
-string GetItemsTimePicture(float i)
-{
-       switch(i)
-       {
-               case 0: return "item_large_armor";
-               case 1: return "item_mega_health";
-               case 2: return "strength";
-               case 3: return "shield";
-               case 4: return "item_mega_health";
-               case 5: return "strength";
-               case 6: return "shield";
-               case 7: return "fuelregen";
-               case 8: return "jetpack";
-               case 9: return "superweapons";
-               default: return "";
-       }
-}
-
-void DrawItemsTimeItem(vector myPos, vector mySize, float ar, float itemcode, float item_time, bool item_available, float item_availableTime)
-{
-       float t = 0;
-       vector color = '0 0 0';
-       float picalpha;
-
-       if(autocvar_hud_panel_itemstime_hidespawned == 2)
-               picalpha = 1;
-       else if(item_available)
-       {
-               float BLINK_FACTOR = 0.15;
-               float BLINK_BASE = 0.85;
-               float BLINK_FREQ = 5;
-               picalpha = BLINK_BASE + BLINK_FACTOR * cos(time * BLINK_FREQ);
-       }
-       else
-               picalpha = 0.5;
-       t = floor(item_time - time + 0.999);
-       if(t < 5)
-               color = '0.7 0 0';
-       else if(t < 10)
-               color = '0.7 0.7 0';
-       else
-               color = '1 1 1';
-
-       vector picpos, numpos;
-       if(autocvar_hud_panel_itemstime_iconalign)
-       {
-               numpos = myPos;
-               picpos = myPos + eX * (ar - 1) * mySize_y;
-       }
-       else
-       {
-               numpos = myPos + eX * mySize_y;
-               picpos = myPos;
-       }
-
-       if(t > 0 && autocvar_hud_panel_itemstime_progressbar)
-       {
-               vector p_pos, p_size;
-               if(autocvar_hud_panel_itemstime_progressbar_reduced)
-               {
-                       p_pos = numpos;
-                       p_size = eX * ((ar - 1)/ar) * mySize_x + eY * mySize_y;
-               }
-               else
-               {
-                       p_pos = myPos;
-                       p_size = mySize;
-               }
-               HUD_Panel_DrawProgressBar(p_pos, p_size, autocvar_hud_panel_itemstime_progressbar_name, t/autocvar_hud_panel_itemstime_progressbar_maxtime, 0, autocvar_hud_panel_itemstime_iconalign, color, autocvar_hud_progressbar_alpha * panel_fg_alpha, DRAWFLAG_NORMAL);
-       }
-
-       if(t > 0 && autocvar_hud_panel_itemstime_text)
-               drawstring_aspect(numpos, ftos(t), eX * ((ar - 1)/ar) * mySize_x + eY * mySize_y, color, panel_fg_alpha, DRAWFLAG_NORMAL);
-       else
-               picpos.x = myPos.x + mySize.x / 2 - mySize.y / 2;
-       if(item_availableTime)
-               drawpic_aspect_skin_expanding(picpos, GetItemsTimePicture(itemcode), '1 1 0' * mySize_y, '1 1 1', panel_fg_alpha * picalpha, DRAWFLAG_NORMAL, item_availableTime);
-       drawpic_aspect_skin(picpos, GetItemsTimePicture(itemcode), '1 1 0' * mySize_y, '1 1 1', panel_fg_alpha * picalpha, DRAWFLAG_NORMAL);
-}
-
-void HUD_ItemsTime(void)
-{
-       if(!autocvar__hud_configure)
-       {
-               if(!(
-                       (autocvar_hud_panel_itemstime == 1 && spectatee_status != 0)
-               ||      (autocvar_hud_panel_itemstime == 2 && (spectatee_status != 0 || warmup_stage))
-                       )) { return; }
-       }
-       else
-       {
-               // do not show here mutator-dependent items
-               ItemsTime_time[0] = time + 0;
-               ItemsTime_time[1] = time + 8;
-               ItemsTime_time[2] = -1; // mutator-dependent
-               ItemsTime_time[3] = -1; // mutator-dependent
-               ItemsTime_time[4] = -1; // mutator-dependent
-               ItemsTime_time[5] = time + 0;
-               ItemsTime_time[6] = time + 4;
-               ItemsTime_time[7] = time + 49;
-               ItemsTime_time[8] = -1;
-               ItemsTime_time[9] = time + 28;
-       }
-
-       float i;
-       float count = 0;
-       if(autocvar_hud_panel_itemstime_hidespawned == 1)
-               for (i = 0; i < ITEMSTIME_MAXITEMS; ++i)
-                       count += (ItemsTime_time[i] > time || -ItemsTime_time[i] > time);
-       else if(autocvar_hud_panel_itemstime_hidespawned == 2)
-               for (i = 0; i < ITEMSTIME_MAXITEMS; ++i)
-                       count += (ItemsTime_time[i] > time);
-       else
-               for (i = 0; i < ITEMSTIME_MAXITEMS; ++i)
-                       count += (ItemsTime_time[i] != -1);
-       if (count == 0)
-               return;
-
-       HUD_Panel_UpdateCvars();
-
-       vector pos, mySize;
-       pos = panel_pos;
-       mySize = panel_size;
-
-       if(panel_bg_padding)
-       {
-               pos += '1 1 0' * panel_bg_padding;
-               mySize -= '2 2 0' * panel_bg_padding;
-       }
-
-       float rows, columns;
-       float ar = max(2, autocvar_hud_panel_itemstime_ratio) + 1;
-       rows = HUD_GetRowCount(count, mySize, ar);
-       columns = ceil(count/rows);
-
-       vector itemstime_size = eX * mySize.x*(1/columns) + eY * mySize.y*(1/rows);
-
-       vector offset = '0 0 0';
-       float newSize;
-       if(autocvar_hud_panel_itemstime_dynamicsize)
-       {
-               if(autocvar__hud_configure)
-               if(menu_enabled != 2)
-                       HUD_Panel_DrawBg(1); // also draw the bg of the entire panel
-
-               // reduce panel to avoid spacing items
-               if(itemstime_size.x / itemstime_size.y < ar)
-               {
-                       newSize = rows * itemstime_size.x / ar;
-                       pos.y += (mySize.y - newSize) / 2;
-                       mySize.y = newSize;
-                       itemstime_size.y = mySize.y / rows;
-               }
-               else
-               {
-                       newSize = columns * itemstime_size.y * ar;
-                       pos.x += (mySize.x - newSize) / 2;
-                       mySize.x = newSize;
-                       itemstime_size.x = mySize.x / columns;
-               }
-               panel_pos = pos - '1 1 0' * panel_bg_padding;
-               panel_size = mySize + '2 2 0' * panel_bg_padding;
-       }
-       else
-       {
-               if(itemstime_size.x/itemstime_size.y > ar)
-               {
-                       newSize = ar * itemstime_size.y;
-                       offset.x = itemstime_size.x - newSize;
-                       pos.x += offset.x/2;
-                       itemstime_size.x = newSize;
-               }
-               else
-               {
-                       newSize = 1/ar * itemstime_size.x;
-                       offset.y = itemstime_size.y - newSize;
-                       pos.y += offset.y/2;
-                       itemstime_size.y = newSize;
-               }
-       }
-
-       HUD_Panel_DrawBg(1);
-
-       float row = 0, column = 0;
-       bool item_available;
-       for (i = 0; i < ITEMSTIME_MAXITEMS; ++i) {
-               if (ItemsTime_time[i] == -1)
-                       continue;
-
-               float item_time = ItemsTime_time[i];
-               if(item_time < -1)
-               {
-                       item_available = true;
-                       item_time = -item_time;
-               }
-               else
-                       item_available = (item_time <= time);
-
-               if(ItemsTime_time[i] >= 0)
-               {
-                       if(time <= ItemsTime_time[i])
-                               ItemsTime_availableTime[i] = 0;
-                       else if(ItemsTime_availableTime[i] == 0)
-                               ItemsTime_availableTime[i] = time;
-               }
-               else if(ItemsTime_availableTime[i] == 0)
-                       ItemsTime_availableTime[i] = time;
-
-               float f = (time - ItemsTime_availableTime[i]) * 2;
-               f = (f > 1) ? 0 : bound(0, f, 1);
-
-               if(autocvar_hud_panel_itemstime_hidespawned == 1)
-                       if(!(ItemsTime_time[i] > time || -ItemsTime_time[i] > time))
-                               continue;
-
-               if(autocvar_hud_panel_itemstime_hidespawned == 2)
-                       if(!(ItemsTime_time[i] > time))
-                               continue;
-
-               DrawItemsTimeItem(pos + eX * column * (itemstime_size.x + offset.x) + eY * row * (itemstime_size.y + offset.y), itemstime_size, ar, i, item_time, item_available, f);
-               ++row;
-               if(row >= rows)
-               {
-                       row = 0;
-                       column = column + 1;
-               }
-       }
-}
-
 
 /*
 ==================
index 8a2f76ded479e0cc2427e32d690b844235f8d1a7..ee8ca1c687a9377e931be117f4aae7679bbaf56d 100644 (file)
@@ -146,6 +146,7 @@ float old_p_healthtime, old_p_armortime;
 // 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) \
index b20cfbff317038378de093c086939e530cc235f0..3fd47c61ade0c220886b3480646b82b72c2969a8 100644 (file)
@@ -12,6 +12,9 @@ void IT_Write(entity e, int i, float f) {
 #endif
 
 #ifdef CSQC
+const float ITEMSTIME_MAXITEMS = 10;
+float ItemsTime_time[ITEMSTIME_MAXITEMS];
+float ItemsTime_availableTime[ITEMSTIME_MAXITEMS];
 MUTATOR_HOOKFUNCTION(itemstime, CSQC_Parse_TempEntity) {
     if (MUTATOR_RETURNVALUE) return false;
     if (!ReadMutatorEquals(mutator_argv_int_0, itemstime)) return false;
@@ -208,3 +211,236 @@ MUTATOR_HOOKFUNCTION(itemstime, PlayerSpawn) {
 }
 
 #endif
+
+#ifdef CSQC
+
+string GetItemsTimePicture(float i)
+{
+    switch(i)
+    {
+        case 0: return "item_large_armor";
+        case 1: return "item_mega_health";
+        case 2: return "strength";
+        case 3: return "shield";
+        case 4: return "item_mega_health";
+        case 5: return "strength";
+        case 6: return "shield";
+        case 7: return "fuelregen";
+        case 8: return "jetpack";
+        case 9: return "superweapons";
+        default: return "";
+    }
+}
+
+void DrawItemsTimeItem(vector myPos, vector mySize, float ar, float itemcode, float item_time, bool item_available, float item_availableTime)
+{
+    float t = 0;
+    vector color = '0 0 0';
+    float picalpha;
+
+    if(autocvar_hud_panel_itemstime_hidespawned == 2)
+        picalpha = 1;
+    else if(item_available)
+    {
+        float BLINK_FACTOR = 0.15;
+        float BLINK_BASE = 0.85;
+        float BLINK_FREQ = 5;
+        picalpha = BLINK_BASE + BLINK_FACTOR * cos(time * BLINK_FREQ);
+    }
+    else
+        picalpha = 0.5;
+    t = floor(item_time - time + 0.999);
+    if(t < 5)
+        color = '0.7 0 0';
+    else if(t < 10)
+        color = '0.7 0.7 0';
+    else
+        color = '1 1 1';
+
+    vector picpos, numpos;
+    if(autocvar_hud_panel_itemstime_iconalign)
+    {
+        numpos = myPos;
+        picpos = myPos + eX * (ar - 1) * mySize_y;
+    }
+    else
+    {
+        numpos = myPos + eX * mySize_y;
+        picpos = myPos;
+    }
+
+    if(t > 0 && autocvar_hud_panel_itemstime_progressbar)
+    {
+        vector p_pos, p_size;
+        if(autocvar_hud_panel_itemstime_progressbar_reduced)
+        {
+            p_pos = numpos;
+            p_size = eX * ((ar - 1)/ar) * mySize_x + eY * mySize_y;
+        }
+        else
+        {
+            p_pos = myPos;
+            p_size = mySize;
+        }
+        HUD_Panel_DrawProgressBar(p_pos, p_size, autocvar_hud_panel_itemstime_progressbar_name, t/autocvar_hud_panel_itemstime_progressbar_maxtime, 0, autocvar_hud_panel_itemstime_iconalign, color, autocvar_hud_progressbar_alpha * panel_fg_alpha, DRAWFLAG_NORMAL);
+    }
+
+    if(t > 0 && autocvar_hud_panel_itemstime_text)
+        drawstring_aspect(numpos, ftos(t), eX * ((ar - 1)/ar) * mySize_x + eY * mySize_y, color, panel_fg_alpha, DRAWFLAG_NORMAL);
+    else
+        picpos.x = myPos.x + mySize.x / 2 - mySize.y / 2;
+    if(item_availableTime)
+        drawpic_aspect_skin_expanding(picpos, GetItemsTimePicture(itemcode), '1 1 0' * mySize_y, '1 1 1', panel_fg_alpha * picalpha, DRAWFLAG_NORMAL, item_availableTime);
+    drawpic_aspect_skin(picpos, GetItemsTimePicture(itemcode), '1 1 0' * mySize_y, '1 1 1', panel_fg_alpha * picalpha, DRAWFLAG_NORMAL);
+}
+
+void HUD_ItemsTime()
+{
+    if(!autocvar__hud_configure)
+    {
+        if(!(
+            (autocvar_hud_panel_itemstime == 1 && spectatee_status != 0)
+        ||     (autocvar_hud_panel_itemstime == 2 && (spectatee_status != 0 || warmup_stage))
+            )) { return; }
+    }
+    else
+    {
+        // do not show here mutator-dependent items
+        ItemsTime_time[0] = time + 0;
+        ItemsTime_time[1] = time + 8;
+        ItemsTime_time[2] = -1; // mutator-dependent
+        ItemsTime_time[3] = -1; // mutator-dependent
+        ItemsTime_time[4] = -1; // mutator-dependent
+        ItemsTime_time[5] = time + 0;
+        ItemsTime_time[6] = time + 4;
+        ItemsTime_time[7] = time + 49;
+        ItemsTime_time[8] = -1;
+        ItemsTime_time[9] = time + 28;
+    }
+
+    float i;
+    float count = 0;
+    if(autocvar_hud_panel_itemstime_hidespawned == 1)
+        for (i = 0; i < ITEMSTIME_MAXITEMS; ++i)
+            count += (ItemsTime_time[i] > time || -ItemsTime_time[i] > time);
+    else if(autocvar_hud_panel_itemstime_hidespawned == 2)
+        for (i = 0; i < ITEMSTIME_MAXITEMS; ++i)
+            count += (ItemsTime_time[i] > time);
+    else
+        for (i = 0; i < ITEMSTIME_MAXITEMS; ++i)
+            count += (ItemsTime_time[i] != -1);
+    if (count == 0)
+        return;
+
+    HUD_Panel_UpdateCvars();
+
+    vector pos, mySize;
+    pos = panel_pos;
+    mySize = panel_size;
+
+    if(panel_bg_padding)
+    {
+        pos += '1 1 0' * panel_bg_padding;
+        mySize -= '2 2 0' * panel_bg_padding;
+    }
+
+    float rows, columns;
+    float ar = max(2, autocvar_hud_panel_itemstime_ratio) + 1;
+    rows = HUD_GetRowCount(count, mySize, ar);
+    columns = ceil(count/rows);
+
+    vector itemstime_size = eX * mySize.x*(1/columns) + eY * mySize.y*(1/rows);
+
+    vector offset = '0 0 0';
+    float newSize;
+    if(autocvar_hud_panel_itemstime_dynamicsize)
+    {
+        if(autocvar__hud_configure)
+        if(menu_enabled != 2)
+            HUD_Panel_DrawBg(1); // also draw the bg of the entire panel
+
+        // reduce panel to avoid spacing items
+        if(itemstime_size.x / itemstime_size.y < ar)
+        {
+            newSize = rows * itemstime_size.x / ar;
+            pos.y += (mySize.y - newSize) / 2;
+            mySize.y = newSize;
+            itemstime_size.y = mySize.y / rows;
+        }
+        else
+        {
+            newSize = columns * itemstime_size.y * ar;
+            pos.x += (mySize.x - newSize) / 2;
+            mySize.x = newSize;
+            itemstime_size.x = mySize.x / columns;
+        }
+        panel_pos = pos - '1 1 0' * panel_bg_padding;
+        panel_size = mySize + '2 2 0' * panel_bg_padding;
+    }
+    else
+    {
+        if(itemstime_size.x/itemstime_size.y > ar)
+        {
+            newSize = ar * itemstime_size.y;
+            offset.x = itemstime_size.x - newSize;
+            pos.x += offset.x/2;
+            itemstime_size.x = newSize;
+        }
+        else
+        {
+            newSize = 1/ar * itemstime_size.x;
+            offset.y = itemstime_size.y - newSize;
+            pos.y += offset.y/2;
+            itemstime_size.y = newSize;
+        }
+    }
+
+    HUD_Panel_DrawBg(1);
+
+    float row = 0, column = 0;
+    bool item_available;
+    for (i = 0; i < ITEMSTIME_MAXITEMS; ++i) {
+        if (ItemsTime_time[i] == -1)
+            continue;
+
+        float item_time = ItemsTime_time[i];
+        if(item_time < -1)
+        {
+            item_available = true;
+            item_time = -item_time;
+        }
+        else
+            item_available = (item_time <= time);
+
+        if(ItemsTime_time[i] >= 0)
+        {
+            if(time <= ItemsTime_time[i])
+                ItemsTime_availableTime[i] = 0;
+            else if(ItemsTime_availableTime[i] == 0)
+                ItemsTime_availableTime[i] = time;
+        }
+        else if(ItemsTime_availableTime[i] == 0)
+            ItemsTime_availableTime[i] = time;
+
+        float f = (time - ItemsTime_availableTime[i]) * 2;
+        f = (f > 1) ? 0 : bound(0, f, 1);
+
+        if(autocvar_hud_panel_itemstime_hidespawned == 1)
+            if(!(ItemsTime_time[i] > time || -ItemsTime_time[i] > time))
+                continue;
+
+        if(autocvar_hud_panel_itemstime_hidespawned == 2)
+            if(!(ItemsTime_time[i] > time))
+                continue;
+
+        DrawItemsTimeItem(pos + eX * column * (itemstime_size.x + offset.x) + eY * row * (itemstime_size.y + offset.y), itemstime_size, ar, i, item_time, item_available, f);
+        ++row;
+        if(row >= rows)
+        {
+            row = 0;
+            column = column + 1;
+        }
+    }
+}
+
+#endif
index 364f4c188dc9da5297766d4394736314d9d15988..35cce6178d8a3ec4ca3078c72f5c4e74251a91de 100644 (file)
@@ -113,10 +113,6 @@ const float ITEM_RESPAWN_TICKS = 10;
 .float max_armorvalue;
 .float pickup_anyway;
 
-void Item_ItemsTime_SetTimesForPlayer(entity e);
-
-void Item_ItemsTime_ResetTimesForPlayer(entity e);
-
 void Item_Show (entity e, float mode);
 
 void Item_Respawn (void);