Added hover button functionality to MenuItemButton component and to InventorySrollableWindowComponent item buttons created via that component. Implemented inventory screen.
This commit is contained in:
@@ -55,14 +55,24 @@ private:
|
||||
std::string itemDescriptionLabelName;
|
||||
bool inventoryButtonsActive=true;
|
||||
std::function<bool(MenuFuncData)>inventoryButtonClickAction;
|
||||
std::function<bool(MenuFuncData)>inventoryButtonHoverAction;
|
||||
std::function<bool(MenuFuncData)>inventoryButtonMouseOutAction;
|
||||
InventoryWindowOptions options;
|
||||
CompactText compact=COMPACT;
|
||||
protected:
|
||||
ITCategory inventoryType;
|
||||
public:
|
||||
inline InventoryScrollableWindowComponent(geom2d::rect<float>rect,ITCategory invType,std::string itemNameLabelName,std::string itemDescriptionLabelName,std::function<bool(MenuFuncData)>inventoryButtonClickAction,InventoryWindowOptions options={.padding=8,.size=24},bool inventoryButtonsActive=true,ComponentAttr attributes=ComponentAttr::BACKGROUND|ComponentAttr::OUTLINE)
|
||||
:ScrollableWindowComponent(rect,attributes),inventoryType(invType),itemNameLabelName(itemNameLabelName),itemDescriptionLabelName(itemDescriptionLabelName),
|
||||
options(options),inventoryButtonClickAction(inventoryButtonClickAction),inventoryButtonsActive(inventoryButtonsActive){
|
||||
Menu::AddInventoryListener(this,invType);
|
||||
this->inventoryButtonHoverAction=DO_NOTHING;
|
||||
this->inventoryButtonMouseOutAction=DO_NOTHING;
|
||||
Menu::AddInventoryListener(this,invType);
|
||||
}
|
||||
inline InventoryScrollableWindowComponent(geom2d::rect<float>rect,ITCategory invType,std::string itemNameLabelName,std::string itemDescriptionLabelName,std::function<bool(MenuFuncData)>inventoryButtonClickAction,std::function<bool(MenuFuncData)>inventoryButtonHoverAction,std::function<bool(MenuFuncData)>inventoryButtonMouseOutAction,InventoryWindowOptions options={.padding=8,.size=24},bool inventoryButtonsActive=true,ComponentAttr attributes=ComponentAttr::BACKGROUND|ComponentAttr::OUTLINE)
|
||||
:InventoryScrollableWindowComponent(rect,invType,itemNameLabelName,itemDescriptionLabelName,inventoryButtonClickAction,options,inventoryButtonsActive,attributes){
|
||||
this->inventoryButtonHoverAction=inventoryButtonHoverAction;
|
||||
this->inventoryButtonMouseOutAction=inventoryButtonMouseOutAction;
|
||||
}
|
||||
virtual inline void Update(Crawler*game)override{
|
||||
ScrollableWindowComponent::Update(game);
|
||||
@@ -78,6 +88,16 @@ public:
|
||||
if(itemDescriptionLabelName.length()>0)Component<MenuLabel>(parentMenu,itemDescriptionLabelName)->SetLabel("");
|
||||
}
|
||||
}
|
||||
inline void SetCompactDescriptions(bool compact){
|
||||
if(compact)this->compact=COMPACT;
|
||||
else this->compact=NON_COMPACT;
|
||||
for(MenuComponent*component:components){
|
||||
MenuItemButton*itemButton=dynamic_cast<MenuItemButton*>(component);
|
||||
if(itemButton){
|
||||
itemButton->SetCompactDescriptions(compact);
|
||||
}
|
||||
}
|
||||
}
|
||||
protected:
|
||||
inline void RemoveEmptySlots(){
|
||||
//Algorithm will iterate through all slots, finding blank slots. Each time a blank slot is found, all items will shift over by one, and then the last item will be removed. Repeat until all slots iterated through.
|
||||
@@ -111,7 +131,8 @@ protected:
|
||||
int buttonSize=options.size;
|
||||
int totalSpacing=options.padding+buttonSize;
|
||||
|
||||
ADD("item_"+cat+"_"+std::to_string(itemIndex),MenuItemButton)({{float(totalSpacing*x),float(totalSpacing*y)},{float(buttonSize),float(buttonSize)}},Inventory::get(cat),itemIndex,inventoryButtonClickAction,parentMenu,itemNameLabelName,itemDescriptionLabelName,inventoryButtonsActive?IconButtonAttr::SELECTABLE:IconButtonAttr::NOT_SELECTABLE)END;
|
||||
ADD("item_"+cat+"_"+std::to_string(itemIndex),MenuItemButton)({{float(totalSpacing*x),float(totalSpacing*y)},{float(buttonSize),float(buttonSize)}},Inventory::get(cat),itemIndex,inventoryButtonClickAction,inventoryButtonHoverAction,inventoryButtonMouseOutAction,parentMenu,itemNameLabelName,itemDescriptionLabelName,inventoryButtonsActive?IconButtonAttr::SELECTABLE:IconButtonAttr::NOT_SELECTABLE)END
|
||||
->SetCompactDescriptions(compact==COMPACT);
|
||||
}else
|
||||
if(components.size()>invSize){ //There are empty spots, so let's clean up.
|
||||
RemoveEmptySlots();
|
||||
|
||||
Reference in New Issue
Block a user