Fixing random game selection, and aligning menus

- Fixing off-by-one error
- Update menu alignment
This commit is contained in:
pjft 2017-07-11 10:07:44 +01:00
parent 2decb2b6a4
commit a035433d1d
3 changed files with 4 additions and 22 deletions

View file

@ -383,13 +383,12 @@ SystemData* SystemData::getRandomSystem()
} }
// get random number in range // get random number in range
int target = std::round(((double)std::rand() / (double)RAND_MAX) * total); int target = std::round(((double)std::rand() / (double)RAND_MAX) * (total - 1));
for (auto it = sSystemVector.begin(); it != sSystemVector.end(); it++) for (auto it = sSystemVector.begin(); it != sSystemVector.end(); it++)
{ {
if ((*it)->isGameSystem()) if ((*it)->isGameSystem())
{ {
if (target >= 0) if (target > 0)
{ {
target--; target--;
} }
@ -406,7 +405,7 @@ FileData* SystemData::getRandomGame()
std::vector<FileData*> list = mRootFolder->getFilesRecursive(GAME, true); std::vector<FileData*> list = mRootFolder->getFilesRecursive(GAME, true);
unsigned int total = list.size(); unsigned int total = list.size();
// get random number in range // get random number in range
int target = std::round(((double)std::rand() / (double)RAND_MAX) * total); int target = std::round(((double)std::rand() / (double)RAND_MAX) * (total - 1));
return list.at(target); return list.at(target);
} }

View file

@ -69,19 +69,6 @@ GuiGamelistOptions::GuiGamelistOptions(Window* window, SystemData* system) : Gui
row.makeAcceptInputHandler(std::bind(&GuiGamelistOptions::openGamelistFilter, this)); row.makeAcceptInputHandler(std::bind(&GuiGamelistOptions::openGamelistFilter, this));
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);
// center the menu // center the menu
setSize((float)Renderer::getScreenWidth(), (float)Renderer::getScreenHeight()); setSize((float)Renderer::getScreenWidth(), (float)Renderer::getScreenHeight());
mMenu.setPosition((mSize.x() - mMenu.getSize().x()) / 2, (mSize.y() - mMenu.getSize().y()) / 2); mMenu.setPosition((mSize.x() - mMenu.getSize().x()) / 2, (mSize.y() - mMenu.getSize().y()) / 2);

View file

@ -373,12 +373,8 @@ GuiMenu::GuiMenu(Window* window) : GuiComponent(window), mMenu(window, "MAIN MEN
addChild(&mMenu); addChild(&mMenu);
addChild(&mVersion); addChild(&mVersion);
/*int menuWidth = Renderer::getScreenWidth() * 0.4f;
int menuHeight = Renderer::getScreenHeight() * 0.74f;
mMenu.setSize(menuWidth, menuHeight);*/
setSize(mMenu.getSize()); setSize(mMenu.getSize());
setPosition((Renderer::getScreenWidth() - mSize.x()) / 2, Renderer::getScreenHeight() * 0.13f); setPosition((Renderer::getScreenWidth() - mSize.x()) / 2, Renderer::getScreenHeight() * 0.15f);
} }
void GuiMenu::openScreensaverOptions() { void GuiMenu::openScreensaverOptions() {