Skip to content

Commit

Permalink
Fix numbers disappearing from factory build buttons
Browse files Browse the repository at this point in the history
  • Loading branch information
MHeasell committed May 29, 2019
1 parent 597a45f commit 34036b4
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 14 deletions.
33 changes: 19 additions & 14 deletions src/rwe/GameScene.cpp
Expand Up @@ -2038,7 +2038,7 @@ namespace rwe
guiInfo.currentBuildPage = (guiInfo.currentBuildPage + 1) % pages;

auto buildPanelDefinition = unitFactory.getBuilderGui(unit.unitType, guiInfo.currentBuildPage);
setNextPanel(uiFactory.panelFromGuiFile(unit.unitType + std::to_string(guiInfo.currentBuildPage + 1), *buildPanelDefinition));
setNextPanel(createBuildPanel(unit.unitType + std::to_string(guiInfo.currentBuildPage + 1), *buildPanelDefinition, unit.getBuildQueueTotals()));
}
}
else if (matchesWithSidePrefix("PREV", message))
Expand All @@ -2057,7 +2057,7 @@ namespace rwe
guiInfo.currentBuildPage = guiInfo.currentBuildPage == 0 ? pages - 1 : guiInfo.currentBuildPage - 1;

auto buildPanelDefinition = unitFactory.getBuilderGui(unit.unitType, guiInfo.currentBuildPage);
setNextPanel(uiFactory.panelFromGuiFile(unit.unitType + std::to_string(guiInfo.currentBuildPage + 1), *buildPanelDefinition));
setNextPanel(createBuildPanel(unit.unitType + std::to_string(guiInfo.currentBuildPage + 1), *buildPanelDefinition, unit.getBuildQueueTotals()));
}
}
else if (matchesWithSidePrefix("BUILD", message))
Expand All @@ -2074,7 +2074,7 @@ namespace rwe
guiInfo.section = UnitGuiInfo::Section::Build;

auto buildPanelDefinition = unitFactory.getBuilderGui(unit.unitType, guiInfo.currentBuildPage);
setNextPanel(uiFactory.panelFromGuiFile(unit.unitType + std::to_string(guiInfo.currentBuildPage + 1), *buildPanelDefinition));
setNextPanel(createBuildPanel(unit.unitType + std::to_string(guiInfo.currentBuildPage + 1), *buildPanelDefinition, unit.getBuildQueueTotals()));
}
}
else if (matchesWithSidePrefix("ORDERS", message))
Expand Down Expand Up @@ -2145,17 +2145,7 @@ namespace rwe
auto buildPanelDefinition = unitFactory.getBuilderGui(unit.unitType, guiInfo.currentBuildPage);
if (guiInfo.section == UnitGuiInfo::Section::Build && buildPanelDefinition)
{
auto panel = uiFactory.panelFromGuiFile(unit.unitType + std::to_string(guiInfo.currentBuildPage + 1), *buildPanelDefinition);
auto totals = unit.getBuildQueueTotals();
for (const auto& e : totals)
{
auto button = panel->find<UiStagedButton>(e.first);
if (button)
{
button->get().setLabel("+" + std::to_string(e.second));
}
}
setNextPanel(std::move(panel));
setNextPanel(createBuildPanel(unit.unitType + std::to_string(guiInfo.currentBuildPage + 1), *buildPanelDefinition, unit.getBuildQueueTotals()));
}
else
{
Expand Down Expand Up @@ -2253,4 +2243,19 @@ namespace rwe

return it2->second;
}

std::unique_ptr<UiPanel> GameScene::createBuildPanel(const std::string& guiName, const std::vector<GuiEntry>& buildPanelDefinition, const std::unordered_map<std::string, int>& totals)
{
auto panel = uiFactory.panelFromGuiFile(guiName, buildPanelDefinition);
for (const auto& e : totals)
{
auto button = panel->find<UiStagedButton>(e.first);
if (button)
{
button->get().setLabel("+" + std::to_string(e.second));
}
}

return panel;
}
}
2 changes: 2 additions & 0 deletions src/rwe/GameScene.h
Expand Up @@ -508,6 +508,8 @@ namespace rwe

int getUnconfirmedBuildQueueCount(UnitId unitId, const std::string& unitType) const;

std::unique_ptr<UiPanel> createBuildPanel(const std::string& guiname, const std::vector<GuiEntry>& panelDefinition, const std::unordered_map<std::string, int>& totals);

template <typename T>
std::optional<std::reference_wrapper<T>> findWithSidePrefix(UiPanel& p, const std::string& name)
{
Expand Down

0 comments on commit 34036b4

Please sign in to comment.