154 |
155 |
155 // get locale |
156 // get locale |
156 QSettings settings(dataMgr.settingsFileName(), |
157 QSettings settings(dataMgr.settingsFileName(), |
157 QSettings::IniFormat); |
158 QSettings::IniFormat); |
158 |
159 |
159 QString loc = settings.value("misc/locale", "").toString(); |
160 QString loc = QLocale().name(); |
160 if (loc.isEmpty()) |
|
161 loc = QLocale::system().name(); |
|
162 |
161 |
163 QString infoFile = QString("physfs://Locale/missions_" + loc + ".txt"); |
162 QString infoFile = QString("physfs://Locale/missions_" + loc + ".txt"); |
164 |
163 |
165 // if file is non-existant try with language only |
164 // if file is non-existant try with language only |
166 if (!QFile::exists(infoFile)) |
165 if (!QFile::exists(infoFile)) |
192 case 3: |
191 case 3: |
193 subFolder = "Scenario"; |
192 subFolder = "Scenario"; |
194 m_widget = lstScenarios; |
193 m_widget = lstScenarios; |
195 break; |
194 break; |
196 } |
195 } |
|
196 // scripts to load |
|
197 // first, load scripts in order specified in order.cfg (if present) |
|
198 QFile orderFile(QString("physfs://Missions/%1/order.cfg").arg(subFolder)); |
|
199 QStringList orderedMissions; |
|
200 if (orderFile.open(QFile::ReadOnly)) |
|
201 { |
|
202 QString m_id; |
|
203 QTextStream input(&orderFile); |
|
204 while(true) |
|
205 { |
|
206 m_id = input.readLine(); |
|
207 if(m_id.isNull() || m_id.isEmpty()) |
|
208 { |
|
209 break; |
|
210 } |
|
211 QListWidgetItem * item = new QListWidgetItem(m_id); |
|
212 QString name = item->text().replace("_", " "); |
|
213 name = m_info->value(m_id + ".name", name).toString(); |
|
214 item->setText(name); |
|
215 item->setData(Qt::UserRole, m_id); |
|
216 m_widget->addItem(item); |
|
217 |
|
218 orderedMissions << m_id; |
|
219 } |
|
220 } |
|
221 |
|
222 // then, just load anything else in no particular order |
197 m_list = dataMgr.entryList( |
223 m_list = dataMgr.entryList( |
198 "Missions/" + subFolder, |
224 "Missions/" + subFolder, |
199 QDir::Files, QStringList("*.lua")). |
225 QDir::Files, QStringList("*.lua")). |
200 replaceInStrings(QRegExp("\\.lua$"), ""); |
226 replaceInStrings(QRegExp("\\.lua$"), ""); |
201 |
227 |
202 // scripts to load - TODO: model? |
|
203 foreach (const QString & m_id, m_list) |
228 foreach (const QString & m_id, m_list) |
204 { |
229 { |
|
230 // Disallow duplicates from order.cfg |
|
231 if (orderedMissions.contains(m_id)) |
|
232 { |
|
233 continue; |
|
234 } |
|
235 |
205 QListWidgetItem * item = new QListWidgetItem(m_id); |
236 QListWidgetItem * item = new QListWidgetItem(m_id); |
206 |
237 |
207 // fallback name: replace underscores in mission name with spaces |
238 // fallback name: replace underscores in mission name with spaces |
208 QString name = item->text().replace("_", " "); |
239 QString name = item->text().replace("_", " "); |
209 |
240 |