1 ////////////////////////////////////////////////////////////////////////////////
2 // Scorched3D (c) 2000-2009
4 // This file is part of Scorched3D.
6 // Scorched3D is free software; you can redistribute it and/or modify
7 // it under the terms of the GNU General Public License as published by
8 // the Free Software Foundation; either version 2 of the License, or
9 // (at your option) any later version.
11 // Scorched3D is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 // GNU General Public License for more details.
16 // You should have received a copy of the GNU General Public License
17 // along with Scorched3D; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 ////////////////////////////////////////////////////////////////////////////////
21 #include <dialogs/AdminDialog.h>
22 #include <GLW/GLWWindowManager.h>
23 #include <GLW/GLWDropDownText.h>
24 #include <GLW/GLWFont.h>
25 #include <tank/TankContainer.h>
26 #include <tank/TankColorGenerator.h>
27 #include <tankai/TankAINames.h>
28 #include <client/ScorchedClient.h>
29 #include <client/ClientAdminResultHandler.h>
30 #include <coms/ComsAdminMessage.h>
31 #include <coms/ComsMessageSender.h>
33 AdminDialog
*AdminDialog::instance_
= 0;
35 AdminDialog
*AdminDialog::instance()
39 instance_
= new AdminDialog
;
44 AdminDialog::AdminDialog() :
45 GLWWindow("", 600.0f
, 400.0f
, 0, "")
48 playerTab_
= (GLWTab
*)
49 addWidget(new GLWTab("Player", LANG_RESOURCE("PLAYER", "Player"), 10, 40, 580, 330));
52 std::list
<GLWIconTable::Column
> adminColumns
;
53 adminColumns
.push_back(GLWIconTable::Column(LANG_RESOURCE("PLAYER", "Player"), 250.0f
));
54 adminColumns
.push_back(GLWIconTable::Column(LANG_RESOURCE("TEAM", "Team"), 100.0f
));
55 adminTable_
= new GLWIconTable(10.0f
, 40.0f
, 560.0f
, 280.0f
, &adminColumns
, 20.0f
);
56 playerTab_
->addWidget(adminTable_
);
57 adminTable_
->setHandler(this);
59 std::map
<unsigned int, Tank
*> &tanks
=
60 ScorchedClient::instance()->getTankContainer().getPlayingTanks();
61 adminTable_
->setItemCount(tanks
.size());
64 GLWPanel
*buttonPanel
= new GLWPanel(10.0f
, 10.0f
, 600.0f
, 50.0f
, false, false);
65 kickButton_
= new GLWTextButton(LANG_RESOURCE("KICK", "Kick"), 0, 0, 80, this,
66 GLWButton::ButtonFlagCenterX
);
67 buttonPanel
->addWidget(kickButton_
, 0, SpaceRight
, 10.0f
);
68 banButton_
= new GLWTextButton(LANG_RESOURCE("BAN", "Ban"), 0, 0, 80, this,
69 GLWButton::ButtonFlagCenterX
);
70 buttonPanel
->addWidget(banButton_
, 0, SpaceRight
, 10.0f
);
71 slapButton_
= new GLWTextButton(LANG_RESOURCE("SLAP", "Slap"), 0, 0, 80, this,
72 GLWButton::ButtonFlagCenterX
);
73 buttonPanel
->addWidget(slapButton_
, 0, SpaceRight
, 10.0f
);
74 poorButton_
= new GLWTextButton(LANG_RESOURCE("POOR", "Poor"), 0, 0, 80, this,
75 GLWButton::ButtonFlagCenterX
);
76 buttonPanel
->addWidget(poorButton_
, 0, SpaceRight
, 10.0f
);
77 muteButton_
= new GLWTextButton(LANG_RESOURCE("MUTE", "Mute"), 0, 0, 80, this,
78 GLWButton::ButtonFlagCenterX
);
79 buttonPanel
->addWidget(muteButton_
, 0, SpaceRight
, 10.0f
);
80 unmuteButton_
= new GLWTextButton(LANG_RESOURCE("UNMUTE", "UnMute"), 0, 0, 80, this,
81 GLWButton::ButtonFlagCenterX
);
82 buttonPanel
->addWidget(unmuteButton_
, 0, SpaceRight
, 10.0f
);
83 buttonPanel
->setLayout(GLWPanel::LayoutHorizontal
);
84 playerTab_
->addWidget(buttonPanel
, 0, SpaceAll
, 10.0f
);
85 buttonPanel
->layout();
89 addWidget(new GLWTab("Bots", LANG_RESOURCE("BOTS", "Bots"), 10, 40, 580, 330));
91 aiSelector_
= (GLWDropDown
*) botsTab_
->addWidget(new GLWDropDownText(10, 150, 150));
94 std::list
<std::string
>::iterator itor
;
95 for (itor
= aiNames
.getAis().begin();
96 itor
!= aiNames
.getAis().end();
101 aiSelector_
->addEntry(GLWSelectorEntry(
102 LANG_STRING(*itor
), 0, false, 0, 0, *itor
));
105 addButton_
= (GLWTextButton
*)
106 botsTab_
->addWidget(new GLWTextButton(LANG_RESOURCE("ADD", "Add"), 10, 120, 80, this,
107 GLWButton::ButtonFlagCenterX
));
110 playerTab_
->setDepressed();
113 ok_
= (GLWTextButton
*) addWidget(
114 new GLWTextButton(LANG_RESOURCE("OK", "Ok"), 500, 10, 90, this,
115 GLWButton::ButtonFlagOk
| GLWButton::ButtonFlagCenterX
));
118 AdminDialog::~AdminDialog()
123 void AdminDialog::drawColumn(unsigned int id
, int row
, int col
,
124 float x
, float y
, float w
)
126 std::map
<unsigned int, Tank
*> &tanks
=
127 ScorchedClient::instance()->getTankContainer().getPlayingTanks();
128 adminTable_
->setItemCount(tanks
.size());
131 std::map
<unsigned int, Tank
*>::iterator itor
;
132 for (itor
= tanks
.begin();
140 GLWFont::instance()->getGameFont()->drawWidth(w
,
141 GLWFont::widgetFontColor
,
142 10.0f
, x
+ 3.0f
, y
+ 5.0f
, 0.0f
,
143 itor
->second
->getTargetName());
147 GLWFont::instance()->getGameFont()->drawWidth(w
,
148 TankColorGenerator::getTeamColor(itor
->second
->getTeam()),
149 10.0f
, x
+ 3.0f
, y
+ 5.0f
, 0.0f
,
150 TankColorGenerator::getTeamName(itor
->second
->getTeam()));
157 void AdminDialog::rowSelected(unsigned int id
, int row
)
162 void AdminDialog::rowChosen(unsigned int id
, int row
)
167 void AdminDialog::columnSelected(unsigned int id
, int col
)
172 void AdminDialog::display()
177 void AdminDialog::buttonDown(unsigned int id
)
179 std::map
<unsigned int, Tank
*> &tanks
=
180 ScorchedClient::instance()->getTankContainer().getPlayingTanks();
181 adminTable_
->setItemCount(tanks
.size());
183 unsigned int sid
= ClientAdminResultHandler::instance()->getSid();
184 unsigned int playerId
= 0;
186 std::map
<unsigned int, Tank
*>::iterator itor
;
187 for (itor
= tanks
.begin();
191 if (adminTable_
->getSelected() == pos
)
193 playerId
= itor
->second
->getPlayerId();
198 if (id
== ok_
->getId())
200 GLWWindowManager::instance()->hideWindow(id_
);
202 else if (id
== kickButton_
->getId())
204 ComsAdminMessage
message(sid
, ComsAdminMessage::AdminKick
,
205 S3D::formatStringBuffer("%u", playerId
));
206 ComsMessageSender::sendToServer(message
);
208 else if (id
== banButton_
->getId())
210 ComsAdminMessage
message(sid
, ComsAdminMessage::AdminBan
,
211 S3D::formatStringBuffer("%u", playerId
));
212 ComsMessageSender::sendToServer(message
);
214 else if (id
== slapButton_
->getId())
216 ComsAdminMessage
message(sid
, ComsAdminMessage::AdminSlap
,
217 S3D::formatStringBuffer("%u", playerId
), "10");
218 ComsMessageSender::sendToServer(message
);
220 else if (id
== poorButton_
->getId())
222 ComsAdminMessage
message(sid
, ComsAdminMessage::AdminPoor
,
223 S3D::formatStringBuffer("%u", playerId
));
224 ComsMessageSender::sendToServer(message
);
226 else if (id
== muteButton_
->getId())
228 ComsAdminMessage
message(sid
, ComsAdminMessage::AdminMute
,
229 S3D::formatStringBuffer("%u", playerId
));
230 ComsMessageSender::sendToServer(message
);
232 else if (id
== unmuteButton_
->getId())
234 ComsAdminMessage
message(sid
, ComsAdminMessage::AdminUnMute
,
235 S3D::formatStringBuffer("%u", playerId
));
236 ComsMessageSender::sendToServer(message
);
238 else if (id
== addButton_
->getId())
240 ComsAdminMessage
message(sid
, ComsAdminMessage::AdminAdd
,
241 aiSelector_
->getCurrentEntry()->getDataText());
242 ComsMessageSender::sendToServer(message
);