mirror of
https://github.com/RetroDECK/ES-DE.git
synced 2024-11-22 22:25:38 +00:00
Merge pull request #118 from zigurana/RandomGame
Go-to Random Game feature
This commit is contained in:
commit
3e15aef1fc
|
@ -35,6 +35,19 @@ GuiGamelistOptions::GuiGamelistOptions(Window* window, SystemData* system) : Gui
|
|||
};
|
||||
mMenu.addRow(row);
|
||||
|
||||
row.elements.clear();
|
||||
row.addElement(std::make_shared<TextComponent>(mWindow, "SURPRISE ME!", Font::get(FONT_SIZE_MEDIUM), 0x777777FF), true);
|
||||
row.input_handler = [&](InputConfig* config, Input input) {
|
||||
if (config->isMappedTo("a", input) && input.value)
|
||||
{
|
||||
ViewController::get()->goToRandomGame();
|
||||
delete this;
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
};
|
||||
mMenu.addRow(row);
|
||||
|
||||
// sort list by
|
||||
mListSort = std::make_shared<SortList>(mWindow, "SORT GAMES BY", false);
|
||||
for(unsigned int i = 0; i < FileSorts::SortTypes.size(); i++)
|
||||
|
|
|
@ -166,6 +166,8 @@ void onExit()
|
|||
|
||||
int main(int argc, char* argv[])
|
||||
{
|
||||
srand((unsigned int)time(NULL));
|
||||
|
||||
unsigned int width = 0;
|
||||
unsigned int height = 0;
|
||||
|
||||
|
|
|
@ -134,6 +134,11 @@ bool SystemView::input(InputConfig* config, Input input)
|
|||
ViewController::get()->goToGameList(getSelected());
|
||||
return true;
|
||||
}
|
||||
if (config->isMappedTo("x", input))
|
||||
{
|
||||
ViewController::get()->goToRandomGame();
|
||||
return true;
|
||||
}
|
||||
}else{
|
||||
if(config->isMappedTo("left", input) ||
|
||||
config->isMappedTo("right", input) ||
|
||||
|
@ -286,6 +291,7 @@ std::vector<HelpPrompt> SystemView::getHelpPrompts()
|
|||
else
|
||||
prompts.push_back(HelpPrompt("left/right", "choose"));
|
||||
prompts.push_back(HelpPrompt("a", "select"));
|
||||
prompts.push_back(HelpPrompt("x", "random"));
|
||||
return prompts;
|
||||
}
|
||||
|
||||
|
|
|
@ -119,6 +119,37 @@ void ViewController::goToGameList(SystemData* system)
|
|||
playViewTransition();
|
||||
}
|
||||
|
||||
void ViewController::goToRandomGame()
|
||||
{
|
||||
unsigned int total = 0;
|
||||
for(auto it = SystemData::sSystemVector.begin(); it != SystemData::sSystemVector.end(); it++)
|
||||
{
|
||||
if ((*it)->getName() != "retropie")
|
||||
total += (*it)->getGameCount();
|
||||
}
|
||||
|
||||
// get random number in range
|
||||
int target = std::round(((double)std::rand() / (double)RAND_MAX) * total);
|
||||
|
||||
for (auto it = SystemData::sSystemVector.begin(); it != SystemData::sSystemVector.end(); it++)
|
||||
{
|
||||
if ((*it)->getName() != "retropie")
|
||||
{
|
||||
if ((target - (int)(*it)->getGameCount()) >= 0)
|
||||
{
|
||||
target -= (int)(*it)->getGameCount();
|
||||
}
|
||||
else
|
||||
{
|
||||
goToGameList(*it);
|
||||
std::vector<FileData*> list = (*it)->getRootFolder()->getFilesRecursive(GAME);
|
||||
getGameListView(*it)->setCursor(list.at(target));
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void ViewController::playViewTransition()
|
||||
{
|
||||
Eigen::Vector3f target(Eigen::Vector3f::Identity());
|
||||
|
|
|
@ -30,6 +30,7 @@ public:
|
|||
void goToGameList(SystemData* system);
|
||||
void goToSystemView(SystemData* system);
|
||||
void goToStart();
|
||||
void goToRandomGame();
|
||||
|
||||
void onFileChanged(FileData* file, FileChangeType change);
|
||||
|
||||
|
|
|
@ -118,5 +118,6 @@ std::vector<HelpPrompt> BasicGameListView::getHelpPrompts()
|
|||
prompts.push_back(HelpPrompt("a", "launch"));
|
||||
prompts.push_back(HelpPrompt("b", "back"));
|
||||
prompts.push_back(HelpPrompt("select", "options"));
|
||||
prompts.push_back(HelpPrompt("x", "random"));
|
||||
return prompts;
|
||||
}
|
||||
|
|
|
@ -102,6 +102,10 @@ bool ISimpleGameListView::input(InputConfig* config, Input input)
|
|||
ViewController::get()->goToPrevGameList();
|
||||
return true;
|
||||
}
|
||||
}else if (config->isMappedTo("x", input))
|
||||
{
|
||||
ViewController::get()->goToRandomGame();
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue