]> git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/commitdiff
Don't attempt to render the itemstats panel at all if there is no inventory entity...
authorMario <zacjardine@y7mail.com>
Thu, 3 Dec 2020 09:31:43 +0000 (19:31 +1000)
committerMario <zacjardine@y7mail.com>
Thu, 3 Dec 2020 09:31:43 +0000 (19:31 +1000)
qcsrc/client/hud/panel/scoreboard.qc
qcsrc/common/items/inventory.qh
qcsrc/common/state.qc

index a9f1a67bc37a2c225881ee780499eb46e5a01236..ad923c5dd5be92c6ec8ad9212d058c70d9e28a38 100644 (file)
@@ -1667,7 +1667,7 @@ bool Scoreboard_ItemStats_WouldDraw(float ypos)
 {
        if (MUTATOR_CALLHOOK(DrawScoreboardItemStats))
                return false;
-       if (!autocvar_hud_panel_scoreboard_itemstats || warmup_stage || ypos > 0.91 * vid_conheight)
+       if (!autocvar_hud_panel_scoreboard_itemstats || !g_inventory || warmup_stage || ypos > 0.91 * vid_conheight)
                return false;
 
        if (time < scoreboard_time + autocvar_hud_panel_scoreboard_itemstats_showdelay
index 87c85198d5c0c9adafdd8b2b9a1caf161b3688b6..3ffa6c003d63155fd6c3f4dd2450cc04a779089e 100644 (file)
@@ -38,10 +38,17 @@ STATIC_INIT(Inventory)
 
 #ifdef CSQC
 Inventory g_inventory;
+void Inventory_remove(entity this)
+{
+    if(g_inventory == this)
+        g_inventory = NULL;
+}
+
 NET_HANDLE(ENT_CLIENT_INVENTORY, bool isnew)
 {
     make_pure(this);
     g_inventory = this;
+    this.entremove = Inventory_remove;
     const int majorBits = Readbits(Inventory_groups_major);
     for (int i = 0; i < Inventory_groups_major; ++i) {
         if (!(majorBits & BIT(i))) {
@@ -137,5 +144,13 @@ void Inventory_delete(entity e) { delete(e.inventory); }
 void Inventory_update(entity e) { e.inventory.SendFlags = 0xFFFFFF; }
 
 void InventoryStorage_attach(entity e) { e.inventory_store = NEW(Inventory); e.inventory_store.drawonlytoclient = e; }
-void InventoryStorage_detach(entity e) { delete(e.inventory_store); }
+void InventoryStorage_delete(entity e) { delete(e.inventory_store); }
+void InventoryStorage_clear(entity e)
+{
+    // we don't need to network the changes, that is done when the inventory is detached
+    FOREACH(Items, true, {
+        .int fld = inv_items[it.m_id];
+        e.inventory_store.(fld) = 0;
+    });
+}
 #endif
index 7a5979e2bc2c0ba261c11281798bf1d2355fdc1a..406003efcb0ab36e3bf7a48ded846b6ac63d4287 100644 (file)
@@ -5,7 +5,8 @@
 void Inventory_new(PlayerState this);
 void Inventory_delete(entity this);
 void InventoryStorage_attach(PlayerState this);
-void InventoryStorage_detach(PlayerState this);
+void InventoryStorage_delete(PlayerState this);
+void InventoryStorage_clear(PlayerState this);
 
 void PlayerState_attach(entity this)
 {
@@ -22,6 +23,7 @@ void PlayerState_detach(entity this)
     PlayerState ps = PS(this);
        if (!ps) return;  // initial connect
        PS(this) = NULL;
+    InventoryStorage_clear(this);
 
        if (ps.m_client != this) return;  // don't own state, spectator
        ps.ps_push(ps, this);
@@ -74,7 +76,7 @@ void ClientState_detach(entity this)
     W_HitPlotClose(this);
     ClientData_Detach(this);
     entcs_detach(this);
-    InventoryStorage_detach(this);
+    InventoryStorage_delete(this);
        delete(CS(this));
        this._cs = NULL;