--- a/QTfrontend/hwform.cpp Wed Nov 15 21:53:50 2006 +0000
+++ b/QTfrontend/hwform.cpp Thu Nov 16 22:01:51 2006 +0000
@@ -42,19 +42,7 @@
config = new GameUIConfig(this);
- QStringList teamslist = config->GetTeamsList();
-
- if(teamslist.empty()) {
- HWTeam defaultTeam("DefaultTeam");
- defaultTeam.SaveToFile();
- teamslist.push_back("DefaultTeam");
- }
-
- for (QStringList::Iterator it = teamslist.begin(); it != teamslist.end(); ++it )
- {
- ui.pageMultiplayer->teamsSelect->addTeam(*it);
- ui.pageOptions->CBTeamName->addItem(*it);
- }
+ UpdateTeamsLists();
connect(ui.pageMain->BtnSinglePlayer, SIGNAL(clicked()), this, SLOT(GoToSinglePlayer()));
connect(ui.pageMain->BtnSetup, SIGNAL(clicked()), this, SLOT(GoToSetup()));
@@ -97,6 +85,20 @@
ui.Pages->setCurrentIndex(ID_PAGE_MAIN);
}
+void HWForm::UpdateTeamsLists()
+{
+ QStringList teamslist = config->GetTeamsList();
+
+ if(teamslist.empty()) {
+ HWTeam defaultTeam("DefaultTeam");
+ defaultTeam.SaveToFile();
+ teamslist.push_back("DefaultTeam");
+ }
+
+ ui.pageOptions->CBTeamName->clear();
+ ui.pageOptions->CBTeamName->addItems(teamslist);
+}
+
void HWForm::GoToMain()
{
ui.Pages->setCurrentIndex(ID_PAGE_MAIN);
@@ -124,7 +126,6 @@
for(QStringList::iterator it=tmNames.begin(); it!=tmNames.end(); it++) {
HWTeam team(*it);
team.LoadFromFile();
- team.TeamName=*it; // FIXME: we can have different different teamnames in config files
teamsList.push_back(team);
}
ui.pageMultiplayer->teamsSelect->resetPlayingTeams(teamsList);
@@ -154,29 +155,31 @@
void HWForm::NewTeam()
{
- tmpTeam = new HWTeam("unnamed");
- tmpTeam->SetToPage(this);
+ editedTeam = new HWTeam("unnamed");
+ editedTeam->SetToPage(this);
ui.Pages->setCurrentIndex(ID_PAGE_SETUP_TEAM);
}
void HWForm::EditTeam()
{
- tmpTeam = new HWTeam(ui.pageOptions->CBTeamName->currentText());
- tmpTeam->LoadFromFile();
- tmpTeam->SetToPage(this);
+ editedTeam = new HWTeam(ui.pageOptions->CBTeamName->currentText());
+ editedTeam->LoadFromFile();
+ editedTeam->SetToPage(this);
ui.Pages->setCurrentIndex(ID_PAGE_SETUP_TEAM);
}
void HWForm::TeamSave()
{
- tmpTeam->GetFromPage(this);
- tmpTeam->SaveToFile();
- delete tmpTeam;
+ editedTeam->GetFromPage(this);
+ editedTeam->SaveToFile();
+ delete editedTeam;
+ UpdateTeamsLists();
ui.Pages->setCurrentIndex(ID_PAGE_SETUP);
}
void HWForm::TeamDiscard()
{
+ delete editedTeam;
ui.Pages->setCurrentIndex(ID_PAGE_SETUP);
}
--- a/QTfrontend/hwform.h Wed Nov 15 21:53:50 2006 +0000
+++ b/QTfrontend/hwform.h Thu Nov 16 22:01:51 2006 +0000
@@ -65,6 +65,7 @@
void StartMPGame();
private:
+ void UpdateTeamsLists();
enum PageIDs {
ID_PAGE_SINGLEPLAYER = 0,
ID_PAGE_SETUP_TEAM = 1,
@@ -78,7 +79,7 @@
ID_PAGE_MAIN = 9
};
HWGame * game;
- HWTeam * tmpTeam;
+ HWTeam * editedTeam;
HWNet * hwnet;
GameUIConfig * config;
};
--- a/QTfrontend/team.cpp Wed Nov 15 21:53:50 2006 +0000
+++ b/QTfrontend/team.cpp Thu Nov 16 22:01:51 2006 +0000
@@ -30,6 +30,7 @@
difficulty(0)
{
TeamName = teamname;
+ OldTeamName = TeamName;
for (int i = 0; i < 8; i++) HHName[i].sprintf("hedgehog %d", i);
Grave = "Simple";
Fort = "Barrelhouse";
@@ -76,11 +77,11 @@
{
str = stream.readLine();
if (str.startsWith(";")) continue;
- if (str.startsWith("name team "))
+ /*if (str.startsWith("name team "))
{
str.remove(0, 10);
TeamName = str;
- } else
+ } else*/
if (str.startsWith("name hh"))
{
str.remove(0, 7);
@@ -125,6 +126,12 @@
bool HWTeam::SaveToFile()
{
+ if (OldTeamName != TeamName)
+ {
+ QFile cfgfile(cfgdir->absolutePath() + "/" + OldTeamName + ".cfg");
+ cfgfile.remove();
+ OldTeamName = TeamName;
+ }
QFile cfgfile(cfgdir->absolutePath() + "/" + TeamName + ".cfg");
if (!cfgfile.open(QIODevice::WriteOnly)) return false;
QTextStream stream(&cfgfile);
--- a/QTfrontend/team.h Wed Nov 15 21:53:50 2006 +0000
+++ b/QTfrontend/team.h Thu Nov 16 22:01:51 2006 +0000
@@ -47,6 +47,8 @@
bool operator==(const HWTeam& t1) const;
bool operator<(const HWTeam& t1) const;
+ private:
+ QString OldTeamName;
};
class HWTeamTempParams