[Orxonox-commit 6684] r11314 - in code/branches/HUD_HS16/src/modules: overlays/hud pickup
patricwi at orxonox.net
patricwi at orxonox.net
Mon Nov 28 19:21:35 CET 2016
Author: patricwi
Date: 2016-11-28 19:21:35 +0100 (Mon, 28 Nov 2016)
New Revision: 11314
Modified:
code/branches/HUD_HS16/src/modules/overlays/hud/HUDPickupItem.cc
code/branches/HUD_HS16/src/modules/overlays/hud/HUDPickupItem.h
code/branches/HUD_HS16/src/modules/overlays/hud/HUDPickupSystem.cc
code/branches/HUD_HS16/src/modules/overlays/hud/HUDPickupSystem.h
code/branches/HUD_HS16/src/modules/pickup/CMakeLists.txt
code/branches/HUD_HS16/src/modules/pickup/PickupManager.cc
code/branches/HUD_HS16/src/modules/pickup/PickupManager.h
Log:
linker problem solved, visuals work as long as only 1 item is picked up.
Modified: code/branches/HUD_HS16/src/modules/overlays/hud/HUDPickupItem.cc
===================================================================
--- code/branches/HUD_HS16/src/modules/overlays/hud/HUDPickupItem.cc 2016-11-28 15:53:24 UTC (rev 11313)
+++ code/branches/HUD_HS16/src/modules/overlays/hud/HUDPickupItem.cc 2016-11-28 18:21:35 UTC (rev 11314)
@@ -51,9 +51,8 @@
overlayElement_ = static_cast<Ogre::PanelOverlayElement* >(Ogre::OverlayManager::getSingleton().createOverlayElement("Panel", "HUDPickupItem" + getUniqueNumberString()));
- overlayElement_->setPosition(0.0f,0.0f);
- overlayElement_->setDimensions(0.5f,0.5f);
- this->background_->addChild(overlayElement_);
+ overlayElement_->setDimensions(0.1f,0.1f);
+
}
HUDPickupItem::~HUDPickupItem()
@@ -64,14 +63,21 @@
}
}
- void HUDPickupItem::initializeMaterial(const std::string& s)
+ void HUDPickupItem::initializeMaterial(const std::string& s, float x, float y)
{
+ orxout() << "material name is: " << s << endl;
overlayElement_->setMaterialName(s);
+ overlayElement_->setPosition(x, y);
+ overlayElement_->show();
+ this->background_->addChild(overlayElement_);
}
- void HUDPickupItem::printHello()
+ void HUDPickupItem::hideMe()
{
- orxout() << "lets say hello" << endl;
+ orxout() << this << " has called hide" << endl;
+ overlayElement_->hide();
+ overlayElement_->_update();
+ orxout() << "after the call the element is visible: " << overlayElement_->isVisible() << endl;
}
// void HUDWeapon::XMLPort(Element& xmlelement, XMLPort::Mode mode)
Modified: code/branches/HUD_HS16/src/modules/overlays/hud/HUDPickupItem.h
===================================================================
--- code/branches/HUD_HS16/src/modules/overlays/hud/HUDPickupItem.h 2016-11-28 15:53:24 UTC (rev 11313)
+++ code/branches/HUD_HS16/src/modules/overlays/hud/HUDPickupItem.h 2016-11-28 18:21:35 UTC (rev 11314)
@@ -35,8 +35,8 @@
// virtual void sizeChanged() override;
// void setPickup(Pickup* pickup);
- void initializeMaterial(const std::string& s);
- void printHello();
+ void initializeMaterial(const std::string& s, float x, float y);
+ void hideMe();
private:
// void createHUDChilds();
Modified: code/branches/HUD_HS16/src/modules/overlays/hud/HUDPickupSystem.cc
===================================================================
--- code/branches/HUD_HS16/src/modules/overlays/hud/HUDPickupSystem.cc 2016-11-28 15:53:24 UTC (rev 11313)
+++ code/branches/HUD_HS16/src/modules/overlays/hud/HUDPickupSystem.cc 2016-11-28 18:21:35 UTC (rev 11314)
@@ -52,8 +52,6 @@
overlayElement_->setDimensions(0.70f,0.15f);
orxout() << "hello here is the HUDPickupSystem" << endl;
this->background_->addChild(overlayElement_);
-
- PickupManager::getInstance().setPickupSystem(this);
}
HUDPickupSystem::~HUDPickupSystem()
@@ -68,21 +66,53 @@
void HUDPickupSystem::updatePickupList(std::vector<Pickupable*> picks)
{
- for(Pickupable* p : picks)
+ int i=0;
+ const float offsetX = 0.32f;
+ float offsetY = 0.77f;
+ const float x = 0.1f;
+
+ orxout() << "size: " << picks.size() << endl;
+
+ if(picks.size()>0)
{
- HUDPickupItem* item = new HUDPickupItem(this->getContext());
- item->initializeMaterial(((Pickup*)p)->getRepresentationName());
- item->printHello();
+
+ for(Pickupable* p : picks)
+ {
+ // orxout() << "actual pick is: " << p << endl;
+ if(i%4==0)
+ {
+ offsetY+=0.04f;
+ i=0;
+ }
+ HUDPickupItem* item = new HUDPickupItem(this->getContext());
+ // item->initializeMaterial(((Pickup*)p)->getRepresentationName(), offsetX+i*x, offsetY);
+ if(i%2==0)
+ item->initializeMaterial("Shield", offsetX+i*x, offsetY);
+ else
+ item->initializeMaterial("ArrowUp", offsetX+i*x, offsetY);
+ item->setOverlayGroup(this->getOverlayGroup());
+ this->picks[p] = item;
+ ++i;
+ }
}
}
void HUDPickupSystem::createPickupList()
{
-
}
+ void HUDPickupSystem::removePickup(Pickupable* pickup)
+ {
+ HUDPickupItem* item = this->picks.find(pickup)->second;
+ orxout() << "removePickup: pickup= " << pickup << " item= " << item << endl;
+ assert(item);
+ item->setOverlayGroup(nullptr);
+ item->hideMe();
+ overlayElement_->_update();
+ }
+
void HUDPickupSystem::destroyAll()
{
-
+ this->background_->removeChild(overlayElement_->getName());
}
}
Modified: code/branches/HUD_HS16/src/modules/overlays/hud/HUDPickupSystem.h
===================================================================
--- code/branches/HUD_HS16/src/modules/overlays/hud/HUDPickupSystem.h 2016-11-28 15:53:24 UTC (rev 11313)
+++ code/branches/HUD_HS16/src/modules/overlays/hud/HUDPickupSystem.h 2016-11-28 18:21:35 UTC (rev 11314)
@@ -62,11 +62,15 @@
// virtual void changedName() override;
// virtual void positionChanged() override;
// virtual void sizeChanged() override;
- void updatePickupList(std::vector<Pickupable*> picks);
+ void updatePickupList(std::vector<Pickupable*> picks);
+ void createPickupList();
+ void removePickup(Pickupable* pickup);
private:
- void createPickupList();
+
void destroyAll();
+ std::map<Pickupable*, HUDPickupItem*> picks;
+
Ogre::PanelOverlayElement* overlayElement_;
WeakPtr<Pawn> owner_;
Modified: code/branches/HUD_HS16/src/modules/pickup/CMakeLists.txt
===================================================================
--- code/branches/HUD_HS16/src/modules/pickup/CMakeLists.txt 2016-11-28 15:53:24 UTC (rev 11313)
+++ code/branches/HUD_HS16/src/modules/pickup/CMakeLists.txt 2016-11-28 18:21:35 UTC (rev 11314)
@@ -18,6 +18,7 @@
PCH_FILE
PickupPrecompiledHeaders.h
LINK_LIBRARIES
+ overlays
orxonox
SOURCE_FILES ${PICKUP_SRC_FILES}
)
Modified: code/branches/HUD_HS16/src/modules/pickup/PickupManager.cc
===================================================================
--- code/branches/HUD_HS16/src/modules/pickup/PickupManager.cc 2016-11-28 15:53:24 UTC (rev 11313)
+++ code/branches/HUD_HS16/src/modules/pickup/PickupManager.cc 2016-11-28 18:21:35 UTC (rev 11314)
@@ -82,11 +82,6 @@
orxout(internal_info, context::pickups) << "PickupManager created." << endl;
}
- void PickupManager::setPickupSystem(HUDPickupSystem* system)
- {
- pickupSystem=system;
- }
-
/**
@brief
Destructor.
@@ -270,6 +265,13 @@
{
assert(pickup);
+ if(!pickupSystem)
+ {
+ for (HUDPickupSystem* hud : ObjectList<HUDPickupSystem>())
+ pickupSystem = hud;
+ }
+ assert(pickupSystem); //pickupSystem HAS to be there!
+
if(!GameMode::isMaster()) // If this is neither standalone nor the server.
return;
@@ -298,19 +300,11 @@
this->indexes_[pickup] = index;
this->pickups_[index] = pickup;
- //TODO
- std::vector<Pickupable*> picks;
+ orxout() << "the pickup is: " << pickup << endl;
- PickupManager& manager = PickupManager::getInstance();
-
- Pickupable* pickup = nullptr;
+ this->picks.push_back(pickup);
- for(uint32_t i = 0; i!=10; i++)
- {
- pickup=manager.pickups_.find(i)->second;
- picks.push_back(pickup);
- }
- // pickupSystem->updatePickupList(picks);
+ pickupSystem->updatePickupList(picks);
}
else // If it was dropped, it is removed from the required lists.
@@ -319,9 +313,14 @@
std::map<Pickupable*, uint32_t>::iterator it = this->indexes_.find(pickup);
index = it->second;
-
this->indexes_.erase(pickup);
this->pickups_.find(index)->second=nullptr; //set to null, so that can be identified as free slot by getPickupIndex()
+
+
+ this->picks.erase(std::remove(this->picks.begin(), this->picks.end(), pickup), this->picks.end()); //remove pickup from vector
+
+ pickupSystem->removePickup(pickup);
+ pickupSystem->updatePickupList(picks);
}
// If we're either in standalone mode or this is the host whom the change of the pickup's status concerns.
Modified: code/branches/HUD_HS16/src/modules/pickup/PickupManager.h
===================================================================
--- code/branches/HUD_HS16/src/modules/pickup/PickupManager.h 2016-11-28 15:53:24 UTC (rev 11313)
+++ code/branches/HUD_HS16/src/modules/pickup/PickupManager.h 2016-11-28 18:21:35 UTC (rev 11314)
@@ -41,7 +41,7 @@
#include "core/object/WeakPtr.h"
#include "PickupRepresentation.h"
-
+#include "interfaces/Pickupable.h"
#include "util/Singleton.h"
#include "interfaces/PickupListener.h"
#include "overlays/hud/HUDPickupSystem.h"
@@ -152,6 +152,8 @@
private:
HUDPickupSystem* pickupSystem;
+ std::vector<Pickupable*> picks;
+
static PickupManager* singletonPtr_s;
static const std::string guiName_s; //!< The name of the PickupInventory
bool guiLoaded_; //!< Whether the PickupInventory GUI has been loaded, yet.
More information about the Orxonox-commit
mailing list