AutoDefenseDialog.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/AutoDefenseDialog.h>
00022 #include <weapons/Accessory.h>
00023 #include <GLW/GLWFlag.h>
00024 #include <GLW/GLWTextButton.h>
00025 #include <GLW/GLWWindowManager.h>
00026 #include <tankgraph/TankKeyboardControlUtil.h>
00027 #include <tank/TankContainer.h>
00028 #include <tank/TankAccessories.h>
00029 #include <tank/TankScore.h>
00030 #include <target/TargetShield.h>
00031 #include <target/TargetParachute.h>
00032 #include <common/OptionsTransient.h>
00033 #include <common/Defines.h>
00034 #include <coms/ComsPlayedMoveMessage.h>
00035 #include <coms/ComsMessageSender.h>
00036 #include <client/ClientState.h>
00037 #include <client/ClientDefenseHandler.h>
00038 #include <client/ScorchedClient.h>
00039 #include <lang/LangResource.h>
00040 
00041 AutoDefenseDialog::AutoDefenseDialog() :
00042         GLWWindow("Auto Defense", 10.0f, 10.0f, 440.0f, 280.0f, 0,
00043                 "Allows the current player to raise and\n"
00044                 "lower defenses before the round starts")
00045 {
00046         needCentered_ = true;
00047 
00048         topPanel_ = (GLWPanel *)
00049                 addWidget(new GLWPanel(10, 245, 420, 50),
00050                 0, SpaceLeft | SpaceRight | SpaceTop, 10.0f);
00051 
00052         ddpara_ = (GLWDropDownText *) addWidget(new GLWDropDownText(120, 170, 420),
00053                 0, SpaceLeft | SpaceRight | SpaceTop, 10.0f);
00054         ddpara_->setHandler(this);
00055         ddpara_->setToolTip(new ToolTip(ToolTip::ToolTipHelp, 
00056                 LANG_RESOURCE("ENABLE_PARACHUTES", "Enable Parachutes"),
00057                 LANG_RESOURCE("ENABLE_PARACHUTES_TOOLTIP", "Choose to enable parachutes before the\n"
00058                 "beginning of the next round.")));
00059         ddshields_ = (GLWDropDownText *) addWidget(new GLWDropDownText(120, 200, 420),
00060                 0, SpaceLeft | SpaceRight | SpaceTop, 10.0f);
00061         ddshields_->setToolTip(new ToolTip(ToolTip::ToolTipHelp, 
00062                 LANG_RESOURCE("CHOOSE_SHIELDS", "Choose Shields"),
00063                 LANG_RESOURCE("CHOOSE_SHIELDS_TOOLTIP", "Choose the shield to use at the beginning\n"
00064                 "of the next round.")));
00065         ddshields_->setHandler(this);
00066 
00067         GLWPanel *buttonPanel = new GLWPanel(0.0f, 0.0f, 0.0f, 0.0f, false, false);
00068         GLWButton *cancelButton = new GLWTextButton(LANG_RESOURCE("CANCEL", "Cancel"), 95, 10, 105, this, 
00069                 GLWButton::ButtonFlagCancel | GLWButton::ButtonFlagCenterX);
00070         cancelId_ = cancelButton->getId();
00071         buttonPanel->addWidget(cancelButton, 0, SpaceRight, 10.0f);
00072         GLWButton *okButton = new GLWTextButton(LANG_RESOURCE("OK", "Ok"), 235, 10, 55, this, 
00073                 GLWButton::ButtonFlagOk | GLWButton::ButtonFlagCenterX);
00074         okId_ = okButton->getId();
00075         buttonPanel->addWidget(okButton);
00076         buttonPanel->setLayout(GLWPanel::LayoutHorizontal);
00077         addWidget(buttonPanel, 0, SpaceAll | AlignRight, 10.0f);
00078 
00079         setLayout(GLWPanel::LayoutVerticle);
00080         layout();
00081 }
00082 
00083 AutoDefenseDialog::~AutoDefenseDialog()
00084 {
00085 
00086 }
00087 
00088 void AutoDefenseDialog::windowInit(const unsigned state)
00089 {
00090         Tank *current = ScorchedClient::instance()->getTankContainer().getCurrentTank();
00091         if (!current) 
00092         {
00093                 finished();
00094         }
00095         else
00096         {
00097                 if (current->getDestinationId() == 
00098                         ScorchedClient::instance()->getTankContainer().getCurrentDestinationId() &&
00099                         current->getAccessories().getAutoDefense().haveDefense())
00100                 {
00101                         displayCurrent();
00102                 }
00103                 else
00104                 {
00105                         finished();
00106                 }
00107         }
00108 }
00109 
00110 void AutoDefenseDialog::buttonDown(unsigned int butid)
00111 {
00112         if (butid == okId_)
00113         {
00114                 Tank *tank = ScorchedClient::instance()->getTankContainer().getCurrentTank();
00115                 if (tank)
00116                 {
00117                         // Set Parachutes on/off
00118                         if (ddpara_->getCurrentPosition() == 0)
00119                         {
00120                                 TankKeyboardControlUtil::parachutesUpDown(tank, 0);
00121                         }
00122                         else
00123                         {
00124                                 std::list<Accessory *> &paras =
00125                                         tank->getAccessories().getAllAccessoriesByType(
00126                                                 AccessoryPart::AccessoryParachute);
00127                                 std::list<Accessory *>::iterator parasItor = paras.begin();
00128                                 for (int i=1; i<ddpara_->getCurrentPosition() && parasItor != paras.end(); i++) parasItor++;
00129                                 
00130                                 if (parasItor != paras.end())
00131                                 {
00132                                         TankKeyboardControlUtil::parachutesUpDown(tank, 
00133                                                 (*parasItor)->getAccessoryId());
00134                                 }
00135                         }
00136 
00137                         // Set shields on/off
00138                         if (ddshields_->getCurrentPosition() == 0)
00139                         {
00140                                 TankKeyboardControlUtil::shieldsUpDown(tank, 0);
00141                         }
00142                         else
00143                         {
00144                                 std::list<Accessory *> &shields =
00145                                         tank->getAccessories().getAllAccessoriesByType(
00146                                                 AccessoryPart::AccessoryShield);
00147                                 std::list<Accessory *>::iterator shieldsItor = shields.begin();
00148                                 for (int i=1; i<ddshields_->getCurrentPosition() && shieldsItor != shields.end(); i++) shieldsItor++;
00149                                 
00150                                 if (shieldsItor != shields.end())
00151                                 {
00152                                         TankKeyboardControlUtil::shieldsUpDown(tank,
00153                                                 (*shieldsItor)->getAccessoryId());
00154                                 }
00155                         }
00156                 }
00157 
00158                 finished();
00159         }
00160         else if (butid == cancelId_)
00161         {
00162                 finished();
00163         }
00164 }
00165 
00166 void AutoDefenseDialog::displayCurrent()
00167 {
00168         GLWWindowManager::instance()->showWindow(getId());
00169         Tank *tank = ScorchedClient::instance()->getTankContainer().getCurrentTank();
00170         if (!tank) return;
00171 
00172         // Put information at the top of the dialog
00173         topPanel_->clear();
00174         topPanel_->addWidget(new GLWFlag(tank->getColor(), 5, 15, 60));
00175         topPanel_->addWidget(new GLWLabel(75, 10, tank->getTargetName()));
00176         topPanel_->addWidget(new GLWLabel(260, 20, 
00177                 LANG_STRING(S3D::formatStringBuffer("$%i", tank->getScore().getMoney()))));
00178         topPanel_->addWidget(new GLWLabel(260, 0,
00179                 LANG_RESOURCE_2("ROUND_OF", "Round {0} of {1}",
00180                 S3D::formatStringBuffer("%i", ScorchedClient::instance()->getOptionsTransient().getCurrentRoundNo()),
00181                 S3D::formatStringBuffer("%i", ScorchedClient::instance()->getOptionsGame().getNoRounds()))));
00182 
00183         // Put shields info
00184         static ToolTip shieldsOffTip(ToolTip::ToolTipHelp, 
00185                 LANG_RESOURCE("SHIELDS_OFF", "Shields Off"),
00186                 LANG_RESOURCE("SHIELDS_OFF_TOOLTIP", "Turns off shields."));
00187         ddshields_->clear();
00188         std::list<Accessory *>::iterator shieldsItor;
00189         std::list<Accessory *> &shields =
00190                 tank->getAccessories().getAllAccessoriesByType(
00191                         AccessoryPart::AccessoryShield);
00192         ddshields_->addEntry(GLWSelectorEntry(LANG_RESOURCE("SHIELDS_OFF", "Shields Off"), &shieldsOffTip));
00193         for (shieldsItor = shields.begin();
00194                 shieldsItor != shields.end();
00195                 shieldsItor++)
00196         {
00197                 Accessory *shield = (*shieldsItor);
00198                 ddshields_->addEntry(GLWSelectorEntry(
00199                         tank->getAccessories().getAccessoryAndCountString(shield),
00200                         &shield->getToolTip(), 0, shield->getTexture()));
00201         }
00202 
00203         // Put paras info
00204         static ToolTip parachutesOffTip(ToolTip::ToolTipHelp, 
00205                 LANG_RESOURCE("PARACHUTES_OFF", "Parachutes Off"),
00206                 LANG_RESOURCE("PARACHUTES_OFF_TOOLTIP", "Turns off parachutes."));
00207         ddpara_->clear();
00208         std::list<Accessory *>::iterator parachutesItor;
00209         std::list<Accessory *> &parachutes =
00210                 tank->getAccessories().getAllAccessoriesByType(
00211                         AccessoryPart::AccessoryParachute);
00212         ddpara_->addEntry(GLWSelectorEntry(LANG_RESOURCE("PARACHUTES_OFF", "Parachutes Off"), &parachutesOffTip));
00213         for (parachutesItor = parachutes.begin();
00214                 parachutesItor != parachutes.end();
00215                 parachutesItor++)
00216         {
00217                 Accessory *parachute = (*parachutesItor);
00218                 ddpara_->addEntry(GLWSelectorEntry(
00219                         tank->getAccessories().getAccessoryAndCountString(parachute),
00220                         &parachute->getToolTip(), 0, parachute->getTexture()));
00221         }
00222 
00223         // Set the currently shown items
00224         Accessory *currentShield = tank->getShield().getCurrentShield();
00225         if (currentShield)
00226         {
00227                 ddshields_->setCurrentText(
00228                         tank->getAccessories().getAccessoryAndCountString(currentShield));
00229         }
00230         else
00231         {
00232                 ddshields_->setCurrentText(LANG_RESOURCE("SHIELDS_OFF", "Shields Off"));
00233         }
00234 
00235         // Set the currently shown items
00236         Accessory *currentParachute = tank->getParachute().getCurrentParachute();
00237         if (currentParachute)
00238         {
00239                 ddpara_->setCurrentText(
00240                         tank->getAccessories().getAccessoryAndCountString(currentParachute));
00241         }
00242         else
00243         {
00244                 ddpara_->setCurrentText(LANG_RESOURCE("PARACHUTES_OFF", "Parachutes Off"));
00245         }
00246 }
00247 
00248 void AutoDefenseDialog::select(unsigned int id, 
00249                                                            const int pos, 
00250                                                            GLWSelectorEntry value)
00251 {
00252         // Nothing to do as we don't actualy set the status
00253         // until the ok button is pressed
00254 }
00255 
00256 void AutoDefenseDialog::finished()
00257 {
00258         // send message saying we are finished with shot
00259         ComsPlayedMoveMessage comsMessage(
00260                 ScorchedClient::instance()->getTankContainer().getCurrentPlayerId(), 
00261                 ComsPlayedMoveMessage::eFinishedBuy);
00262         ComsMessageSender::sendToServer(comsMessage);
00263 
00264         GLWWindowManager::instance()->hideWindow(getId());
00265         ScorchedClient::instance()->getGameState().stimulate(ClientState::StimWait);
00266 }

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