Added "PRESS ANYTHING" and "ALREADY TAKEN" notifications to GuiInputConfig.

This commit is contained in:
Aloshi 2014-03-21 20:38:16 -05:00
parent 980a2c4ec6
commit 3c5fa89eaf
3 changed files with 37 additions and 7 deletions

View file

@ -54,11 +54,18 @@ GuiInputConfig::GuiInputConfig(Window* window, InputConfig* target, bool reconfi
icon->setResize(0, Font::get(FONT_SIZE_MEDIUM)->getHeight() * 0.8f); icon->setResize(0, Font::get(FONT_SIZE_MEDIUM)->getHeight() * 0.8f);
row.addElement(icon, false); row.addElement(icon, false);
// spacer between icon and text
auto spacer = std::make_shared<GuiComponent>(mWindow);
spacer->setSize(16, 0);
row.addElement(spacer, false);
auto text = std::make_shared<TextComponent>(mWindow, inputDispName[i], Font::get(FONT_SIZE_MEDIUM), 0x777777FF); auto text = std::make_shared<TextComponent>(mWindow, inputDispName[i], Font::get(FONT_SIZE_MEDIUM), 0x777777FF);
row.addElement(text, true); row.addElement(text, true);
auto mapping = std::make_shared<TextComponent>(mWindow, "-NOT DEFINED-", Font::get(FONT_SIZE_MEDIUM, FONT_PATH_LIGHT), 0x999999FF); auto mapping = std::make_shared<TextComponent>(mWindow, "-NOT DEFINED-", Font::get(FONT_SIZE_MEDIUM, FONT_PATH_LIGHT), 0x999999FF, TextComponent::ALIGN_RIGHT);
setNotDefined(mapping); // overrides text and color set above
row.addElement(mapping, true); row.addElement(mapping, true);
mMappings.push_back(mapping);
row.input_handler = [this, i, mapping](InputConfig* config, Input input) -> bool row.input_handler = [this, i, mapping](InputConfig* config, Input input) -> bool
{ {
@ -77,6 +84,9 @@ GuiInputConfig::GuiInputConfig(Window* window, InputConfig* target, bool reconfi
mConfiguringAll = false; mConfiguringAll = false;
mConfiguringRow = false; mConfiguringRow = false;
mGrid.moveCursor(Vector2i(0, 1)); mGrid.moveCursor(Vector2i(0, 1));
}else{
// on another one
setPress(mMappings.at(mList->getCursorId()));
} }
}else{ }else{
mConfiguringRow = false; // we only wanted to configure one row mConfiguringRow = false; // we only wanted to configure one row
@ -87,6 +97,7 @@ GuiInputConfig::GuiInputConfig(Window* window, InputConfig* target, bool reconfi
if(config->isMappedTo("a", input) && input.value) if(config->isMappedTo("a", input) && input.value)
{ {
mConfiguringRow = true; mConfiguringRow = true;
setPress(mapping);
return true; return true;
} }
return false; return false;
@ -97,6 +108,10 @@ GuiInputConfig::GuiInputConfig(Window* window, InputConfig* target, bool reconfi
mList->addRow(row); mList->addRow(row);
} }
// make the first one say "NOT DEFINED" if we're re-configuring everything
if(mConfiguringAll)
setPress(mMappings.front());
// buttons // buttons
std::vector< std::shared_ptr<ButtonComponent> > buttons; std::vector< std::shared_ptr<ButtonComponent> > buttons;
buttons.push_back(std::make_shared<ButtonComponent>(mWindow, "OK", "ok", [this, okCallback] { buttons.push_back(std::make_shared<ButtonComponent>(mWindow, "OK", "ok", [this, okCallback] {
@ -125,10 +140,22 @@ void GuiInputConfig::onSizeChanged()
mGrid.setRowHeightPerc(4, mButtonGrid->getSize().y() / mSize.y()); mGrid.setRowHeightPerc(4, mButtonGrid->getSize().y() / mSize.y());
} }
void GuiInputConfig::error(const std::string& msg) void GuiInputConfig::setPress(const std::shared_ptr<TextComponent>& text)
{ {
// TODO text->setText("PRESS ANYTHING");
LOG(LogWarning) << msg; text->setColor(0x656565FF);
}
void GuiInputConfig::setNotDefined(const std::shared_ptr<TextComponent>& text)
{
text->setText("-NOT DEFINED-");
text->setColor(0x999999FF);
}
void GuiInputConfig::error(const std::shared_ptr<TextComponent>& text, const std::string& msg)
{
text->setText("ALREADY TAKEN");
text->setColor(0x656565FF);
} }
bool GuiInputConfig::process(InputConfig* config, Input input, int inputId, const std::shared_ptr<TextComponent>& text) bool GuiInputConfig::process(InputConfig* config, Input input, int inputId, const std::shared_ptr<TextComponent>& text)
@ -141,7 +168,7 @@ bool GuiInputConfig::process(InputConfig* config, Input input, int inputId, cons
// (if it's the same as what it was before, allow it) // (if it's the same as what it was before, allow it)
if(config->getMappedTo(input).size() > 0 && !config->isMappedTo(inputName[inputId], input)) if(config->getMappedTo(input).size() > 0 && !config->isMappedTo(inputName[inputId], input))
{ {
error("Already mapped!"); error(text, "Already mapped!");
return false; return false;
} }

View file

@ -15,7 +15,9 @@ public:
void onSizeChanged() override; void onSizeChanged() override;
private: private:
void error(const std::string& msg); void error(const std::shared_ptr<TextComponent>& text, const std::string& msg);
void setPress(const std::shared_ptr<TextComponent>& text);
void setNotDefined(const std::shared_ptr<TextComponent>& text);
bool process(InputConfig* config, Input input, int inputId, const std::shared_ptr<TextComponent>& text); bool process(InputConfig* config, Input input, int inputId, const std::shared_ptr<TextComponent>& text);
NinePatchComponent mBackground; NinePatchComponent mBackground;
@ -25,6 +27,7 @@ private:
std::shared_ptr<TextComponent> mSubtitle1; std::shared_ptr<TextComponent> mSubtitle1;
std::shared_ptr<TextComponent> mSubtitle2; std::shared_ptr<TextComponent> mSubtitle2;
std::shared_ptr<ComponentList> mList; std::shared_ptr<ComponentList> mList;
std::vector< std::shared_ptr<TextComponent> > mMappings;
std::shared_ptr<ComponentGrid> mButtonGrid; std::shared_ptr<ComponentGrid> mButtonGrid;
InputConfig* mTargetConfig; InputConfig* mTargetConfig;