~ubuntu-branches/ubuntu/wily/hedgewars/wily

« back to all changes in this revision

Viewing changes to QTfrontend/gameuiconfig.cpp

  • Committer: Package Import Robot
  • Author(s): Dmitry E. Oboukhov
  • Date: 2011-09-23 10:16:55 UTC
  • mfrom: (1.2.11 upstream)
  • Revision ID: package-import@ubuntu.com-20110923101655-3977th2gc5n0a3pv
Tags: 0.9.16-1
* New upstream version.
 + Downloadable content! Simply click to install any content.
   New voices, hats, maps, themes, translations, music, scripts...
   Hedgewars is now more customisable than ever before! As time goes
   by we will be soliciting community content to feature on this page,
   so remember to check it from time to time. If you decide you want
   to go back to standard Hedgewars, just remove the Data directory
   from your Hedgewars config directory.
 + 3-D rendering! Diorama-like rendering of the game in a variety
   of 3D modes. Let us know which ones work best for you, we didn't
   really have the equipment to test them all.
 + Resizable game window.
 + New utilities! The Time Box will remove one of your hedgehogs
   from the game for a while, protecting from attack until it returns,
   somewhere else on the map. Land spray will allow you to build bridges,
   seal up holes, or just make life unpleasant for your enemies.
 + New single player: Bamboo Thicket, That Sinking Feeling, Newton and
   the Tree and multi-player: The Specialists, Space Invaders,
   Racer - scripts! And a ton more script hooks for scripters
 + New twists on old weapons. Drill strike, seduction and fire have
   been adjusted. Defective mines have been added, rope can attach to
   hogs/crates/barrels again, grenades now have variable bounce (use
   precise key + 1-5). Portal gun is now more usable in flight and
   all game actions are a lot faster.
 + New theme - Golf, dozens of new community hats and a new
   localised Default voice, Ukranian.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/*
2
2
 * Hedgewars, a free turn based strategy game
3
 
 * Copyright (c) 2006-2010 Andrey Korotaev <unC0Rr@gmail.com>
 
3
 * Copyright (c) 2006-2011 Andrey Korotaev <unC0Rr@gmail.com>
4
4
 *
5
5
 * This program is free software; you can redistribute it and/or modify
6
6
 * it under the terms of the GNU General Public License as published by
20
20
#include <QCheckBox>
21
21
#include <QLineEdit>
22
22
#include <QDesktopWidget>
23
 
#include <QApplication>
24
23
#include <QInputDialog>
 
24
#include <QCryptographicHash>
25
25
 
26
26
#include "gameuiconfig.h"
27
27
#include "hwform.h"
28
 
#include "pages.h"
 
28
#include "pageoptions.h"
 
29
#include "pagenetserver.h"
29
30
#include "hwconsts.h"
30
31
#include "fpsedit.h"
 
32
#include "HWApplication.h"
31
33
 
32
34
GameUIConfig::GameUIConfig(HWForm * FormWidgets, const QString & fileName)
33
35
    : QSettings(fileName, QSettings::IniFormat)
42
44
    Form->ui.pageOptions->WeaponTooltip->setChecked(value("misc/weaponTooltips", true).toBool());
43
45
 
44
46
    int t = Form->ui.pageOptions->CBResolution->findText(value("video/resolution").toString());
45
 
    Form->ui.pageOptions->CBResolution->setCurrentIndex((t < 0) ? 0 : t);
 
47
    if (t < 0) {
 
48
        if (Form->ui.pageOptions->CBResolution->count() > 1)
 
49
            Form->ui.pageOptions->CBResolution->setCurrentIndex(1);
 
50
        else 
 
51
            Form->ui.pageOptions->CBResolution->setCurrentIndex(0);
 
52
    }
 
53
    else Form->ui.pageOptions->CBResolution->setCurrentIndex(t);
 
54
    Form->ui.pageOptions->CBResolution->setCurrentIndex((t < 0) ? 1 : t);
46
55
    Form->ui.pageOptions->CBFullscreen->setChecked(value("video/fullscreen", false).toBool());
47
56
    bool ffscr=value("frontend/fullscreen", false).toBool();
48
57
    Form->ui.pageOptions->CBFrontendFullscreen->setChecked(ffscr);
49
58
 
50
59
    Form->ui.pageOptions->SLQuality->setValue(value("video/quality", 5).toUInt());
 
60
    Form->ui.pageOptions->CBStereoMode->setCurrentIndex(value("video/stereo", 0).toUInt());
51
61
    Form->ui.pageOptions->CBFrontendEffects->setChecked(frontendEffects);
52
62
    Form->ui.pageOptions->CBEnableSound->setChecked(value("audio/sound", true).toBool());
53
63
    Form->ui.pageOptions->CBEnableFrontendSound->setChecked(value("frontend/sound", true).toBool());
56
66
    Form->ui.pageOptions->volumeBox->setValue(value("audio/volume", 100).toUInt());
57
67
 
58
68
    QString netNick = value("net/nick", "").toString();
59
 
    if (netNick.isEmpty())
60
 
        netNick = QInputDialog::getText(Form,
61
 
                QObject::tr("Nickname"),
62
 
                QObject::tr("Please enter your nickname"),
63
 
                QLineEdit::Normal,
64
 
                QDir::home().dirName());
65
 
 
66
69
    Form->ui.pageOptions->editNetNick->setText(netNick);
 
70
    
 
71
    Form->ui.pageOptions->editNetPassword->installEventFilter(this);
 
72
    
 
73
    int passLength = value("net/passwordlength", 0).toInt();
 
74
    setNetPasswordLength(passLength);
67
75
 
68
76
    delete netHost;
69
77
    netHost = new QString(value("net/ip", "").toString());
84
92
 
85
93
    Form->ui.pageOptions->CBLanguage->setCurrentIndex(Form->ui.pageOptions->CBLanguage->findData(value("misc/locale", "").toString()));
86
94
 
87
 
    depth = QApplication::desktop()->depth();
 
95
    depth = HWApplication::desktop()->depth();
88
96
    if (depth < 16) depth = 16;
89
97
    else if (depth > 16) depth = 32;
90
98
}
93
101
{
94
102
    QDir teamdir;
95
103
    teamdir.cd(cfgdir->absolutePath() + "/Teams");
96
 
    QStringList teamslist = teamdir.entryList(QStringList("*.hwt"));
 
104
    QStringList teamslist = teamdir.entryList(QStringList("*.hwt"),QDir::Files|QDir::Hidden);
97
105
    QStringList cleanedList;
98
106
    for (QStringList::Iterator it = teamslist.begin(); it != teamslist.end(); ++it ) {
99
107
            QString tmpTeamStr=(*it).replace(QRegExp("^(.*)\\.hwt$"), "\\1");
113
121
    setValue("video/fullscreen", vid_Fullscreen());
114
122
 
115
123
    setValue("video/quality", Form->ui.pageOptions->SLQuality->value());
 
124
    setValue("video/stereo", stereoMode());
116
125
 
117
126
    setValue("frontend/effects", isFrontendEffects());
118
127
 
135
144
    setValue("audio/volume", Form->ui.pageOptions->volumeBox->value());
136
145
 
137
146
    setValue("net/nick", netNick());
 
147
    if (netPasswordIsValid())
 
148
    {
 
149
        setValue("net/passwordhash", netPasswordHash());
 
150
        setValue("net/passwordlength", netPasswordLength());
 
151
    }
138
152
    setValue("net/ip", *netHost);
139
153
    setValue("net/port", netPort);
140
154
    setValue("net/servername", Form->ui.pageNetServer->leServerDescr->text());
142
156
 
143
157
    setValue("fps/show", isShowFPSEnabled());
144
158
    setValue("fps/limit", Form->ui.pageOptions->fpsedit->value());
145
 
 
 
159
    
146
160
    setValue("misc/altdamage", isAltDamageEnabled());
147
161
    setValue("misc/appendTimeToRecords", appendDateTimeToRecordName());
148
162
    setValue("misc/locale", language());
183
197
    quint32 rqNoBackground = 0x00000004;  // don't draw background
184
198
    quint32 rqSimpleRope = 0x00000008;  // avoid drawing rope
185
199
    quint32 rq2DWater = 0x00000010;  // disabe 3D water effect
186
 
    quint32 rqFancyBoom = 0x00000020;  // no fancy explosion effects
 
200
    quint32 rqAntiBoom = 0x00000020;  // no fancy explosion effects
187
201
    quint32 rqKillFlakes = 0x00000040;  // no flakes
188
202
    quint32 rqSlowMenu = 0x00000080;  // ammomenu appears with no animation
189
203
    quint32 rqPlainSplash = 0x00000100;  // no droplets
204
218
        break;
205
219
      case 2:
206
220
        result |= rqBlurryLand | rqKillFlakes | rqPlainSplash | rq2DWater |
207
 
                  rqFancyBoom | rqSlowMenu;
 
221
                  rqAntiBoom | rqSlowMenu;
208
222
        break;
209
223
      case 1:
210
224
        result |= rqBlurryLand | rqKillFlakes | rqPlainSplash | rq2DWater |
211
 
                  rqFancyBoom | rqSlowMenu | rqSimpleRope | rqDesyncVBlank;
 
225
                  rqAntiBoom | rqSlowMenu | rqSimpleRope | rqDesyncVBlank;
212
226
        break;
213
227
      case 0:
214
228
        result |= rqBlurryLand | rqKillFlakes | rqPlainSplash | rq2DWater |
215
 
                  rqFancyBoom | rqSlowMenu | rqSimpleRope | rqDesyncVBlank |
 
229
                  rqAntiBoom | rqSlowMenu | rqSimpleRope | rqDesyncVBlank |
216
230
                  rqNoBackground | rqClampLess;
217
231
        break;
218
232
      default:
261
275
    return Form->ui.pageOptions->CBAltDamage->isChecked();
262
276
}
263
277
 
 
278
quint32 GameUIConfig::stereoMode() const
 
279
{
 
280
    return Form->ui.pageOptions->CBStereoMode->currentIndex();
 
281
}
 
282
 
264
283
bool GameUIConfig::appendDateTimeToRecordName()
265
284
{
266
285
    return Form->ui.pageOptions->CBNameWithDate->isChecked();
288
307
    return Form->ui.pageOptions->editNetNick->text();
289
308
}
290
309
 
 
310
void GameUIConfig::updNetNick()
 
311
{
 
312
    Form->ui.pageOptions->editNetNick->setText(value("net/nick", "").toString());
 
313
}
 
314
 
 
315
QByteArray GameUIConfig::netPasswordHash()
 
316
{
 
317
    return QCryptographicHash::hash(Form->ui.pageOptions->editNetPassword->text().toLatin1(), QCryptographicHash::Md5).toHex();
 
318
}
 
319
 
 
320
int GameUIConfig::netPasswordLength()
 
321
{
 
322
    return Form->ui.pageOptions->editNetPassword->text().size();
 
323
}
 
324
 
 
325
bool GameUIConfig::netPasswordIsValid()
 
326
{
 
327
    return (netPasswordLength() == 0 || Form->ui.pageOptions->editNetPassword->text() != QString(netPasswordLength(), '\0'));
 
328
}
 
329
 
 
330
// When hedgewars launches, the password field is set with null characters. If the user tries to edit the field and there are such characters, then clear the field
 
331
bool GameUIConfig::eventFilter(QObject *object, QEvent *event)
 
332
{
 
333
    if (event->type() == QEvent::FocusIn)
 
334
    {
 
335
        if ((QLineEdit *)object == Form->ui.pageOptions->editNetPassword)
 
336
        {
 
337
            if (!netPasswordIsValid())
 
338
            {
 
339
                Form->ui.pageOptions->editNetPassword->clear();
 
340
            }
 
341
        }
 
342
    }
 
343
    
 
344
    // Don't filter anything
 
345
    return false;
 
346
}
 
347
 
 
348
void GameUIConfig::setNetPasswordLength(int passwordLength)
 
349
{
 
350
    if (passwordLength > 0)
 
351
    {
 
352
        Form->ui.pageOptions->editNetPassword->setText(QString(passwordLength, '\0'));
 
353
    }
 
354
    else
 
355
    {
 
356
        Form->ui.pageOptions->editNetPassword->setText("");
 
357
    }
 
358
}
 
359
 
291
360
quint8 GameUIConfig::volume()
292
361
{
293
362
    return Form->ui.pageOptions->volumeBox->value() * 128 / 100;