mirror of
https://github.com/Cockatrice/Cockatrice.git
synced 2026-07-06 05:23:56 -07:00
refactor: Create forManagedComponents method
This commit is contained in:
parent
b7b7a385ea
commit
c8b6d7bf83
2 changed files with 11 additions and 9 deletions
|
|
@ -144,9 +144,7 @@ void PlayerMenu::setShortcutsActive()
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!player->getGame()->getGameMetaInfo()->started()) {
|
if (!player->getGame()->getGameMetaInfo()->started()) {
|
||||||
for (auto *component : managedComponents) {
|
forManagedComponents([](auto *component) { component->setShortcutsInactive(); });
|
||||||
component->setShortcutsInactive();
|
|
||||||
}
|
|
||||||
|
|
||||||
QMapIterator<int, AbstractCounter *> counterIterator(player->getCounters());
|
QMapIterator<int, AbstractCounter *> counterIterator(player->getCounters());
|
||||||
while (counterIterator.hasNext()) {
|
while (counterIterator.hasNext()) {
|
||||||
|
|
@ -159,9 +157,7 @@ void PlayerMenu::setShortcutsActive()
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
for (auto *component : managedComponents) {
|
forManagedComponents([](auto *component) { component->setShortcutsActive(); });
|
||||||
component->setShortcutsActive();
|
|
||||||
}
|
|
||||||
|
|
||||||
// Counters implement AbstractPlayerComponent but are iterated via Player::counters
|
// Counters implement AbstractPlayerComponent but are iterated via Player::counters
|
||||||
// (the authoritative source) rather than managedComponents to avoid a redundant
|
// (the authoritative source) rather than managedComponents to avoid a redundant
|
||||||
|
|
@ -176,9 +172,7 @@ void PlayerMenu::setShortcutsInactive()
|
||||||
{
|
{
|
||||||
shortcutsActive = false;
|
shortcutsActive = false;
|
||||||
|
|
||||||
for (auto *component : managedComponents) {
|
forManagedComponents([](auto *component) { component->setShortcutsInactive(); });
|
||||||
component->setShortcutsInactive();
|
|
||||||
}
|
|
||||||
|
|
||||||
QMapIterator<int, AbstractCounter *> counterIterator(player->getCounters());
|
QMapIterator<int, AbstractCounter *> counterIterator(player->getCounters());
|
||||||
while (counterIterator.hasNext()) {
|
while (counterIterator.hasNext()) {
|
||||||
|
|
|
||||||
|
|
@ -111,6 +111,14 @@ private:
|
||||||
managedComponents.append(component);
|
managedComponents.append(component);
|
||||||
return component;
|
return component;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Runs a normal for loop over all managedComponents, applying the provided function.
|
||||||
|
template <typename Func> void forManagedComponents(Func func)
|
||||||
|
{
|
||||||
|
for (auto *component : managedComponents) {
|
||||||
|
func(component);
|
||||||
|
}
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // COCKATRICE_PLAYER_MENU_H
|
#endif // COCKATRICE_PLAYER_MENU_H
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue