InventoryDialog.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/InventoryDialog.h>
00022 #include <GLW/GLWTextButton.h>
00023 #include <GLW/GLWIcon.h>
00024 #include <GLW/GLWFlag.h>
00025 #include <GLW/GLWWindowManager.h>
00026 #include <GLEXT/GLViewPort.h>
00027 #include <client/ClientState.h>
00028 #include <client/ScorchedClient.h>
00029 #include <common/OptionsScorched.h>
00030 #include <graph/OptionsDisplay.h>
00031 #include <common/OptionsTransient.h>
00032 #include <common/Defines.h>
00033 #include <weapons/AccessoryStore.h>
00034 #include <tank/TankContainer.h>
00035 #include <tank/TankScore.h>
00036 #include <tank/TankAccessories.h>
00037 #include <stdio.h>
00038 
00039 InventoryDialog *InventoryDialog::instance_ = 0;
00040 
00041 InventoryDialog *InventoryDialog::instance()
00042 {
00043         if (!instance_) instance_ = new InventoryDialog;
00044         return instance_;
00045 }
00046 
00047 InventoryDialog::InventoryDialog() : 
00048         GLWWindow("Inventory", 10.0f, 10.0f, 440.0f, 300.0f, 0,
00049                 "Show the current weapon inventory")
00050 {
00051         okId_ = addWidget(new GLWTextButton(LANG_RESOURCE("OK", "Ok"), 375, 10, 55, this, 
00052                 GLWButton::ButtonFlagOk | GLWButton::ButtonFlagCenterX))->getId();
00053 
00054         sellTab_ = (GLWTab *)
00055                 addWidget(new GLWTab("Inv", LANG_RESOURCE("INVENTORY_TAB", "Inv"), 10, 40, 420, 160));
00056         topPanel_ = (GLWPanel *)
00057                 addWidget(new GLWPanel(10, 265, 420, 50));
00058 
00059         addWidget(new GLWLabel(15, 9, LANG_RESOURCE("SORT_LABEL", "Sort by:")));
00060 
00061         sortDropDown_ = (GLWDropDownText *) addWidget(new GLWDropDownText(100, 9, 100));
00062 
00063         sortDropDown_->addText(LANG_RESOURCE("SORT_NOTHING", "Nothing"), "Nothing");
00064         sortDropDown_->addText(LANG_RESOURCE("SORT_NAME", "Name"), "Name");
00065         sortDropDown_->addText(LANG_RESOURCE("SORT_PRICE", "Price"), "Price");
00066         sortDropDown_->setName("Sort");
00067         sortDropDown_->setHandler(this);
00068 }
00069 
00070 InventoryDialog::~InventoryDialog()
00071 {
00072 
00073 }
00074 
00075 void InventoryDialog::select(unsigned int id, const int pos, GLWSelectorEntry value)
00076 {
00077         if (id == sortDropDown_->getId())
00078         {
00079                 OptionsDisplay *display = OptionsDisplay::instance();
00080                 const char *dataText = value.getDataText();
00081 
00082                 if (strcmp(dataText, "Name") == 0)
00083                         display->getAccessorySortKeyEntry().setValue(AccessoryStore::SortName);
00084                 else if (strcmp(dataText, "Price") == 0)
00085                         display->getAccessorySortKeyEntry().setValue(AccessoryStore::SortPrice);
00086                 else
00087                         display->getAccessorySortKeyEntry().setValue(AccessoryStore::SortNothing);
00088 
00089                 playerRefresh();
00090         }
00091 }
00092 
00093 void InventoryDialog::display()
00094 {
00095         sortDropDown_->setHandler(0);
00096 
00097         switch (OptionsDisplay::instance()->getAccessorySortKey())
00098         {
00099         case AccessoryStore::SortName:
00100                 sortDropDown_->setCurrentText(LANG_RESOURCE("SORT_NAME", "Name"));
00101                 break;
00102 
00103         case AccessoryStore::SortPrice:
00104                 sortDropDown_->setCurrentText(LANG_RESOURCE("SORT_PRICE", "Price"));
00105                 break;
00106 
00107         case AccessoryStore::SortNothing:
00108                 sortDropDown_->setCurrentText(LANG_RESOURCE("SORT_NOTHING", "Nothing"));
00109                 break;
00110         }
00111 
00112         sortDropDown_->setHandler(this);
00113 
00114         playerRefresh();
00115 }
00116 
00117 void InventoryDialog::setupWindow()
00118 {
00119         float screenHeight = (float) GLViewPort::getHeight();
00120         float addition = 0;
00121         if (screenHeight > 340) addition = screenHeight - 340;
00122         if (addition > 200) addition = 200;
00123 
00124         setH(300 + addition);
00125         sellTab_->setH(160 + addition);
00126         topPanel_->setY(240 + addition);
00127 
00128         needCentered_ = true;
00129 }
00130 
00131 void InventoryDialog::addPlayerName()
00132 {
00133         topPanel_->clear();
00134 
00135         Tank *tank = ScorchedClient::instance()->getTankContainer().getCurrentTank();
00136         if (!tank) return;
00137 
00138         topPanel_->addWidget(new GLWFlag(tank->getColor(), 5, 15, 60));
00139         topPanel_->addWidget(new GLWLabel(75, 10, tank->getTargetName()));
00140         topPanel_->addWidget(new GLWLabel(260, 20, 
00141                 LANG_STRING(S3D::formatStringBuffer("$%i", tank->getScore().getMoney()))));
00142         topPanel_->addWidget(new GLWLabel(260, 0,
00143                 LANG_RESOURCE_2("ROUND_OF", "Round {0} of {1}",
00144                 S3D::formatStringBuffer("%i", ScorchedClient::instance()->getOptionsTransient().getCurrentRoundNo()),
00145                 S3D::formatStringBuffer("%i", ScorchedClient::instance()->getOptionsGame().getNoRounds()))));
00146 }
00147 
00148 void InventoryDialog::addPlayerWeapons()
00149 {
00150         sellTab_->clear();
00151 
00152         int height = 10;
00153 
00154         Tank *tank = ScorchedClient::instance()->getTankContainer().getCurrentTank();
00155         if (!tank) return;
00156 
00157         std::list<Accessory *> tankAccessories;
00158         tank->getAccessories().getAllAccessories(tankAccessories);
00159         ScorchedClient::instance()->getAccessoryStore().sortList(tankAccessories, 
00160                 OptionsDisplay::instance()->getAccessorySortKey());
00161 
00162         std::list<Accessory *>::reverse_iterator itor;
00163         for (itor = tankAccessories.rbegin();
00164                 itor != tankAccessories.rend();
00165                 itor++)
00166         {
00167                 Accessory *current = *itor;
00168                 int count = tank->getAccessories().getAccessoryCount(current);
00169 
00170                 GLWPanel *newPanel = (GLWPanel *)
00171                         sellTab_->addWidget(new GLWPanel(10.0f, (float) height, 315.0f, 20.0f, true));
00172                 newPanel->setToolTip(&current->getToolTip());
00173                 newPanel->addWidget(new GLWLabel(0, -2, tank->getAccessories().getAccessoryCountString(current)));
00174                 newPanel->addWidget(new GLWIcon(30, 2, 16, 16, current->getTexture()));
00175                 newPanel->addWidget(new GLWLabel(50, -2, LANG_RESOURCE(current->getName(), current->getName())));
00176                 newPanel->addWidget(new GLWLabel(205, -2, 
00177                         LANG_STRING(S3D::formatStringBuffer("$%i/%i", current->getSellPrice(), 1))));
00178 
00179                 height += 24;
00180         }
00181 }
00182 
00183 void InventoryDialog::playerRefresh()
00184 {
00185         setupWindow();
00186         addPlayerName();
00187         addPlayerWeapons();
00188 }
00189 
00190 void InventoryDialog::windowInit(const unsigned state)
00191 {
00192         Tank *tank = ScorchedClient::instance()->getTankContainer().getCurrentTank();
00193         if (tank)
00194         {
00195                 playerRefresh();
00196         }
00197 }
00198 
00199 void InventoryDialog::buttonDown(unsigned int id)
00200 {
00201         if (id == okId_)
00202         {
00203                 GLWWindowManager::instance()->hideWindow(getId());
00204         }
00205 }
00206 

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