notificacions: paleta semàntica pastel centralitzada amb outline derivat
This commit is contained in:
@@ -4,9 +4,9 @@
|
||||
|
||||
#include "core/input/input.h"
|
||||
#include "core/locale/lang.h"
|
||||
#include "core/rendering/notifications.hpp"
|
||||
#include "core/rendering/screen.h"
|
||||
#include "game/options.hpp"
|
||||
#include "utils/utils.h"
|
||||
|
||||
namespace GlobalInputs {
|
||||
|
||||
@@ -19,15 +19,6 @@ namespace GlobalInputs {
|
||||
constexpr int LANG_PRESET = 100;
|
||||
constexpr int LANG_EXIT_CONFIRM = 101;
|
||||
|
||||
constexpr Uint32 NOTIFY_MS = 1500;
|
||||
constexpr Uint32 EXIT_CONFIRM_MS = 2000;
|
||||
const Color BLACK = {0x00, 0x00, 0x00};
|
||||
const Color CYAN = {0x00, 0xFF, 0xFF};
|
||||
const Color YELLOW = {0xFF, 0xE0, 0x40};
|
||||
const Color MAGENTA = {0xFF, 0x00, 0xFF};
|
||||
const Color GREEN = {0x00, 0xFF, 0x80};
|
||||
const Color RED = {0xFF, 0x40, 0x40};
|
||||
|
||||
// Patró de doble pulsació: la primera pulsació d'EXIT mostra una
|
||||
// notificació en vermell i obre una finestra de confirmació; una
|
||||
// segona pulsació dins la finestra activa `quit_requested`. La
|
||||
@@ -38,29 +29,29 @@ namespace GlobalInputs {
|
||||
|
||||
void notifyZoom() {
|
||||
const std::string MSG = Lang::get()->getText(LANG_ZOOM) + " " + std::to_string(Options::window.zoom) + "x";
|
||||
Screen::get()->notify(MSG, YELLOW, BLACK, NOTIFY_MS);
|
||||
Notifications::show(MSG, Notifications::Palette::INFO, Notifications::STANDARD_MS);
|
||||
}
|
||||
|
||||
void notifyFullscreen() {
|
||||
const int IDX = Options::video.fullscreen ? LANG_FULLSCREEN : LANG_WINDOW;
|
||||
Screen::get()->notify(Lang::get()->getText(IDX), YELLOW, BLACK, NOTIFY_MS);
|
||||
Notifications::show(Lang::get()->getText(IDX), Notifications::Palette::INFO, Notifications::STANDARD_MS);
|
||||
}
|
||||
|
||||
void notifyShaderEnabled() {
|
||||
const std::string STATE = Screen::isShaderEnabled() ? "ON" : "OFF";
|
||||
const std::string MSG = Lang::get()->getText(LANG_SHADER) + " " + STATE;
|
||||
Screen::get()->notify(MSG, CYAN, BLACK, NOTIFY_MS);
|
||||
Notifications::show(MSG, Notifications::Palette::TOGGLE, Notifications::STANDARD_MS);
|
||||
}
|
||||
|
||||
void notifyShaderType() {
|
||||
const bool IS_CRTPI = Options::video.shader.current_shader == Rendering::ShaderType::CRTPI;
|
||||
const std::string MSG = Lang::get()->getText(LANG_SHADER) + " " + (IS_CRTPI ? "CRTPI" : "POSTFX");
|
||||
Screen::get()->notify(MSG, MAGENTA, BLACK, NOTIFY_MS);
|
||||
Notifications::show(MSG, Notifications::Palette::CHOICE, Notifications::STANDARD_MS);
|
||||
}
|
||||
|
||||
void notifyPreset() {
|
||||
const std::string MSG = Lang::get()->getText(LANG_PRESET) + " " + Screen::get()->getCurrentPresetName();
|
||||
Screen::get()->notify(MSG, GREEN, BLACK, NOTIFY_MS);
|
||||
Notifications::show(MSG, Notifications::Palette::SUCCESS, Notifications::STANDARD_MS);
|
||||
}
|
||||
|
||||
void onExit() {
|
||||
@@ -69,8 +60,8 @@ namespace GlobalInputs {
|
||||
quit_requested = true;
|
||||
return;
|
||||
}
|
||||
exit_window_until_ticks = NOW + EXIT_CONFIRM_MS;
|
||||
Screen::get()->notify(Lang::get()->getText(LANG_EXIT_CONFIRM), RED, BLACK, EXIT_CONFIRM_MS);
|
||||
exit_window_until_ticks = NOW + Notifications::CONFIRM_MS;
|
||||
Notifications::show(Lang::get()->getText(LANG_EXIT_CONFIRM), Notifications::Palette::DANGER, Notifications::CONFIRM_MS);
|
||||
}
|
||||
} // namespace
|
||||
|
||||
|
||||
@@ -0,0 +1,54 @@
|
||||
#include "core/rendering/notifications.hpp"
|
||||
|
||||
#include "core/rendering/screen.h"
|
||||
#include "utils/utils.h"
|
||||
|
||||
namespace Notifications {
|
||||
|
||||
namespace {
|
||||
// Paleta pastel. Per a tunejar l'aparença només cal tocar aquí.
|
||||
// (Color no és literal type ⇒ const, no constexpr.)
|
||||
const Color INFO_COLOR{0xF0, 0xE0, 0x90}; // groc trigo
|
||||
const Color TOGGLE_COLOR{0xA0, 0xE0, 0xF0}; // cian gel
|
||||
const Color CHOICE_COLOR{0xE0, 0xA0, 0xE0}; // rosa orquídia
|
||||
const Color SUCCESS_COLOR{0xB0, 0xE6, 0xB0}; // verd menta
|
||||
const Color DANGER_COLOR{0xF0, 0xA0, 0xA0}; // rosa salmó
|
||||
|
||||
// Factor de foscor per a l'outline (~40% de la lluminositat del
|
||||
// color base): manté el matís i queda prou fosc per a contrastar
|
||||
// amb el text pastel sobre el fons del joc.
|
||||
constexpr float OUTLINE_FACTOR = 0.40F;
|
||||
|
||||
auto baseColor(Palette p) -> Color {
|
||||
switch (p) {
|
||||
case Palette::INFO:
|
||||
return INFO_COLOR;
|
||||
case Palette::TOGGLE:
|
||||
return TOGGLE_COLOR;
|
||||
case Palette::CHOICE:
|
||||
return CHOICE_COLOR;
|
||||
case Palette::SUCCESS:
|
||||
return SUCCESS_COLOR;
|
||||
case Palette::DANGER:
|
||||
return DANGER_COLOR;
|
||||
}
|
||||
return INFO_COLOR;
|
||||
}
|
||||
|
||||
auto darken(Color c, float factor) -> Color {
|
||||
return Color{
|
||||
static_cast<Uint8>(static_cast<float>(c.r) * factor),
|
||||
static_cast<Uint8>(static_cast<float>(c.g) * factor),
|
||||
static_cast<Uint8>(static_cast<float>(c.b) * factor),
|
||||
};
|
||||
}
|
||||
} // namespace
|
||||
|
||||
void show(const std::string &text, Palette palette, Uint32 duration_ms) {
|
||||
if (Screen::get() == nullptr) { return; }
|
||||
const Color BASE = baseColor(palette);
|
||||
const Color OUTLINE = darken(BASE, OUTLINE_FACTOR);
|
||||
Screen::get()->notify(text, BASE, OUTLINE, duration_ms);
|
||||
}
|
||||
|
||||
} // namespace Notifications
|
||||
@@ -0,0 +1,32 @@
|
||||
#pragma once
|
||||
|
||||
#include <SDL3/SDL.h>
|
||||
|
||||
#include <cstdint>
|
||||
#include <string>
|
||||
|
||||
// Notificacions overlay centralitzades. Cada call site tria una entrada de
|
||||
// la `Palette` semàntica i una durada; el color base (pastel) i el seu
|
||||
// outline (versió fosca derivada) viuen en un sol lloc — `notifications.cpp`.
|
||||
//
|
||||
// Per a tunejar l'estètica només cal editar les constants del .cpp.
|
||||
|
||||
namespace Notifications {
|
||||
|
||||
enum class Palette : std::uint8_t {
|
||||
INFO, // pastel groc — zoom, finestra/fullscreen
|
||||
TOGGLE, // pastel cian — activacions on/off (shader)
|
||||
CHOICE, // pastel magenta — selecció entre opcions (tipus shader)
|
||||
SUCCESS, // pastel verd — acceptat / connectat (preset, mando added)
|
||||
DANGER, // pastel roig — confirmacions perilloses / desconnexions
|
||||
};
|
||||
|
||||
constexpr Uint32 STANDARD_MS = 1500; // Hotkeys "normals"
|
||||
constexpr Uint32 CONFIRM_MS = 2000; // Doble pulsació d'ESC
|
||||
constexpr Uint32 LONG_MS = 2500; // Esdeveniments rellevants (mando)
|
||||
|
||||
// Mostra una notificació. L'outline es deriva automàticament del color
|
||||
// base com a versió fosca (~25% de lluminositat).
|
||||
void show(const std::string &text, Palette palette, Uint32 duration_ms);
|
||||
|
||||
} // namespace Notifications
|
||||
@@ -16,14 +16,15 @@
|
||||
#include <memory>
|
||||
#include <string> // for basic_string, operator+, char_t...
|
||||
|
||||
#include "core/audio/audio.hpp" // for Audio::init, Audio::destroy
|
||||
#include "core/input/global_inputs.hpp" // for GlobalInputs::wantsQuit
|
||||
#include "core/input/input.h" // for Input, InputAction
|
||||
#include "core/input/mouse.hpp" // for Mouse::handleEvent, Mouse::upda...
|
||||
#include "core/locale/lang.h" // for Lang, Lang::Code
|
||||
#include "core/rendering/screen.h" // for Screen
|
||||
#include "core/rendering/texture.h" // for Texture
|
||||
#include "core/resources/asset.h" // for Asset, Asset::Type
|
||||
#include "core/audio/audio.hpp" // for Audio::init, Audio::destroy
|
||||
#include "core/input/global_inputs.hpp" // for GlobalInputs::wantsQuit
|
||||
#include "core/input/input.h" // for Input, InputAction
|
||||
#include "core/input/mouse.hpp" // for Mouse::handleEvent, Mouse::upda...
|
||||
#include "core/locale/lang.h" // for Lang, Lang::Code
|
||||
#include "core/rendering/notifications.hpp" // for Notifications::show
|
||||
#include "core/rendering/screen.h" // for Screen
|
||||
#include "core/rendering/texture.h" // for Texture
|
||||
#include "core/resources/asset.h" // for Asset, Asset::Type
|
||||
#include "core/resources/resource.h"
|
||||
#include "core/resources/resource_helper.h"
|
||||
#include "game/defaults.hpp" // for SECTION_PROG_LOGO, GAMECANVAS_H...
|
||||
@@ -642,18 +643,16 @@ auto Director::handleEvent(SDL_Event *event) -> SDL_AppResult {
|
||||
if (event->type == SDL_EVENT_GAMEPAD_ADDED) {
|
||||
std::string name;
|
||||
if (Input::get()->handleGamepadAdded(event->gdevice.which, name)) {
|
||||
Screen::get()->notify(name + " " + Lang::get()->getText(94),
|
||||
Color{0x40, 0xFF, 0x40},
|
||||
Color{0, 0, 0},
|
||||
2500);
|
||||
Notifications::show(name + " " + Lang::get()->getText(94),
|
||||
Notifications::Palette::SUCCESS,
|
||||
Notifications::LONG_MS);
|
||||
}
|
||||
} else if (event->type == SDL_EVENT_GAMEPAD_REMOVED) {
|
||||
std::string name;
|
||||
if (Input::get()->handleGamepadRemoved(event->gdevice.which, name)) {
|
||||
Screen::get()->notify(name + " " + Lang::get()->getText(95),
|
||||
Color{0xFF, 0x50, 0x50},
|
||||
Color{0, 0, 0},
|
||||
2500);
|
||||
Notifications::show(name + " " + Lang::get()->getText(95),
|
||||
Notifications::Palette::DANGER,
|
||||
Notifications::LONG_MS);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user