From b8c465086ae947c91a9003273efad3bd56279199 Mon Sep 17 00:00:00 2001 From: Roman Chistokhodov Date: Wed, 5 Jun 2024 17:41:20 +0300 Subject: [PATCH] Add show_in_history property for hud inventory items --- cl_dll/hud_inventory.cpp | 6 +++++- cl_dll/hud_inventory.h | 1 + cl_dll/status_icons.cpp | 2 +- game_shared/json_utils.cpp | 11 +++++++++++ game_shared/json_utils.h | 1 + 5 files changed, 19 insertions(+), 2 deletions(-) diff --git a/cl_dll/hud_inventory.cpp b/cl_dll/hud_inventory.cpp index d973d696b7..4332a697f2 100644 --- a/cl_dll/hud_inventory.cpp +++ b/cl_dll/hud_inventory.cpp @@ -43,6 +43,9 @@ const char hudInventorySchema[] = R"( "position": { "type": "string", "pattern": "^topleft|status|bottom|topright|hide$" + }, + "show_in_history": { + "type": "boolean" } } } @@ -51,7 +54,7 @@ const char hudInventorySchema[] = R"( } )"; -InventoryItemHudSpec::InventoryItemHudSpec(): packedColor(0), alpha(0), position(INVENTORY_PLACE_DEFAULT), colorDefined(false) +InventoryItemHudSpec::InventoryItemHudSpec(): packedColor(0), alpha(0), position(INVENTORY_PLACE_DEFAULT), colorDefined(false), showInHistory(true) { itemName[0] = '\0'; spriteName[0] = '\0'; @@ -104,6 +107,7 @@ bool InventoryHudSpec::ReadFromFile(const char *fileName) item.colorDefined = ParseColor(colorIt->value.GetString(), item.packedColor); } UpdatePropertyFromJson(item.alpha, value, "alpha"); + UpdatePropertyFromJson(item.showInHistory, value, "show_in_history"); auto positionIt = value.FindMember("position"); if (positionIt != value.MemberEnd()) { diff --git a/cl_dll/hud_inventory.h b/cl_dll/hud_inventory.h index e458865b8b..58f1dc68a8 100644 --- a/cl_dll/hud_inventory.h +++ b/cl_dll/hud_inventory.h @@ -22,6 +22,7 @@ struct InventoryItemHudSpec int alpha; int position; bool colorDefined; + bool showInHistory; }; class InventoryHudSpec diff --git a/cl_dll/status_icons.cpp b/cl_dll/status_icons.cpp index d71c91ecfc..3b9b284fee 100644 --- a/cl_dll/status_icons.cpp +++ b/cl_dll/status_icons.cpp @@ -333,7 +333,7 @@ int CHudStatusIcons::MsgFunc_Inventory(const char *pszName, int iSize, void *pbu item.rc = gHUD.GetSpriteRect( spr_index ); m_iFlags |= HUD_ACTIVE; - if (countDiff >= 1) + if (countDiff >= 1 && (!itemSpec || itemSpec->showInHistory)) gHR.AddToHistory(HISTSLOT_ITEM, spriteName, countDiff, itemSpec ? itemSpec->packedColor : 0); return 1; diff --git a/game_shared/json_utils.cpp b/game_shared/json_utils.cpp index 320960939f..cf2c50e2e4 100644 --- a/game_shared/json_utils.cpp +++ b/game_shared/json_utils.cpp @@ -116,6 +116,17 @@ bool UpdatePropertyFromJson(float& f, Value& jsonValue, const char* key) return false; } +bool UpdatePropertyFromJson(bool& b, Value& jsonValue, const char* key) +{ + auto it = jsonValue.FindMember(key); + if (it != jsonValue.MemberEnd()) + { + b = it->value.GetBool(); + return true; + } + return false; +} + bool UpdatePropertyFromJson(Color& color, Value& jsonValue, const char* key) { auto it = jsonValue.FindMember(key); diff --git a/game_shared/json_utils.h b/game_shared/json_utils.h index a8a214b121..b41e059cae 100644 --- a/game_shared/json_utils.h +++ b/game_shared/json_utils.h @@ -12,6 +12,7 @@ bool ReadJsonDocumentWithSchema(rapidjson::Document& document, const char* pMemF bool UpdatePropertyFromJson(std::string& str, rapidjson::Value& jsonValue, const char* key); bool UpdatePropertyFromJson(int& i, rapidjson::Value& jsonValue, const char* key); bool UpdatePropertyFromJson(float& f, rapidjson::Value& jsonValue, const char* key); +bool UpdatePropertyFromJson(bool& b, rapidjson::Value& jsonValue, const char* key); bool UpdatePropertyFromJson(Color& color, rapidjson::Value& jsonValue, const char* key); bool UpdatePropertyFromJson(FloatRange& floatRange, rapidjson::Value& jsonValue, const char* key); bool UpdatePropertyFromJson(IntRange& intRange, rapidjson::Value& jsonValue, const char* key);