22 #include <QInputDialog> |
22 #include <QInputDialog> |
23 #include <QCryptographicHash> |
23 #include <QCryptographicHash> |
24 #include <QStandardItemModel> |
24 #include <QStandardItemModel> |
25 #include <QNetworkProxy> |
25 #include <QNetworkProxy> |
26 #include <QNetworkProxyFactory> |
26 #include <QNetworkProxyFactory> |
|
27 #include <utility> |
27 |
28 |
28 #include "gameuiconfig.h" |
29 #include "gameuiconfig.h" |
29 #include "hwform.h" |
30 #include "hwform.h" |
30 #include "pageoptions.h" |
31 #include "pageoptions.h" |
31 #include "pagevideos.h" |
32 #include "pagevideos.h" |
32 #include "pagenetserver.h" |
33 #include "pagenetserver.h" |
33 #include "hwconsts.h" |
34 #include "hwconsts.h" |
34 #include "fpsedit.h" |
35 #include "fpsedit.h" |
35 #include "HWApplication.h" |
36 #include "HWApplication.h" |
36 #include "DataManager.h" |
37 #include "DataManager.h" |
|
38 #include "SDL.h" |
37 |
39 |
38 |
40 |
39 const QNetworkProxy::ProxyType proxyTypesMap[] = { |
41 const QNetworkProxy::ProxyType proxyTypesMap[] = { |
40 QNetworkProxy::NoProxy |
42 QNetworkProxy::NoProxy |
41 , QNetworkProxy::NoProxy // dummy value |
43 , QNetworkProxy::NoProxy // dummy value |
50 |
52 |
51 setIniCodec("UTF-8"); |
53 setIniCodec("UTF-8"); |
52 |
54 |
53 connect(Form->ui.pageOptions->CBFrontendMusic, SIGNAL(toggled(bool)), Form, SLOT(Music(bool))); |
55 connect(Form->ui.pageOptions->CBFrontendMusic, SIGNAL(toggled(bool)), Form, SLOT(Music(bool))); |
54 |
56 |
|
57 for(int i = 0; i < BINDS_NUMBER; i++) |
|
58 { |
|
59 m_binds.append(BindAction()); |
|
60 m_binds[i].action = cbinds[i].action; |
|
61 m_binds[i].strbind = cbinds[i].strbind; |
|
62 } |
|
63 |
55 //Form->resize(value("frontend/width", 640).toUInt(), value("frontend/height", 450).toUInt()); |
64 //Form->resize(value("frontend/width", 640).toUInt(), value("frontend/height", 450).toUInt()); |
56 resizeToConfigValues(); |
65 resizeToConfigValues(); |
57 |
66 |
58 reloadValues(); |
67 reloadValues(); |
59 #ifdef VIDEOREC |
68 #ifdef VIDEOREC |
63 |
72 |
64 void GameUIConfig::reloadValues(void) |
73 void GameUIConfig::reloadValues(void) |
65 { |
74 { |
66 Form->ui.pageOptions->WeaponTooltip->setChecked(value("misc/weaponTooltips", true).toBool()); |
75 Form->ui.pageOptions->WeaponTooltip->setChecked(value("misc/weaponTooltips", true).toBool()); |
67 |
76 |
68 int t = Form->ui.pageOptions->CBResolution->findText(value("video/resolution").toString()); |
77 int t = Form->ui.pageOptions->CBResolution->findText(value("video/fullscreenResolution").toString()); |
69 if (t < 0) |
78 if (t < 0) |
70 { |
79 { |
71 if (Form->ui.pageOptions->CBResolution->count() > 1) |
80 if (Form->ui.pageOptions->CBResolution->count() > 1) |
72 Form->ui.pageOptions->CBResolution->setCurrentIndex(1); |
81 Form->ui.pageOptions->CBResolution->setCurrentIndex(1); |
73 else |
82 else |
74 Form->ui.pageOptions->CBResolution->setCurrentIndex(0); |
83 Form->ui.pageOptions->CBResolution->setCurrentIndex(0); |
75 } |
84 } |
76 else Form->ui.pageOptions->CBResolution->setCurrentIndex(t); |
85 else Form->ui.pageOptions->CBResolution->setCurrentIndex(t); |
|
86 |
|
87 // Default the windowed resolution to 5/6 of the screen size |
|
88 int screenWidth = SDL_GetVideoInfo()->current_w * 5 / 6; |
|
89 int screenHeight = SDL_GetVideoInfo()->current_h * 5 / 6; |
|
90 QString widthStr; widthStr.setNum(screenWidth); |
|
91 QString heightStr; heightStr.setNum(screenHeight); |
|
92 QString wWidth = value("video/windowedWidth", widthStr).toString(); |
|
93 QString wHeight = value("video/windowedHeight", heightStr).toString(); |
|
94 // If left blank reset the resolution to the default |
|
95 wWidth = (wWidth == "" ? widthStr : wWidth); |
|
96 wHeight = (wHeight == "" ? heightStr : wHeight); |
|
97 Form->ui.pageOptions->windowWidthEdit->setText(wWidth); |
|
98 Form->ui.pageOptions->windowHeightEdit->setText(wHeight); |
|
99 |
77 Form->ui.pageOptions->CBResolution->setCurrentIndex((t < 0) ? 1 : t); |
100 Form->ui.pageOptions->CBResolution->setCurrentIndex((t < 0) ? 1 : t); |
78 Form->ui.pageOptions->CBFullscreen->setChecked(value("video/fullscreen", false).toBool()); |
101 Form->ui.pageOptions->CBFullscreen->setChecked(value("video/fullscreen", false).toBool()); |
79 bool ffscr=value("frontend/fullscreen", false).toBool(); |
102 bool ffscr=value("frontend/fullscreen", false).toBool(); |
80 Form->ui.pageOptions->CBFrontendFullscreen->setChecked(ffscr); |
103 Form->ui.pageOptions->CBFrontendFullscreen->setChecked(ffscr); |
81 |
104 |
84 Form->ui.pageOptions->CBFrontendEffects->setChecked(value("frontend/effects", true).toBool()); |
107 Form->ui.pageOptions->CBFrontendEffects->setChecked(value("frontend/effects", true).toBool()); |
85 Form->ui.pageOptions->CBSound->setChecked(value("audio/sound", true).toBool()); |
108 Form->ui.pageOptions->CBSound->setChecked(value("audio/sound", true).toBool()); |
86 Form->ui.pageOptions->CBFrontendSound->setChecked(value("frontend/sound", true).toBool()); |
109 Form->ui.pageOptions->CBFrontendSound->setChecked(value("frontend/sound", true).toBool()); |
87 Form->ui.pageOptions->CBMusic->setChecked(value("audio/music", true).toBool()); |
110 Form->ui.pageOptions->CBMusic->setChecked(value("audio/music", true).toBool()); |
88 Form->ui.pageOptions->CBFrontendMusic->setChecked(value("frontend/music", true).toBool()); |
111 Form->ui.pageOptions->CBFrontendMusic->setChecked(value("frontend/music", true).toBool()); |
89 Form->ui.pageOptions->volumeBox->setValue(value("audio/volume", 100).toUInt()); |
112 Form->ui.pageOptions->SLVolume->setValue(value("audio/volume", 100).toUInt()); |
90 |
113 |
91 QString netNick = value("net/nick", "").toString(); |
114 QString netNick = value("net/nick", "").toString(); |
92 Form->ui.pageOptions->editNetNick->setText(netNick); |
115 Form->ui.pageOptions->editNetNick->setText(netNick); |
93 bool savePwd = value("net/savepassword",true).toBool(); |
116 bool savePwd = value("net/savepassword",true).toBool(); |
94 Form->ui.pageOptions->CBSavePassword->setChecked(savePwd); |
117 Form->ui.pageOptions->CBSavePassword->setChecked(savePwd); |
131 Form->ui.pageOptions->leProxyPassword->setText(value("proxy/password", "").toString()); |
154 Form->ui.pageOptions->leProxyPassword->setText(value("proxy/password", "").toString()); |
132 |
155 |
133 { // load colors |
156 { // load colors |
134 QStandardItemModel * model = DataManager::instance().colorsModel(); |
157 QStandardItemModel * model = DataManager::instance().colorsModel(); |
135 for(int i = model->rowCount() - 1; i >= 0; --i) |
158 for(int i = model->rowCount() - 1; i >= 0; --i) |
136 model->item(i)->setData(QColor(value(QString("colors/color%1").arg(i), model->item(i)->data().value<QColor>()).value<QColor>())); |
159 model->item(i)->setData(value(QString("colors/color%1").arg(i), model->item(i)->data())); |
|
160 } |
|
161 |
|
162 { // load binds |
|
163 for(int i = 0; i < BINDS_NUMBER; i++) |
|
164 { |
|
165 m_binds[i].strbind = value(QString("Binds/%1").arg(m_binds[i].action), cbinds[i].strbind).toString(); |
|
166 if (m_binds[i].strbind.isEmpty() || m_binds[i].strbind == "default") m_binds[i].strbind = cbinds[i].strbind; |
|
167 } |
137 } |
168 } |
138 } |
169 } |
139 |
170 |
140 void GameUIConfig::reloadVideosValues(void) |
171 void GameUIConfig::reloadVideosValues(void) |
141 { |
172 { |
197 Form->move(center); |
228 Form->move(center); |
198 } |
229 } |
199 |
230 |
200 void GameUIConfig::SaveOptions() |
231 void GameUIConfig::SaveOptions() |
201 { |
232 { |
202 setValue("video/resolution", Form->ui.pageOptions->CBResolution->currentText()); |
233 setValue("video/fullscreenResolution", Form->ui.pageOptions->CBResolution->currentText()); |
|
234 setValue("video/windowedWidth", Form->ui.pageOptions->windowWidthEdit->text()); |
|
235 setValue("video/windowedHeight", Form->ui.pageOptions->windowHeightEdit->text()); |
203 setValue("video/fullscreen", vid_Fullscreen()); |
236 setValue("video/fullscreen", vid_Fullscreen()); |
204 |
237 |
205 setValue("video/quality", Form->ui.pageOptions->SLQuality->value()); |
238 setValue("video/quality", Form->ui.pageOptions->SLQuality->value()); |
206 setValue("video/stereo", stereoMode()); |
239 setValue("video/stereo", stereoMode()); |
207 |
240 |
224 |
257 |
225 setValue("audio/sound", isSoundEnabled()); |
258 setValue("audio/sound", isSoundEnabled()); |
226 setValue("frontend/sound", isFrontendSoundEnabled()); |
259 setValue("frontend/sound", isFrontendSoundEnabled()); |
227 setValue("audio/music", isMusicEnabled()); |
260 setValue("audio/music", isMusicEnabled()); |
228 setValue("frontend/music", isFrontendMusicEnabled()); |
261 setValue("frontend/music", isFrontendMusicEnabled()); |
229 setValue("audio/volume", Form->ui.pageOptions->volumeBox->value()); |
262 setValue("audio/volume", Form->ui.pageOptions->SLVolume->value()); |
230 |
263 |
231 setValue("net/nick", netNick()); |
264 setValue("net/nick", netNick()); |
232 if (netPasswordIsValid() && Form->ui.pageOptions->CBSavePassword->isChecked()) { |
265 if (netPasswordIsValid() && Form->ui.pageOptions->CBSavePassword->isChecked()) { |
233 setPasswordHash(netPasswordHash()); |
266 setPasswordHash(netPasswordHash()); |
234 } |
267 } |
235 else if(!Form->ui.pageOptions->CBSavePassword->isChecked()) { |
268 else if(!Form->ui.pageOptions->CBSavePassword->isChecked()) { |
236 clearPasswordHash(); |
269 clearPasswordHash(); |
237 } |
270 } |
238 |
271 |
317 QString GameUIConfig::language() |
350 QString GameUIConfig::language() |
318 { |
351 { |
319 return Form->ui.pageOptions->CBLanguage->itemData(Form->ui.pageOptions->CBLanguage->currentIndex()).toString(); |
352 return Form->ui.pageOptions->CBLanguage->itemData(Form->ui.pageOptions->CBLanguage->currentIndex()).toString(); |
320 } |
353 } |
321 |
354 |
322 QRect GameUIConfig::vid_Resolution() |
355 std::pair<QRect, QRect> GameUIConfig::vid_ResolutionPair() { |
323 { |
356 // returns a pair of both the fullscreen and the windowed resolution |
324 QRect result(0, 0, 640, 480); |
357 QRect full(0, 0, 640, 480); |
|
358 QRect windowed(0, 0, 640, 480); |
325 QStringList wh = Form->ui.pageOptions->CBResolution->currentText().split('x'); |
359 QStringList wh = Form->ui.pageOptions->CBResolution->currentText().split('x'); |
326 if (wh.size() == 2) |
360 if (wh.size() == 2) |
327 { |
361 { |
328 result.setWidth(wh[0].toInt()); |
362 full.setWidth(wh[0].toInt()); |
329 result.setHeight(wh[1].toInt()); |
363 full.setHeight(wh[1].toInt()); |
330 } |
364 } |
331 return result; |
365 windowed.setWidth(Form->ui.pageOptions->windowWidthEdit->text().toInt()); |
|
366 windowed.setHeight(Form->ui.pageOptions->windowHeightEdit->text().toInt()); |
|
367 return std::make_pair(full, windowed); |
|
368 } |
|
369 |
|
370 QRect GameUIConfig::vid_Resolution() |
|
371 { |
|
372 std::pair<QRect, QRect> result = vid_ResolutionPair(); |
|
373 if(Form->ui.pageOptions->CBFullscreen->isChecked()) |
|
374 return result.first; |
|
375 else |
|
376 return result.second; |
332 } |
377 } |
333 |
378 |
334 bool GameUIConfig::vid_Fullscreen() |
379 bool GameUIConfig::vid_Fullscreen() |
335 { |
380 { |
336 return Form->ui.pageOptions->CBFullscreen->isChecked(); |
381 return Form->ui.pageOptions->CBFullscreen->isChecked(); |
579 |
624 |
580 bool GameUIConfig::recordAudio() |
625 bool GameUIConfig::recordAudio() |
581 { |
626 { |
582 return Form->ui.pageOptions->checkRecordAudio->isChecked(); |
627 return Form->ui.pageOptions->checkRecordAudio->isChecked(); |
583 } |
628 } |
|
629 |
|
630 // Gets a bind for a bindID |
|
631 QString GameUIConfig::bind(int bindID) |
|
632 { |
|
633 return m_binds[bindID].strbind; |
|
634 } |
|
635 |
|
636 // Sets a bind for a bindID and saves it |
|
637 void GameUIConfig::setBind(int bindID, QString & strbind) |
|
638 { |
|
639 m_binds[bindID].strbind = strbind; |
|
640 setValue(QString("Binds/%1").arg(m_binds[bindID].action), strbind); |
|
641 } |