QTfrontend/ui/page/pagetraining.cpp
author sheepluva
Sat, 22 Oct 2011 10:59:06 +0200
changeset 6183 46895724fd7f
parent 6167 728cabee2c9f
child 6196 c16e84558f71
permissions -rw-r--r--
minor signal fail fix
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
5078
3527f0e7bb21 Removing pages.cpp and splitting it up into various files.
Zorg <zorgiepoo@gmail.com>
parents:
diff changeset
     1
/*
3527f0e7bb21 Removing pages.cpp and splitting it up into various files.
Zorg <zorgiepoo@gmail.com>
parents:
diff changeset
     2
 * Hedgewars, a free turn based strategy game
3527f0e7bb21 Removing pages.cpp and splitting it up into various files.
Zorg <zorgiepoo@gmail.com>
parents:
diff changeset
     3
 * Copyright (c) 2006-2011 Andrey Korotaev <unC0Rr@gmail.com>
3527f0e7bb21 Removing pages.cpp and splitting it up into various files.
Zorg <zorgiepoo@gmail.com>
parents:
diff changeset
     4
 *
3527f0e7bb21 Removing pages.cpp and splitting it up into various files.
Zorg <zorgiepoo@gmail.com>
parents:
diff changeset
     5
 * This program is free software; you can redistribute it and/or modify
3527f0e7bb21 Removing pages.cpp and splitting it up into various files.
Zorg <zorgiepoo@gmail.com>
parents:
diff changeset
     6
 * it under the terms of the GNU General Public License as published by
3527f0e7bb21 Removing pages.cpp and splitting it up into various files.
Zorg <zorgiepoo@gmail.com>
parents:
diff changeset
     7
 * the Free Software Foundation; version 2 of the License
3527f0e7bb21 Removing pages.cpp and splitting it up into various files.
Zorg <zorgiepoo@gmail.com>
parents:
diff changeset
     8
 *
3527f0e7bb21 Removing pages.cpp and splitting it up into various files.
Zorg <zorgiepoo@gmail.com>
parents:
diff changeset
     9
 * This program is distributed in the hope that it will be useful,
3527f0e7bb21 Removing pages.cpp and splitting it up into various files.
Zorg <zorgiepoo@gmail.com>
parents:
diff changeset
    10
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
3527f0e7bb21 Removing pages.cpp and splitting it up into various files.
Zorg <zorgiepoo@gmail.com>
parents:
diff changeset
    11
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
3527f0e7bb21 Removing pages.cpp and splitting it up into various files.
Zorg <zorgiepoo@gmail.com>
parents:
diff changeset
    12
 * GNU General Public License for more details.
3527f0e7bb21 Removing pages.cpp and splitting it up into various files.
Zorg <zorgiepoo@gmail.com>
parents:
diff changeset
    13
 *
3527f0e7bb21 Removing pages.cpp and splitting it up into various files.
Zorg <zorgiepoo@gmail.com>
parents:
diff changeset
    14
 * You should have received a copy of the GNU General Public License
3527f0e7bb21 Removing pages.cpp and splitting it up into various files.
Zorg <zorgiepoo@gmail.com>
parents:
diff changeset
    15
 * along with this program; if not, write to the Free Software
3527f0e7bb21 Removing pages.cpp and splitting it up into various files.
Zorg <zorgiepoo@gmail.com>
parents:
diff changeset
    16
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
3527f0e7bb21 Removing pages.cpp and splitting it up into various files.
Zorg <zorgiepoo@gmail.com>
parents:
diff changeset
    17
 */
3527f0e7bb21 Removing pages.cpp and splitting it up into various files.
Zorg <zorgiepoo@gmail.com>
parents:
diff changeset
    18
3527f0e7bb21 Removing pages.cpp and splitting it up into various files.
Zorg <zorgiepoo@gmail.com>
parents:
diff changeset
    19
#include <QGridLayout>
6052
5e3e7d19bdb5 stuffToBeAvoidedInFuture->append("layouting");
sheepluva
parents: 6050
diff changeset
    20
#include <QVBoxLayout>
6048
ae213ef7030a PIMP'ed up training screen. special thanks to mikade for supplying the pics <3
sheepluva
parents: 6042
diff changeset
    21
#include <QLabel>
ae213ef7030a PIMP'ed up training screen. special thanks to mikade for supplying the pics <3
sheepluva
parents: 6042
diff changeset
    22
#include <QListWidget>
ae213ef7030a PIMP'ed up training screen. special thanks to mikade for supplying the pics <3
sheepluva
parents: 6042
diff changeset
    23
#include <QListWidgetItem>
5078
3527f0e7bb21 Removing pages.cpp and splitting it up into various files.
Zorg <zorgiepoo@gmail.com>
parents:
diff changeset
    24
#include <QPushButton>
3527f0e7bb21 Removing pages.cpp and splitting it up into various files.
Zorg <zorgiepoo@gmail.com>
parents:
diff changeset
    25
6059
ddf020d0941a training screen localization works now
sheepluva
parents: 6058
diff changeset
    26
#include <QFile>
ddf020d0941a training screen localization works now
sheepluva
parents: 6058
diff changeset
    27
#include <QLocale>
6058
ae8684864a6e load mission caption and description from localization file (WIP)
sheepluva
parents: 6054
diff changeset
    28
#include <QSettings>
ae8684864a6e load mission caption and description from localization file (WIP)
sheepluva
parents: 6054
diff changeset
    29
6159
c780b8cf4d75 introduce HWDataManager util for transparent access to [user-]data files
sheepluva
parents: 6073
diff changeset
    30
#include "hwconsts.h"
c780b8cf4d75 introduce HWDataManager util for transparent access to [user-]data files
sheepluva
parents: 6073
diff changeset
    31
c780b8cf4d75 introduce HWDataManager util for transparent access to [user-]data files
sheepluva
parents: 6073
diff changeset
    32
#include "HWDataManager.h"
c780b8cf4d75 introduce HWDataManager util for transparent access to [user-]data files
sheepluva
parents: 6073
diff changeset
    33
5204
e1a5f4d5d86a split pages.h into several header files
koda
parents: 5078
diff changeset
    34
#include "pagetraining.h"
5078
3527f0e7bb21 Removing pages.cpp and splitting it up into various files.
Zorg <zorgiepoo@gmail.com>
parents:
diff changeset
    35
6042
8b5345758f62 some more cleanups/refactoring/blahblah, some button positions may are a bit off atm. also I added a new picture for one of the buttons
sheepluva
parents: 6009
diff changeset
    36
QLayout * PageTraining::bodyLayoutDefinition()
5078
3527f0e7bb21 Removing pages.cpp and splitting it up into various files.
Zorg <zorgiepoo@gmail.com>
parents:
diff changeset
    37
{
6042
8b5345758f62 some more cleanups/refactoring/blahblah, some button positions may are a bit off atm. also I added a new picture for one of the buttons
sheepluva
parents: 6009
diff changeset
    38
    QGridLayout * pageLayout = new QGridLayout();
8b5345758f62 some more cleanups/refactoring/blahblah, some button positions may are a bit off atm. also I added a new picture for one of the buttons
sheepluva
parents: 6009
diff changeset
    39
6048
ae213ef7030a PIMP'ed up training screen. special thanks to mikade for supplying the pics <3
sheepluva
parents: 6042
diff changeset
    40
// left column
ae213ef7030a PIMP'ed up training screen. special thanks to mikade for supplying the pics <3
sheepluva
parents: 6042
diff changeset
    41
ae213ef7030a PIMP'ed up training screen. special thanks to mikade for supplying the pics <3
sheepluva
parents: 6042
diff changeset
    42
    // declare start button, caption and description
6052
5e3e7d19bdb5 stuffToBeAvoidedInFuture->append("layouting");
sheepluva
parents: 6050
diff changeset
    43
    btnPreview = formattedButton(":/res/Trainings.png", true);
5e3e7d19bdb5 stuffToBeAvoidedInFuture->append("layouting");
sheepluva
parents: 6050
diff changeset
    44
    btnPreview->setToolTip(QPushButton::tr("Go!"));
5e3e7d19bdb5 stuffToBeAvoidedInFuture->append("layouting");
sheepluva
parents: 6050
diff changeset
    45
5e3e7d19bdb5 stuffToBeAvoidedInFuture->append("layouting");
sheepluva
parents: 6050
diff changeset
    46
    // make both rows equal height
5e3e7d19bdb5 stuffToBeAvoidedInFuture->append("layouting");
sheepluva
parents: 6050
diff changeset
    47
    pageLayout->setRowStretch(0, 1);
5e3e7d19bdb5 stuffToBeAvoidedInFuture->append("layouting");
sheepluva
parents: 6050
diff changeset
    48
    pageLayout->setRowStretch(1, 1);
6048
ae213ef7030a PIMP'ed up training screen. special thanks to mikade for supplying the pics <3
sheepluva
parents: 6042
diff changeset
    49
ae213ef7030a PIMP'ed up training screen. special thanks to mikade for supplying the pics <3
sheepluva
parents: 6042
diff changeset
    50
    // add start button, caption and description to 3 different rows
6052
5e3e7d19bdb5 stuffToBeAvoidedInFuture->append("layouting");
sheepluva
parents: 6050
diff changeset
    51
    pageLayout->addWidget(btnPreview, 0, 0);
5078
3527f0e7bb21 Removing pages.cpp and splitting it up into various files.
Zorg <zorgiepoo@gmail.com>
parents:
diff changeset
    52
6052
5e3e7d19bdb5 stuffToBeAvoidedInFuture->append("layouting");
sheepluva
parents: 6050
diff changeset
    53
    // center preview
5e3e7d19bdb5 stuffToBeAvoidedInFuture->append("layouting");
sheepluva
parents: 6050
diff changeset
    54
    pageLayout->setAlignment(btnPreview, Qt::AlignRight | Qt::AlignVCenter);
5078
3527f0e7bb21 Removing pages.cpp and splitting it up into various files.
Zorg <zorgiepoo@gmail.com>
parents:
diff changeset
    55
6048
ae213ef7030a PIMP'ed up training screen. special thanks to mikade for supplying the pics <3
sheepluva
parents: 6042
diff changeset
    56
ae213ef7030a PIMP'ed up training screen. special thanks to mikade for supplying the pics <3
sheepluva
parents: 6042
diff changeset
    57
// right column
ae213ef7030a PIMP'ed up training screen. special thanks to mikade for supplying the pics <3
sheepluva
parents: 6042
diff changeset
    58
6052
5e3e7d19bdb5 stuffToBeAvoidedInFuture->append("layouting");
sheepluva
parents: 6050
diff changeset
    59
    // info area (caption on top, description below)
5e3e7d19bdb5 stuffToBeAvoidedInFuture->append("layouting");
sheepluva
parents: 6050
diff changeset
    60
    QVBoxLayout * infoLayout = new QVBoxLayout();
5e3e7d19bdb5 stuffToBeAvoidedInFuture->append("layouting");
sheepluva
parents: 6050
diff changeset
    61
5e3e7d19bdb5 stuffToBeAvoidedInFuture->append("layouting");
sheepluva
parents: 6050
diff changeset
    62
    lblCaption = new QLabel();
5e3e7d19bdb5 stuffToBeAvoidedInFuture->append("layouting");
sheepluva
parents: 6050
diff changeset
    63
    lblCaption->setMinimumWidth(360);
5e3e7d19bdb5 stuffToBeAvoidedInFuture->append("layouting");
sheepluva
parents: 6050
diff changeset
    64
    lblCaption->setAlignment(Qt::AlignHCenter | Qt::AlignBottom);
5e3e7d19bdb5 stuffToBeAvoidedInFuture->append("layouting");
sheepluva
parents: 6050
diff changeset
    65
    lblCaption->setWordWrap(true);
5e3e7d19bdb5 stuffToBeAvoidedInFuture->append("layouting");
sheepluva
parents: 6050
diff changeset
    66
    lblDescription = new QLabel();
5e3e7d19bdb5 stuffToBeAvoidedInFuture->append("layouting");
sheepluva
parents: 6050
diff changeset
    67
    lblDescription->setMinimumWidth(360);
5e3e7d19bdb5 stuffToBeAvoidedInFuture->append("layouting");
sheepluva
parents: 6050
diff changeset
    68
    lblDescription->setAlignment(Qt::AlignHCenter | Qt::AlignTop);
5e3e7d19bdb5 stuffToBeAvoidedInFuture->append("layouting");
sheepluva
parents: 6050
diff changeset
    69
    lblDescription->setWordWrap(true);
5e3e7d19bdb5 stuffToBeAvoidedInFuture->append("layouting");
sheepluva
parents: 6050
diff changeset
    70
5e3e7d19bdb5 stuffToBeAvoidedInFuture->append("layouting");
sheepluva
parents: 6050
diff changeset
    71
    infoLayout->addWidget(lblCaption);
5e3e7d19bdb5 stuffToBeAvoidedInFuture->append("layouting");
sheepluva
parents: 6050
diff changeset
    72
    infoLayout->addWidget(lblDescription);
5e3e7d19bdb5 stuffToBeAvoidedInFuture->append("layouting");
sheepluva
parents: 6050
diff changeset
    73
5e3e7d19bdb5 stuffToBeAvoidedInFuture->append("layouting");
sheepluva
parents: 6050
diff changeset
    74
    pageLayout->addLayout(infoLayout, 0, 1);
5e3e7d19bdb5 stuffToBeAvoidedInFuture->append("layouting");
sheepluva
parents: 6050
diff changeset
    75
    pageLayout->setAlignment(infoLayout, Qt::AlignLeft);
5e3e7d19bdb5 stuffToBeAvoidedInFuture->append("layouting");
sheepluva
parents: 6050
diff changeset
    76
5e3e7d19bdb5 stuffToBeAvoidedInFuture->append("layouting");
sheepluva
parents: 6050
diff changeset
    77
5e3e7d19bdb5 stuffToBeAvoidedInFuture->append("layouting");
sheepluva
parents: 6050
diff changeset
    78
    // mission list
6048
ae213ef7030a PIMP'ed up training screen. special thanks to mikade for supplying the pics <3
sheepluva
parents: 6042
diff changeset
    79
    lstMissions = new QListWidget(this);
6052
5e3e7d19bdb5 stuffToBeAvoidedInFuture->append("layouting");
sheepluva
parents: 6050
diff changeset
    80
    pageLayout->addWidget(lstMissions, 1, 0, 1, 2); // span 2 columns
5e3e7d19bdb5 stuffToBeAvoidedInFuture->append("layouting");
sheepluva
parents: 6050
diff changeset
    81
5e3e7d19bdb5 stuffToBeAvoidedInFuture->append("layouting");
sheepluva
parents: 6050
diff changeset
    82
    // let's not make the list use more space than needed
5e3e7d19bdb5 stuffToBeAvoidedInFuture->append("layouting");
sheepluva
parents: 6050
diff changeset
    83
    lstMissions->setFixedWidth(360);
5e3e7d19bdb5 stuffToBeAvoidedInFuture->append("layouting");
sheepluva
parents: 6050
diff changeset
    84
    pageLayout->setAlignment(lstMissions, Qt::AlignHCenter);
5078
3527f0e7bb21 Removing pages.cpp and splitting it up into various files.
Zorg <zorgiepoo@gmail.com>
parents:
diff changeset
    85
6042
8b5345758f62 some more cleanups/refactoring/blahblah, some button positions may are a bit off atm. also I added a new picture for one of the buttons
sheepluva
parents: 6009
diff changeset
    86
    return pageLayout;
8b5345758f62 some more cleanups/refactoring/blahblah, some button positions may are a bit off atm. also I added a new picture for one of the buttons
sheepluva
parents: 6009
diff changeset
    87
}
6009
14f6fc9869f2 code cleanup/etc
sheepluva
parents: 5238
diff changeset
    88
6052
5e3e7d19bdb5 stuffToBeAvoidedInFuture->append("layouting");
sheepluva
parents: 6050
diff changeset
    89
QLayout * PageTraining::footerLayoutDefinition()
5e3e7d19bdb5 stuffToBeAvoidedInFuture->append("layouting");
sheepluva
parents: 6050
diff changeset
    90
{
5e3e7d19bdb5 stuffToBeAvoidedInFuture->append("layouting");
sheepluva
parents: 6050
diff changeset
    91
    QBoxLayout * bottomLayout = new QVBoxLayout();
5e3e7d19bdb5 stuffToBeAvoidedInFuture->append("layouting");
sheepluva
parents: 6050
diff changeset
    92
5e3e7d19bdb5 stuffToBeAvoidedInFuture->append("layouting");
sheepluva
parents: 6050
diff changeset
    93
    btnStart = formattedButton(QPushButton::tr("Go!"));
5e3e7d19bdb5 stuffToBeAvoidedInFuture->append("layouting");
sheepluva
parents: 6050
diff changeset
    94
    btnStart->setFixedWidth(140);
5e3e7d19bdb5 stuffToBeAvoidedInFuture->append("layouting");
sheepluva
parents: 6050
diff changeset
    95
5e3e7d19bdb5 stuffToBeAvoidedInFuture->append("layouting");
sheepluva
parents: 6050
diff changeset
    96
    bottomLayout->addWidget(btnStart);
5e3e7d19bdb5 stuffToBeAvoidedInFuture->append("layouting");
sheepluva
parents: 6050
diff changeset
    97
5e3e7d19bdb5 stuffToBeAvoidedInFuture->append("layouting");
sheepluva
parents: 6050
diff changeset
    98
    bottomLayout->setAlignment(btnStart, Qt::AlignRight | Qt::AlignVCenter);
5e3e7d19bdb5 stuffToBeAvoidedInFuture->append("layouting");
sheepluva
parents: 6050
diff changeset
    99
5e3e7d19bdb5 stuffToBeAvoidedInFuture->append("layouting");
sheepluva
parents: 6050
diff changeset
   100
    return bottomLayout;
5e3e7d19bdb5 stuffToBeAvoidedInFuture->append("layouting");
sheepluva
parents: 6050
diff changeset
   101
}
5e3e7d19bdb5 stuffToBeAvoidedInFuture->append("layouting");
sheepluva
parents: 6050
diff changeset
   102
6048
ae213ef7030a PIMP'ed up training screen. special thanks to mikade for supplying the pics <3
sheepluva
parents: 6042
diff changeset
   103
6042
8b5345758f62 some more cleanups/refactoring/blahblah, some button positions may are a bit off atm. also I added a new picture for one of the buttons
sheepluva
parents: 6009
diff changeset
   104
void PageTraining::connectSignals()
8b5345758f62 some more cleanups/refactoring/blahblah, some button positions may are a bit off atm. also I added a new picture for one of the buttons
sheepluva
parents: 6009
diff changeset
   105
{
6054
d3751a18cecb use currentItemChanged signal instead of itemSelectionChanged - since the latter is always one item behind if you hold down the mousebutton and move the cursor through the list
sheepluva
parents: 6052
diff changeset
   106
    connect(lstMissions, SIGNAL(currentItemChanged(QListWidgetItem*, QListWidgetItem*)), this, SLOT(updateInfo()));
6183
46895724fd7f minor signal fail fix
sheepluva
parents: 6167
diff changeset
   107
    connect(lstMissions, SIGNAL(itemClicked(QListWidgetItem*)), this, SLOT(updateInfo()));
6054
d3751a18cecb use currentItemChanged signal instead of itemSelectionChanged - since the latter is always one item behind if you hold down the mousebutton and move the cursor through the list
sheepluva
parents: 6052
diff changeset
   108
    connect(lstMissions, SIGNAL(itemDoubleClicked(QListWidgetItem*)), this, SLOT(startSelected()));
6052
5e3e7d19bdb5 stuffToBeAvoidedInFuture->append("layouting");
sheepluva
parents: 6050
diff changeset
   109
    connect(btnPreview, SIGNAL(clicked()), this, SLOT(startSelected()));
6048
ae213ef7030a PIMP'ed up training screen. special thanks to mikade for supplying the pics <3
sheepluva
parents: 6042
diff changeset
   110
    connect(btnStart, SIGNAL(clicked()), this, SLOT(startSelected()));
5078
3527f0e7bb21 Removing pages.cpp and splitting it up into various files.
Zorg <zorgiepoo@gmail.com>
parents:
diff changeset
   111
}
6042
8b5345758f62 some more cleanups/refactoring/blahblah, some button positions may are a bit off atm. also I added a new picture for one of the buttons
sheepluva
parents: 6009
diff changeset
   112
6048
ae213ef7030a PIMP'ed up training screen. special thanks to mikade for supplying the pics <3
sheepluva
parents: 6042
diff changeset
   113
6042
8b5345758f62 some more cleanups/refactoring/blahblah, some button positions may are a bit off atm. also I added a new picture for one of the buttons
sheepluva
parents: 6009
diff changeset
   114
PageTraining::PageTraining(QWidget* parent) : AbstractPage(parent)
8b5345758f62 some more cleanups/refactoring/blahblah, some button positions may are a bit off atm. also I added a new picture for one of the buttons
sheepluva
parents: 6009
diff changeset
   115
{
8b5345758f62 some more cleanups/refactoring/blahblah, some button positions may are a bit off atm. also I added a new picture for one of the buttons
sheepluva
parents: 6009
diff changeset
   116
    initPage();
8b5345758f62 some more cleanups/refactoring/blahblah, some button positions may are a bit off atm. also I added a new picture for one of the buttons
sheepluva
parents: 6009
diff changeset
   117
6059
ddf020d0941a training screen localization works now
sheepluva
parents: 6058
diff changeset
   118
    // get locale
ddf020d0941a training screen localization works now
sheepluva
parents: 6058
diff changeset
   119
    QSettings settings(cfgdir->absolutePath() + "/hedgewars.ini",
ddf020d0941a training screen localization works now
sheepluva
parents: 6058
diff changeset
   120
                       QSettings::IniFormat);
ddf020d0941a training screen localization works now
sheepluva
parents: 6058
diff changeset
   121
ddf020d0941a training screen localization works now
sheepluva
parents: 6058
diff changeset
   122
    QString loc = settings.value("misc/locale", "").toString();
ddf020d0941a training screen localization works now
sheepluva
parents: 6058
diff changeset
   123
    if (loc.isEmpty())
ddf020d0941a training screen localization works now
sheepluva
parents: 6058
diff changeset
   124
        loc = QLocale::system().name();
ddf020d0941a training screen localization works now
sheepluva
parents: 6058
diff changeset
   125
6167
728cabee2c9f simplified some stuff I wrote
sheepluva
parents: 6160
diff changeset
   126
    QString infoFile = HWDataManager::instance().findFileForRead(
728cabee2c9f simplified some stuff I wrote
sheepluva
parents: 6160
diff changeset
   127
                            QString("Locale/missions_" + loc + ".txt"));
6059
ddf020d0941a training screen localization works now
sheepluva
parents: 6058
diff changeset
   128
ddf020d0941a training screen localization works now
sheepluva
parents: 6058
diff changeset
   129
    // if file is non-existant try with language only
6167
728cabee2c9f simplified some stuff I wrote
sheepluva
parents: 6160
diff changeset
   130
    if (!QFile::exists(infoFile))
6159
c780b8cf4d75 introduce HWDataManager util for transparent access to [user-]data files
sheepluva
parents: 6073
diff changeset
   131
        infoFile = HWDataManager::instance().findFileForRead(QString(
6160
863d3edf5690 cleaning up some more, also adding a WIP file. changes: hats in the hat selection are now sorted like this: NoHat, Reserved hats (alphabetically), All other hats (alphabeticall)
sheepluva
parents: 6159
diff changeset
   132
                "Locale/missions_" + loc.remove(QRegExp("_.*$")) + ".txt"));
6059
ddf020d0941a training screen localization works now
sheepluva
parents: 6058
diff changeset
   133
ddf020d0941a training screen localization works now
sheepluva
parents: 6058
diff changeset
   134
    // fallback if file for current locale is non-existant
6167
728cabee2c9f simplified some stuff I wrote
sheepluva
parents: 6160
diff changeset
   135
    if (!QFile::exists(infoFile))
6159
c780b8cf4d75 introduce HWDataManager util for transparent access to [user-]data files
sheepluva
parents: 6073
diff changeset
   136
    {
6160
863d3edf5690 cleaning up some more, also adding a WIP file. changes: hats in the hat selection are now sorted like this: NoHat, Reserved hats (alphabetically), All other hats (alphabeticall)
sheepluva
parents: 6159
diff changeset
   137
        infoFile = HWDataManager::instance().findFileForRead(
863d3edf5690 cleaning up some more, also adding a WIP file. changes: hats in the hat selection are now sorted like this: NoHat, Reserved hats (alphabetically), All other hats (alphabeticall)
sheepluva
parents: 6159
diff changeset
   138
                                            QString("Locale/missions_en.txt"));
6159
c780b8cf4d75 introduce HWDataManager util for transparent access to [user-]data files
sheepluva
parents: 6073
diff changeset
   139
    }
c780b8cf4d75 introduce HWDataManager util for transparent access to [user-]data files
sheepluva
parents: 6073
diff changeset
   140
6059
ddf020d0941a training screen localization works now
sheepluva
parents: 6058
diff changeset
   141
ddf020d0941a training screen localization works now
sheepluva
parents: 6058
diff changeset
   142
    // preload mission info for current locale
6167
728cabee2c9f simplified some stuff I wrote
sheepluva
parents: 6160
diff changeset
   143
    m_info = new QSettings(infoFile, QSettings::IniFormat, this);
6058
ae8684864a6e load mission caption and description from localization file (WIP)
sheepluva
parents: 6054
diff changeset
   144
6042
8b5345758f62 some more cleanups/refactoring/blahblah, some button positions may are a bit off atm. also I added a new picture for one of the buttons
sheepluva
parents: 6009
diff changeset
   145
6159
c780b8cf4d75 introduce HWDataManager util for transparent access to [user-]data files
sheepluva
parents: 6073
diff changeset
   146
    QStringList missionList =
6160
863d3edf5690 cleaning up some more, also adding a WIP file. changes: hats in the hat selection are now sorted like this: NoHat, Reserved hats (alphabetically), All other hats (alphabeticall)
sheepluva
parents: 6159
diff changeset
   147
            HWDataManager::instance().entryList(
863d3edf5690 cleaning up some more, also adding a WIP file. changes: hats in the hat selection are now sorted like this: NoHat, Reserved hats (alphabetically), All other hats (alphabeticall)
sheepluva
parents: 6159
diff changeset
   148
                                                "Missions/Training",
863d3edf5690 cleaning up some more, also adding a WIP file. changes: hats in the hat selection are now sorted like this: NoHat, Reserved hats (alphabetically), All other hats (alphabeticall)
sheepluva
parents: 6159
diff changeset
   149
                                                QDir::Files,
863d3edf5690 cleaning up some more, also adding a WIP file. changes: hats in the hat selection are now sorted like this: NoHat, Reserved hats (alphabetically), All other hats (alphabeticall)
sheepluva
parents: 6159
diff changeset
   150
                                                QStringList("*.lua")
863d3edf5690 cleaning up some more, also adding a WIP file. changes: hats in the hat selection are now sorted like this: NoHat, Reserved hats (alphabetically), All other hats (alphabeticall)
sheepluva
parents: 6159
diff changeset
   151
                                    ).replaceInStrings(QRegExp("\\.lua$"), "");
6042
8b5345758f62 some more cleanups/refactoring/blahblah, some button positions may are a bit off atm. also I added a new picture for one of the buttons
sheepluva
parents: 6009
diff changeset
   152
6159
c780b8cf4d75 introduce HWDataManager util for transparent access to [user-]data files
sheepluva
parents: 6073
diff changeset
   153
    // scripts to lost - TODO: model?
6048
ae213ef7030a PIMP'ed up training screen. special thanks to mikade for supplying the pics <3
sheepluva
parents: 6042
diff changeset
   154
    foreach (const QString & mission, missionList)
6042
8b5345758f62 some more cleanups/refactoring/blahblah, some button positions may are a bit off atm. also I added a new picture for one of the buttons
sheepluva
parents: 6009
diff changeset
   155
    {
6048
ae213ef7030a PIMP'ed up training screen. special thanks to mikade for supplying the pics <3
sheepluva
parents: 6042
diff changeset
   156
        QListWidgetItem * item = new QListWidgetItem(mission);
ae213ef7030a PIMP'ed up training screen. special thanks to mikade for supplying the pics <3
sheepluva
parents: 6042
diff changeset
   157
6059
ddf020d0941a training screen localization works now
sheepluva
parents: 6058
diff changeset
   158
        // fallback name: replace underscores in mission name with spaces
6160
863d3edf5690 cleaning up some more, also adding a WIP file. changes: hats in the hat selection are now sorted like this: NoHat, Reserved hats (alphabetically), All other hats (alphabeticall)
sheepluva
parents: 6159
diff changeset
   159
        QString name = item->text().remove("_");
6059
ddf020d0941a training screen localization works now
sheepluva
parents: 6058
diff changeset
   160
ddf020d0941a training screen localization works now
sheepluva
parents: 6058
diff changeset
   161
        // see if we can get a prettier/translated name
ddf020d0941a training screen localization works now
sheepluva
parents: 6058
diff changeset
   162
        name = m_info->value(mission + ".name", name).toString();
ddf020d0941a training screen localization works now
sheepluva
parents: 6058
diff changeset
   163
ddf020d0941a training screen localization works now
sheepluva
parents: 6058
diff changeset
   164
        item->setText(name);
6048
ae213ef7030a PIMP'ed up training screen. special thanks to mikade for supplying the pics <3
sheepluva
parents: 6042
diff changeset
   165
ae213ef7030a PIMP'ed up training screen. special thanks to mikade for supplying the pics <3
sheepluva
parents: 6042
diff changeset
   166
        // store original name in data
ae213ef7030a PIMP'ed up training screen. special thanks to mikade for supplying the pics <3
sheepluva
parents: 6042
diff changeset
   167
        item->setData(Qt::UserRole, mission);
ae213ef7030a PIMP'ed up training screen. special thanks to mikade for supplying the pics <3
sheepluva
parents: 6042
diff changeset
   168
ae213ef7030a PIMP'ed up training screen. special thanks to mikade for supplying the pics <3
sheepluva
parents: 6042
diff changeset
   169
        lstMissions->addItem(item);
6042
8b5345758f62 some more cleanups/refactoring/blahblah, some button positions may are a bit off atm. also I added a new picture for one of the buttons
sheepluva
parents: 6009
diff changeset
   170
    }
8b5345758f62 some more cleanups/refactoring/blahblah, some button positions may are a bit off atm. also I added a new picture for one of the buttons
sheepluva
parents: 6009
diff changeset
   171
6048
ae213ef7030a PIMP'ed up training screen. special thanks to mikade for supplying the pics <3
sheepluva
parents: 6042
diff changeset
   172
    updateInfo();
6052
5e3e7d19bdb5 stuffToBeAvoidedInFuture->append("layouting");
sheepluva
parents: 6050
diff changeset
   173
5e3e7d19bdb5 stuffToBeAvoidedInFuture->append("layouting");
sheepluva
parents: 6050
diff changeset
   174
    // pre-select first mission
5e3e7d19bdb5 stuffToBeAvoidedInFuture->append("layouting");
sheepluva
parents: 6050
diff changeset
   175
    if (lstMissions->count() > 0)
5e3e7d19bdb5 stuffToBeAvoidedInFuture->append("layouting");
sheepluva
parents: 6050
diff changeset
   176
        lstMissions->setCurrentRow(0);
6042
8b5345758f62 some more cleanups/refactoring/blahblah, some button positions may are a bit off atm. also I added a new picture for one of the buttons
sheepluva
parents: 6009
diff changeset
   177
}
8b5345758f62 some more cleanups/refactoring/blahblah, some button positions may are a bit off atm. also I added a new picture for one of the buttons
sheepluva
parents: 6009
diff changeset
   178
6048
ae213ef7030a PIMP'ed up training screen. special thanks to mikade for supplying the pics <3
sheepluva
parents: 6042
diff changeset
   179
ae213ef7030a PIMP'ed up training screen. special thanks to mikade for supplying the pics <3
sheepluva
parents: 6042
diff changeset
   180
void PageTraining::startSelected()
ae213ef7030a PIMP'ed up training screen. special thanks to mikade for supplying the pics <3
sheepluva
parents: 6042
diff changeset
   181
{
6050
07561ade87ca oops, I forgot I wanted to fix that before committing xD
sheepluva
parents: 6048
diff changeset
   182
    QListWidgetItem * curItem = lstMissions->currentItem();
07561ade87ca oops, I forgot I wanted to fix that before committing xD
sheepluva
parents: 6048
diff changeset
   183
07561ade87ca oops, I forgot I wanted to fix that before committing xD
sheepluva
parents: 6048
diff changeset
   184
    if (curItem != NULL)
07561ade87ca oops, I forgot I wanted to fix that before committing xD
sheepluva
parents: 6048
diff changeset
   185
        emit startMission(curItem->data(Qt::UserRole).toString());
6048
ae213ef7030a PIMP'ed up training screen. special thanks to mikade for supplying the pics <3
sheepluva
parents: 6042
diff changeset
   186
}
ae213ef7030a PIMP'ed up training screen. special thanks to mikade for supplying the pics <3
sheepluva
parents: 6042
diff changeset
   187
ae213ef7030a PIMP'ed up training screen. special thanks to mikade for supplying the pics <3
sheepluva
parents: 6042
diff changeset
   188
ae213ef7030a PIMP'ed up training screen. special thanks to mikade for supplying the pics <3
sheepluva
parents: 6042
diff changeset
   189
void PageTraining::updateInfo()
ae213ef7030a PIMP'ed up training screen. special thanks to mikade for supplying the pics <3
sheepluva
parents: 6042
diff changeset
   190
{
ae213ef7030a PIMP'ed up training screen. special thanks to mikade for supplying the pics <3
sheepluva
parents: 6042
diff changeset
   191
    if (lstMissions->currentItem())
ae213ef7030a PIMP'ed up training screen. special thanks to mikade for supplying the pics <3
sheepluva
parents: 6042
diff changeset
   192
    {
6050
07561ade87ca oops, I forgot I wanted to fix that before committing xD
sheepluva
parents: 6048
diff changeset
   193
        // TODO also use .pngs in userdata folder
6058
ae8684864a6e load mission caption and description from localization file (WIP)
sheepluva
parents: 6054
diff changeset
   194
        QString thumbFile = datadir->absolutePath() +
ae8684864a6e load mission caption and description from localization file (WIP)
sheepluva
parents: 6054
diff changeset
   195
                    "/Graphics/Missions/Training/" +
ae8684864a6e load mission caption and description from localization file (WIP)
sheepluva
parents: 6054
diff changeset
   196
                    lstMissions->currentItem()->data(Qt::UserRole).toString() +
6073
e6ce1a337e0f infecting sheepluva's mission graphics with retina images
koda
parents: 6060
diff changeset
   197
                    "@2x.png";
6058
ae8684864a6e load mission caption and description from localization file (WIP)
sheepluva
parents: 6054
diff changeset
   198
6048
ae213ef7030a PIMP'ed up training screen. special thanks to mikade for supplying the pics <3
sheepluva
parents: 6042
diff changeset
   199
        if (QFile::exists(thumbFile))
6052
5e3e7d19bdb5 stuffToBeAvoidedInFuture->append("layouting");
sheepluva
parents: 6050
diff changeset
   200
            btnPreview->setIcon(QIcon(thumbFile));
6048
ae213ef7030a PIMP'ed up training screen. special thanks to mikade for supplying the pics <3
sheepluva
parents: 6042
diff changeset
   201
        else
6052
5e3e7d19bdb5 stuffToBeAvoidedInFuture->append("layouting");
sheepluva
parents: 6050
diff changeset
   202
            btnPreview->setIcon(QIcon(":/res/Trainings.png"));
6048
ae213ef7030a PIMP'ed up training screen. special thanks to mikade for supplying the pics <3
sheepluva
parents: 6042
diff changeset
   203
6058
ae8684864a6e load mission caption and description from localization file (WIP)
sheepluva
parents: 6054
diff changeset
   204
        QString realName = lstMissions->currentItem()->data(
ae8684864a6e load mission caption and description from localization file (WIP)
sheepluva
parents: 6054
diff changeset
   205
                           Qt::UserRole).toString();
ae8684864a6e load mission caption and description from localization file (WIP)
sheepluva
parents: 6054
diff changeset
   206
ae8684864a6e load mission caption and description from localization file (WIP)
sheepluva
parents: 6054
diff changeset
   207
        QString caption = m_info->value(realName + ".name", 
ae8684864a6e load mission caption and description from localization file (WIP)
sheepluva
parents: 6054
diff changeset
   208
                          lstMissions->currentItem()->text()).toString();
ae8684864a6e load mission caption and description from localization file (WIP)
sheepluva
parents: 6054
diff changeset
   209
ae8684864a6e load mission caption and description from localization file (WIP)
sheepluva
parents: 6054
diff changeset
   210
        QString description = m_info->value(realName + ".desc",
ae8684864a6e load mission caption and description from localization file (WIP)
sheepluva
parents: 6054
diff changeset
   211
                              tr("No description available")).toString();
ae8684864a6e load mission caption and description from localization file (WIP)
sheepluva
parents: 6054
diff changeset
   212
ae8684864a6e load mission caption and description from localization file (WIP)
sheepluva
parents: 6054
diff changeset
   213
        lblCaption->setText("<h2>" + caption +"</h2>");
ae8684864a6e load mission caption and description from localization file (WIP)
sheepluva
parents: 6054
diff changeset
   214
        lblDescription->setText(description);
6048
ae213ef7030a PIMP'ed up training screen. special thanks to mikade for supplying the pics <3
sheepluva
parents: 6042
diff changeset
   215
    }
ae213ef7030a PIMP'ed up training screen. special thanks to mikade for supplying the pics <3
sheepluva
parents: 6042
diff changeset
   216
    else
ae213ef7030a PIMP'ed up training screen. special thanks to mikade for supplying the pics <3
sheepluva
parents: 6042
diff changeset
   217
    {
6052
5e3e7d19bdb5 stuffToBeAvoidedInFuture->append("layouting");
sheepluva
parents: 6050
diff changeset
   218
        btnPreview->setIcon(QIcon(":/res/Trainings.png"));
5e3e7d19bdb5 stuffToBeAvoidedInFuture->append("layouting");
sheepluva
parents: 6050
diff changeset
   219
        lblCaption->setText(tr("Select a mission!"));
6048
ae213ef7030a PIMP'ed up training screen. special thanks to mikade for supplying the pics <3
sheepluva
parents: 6042
diff changeset
   220
        // TODO better text and tr()
6052
5e3e7d19bdb5 stuffToBeAvoidedInFuture->append("layouting");
sheepluva
parents: 6050
diff changeset
   221
        lblDescription->setText("");
6048
ae213ef7030a PIMP'ed up training screen. special thanks to mikade for supplying the pics <3
sheepluva
parents: 6042
diff changeset
   222
    }
ae213ef7030a PIMP'ed up training screen. special thanks to mikade for supplying the pics <3
sheepluva
parents: 6042
diff changeset
   223
}