AdminDialog.cpp

Go to the documentation of this file.
00001 ////////////////////////////////////////////////////////////////////////////////
00002 //    Scorched3D (c) 2000-2009
00003 //
00004 //    This file is part of Scorched3D.
00005 //
00006 //    Scorched3D is free software; you can redistribute it and/or modify
00007 //    it under the terms of the GNU General Public License as published by
00008 //    the Free Software Foundation; either version 2 of the License, or
00009 //    (at your option) any later version.
00010 //
00011 //    Scorched3D is distributed in the hope that it will be useful,
00012 //    but WITHOUT ANY WARRANTY; without even the implied warranty of
00013 //    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00014 //    GNU General Public License for more details.
00015 //
00016 //    You should have received a copy of the GNU General Public License
00017 //    along with Scorched3D; if not, write to the Free Software
00018 //    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00019 ////////////////////////////////////////////////////////////////////////////////
00020 
00021 #include <dialogs/AdminDialog.h>
00022 #include <GLW/GLWWindowManager.h>
00023 #include <GLW/GLWDropDownText.h>
00024 #include <GLW/GLWFont.h>
00025 #include <tank/TankContainer.h>
00026 #include <tank/TankColorGenerator.h>
00027 #include <tankai/TankAINames.h>
00028 #include <client/ScorchedClient.h>
00029 #include <client/ClientAdminResultHandler.h>
00030 #include <coms/ComsAdminMessage.h>
00031 #include <coms/ComsMessageSender.h>
00032 
00033 AdminDialog *AdminDialog::instance_ = 0;
00034 
00035 AdminDialog *AdminDialog::instance()
00036 {
00037         if (!instance_)
00038         {
00039                 instance_ = new AdminDialog;
00040         }
00041         return instance_;
00042 }
00043 
00044 AdminDialog::AdminDialog() : 
00045         GLWWindow("", 600.0f, 400.0f, 0, "")
00046 {
00047         {
00048                 playerTab_ = (GLWTab *)
00049                         addWidget(new GLWTab("Player", LANG_RESOURCE("PLAYER", "Player"), 10, 40, 580, 330));
00050 
00051                 // Player Table
00052                 std::list<GLWIconTable::Column> adminColumns;
00053                 adminColumns.push_back(GLWIconTable::Column(LANG_RESOURCE("PLAYER", "Player"), 250.0f));
00054                 adminColumns.push_back(GLWIconTable::Column(LANG_RESOURCE("TEAM", "Team"), 100.0f));
00055                 adminTable_ = new GLWIconTable(10.0f, 40.0f, 560.0f, 280.0f, &adminColumns, 20.0f);
00056                 playerTab_->addWidget(adminTable_);
00057                 adminTable_->setHandler(this);
00058 
00059                 std::map<unsigned int, Tank *> &tanks = 
00060                         ScorchedClient::instance()->getTankContainer().getPlayingTanks();
00061                 adminTable_->setItemCount(tanks.size());
00062 
00063                 // Player Actions
00064                 GLWPanel *buttonPanel = new GLWPanel(10.0f, 10.0f, 600.0f, 50.0f, false, false);
00065                 kickButton_ = new GLWTextButton(LANG_RESOURCE("KICK", "Kick"), 0, 0, 80, this, 
00066                         GLWButton::ButtonFlagCenterX);
00067                 buttonPanel->addWidget(kickButton_, 0, SpaceRight, 10.0f);
00068                 banButton_ = new GLWTextButton(LANG_RESOURCE("BAN", "Ban"), 0, 0, 80, this, 
00069                         GLWButton::ButtonFlagCenterX);
00070                 buttonPanel->addWidget(banButton_, 0, SpaceRight, 10.0f);
00071                 slapButton_ = new GLWTextButton(LANG_RESOURCE("SLAP", "Slap"), 0, 0, 80, this, 
00072                         GLWButton::ButtonFlagCenterX);
00073                 buttonPanel->addWidget(slapButton_, 0, SpaceRight, 10.0f);
00074                 poorButton_ = new GLWTextButton(LANG_RESOURCE("POOR", "Poor"), 0, 0, 80, this, 
00075                         GLWButton::ButtonFlagCenterX);
00076                 buttonPanel->addWidget(poorButton_, 0, SpaceRight, 10.0f);
00077                 muteButton_ = new GLWTextButton(LANG_RESOURCE("MUTE", "Mute"), 0, 0, 80, this, 
00078                         GLWButton::ButtonFlagCenterX);
00079                 buttonPanel->addWidget(muteButton_, 0, SpaceRight, 10.0f);
00080                 unmuteButton_ = new GLWTextButton(LANG_RESOURCE("UNMUTE", "UnMute"), 0, 0, 80, this, 
00081                         GLWButton::ButtonFlagCenterX);
00082                 buttonPanel->addWidget(unmuteButton_, 0, SpaceRight, 10.0f);
00083                 buttonPanel->setLayout(GLWPanel::LayoutHorizontal);
00084                 playerTab_->addWidget(buttonPanel, 0, SpaceAll, 10.0f);
00085                 buttonPanel->layout();
00086         }
00087         {
00088                 botsTab_ = (GLWTab *)
00089                         addWidget(new GLWTab("Bots", LANG_RESOURCE("BOTS", "Bots"), 10, 40, 580, 330));
00090 
00091                 aiSelector_ = (GLWDropDown *) botsTab_->addWidget(new GLWDropDownText(10, 150, 150));
00092                 TankAINames aiNames;
00093                 aiNames.loadAIs();
00094                 std::list<std::string>::iterator itor;
00095                 for (itor = aiNames.getAis().begin();
00096                         itor != aiNames.getAis().end();
00097                         itor++)
00098                 {
00099                         if (*itor != "Human")
00100                         {
00101                                 aiSelector_->addEntry(GLWSelectorEntry(
00102                                         LANG_STRING(*itor), 0, false, 0, 0, *itor));
00103                         }
00104                 }
00105                 addButton_ = (GLWTextButton *)
00106                         botsTab_->addWidget(new GLWTextButton(LANG_RESOURCE("ADD", "Add"), 10, 120, 80, this, 
00107                         GLWButton::ButtonFlagCenterX));
00108         }
00109 
00110         playerTab_->setDepressed();
00111 
00112         // Ok
00113         ok_ = (GLWTextButton *) addWidget(
00114                 new GLWTextButton(LANG_RESOURCE("OK", "Ok"), 500, 10, 90, this, 
00115                 GLWButton::ButtonFlagOk | GLWButton::ButtonFlagCenterX));
00116 }
00117 
00118 AdminDialog::~AdminDialog()
00119 {
00120 
00121 }
00122 
00123 void AdminDialog::drawColumn(unsigned int id, int row, int col,
00124         float x, float y, float w)
00125 {
00126         std::map<unsigned int, Tank *> &tanks = 
00127                 ScorchedClient::instance()->getTankContainer().getPlayingTanks();
00128         adminTable_->setItemCount(tanks.size());
00129 
00130         int pos = 0;
00131         std::map<unsigned int, Tank *>::iterator itor;
00132         for (itor = tanks.begin();
00133                 itor != tanks.end();
00134                 itor++, pos++)
00135         {
00136                 if (pos == row) 
00137                 {
00138                         if (col == 0)
00139                         {
00140                                 GLWFont::instance()->getGameFont()->drawWidth(w, 
00141                                         GLWFont::widgetFontColor, 
00142                                         10.0f, x + 3.0f, y + 5.0f, 0.0f, 
00143                                         itor->second->getTargetName());
00144                         }
00145                         else
00146                         {
00147                                 GLWFont::instance()->getGameFont()->drawWidth(w, 
00148                                         TankColorGenerator::getTeamColor(itor->second->getTeam()),
00149                                         10.0f, x + 3.0f, y + 5.0f, 0.0f, 
00150                                         TankColorGenerator::getTeamName(itor->second->getTeam()));
00151                         }
00152                         break;
00153                 }
00154         }
00155 }
00156 
00157 void AdminDialog::rowSelected(unsigned int id, int row)
00158 {
00159 
00160 }
00161 
00162 void AdminDialog::rowChosen(unsigned int id, int row)
00163 {
00164 
00165 }
00166 
00167 void AdminDialog::columnSelected(unsigned int id, int col)
00168 {
00169         
00170 }
00171 
00172 void AdminDialog::display()
00173 {
00174 
00175 }
00176 
00177 void AdminDialog::buttonDown(unsigned int id)
00178 {
00179         std::map<unsigned int, Tank *> &tanks = 
00180                 ScorchedClient::instance()->getTankContainer().getPlayingTanks();
00181         adminTable_->setItemCount(tanks.size());
00182 
00183         unsigned int sid = ClientAdminResultHandler::instance()->getSid();
00184         unsigned int playerId = 0;
00185         int pos = 0;
00186         std::map<unsigned int, Tank *>::iterator itor;
00187         for (itor = tanks.begin();
00188                 itor != tanks.end();
00189                 itor++, pos++)
00190         {
00191                 if (adminTable_->getSelected() == pos)
00192                 {
00193                         playerId = itor->second->getPlayerId();
00194                         break;
00195                 }
00196         }
00197 
00198         if (id == ok_->getId())
00199         {
00200                 GLWWindowManager::instance()->hideWindow(id_);
00201         }
00202         else if (id == kickButton_->getId())
00203         {
00204                 ComsAdminMessage message(sid, ComsAdminMessage::AdminKick, 
00205                         S3D::formatStringBuffer("%u", playerId));
00206                 ComsMessageSender::sendToServer(message);
00207         }
00208         else if (id == banButton_->getId())
00209         {
00210                 ComsAdminMessage message(sid, ComsAdminMessage::AdminBan, 
00211                         S3D::formatStringBuffer("%u", playerId));
00212                 ComsMessageSender::sendToServer(message);
00213         }
00214         else if (id == slapButton_->getId())
00215         {
00216                 ComsAdminMessage message(sid, ComsAdminMessage::AdminSlap, 
00217                         S3D::formatStringBuffer("%u", playerId), "10");
00218                 ComsMessageSender::sendToServer(message);
00219         }
00220         else if (id == poorButton_->getId())
00221         {
00222                 ComsAdminMessage message(sid, ComsAdminMessage::AdminPoor,
00223                         S3D::formatStringBuffer("%u", playerId));
00224                 ComsMessageSender::sendToServer(message);
00225         }
00226         else if (id == muteButton_->getId())
00227         {
00228                 ComsAdminMessage message(sid, ComsAdminMessage::AdminMute, 
00229                         S3D::formatStringBuffer("%u", playerId));
00230                 ComsMessageSender::sendToServer(message);
00231         }
00232         else if (id == unmuteButton_->getId())
00233         {
00234                 ComsAdminMessage message(sid, ComsAdminMessage::AdminUnMute, 
00235                         S3D::formatStringBuffer("%u", playerId));
00236                 ComsMessageSender::sendToServer(message);
00237         }
00238         else if (id == addButton_->getId())
00239         {
00240                 ComsAdminMessage message(sid, ComsAdminMessage::AdminAdd, 
00241                         aiSelector_->getCurrentEntry()->getDataText());
00242                 ComsMessageSender::sendToServer(message);
00243         }
00244 }

Generated on Mon Feb 16 15:14:37 2009 for Scorched3D by  doxygen 1.5.3