@ -44,11 +44,14 @@ class InventoryScrollableWindowComponent:public ScrollableWindowComponent{
private :
std : : string itemNameLabelName ;
std : : string itemDescriptionLabelName ;
bool inventoryButtonsActive = true ;
std : : function < bool ( MenuFuncData ) > inventoryButtonClickAction ;
protected :
ITCategory inventoryType ;
public :
inline InventoryScrollableWindowComponent ( MenuType parent , geom2d : : rect < float > rect , ITCategory invType , std : : string itemNameLabelName , std : : string itemDescriptionLabelName , ComponentAttr attributes = ComponentAttr : : BACKGROUND | ComponentAttr : : OUTLINE )
: ScrollableWindowComponent ( parent , rect , attributes ) , inventoryType ( invType ) , itemNameLabelName ( itemNameLabelName ) , itemDescriptionLabelName ( itemDescriptionLabelName ) {
inline InventoryScrollableWindowComponent ( MenuType parent , geom2d : : rect < float > rect , ITCategory invType , std : : string itemNameLabelName , std : : string itemDescriptionLabelName , std : : function < bool ( MenuFuncData ) > inventoryButtonClickAction , bool inventoryButtonsActive = true , ComponentAttr attributes = ComponentAttr : : BACKGROUND | ComponentAttr : : OUTLINE )
: ScrollableWindowComponent ( parent , rect , attributes ) , inventoryType ( invType ) , itemNameLabelName ( itemNameLabelName ) , itemDescriptionLabelName ( itemDescriptionLabelName ) ,
inventoryButtonClickAction ( inventoryButtonClickAction ) , inventoryButtonsActive ( inventoryButtonsActive ) {
Menu : : AddInventoryListener ( this , invType ) ;
}
virtual inline void Update ( Crawler * game ) override {
@ -67,22 +70,24 @@ public:
}
protected :
virtual inline void RemoveButton ( MenuComponent * button ) {
std : : vector < MenuComponent * > & buttonList = Menu : : menus [ button - > parentMenu ] - > buttons . at ( button - > GetPos ( ) . y ) ;
std : : vector < MenuComponent * > & keyboardButtonList = Menu : : menus [ button - > parentMenu ] - > keyboardButtons . at ( button - > GetPos ( ) . y ) ;
size_t removedCount = 0 ;
removedCount + = std : : erase ( buttonList , button ) ;
removedCount + = std : : erase ( keyboardButtonList , button ) ;
if ( removedCount ! = 2 ) {
std : : cout < < " WARNING! Attempted to remove buttons from button listing, but not found! " ;
}
if ( buttonList . size ( ) = = 0 ) {
if ( ! Menu : : menus [ button - > parentMenu ] - > buttons . erase ( button - > GetPos ( ) . y ) ) {
ERR ( " WARNING! Attempted to erase key " < < button - > GetPos ( ) . y < < " from button map, but the list still exists! " )
if ( button - > selectable ) {
std : : vector < MenuComponent * > & buttonList = Menu : : menus [ button - > parentMenu ] - > buttons . at ( button - > GetPos ( ) . y ) ;
std : : vector < MenuComponent * > & keyboardButtonList = Menu : : menus [ button - > parentMenu ] - > keyboardButtons . at ( button - > GetPos ( ) . y ) ;
size_t removedCount = 0 ;
removedCount + = std : : erase ( buttonList , button ) ;
removedCount + = std : : erase ( keyboardButtonList , button ) ;
if ( removedCount ! = 2 ) {
std : : cout < < " WARNING! Attempted to remove buttons from button listing, but not found! " ;
}
}
if ( keyboardButtonList . size ( ) = = 0 ) {
if ( ! Menu : : menus [ button - > parentMenu ] - > keyboardButtons . erase ( button - > GetPos ( ) . y ) ) {
ERR ( " WARNING! Attempted to erase key " < < button - > GetPos ( ) . y < < " from button map, but the list still exists! " )
if ( buttonList . size ( ) = = 0 ) {
if ( ! Menu : : menus [ button - > parentMenu ] - > buttons . erase ( button - > GetPos ( ) . y ) ) {
ERR ( " WARNING! Attempted to erase key " < < button - > GetPos ( ) . y < < " from button map, but the list still exists! " )
}
}
if ( keyboardButtonList . size ( ) = = 0 ) {
if ( ! Menu : : menus [ button - > parentMenu ] - > keyboardButtons . erase ( button - > GetPos ( ) . y ) ) {
ERR ( " WARNING! Attempted to erase key " < < button - > GetPos ( ) . y < < " from button map, but the list still exists! " )
}
}
}
}
@ -121,30 +126,8 @@ protected:
int buttonSize = " ThemeGlobal.InventoryButtonSize " _I ;
int totalSpacing = " ThemeGlobal.InventoryItemSpacing " _I + buttonSize ;
MenuFunc useItemFunc = [ & ] ( MenuFuncData data ) {
MenuItemButton * button = ( MenuItemButton * ) data . component ;
data . game - > ClearLoadoutItem ( data . menu . I ( A : : LOADOUT_SLOT ) ) ;
for ( MenuComponent * component : components ) {
if ( component - > GetName ( ) . starts_with ( " item " ) ) {
MenuItemButton * button2 = ( MenuItemButton * ) component ; //HACK ALERT! This is probably an item since we populated item lists using this name for the components. So we assume these are MenuItemButton classes.
if ( button2 = = button ) {
if ( button2 - > selected ! = - 1 ) {
data . game - > ClearLoadoutItem ( button2 - > selected ) ;
}
button2 - > selected = - 1 ;
}
if ( button2 - > selected = = data . menu . I ( A : : LOADOUT_SLOT ) ) {
button2 - > selected = - 1 ;
}
}
}
button - > selected = data . menu . I ( A : : LOADOUT_SLOT ) ;
data . game - > SetLoadoutItem ( button - > selected , button - > GetItem ( ) . Name ( ) ) ;
return true ;
} ;
MenuItemButton * button = NEW MenuItemButton { parentMenu , { { float ( totalSpacing * x ) , float ( totalSpacing * y ) } , { float ( buttonSize ) , float ( buttonSize ) } } , Inventory : : get ( cat ) , itemIndex , useItemFunc , parentMenu , itemNameLabelName , itemDescriptionLabelName } ;
MenuItemButton * button = NEW MenuItemButton { parentMenu , { { float ( totalSpacing * x ) , float ( totalSpacing * y ) } , { float ( buttonSize ) , float ( buttonSize ) } } , Inventory : : get ( cat ) , itemIndex , inventoryButtonClickAction , parentMenu , itemNameLabelName , itemDescriptionLabelName , inventoryButtonsActive ? IconButtonAttr : : SELECTABLE : IconButtonAttr : : NOT_SELECTABLE } ;
AddComponent ( Menu : : menus [ parentMenu ] , " item_ " + cat + " _ " + std : : to_string ( itemIndex ) , button ) ;
} else
if ( components . size ( ) > invSize ) { //There are empty spots, so let's clean up.