Service Menu: afegides opcions per als mandos

This commit is contained in:
2025-08-05 13:12:48 +02:00
parent 12e3226f17
commit 3bb5e5d604
7 changed files with 89 additions and 4 deletions

View File

@@ -138,6 +138,15 @@ auto Input::gameControllerFound() const -> bool { return !gamepads_.empty(); }
// Obten el nombre de un mando de juego
auto Input::getControllerName(std::shared_ptr<Gamepad> gamepad) const -> std::string { return gamepad == nullptr ? std::string() : gamepad->name; }
// Obtiene la lista de nombres de mandos
auto Input::getControllerNames() const -> std::vector<std::string> {
std::vector<std::string> names;
for (const auto &gamepad : gamepads_) {
names.push_back(gamepad->name);
}
return names;
}
// Obten el número de mandos conectados
auto Input::getNumGamepads() const -> int { return gamepads_.size(); }
@@ -151,6 +160,15 @@ std::shared_ptr<Input::Gamepad> Input::getGamepad(SDL_JoystickID id) const {
return nullptr;
}
std::shared_ptr<Input::Gamepad> Input::getGamepadByName(const std::string &name) const {
for (const auto &gamepad : gamepads_) {
if (gamepad && gamepad->name == name) {
return gamepad;
}
}
return nullptr;
}
// Obtiene el SDL_GamepadButton asignado a un input
auto Input::getControllerBinding(std::shared_ptr<Gamepad> gamepad, Action input) const -> SDL_GamepadButton {
return gamepad->bindings[input].button;

View File

@@ -153,8 +153,10 @@ class Input {
// --- Métodos de gestión de mandos ---
[[nodiscard]] auto gameControllerFound() const -> bool;
auto getControllerName(std::shared_ptr<Gamepad> gamepad) const -> std::string;
auto getControllerNames() const -> std::vector<std::string>;
[[nodiscard]] auto getNumGamepads() const -> int;
std::shared_ptr<Gamepad> getGamepad(SDL_JoystickID id) const;
std::shared_ptr<Input::Gamepad> getGamepadByName(const std::string &name) const;
const Gamepads &getGamepads() const { return gamepads_; }
// --- Métodos de consulta y utilidades ---
@@ -170,7 +172,6 @@ class Input {
void printConnectedGamepads() const;
//[[nodiscard]] auto getGamepads() const -> const Gamepads & { return gamepads_; }
std::shared_ptr<Gamepad> findAvailableGamepadByName(const std::string &gamepad_name);
void saveGamepadConfigFromGamepad(std::shared_ptr<Gamepad> gamepad);

View File

@@ -57,7 +57,7 @@ class MenuRenderer {
bool resizing_ = false;
// --- Anchos precalculados ---
std::array<int, 5> group_menu_widths_ = {};
std::array<int, ServiceMenu::SETTINGS_GROUP_SIZE> group_menu_widths_ = {};
// --- Métodos privados de la vista ---
void setAnchors(const ServiceMenu *menu_state);

View File

@@ -176,6 +176,9 @@ void ServiceMenu::updateMenu() {
}
void ServiceMenu::applySettings() {
if (current_settings_group_ == SettingsGroup::CONTROLS) {
applyControlsSettings();
}
if (current_settings_group_ == SettingsGroup::VIDEO) {
applyVideoSettings();
}
@@ -190,6 +193,8 @@ void ServiceMenu::applySettings() {
updateOptionPairs();
}
void ServiceMenu::applyControlsSettings() {}
void ServiceMenu::applyVideoSettings() {
Screen::get()->applySettings();
setHiddenOptions();
@@ -216,6 +221,7 @@ auto ServiceMenu::getOptionByCaption(const std::string &caption) const -> MenuOp
auto ServiceMenu::getCurrentGroupAlignment() const -> ServiceMenu::GroupAlignment {
switch (current_settings_group_) {
case SettingsGroup::CONTROLS:
case SettingsGroup::VIDEO:
case SettingsGroup::AUDIO:
case SettingsGroup::SETTINGS:
@@ -239,6 +245,43 @@ auto ServiceMenu::countOptionsInGroup(SettingsGroup group) const -> size_t {
void ServiceMenu::initializeOptions() {
options_.clear();
// CONTROLS
options_.push_back(std::make_unique<ListOption>(
"Mando Jugador 1",
SettingsGroup::CONTROLS,
Input::get()->getControllerNames(),
[]() {
return Options::gamepad_manager.getGamepad(Player::Id::PLAYER1).name;
},
[](const std::string &val) {
Options::gamepad_manager.assignGamepadToPlayer(Player::Id::PLAYER1, Input::get()->getGamepadByName(val), val);
}));
options_.push_back(std::make_unique<ListOption>(
"Mando Jugador 2",
SettingsGroup::CONTROLS,
Input::get()->getControllerNames(),
[]() {
return Options::gamepad_manager.getGamepad(Player::Id::PLAYER2).name;
},
[](const std::string &val) {
Options::gamepad_manager.assignGamepadToPlayer(Player::Id::PLAYER2, Input::get()->getGamepadByName(val), val);
}));
options_.push_back(std::make_unique<ListOption>(
"Teclat",
SettingsGroup::CONTROLS,
std::vector<std::string>{
"Jugador 1",
"Jugador 2"},
[]() {
return Lang::getNameFromCode(Options::pending_changes.new_language);
},
[](const std::string &val) {
Options::pending_changes.new_language = Lang::getCodeFromName(val);
Options::checkPendingChanges();
}));
// VIDEO
options_.push_back(std::make_unique<BoolOption>(
Lang::getText("[SERVICE_MENU] FULLSCREEN"),
@@ -366,6 +409,11 @@ void ServiceMenu::initializeOptions() {
!Options::settings.shutdown_enabled));
// MAIN MENU
options_.push_back(std::make_unique<FolderOption>(
"Controls",
SettingsGroup::MAIN,
SettingsGroup::CONTROLS));
options_.push_back(std::make_unique<FolderOption>(
Lang::getText("[SERVICE_MENU] VIDEO"),
SettingsGroup::MAIN,
@@ -410,8 +458,10 @@ auto ServiceMenu::settingsGroupToString(SettingsGroup group) -> std::string {
switch (group) {
case SettingsGroup::MAIN:
return Lang::getText("[SERVICE_MENU] TITLE");
case SettingsGroup::CONTROLS:
return Lang::getText("[SERVICE_MENU] TITLE");
case SettingsGroup::VIDEO:
return Lang::getText("[SERVICE_MENU] VIDEO");
return "Controls";
case SettingsGroup::AUDIO:
return Lang::getText("[SERVICE_MENU] AUDIO");
case SettingsGroup::SETTINGS:

View File

@@ -9,11 +9,12 @@
#include "ui_message.h" // Para UIMessage
class MenuOption;
class MenuRenderer; // <-- Nuevo
class MenuRenderer;
class ServiceMenu {
public:
enum class SettingsGroup {
CONTROLS,
VIDEO,
AUDIO,
SETTINGS,
@@ -30,6 +31,7 @@ class ServiceMenu {
static constexpr size_t OPTIONS_HORIZONTAL_PADDING = 20;
static constexpr size_t MIN_WIDTH = 240;
static constexpr size_t MIN_GAP_OPTION_VALUE = 30;
static constexpr size_t SETTINGS_GROUP_SIZE = 6;
// --- Métodos de singleton ---
static void init();
@@ -88,6 +90,7 @@ class ServiceMenu {
void initializeOptions();
void updateMenu();
void applySettings();
void applyControlsSettings();
void applyVideoSettings();
static void applyAudioSettings();
void applySettingsSettings();

View File

@@ -383,4 +383,16 @@ auto getFileName(const std::string &path) -> std::string {
auto getPath(const std::string &full_path) -> std::string {
std::filesystem::path path(full_path);
return path.parent_path().string();
}
// Trunca un string y le añade puntos suspensivos
auto truncateWithEllipsis(const std::string &input, size_t length) -> std::string {
if (input.size() <= length) {
return input;
}
if (length <= 3) {
// Not enough space for any content plus ellipsis
return std::string(length, '.');
}
return input.substr(0, length) + "...";
}

View File

@@ -116,6 +116,7 @@ auto easeInCubic(double time) -> double;
// Utilidades varias
auto stringInVector(const std::vector<std::string> &vec, const std::string &str) -> bool; // Comprueba si un vector contiene una cadena
void printWithDots(const std::string &text1, const std::string &text2, const std::string &text3); // Imprime una línea con puntos
auto truncateWithEllipsis(const std::string &input, size_t length) -> std::string; // Trunca un string y le añade puntos suspensivos
// Demo
auto loadDemoDataFromFile(const std::string &file_path) -> DemoData;