71 |
71 |
72 pageLayout->addLayout(infoLayout, 0, 1); |
72 pageLayout->addLayout(infoLayout, 0, 1); |
73 pageLayout->setAlignment(infoLayout, Qt::AlignLeft); |
73 pageLayout->setAlignment(infoLayout, Qt::AlignLeft); |
74 |
74 |
75 |
75 |
76 // mission list |
76 // tab widget containing all lists |
77 lstMissions = new QListWidget(this); |
77 tbw = new QTabWidget(this); |
78 lstMissions->setWhatsThis(tr("Pick the mission or training to play")); |
78 pageLayout->addWidget(tbw, 1, 0, 1, 2); // span 2 columns |
79 pageLayout->addWidget(lstMissions, 1, 0, 1, 2); // span 2 columns |
79 // let's not make the tab widget use more space than needed |
80 |
80 tbw->setFixedWidth(400); |
81 // let's not make the list use more space than needed |
81 pageLayout->setAlignment(tbw, Qt::AlignHCenter); |
82 lstMissions->setFixedWidth(400); |
82 |
83 pageLayout->setAlignment(lstMissions, Qt::AlignHCenter); |
83 // training/challenge/scenario lists |
|
84 lstTrainings = new QListWidget(this); |
|
85 lstTrainings ->setWhatsThis(tr("Pick the training to play")); |
|
86 |
|
87 lstChallenges = new QListWidget(this); |
|
88 lstChallenges ->setWhatsThis(tr("Pick the challenge to play")); |
|
89 |
|
90 lstScenarios= new QListWidget(this); |
|
91 lstScenarios->setWhatsThis(tr("Pick the scenario to play")); |
|
92 |
|
93 tbw->addTab(lstTrainings, tr("Trainings")); |
|
94 tbw->addTab(lstChallenges, tr("Challenges")); |
|
95 tbw->addTab(lstScenarios, tr("Scenarios")); |
|
96 tbw->setCurrentWidget(lstTrainings); |
84 |
97 |
85 return pageLayout; |
98 return pageLayout; |
86 } |
99 } |
87 |
100 |
88 QLayout * PageTraining::footerLayoutDefinition() |
101 QLayout * PageTraining::footerLayoutDefinition() |
101 } |
114 } |
102 |
115 |
103 |
116 |
104 void PageTraining::connectSignals() |
117 void PageTraining::connectSignals() |
105 { |
118 { |
106 connect(lstMissions, SIGNAL(currentItemChanged(QListWidgetItem*, QListWidgetItem*)), this, SLOT(updateInfo())); |
119 connect(lstTrainings, SIGNAL(currentItemChanged(QListWidgetItem*, QListWidgetItem*)), this, SLOT(updateInfo())); |
107 connect(lstMissions, SIGNAL(itemClicked(QListWidgetItem*)), this, SLOT(updateInfo())); |
120 connect(lstTrainings, SIGNAL(itemClicked(QListWidgetItem*)), this, SLOT(updateInfo())); |
108 connect(lstMissions, SIGNAL(itemDoubleClicked(QListWidgetItem*)), this, SLOT(startSelected())); |
121 connect(lstTrainings, SIGNAL(itemDoubleClicked(QListWidgetItem*)), this, SLOT(startSelected())); |
|
122 |
|
123 connect(lstChallenges, SIGNAL(currentItemChanged(QListWidgetItem*, QListWidgetItem*)), this, SLOT(updateInfo())); |
|
124 connect(lstChallenges, SIGNAL(itemClicked(QListWidgetItem*)), this, SLOT(updateInfo())); |
|
125 connect(lstChallenges, SIGNAL(itemDoubleClicked(QListWidgetItem*)), this, SLOT(startSelected())); |
|
126 |
|
127 connect(lstScenarios, SIGNAL(currentItemChanged(QListWidgetItem*, QListWidgetItem*)), this, SLOT(updateInfo())); |
|
128 connect(lstScenarios, SIGNAL(itemClicked(QListWidgetItem*)), this, SLOT(updateInfo())); |
|
129 connect(lstScenarios, SIGNAL(itemDoubleClicked(QListWidgetItem*)), this, SLOT(startSelected())); |
|
130 |
|
131 connect(tbw, SIGNAL(currentChanged(int)), this, SLOT(updateInfo())); |
|
132 |
109 connect(btnPreview, SIGNAL(clicked()), this, SLOT(startSelected())); |
133 connect(btnPreview, SIGNAL(clicked()), this, SLOT(startSelected())); |
110 connect(btnStart, SIGNAL(clicked()), this, SLOT(startSelected())); |
134 connect(btnStart, SIGNAL(clicked()), this, SLOT(startSelected())); |
111 } |
135 } |
112 |
136 |
113 |
137 |
138 |
162 |
139 // preload mission info for current locale |
163 // preload mission info for current locale |
140 m_info = new QSettings(infoFile, QSettings::IniFormat, this); |
164 m_info = new QSettings(infoFile, QSettings::IniFormat, this); |
141 m_info->setIniCodec("UTF-8"); |
165 m_info->setIniCodec("UTF-8"); |
142 |
166 |
143 |
167 QStringList m_list; |
144 QStringList missionList = dataMgr.entryList( |
168 QListWidget * m_widget; |
145 "Missions/Training", |
169 QString subFolder; |
146 QDir::Files, QStringList("*.lua")). |
170 |
147 replaceInStrings(QRegExp("\\.lua$"), ""); |
171 for(int i=1; i<=3; i++) { |
148 |
172 switch(i) { |
149 // scripts to lost - TODO: model? |
173 case 1: |
150 foreach (const QString & mission, missionList) |
174 subFolder = "Training"; |
|
175 m_widget = lstTrainings; |
|
176 break; |
|
177 case 2: |
|
178 subFolder = "Challenge"; |
|
179 m_widget = lstChallenges; |
|
180 break; |
|
181 case 3: |
|
182 subFolder = "Scenario"; |
|
183 m_widget = lstScenarios; |
|
184 break; |
|
185 } |
|
186 m_list = dataMgr.entryList( |
|
187 "Missions/" + subFolder, |
|
188 QDir::Files, QStringList("*.lua")). |
|
189 replaceInStrings(QRegExp("\\.lua$"), ""); |
|
190 |
|
191 // scripts to load - TODO: model? |
|
192 foreach (const QString & m_id, m_list) |
|
193 { |
|
194 QListWidgetItem * item = new QListWidgetItem(m_id); |
|
195 |
|
196 // fallback name: replace underscores in mission name with spaces |
|
197 QString name = item->text().replace("_", " "); |
|
198 |
|
199 // see if we can get a prettier/translated name |
|
200 name = m_info->value(m_id + ".name", name).toString(); |
|
201 |
|
202 item->setText(name); |
|
203 |
|
204 // store original name in data |
|
205 item->setData(Qt::UserRole, m_id); |
|
206 |
|
207 m_widget->addItem(item); |
|
208 } |
|
209 } |
|
210 |
|
211 updateInfo(); |
|
212 |
|
213 // pre-select first mission |
|
214 if (lstTrainings->count() > 0) |
|
215 lstTrainings->setCurrentRow(0); |
|
216 |
|
217 if (lstChallenges->count() > 0) |
|
218 lstChallenges->setCurrentRow(0); |
|
219 |
|
220 if (lstScenarios->count() > 0) |
|
221 lstScenarios->setCurrentRow(0); |
|
222 } |
|
223 |
|
224 QString PageTraining::getSubFolderOfSelected() |
|
225 { |
|
226 QString subFolder; |
|
227 if (tbw->currentWidget() == lstTrainings) { |
|
228 subFolder = "Training"; |
|
229 } else if (tbw->currentWidget() == lstChallenges) { |
|
230 subFolder = "Challenge"; |
|
231 } else if (tbw->currentWidget() == lstScenarios) { |
|
232 subFolder = "Scenario"; |
|
233 } else { |
|
234 subFolder = "Training"; |
|
235 } |
|
236 return subFolder; |
|
237 } |
|
238 |
|
239 void PageTraining::startSelected() |
|
240 { |
|
241 QListWidget *list; |
|
242 list = (QListWidget*) tbw->currentWidget(); |
|
243 QListWidgetItem * curItem = list->currentItem(); |
|
244 |
|
245 if (curItem != NULL) |
|
246 emit startMission(curItem->data(Qt::UserRole).toString(), getSubFolderOfSelected()); |
|
247 } |
|
248 |
|
249 |
|
250 void PageTraining::updateInfo() |
|
251 { |
|
252 if (tbw->currentWidget()) |
151 { |
253 { |
152 QListWidgetItem * item = new QListWidgetItem(mission); |
254 QString subFolder; |
153 |
255 QListWidget *list; |
154 // fallback name: replace underscores in mission name with spaces |
256 subFolder = getSubFolderOfSelected(); |
155 QString name = item->text().replace("_", " "); |
257 list = (QListWidget*) tbw->currentWidget(); |
156 |
258 if (list->currentItem()) |
157 // see if we can get a prettier/translated name |
259 { |
158 name = m_info->value(mission + ".name", name).toString(); |
260 // TODO also use .pngs in userdata folder |
159 |
261 QString thumbFile = "physfs://Graphics/Missions/" + |
160 item->setText(name); |
262 subFolder + "/" + |
161 |
263 list->currentItem()->data(Qt::UserRole).toString() + |
162 // store original name in data |
264 "@2x.png"; |
163 item->setData(Qt::UserRole, mission); |
265 |
164 |
266 if (QFile::exists(thumbFile)) |
165 lstMissions->addItem(item); |
267 btnPreview->setIcon(QIcon(thumbFile)); |
|
268 else |
|
269 btnPreview->setIcon(QIcon(":/res/Trainings.png")); |
|
270 |
|
271 QString realName = list->currentItem()->data( |
|
272 Qt::UserRole).toString(); |
|
273 |
|
274 QString caption = m_info->value(realName + ".name", |
|
275 list->currentItem()->text()).toString(); |
|
276 |
|
277 QString description = m_info->value(realName + ".desc", |
|
278 tr("No description available")).toString(); |
|
279 |
|
280 lblCaption->setText("<h2>" + caption +"</h2>"); |
|
281 lblDescription->setText(description); |
|
282 } |
|
283 else |
|
284 { |
|
285 btnPreview->setIcon(QIcon(":/res/Trainings.png")); |
|
286 lblCaption->setText(tr("Select a mission!")); |
|
287 // TODO better text and tr() |
|
288 lblDescription->setText(""); |
|
289 } |
166 } |
290 } |
167 |
291 } |
168 updateInfo(); |
|
169 |
|
170 // pre-select first mission |
|
171 if (lstMissions->count() > 0) |
|
172 lstMissions->setCurrentRow(0); |
|
173 } |
|
174 |
|
175 |
|
176 void PageTraining::startSelected() |
|
177 { |
|
178 QListWidgetItem * curItem = lstMissions->currentItem(); |
|
179 |
|
180 if (curItem != NULL) |
|
181 emit startMission(curItem->data(Qt::UserRole).toString()); |
|
182 } |
|
183 |
|
184 |
|
185 void PageTraining::updateInfo() |
|
186 { |
|
187 if (lstMissions->currentItem()) |
|
188 { |
|
189 // TODO also use .pngs in userdata folder |
|
190 QString thumbFile = "physfs://Graphics/Missions/Training/" + |
|
191 lstMissions->currentItem()->data(Qt::UserRole).toString() + |
|
192 "@2x.png"; |
|
193 |
|
194 if (QFile::exists(thumbFile)) |
|
195 btnPreview->setIcon(QIcon(thumbFile)); |
|
196 else |
|
197 btnPreview->setIcon(QIcon(":/res/Trainings.png")); |
|
198 |
|
199 QString realName = lstMissions->currentItem()->data( |
|
200 Qt::UserRole).toString(); |
|
201 |
|
202 QString caption = m_info->value(realName + ".name", |
|
203 lstMissions->currentItem()->text()).toString(); |
|
204 |
|
205 QString description = m_info->value(realName + ".desc", |
|
206 tr("No description available")).toString(); |
|
207 |
|
208 lblCaption->setText("<h2>" + caption +"</h2>"); |
|
209 lblDescription->setText(description); |
|
210 } |
|
211 else |
|
212 { |
|
213 btnPreview->setIcon(QIcon(":/res/Trainings.png")); |
|
214 lblCaption->setText(tr("Select a mission!")); |
|
215 // TODO better text and tr() |
|
216 lblDescription->setText(""); |
|
217 } |
|
218 } |
|