[Orxonox-commit 6601] r11241 - code/branches/HUD_HS16/src/modules/pickup
patricwi at orxonox.net
patricwi at orxonox.net
Mon Oct 17 20:35:19 CEST 2016
Author: patricwi
Date: 2016-10-17 20:35:19 +0200 (Mon, 17 Oct 2016)
New Revision: 11241
Modified:
code/branches/HUD_HS16/src/modules/pickup/PickupManager.cc
code/branches/HUD_HS16/src/modules/pickup/PickupManager.h
Log:
KeyBindings-logic added, eventhough still all leading to ESC
Modified: code/branches/HUD_HS16/src/modules/pickup/PickupManager.cc
===================================================================
--- code/branches/HUD_HS16/src/modules/pickup/PickupManager.cc 2016-10-17 14:35:27 UTC (rev 11240)
+++ code/branches/HUD_HS16/src/modules/pickup/PickupManager.cc 2016-10-17 18:35:19 UTC (rev 11241)
@@ -75,7 +75,7 @@
this->defaultRepresentation_ = new PickupRepresentation();
- orxout() << "PickupManager created." << endl;
+ orxout(internal_info, context::pickups) << "PickupManager created." << endl;
}
/**
@@ -284,17 +284,16 @@
uint32_t index = 0;
if(pickedUp) // If the Pickupable has changed to picked up, it is added to the required lists.
{
- index = this->getPickupIndex(); // Ge a new identifier (index) for the Pickupable.
+ index = this->getPickupIndex(); // Get a new identifier (index) for the Pickupable.
// Add the Pickupable to the indexes_ and pickups_ lists.
this->indexes_[pickup] = index;
this->pickups_[index] = pickup;
- // TODO: Add pickup keybinding -------------------------------------------
+
+ //Add pickup keybinding
if( KeyBinderManager::exists() )
- KeyBinderManager::getInstance().getCurrent()->setBinding("KeyESC", "Keys.KeyNumpad0",true);
+ addKeyBindingForNewPickup(pickup, index);
else
orxout() << "Could not create new keybinding because KeyBinderManager doesn't exist." << endl;
- //----------------------------
-
}
else // If it was dropped, it is removed from the required lists.
{
@@ -302,15 +301,15 @@
std::map<Pickupable*, uint32_t>::iterator it = this->indexes_.find(pickup);
index = it->second;
- // Remove the Pickupable from the indexes_ and pickups_ list.
- this->indexes_.erase(it);
- this->pickups_.erase(index);
- // TODO: Remove pickup keybinding ------------------------------------
+ //Remove pickup keybinding
if( KeyBinderManager::exists() )
- KeyBinderManager::getInstance().getCurrent()->setBinding("", "Keys.KeyNumpad0",true);
+ removeKeyBindingForOldPickup(pickup, index);
else
orxout() << "Could not delete old keybinding because KeyBinderManager doesn't exist." << endl;
- //----------------------------
+
+ // Remove the Pickupable from the indexes_ and pickups_ list.
+ this->indexes_.erase(pickup);
+ this->pickups_.find(index)->second=nullptr; //set to null, so that can be indentified as free slot by getPickupIndex()
}
// If we're either in standalone mode or this is the host whom the change of the pickup's status concerns.
@@ -338,6 +337,37 @@
}
+ //PRECONDITION: KeyBinderManager exists, pickup is not NULL, 0 < index < 9
+ //FUNCTION: Adds a keybinding for the new pickup using its index
+ void PickupManager::addKeyBindingForNewPickup(Pickupable* pickup, uint32_t index)
+ {
+ std::string name="Keys.KeyNumpad";
+ std::string binding="";
+
+ name.append(std::to_string(index));
+
+ KeyBinderManager::getInstance().getCurrent()->setBinding("KeyESC", name, true); // TODO do not set all bindings to ESC
+
+ orxout() << "Keybinding for item " << index << " has been added on keybinding " << name << endl;
+
+
+ }
+
+ //PRECONDITION: KeyBinderManager exists, pickup is not NULL, 0 < index < 9
+ //FUNCTION: Removes the keybinding of the pickup using its index
+ void PickupManager::removeKeyBindingForOldPickup(Pickupable* pickup, uint32_t index)
+ {
+ std::string name="Keys.KeyNumpad";
+ std::string binding="";
+
+ name.append(std::to_string(index));
+
+ KeyBinderManager::getInstance().getCurrent()->setBinding("", name, true);
+
+ orxout() << "Keybinding for item " << index << " has been removed on keybinding " << name << endl;
+
+ }
+
/**
@brief
Helper method to react to the change in the pickedUp status of a Pickupable.
@@ -416,7 +446,10 @@
return;
Pickupable* pickupable = this->pickups_.find(pickup)->second;
if(pickupable != nullptr)
+ {
pickupable->drop();
+
+ }
}
// If we're neither server nor standalone we drop the pickup by calling dropPickupNetworked() of the PickupManager on the server.
else
@@ -509,16 +542,23 @@
/**
@brief
- Get a new index for a Pickupable.
- This will work as long as the number of Pickupables that are picked up is sufficiently small and as long as they don't exist forever.
+ Get a new index between 0 and 9 for a Pickupable.
+ If all slots are occupied, the Pickupable in the first slot will be dropped.
@return
Returns the new index.
*/
uint32_t PickupManager::getPickupIndex(void)
{
- if(this->pickupHighestIndex_ == uint32_t(~0x0)-1) // If we've reached the highest possible number, we wrap around.
- this->pickupHighestIndex_ = 0;
- return this->pickupHighestIndex_++;
+ //check if there are free slots available
+
+ for(uint32_t i=0; i<10; i++)
+ {
+ if(pickups_.find(i)->second==nullptr) return i;
+ }
+ //all slots are full and we have to drop sth
+ orxout() << "everything was full and we have now dropped the first element" << endl;
+ this->dropPickup(0);
+ return 0;
}
}
Modified: code/branches/HUD_HS16/src/modules/pickup/PickupManager.h
===================================================================
--- code/branches/HUD_HS16/src/modules/pickup/PickupManager.h 2016-10-17 14:35:27 UTC (rev 11240)
+++ code/branches/HUD_HS16/src/modules/pickup/PickupManager.h 2016-10-17 18:35:19 UTC (rev 11241)
@@ -166,6 +166,9 @@
void updateGUI(void); //!< Updates the PickupInventory GUI.
uint32_t getPickupIndex(void); //!< Get a new index for a Pickupable.
+ void addKeyBindingForNewPickup(Pickupable* pickup, uint32_t index);
+ void removeKeyBindingForOldPickup(Pickupable* pickup, uint32_t index);
+
}; // tolua_export
} // tolua_export
More information about the Orxonox-commit
mailing list