refactor jail_audio: namespace Ja, enum class, tipus sense prefix JA_

This commit is contained in:
2026-05-16 17:56:46 +02:00
parent 9f6d38cf48
commit be95b8afab
14 changed files with 741 additions and 832 deletions
+14 -14
View File
@@ -6,7 +6,7 @@
#include <sstream> // for basic_stringstream
#include "core/audio/audio.hpp" // for Audio::get (playSound)
#include "core/audio/jail_audio.hpp" // for JA_LoadSound, JA_DeleteSound (propietat local)
#include "core/audio/jail_audio.hpp" // for Ja::loadSound, Ja::deleteSound (propietat local)
#include "core/input/input.h" // for Input, REPEAT_FALSE, InputAction
#include "core/rendering/text.h" // for Text
#include "core/resources/asset.h" // for Asset
@@ -40,7 +40,7 @@ Menu::Menu(SDL_Renderer *renderer, const std::string &file)
center_x_ = 0;
center_y_ = 0;
widest_item_ = 0;
default_action_when_cancel = 0;
default_action_when_cancel_ = 0;
// Selector
selector_.origin_y = 0;
@@ -73,15 +73,15 @@ Menu::~Menu() {
renderer_ = nullptr;
if (sound_move_ != nullptr) {
JA_DeleteSound(sound_move_);
Ja::deleteSound(sound_move_);
}
if (sound_accept_ != nullptr) {
JA_DeleteSound(sound_accept_);
Ja::deleteSound(sound_accept_);
}
if (sound_cancel_ != nullptr) {
JA_DeleteSound(sound_cancel_);
Ja::deleteSound(sound_cancel_);
}
delete text_;
@@ -229,21 +229,21 @@ auto Menu::setVars(const std::string &var, const std::string &value) -> bool {
else if (var == "sound_cancel") {
auto bytes = ResourceHelper::loadFile(Asset::get()->get(value));
if (!bytes.empty()) {
sound_cancel_ = JA_LoadSound(bytes.data(), (uint32_t)bytes.size());
sound_cancel_ = Ja::loadSound(bytes.data(), (uint32_t)bytes.size());
}
}
else if (var == "sound_accept") {
auto bytes = ResourceHelper::loadFile(Asset::get()->get(value));
if (!bytes.empty()) {
sound_accept_ = JA_LoadSound(bytes.data(), (uint32_t)bytes.size());
sound_accept_ = Ja::loadSound(bytes.data(), (uint32_t)bytes.size());
}
}
else if (var == "sound_move") {
auto bytes = ResourceHelper::loadFile(Asset::get()->get(value));
if (!bytes.empty()) {
sound_move_ = JA_LoadSound(bytes.data(), (uint32_t)bytes.size());
sound_move_ = Ja::loadSound(bytes.data(), (uint32_t)bytes.size());
}
}
@@ -324,7 +324,7 @@ auto Menu::setVars(const std::string &var, const std::string &value) -> bool {
}
else if (var == "defaultActionWhenCancel") {
default_action_when_cancel = std::stoi(value);
default_action_when_cancel_ = std::stoi(value);
}
else if (var.empty()) {
@@ -341,15 +341,15 @@ auto Menu::setVars(const std::string &var, const std::string &value) -> bool {
void Menu::loadAudioFile(const std::string &file, int sound) {
switch (sound) {
case SOUND_ACCEPT:
sound_accept_ = JA_LoadSound(file.c_str());
sound_accept_ = Ja::loadSound(file.c_str());
break;
case SOUND_CANCEL:
sound_cancel_ = JA_LoadSound(file.c_str());
sound_cancel_ = Ja::loadSound(file.c_str());
break;
case SOUND_MOVE:
sound_move_ = JA_LoadSound(file.c_str());
sound_move_ = Ja::loadSound(file.c_str());
break;
default:
@@ -770,7 +770,7 @@ void Menu::setItemCaption(int index, const std::string &text) {
// Establece el indice del itemm que se usará por defecto al cancelar el menu
void Menu::setDefaultActionWhenCancel(int item) {
default_action_when_cancel = item;
default_action_when_cancel_ = item;
}
// Gestiona la entrada de teclado y mando durante el menu
@@ -797,7 +797,7 @@ void Menu::checkInput() {
}
if (Input::get()->checkInput(CANCEL, REPEAT_FALSE)) {
item_selected_ = default_action_when_cancel;
item_selected_ = default_action_when_cancel_;
if (sound_cancel_ != nullptr) {
Audio::get()->playSound(sound_cancel_);
}
+6 -4
View File
@@ -8,7 +8,9 @@
#include "utils/utils.h" // for Color
class Text;
struct JA_Sound_t;
namespace Ja {
struct Sound;
} // namespace Ja
// Tipos de fondos para el menú
constexpr int MENU_BACKGROUND_TRANSPARENT = 0;
@@ -140,9 +142,9 @@ class Menu {
bool is_centered_on_y_; // Variable para saber si el menu debe estar centrado respecto a un punto en el eje Y
bool are_elements_centered_on_x_; // Variable para saber si los elementos van centrados en el eje X
int widest_item_; // Anchura del elemento más ancho
JA_Sound_t *sound_accept_; // Sonido al aceptar o elegir una opción del menu
JA_Sound_t *sound_cancel_; // Sonido al cancelar el menu
JA_Sound_t *sound_move_; // Sonido al mover el selector
Ja::Sound *sound_accept_; // Sonido al aceptar o elegir una opción del menu
Ja::Sound *sound_cancel_; // Sonido al cancelar el menu
Ja::Sound *sound_move_; // Sonido al mover el selector
Color color_greyed_; // Color para los elementos agrisados
Rectangle rect_bg_; // Rectangulo de fondo del menu
std::vector<Item> items_; // Estructura para cada elemento del menu