Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/pickups2/src/orxonox/objects/pickup/PickupInventory.cc @ 2972

Last change on this file since 2972 was 2972, checked in by danielh, 15 years ago

Update

  • Minor changes in BaseItem
  • Updated to NotificationQueue from trunk (compile error with old)
  • Added PickupInventory for GUI handling
  • Added basic support for toLua++ methods
File size: 7.4 KB
Line 
1/*
2 *   ORXONOX - the hottest 3D action shooter ever to exist
3 *                    > www.orxonox.net <
4 *
5 *
6 *   License notice:
7 *
8 *   This program is free software; you can redistribute it and/or
9 *   modify it under the terms of the GNU General Public License
10 *   as published by the Free Software Foundation; either version 2
11 *   of the License, or (at your option) any later version.
12 *
13 *   This program is distributed in the hope that it will be useful,
14 *   but WITHOUT ANY WARRANTY; without even the implied warranty of
15 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16 *   GNU General Public License for more details.
17 *
18 *   You should have received a copy of the GNU General Public License
19 *   along with this program; if not, write to the Free Software
20 *   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
21 *
22 *   Author:
23 *      Daniel 'Huty' Haggenmueller
24 *   Co-authors:
25 *      ...
26 *
27 */
28
29#include "PickupInventory.h"
30
31#include "EquipmentItem.h"
32#include "UsableItem.h"
33#include "PassiveItem.h"
34
35#include "core/CoreIncludes.h"
36#include "core/ConsoleCommand.h"
37#include "core/input/InputManager.h"
38
39#include "gui/GUIManager.h"
40#include "objects/controllers/HumanController.h"
41#include "objects/worldentities/pawns/SpaceShip.h"
42
43#include <CEGUIImagesetManager.h>
44#include <CEGUIWindow.h>
45#include <elements/CEGUITabControl.h>
46
47namespace orxonox
48{
49    orxonox::ConsoleCommand& function_PickupInventory_ToggleInventory_0 =
50        orxonox::CommandExecutor::addConsoleCommandShortcut(orxonox::createConsoleCommand(orxonox::createFunctor(&PickupInventory::toggleInventory), "toggleInventory"), true);
51
52    static bool bInventoryVisible_ = false;
53    void PickupInventory::toggleInventory()
54    {
55        if(bInventoryVisible_) {
56            GUIManager::getInstancePtr()->executeCode("hideGUI(\"PickupInventory\")");
57            GUIManager::getInstancePtr()->executeCode("hideCursor()");
58            InputManager::getInstance().requestLeaveState("guiMouseOnly");
59        }
60        else
61        {
62            GUIManager::getInstancePtr()->showGUI("PickupInventory");
63            GUIManager::getInstancePtr()->executeCode("showCursor()");
64            InputManager::getInstance().requestEnterState("guiMouseOnly");
65        }
66        bInventoryVisible_ = !bInventoryVisible_;
67    }
68    void PickupInventory::tabChanged(CEGUI::Window *tab)
69    {
70        CEGUI::TabControl* tabCtrl = dynamic_cast<CEGUI::TabControl*>(tab);
71        if(tabCtrl != NULL)
72        {
73            COUT(1) << "tabChanged() tab index: " << tabCtrl->getSelectedTabIndex() << std::endl;
74        }
75        else
76        {
77            COUT(1) << "tabChanged() argument is no CEGUI::TabControl!" << std::endl;
78        }
79    }
80    unsigned int PickupInventory::getEquipmentCount()
81    {
82        if (HumanController::getLocalControllerSingleton() && HumanController::getLocalControllerSingleton()->getControllableEntity())
83        {
84            Pawn* pawn = dynamic_cast<Pawn*>(HumanController::getLocalControllerSingleton()->getControllableEntity());
85            if(pawn)
86                return pawn->getPickups().getEquipmentItems().size();
87
88        }
89        return 0;
90    }
91    unsigned int PickupInventory::getUsableCount()
92    {
93        if (HumanController::getLocalControllerSingleton() && HumanController::getLocalControllerSingleton()->getControllableEntity())
94        {
95            Pawn* pawn = dynamic_cast<Pawn*>(HumanController::getLocalControllerSingleton()->getControllableEntity());
96            if(pawn)
97                return pawn->getPickups().getUsableItems().size();
98
99        }
100        return 0;
101    }
102    unsigned int PickupInventory::getPassiveCount()
103    {
104        if (HumanController::getLocalControllerSingleton() && HumanController::getLocalControllerSingleton()->getControllableEntity())
105        {
106            Pawn* pawn = dynamic_cast<Pawn*>(HumanController::getLocalControllerSingleton()->getControllableEntity());
107            if(pawn)
108                return pawn->getPickups().getPassiveItems().size();
109
110        }
111        return 0;
112    }
113    EquipmentItem* PickupInventory::getEquipmentItem(unsigned int i)
114    {
115        if (HumanController::getLocalControllerSingleton() && HumanController::getLocalControllerSingleton()->getControllableEntity())
116        {
117            Pawn* pawn = dynamic_cast<Pawn*>(HumanController::getLocalControllerSingleton()->getControllableEntity());
118            if(pawn)
119            {
120                std::deque<EquipmentItem*> l = pawn->getPickups().getEquipmentItems();
121                if (i >= l.size()) { return NULL; }
122                return l.at(i);
123            }
124
125        }
126        return NULL;
127    }
128    UsableItem* PickupInventory::getUsableItem(unsigned int i)
129    {
130        if (HumanController::getLocalControllerSingleton() && HumanController::getLocalControllerSingleton()->getControllableEntity())
131        {
132            Pawn* pawn = dynamic_cast<Pawn*>(HumanController::getLocalControllerSingleton()->getControllableEntity());
133            if(pawn)
134            {
135                std::deque<UsableItem*> l = pawn->getPickups().getUsableItems();
136                if (i >= l.size()) { return NULL; }
137                return l.at(i);
138            }
139
140        }
141        return NULL;
142    }
143    PassiveItem* PickupInventory::getPassiveItem(unsigned int i)
144    {
145        if (HumanController::getLocalControllerSingleton() && HumanController::getLocalControllerSingleton()->getControllableEntity())
146        {
147            Pawn* pawn = dynamic_cast<Pawn*>(HumanController::getLocalControllerSingleton()->getControllableEntity());
148            if(pawn)
149            {
150                std::deque<PassiveItem*> l = pawn->getPickups().getPassiveItems();
151                if (i >= l.size()) { return NULL; }
152                return l.at(i);
153            }
154
155        }
156        return NULL;
157    }
158    std::string PickupInventory::getImagesetForEquipment(unsigned int i)
159    {
160        EquipmentItem* item = PickupInventory::getEquipmentItem(i);
161        if(!item)
162            return "";
163
164        std::string name = "pickup_" + item->getGUIImage();
165
166        if(!CEGUI::ImagesetManager::getSingletonPtr()->isImagesetPresent(name)) {
167            CEGUI::ImagesetManager::getSingletonPtr()->createImagesetFromImageFile(name, item->getGUIImage(), "pickups");
168        }
169
170        return name;
171    }
172    std::string PickupInventory::getImagesetForUsable(unsigned int i)
173    {
174        UsableItem* item = PickupInventory::getUsableItem(i);
175        if(!item)
176            return "";
177
178        std::string name = "pickup_" + item->getGUIImage();
179
180        if(!CEGUI::ImagesetManager::getSingletonPtr()->isImagesetPresent(name)) {
181            CEGUI::ImagesetManager::getSingletonPtr()->createImagesetFromImageFile(name, item->getGUIImage(), "pickups");
182        }
183
184        return name;
185    }
186    std::string PickupInventory::getImagesetForPassive(unsigned int i)
187    {
188        PassiveItem* item = PickupInventory::getPassiveItem(i);
189        if(!item)
190            return "";
191
192        std::string name = "pickup_" + item->getGUIImage();
193
194        if(!CEGUI::ImagesetManager::getSingletonPtr()->isImagesetPresent(name)) {
195            CEGUI::ImagesetManager::getSingletonPtr()->createImagesetFromImageFile(name, item->getGUIImage(), "pickups");
196        }
197
198        return name;
199    }
200}
Note: See TracBrowser for help on using the repository browser.