Skip to content

Commit 87bd286

Browse files
committed
feat: countdown command presets
1 parent 1aed2ee commit 87bd286

5 files changed

Lines changed: 67 additions & 29 deletions

File tree

GhostServer/GhostServer.vcxproj

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -209,9 +209,6 @@
209209
<QtMoc Include="networkmanager.h">
210210
<ExcludedFromBuild Condition="'$(Configuration)'=='DebugCLI' or '$(Configuration)'=='ReleaseCLI'">true</ExcludedFromBuild>
211211
</QtMoc>
212-
<QtMoc Include="commands.h">
213-
<ExcludedFromBuild Condition="'$(Configuration)'=='DebugCLI' or '$(Configuration)'=='ReleaseCLI'">true</ExcludedFromBuild>
214-
</QtMoc>
215212
</ItemGroup>
216213
<ItemGroup>
217214
<QtUic Include="mainwindow.ui">

GhostServer/GhostServer.vcxproj.filters

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,9 +47,6 @@
4747
<QtMoc Include="mainwindow.h">
4848
<Filter>Header Files</Filter>
4949
</QtMoc>
50-
<QtMoc Include="commands.h">
51-
<Filter>Header Files</Filter>
52-
</QtMoc>
5350
<QtMoc Include="networkmanager.h">
5451
<Filter>Header Files</Filter>
5552
</QtMoc>

GhostServer/mainwindow.cpp

Lines changed: 45 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,34 @@
99

1010
#include <qdebug.h>
1111

12+
struct CountdownPreset {
13+
QString name;
14+
QString preCommands;
15+
QString postCommands;
16+
};
17+
std::vector<CountdownPreset> countdownPresets = {
18+
{
19+
"None",
20+
"",
21+
""
22+
},
23+
{
24+
"Fullgame",
25+
"ghost_sync 1\nghost_sync_countdown 3\nsvar_set sp_use_save 2\nghost_leaderboard_mode 1\nghost_leaderboard_reset\nsar_on_load conds map=sp_a1_wakeup \"ghost_sync 0\" map=sp_a2_intro \"ghost_sync 1\"",
26+
"sar_speedrun_skip_cutscenes 1; sar_speedrun_offset 18980; sar_speedrun_reset; stop; sv_allow_mobile_portals 0; load vault"
27+
},
28+
{
29+
"Speedrun Mod",
30+
"ghost_sync 1\nghost_sync_countdown 3\nsvar_set sp_use_save 2\nghost_leaderboard_mode 1\nghost_leaderboard_reset",
31+
"sar_speedrun_offset 0; sar_speedrun_reset; stop; sv_allow_mobile_portals 0; map sp_a1_intro1"
32+
},
33+
{
34+
"Portal Stories: Mel",
35+
"ghost_sync 1\nghost_sync_countdown 3\nghost_leaderboard_mode 1\nghost_leaderboard_reset\nsar_ent_slot_serial 838 16301",
36+
"sar_speedrun_reset; map st_a1_tramride"
37+
}
38+
};
39+
1240
MainWindow::MainWindow(QWidget* parent)
1341
: QWidget(parent)
1442
{
@@ -27,6 +55,12 @@ MainWindow::MainWindow(QWidget* parent)
2755
connect(ui.resetButton, &QPushButton::clicked, this, &MainWindow::ResetServer);
2856
connect(ui.submitCommandButton, &QPushButton::clicked, this, &MainWindow::SubmitCommand);
2957
connect(ui.commandInput, &QLineEdit::returnPressed, this, &MainWindow::SubmitCommand);
58+
connect(ui.presetDropdown, &QComboBox::currentIndexChanged, this, &MainWindow::OnPresetChanged);
59+
60+
for (const auto& preset : countdownPresets) {
61+
ui.presetDropdown->addItem(preset.name);
62+
}
63+
ui.presetDropdown->setCurrentIndex(0);
3064
}
3165

3266
MainWindow::~MainWindow()
@@ -69,25 +103,11 @@ void MainWindow::ResetServer()
69103
void MainWindow::StartCountdown()
70104
{
71105
QTextDocument* pre_doc = ui.preCommandList->document();
72-
QString pre_cmds = "";
73-
for (int i = 0; i < pre_doc->lineCount(); ++i) {
74-
QTextBlock tb = pre_doc->findBlockByLineNumber(i);
75-
pre_cmds += tb.text();
76-
if (i < pre_doc->lineCount() - 1) {
77-
pre_cmds += "; ";
78-
}
79-
}
106+
QString pre_cmds = pre_doc->toPlainText().split(QString("\n")).join(QString("; "));
80107

81108

82109
QTextDocument* post_doc = ui.postCommandList->document();
83-
QString post_cmds = "";
84-
for (int i = 0; i < post_doc->lineCount(); ++i) {
85-
QTextBlock tb = post_doc->findBlockByLineNumber(i);
86-
post_cmds += tb.text();
87-
if (i < post_doc->lineCount() - 1) {
88-
post_cmds += "; ";
89-
}
90-
}
110+
QString post_cmds = post_doc->toPlainText().split(QString("\n")).join(QString("; "));
91111

92112
int duration = ui.duration->value();
93113
this->network->StartCountdown(pre_cmds.toStdString(), post_cmds.toStdString(), duration);
@@ -106,3 +126,12 @@ void MainWindow::SubmitCommand()
106126

107127
ui.commandInput->clear();
108128
}
129+
130+
void MainWindow::OnPresetChanged(int index)
131+
{
132+
if (index < 0 || index >= static_cast<int>(countdownPresets.size())) return;
133+
134+
const CountdownPreset& preset = countdownPresets[index];
135+
ui.preCommandList->setPlainText(preset.preCommands);
136+
ui.postCommandList->setPlainText(preset.postCommands);
137+
}

GhostServer/mainwindow.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ class MainWindow : public QWidget
2727
void StopServer();
2828
void ResetServer();
2929
void SubmitCommand();
30+
void OnPresetChanged(int index);
3031

3132
public slots:
3233
void AddEventLog(QString log) {ui.textBrowser->append(log);}

GhostServer/mainwindow.ui

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -101,13 +101,27 @@
101101
<number>9</number>
102102
</property>
103103
<item row="0" column="0">
104+
<widget class="QLabel" name="label_1">
105+
<property name="text">
106+
<string>Preset</string>
107+
</property>
108+
</widget>
109+
</item>
110+
<item row="0" column="1">
111+
<widget class="QComboBox" name="presetDropdown">
112+
<property name="editable">
113+
<bool>false</bool>
114+
</property>
115+
</widget>
116+
</item>
117+
<item row="1" column="0">
104118
<widget class="QLabel" name="label_4">
105119
<property name="text">
106120
<string>Pre-countdown commands</string>
107121
</property>
108122
</widget>
109123
</item>
110-
<item row="0" column="1">
124+
<item row="1" column="1">
111125
<widget class="QPlainTextEdit" name="preCommandList">
112126
<property name="sizePolicy">
113127
<sizepolicy hsizetype="Preferred" vsizetype="Fixed">
@@ -126,14 +140,14 @@
126140
</property>
127141
</widget>
128142
</item>
129-
<item row="1" column="0">
143+
<item row="2" column="0">
130144
<widget class="QLabel" name="label_5">
131145
<property name="text">
132146
<string>Post-countdown commands</string>
133147
</property>
134148
</widget>
135149
</item>
136-
<item row="1" column="1">
150+
<item row="2" column="1">
137151
<widget class="QPlainTextEdit" name="postCommandList">
138152
<property name="sizePolicy">
139153
<sizepolicy hsizetype="Preferred" vsizetype="Fixed">
@@ -152,28 +166,28 @@
152166
</property>
153167
</widget>
154168
</item>
155-
<item row="2" column="0">
169+
<item row="3" column="0">
156170
<widget class="QLabel" name="label_6">
157171
<property name="text">
158172
<string>Countdown duration (seconds)</string>
159173
</property>
160174
</widget>
161175
</item>
162-
<item row="2" column="1">
176+
<item row="3" column="1">
163177
<widget class="QSpinBox" name="duration">
164178
<property name="value">
165179
<number>5</number>
166180
</property>
167181
</widget>
168182
</item>
169-
<item row="3" column="0" colspan="2">
183+
<item row="4" column="0" colspan="2">
170184
<widget class="QPushButton" name="startCountdown">
171185
<property name="text">
172186
<string>Start countdown</string>
173187
</property>
174188
</widget>
175189
</item>
176-
<item row="4" column="0" colspan="2">
190+
<item row="5" column="0" colspan="2">
177191
<widget class="QPushButton" name="resetButton">
178192
<property name="enabled">
179193
<bool>true</bool>

0 commit comments

Comments
 (0)