Implement config-driven unlock groups so that multiple things can be unlocked at once (including buildings)
This commit is contained in:
@@ -82,6 +82,7 @@ BuildButtonGrid::BuildButtonGrid(Simulation* sim, const GameConfig* config, QWid
|
||||
std::make_shared<DemolishModeToggleRequestedEvent>());
|
||||
});
|
||||
|
||||
updateVisibility();
|
||||
registerForEvents();
|
||||
}
|
||||
|
||||
@@ -119,6 +120,17 @@ void BuildButtonGrid::updateAffordability()
|
||||
}
|
||||
}
|
||||
|
||||
void BuildButtonGrid::updateVisibility()
|
||||
{
|
||||
// A locked building type's button is hidden until its unlock group is awarded
|
||||
// (REQ-LOCK-BUILDING). Buttons keep their index so hotkeys/affordability stay
|
||||
// stable; they simply appear once the type is unlocked.
|
||||
for (std::size_t i = 0; i < m_buttons.size(); ++i)
|
||||
{
|
||||
m_buttons[i]->setVisible(m_sim->isBuildingUnlocked(m_types[i]));
|
||||
}
|
||||
}
|
||||
|
||||
void BuildButtonGrid::clearActiveButton()
|
||||
{
|
||||
if (m_activeIndex)
|
||||
@@ -165,6 +177,12 @@ void BuildButtonGrid::handleEvent(std::shared_ptr<const BuildingBlocksChangedEve
|
||||
updateAffordability();
|
||||
}
|
||||
|
||||
void BuildButtonGrid::handleEvent(std::shared_ptr<const UnlockedBuildingsChangedEvent> /*event*/)
|
||||
{
|
||||
updateVisibility();
|
||||
updateAffordability();
|
||||
}
|
||||
|
||||
void BuildButtonGrid::handleEvent(std::shared_ptr<const DemolishModeChangedEvent> event)
|
||||
{
|
||||
m_demolishButton->setChecked(event->active);
|
||||
@@ -176,9 +194,10 @@ void BuildButtonGrid::handleEvent(std::shared_ptr<const BuildHotkeyPressedEvent>
|
||||
{
|
||||
if (m_types[i] == event->type)
|
||||
{
|
||||
// Equivalent to clicking the build button: a disabled (unaffordable)
|
||||
// button cannot be clicked, so the hotkey is likewise inert.
|
||||
if (m_buttons[i]->isEnabled())
|
||||
// Equivalent to clicking the build button: a disabled (unaffordable) or
|
||||
// hidden (locked, REQ-LOCK-BUILDING) button cannot be clicked, so the
|
||||
// hotkey is likewise inert.
|
||||
if (m_buttons[i]->isEnabled() && m_buttons[i]->isVisible())
|
||||
{
|
||||
onBuildButton(static_cast<int>(i));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user