Fixed help system being broken for MenuComponent. Still missing in a few places.

Added some "BACK" buttons to various GUIs.
This commit is contained in:
Aloshi 2014-03-13 14:09:50 -05:00
parent 5039b38d8d
commit 18b428f79a
12 changed files with 77 additions and 27 deletions

View file

@ -412,8 +412,8 @@ std::vector<HelpPrompt> ComponentGrid::getHelpPrompts()
if(e)
prompts = e->component->getHelpPrompts();
bool canScrollVert = true;
bool canScrollHoriz = true;
bool canScrollVert = mGridSize.y() > 1;
bool canScrollHoriz = mGridSize.x() > 1;
for(auto it = prompts.begin(); it != prompts.end(); it++)
{
if(it->first == "up/down/left/right")

View file

@ -117,6 +117,8 @@ void ComponentList::onCursorChanged(const CursorState& state)
else if(mCameraOffset + mSize.y() > totalHeight)
mCameraOffset = totalHeight - mSize.y();
}
updateHelpPrompts();
}
void ComponentList::render(const Eigen::Affine3f& parentTrans)
@ -238,3 +240,11 @@ void ComponentList::updateElementSize(const ComponentListRow& row)
(*it)->setSize(width, (*it)->getSize().y());
}
}
std::vector<HelpPrompt> ComponentList::getHelpPrompts()
{
if(!size())
return std::vector<HelpPrompt>();
return mEntries.at(mCursor).data.elements.back().component->getHelpPrompts();
}

View file

@ -50,6 +50,7 @@ public:
bool input(InputConfig* config, Input input) override;
void update(int deltaTime) override;
void render(const Eigen::Affine3f& parentTrans) override;
virtual std::vector<HelpPrompt> getHelpPrompts() override;
void onSizeChanged() override;
void onFocusGained() override;

View file

@ -77,3 +77,8 @@ void MenuComponent::updateGrid()
mButtonGrid.reset();
}
}
std::vector<HelpPrompt> MenuComponent::getHelpPrompts()
{
return mGrid.getHelpPrompts();
}

View file

@ -30,6 +30,8 @@ public:
inline void setCursorToList() { mGrid.setCursorTo(mList); }
inline void setCursorToButtons() { assert(mButtonGrid); mGrid.setCursorTo(mButtonGrid); }
virtual std::vector<HelpPrompt> getHelpPrompts() override;
private:
void updateSize();
void updateGrid();

View file

@ -37,8 +37,8 @@ private:
OptionListComponent<T>* mParent;
public:
OptionListPopup(Window* window, OptionListComponent<T>* parent) : GuiComponent(window),
mMenu(window, ""), mParent(parent)
OptionListPopup(Window* window, OptionListComponent<T>* parent, const std::string& title) : GuiComponent(window),
mMenu(window, title.c_str()), mParent(parent)
{
auto font = Font::get(FONT_SIZE_MEDIUM);
ComponentListRow row;
@ -85,7 +85,10 @@ private:
mMenu.addRow(row, (!mParent->mMultiSelect && it->selected));
}
mMenu.setPosition((Renderer::getScreenWidth() - mMenu.getSize().x()) / 2, (Renderer::getScreenHeight() - mMenu.getSize().y()) / 2);
if(mParent->mMultiSelect)
mMenu.addButton("BACK", "accept", [this] { delete this; });
mMenu.setPosition((Renderer::getScreenWidth() - mMenu.getSize().x()) / 2, Renderer::getScreenHeight() * 0.15f);
addChild(&mMenu);
}
@ -102,7 +105,7 @@ private:
};
public:
OptionListComponent(Window* window, bool multiSelect = false) : GuiComponent(window), mMultiSelect(multiSelect),
OptionListComponent(Window* window, const std::string& name, bool multiSelect = false) : GuiComponent(window), mMultiSelect(multiSelect), mName(name),
mText(window), mLeftArrow(window), mRightArrow(window)
{
auto font = Font::get(FONT_SIZE_MEDIUM);
@ -124,10 +127,10 @@ public:
addChild(&mRightArrow);
}
// handles positioning/resizing of text and arrows
setSize(Renderer::getScreenWidth() * 0.2f, (float)font->getHeight());
setSize(mLeftArrow.getSize().x() + mRightArrow.getSize().x(), (float)font->getHeight());
}
// handles positioning/resizing of text and arrows
void onSizeChanged() override
{
// size
@ -239,7 +242,7 @@ private:
void open()
{
mWindow->pushGui(new OptionListPopup(mWindow, this));
mWindow->pushGui(new OptionListPopup(mWindow, this, mName));
}
void onSelectedChanged()
@ -250,6 +253,10 @@ private:
std::stringstream ss;
ss << getSelectedObjects().size() << " selected";
mText.setText(ss.str());
mText.setSize(0, mText.getSize().y());
setSize(mText.getSize().x() + mRightArrow.getSize().x() + 16, mText.getSize().y());
if(mParent) // hack since theres no "on child size changed" callback atm...
mParent->onSizeChanged();
}else{
// display currently selected + l/r cursors
for(auto it = mEntries.begin(); it != mEntries.end(); it++)
@ -257,14 +264,29 @@ private:
if(it->selected)
{
mText.setText(it->name);
mText.setSize(0, mText.getSize().y());
setSize(mText.getSize().x() + mLeftArrow.getSize().x() + mRightArrow.getSize().x() + 16, mText.getSize().y());
if(mParent) // hack since theres no "on child size changed" callback atm...
mParent->onSizeChanged();
break;
}
}
}
}
std::vector<HelpPrompt> getHelpPrompts() override
{
std::vector<HelpPrompt> prompts;
if(!mMultiSelect)
prompts.push_back(HelpPrompt("left/right", "change"));
prompts.push_back(HelpPrompt("a", "change"));
return prompts;
}
bool mMultiSelect;
std::string mName;
TextComponent mText;
ImageComponent mLeftArrow;
ImageComponent mRightArrow;

View file

@ -60,8 +60,7 @@ public:
inline void setFont(const std::shared_ptr<Font>& font)
{
mFont = font;
this->mTitleOverlayFont = Font::get(FONT_SIZE_LARGE, mFont->getPath());
for(auto it = mEntries.begin(); it != mEntries.end(); it++)
it->data.textCache.reset();
}

View file

@ -44,7 +44,7 @@ GuiMenu::GuiMenu(Window* window) : GuiComponent(window), mMenu(window, "MAIN MEN
auto s = new GuiSettings(mWindow, "SCRAPER");
// scrape from
auto scraper_list = std::make_shared< OptionListComponent< std::shared_ptr<Scraper> > >(mWindow, false);
auto scraper_list = std::make_shared< OptionListComponent< std::shared_ptr<Scraper> > >(mWindow, "SCRAPE FROM", false);
std::vector< std::shared_ptr<Scraper> > scrapers;
scrapers.push_back(std::make_shared<GamesDBScraper>());
scrapers.push_back(std::make_shared<TheArchiveScraper>());
@ -152,14 +152,14 @@ GuiMenu::GuiMenu(Window* window) : GuiComponent(window), mMenu(window, "MAIN MEN
{
row.elements.clear();
row.makeAcceptInputHandler([window] {
window->pushGui(new GuiMsgBoxYesNo(window, "REALLY EXIT?",
window->pushGui(new GuiMsgBoxYesNo(window, "REALLY QUIT?",
[] {
SDL_Event ev;
ev.type = SDL_QUIT;
SDL_PushEvent(&ev);
}));
});
row.addElement(std::make_shared<TextComponent>(window, "EXIT EMULATIONSTATION", Font::get(FONT_SIZE_MEDIUM), 0x770000FF), true);
row.addElement(std::make_shared<TextComponent>(window, "QUIT EMULATIONSTATION", Font::get(FONT_SIZE_MEDIUM), 0x777777FF), true);
s->addRow(row);
}
@ -199,3 +199,11 @@ bool GuiMenu::input(InputConfig* config, Input input)
return GuiComponent::input(config, input);
}
std::vector<HelpPrompt> GuiMenu::getHelpPrompts()
{
std::vector<HelpPrompt> prompts;
prompts.push_back(HelpPrompt("up/down", "move cursor"));
prompts.push_back(HelpPrompt("a", "accept"));
return prompts;
}

View file

@ -10,6 +10,7 @@ public:
GuiMenu(Window* window);
bool input(InputConfig* config, Input input) override;
std::vector<HelpPrompt> getHelpPrompts() override;
private:
void addEntry(const char* name, unsigned int color, bool add_arrow, const std::function<void()>& func);

View file

@ -12,7 +12,7 @@ GuiScraperStart::GuiScraperStart(Window* window) : GuiComponent(window),
addChild(&mMenu);
// add filters (with first one selected)
mFilters = std::make_shared< OptionListComponent<GameFilterFunc> >(mWindow, false);
mFilters = std::make_shared< OptionListComponent<GameFilterFunc> >(mWindow, "SCRAPE THESE GAMES", false);
mFilters->add("All Games",
[](SystemData*, FileData*) -> bool { return true; }, true);
mFilters->add("Only missing image",
@ -20,20 +20,16 @@ GuiScraperStart::GuiScraperStart(Window* window) : GuiComponent(window),
mMenu.addWithLabel("Filter", mFilters);
//add systems (all with a platformid specified selected)
mSystems = std::make_shared< OptionListComponent<SystemData*> >(mWindow, true);
mSystems = std::make_shared< OptionListComponent<SystemData*> >(mWindow, "SCRAPE THESE SYSTEMS", true);
for(auto it = SystemData::sSystemVector.begin(); it != SystemData::sSystemVector.end(); it++)
mSystems->add((*it)->getFullName(), *it, (*it)->getPlatformId() != PlatformIds::PLATFORM_UNKNOWN);
mMenu.addWithLabel("Systems", mSystems);
mAutoStyle = std::make_shared< OptionListComponent<int> >(mWindow, false);
mAutoStyle->add("Never automatically accept result", 0, true);
mAutoStyle->add("Always accept first result", 1, false);
mMenu.addWithLabel("Auto style", mAutoStyle);
mApproveResults = std::make_shared<SwitchComponent>(mWindow);
mApproveResults->setState(true);
mMenu.addWithLabel("User decides on conflicts", mApproveResults);
ComponentListRow row;
row.addElement(std::make_shared<TextComponent>(mWindow, "GO GO GO", Font::get(FONT_SIZE_MEDIUM), 0x777777FF), true);
row.makeAcceptInputHandler(std::bind(&GuiScraperStart::pressedStart, this));
mMenu.addRow(row);
mMenu.addButton("START", "start scraping", std::bind(&GuiScraperStart::pressedStart, this));
mMenu.setPosition((Renderer::getScreenWidth() - mMenu.getSize().x()) / 2, Renderer::getScreenHeight() * 0.15f);
}
@ -58,7 +54,7 @@ void GuiScraperStart::start()
{
std::queue<ScraperSearchParams> searches = getSearches(mSystems->getSelectedObjects(), mFilters->getSelected());
GuiScraperLog* gsl = new GuiScraperLog(mWindow, searches, mAutoStyle->getSelected() == 0);
GuiScraperLog* gsl = new GuiScraperLog(mWindow, searches, mApproveResults->getState());
mWindow->pushGui(gsl);
gsl->start();
delete this;

View file

@ -32,7 +32,7 @@ private:
std::shared_ptr< OptionListComponent<GameFilterFunc> > mFilters;
std::shared_ptr< OptionListComponent<SystemData*> > mSystems;
std::shared_ptr< OptionListComponent<int> > mAutoStyle;
std::shared_ptr<SwitchComponent> mApproveResults;
MenuComponent mMenu;
};

View file

@ -5,6 +5,8 @@ GuiSettings::GuiSettings(Window* window, const char* title) : GuiComponent(windo
{
addChild(&mMenu);
mMenu.addButton("BACK", "go back", [this] { delete this; });
setSize((float)Renderer::getScreenWidth(), (float)Renderer::getScreenHeight());
mMenu.setPosition((mSize.x() - mMenu.getSize().x()) / 2, Renderer::getScreenHeight() * 0.15f);
}
@ -38,5 +40,9 @@ bool GuiSettings::input(InputConfig* config, Input input)
std::vector<HelpPrompt> GuiSettings::getHelpPrompts()
{
return mMenu.getHelpPrompts();
std::vector<HelpPrompt> prompts = mMenu.getHelpPrompts();
prompts.push_back(HelpPrompt("b", "go back"));
return prompts;
}