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.h
|
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
|
|
|
//
|
|
|
|
|
2017-10-31 17:12:50 +00:00
|
|
|
#ifndef ES_APP_VIEWS_VIEW_CONTROLLER_H
|
|
|
|
#define ES_APP_VIEWS_VIEW_CONTROLLER_H
|
2014-06-25 16:29:58 +00:00
|
|
|
|
2021-07-07 18:03:42 +00:00
|
|
|
#include "FileData.h"
|
|
|
|
#include "GuiComponent.h"
|
2021-03-10 17:21:49 +00:00
|
|
|
#include "guis/GuiComplexTextEditPopup.h"
|
|
|
|
#include "guis/GuiMsgBox.h"
|
2019-08-08 20:16:11 +00:00
|
|
|
#include "renderers/Renderer.h"
|
2020-09-15 20:57:54 +00:00
|
|
|
|
2017-11-01 22:21:10 +00:00
|
|
|
#include <vector>
|
2014-06-25 16:29:58 +00:00
|
|
|
|
2017-11-01 22:21:10 +00:00
|
|
|
class IGameListView;
|
2014-06-25 16:29:58 +00:00
|
|
|
class SystemData;
|
2017-11-01 22:21:10 +00:00
|
|
|
class SystemView;
|
2014-06-25 16:29:58 +00:00
|
|
|
|
2020-05-24 08:29:29 +00:00
|
|
|
// Handles transitions between views, e.g. from system to system and from gamelist to gamelist.
|
|
|
|
// Also sets up the initial gamelists and refreshes and reloads them as required.
|
2014-06-25 16:29:58 +00:00
|
|
|
class ViewController : public GuiComponent
|
|
|
|
{
|
|
|
|
public:
|
2020-06-21 12:25:28 +00:00
|
|
|
static void init(Window* window);
|
|
|
|
static ViewController* get();
|
|
|
|
|
|
|
|
virtual ~ViewController();
|
|
|
|
|
2021-03-10 17:21:49 +00:00
|
|
|
// These functions are called from main().
|
2021-06-16 16:54:04 +00:00
|
|
|
void invalidSystemsFileDialog();
|
2021-03-10 17:21:49 +00:00
|
|
|
void noGamesDialog();
|
|
|
|
|
2020-06-21 12:25:28 +00:00
|
|
|
// Try to completely populate the GameListView map.
|
|
|
|
// Caches things so there's no pauses during transitions.
|
|
|
|
void preload();
|
|
|
|
|
|
|
|
// If a basic view detected a metadata change, it can request to recreate
|
|
|
|
// the current gamelist view (as it may change to be detailed).
|
|
|
|
void reloadGameListView(IGameListView* gamelist, bool reloadTheme = false);
|
2021-07-07 18:03:42 +00:00
|
|
|
void reloadGameListView(SystemData* system, bool reloadTheme = false)
|
|
|
|
{
|
|
|
|
reloadGameListView(getGameListView(system).get(), reloadTheme);
|
|
|
|
}
|
2020-06-21 12:25:28 +00:00
|
|
|
// Reload everything with a theme.
|
|
|
|
// Used when the "ThemeSet" setting changes.
|
|
|
|
void reloadAll();
|
|
|
|
|
|
|
|
// Navigation.
|
|
|
|
void goToNextGameList();
|
|
|
|
void goToPrevGameList();
|
|
|
|
void goToGameList(SystemData* system);
|
2020-11-15 21:54:39 +00:00
|
|
|
void goToSystemView(SystemData* system, bool playTransition);
|
2021-01-01 21:37:21 +00:00
|
|
|
void goToSystem(SystemData* system, bool animate);
|
2020-06-21 12:25:28 +00:00
|
|
|
void goToStart();
|
|
|
|
void ReloadAndGoToStart();
|
|
|
|
|
2020-09-15 20:57:54 +00:00
|
|
|
// Functions to make the GUI behave properly.
|
|
|
|
bool isCameraMoving();
|
2020-11-16 16:44:33 +00:00
|
|
|
void cancelViewTransitions();
|
2020-09-15 20:57:54 +00:00
|
|
|
void stopScrolling();
|
|
|
|
|
2020-10-27 18:07:35 +00:00
|
|
|
void onFileChanged(FileData* file, bool reloadGameList);
|
2021-07-07 18:03:42 +00:00
|
|
|
void triggerGameLaunch(FileData* game)
|
|
|
|
{
|
|
|
|
mGameToLaunch = game;
|
|
|
|
mLockInput = true;
|
|
|
|
};
|
|
|
|
bool getGameLaunchTriggered() { return (mGameToLaunch != nullptr); }
|
2020-06-21 12:25:28 +00:00
|
|
|
|
|
|
|
bool input(InputConfig* config, Input input) override;
|
|
|
|
void update(int deltaTime) override;
|
|
|
|
void render(const Transform4x4f& parentTrans) override;
|
|
|
|
|
|
|
|
enum ViewMode {
|
2021-07-07 18:03:42 +00:00
|
|
|
NOTHING, // Replace with AllowShortEnumsOnASingleLine: false (clang-format >=11.0).
|
2020-06-21 12:25:28 +00:00
|
|
|
START_SCREEN,
|
|
|
|
SYSTEM_SELECT,
|
|
|
|
GAME_LIST
|
|
|
|
};
|
|
|
|
|
2021-01-12 17:40:25 +00:00
|
|
|
enum GameListViewStyle {
|
2021-07-07 18:03:42 +00:00
|
|
|
AUTOMATIC, // Replace with AllowShortEnumsOnASingleLine: false (clang-format >=11.0).
|
2020-06-21 12:25:28 +00:00
|
|
|
BASIC,
|
|
|
|
DETAILED,
|
|
|
|
GRID,
|
|
|
|
VIDEO
|
|
|
|
};
|
|
|
|
|
|
|
|
struct State {
|
|
|
|
ViewMode viewing;
|
2021-01-12 17:40:25 +00:00
|
|
|
GameListViewStyle viewstyle;
|
2020-06-21 12:25:28 +00:00
|
|
|
|
2021-07-07 18:03:42 +00:00
|
|
|
SystemData* getSystem() const
|
2020-09-17 20:00:07 +00:00
|
|
|
{
|
|
|
|
assert(viewing == GAME_LIST || viewing == SYSTEM_SELECT);
|
|
|
|
return system;
|
|
|
|
}
|
|
|
|
|
2021-07-07 18:03:42 +00:00
|
|
|
private:
|
|
|
|
friend ViewController;
|
|
|
|
SystemData* system;
|
2020-06-21 12:25:28 +00:00
|
|
|
};
|
|
|
|
|
2021-07-07 18:03:42 +00:00
|
|
|
const State& getState() const { return mState; }
|
2020-06-21 12:25:28 +00:00
|
|
|
|
|
|
|
virtual std::vector<HelpPrompt> getHelpPrompts() override;
|
|
|
|
virtual HelpStyle getHelpStyle() override;
|
|
|
|
|
|
|
|
std::shared_ptr<IGameListView> getGameListView(SystemData* system);
|
|
|
|
std::shared_ptr<SystemView> getSystemListView();
|
|
|
|
void removeGameListView(SystemData* system);
|
2014-06-25 16:29:58 +00:00
|
|
|
|
2021-03-27 12:49:09 +00:00
|
|
|
// Whether to run in the background while a game is launched.
|
|
|
|
bool runInBackground(SystemData* system);
|
|
|
|
|
2020-12-16 20:19:48 +00:00
|
|
|
static const std::string FAVORITE_CHAR;
|
|
|
|
static const std::string FOLDER_CHAR;
|
2020-12-29 13:51:29 +00:00
|
|
|
static const std::string TICKMARK_CHAR;
|
|
|
|
static const std::string CONTROLLER_CHAR;
|
|
|
|
static const std::string FILTER_CHAR;
|
2020-12-16 20:19:48 +00:00
|
|
|
|
2014-06-25 16:29:58 +00:00
|
|
|
private:
|
2020-06-21 12:25:28 +00:00
|
|
|
ViewController(Window* window);
|
|
|
|
static ViewController* sInstance;
|
2014-06-25 16:29:58 +00:00
|
|
|
|
2020-11-17 16:30:23 +00:00
|
|
|
void launch(FileData* game);
|
|
|
|
|
2021-03-10 17:21:49 +00:00
|
|
|
std::string mNoGamesErrorMessage;
|
|
|
|
std::string mRomDirectory;
|
|
|
|
GuiMsgBox* mNoGamesMessageBox;
|
|
|
|
|
2020-11-15 21:54:39 +00:00
|
|
|
void playViewTransition(bool instant = false);
|
2020-06-21 12:25:28 +00:00
|
|
|
int getSystemId(SystemData* system);
|
2020-11-15 21:54:39 +00:00
|
|
|
// Restore view position if it was moved during wrap around.
|
|
|
|
void restoreViewPosition();
|
2019-08-25 15:23:02 +00:00
|
|
|
|
2020-06-21 12:25:28 +00:00
|
|
|
std::shared_ptr<GuiComponent> mCurrentView;
|
2020-11-15 21:54:39 +00:00
|
|
|
std::shared_ptr<GuiComponent> mPreviousView;
|
2020-11-18 21:26:58 +00:00
|
|
|
std::shared_ptr<GuiComponent> mSkipView;
|
2020-08-08 20:33:27 +00:00
|
|
|
std::map<SystemData*, std::shared_ptr<IGameListView>> mGameListViews;
|
2020-06-21 12:25:28 +00:00
|
|
|
std::shared_ptr<SystemView> mSystemListView;
|
2019-08-25 15:23:02 +00:00
|
|
|
|
2021-07-07 18:03:42 +00:00
|
|
|
FileData* mGameToLaunch;
|
|
|
|
State mState;
|
|
|
|
|
2020-06-21 12:25:28 +00:00
|
|
|
Transform4x4f mCamera;
|
2020-11-18 22:47:32 +00:00
|
|
|
bool mSystemViewTransition;
|
2020-11-15 21:54:39 +00:00
|
|
|
bool mWrappedViews;
|
|
|
|
float mWrapPreviousPositionX;
|
2020-06-21 12:25:28 +00:00
|
|
|
float mFadeOpacity;
|
2020-11-18 21:26:58 +00:00
|
|
|
bool mCancelledTransition; // Needed only for the Fade transition style.
|
2020-06-21 12:25:28 +00:00
|
|
|
bool mLockInput;
|
2021-01-01 20:45:51 +00:00
|
|
|
bool mNextSystem;
|
2014-06-25 16:29:58 +00:00
|
|
|
};
|
2017-10-31 17:12:50 +00:00
|
|
|
|
|
|
|
#endif // ES_APP_VIEWS_VIEW_CONTROLLER_H
|