28 #include "pages.h" |
28 #include "pages.h" |
29 #include "hwconsts.h" |
29 #include "hwconsts.h" |
30 #include "fpsedit.h" |
30 #include "fpsedit.h" |
31 |
31 |
32 GameUIConfig::GameUIConfig(HWForm * FormWidgets, const QString & fileName) |
32 GameUIConfig::GameUIConfig(HWForm * FormWidgets, const QString & fileName) |
33 : QSettings(fileName, QSettings::IniFormat) |
33 : QSettings(fileName, QSettings::IniFormat) |
34 { |
34 { |
35 Form = FormWidgets; |
35 Form = FormWidgets; |
36 |
36 |
37 connect(Form->ui.pageOptions->CBEnableFrontendMusic, SIGNAL(toggled(bool)), Form, SLOT(Music(bool))); |
37 connect(Form->ui.pageOptions->CBEnableFrontendMusic, SIGNAL(toggled(bool)), Form, SLOT(Music(bool))); |
38 |
38 |
39 //Form->resize(value("window/width", 640).toUInt(), value("window/height", 450).toUInt()); |
39 //Form->resize(value("window/width", 640).toUInt(), value("window/height", 450).toUInt()); |
40 resizeToConfigValues(); |
40 resizeToConfigValues(); |
41 |
41 |
42 Form->ui.pageOptions->WeaponTooltip->setChecked(value("misc/weaponTooltip", true).toBool()); |
42 Form->ui.pageOptions->WeaponTooltip->setChecked(value("misc/weaponTooltip", true).toBool()); |
43 |
43 |
44 int t = Form->ui.pageOptions->CBResolution->findText(value("video/resolution").toString()); |
44 int t = Form->ui.pageOptions->CBResolution->findText(value("video/resolution").toString()); |
45 Form->ui.pageOptions->CBResolution->setCurrentIndex((t < 0) ? 0 : t); |
45 Form->ui.pageOptions->CBResolution->setCurrentIndex((t < 0) ? 0 : t); |
46 Form->ui.pageOptions->CBFullscreen->setChecked(value("video/fullscreen", false).toBool()); |
46 Form->ui.pageOptions->CBFullscreen->setChecked(value("video/fullscreen", false).toBool()); |
47 bool ffscr=value("video/frontendfullscreen", false).toBool(); |
47 bool ffscr=value("video/frontendfullscreen", false).toBool(); |
48 Form->ui.pageOptions->CBFrontendFullscreen->setChecked(ffscr); |
48 Form->ui.pageOptions->CBFrontendFullscreen->setChecked(ffscr); |
49 |
49 |
50 Form->ui.pageOptions->CBReduceQuality->setChecked(value("video/reducequality", false).toBool()); |
50 Form->ui.pageOptions->CBReduceQuality->setChecked(value("video/reducequality", false).toBool()); |
51 Form->ui.pageOptions->CBFrontendEffects->setChecked(frontendEffects); |
51 Form->ui.pageOptions->CBFrontendEffects->setChecked(frontendEffects); |
52 Form->ui.pageOptions->CBEnableSound->setChecked(value("audio/sound", true).toBool()); |
52 Form->ui.pageOptions->CBEnableSound->setChecked(value("audio/sound", true).toBool()); |
53 Form->ui.pageOptions->CBEnableFrontendSound->setChecked(value("audio/frontendsound", true).toBool()); |
53 Form->ui.pageOptions->CBEnableFrontendSound->setChecked(value("audio/frontendsound", true).toBool()); |
54 #ifdef _WIN32 |
54 #ifdef _WIN32 |
55 // Form->ui.pageOptions->CBHardwareSound->setChecked(value("audio/hardware", false).toBool()); |
55 // Form->ui.pageOptions->CBHardwareSound->setChecked(value("audio/hardware", false).toBool()); |
56 #endif |
56 #endif |
57 Form->ui.pageOptions->CBEnableMusic->setChecked(value("audio/music", true).toBool()); |
57 Form->ui.pageOptions->CBEnableMusic->setChecked(value("audio/music", true).toBool()); |
58 Form->ui.pageOptions->CBEnableFrontendMusic->setChecked(value("audio/frontendmusic", true).toBool()); |
58 Form->ui.pageOptions->CBEnableFrontendMusic->setChecked(value("audio/frontendmusic", true).toBool()); |
59 Form->ui.pageOptions->volumeBox->setValue(value("audio/volume", 100).toUInt()); |
59 Form->ui.pageOptions->volumeBox->setValue(value("audio/volume", 100).toUInt()); |
60 |
60 |
61 QString netNick = value("net/nick", "").toString(); |
61 QString netNick = value("net/nick", "").toString(); |
62 if (netNick.isEmpty()) |
62 if (netNick.isEmpty()) |
63 netNick = QInputDialog::getText(Form, |
63 netNick = QInputDialog::getText(Form, |
64 QObject::tr("Nickname"), |
64 QObject::tr("Nickname"), |
65 QObject::tr("Please enter your nickname"), |
65 QObject::tr("Please enter your nickname"), |
66 QLineEdit::Normal, |
66 QLineEdit::Normal, |
67 QDir::home().dirName()); |
67 QDir::home().dirName()); |
68 |
68 |
69 Form->ui.pageOptions->editNetNick->setText(netNick); |
69 Form->ui.pageOptions->editNetNick->setText(netNick); |
70 |
70 |
71 delete netHost; |
71 delete netHost; |
72 netHost = new QString(value("net/ip", "").toString()); |
72 netHost = new QString(value("net/ip", "").toString()); |
73 netPort = value("net/port", 46631).toUInt(); |
73 netPort = value("net/port", 46631).toUInt(); |
74 |
74 |
75 Form->ui.pageNetServer->leServerDescr->setText(value("net/servername", "hedgewars server").toString()); |
75 Form->ui.pageNetServer->leServerDescr->setText(value("net/servername", "hedgewars server").toString()); |
76 Form->ui.pageNetServer->sbPort->setValue(value("net/serverport", 46631).toUInt()); |
76 Form->ui.pageNetServer->sbPort->setValue(value("net/serverport", 46631).toUInt()); |
77 |
77 |
78 Form->ui.pageOptions->CBShowFPS->setChecked(value("fps/show", false).toBool()); |
78 Form->ui.pageOptions->CBShowFPS->setChecked(value("fps/show", false).toBool()); |
79 Form->ui.pageOptions->fpsedit->setValue(value("fps/interval", 27).toUInt()); |
79 Form->ui.pageOptions->fpsedit->setValue(value("fps/interval", 27).toUInt()); |
80 |
80 |
81 Form->ui.pageOptions->CBAltDamage->setChecked(value("misc/altdamage", false).toBool()); |
81 Form->ui.pageOptions->CBAltDamage->setChecked(value("misc/altdamage", false).toBool()); |
82 Form->ui.pageOptions->CBNameWithDate->setChecked(value("misc/appendTimeToRecords", false).toBool()); |
82 Form->ui.pageOptions->CBNameWithDate->setChecked(value("misc/appendTimeToRecords", false).toBool()); |
83 |
83 |
84 #ifdef SPARKLE_ENABLED |
84 #ifdef SPARKLE_ENABLED |
85 Form->ui.pageOptions->CBAutoUpdate->setChecked(value("misc/autoUpdate", true).toBool()); |
85 Form->ui.pageOptions->CBAutoUpdate->setChecked(value("misc/autoUpdate", true).toBool()); |
86 #endif |
86 #endif |
87 |
87 |
88 Form->ui.pageOptions->CBLanguage->setCurrentIndex(Form->ui.pageOptions->CBLanguage->findData(value("misc/locale", "").toString())); |
88 Form->ui.pageOptions->CBLanguage->setCurrentIndex(Form->ui.pageOptions->CBLanguage->findData(value("misc/locale", "").toString())); |
89 |
89 |
90 depth = QApplication::desktop()->depth(); |
90 depth = QApplication::desktop()->depth(); |
91 if (depth < 16) depth = 16; |
91 if (depth < 16) depth = 16; |
92 else if (depth > 16) depth = 32; |
92 else if (depth > 16) depth = 32; |
93 } |
93 } |
94 |
94 |
95 QStringList GameUIConfig::GetTeamsList() |
95 QStringList GameUIConfig::GetTeamsList() |
96 { |
96 { |
97 QStringList teamslist = cfgdir->entryList(QStringList("*.cfg")); |
97 QStringList teamslist = cfgdir->entryList(QStringList("*.cfg")); |
98 QStringList cleanedList; |
98 QStringList cleanedList; |
99 for (QStringList::Iterator it = teamslist.begin(); it != teamslist.end(); ++it ) { |
99 for (QStringList::Iterator it = teamslist.begin(); it != teamslist.end(); ++it ) { |
100 QString tmpTeamStr=(*it).replace(QRegExp("^(.*)\\.cfg$"), "\\1"); |
100 QString tmpTeamStr=(*it).replace(QRegExp("^(.*)\\.cfg$"), "\\1"); |
101 cleanedList.push_back(tmpTeamStr); |
101 cleanedList.push_back(tmpTeamStr); |
102 } |
102 } |
103 return cleanedList; |
103 return cleanedList; |
104 } |
104 } |
105 |
105 |
106 void GameUIConfig::resizeToConfigValues() |
106 void GameUIConfig::resizeToConfigValues() |
107 { |
107 { |
108 Form->resize(value("window/width", 720).toUInt(), value("window/height", 450).toUInt()); |
108 Form->resize(value("window/width", 720).toUInt(), value("window/height", 450).toUInt()); |
109 } |
109 } |
110 |
110 |
111 void GameUIConfig::SaveOptions() |
111 void GameUIConfig::SaveOptions() |
112 { |
112 { |
113 setValue("video/resolution", Form->ui.pageOptions->CBResolution->currentText()); |
113 setValue("video/resolution", Form->ui.pageOptions->CBResolution->currentText()); |
114 setValue("video/fullscreen", vid_Fullscreen()); |
114 setValue("video/fullscreen", vid_Fullscreen()); |
115 |
115 |
116 setValue("video/reducequality", isReducedQuality()); |
116 setValue("video/reducequality", isReducedQuality()); |
117 |
117 |
118 setValue("video/frontendeffects", isFrontendEffects()); |
118 setValue("video/frontendeffects", isFrontendEffects()); |
119 |
119 |
120 setValue("misc/weaponTooltip", isWeaponTooltip()); |
120 setValue("misc/weaponTooltip", isWeaponTooltip()); |
121 |
121 |
122 bool ffscr = isFrontendFullscreen(); |
122 bool ffscr = isFrontendFullscreen(); |
123 setValue("video/frontendfullscreen", ffscr); |
123 setValue("video/frontendfullscreen", ffscr); |
124 emit frontendFullscreen(ffscr); |
124 emit frontendFullscreen(ffscr); |
125 if (!ffscr) { |
125 if (!ffscr) { |
126 setValue("window/width", Form->width()); |
126 setValue("window/width", Form->width()); |
127 setValue("window/height", Form->height()); |
127 setValue("window/height", Form->height()); |
128 } else { |
128 } else { |
129 //resizeToConfigValues(); // TODO: why this has been made? |
129 //resizeToConfigValues(); // TODO: why this has been made? |
130 } |
130 } |
131 |
131 |
132 setValue("audio/sound", isSoundEnabled()); |
132 setValue("audio/sound", isSoundEnabled()); |
133 setValue("audio/frontendsound", isFrontendSoundEnabled()); |
133 setValue("audio/frontendsound", isFrontendSoundEnabled()); |
134 #ifdef _WIN32 |
134 #ifdef _WIN32 |
135 // setValue("audio/hardware", isSoundHardware()); |
135 // setValue("audio/hardware", isSoundHardware()); |
136 #endif |
136 #endif |
137 setValue("audio/music", isMusicEnabled()); |
137 setValue("audio/music", isMusicEnabled()); |
138 setValue("audio/frontendmusic", isFrontendMusicEnabled()); |
138 setValue("audio/frontendmusic", isFrontendMusicEnabled()); |
139 setValue("audio/volume", Form->ui.pageOptions->volumeBox->value()); |
139 setValue("audio/volume", Form->ui.pageOptions->volumeBox->value()); |
140 |
140 |
141 setValue("net/nick", netNick()); |
141 setValue("net/nick", netNick()); |
142 setValue("net/ip", *netHost); |
142 setValue("net/ip", *netHost); |
143 setValue("net/port", netPort); |
143 setValue("net/port", netPort); |
144 setValue("net/servername", Form->ui.pageNetServer->leServerDescr->text()); |
144 setValue("net/servername", Form->ui.pageNetServer->leServerDescr->text()); |
145 setValue("net/serverport", Form->ui.pageNetServer->sbPort->value()); |
145 setValue("net/serverport", Form->ui.pageNetServer->sbPort->value()); |
146 |
146 |
147 setValue("fps/show", isShowFPSEnabled()); |
147 setValue("fps/show", isShowFPSEnabled()); |
148 setValue("fps/interval", Form->ui.pageOptions->fpsedit->value()); |
148 setValue("fps/interval", Form->ui.pageOptions->fpsedit->value()); |
149 |
149 |
150 setValue("misc/altdamage", isAltDamageEnabled()); |
150 setValue("misc/altdamage", isAltDamageEnabled()); |
151 setValue("misc/appendTimeToRecords", appendDateTimeToRecordName()); |
151 setValue("misc/appendTimeToRecords", appendDateTimeToRecordName()); |
152 setValue("misc/locale", language()); |
152 setValue("misc/locale", language()); |
153 |
153 |
154 #ifdef SPARKLE_ENABLED |
154 #ifdef SPARKLE_ENABLED |
155 setValue("misc/autoUpdate", isAutoUpdateEnabled()); |
155 setValue("misc/autoUpdate", isAutoUpdateEnabled()); |
156 #endif |
156 #endif |
157 Form->gameSettings->sync(); |
157 Form->gameSettings->sync(); |
158 } |
158 } |
159 |
159 |
160 QString GameUIConfig::language() |
160 QString GameUIConfig::language() |
161 { |
161 { |
162 return Form->ui.pageOptions->CBLanguage->itemData(Form->ui.pageOptions->CBLanguage->currentIndex()).toString(); |
162 return Form->ui.pageOptions->CBLanguage->itemData(Form->ui.pageOptions->CBLanguage->currentIndex()).toString(); |
163 } |
163 } |
164 |
164 |
165 QRect GameUIConfig::vid_Resolution() |
165 QRect GameUIConfig::vid_Resolution() |
166 { |
166 { |
167 QRect result(0, 0, 640, 480); |
167 QRect result(0, 0, 640, 480); |
168 QStringList wh = Form->ui.pageOptions->CBResolution->currentText().split('x'); |
168 QStringList wh = Form->ui.pageOptions->CBResolution->currentText().split('x'); |
169 if (wh.size() == 2) |
169 if (wh.size() == 2) |
170 { |
170 { |
171 result.setWidth(wh[0].toInt()); |
171 result.setWidth(wh[0].toInt()); |
172 result.setHeight(wh[1].toInt()); |
172 result.setHeight(wh[1].toInt()); |
173 } |
173 } |
174 return result; |
174 return result; |
175 } |
175 } |
176 |
176 |
177 bool GameUIConfig::vid_Fullscreen() |
177 bool GameUIConfig::vid_Fullscreen() |
178 { |
178 { |
179 return Form->ui.pageOptions->CBFullscreen->isChecked(); |
179 return Form->ui.pageOptions->CBFullscreen->isChecked(); |
180 } |
180 } |
181 |
181 |
182 bool GameUIConfig::isReducedQuality() const |
182 bool GameUIConfig::isReducedQuality() const |
183 { |
183 { |
184 return Form->ui.pageOptions->CBReduceQuality->isChecked(); |
184 return Form->ui.pageOptions->CBReduceQuality->isChecked(); |