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/AutoDefenseDialog.h>
22 #include <weapons/Accessory.h>
23 #include <GLW/GLWFlag.h>
24 #include <GLW/GLWTextButton.h>
25 #include <GLW/GLWWindowManager.h>
26 #include <tankgraph/TankKeyboardControlUtil.h>
27 #include <tank/TankContainer.h>
28 #include <tank/TankAccessories.h>
29 #include <tank/TankScore.h>
30 #include <target/TargetShield.h>
31 #include <target/TargetParachute.h>
32 #include <common/OptionsTransient.h>
33 #include <common/Defines.h>
34 #include <coms/ComsPlayedMoveMessage.h>
35 #include <coms/ComsMessageSender.h>
36 #include <client/ClientState.h>
37 #include <client/ClientDefenseHandler.h>
38 #include <client/ScorchedClient.h>
39 #include <lang/LangResource.h>
41 AutoDefenseDialog::AutoDefenseDialog() :
42 GLWWindow("Auto Defense", 10.0f
, 10.0f
, 440.0f
, 280.0f
, 0,
43 "Allows the current player to raise and\n"
44 "lower defenses before the round starts")
48 topPanel_
= (GLWPanel
*)
49 addWidget(new GLWPanel(10, 245, 420, 50),
50 0, SpaceLeft
| SpaceRight
| SpaceTop
, 10.0f
);
52 ddpara_
= (GLWDropDownText
*) addWidget(new GLWDropDownText(120, 170, 420),
53 0, SpaceLeft
| SpaceRight
| SpaceTop
, 10.0f
);
54 ddpara_
->setHandler(this);
55 ddpara_
->setToolTip(new ToolTip(ToolTip::ToolTipHelp
,
56 LANG_RESOURCE("ENABLE_PARACHUTES", "Enable Parachutes"),
57 LANG_RESOURCE("ENABLE_PARACHUTES_TOOLTIP", "Choose to enable parachutes before the\n"
58 "beginning of the next round.")));
59 ddshields_
= (GLWDropDownText
*) addWidget(new GLWDropDownText(120, 200, 420),
60 0, SpaceLeft
| SpaceRight
| SpaceTop
, 10.0f
);
61 ddshields_
->setToolTip(new ToolTip(ToolTip::ToolTipHelp
,
62 LANG_RESOURCE("CHOOSE_SHIELDS", "Choose Shields"),
63 LANG_RESOURCE("CHOOSE_SHIELDS_TOOLTIP", "Choose the shield to use at the beginning\n"
64 "of the next round.")));
65 ddshields_
->setHandler(this);
67 GLWPanel
*buttonPanel
= new GLWPanel(0.0f
, 0.0f
, 0.0f
, 0.0f
, false, false);
68 GLWButton
*cancelButton
= new GLWTextButton(LANG_RESOURCE("CANCEL", "Cancel"), 95, 10, 105, this,
69 GLWButton::ButtonFlagCancel
| GLWButton::ButtonFlagCenterX
);
70 cancelId_
= cancelButton
->getId();
71 buttonPanel
->addWidget(cancelButton
, 0, SpaceRight
, 10.0f
);
72 GLWButton
*okButton
= new GLWTextButton(LANG_RESOURCE("OK", "Ok"), 235, 10, 55, this,
73 GLWButton::ButtonFlagOk
| GLWButton::ButtonFlagCenterX
);
74 okId_
= okButton
->getId();
75 buttonPanel
->addWidget(okButton
);
76 buttonPanel
->setLayout(GLWPanel::LayoutHorizontal
);
77 addWidget(buttonPanel
, 0, SpaceAll
| AlignRight
, 10.0f
);
79 setLayout(GLWPanel::LayoutVerticle
);
83 AutoDefenseDialog::~AutoDefenseDialog()
88 void AutoDefenseDialog::windowInit(const unsigned state
)
90 Tank
*current
= ScorchedClient::instance()->getTankContainer().getCurrentTank();
97 if (current
->getDestinationId() ==
98 ScorchedClient::instance()->getTankContainer().getCurrentDestinationId() &&
99 current
->getAccessories().getAutoDefense().haveDefense())
110 void AutoDefenseDialog::buttonDown(unsigned int butid
)
114 Tank
*tank
= ScorchedClient::instance()->getTankContainer().getCurrentTank();
117 // Set Parachutes on/off
118 if (ddpara_
->getCurrentPosition() == 0)
120 TankKeyboardControlUtil::parachutesUpDown(tank
, 0);
124 std::list
<Accessory
*> ¶s
=
125 tank
->getAccessories().getAllAccessoriesByType(
126 AccessoryPart::AccessoryParachute
);
127 std::list
<Accessory
*>::iterator parasItor
= paras
.begin();
128 for (int i
=1; i
<ddpara_
->getCurrentPosition() && parasItor
!= paras
.end(); i
++) parasItor
++;
130 if (parasItor
!= paras
.end())
132 TankKeyboardControlUtil::parachutesUpDown(tank
,
133 (*parasItor
)->getAccessoryId());
137 // Set shields on/off
138 if (ddshields_
->getCurrentPosition() == 0)
140 TankKeyboardControlUtil::shieldsUpDown(tank
, 0);
144 std::list
<Accessory
*> &shields
=
145 tank
->getAccessories().getAllAccessoriesByType(
146 AccessoryPart::AccessoryShield
);
147 std::list
<Accessory
*>::iterator shieldsItor
= shields
.begin();
148 for (int i
=1; i
<ddshields_
->getCurrentPosition() && shieldsItor
!= shields
.end(); i
++) shieldsItor
++;
150 if (shieldsItor
!= shields
.end())
152 TankKeyboardControlUtil::shieldsUpDown(tank
,
153 (*shieldsItor
)->getAccessoryId());
160 else if (butid
== cancelId_
)
166 void AutoDefenseDialog::displayCurrent()
168 GLWWindowManager::instance()->showWindow(getId());
169 Tank
*tank
= ScorchedClient::instance()->getTankContainer().getCurrentTank();
172 // Put information at the top of the dialog
174 topPanel_
->addWidget(new GLWFlag(tank
->getColor(), 5, 15, 60));
175 topPanel_
->addWidget(new GLWLabel(75, 10, tank
->getTargetName()));
176 topPanel_
->addWidget(new GLWLabel(260, 20,
177 LANG_STRING(S3D::formatStringBuffer("$%i", tank
->getScore().getMoney()))));
178 topPanel_
->addWidget(new GLWLabel(260, 0,
179 LANG_RESOURCE_2("ROUND_OF", "Round {0} of {1}",
180 S3D::formatStringBuffer("%i", ScorchedClient::instance()->getOptionsTransient().getCurrentRoundNo()),
181 S3D::formatStringBuffer("%i", ScorchedClient::instance()->getOptionsGame().getNoRounds()))));
184 static ToolTip
shieldsOffTip(ToolTip::ToolTipHelp
,
185 LANG_RESOURCE("SHIELDS_OFF", "Shields Off"),
186 LANG_RESOURCE("SHIELDS_OFF_TOOLTIP", "Turns off shields."));
188 std::list
<Accessory
*>::iterator shieldsItor
;
189 std::list
<Accessory
*> &shields
=
190 tank
->getAccessories().getAllAccessoriesByType(
191 AccessoryPart::AccessoryShield
);
192 ddshields_
->addEntry(GLWSelectorEntry(LANG_RESOURCE("SHIELDS_OFF", "Shields Off"), &shieldsOffTip
));
193 for (shieldsItor
= shields
.begin();
194 shieldsItor
!= shields
.end();
197 Accessory
*shield
= (*shieldsItor
);
198 ddshields_
->addEntry(GLWSelectorEntry(
199 tank
->getAccessories().getAccessoryAndCountString(shield
),
200 &shield
->getToolTip(), 0, shield
->getTexture()));
204 static ToolTip
parachutesOffTip(ToolTip::ToolTipHelp
,
205 LANG_RESOURCE("PARACHUTES_OFF", "Parachutes Off"),
206 LANG_RESOURCE("PARACHUTES_OFF_TOOLTIP", "Turns off parachutes."));
208 std::list
<Accessory
*>::iterator parachutesItor
;
209 std::list
<Accessory
*> ¶chutes
=
210 tank
->getAccessories().getAllAccessoriesByType(
211 AccessoryPart::AccessoryParachute
);
212 ddpara_
->addEntry(GLWSelectorEntry(LANG_RESOURCE("PARACHUTES_OFF", "Parachutes Off"), ¶chutesOffTip
));
213 for (parachutesItor
= parachutes
.begin();
214 parachutesItor
!= parachutes
.end();
217 Accessory
*parachute
= (*parachutesItor
);
218 ddpara_
->addEntry(GLWSelectorEntry(
219 tank
->getAccessories().getAccessoryAndCountString(parachute
),
220 ¶chute
->getToolTip(), 0, parachute
->getTexture()));
223 // Set the currently shown items
224 Accessory
*currentShield
= tank
->getShield().getCurrentShield();
227 ddshields_
->setCurrentText(
228 tank
->getAccessories().getAccessoryAndCountString(currentShield
));
232 ddshields_
->setCurrentText(LANG_RESOURCE("SHIELDS_OFF", "Shields Off"));
235 // Set the currently shown items
236 Accessory
*currentParachute
= tank
->getParachute().getCurrentParachute();
237 if (currentParachute
)
239 ddpara_
->setCurrentText(
240 tank
->getAccessories().getAccessoryAndCountString(currentParachute
));
244 ddpara_
->setCurrentText(LANG_RESOURCE("PARACHUTES_OFF", "Parachutes Off"));
248 void AutoDefenseDialog::select(unsigned int id
,
250 GLWSelectorEntry value
)
252 // Nothing to do as we don't actualy set the status
253 // until the ok button is pressed
256 void AutoDefenseDialog::finished()
258 // send message saying we are finished with shot
259 ComsPlayedMoveMessage
comsMessage(
260 ScorchedClient::instance()->getTankContainer().getCurrentPlayerId(),
261 ComsPlayedMoveMessage::eFinishedBuy
);
262 ComsMessageSender::sendToServer(comsMessage
);
264 GLWWindowManager::instance()->hideWindow(getId());
265 ScorchedClient::instance()->getGameState().stimulate(ClientState::StimWait
);