QTfrontend/team.cpp
changeset 26 e32fa14529f8
parent 25 27aa8030322b
child 86 664b536a1c27
equal deleted inserted replaced
25:27aa8030322b 26:e32fa14529f8
    47 		binds[i].action = cbinds[i].action;
    47 		binds[i].action = cbinds[i].action;
    48 		binds[i].strbind = cbinds[i].strbind;
    48 		binds[i].strbind = cbinds[i].strbind;
    49 	}
    49 	}
    50 	dir = "";
    50 	dir = "";
    51 }
    51 }
    52 	
    52 
    53 bool HWTeam::LoadFromFile()
    53 bool HWTeam::LoadFromFile()
    54 {
    54 {
    55 	QFile cfgfile(dir + "/" + TeamName + ".cfg");
    55 	QFile cfgfile(dir + "/" + TeamName + ".cfg");
    56 	if (!cfgfile.open(QIODevice::ReadOnly)) return false;
    56 	if (!cfgfile.open(QIODevice::ReadOnly)) return false;
    57 	QTextStream stream(&cfgfile);
    57 	QTextStream stream(&cfgfile);
    58 	stream.setCodec("UTF-8");	
    58 	stream.setCodec("UTF-8");
    59 	QString str;
    59 	QString str;
    60 	QString action;
    60 	QString action;
    61 	
    61 
    62 	while (!stream.atEnd())
    62 	while (!stream.atEnd())
    63 	{
    63 	{
    64 		str = stream.readLine();
    64 		str = stream.readLine();
    65 		if (str.startsWith(";")) continue;
    65 		if (str.startsWith(";")) continue;
    66 		if (str.startsWith("name team "))
    66 		if (str.startsWith("name team "))
   103 	cfgfile.close();
   103 	cfgfile.close();
   104 	return true;
   104 	return true;
   105 }
   105 }
   106 
   106 
   107 bool HWTeam::SaveToFile()
   107 bool HWTeam::SaveToFile()
   108 {			
   108 {
   109 	QFile cfgfile(dir + "/" + TeamName + ".cfg");
   109 	QFile cfgfile(dir + "/" + TeamName + ".cfg");
   110 	if (!cfgfile.open(QIODevice::WriteOnly)) return false;
   110 	if (!cfgfile.open(QIODevice::WriteOnly)) return false;
   111 	QTextStream stream(&cfgfile);
   111 	QTextStream stream(&cfgfile);
   112 	stream.setCodec("UTF-8");
   112 	stream.setCodec("UTF-8");
   113 	stream << "; Generated by Hedgewars, do not modify" << endl;
   113 	stream << "; Generated by Hedgewars, do not modify" << endl;
   114 	stream << "name team " << TeamName << endl;
   114 	stream << "name team " << TeamName << endl;
   115 	for (int i = 0; i < BINDS_NUMBER; i++)
   115 	for (int i = 0; i < 8; i++)
   116 		stream << "name hh" << i << " " << HHName[i] << endl;
   116 		stream << "name hh" << i << " " << HHName[i] << endl;
   117 	stream << "grave " << Grave << endl;
   117 	stream << "grave " << Grave << endl;
   118 	stream << "fort " << Fort << endl;
   118 	stream << "fort " << Fort << endl;
   119 	for(int i = 0; i < BINDS_NUMBER; i++)
   119 	for(int i = 0; i < BINDS_NUMBER; i++)
   120 	{
   120 	{
   131 	{
   131 	{
   132 		hwform->HHNameEdit[i]->setText(HHName[i]);
   132 		hwform->HHNameEdit[i]->setText(HHName[i]);
   133 	}
   133 	}
   134 	hwform->ui.CBGrave->setCurrentIndex(hwform->ui.CBGrave->findText(Grave));
   134 	hwform->ui.CBGrave->setCurrentIndex(hwform->ui.CBGrave->findText(Grave));
   135 	hwform->CBGrave_activated(Grave);
   135 	hwform->CBGrave_activated(Grave);
   136 	
   136 
   137 	hwform->ui.CBFort->setCurrentIndex(hwform->ui.CBFort->findText(Fort));
   137 	hwform->ui.CBFort->setCurrentIndex(hwform->ui.CBFort->findText(Fort));
   138 	hwform->CBFort_activated(Fort);
   138 	hwform->CBFort_activated(Fort);
   139 	
   139 
   140 	for(int i = 0; i < BINDS_NUMBER; i++)
   140 	for(int i = 0; i < BINDS_NUMBER; i++)
   141 	{
   141 	{
   142 		hwform->CBBind[i]->setCurrentIndex(hwform->CBBind[i]->findText(binds[i].strbind));
   142 		hwform->CBBind[i]->setCurrentIndex(hwform->CBBind[i]->findText(binds[i].strbind));
   143 	}
   143 	}
   144 }
   144 }
   148 	TeamName  = hwform->TeamNameEdit->text();
   148 	TeamName  = hwform->TeamNameEdit->text();
   149 	for(int i = 0; i < 8; i++)
   149 	for(int i = 0; i < 8; i++)
   150 	{
   150 	{
   151 		HHName[i] = hwform->HHNameEdit[i]->text();
   151 		HHName[i] = hwform->HHNameEdit[i]->text();
   152 	}
   152 	}
   153 	
   153 
   154 	Grave = hwform->ui.CBGrave->currentText();
   154 	Grave = hwform->ui.CBGrave->currentText();
   155 	Fort = hwform->ui.CBFort->currentText();
   155 	Fort = hwform->ui.CBFort->currentText();
   156 	for(int i = 0; i < 8; i++)
   156 	for(int i = 0; i < 8; i++)
   157 	{
   157 	{
   158 		binds[i].strbind = hwform->CBBind[i]->currentText();
   158 		binds[i].strbind = hwform->CBBind[i]->currentText();