2020-09-15 20:57:54 +00:00
|
|
|
// SPDX-License-Identifier: MIT
|
2020-05-24 08:29:29 +00:00
|
|
|
//
|
2020-09-15 20:57:54 +00:00
|
|
|
// EmulationStation Desktop Edition
|
2020-06-21 12:25:28 +00:00
|
|
|
// ViewController.cpp
|
2020-05-24 08:29:29 +00:00
|
|
|
//
|
2020-06-21 12:25:28 +00:00
|
|
|
// Handles overall system navigation including animations and transitions.
|
2021-03-10 17:21:49 +00:00
|
|
|
// Creates the gamelist views and handles refresh and reloads of these when needed
|
2020-06-21 12:25:28 +00:00
|
|
|
// (for example when metadata has been changed or when a list sorting has taken place).
|
|
|
|
// Initiates the launching of games, calling FileData to do the actual launch.
|
2021-03-10 17:21:49 +00:00
|
|
|
// Displays a dialog when there are no games found on startup.
|
2020-05-24 08:29:29 +00:00
|
|
|
//
|
|
|
|
|
2014-06-25 16:29:58 +00:00
|
|
|
#include "views/ViewController.h"
|
|
|
|
|
2017-11-01 22:21:10 +00:00
|
|
|
#include "animations/Animation.h"
|
|
|
|
#include "animations/LambdaAnimation.h"
|
2014-06-25 16:29:58 +00:00
|
|
|
#include "animations/MoveCameraAnimation.h"
|
2020-08-15 13:41:11 +00:00
|
|
|
#include "guis/GuiInfoPopup.h"
|
2017-11-01 22:21:10 +00:00
|
|
|
#include "guis/GuiMenu.h"
|
|
|
|
#include "views/gamelist/DetailedGameListView.h"
|
2018-03-22 07:03:12 +00:00
|
|
|
#include "views/gamelist/GridGameListView.h"
|
2020-09-15 20:57:54 +00:00
|
|
|
#include "views/gamelist/IGameListView.h"
|
2017-11-01 22:21:10 +00:00
|
|
|
#include "views/gamelist/VideoGameListView.h"
|
|
|
|
#include "views/SystemView.h"
|
2017-11-18 22:23:56 +00:00
|
|
|
#include "views/UIModeController.h"
|
2017-09-08 13:20:07 +00:00
|
|
|
#include "FileFilterIndex.h"
|
2020-07-14 17:16:21 +00:00
|
|
|
#include "InputManager.h"
|
2017-11-01 22:21:10 +00:00
|
|
|
#include "Log.h"
|
|
|
|
#include "Settings.h"
|
2020-07-14 17:16:21 +00:00
|
|
|
#include "Sound.h"
|
2017-11-01 22:21:10 +00:00
|
|
|
#include "SystemData.h"
|
2020-11-17 16:30:23 +00:00
|
|
|
#include "SystemView.h"
|
2017-11-01 22:21:10 +00:00
|
|
|
#include "Window.h"
|
2014-06-25 16:29:58 +00:00
|
|
|
|
2020-05-24 08:29:29 +00:00
|
|
|
ViewController* ViewController::sInstance = nullptr;
|
2020-12-29 13:51:29 +00:00
|
|
|
#if defined(_MSC_VER) // MSVC compiler.
|
|
|
|
const std::string ViewController::FAVORITE_CHAR = Utils::String::wideStringToString(L"\uF005");
|
|
|
|
const std::string ViewController::FOLDER_CHAR = Utils::String::wideStringToString(L"\uF07C");
|
|
|
|
const std::string ViewController::TICKMARK_CHAR = Utils::String::wideStringToString(L"\uF14A");
|
|
|
|
const std::string ViewController::CONTROLLER_CHAR = Utils::String::wideStringToString(L"\uF11b");
|
|
|
|
const std::string ViewController::FILTER_CHAR = Utils::String::wideStringToString(L"\uF0b0");
|
|
|
|
#else
|
2020-12-16 20:19:48 +00:00
|
|
|
const std::string ViewController::FAVORITE_CHAR = "\uF005";
|
|
|
|
const std::string ViewController::FOLDER_CHAR = "\uF07C";
|
2020-12-29 13:51:29 +00:00
|
|
|
const std::string ViewController::TICKMARK_CHAR = "\uF14A";
|
|
|
|
const std::string ViewController::CONTROLLER_CHAR = "\uF11b";
|
|
|
|
const std::string ViewController::FILTER_CHAR = "\uF0b0";
|
|
|
|
#endif
|
2014-06-25 16:29:58 +00:00
|
|
|
|
|
|
|
ViewController* ViewController::get()
|
|
|
|
{
|
2020-06-21 12:25:28 +00:00
|
|
|
assert(sInstance);
|
|
|
|
return sInstance;
|
2014-06-25 16:29:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void ViewController::init(Window* window)
|
|
|
|
{
|
2020-06-21 12:25:28 +00:00
|
|
|
assert(!sInstance);
|
|
|
|
sInstance = new ViewController(window);
|
2014-06-25 16:29:58 +00:00
|
|
|
}
|
|
|
|
|
2020-05-24 08:29:29 +00:00
|
|
|
ViewController::ViewController(
|
2020-06-21 12:25:28 +00:00
|
|
|
Window* window)
|
|
|
|
: GuiComponent(window),
|
|
|
|
mCurrentView(nullptr),
|
2020-11-15 21:54:39 +00:00
|
|
|
mPreviousView(nullptr),
|
2020-11-18 21:26:58 +00:00
|
|
|
mSkipView(nullptr),
|
2020-06-21 12:25:28 +00:00
|
|
|
mCamera(Transform4x4f::Identity()),
|
2020-11-18 22:47:32 +00:00
|
|
|
mSystemViewTransition(false),
|
2020-11-15 21:54:39 +00:00
|
|
|
mWrappedViews(false),
|
2020-06-21 12:25:28 +00:00
|
|
|
mFadeOpacity(0),
|
2020-11-18 21:26:58 +00:00
|
|
|
mCancelledTransition(false),
|
2020-11-17 16:30:23 +00:00
|
|
|
mLockInput(false),
|
2021-01-01 20:45:51 +00:00
|
|
|
mNextSystem(false),
|
2021-03-10 17:21:49 +00:00
|
|
|
mGameToLaunch(nullptr),
|
|
|
|
mNoGamesMessageBox(nullptr)
|
2014-06-25 16:29:58 +00:00
|
|
|
{
|
2020-06-21 12:25:28 +00:00
|
|
|
mState.viewing = NOTHING;
|
2021-01-12 17:40:25 +00:00
|
|
|
mState.viewstyle = AUTOMATIC;
|
2014-06-25 16:29:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
ViewController::~ViewController()
|
|
|
|
{
|
2020-06-21 12:25:28 +00:00
|
|
|
assert(sInstance == this);
|
|
|
|
sInstance = nullptr;
|
2014-06-25 16:29:58 +00:00
|
|
|
}
|
|
|
|
|
2021-03-10 17:21:49 +00:00
|
|
|
void ViewController::noSystemsFileDialog()
|
|
|
|
{
|
|
|
|
std::string errorMessage =
|
|
|
|
"COULDN'T FIND THE SYSTEMS CONFIGURATION FILE.\n"
|
|
|
|
"ATTEMPTED TO COPY A TEMPLATE es_systems.cfg FILE\n"
|
|
|
|
"FROM THE EMULATIONSTATION RESOURCES DIRECTORY,\n"
|
|
|
|
"BUT THIS FAILED. HAS EMULATIONSTATION BEEN PROPERLY\n"
|
|
|
|
"INSTALLED AND DO YOU HAVE WRITE PERMISSIONS TO \n"
|
|
|
|
"YOUR HOME DIRECTORY?";
|
|
|
|
|
|
|
|
mWindow->pushGui(new GuiMsgBox(mWindow, HelpStyle(),
|
|
|
|
errorMessage.c_str(),
|
|
|
|
"QUIT", [] {
|
|
|
|
SDL_Event quit;
|
|
|
|
quit.type = SDL_QUIT;
|
|
|
|
SDL_PushEvent(&quit);
|
|
|
|
}, "", nullptr, "", nullptr, true));
|
|
|
|
}
|
|
|
|
|
|
|
|
void ViewController::noGamesDialog()
|
|
|
|
{
|
|
|
|
mNoGamesErrorMessage =
|
|
|
|
"THE SYSTEMS CONFIGURATION FILE EXISTS, BUT NO\n"
|
|
|
|
"GAME FILES WERE FOUND. EITHER PLACE YOUR GAMES\n"
|
|
|
|
"IN THE CURRENTLY CONFIGURED ROM DIRECTORY OR\n"
|
|
|
|
"CHANGE IT USING THE BUTTON BELOW. OPTIONALLY THE\n"
|
|
|
|
"ROM DIRECTORY STRUCTURE CAN BE GENERATED WHICH\n"
|
2021-03-11 16:33:25 +00:00
|
|
|
"WILL CREATE A TEXT FILE FOR EACH SYSTEM PROVIDING\n"
|
2021-03-10 17:21:49 +00:00
|
|
|
"SOME INFO SUCH AS THE SUPPORTED FILE EXTENSIONS.\n"
|
|
|
|
"THIS IS THE CURRENTLY CONFIGURED ROM DIRECTORY:\n";
|
|
|
|
|
|
|
|
#if defined(_WIN64)
|
|
|
|
mRomDirectory = Utils::String::replace(FileData::getROMDirectory(), "/", "\\");
|
|
|
|
#else
|
|
|
|
mRomDirectory = FileData::getROMDirectory();
|
|
|
|
#endif
|
|
|
|
|
|
|
|
mNoGamesMessageBox = new GuiMsgBox(mWindow, HelpStyle(), mNoGamesErrorMessage + mRomDirectory,
|
|
|
|
"CHANGE ROM DIRECTORY", [this] {
|
|
|
|
std::string currentROMDirectory;
|
|
|
|
#if defined(_WIN64)
|
|
|
|
currentROMDirectory = Utils::String::replace(FileData::getROMDirectory(), "/", "\\");
|
|
|
|
#else
|
|
|
|
currentROMDirectory = FileData::getROMDirectory();
|
|
|
|
#endif
|
|
|
|
|
|
|
|
mWindow->pushGui(new GuiComplexTextEditPopup(
|
|
|
|
mWindow,
|
|
|
|
HelpStyle(),
|
|
|
|
"ENTER ROM DIRECTORY",
|
|
|
|
"Currently configured directory:",
|
|
|
|
currentROMDirectory,
|
|
|
|
currentROMDirectory,
|
|
|
|
[this](const std::string& newROMDirectory) {
|
|
|
|
Settings::getInstance()->setString("ROMDirectory", newROMDirectory);
|
|
|
|
Settings::getInstance()->saveFile();
|
|
|
|
#if defined(_WIN64)
|
|
|
|
mRomDirectory = Utils::String::replace(FileData::getROMDirectory(), "/", "\\");
|
|
|
|
#else
|
|
|
|
mRomDirectory = FileData::getROMDirectory();
|
|
|
|
#endif
|
|
|
|
mNoGamesMessageBox->changeText(mNoGamesErrorMessage + mRomDirectory);
|
|
|
|
mWindow->pushGui(new GuiMsgBox(mWindow, HelpStyle(),
|
2021-03-11 16:33:25 +00:00
|
|
|
"ROM DIRECTORY SETTING SAVED, RESTART\n"
|
|
|
|
"THE APPLICATION TO RESCAN THE SYSTEMS",
|
2021-03-10 17:21:49 +00:00
|
|
|
"OK", nullptr, "", nullptr, "", nullptr, true));
|
|
|
|
},
|
|
|
|
false,
|
|
|
|
"SAVE",
|
|
|
|
"SAVE CHANGES?",
|
|
|
|
"LOAD CURRENT",
|
|
|
|
"LOAD CURRENTLY CONFIGURED VALUE",
|
|
|
|
"CLEAR",
|
|
|
|
"CLEAR (LEAVE BLANK TO RESET TO DEFAULT DIRECTORY)",
|
|
|
|
false));
|
|
|
|
},
|
|
|
|
"CREATE DIRECTORIES", [this] {
|
|
|
|
mWindow->pushGui(new GuiMsgBox(mWindow, HelpStyle(),
|
|
|
|
"THIS WILL CREATE DIRECTORIES FOR ALL THE\n"
|
|
|
|
"GAME SYSTEMS DEFINED IN es_systems.cfg\n\n"
|
|
|
|
"THIS MAY CREATE A LOT OF FOLDERS SO IT'S\n"
|
|
|
|
"ADVICED TO DELETE THE ONES YOU DON'T NEED\n\n"
|
|
|
|
"PROCEED?",
|
|
|
|
"YES", [this] {
|
|
|
|
if (!SystemData::createSystemDirectories()) {
|
|
|
|
mWindow->pushGui(new GuiMsgBox(mWindow, HelpStyle(),
|
2021-03-15 18:51:54 +00:00
|
|
|
"THE SYSTEM DIRECTORIES WERE SUCCESSFULLY\n"
|
|
|
|
"GENERATED, EXIT THE APPLICATION AND PLACE\n"
|
|
|
|
"YOUR GAMES IN THE NEWLY CREATED FOLDERS", "OK", nullptr,
|
2021-03-10 17:21:49 +00:00
|
|
|
"", nullptr, "", nullptr, true));
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
mWindow->pushGui(new GuiMsgBox(mWindow, HelpStyle(),
|
|
|
|
"ERROR CREATING THE SYSTEM DIRECTORIES,\n"
|
|
|
|
"PERMISSION PROBLEMS OR DISK FULL?\n\n"
|
|
|
|
"SEE THE LOG FILE FOR MORE DETAILS", "OK", nullptr,
|
|
|
|
"", nullptr, "", nullptr, true));
|
|
|
|
}
|
|
|
|
}, "NO", nullptr, "", nullptr, true));
|
|
|
|
},
|
|
|
|
"QUIT", [] {
|
|
|
|
SDL_Event quit;
|
|
|
|
quit.type = SDL_QUIT;
|
|
|
|
SDL_PushEvent(&quit);
|
|
|
|
}, true, false);
|
|
|
|
|
|
|
|
mWindow->pushGui(mNoGamesMessageBox);
|
|
|
|
}
|
|
|
|
|
2014-06-25 16:29:58 +00:00
|
|
|
void ViewController::goToStart()
|
|
|
|
{
|
2020-07-14 17:16:21 +00:00
|
|
|
// Check if the keyboard config is set as application default, meaning no user
|
|
|
|
// configuration has been performed.
|
|
|
|
if (InputManager::getInstance()->
|
|
|
|
getInputConfigByDevice(DEVICE_KEYBOARD)->getDefaultConfigFlag()) {
|
2021-01-06 23:14:45 +00:00
|
|
|
LOG(LogInfo) << "Applying default keyboard mappings...";
|
2020-08-03 09:39:04 +00:00
|
|
|
|
2020-07-14 17:16:21 +00:00
|
|
|
if (Settings::getInstance()->getBool("ShowDefaultKeyboardWarning")) {
|
|
|
|
std::string message = "NO KEYBOARD CONFIGURATION COULD BE\n"
|
|
|
|
"FOUND IN ES_INPUT.CFG, SO APPLYING THE\n"
|
|
|
|
"DEFAULT KEYBOARD MAPPINGS. IT'S HOWEVER\n"
|
|
|
|
"RECOMMENDED TO SETUP YOUR OWN KEYBOARD\n"
|
|
|
|
"CONFIGURATION. TO DO SO, CHOOSE THE ENTRY\n"
|
2020-11-28 21:18:10 +00:00
|
|
|
"'CONFIGURE INPUT' ON THE MAIN MENU.";
|
2020-07-14 17:16:21 +00:00
|
|
|
|
|
|
|
mWindow->pushGui(new GuiMsgBox(mWindow, HelpStyle(), message.c_str(),
|
|
|
|
"OK", nullptr, "DON'T SHOW AGAIN", [] {
|
|
|
|
Settings::getInstance()->setBool("ShowDefaultKeyboardWarning", false);
|
|
|
|
Settings::getInstance()->saveFile();
|
|
|
|
}));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-12-15 17:44:56 +00:00
|
|
|
// If the system view does not exist, then create it. We do this here as it would
|
|
|
|
// otherwise not be done if jumping directly into a specific game system on startup.
|
|
|
|
if (!mSystemListView)
|
|
|
|
getSystemListView();
|
|
|
|
|
2020-06-21 12:25:28 +00:00
|
|
|
// If a specific system is requested, go directly to its game list.
|
|
|
|
auto requestedSystem = Settings::getInstance()->getString("StartupSystem");
|
|
|
|
if ("" != requestedSystem && "retropie" != requestedSystem) {
|
|
|
|
for (auto it = SystemData::sSystemVector.cbegin();
|
|
|
|
it != SystemData::sSystemVector.cend(); it++) {
|
|
|
|
if ((*it)->getName() == requestedSystem) {
|
|
|
|
goToGameList(*it);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Requested system doesn't exist.
|
|
|
|
Settings::getInstance()->setString("StartupSystem", "");
|
|
|
|
}
|
2020-09-27 10:49:14 +00:00
|
|
|
// Get the first system entry.
|
2020-11-15 21:54:39 +00:00
|
|
|
goToSystemView(getSystemListView()->getFirst(), false);
|
2014-06-25 16:29:58 +00:00
|
|
|
}
|
|
|
|
|
2017-11-18 22:23:56 +00:00
|
|
|
void ViewController::ReloadAndGoToStart()
|
|
|
|
{
|
2020-06-21 12:25:28 +00:00
|
|
|
mWindow->renderLoadingScreen("Loading...");
|
2021-01-05 09:45:32 +00:00
|
|
|
reloadAll();
|
|
|
|
if (mState.viewing == GAME_LIST) {
|
|
|
|
goToSystemView(SystemData::sSystemVector.front(), false);
|
|
|
|
goToSystem(SystemData::sSystemVector.front(), false);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
goToSystem(SystemData::sSystemVector.front(), false);
|
|
|
|
}
|
2017-11-18 22:23:56 +00:00
|
|
|
}
|
|
|
|
|
2020-09-15 20:57:54 +00:00
|
|
|
bool ViewController::isCameraMoving()
|
|
|
|
{
|
|
|
|
if (mCurrentView) {
|
|
|
|
if (mCamera.r3().x() != -mCurrentView->getPosition().x() ||
|
|
|
|
mCamera.r3().y() != -mCurrentView->getPosition().y())
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2020-11-16 16:44:33 +00:00
|
|
|
void ViewController::cancelViewTransitions()
|
2020-09-15 20:57:54 +00:00
|
|
|
{
|
2020-11-18 21:26:58 +00:00
|
|
|
if (Settings::getInstance()->getString("TransitionStyle") == "slide") {
|
|
|
|
if (isCameraMoving()) {
|
|
|
|
mCamera.r3().x() = -mCurrentView->getPosition().x();
|
|
|
|
mCamera.r3().y() = -mCurrentView->getPosition().y();
|
|
|
|
stopAllAnimations();
|
|
|
|
}
|
|
|
|
// mSkipView is used when skipping through the gamelists in quick succession.
|
|
|
|
// Without this, the game video (or static image) would not get rendered during
|
|
|
|
// the slide transition animation.
|
|
|
|
else if (mSkipView) {
|
|
|
|
mSkipView.reset();
|
|
|
|
mSkipView = nullptr;
|
|
|
|
}
|
2020-09-15 20:57:54 +00:00
|
|
|
}
|
2020-11-16 16:44:33 +00:00
|
|
|
else if (Settings::getInstance()->getString("TransitionStyle") == "fade") {
|
|
|
|
if (isAnimationPlaying(0)) {
|
|
|
|
finishAnimation(0);
|
2020-11-18 21:26:58 +00:00
|
|
|
mCancelledTransition = true;
|
2020-11-16 16:44:33 +00:00
|
|
|
mFadeOpacity = 0;
|
|
|
|
mWindow->invalidateCachedBackground();
|
|
|
|
}
|
|
|
|
}
|
2020-09-15 20:57:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void ViewController::stopScrolling()
|
|
|
|
{
|
|
|
|
mSystemListView->stopScrolling();
|
|
|
|
mCurrentView->stopListScrolling();
|
|
|
|
|
|
|
|
if (mSystemListView->isAnimationPlaying(0))
|
|
|
|
mSystemListView->finishAnimation(0);
|
|
|
|
}
|
|
|
|
|
2014-06-25 16:29:58 +00:00
|
|
|
int ViewController::getSystemId(SystemData* system)
|
|
|
|
{
|
2020-06-21 12:25:28 +00:00
|
|
|
std::vector<SystemData*>& sysVec = SystemData::sSystemVector;
|
2020-09-15 20:57:54 +00:00
|
|
|
return static_cast<int>(std::find(sysVec.cbegin(), sysVec.cend(), system) - sysVec.cbegin());
|
2014-06-25 16:29:58 +00:00
|
|
|
}
|
|
|
|
|
2020-11-15 21:54:39 +00:00
|
|
|
void ViewController::restoreViewPosition()
|
2014-06-25 16:29:58 +00:00
|
|
|
{
|
2020-11-15 21:54:39 +00:00
|
|
|
if (mPreviousView) {
|
|
|
|
Vector3f restorePosition = mPreviousView->getPosition();
|
|
|
|
restorePosition.x() = mWrapPreviousPositionX;
|
|
|
|
mPreviousView->setPosition(restorePosition);
|
|
|
|
mWrapPreviousPositionX = 0;
|
|
|
|
mWrappedViews = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void ViewController::goToSystemView(SystemData* system, bool playTransition)
|
|
|
|
{
|
2020-11-17 16:30:23 +00:00
|
|
|
bool applicationStartup = false;
|
|
|
|
|
|
|
|
if (mState.viewing == NOTHING)
|
|
|
|
applicationStartup = true;
|
|
|
|
|
2020-11-15 21:54:39 +00:00
|
|
|
// Restore the X position for the view, if it was previously moved.
|
|
|
|
if (mWrappedViews)
|
|
|
|
restoreViewPosition();
|
|
|
|
|
2020-11-18 21:26:58 +00:00
|
|
|
if (mPreviousView) {
|
|
|
|
mPreviousView.reset();
|
|
|
|
mPreviousView = nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
mPreviousView = mCurrentView;
|
|
|
|
|
2020-11-06 19:27:41 +00:00
|
|
|
if (system->isGroupedCustomCollection())
|
|
|
|
system = system->getRootFolder()->getParent()->getSystem();
|
|
|
|
|
2020-06-21 12:25:28 +00:00
|
|
|
mState.viewing = SYSTEM_SELECT;
|
|
|
|
mState.system = system;
|
2020-11-18 22:47:32 +00:00
|
|
|
mSystemViewTransition = true;
|
2014-06-25 16:29:58 +00:00
|
|
|
|
2020-06-21 12:25:28 +00:00
|
|
|
auto systemList = getSystemListView();
|
2020-09-15 20:57:54 +00:00
|
|
|
systemList->setPosition(getSystemId(system) * static_cast<float>(Renderer::getScreenWidth()),
|
2020-06-21 12:25:28 +00:00
|
|
|
systemList->getPosition().y());
|
2014-06-25 16:29:58 +00:00
|
|
|
|
2020-06-21 12:25:28 +00:00
|
|
|
systemList->goToSystem(system, false);
|
|
|
|
mCurrentView = systemList;
|
|
|
|
mCurrentView->onShow();
|
2014-06-25 16:29:58 +00:00
|
|
|
|
2020-11-17 16:30:23 +00:00
|
|
|
// Application startup animation.
|
|
|
|
if (applicationStartup) {
|
|
|
|
mCamera.translation() = -mCurrentView->getPosition();
|
|
|
|
if (Settings::getInstance()->getString("TransitionStyle") == "slide") {
|
|
|
|
if (getSystemListView()->getCarouselType() == CarouselType::HORIZONTAL ||
|
|
|
|
getSystemListView()->getCarouselType() == CarouselType::HORIZONTAL_WHEEL)
|
|
|
|
mCamera.translation().y() += Renderer::getScreenHeight();
|
|
|
|
else
|
|
|
|
mCamera.translation().x() -= Renderer::getScreenWidth();
|
|
|
|
updateHelpPrompts();
|
|
|
|
}
|
|
|
|
else if (Settings::getInstance()->getString("TransitionStyle") == "fade") {
|
|
|
|
if (getSystemListView()->getCarouselType() == CarouselType::HORIZONTAL ||
|
|
|
|
getSystemListView()->getCarouselType() == CarouselType::HORIZONTAL_WHEEL)
|
|
|
|
mCamera.translation().y() += Renderer::getScreenHeight();
|
|
|
|
else
|
|
|
|
mCamera.translation().x() += Renderer::getScreenWidth();
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
updateHelpPrompts();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (playTransition || applicationStartup)
|
2020-11-15 21:54:39 +00:00
|
|
|
playViewTransition();
|
|
|
|
else
|
|
|
|
playViewTransition(true);
|
2014-06-25 16:29:58 +00:00
|
|
|
}
|
|
|
|
|
2021-01-01 21:37:21 +00:00
|
|
|
void ViewController::goToSystem(SystemData* system, bool animate)
|
|
|
|
{
|
|
|
|
mSystemListView->goToSystem(system, animate);
|
|
|
|
}
|
|
|
|
|
2014-06-25 16:29:58 +00:00
|
|
|
void ViewController::goToNextGameList()
|
|
|
|
{
|
2020-06-21 12:25:28 +00:00
|
|
|
assert(mState.viewing == GAME_LIST);
|
|
|
|
SystemData* system = getState().getSystem();
|
|
|
|
assert(system);
|
|
|
|
NavigationSounds::getInstance()->playThemeNavigationSound(QUICKSYSSELECTSOUND);
|
2021-01-01 20:45:51 +00:00
|
|
|
mNextSystem = true;
|
2020-06-21 12:25:28 +00:00
|
|
|
goToGameList(system->getNext());
|
2014-06-25 16:29:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void ViewController::goToPrevGameList()
|
|
|
|
{
|
2020-06-21 12:25:28 +00:00
|
|
|
assert(mState.viewing == GAME_LIST);
|
|
|
|
SystemData* system = getState().getSystem();
|
|
|
|
assert(system);
|
|
|
|
NavigationSounds::getInstance()->playThemeNavigationSound(QUICKSYSSELECTSOUND);
|
2021-01-01 20:45:51 +00:00
|
|
|
mNextSystem = false;
|
2020-06-21 12:25:28 +00:00
|
|
|
goToGameList(system->getPrev());
|
2014-06-25 16:29:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void ViewController::goToGameList(SystemData* system)
|
|
|
|
{
|
2020-11-15 21:54:39 +00:00
|
|
|
bool wrapFirstToLast = false;
|
|
|
|
bool wrapLastToFirst = false;
|
2020-11-16 16:44:33 +00:00
|
|
|
bool slideTransitions = false;
|
|
|
|
|
|
|
|
if (Settings::getInstance()->getString("TransitionStyle") == "slide")
|
|
|
|
slideTransitions = true;
|
2020-11-15 21:54:39 +00:00
|
|
|
|
|
|
|
// Restore the X position for the view, if it was previously moved.
|
|
|
|
if (mWrappedViews)
|
|
|
|
restoreViewPosition();
|
|
|
|
|
2020-11-18 21:26:58 +00:00
|
|
|
if (mPreviousView && Settings::getInstance()->getString("TransitionStyle") == "fade" &&
|
|
|
|
isAnimationPlaying(0))
|
|
|
|
mPreviousView->onHide();
|
|
|
|
|
|
|
|
if (mPreviousView) {
|
|
|
|
mSkipView = mPreviousView;
|
|
|
|
mPreviousView.reset();
|
|
|
|
mPreviousView = nullptr;
|
|
|
|
}
|
|
|
|
|
2020-11-18 22:47:32 +00:00
|
|
|
if (mState.viewing != SYSTEM_SELECT) {
|
2020-11-18 21:26:58 +00:00
|
|
|
mPreviousView = mCurrentView;
|
2020-11-18 22:47:32 +00:00
|
|
|
mSystemViewTransition = false;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
mSystemViewTransition = true;
|
|
|
|
}
|
2020-11-18 21:26:58 +00:00
|
|
|
|
2020-11-15 21:54:39 +00:00
|
|
|
// Find if we're wrapping around the first and last systems, which requires the gamelist
|
|
|
|
// to be moved in order to avoid weird camera movements. This is only needed for the
|
|
|
|
// slide transition style though.
|
2020-11-16 16:44:33 +00:00
|
|
|
if (mState.viewing == GAME_LIST && slideTransitions) {
|
2020-11-15 21:54:39 +00:00
|
|
|
if (SystemData::sSystemVector.front() == mState.getSystem()) {
|
|
|
|
if (SystemData::sSystemVector.back() == system)
|
|
|
|
wrapFirstToLast = true;
|
|
|
|
}
|
|
|
|
else if (SystemData::sSystemVector.back() == mState.getSystem()) {
|
|
|
|
if (SystemData::sSystemVector.front() == system)
|
|
|
|
wrapLastToFirst = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-09-15 20:57:54 +00:00
|
|
|
// Stop any scrolling, animations and camera movements.
|
2020-09-18 16:40:22 +00:00
|
|
|
if (mState.viewing == SYSTEM_SELECT) {
|
2020-09-15 20:57:54 +00:00
|
|
|
mSystemListView->stopScrolling();
|
|
|
|
if (mSystemListView->isAnimationPlaying(0))
|
|
|
|
mSystemListView->finishAnimation(0);
|
|
|
|
}
|
2020-11-16 16:44:33 +00:00
|
|
|
|
|
|
|
if (slideTransitions)
|
|
|
|
cancelViewTransitions();
|
2020-09-15 20:57:54 +00:00
|
|
|
|
2020-06-21 12:25:28 +00:00
|
|
|
if (mState.viewing == SYSTEM_SELECT) {
|
2020-11-18 21:26:58 +00:00
|
|
|
// Move the system list.
|
2020-06-21 12:25:28 +00:00
|
|
|
auto sysList = getSystemListView();
|
2020-11-15 21:54:39 +00:00
|
|
|
float offsetX = sysList->getPosition().x();
|
2020-06-21 12:25:28 +00:00
|
|
|
int sysId = getSystemId(system);
|
2020-05-24 08:29:29 +00:00
|
|
|
|
2020-11-16 16:44:33 +00:00
|
|
|
sysList->setPosition(sysId * static_cast<float>(Renderer::getScreenWidth()),
|
2020-06-21 12:25:28 +00:00
|
|
|
sysList->getPosition().y());
|
2020-11-15 21:54:39 +00:00
|
|
|
offsetX = sysList->getPosition().x() - offsetX;
|
|
|
|
mCamera.translation().x() -= offsetX;
|
|
|
|
}
|
|
|
|
|
|
|
|
// If we are wrapping around, either from the first to last system, or the other way
|
|
|
|
// around, we need to temporarily move the gamelist view location so that the camera
|
|
|
|
// movements will be correct. This is accomplished by simply offsetting the X position
|
|
|
|
// with the position of the first or last system plus the screen width.
|
|
|
|
if (wrapFirstToLast) {
|
|
|
|
Vector3f currentPosition = mCurrentView->getPosition();
|
|
|
|
mWrapPreviousPositionX = currentPosition.x();
|
|
|
|
float offsetX = getGameListView(system)->getPosition().x();
|
2021-01-01 20:45:51 +00:00
|
|
|
// This is needed to move the camera in the correct direction if there are only two systems.
|
|
|
|
if (SystemData::sSystemVector.size() == 2 && mNextSystem)
|
|
|
|
offsetX -= Renderer::getScreenWidth();
|
|
|
|
else
|
|
|
|
offsetX += Renderer::getScreenWidth();
|
2020-11-15 21:54:39 +00:00
|
|
|
currentPosition.x() = offsetX;
|
|
|
|
mCurrentView->setPosition(currentPosition);
|
|
|
|
mCamera.translation().x() -= offsetX;
|
|
|
|
mWrappedViews = true;
|
|
|
|
}
|
|
|
|
else if (wrapLastToFirst) {
|
|
|
|
Vector3f currentPosition = mCurrentView->getPosition();
|
|
|
|
mWrapPreviousPositionX = currentPosition.x();
|
|
|
|
float offsetX = getGameListView(system)->getPosition().x();
|
2021-01-01 20:45:51 +00:00
|
|
|
if (SystemData::sSystemVector.size() == 2 && !mNextSystem)
|
|
|
|
offsetX += Renderer::getScreenWidth();
|
|
|
|
else
|
|
|
|
offsetX -= Renderer::getScreenWidth();
|
2020-11-15 21:54:39 +00:00
|
|
|
currentPosition.x() = offsetX;
|
|
|
|
mCurrentView->setPosition(currentPosition);
|
|
|
|
mCamera.translation().x() = -offsetX;
|
|
|
|
mWrappedViews = true;
|
2020-06-21 12:25:28 +00:00
|
|
|
}
|
2014-06-25 16:29:58 +00:00
|
|
|
|
2020-11-17 16:30:23 +00:00
|
|
|
mCurrentView = getGameListView(system);
|
|
|
|
|
|
|
|
// Application startup animation, if starting in a gamelist rather than in the system view.
|
|
|
|
if (mState.viewing == NOTHING) {
|
|
|
|
mCamera.translation() = -mCurrentView->getPosition();
|
|
|
|
if (Settings::getInstance()->getString("TransitionStyle") == "slide") {
|
|
|
|
mCamera.translation().y() -= Renderer::getScreenHeight();
|
|
|
|
updateHelpPrompts();
|
|
|
|
}
|
|
|
|
else if (Settings::getInstance()->getString("TransitionStyle") == "fade") {
|
|
|
|
mCamera.translation().y() += Renderer::getScreenHeight() * 2;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
updateHelpPrompts();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-06-21 12:25:28 +00:00
|
|
|
mState.viewing = GAME_LIST;
|
|
|
|
mState.system = system;
|
2014-06-25 16:29:58 +00:00
|
|
|
|
2020-11-18 22:47:32 +00:00
|
|
|
if (mCurrentView)
|
2020-06-21 12:25:28 +00:00
|
|
|
mCurrentView->onShow();
|
2020-11-18 22:47:32 +00:00
|
|
|
|
2020-06-21 12:25:28 +00:00
|
|
|
playViewTransition();
|
2014-06-25 16:29:58 +00:00
|
|
|
}
|
|
|
|
|
2020-11-15 21:54:39 +00:00
|
|
|
void ViewController::playViewTransition(bool instant)
|
2014-06-25 16:29:58 +00:00
|
|
|
{
|
2020-11-18 21:26:58 +00:00
|
|
|
mCancelledTransition = false;
|
2020-11-16 16:44:33 +00:00
|
|
|
|
2020-06-21 12:25:28 +00:00
|
|
|
Vector3f target(Vector3f::Zero());
|
|
|
|
if (mCurrentView)
|
|
|
|
target = mCurrentView->getPosition();
|
|
|
|
|
|
|
|
// No need to animate, we're not going anywhere (probably due to goToNextGamelist()
|
|
|
|
// or goToPrevGamelist() being called when there's only 1 system).
|
|
|
|
if (target == -mCamera.translation() && !isAnimationPlaying(0))
|
|
|
|
return;
|
|
|
|
|
|
|
|
std::string transition_style = Settings::getInstance()->getString("TransitionStyle");
|
|
|
|
|
2020-11-15 21:54:39 +00:00
|
|
|
if (instant || transition_style == "instant") {
|
|
|
|
setAnimation(new LambdaAnimation([this, target](float /*t*/) {
|
2020-11-18 21:26:58 +00:00
|
|
|
this->mCamera.translation() = -target;
|
|
|
|
if (mPreviousView)
|
|
|
|
mPreviousView->onHide();
|
|
|
|
}, 1));
|
2020-11-15 21:54:39 +00:00
|
|
|
updateHelpPrompts();
|
|
|
|
}
|
|
|
|
else if (transition_style == "fade") {
|
2020-06-21 12:25:28 +00:00
|
|
|
// Stop whatever's currently playing, leaving mFadeOpacity wherever it is.
|
|
|
|
cancelAnimation(0);
|
|
|
|
|
|
|
|
auto fadeFunc = [this](float t) {
|
2020-11-18 21:26:58 +00:00
|
|
|
// The flag mCancelledTransition is required only when cancelViewTransitions()
|
2020-11-16 16:44:33 +00:00
|
|
|
// cancels the animation, and it's only needed for the Fade transitions.
|
|
|
|
// Without this, a (much shorter) fade transition would still play as
|
|
|
|
// finishedCallback is calling this function.
|
2020-11-18 21:26:58 +00:00
|
|
|
if (!mCancelledTransition)
|
2020-11-16 16:44:33 +00:00
|
|
|
mFadeOpacity = Math::lerp(0, 1, t);
|
2020-06-21 12:25:28 +00:00
|
|
|
};
|
|
|
|
|
2020-11-18 21:26:58 +00:00
|
|
|
auto fadeCallback = [this]() {
|
|
|
|
if (mPreviousView)
|
|
|
|
mPreviousView->onHide();
|
|
|
|
};
|
|
|
|
|
2020-07-19 10:23:30 +00:00
|
|
|
const static int FADE_DURATION = 120; // Fade in/out time.
|
|
|
|
const static int FADE_WAIT = 200; // Time to wait between in/out.
|
2020-11-18 21:26:58 +00:00
|
|
|
setAnimation(new LambdaAnimation(fadeFunc, FADE_DURATION), 0,
|
|
|
|
[this, fadeFunc, fadeCallback, target] {
|
2020-06-21 12:25:28 +00:00
|
|
|
this->mCamera.translation() = -target;
|
|
|
|
updateHelpPrompts();
|
2020-11-18 21:26:58 +00:00
|
|
|
setAnimation(new LambdaAnimation(fadeFunc, FADE_DURATION),
|
|
|
|
FADE_WAIT, fadeCallback, true);
|
2020-06-21 12:25:28 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
// Fast-forward animation if we're partway faded.
|
|
|
|
if (target == -mCamera.translation()) {
|
|
|
|
// Not changing screens, so cancel the first half entirely.
|
|
|
|
advanceAnimation(0, FADE_DURATION);
|
|
|
|
advanceAnimation(0, FADE_WAIT);
|
2020-09-15 20:57:54 +00:00
|
|
|
advanceAnimation(0, FADE_DURATION - static_cast<int>(mFadeOpacity * FADE_DURATION));
|
2020-06-21 12:25:28 +00:00
|
|
|
}
|
|
|
|
else {
|
2020-09-15 20:57:54 +00:00
|
|
|
advanceAnimation(0, static_cast<int>(mFadeOpacity * FADE_DURATION));
|
2020-06-21 12:25:28 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (transition_style == "slide") {
|
2020-11-18 21:26:58 +00:00
|
|
|
auto slideCallback = [this]() {
|
|
|
|
if (mSkipView) {
|
|
|
|
mSkipView->onHide();
|
|
|
|
mSkipView.reset();
|
|
|
|
mSkipView = nullptr;
|
|
|
|
}
|
|
|
|
else if (mPreviousView) {
|
|
|
|
mPreviousView->onHide();
|
|
|
|
}
|
|
|
|
};
|
|
|
|
setAnimation(new MoveCameraAnimation(mCamera, target), 0, slideCallback);
|
2020-06-21 12:25:28 +00:00
|
|
|
updateHelpPrompts(); // Update help prompts immediately.
|
|
|
|
}
|
2014-06-25 16:29:58 +00:00
|
|
|
}
|
|
|
|
|
2020-10-27 18:07:35 +00:00
|
|
|
void ViewController::onFileChanged(FileData* file, bool reloadGameList)
|
2014-06-25 16:29:58 +00:00
|
|
|
{
|
2020-06-21 12:25:28 +00:00
|
|
|
auto it = mGameListViews.find(file->getSystem());
|
|
|
|
if (it != mGameListViews.cend())
|
2020-10-27 18:07:35 +00:00
|
|
|
it->second->onFileChanged(file, reloadGameList);
|
2014-06-25 16:29:58 +00:00
|
|
|
}
|
|
|
|
|
2020-11-17 16:30:23 +00:00
|
|
|
void ViewController::launch(FileData* game)
|
2014-06-25 16:29:58 +00:00
|
|
|
{
|
2020-06-21 12:25:28 +00:00
|
|
|
if (game->getType() != GAME) {
|
2021-02-01 17:51:00 +00:00
|
|
|
LOG(LogError) << "Tried to launch something that isn't a game";
|
2020-06-21 12:25:28 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2020-09-15 20:57:54 +00:00
|
|
|
// If the video view style is used, pause the video currently playing or block the
|
|
|
|
// video from starting to play if the static image is still shown.
|
2020-06-21 12:25:28 +00:00
|
|
|
if (mCurrentView)
|
2020-09-15 20:57:54 +00:00
|
|
|
mCurrentView->onPauseVideo();
|
2020-06-21 12:25:28 +00:00
|
|
|
|
2020-09-17 20:00:07 +00:00
|
|
|
// Disable text scrolling. It will be enabled again in FileData upon returning from the game.
|
|
|
|
mWindow->setAllowTextScrolling(false);
|
|
|
|
|
2020-06-21 12:25:28 +00:00
|
|
|
stopAnimation(1); // Make sure the fade in isn't still playing.
|
|
|
|
mWindow->stopInfoPopup(); // Make sure we disable any existing info popup.
|
|
|
|
|
2020-09-15 20:57:54 +00:00
|
|
|
// Until a proper game launch screen is implemented, at least this will let the
|
|
|
|
// user know that something is actually happening (in addition to the launch sound,
|
|
|
|
// if navigation sounds are enabled).
|
2020-08-15 13:41:11 +00:00
|
|
|
GuiInfoPopup* s = new GuiInfoPopup(mWindow, "LAUNCHING GAME '" +
|
|
|
|
Utils::String::toUpper(game->metadata.get("name") + "'"), 10000);
|
|
|
|
mWindow->setInfoPopup(s);
|
|
|
|
|
2020-06-21 12:25:28 +00:00
|
|
|
NavigationSounds::getInstance()->playThemeNavigationSound(LAUNCHSOUND);
|
2020-09-15 20:57:54 +00:00
|
|
|
|
|
|
|
// This is just a dummy animation in order for the launch notification popup to be
|
|
|
|
// displayed briefly, and for the navigation sound playing to be able to complete.
|
|
|
|
// During this time period, all user input is blocked.
|
|
|
|
setAnimation(new LambdaAnimation([](float t){}, 1700), 0, [this, game] {
|
|
|
|
while (NavigationSounds::getInstance()->isPlayingThemeNavigationSound(LAUNCHSOUND));
|
2020-07-19 20:08:14 +00:00
|
|
|
game->launchGame(mWindow);
|
2020-10-27 18:07:35 +00:00
|
|
|
onFileChanged(game, true);
|
2020-09-15 20:57:54 +00:00
|
|
|
// This is a workaround so that any key or button presses used for exiting the emulator
|
|
|
|
// are not captured upon returning to ES.
|
|
|
|
setAnimation(new LambdaAnimation([](float t){}, 1), 0, [this] {
|
|
|
|
mLockInput = false;
|
|
|
|
});
|
2020-07-19 20:08:14 +00:00
|
|
|
});
|
2014-06-25 16:29:58 +00:00
|
|
|
}
|
|
|
|
|
2017-07-18 09:45:50 +00:00
|
|
|
void ViewController::removeGameListView(SystemData* system)
|
|
|
|
{
|
2020-06-21 12:25:28 +00:00
|
|
|
auto exists = mGameListViews.find(system);
|
|
|
|
if (exists != mGameListViews.cend()) {
|
|
|
|
exists->second.reset();
|
|
|
|
mGameListViews.erase(system);
|
|
|
|
}
|
2017-07-18 09:45:50 +00:00
|
|
|
}
|
|
|
|
|
2014-06-25 16:29:58 +00:00
|
|
|
std::shared_ptr<IGameListView> ViewController::getGameListView(SystemData* system)
|
|
|
|
{
|
2020-09-15 20:57:54 +00:00
|
|
|
// If we have already created an entry for this system, then return that one.
|
2020-06-21 12:25:28 +00:00
|
|
|
auto exists = mGameListViews.find(system);
|
|
|
|
if (exists != mGameListViews.cend())
|
|
|
|
return exists->second;
|
|
|
|
|
2021-01-05 09:45:32 +00:00
|
|
|
system->getIndex()->setKidModeFilters();
|
2020-09-15 20:57:54 +00:00
|
|
|
// If there's no entry, then create it and return it.
|
2020-06-21 12:25:28 +00:00
|
|
|
std::shared_ptr<IGameListView> view;
|
|
|
|
|
|
|
|
bool themeHasVideoView = system->getTheme()->hasView("video");
|
|
|
|
|
2020-09-15 20:57:54 +00:00
|
|
|
// Decide which view style to use.
|
2021-01-12 17:40:25 +00:00
|
|
|
GameListViewStyle selectedViewStyle = AUTOMATIC;
|
2020-06-21 12:25:28 +00:00
|
|
|
|
|
|
|
std::string viewPreference = Settings::getInstance()->getString("GamelistViewStyle");
|
|
|
|
if (viewPreference.compare("basic") == 0)
|
2020-09-15 20:57:54 +00:00
|
|
|
selectedViewStyle = BASIC;
|
2020-06-21 12:25:28 +00:00
|
|
|
if (viewPreference.compare("detailed") == 0)
|
2020-09-15 20:57:54 +00:00
|
|
|
selectedViewStyle = DETAILED;
|
2020-06-21 12:25:28 +00:00
|
|
|
if (viewPreference.compare("grid") == 0)
|
2020-09-15 20:57:54 +00:00
|
|
|
selectedViewStyle = GRID;
|
2020-06-21 12:25:28 +00:00
|
|
|
if (viewPreference.compare("video") == 0)
|
2020-09-15 20:57:54 +00:00
|
|
|
selectedViewStyle = VIDEO;
|
2020-06-21 12:25:28 +00:00
|
|
|
|
2020-09-15 20:57:54 +00:00
|
|
|
if (selectedViewStyle == AUTOMATIC) {
|
2020-06-21 12:25:28 +00:00
|
|
|
std::vector<FileData*> files = system->getRootFolder()->getFilesRecursive(GAME | FOLDER);
|
|
|
|
for (auto it = files.cbegin(); it != files.cend(); it++) {
|
|
|
|
if (themeHasVideoView && !(*it)->getVideoPath().empty()) {
|
2020-09-15 20:57:54 +00:00
|
|
|
selectedViewStyle = VIDEO;
|
2020-06-21 12:25:28 +00:00
|
|
|
break;
|
|
|
|
}
|
2020-07-13 18:10:09 +00:00
|
|
|
else if (!(*it)->getImagePath().empty()) {
|
2020-09-15 20:57:54 +00:00
|
|
|
selectedViewStyle = DETAILED;
|
2020-06-21 12:25:28 +00:00
|
|
|
// Don't break out in case any subsequent files have videos.
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Create the view.
|
2020-09-15 20:57:54 +00:00
|
|
|
switch (selectedViewStyle)
|
2020-06-21 12:25:28 +00:00
|
|
|
{
|
|
|
|
case VIDEO:
|
|
|
|
view = std::shared_ptr<IGameListView>(
|
|
|
|
new VideoGameListView(mWindow, system->getRootFolder()));
|
2021-01-12 17:40:25 +00:00
|
|
|
mState.viewstyle = VIDEO;
|
2020-06-21 12:25:28 +00:00
|
|
|
break;
|
|
|
|
case DETAILED:
|
|
|
|
view = std::shared_ptr<IGameListView>(
|
|
|
|
new DetailedGameListView(mWindow, system->getRootFolder()));
|
2021-01-12 17:40:25 +00:00
|
|
|
mState.viewstyle = DETAILED;
|
2020-06-21 12:25:28 +00:00
|
|
|
break;
|
|
|
|
case GRID:
|
|
|
|
view = std::shared_ptr<IGameListView>(
|
|
|
|
new GridGameListView(mWindow, system->getRootFolder()));
|
2021-01-12 17:40:25 +00:00
|
|
|
mState.viewstyle = GRID;
|
2020-06-21 12:25:28 +00:00
|
|
|
break;
|
|
|
|
case BASIC:
|
|
|
|
default:
|
|
|
|
view = std::shared_ptr<IGameListView>(
|
|
|
|
new BasicGameListView(mWindow, system->getRootFolder()));
|
2021-01-12 17:40:25 +00:00
|
|
|
mState.viewstyle = BASIC;
|
2020-06-21 12:25:28 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
view->setTheme(system->getTheme());
|
|
|
|
|
|
|
|
std::vector<SystemData*>& sysVec = SystemData::sSystemVector;
|
2020-09-15 20:57:54 +00:00
|
|
|
int id = static_cast<int>(
|
|
|
|
std::find(sysVec.cbegin(), sysVec.cend(), system) - sysVec.cbegin());
|
|
|
|
view->setPosition(id * static_cast<float>(Renderer::getScreenWidth()),
|
|
|
|
static_cast<float>(Renderer::getScreenHeight() * 2));
|
2020-06-21 12:25:28 +00:00
|
|
|
|
|
|
|
addChild(view.get());
|
|
|
|
|
|
|
|
mGameListViews[system] = view;
|
|
|
|
return view;
|
2014-06-25 16:29:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
std::shared_ptr<SystemView> ViewController::getSystemListView()
|
|
|
|
{
|
2020-09-15 20:57:54 +00:00
|
|
|
// If we have already created a system view entry, then return it.
|
2020-06-21 12:25:28 +00:00
|
|
|
if (mSystemListView)
|
|
|
|
return mSystemListView;
|
|
|
|
|
|
|
|
mSystemListView = std::shared_ptr<SystemView>(new SystemView(mWindow));
|
|
|
|
addChild(mSystemListView.get());
|
2020-09-15 20:57:54 +00:00
|
|
|
mSystemListView->setPosition(0, static_cast<float>(Renderer::getScreenHeight()));
|
2020-06-21 12:25:28 +00:00
|
|
|
return mSystemListView;
|
2014-06-25 16:29:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool ViewController::input(InputConfig* config, Input input)
|
|
|
|
{
|
2020-06-21 12:25:28 +00:00
|
|
|
if (mLockInput)
|
|
|
|
return true;
|
|
|
|
|
2020-08-23 15:04:30 +00:00
|
|
|
#if defined(_WIN64)
|
2020-07-19 20:08:14 +00:00
|
|
|
// This code is only needed for Windows, where we may need to keep ES running while
|
|
|
|
// the game/emulator is in use. It's basically used to pause any playing game video
|
|
|
|
// and to keep the screensaver from activating.
|
|
|
|
if (Settings::getInstance()->getBool("RunInBackground")) {
|
|
|
|
// If we have previously launched a game and there is now input registered, it means
|
|
|
|
// the user is back in ES, so unset the flag to indicate that a game has been launched
|
|
|
|
// and update all the GUI components to reflect this.
|
|
|
|
if (mWindow->getGameLaunchedState())
|
|
|
|
mWindow->unsetLaunchedGame();
|
2020-07-18 11:21:44 +00:00
|
|
|
}
|
2020-07-18 21:07:02 +00:00
|
|
|
#endif
|
2020-07-18 11:21:44 +00:00
|
|
|
|
2020-09-15 20:57:54 +00:00
|
|
|
// Open the main menu.
|
2020-06-21 12:25:28 +00:00
|
|
|
if (!(UIModeController::getInstance()->isUIModeKid() &&
|
2020-12-17 22:45:29 +00:00
|
|
|
!Settings::getInstance()->getBool("EnableMenuKidMode")) &&
|
2020-06-21 12:25:28 +00:00
|
|
|
config->isMappedTo("start", input) && input.value != 0) {
|
|
|
|
// If we don't stop the scrolling here, it will continue to
|
|
|
|
// run after closing the menu.
|
|
|
|
if (mSystemListView->isScrolling())
|
|
|
|
mSystemListView->stopScrolling();
|
|
|
|
// Finish the animation too, so that it doesn't continue
|
|
|
|
// to play when we've closed the menu.
|
|
|
|
if (mSystemListView->isAnimationPlaying(0))
|
|
|
|
mSystemListView->finishAnimation(0);
|
2020-09-13 17:08:17 +00:00
|
|
|
// Stop the gamelist scrolling as well as it would otherwise
|
|
|
|
// also continue to run after closing the menu.
|
2020-09-15 20:57:54 +00:00
|
|
|
mCurrentView->stopListScrolling();
|
|
|
|
// Finally, if the camera is currently moving, reset its position.
|
2020-11-16 16:44:33 +00:00
|
|
|
cancelViewTransitions();
|
2020-06-21 12:25:28 +00:00
|
|
|
|
|
|
|
mWindow->pushGui(new GuiMenu(mWindow));
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Check if UI mode has changed due to passphrase completion.
|
|
|
|
if (UIModeController::getInstance()->listen(config, input))
|
|
|
|
return true;
|
|
|
|
|
|
|
|
if (mCurrentView)
|
|
|
|
return mCurrentView->input(config, input);
|
|
|
|
|
|
|
|
return false;
|
2014-06-25 16:29:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void ViewController::update(int deltaTime)
|
|
|
|
{
|
2020-06-21 12:25:28 +00:00
|
|
|
if (mCurrentView)
|
|
|
|
mCurrentView->update(deltaTime);
|
2014-06-25 16:29:58 +00:00
|
|
|
|
2020-06-21 12:25:28 +00:00
|
|
|
updateSelf(deltaTime);
|
2020-11-17 16:30:23 +00:00
|
|
|
|
|
|
|
if (mGameToLaunch) {
|
|
|
|
launch(mGameToLaunch);
|
|
|
|
mGameToLaunch = nullptr;
|
|
|
|
}
|
2014-06-25 16:29:58 +00:00
|
|
|
}
|
|
|
|
|
2017-10-28 20:24:35 +00:00
|
|
|
void ViewController::render(const Transform4x4f& parentTrans)
|
2014-06-25 16:29:58 +00:00
|
|
|
{
|
2020-06-21 12:25:28 +00:00
|
|
|
Transform4x4f trans = mCamera * parentTrans;
|
|
|
|
Transform4x4f transInverse;
|
|
|
|
transInverse.invert(trans);
|
|
|
|
|
|
|
|
// Camera position, position + size.
|
|
|
|
Vector3f viewStart = transInverse.translation();
|
2020-09-15 20:57:54 +00:00
|
|
|
Vector3f viewEnd = transInverse * Vector3f(static_cast<float>(Renderer::getScreenWidth()),
|
|
|
|
static_cast<float>(Renderer::getScreenHeight(), 0));
|
2020-06-21 12:25:28 +00:00
|
|
|
|
|
|
|
// Keep track of UI mode changes.
|
|
|
|
UIModeController::getInstance()->monitorUIMode();
|
|
|
|
|
2020-11-18 22:47:32 +00:00
|
|
|
// Render the system view if it's the currently displayed view, or if we're in the progress
|
|
|
|
// of transitioning to or from this view.
|
|
|
|
if (mSystemListView == mCurrentView || (mSystemViewTransition && isCameraMoving()))
|
2020-09-15 20:57:54 +00:00
|
|
|
getSystemListView()->render(trans);
|
2020-06-21 12:25:28 +00:00
|
|
|
|
2020-09-15 20:57:54 +00:00
|
|
|
// Draw the gamelists.
|
2020-06-21 12:25:28 +00:00
|
|
|
for (auto it = mGameListViews.cbegin(); it != mGameListViews.cend(); it++) {
|
2020-09-15 20:57:54 +00:00
|
|
|
// Same thing as for the system view, limit the rendering only to what needs to be drawn.
|
2020-11-18 22:47:32 +00:00
|
|
|
if (it->second == mCurrentView || (it->second == mPreviousView && isCameraMoving())) {
|
2020-09-15 20:57:54 +00:00
|
|
|
// Clipping.
|
|
|
|
Vector3f guiStart = it->second->getPosition();
|
|
|
|
Vector3f guiEnd = it->second->getPosition() + Vector3f(it->second->getSize().x(),
|
|
|
|
it->second->getSize().y(), 0);
|
|
|
|
|
|
|
|
if (guiEnd.x() >= viewStart.x() && guiEnd.y() >= viewStart.y() &&
|
|
|
|
guiStart.x() <= viewEnd.x() && guiStart.y() <= viewEnd.y())
|
|
|
|
it->second->render(trans);
|
|
|
|
}
|
2020-06-21 12:25:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (mWindow->peekGui() == this)
|
|
|
|
mWindow->renderHelpPromptsEarly();
|
|
|
|
|
|
|
|
// Fade out.
|
|
|
|
if (mFadeOpacity) {
|
2020-09-15 20:57:54 +00:00
|
|
|
unsigned int fadeColor = 0x00000000 | static_cast<unsigned char>(mFadeOpacity * 255);
|
2020-06-21 12:25:28 +00:00
|
|
|
Renderer::setMatrix(parentTrans);
|
2020-12-29 11:54:24 +00:00
|
|
|
Renderer::drawRect(0.0f, 0.0f, static_cast<float>(Renderer::getScreenWidth()),
|
|
|
|
static_cast<float>(Renderer::getScreenHeight()), fadeColor, fadeColor);
|
2020-06-21 12:25:28 +00:00
|
|
|
}
|
2014-06-25 16:29:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void ViewController::preload()
|
|
|
|
{
|
2020-12-29 11:54:24 +00:00
|
|
|
unsigned int systemCount = static_cast<int>(SystemData::sSystemVector.size());
|
2020-09-15 20:57:54 +00:00
|
|
|
|
2020-06-21 12:25:28 +00:00
|
|
|
for (auto it = SystemData::sSystemVector.cbegin();
|
2020-09-15 20:57:54 +00:00
|
|
|
it != SystemData::sSystemVector.cend(); it ++) {
|
2020-06-21 12:25:28 +00:00
|
|
|
if (Settings::getInstance()->getBool("SplashScreen") &&
|
2020-09-15 20:57:54 +00:00
|
|
|
Settings::getInstance()->getBool("SplashScreenProgress")) {
|
|
|
|
mWindow->renderLoadingScreen("Loading '" + (*it)->getFullName() + "' (" +
|
|
|
|
std::to_string(std::distance(SystemData::sSystemVector.cbegin(), it)+1) +
|
|
|
|
"/" + std::to_string(systemCount) + ")");
|
2020-06-21 12:25:28 +00:00
|
|
|
}
|
|
|
|
(*it)->getIndex()->resetFilters();
|
|
|
|
getGameListView(*it);
|
|
|
|
}
|
|
|
|
// Load navigation sounds, but only if at least one system exists.
|
2020-09-15 20:57:54 +00:00
|
|
|
if (systemCount > 0)
|
2020-06-21 12:25:28 +00:00
|
|
|
NavigationSounds::getInstance()->loadThemeNavigationSounds(
|
|
|
|
SystemData::sSystemVector.front()->getTheme());
|
2014-06-25 16:29:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void ViewController::reloadGameListView(IGameListView* view, bool reloadTheme)
|
|
|
|
{
|
2020-06-21 12:25:28 +00:00
|
|
|
for (auto it = mGameListViews.cbegin(); it != mGameListViews.cend(); it++) {
|
|
|
|
if (it->second.get() == view) {
|
|
|
|
bool isCurrent = (mCurrentView == it->second);
|
|
|
|
SystemData* system = it->first;
|
|
|
|
FileData* cursor = view->getCursor();
|
2020-12-20 11:07:02 +00:00
|
|
|
|
|
|
|
// Retain the cursor history for the view.
|
|
|
|
std::vector<FileData*> cursorHistoryTemp;
|
|
|
|
it->second->copyCursorHistory(cursorHistoryTemp);
|
|
|
|
|
2020-06-21 12:25:28 +00:00
|
|
|
mGameListViews.erase(it);
|
|
|
|
|
2021-03-01 17:50:12 +00:00
|
|
|
if (isCurrent)
|
|
|
|
mCurrentView = nullptr;
|
|
|
|
|
2020-06-21 12:25:28 +00:00
|
|
|
if (reloadTheme)
|
|
|
|
system->loadTheme();
|
2021-01-05 09:45:32 +00:00
|
|
|
system->getIndex()->setKidModeFilters();
|
2020-06-21 12:25:28 +00:00
|
|
|
std::shared_ptr<IGameListView> newView = getGameListView(system);
|
|
|
|
|
|
|
|
// To counter having come from a placeholder.
|
|
|
|
if (!cursor->isPlaceHolder()) {
|
|
|
|
newView->setCursor(cursor);
|
|
|
|
}
|
|
|
|
if (isCurrent)
|
|
|
|
mCurrentView = newView;
|
|
|
|
|
2020-12-20 11:07:02 +00:00
|
|
|
newView->populateCursorHistory(cursorHistoryTemp);
|
2020-06-21 12:25:28 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2020-07-18 11:21:44 +00:00
|
|
|
|
2020-08-23 15:04:30 +00:00
|
|
|
#if defined(_WIN64)
|
2020-07-19 20:08:14 +00:00
|
|
|
// This code is only needed for Windows, where we may need to keep ES running while
|
|
|
|
// the game/emulator is in use. It's basically used to pause any playing game video
|
|
|
|
// and to keep the screensaver from activating.
|
|
|
|
if (Settings::getInstance()->getBool("RunInBackground")) {
|
|
|
|
// If a game has been launched, then update all the GUI components to reflect this.
|
|
|
|
if (mWindow->getGameLaunchedState())
|
|
|
|
mWindow->setLaunchedGame();
|
|
|
|
}
|
2020-07-18 21:07:02 +00:00
|
|
|
#endif
|
2020-07-18 11:21:44 +00:00
|
|
|
|
2020-06-21 12:25:28 +00:00
|
|
|
// Redisplay the current view.
|
2020-11-18 22:47:32 +00:00
|
|
|
if (mCurrentView)
|
2020-06-21 12:25:28 +00:00
|
|
|
mCurrentView->onShow();
|
2014-06-25 16:29:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void ViewController::reloadAll()
|
|
|
|
{
|
2020-06-21 12:25:28 +00:00
|
|
|
// Clear all GameListViews.
|
|
|
|
std::map<SystemData*, FileData*> cursorMap;
|
|
|
|
for (auto it = mGameListViews.cbegin(); it != mGameListViews.cend(); it++)
|
|
|
|
cursorMap[it->first] = it->second->getCursor();
|
|
|
|
|
|
|
|
mGameListViews.clear();
|
2021-03-01 17:50:12 +00:00
|
|
|
mCurrentView = nullptr;
|
2020-06-21 12:25:28 +00:00
|
|
|
|
|
|
|
// Load themes, create GameListViews and reset filters.
|
|
|
|
for (auto it = cursorMap.cbegin(); it != cursorMap.cend(); it++) {
|
|
|
|
it->first->loadTheme();
|
|
|
|
it->first->getIndex()->resetFilters();
|
|
|
|
getGameListView(it->first)->setCursor(it->second);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Rebuild SystemListView.
|
|
|
|
mSystemListView.reset();
|
|
|
|
getSystemListView();
|
|
|
|
|
|
|
|
// Update mCurrentView since the pointers changed.
|
|
|
|
if (mState.viewing == GAME_LIST) {
|
|
|
|
mCurrentView = getGameListView(mState.getSystem());
|
|
|
|
}
|
|
|
|
else if (mState.viewing == SYSTEM_SELECT) {
|
|
|
|
SystemData* system = mState.getSystem();
|
|
|
|
mSystemListView->goToSystem(system, false);
|
|
|
|
mCurrentView = mSystemListView;
|
2020-11-16 16:44:33 +00:00
|
|
|
mCamera.r3().x() = 0;
|
2020-06-21 12:25:28 +00:00
|
|
|
}
|
|
|
|
else {
|
2020-11-15 21:54:39 +00:00
|
|
|
goToSystemView(SystemData::sSystemVector.front(), false);
|
2020-06-21 12:25:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Load navigation sounds.
|
|
|
|
NavigationSounds::getInstance()->deinit();
|
|
|
|
NavigationSounds::getInstance()->loadThemeNavigationSounds(
|
|
|
|
SystemData::sSystemVector.front()->getTheme());
|
|
|
|
|
2020-09-15 20:57:54 +00:00
|
|
|
mCurrentView->onShow();
|
2020-06-21 12:25:28 +00:00
|
|
|
updateHelpPrompts();
|
2014-06-25 16:29:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
std::vector<HelpPrompt> ViewController::getHelpPrompts()
|
|
|
|
{
|
2020-06-21 12:25:28 +00:00
|
|
|
std::vector<HelpPrompt> prompts;
|
|
|
|
if (!mCurrentView)
|
|
|
|
return prompts;
|
|
|
|
|
|
|
|
prompts = mCurrentView->getHelpPrompts();
|
|
|
|
if (!(UIModeController::getInstance()->isUIModeKid() &&
|
2020-12-17 22:45:29 +00:00
|
|
|
!Settings::getInstance()->getBool("EnableMenuKidMode")))
|
2020-06-21 12:25:28 +00:00
|
|
|
prompts.push_back(HelpPrompt("start", "menu"));
|
|
|
|
return prompts;
|
2014-06-25 16:29:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
HelpStyle ViewController::getHelpStyle()
|
|
|
|
{
|
2020-06-21 12:25:28 +00:00
|
|
|
if (!mCurrentView)
|
|
|
|
return GuiComponent::getHelpStyle();
|
2014-06-25 16:29:58 +00:00
|
|
|
|
2020-06-21 12:25:28 +00:00
|
|
|
return mCurrentView->getHelpStyle();
|
2014-06-25 16:29:58 +00:00
|
|
|
}
|