feat(ui): captura F9, tema a data/ui.yaml i retocs estètics

Captura de pantalla amb F9: volca el canvas ARGB a
screenshots/scr_<timestamp>.png via stb_image_write.

Tot el tema d'UI (colors, timings, fonts, flag hud.bg_enabled)
passa a data/ui.yaml via UiConfig; els valors de Defaults::UI
queden com a fallbacks si el fitxer falta o li manca alguna clau.

Retocs estètics: paleta "uzebox" per a la UI, strings del HUD
(P1/P2/V/T/PIRAMIDE/SALA) traduïts a locale, i fons del marcador
opcional amb backdrop continu de franja per evitar el trencament
visual durant el shake o l'animació d'entrada dels panells.
This commit is contained in:
JailDesigner committed 2026-04-24 10:58:02 +02:00
1 parent 82b229222f
commit dc8a7723e3
26 files changed
+2593 -210

No files matched your search

+29 -19
View File
@@ -5,12 +5,13 @@
#include <string>
#include "core/rendering/notifier.hpp"
#include "utils/defaults.hpp"
#include "core/ui/ui_config.hpp"
// Temes per a les notificacions de pantalla. Un "preset" captura els dos
// colors (text i fons, índexs sobre la paleta "ui") i el temps de visibilitat
// en mil·lisegons. Per a llançar una notificació amb un preset concret,
// cridar Notification::notify(text, preset); si s'omet, s'usa DEFAULT.
// en mil·lisegons. Els valors concrets viuen a data/ui.yaml (carregat per
// UiConfig); per llançar una notificació amb un preset concret, cridar
// Notification::notify(text, preset). Sense preset s'usa el DEFAULT.
namespace Notification {
struct Preset {
@@ -19,27 +20,36 @@ namespace Notification {
int time_ms;
};
// Tema per defecte: text clar sobre fons fosc. Els valors concrets
// viuen a `Defaults::UI` — tocar l'aparença global es fa allà.
constexpr Preset DEFAULT{
.text_color = Defaults::UI::NOTIFICATION_TEXT,
.bg_color = Defaults::UI::NOTIFICATION_BG,
.time_ms = Defaults::UI::NOTIFICATION_TIME_MS,
};
// Preset per defecte: text clar sobre fons fosc. Es construeix en cada
// crida a partir d'UiConfig perquè els valors no són constexpr: viuen a
// data/ui.yaml i es carreguen a l'arrencada.
[[nodiscard]] inline auto defaultPreset() -> Preset {
return {
.text_color = UiConfig::get().notificationText(),
.bg_color = UiConfig::get().notificationBg(),
.time_ms = UiConfig::get().notificationMs(),
};
}
// Preset per al missatge de confirmació d'eixida (ESC doble). Color
// d'accent per a distingir-lo d'una notificació informativa; la durada
// d'accent per distingir-lo d'una notificació informativa; la durada
// coincideix amb la finestra durant la qual la segona pulsació d'ESC
// confirma el tancament — veure GlobalInputs::onExit.
constexpr Preset EXIT{
.text_color = Defaults::UI::EXIT_TEXT,
.bg_color = Defaults::UI::EXIT_BG,
.time_ms = Defaults::UI::EXIT_TIME_MS,
};
[[nodiscard]] inline auto exitPreset() -> Preset {
return {
.text_color = UiConfig::get().exitText(),
.bg_color = UiConfig::get().exitBg(),
.time_ms = UiConfig::get().exitMs(),
};
}
// Helper de conveniència: aplica un preset (per defecte DEFAULT) cridant
// la API crua de Notifier. La direcció game → core és la correcta.
inline void notify(const std::string& text, const Preset& preset = DEFAULT) {
// Helper de conveniència: aplica un preset (per defecte el DEFAULT)
// cridant la API crua de Notifier. La direcció game → core és correcta.
inline void notify(const std::string& text) {
const auto P = defaultPreset();
Notifier::get().notify(text, P.text_color, P.bg_color, P.time_ms);
}
inline void notify(const std::string& text, const Preset& preset) {
Notifier::get().notify(text, preset.text_color, preset.bg_color, preset.time_ms);
}
+62
View File
@@ -0,0 +1,62 @@
#include "core/rendering/screenshot.hpp"
#include <chrono>
#include <cstdint>
#include <ctime>
#include <filesystem>
#include <string>
#include <vector>
#define STB_IMAGE_WRITE_IMPLEMENTATION
#include "external/stb_image_write.h"
namespace Screenshot {
namespace {
// Crea la carpeta `screenshots/` si no existeix i torna la ruta
// completa al fitxer. El paràmetre `filename` rep el nom nu (sense
// directori) per poder mostrar-lo a la notificació.
auto generateFilePath(std::string& filename) -> std::string {
std::filesystem::create_directories("screenshots");
const auto NOW = std::chrono::system_clock::now();
const std::time_t TIME = std::chrono::system_clock::to_time_t(NOW);
const std::tm* tm = std::localtime(&TIME);
char timestamp[20];
std::strftime(timestamp, sizeof(timestamp), "%Y%m%d_%H%M%S", tm);
filename = std::string("scr_") + timestamp + ".png";
return "screenshots/" + filename;
}
// Converteix ARGB8888 → RGBA8888 in-place i escriu el PNG. stb_image_write
// espera RGBA en ordre byte (little-endian: R al byte baix, A al byte alt).
auto writePng(std::uint32_t* buffer, int width, int height, const std::string& filepath) -> bool {
const int TOTAL = width * height;
for (int i = 0; i < TOTAL; ++i) {
const std::uint32_t P = buffer[i];
const std::uint32_t A = (P >> 24) & 0xFF;
const std::uint32_t R = (P >> 16) & 0xFF;
const std::uint32_t G = (P >> 8) & 0xFF;
const std::uint32_t B = P & 0xFF;
buffer[i] = R | (G << 8) | (B << 16) | (A << 24);
}
// NOLINTNEXTLINE(clang-analyzer-optin.portability.UnixAPI) — fals positiu dins de stb_image_write
return stbi_write_png(filepath.c_str(), width, height, 4, buffer, width * 4) != 0;
}
} // namespace
auto save(const std::uint32_t* buffer, int width, int height) -> std::string {
// Còpia local per no tocar el canvas original durant la conversió.
std::vector<std::uint32_t> copy(buffer, buffer + (static_cast<size_t>(width) * height));
std::string filename;
const std::string FILEPATH = generateFilePath(filename);
return writePng(copy.data(), width, height, FILEPATH) ? filename : "";
}
} // namespace Screenshot
+13
View File
@@ -0,0 +1,13 @@
#pragma once
#include <cstdint>
#include <string>
// Volca un buffer ARGB8888 a un fitxer PNG dins de la carpeta `screenshots/`
// (relativa al CWD). El nom es genera amb un timestamp i la funció retorna
// el nom del fitxer creat, o una cadena buida si l'escriptura ha fallat.
namespace Screenshot {
auto save(const std::uint32_t* buffer, int width, int height) -> std::string;
} // namespace Screenshot