refactor(defaults): centralitza constants de bullet, ship, enemy, hud i notifier
This commit is contained in:
@@ -2,24 +2,15 @@
|
||||
|
||||
#include "core/system/notifier.hpp"
|
||||
|
||||
#include "core/defaults.hpp"
|
||||
#include "core/rendering/gpu/gpu_frame_renderer.hpp"
|
||||
#include "core/utils/easing.hpp"
|
||||
|
||||
namespace System {
|
||||
|
||||
namespace {
|
||||
// Geometria del cuadre en coordenades lògiques (1280×720).
|
||||
constexpr float CANVAS_WIDTH = 1280.0F;
|
||||
constexpr float MARGIN_TOP = 40.0F;
|
||||
constexpr float PADDING_H = 16.0F;
|
||||
constexpr float PADDING_V = 10.0F;
|
||||
constexpr float BORDER_THICKNESS = 2.0F;
|
||||
constexpr float TEXT_SCALE = 0.55F;
|
||||
constexpr float TEXT_SPACING = 2.0F;
|
||||
constexpr float BORDER_BRIGHTNESS = 1.0F;
|
||||
|
||||
// Cinemàtica del slide.
|
||||
constexpr float SLIDE_DURATION_S = 0.30F;
|
||||
// Alias d'àmbit local per accedir compactament als defaults del notifier.
|
||||
namespace Cfg = Defaults::Notifier;
|
||||
|
||||
// Conversió color SDL → float [0,1].
|
||||
constexpr auto toUnit(Uint8 v) -> float {
|
||||
@@ -47,14 +38,6 @@ namespace System {
|
||||
.b = toUnit(c.b) * DARKEN,
|
||||
.a = BG_ALPHA};
|
||||
}
|
||||
|
||||
// Presets per als atajos semàntics.
|
||||
constexpr SDL_Color COLOR_INFO{.r = 80, .g = 230, .b = 255, .a = 255};
|
||||
constexpr SDL_Color COLOR_WARN{.r = 255, .g = 180, .b = 40, .a = 255};
|
||||
constexpr SDL_Color COLOR_EXIT{.r = 255, .g = 80, .b = 80, .a = 255};
|
||||
constexpr float DURATION_INFO = 2.0F;
|
||||
constexpr float DURATION_WARN = 3.0F;
|
||||
constexpr float DURATION_EXIT = 3.0F;
|
||||
} // namespace
|
||||
|
||||
std::unique_ptr<Notifier> Notifier::instance;
|
||||
@@ -79,15 +62,15 @@ namespace System {
|
||||
hold_remaining_s_ = duration_s;
|
||||
current_is_exit_ = false;
|
||||
|
||||
const float TEXT_W = Graphics::VectorText::getTextWidth(text, TEXT_SCALE, TEXT_SPACING);
|
||||
const float TEXT_H = Graphics::VectorText::getTextHeight(TEXT_SCALE);
|
||||
const float TEXT_W = Graphics::VectorText::getTextWidth(text, Cfg::TEXT_SCALE, Cfg::TEXT_SPACING);
|
||||
const float TEXT_H = Graphics::VectorText::getTextHeight(Cfg::TEXT_SCALE);
|
||||
|
||||
box_w_ = TEXT_W + (PADDING_H * 2.0F);
|
||||
box_h_ = TEXT_H + (PADDING_V * 2.0F);
|
||||
text_x_ = (CANVAS_WIDTH - TEXT_W) * 0.5F;
|
||||
box_w_ = TEXT_W + (Cfg::PADDING_H * 2.0F);
|
||||
box_h_ = TEXT_H + (Cfg::PADDING_V * 2.0F);
|
||||
text_x_ = (Cfg::CANVAS_WIDTH - TEXT_W) * 0.5F;
|
||||
|
||||
y_on_ = MARGIN_TOP;
|
||||
y_off_ = -(box_h_ + BORDER_THICKNESS);
|
||||
y_on_ = Cfg::MARGIN_TOP;
|
||||
y_off_ = -(box_h_ + Cfg::BORDER_THICKNESS);
|
||||
|
||||
// Si ja es veu, reseteja el slide-in des de la posició actual perquè
|
||||
// la transició sembli continua. Si està amagat, arrenc des de fora.
|
||||
@@ -96,13 +79,13 @@ namespace System {
|
||||
}
|
||||
status_ = Status::ENTERING;
|
||||
slide_elapsed_s_ = 0.0F;
|
||||
text_scale_ = TEXT_SCALE;
|
||||
text_scale_ = Cfg::TEXT_SCALE;
|
||||
}
|
||||
|
||||
void Notifier::notifyInfo(const std::string& text) { notify(text, COLOR_INFO, DURATION_INFO); }
|
||||
void Notifier::notifyWarn(const std::string& text) { notify(text, COLOR_WARN, DURATION_WARN); }
|
||||
void Notifier::notifyInfo(const std::string& text) { notify(text, Cfg::COLOR_INFO, Cfg::DURATION_INFO); }
|
||||
void Notifier::notifyWarn(const std::string& text) { notify(text, Cfg::COLOR_WARN, Cfg::DURATION_WARN); }
|
||||
void Notifier::notifyExit(const std::string& text) {
|
||||
notify(text, COLOR_EXIT, DURATION_EXIT);
|
||||
notify(text, Cfg::COLOR_EXIT, Cfg::DURATION_EXIT);
|
||||
current_is_exit_ = true; // notify() ho ha posat a false; restaurem.
|
||||
}
|
||||
|
||||
@@ -110,12 +93,12 @@ namespace System {
|
||||
switch (status_) {
|
||||
case Status::ENTERING: {
|
||||
slide_elapsed_s_ += delta_time;
|
||||
if (slide_elapsed_s_ >= SLIDE_DURATION_S) {
|
||||
if (slide_elapsed_s_ >= Cfg::SLIDE_DURATION_S) {
|
||||
y_current_ = y_on_;
|
||||
status_ = Status::HOLDING;
|
||||
slide_elapsed_s_ = 0.0F;
|
||||
} else {
|
||||
const float T = slide_elapsed_s_ / SLIDE_DURATION_S;
|
||||
const float T = slide_elapsed_s_ / Cfg::SLIDE_DURATION_S;
|
||||
const float K = Utils::Easing::outCubic(T);
|
||||
y_current_ = y_off_ + ((y_on_ - y_off_) * K);
|
||||
}
|
||||
@@ -131,11 +114,11 @@ namespace System {
|
||||
}
|
||||
case Status::EXITING: {
|
||||
slide_elapsed_s_ += delta_time;
|
||||
if (slide_elapsed_s_ >= SLIDE_DURATION_S) {
|
||||
if (slide_elapsed_s_ >= Cfg::SLIDE_DURATION_S) {
|
||||
y_current_ = y_off_;
|
||||
status_ = Status::HIDDEN;
|
||||
} else {
|
||||
const float T = slide_elapsed_s_ / SLIDE_DURATION_S;
|
||||
const float T = slide_elapsed_s_ / Cfg::SLIDE_DURATION_S;
|
||||
const float K = Utils::Easing::inCubic(T);
|
||||
y_current_ = y_on_ + ((y_off_ - y_on_) * K);
|
||||
}
|
||||
@@ -152,7 +135,7 @@ namespace System {
|
||||
return;
|
||||
}
|
||||
|
||||
const float BOX_X = (CANVAS_WIDTH - box_w_) * 0.5F;
|
||||
const float BOX_X = (Cfg::CANVAS_WIDTH - box_w_) * 0.5F;
|
||||
const float BOX_Y = y_current_;
|
||||
const UnitRGBA TC = textColorFloat(current_color_);
|
||||
const UnitRGBA BG = bgColorFloat(current_color_);
|
||||
@@ -167,19 +150,19 @@ namespace System {
|
||||
const float Y1 = BOX_Y;
|
||||
const float X2 = BOX_X + box_w_;
|
||||
const float Y2 = BOX_Y + box_h_;
|
||||
gpu->pushLine(X1, Y1, X2, Y1, BORDER_THICKNESS, TC.r, TC.g, TC.b, TC.a); // top
|
||||
gpu->pushLine(X1, Y2, X2, Y2, BORDER_THICKNESS, TC.r, TC.g, TC.b, TC.a); // bottom
|
||||
gpu->pushLine(X1, Y1, X1, Y2, BORDER_THICKNESS, TC.r, TC.g, TC.b, TC.a); // left
|
||||
gpu->pushLine(X2, Y1, X2, Y2, BORDER_THICKNESS, TC.r, TC.g, TC.b, TC.a); // right
|
||||
gpu->pushLine(X1, Y1, X2, Y1, Cfg::BORDER_THICKNESS, TC.r, TC.g, TC.b, TC.a); // top
|
||||
gpu->pushLine(X1, Y2, X2, Y2, Cfg::BORDER_THICKNESS, TC.r, TC.g, TC.b, TC.a); // bottom
|
||||
gpu->pushLine(X1, Y1, X1, Y2, Cfg::BORDER_THICKNESS, TC.r, TC.g, TC.b, TC.a); // left
|
||||
gpu->pushLine(X2, Y1, X2, Y2, Cfg::BORDER_THICKNESS, TC.r, TC.g, TC.b, TC.a); // right
|
||||
|
||||
// 3. Text centrat dins la caixa, amb color explícit (l'alpha != 0
|
||||
// li diu al renderShape que no agafe l'oscil·lador global de color).
|
||||
const float TEXT_Y = BOX_Y + PADDING_V;
|
||||
const float TEXT_Y = BOX_Y + Cfg::PADDING_V;
|
||||
text_.render(current_text_,
|
||||
Vec2{.x = text_x_, .y = TEXT_Y},
|
||||
text_scale_,
|
||||
TEXT_SPACING,
|
||||
BORDER_BRIGHTNESS,
|
||||
Cfg::TEXT_SPACING,
|
||||
Cfg::BORDER_BRIGHTNESS,
|
||||
current_color_);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user