QTfrontend/team.cpp
changeset 86 664b536a1c27
parent 26 e32fa14529f8
child 87 ff213e443336
equal deleted inserted replaced
85:44d9045b26ff 86:664b536a1c27
    33 
    33 
    34 #include <QFile>
    34 #include <QFile>
    35 #include <QTextStream>
    35 #include <QTextStream>
    36 #include "team.h"
    36 #include "team.h"
    37 #include "hwform.h"
    37 #include "hwform.h"
    38 
    38 #include "gameuiconfig.h"
    39 HWTeam::HWTeam(const QString & teamname)
    39 #include "predefteams.h"
    40 {
    40 
       
    41 HWTeam::HWTeam(const QString & teamname, GameUIConfig * config)
       
    42 {
       
    43 	this->config = config;
    41 	TeamName = teamname;
    44 	TeamName = teamname;
    42 	for (int i = 0; i < 8; i++) HHName[i].sprintf("hedgehog %d", i);
    45 	for (int i = 0; i < 8; i++) HHName[i].sprintf("hedgehog %d", i);
    43 	Grave = "Simple";
    46 	Grave = "Simple";
    44 	Fort = "Barrelhouse";
    47 	Fort = "Barrelhouse";
    45 	for(int i = 0; i < BINDS_NUMBER; i++)
    48 	for(int i = 0; i < BINDS_NUMBER; i++)
    46 	{
    49 	{
    47 		binds[i].action = cbinds[i].action;
    50 		binds[i].action = cbinds[i].action;
    48 		binds[i].strbind = cbinds[i].strbind;
    51 		binds[i].strbind = cbinds[i].strbind;
    49 	}
    52 	}
    50 	dir = "";
    53 }
    51 }
    54 
       
    55 HWTeam::HWTeam(quint8 num, GameUIConfig * config)
       
    56 {
       
    57 	this->config = config;
       
    58 	num %= PREDEFTEAMS_COUNT;
       
    59 	TeamName = pteams[num].TeamName;
       
    60 	HHName[0] = pteams[num].hh0name;
       
    61 	HHName[1] = pteams[num].hh1name;
       
    62 	HHName[2] = pteams[num].hh2name;
       
    63 	HHName[3] = pteams[num].hh3name;
       
    64 	HHName[4] = pteams[num].hh4name;
       
    65 	HHName[5] = pteams[num].hh5name;
       
    66 	HHName[6] = pteams[num].hh6name;
       
    67 	HHName[7] = pteams[num].hh7name;
       
    68 	Grave = pteams[num].Grave;
       
    69 	Fort = pteams[num].Fort;
       
    70 }
       
    71 
    52 
    72 
    53 bool HWTeam::LoadFromFile()
    73 bool HWTeam::LoadFromFile()
    54 {
    74 {
    55 	QFile cfgfile(dir + "/" + TeamName + ".cfg");
    75 	QFile cfgfile(config->cfgdir.absolutePath() + "/" + TeamName + ".cfg");
    56 	if (!cfgfile.open(QIODevice::ReadOnly)) return false;
    76 	if (!cfgfile.open(QIODevice::ReadOnly)) return false;
    57 	QTextStream stream(&cfgfile);
    77 	QTextStream stream(&cfgfile);
    58 	stream.setCodec("UTF-8");
    78 	stream.setCodec("UTF-8");
    59 	QString str;
    79 	QString str;
    60 	QString action;
    80 	QString action;
   104 	return true;
   124 	return true;
   105 }
   125 }
   106 
   126 
   107 bool HWTeam::SaveToFile()
   127 bool HWTeam::SaveToFile()
   108 {
   128 {
   109 	QFile cfgfile(dir + "/" + TeamName + ".cfg");
   129 	QFile cfgfile(config->cfgdir.absolutePath() + "/" + TeamName + ".cfg");
   110 	if (!cfgfile.open(QIODevice::WriteOnly)) return false;
   130 	if (!cfgfile.open(QIODevice::WriteOnly)) return false;
   111 	QTextStream stream(&cfgfile);
   131 	QTextStream stream(&cfgfile);
   112 	stream.setCodec("UTF-8");
   132 	stream.setCodec("UTF-8");
   113 	stream << "; Generated by Hedgewars, do not modify" << endl;
   133 	stream << "; Generated by Hedgewars, do not modify" << endl;
   114 	stream << "name team " << TeamName << endl;
   134 	stream << "name team " << TeamName << endl;
   157 	{
   177 	{
   158 		binds[i].strbind = hwform->CBBind[i]->currentText();
   178 		binds[i].strbind = hwform->CBBind[i]->currentText();
   159 	}
   179 	}
   160 }
   180 }
   161 
   181 
   162 void HWTeam::SetCfgDir(const QString & dir)
   182 QByteArray HWTeam::IPCTeamInfo() const
   163 {
   183 {
   164 	this->dir = dir;
   184 	QByteArray buf;
   165 }
   185 	#define ADD(a) { \
       
   186 					QByteArray strmsg = a.toUtf8(); \
       
   187 					quint8 sz = strmsg.size(); \
       
   188 					buf.append(QByteArray((char *)&sz, 1)); \
       
   189 					buf.append(strmsg); \
       
   190 					}
       
   191 
       
   192 	ADD(QString("ename team " + TeamName));
       
   193 	for (int i = 0; i < 8; i++)
       
   194 		ADD(QString("ename hh%1 ").arg(i).append(HHName[i]));
       
   195 	ADD(QString("egrave " + Grave));
       
   196 	ADD(QString("efort " + Fort));
       
   197 	for(int i = 0; i < BINDS_NUMBER; i++)
       
   198 	{
       
   199 		ADD(QString("ebind " + binds[i].strbind + " " + binds[i].action));
       
   200 	}
       
   201 	#undef ADD
       
   202 	return buf;
       
   203 }
       
   204