Skip to content

Commit

Permalink
allow overlay_background for map locations
Browse files Browse the repository at this point in the history
  • Loading branch information
black-sliver committed Jan 29, 2022
1 parent d6752ac commit 410c384
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 9 deletions.
1 change: 1 addition & 0 deletions doc/PACKS.md
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
16 changes: 10 additions & 6 deletions src/core/location.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,14 @@ bool LocationSection::Lua_NewIndex(lua_State *L, const char *key)
return false;
}

std::list<Location> Location::FromJSON(json& j, const std::list< std::list<std::string> >& parentAccessRules, const std::list< std::list<std::string> >& parentVisibilityRules, const std::string& parentName, const std::string& closedImgR, const std::string& openedImgR)
std::list<Location> Location::FromJSON(json& j, const std::list< std::list<std::string> >& parentAccessRules, const std::list< std::list<std::string> >& 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<Location> 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
}
}
Expand Down Expand Up @@ -111,7 +112,8 @@ std::list<Location> Location::FromJSON(json& j, const std::list< std::list<std::

std::string closedImg = to_string(j["chest_unopened_img"], closedImgR); // TODO: avoid copy
std::string openedImg = to_string(j["chest_opened_img"], openedImgR);

std::string overlayBackground = to_string(j["overlay_background"], overlayBackgroundR);

// TODO: if maplocation or sections in j, add locations to locs
if (j["sections"].type() == json::value_t::array)
{
Expand All @@ -135,7 +137,7 @@ std::list<Location> Location::FromJSON(json& j, const std::list< std::list<std::
fprintf(stderr, "Location: bad section\n");
continue;
}
loc._sections.push_back(LocationSection::FromJSON(v, accessRules, visibilityRules, closedImg, openedImg));
loc._sections.push_back(LocationSection::FromJSON(v, accessRules, visibilityRules, closedImg, openedImg, overlayBackground));
}
locs.push_back(loc);
}
Expand All @@ -147,7 +149,7 @@ std::list<Location> Location::FromJSON(json& j, const std::list< std::list<std::

if (j["children"].type() == json::value_t::array) {
std::string fullname = parentName.empty() ? name : (parentName + "/" + name);
for (auto& loc : Location::FromJSON(j["children"], accessRules, visibilityRules, fullname, closedImg, openedImg)) {
for (auto& loc : Location::FromJSON(j["children"], accessRules, visibilityRules, fullname, closedImg, openedImg, overlayBackground)) {
locs.push_back(std::move(loc));
}
} else if (j["children"].type() != json::value_t::null) {
Expand All @@ -168,13 +170,15 @@ Location::MapLocation Location::MapLocation::FromJSON(json& j)
}


LocationSection LocationSection::FromJSON(json& j, const std::list< std::list<std::string> >& parentAccessRules, const std::list< std::list<std::string> >& parentVisibilityRules, const std::string& closedImg, const std::string& openedImg)
LocationSection LocationSection::FromJSON(json& j, const std::list< std::list<std::string> >& parentAccessRules, const std::list< std::list<std::string> >& 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);
Expand Down
8 changes: 6 additions & 2 deletions src/core/location.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ class LocationSection final : public LuaInterface<LocationSection> {
static LocationSection FromJSON(nlohmann::json& j,
const std::list< std::list<std::string> >& parentAccessRules={},
const std::list< std::list<std::string> >& 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;
Expand All @@ -26,6 +27,7 @@ class LocationSection final : public LuaInterface<LocationSection> {
std::list<std::string> _hostedItems;
std::list< std::list<std::string> > _accessRules;
std::list< std::list<std::string> > _visibilityRules;
std::string _overlayBackground;
public:
// getters
const std::string& getName() const { return _name; }
Expand All @@ -39,6 +41,7 @@ class LocationSection final : public LuaInterface<LocationSection> {
const std::string& getClosedImage() const { return _closedImg; }
const std::string& getOpenedImage() const { return _openedImg; }
const std::list<std::string>& getHostedItems() const { return _hostedItems; }
const std::string& getOverlayBackground() const { return _overlayBackground; }

virtual nlohmann::json save() const;
virtual bool load(nlohmann::json& j);
Expand Down Expand Up @@ -69,7 +72,8 @@ class Location final {
static std::list<Location> FromJSON(nlohmann::json& j,
const std::list< std::list<std::string> >& parentAccessRules={},
const std::list< std::list<std::string> >& 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;
Expand Down
3 changes: 2 additions & 1 deletion src/ui/trackerview.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down

0 comments on commit 410c384

Please sign in to comment.