Skip to content

Commit b123178

Browse files
committed
fix some commandline startup options
1 parent 4fbf18d commit b123178

File tree

4 files changed

+74
-40
lines changed

4 files changed

+74
-40
lines changed

src/CommandLineParser.cpp

Lines changed: 38 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,13 @@ CommandLineParser::CommandLineParser(const QString& type) : m_processStatus(0) {
2020
m_parser.setApplicationDescription("Tomb Raider Linux Launcher");
2121
m_parser.addHelpOption();
2222

23+
// Fullscreen ------------
24+
QStringList fullscreenName;
25+
fullscreenName << "f" << "fullscreen";
26+
QCommandLineOption fullscreenOption(fullscreenName);
27+
fullscreenOption.setDescription("Start in fullscreen");
28+
m_parser.addOption(fullscreenOption);
29+
2330
// Original ------------
2431
QStringList showOriginalName;
2532
showOriginalName << "so" << "showOriginal";
@@ -38,9 +45,10 @@ CommandLineParser::CommandLineParser(const QString& type) : m_processStatus(0) {
3845
QStringList filterByClassName;
3946
filterByClassName << "fc" << "filterByClass";
4047
QCommandLineOption filterByClassOption(filterByClassName);
41-
const QString filterByClassDesc =
42-
"\nFilter levels by class. Allowed values:\n"
43-
+ m_class_options.join(", ") + "\n";
48+
const QString filterByClassDesc = QString("%1%2%3").arg(
49+
"\nFilter levels by class. Allowed values:\n",
50+
m_class_options.join(", "),
51+
"\n");
4452
filterByClassOption.setDescription(filterByClassDesc);
4553
filterByClassOption.setValueName("class");
4654
m_parser.addOption(filterByClassOption);
@@ -49,9 +57,10 @@ CommandLineParser::CommandLineParser(const QString& type) : m_processStatus(0) {
4957
QStringList filterByTypeName;
5058
filterByTypeName << "ft" << "filterByType";
5159
QCommandLineOption filterByTypeOption(filterByTypeName);
52-
const QString filterByTypeDesc =
53-
"Filter levels by TR game type. Allowed values:\n"
54-
+ m_type_options.join(", ") + "\n";
60+
const QString filterByTypeDesc = QString("%1%2%3").arg(
61+
"Filter levels by TR game type. Allowed values:\n",
62+
m_type_options.join(", "),
63+
"\n");
5564
filterByTypeOption.setDescription(filterByTypeDesc);
5665
filterByTypeOption.setValueName("type");
5766
m_parser.addOption(filterByTypeOption);
@@ -60,9 +69,10 @@ CommandLineParser::CommandLineParser(const QString& type) : m_processStatus(0) {
6069
QStringList filterByDifficultyName;
6170
filterByDifficultyName << "fd" << "filterByDifficulty";
6271
QCommandLineOption filterByDifficultyOption(filterByDifficultyName);
63-
const QString filterByDifficultyDesc =
64-
"Filter levels by difficulty. Allowed values:\n"
65-
+ m_type_options.join(", ") + "\n";
72+
const QString filterByDifficultyDesc = QString("%1%2%3").arg(
73+
"Filter levels by difficulty. Allowed values:\n",
74+
m_type_options.join(", "),
75+
"\n");
6676
filterByDifficultyOption.setDescription(filterByDifficultyDesc);
6777
filterByDifficultyOption.setValueName("difficulty");
6878
m_parser.addOption(filterByDifficultyOption);
@@ -72,9 +82,10 @@ CommandLineParser::CommandLineParser(const QString& type) : m_processStatus(0) {
7282
filterByDurationName << "fr" << "filterByDuration";
7383
QCommandLineOption filterByDurationOption(filterByDurationName);
7484

75-
const QString filterByDurationDesc =
76-
"Filter levels by duration. Allowed values:\n"
77-
+ m_type_options.join(", ") + "\n";
85+
const QString filterByDurationDesc = QString("%1%2%3").arg(
86+
"Filter levels by duration. Allowed values:\n",
87+
m_type_options.join(", "),
88+
"\n");
7889
filterByDurationOption.setDescription(filterByDurationDesc);
7990
filterByDurationOption.setValueName("duration");
8091
m_parser.addOption(filterByDurationOption);
@@ -111,17 +122,19 @@ CommandLineParser::CommandLineParser(const QString& type) : m_processStatus(0) {
111122
QStringList widescreenName;
112123
widescreenName << "w" << "widescreen";
113124
QCommandLineOption widescreenOption(widescreenName);
114-
const QString widescreenDesc = "Set widescreen bit on original games,"
115-
+ QString(" probably not useful for TRLE");
125+
const QString widescreenDesc = QString("%1%2").arg(
126+
"Set widescreen bit on original games,",
127+
" probably not useful for TRLE");
116128
widescreenOption.setDescription(widescreenDesc);
117129
widescreenOption.setDefaultValue("PATH");
118130
m_parser.addOption(widescreenOption);
119131

120132
QStringList binaryName;
121133
binaryName << "b" << "binary";
122134
QCommandLineOption binaryOption(binaryName);
123-
const QString binaryDesc = "Print PE Header Information,"
124-
+ QString(" to record Tomb Raider and TRLE binaries");
135+
const QString binaryDesc = QString("%1%2").arg(
136+
"Print PE Header Information,",
137+
" to record Tomb Raider and TRLE binaries");
125138
binaryOption.setDescription(binaryDesc);
126139
binaryOption.setDefaultValue("PATH");
127140
m_parser.addOption(binaryOption);
@@ -135,6 +148,10 @@ StartupSetting CommandLineParser::process(const QStringList& arguments) {
135148
m_parser.process(arguments);
136149

137150
StartupSetting settings;
151+
152+
if (m_parser.isSet("fullscreen") == true) {
153+
settings.fullscreen = true;
154+
}
138155

139156
if (m_parser.isSet("showInstalled") == true) {
140157
settings.installed = true;
@@ -149,7 +166,7 @@ StartupSetting CommandLineParser::process(const QStringList& arguments) {
149166
QString value = m_parser.value("filterByClass");
150167
int idx = m_class_options.indexOf(value, Qt::CaseInsensitive);
151168
if (idx != -1) {
152-
settings.class_id = static_cast<quint8>(idx+1);
169+
settings.class_id = static_cast<quint8>(idx + 1);
153170
} else {
154171
qCritical().noquote() << "Invalid class value:" << value
155172
<< "\nAllowed:" << m_class_options.join(", ");
@@ -162,7 +179,7 @@ StartupSetting CommandLineParser::process(const QStringList& arguments) {
162179
QString value = m_parser.value("filterByType");
163180
int idx = m_type_options.indexOf(value, Qt::CaseInsensitive);
164181
if (idx != -1) {
165-
settings.type_id = static_cast<quint8>(idx);
182+
settings.type_id = static_cast<quint8>(idx + 1);
166183
} else {
167184
qCritical().noquote() << "Invalid type value:" << value
168185
<< "\nAllowed:" << m_type_options.join(", ");
@@ -175,7 +192,7 @@ StartupSetting CommandLineParser::process(const QStringList& arguments) {
175192
QString value = m_parser.value("filterByDifficulty");
176193
int idx = m_difficulty_options.indexOf(value, Qt::CaseInsensitive);
177194
if (idx != -1) {
178-
settings.difficulty_id = static_cast<quint8>(idx);
195+
settings.difficulty_id = static_cast<quint8>(idx + 1);
179196
} else {
180197
qCritical().noquote() << "Invalid difficulty value:" << value
181198
<< "\nAllowed:" << m_difficulty_options.join(", ");
@@ -188,7 +205,7 @@ StartupSetting CommandLineParser::process(const QStringList& arguments) {
188205
QString value = m_parser.value("filterByDuration");
189206
int idx = m_duration_options.indexOf(value, Qt::CaseInsensitive);
190207
if (idx != -1) {
191-
settings.duration_id = static_cast<quint8>(idx);
208+
settings.duration_id = static_cast<quint8>(idx + 1);
192209
} else {
193210
qCritical().noquote() << "Invalid duration value:" << value
194211
<< "\nAllowed:" << m_duration_options.join(", ");
@@ -208,7 +225,7 @@ StartupSetting CommandLineParser::process(const QStringList& arguments) {
208225

209226
QStringList setSorts;
210227
for (const QString &opt : sortOptions) {
211-
if (m_parser.isSet(opt)) {
228+
if (m_parser.isSet(opt) == true) {
212229
setSorts << opt;
213230
}
214231
}

src/LevelViewList.cpp

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,8 @@ QVariant LevelListModel::data(const QModelIndex &index, int role) const {
3131

3232
if (index.isValid() && index.row() < m_levels.size()) {
3333
const ListItemData &item = *m_levels[index.row()];
34-
const auto it = m_roleMap.find(role);
35-
if (it != m_roleMap.end()) {
34+
const auto it = m_roleTable.find(role);
35+
if (it != m_roleTable.end()) {
3636
result = it.value()(item);
3737
}
3838
}
@@ -147,23 +147,34 @@ void LevelListProxy::setInstalledFilter(bool on) {
147147
void LevelListProxy::setSortMode(SortMode mode) {
148148
m_sortMode = mode;
149149
invalidate();
150-
this->sort(0);
150+
this->sort(0, Qt::DescendingOrder);
151151
}
152152

153153
bool LevelListProxy::lessThan(const QModelIndex &left,
154154
const QModelIndex &right) const {
155-
int role = roleForMode();
155+
const quint64 role = roleForMode();
156156
QVariant l = sourceModel()->data(left, role);
157157
QVariant r = sourceModel()->data(right, role);
158158

159+
bool less = false;
159160
switch (m_sortMode) {
160161
case Title:
161-
return l.toString().localeAwareCompare(r.toString()) < 0;
162+
less = l.toString().localeAwareCompare(r.toString()) < 0;
163+
break;
162164
case ReleaseDate:
163-
return l.toDateTime() > r.toDateTime();
165+
less = l.toDateTime() < r.toDateTime();
166+
break;
167+
case Difficulty:
168+
case Duration:
169+
case Class:
170+
case Type:
171+
less = l.toUInt() < r.toUInt();
172+
break;
164173
default:
165-
return l.toInt() > r.toInt();
174+
less = false;
175+
break;
166176
}
177+
return less;
167178
}
168179

169180
bool LevelListProxy::filterAcceptsRow(int sourceRow,

src/LevelViewList.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ class LevelListModel : public QAbstractListModel {
3232
m_scrollCoversCursor(0),
3333
m_sequentialCoversCursor(0),
3434
m_scrollCoversCursorChanged(false),
35-
m_roleMap({
35+
m_roleTable({
3636
{ Qt::DisplayRole, [](const ListItemData &i){ return i.m_title; }},
3737
{ Qt::UserRole+1, [](const ListItemData &i){ return i.m_game_id; }},
3838
{ Qt::UserRole+2, [](const ListItemData &i){ return i.m_type; }},
@@ -57,7 +57,7 @@ class LevelListModel : public QAbstractListModel {
5757
QVariant data(const QModelIndex &index, int role) const override;
5858

5959
private:
60-
const QMap<int, std::function<QVariant(const ListItemData&)>> m_roleMap;
60+
const QHash<int, std::function<QVariant(const ListItemData&)>> m_roleTable;
6161
QVector<QSharedPointer<ListItemData>> m_levels;
6262
bool m_scrollCoversCursorChanged;
6363
quint64 m_scrollCoversCursor;

src/TombRaiderLinuxLauncher.cpp

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -220,13 +220,23 @@ void TombRaiderLinuxLauncher::setInstalled() {
220220

221221
bool TombRaiderLinuxLauncher::setStartupSetting(const StartupSetting settings) {
222222
bool status = true;
223-
if (settings.installed) {
223+
if (settings.installed == true) {
224224
ui->checkBoxInstalled->setChecked(true);
225-
levelListProxy->setInstalledFilter(true);
226225
}
227-
if (settings.original) {
228-
// ui->checkBoxOriginal->setChecked(true);
229-
// levelListProxy->set
226+
if (settings.original == true) {
227+
ui->checkBoxOriginal->setChecked(true);
228+
}
229+
if (settings.type_id != 0) {
230+
ui->comboBoxType->setCurrentIndex(settings.type_id);
231+
}
232+
if (settings.class_id != 0) {
233+
ui->comboBoxClass->setCurrentIndex(settings.class_id);
234+
}
235+
if (settings.difficulty_id != 0) {
236+
ui->comboBoxDifficulty->setCurrentIndex(settings.difficulty_id);
237+
}
238+
if (settings.duration_id != 0) {
239+
ui->comboBoxDuration->setCurrentIndex(settings.duration_id);
230240
}
231241
return status;
232242
}
@@ -250,12 +260,8 @@ void TombRaiderLinuxLauncher::sortByReleaseDate() {
250260
levelListProxy->setSortMode(LevelListProxy::ReleaseDate);
251261
}
252262

253-
// void TombRaiderLinuxLauncher::showOriginal() {
254-
// levelListProxy->setSortMode(LevelListProxy::None);
255-
// }
256-
257263
void TombRaiderLinuxLauncher::showtOriginal() {
258-
//levelListModel->showOriginal();
264+
// levelListModel->showOriginal();
259265
}
260266

261267
void TombRaiderLinuxLauncher::filterByClass(const QString &class_) {

0 commit comments

Comments
 (0)