43 #include "netudpserver.h" |
43 #include "netudpserver.h" |
44 #include "netudpwidget.h" |
44 #include "netudpwidget.h" |
45 #include "chatwidget.h" |
45 #include "chatwidget.h" |
46 |
46 |
47 HWForm::HWForm(QWidget *parent) |
47 HWForm::HWForm(QWidget *parent) |
48 : QMainWindow(parent), pnetserver(0), pUdpServer(0) |
48 : QMainWindow(parent), pnetserver(0), pUdpServer(0), editedTeam(0) |
49 { |
49 { |
50 ui.setupUi(this); |
50 ui.setupUi(this); |
51 |
51 |
52 config = new GameUIConfig(this, cfgdir->absolutePath() + "/hedgewars.ini"); |
52 config = new GameUIConfig(this, cfgdir->absolutePath() + "/hedgewars.ini"); |
53 |
53 |
92 |
92 |
93 connect(ui.pageNetGame->BtnBack, SIGNAL(clicked()), this, SLOT(GoBack())); |
93 connect(ui.pageNetGame->BtnBack, SIGNAL(clicked()), this, SLOT(GoBack())); |
94 connect(ui.pageNetGame->BtnGo, SIGNAL(clicked()), this, SLOT(NetStartGame())); |
94 connect(ui.pageNetGame->BtnGo, SIGNAL(clicked()), this, SLOT(NetStartGame())); |
95 connect(ui.pageNetGame->pNetTeamsWidget, SIGNAL(setEnabledGameStart(bool)), |
95 connect(ui.pageNetGame->pNetTeamsWidget, SIGNAL(setEnabledGameStart(bool)), |
96 ui.pageNetGame->BtnGo, SLOT(setEnabled(bool))); |
96 ui.pageNetGame->BtnGo, SLOT(setEnabled(bool))); |
97 connect(ui.pageNetGame->pNetTeamsWidget, SIGNAL(NewTeam()), this, SLOT(NewTeam())); |
97 connect(ui.pageNetGame->pNetTeamsWidget, SIGNAL(SetupClicked()), this, SLOT(IntermediateSetup())); |
98 |
98 |
99 connect(ui.pageInfo->BtnBack, SIGNAL(clicked()), this, SLOT(GoBack())); |
99 connect(ui.pageInfo->BtnBack, SIGNAL(clicked()), this, SLOT(GoBack())); |
100 |
100 |
101 connect(ui.pageGameStats->BtnBack, SIGNAL(clicked()), this, SLOT(GoBack())); |
101 connect(ui.pageGameStats->BtnBack, SIGNAL(clicked()), this, SLOT(GoBack())); |
102 |
102 |
103 connect(ui.pageMultiplayer->teamsSelect, SIGNAL(NewTeam()), this, SLOT(NewTeam())); |
103 connect(ui.pageMultiplayer->teamsSelect, SIGNAL(SetupClicked()), this, SLOT(IntermediateSetup())); |
104 |
104 |
105 GoToPage(ID_PAGE_MAIN); |
105 GoToPage(ID_PAGE_MAIN); |
106 } |
106 } |
107 |
107 |
108 void HWForm::UpdateTeamsLists() |
108 void HWForm::UpdateTeamsLists(const QStringList* editable_teams) |
109 { |
109 { |
110 QStringList teamslist = config->GetTeamsList(); |
110 QStringList teamslist; |
|
111 if(editable_teams) { |
|
112 teamslist=*editable_teams; |
|
113 } else { |
|
114 teamslist = config->GetTeamsList(); |
|
115 } |
111 |
116 |
112 if(teamslist.empty()) { |
117 if(teamslist.empty()) { |
113 HWTeam defaultTeam("DefaultTeam"); |
118 HWTeam defaultTeam("DefaultTeam"); |
114 defaultTeam.SaveToFile(); |
119 defaultTeam.SaveToFile(); |
115 teamslist.push_back("DefaultTeam"); |
120 teamslist.push_back("DefaultTeam"); |
175 for(QStringList::iterator it=tmNames.begin(); it!=tmNames.end(); it++) { |
180 for(QStringList::iterator it=tmNames.begin(); it!=tmNames.end(); it++) { |
176 HWTeam team(*it); |
181 HWTeam team(*it); |
177 team.LoadFromFile(); |
182 team.LoadFromFile(); |
178 teamsList.push_back(team); |
183 teamsList.push_back(team); |
179 } |
184 } |
180 if(lastid==ID_PAGE_SETUP_TEAM) { |
185 if(lastid==ID_PAGE_SETUP) { // _TEAM |
181 if (editedTeam) curTeamSelWidget->addTeam(*editedTeam); |
186 if (editedTeam) { |
|
187 curTeamSelWidget->addTeam(*editedTeam); |
|
188 } |
182 } else { |
189 } else { |
183 curTeamSelWidget->resetPlayingTeams(teamsList); |
190 curTeamSelWidget->resetPlayingTeams(teamsList); |
184 } |
191 } |
185 } |
192 } |
186 } |
193 } |
187 |
194 |
188 void HWForm::GoToPage(quint8 id) |
195 void HWForm::GoToPage(quint8 id) |
189 { |
196 { |
|
197 quint8 lastid=ui.Pages->currentIndex(); |
190 PagesStack.push(ui.Pages->currentIndex()); |
198 PagesStack.push(ui.Pages->currentIndex()); |
191 OnPageShown(id); |
199 OnPageShown(id, lastid); |
192 ui.Pages->setCurrentIndex(id); |
200 ui.Pages->setCurrentIndex(id); |
193 } |
201 } |
194 |
202 |
195 void HWForm::GoBack() |
203 void HWForm::GoBack() |
196 { |
204 { |
219 btn->setIcon(QIcon(":/res/bonus.png")); |
227 btn->setIcon(QIcon(":/res/bonus.png")); |
220 } |
228 } |
221 } |
229 } |
222 } |
230 } |
223 |
231 |
|
232 void HWForm::IntermediateSetup() |
|
233 { |
|
234 quint8 id=ui.Pages->currentIndex(); |
|
235 TeamSelWidget* curTeamSelWidget; |
|
236 if(id == ID_PAGE_MULTIPLAYER) { |
|
237 curTeamSelWidget=ui.pageMultiplayer->teamsSelect; |
|
238 } else { |
|
239 curTeamSelWidget=ui.pageNetGame->pNetTeamsWidget; |
|
240 } |
|
241 QList<HWTeam> teams=curTeamSelWidget->getDontPlayingTeams(); |
|
242 QStringList tmnames; |
|
243 for(QList<HWTeam>::iterator it = teams.begin(); it != teams.end(); ++it) { |
|
244 qDebug() << it->TeamName; |
|
245 tmnames+=it->TeamName; |
|
246 } |
|
247 UpdateTeamsLists(&tmnames); // FIXME: still need more work if teamname is updated while configuring |
|
248 |
|
249 GoToPage(ID_PAGE_SETUP); |
|
250 } |
|
251 |
224 void HWForm::NewTeam() |
252 void HWForm::NewTeam() |
225 { |
253 { |
226 editedTeam = new HWTeam("unnamed"); |
254 editedTeam = new HWTeam("unnamed"); |
227 editedTeam->SetToPage(this); |
255 editedTeam->SetToPage(this); |
228 GoToPage(ID_PAGE_SETUP_TEAM); |
256 GoToPage(ID_PAGE_SETUP_TEAM); |