113 |
112 |
114 PageTraining::PageTraining(QWidget* parent) : AbstractPage(parent) |
113 PageTraining::PageTraining(QWidget* parent) : AbstractPage(parent) |
115 { |
114 { |
116 initPage(); |
115 initPage(); |
117 |
116 |
|
117 HWDataManager & dataMgr = HWDataManager::instance(); |
|
118 |
118 // get locale |
119 // get locale |
119 QSettings settings(cfgdir->absolutePath() + "/hedgewars.ini", |
120 QSettings settings(cfgdir->absolutePath() + "/hedgewars.ini", |
120 QSettings::IniFormat); |
121 QSettings::IniFormat); |
121 |
122 |
122 QString loc = settings.value("misc/locale", "").toString(); |
123 QString loc = settings.value("misc/locale", "").toString(); |
123 if (loc.isEmpty()) |
124 if (loc.isEmpty()) |
124 loc = QLocale::system().name(); |
125 loc = QLocale::system().name(); |
125 |
126 |
126 QString infoFile = HWDataManager::instance().findFileForRead( |
127 QString infoFile = dataMgr.findFileForRead( |
127 QString("Locale/missions_" + loc + ".txt")); |
128 QString("Locale/missions_" + loc + ".txt")); |
128 |
129 |
129 // if file is non-existant try with language only |
130 // if file is non-existant try with language only |
130 if (!QFile::exists(infoFile)) |
131 if (!QFile::exists(infoFile)) |
131 infoFile = HWDataManager::instance().findFileForRead(QString( |
132 infoFile = dataMgr.findFileForRead(QString( |
132 "Locale/missions_" + loc.remove(QRegExp("_.*$")) + ".txt")); |
133 "Locale/missions_" + loc.remove(QRegExp("_.*$")) + ".txt")); |
133 |
134 |
134 // fallback if file for current locale is non-existant |
135 // fallback if file for current locale is non-existant |
135 if (!QFile::exists(infoFile)) |
136 if (!QFile::exists(infoFile)) |
136 { |
137 infoFile = dataMgr.findFileForRead(QString("Locale/missions_en.txt")); |
137 infoFile = HWDataManager::instance().findFileForRead( |
|
138 QString("Locale/missions_en.txt")); |
|
139 } |
|
140 |
138 |
141 |
139 |
142 // preload mission info for current locale |
140 // preload mission info for current locale |
143 m_info = new QSettings(infoFile, QSettings::IniFormat, this); |
141 m_info = new QSettings(infoFile, QSettings::IniFormat, this); |
144 |
142 |
145 |
143 |
146 QStringList missionList = |
144 QStringList missionList = dataMgr.entryList( |
147 HWDataManager::instance().entryList( |
145 "Missions/Training", |
148 "Missions/Training", |
146 QDir::Files, QStringList("*.lua")). |
149 QDir::Files, |
147 replaceInStrings(QRegExp("\\.lua$"), ""); |
150 QStringList("*.lua") |
|
151 ).replaceInStrings(QRegExp("\\.lua$"), ""); |
|
152 |
148 |
153 // scripts to lost - TODO: model? |
149 // scripts to lost - TODO: model? |
154 foreach (const QString & mission, missionList) |
150 foreach (const QString & mission, missionList) |
155 { |
151 { |
156 QListWidgetItem * item = new QListWidgetItem(mission); |
152 QListWidgetItem * item = new QListWidgetItem(mission); |
157 |
153 |
158 // fallback name: replace underscores in mission name with spaces |
154 // fallback name: replace underscores in mission name with spaces |
159 QString name = item->text().remove("_"); |
155 QString name = item->text().replace("_", " "); |
160 |
156 |
161 // see if we can get a prettier/translated name |
157 // see if we can get a prettier/translated name |
162 name = m_info->value(mission + ".name", name).toString(); |
158 name = m_info->value(mission + ".name", name).toString(); |
163 |
159 |
164 item->setText(name); |
160 item->setText(name); |
186 } |
182 } |
187 |
183 |
188 |
184 |
189 void PageTraining::updateInfo() |
185 void PageTraining::updateInfo() |
190 { |
186 { |
|
187 HWDataManager & dataMgr = HWDataManager::instance(); |
|
188 |
191 if (lstMissions->currentItem()) |
189 if (lstMissions->currentItem()) |
192 { |
190 { |
193 // TODO also use .pngs in userdata folder |
191 // TODO also use .pngs in userdata folder |
194 QString thumbFile = datadir->absolutePath() + |
192 QString thumbFile = dataMgr.findFileForRead( |
195 "/Graphics/Missions/Training/" + |
193 "Graphics/Missions/Training/" + |
196 lstMissions->currentItem()->data(Qt::UserRole).toString() + |
194 lstMissions->currentItem()->data(Qt::UserRole).toString() + |
197 "@2x.png"; |
195 "@2x.png"); |
198 |
196 |
199 if (QFile::exists(thumbFile)) |
197 if (QFile::exists(thumbFile)) |
200 btnPreview->setIcon(QIcon(thumbFile)); |
198 btnPreview->setIcon(QIcon(thumbFile)); |
201 else |
199 else |
202 btnPreview->setIcon(QIcon(":/res/Trainings.png")); |
200 btnPreview->setIcon(QIcon(":/res/Trainings.png")); |