Changeset 3001 for code/branches/pickups2
- Timestamp:
- May 20, 2009, 9:01:17 PM (16 years ago)
- Location:
- code/branches/pickups2/src/orxonox
- Files:
-
- 10 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/pickups2/src/orxonox/CMakeLists.txt
r2972 r3001 35 35 36 36 GENERATE_SOURCE_GROUPS(${ORXONOX_FILES}) 37 GENERATE_TOLUA_BINDINGS(Orxonox ORXONOX_FILES INPUTFILES gui/GUIManager.h objects/pickup/PickupInventory.h objects/pickup/BaseItem.h objects/pickup/EquipmentItem.h objects/pickup/UsableItem.h objects/pickup/PassiveItem.h)37 GENERATE_TOLUA_BINDINGS(Orxonox ORXONOX_FILES INPUTFILES gui/GUIManager.h objects/pickup/PickupInventory.h objects/pickup/BaseItem.h) 38 38 39 39 # Not using precompiled header files: Avoid dependencies -
code/branches/pickups2/src/orxonox/objects/controllers/HumanController.h
r2972 r3001 34 34 #include "util/Math.h" 35 35 #include "Controller.h" 36 #include "objects/worldentities/pawns/Pawn.h" 36 37 37 38 namespace orxonox … … 68 69 static inline HumanController* getLocalControllerSingleton() 69 70 { return HumanController::localController_s; } 71 static inline Pawn* getLocalControllerEntityAsPawn() 72 { 73 if (HumanController::localController_s) { 74 return dynamic_cast<Pawn*>(HumanController::localController_s->getControllableEntity()); 75 } else { 76 return NULL; 77 } 78 } 70 79 71 80 private: -
code/branches/pickups2/src/orxonox/objects/pickup/BaseItem.cc
r2972 r3001 52 52 this->setOwner(0); 53 53 this->setPickupIdentifier(this->getName()); 54 this->setGUIImage(""); 55 this->setGUIText(""); 54 56 } 55 57 //! Deconstructor. … … 68 70 69 71 XMLPortParam(BaseItem, "guiText", setGUIText, getGUIText, xmlelement, mode); 70 XMLPortParam(BaseItem, "guiTooltip", setGUITooltip, getGUITooltip, xmlelement, mode);71 72 XMLPortParam(BaseItem, "guiImage", setGUIImage, getGUIImage, xmlelement, mode); 72 73 } … … 103 104 return true; 104 105 } 106 107 const std::string& BaseItem::getGUIText() const { return this->guiText_; } 105 108 } -
code/branches/pickups2/src/orxonox/objects/pickup/BaseItem.h
r2972 r3001 50 50 Daniel 'Huty' Haggenmueller 51 51 */ 52 class _OrxonoxExport BaseItem : public BaseObject 52 class _OrxonoxExport BaseItem 53 // tolua_end 54 : public BaseObject 55 // tolua_begin 53 56 { 54 57 // tolua_end … … 122 125 123 126 // GUI stuff 124 virtual const std::string& getGUIText() 125 { return this->guiText_; } 127 virtual const std::string& getGUIText() const; // tolua_export 126 128 inline void setGUIText(const std::string& text) 127 129 { this->guiText_ = text; } 128 130 129 virtual const std::string& getGUITooltip() 130 { return this->guiTooltip_; } 131 inline void setGUITooltip(const std::string& tooltip) 132 { this->guiTooltip_ = tooltip; } 133 134 virtual const std::string& getGUIImage() 131 virtual const std::string& getGUIImage() const 135 132 { return this->guiImage_; } 136 133 inline void setGUIImage(const std::string& image) … … 149 146 150 147 std::string guiText_; 151 std::string guiTooltip_;152 148 std::string guiImage_; 153 }; 154 } 149 }; // tolua_export 150 } // tolua_export 155 151 156 152 #endif /* _BaseItem_H__ */ -
code/branches/pickups2/src/orxonox/objects/pickup/Jump.cc
r2917 r3001 103 103 bool Jump::dropped(Pawn* pawn) 104 104 { 105 DroppedItem::createDefaultDrop(this, pawn, ColourValue(1.0f, 0.0f, 0.0f), 5.0f);105 DroppedItem::createDefaultDrop(this, pawn, ColourValue(1.0f, 0.0f, 0.0f), 30.0f); 106 106 return this->removeFrom(pawn); 107 107 } -
code/branches/pickups2/src/orxonox/objects/pickup/Jump.h
r2917 r3001 55 55 virtual void XMLPort(Element& xmlelement, XMLPort::Mode mode); //!< XMLPort 56 56 57 virtual int getMaxCarryAmount() const 58 { return INT_MAX; } 59 57 60 virtual void used(Pawn* pawn); //!< Called when the item is used. 58 61 -
code/branches/pickups2/src/orxonox/objects/pickup/PickupCollection.cc
r2972 r3001 49 49 { 50 50 this->bBlockRemovals_ = false; 51 this->currentUsable_ = NULL; 51 52 } 52 53 … … 64 65 if (this->checkSlot(item)) 65 66 { 67 Identifier* ident = Class(UsableItem); 68 if(this->currentUsable_ == NULL && item->isA(ident)) 69 this->currentUsable_ = dynamic_cast<UsableItem*>(item); 70 66 71 this->items_.insert( std::pair<std::string, BaseItem*> (item->getPickupIdentifier(), item) ); 67 72 return true; … … 99 104 (*it).second->dropped((*it).second->getOwner()); 100 105 } 106 this->currentUsable_ = NULL; 101 107 this->items_.clear(); 102 108 this->bBlockRemovals_ = false; … … 130 136 void PickupCollection::useItem() 131 137 { 132 Identifier* ident = Class(UsableItem); 133 for (std::multimap<std::string, BaseItem*>::iterator it = this->items_.begin(); it != this->items_.end(); it++) 134 { 135 if ((*it).second->isA(ident)) 136 { 137 UsableItem* asUsable = dynamic_cast<UsableItem*>((*it).second); 138 asUsable->used(this->owner_); 139 return; 140 } 141 } 138 if(this->currentUsable_) 139 this->currentUsable_->used(this->owner_); 142 140 } 143 141 /** … … 160 158 return; 161 159 160 if (item == this->currentUsable_ || (this->currentUsable_ && removeAllOfType && this->currentUsable_->getPickupIdentifier() == item->getPickupIdentifier())) 161 { 162 std::deque<UsableItem*> usables = this->getUsableItems(); 163 164 if(usables.size() > 0) 165 this->currentUsable_ = usables.at(0); 166 else 167 this->currentUsable_ = NULL; 168 } 162 169 if (removeAllOfType) 163 170 { -
code/branches/pickups2/src/orxonox/objects/pickup/PickupCollection.h
r2972 r3001 106 106 { this->owner_ = owner; } 107 107 108 inline UsableItem* getCurrentUsable() 109 { return this->currentUsable_; }; 110 inline void setCurrentUsable(UsableItem* usable) 111 { this->currentUsable_ = usable; } 112 108 113 std::deque<EquipmentItem*> getEquipmentItems(); //!< Get a list of equipment-type items. 109 114 std::deque<PassiveItem*> getPassiveItems(); //!< Get a list of passive items. … … 111 116 private: 112 117 Pawn* owner_; //!< The owner of the PickupCollection. 118 UsableItem* currentUsable_; 113 119 114 120 bool bBlockRemovals_; //!< Whether to block direct removals through remove(). -
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 } -
code/branches/pickups2/src/orxonox/objects/pickup/PickupInventory.h
r2972 r3001 39 39 #include "core/BaseObject.h" 40 40 41 namespace CEGUI { class Window; }41 namespace CEGUI { class Window; class WindowManager; class Image; } 42 42 43 43 // tolua_begin 44 44 namespace orxonox 45 45 { 46 class EquipmentItem; 47 class PassiveItem; 48 class UsableItem; 46 // tolua_end 47 class _OrxonoxExport BaseItem; 49 48 50 49 /** 51 50 @brief Static class for the inventory GUI window. 52 51 @author Daniel 'Huty' Haggenmueller 53 */ 52 */ 53 // tolua_begin 54 54 class _OrxonoxExport PickupInventory 55 55 { … … 70 70 static unsigned int getPassiveCount(); // tolua_export 71 71 72 static EquipmentItem* getEquipmentItem(unsigned int i); // tolua_export73 static UsableItem* getUsableItem(unsigned int i); // tolua_export74 static PassiveItem* getPassiveItem(unsigned int i); // tolua_export72 static unsigned int getCurrentUsableIndex(); // tolua_export 73 static bool isCurrentUsable(const BaseItem* item); // tolua_export 74 static void selectUsable(unsigned int i); // tolua_export 75 75 76 static std::string getImagesetForEquipment(unsigned int i); // tolua_export 77 static std::string getImagesetForUsable(unsigned int i); // tolua_export 78 static std::string getImagesetForPassive(unsigned int i); // tolua_export 76 static BaseItem* getEquipmentItem(unsigned int i); // tolua_export 77 static BaseItem* getUsableItem(unsigned int i); // tolua_export 78 static BaseItem* getPassiveItem(unsigned int i); // tolua_export 79 80 static std::string getImageForItem(const BaseItem* item); // tolua_export 81 82 static void clearInventory(CEGUI::WindowManager* winMgr, int equipCount, int usableCount); // tolua_export 83 static void updateTabs(CEGUI::WindowManager* winMgr, CEGUI::Window* equipWindow, CEGUI::Window* usableWindow); // tolua_export 84 85 static void updateEquipment(CEGUI::WindowManager* winMgr, CEGUI::Window* target); 86 static void updateUsable(CEGUI::WindowManager* winMgr, CEGUI::Window* target); 87 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 79 89 }; // tolua_export 80 90 } // tolua_export
Note: See TracChangeset
for help on using the changeset viewer.