diff --git a/assets/modern/art/environment-doctor.png b/assets/modern/art/environment-doctor.png new file mode 100644 index 0000000..760d3ba Binary files /dev/null and b/assets/modern/art/environment-doctor.png differ diff --git a/assets/modern/art/environment-people.png b/assets/modern/art/environment-people.png new file mode 100644 index 0000000..492bc0b Binary files /dev/null and b/assets/modern/art/environment-people.png differ diff --git a/assets/modern/art/gui-assets.json b/assets/modern/art/gui-assets.json new file mode 100644 index 0000000..8b29b6f --- /dev/null +++ b/assets/modern/art/gui-assets.json @@ -0,0 +1,66 @@ +{ + "schema": "openbmh-gui-assets@1", + "note": "The project's own pictures. A key named here is drawn from this folder, whatever a supplied picture pack says about it.", + "items": { + "environment.youth.0": { + "file": "environment-people.png", + "sha256": "644f491b9a19ac7f6ed1aeffde50b8fb55f4cc38a234b8674d84e8c5e1e4d957", + "crop": [ + 0.0055, + 0.0405, + 0.3223, + 0.231 + ] + }, + "environment.youth.1": { + "file": "environment-people.png", + "sha256": "644f491b9a19ac7f6ed1aeffde50b8fb55f4cc38a234b8674d84e8c5e1e4d957", + "crop": [ + 0.3389, + 0.0147, + 0.3223, + 0.231 + ] + }, + "environment.youth.2": { + "file": "environment-people.png", + "sha256": "644f491b9a19ac7f6ed1aeffde50b8fb55f4cc38a234b8674d84e8c5e1e4d957", + "crop": [ + 0.6722, + 0.0037, + 0.3223, + 0.231 + ] + }, + "environment.staff.0": { + "file": "environment-people.png", + "sha256": "644f491b9a19ac7f6ed1aeffde50b8fb55f4cc38a234b8674d84e8c5e1e4d957", + "crop": [ + 0.0055, + 0.5037, + 0.3223, + 0.231 + ] + }, + "environment.staff.1": { + "file": "environment-doctor.png", + "sha256": "4ac325814508a6dad9115451ce0ce6159372fbb932ef7c08dd5094dc7e555205", + "crop": [ + 0, + 0.0074, + 1, + 0.7168 + ] + }, + "environment.staff.2": { + "file": "environment-people.png", + "sha256": "644f491b9a19ac7f6ed1aeffde50b8fb55f4cc38a234b8674d84e8c5e1e4d957", + "crop": [ + 0.6722, + 0.5037, + 0.3223, + 0.231 + ] + } + } +} diff --git a/src/modern/ui/CMakeLists.txt b/src/modern/ui/CMakeLists.txt index 287bc75..d7094e2 100644 --- a/src/modern/ui/CMakeLists.txt +++ b/src/modern/ui/CMakeLists.txt @@ -69,6 +69,13 @@ foreach(icon ${modern_icons}) get_filename_component(icon_name "${icon}" NAME) configure_file("${icon}" "${modern_assets}/icons/${icon_name}" COPYONLY) endforeach() +# the project's own pictures with their catalogue +file(GLOB modern_art CONFIGURE_DEPENDS "${CMAKE_SOURCE_DIR}/assets/modern/art/*") +file(MAKE_DIRECTORY "${modern_assets}/art") +foreach(art ${modern_art}) + get_filename_component(art_name "${art}" NAME) + configure_file("${art}" "${modern_assets}/art/${art_name}" COPYONLY) +endforeach() # the display serif and the chalk hand (SIL Open Font License, THIRD_PARTY_NOTICES.md) file(GLOB modern_fonts CONFIGURE_DEPENDS "${CMAKE_SOURCE_DIR}/assets/modern/fonts/*") file(MAKE_DIRECTORY "${modern_assets}/fonts") diff --git a/src/modern/ui/environment_screens.inc b/src/modern/ui/environment_screens.inc index 8d14de4..eedfd16 100644 --- a/src/modern/ui/environment_screens.inc +++ b/src/modern/ui/environment_screens.inc @@ -19,7 +19,7 @@ std::string App::render_environment() { for (const auto &row : rows) total += row.at("cost").get(); page_title_ = "Umfeld – " + money(total, currency) + " pro Monat"; // a card is a third of the page wide; its picture takes the height that is left - const double card_width = (2799 - 2 * 31.5) / 3, picture_width = card_width - 2 * 36 - 4, picture_height = 396; + const double card_width = (2799 - 2 * 31.5) / 3, picture_width = card_width - 2 * 36 - 4, picture_height = 500; std::string out = "
"; for (size_t i = 0; i < rows.size(); ++i) { const auto &row = rows[i]; diff --git a/src/modern/ui/gui_assets.cpp b/src/modern/ui/gui_assets.cpp index 9ea469e..1ce9ee2 100644 --- a/src/modern/ui/gui_assets.cpp +++ b/src/modern/ui/gui_assets.cpp @@ -4,22 +4,30 @@ #include namespace bmh::modern_ui { -GuiAssets::GuiAssets(fs::path root) : root_(std::move(root)) { - if (root_.empty() || !fs::exists(root_ / "gui-assets.json")) - return; - root_ = fs::weakly_canonical(root_); - auto document = Json::parse(editor::read_file(root_ / "gui-assets.json")); +GuiAssets::GuiAssets(fs::path root, fs::path own) : root_(std::move(root)), own_root_(std::move(own)) { + if (!root_.empty() && fs::exists(root_ / "gui-assets.json")) { + root_ = fs::weakly_canonical(root_); + load(root_, false); + } + if (!own_root_.empty() && fs::exists(own_root_ / "gui-assets.json")) { + own_root_ = fs::weakly_canonical(own_root_); + load(own_root_, true); + } +} +void GuiAssets::load(const fs::path &folder, bool own) { + auto document = Json::parse(editor::read_file(folder / "gui-assets.json")); if (document.value("schema", "") != "openbmh-gui-assets@1" || !document.at("items").is_object()) throw editor::Error("invalid_gui_catalog"); - items_ = document.at("items"); - for (const auto &[key, item] : items_.items()) { + for (const auto &[key, item] : document.at("items").items()) { const auto relative = editor::path(item.at("file").get()); - const auto full = fs::weakly_canonical(root_ / relative); - const auto inside = full.lexically_relative(root_); + const auto full = fs::weakly_canonical(folder / relative); + const auto inside = full.lexically_relative(folder); if (relative.is_absolute() || inside.empty() || *inside.begin() == ".." || !fs::is_regular_file(full)) throw editor::Error("missing_or_unsafe_gui_asset", {{"key", key}}); + items_[key] = item; + if (own) own_.insert(key); } } editor::images::Raster GuiAssets::decode(const std::string &key, @@ -27,7 +35,7 @@ editor::images::Raster GuiAssets::decode(const std::string &key, if (!items_.contains(key)) throw editor::Error("missing_gui_asset", {{"key", key}}); const auto item = items_.at(key); - const auto file = root_ / editor::path(item.at("file").get()); + const auto file = (own_.contains(key) ? own_root_ : root_) / editor::path(item.at("file").get()); auto image = editor::images::decode(editor::read_file(file), file.extension().string(), pixels); if (!item.contains("crop")) diff --git a/src/modern/ui/gui_assets.hpp b/src/modern/ui/gui_assets.hpp index 2c33a65..d5ca209 100644 --- a/src/modern/ui/gui_assets.hpp +++ b/src/modern/ui/gui_assets.hpp @@ -2,19 +2,25 @@ #pragma once #include "editor/images.hpp" #include "modern/ui/catalog.hpp" +#include namespace bmh::modern_ui { class GuiAssets { public: - explicit GuiAssets(fs::path root = {}); - bool available() const { return !items_.empty(); } + // `own` is the folder of the project's own pictures; what its catalogue names comes from + // there, whatever the supplied catalogue under `root` says about the same key. + explicit GuiAssets(fs::path root = {}, fs::path own = {}); + // whether a picture pack was supplied; the own pictures alone do not make one + bool available() const { return items_.size() > own_.size(); } editor::images::Raster decode(const std::string &, int pixels = 1024) const; bool contains(const std::string &key) const { return items_.contains(key); } const Json &items() const { return items_; } const fs::path &root() const { return root_; } private: - fs::path root_; + void load(const fs::path &folder, bool own); + fs::path root_, own_root_; Json items_ = Json::object(); + std::set own_; // the keys that come from the project's own pictures }; } // namespace bmh::modern_ui diff --git a/src/modern/ui/view.cpp b/src/modern/ui/view.cpp index 4e8d43b..819d066 100644 --- a/src/modern/ui/view.cpp +++ b/src/modern/ui/view.cpp @@ -1526,7 +1526,7 @@ public: gui_root_(config.gui_assets.empty() ? assets_ / "gui" : config.gui_assets), migrate_(std::move(migrate)), config_(std::move(config)), - gui_(gui_root_), + gui_(gui_root_, assets_ / "art"), video_("Dreierpack Manager", config_.width, config_.height, 960, 540), system_(video_.window), renderer_(video_, gui_, assets_) { try {