From 410c384df9f6ed24b56c4cc253a2d0ab05bcc15a Mon Sep 17 00:00:00 2001 From: black-sliver <59490463+black-sliver@users.noreply.github.com> Date: Sat, 29 Jan 2022 16:41:07 +0100 Subject: [PATCH] allow overlay_background for map locations --- doc/PACKS.md | 1 + src/core/location.cpp | 16 ++++++++++------ src/core/location.h | 8 ++++++-- src/ui/trackerview.cpp | 3 ++- 4 files changed, 19 insertions(+), 9 deletions(-) diff --git a/doc/PACKS.md b/doc/PACKS.md index bd682238..d6277db7 100644 --- a/doc/PACKS.md +++ b/doc/PACKS.md @@ -272,6 +272,7 @@ Locations define drops on maps, rules to have them accessible as well as the loo ], "chest_unopened_img": "path/to/chest.png", // default if children do not override "chest_opened_img": "path/to/chest.png", + "overlay_background": "#000000", // set background for number of unopened chests "children": [ { "name": "Location or check name", diff --git a/src/core/location.cpp b/src/core/location.cpp index 2681eb68..eaa48ec0 100644 --- a/src/core/location.cpp +++ b/src/core/location.cpp @@ -36,13 +36,14 @@ bool LocationSection::Lua_NewIndex(lua_State *L, const char *key) return false; } -std::list Location::FromJSON(json& j, const std::list< std::list >& parentAccessRules, const std::list< std::list >& parentVisibilityRules, const std::string& parentName, const std::string& closedImgR, const std::string& openedImgR) +std::list Location::FromJSON(json& j, const std::list< std::list >& parentAccessRules, const std::list< std::list >& parentVisibilityRules, const std::string& parentName, const std::string& closedImgR, const std::string& openedImgR, const std::string& overlayBackgroundR) { + // TODO: pass inherited values as parent instead std::list locs; if (j.type() == json::value_t::array) { for (auto& v : j) { - for (auto& loc : FromJSON(v, parentAccessRules, parentVisibilityRules, parentName, closedImgR, openedImgR)) { + for (auto& loc : FromJSON(v, parentAccessRules, parentVisibilityRules, parentName, closedImgR, openedImgR, overlayBackgroundR)) { locs.push_back(std::move(loc)); // TODO: move constructor } } @@ -111,7 +112,8 @@ std::list Location::FromJSON(json& j, const std::list< std::list Location::FromJSON(json& j, const std::list< std::list Location::FromJSON(json& j, const std::list< std::list >& parentAccessRules, const std::list< std::list >& parentVisibilityRules, const std::string& closedImg, const std::string& openedImg) +LocationSection LocationSection::FromJSON(json& j, const std::list< std::list >& parentAccessRules, const std::list< std::list >& parentVisibilityRules, const std::string& closedImg, const std::string& openedImg, const std::string& overlayBackground) { + // TODO: pass inherited values as parent instead LocationSection sec; sec._name = to_string(j["name"],sec._name); sec._clearAsGroup = to_bool(j["clear_as_group"],sec._clearAsGroup); sec._closedImg = to_string(j["chest_unopened_img"], closedImg); sec._openedImg = to_string(j["chest_opened_img"], openedImg); + sec._overlayBackground = to_string(j["overlay_background"], overlayBackground); sec._itemCount = to_int(j["item_count"], sec._itemCount); auto tmp = to_string(j["hosted_item"], ""); commasplit(tmp, sec._hostedItems); diff --git a/src/core/location.h b/src/core/location.h index b814c86b..8ea9faa7 100644 --- a/src/core/location.h +++ b/src/core/location.h @@ -14,7 +14,8 @@ class LocationSection final : public LuaInterface { static LocationSection FromJSON(nlohmann::json& j, const std::list< std::list >& parentAccessRules={}, const std::list< std::list >& parentVisibilityRules={}, - const std::string& closedImg="", const std::string& openedImg=""); + const std::string& closedImg="", const std::string& openedImg="", + const std::string& overlayBackground=""); Signal<> onChange; protected: std::string _name; @@ -26,6 +27,7 @@ class LocationSection final : public LuaInterface { std::list _hostedItems; std::list< std::list > _accessRules; std::list< std::list > _visibilityRules; + std::string _overlayBackground; public: // getters const std::string& getName() const { return _name; } @@ -39,6 +41,7 @@ class LocationSection final : public LuaInterface { const std::string& getClosedImage() const { return _closedImg; } const std::string& getOpenedImage() const { return _openedImg; } const std::list& getHostedItems() const { return _hostedItems; } + const std::string& getOverlayBackground() const { return _overlayBackground; } virtual nlohmann::json save() const; virtual bool load(nlohmann::json& j); @@ -69,7 +72,8 @@ class Location final { static std::list FromJSON(nlohmann::json& j, const std::list< std::list >& parentAccessRules={}, const std::list< std::list >& parentVisibilityRules={}, - const std::string& parentName="", const std::string& closedImg="", const std::string& openedImg=""); + const std::string& parentName="", const std::string& closedImg="", + const std::string& openedImg="", const std::string& overlayBackground=""); protected: std::string _name; diff --git a/src/ui/trackerview.cpp b/src/ui/trackerview.cpp index 56a3fa12..d587e65f 100644 --- a/src/ui/trackerview.cpp +++ b/src/ui/trackerview.cpp @@ -177,7 +177,8 @@ Item* TrackerView::makeLocationIcon(int x, int y, int width, int height, const s w->addStage(1,0, sOpened.c_str(), sOpened.length()); // TODO: +img_mods w->setStage(opened?1:0,0); w->setMinSize(w->getSize()); // FIXME: this is a dirty work-around - + w->setOverlayBackgroundColor(sec.getOverlayBackground()); + if (compact) { int itemcount = sec.getItemCount(); int looted = sec.getItemCleared();