579
|
1 |
/*
|
|
2 |
* Hedgewars, a worms-like game
|
|
3 |
* Copyright (c) 2006, 2007 Andrey Korotaev <unC0Rr@gmail.com>
|
|
4 |
*
|
|
5 |
* This program is free software; you can redistribute it and/or modify
|
|
6 |
* it under the terms of the GNU General Public License as published by
|
|
7 |
* the Free Software Foundation; version 2 of the License
|
|
8 |
*
|
|
9 |
* This program is distributed in the hope that it will be useful,
|
|
10 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
11 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
12 |
* GNU General Public License for more details.
|
|
13 |
*
|
|
14 |
* You should have received a copy of the GNU General Public License
|
|
15 |
* along with this program; if not, write to the Free Software
|
|
16 |
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
|
|
17 |
*/
|
|
18 |
|
|
19 |
#include <QFont>
|
|
20 |
#include <QGridLayout>
|
|
21 |
#include <QPushButton>
|
|
22 |
#include <QListWidget>
|
|
23 |
|
|
24 |
#include "hwconsts.h"
|
|
25 |
#include "playrecordpage.h"
|
|
26 |
|
|
27 |
PagePlayDemo::PagePlayDemo(QWidget* parent) : QWidget(parent)
|
|
28 |
{
|
|
29 |
QFont * font14 = new QFont("MS Shell Dlg", 14);
|
|
30 |
QGridLayout * pageLayout = new QGridLayout(this);
|
|
31 |
pageLayout->setColumnStretch(0, 1);
|
|
32 |
pageLayout->setColumnStretch(1, 2);
|
|
33 |
pageLayout->setColumnStretch(2, 1);
|
|
34 |
|
|
35 |
BtnBack = new QPushButton(this);
|
|
36 |
BtnBack->setFont(*font14);
|
|
37 |
BtnBack->setText(QPushButton::tr("Back"));
|
|
38 |
pageLayout->addWidget(BtnBack, 1, 0);
|
|
39 |
|
|
40 |
BtnPlayDemo = new QPushButton(this);
|
|
41 |
BtnPlayDemo->setGeometry(QRect(240, 330, 161, 41));
|
|
42 |
BtnPlayDemo->setFont(*font14);
|
|
43 |
BtnPlayDemo->setText(QPushButton::tr("Play demo"));
|
|
44 |
pageLayout->addWidget(BtnPlayDemo, 1, 2);
|
|
45 |
|
|
46 |
DemosList = new QListWidget(this);
|
|
47 |
DemosList->setGeometry(QRect(170, 10, 311, 311));
|
|
48 |
pageLayout->addWidget(DemosList, 0, 1);
|
|
49 |
}
|
|
50 |
|
581
|
51 |
void PagePlayDemo::FillFromDir(RecordType rectype)
|
579
|
52 |
{
|
581
|
53 |
QDir dir;
|
|
54 |
QString extension;
|
|
55 |
|
|
56 |
dir.cd(cfgdir->absolutePath());
|
|
57 |
if (rectype == RT_Demo)
|
|
58 |
{
|
|
59 |
dir.cd("Demos");
|
|
60 |
extension = "hwd_" + *cProtoVer;
|
|
61 |
BtnPlayDemo->setText(QPushButton::tr("Play demo"));
|
|
62 |
} else
|
|
63 |
{
|
|
64 |
dir.cd("Saves");
|
|
65 |
extension = "hws_" + *cProtoVer;
|
|
66 |
BtnPlayDemo->setText(QPushButton::tr("Load"));
|
|
67 |
}
|
579
|
68 |
dir.setFilter(QDir::Files);
|
580
|
69 |
|
|
70 |
QStringList sl = dir.entryList(QStringList(QString("*.%1").arg(extension)));
|
603
|
71 |
sl.replaceInStrings(QRegExp(QString("^(.*)\\.%1$").arg(extension)), "\\1");
|
580
|
72 |
|
579
|
73 |
DemosList->clear();
|
580
|
74 |
DemosList->addItems(sl);
|
579
|
75 |
|
580
|
76 |
for (int i = 0; i < DemosList->count(); ++i)
|
|
77 |
{
|
|
78 |
DemosList->item(i)->setData(Qt::UserRole, dir.absoluteFilePath(QString("%1.%2").arg(sl[i], extension)));
|
|
79 |
}
|
579
|
80 |
}
|
|
81 |
|