00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021 #include <dialogs/GiftMoneyDialog.h>
00022 #include <dialogs/BuyAccessoryDialog.h>
00023 #include <graph/OptionsDisplay.h>
00024 #include <client/ScorchedClient.h>
00025 #include <tank/TankContainer.h>
00026 #include <tank/TankScore.h>
00027 #include <tank/TankState.h>
00028 #include <GLW/GLWTextButton.h>
00029 #include <GLW/GLWWindowManager.h>
00030 #include <coms/ComsGiftMoneyMessage.h>
00031 #include <coms/ComsMessageSender.h>
00032
00033 GiftMoneyDialog *GiftMoneyDialog::instance_ = 0;
00034
00035 GiftMoneyDialog *GiftMoneyDialog::instance()
00036 {
00037 if (!instance_)
00038 {
00039 instance_ = new GiftMoneyDialog;
00040 }
00041 return instance_;
00042 }
00043
00044 GiftMoneyDialog::GiftMoneyDialog() :
00045 GLWWindow("", 10.0f, 10.0f, 300.0f, 70.0f, eSmallTitle,
00046 "Send money to other team players")
00047 {
00048 needCentered_ = true;
00049
00050 GLWPanel *mainPanel = new GLWPanel(0.0f, 0.0f, 0.0f, 0.0f, false, false);
00051 mainPanel->addWidget(
00052 new GLWLabel(0.0f, 0.0f, LANG_RESOURCE("GIFT", "Gift")),
00053 0, SpaceRight, 10.0f);
00054 money_ = (GLWDropDownText *) mainPanel->addWidget(
00055 new GLWDropDownText(0.0f, 0.0f, 150.0f),
00056 0, SpaceRight, 10.0f);
00057 mainPanel->addWidget(
00058 new GLWLabel(0.0f, 0.0f, LANG_RESOURCE("TO", "to")),
00059 0, SpaceRight, 10.0f);
00060 players_ = (GLWDropDownText *) mainPanel->addWidget(
00061 new GLWDropDownText(0.0f, 0.0f, 150.0f));
00062 mainPanel->setLayout(GLWPanel::LayoutHorizontal);
00063 addWidget(mainPanel, 0, SpaceLeft | SpaceRight | SpaceTop, 10.0f);
00064
00065 GLWPanel *buttonPanel = new GLWPanel(0.0f, 0.0f, 0.0f, 0.0f, false, false);
00066 GLWButton *cancelButton = new GLWTextButton(LANG_RESOURCE("CANCEL", "Cancel"), 95, 10, 105, this,
00067 GLWButton::ButtonFlagCancel | GLWButton::ButtonFlagCenterX);
00068 cancelId_ = cancelButton->getId();
00069 buttonPanel->addWidget(cancelButton, 0, SpaceRight, 10.0f);
00070 GLWButton *okButton = new GLWTextButton(LANG_RESOURCE("OK", "Ok"), 235, 10, 55, this,
00071 GLWButton::ButtonFlagOk | GLWButton::ButtonFlagCenterX);
00072 okId_ = okButton->getId();
00073 buttonPanel->addWidget(okButton);
00074 buttonPanel->setLayout(GLWPanel::LayoutHorizontal);
00075 addWidget(buttonPanel, 0, SpaceAll, 10.0f);
00076
00077 setLayout(GLWPanel::LayoutVerticle);
00078 layout();
00079 }
00080
00081 GiftMoneyDialog::~GiftMoneyDialog()
00082 {
00083 }
00084
00085 void GiftMoneyDialog::display()
00086 {
00087 GLWWindow::display();
00088
00089 players_->clear();
00090 money_->clear();
00091
00092
00093 Tank *currentTank =
00094 ScorchedClient::instance()->getTankContainer().getCurrentTank();
00095 if (!currentTank)
00096 {
00097 GLWWindowManager::instance()->hideWindow(getId());
00098 return;
00099 }
00100
00101
00102 if (currentTank->getScore().getMoney() >= 1000)
00103 money_->addEntry(GLWSelectorEntry(LANG_RESOURCE("1000_DOLLARS", "$1000"), 0, false, 0, (void *) 1000));
00104 if (currentTank->getScore().getMoney() >= 2500)
00105 money_->addEntry(GLWSelectorEntry(LANG_RESOURCE("2500_DOLLARS", "$2500"), 0, false, 0, (void *) 2500));
00106 if (currentTank->getScore().getMoney() >= 5000)
00107 money_->addEntry(GLWSelectorEntry(LANG_RESOURCE("5000_DOLLARS", "$5000"), 0, false, 0, (void *) 5000));
00108 if (currentTank->getScore().getMoney() >= 10000)
00109 money_->addEntry(GLWSelectorEntry(LANG_RESOURCE("10000_DOLLARS", "$10000"), 0, false, 0, (void *) 10000));
00110 if (currentTank->getScore().getMoney() >= 15000)
00111 money_->addEntry(GLWSelectorEntry(LANG_RESOURCE("15000_DOLLARS", "$15000"), 0, false, 0, (void *) 15000));
00112 if (currentTank->getScore().getMoney() >= 20000)
00113 money_->addEntry(GLWSelectorEntry(LANG_RESOURCE("20000_DOLLARS", "$20000"), 0, false, 0, (void *) 20000));
00114 if (currentTank->getScore().getMoney() >= 25000)
00115 money_->addEntry(GLWSelectorEntry(LANG_RESOURCE("25000_DOLLARS", "$25000"), 0, false, 0, (void *) 25000));
00116
00117
00118 std::map<unsigned int, Tank *> &tanks =
00119 ScorchedClient::instance()->getTankContainer().getPlayingTanks();
00120 std::map<unsigned int, Tank *>::iterator itor;
00121 for (itor = tanks.begin();
00122 itor != tanks.end();
00123 itor++)
00124 {
00125 Tank *tank = itor->second;
00126 if (tank->getTeam() == currentTank->getTeam() &&
00127 !tank->getState().getSpectator() &&
00128 tank != currentTank &&
00129 (tank->getState().getState() == TankState::sDead ||
00130 tank->getState().getState() == TankState::sNormal))
00131 {
00132 players_->addEntry(GLWSelectorEntry(
00133 tank->getTargetName(), 0, false, 0, (void *) tank->getPlayerId()));
00134 }
00135 }
00136 }
00137
00138 void GiftMoneyDialog::buttonDown(unsigned int id)
00139 {
00140 if (id == okId_)
00141 {
00142 if (money_->getCurrentEntry() &&
00143 players_->getCurrentEntry())
00144 {
00145 int money = (int)
00146 long(money_->getCurrentEntry()->getUserData());
00147 unsigned int playerId = (unsigned int)
00148 long(players_->getCurrentEntry()->getUserData());
00149
00150 Tank *currentTank =
00151 ScorchedClient::instance()->getTankContainer().getCurrentTank();
00152 if (currentTank)
00153 {
00154 ComsGiftMoneyMessage message(
00155 currentTank->getPlayerId(), playerId, money);
00156 ComsMessageSender::sendToServer(message);
00157 }
00158 }
00159 }
00160 GLWWindowManager::instance()->hideWindow(getId());
00161 GLWWindowManager::instance()->showWindow(
00162 BuyAccessoryDialog::instance()->getId());
00163 }