QTfrontend/team.cpp
branchhedgeroid
changeset 6224 42b256eca362
parent 6223 cc3eb9b7230f
child 6225 505643d4c23d
--- a/QTfrontend/team.cpp	Fri Oct 28 17:41:39 2011 +0200
+++ b/QTfrontend/team.cpp	Fri Oct 28 18:26:17 2011 +0200
@@ -25,13 +25,13 @@
 
 #include "team.h"
 #include "hwform.h"
-#include "pageeditteam.h"
 #include "hats.h"
 
 HWTeam::HWTeam(const QString & teamname) :
-    m_difficulty(0),
-    m_numHedgehogs(4),
-    m_isNetTeam(false)
+	QObject(0)
+	, m_difficulty(0)
+	, m_numHedgehogs(4)
+	, m_isNetTeam(false)
 {
     m_name = teamname;
     OldTeamName = m_name;
@@ -46,8 +46,8 @@
     m_flag = "hedgewars";
     for(int i = 0; i < BINDS_NUMBER; i++)
     {
-        binds[i].action = cbinds[i].action;
-        binds[i].strbind = cbinds[i].strbind;
+        m_binds[i].action = cbinds[i].action;
+        m_binds[i].strbind = cbinds[i].strbind;
     }
     m_rounds = 0;
     m_wins = 0;
@@ -55,8 +55,9 @@
 }
 
 HWTeam::HWTeam(const QStringList& strLst) :
-  m_numHedgehogs(4),
-  m_isNetTeam(true)
+	QObject(0)
+	, m_numHedgehogs(4)
+	, m_isNetTeam(true)
 {
     // net teams are configured from QStringList
     if(strLst.size() != 23) throw HWTeamConstructException();
@@ -81,9 +82,10 @@
 }
 
 HWTeam::HWTeam() :
-  m_difficulty(0),
-  m_numHedgehogs(4),
-  m_isNetTeam(false)
+	QObject(0)
+  , m_difficulty(0)
+  , m_numHedgehogs(4)
+  , m_isNetTeam(false)
 {
     m_name = QString("Team");
     for (int i = 0; i < HEDGEHOGS_PER_TEAM; i++)
@@ -99,14 +101,61 @@
 
     for(int i = 0; i < BINDS_NUMBER; i++)
     {
-        binds[i].action = cbinds[i].action;
-        binds[i].strbind = cbinds[i].strbind;
+        m_binds[i].action = cbinds[i].action;
+        m_binds[i].strbind = cbinds[i].strbind;
     }
     m_rounds = 0;
     m_wins = 0;
     m_campaignProgress = 0;
 }
 
+HWTeam::HWTeam(const HWTeam & other) :
+		QObject(0)
+		, OldTeamName(other.OldTeamName)
+		, m_name(other.m_name)
+		, m_grave(other.m_grave)
+		, m_fort(other.m_fort)
+		, m_flag(other.m_flag)
+		, m_voicepack(other.m_voicepack)
+		, m_hedgehogs(other.m_hedgehogs)
+		, m_difficulty(other.m_difficulty)
+		, m_binds(other.m_binds)
+		, m_numHedgehogs(other.m_numHedgehogs)
+		, m_color(other.m_color)
+		, m_isNetTeam(other.m_isNetTeam)
+		, m_owner(other.m_owner)
+		, m_campaignProgress(other.m_campaignProgress)
+		, m_rounds(other.m_rounds)
+		, m_wins(other.m_wins)
+//	  , AchievementProgress(other.AchievementProgress)
+{
+
+}
+
+HWTeam & HWTeam::operator = (const HWTeam & other)
+{
+	if(this != &other)
+	{
+		OldTeamName = other.OldTeamName;
+		m_name = other.m_name;
+		m_grave = other.m_grave;
+		m_fort = other.m_fort;
+		m_flag = other.m_flag;
+		m_voicepack = other.m_voicepack;
+//		m_hedgehogs = other.m_hedgehogs;
+		m_difficulty = other.m_difficulty;
+//		m_binds = other.m_binds;
+		m_numHedgehogs = other.m_numHedgehogs;
+		m_color = other.m_color;
+		m_isNetTeam = other.m_isNetTeam;
+		m_owner = other.m_owner;
+		m_campaignProgress = other.m_campaignProgress;
+		m_rounds = other.m_rounds;
+		m_wins = other.m_wins;
+	}
+
+	return *this;
+}
 
 bool HWTeam::loadFromFile()
 {
@@ -132,7 +181,7 @@
         m_hedgehogs[i].Suicides = teamfile.value(hh + "Suicides", 0).toInt();
     }
     for(int i = 0; i < BINDS_NUMBER; i++)
-        binds[i].strbind = teamfile.value(QString("Binds/%1").arg(binds[i].action), cbinds[i].strbind).toString();
+        m_binds[i].strbind = teamfile.value(QString("Binds/%1").arg(m_binds[i].action), cbinds[i].strbind).toString();
     for(int i = 0; i < MAX_ACHIEVEMENTS; i++)
         if(achievements[i][0][0])
             AchievementProgress[i] = teamfile.value(QString("Achievements/%1").arg(achievements[i][0]), 0).toUInt();
@@ -186,7 +235,7 @@
         teamfile.setValue(hh + "Suicides", m_hedgehogs[i].Suicides);
     }
     for(int i = 0; i < BINDS_NUMBER; i++)
-        teamfile.setValue(QString("Binds/%1").arg(binds[i].action), binds[i].strbind);
+        teamfile.setValue(QString("Binds/%1").arg(m_binds[i].action), m_binds[i].strbind);
     for(int i = 0; i < MAX_ACHIEVEMENTS; i++)
         if(achievements[i][0][0])
             teamfile.setValue(QString("Achievements/%1").arg(achievements[i][0]), AchievementProgress[i]);
@@ -195,54 +244,6 @@
     return true;
 }
 
-void HWTeam::SetToPage(HWForm * hwform)
-{
-    hwform->ui.pageEditTeam->TeamNameEdit->setText(m_name);
-    hwform->ui.pageEditTeam->CBTeamLvl->setCurrentIndex(m_difficulty);
-    for(int i = 0; i < HEDGEHOGS_PER_TEAM; i++)
-    {
-         hwform->ui.pageEditTeam->HHNameEdit[i]->setText(m_hedgehogs[i].Name);
-         if (m_hedgehogs[i].Hat.startsWith("Reserved"))
-            hwform->ui.pageEditTeam->HHHats[i]->setCurrentIndex(hwform->ui.pageEditTeam->HHHats[i]->findData("Reserved "+m_hedgehogs[i].Hat.remove(0,40), Qt::DisplayRole));
-         else
-            hwform->ui.pageEditTeam->HHHats[i]->setCurrentIndex(hwform->ui.pageEditTeam->HHHats[i]->findData(m_hedgehogs[i].Hat, Qt::DisplayRole));
-    }
-    hwform->ui.pageEditTeam->CBGrave->setCurrentIndex(hwform->ui.pageEditTeam->CBGrave->findText(m_grave));
-    hwform->ui.pageEditTeam->CBFlag->setCurrentIndex(hwform->ui.pageEditTeam->CBFlag->findData(m_flag));
-
-    hwform->ui.pageEditTeam->CBFort->setCurrentIndex(hwform->ui.pageEditTeam->CBFort->findText(m_fort));
-    hwform->ui.pageEditTeam->CBVoicepack->setCurrentIndex(hwform->ui.pageEditTeam->CBVoicepack->findText(m_voicepack));
-    //hwform->ui.pageEditTeam->CBFort_activated(Fort);
-
-    for(int i = 0; i < BINDS_NUMBER; i++)
-    {
-        hwform->ui.pageEditTeam->CBBind[i]->setCurrentIndex(hwform->ui.pageEditTeam->CBBind[i]->findData(binds[i].strbind));
-    }
-}
-
-void HWTeam::GetFromPage(HWForm * hwform)
-{
-    m_name  = hwform->ui.pageEditTeam->TeamNameEdit->text();
-    m_difficulty = hwform->ui.pageEditTeam->CBTeamLvl->currentIndex();
-    for(int i = 0; i < HEDGEHOGS_PER_TEAM; i++)
-    {
-        m_hedgehogs[i].Name = hwform->ui.pageEditTeam->HHNameEdit[i]->text();
-        if (hwform->ui.pageEditTeam->HHHats[i]->currentText().startsWith("Reserved"))
-            m_hedgehogs[i].Hat = "Reserved"+playerHash+hwform->ui.pageEditTeam->HHHats[i]->currentText().remove(0,9);
-        else
-            m_hedgehogs[i].Hat = hwform->ui.pageEditTeam->HHHats[i]->currentText();
-    }
-
-    m_grave = hwform->ui.pageEditTeam->CBGrave->currentText();
-    m_fort = hwform->ui.pageEditTeam->CBFort->currentText();
-    m_voicepack = hwform->ui.pageEditTeam->CBVoicepack->currentText();
-    m_flag = hwform->ui.pageEditTeam->CBFlag->itemData(hwform->ui.pageEditTeam->CBFlag->currentIndex()).toString();
-    for(int i = 0; i < BINDS_NUMBER; i++)
-    {
-        binds[i].strbind = hwform->ui.pageEditTeam->CBBind[i]->itemData(hwform->ui.pageEditTeam->CBBind[i]->currentIndex()).toString();
-    }
-}
-
 QStringList HWTeam::teamGameConfig(quint32 InitHealth) const
 {
     QStringList sl;
@@ -260,8 +261,8 @@
 
     if (!m_isNetTeam)
         for(int i = 0; i < BINDS_NUMBER; i++)
-            if(!binds[i].strbind.isEmpty())
-                sl.push_back(QString("ebind " + binds[i].strbind + " " + binds[i].action));
+            if(!m_binds[i].strbind.isEmpty())
+                sl.push_back(QString("ebind " + m_binds[i].strbind + " " + m_binds[i].action));
 
     for (int t = 0; t < m_numHedgehogs; t++)
     {
@@ -299,7 +300,7 @@
 
 // single hedgehog
 const HWHog & HWTeam::hedgehog(unsigned int idx) const { return m_hedgehogs[idx]; }
-         void HWTeam::setHedgehog(unsigned int idx, const HWHog & hh) { m_hedgehogs[idx] = hh; }
+         void HWTeam::setHedgehog(unsigned int idx, HWHog hh) { m_hedgehogs[idx] = hh; }
 
 // owner
 QString HWTeam::owner() const { return m_owner; }
@@ -315,6 +316,9 @@
   void HWTeam::setColor(const QColor & color) { m_color = color; }
 
 
+// binds
+QString HWTeam::keyBind(unsigned int idx) const { return m_binds[idx].strbind; }
+   void HWTeam::bindKey(unsigned int idx, const QString & key) { m_binds[idx].strbind = key; }
 
 // flag
 void    HWTeam::setFlag(const QString & flag) { m_flag = flag; }