ES-DE/es-app/src/views/gamelist/ISimpleGameListView.cpp

171 lines
5.8 KiB
C++
Raw Normal View History

//
// ISimpleGameListView.cpp
//
// Interface that defines a simple GameListView.
//
#include "views/gamelist/ISimpleGameListView.h"
2017-11-01 22:21:10 +00:00
#include "views/UIModeController.h"
#include "views/ViewController.h"
#include "CollectionSystemManager.h"
2017-11-01 22:21:10 +00:00
#include "Settings.h"
#include "Sound.h"
#include "SystemData.h"
ISimpleGameListView::ISimpleGameListView(
Window* window,
FileData* root)
: IGameListView(window, root),
mHeaderText(window),
mHeaderImage(window),
mBackground(window)
{
mHeaderText.setText("Logo Text");
mHeaderText.setSize(mSize.x(), 0);
mHeaderText.setPosition(0, 0);
mHeaderText.setHorizontalAlignment(ALIGN_CENTER);
mHeaderText.setDefaultZIndex(50);
mHeaderImage.setResize(0, mSize.y() * 0.185f);
mHeaderImage.setOrigin(0.5f, 0.0f);
mHeaderImage.setPosition(mSize.x() / 2, 0);
mHeaderImage.setDefaultZIndex(50);
mBackground.setResize(mSize.x(), mSize.y());
mBackground.setDefaultZIndex(0);
addChild(&mHeaderText);
addChild(&mBackground);
}
void ISimpleGameListView::onThemeChanged(const std::shared_ptr<ThemeData>& theme)
{
using namespace ThemeFlags;
mBackground.applyTheme(theme, getName(), "background", ALL);
mHeaderImage.applyTheme(theme, getName(), "logo", ALL);
mHeaderText.applyTheme(theme, getName(), "logoText", ALL);
// Remove old theme extras.
2020-07-13 18:58:25 +00:00
for (auto extra : mThemeExtras) {
removeChild(extra);
delete extra;
}
mThemeExtras.clear();
// Add new theme extras.
mThemeExtras = ThemeData::makeExtras(theme, getName(), mWindow);
for (auto extra : mThemeExtras)
addChild(extra);
if (mHeaderImage.hasImage()) {
removeChild(&mHeaderText);
addChild(&mHeaderImage);
}
else {
addChild(&mHeaderText);
removeChild(&mHeaderImage);
}
}
2017-11-17 14:58:52 +00:00
void ISimpleGameListView::onFileChanged(FileData* /*file*/, FileChangeType /*change*/)
{
// We could be tricky here to be efficient;
// but this shouldn't happen very often so we'll just always repopulate.
FileData* cursor = getCursor();
if (!cursor->isPlaceHolder()) {
populateList(cursor->getParent()->getChildrenListToDisplay());
setCursor(cursor);
}
2020-07-13 18:58:25 +00:00
else {
populateList(mRoot->getChildrenListToDisplay());
setCursor(cursor);
}
}
bool ISimpleGameListView::input(InputConfig* config, Input input)
{
if (input.value != 0) {
if (config->isMappedTo("a", input)) {
FileData* cursor = getCursor();
if (cursor->getType() == GAME) {
launch(cursor);
}
else {
// It's a folder.
if (cursor->getChildren().size() > 0) {
NavigationSounds::getInstance()->playThemeNavigationSound(SELECTSOUND);
mCursorStack.push(cursor);
populateList(cursor->getChildrenListToDisplay());
FileData* cursor = getCursor();
setCursor(cursor);
}
}
return true;
}
else if (config->isMappedTo("b", input)) {
if (mCursorStack.size()) {
NavigationSounds::getInstance()->playThemeNavigationSound(BACKSOUND);
populateList(mCursorStack.top()->getParent()->getChildren());
setCursor(mCursorStack.top());
mCursorStack.pop();
}
else {
NavigationSounds::getInstance()->playThemeNavigationSound(BACKSOUND);
onFocusLost();
SystemData* systemToView = getCursor()->getSystem();
if (systemToView->isCollection())
systemToView = CollectionSystemManager::get()->getSystemToView(systemToView);
2020-07-13 18:58:25 +00:00
ViewController::get()->goToSystemView(systemToView);
}
return true;
}
else if (config->isMappedLike(getQuickSystemSelectRightButton(), input)) {
if (Settings::getInstance()->getBool("QuickSystemSelect")) {
onFocusLost();
ViewController::get()->goToNextGameList();
return true;
}
}
else if (config->isMappedLike(getQuickSystemSelectLeftButton(), input)) {
if (Settings::getInstance()->getBool("QuickSystemSelect")) {
onFocusLost();
ViewController::get()->goToPrevGameList();
return true;
}
}
else if (config->isMappedTo("x", input)) {
if (mRoot->getSystem()->isGameSystem()) {
// Go to random system game.
NavigationSounds::getInstance()->playThemeNavigationSound(SCROLLSOUND);
FileData* randomGame = getCursor()->getSystem()->getRandomGame(getCursor());
if (randomGame)
setCursor(randomGame);
// If it's not a game, maybe it's a folder for an unthemed collection.
else if (getCursor()->getSystem()->isCollection()) {
FileData* randomFolder =
mRoot->getSystem()->getRandomCollectionFolder(getCursor());
if (randomFolder)
setCursor(randomFolder);
}
return true;
}
}
else if (config->isMappedTo("y", input) &&
!UIModeController::getInstance()->isUIModeKid()) {
if (mRoot->getSystem()->isGameSystem()) {
if (getCursor()->getType() == GAME)
NavigationSounds::getInstance()->playThemeNavigationSound(FAVORITESOUND);
if (CollectionSystemManager::get()->toggleGameInCollection(getCursor()))
return true;
}
}
}
return IGameListView::input(config, input);
}