- Timestamp:
- May 20, 2009, 9:01:17 PM (15 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/pickups2/src/orxonox/objects/pickup/PickupInventory.cc
r2972 r3001 30 30 31 31 #include "EquipmentItem.h" 32 #include "PassiveItem.h" 32 33 #include "UsableItem.h" 33 #include "PassiveItem.h"34 34 35 35 #include "core/CoreIncludes.h" … … 39 39 #include "gui/GUIManager.h" 40 40 #include "objects/controllers/HumanController.h" 41 #include "objects/worldentities/pawns/SpaceShip.h" 42 41 #include "objects/worldentities/pawns/Pawn.h" 42 43 #include <CEGUIImage.h> 44 #include <CEGUIImageset.h> 43 45 #include <CEGUIImagesetManager.h> 44 46 #include <CEGUIWindow.h> 47 #include <CEGUIWindowManager.h> 45 48 #include <elements/CEGUITabControl.h> 46 49 … … 78 81 } 79 82 } 83 84 unsigned int PickupInventory::getCurrentUsableIndex() 85 { 86 Pawn* pawn = HumanController::getLocalControllerEntityAsPawn(); 87 if(pawn && pawn->getPickups().getCurrentUsable()) 88 { 89 UsableItem* use = pawn->getPickups().getCurrentUsable(); 90 std::deque<UsableItem*> items = pawn->getPickups().getUsableItems(); 91 for(unsigned int i = 0; i < items.size(); i++) 92 { 93 if(items.at(i) == use) 94 return i; 95 } 96 } 97 98 return 0; 99 } 100 bool PickupInventory::isCurrentUsable(const BaseItem* item) 101 { 102 Pawn* pawn = HumanController::getLocalControllerEntityAsPawn(); 103 if(pawn) 104 return (pawn->getPickups().getCurrentUsable() == item); 105 else 106 return false; 107 } 108 void PickupInventory::selectUsable(unsigned int i) 109 { 110 Pawn* pawn = HumanController::getLocalControllerEntityAsPawn(); 111 if(pawn) 112 { 113 std::deque<UsableItem*> items = pawn->getPickups().getUsableItems(); 114 if(i < items.size()) 115 pawn->getPickups().setCurrentUsable(items.at(i)); 116 } 117 } 118 80 119 unsigned int PickupInventory::getEquipmentCount() 81 120 { 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; 121 Pawn* pawn = HumanController::getLocalControllerEntityAsPawn(); 122 if(pawn) 123 return pawn->getPickups().getEquipmentItems().size(); 124 else 125 return 0; 90 126 } 91 127 unsigned int PickupInventory::getUsableCount() 92 128 { 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; 129 Pawn* pawn = HumanController::getLocalControllerEntityAsPawn(); 130 if(pawn) 131 return pawn->getPickups().getUsableItems().size(); 132 else 133 return 0; 101 134 } 102 135 unsigned int PickupInventory::getPassiveCount() 103 136 { 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); 137 Pawn* pawn = HumanController::getLocalControllerEntityAsPawn(); 138 if(pawn) 139 return pawn->getPickups().getPassiveItems().size(); 140 else 141 return 0; 142 } 143 BaseItem* PickupInventory::getEquipmentItem(unsigned int i) 144 { 145 Pawn* pawn = HumanController::getLocalControllerEntityAsPawn(); 146 if(pawn) 147 { 148 std::deque<EquipmentItem*> l = pawn->getPickups().getEquipmentItems(); 149 if (i >= l.size()) { return NULL; } 150 return l.at(i); 151 } 152 else 153 return NULL; 154 } 155 BaseItem* PickupInventory::getUsableItem(unsigned int i) 156 { 157 Pawn* pawn = HumanController::getLocalControllerEntityAsPawn(); 158 if(pawn) 159 { 160 std::deque<UsableItem*> l = pawn->getPickups().getUsableItems(); 161 if (i >= l.size()) { return NULL; } 162 return l.at(i); 163 } 164 else 165 return NULL; 166 } 167 BaseItem* PickupInventory::getPassiveItem(unsigned int i) 168 { 169 Pawn* pawn = HumanController::getLocalControllerEntityAsPawn(); 170 if(pawn) 171 { 172 std::deque<PassiveItem*> l = pawn->getPickups().getPassiveItems(); 173 if (i >= l.size()) { return NULL; } 174 return l.at(i); 175 } 176 else 177 return NULL; 178 } 179 180 std::string PickupInventory::getImageForItem(const BaseItem* item) 181 { 161 182 if(!item) 162 183 return ""; … … 164 185 std::string name = "pickup_" + item->getGUIImage(); 165 186 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; 187 if(!CEGUI::ImagesetManager::getSingletonPtr()->isImagesetPresent(name)) 188 { 189 CEGUI::ImagesetManager::getSingletonPtr()->createImagesetFromImageFile(name, item->getGUIImage(), ""); 190 } 191 192 return "set:" + name + " image:full_image"; 193 } 194 195 void PickupInventory::clearInventory(CEGUI::WindowManager* winMgr, int equipCount, int usableCount) 196 { 197 for(int i = 0; i < equipCount; i++) 198 { 199 std::ostringstream id; 200 id << i; 201 202 winMgr->destroyWindow("orxonox/Inventory/Frame/equ/" + id.str()); 203 winMgr->destroyWindow("orxonox/Inventory/Title/equ/" + id.str()); 204 winMgr->destroyWindow("orxonox/Inventory/Items/equ/" + id.str()); 205 } 206 for(int i = 0; i < usableCount; i++) 207 { 208 std::ostringstream id; 209 id << i; 210 211 std::string s = id.str(); 212 winMgr->destroyWindow("orxonox/Inventory/Frame/use/" + id.str()); 213 winMgr->destroyWindow("orxonox/Inventory/Title/use/" + id.str()); 214 winMgr->destroyWindow("orxonox/Inventory/Items/use/" + id.str()); 215 } 216 } 217 void PickupInventory::updateTabs(CEGUI::WindowManager *winMgr, CEGUI::Window *equipWindow, CEGUI::Window *usableWindow) 218 { 219 PickupInventory::updateEquipment(winMgr, equipWindow); 220 PickupInventory::updateUsable(winMgr, usableWindow); 221 } 222 223 void PickupInventory::updateEquipment(CEGUI::WindowManager* winMgr, CEGUI::Window* target) 224 { 225 Pawn* pawn; 226 if(pawn = HumanController::getLocalControllerEntityAsPawn()) 227 { 228 std::deque<EquipmentItem*> items = pawn->getPickups().getEquipmentItems(); 229 for(unsigned int i = 0; i < items.size(); i++) 230 { 231 std::ostringstream id; 232 id << "equ/" << i; 233 234 EquipmentItem* item = items.at(i); 235 236 PickupInventory::addItem(winMgr, target, id.str(), item, "FFFFFFFF", i % 5, i / 5); 237 } 238 } 239 } 240 void PickupInventory::updateUsable(CEGUI::WindowManager* winMgr, CEGUI::Window* target) 241 { 242 Pawn* pawn; 243 if(pawn = HumanController::getLocalControllerEntityAsPawn()) 244 { 245 std::deque<UsableItem*> items = pawn->getPickups().getUsableItems(); 246 for(unsigned int i = 0; i < items.size(); i++) 247 { 248 std::ostringstream id; 249 id << "use/" << i; 250 251 UsableItem* item = items.at(i); 252 std::string colour; 253 254 if(PickupInventory::isCurrentUsable(item)) 255 colour = "FFFF5555"; 256 else 257 colour = "FFFFFFFF"; 258 259 PickupInventory::addItem(winMgr, target, id.str(), item, colour, i % 5, i / 5); 260 } 261 } 262 } 263 264 void PickupInventory::addItem(CEGUI::WindowManager* winMgr, CEGUI::Window* target, const std::string& id, BaseItem* item, const std::string& titleColour, int x, int y) 265 { 266 if(!winMgr || !target || !item) { return; } 267 268 std::string image = PickupInventory::getImageForItem(item); 269 270 CEGUI::Window* frame = winMgr->createWindow("TaharezLook/StaticImage", "orxonox/Inventory/Frame/" + id); 271 frame->setPosition(CEGUI::UVector2(CEGUI::UDim(0, 5 + x * 70), CEGUI::UDim(0, 5 + y * 90))); 272 frame->setSize(CEGUI::UVector2(CEGUI::UDim(0, 65), CEGUI::UDim(0, 65))); 273 274 CEGUI::Window* text = winMgr->createWindow("TaharezLook/StaticText", "orxonox/Inventory/Title/" + id); 275 text->setPosition(CEGUI::UVector2(CEGUI::UDim(0, 5 + x * 70), CEGUI::UDim(0, 70 + y * 90))); 276 text->setSize(CEGUI::UVector2(CEGUI::UDim(0, 65), CEGUI::UDim(0, 20))); 277 text->setProperty("Text", item->getGUIText()); 278 text->setProperty("FrameEnabled", "False"); 279 text->setProperty("BackgroundEnabled", "False"); 280 text->setProperty("HorzFormatting", "HorzCentred"); 281 text->setProperty("VertFormatting", "VertCentred"); 282 text->setProperty("TextColours", "tl:" + titleColour + " tr:" + titleColour + " bl:" + titleColour + " br:" + titleColour + ""); 283 284 CEGUI::Window* btn = winMgr->createWindow("TaharezLook/Button", "orxonox/Inventory/Items/" + id); 285 btn->setPosition(CEGUI::UVector2(CEGUI::UDim(0, 8 + x * 70), CEGUI::UDim(0, 8 + y * 90))); 286 btn->setSize(CEGUI::UVector2(CEGUI::UDim(0, 59), CEGUI::UDim(0, 59))); 287 btn->setProperty("NormalImage", image); 288 btn->setProperty("HoverImage", image); 289 btn->setProperty("PushedImage", image); 290 btn->setProperty("DisabledImage", image); 291 btn->setProperty("Tooltip", item->getGUIText()); 292 btn->subscribeScriptedEvent("Clicked", "itemClicked"); 293 294 target->addChildWindow(text); 295 target->addChildWindow(frame); 296 target->addChildWindow(btn); 199 297 } 200 298 }
Note: See TracChangeset
for help on using the changeset viewer.