Skip to content

Commit

Permalink
Add show_in_history property for hud inventory items
Browse files Browse the repository at this point in the history
  • Loading branch information
FreeSlave committed Jun 5, 2024
1 parent bdb76cd commit b8c4650
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 2 deletions.
6 changes: 5 additions & 1 deletion cl_dll/hud_inventory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,9 @@ const char hudInventorySchema[] = R"(
"position": {
"type": "string",
"pattern": "^topleft|status|bottom|topright|hide$"
},
"show_in_history": {
"type": "boolean"
}
}
}
Expand All @@ -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';
Expand Down Expand Up @@ -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())
{
Expand Down
1 change: 1 addition & 0 deletions cl_dll/hud_inventory.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ struct InventoryItemHudSpec
int alpha;
int position;
bool colorDefined;
bool showInHistory;
};

class InventoryHudSpec
Expand Down
2 changes: 1 addition & 1 deletion cl_dll/status_icons.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
11 changes: 11 additions & 0 deletions game_shared/json_utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
1 change: 1 addition & 0 deletions game_shared/json_utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit b8c4650

Please sign in to comment.