2009-10-01 01:10:58 +02:00
|
|
|
/****************************************************************************
|
|
|
|
* USB Loader GX Team
|
|
|
|
*
|
|
|
|
* libwiigui Template
|
|
|
|
* by Tantric 2009
|
|
|
|
*
|
|
|
|
* menu.cpp
|
|
|
|
* Menu flow routines - handles all menu logic
|
|
|
|
***************************************************************************/
|
|
|
|
#include <unistd.h>
|
|
|
|
|
2011-06-14 19:53:19 +02:00
|
|
|
#include "GUI/gui.h"
|
2009-10-01 01:10:58 +02:00
|
|
|
#include "homebrewboot/BootHomebrew.h"
|
2011-03-14 22:19:21 +01:00
|
|
|
#include "homebrewboot/HomebrewBrowser.hpp"
|
2009-10-01 01:10:58 +02:00
|
|
|
#include "prompts/ProgressWindow.h"
|
2011-01-21 20:43:59 +01:00
|
|
|
#include "menu/GameBrowseMenu.hpp"
|
2009-11-15 20:52:58 +01:00
|
|
|
#include "menu/menus.h"
|
2009-10-01 01:10:58 +02:00
|
|
|
#include "mload/mload.h"
|
2010-02-15 00:22:52 +01:00
|
|
|
#include "mload/mload_modules.h"
|
2009-10-01 01:10:58 +02:00
|
|
|
#include "network/networkops.h"
|
2009-11-15 20:52:58 +01:00
|
|
|
#include "patches/patchcode.h"
|
2011-06-03 22:31:09 +02:00
|
|
|
#include "settings/menus/GlobalSettings.hpp"
|
2010-09-24 23:22:01 +02:00
|
|
|
#include "settings/CGameSettings.h"
|
2010-09-24 19:58:56 +02:00
|
|
|
#include "themes/CTheme.h"
|
2011-02-05 15:46:06 +01:00
|
|
|
#include "themes/ThemeMenu.h"
|
2011-01-02 10:23:44 +01:00
|
|
|
#include "themes/ThemeDownloader.h"
|
2009-11-15 20:52:58 +01:00
|
|
|
#include "usbloader/disc.h"
|
2010-09-18 13:46:25 +02:00
|
|
|
#include "usbloader/GameList.h"
|
2010-12-31 00:49:22 +01:00
|
|
|
#include "usbloader/MountGamePartition.h"
|
2010-10-01 17:01:19 +02:00
|
|
|
#include "mload/mload_modules.h"
|
2010-05-29 09:38:54 +02:00
|
|
|
#include "audio.h"
|
2009-11-15 20:52:58 +01:00
|
|
|
#include "gecko.h"
|
|
|
|
#include "menu.h"
|
2009-10-01 01:10:58 +02:00
|
|
|
#include "sys.h"
|
|
|
|
#include "wpad.h"
|
2009-11-21 23:59:57 +01:00
|
|
|
#include "settings/newtitles.h"
|
2009-12-19 15:05:31 +01:00
|
|
|
#include "usbloader/frag.h"
|
|
|
|
#include "usbloader/wbfs.h"
|
2010-09-19 01:04:39 +02:00
|
|
|
#include "wad/nandtitle.h"
|
2009-10-01 01:10:58 +02:00
|
|
|
|
|
|
|
/*** Variables that are also used extern ***/
|
|
|
|
GuiWindow * mainWindow = NULL;
|
2011-12-28 17:27:30 +01:00
|
|
|
WiiPointer * pointer[4] = { NULL, NULL, NULL, NULL };
|
2009-10-01 01:10:58 +02:00
|
|
|
GuiImage * bgImg = NULL;
|
|
|
|
GuiImageData * background = NULL;
|
2010-02-15 00:22:52 +01:00
|
|
|
GuiBGM * bgMusic = NULL;
|
2010-11-13 23:34:53 +01:00
|
|
|
GuiSound *btnSoundClick = NULL;
|
|
|
|
GuiSound *btnSoundClick2 = NULL;
|
|
|
|
GuiSound *btnSoundOver = NULL;
|
2009-11-10 00:03:13 +01:00
|
|
|
|
2011-12-20 22:41:00 +01:00
|
|
|
static int currentMenu = 0;
|
2009-10-01 01:10:58 +02:00
|
|
|
|
|
|
|
static lwp_t guithread = LWP_THREAD_NULL;
|
|
|
|
static bool guiHalt = true;
|
2010-11-06 16:30:14 +01:00
|
|
|
static bool ExitRequested = false;
|
2009-10-01 01:10:58 +02:00
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* ResumeGui
|
|
|
|
*
|
|
|
|
* Signals the GUI thread to start, and resumes the thread. This is called
|
|
|
|
* after finishing the removal/insertion of new elements, and after initial
|
|
|
|
* GUI setup.
|
|
|
|
***************************************************************************/
|
2010-09-19 01:16:05 +02:00
|
|
|
void ResumeGui()
|
|
|
|
{
|
2011-07-26 00:28:22 +02:00
|
|
|
guiHalt = false;
|
|
|
|
LWP_ResumeThread(guithread);
|
2009-10-01 01:10:58 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* HaltGui
|
|
|
|
*
|
|
|
|
* Signals the GUI thread to stop, and waits for GUI thread to stop
|
|
|
|
* This is necessary whenever removing/inserting new elements into the GUI.
|
|
|
|
* This eliminates the possibility that the GUI is in the middle of accessing
|
|
|
|
* an element that is being changed.
|
|
|
|
***************************************************************************/
|
2010-09-19 01:16:05 +02:00
|
|
|
void HaltGui()
|
|
|
|
{
|
2011-07-26 00:28:22 +02:00
|
|
|
if (guiHalt) return;
|
|
|
|
guiHalt = true;
|
2009-10-01 01:10:58 +02:00
|
|
|
|
2011-07-26 00:28:22 +02:00
|
|
|
// wait for thread to finish
|
|
|
|
while (!LWP_ThreadIsSuspended(guithread))
|
|
|
|
usleep(100);
|
2009-10-01 01:10:58 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* UpdateGUI
|
|
|
|
*
|
|
|
|
* Primary thread to allow GUI to respond to state changes, and draws GUI
|
|
|
|
***************************************************************************/
|
2010-09-24 02:48:03 +02:00
|
|
|
static void * UpdateGUI(void *arg)
|
2010-09-17 19:48:16 +02:00
|
|
|
{
|
2015-03-08 17:49:07 +01:00
|
|
|
u8 i;
|
2011-07-26 00:28:22 +02:00
|
|
|
|
|
|
|
while (!ExitRequested)
|
|
|
|
{
|
|
|
|
if (guiHalt)
|
|
|
|
{
|
|
|
|
LWP_SuspendThread(guithread);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2011-12-28 17:27:30 +01:00
|
|
|
UpdatePads();
|
2011-07-26 00:28:22 +02:00
|
|
|
|
2011-12-28 17:27:30 +01:00
|
|
|
mainWindow->Draw();
|
|
|
|
if (Settings.tooltips && Theme::ShowTooltips && mainWindow->GetState() != STATE_DISABLED)
|
|
|
|
mainWindow->DrawTooltip();
|
2012-02-09 22:18:16 +01:00
|
|
|
|
2011-12-28 17:27:30 +01:00
|
|
|
// Pointer modifies wpad data struct for easy implementation of "virtual pointer" with PAD-Sticks
|
|
|
|
// That is why it has to be called right before updating other gui elements with the triggers
|
2015-03-08 17:49:07 +01:00
|
|
|
i = 4;
|
|
|
|
while(i--)
|
2011-12-28 17:27:30 +01:00
|
|
|
pointer[i]->Draw(&userInput[i]);
|
2011-07-26 00:28:22 +02:00
|
|
|
|
|
|
|
for (i = 0; i < 4; i++)
|
|
|
|
mainWindow->Update(&userInput[i]);
|
|
|
|
|
2011-12-28 17:27:30 +01:00
|
|
|
Menu_Render();
|
|
|
|
|
2011-07-26 00:28:22 +02:00
|
|
|
if (bgMusic) bgMusic->UpdateState();
|
2011-01-02 10:23:44 +01:00
|
|
|
}
|
2010-01-19 11:48:50 +01:00
|
|
|
|
2011-07-26 00:28:22 +02:00
|
|
|
for (i = 5; i < 255; i += 10)
|
|
|
|
{
|
|
|
|
mainWindow->Draw();
|
|
|
|
Menu_DrawRectangle(0, 0, screenwidth, screenheight, (GXColor) {0, 0, 0, i}, 1);
|
|
|
|
Menu_Render();
|
|
|
|
}
|
2010-11-06 16:30:14 +01:00
|
|
|
|
2011-07-26 00:28:22 +02:00
|
|
|
mainWindow->RemoveAll();
|
|
|
|
ShutoffRumble();
|
2010-09-17 19:48:16 +02:00
|
|
|
|
2011-07-26 00:28:22 +02:00
|
|
|
return NULL;
|
2009-10-01 01:10:58 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* InitGUIThread
|
|
|
|
*
|
|
|
|
* Startup GUI threads
|
|
|
|
***************************************************************************/
|
2010-09-19 01:16:05 +02:00
|
|
|
void InitGUIThreads()
|
|
|
|
{
|
2011-07-26 00:28:22 +02:00
|
|
|
ExitRequested = false;
|
2009-10-01 01:10:58 +02:00
|
|
|
|
2011-07-26 00:28:22 +02:00
|
|
|
if(guithread == LWP_THREAD_NULL)
|
|
|
|
LWP_CreateThread(&guithread, UpdateGUI, NULL, NULL, 65536, LWP_PRIO_HIGHEST);
|
2009-10-01 01:10:58 +02:00
|
|
|
}
|
|
|
|
|
2010-09-19 01:16:05 +02:00
|
|
|
void ExitGUIThreads()
|
|
|
|
{
|
2011-07-26 00:28:22 +02:00
|
|
|
ExitRequested = true;
|
|
|
|
|
|
|
|
if(guithread != LWP_THREAD_NULL)
|
|
|
|
{
|
|
|
|
ResumeGui();
|
|
|
|
LWP_JoinThread(guithread, NULL);
|
|
|
|
guithread = LWP_THREAD_NULL;
|
|
|
|
}
|
2009-10-01 01:10:58 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* MainMenu
|
|
|
|
***************************************************************************/
|
2010-09-24 02:48:03 +02:00
|
|
|
int MainMenu(int menu)
|
2010-09-19 01:16:05 +02:00
|
|
|
{
|
2011-07-26 00:28:22 +02:00
|
|
|
currentMenu = menu;
|
|
|
|
|
|
|
|
InitGUIThreads();
|
|
|
|
|
|
|
|
InitProgressThread();
|
|
|
|
InitNetworkThread();
|
|
|
|
|
|
|
|
if (Settings.autonetwork)
|
|
|
|
ResumeNetworkThread();
|
|
|
|
|
2012-05-06 12:59:58 +02:00
|
|
|
btnSoundClick = new GuiSound(NULL, 0, Settings.sfxvolume);
|
|
|
|
btnSoundClick->LoadSoundEffect(Resources::GetFile("button_click.wav"), Resources::GetFileSize("button_click.wav"));
|
|
|
|
btnSoundClick2 = new GuiSound(NULL, 0, Settings.sfxvolume);
|
|
|
|
btnSoundClick2->LoadSoundEffect(Resources::GetFile("button_click2.wav"), Resources::GetFileSize("button_click2.wav"));
|
|
|
|
btnSoundOver = new GuiSound(NULL, 0, Settings.sfxvolume);
|
|
|
|
btnSoundOver->LoadSoundEffect(Resources::GetFile("button_over.wav"), Resources::GetFileSize("button_over.wav"));
|
2011-07-26 00:28:22 +02:00
|
|
|
|
2011-12-28 17:27:30 +01:00
|
|
|
pointer[0] = new WiiPointer("player1_point.png");
|
|
|
|
pointer[1] = new WiiPointer("player2_point.png");
|
|
|
|
pointer[2] = new WiiPointer("player3_point.png");
|
|
|
|
pointer[3] = new WiiPointer("player4_point.png");
|
2011-07-26 00:28:22 +02:00
|
|
|
|
|
|
|
mainWindow = new GuiWindow(screenwidth, screenheight);
|
|
|
|
|
|
|
|
background = Resources::GetImageData(Settings.widescreen ? "wbackground.png" : "background.png");
|
|
|
|
|
|
|
|
bgImg = new GuiImage(background);
|
|
|
|
mainWindow->Append(bgImg);
|
|
|
|
|
|
|
|
ResumeGui();
|
|
|
|
|
|
|
|
bgMusic = new GuiBGM(Resources::GetFile("bg_music.ogg"), Resources::GetFileSize("bg_music.ogg"), Settings.volume);
|
|
|
|
bgMusic->SetLoop(Settings.musicloopmode); //loop music
|
|
|
|
bgMusic->Load(Settings.ogg_path);
|
|
|
|
bgMusic->Play();
|
|
|
|
|
|
|
|
MountGamePartition();
|
|
|
|
|
|
|
|
while (currentMenu != MENU_EXIT)
|
|
|
|
{
|
|
|
|
bgMusic->SetVolume(Settings.volume);
|
|
|
|
|
|
|
|
switch (currentMenu)
|
|
|
|
{
|
|
|
|
case MENU_SETTINGS:
|
2011-11-12 19:14:09 +01:00
|
|
|
currentMenu = GlobalSettings::Execute();
|
2011-07-26 00:28:22 +02:00
|
|
|
break;
|
|
|
|
case MENU_THEMEMENU:
|
2011-11-12 19:14:09 +01:00
|
|
|
currentMenu = ThemeMenu::Execute();
|
2011-07-26 00:28:22 +02:00
|
|
|
break;
|
2015-07-13 16:26:30 +02:00
|
|
|
// case MENU_THEMEDOWNLOADER:
|
|
|
|
// currentMenu = ThemeDownloader::Execute();
|
|
|
|
// break;
|
2011-07-26 00:28:22 +02:00
|
|
|
case MENU_HOMEBREWBROWSE:
|
|
|
|
currentMenu = HomebrewBrowser::Execute();
|
|
|
|
break;
|
|
|
|
case MENU_DISCLIST:
|
|
|
|
default: // unrecognized menu
|
|
|
|
currentMenu = GameBrowseMenu::Execute();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//! THIS SHOULD NEVER HAPPEN ANYMORE
|
|
|
|
ExitApp();
|
|
|
|
|
|
|
|
return -1;
|
2009-10-01 01:10:58 +02:00
|
|
|
}
|