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
@@ -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};
|
||||
};
|
||||
Reference in new issue
Block a user