feat(title): primera passada — fons casi negre, títol+ARCADE i prompt START intermitent (configurable a ui.yaml)
This commit is contained in:
1 parent
5710568af8
commit
dadbee9bad
9 files changed
+135
-31
No files matched your search
@@ -39,6 +39,10 @@ hud:
|
||||
pyramid: "Piramide"
|
||||
room: "Sala"
|
||||
|
||||
# Textos de l'escena TITLE.
|
||||
title:
|
||||
press_start: "Polsa START per a començar"
|
||||
|
||||
# Textos de la transició d'entrada/sortida de sala (FSM de GameScene).
|
||||
# Tant l'INTRO com l'OUTRO es renderitzen com a dues línies separades
|
||||
# (cadascuna amb la seua animació). L'INTRO accepta els placeholders
|
||||
|
||||
@@ -39,6 +39,10 @@ hud:
|
||||
pyramid: "Pyramid"
|
||||
room: "Room"
|
||||
|
||||
# Texts of the TITLE scene.
|
||||
title:
|
||||
press_start: "Press START to begin"
|
||||
|
||||
# Room transition texts (GameScene FSM intro/outro). Both INTRO and
|
||||
# OUTRO render as two independent lines with their own animation.
|
||||
# INTRO uses `{p}` (pyramid) and `{r}` (room) placeholders; OUTRO has
|
||||
|
||||
@@ -98,3 +98,17 @@ pause:
|
||||
sounds:
|
||||
menu_select: "menu_select.wav"
|
||||
menu_accept: "menu_accept.wav"
|
||||
|
||||
# Escena TITLE (placeholder visual mentre no hi haja artwork).
|
||||
# `bg_color` i `text_color` són índexs sobre la paleta "ui" (uzebox.pal):
|
||||
# 1 = (36,0,0) gairebé negre amb un mínim de càlid; 31 = (255,109,0)
|
||||
# taronja pur. `duration_ms` és el timeout abans de saltar a la
|
||||
# següent escena (skipable amb tecla no reservada). Els dos
|
||||
# `blink_*_ms` defineixen el cicle del prompt "press start": el text
|
||||
# es veu durant `visible_ms` i s'amaga durant `hidden_ms` repetint-se.
|
||||
title:
|
||||
duration_ms: 30000
|
||||
bg_color: 1
|
||||
text_color: 31
|
||||
blink_visible_ms: 800
|
||||
blink_hidden_ms: 200
|
||||
@@ -251,8 +251,8 @@ Director::Director() {
|
||||
auto make_intro = [placeholder_text, make_game]() -> std::unique_ptr<Scene> {
|
||||
return std::make_unique<IntroScene>(placeholder_text, make_game);
|
||||
};
|
||||
auto make_title = [placeholder_text, make_intro]() -> std::unique_ptr<Scene> {
|
||||
return std::make_unique<TitleScene>(placeholder_text, make_intro);
|
||||
auto make_title = [menu_title_text, placeholder_text, make_intro]() -> std::unique_ptr<Scene> {
|
||||
return std::make_unique<TitleScene>(menu_title_text, placeholder_text, make_intro);
|
||||
};
|
||||
|
||||
switch (START) {
|
||||
|
||||
@@ -96,6 +96,11 @@ UiConfig::UiConfig()
|
||||
pause_exit_ms_(Defaults::UI::PAUSE_EXIT_MS),
|
||||
pause_enter_curve_(curveByName(Defaults::UI::PAUSE_ENTER_CURVE)),
|
||||
pause_exit_curve_(curveByName(Defaults::UI::PAUSE_EXIT_CURVE)),
|
||||
title_duration_ms_(Defaults::UI::Title::DURATION_MS),
|
||||
title_bg_color_(Defaults::UI::Title::BG_COLOR),
|
||||
title_text_color_(Defaults::UI::Title::TEXT_COLOR),
|
||||
title_blink_visible_ms_(Defaults::UI::Title::BLINK_VISIBLE_MS),
|
||||
title_blink_hidden_ms_(Defaults::UI::Title::BLINK_HIDDEN_MS),
|
||||
menu_select_sound_(Defaults::UI::MENU_SELECT_SOUND),
|
||||
menu_accept_sound_(Defaults::UI::MENU_ACCEPT_SOUND),
|
||||
hud_font_{.name = Defaults::UI::Font::HUD_NAME, .gif = Defaults::UI::Font::HUD_GIF, .fnt = Defaults::UI::Font::HUD_FNT, .kerning = Defaults::UI::Font::HUD_KERNING},
|
||||
@@ -204,6 +209,15 @@ void UiConfig::load(const std::string& file_path) {
|
||||
readField(s, "menu_accept", menu_accept_sound_);
|
||||
}
|
||||
|
||||
if (yaml.contains("title")) {
|
||||
const auto& t = yaml["title"];
|
||||
readField(t, "duration_ms", title_duration_ms_);
|
||||
readColorIndex(t, "bg_color", title_bg_color_);
|
||||
readColorIndex(t, "text_color", title_text_color_);
|
||||
readField(t, "blink_visible_ms", title_blink_visible_ms_);
|
||||
readField(t, "blink_hidden_ms", title_blink_hidden_ms_);
|
||||
}
|
||||
|
||||
if (yaml.contains("notifier")) {
|
||||
const auto& n = yaml["notifier"];
|
||||
readField(n, "padding_h", notifier_.padding_h);
|
||||
|
||||
@@ -81,6 +81,13 @@ class UiConfig {
|
||||
[[nodiscard]] auto pauseEnterMs() const -> int { return pause_enter_ms_; }
|
||||
[[nodiscard]] auto pauseExitMs() const -> int { return pause_exit_ms_; }
|
||||
|
||||
// Escena TITLE (placeholder visual fins que tinguem artwork).
|
||||
[[nodiscard]] auto titleDurationMs() const -> int { return title_duration_ms_; }
|
||||
[[nodiscard]] auto titleBgColor() const -> Uint8 { return title_bg_color_; }
|
||||
[[nodiscard]] auto titleTextColor() const -> Uint8 { return title_text_color_; }
|
||||
[[nodiscard]] auto titleBlinkVisibleMs() const -> int { return title_blink_visible_ms_; }
|
||||
[[nodiscard]] auto titleBlinkHiddenMs() const -> int { return title_blink_hidden_ms_; }
|
||||
|
||||
// Corbes d'easing triades al YAML. Si el nom no és conegut, s'usa
|
||||
// Easing::linear com a fallback.
|
||||
[[nodiscard]] auto pauseEnterCurve() const -> CurveFn { return pause_enter_curve_; }
|
||||
@@ -145,6 +152,12 @@ class UiConfig {
|
||||
CurveFn pause_enter_curve_;
|
||||
CurveFn pause_exit_curve_;
|
||||
|
||||
int title_duration_ms_;
|
||||
Uint8 title_bg_color_;
|
||||
Uint8 title_text_color_;
|
||||
int title_blink_visible_ms_;
|
||||
int title_blink_hidden_ms_;
|
||||
|
||||
std::string menu_select_sound_;
|
||||
std::string menu_accept_sound_;
|
||||
|
||||
|
||||
@@ -9,30 +9,47 @@
|
||||
#include <utility>
|
||||
|
||||
#include "core/input/global_inputs.hpp"
|
||||
#include "core/locale/locale.hpp"
|
||||
#include "core/rendering/notifier.hpp"
|
||||
#include "core/rendering/render_info.hpp"
|
||||
#include "core/rendering/screen.hpp"
|
||||
#include "core/rendering/text.hpp"
|
||||
#include "core/resources/resource_cache.hpp"
|
||||
#include "core/system/event_buffer.hpp"
|
||||
#include "core/ui/ui_config.hpp"
|
||||
#include "game/options.hpp"
|
||||
#include "game/scenes/placeholder_input.hpp"
|
||||
#include "utils/defaults.hpp"
|
||||
#include "utils/defines.hpp"
|
||||
|
||||
namespace {
|
||||
|
||||
constexpr int NAME_Y_OFFSET = -8;
|
||||
constexpr int TIMER_Y_OFFSET = 8;
|
||||
// TODO: migrar a un logger unificat quan es decideixi (veure INC-03 a
|
||||
// docs/audit-core-rendering.md).
|
||||
const char* const SCENE_NAME = "TITLE";
|
||||
|
||||
// Textos hardcodejats fins que tinguem artwork. Quan apareguen com
|
||||
// a sprites, aquesta secció desapareix sencera.
|
||||
const char* const TITLE_LINE_1 = "Aventures en Egipte";
|
||||
const char* const TITLE_LINE_2 = "A R C A D E";
|
||||
|
||||
constexpr int TITLE_Y_PERCENT = 25;
|
||||
constexpr int PROMPT_Y_PERCENT = 60;
|
||||
|
||||
// Separació vertical entre la primera i segona línia del títol. Una
|
||||
// alçada de línia és l'opció més llegible al canvas de 240 px sense
|
||||
// entrar a configuració extra; si demà cal afinar-ho, mou-se a
|
||||
// ui.yaml.
|
||||
[[nodiscard]] auto titleLineGap(const Text& font) -> int {
|
||||
return font.getLineHeight();
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
TitleScene::TitleScene(std::shared_ptr<Text> font, SceneFactory next_factory)
|
||||
: font_(std::move(font)),
|
||||
next_factory_(std::move(next_factory)) {
|
||||
TitleScene::TitleScene(std::shared_ptr<Text> display_font, std::shared_ptr<Text> condensed_font, SceneFactory next_factory)
|
||||
: display_font_(std::move(display_font)),
|
||||
condensed_font_(std::move(condensed_font)),
|
||||
next_factory_(std::move(next_factory)),
|
||||
timer_ms_(UiConfig::get().titleDurationMs()) {
|
||||
std::cout << "[scene] " << SCENE_NAME << " start\n";
|
||||
}
|
||||
|
||||
@@ -46,6 +63,7 @@ void TitleScene::update(int delta_ms) {
|
||||
}
|
||||
|
||||
timer_ms_ -= delta_ms;
|
||||
blink_elapsed_ms_ += delta_ms;
|
||||
|
||||
const bool SKIPPED = std::ranges::any_of(EventBuffer::events, [](const SDL_Event& ev) {
|
||||
return ev.type == SDL_EVENT_KEY_DOWN && !Placeholder::isReservedScancode(ev.key.scancode);
|
||||
@@ -60,23 +78,46 @@ void TitleScene::update(int delta_ms) {
|
||||
}
|
||||
|
||||
void TitleScene::render() {
|
||||
constexpr std::uint32_t BLACK_ARGB = 0xFF000000U;
|
||||
Screen::get().fillRect(0, 0, GameCanvas::WIDTH, GameCanvas::HEIGHT, BLACK_ARGB);
|
||||
const auto& ui_config = UiConfig::get();
|
||||
const auto& palette = Resource::Cache::get().getPalette("ui");
|
||||
|
||||
if (font_) {
|
||||
const int SECS_LEFT = std::max(1, (timer_ms_ + 999) / 1000);
|
||||
font_->writeDX(Text::CENTER_FLAG | Text::COLOR_FLAG,
|
||||
Screen::get().fillRect(0, 0, GameCanvas::WIDTH, GameCanvas::HEIGHT, palette[ui_config.titleBgColor()]);
|
||||
|
||||
const Uint8 TEXT_COLOR = ui_config.titleTextColor();
|
||||
|
||||
if (display_font_) {
|
||||
const int TITLE_Y = (GameCanvas::HEIGHT * TITLE_Y_PERCENT) / 100;
|
||||
display_font_->writeDX(Text::CENTER_FLAG | Text::COLOR_FLAG,
|
||||
GameCanvas::CENTER_X,
|
||||
GameCanvas::CENTER_Y + NAME_Y_OFFSET,
|
||||
SCENE_NAME,
|
||||
1,
|
||||
UiConfig::get().notificationText());
|
||||
font_->writeDX(Text::CENTER_FLAG | Text::COLOR_FLAG,
|
||||
TITLE_Y,
|
||||
TITLE_LINE_1,
|
||||
display_font_->getDefaultKerning(),
|
||||
TEXT_COLOR);
|
||||
display_font_->writeDX(Text::CENTER_FLAG | Text::COLOR_FLAG,
|
||||
GameCanvas::CENTER_X,
|
||||
GameCanvas::CENTER_Y + TIMER_Y_OFFSET,
|
||||
std::to_string(SECS_LEFT),
|
||||
1,
|
||||
UiConfig::get().notificationText());
|
||||
TITLE_Y + titleLineGap(*display_font_),
|
||||
TITLE_LINE_2,
|
||||
display_font_->getDefaultKerning(),
|
||||
TEXT_COLOR);
|
||||
}
|
||||
|
||||
if (condensed_font_) {
|
||||
// Cicle de parpadeig: visible_ms ON + hidden_ms OFF, repetint-se.
|
||||
// Si la suma val 0 (configuració degenerada), cau a "sempre visible".
|
||||
const int VISIBLE_MS = std::max(0, ui_config.titleBlinkVisibleMs());
|
||||
const int HIDDEN_MS = std::max(0, ui_config.titleBlinkHiddenMs());
|
||||
const int CYCLE_MS = VISIBLE_MS + HIDDEN_MS;
|
||||
const bool VISIBLE = (CYCLE_MS == 0) || ((blink_elapsed_ms_ % CYCLE_MS) < VISIBLE_MS);
|
||||
|
||||
if (VISIBLE) {
|
||||
const int PROMPT_Y = (GameCanvas::HEIGHT * PROMPT_Y_PERCENT) / 100;
|
||||
condensed_font_->writeDX(Text::CENTER_FLAG | Text::COLOR_FLAG,
|
||||
GameCanvas::CENTER_X,
|
||||
PROMPT_Y,
|
||||
Locale::get().text("title.press_start"),
|
||||
condensed_font_->getDefaultKerning() - 1,
|
||||
TEXT_COLOR);
|
||||
}
|
||||
}
|
||||
|
||||
Notifier::get().render();
|
||||
|
||||
@@ -7,24 +7,24 @@
|
||||
|
||||
class Text;
|
||||
|
||||
// Escena placeholder del títol. Mateix comportament que LogoScene — duració
|
||||
// fixa de 5 s i skip amb tecla no reservada —, però classe separada perquè
|
||||
// quan divergeixi en contingut real (menú, seleccions, animacions) creixi en
|
||||
// el seu propi fitxer sense haver de refactoritzar cap base comuna.
|
||||
// Escena TITLE provisional. Pinta dos blocs de text sobre un fons gairebé
|
||||
// negre i un prompt "press start" intermitent fins que apareix l'artwork
|
||||
// real. Tota la cosmètica (colors, durada, ritme del parpadeig) viu a
|
||||
// data/ui.yaml secció `title:` per poder afinar-la sense recompilar.
|
||||
class TitleScene : public Scene {
|
||||
public:
|
||||
using SceneFactory = std::function<std::unique_ptr<Scene>()>;
|
||||
|
||||
static constexpr int DURATION_MS = 5000;
|
||||
|
||||
TitleScene(std::shared_ptr<Text> font, SceneFactory next_factory);
|
||||
TitleScene(std::shared_ptr<Text> display_font, std::shared_ptr<Text> condensed_font, SceneFactory next_factory);
|
||||
~TitleScene() override;
|
||||
|
||||
void update(int delta_ms) override;
|
||||
void render() override;
|
||||
|
||||
private:
|
||||
std::shared_ptr<Text> font_;
|
||||
std::shared_ptr<Text> display_font_;
|
||||
std::shared_ptr<Text> condensed_font_;
|
||||
SceneFactory next_factory_;
|
||||
int timer_ms_{DURATION_MS};
|
||||
int timer_ms_;
|
||||
int blink_elapsed_ms_{0};
|
||||
};
|
||||
@@ -244,6 +244,20 @@ namespace Defaults {
|
||||
// Els fitxers viuen a `data/sounds/`; només es referencia el nom.
|
||||
constexpr const char* MENU_SELECT_SOUND = "menu_select.wav";
|
||||
constexpr const char* MENU_ACCEPT_SOUND = "menu_accept.wav";
|
||||
|
||||
// Escena TITLE (provisional fins que tinguem artwork). Colors
|
||||
// referits a la paleta "ui" (uzebox.pal): BG_COLOR és el to més
|
||||
// proper al negre sense ser-ho (índex 1 = 36,0,0); TEXT_COLOR és
|
||||
// el taronja més pur de la paleta (índex 31 = 255,109,0). Els
|
||||
// ms del cicle de parpadeig sumen el cicle complet del prompt
|
||||
// "press start" — 80% visible / 20% ocult per defecte.
|
||||
namespace Title {
|
||||
constexpr int DURATION_MS = 30000;
|
||||
constexpr Uint8 BG_COLOR = 1;
|
||||
constexpr Uint8 TEXT_COLOR = 31;
|
||||
constexpr int BLINK_VISIBLE_MS = 800;
|
||||
constexpr int BLINK_HIDDEN_MS = 200;
|
||||
} // namespace Title
|
||||
} // namespace UI
|
||||
|
||||
#ifdef _DEBUG
|
||||
|
||||
Reference in new issue
Block a user