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\n ghost_sync_countdown 3\n svar_set sp_use_save 2\n ghost_leaderboard_mode 1\n ghost_leaderboard_reset\n sar_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\n ghost_sync_countdown 3\n svar_set sp_use_save 2\n ghost_leaderboard_mode 1\n ghost_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\n ghost_sync_countdown 3\n ghost_leaderboard_mode 1\n ghost_leaderboard_reset\n sar_ent_slot_serial 838 16301" ,
36+ " sar_speedrun_reset; map st_a1_tramride"
37+ }
38+ };
39+
1240MainWindow::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
3266MainWindow::~MainWindow ()
@@ -69,25 +103,11 @@ void MainWindow::ResetServer()
69103void 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+ }
0 commit comments