Added time duration and countdown duration to game tab

This commit is contained in:
Jon ESA
2026-04-01 21:27:46 +01:00
parent 90493a3864
commit 96079b493a
2 changed files with 46 additions and 9 deletions

View File

@@ -2,6 +2,7 @@
#include <QHBoxLayout>
#include <QLabel>
#include <QLineEdit>
#include <QListWidget>
#include <QPushButton>
#include <QSet>
@@ -22,7 +23,7 @@ static QMap<QString,QString> parseGamResponse(const QString &response,
return result;
for (const QString &entry : tokens.mid(2)) {
if (entry.size() < 5) continue; // need at least 4-char code + 1-char name
if (entry.size() < 5) continue;
const QString code = entry.left(4);
QString name = entry.mid(4);
name.replace("_S", " ");
@@ -59,7 +60,7 @@ GamesPanel::GamesPanel(QWidget *parent) : QWidget(parent)
leftLayout->addWidget(m_availableList, 1);
leftLayout->addWidget(m_addBtn);
// ---- Right pane: Installed games + Start/Stop ----
// ---- Right pane: Installed games + Start/Stop + time/countdown inputs ----
auto *rightWidget = new QWidget(splitter);
auto *rightLayout = new QVBoxLayout(rightWidget);
rightLayout->setContentsMargins(4, 4, 4, 4);
@@ -67,13 +68,32 @@ GamesPanel::GamesPanel(QWidget *parent) : QWidget(parent)
auto *instLabel = new QLabel("<b>Installed Games</b>", rightWidget);
instLabel->setStyleSheet("color: #555;");
m_installedList = new QListWidget(rightWidget);
m_installedList = new QListWidget(rightWidget);
m_installedList->addItem("Connect to load installed games...");
// Parameter inputs row
auto *paramRow = new QHBoxLayout();
auto *timeLabel = new QLabel("Time:", rightWidget);
m_timeEdit = new QLineEdit(rightWidget);
m_timeEdit->setPlaceholderText("seconds");
m_timeEdit->setFixedWidth(72);
m_timeEdit->setToolTip("Optional: game duration in seconds (adds ,t<value>)");
auto *countLabel = new QLabel("Countdown:", rightWidget);
m_countdownEdit = new QLineEdit(rightWidget);
m_countdownEdit->setPlaceholderText("seconds");
m_countdownEdit->setFixedWidth(72);
m_countdownEdit->setToolTip("Optional: countdown duration in seconds (adds ,c<value>)");
paramRow->addWidget(timeLabel);
paramRow->addWidget(m_timeEdit);
paramRow->addSpacing(8);
paramRow->addWidget(countLabel);
paramRow->addWidget(m_countdownEdit);
paramRow->addStretch(1);
// Start / Stop button row
auto *btnRow = new QHBoxLayout();
m_startBtn = new QPushButton("▶ Start Game", rightWidget);
m_stopBtn = new QPushButton("■ Stop Game", rightWidget);
auto *btnRow = new QHBoxLayout();
m_startBtn = new QPushButton("▶ Start Game", rightWidget);
m_stopBtn = new QPushButton("■ Stop Game", rightWidget);
m_startBtn->setEnabled(false);
m_startBtn->setStyleSheet(
"QPushButton { color: white; background-color: #2e7d32;"
@@ -90,6 +110,7 @@ GamesPanel::GamesPanel(QWidget *parent) : QWidget(parent)
rightLayout->addWidget(instLabel);
rightLayout->addWidget(m_installedList, 1);
rightLayout->addLayout(paramRow);
rightLayout->addLayout(btnRow);
splitter->addWidget(leftWidget);
@@ -154,7 +175,7 @@ void GamesPanel::rebuildAvailable()
}
// ---------------------------------------------------------------------------
// Add selected available game to installed list
// Add selected available game
// ---------------------------------------------------------------------------
void GamesPanel::onAddClicked()
{
@@ -166,7 +187,11 @@ void GamesPanel::onAddClicked()
}
// ---------------------------------------------------------------------------
// Start selected installed game: GST <code> ,p
// Start selected installed game:
// GST <code> ,p (no params)
// GST <code> ,p,t<time> (time only)
// GST <code> ,p,c<countdown> (countdown only)
// GST <code> ,p,t<time>,c<countdown> (both)
// ---------------------------------------------------------------------------
void GamesPanel::onStartClicked()
{
@@ -174,5 +199,14 @@ void GamesPanel::onStartClicked()
if (!item) return;
const QString name = item->text();
if (!m_installedGames.contains(name)) return;
emit commandRequested(QString("GST %1 ,p").arg(m_installedGames[name]));
const QString code = m_installedGames[name];
const QString timeVal = m_timeEdit->text().trimmed();
const QString countVal = m_countdownEdit->text().trimmed();
QString params = ",p";
if (!timeVal.isEmpty()) params += QString(",t%1").arg(timeVal);
if (!countVal.isEmpty()) params += QString(",c%1").arg(countVal);
emit commandRequested(QString("GST %1 %2").arg(code, params));
}

View File

@@ -4,6 +4,7 @@
#include <QWidget>
class QLabel;
class QLineEdit;
class QListWidget;
class QPushButton;
@@ -31,6 +32,8 @@ private:
// Right pane
QListWidget *m_installedList = nullptr;
QLineEdit *m_timeEdit = nullptr;
QLineEdit *m_countdownEdit = nullptr;
QPushButton *m_startBtn = nullptr;
QPushButton *m_stopBtn = nullptr;