From a1dad5d841ca1bd1051452b2344d1fd82a8009b0 Mon Sep 17 00:00:00 2001 From: Sergio Valor Date: Mon, 29 Aug 2022 20:11:46 +0200 Subject: [PATCH] Actualizado jail_adudio y Menu --- source/jail_audio.cpp | 39 +- source/jail_audio.h | 3 + source/menu.cpp | 915 ++++++++++++++++++++++++++++-------------- source/menu.h | 188 +++++---- 4 files changed, 739 insertions(+), 406 deletions(-) diff --git a/source/jail_audio.cpp b/source/jail_audio.cpp index e22b355..fc23241 100644 --- a/source/jail_audio.cpp +++ b/source/jail_audio.cpp @@ -1,6 +1,7 @@ -#ifndef __MIPSEL__ #include "jail_audio.h" #include "stb_vorbis.c" +#include +#include #define JA_MAX_SIMULTANEOUS_CHANNELS 5 @@ -30,16 +31,17 @@ JA_Channel_t channels[JA_MAX_SIMULTANEOUS_CHANNELS]; int JA_freq {48000}; SDL_AudioFormat JA_format {AUDIO_S16}; Uint8 JA_channels {2}; +int JA_volume = 128; void audioCallback(void * userdata, uint8_t * stream, int len) { SDL_memset(stream, 0, len); if (current_music != NULL && current_music->state == JA_MUSIC_PLAYING) { const int size = SDL_min(len, current_music->samples*2-current_music->pos); - SDL_memcpy(stream, current_music->output+current_music->pos, size); + SDL_MixAudioFormat(stream, (Uint8*)(current_music->output+current_music->pos), AUDIO_S16, size, JA_volume); current_music->pos += size/2; if (size < len) { if (current_music->times != 0) { - SDL_memcpy(stream+size, current_music->output, len-size); + SDL_MixAudioFormat(stream+size, (Uint8*)current_music->output, AUDIO_S16, len-size, JA_volume); current_music->pos = (len-size)/2; if (current_music->times > 0) current_music->times--; } else { @@ -52,11 +54,11 @@ void audioCallback(void * userdata, uint8_t * stream, int len) { for (int i = 0; i < JA_MAX_SIMULTANEOUS_CHANNELS; i++) { if (channels[i].state == JA_CHANNEL_PLAYING) { const int size = SDL_min(len, channels[i].sound->length - channels[i].pos); - SDL_MixAudioFormat(stream, channels[i].sound->buffer + channels[i].pos, AUDIO_S16, size, 64); + SDL_MixAudioFormat(stream, channels[i].sound->buffer + channels[i].pos, AUDIO_S16, size, JA_volume/2); channels[i].pos += size; if (size < len) { if (channels[i].times != 0) { - SDL_MixAudioFormat(stream + size, channels[i].sound->buffer, AUDIO_S16, len-size, 64); + SDL_MixAudioFormat(stream + size, channels[i].sound->buffer, AUDIO_S16, len-size, JA_volume/2); channels[i].pos = len-size; if (channels[i].times > 0) channels[i].times--; } else { @@ -79,7 +81,19 @@ void JA_Init(const int freq, const SDL_AudioFormat format, const int channels) { JA_Music JA_LoadMusic(const char* filename) { int chan, samplerate; JA_Music music = new JA_Music_t(); - music->samples = stb_vorbis_decode_filename(filename, &chan, &samplerate, &music->output); + + // [RZC 28/08/22] Carreguem primer el arxiu en memòria i després el descomprimim. Es algo més rapid. + FILE *f = fopen(filename, "rb"); + fseek(f, 0, SEEK_END); + long fsize = ftell(f); + fseek(f, 0, SEEK_SET); + Uint8 *buffer = (Uint8*)malloc(fsize + 1); + fread(buffer, fsize, 1, f); + fclose(f); + music->samples = stb_vorbis_decode_memory(buffer, fsize, &chan, &samplerate, &music->output); + free(buffer); + // [RZC 28/08/22] Abans el descomprimiem mentre el teniem obert +// music->samples = stb_vorbis_decode_filename(filename, &chan, &samplerate, &music->output); SDL_AudioCVT cvt; SDL_BuildAudioCVT(&cvt, AUDIO_S16, chan, samplerate, JA_format, JA_channels, JA_freq); @@ -134,6 +148,13 @@ void JA_DeleteMusic(JA_Music music) { delete music; } +JA_Sound JA_NewSound(Uint8* buffer, Uint32 length) { + JA_Sound sound = new JA_Sound_t(); + sound->buffer = buffer; + sound->length = length; + return sound; +} + JA_Sound JA_LoadSound(const char* filename) { JA_Sound sound = new JA_Sound_t(); SDL_AudioSpec wavSpec; @@ -210,4 +231,8 @@ JA_Channel_state JA_GetChannelState(const int channel) { if (channel < 0 || channel >= JA_MAX_SIMULTANEOUS_CHANNELS) return JA_CHANNEL_INVALID; return channels[channel].state; } -#endif + +int JA_SetVolume(int volume) { + JA_volume = volume > 128 ? 128 : volume < 0 ? 0 : volume; + return JA_volume; +} \ No newline at end of file diff --git a/source/jail_audio.h b/source/jail_audio.h index 344f716..2a2fc9f 100644 --- a/source/jail_audio.h +++ b/source/jail_audio.h @@ -17,6 +17,7 @@ void JA_StopMusic(); JA_Music_state JA_GetMusicState(); void JA_DeleteMusic(JA_Music music); +JA_Sound JA_NewSound(Uint8* buffer, Uint32 length); JA_Sound JA_LoadSound(const char* filename); int JA_PlaySound(JA_Sound sound, const int loop = 0); void JA_PauseChannel(const int channel); @@ -24,3 +25,5 @@ void JA_ResumeChannel(const int channel); void JA_StopChannel(const int channel); JA_Channel_state JA_GetChannelState(const int channel); void JA_DeleteSound(JA_Sound sound); + +int JA_SetVolume(int volume); \ No newline at end of file diff --git a/source/menu.cpp b/source/menu.cpp index c8deee5..bc6c5be 100644 --- a/source/menu.cpp +++ b/source/menu.cpp @@ -2,194 +2,477 @@ #include "menu.h" // Constructor -Menu::Menu(SDL_Renderer *renderer, Text *text, Input *input, std::string *fileList) +Menu::Menu(SDL_Renderer *renderer, Asset *asset, Input *input, std::string file) { - mRenderer = renderer; - mText = text; - mInput = input; - mFileList = fileList; + this->renderer = renderer; + this->asset = asset; + this->input = input; + + soundMove = nullptr; + soundAccept = nullptr; + soundCancel = nullptr; + + init(); + if (file != "") + { + load(file); + } + reorganize(); } Menu::~Menu() { - mRenderer = nullptr; - mText = nullptr; - mInput = nullptr; - mFileList = nullptr; -} + renderer = nullptr; + asset = nullptr; + input = nullptr; -// Inicializador -void Menu::init(std::string name, int x, int y, int backgroundType) -{ - loadMedia(); - - // Inicia variables - mName = name; - mSelector.index = 0; - mTotalItems = 0; - mItemSelected = MENU_NO_OPTION; - mPosX = x; - mPosY = y; - mRectBG.rect.x = 0; - mRectBG.rect.y = 0; - mRectBG.rect.w = 0; - mRectBG.rect.h = 0; - mRectBG.r = 0; - mRectBG.g = 0; - mRectBG.b = 0; - mBackgroundType = backgroundType; - mIsCenteredOnX = false; - mIsCenteredOnY = false; - mAreElementsCenteredOnX = false; - mCenterX = 0; - mCenterY = 0; - mWidestItem = 0; - mColorGreyed = {128, 128, 128}; - - // Selector - mSelector.originY = 0; - mSelector.targetY = 0; - mSelector.despY = 0; - mSelector.originH = 0; - mSelector.targetH = 0; - mSelector.incH = 0; - mSelector.y = 0.0f; - mSelector.h = 0.0f; - mSelector.numJumps = 8; - mSelector.moving = false; - mSelector.resizing = false; - mSelector.rect = {0, 0, 0, 0}; - mSelector.r = 0; - mSelector.g = 0; - mSelector.b = 0; - mSelector.a = 255; - - // Elementos del menu - for (int i = 0; i < MENU_MAX_ITEMS; i++) + if (soundMove) { - mItem[i].label = ""; - mItem[i].rect = {0, 0, 0, 0}; - mItem[i].hPaddingDown = 0; - mItem[i].selectable = false; - mItem[i].greyed = false; - mItem[i].linkedDown = false; - mItem[i].linkedUp = false; + JA_DeleteSound(soundMove); + } + + if (soundAccept) + { + JA_DeleteSound(soundAccept); + } + + if (soundCancel) + { + JA_DeleteSound(soundCancel); + } + + if (text != nullptr) + { + delete text; } } -// Carga los recursos necesarios para la sección 'Title' -bool Menu::loadMedia() +// Carga la configuración del menu desde un archivo de texto +bool Menu::load(std::string file_path) { // Indicador de éxito en la carga bool success = true; - // Sonidos - mSoundMove = JA_LoadSound(mFileList[17].c_str()); - mSoundAccept = JA_LoadSound(mFileList[18].c_str()); - mSoundCancel = JA_LoadSound(mFileList[16].c_str()); + // Indica si se ha creado ya el objeto de texto + bool textAllocated = false; + + std::string filename = file_path.substr(file_path.find_last_of("\\/") + 1); + std::string line; + std::ifstream file(file_path); + + // El fichero se puede abrir + if (file.good()) + { + // Procesa el fichero linea a linea + printf("Reading file %s\n", filename.c_str()); + while (std::getline(file, line)) + { + if (line == "[item]") + { + item_t item; + item.label = ""; + item.hPaddingDown = 1; + item.selectable = true; + item.greyed = false; + item.linkedDown = false; + + do + { + + std::getline(file, line); + + // Encuentra la posición del caracter '=' + int pos = line.find("="); + + // Procesa las dos subcadenas + if (!setItem(&item, line.substr(0, pos), line.substr(pos + 1, line.length()))) + { + printf("Warning: file %s\n, unknown parameter \"%s\"\n", filename.c_str(), line.substr(0, pos).c_str()); + success = false; + } + + } while (line != "[/item]"); + + addItem(item.label, item.hPaddingDown, item.selectable, item.greyed, item.linkedDown); + } + + // En caso contrario se parsea el fichero para buscar las variables y los valores + else + { + // Encuentra la posición del caracter '=' + int pos = line.find("="); + // Procesa las dos subcadenas + if (!setVars(line.substr(0, pos), line.substr(pos + 1, line.length()))) + { + printf("Warning: file %s, unknown parameter \"%s\"\n", filename.c_str(), line.substr(0, pos).c_str()); + success = false; + } + + // Crea el objeto text tan pronto como se pueda. Necesario para añadir items + if (font_png != "" && font_txt != "" && !textAllocated) + { + text = new Text(asset->get(font_png), asset->get(font_txt), renderer); + textAllocated = true; + } + } + } + + // Cierra el fichero + printf("Closing file %s\n\n", filename.c_str()); + file.close(); + } + // El fichero no se puede abrir + else + { + printf("Warning: Unable to open %s file\n", filename.c_str()); + success = false; + } return success; } +// Asigna variables a partir de dos cadenas +bool Menu::setItem(item_t *item, std::string var, std::string value) +{ + // Indicador de éxito en la asignación + bool success = true; + + if (var == "text") + { + item->label = value; + } + + else if (var == "hPaddingDown") + { + item->hPaddingDown = std::stoi(value); + } + + else if (var == "selectable") + { + item->selectable = value == "true" ? true : false; + } + + else if (var == "greyed") + { + item->greyed = value == "true" ? true : false; + } + + else if (var == "linkedDown") + { + item->linkedDown = value == "true" ? true : false; + } + + else if ((var == "") || (var == "[/item]")) + { + } + else + { + success = false; + } + + return success; +} + +// Asigna variables a partir de dos cadenas +bool Menu::setVars(std::string var, std::string value) +{ + // Indicador de éxito en la asignación + bool success = true; + + if (var == "font_png") + { + font_png = value; + } + + else if (var == "font_txt") + { + font_txt = value; + } + + else if (var == "sound_cancel") + { + soundCancel = JA_LoadSound(asset->get(value).c_str()); + } + + else if (var == "sound_accept") + { + soundAccept = JA_LoadSound(asset->get(value).c_str()); + } + + else if (var == "sound_move") + { + soundMove = JA_LoadSound(asset->get(value).c_str()); + } + + else if (var == "name") + { + name = value; + } + + else if (var == "x") + { + x = std::stoi(value); + } + + else if (var == "centerX") + { + centerX = std::stoi(value); + } + + else if (var == "centerY") + { + centerY = std::stoi(value); + } + + else if (var == "y") + { + y = std::stoi(value); + } + + else if (var == "backgroundType") + { + backgroundType = std::stoi(value); + } + + else if (var == "backgroundColor") + { + // Se introducen los valores separados por comas en un vector + std::stringstream ss(value); + std::string tmp; + getline(ss, tmp, ','); + rectBG.color.r = std::stoi(tmp); + getline(ss, tmp, ','); + rectBG.color.g = std::stoi(tmp); + getline(ss, tmp, ','); + rectBG.color.b = std::stoi(tmp); + getline(ss, tmp, ','); + rectBG.a = std::stoi(tmp); + } + + else if (var == "selector_color") + { + // Se introducen los valores separados por comas en un vector + std::stringstream ss(value); + std::string tmp; + getline(ss, tmp, ','); + selector.color.r = std::stoi(tmp); + getline(ss, tmp, ','); + selector.color.g = std::stoi(tmp); + getline(ss, tmp, ','); + selector.color.b = std::stoi(tmp); + getline(ss, tmp, ','); + selector.a = std::stoi(tmp); + } + + else if (var == "selector_text_color") + { + // Se introducen los valores separados por comas en un vector + std::stringstream ss(value); + std::string tmp; + getline(ss, tmp, ','); + selector.itemColor.r = std::stoi(tmp); + getline(ss, tmp, ','); + selector.itemColor.g = std::stoi(tmp); + getline(ss, tmp, ','); + selector.itemColor.b = std::stoi(tmp); + } + + else if (var == "areElementsCenteredOnX") + { + areElementsCenteredOnX = value == "true" ? true : false; + } + + else if (var == "isCenteredOnX") + { + isCenteredOnX = value == "true" ? true : false; + } + + else if (var == "isCenteredOnY") + { + isCenteredOnY = value == "true" ? true : false; + } + + else if (var == "defaultActionWhenCancel") + { + defaultActionWhenCancel = std::stoi(value); + } + + else if (var == "") + { + } + + else + { + success = false; + } + + return success; +} + +// Inicializa las variables +void Menu::init() +{ + // Inicia variables + name = ""; + selector.index = 0; + itemSelected = MENU_NO_OPTION; + x = 0; + y = 0; + rectBG.rect = {0, 0, 0, 0}; + rectBG.color = {0, 0, 0}; + rectBG.a = 0; + backgroundType = MENU_BACKGROUND_SOLID; + isCenteredOnX = false; + isCenteredOnY = false; + areElementsCenteredOnX = false; + centerX = 0; + centerY = 0; + widestItem = 0; + colorGreyed = {128, 128, 128}; + defaultActionWhenCancel = 0; + font_png = ""; + font_txt = ""; + + // Selector + selector.originY = 0; + selector.targetY = 0; + selector.despY = 0; + selector.originH = 0; + selector.targetH = 0; + selector.incH = 0; + selector.y = 0.0f; + selector.h = 0.0f; + selector.numJumps = 8; + selector.moving = false; + selector.resizing = false; + selector.rect = {0, 0, 0, 0}; + selector.color = {0, 0, 0}; + selector.itemColor = {0, 0, 0}; + selector.a = 255; +} + +// Carga los ficheros de audio +void Menu::loadAudioFile(std::string file, int sound) +{ + switch (sound) + { + case SOUND_ACCEPT: + soundAccept = JA_LoadSound(file.c_str()); + break; + + case SOUND_CANCEL: + soundCancel = JA_LoadSound(file.c_str()); + break; + + case SOUND_MOVE: + soundMove = JA_LoadSound(file.c_str()); + break; + + default: + break; + } +} + // Obtiene el nombre del menu std::string Menu::getName() { - return mName; + return name; } // Obtiene el valor de la variable -Uint8 Menu::getItemSelected() +int Menu::getItemSelected() { // Al llamar a esta funcion, se obtiene el valor y se borra - const int temp = mItemSelected; - mItemSelected = MENU_NO_OPTION; + const int temp = itemSelected; + itemSelected = MENU_NO_OPTION; return temp; } // Actualiza la posicion y el estado del selector void Menu::updateSelector() { - if (mSelector.moving) + if (selector.moving) { // Calcula el desplazamiento en Y - mSelector.y += mSelector.despY; - if (mSelector.despY > 0) // Va hacia abajo + selector.y += selector.despY; + if (selector.despY > 0) // Va hacia abajo { - if (mSelector.y > mSelector.targetY) // Ha llegado al destino + if (selector.y > selector.targetY) // Ha llegado al destino { - mSelector.originY = mSelector.y = mSelector.targetY; - mSelector.moving = false; + selector.originY = selector.y = selector.targetY; + selector.moving = false; } } - if (mSelector.despY < 0) // Va hacia arriba + if (selector.despY < 0) // Va hacia arriba { - if (mSelector.y < mSelector.targetY) // Ha llegado al destino + if (selector.y < selector.targetY) // Ha llegado al destino { - mSelector.originY = mSelector.y = mSelector.targetY; - mSelector.moving = false; + selector.originY = selector.y = selector.targetY; + selector.moving = false; } } - mSelector.rect.y = int(mSelector.y); + selector.rect.y = int(selector.y); } else { - mSelector.rect.y = int(mSelector.y); + selector.rect.y = int(selector.y); } - if (mSelector.resizing) + if (selector.resizing) { // Calcula el incremento en H - mSelector.h += mSelector.incH; - if (mSelector.incH > 0) // Crece + selector.h += selector.incH; + if (selector.incH > 0) // Crece { - if (mSelector.h > mSelector.targetH) // Ha llegado al destino + if (selector.h > selector.targetH) // Ha llegado al destino { - //mSelector.originH = mSelector.targetH = mSelector.rect.h = getSelectorHeight(mSelector.index); - mSelector.originH = mSelector.h = mSelector.targetH; - mSelector.resizing = false; + // selector.originH = selector.targetH = selector.rect.h = getSelectorHeight(selector.index); + selector.originH = selector.h = selector.targetH; + selector.resizing = false; } } - if (mSelector.incH < 0) // Decrece + if (selector.incH < 0) // Decrece { - if (mSelector.h < mSelector.targetH) // Ha llegado al destino + if (selector.h < selector.targetH) // Ha llegado al destino { - //mSelector.originH = mSelector.targetH = mSelector.rect.h = getSelectorHeight(mSelector.index); - mSelector.originH = mSelector.h = mSelector.targetH; - mSelector.resizing = false; + // selector.originH = selector.targetH = selector.rect.h = getSelectorHeight(selector.index); + selector.originH = selector.h = selector.targetH; + selector.resizing = false; } } - mSelector.rect.h = int(mSelector.h); + selector.rect.h = int(selector.h); } else { - mSelector.rect.h = getSelectorHeight(mSelector.index); + selector.rect.h = getSelectorHeight(selector.index); } } // Coloca el selector en una posición específica -void Menu::setSelectorPos(Uint8 index) +void Menu::setSelectorPos(int index) { - if (index < mTotalItems) + if (index < item.size()) { - mSelector.index = index; - mSelector.rect.y = mSelector.y = mSelector.originY = mSelector.targetY = mItem[mSelector.index].rect.y; - mSelector.rect.w = mRectBG.rect.w; - mSelector.rect.x = mRectBG.rect.x; - mSelector.originH = mSelector.targetH = mSelector.rect.h = getSelectorHeight(mSelector.index); - mSelector.moving = false; - mSelector.resizing = false; + selector.index = index; + selector.rect.y = selector.y = selector.originY = selector.targetY = item[selector.index].rect.y; + selector.rect.w = rectBG.rect.w; + selector.rect.x = rectBG.rect.x; + selector.originH = selector.targetH = selector.rect.h = getSelectorHeight(selector.index); + selector.moving = false; + selector.resizing = false; } } // Obtiene la anchura del elemento más ancho del menu -Uint16 Menu::getWidestItem() +int Menu::getWidestItem() { - Uint16 result = 0; + int result = 0; // Obtenemos la anchura del item mas ancho - for (int i = 0; i < mTotalItems; i++) - if (mItem[i].rect.w > result) - result = mItem[i].rect.w; + for (auto &i : item) + { + result = std::max(result, i.rect.w); + } return result; } @@ -197,124 +480,114 @@ Uint16 Menu::getWidestItem() // Deja el menu apuntando al primer elemento void Menu::reset() { - mItemSelected = MENU_NO_OPTION; - mSelector.index = 0; - mSelector.originY = mSelector.targetY = mSelector.y = mItem[0].rect.y; - mSelector.originH = mSelector.targetH = mItem[0].rect.h; - mSelector.moving = false; - mSelector.resizing = false; + itemSelected = MENU_NO_OPTION; + selector.index = 0; + selector.originY = selector.targetY = selector.y = item[0].rect.y; + selector.originH = selector.targetH = item[0].rect.h; + selector.moving = false; + selector.resizing = false; } // Actualiza el menu para recolocarlo correctamente y establecer el tamaño void Menu::reorganize() { setRectSize(); - if (mIsCenteredOnX) - centerMenuOnX(mCenterX); - if (mIsCenteredOnY) - centerMenuOnY(mCenterY); - if (mAreElementsCenteredOnX) + + if (isCenteredOnX) + { + centerMenuOnX(centerX); + } + + if (isCenteredOnY) + { + centerMenuOnY(centerY); + } + + if (areElementsCenteredOnX) + { centerMenuElementsOnX(); + } } // Deja el menu apuntando al siguiente elemento bool Menu::increaseSelectorIndex() { - bool success = false; - // Obten las coordenadas del elemento actual - mSelector.y = mSelector.originY = mItem[mSelector.index].rect.y; - mSelector.h = mSelector.originH = getSelectorHeight(mSelector.index); + selector.y = selector.originY = item[selector.index].rect.y; + selector.h = selector.originH = getSelectorHeight(selector.index); // Calcula cual es el siguiente elemento - //if (mSelector.index < (mTotalItems - 1)) - //{ - // mSelector.index++; - // while ((!mItem[mSelector.index].selectable) && (mSelector.index < (mTotalItems - 1))) - // mSelector.index++; - // success = true; - //} - - // Calcula cual es el siguiente elemento (versión con loop) - //if (mSelector.index < (mTotalItems - 1)) + ++selector.index %= item.size(); + while (!item[selector.index].selectable) { - ++mSelector.index %= mTotalItems; - while (!mItem[mSelector.index].selectable) - //mSelector.index++; - ++mSelector.index %= mTotalItems; - success = true; + ++selector.index %= item.size(); } - if (success) - { // Establece las coordenadas y altura de destino - mSelector.targetY = mItem[mSelector.index].rect.y; - mSelector.despY = (mSelector.targetY - mSelector.originY) / mSelector.numJumps; + // Establece las coordenadas y altura de destino + selector.targetY = item[selector.index].rect.y; + selector.despY = (selector.targetY - selector.originY) / selector.numJumps; - mSelector.targetH = getSelectorHeight(mSelector.index); - mSelector.incH = (mSelector.targetH - mSelector.originH) / mSelector.numJumps; + selector.targetH = getSelectorHeight(selector.index); + selector.incH = (selector.targetH - selector.originH) / selector.numJumps; - mSelector.moving = true; - if (mSelector.incH != 0) - mSelector.resizing = true; + selector.moving = true; + if (selector.incH != 0) + { + selector.resizing = true; } - return success; + return true; } // Deja el menu apuntando al elemento anterior bool Menu::decreaseSelectorIndex() { - bool success = false; - // Obten las coordenadas del elemento actual - mSelector.y = mSelector.originY = mItem[mSelector.index].rect.y; - mSelector.h = mSelector.originH = getSelectorHeight(mSelector.index); + selector.y = selector.originY = item[selector.index].rect.y; + selector.h = selector.originH = getSelectorHeight(selector.index); // Calcula cual es el siguiente elemento - //if (mSelector.index > 0) - //{ - // mSelector.index--; - // while ((!mItem[mSelector.index].selectable) && (mSelector.index > 0)) - // mSelector.index--; - // success = true; - //} - - // Calcula cual es el siguiente elemento (versión con loop) - //if (mSelector.index > 0) + if (selector.index == 0) { - if (mSelector.index == 0) - mSelector.index = mTotalItems; - else - mSelector.index--; - while (!mItem[mSelector.index].selectable) + selector.index = item.size(); + } + else + { + selector.index--; + } + + while (!item[selector.index].selectable) + { + if (selector.index == 0) { - if (mSelector.index == 0) - mSelector.index = mTotalItems; - else - mSelector.index--; + selector.index = item.size(); + } + else + { + selector.index--; } - success = true; } - if (success) - { // Establece las coordenadas y altura de destino - mSelector.targetY = mItem[mSelector.index].rect.y; - mSelector.despY = (mSelector.targetY - mSelector.originY) / mSelector.numJumps; + // Establece las coordenadas y altura de destino + selector.targetY = item[selector.index].rect.y; + selector.despY = (selector.targetY - selector.originY) / selector.numJumps; - mSelector.targetH = getSelectorHeight(mSelector.index); - mSelector.incH = (mSelector.targetH - mSelector.originH) / mSelector.numJumps; + selector.targetH = getSelectorHeight(selector.index); + selector.incH = (selector.targetH - selector.originH) / selector.numJumps; - mSelector.moving = true; - if (mSelector.incH != 0) - mSelector.resizing = true; + selector.moving = true; + if (selector.incH != 0) + { + selector.resizing = true; } - return success; + return true; } // Actualiza la logica del menu void Menu::update() { + checkInput(); updateSelector(); } @@ -322,126 +595,108 @@ void Menu::update() void Menu::render() { // Rendereritza el fondo del menu - if (mBackgroundType == MENU_BACKGROUND_SOLID) + if (backgroundType == MENU_BACKGROUND_SOLID) { - SDL_SetRenderDrawColor(mRenderer, mRectBG.r, mRectBG.g, mRectBG.b, mRectBG.a); - SDL_RenderFillRect(mRenderer, &mRectBG.rect); + SDL_SetRenderDrawColor(renderer, rectBG.color.r, rectBG.color.g, rectBG.color.b, rectBG.a); + SDL_RenderFillRect(renderer, &rectBG.rect); } // Renderiza el rectangulo del selector - SDL_Rect temp = mSelector.rect; - temp.y--; - temp.h++; - SDL_SetRenderDrawColor(mRenderer, mSelector.r, mSelector.g, mSelector.b, mSelector.a); - SDL_RenderFillRect(mRenderer, &temp); + const SDL_Rect temp = {selector.rect.x, selector.rect.y - 1, selector.rect.w, selector.rect.h + 1}; + // temp.y--; + // temp.h++; + SDL_SetRenderDrawColor(renderer, selector.color.r, selector.color.g, selector.color.b, selector.a); + SDL_RenderFillRect(renderer, &temp); // Renderiza el borde del fondo - if (mBackgroundType == MENU_BACKGROUND_SOLID) + if (backgroundType == MENU_BACKGROUND_SOLID) { - SDL_SetRenderDrawColor(mRenderer, mRectBG.r, mRectBG.g, mRectBG.b, 255); - SDL_RenderDrawRect(mRenderer, &mRectBG.rect); + SDL_SetRenderDrawColor(renderer, rectBG.color.r, rectBG.color.g, rectBG.color.b, 255); + SDL_RenderDrawRect(renderer, &rectBG.rect); } // Renderitza el texto - for (int i = 0; i < mTotalItems; i++) + for (int i = 0; i < item.size(); i++) { - if (i == mSelector.index) + if (i == selector.index) { - const color_t color = {mSelector.itemR, mSelector.itemG, mSelector.itemB}; - mText->writeColored(mItem[i].rect.x, mItem[i].rect.y, mItem[i].label, color); + const color_t color = {selector.itemColor.r, selector.itemColor.g, selector.itemColor.b}; + text->writeColored(item[i].rect.x, item[i].rect.y, item[i].label, color); } - else if (mItem[i].selectable) + else if (item[i].selectable) { - mText->write(mItem[i].rect.x, mItem[i].rect.y, mItem[i].label); + text->write(item[i].rect.x, item[i].rect.y, item[i].label); } - else if (mItem[i].greyed) + else if (item[i].greyed) { - mText->writeColored(mItem[i].rect.x, mItem[i].rect.y, mItem[i].label, mColorGreyed); + text->writeColored(item[i].rect.x, item[i].rect.y, item[i].label, colorGreyed); } - else // No seleccionable + else + // No seleccionable { - if ((mItem[i].linkedUp) && (i == mSelector.index + 1)) + if ((item[i].linkedUp) && (i == selector.index + 1)) { - const color_t color = {mSelector.itemR, mSelector.itemG, mSelector.itemB}; - mText->writeColored(mItem[i].rect.x, mItem[i].rect.y, mItem[i].label, color); + const color_t color = {selector.itemColor.r, selector.itemColor.g, selector.itemColor.b}; + text->writeColored(item[i].rect.x, item[i].rect.y, item[i].label, color); } else // No enlazado con el de arriba { - mText->write(mItem[i].rect.x, mItem[i].rect.y, mItem[i].label); + text->write(item[i].rect.x, item[i].rect.y, item[i].label); } } - - //borrar - //mText->write(0, 0, std::to_string(mSelector.h) + " " + std::to_string(mSelector.incH) + " " + std::to_string(mSelector.resizing)); - //mText->write(0, 8, std::to_string(mSelector.y) + " " + std::to_string(mSelector.despY) + " " + std::to_string(mSelector.moving)); } } // Establece el rectangulo de fondo del menu y el selector void Menu::setRectSize() { - mRectBG.rect.w = findWidth() + mText->getCharacterWidth(); - mRectBG.rect.h = findHeight() + mText->getCharacterWidth(); + rectBG.rect.w = findWidth() + text->getCharacterWidth(); + rectBG.rect.h = findHeight() + text->getCharacterWidth(); // La posición X es la del menú menos medio caracter - mRectBG.rect.x = mPosX - (mText->getCharacterWidth() / 2); + rectBG.rect.x = x - (text->getCharacterWidth() / 2); // La posición Y es la del menu menos la altura de medio caracter - mRectBG.rect.y = mPosY - (mText->getCharacterWidth() / 2); + rectBG.rect.y = y - (text->getCharacterWidth() / 2); // Establecemos los valores del rectangulo del selector a partir de los valores del rectangulo de fondo - setSelectorPos(mSelector.index); -} - -// Establece el valor de la variable -void Menu::setTotalItems(int num) -{ - mTotalItems = num; - if (mTotalItems > MENU_MAX_ITEMS) - mTotalItems = MENU_MAX_ITEMS; + setSelectorPos(selector.index); } // Establece el color del rectangulo de fondo -void Menu::setBackgroundColor(int r, int g, int b, int alpha) +void Menu::setBackgroundColor(color_t color, int alpha) { - mRectBG.r = r; - mRectBG.g = g; - mRectBG.b = b; - mRectBG.a = alpha; + rectBG.color = color; + rectBG.a = alpha; } // Establece el color del rectangulo del selector -void Menu::setSelectorColor(int r, int g, int b, int alpha) +void Menu::setSelectorColor(color_t color, int alpha) { - mSelector.r = r; - mSelector.g = g; - mSelector.b = b; - mSelector.a = alpha; + selector.color = color; + selector.a = alpha; } // Establece el color del texto del selector -void Menu::setSelectorTextColor(int r, int g, int b) +void Menu::setSelectorTextColor(color_t color) { - mSelector.itemR = r; - mSelector.itemG = g; - mSelector.itemB = b; + selector.itemColor = color; } // Centra el menu respecto un punto en el eje X void Menu::centerMenuOnX(int value) { - mIsCenteredOnX = true; - mCenterX = value; - - // Actualiza el rectangulo de fondo para recalcular las dimensiones - //setRectSize(); + isCenteredOnX = true; + centerX = value; // Establece la nueva posición centrada en funcion del elemento más ancho - mPosX = (value) - (findWidth() / 2); + x = (value) - (findWidth() / 2); // Reposiciona los elementos del menu - for (int i = 0; i < MENU_MAX_ITEMS; i++) - mItem[i].rect.x = mPosX; + for (auto &i : item) + { + i.rect.x = x; + } // Recalcula el rectangulo de fondo setRectSize(); @@ -450,14 +705,11 @@ void Menu::centerMenuOnX(int value) // Centra el menu respecto un punto en el eje Y void Menu::centerMenuOnY(int value) { - mIsCenteredOnY = true; - mCenterY = value; - - // Actualiza el rectangulo de fondo para recalcular las dimensiones - //setRectSize(); + isCenteredOnY = true; + centerY = value; // Establece la nueva posición centrada en funcion del elemento más ancho - mPosY = (value) - (findHeight() / 2); + y = (value) - (findHeight() / 2); // Reposiciona los elementos del menu replaceElementsOnY(); @@ -469,131 +721,170 @@ void Menu::centerMenuOnY(int value) // Centra los elementos del menu en el eje X void Menu::centerMenuElementsOnX() { - mAreElementsCenteredOnX = true; + areElementsCenteredOnX = true; - for (int i = 0; i < mTotalItems; i++) - mItem[i].rect.x = (mCenterX - (mItem[i].rect.w / 2)); + for (auto &i : item) + { + i.rect.x = (centerX - (i.rect.w / 2)); + } } // Añade un item al menu -void Menu::addItem(std::string text, Uint8 hPaddingDown, bool selectable, bool greyed, bool linkedDown) +void Menu::addItem(std::string text, int hPaddingDown, bool selectable, bool greyed, bool linkedDown) { + item_t temp; // Si es el primer item coge la posición en el eje Y del propio menu - if (mTotalItems == 0) - mItem[mTotalItems].rect.y = mPosY; + if (item.size() == 0) + { + temp.rect.y = y; + } else - // En caso contrario, coge la posición en el eje Y a partir del elemento anterior - mItem[mTotalItems].rect.y = mItem[mTotalItems - 1].rect.y + mItem[mTotalItems - 1].rect.h + mItem[mTotalItems - 1].hPaddingDown; + // En caso contrario, coge la posición en el eje Y a partir del elemento anterior + { + temp.rect.y = item.back().rect.y + item.back().rect.h + item.back().hPaddingDown; + } - setItemCaption(mTotalItems, text); - mItem[mTotalItems].rect.x = mPosX; - mItem[mTotalItems].hPaddingDown = hPaddingDown; - mItem[mTotalItems].selectable = selectable; - mItem[mTotalItems].greyed = greyed; - mItem[mTotalItems].linkedDown = linkedDown; - if (mTotalItems > 0) - if (mItem[mTotalItems - 1].linkedDown) - mItem[mTotalItems].linkedUp = true; + temp.rect.x = x; + temp.hPaddingDown = hPaddingDown; + temp.selectable = selectable; + temp.greyed = greyed; + temp.linkedDown = linkedDown; - setTotalItems(mTotalItems + 1); - mCenterX = mPosX + (findWidth() / 2); - //setSelectorPos(0); + item.push_back(temp); + setItemCaption(item.size() - 1, text); + + if (item.size() > 0) + { + if (item[item.size() - 1].linkedDown) + { + item[item.size()].linkedUp = true; + } + } + + centerX = x + (findWidth() / 2); reorganize(); } // Cambia el texto de un item -void Menu::setItemCaption(Uint8 index, std::string text) +void Menu::setItemCaption(int index, std::string text) { - mItem[index].label = text; - mItem[index].rect.w = mText->lenght(mItem[index].label); - mItem[index].rect.h = mText->getCharacterWidth(); + item[index].label = text; + item[index].rect.w = this->text->lenght(item[index].label); + item[index].rect.h = this->text->getCharacterWidth(); reorganize(); + + const std::string texto = item[index].label + ":" + std::to_string(item[index].rect.w); + printf("Adding menu item -> %s\n", texto.c_str()); } // Establece el indice del itemm que se usará por defecto al cancelar el menu -void Menu::setDefaultActionWhenCancel(Uint8 item) +void Menu::setDefaultActionWhenCancel(int item) { - mDefaultActionWhenCancel = item; + defaultActionWhenCancel = item; } // Gestiona la entrada de teclado y mando durante el menu void Menu::checkInput() { - if (mInput->checkInput(INPUT_UP, REPEAT_FALSE)) + if (input->checkInput(INPUT_UP, REPEAT_FALSE)) { if (decreaseSelectorIndex()) - JA_PlaySound(mSoundMove); + { + if (soundMove) + { + JA_PlaySound(soundMove); + } + } } - if (mInput->checkInput(INPUT_DOWN, REPEAT_FALSE)) + if (input->checkInput(INPUT_DOWN, REPEAT_FALSE)) { if (increaseSelectorIndex()) - JA_PlaySound(mSoundMove); + { + if (soundMove) + { + JA_PlaySound(soundMove); + } + } } - if (mInput->checkInput(INPUT_ACCEPT, REPEAT_FALSE)) + if (input->checkInput(INPUT_ACCEPT, REPEAT_FALSE)) { - mItemSelected = mSelector.index; - JA_PlaySound(mSoundAccept); + itemSelected = selector.index; + if (soundAccept) + { + JA_PlaySound(soundAccept); + } } - if (mInput->checkInput(INPUT_CANCEL, REPEAT_FALSE)) + if (input->checkInput(INPUT_CANCEL, REPEAT_FALSE)) { - mItemSelected = mDefaultActionWhenCancel; - JA_PlaySound(mSoundCancel); + itemSelected = defaultActionWhenCancel; + if (soundCancel) + { + JA_PlaySound(soundCancel); + } } } // Calcula el ancho del menu -Uint16 Menu::findWidth() +int Menu::findWidth() { return getWidestItem(); } // Calcula el alto del menu -Uint16 Menu::findHeight() +int Menu::findHeight() { - Uint16 height = 0; + int height = 0; // Obtenemos la altura de la suma de alturas de los items - for (int i = 0; i < mTotalItems; i++) - height += mItem[i].rect.h + mItem[i].hPaddingDown; + for (auto &i : item) + { + height += i.rect.h + i.hPaddingDown; + } - return height - mItem[mTotalItems - 1].hPaddingDown; + return height - item.back().hPaddingDown; } // Recoloca los elementos del menu en el eje Y void Menu::replaceElementsOnY() { - mItem[0].rect.y = mPosY; + item[0].rect.y = y; - for (int i = 1; i < mTotalItems; i++) - mItem[i].rect.y = mItem[i - 1].rect.y + mItem[i - 1].rect.h + mItem[i - 1].hPaddingDown; + for (int i = 1; i < item.size(); i++) + { + item[i].rect.y = item[i - 1].rect.y + item[i - 1].rect.h + item[i - 1].hPaddingDown; + } } // Establece el estado seleccionable de un item -void Menu::setSelectable(Uint8 index, bool value) +void Menu::setSelectable(int index, bool value) { - mItem[index].selectable = value; + item[index].selectable = value; } // Establece el estado agrisado de un item -void Menu::setGreyed(Uint8 index, bool value) +void Menu::setGreyed(int index, bool value) { - mItem[index].greyed = value; + item[index].greyed = value; } // Establece el estado de enlace de un item -void Menu::setLinkedDown(Uint8 index, bool value) +void Menu::setLinkedDown(int index, bool value) { - mItem[index].linkedDown = value; + item[index].linkedDown = value; } // Calcula la altura del selector int Menu::getSelectorHeight(int value) { - if (mItem[value].linkedDown) - return mItem[value].rect.h + mItem[value].hPaddingDown + mItem[value + 1].rect.h; + if (item[value].linkedDown) + { + return item[value].rect.h + item[value].hPaddingDown + item[value + 1].rect.h; + } else - return mItem[value].rect.h; + { + return item[value].rect.h; + } } \ No newline at end of file diff --git a/source/menu.h b/source/menu.h index 6157ba1..09a001c 100644 --- a/source/menu.h +++ b/source/menu.h @@ -1,100 +1,112 @@ #pragma once + #include +#include #include "sprite.h" #include "text.h" +#include "asset.h" #include "input.h" +#include "utils.h" #include "jail_audio.h" +#include +#include #ifndef MENU_H #define MENU_H -#define MENU_MAX_ITEMS 50 - -#define MENU_NO_OPTION -1 - +// Tipos de fondos para el menu #define MENU_BACKGROUND_TRANSPARENT 0 #define MENU_BACKGROUND_SOLID 1 -// Clase menu +// Tipos de archivos de audio +#define SOUND_ACCEPT 0 +#define SOUND_MOVE 1 +#define SOUND_CANCEL 2 + +// Opciones de menu +#define MENU_NO_OPTION -1 + +// Clase Menu class Menu { private: - std::string mName; // Nombre del menu - int mPosX; // Posición en el eje X de la primera letra del primer elemento - int mPosY; // Posición en el eje Y de la primera letra del primer elemento - Uint16 mHeight; // Altura del menu - Uint16 mWidth; // Anchura del menu - Uint8 mTotalItems; // Numero total de items del menu - int mItemSelected; // Índice del item del menu que ha sido seleccionado - Uint8 mDefaultActionWhenCancel; // Indice del item del menu que se selecciona cuando se cancela el menu - Uint8 mBackgroundType; // Tipo de fondo para el menu - bool mIsCenteredOnX; // Variable para saber si el menu debe estar centrado respecto a un punto en el eje X - bool mIsCenteredOnY; // Variable para saber si el menu debe estar centrado respecto a un punto en el eje Y - int mCenterX; // Centro del menu en el eje X - int mCenterY; // Centro del menu en el eje Y - bool mAreElementsCenteredOnX; // Variable para saber si los elementos van centrados en el eje X - Uint16 mWidestItem; // Anchura del elemento más ancho - JA_Sound mSoundAccept; // Sonido al aceptar o elegir una opción del menu - JA_Sound mSoundCancel; // Sonido al cancelar el menu - JA_Sound mSoundMove; // Sonido al mover el selector - SDL_Renderer *mRenderer; // Puntero al renderizador de la ventana - std::string *mFileList; // Lista de ficheros - Text *mText; // Texto para poder escribir los items del menu - Input *mInput; // Gestor de eventos de entrada de teclado o gamepad - color_t mColorGreyed; // Color para los elementos agrisados - - struct rectangle + struct rectangle_t { SDL_Rect rect; // Rectangulo - Uint8 r; // Rojo - Uint8 g; // Verde - Uint8 b; // Azul - Uint8 a; // Transparencia + color_t color; // Color + int a; // Transparencia }; - rectangle mRectBG; // Rectangulo de fondo del menu - struct item + struct item_t { - std::string label; // Texto - SDL_Rect rect; // Rectangulo que delimita el elemento - Uint8 hPaddingDown; // Espaciado bajo el elemento - bool selectable; // Indica si se puede seleccionar - bool greyed; // Indica si ha de aparecer con otro color mas oscuro - bool linkedDown; // Indica si el elemento actual y el siguiente se tratan como uno solo. Afecta al selector - bool linkedUp; // Indica si el elemento actual y el anterior se tratan como uno solo. Afecta al selector + std::string label; // Texto + SDL_Rect rect; // Rectangulo que delimita el elemento + int hPaddingDown; // Espaciado bajo el elemento + bool selectable; // Indica si se puede seleccionar + bool greyed; // Indica si ha de aparecer con otro color mas oscuro + bool linkedDown; // Indica si el elemento actual y el siguiente se tratan como uno solo. Afecta al selector + bool linkedUp; // Indica si el elemento actual y el anterior se tratan como uno solo. Afecta al selector }; - item mItem[MENU_MAX_ITEMS]; // Estructura para cada elemento del menu - struct selector + struct selector_t { - float originY; // Coordenada de origen - float targetY; // Coordenada de destino - float despY; // Cantidad de pixeles que se desplaza el selector en cada salto: (target - origin) / numJumps - bool moving; // Indica si el selector está avanzando hacia el destino - float originH; // Altura de origen - float targetH; // Altura de destino - float incH; // Cantidad de pixels que debe incrementar o decrementar el selector en cada salto - bool resizing; // Indica si el selector está cambiando de tamaño - float y; // Coordenada actual, usado para el desplazamiento - float h; // Altura actual, usado para el cambio de tamaño - Uint8 numJumps; // Numero de pasos preestablecido para llegar al destino - Uint8 index; // Elemento del menu que tiene el foco - SDL_Rect rect; // Rectangulo del selector - Uint8 r; // Cantidad de color rojo para el rectangulo del selector - Uint8 g; // Cantidad de color verde para el rectangulo del selector - Uint8 b; // Cantidad de color azul para el rectangulo del selector - Uint8 a; // Cantidad de transparencia para el rectangulo del selector - Uint8 itemR; // Cantidad de color rojo para el texto del elemento seleccionado - Uint8 itemG; // Cantidad de color verde para el texto del elemento seleccionado - Uint8 itemB; // Cantidad de color azul para el texto del elemento seleccionado + float originY; // Coordenada de origen + float targetY; // Coordenada de destino + float despY; // Cantidad de pixeles que se desplaza el selector en cada salto: (target - origin) / numJumps + bool moving; // Indica si el selector está avanzando hacia el destino + float originH; // Altura de origen + float targetH; // Altura de destino + float incH; // Cantidad de pixels que debe incrementar o decrementar el selector en cada salto + bool resizing; // Indica si el selector está cambiando de tamaño + float y; // Coordenada actual, usado para el desplazamiento + float h; // Altura actual, usado para el cambio de tamaño + int numJumps; // Numero de pasos preestablecido para llegar al destino + int index; // Elemento del menu que tiene el foco + SDL_Rect rect; // Rectangulo del selector + color_t color; // Color del selector + color_t itemColor; // Color del item + int a; // Cantidad de transparencia para el rectangulo del selector }; - selector mSelector; // Variables para pintar el selector del menu - // Carga los recursos necesarios para la sección 'Title' - bool loadMedia(); + std::string name; // Nombre del menu + int x; // Posición en el eje X de la primera letra del primer elemento + int y; // Posición en el eje Y de la primera letra del primer elemento + int h; // Altura del menu + int w; // Anchura del menu + int itemSelected; // Índice del item del menu que ha sido seleccionado + int defaultActionWhenCancel; // Indice del item del menu que se selecciona cuando se cancela el menu + int backgroundType; // Tipo de fondo para el menu + int centerX; // Centro del menu en el eje X + int centerY; // Centro del menu en el eje Y + bool isCenteredOnX; // Variable para saber si el menu debe estar centrado respecto a un punto en el eje X + bool isCenteredOnY; // Variable para saber si el menu debe estar centrado respecto a un punto en el eje Y + bool areElementsCenteredOnX; // Variable para saber si los elementos van centrados en el eje X + int widestItem; // Anchura del elemento más ancho + JA_Sound soundAccept; // Sonido al aceptar o elegir una opción del menu + JA_Sound soundCancel; // Sonido al cancelar el menu + JA_Sound soundMove; // Sonido al mover el selector + SDL_Renderer *renderer; // Puntero al renderizador de la ventana + Text *text; // Texto para poder escribir los items del menu + Input *input; // Gestor de eventos de entrada de teclado o gamepad + Asset *asset; // Objeto para gestionar los ficheros de recursos + color_t colorGreyed; // Color para los elementos agrisados + rectangle_t rectBG; // Rectangulo de fondo del menu + std::vector item; // Estructura para cada elemento del menu + selector_t selector; // Variables para pintar el selector del menu + std::string font_png; + std::string font_txt; - // Establece el valor de la variable - void setTotalItems(int num); + // Carga la configuración del menu desde un archivo de texto + bool load(std::string file_path); + + // Asigna variables a partir de dos cadenas + bool setVars(std::string var, std::string value); + + // Asigna variables a partir de dos cadenas + bool setItem(item_t *item, std::string var, std::string value); + + // Inicializa las variables + void init(); // Establece el rectangulo de fondo del menu void setRectSize(); @@ -112,16 +124,16 @@ private: void updateSelector(); // Obtiene la anchura del elemento más ancho del menu - Uint16 getWidestItem(); + int getWidestItem(); // Gestiona la entrada de teclado y mando durante el menu void checkMenuInput(Menu *menu); // Calcula el ancho del menu - Uint16 findWidth(); + int findWidth(); // Calcula el alto del menu - Uint16 findHeight(); + int findHeight(); // Recoloca los elementos del menu en el eje Y void replaceElementsOnY(); @@ -131,19 +143,19 @@ private: public: // Constructor - Menu(SDL_Renderer *renderer, Text *text, Input *input, std::string *fileList); + Menu(SDL_Renderer *renderer, Asset *asset, Input *input, std::string file=""); // Destructor ~Menu(); - // Inicializador - void init(std::string name, int x, int y, int backgroundType); + // Carga los ficheros de audio + void loadAudioFile(std::string file, int sound); // Obtiene el nombre del menu std::string getName(); // Obtiene el valor de la variable - Uint8 getItemSelected(); + int getItemSelected(); // Deja el menu apuntando al primer elemento void reset(); @@ -158,13 +170,13 @@ public: void render(); // Establece el color del rectangulo de fondo - void setBackgroundColor(int r, int g, int b, int alpha); + void setBackgroundColor(color_t color, int alpha); // Establece el color del rectangulo del selector - void setSelectorColor(int r, int g, int b, int alpha); + void setSelectorColor(color_t color, int alpha); // Establece el color del texto del selector - void setSelectorTextColor(int r, int g, int b); + void setSelectorTextColor(color_t color); // Centra el menu respecto a un punto en el eje X void centerMenuOnX(int value); @@ -176,25 +188,27 @@ public: void centerMenuElementsOnX(); // Añade un item al menu - void addItem(std::string text, Uint8 hPaddingDown = 1, bool selectable = true, bool greyed = false, bool linkedDown = false); + void addItem(std::string text, int hPaddingDown = 1, bool selectable = true, bool greyed = false, bool linkedDown = false); // Cambia el texto de un item - void setItemCaption(Uint8 index, std::string text); + void setItemCaption(int index, std::string text); // Establece el indice del item que se usará por defecto al cancelar el menu - void setDefaultActionWhenCancel(Uint8 item); + void setDefaultActionWhenCancel(int item); // Coloca el selector en una posición específica - void setSelectorPos(Uint8 index); + void setSelectorPos(int index); // Establece el estado seleccionable de un item - void setSelectable(Uint8 index, bool value); + void setSelectable(int index, bool value); // Establece el estado agrisado de un item - void setGreyed(Uint8 index, bool value); + void setGreyed(int index, bool value); // Establece el estado de enlace de un item - void setLinkedDown(Uint8 index, bool value); + void setLinkedDown(int index, bool value); + + // hacer procedimientos para establecer el titulo, la x, la y, la tipografia y el tipo de fondo }; #endif