From 7678a368bc5ff120b0d32545df01b464668a1e34 Mon Sep 17 00:00:00 2001 From: terencehill Date: Wed, 29 Jan 2025 19:44:26 +0100 Subject: [PATCH] Menu: get rid of the small lag when opening Settings/Game/Weapons Also allow loading weapon fallback icons from default/ --- qcsrc/common/items/item.qh | 57 ++++++++++++------- qcsrc/common/mutators/mutator/buffs/buffs.qh | 15 ++++- qcsrc/common/mutators/mutator/nades/nades.qh | 15 ++++- .../mutators/mutator/status_effects/all.qh | 18 +++++- qcsrc/common/weapons/weapon.qh | 20 ++++++- 5 files changed, 95 insertions(+), 30 deletions(-) diff --git a/qcsrc/common/items/item.qh b/qcsrc/common/items/item.qh index 3b5970a4a..43a66dc38 100644 --- a/qcsrc/common/items/item.qh +++ b/qcsrc/common/items/item.qh @@ -119,28 +119,41 @@ enum #define ITEM_HANDLE(signal, ...) __Item_Send_##signal(__VA_ARGS__) CLASS(GameItem, Object) - ATTRIB(GameItem, m_id, int, 0); - /** the canonical spawnfunc name */ - ATTRIB(GameItem, m_canonical_spawnfunc, string); - METHOD(GameItem, m_spawnfunc_hookreplace, GameItem(GameItem this, entity e)) { return this; } - ATTRIB(GameItem, m_name, string); - ATTRIB(GameItem, m_icon, string); - ATTRIB(GameItem, m_color, vector, '1 1 1'); - ATTRIB(GameItem, m_waypoint, string); - ATTRIB(GameItem, m_waypointblink, int, 1); + ATTRIB(GameItem, m_id, int, 0); + /** the canonical spawnfunc name */ + ATTRIB(GameItem, m_canonical_spawnfunc, string); + METHOD(GameItem, m_spawnfunc_hookreplace, GameItem(GameItem this, entity e)) { return this; } + ATTRIB(GameItem, m_name, string); + ATTRIB(GameItem, m_icon, string); + ATTRIB(GameItem, m_color, vector, '1 1 1'); + ATTRIB(GameItem, m_waypoint, string); + ATTRIB(GameItem, m_waypointblink, int, 1); #ifdef GAMEQC - ATTRIB(GameItem, m_glow, bool, false); - ATTRIB(GameItem, m_respawnsound, Sound, SND_ITEMRESPAWN); + ATTRIB(GameItem, m_glow, bool, false); + ATTRIB(GameItem, m_respawnsound, Sound, SND_ITEMRESPAWN); #endif - METHOD(GameItem, display, void(GameItem this, void(string name, string icon) returns)) - { - TC(GameItem, this); - returns(this.m_name, (this.m_icon != "") ? sprintf("/gfx/hud/%s/%s", cvar_string("hud_skin"), this.m_icon) : string_null); - } - METHOD(GameItem, show, void(GameItem this)) - { - TC(GameItem, this); - LOG_INFO("A game item"); - } - void ITEM_HANDLE(Show, GameItem this) { this.show(this); } +#ifndef SVQC + METHOD(GameItem, display, void(entity this, void(string name, string icon) returns)) + { + string img = this.m_icon; + if (img != "") + { + img = sprintf("/gfx/hud/%s/%s", cvar_string("hud_skin"), this.m_icon); + #ifdef CSQC + if (precache_pic(img) == "") + #endif + #ifdef MENUQC + if (draw_PreloadPicture(img) == "") + #endif + img = sprintf("/gfx/hud/default/%s", this.m_icon); + } + returns(this.m_name, img); + } +#endif + METHOD(GameItem, show, void(GameItem this)) + { + TC(GameItem, this); + LOG_INFO("A game item"); + } + void ITEM_HANDLE(Show, GameItem this) { this.show(this); } ENDCLASS(GameItem) diff --git a/qcsrc/common/mutators/mutator/buffs/buffs.qh b/qcsrc/common/mutators/mutator/buffs/buffs.qh index b936cac65..7e59976ee 100644 --- a/qcsrc/common/mutators/mutator/buffs/buffs.qh +++ b/qcsrc/common/mutators/mutator/buffs/buffs.qh @@ -22,9 +22,20 @@ CLASS(Buff, StatusEffect) ATTRIB(Buff, m_skin, int, 0); ATTRIB(Buff, m_lifetime, float, 60); ATTRIB(Buff, m_sprite, string, ""); - METHOD(Buff, display, void(entity this, void(string name, string icon) returns)) { - returns(this.m_name, sprintf("/gfx/hud/%s/%s", cvar_string("hud_skin"), this.m_icon)); +#ifndef SVQC + METHOD(Buff, display, void(entity this, void(string name, string icon) returns)) + { + string img = sprintf("/gfx/hud/%s/%s", cvar_string("hud_skin"), this.m_icon); + #ifdef CSQC + if (precache_pic(img) == "") + #endif + #ifdef MENUQC + if (draw_PreloadPicture(img) == "") + #endif + img = sprintf("/gfx/hud/default/%s", this.m_icon); + returns(this.m_name, img); } +#endif #ifdef SVQC METHOD(Buff, m_time, float(Buff this)) { return cvar(strcat("g_buffs_", this.netname, "_time")); } diff --git a/qcsrc/common/mutators/mutator/nades/nades.qh b/qcsrc/common/mutators/mutator/nades/nades.qh index 456fb608a..6880befba 100644 --- a/qcsrc/common/mutators/mutator/nades/nades.qh +++ b/qcsrc/common/mutators/mutator/nades/nades.qh @@ -16,9 +16,20 @@ CLASS(Nade, Object) ATTRIB(Nade, m_alpha, float, 1); ATTRIBARRAY(Nade, m_projectile, int, 2); ATTRIBARRAY(Nade, m_trail, entity, 2); - METHOD(Nade, display, void(entity this, void(string name, string icon) returns)) { - returns(this.m_name, sprintf("/gfx/hud/%s/%s", cvar_string("hud_skin"), this.m_icon)); +#ifndef SVQC + METHOD(Nade, display, void(entity this, void(string name, string icon) returns)) + { + string img = sprintf("/gfx/hud/%s/%s", cvar_string("hud_skin"), this.m_icon); + #ifdef CSQC + if (precache_pic(img) == "") + #endif + #ifdef MENUQC + if (draw_PreloadPicture(img) == "") + #endif + img = sprintf("/gfx/hud/default/%s", this.m_icon); + returns(this.m_name, img); } +#endif ENDCLASS(Nade) REGISTER_NADE(Null, NEW(Nade)); diff --git a/qcsrc/common/mutators/mutator/status_effects/all.qh b/qcsrc/common/mutators/mutator/status_effects/all.qh index 726733036..87f7f4992 100644 --- a/qcsrc/common/mutators/mutator/status_effects/all.qh +++ b/qcsrc/common/mutators/mutator/status_effects/all.qh @@ -51,9 +51,23 @@ CLASS(StatusEffect, Object) /** Sets the persistent flag and updates client side if returning true */ METHOD(StatusEffect, m_persistent, bool(StatusEffect this, entity actor)) { return false; }; #endif - METHOD(StatusEffect, display, void(StatusEffect this, void(string name, string icon) returns)) +#ifndef SVQC + METHOD(StatusEffect, display, void(entity this, void(string name, string icon) returns)) { TC(StatusEffect, this); - returns(this.m_name, (this.m_icon != "") ? sprintf("/gfx/hud/%s/%s", cvar_string("hud_skin"), this.m_icon) : string_null); + string img = this.m_icon; + if (img != "") + { + img = sprintf("/gfx/hud/%s/%s", cvar_string("hud_skin"), this.m_icon); + #ifdef CSQC + if (precache_pic(img) == "") + #endif + #ifdef MENUQC + if (draw_PreloadPicture(img) == "") + #endif + img = sprintf("/gfx/hud/default/%s", this.m_icon); + } + returns(this.m_name, img); } +#endif ENDCLASS(StatusEffect) diff --git a/qcsrc/common/weapons/weapon.qh b/qcsrc/common/weapons/weapon.qh index 611f8f5f7..095cdff57 100644 --- a/qcsrc/common/weapons/weapon.qh +++ b/qcsrc/common/weapons/weapon.qh @@ -126,9 +126,25 @@ CLASS(Weapon, Object) METHOD(Weapon, wr_pickup, void(Weapon this, entity actor, .entity weaponentity)) {} /** (SERVER) update cvar based properties */ METHOD(Weapon, wr_update, void(Weapon this)) {} - METHOD(Weapon, display, void(entity this, void(string name, string icon) returns)) { - returns(this.m_name, (this.model2 != "") ? sprintf("/gfx/hud/%s/%s", cvar_string("hud_skin"), this.model2) : string_null); + +#ifndef SVQC + METHOD(Weapon, display, void(entity this, void(string name, string icon) returns)) + { + string img = this.model2; + if (img != "") + { + img = sprintf("/gfx/hud/%s/%s", cvar_string("hud_skin"), this.model2); + #ifdef CSQC + if (precache_pic(img) == "") + #endif + #ifdef MENUQC + if (draw_PreloadPicture(img) == "") + #endif + img = sprintf("/gfx/hud/default/%s", this.model2); + } + returns(this.m_name, img); } +#endif ENDCLASS(Weapon) #ifdef SVQC -- 2.39.5