allow to inspect balancing arena
This commit is contained in:
@@ -5,6 +5,8 @@
|
||||
#include <QVBoxLayout>
|
||||
|
||||
#include "ConfigLoader.h"
|
||||
#include "InspectWindow.h"
|
||||
#include "VisualsLoader.h"
|
||||
|
||||
BalancingWindow::BalancingWindow(const BalancingConfig& balancingConfig,
|
||||
GameConfig gameConfig,
|
||||
@@ -16,7 +18,10 @@ BalancingWindow::BalancingWindow(const BalancingConfig& balancingConfig,
|
||||
, m_configDir(configDir)
|
||||
, m_balancingConfigPath(balancingConfigPath)
|
||||
, m_nextSeed(0)
|
||||
, m_inspectWindow(nullptr)
|
||||
, m_inspectedArenaIndex(-1)
|
||||
{
|
||||
m_visuals = VisualsLoader::load(m_configDir + "/visuals.toml");
|
||||
setWindowTitle("DotaFactory — Balancing Tool");
|
||||
resize(800, 600);
|
||||
|
||||
@@ -48,6 +53,13 @@ BalancingWindow::BalancingWindow(const BalancingConfig& balancingConfig,
|
||||
BalancingWindow::~BalancingWindow()
|
||||
{
|
||||
m_pollTimer->stop();
|
||||
if (m_inspectWindow)
|
||||
{
|
||||
m_inspectWindow->disconnect(this);
|
||||
delete m_inspectWindow;
|
||||
m_inspectWindow = nullptr;
|
||||
}
|
||||
m_inspectedSim.reset();
|
||||
stopAllArenas();
|
||||
}
|
||||
|
||||
@@ -76,6 +88,8 @@ void BalancingWindow::populateArenas(const BalancingConfig& balancingConfig)
|
||||
|
||||
connect(entry.widget, &ArenaWidget::startRequested,
|
||||
this, [this, index]() { startArena(index); });
|
||||
connect(entry.widget, &ArenaWidget::inspectRequested,
|
||||
this, [this, index]() { inspectArena(index); });
|
||||
|
||||
m_arenas.push_back(std::move(entry));
|
||||
}
|
||||
@@ -111,6 +125,13 @@ void BalancingWindow::pollStatuses()
|
||||
entry.widget->updateStatus(status);
|
||||
}
|
||||
}
|
||||
|
||||
if (m_inspectedSim && m_inspectedArenaIndex >= 0)
|
||||
{
|
||||
const ArenaStatus status = m_inspectedSim->status();
|
||||
m_arenas[static_cast<std::size_t>(m_inspectedArenaIndex)].widget->updateStatus(status);
|
||||
}
|
||||
|
||||
updateButtons();
|
||||
}
|
||||
|
||||
@@ -154,8 +175,93 @@ void BalancingWindow::startArena(int index)
|
||||
updateButtons();
|
||||
}
|
||||
|
||||
void BalancingWindow::inspectArena(int index)
|
||||
{
|
||||
if (m_inspectWindow)
|
||||
{
|
||||
m_inspectWindow->disconnect(this);
|
||||
delete m_inspectWindow;
|
||||
m_inspectWindow = nullptr;
|
||||
|
||||
if (m_inspectedSim && m_inspectedArenaIndex >= 0
|
||||
&& !m_inspectedSim->isFinished())
|
||||
{
|
||||
m_arenas[static_cast<std::size_t>(m_inspectedArenaIndex)].widget->resetToGrey();
|
||||
}
|
||||
m_inspectedSim.reset();
|
||||
m_inspectedArenaIndex = -1;
|
||||
}
|
||||
|
||||
ArenaEntry& entry = m_arenas[static_cast<std::size_t>(index)];
|
||||
|
||||
if (entry.worker.joinable())
|
||||
{
|
||||
entry.simulation->requestStop();
|
||||
entry.worker.join();
|
||||
}
|
||||
|
||||
m_inspectedSim = std::make_unique<ArenaSimulation>(
|
||||
m_gameConfig, entry.config, m_nextSeed++);
|
||||
m_inspectedArenaIndex = index;
|
||||
|
||||
entry.widget->resetToGrey();
|
||||
entry.widget->startSimulation();
|
||||
entry.widget->updateStatus(m_inspectedSim->status());
|
||||
|
||||
m_inspectWindow = new InspectWindow(
|
||||
m_inspectedSim.get(), &m_visuals, entry.config.name, nullptr);
|
||||
connect(m_inspectWindow, &InspectWindow::closed,
|
||||
this, &BalancingWindow::closeInspectWindow);
|
||||
|
||||
setMainControlsEnabled(false);
|
||||
m_inspectWindow->show();
|
||||
}
|
||||
|
||||
void BalancingWindow::closeInspectWindow()
|
||||
{
|
||||
if (!m_inspectWindow)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
m_inspectWindow->disconnect(this);
|
||||
m_inspectWindow->deleteLater();
|
||||
m_inspectWindow = nullptr;
|
||||
|
||||
if (m_inspectedArenaIndex >= 0 && m_inspectedSim)
|
||||
{
|
||||
if (!m_inspectedSim->isFinished())
|
||||
{
|
||||
m_arenas[static_cast<std::size_t>(m_inspectedArenaIndex)].widget->resetToGrey();
|
||||
}
|
||||
}
|
||||
|
||||
m_inspectedSim.reset();
|
||||
m_inspectedArenaIndex = -1;
|
||||
setMainControlsEnabled(true);
|
||||
updateButtons();
|
||||
}
|
||||
|
||||
void BalancingWindow::setMainControlsEnabled(bool enabled)
|
||||
{
|
||||
m_reloadButton->setEnabled(enabled);
|
||||
m_startAllButton->setEnabled(enabled);
|
||||
for (ArenaEntry& entry : m_arenas)
|
||||
{
|
||||
for (QPushButton* btn : entry.widget->findChildren<QPushButton*>())
|
||||
{
|
||||
btn->setEnabled(enabled);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void BalancingWindow::updateButtons()
|
||||
{
|
||||
if (m_inspectWindow)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
bool anyRunning = false;
|
||||
bool allRunning = true;
|
||||
for (ArenaEntry& entry : m_arenas)
|
||||
|
||||
Reference in New Issue
Block a user