From 3c5fa89eaf20f74cc16a4dbcee34bf928e6c5ca5 Mon Sep 17 00:00:00 2001 From: Aloshi Date: Fri, 21 Mar 2014 20:38:16 -0500 Subject: [PATCH] Added "PRESS ANYTHING" and "ALREADY TAKEN" notifications to GuiInputConfig. --- src/components/ComponentList.h | 2 +- src/guis/GuiInputConfig.cpp | 37 +++++++++++++++++++++++++++++----- src/guis/GuiInputConfig.h | 5 ++++- 3 files changed, 37 insertions(+), 7 deletions(-) diff --git a/src/components/ComponentList.h b/src/components/ComponentList.h index fc33d6417..5a0730891 100644 --- a/src/components/ComponentList.h +++ b/src/components/ComponentList.h @@ -61,7 +61,7 @@ public: bool moveCursor(int amt); inline int getCursorId() const { return mCursor; } - + float getTotalRowHeight() const; protected: diff --git a/src/guis/GuiInputConfig.cpp b/src/guis/GuiInputConfig.cpp index 509986c47..0b78a7ade 100644 --- a/src/guis/GuiInputConfig.cpp +++ b/src/guis/GuiInputConfig.cpp @@ -54,11 +54,18 @@ GuiInputConfig::GuiInputConfig(Window* window, InputConfig* target, bool reconfi icon->setResize(0, Font::get(FONT_SIZE_MEDIUM)->getHeight() * 0.8f); row.addElement(icon, false); + // spacer between icon and text + auto spacer = std::make_shared(mWindow); + spacer->setSize(16, 0); + row.addElement(spacer, false); + auto text = std::make_shared(mWindow, inputDispName[i], Font::get(FONT_SIZE_MEDIUM), 0x777777FF); row.addElement(text, true); - auto mapping = std::make_shared(mWindow, "-NOT DEFINED-", Font::get(FONT_SIZE_MEDIUM, FONT_PATH_LIGHT), 0x999999FF); + auto mapping = std::make_shared(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); + mMappings.push_back(mapping); 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; mConfiguringRow = false; mGrid.moveCursor(Vector2i(0, 1)); + }else{ + // on another one + setPress(mMappings.at(mList->getCursorId())); } }else{ 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) { mConfiguringRow = true; + setPress(mapping); return true; } return false; @@ -97,6 +108,10 @@ GuiInputConfig::GuiInputConfig(Window* window, InputConfig* target, bool reconfi mList->addRow(row); } + // make the first one say "NOT DEFINED" if we're re-configuring everything + if(mConfiguringAll) + setPress(mMappings.front()); + // buttons std::vector< std::shared_ptr > buttons; buttons.push_back(std::make_shared(mWindow, "OK", "ok", [this, okCallback] { @@ -125,10 +140,22 @@ void GuiInputConfig::onSizeChanged() mGrid.setRowHeightPerc(4, mButtonGrid->getSize().y() / mSize.y()); } -void GuiInputConfig::error(const std::string& msg) +void GuiInputConfig::setPress(const std::shared_ptr& text) { - // TODO - LOG(LogWarning) << msg; + text->setText("PRESS ANYTHING"); + text->setColor(0x656565FF); +} + +void GuiInputConfig::setNotDefined(const std::shared_ptr& text) +{ + text->setText("-NOT DEFINED-"); + text->setColor(0x999999FF); +} + +void GuiInputConfig::error(const std::shared_ptr& 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& 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(config->getMappedTo(input).size() > 0 && !config->isMappedTo(inputName[inputId], input)) { - error("Already mapped!"); + error(text, "Already mapped!"); return false; } diff --git a/src/guis/GuiInputConfig.h b/src/guis/GuiInputConfig.h index be701b029..e5c28a376 100644 --- a/src/guis/GuiInputConfig.h +++ b/src/guis/GuiInputConfig.h @@ -15,7 +15,9 @@ public: void onSizeChanged() override; private: - void error(const std::string& msg); + void error(const std::shared_ptr& text, const std::string& msg); + void setPress(const std::shared_ptr& text); + void setNotDefined(const std::shared_ptr& text); bool process(InputConfig* config, Input input, int inputId, const std::shared_ptr& text); NinePatchComponent mBackground; @@ -25,6 +27,7 @@ private: std::shared_ptr mSubtitle1; std::shared_ptr mSubtitle2; std::shared_ptr mList; + std::vector< std::shared_ptr > mMappings; std::shared_ptr mButtonGrid; InputConfig* mTargetConfig;