QTfrontend/gamecfgwidget.cpp
changeset 1885 75489216b5b0
parent 1884 40e59e9f82ce
child 1887 d68939b3f7f0
equal deleted inserted replaced
1884:40e59e9f82ce 1885:75489216b5b0
    22 #include <QGridLayout>
    22 #include <QGridLayout>
    23 #include <QSpinBox>
    23 #include <QSpinBox>
    24 #include <QLabel>
    24 #include <QLabel>
    25 #include <QMessageBox>
    25 #include <QMessageBox>
    26 #include <QTableView>
    26 #include <QTableView>
       
    27 #include <QPushButton>
    27 
    28 
    28 #include "gamecfgwidget.h"
    29 #include "gamecfgwidget.h"
    29 #include "igbox.h"
    30 #include "igbox.h"
    30 #include "hwconsts.h"
    31 #include "hwconsts.h"
    31 #include "ammoSchemeModel.h"
    32 #include "ammoSchemeModel.h"
    46 	QGridLayout *GBoxOptionsLayout = new QGridLayout(GBoxOptions);
    47 	QGridLayout *GBoxOptionsLayout = new QGridLayout(GBoxOptions);
    47 
    48 
    48 	QTableView * tv = new QTableView(this);
    49 	QTableView * tv = new QTableView(this);
    49 	tv->setModel(new AmmoSchemeModel);
    50 	tv->setModel(new AmmoSchemeModel);
    50 	GBoxOptionsLayout->addWidget(tv, 0, 0, 1, 2);
    51 	GBoxOptionsLayout->addWidget(tv, 0, 0, 1, 2);
       
    52 
       
    53 	QPushButton * goToSchemePage = new QPushButton(GBoxOptions);
       
    54 	goToSchemePage->setText(tr("Edit schemes"));
       
    55 	GBoxOptionsLayout->addWidget(goToSchemePage, 1, 0, 1, 2);
       
    56 	connect(goToSchemePage, SIGNAL(clicked()), this, SIGNAL(goToSchemes()));
    51 	
    57 	
    52 	CB_mode_Forts = new QCheckBox(GBoxOptions);
       
    53 	CB_mode_Forts->setText(QCheckBox::tr("Forts mode"));
       
    54 	GBoxOptionsLayout->addWidget(CB_mode_Forts, 9, 0, 1, 2);
       
    55 
       
    56 	CB_teamsDivide = new QCheckBox(GBoxOptions);
       
    57 	CB_teamsDivide->setText(QCheckBox::tr("Divide teams"));
       
    58 	GBoxOptionsLayout->addWidget(CB_teamsDivide, 1, 0, 1, 2);
       
    59 
       
    60 	CB_solid = new QCheckBox(GBoxOptions);
       
    61 	CB_solid->setText(QCheckBox::tr("Solid land"));
       
    62 	GBoxOptionsLayout->addWidget(CB_solid, 2, 0, 1, 2);
       
    63 
       
    64 	CB_border = new QCheckBox(GBoxOptions);
       
    65 	CB_border->setText(QCheckBox::tr("Add Border"));
       
    66 	GBoxOptionsLayout->addWidget(CB_border, 3, 0, 1, 2);
       
    67 
       
    68 	L_TurnTime = new QLabel(QLabel::tr("Turn time"), GBoxOptions);
       
    69 	L_InitHealth = new QLabel(QLabel::tr("Initial health"), GBoxOptions);
       
    70 	L_SuddenDeath = new QLabel(QLabel::tr("Turns before SD"), GBoxOptions);
       
    71 	L_CaseProb = new QLabel(QLabel::tr("Crate drops"), GBoxOptions);
       
    72 	GBoxOptionsLayout->addWidget(L_TurnTime, 4, 0);
       
    73 	GBoxOptionsLayout->addWidget(L_InitHealth, 5, 0);
       
    74 	GBoxOptionsLayout->addWidget(L_SuddenDeath, 6, 0);
       
    75 	GBoxOptionsLayout->addWidget(L_CaseProb, 7, 0);
       
    76 	GBoxOptionsLayout->addWidget(new QLabel(QLabel::tr("Weapons"), GBoxOptions), 8, 0);
    58 	GBoxOptionsLayout->addWidget(new QLabel(QLabel::tr("Weapons"), GBoxOptions), 8, 0);
    77 
    59 
    78 	SB_TurnTime = new QSpinBox(GBoxOptions);
       
    79 	SB_TurnTime->setRange(1, 99);
       
    80 	SB_TurnTime->setValue(45);
       
    81 	SB_TurnTime->setSingleStep(15);
       
    82 	
       
    83 	SB_InitHealth = new QSpinBox(GBoxOptions);
       
    84 	SB_InitHealth->setRange(50, 200);
       
    85 	SB_InitHealth->setValue(100);
       
    86 	SB_InitHealth->setSingleStep(25);
       
    87 	
       
    88 	SB_SuddenDeath = new QSpinBox(GBoxOptions);
       
    89 	SB_SuddenDeath->setRange(0, 50);
       
    90 	SB_SuddenDeath->setValue(15);
       
    91 	SB_SuddenDeath->setSingleStep(3);
       
    92 	
       
    93 	SB_CaseProb = new FreqSpinBox(GBoxOptions);
       
    94 	SB_CaseProb->setRange(0, 9);
       
    95 	SB_CaseProb->setValue(5);
       
    96 
       
    97 	GBoxOptionsLayout->addWidget(SB_TurnTime, 4, 1);
       
    98 	GBoxOptionsLayout->addWidget(SB_InitHealth, 5, 1);
       
    99 	GBoxOptionsLayout->addWidget(SB_SuddenDeath, 6, 1);
       
   100 	GBoxOptionsLayout->addWidget(SB_CaseProb, 7, 1);
       
   101 	
       
   102 	WeaponsName = new QComboBox(GBoxOptions);
    60 	WeaponsName = new QComboBox(GBoxOptions);
   103 	GBoxOptionsLayout->addWidget(WeaponsName, 8, 1);
    61 	GBoxOptionsLayout->addWidget(WeaponsName, 8, 1);
   104 	
    62 	
   105 	connect(SB_InitHealth, SIGNAL(valueChanged(int)), this, SLOT(initHealthChanged(int)));
       
   106 	connect(SB_TurnTime, SIGNAL(valueChanged(int)), this, SLOT(turnTimeChanged(int)));
       
   107 	connect(SB_SuddenDeath, SIGNAL(valueChanged(int)), this, SLOT(suddenDeathTurnsChanged(int)));
       
   108 	connect(SB_CaseProb, SIGNAL(valueChanged(int)), this, SLOT(caseProbabilityChanged(int)));
       
   109 	connect(CB_mode_Forts, SIGNAL(toggled(bool)), this, SLOT(fortsModeChanged(bool)));
       
   110 	connect(CB_teamsDivide, SIGNAL(toggled(bool)), this, SLOT(teamsDivideChanged(bool)));
       
   111 	connect(CB_solid, SIGNAL(toggled(bool)), this, SLOT(solidChanged(bool)));
       
   112 	connect(CB_border, SIGNAL(toggled(bool)), this, SLOT(borderChanged(bool)));
       
   113 	connect(WeaponsName, SIGNAL(currentIndexChanged(int)), this, SLOT(ammoChanged(int)));
    63 	connect(WeaponsName, SIGNAL(currentIndexChanged(int)), this, SLOT(ammoChanged(int)));
   114 
    64 
   115 	connect(pMapContainer, SIGNAL(seedChanged(const QString &)), this, SLOT(seedChanged(const QString &)));
    65 	connect(pMapContainer, SIGNAL(seedChanged(const QString &)), this, SLOT(seedChanged(const QString &)));
   116 	connect(pMapContainer, SIGNAL(mapChanged(const QString &)), this, SLOT(mapChanged(const QString &)));
    66 	connect(pMapContainer, SIGNAL(mapChanged(const QString &)), this, SLOT(mapChanged(const QString &)));
   117 	connect(pMapContainer, SIGNAL(themeChanged(const QString &)), this, SLOT(themeChanged(const QString &)));
    67 	connect(pMapContainer, SIGNAL(themeChanged(const QString &)), this, SLOT(themeChanged(const QString &)));
   120 
    70 
   121 quint32 GameCFGWidget::getGameFlags() const
    71 quint32 GameCFGWidget::getGameFlags() const
   122 {
    72 {
   123 	quint32 result = 0;
    73 	quint32 result = 0;
   124 
    74 
   125 	if (CB_mode_Forts->isChecked())
    75 /*	if (CB_mode_Forts->isChecked())
   126 		result |= 0x01;
    76 		result |= 0x01;
   127 	if (CB_teamsDivide->isChecked())
    77 	if (CB_teamsDivide->isChecked())
   128 		result |= 0x10;
    78 		result |= 0x10;
   129 	if (CB_solid->isChecked())
    79 	if (CB_solid->isChecked())
   130 		result |= 0x04;
    80 		result |= 0x04;
   131 	if (CB_border->isChecked())
    81 	if (CB_border->isChecked())
   132 		result |= 0x08;
    82 		result |= 0x08;*/
   133 
    83 
   134 	return result;
    84 	return result;
   135 }
    85 }
   136 
    86 
   137 quint32 GameCFGWidget::getInitHealth() const
    87 quint32 GameCFGWidget::getInitHealth() const
   138 {
    88 {
   139 	return SB_InitHealth->value();
    89 //	return SB_InitHealth->value();
   140 }
    90 }
   141 
    91 
   142 QStringList GameCFGWidget::getFullConfig() const
    92 QStringList GameCFGWidget::getFullConfig() const
   143 {
    93 {
   144 	QStringList sl;
    94 	QStringList sl;
   145 	sl.append("eseed " + pMapContainer->getCurrentSeed());
    95 	sl.append("eseed " + pMapContainer->getCurrentSeed());
   146 	sl.append(QString("e$gmflags %1").arg(getGameFlags()));
    96 	sl.append(QString("e$gmflags %1").arg(getGameFlags()));
   147 	sl.append(QString("e$turntime %1").arg(SB_TurnTime->value() * 1000));
    97 //	sl.append(QString("e$turntime %1").arg(SB_TurnTime->value() * 1000));
   148 	sl.append(QString("e$sd_turns %1").arg(SB_SuddenDeath->value()));
    98 //	sl.append(QString("e$sd_turns %1").arg(SB_SuddenDeath->value()));
   149 	sl.append(QString("e$casefreq %1").arg(SB_CaseProb->value()));
    99 //	sl.append(QString("e$casefreq %1").arg(SB_CaseProb->value()));
   150 	sl.append(QString("e$template_filter %1").arg(pMapContainer->getTemplateFilter()));
   100 	sl.append(QString("e$template_filter %1").arg(pMapContainer->getTemplateFilter()));
   151 
   101 
   152 	QString currentMap = pMapContainer->getCurrentMap();
   102 	QString currentMap = pMapContainer->getCurrentMap();
   153 	if (currentMap.size() > 0)
   103 	if (currentMap.size() > 0)
   154 		sl.append("emap " + currentMap);
   104 		sl.append("emap " + currentMap);
   173 
   123 
   174 void GameCFGWidget::fullNetConfig()
   124 void GameCFGWidget::fullNetConfig()
   175 {
   125 {
   176 	ammoChanged(WeaponsName->currentIndex());
   126 	ammoChanged(WeaponsName->currentIndex());
   177 	
   127 	
   178 	borderChanged(CB_border->isChecked());
       
   179 	caseProbabilityChanged(SB_CaseProb->value());
       
   180 	fortsModeChanged(CB_mode_Forts->isChecked());
       
   181 	initHealthChanged(SB_InitHealth->value());
       
   182 	seedChanged(pMapContainer->getCurrentSeed());
   128 	seedChanged(pMapContainer->getCurrentSeed());
   183 	solidChanged(CB_solid->isChecked());
       
   184 	suddenDeathTurnsChanged(SB_SuddenDeath->value());
       
   185 	teamsDivideChanged(CB_teamsDivide->isChecked());
       
   186 	templateFilterChanged(pMapContainer->getTemplateFilter());
   129 	templateFilterChanged(pMapContainer->getTemplateFilter());
   187 	themeChanged(pMapContainer->getCurrentTheme());
   130 	themeChanged(pMapContainer->getCurrentTheme());
   188 	turnTimeChanged(SB_TurnTime->value());
       
   189 
   131 
   190 	// map must be the last
   132 	// map must be the last
   191 	QString map = pMapContainer->getCurrentMap();
   133 	QString map = pMapContainer->getCurrentMap();
   192 	if (map.size())
   134 	if (map.size())
   193 		mapChanged(map);
   135 		mapChanged(map);
   209 		if (param == "THEME") {
   151 		if (param == "THEME") {
   210 			pMapContainer->setTheme(value);
   152 			pMapContainer->setTheme(value);
   211 			return;
   153 			return;
   212 		}
   154 		}
   213 		if (param == "HEALTH") {
   155 		if (param == "HEALTH") {
   214 			SB_InitHealth->setValue(value.toUInt());
   156 //			SB_InitHealth->setValue(value.toUInt());
   215 			return;
   157 			return;
   216 		}
   158 		}
   217 		if (param == "TURNTIME") {
   159 		if (param == "TURNTIME") {
   218 			SB_TurnTime->setValue(value.toUInt());
   160 //			SB_TurnTime->setValue(value.toUInt());
   219 			return;
   161 			return;
   220 		}
   162 		}
   221 		if (param == "SD_TURNS") {
   163 		if (param == "SD_TURNS") {
   222 			SB_SuddenDeath->setValue(value.toUInt());
   164 //			SB_SuddenDeath->setValue(value.toUInt());
   223 			return;
   165 			return;
   224 		}
   166 		}
   225 		if (param == "CASEFACTOR") {
   167 		if (param == "CASEFACTOR") {
   226 			SB_CaseProb->setValue(value.toUInt());
   168 //			SB_CaseProb->setValue(value.toUInt());
   227 			return;
   169 			return;
   228 		}
   170 		}
   229 		if (param == "FORTSMODE") {
   171 		if (param == "FORTSMODE") {
   230 			CB_mode_Forts->setChecked(value.toUInt() != 0);
   172 //			CB_mode_Forts->setChecked(value.toUInt() != 0);
   231 			return;
   173 			return;
   232 		}
   174 		}
   233 		if (param == "DIVIDETEAMS") {
   175 		if (param == "DIVIDETEAMS") {
   234 			CB_teamsDivide->setChecked(value.toUInt() != 0);
   176 //			CB_teamsDivide->setChecked(value.toUInt() != 0);
   235 			return;
   177 			return;
   236 		}
   178 		}
   237 		if (param == "SOLIDLAND") {
   179 		if (param == "SOLIDLAND") {
   238 			CB_solid->setChecked(value.toUInt() != 0);
   180 //			CB_solid->setChecked(value.toUInt() != 0);
   239 			return;
   181 			return;
   240 		}
   182 		}
   241 		if (param == "BORDER") {
   183 		if (param == "BORDER") {
   242 			CB_border->setChecked(value.toUInt() != 0);
   184 //			CB_border->setChecked(value.toUInt() != 0);
   243 			return;
   185 			return;
   244 		}
   186 		}
   245 		if (param == "TEMPLATE") {
   187 		if (param == "TEMPLATE") {
   246 			pMapContainer->setTemplateFilter(value.toUInt());
   188 			pMapContainer->setTemplateFilter(value.toUInt());
   247 			return;
   189 			return;
   264 			"AMMO",
   206 			"AMMO",
   265 			QStringList() << WeaponsName->itemText(index) << WeaponsName->itemData(index).toString()
   207 			QStringList() << WeaponsName->itemText(index) << WeaponsName->itemData(index).toString()
   266 		);
   208 		);
   267 }
   209 }
   268 
   210 
   269 void GameCFGWidget::borderChanged(bool value)
       
   270 {
       
   271 	emit paramChanged("BORDER", QStringList(value ? "1" : "0"));
       
   272 }
       
   273 
       
   274 void GameCFGWidget::caseProbabilityChanged(int value)
       
   275 {
       
   276 	emit paramChanged("CASEFACTOR", QStringList(QString::number(value)));
       
   277 }
       
   278 
       
   279 void GameCFGWidget::fortsModeChanged(bool value)
       
   280 {
       
   281 	emit paramChanged("FORTSMODE", QStringList(value ? "1" : "0"));
       
   282 }
       
   283 
       
   284 void GameCFGWidget::initHealthChanged(int value)
       
   285 {
       
   286 	emit paramChanged("HEALTH", QStringList(QString::number(value)));
       
   287 }
       
   288 
       
   289 void GameCFGWidget::mapChanged(const QString & value)
   211 void GameCFGWidget::mapChanged(const QString & value)
   290 {
   212 {
   291 	emit paramChanged("MAP", QStringList(value));
   213 	emit paramChanged("MAP", QStringList(value));
   292 }
   214 }
   293 
   215 
   299 void GameCFGWidget::seedChanged(const QString & value)
   221 void GameCFGWidget::seedChanged(const QString & value)
   300 {
   222 {
   301 	emit paramChanged("SEED", QStringList(value));
   223 	emit paramChanged("SEED", QStringList(value));
   302 }
   224 }
   303 
   225 
   304 void GameCFGWidget::solidChanged(bool value)
       
   305 {
       
   306 	emit paramChanged("SOLIDLAND", QStringList(value ? "1" : "0"));
       
   307 }
       
   308 
       
   309 void GameCFGWidget::suddenDeathTurnsChanged(int value)
       
   310 {
       
   311 	emit paramChanged("SD_TURNS", QStringList(QString::number(value)));
       
   312 }
       
   313 
       
   314 void GameCFGWidget::teamsDivideChanged(bool value)
       
   315 {
       
   316 	emit paramChanged("DIVIDETEAMS", QStringList(value ? "1" : "0"));
       
   317 }
       
   318 
       
   319 void GameCFGWidget::themeChanged(const QString & value)
   226 void GameCFGWidget::themeChanged(const QString & value)
   320 {
   227 {
   321 	emit paramChanged("THEME", QStringList(value));
   228 	emit paramChanged("THEME", QStringList(value));
   322 }
   229 }
   323 
       
   324 void GameCFGWidget::turnTimeChanged(int value)
       
   325 {
       
   326 	emit paramChanged("TURNTIME", QStringList(QString::number(value)));
       
   327 }