From 2ce75a8ebf6a422b7bcffc02a8cf6c57323b409d Mon Sep 17 00:00:00 2001 From: black-sliver <59490463+black-sliver@users.noreply.github.com> Date: Fri, 29 Dec 2023 18:05:21 +0100 Subject: [PATCH] allow image mods for overlay image mod "img_mods" = "overlay|path/to/file|@disabled" --- doc/PACKS.md | 3 ++- src/ui/trackerview.cpp | 24 +++++++++++++++++++----- src/uilib/imagefilter.cpp | 16 ++++++++++++---- src/uilib/imagefilter.h | 25 +++++++++++++++++++------ 4 files changed, 52 insertions(+), 16 deletions(-) diff --git a/doc/PACKS.md b/doc/PACKS.md index 24631a5c..b3020c1c 100644 --- a/doc/PACKS.md +++ b/doc/PACKS.md @@ -231,7 +231,8 @@ a table representing an enum with the following constants: \ + img_mods filter to be applied on the img - `@disabled`: grey-scale - - `overlay|path/to/img.png`: draw a second image over it + - `overlay|path/to/img.png|overlay_filters...`: draw a second image over it; overlay_filters are applied to overlay (since 0.25.6) + - NOTE: order matters, applied left to right + inherit_codes: true will make stage3 provide codes for item, stage1, 2 and 3 (default true) * `"toggle"`: diff --git a/src/ui/trackerview.cpp b/src/ui/trackerview.cpp index 7cb1135f..411e8e3f 100644 --- a/src/ui/trackerview.cpp +++ b/src/ui/trackerview.cpp @@ -15,6 +15,8 @@ #include "maptooltip.h" #include "mapwidget.h" #include "defaults.h" // DEFAULT_FONT_* +#include +#include namespace Ui { @@ -25,23 +27,35 @@ std::list imageModsToFilters(Tracker* tracker, const std::list filters; for (auto& mod: mods) { - std::string name, arg; + std::string name; + std::vector args; size_t p = mod.find('|'); if (p == mod.npos) name = mod; else { name = mod.substr(0,p); - arg = mod.substr(p+1); + while (true) { + auto q = mod.find('|', p+1); + if (q == mod.npos) { + args.push_back(mod.substr(p+1)); + break; + } + args.push_back(mod.substr(p+1, q-p-1)); + p = q; + } } if (name == "overlay") { // read actual image data into arg instead of filename - std::string tmp = std::move(arg); - tracker->getPack()->ReadFile(tmp, arg); + std::string tmp = std::move(args[0]); + tracker->getPack()->ReadFile(tmp, args[0]); + for (size_t i=1; i +#include #include namespace Ui { struct ImageFilter { - ImageFilter(std::string name) { this->name=name; } - ImageFilter(std::string name, std::string arg) { this->name=name; this->arg=arg; } - + ImageFilter(std::string name) + : name(name) + { + } + + ImageFilter(std::string name, std::string arg) + : name(name), args({arg}) + { + } + + ImageFilter(std::string name, std::vector& args) + : name(name), args(args) + { + } + std::string name; - std::string arg; + std::vector args; - SDL_Surface* apply(SDL_Surface *surf); + SDL_Surface* apply(SDL_Surface *surf) const; bool operator==(const ImageFilter& rhs) const { - return name == rhs.name && arg == rhs.arg; + return name == rhs.name && args == rhs.args; } };