@ -44,11 +44,14 @@ class InventoryScrollableWindowComponent:public ScrollableWindowComponent{
private :
private :
std : : string itemNameLabelName ;
std : : string itemNameLabelName ;
std : : string itemDescriptionLabelName ;
std : : string itemDescriptionLabelName ;
bool inventoryButtonsActive = true ;
std : : function < bool ( MenuFuncData ) > inventoryButtonClickAction ;
protected :
protected :
ITCategory inventoryType ;
ITCategory inventoryType ;
public :
public :
inline InventoryScrollableWindowComponent ( MenuType parent , geom2d : : rect < float > rect , ITCategory invType , std : : string itemNameLabelName , std : : string itemDescriptionLabelName , ComponentAttr attributes = ComponentAttr : : BACKGROUND | ComponentAttr : : OUTLINE )
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 ) {
: ScrollableWindowComponent ( parent , rect , attributes ) , inventoryType ( invType ) , itemNameLabelName ( itemNameLabelName ) , itemDescriptionLabelName ( itemDescriptionLabelName ) ,
inventoryButtonClickAction ( inventoryButtonClickAction ) , inventoryButtonsActive ( inventoryButtonsActive ) {
Menu : : AddInventoryListener ( this , invType ) ;
Menu : : AddInventoryListener ( this , invType ) ;
}
}
virtual inline void Update ( Crawler * game ) override {
virtual inline void Update ( Crawler * game ) override {
@ -67,22 +70,24 @@ public:
}
}
protected :
protected :
virtual inline void RemoveButton ( MenuComponent * button ) {
virtual inline void RemoveButton ( MenuComponent * button ) {
std : : vector < MenuComponent * > & buttonList = Menu : : menus [ button - > parentMenu ] - > buttons . at ( button - > GetPos ( ) . y ) ;
if ( button - > selectable ) {
std : : vector < MenuComponent * > & keyboardButtonList = Menu : : menus [ button - > parentMenu ] - > keyboardButtons . at ( button - > GetPos ( ) . y ) ;
std : : vector < MenuComponent * > & buttonList = Menu : : menus [ button - > parentMenu ] - > buttons . at ( button - > GetPos ( ) . y ) ;
size_t removedCount = 0 ;
std : : vector < MenuComponent * > & keyboardButtonList = Menu : : menus [ button - > parentMenu ] - > keyboardButtons . at ( button - > GetPos ( ) . y ) ;
removedCount + = std : : erase ( buttonList , button ) ;
size_t removedCount = 0 ;
removedCount + = std : : erase ( keyboardButtonList , button ) ;
removedCount + = std : : erase ( buttonList , button ) ;
if ( removedCount ! = 2 ) {
removedCount + = std : : erase ( keyboardButtonList , button ) ;
std : : cout < < " WARNING! Attempted to remove buttons from button listing, but not found! " ;
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 ( buttonList . size ( ) = = 0 ) {
if ( keyboardButtonList . size ( ) = = 0 ) {
if ( ! Menu : : menus [ button - > parentMenu ] - > buttons . erase ( button - > GetPos ( ) . y ) ) {
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! " )
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! " )
}
}
}
}
}
}
}
@ -122,29 +127,7 @@ protected:
int buttonSize = " ThemeGlobal.InventoryButtonSize " _I ;
int buttonSize = " ThemeGlobal.InventoryButtonSize " _I ;
int totalSpacing = " ThemeGlobal.InventoryItemSpacing " _I + buttonSize ;
int totalSpacing = " ThemeGlobal.InventoryItemSpacing " _I + buttonSize ;
MenuFunc useItemFunc = [ & ] ( MenuFuncData data ) {
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 } ;
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 } ;
AddComponent ( Menu : : menus [ parentMenu ] , " item_ " + cat + " _ " + std : : to_string ( itemIndex ) , button ) ;
AddComponent ( Menu : : menus [ parentMenu ] , " item_ " + cat + " _ " + std : : to_string ( itemIndex ) , button ) ;
} else
} else
if ( components . size ( ) > invSize ) { //There are empty spots, so let's clean up.
if ( components . size ( ) > invSize ) { //There are empty spots, so let's clean up.