eliminades locales no utilitzades

modificats textos de ui a case tipo frase
notificacions llargues pasen a multilinea
This commit is contained in:
2026-04-17 10:11:31 +02:00
parent 5eb178b039
commit 8a44ab15e7
4 changed files with 118 additions and 184 deletions

View File

@@ -211,10 +211,10 @@ void Game::handleEvents() {
if (event.type == SDL_EVENT_KEY_DOWN && event.key.key == KeyConfig::get()->key("EDITOR", "toggle") && static_cast<int>(event.key.repeat) == 0) {
if (MapEditor::get()->isActive()) {
GameControl::exit_editor();
Notifier::get()->show({Locale::get()->get("game.editor_disabled")});
Notifier::get()->show({Locale::get()->get("ui.editor_disabled")});
} else {
GameControl::enter_editor();
Notifier::get()->show({Locale::get()->get("game.editor_enabled")});
Notifier::get()->show({Locale::get()->get("ui.editor_enabled")});
}
} else if (event.type == SDL_EVENT_KEY_DOWN && event.key.key == KeyConfig::get()->key("EDITOR", "grid") && static_cast<int>(event.key.repeat) == 0 && MapEditor::get()->isActive()) {
MapEditor::get()->showGrid(!MapEditor::get()->isGridEnabled());
@@ -236,7 +236,7 @@ void Game::handleInput() {
if (Input::get()->checkAction(InputAction::TOGGLE_IN_GAME_MUSIC, Input::DO_NOT_ALLOW_REPEAT)) {
scoreboard_data_->music = !scoreboard_data_->music;
scoreboard_data_->music ? Audio::get()->resumeMusic() : Audio::get()->pauseMusic();
Notifier::get()->show({scoreboard_data_->music ? Locale::get()->get("game.music_enabled") : Locale::get()->get("game.music_disabled")});
Notifier::get()->show({scoreboard_data_->music ? Locale::get()->get("ui.music_enabled") : Locale::get()->get("ui.music_disabled")});
}
// Si la consola está activa, no procesar inputs del juego
@@ -262,7 +262,7 @@ void Game::handleInput() {
// Input de pausa solo en estado PLAYING
if (Input::get()->checkAction(InputAction::PAUSE, Input::DO_NOT_ALLOW_REPEAT)) {
togglePause();
Notifier::get()->show({paused_ ? Locale::get()->get("game.paused") : Locale::get()->get("game.running")});
Notifier::get()->show({paused_ ? Locale::get()->get("ui.paused") : Locale::get()->get("ui.running")});
}
GlobalInputs::handle();
@@ -612,7 +612,7 @@ void Game::renderPostFadeEnding() {
static void toggleCheat(Options::Cheat::State& cheat, const std::string& label) {
cheat = (cheat == Options::Cheat::State::ENABLED) ? Options::Cheat::State::DISABLED : Options::Cheat::State::ENABLED;
const bool ENABLED = (cheat == Options::Cheat::State::ENABLED);
Notifier::get()->show({label + (ENABLED ? Locale::get()->get("game.enabled") : Locale::get()->get("game.disabled"))}, Notifier::Style::DEFAULT, -1, true);
Notifier::get()->show({label + (ENABLED ? Locale::get()->get("ui.enabled") : Locale::get()->get("ui.disabled"))}, Notifier::Style::DEFAULT, -1, true);
}
// Pone la información de debug en pantalla
@@ -655,9 +655,9 @@ void Game::handleDebugEvents(const SDL_Event& event) {
} else if (KEY == kc->key("DEBUG", "nav_right")) {
changeRoom(room_->getRoom(Room::Border::RIGHT));
} else if (KEY == kc->key("DEBUG", "infinite_lives")) {
toggleCheat(Options::cheats.infinite_lives, Locale::get()->get("game.cheat_infinite_lives"));
toggleCheat(Options::cheats.infinite_lives, Locale::get()->get("ui.cheat_infinite_lives"));
} else if (KEY == kc->key("DEBUG", "invincibility")) {
toggleCheat(Options::cheats.invincible, Locale::get()->get("game.cheat_invincible"));
toggleCheat(Options::cheats.invincible, Locale::get()->get("ui.cheat_invincible"));
} else if (KEY == kc->key("DEBUG", "test_cheevo")) {
Notifier::get()->show({Locale::get()->get("achievements.header"), Locale::get()->get("achievements.c11")}, Notifier::Style::CHEEVO, -1, false, "F7");
} else if (KEY == kc->key("DEBUG", "debug_mode")) {
@@ -666,7 +666,7 @@ void Game::handleDebugEvents(const SDL_Event& event) {
invincible_before_debug_ = (Options::cheats.invincible == Options::Cheat::State::ENABLED);
}
Debug::get()->toggleEnabled();
Notifier::get()->show({Debug::get()->isEnabled() ? Locale::get()->get("game.debug_enabled") : Locale::get()->get("game.debug_disabled")});
Notifier::get()->show({Debug::get()->isEnabled() ? Locale::get()->get("ui.debug_enabled") : Locale::get()->get("ui.debug_disabled")});
room_->redrawMap();
if (Debug::get()->isEnabled()) {
Options::cheats.invincible = Options::Cheat::State::ENABLED;

View File

@@ -22,6 +22,41 @@
// [SINGLETON]
Notifier* Notifier::notifier = nullptr;
// Parte un texto en varias líneas cuando no cabe en max_width píxeles.
// Divide por espacios; si una palabra sola excede el ancho, queda en su propia línea.
static auto wrapToWidth(const std::string& text, int max_width, Text* text_obj, int kerning = 1) -> std::vector<std::string> {
if (max_width <= 0 || text_obj->length(text, kerning) <= max_width) {
return {text};
}
std::vector<std::string> lines;
std::string current;
std::string word;
auto flush_word = [&]() {
if (word.empty()) { return; }
const std::string CANDIDATE = current.empty() ? word : current + " " + word;
if (text_obj->length(CANDIDATE, kerning) <= max_width) {
current = CANDIDATE;
} else {
if (!current.empty()) { lines.push_back(current); }
current = word;
}
word.clear();
};
for (const char c : text) {
if (c == ' ') {
flush_word();
} else {
word += c;
}
}
flush_word();
if (!current.empty()) { lines.push_back(current); }
return lines;
}
// Definición de estilos predefinidos
const Notifier::Style Notifier::Style::DEFAULT = {
.bg_color = Defaults::Notification::BG_COLOR,
@@ -149,14 +184,6 @@ void Notifier::show(std::vector<std::string> texts, const Style& style, int icon
auto result = std::ranges::remove_if(texts, [](const std::string& s) -> bool { return s.empty(); });
texts.erase(result.begin(), result.end());
// Encuentra la cadena más larga
std::string longest;
for (const auto& text : texts) {
if (text.length() > longest.length()) {
longest = text;
}
}
// Inicializa variables
constexpr float TEXT_SIZE = LINE_HEIGHT;
const auto PADDING_IN_H = TEXT_SIZE;
@@ -164,6 +191,17 @@ void Notifier::show(std::vector<std::string> texts, const Style& style, int icon
const int ICON_SPACE = icon >= 0 ? ICON_SIZE + PADDING_IN_H : 0;
const TextAlign TEXT_IS = ICON_SPACE > 0 ? TextAlign::LEFT : style.text_align;
const float WIDTH = Options::game.width - (PADDING_OUT * 2);
const int MAX_TEXT_WIDTH = static_cast<int>(WIDTH - (PADDING_IN_H * 2) - ICON_SPACE);
// Si un texto no cabe en una línea, parte por espacios en varias líneas
std::vector<std::string> wrapped;
wrapped.reserve(texts.size());
for (const auto& t : texts) {
auto lines = wrapToWidth(t, MAX_TEXT_WIDTH, text_.get());
wrapped.insert(wrapped.end(), std::make_move_iterator(lines.begin()), std::make_move_iterator(lines.end()));
}
texts = std::move(wrapped);
const float HEIGHT = (TEXT_SIZE * texts.size()) + (PADDING_IN_V * 2);
const auto SHAPE = style.shape;