share a single ItemIconCache across the UI
Four separate caches rasterized the same item SVGs, one of them rebuilt on every recipe-dialog open. MainWindow now owns one cache and hands a non-owning pointer to HeaderBar, BuildButtonGrid, GameWorldView and RecipeSelectionDialog. Co-Authored-By: Claude <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01GH8ZMRY3vhxxXcaUxBqxkk
This commit is contained in:
@@ -27,6 +27,7 @@
|
||||
#include "SelectedBuildingPanel.h"
|
||||
#include "ShipLayoutBlueprintSerializer.h"
|
||||
#include "ShipLayoutDialog.h"
|
||||
#include "ItemIconCache.h"
|
||||
#include "Simulation.h"
|
||||
#include "Tick.h"
|
||||
#include "VisualsLoader.h"
|
||||
@@ -47,10 +48,13 @@ MainWindow::MainWindow(Simulation* sim, const std::string& configDir,
|
||||
const std::string itemsIconDir = QDir::cleanPath(
|
||||
QString::fromStdString(m_configDir) + "/../icons/items").toStdString();
|
||||
|
||||
m_headerBar = new HeaderBar(sim, &sim->getConfig(), itemsIconDir, this);
|
||||
m_itemIcons = std::make_unique<ItemIconCache>(
|
||||
QString::fromStdString(itemsIconDir));
|
||||
|
||||
m_headerBar = new HeaderBar(sim, &sim->getConfig(), m_itemIcons.get(), this);
|
||||
|
||||
m_gameWorldView = new GameWorldView(sim, &sim->getConfig(), &m_visuals, m_configDir,
|
||||
m_replay.get(), this);
|
||||
m_itemIcons.get(), m_replay.get(), this);
|
||||
|
||||
m_sidePanel = new QWidget(this);
|
||||
QVBoxLayout* sideLayout = new QVBoxLayout(m_sidePanel);
|
||||
@@ -63,7 +67,7 @@ MainWindow::MainWindow(Simulation* sim, const std::string& configDir,
|
||||
QString::fromStdString(m_configDir) + "/../icons/buildings").toStdString();
|
||||
|
||||
m_selectedBuildingPanel = new SelectedBuildingPanel(sim, &sim->getConfig(), m_sidePanel);
|
||||
m_buildButtonGrid = new BuildButtonGrid(sim, &sim->getConfig(), iconDir, itemsIconDir, m_sidePanel);
|
||||
m_buildButtonGrid = new BuildButtonGrid(sim, &sim->getConfig(), iconDir, m_itemIcons.get(), m_sidePanel);
|
||||
m_blueprintPanel = new BlueprintPanel(sim, &sim->getConfig(), m_sidePanel);
|
||||
|
||||
sideLayout->addWidget(m_selectedBuildingPanel, 1);
|
||||
@@ -328,11 +332,7 @@ void MainWindow::handleEvent(std::shared_ptr<const RecipeSelectionRequestedEvent
|
||||
|
||||
bool autoOpenLayout = false;
|
||||
std::string chosenSchematic;
|
||||
// Item icons live beside the config dir, mirroring the buildings icon path
|
||||
// (REQ-UI-ITEM-ICON, REQ-UI-BUILD-ICON).
|
||||
const QString itemIconDir = QDir::cleanPath(
|
||||
QString::fromStdString(m_configDir) + "/../icons/items");
|
||||
RecipeSelectionDialog dialog(options, title, itemIconDir, this);
|
||||
RecipeSelectionDialog dialog(options, title, m_itemIcons.get(), this);
|
||||
if (dialog.exec() == QDialog::Accepted && dialog.getChosenId().has_value())
|
||||
{
|
||||
std::shared_ptr<SetRecipeCommand> command = std::make_shared<SetRecipeCommand>();
|
||||
|
||||
Reference in New Issue
Block a user