QTfrontend/team.cpp
changeset 231 c77b16e48273
parent 184 f97a7a3dc8f6
child 239 f9adf3c73bed
equal deleted inserted replaced
230:ff76ba0671f7 231:c77b16e48273
    17  */
    17  */
    18 
    18 
    19 #include <QFile>
    19 #include <QFile>
    20 #include <QTextStream>
    20 #include <QTextStream>
    21 #include <QApplication>
    21 #include <QApplication>
       
    22 #include <QSpinBox>
    22 #include "team.h"
    23 #include "team.h"
    23 #include "hwform.h"
    24 #include "hwform.h"
    24 #include "predefteams.h"
    25 #include "predefteams.h"
    25 #include "pages.h"
    26 #include "pages.h"
    26 #include "hwconsts.h"
    27 #include "hwconsts.h"
    27 
    28 
    28 HWTeam::HWTeam(const QString & teamname)
    29 HWTeam::HWTeam(const QString & teamname) :
       
    30   difficulty(0)
    29 {
    31 {
    30 	TeamName = teamname;
    32 	TeamName = teamname;
    31 	for (int i = 0; i < 8; i++) HHName[i].sprintf("hedgehog %d", i);
    33 	for (int i = 0; i < 8; i++) HHName[i].sprintf("hedgehog %d", i);
    32 	Grave = "Simple";
    34 	Grave = "Simple";
    33 	Fort = "Barrelhouse";
    35 	Fort = "Barrelhouse";
    36 		binds[i].action = cbinds[i].action;
    38 		binds[i].action = cbinds[i].action;
    37 		binds[i].strbind = cbinds[i].strbind;
    39 		binds[i].strbind = cbinds[i].strbind;
    38 	}
    40 	}
    39 }
    41 }
    40 
    42 
    41 HWTeam::HWTeam(quint8 num)
    43 HWTeam::HWTeam(quint8 num) :
       
    44   difficulty(0)
    42 {
    45 {
    43 	num %= PREDEFTEAMS_COUNT;
    46 	num %= PREDEFTEAMS_COUNT;
    44 	TeamName = QApplication::translate("teams", pteams[num].TeamName);
    47 	TeamName = QApplication::translate("teams", pteams[num].TeamName);
    45 	HHName[0] = QApplication::translate("teams", pteams[num].hh0name);
    48 	HHName[0] = QApplication::translate("teams", pteams[num].hh0name);
    46 	HHName[1] = QApplication::translate("teams", pteams[num].hh1name);
    49 	HHName[1] = QApplication::translate("teams", pteams[num].hh1name);
   106 				if (action == binds[i].action)
   109 				if (action == binds[i].action)
   107 				{
   110 				{
   108 					binds[i].strbind = str;
   111 					binds[i].strbind = str;
   109 					break;
   112 					break;
   110 				}
   113 				}
       
   114 		} else 
       
   115 		if (str.startsWith("difficulty "))
       
   116 		{
       
   117 		  str.remove(0, 11);
       
   118 		  difficulty=str.toUInt();
       
   119 		  if (difficulty>5) difficulty=0; // this shouldn't normally happen
   111 		}
   120 		}
   112 	}
   121 	}
   113 	cfgfile.close();
   122 	cfgfile.close();
   114 	return true;
   123 	return true;
   115 }
   124 }
   128 	stream << "fort " << Fort << endl;
   137 	stream << "fort " << Fort << endl;
   129 	for(int i = 0; i < BINDS_NUMBER; i++)
   138 	for(int i = 0; i < BINDS_NUMBER; i++)
   130 	{
   139 	{
   131 		stream << "bind " << binds[i].strbind << " " << binds[i].action << endl;
   140 		stream << "bind " << binds[i].strbind << " " << binds[i].action << endl;
   132 	}
   141 	}
       
   142 	stream << "difficulty " << difficulty << endl;
   133 	cfgfile.close();
   143 	cfgfile.close();
   134 	return true;
   144 	return true;
   135 }
   145 }
   136 
   146 
   137 void HWTeam::SetToPage(HWForm * hwform)
   147 void HWTeam::SetToPage(HWForm * hwform)
   138 {
   148 {
   139 	hwform->ui.pageEditTeam->TeamNameEdit->setText(TeamName);
   149 	hwform->ui.pageEditTeam->TeamNameEdit->setText(TeamName);
       
   150 	hwform->ui.pageEditTeam->difficultyBox->setValue(difficulty);
   140 	for(int i = 0; i < 8; i++)
   151 	for(int i = 0; i < 8; i++)
   141 	{
   152 	{
   142 		hwform->ui.pageEditTeam->HHNameEdit[i]->setText(HHName[i]);
   153 		hwform->ui.pageEditTeam->HHNameEdit[i]->setText(HHName[i]);
   143 	}
   154 	}
   144 	hwform->ui.pageEditTeam->CBGrave->setCurrentIndex(hwform->ui.pageEditTeam->CBGrave->findText(Grave));
   155 	hwform->ui.pageEditTeam->CBGrave->setCurrentIndex(hwform->ui.pageEditTeam->CBGrave->findText(Grave));
   154 }
   165 }
   155 
   166 
   156 void HWTeam::GetFromPage(HWForm * hwform)
   167 void HWTeam::GetFromPage(HWForm * hwform)
   157 {
   168 {
   158 	TeamName  = hwform->ui.pageEditTeam->TeamNameEdit->text();
   169 	TeamName  = hwform->ui.pageEditTeam->TeamNameEdit->text();
       
   170 	difficulty = hwform->ui.pageEditTeam->difficultyBox->value();
   159 	for(int i = 0; i < 8; i++)
   171 	for(int i = 0; i < 8; i++)
   160 	{
   172 	{
   161 		HHName[i] = hwform->ui.pageEditTeam->HHNameEdit[i]->text();
   173 		HHName[i] = hwform->ui.pageEditTeam->HHNameEdit[i]->text();
   162 	}
   174 	}
   163 
   175