Refactor InGameMenu::getBtn* and GUI::getControl(Ptr) for brevity
Signed-off-by: William Brawner <me@wbrawner.com>
This commit is contained in:
parent
6fd62fc65c
commit
46bb9d42f6
2 changed files with 8 additions and 22 deletions
|
@ -250,17 +250,11 @@ void InGameMenu::onClick(const string &control) {
|
|||
}
|
||||
|
||||
shared_ptr<Button> InGameMenu::getBtnChange2() {
|
||||
if (!isTSL(_game->gameId())) {
|
||||
return nullptr;
|
||||
}
|
||||
return getControlPtr<Button>("BTN_CHANGE2");
|
||||
return isTSL(_game->gameId()) ? getControlPtr<Button>("BTN_CHANGE2") : nullptr;
|
||||
}
|
||||
|
||||
shared_ptr<Button> InGameMenu::getBtnChange3() {
|
||||
if (!isTSL(_game->gameId())) {
|
||||
return nullptr;
|
||||
}
|
||||
return getControlPtr<Button>("BTN_CHANGE3");
|
||||
return isTSL(_game->gameId()) ? getControlPtr<Button>("BTN_CHANGE3") : nullptr;
|
||||
}
|
||||
|
||||
} // namespace game
|
||||
|
|
|
@ -324,24 +324,16 @@ void GUI::setControlDiscardColor(const string &tag, glm::vec3 color) {
|
|||
}
|
||||
|
||||
Control &GUI::getControl(const string &tag) const {
|
||||
auto it = find_if(
|
||||
_controls.begin(),
|
||||
_controls.end(),
|
||||
[&tag](auto &ctrl) { return ctrl->tag() == tag; });
|
||||
|
||||
if (it != _controls.end()) return **it;
|
||||
|
||||
for (auto &control : _controls) {
|
||||
if (control->tag() == tag) return *control;
|
||||
}
|
||||
throw runtime_error("Control not found: " + tag);
|
||||
}
|
||||
|
||||
shared_ptr<Control> GUI::getControlPtr(const string &tag) const {
|
||||
auto it = find_if(
|
||||
_controls.begin(),
|
||||
_controls.end(),
|
||||
[&tag](auto &ctrl) { return ctrl->tag() == tag; });
|
||||
|
||||
if (it != _controls.end()) return *it;
|
||||
|
||||
for (auto &control : _controls) {
|
||||
if (control->tag() == tag) return control;
|
||||
}
|
||||
throw runtime_error("Control not found: " + tag);
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue