screen torna llista de paletes i permet canviar a una paleta pel nom

console 2.1 por canviar de paleta pel nom
This commit is contained in:
2026-03-30 23:03:21 +02:00
parent 8dcf473f31
commit 1817d00881
4 changed files with 90 additions and 45 deletions

View File

@@ -482,6 +482,33 @@ auto Screen::findPalette(const std::string& name) -> size_t { // NOLINT(readabi
return static_cast<size_t>(0);
}
// Cambia a una paleta por nombre (case-insensitive); devuelve false si no existe
bool Screen::setPaletteByName(const std::string& name) {
const std::string upper_name = toUpper(name + ".pal");
for (size_t i = 0; i < palettes_.size(); ++i) {
if (toUpper(getFileName(palettes_[i])) == upper_name) {
current_palette_ = static_cast<Uint8>(i);
setPalete();
return true;
}
}
return false;
}
// Devuelve los nombres de paletas disponibles (mayúsculas, sin extensión .pal)
auto Screen::getPaletteNames() const -> std::vector<std::string> {
std::vector<std::string> names;
names.reserve(palettes_.size());
for (const auto& p : palettes_) {
std::string name = p;
const size_t pos = name.find(".pal");
if (pos != std::string::npos) { name.erase(pos, 4); }
std::ranges::transform(name, name.begin(), ::toupper);
names.push_back(std::move(name));
}
return names;
}
// Limpia la game_surface_
void Screen::clearSurface(Uint8 index) { game_surface_->clear(index); }

View File

@@ -55,6 +55,8 @@ class Screen {
void nextPalette(); // Cambia a la siguiente paleta
void previousPalette(); // Cambia a la paleta anterior
void setPalete(); // Establece la paleta actual
bool setPaletteByName(const std::string& name); // Cambia a paleta por nombre; false si no existe
[[nodiscard]] auto getPaletteNames() const -> std::vector<std::string>; // Nombres disponibles (mayúsculas, sin .pal)
void toggleShaders(); // Activa/desactiva todos los shaders respetando current_shader
void toggleSupersampling(); // Activa/desactiva el supersampling global
void reloadPostFX(); // Recarga el shader del preset actual sin toggle

View File

@@ -369,9 +369,9 @@ static const std::vector<ConsoleCommand> COMMANDS = {
return "Driver: " + driver_lower + " (restart)";
}},
// PALETTE NEXT/PREV — Paleta de colores (F5/F6)
// PALETTE NEXT/PREV/<nombre> — Paleta de colores (F5/F6 o por nombre)
{.keyword = "PALETTE", .execute = [](const std::vector<std::string>& args) -> std::string {
if (args.empty()) { return "usage: palette [next|prev]"; }
if (args.empty()) { return "usage: palette [next|prev|<name>]"; }
if (args[0] == "NEXT") {
Screen::get()->nextPalette();
return "Palette: " + Options::video.palette;
@@ -380,7 +380,10 @@ static const std::vector<ConsoleCommand> COMMANDS = {
Screen::get()->previousPalette();
return "Palette: " + Options::video.palette;
}
return "usage: palette [next|prev]";
if (!Screen::get()->setPaletteByName(args[0])) {
return "Unknown palette: " + args[0];
}
return "Palette: " + Options::video.palette;
}},
#ifdef _DEBUG
@@ -1160,7 +1163,6 @@ void Console::handleEvent(const SDL_Event& event) {
{"INTSCALE", {"ON", "OFF"}},
{"VSYNC", {"ON", "OFF"}},
{"DRIVER", {"LIST", "AUTO", "NONE"}},
{"PALETTE", {"NEXT", "PREV"}},
{"AUDIO", {"ON", "OFF", "VOL"}},
{"MUSIC", {"ON", "OFF", "VOL"}},
{"SOUND", {"ON", "OFF", "VOL"}},
@@ -1180,6 +1182,19 @@ void Console::handleEvent(const SDL_Event& event) {
};
const std::string base_cmd = upper.substr(0, space_pos);
const std::string sub_prefix = upper.substr(space_pos + 1);
if (base_cmd == "PALETTE" && Screen::get() != nullptr) {
// NEXT/PREV primero, luego todos los nombres de paleta disponibles
for (const auto sv : {"NEXT", "PREV"}) {
if (sub_prefix.empty() || std::string_view{sv}.starts_with(sub_prefix)) {
tab_matches_.emplace_back("PALETTE " + std::string(sv));
}
}
for (const auto& name : Screen::get()->getPaletteNames()) {
if (sub_prefix.empty() || std::string_view{name}.starts_with(sub_prefix)) {
tab_matches_.emplace_back("PALETTE " + name);
}
}
} else {
for (const auto& [keyword, args] : SUB_ARGS) {
if (keyword == base_cmd) {
for (const auto& arg : args) {
@@ -1191,6 +1206,7 @@ void Console::handleEvent(const SDL_Event& event) {
}
}
}
}
tab_index_ = -1;
}
if (tab_matches_.empty()) { break; }

View File

@@ -6,7 +6,7 @@
namespace Texts {
constexpr const char* WINDOW_CAPTION = "© 2022 JailDoctor's Dilemma — JailDesigner";
constexpr const char* COPYRIGHT = "@2022 JailDesigner";
constexpr const char* VERSION = "1.10"; // Versión por defecto
constexpr const char* VERSION = "1.11"; // Versión por defecto
} // namespace Texts
// Tamaño de bloque