singletons
This commit is contained in:
@@ -11,11 +11,9 @@
|
||||
#include "core/resources/resource_helper.h"
|
||||
|
||||
// Constructor
|
||||
Menu::Menu(SDL_Renderer *renderer, Asset *asset, Input *input, std::string file) {
|
||||
Menu::Menu(SDL_Renderer *renderer, std::string file) {
|
||||
// Copia punteros
|
||||
this->renderer = renderer;
|
||||
this->asset = asset;
|
||||
this->input = input;
|
||||
|
||||
// Inicializa punteros
|
||||
soundMove = nullptr;
|
||||
@@ -74,8 +72,6 @@ Menu::Menu(SDL_Renderer *renderer, Asset *asset, Input *input, std::string file)
|
||||
|
||||
Menu::~Menu() {
|
||||
renderer = nullptr;
|
||||
asset = nullptr;
|
||||
input = nullptr;
|
||||
|
||||
if (soundMove) {
|
||||
JA_DeleteSound(soundMove);
|
||||
@@ -130,8 +126,8 @@ bool Menu::parseFromStream(std::istream &file, const std::string &filename) {
|
||||
// Crea el objeto text tan pronto como se pueda. Necesario para añadir items.
|
||||
// Carga via ResourceHelper para que funcione tanto con pack como con filesystem.
|
||||
if (font_png != "" && font_txt != "" && !textAllocated) {
|
||||
auto pngBytes = ResourceHelper::loadFile(asset->get(font_png));
|
||||
auto txtBytes = ResourceHelper::loadFile(asset->get(font_txt));
|
||||
auto pngBytes = ResourceHelper::loadFile(Asset::get()->get(font_png));
|
||||
auto txtBytes = ResourceHelper::loadFile(Asset::get()->get(font_txt));
|
||||
text = new Text(pngBytes, txtBytes, renderer);
|
||||
textAllocated = true;
|
||||
}
|
||||
@@ -218,17 +214,17 @@ bool Menu::setVars(std::string var, std::string value) {
|
||||
}
|
||||
|
||||
else if (var == "sound_cancel") {
|
||||
auto bytes = ResourceHelper::loadFile(asset->get(value));
|
||||
auto bytes = ResourceHelper::loadFile(Asset::get()->get(value));
|
||||
if (!bytes.empty()) soundCancel = JA_LoadSound(bytes.data(), (uint32_t)bytes.size());
|
||||
}
|
||||
|
||||
else if (var == "sound_accept") {
|
||||
auto bytes = ResourceHelper::loadFile(asset->get(value));
|
||||
auto bytes = ResourceHelper::loadFile(Asset::get()->get(value));
|
||||
if (!bytes.empty()) soundAccept = JA_LoadSound(bytes.data(), (uint32_t)bytes.size());
|
||||
}
|
||||
|
||||
else if (var == "sound_move") {
|
||||
auto bytes = ResourceHelper::loadFile(asset->get(value));
|
||||
auto bytes = ResourceHelper::loadFile(Asset::get()->get(value));
|
||||
if (!bytes.empty()) soundMove = JA_LoadSound(bytes.data(), (uint32_t)bytes.size());
|
||||
}
|
||||
|
||||
@@ -770,7 +766,7 @@ void Menu::setDefaultActionWhenCancel(int item) {
|
||||
|
||||
// Gestiona la entrada de teclado y mando durante el menu
|
||||
void Menu::checkInput() {
|
||||
if (input->checkInput(input_up, REPEAT_FALSE)) {
|
||||
if (Input::get()->checkInput(input_up, REPEAT_FALSE)) {
|
||||
if (decreaseSelectorIndex()) {
|
||||
if (soundMove) {
|
||||
JA_PlaySound(soundMove);
|
||||
@@ -778,7 +774,7 @@ void Menu::checkInput() {
|
||||
}
|
||||
}
|
||||
|
||||
if (input->checkInput(input_down, REPEAT_FALSE)) {
|
||||
if (Input::get()->checkInput(input_down, REPEAT_FALSE)) {
|
||||
if (increaseSelectorIndex()) {
|
||||
if (soundMove) {
|
||||
JA_PlaySound(soundMove);
|
||||
@@ -786,14 +782,14 @@ void Menu::checkInput() {
|
||||
}
|
||||
}
|
||||
|
||||
if (input->checkInput(input_accept, REPEAT_FALSE)) {
|
||||
if (Input::get()->checkInput(input_accept, REPEAT_FALSE)) {
|
||||
itemSelected = selector.index;
|
||||
if (soundAccept) {
|
||||
JA_PlaySound(soundAccept);
|
||||
}
|
||||
}
|
||||
|
||||
if (input->checkInput(input_cancel, REPEAT_FALSE)) {
|
||||
if (Input::get()->checkInput(input_cancel, REPEAT_FALSE)) {
|
||||
itemSelected = defaultActionWhenCancel;
|
||||
if (soundCancel) {
|
||||
JA_PlaySound(soundCancel);
|
||||
@@ -875,7 +871,7 @@ void Menu::setBackgroundType(int value) {
|
||||
// Establece la fuente de texto que se utilizará
|
||||
void Menu::setText(std::string font_png, std::string font_txt) {
|
||||
if (!text) {
|
||||
text = new Text(asset->get(font_png), asset->get(font_txt), renderer);
|
||||
text = new Text(Asset::get()->get(font_png), Asset::get()->get(font_txt), renderer);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user