QTfrontend/team.h
changeset 19 09de46a3328c
parent 18 d49c23eba8ba
--- a/QTfrontend/team.h	Wed Oct 26 17:26:39 2005 +0000
+++ b/QTfrontend/team.h	Wed Oct 26 21:15:35 2005 +0000
@@ -34,22 +34,56 @@
 #include <qstring.h>
 #include <qfile.h>
 #include <qtextstream.h>
+#include <qcombobox.h>
 #include "hw.h"
 
 class QString;
 class QTextStream;
 class QFile;
-class HWForm;
+class QComboBox;
+
+struct BindAction
+{
+	QComboBox * cbind;
+	char action[15];
+	char strbind[15];
+};
+
+const BindAction cbinds[8] =
+{
+	{0, "+up", "up"},
+	{0, "+left", "left"},
+	{0, "+right", "right"},
+	{0, "+down", "down"},
+	{0, "ljump", "return"},
+	{0, "hjump", "backspace"},
+	{0, "+attack", "space"},
+	{0, "switch", "tab"}
+};
+
 
 class HWTeam
 {
 	public:
-		HWTeam()
+		HWTeam(HWForm * hwform)
 		{
 			TeamName = "unnamed";
 			for (int i = 0; i < 8; i++) HHName[i].sprintf("hedgehog %d", i);
 			Grave = "Simple";
+			form = hwform;
+			memcpy(binds, cbinds, sizeof(cbinds));
+			binds[0].cbind = form->CBindUp;
+			binds[1].cbind = form->CBindLeft;
+			binds[2].cbind = form->CBindRight;
+			binds[3].cbind = form->CBindDown;
+			binds[4].cbind = form->CBindLJump;
+			binds[5].cbind = form->CBindHJump;
+			binds[6].cbind = form->CBindAttack;
+			binds[7].cbind = form->CBindSwitch;
 		}
+		
+		HWForm * form;
+		BindAction binds[8];
 		QString TeamName;
 		QString HHName[8];
 		QString	Grave;
@@ -62,19 +96,20 @@
 			QTextStream stream(&cfgfile);
 			stream.setEncoding(QTextStream::Unicode);	
 			QString str;
+			QString action;
 			
 			while (!stream.atEnd())
 			{
 				str = stream.readLine();
 				if (str.startsWith(";")) continue;
-				if (str.startsWith("teamname "))
+				if (str.startsWith("name team "))
 				{
-					str.remove(0, 9);
+					str.remove(0, 10);
 					TeamName = str;
 				} else
-				if (str.startsWith("name"))
+				if (str.startsWith("name hh"))
 				{
-					str.remove(0, 4);
+					str.remove(0, 7);
 					long i = str.left(1).toLong();
 					if ((i < 0) || (i > 7)) continue;
 					str.remove(0, 2);
@@ -89,7 +124,20 @@
 				{
 					str.remove(0, 5);
 					Fort = str;
-				}				
+				} else
+				if (str.startsWith("bind "))
+				{
+					str.remove(0, 5);
+					action = str.section(' ', 1);
+					str = str.section(' ', 0, 0);
+					str.truncate(15);
+					for (int i = 0; i < 8; i++)
+						if (action == binds[i].action)
+						{
+							strcpy((char *)&binds[i].strbind, str.latin1());
+							break;
+						}
+				}
 			}
 			cfgfile.close();
 			return true;
@@ -102,16 +150,20 @@
 			QTextStream stream(&cfgfile);
 			stream.setEncoding(QTextStream::Unicode);
 			stream << "; Generated by Hedgewars, do not modify" << endl;
-			stream << "teamname " << TeamName << endl;
+			stream << "name team " << TeamName << endl;
 			for (int i = 0; i < 8; i++)
-				stream << "name" << i << " " << HHName[i] << endl;
+				stream << "name hh" << i << " " << HHName[i] << endl;
 			stream << "grave " << Grave << endl;
 			stream << "fort " << Fort << endl;
+			for(int i = 0; i < 8; i++)
+			{
+				stream << "bind " << binds[i].strbind << " " << binds[i].action << endl;
+			}
 			cfgfile.close();
 			return true;
 		}
 		
-		void ToPage(HWForm * form)
+		void ToPage()
 		{
 			form->EditTeamName->setText(TeamName);
 			form->HHName0->setText(HHName[0]);
@@ -128,9 +180,15 @@
 			
 			lb = form->CBForts->listBox();
 			form->CBForts->setCurrentItem(lb->index(lb->findItem(Fort)));
+			
+			lb = form->CBindUp->listBox();
+			for(int i = 0; i < 8; i++)
+			{
+				binds[i].cbind->setCurrentItem(lb->index(lb->findItem(binds[i].strbind)));
+			}
 		}
 		
-		void FromPage(HWForm * form)
+		void FromPage()
 		{
 			TeamName  = form->EditTeamName->text();
 			HHName[0] = form->HHName0->text();
@@ -144,6 +202,10 @@
 			
 			Grave = form->CBGraves->currentText();
 			Fort = form->CBForts->currentText();
+			for(int i = 0; i < 8; i++)
+			{
+				strcpy((char *)&binds[i].strbind,  binds[i].cbind->currentText().latin1());
+			}
 		}
 	private:
 };