Added games installer and now its amazing
This commit is contained in:
164
GamesPanel.cpp
164
GamesPanel.cpp
@@ -3,9 +3,40 @@
|
||||
#include <QHBoxLayout>
|
||||
#include <QLabel>
|
||||
#include <QListWidget>
|
||||
#include <QPushButton>
|
||||
#include <QSet>
|
||||
#include <QSplitter>
|
||||
#include <QVBoxLayout>
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// Helper: parse "GAM <cmd> CODE1Name1 CODE2Name2 ..." → name->code map
|
||||
// ---------------------------------------------------------------------------
|
||||
static QMap<QString,QString> parseGamResponse(const QString &response,
|
||||
const QString &subCmd)
|
||||
{
|
||||
QMap<QString,QString> result;
|
||||
const QStringList tokens = response.split(' ', Qt::SkipEmptyParts);
|
||||
if (tokens.size() < 3 || tokens[0] != "GAM" || tokens[1] != subCmd)
|
||||
return result;
|
||||
|
||||
for (const QString &entry : tokens.mid(2)) {
|
||||
if (entry.isEmpty()) continue;
|
||||
// First up-to-4 uppercase chars = code, remainder = name
|
||||
int splitPos = 0;
|
||||
while (splitPos < entry.size() && entry[splitPos].isUpper())
|
||||
++splitPos;
|
||||
const QString code = entry.left(qMin(splitPos, 4));
|
||||
QString name = entry.mid(code.size());
|
||||
name.replace("_S", " ");
|
||||
if (code.isEmpty() || name.isEmpty()) continue;
|
||||
result[name] = code;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// Constructor
|
||||
// ---------------------------------------------------------------------------
|
||||
GamesPanel::GamesPanel(QWidget *parent) : QWidget(parent)
|
||||
{
|
||||
auto *layout = new QHBoxLayout(this);
|
||||
@@ -13,74 +44,97 @@ GamesPanel::GamesPanel(QWidget *parent) : QWidget(parent)
|
||||
|
||||
auto *splitter = new QSplitter(Qt::Horizontal, this);
|
||||
|
||||
m_gameList = new QListWidget(splitter);
|
||||
m_gameList->setMinimumWidth(180);
|
||||
m_gameList->setMaximumWidth(300);
|
||||
// ---- Left pane: Available (not installed) games ----
|
||||
auto *leftWidget = new QWidget(splitter);
|
||||
auto *leftLayout = new QVBoxLayout(leftWidget);
|
||||
leftLayout->setContentsMargins(4, 4, 4, 4);
|
||||
leftLayout->setSpacing(4);
|
||||
|
||||
m_detailWidget = new QWidget(splitter);
|
||||
auto *detailLayout = new QVBoxLayout(m_detailWidget);
|
||||
detailLayout->setContentsMargins(8, 8, 8, 8);
|
||||
auto *availLabel = new QLabel("<b>Available Games</b>", leftWidget);
|
||||
availLabel->setStyleSheet("color: #555;");
|
||||
m_availableList = new QListWidget(leftWidget);
|
||||
m_availableList->addItem("Connect to load available games...");
|
||||
m_addBtn = new QPushButton("Add to Installed →", leftWidget);
|
||||
m_addBtn->setEnabled(false);
|
||||
|
||||
m_nameLabel = new QLabel(m_detailWidget);
|
||||
m_nameLabel->setStyleSheet("font-size: 14pt; font-weight: bold;");
|
||||
m_codeLabel = new QLabel(m_detailWidget);
|
||||
m_codeLabel->setStyleSheet("font-size: 11pt; color: gray;");
|
||||
m_hintLabel = new QLabel("Select a game to view details.", m_detailWidget);
|
||||
m_hintLabel->setAlignment(Qt::AlignTop);
|
||||
leftLayout->addWidget(availLabel);
|
||||
leftLayout->addWidget(m_availableList, 1);
|
||||
leftLayout->addWidget(m_addBtn);
|
||||
|
||||
detailLayout->addWidget(m_nameLabel);
|
||||
detailLayout->addWidget(m_codeLabel);
|
||||
detailLayout->addWidget(m_hintLabel);
|
||||
detailLayout->addStretch(1);
|
||||
// ---- Right pane: Installed games ----
|
||||
auto *rightWidget = new QWidget(splitter);
|
||||
auto *rightLayout = new QVBoxLayout(rightWidget);
|
||||
rightLayout->setContentsMargins(4, 4, 4, 4);
|
||||
rightLayout->setSpacing(4);
|
||||
|
||||
splitter->addWidget(m_gameList);
|
||||
splitter->addWidget(m_detailWidget);
|
||||
splitter->setStretchFactor(0, 0);
|
||||
auto *instLabel = new QLabel("<b>Installed Games</b>", rightWidget);
|
||||
instLabel->setStyleSheet("color: #555;");
|
||||
m_installedList = new QListWidget(rightWidget);
|
||||
m_installedList->addItem("Connect to load installed games...");
|
||||
|
||||
rightLayout->addWidget(instLabel);
|
||||
rightLayout->addWidget(m_installedList, 1);
|
||||
|
||||
splitter->addWidget(leftWidget);
|
||||
splitter->addWidget(rightWidget);
|
||||
splitter->setStretchFactor(0, 1);
|
||||
splitter->setStretchFactor(1, 1);
|
||||
splitter->setSizes({200, 600});
|
||||
splitter->setSizes({420, 420});
|
||||
|
||||
layout->addWidget(splitter);
|
||||
|
||||
connect(m_gameList, &QListWidget::currentTextChanged,
|
||||
this, &GamesPanel::onGameSelected);
|
||||
// Enable Add button only when something is selected in available list
|
||||
connect(m_availableList, &QListWidget::currentRowChanged, this,
|
||||
[this](int row) { m_addBtn->setEnabled(row >= 0); });
|
||||
connect(m_addBtn, &QPushButton::clicked, this, &GamesPanel::onAddClicked);
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// Load installed games (GAM list response)
|
||||
// ---------------------------------------------------------------------------
|
||||
void GamesPanel::loadFromResponse(const QString &response)
|
||||
{
|
||||
// Format: "GAM list LEADVision ARCHArchitect ..."
|
||||
// Each token: 4 uppercase letters = code, rest = name (_S = space)
|
||||
const QStringList tokens = response.split(' ', Qt::SkipEmptyParts);
|
||||
if (tokens.size() < 3 || tokens[0] != "GAM" || tokens[1] != "list") return;
|
||||
|
||||
m_games.clear();
|
||||
m_gameList->clear();
|
||||
|
||||
for (const QString &entry : tokens.mid(2)) {
|
||||
if (entry.isEmpty()) continue;
|
||||
|
||||
int splitPos = 0;
|
||||
while (splitPos < entry.size() && entry[splitPos].isUpper())
|
||||
++splitPos;
|
||||
|
||||
const QString code = entry.left(qMin(splitPos, 4));
|
||||
QString name = entry.mid(code.size());
|
||||
name.replace("_S", " ");
|
||||
|
||||
if (code.isEmpty() || name.isEmpty()) continue;
|
||||
m_games[name] = code;
|
||||
m_gameList->addItem(name);
|
||||
}
|
||||
m_installedGames = parseGamResponse(response, "list");
|
||||
m_installedList->clear();
|
||||
for (const QString &name : m_installedGames.keys())
|
||||
m_installedList->addItem(name);
|
||||
rebuildAvailable();
|
||||
}
|
||||
|
||||
void GamesPanel::onGameSelected(const QString &name)
|
||||
// ---------------------------------------------------------------------------
|
||||
// Load all available games (GAM listall response)
|
||||
// ---------------------------------------------------------------------------
|
||||
void GamesPanel::loadAllFromResponse(const QString &response)
|
||||
{
|
||||
if (name.isEmpty() || !m_games.contains(name)) {
|
||||
m_nameLabel->clear();
|
||||
m_codeLabel->clear();
|
||||
m_hintLabel->setText("Select a game to view details.");
|
||||
return;
|
||||
}
|
||||
m_nameLabel->setText(name);
|
||||
m_codeLabel->setText(QString("Code: %1").arg(m_games[name]));
|
||||
m_hintLabel->setText("Game selected. Future controls will appear here.");
|
||||
m_allGames = parseGamResponse(response, "listall");
|
||||
rebuildAvailable();
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// Rebuild available list = allGames minus installedGames (by code)
|
||||
// ---------------------------------------------------------------------------
|
||||
void GamesPanel::rebuildAvailable()
|
||||
{
|
||||
const QSet<QString> installedCodes(m_installedGames.values().begin(),
|
||||
m_installedGames.values().end());
|
||||
m_availableList->clear();
|
||||
for (auto it = m_allGames.constBegin(); it != m_allGames.constEnd(); ++it) {
|
||||
if (!installedCodes.contains(it.value()))
|
||||
m_availableList->addItem(it.key());
|
||||
}
|
||||
if (m_availableList->count() == 0 && !m_allGames.isEmpty())
|
||||
m_availableList->addItem("(all available games are installed)");
|
||||
m_addBtn->setEnabled(false);
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// Add button clicked → emit GAM add <code>
|
||||
// ---------------------------------------------------------------------------
|
||||
void GamesPanel::onAddClicked()
|
||||
{
|
||||
auto *item = m_availableList->currentItem();
|
||||
if (!item) return;
|
||||
const QString name = item->text();
|
||||
if (!m_allGames.contains(name)) return;
|
||||
emit commandRequested(QString("GAM add %1").arg(m_allGames[name]));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user