QTfrontend/gameuiconfig.cpp
changeset 2948 3f21a9dc93d0
parent 2913 865ae941d59e
child 3019 d6e19f35d98d
equal deleted inserted replaced
2947:803b277e4894 2948:3f21a9dc93d0
    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();
   198   return Form->ui.pageOptions->CBFrontendFullscreen->isChecked();
   198   return Form->ui.pageOptions->CBFrontendFullscreen->isChecked();
   199 }
   199 }
   200 
   200 
   201 bool GameUIConfig::isSoundEnabled()
   201 bool GameUIConfig::isSoundEnabled()
   202 {
   202 {
   203 	return Form->ui.pageOptions->CBEnableSound->isChecked();
   203     return Form->ui.pageOptions->CBEnableSound->isChecked();
   204 }
   204 }
   205 bool GameUIConfig::isFrontendSoundEnabled()
   205 bool GameUIConfig::isFrontendSoundEnabled()
   206 {
   206 {
   207 	return Form->ui.pageOptions->CBEnableFrontendSound->isChecked();
   207     return Form->ui.pageOptions->CBEnableFrontendSound->isChecked();
   208 }
   208 }
   209 
   209 
   210 #ifdef _WIN32
   210 #ifdef _WIN32
   211 bool GameUIConfig::isSoundHardware()
   211 bool GameUIConfig::isSoundHardware()
   212 {
   212 {
   213 //	return Form->ui.pageOptions->CBHardwareSound->isChecked();
   213 //  return Form->ui.pageOptions->CBHardwareSound->isChecked();
   214 return false;
   214 return false;
   215 }
   215 }
   216 #endif
   216 #endif
   217 
   217 
   218 bool GameUIConfig::isMusicEnabled()
   218 bool GameUIConfig::isMusicEnabled()
   219 {
   219 {
   220 	return Form->ui.pageOptions->CBEnableMusic->isChecked();
   220     return Form->ui.pageOptions->CBEnableMusic->isChecked();
   221 }
   221 }
   222 bool GameUIConfig::isFrontendMusicEnabled()
   222 bool GameUIConfig::isFrontendMusicEnabled()
   223 {
   223 {
   224 	return Form->ui.pageOptions->CBEnableFrontendMusic->isChecked();
   224     return Form->ui.pageOptions->CBEnableFrontendMusic->isChecked();
   225 }
   225 }
   226 
   226 
   227 bool GameUIConfig::isShowFPSEnabled()
   227 bool GameUIConfig::isShowFPSEnabled()
   228 {
   228 {
   229 	return Form->ui.pageOptions->CBShowFPS->isChecked();
   229     return Form->ui.pageOptions->CBShowFPS->isChecked();
   230 }
   230 }
   231 
   231 
   232 bool GameUIConfig::isAltDamageEnabled()
   232 bool GameUIConfig::isAltDamageEnabled()
   233 {
   233 {
   234 	return Form->ui.pageOptions->CBAltDamage->isChecked();
   234     return Form->ui.pageOptions->CBAltDamage->isChecked();
   235 }
   235 }
   236 
   236 
   237 bool GameUIConfig::appendDateTimeToRecordName()
   237 bool GameUIConfig::appendDateTimeToRecordName()
   238 {
   238 {
   239 	return Form->ui.pageOptions->CBNameWithDate->isChecked();
   239     return Form->ui.pageOptions->CBNameWithDate->isChecked();
   240 }
   240 }
   241 
   241 
   242 #ifdef SPARKLE_ENABLED
   242 #ifdef SPARKLE_ENABLED
   243 bool GameUIConfig::isAutoUpdateEnabled()
   243 bool GameUIConfig::isAutoUpdateEnabled()
   244 {
   244 {
   246 }
   246 }
   247 #endif
   247 #endif
   248 
   248 
   249 quint8 GameUIConfig::timerInterval()
   249 quint8 GameUIConfig::timerInterval()
   250 {
   250 {
   251 	return 35 - Form->ui.pageOptions->fpsedit->value();
   251     return 35 - Form->ui.pageOptions->fpsedit->value();
   252 }
   252 }
   253 
   253 
   254 quint8 GameUIConfig::bitDepth()
   254 quint8 GameUIConfig::bitDepth()
   255 {
   255 {
   256 	return depth;
   256     return depth;
   257 }
   257 }
   258 
   258 
   259 QString GameUIConfig::netNick()
   259 QString GameUIConfig::netNick()
   260 {
   260 {
   261 	return Form->ui.pageOptions->editNetNick->text();
   261     return Form->ui.pageOptions->editNetNick->text();
   262 }
   262 }
   263 
   263 
   264 quint8 GameUIConfig::volume()
   264 quint8 GameUIConfig::volume()
   265 {
   265 {
   266 	return Form->ui.pageOptions->volumeBox->value() * 128 / 100;
   266     return Form->ui.pageOptions->volumeBox->value() * 128 / 100;
   267 }
   267 }