- Timestamp:
- May 23, 2009, 9:53:13 AM (15 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/pickups2/src/orxonox/objects/pickup/PickupInventory.cc
r3001 r3016 53 53 orxonox::CommandExecutor::addConsoleCommandShortcut(orxonox::createConsoleCommand(orxonox::createFunctor(&PickupInventory::toggleInventory), "toggleInventory"), true); 54 54 55 static bool bInventoryVisible_ = false; 55 PickupInventory* PickupInventory::pickupInventory_s = NULL; 56 PickupInventory* PickupInventory::getSingleton() 57 { 58 if(!PickupInventory::pickupInventory_s) 59 PickupInventory::pickupInventory_s = new PickupInventory(); 60 61 return PickupInventory::pickupInventory_s; 62 } 63 64 PickupInventory::PickupInventory() 65 { 66 this->bInventoryVisible_ = false; 67 this->createdEquipmentWindows_ = this->createdUsableWindows_ = 0; 68 this->visibleEquipmentWindows_ = this->visibleUsableWIndows_ = 0; 69 } 70 PickupInventory::~PickupInventory() 71 { 72 } 73 74 75 56 76 void PickupInventory::toggleInventory() 57 77 { 58 if( bInventoryVisible_) {78 if(PickupInventory::getSingleton()->isVisible()) { 59 79 GUIManager::getInstancePtr()->executeCode("hideGUI(\"PickupInventory\")"); 60 80 GUIManager::getInstancePtr()->executeCode("hideCursor()"); … … 67 87 InputManager::getInstance().requestEnterState("guiMouseOnly"); 68 88 } 69 bInventoryVisible_ = !bInventoryVisible_; 70 } 71 void PickupInventory::tabChanged(CEGUI::Window *tab) 72 { 73 CEGUI::TabControl* tabCtrl = dynamic_cast<CEGUI::TabControl*>(tab); 74 if(tabCtrl != NULL) 75 { 76 COUT(1) << "tabChanged() tab index: " << tabCtrl->getSelectedTabIndex() << std::endl; 77 } 78 else 79 { 80 COUT(1) << "tabChanged() argument is no CEGUI::TabControl!" << std::endl; 81 } 89 PickupInventory::getSingleton()->setVisible(!PickupInventory::getSingleton()->isVisible()); 82 90 } 83 91 … … 193 201 } 194 202 195 void PickupInventory::clearInventory(CEGUI::WindowManager* winMgr, int equipCount, int usableCount)196 { 197 for( int i = 0; i < equipCount; i++)203 void PickupInventory::clearInventory(CEGUI::WindowManager* winMgr, CEGUI::Window* equipPane, CEGUI::Window* usablePane) 204 { 205 for(unsigned int i = 0; i < this->visibleEquipmentWindows_; i++) 198 206 { 199 207 std::ostringstream id; 200 208 id << i; 201 209 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++) 210 winMgr->getWindow("orxonox/Inventory/Frame/equ/" + id.str())->setVisible(false); 211 winMgr->getWindow("orxonox/Inventory/Title/equ/" + id.str())->setVisible(false); 212 winMgr->getWindow("orxonox/Inventory/Items/equ/" + id.str())->setVisible(false); 213 214 /*equipPane->removeChildWindow("orxonox/Inventory/Frame/equ/" + id.str()); 215 equipPane->removeChildWindow("orxonox/Inventory/Title/equ/" + id.str()); 216 equipPane->removeChildWindow("orxonox/Inventory/Items/equ/" + id.str());*/ 217 } 218 for(unsigned int i = 0; i < this->visibleUsableWIndows_; i++) 207 219 { 208 220 std::ostringstream id; 209 221 id << i; 210 222 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()); 223 winMgr->getWindow("orxonox/Inventory/Frame/use/" + id.str())->setVisible(false); 224 winMgr->getWindow("orxonox/Inventory/Title/use/" + id.str())->setVisible(false); 225 winMgr->getWindow("orxonox/Inventory/Items/use/" + id.str())->setVisible(false); 226 227 /*usablePane->removeChildWindow("orxonox/Inventory/Frame/use/" + id.str()); 228 usablePane->removeChildWindow("orxonox/Inventory/Title/use/" + id.str()); 229 usablePane->removeChildWindow("orxonox/Inventory/Items/use/" + id.str());*/ 215 230 } 216 231 } 217 232 void PickupInventory::updateTabs(CEGUI::WindowManager *winMgr, CEGUI::Window *equipWindow, CEGUI::Window *usableWindow) 218 233 { 219 PickupInventory::updateEquipment(winMgr, equipWindow);220 PickupInventory::updateUsable(winMgr, usableWindow);234 this->updateEquipment(winMgr, equipWindow); 235 this->updateUsable(winMgr, usableWindow); 221 236 } 222 237 … … 234 249 EquipmentItem* item = items.at(i); 235 250 236 PickupInventory::addItem(winMgr, target, id.str(), item, "FFFFFFFF", i % 5, i / 5); 251 if(this->createdEquipmentWindows_ <= i) 252 { 253 PickupInventory::createItemWindows(winMgr, id.str(), i % 5, i / 5); 254 this->createdEquipmentWindows_++; 255 } 256 257 PickupInventory::setWindowProperties(winMgr, target, id.str(), item, "FFFFFFFF"); 237 258 } 259 this->visibleEquipmentWindows_ = items.size(); 238 260 } 239 261 } … … 257 279 colour = "FFFFFFFF"; 258 280 259 PickupInventory::addItem(winMgr, target, id.str(), item, colour, i % 5, i / 5); 281 if(this->createdUsableWindows_ <= i) 282 { 283 PickupInventory::createItemWindows(winMgr, id.str(), i % 5, i / 5); 284 this->createdUsableWindows_++; 285 } 286 287 PickupInventory::setWindowProperties(winMgr, target, id.str(), item, colour); 260 288 } 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) 289 this->visibleUsableWIndows_ = items.size(); 290 } 291 } 292 293 void PickupInventory::createItemWindows(CEGUI::WindowManager* winMgr, const std::string& id, int x, int y) 265 294 { 266 if(!winMgr || !target || !item) { return; } 267 268 std::string image = PickupInventory::getImageForItem(item); 295 if(!winMgr) { return; } 269 296 270 297 CEGUI::Window* frame = winMgr->createWindow("TaharezLook/StaticImage", "orxonox/Inventory/Frame/" + id); … … 275 302 text->setPosition(CEGUI::UVector2(CEGUI::UDim(0, 5 + x * 70), CEGUI::UDim(0, 70 + y * 90))); 276 303 text->setSize(CEGUI::UVector2(CEGUI::UDim(0, 65), CEGUI::UDim(0, 20))); 277 text->setProperty("Text", item->getGUIText());278 304 text->setProperty("FrameEnabled", "False"); 279 305 text->setProperty("BackgroundEnabled", "False"); 280 306 text->setProperty("HorzFormatting", "HorzCentred"); 281 307 text->setProperty("VertFormatting", "VertCentred"); 282 text->setProperty("TextColours", "tl: " + titleColour + " tr:" + titleColour + " bl:" + titleColour + " br:" + titleColour + "");308 text->setProperty("TextColours", "tl:FFFFFFFF tr:FFFFFFFF bl:FFFFFFFF br:FFFFFFFF"); 283 309 284 310 CEGUI::Window* btn = winMgr->createWindow("TaharezLook/Button", "orxonox/Inventory/Items/" + id); 285 311 btn->setPosition(CEGUI::UVector2(CEGUI::UDim(0, 8 + x * 70), CEGUI::UDim(0, 8 + y * 90))); 286 312 btn->setSize(CEGUI::UVector2(CEGUI::UDim(0, 59), CEGUI::UDim(0, 59))); 313 btn->subscribeScriptedEvent("Clicked", "itemClicked"); 314 } 315 void PickupInventory::setWindowProperties(CEGUI::WindowManager* winMgr, CEGUI::Window* target, const std::string& id, const BaseItem* item, const std::string& textColour) 316 { 317 CEGUI::Window* txt = winMgr->getWindow("orxonox/Inventory/Title/" + id); 318 CEGUI::Window* btn = winMgr->getWindow("orxonox/Inventory/Items/" + id); 319 CEGUI::Window* frm = winMgr->getWindow("orxonox/Inventory/Frame/" + id); 320 321 frm->setVisible(true); 322 323 txt->setVisible(true); 324 txt->setProperty("Text", item->getGUIText()); 325 txt->setProperty("TextColours", "tl:" + textColour + " tr:" + textColour + " bl:" + textColour + " br:" + textColour + ""); 326 327 std::string image = PickupInventory::getImageForItem(item); 328 btn->setVisible(true); 287 329 btn->setProperty("NormalImage", image); 288 330 btn->setProperty("HoverImage", image); … … 290 332 btn->setProperty("DisabledImage", image); 291 333 btn->setProperty("Tooltip", item->getGUIText()); 292 btn->subscribeScriptedEvent("Clicked", "itemClicked"); 293 294 target->addChildWindow(text); 295 target->addChildWindow(frame); 334 335 target->addChildWindow(frm); 336 target->addChildWindow(txt); 296 337 target->addChildWindow(btn); 297 338 }
Note: See TracChangeset
for help on using the changeset viewer.