Changeset 3016 for code/branches/pickups2/src/orxonox/objects
- Timestamp:
- May 23, 2009, 9:53:13 AM (16 years ago)
- Location:
- code/branches/pickups2/src/orxonox/objects/pickup
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/pickups2/src/orxonox/objects/pickup/PickupCollection.cc
r3001 r3016 158 158 return; 159 159 160 bool getNewUsable = false; 160 161 if (item == this->currentUsable_ || (this->currentUsable_ && removeAllOfType && this->currentUsable_->getPickupIdentifier() == item->getPickupIdentifier())) 162 { 163 getNewUsable = true; 164 } 165 166 if (removeAllOfType) 167 { 168 std::multimap<std::string, BaseItem*>::iterator it; 169 while ((it = this->items_.find(item->getPickupIdentifier())) != this->items_.end()) 170 { 171 this->items_.erase(it); 172 } 173 } 174 else 175 { 176 std::multimap<std::string, BaseItem*>::_Pairii bounds = this->items_.equal_range(item->getPickupIdentifier()); 177 for (std::multimap<std::string, BaseItem*>::iterator it = bounds.first; it != bounds.second && it != this->items_.end(); it++) 178 { 179 if ((*it).second == item) 180 { 181 this->items_.erase(it); 182 break; 183 } 184 } 185 } 186 187 if (getNewUsable) 161 188 { 162 189 std::deque<UsableItem*> usables = this->getUsableItems(); … … 166 193 else 167 194 this->currentUsable_ = NULL; 168 } 169 if (removeAllOfType) 170 { 171 std::multimap<std::string, BaseItem*>::iterator it; 172 while ((it = this->items_.find(item->getPickupIdentifier())) != this->items_.end()) 173 { 174 this->items_.erase(it); 175 } 176 } 177 else 178 { 179 std::multimap<std::string, BaseItem*>::_Pairii bounds = this->items_.equal_range(item->getPickupIdentifier()); 180 for (std::multimap<std::string, BaseItem*>::iterator it = bounds.first; it != bounds.second && it != this->items_.end(); it++) 181 { 182 if ((*it).second == item) 183 { 184 this->items_.erase(it); 185 return; 186 } 187 } 195 188 196 } 189 197 } -
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 } -
code/branches/pickups2/src/orxonox/objects/pickup/PickupInventory.h
r3001 r3016 56 56 // tolua_end 57 57 public: 58 //PickupInventory(BaseObject* creator);59 //virtual ~PickupInventory();58 PickupInventory(); 59 virtual ~PickupInventory(); 60 60 61 /** 62 @brief Toggle visiblity of inventory. 63 */ 61 static PickupInventory* getSingleton(); // tolua_export 62 64 63 static void toggleInventory(); // tolua_export 65 66 static void tabChanged(CEGUI::Window* tab); // tolua_export67 64 68 65 static unsigned int getEquipmentCount(); // tolua_export … … 80 77 static std::string getImageForItem(const BaseItem* item); // tolua_export 81 78 82 static void clearInventory(CEGUI::WindowManager* winMgr, int equipCount, int usableCount); // tolua_export83 staticvoid updateTabs(CEGUI::WindowManager* winMgr, CEGUI::Window* equipWindow, CEGUI::Window* usableWindow); // tolua_export79 void clearInventory(CEGUI::WindowManager* winMgr, CEGUI::Window* equipPane, CEGUI::Window* usablePane); // tolua_export 80 void updateTabs(CEGUI::WindowManager* winMgr, CEGUI::Window* equipWindow, CEGUI::Window* usableWindow); // tolua_export 84 81 85 staticvoid updateEquipment(CEGUI::WindowManager* winMgr, CEGUI::Window* target);86 staticvoid updateUsable(CEGUI::WindowManager* winMgr, CEGUI::Window* target);82 void updateEquipment(CEGUI::WindowManager* winMgr, CEGUI::Window* target); 83 void updateUsable(CEGUI::WindowManager* winMgr, CEGUI::Window* target); 87 84 88 static void addItem(CEGUI::WindowManager* winMgr, CEGUI::Window* target, const std::string& id, BaseItem* item, const std::string& titleColour, int x, int y); // tolua_export 85 static void createItemWindows(CEGUI::WindowManager* winMgr, const std::string& id, int x, int y); 86 static void setWindowProperties(CEGUI::WindowManager* winMgr, CEGUI::Window* target, const std::string& id, const BaseItem* item, const std::string& textColour); 87 88 const bool isVisible() const 89 { return this->bInventoryVisible_; } 90 void setVisible(bool visible) 91 { this->bInventoryVisible_ = visible; } 92 private: 93 bool bInventoryVisible_; 94 unsigned int createdEquipmentWindows_; 95 unsigned int createdUsableWindows_; 96 unsigned int visibleEquipmentWindows_; 97 unsigned int visibleUsableWIndows_; 98 99 static PickupInventory* pickupInventory_s; 89 100 }; // tolua_export 90 101 } // tolua_export
Note: See TracChangeset
for help on using the changeset viewer.