Go-to Random Game feature

This commit is contained in:
D. Polders 2016-12-20 21:25:35 +01:00
parent 4cc0ced851
commit 3c76a4b5a7
7 changed files with 58 additions and 0 deletions

View file

@ -35,6 +35,19 @@ GuiGamelistOptions::GuiGamelistOptions(Window* window, SystemData* system) : Gui
}; };
mMenu.addRow(row); 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 // sort list by
mListSort = std::make_shared<SortList>(mWindow, "SORT GAMES BY", false); mListSort = std::make_shared<SortList>(mWindow, "SORT GAMES BY", false);
for(unsigned int i = 0; i < FileSorts::SortTypes.size(); i++) for(unsigned int i = 0; i < FileSorts::SortTypes.size(); i++)

View file

@ -166,6 +166,8 @@ void onExit()
int main(int argc, char* argv[]) int main(int argc, char* argv[])
{ {
srand((unsigned int)time(NULL));
unsigned int width = 0; unsigned int width = 0;
unsigned int height = 0; unsigned int height = 0;

View file

@ -134,6 +134,11 @@ bool SystemView::input(InputConfig* config, Input input)
ViewController::get()->goToGameList(getSelected()); ViewController::get()->goToGameList(getSelected());
return true; return true;
} }
if (config->isMappedTo("x", input))
{
ViewController::get()->goToRandomGame();
return true;
}
}else{ }else{
if(config->isMappedTo("left", input) || if(config->isMappedTo("left", input) ||
config->isMappedTo("right", input) || config->isMappedTo("right", input) ||
@ -286,6 +291,7 @@ std::vector<HelpPrompt> SystemView::getHelpPrompts()
else else
prompts.push_back(HelpPrompt("left/right", "choose")); prompts.push_back(HelpPrompt("left/right", "choose"));
prompts.push_back(HelpPrompt("a", "select")); prompts.push_back(HelpPrompt("a", "select"));
prompts.push_back(HelpPrompt("x", "random"));
return prompts; return prompts;
} }

View file

@ -119,6 +119,37 @@ void ViewController::goToGameList(SystemData* system)
playViewTransition(); 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() void ViewController::playViewTransition()
{ {
Eigen::Vector3f target(Eigen::Vector3f::Identity()); Eigen::Vector3f target(Eigen::Vector3f::Identity());

View file

@ -30,6 +30,7 @@ public:
void goToGameList(SystemData* system); void goToGameList(SystemData* system);
void goToSystemView(SystemData* system); void goToSystemView(SystemData* system);
void goToStart(); void goToStart();
void goToRandomGame();
void onFileChanged(FileData* file, FileChangeType change); void onFileChanged(FileData* file, FileChangeType change);

View file

@ -118,5 +118,6 @@ std::vector<HelpPrompt> BasicGameListView::getHelpPrompts()
prompts.push_back(HelpPrompt("a", "launch")); prompts.push_back(HelpPrompt("a", "launch"));
prompts.push_back(HelpPrompt("b", "back")); prompts.push_back(HelpPrompt("b", "back"));
prompts.push_back(HelpPrompt("select", "options")); prompts.push_back(HelpPrompt("select", "options"));
prompts.push_back(HelpPrompt("x", "random"));
return prompts; return prompts;
} }

View file

@ -102,6 +102,10 @@ bool ISimpleGameListView::input(InputConfig* config, Input input)
ViewController::get()->goToPrevGameList(); ViewController::get()->goToPrevGameList();
return true; return true;
} }
}else if (config->isMappedTo("x", input))
{
ViewController::get()->goToRandomGame();
return true;
} }
} }