colorins en la consola
This commit is contained in:
@@ -133,14 +133,23 @@ void Console::redrawText() {
|
||||
const float WIDTH = Options::game.width;
|
||||
constexpr int PADDING_IN_H = TEXT_SIZE;
|
||||
constexpr int PADDING_IN_V = TEXT_SIZE / 2;
|
||||
constexpr Uint8 TRANSPARENT_SENTINEL = 255; // Coincide con Surface::transparent_color_ por defecto
|
||||
|
||||
auto previous_renderer = Screen::get()->getRendererSurface();
|
||||
Screen::get()->setRendererSurface(surface_);
|
||||
|
||||
// Colores leídos de Options (modificables en caliente con el comando CONSOLE)
|
||||
const Uint8 BG_COLOR = Options::console.transparent
|
||||
? TRANSPARENT_SENTINEL
|
||||
: static_cast<Uint8>(Options::console.bg_color);
|
||||
const auto MSG_COLOR = static_cast<Uint8>(Options::console.msg_color);
|
||||
const auto PROMPT_COLOR = static_cast<Uint8>(Options::console.prompt_color);
|
||||
const auto COMMAND_COLOR = static_cast<Uint8>(Options::console.command_color);
|
||||
|
||||
// Fondo y borde
|
||||
surface_->clear(BG_COLOR);
|
||||
SDL_FRect rect = {.x = 0, .y = 0, .w = WIDTH, .h = height_};
|
||||
surface_->drawRectBorder(&rect, BORDER_COLOR);
|
||||
surface_->drawRectBorder(&rect, PROMPT_COLOR);
|
||||
|
||||
// La surface de la fuente tiene transparent_color_=255 por defecto,
|
||||
// pero sus píxeles de fondo son color 0. Cambiarlo temporalmente a 0
|
||||
@@ -160,10 +169,12 @@ void Console::redrawText() {
|
||||
y_pos += TEXT_SIZE;
|
||||
}
|
||||
|
||||
// Línea de input (siempre la última)
|
||||
// Línea de input (siempre la última): prompt en PROMPT_COLOR, comando + cursor en COMMAND_COLOR
|
||||
const bool SHOW_CURSOR = cursor_visible_ && (static_cast<int>(input_line_.size()) < MAX_LINE_CHARS);
|
||||
const std::string INPUT_STR = prompt_ + input_line_ + (SHOW_CURSOR ? "_" : "");
|
||||
text_->writeColored(PADDING_IN_H, y_pos, INPUT_STR, BORDER_COLOR);
|
||||
text_->writeColored(PADDING_IN_H, y_pos, prompt_, PROMPT_COLOR);
|
||||
const int PROMPT_PX = text_->length(prompt_);
|
||||
const std::string CMD_STR = input_line_ + (SHOW_CURSOR ? "_" : "");
|
||||
text_->writeColored(PADDING_IN_H + PROMPT_PX, y_pos, CMD_STR, COMMAND_COLOR);
|
||||
|
||||
// Restaurar transparent_color_ original de la fuente
|
||||
font_surface->setTransparentColor(PREV_TRANSPARENT);
|
||||
|
||||
@@ -54,9 +54,6 @@ class Console {
|
||||
};
|
||||
|
||||
// Constantes visuales
|
||||
static constexpr Uint8 BG_COLOR = 255; // Transparente (sin fondo)
|
||||
static constexpr Uint8 BORDER_COLOR = 9; // PaletteColor::BRIGHT_GREEN
|
||||
static constexpr Uint8 MSG_COLOR = 8; // PaletteColor::GREEN
|
||||
static constexpr float SLIDE_SPEED = 180.0F;
|
||||
|
||||
// Constantes de consola
|
||||
|
||||
@@ -951,6 +951,54 @@ static auto cmdSize(const std::vector<std::string>& /*unused*/) -> std::string {
|
||||
return std::to_string(w) + "x" + std::to_string(h);
|
||||
}
|
||||
|
||||
// CONSOLE [TRANSPARENT [ON|OFF]|BG|MSG|PROMPT|COMMAND <0-255>]
|
||||
static auto cmdConsole(const std::vector<std::string>& args) -> std::string { // NOLINT(readability-function-cognitive-complexity)
|
||||
if (args.empty()) {
|
||||
return std::string("Console ") + (Options::console.transparent ? "transparent" : "solid")
|
||||
+ " bg:" + std::to_string(Options::console.bg_color)
|
||||
+ " msg:" + std::to_string(Options::console.msg_color)
|
||||
+ " prompt:" + std::to_string(Options::console.prompt_color)
|
||||
+ " cmd:" + std::to_string(Options::console.command_color);
|
||||
}
|
||||
|
||||
if (args[0] == "TRANSPARENT") {
|
||||
if (args.size() < 2) {
|
||||
return std::string("Console ") + (Options::console.transparent ? "transparent" : "solid");
|
||||
}
|
||||
if (args[1] == "ON") {
|
||||
Options::console.transparent = true;
|
||||
return "Console transparent";
|
||||
}
|
||||
if (args[1] == "OFF") {
|
||||
Options::console.transparent = false;
|
||||
return "Console solid";
|
||||
}
|
||||
return "usage: console transparent [on|off]";
|
||||
}
|
||||
|
||||
// Helper para los cuatro comandos de color (BG, MSG, PROMPT, COMMAND)
|
||||
const auto SET_COLOR = [&args](int& target, const char* label) -> std::string {
|
||||
if (args.size() < 2) {
|
||||
return std::string("Console ") + label + ":" + std::to_string(target);
|
||||
}
|
||||
try {
|
||||
const int VAL = std::stoi(args[1]);
|
||||
if (VAL < 0 || VAL > 255) { return std::string(label) + " must be 0-255"; }
|
||||
target = VAL;
|
||||
return std::string("Console ") + label + ":" + std::to_string(VAL);
|
||||
} catch (...) {
|
||||
return std::string("usage: console ") + label + " <0-255>";
|
||||
}
|
||||
};
|
||||
|
||||
if (args[0] == "BG") { return SET_COLOR(Options::console.bg_color, "bg"); }
|
||||
if (args[0] == "MSG") { return SET_COLOR(Options::console.msg_color, "msg"); }
|
||||
if (args[0] == "PROMPT") { return SET_COLOR(Options::console.prompt_color, "prompt"); }
|
||||
if (args[0] == "COMMAND") { return SET_COLOR(Options::console.command_color, "command"); }
|
||||
|
||||
return "usage: console [transparent [on|off]|bg|msg|prompt|command <0-255>]";
|
||||
}
|
||||
|
||||
// ── CommandRegistry ──────────────────────────────────────────────────────────
|
||||
|
||||
void CommandRegistry::registerHandlers() { // NOLINT(readability-function-cognitive-complexity)
|
||||
@@ -974,6 +1022,7 @@ void CommandRegistry::registerHandlers() { // NOLINT(readability-function-cogni
|
||||
handlers_["cmd_exit"] = cmdExit;
|
||||
handlers_["cmd_quit"] = cmdExit; // QUIT usa el mismo handler que EXIT
|
||||
handlers_["cmd_size"] = cmdSize;
|
||||
handlers_["cmd_console"] = cmdConsole;
|
||||
#ifdef _DEBUG
|
||||
handlers_["cmd_debug"] = cmdDebug;
|
||||
handlers_["cmd_items"] = cmdItems;
|
||||
|
||||
Reference in New Issue
Block a user