@ -60,6 +60,36 @@ void Menu::InitializeMerchantWindow(){
}
std : : sort ( categories . begin ( ) , categories . end ( ) , [ ] ( std : : pair < std : : string , int > & cat1 , std : : pair < std : : string , int > & cat2 ) { return cat1 . second < cat2 . second ; } ) ;
auto buyTab = merchantWindow - > ADD ( " Buy Tab " , MenuComponent ) ( { { 2 , 0 } , { merchantWindow - > size . x / 2 - 4 , 24 } } , " Buy " , [ ] ( MenuFuncData data ) {
Component < RowMerchantInventoryScrollableWindowComponent > ( MERCHANT , " Merchant Inventory Display " ) - > Enable ( true ) ;
Component < MenuComponent > ( MERCHANT , " Sell Tab " ) - > selected = false ;
Component < MenuComponent > ( MERCHANT , " Inventory Tabs Outline " ) - > Enable ( false ) ;
for ( auto & [ category , items ] : ITEM_CATEGORIES ) {
if ( DATA [ " ItemCategory " ] [ category ] . GetString ( 0 ) = = " !HIDE " ) continue ; //This category is meant to be hidden!
Component < MenuComponent > ( MERCHANT , category + " Inventory Tab " ) - > Enable ( false ) ;
}
Component < RowInventoryScrollableWindowComponent > ( data . menu . GetType ( ) , " Inventory Display - " + data . menu . S ( A : : LAST_INVENTORY_TYPE_OPENED ) ) - > Enable ( false ) ;
Component < MenuComponent > ( data . menu . GetType ( ) , data . menu . S ( A : : LAST_INVENTORY_TYPE_OPENED ) + " Inventory Tab " ) - > Enable ( false ) ;
data . component - > selected = true ;
return true ;
} ) END ;
buyTab - > selected = true ;
buyTab - > selectionType = SelectionType : : HIGHLIGHT ;
auto sellTab = merchantWindow - > ADD ( " Sell Tab " , MenuComponent ) ( { { merchantWindow - > size . x / 2 + 2 , 0 } , { merchantWindow - > size . x / 2 - 4 , 24 } } , " Sell " , [ ] ( MenuFuncData data ) {
Component < RowMerchantInventoryScrollableWindowComponent > ( MERCHANT , " Merchant Inventory Display " ) - > Enable ( false ) ;
Component < MenuComponent > ( MERCHANT , " Buy Tab " ) - > selected = false ;
Component < MenuComponent > ( MERCHANT , " Inventory Tabs Outline " ) - > Enable ( true ) ;
for ( auto & [ category , items ] : ITEM_CATEGORIES ) {
if ( DATA [ " ItemCategory " ] [ category ] . GetString ( 0 ) = = " !HIDE " ) continue ; //This category is meant to be hidden!
Component < MenuComponent > ( MERCHANT , category + " Inventory Tab " ) - > Enable ( true ) ;
}
Component < RowInventoryScrollableWindowComponent > ( data . menu . GetType ( ) , " Inventory Display - " + data . menu . S ( A : : LAST_INVENTORY_TYPE_OPENED ) ) - > Enable ( true ) ;
Component < MenuComponent > ( data . menu . GetType ( ) , data . menu . S ( A : : LAST_INVENTORY_TYPE_OPENED ) + " Inventory Tab " ) - > Enable ( true ) ;
data . component - > selected = true ;
return true ;
} ) END ;
sellTab - > selectionType = SelectionType : : HIGHLIGHT ;
auto inventoryDisplay = merchantWindow - > ADD ( " Merchant Inventory Display " , RowMerchantInventoryScrollableWindowComponent ) ( { { 2 , 28 } , { 220 , merchantWindow - > size . y - 44 } } , " Item Name Label " , " Item Description Label " ,
[ ] ( MenuFuncData data ) {
@ -94,6 +124,73 @@ void Menu::InitializeMerchantWindow(){
Menu : : AddMerchantInventoryListener ( inventoryDisplay , category ) ;
}
merchantWindow - > ADD ( " Inventory Tabs Outline " , MenuComponent ) ( { { 0 , 28 } , { 72 , merchantWindow - > size . y - 44 } } , " " , DO_NOTHING , ButtonAttr : : UNSELECTABLE ) END ;
std : : sort ( categories . begin ( ) , categories . end ( ) , [ ] ( std : : pair < std : : string , int > & cat1 , std : : pair < std : : string , int > & cat2 ) { return cat1 . second < cat2 . second ; } ) ;
# pragma region Inventory Tabs
bool first = true ;
for ( float yOffset = 0 ; auto & [ category , sortOrder ] : categories ) {
float textWidth = game - > GetTextSizeProp ( category ) . x ;
float buttonWidth = 64 ;
float textScaling = std : : min ( 1.f , buttonWidth / textWidth ) ;
auto button = merchantWindow - > ADD ( category + " Inventory Tab " , MenuComponent ) ( { { 2 , 30 + yOffset } , { 68 , 16 } } , category , MenuType : : ENUM_END ,
[ & ] ( MenuFuncData data ) {
//Close the old inventory window and show the proper one.
Component < RowInventoryScrollableWindowComponent > ( data . menu . GetType ( ) , " Inventory Display - " + data . menu . S ( A : : LAST_INVENTORY_TYPE_OPENED ) ) - > Enable ( false ) ;
Component < MenuComponent > ( data . menu . GetType ( ) , data . menu . S ( A : : LAST_INVENTORY_TYPE_OPENED ) + " Inventory Tab " ) - > SetSelected ( false ) ;
Component < RowInventoryScrollableWindowComponent > ( data . menu . GetType ( ) , " Inventory Display - " + data . component - > S ( A : : CATEGORY_NAME ) ) - > Enable ( true ) ;
Component < MenuComponent > ( data . menu . GetType ( ) , data . component - > S ( A : : CATEGORY_NAME ) + " Inventory Tab " ) - > SetSelected ( true ) ;
data . menu . S ( A : : LAST_INVENTORY_TYPE_OPENED ) = data . component - > S ( A : : CATEGORY_NAME ) ;
return true ;
} , { textScaling , 1.f } ) END ;
button - > SetSelectionType ( HIGHLIGHT ) ;
button - > S ( A : : CATEGORY_NAME ) = category ;
auto inventoryDisplay = merchantWindow - > ADD ( " Inventory Display - " + category , RowInventoryScrollableWindowComponent ) ( { { 72 , 28 } , { 150 , merchantWindow - > size . y - 44 } } , category , " Item Name Label " , " Item Description Label " ,
[ ] ( MenuFuncData data ) {
RowItemDisplay * item = dynamic_cast < RowItemDisplay * > ( data . component ) ;
Component < MenuLabel > ( SELL_ITEM , " Item Sell Header " ) - > S ( A : : ITEM_NAME ) = item - > GetItem ( ) . lock ( ) - > ActualName ( ) ;
Component < MenuLabel > ( SELL_ITEM , " Price per item Amount Label " ) - > SetLabel ( std : : to_string ( item - > GetItem ( ) . lock ( ) - > BuyValue ( ) ) ) ;
Component < MenuLabel > ( SELL_ITEM , " Amount to sell Amount Label " ) - > SetLabel ( " 1 " ) ;
Component < MenuLabel > ( SELL_ITEM , " Total Price Amount Label " ) - > SetLabel ( std : : to_string ( item - > GetItem ( ) . lock ( ) - > BuyValue ( ) ) ) ;
Merchant & merchant = Merchant : : GetCurrentTravelingMerchant ( ) ;
bool canPurchase = merchant . CanPurchaseItem ( item - > GetItem ( ) . lock ( ) - > ActualName ( ) , 1 ) ;
std : : string colorCode = " " ;
if ( ! canPurchase ) colorCode = " #FF0000 " ;
Component < MenuLabel > ( SELL_ITEM , " Total Price Amount Label " ) - > SetLabel ( colorCode + std : : to_string ( item - > GetItem ( ) . lock ( ) - > BuyValue ( ) ) ) ;
Component < MenuLabel > ( SELL_ITEM , " Item Purchase Header " ) - > SetLabel ( " Buying " + item - > GetItem ( ) . lock ( ) - > DisplayName ( ) ) ;
Component < MenuComponent > ( SELL_ITEM , " Purchase Button " ) - > SetGrayedOut ( ! merchant . CanPurchaseItem ( item - > GetItem ( ) . lock ( ) - > ActualName ( ) , 1 ) ) ;
Menu : : OpenMenu ( SELL_ITEM ) ;
return true ;
} ,
[ ] ( MenuFuncData data ) {
Component < MenuItemItemButton > ( data . menu . GetType ( ) , " Item Icon " ) - > SetItem ( dynamic_cast < RowItemDisplay * > ( data . component ) - > GetItem ( ) ) ;
Component < MenuItemItemButton > ( data . menu . GetType ( ) , " Item Icon " ) - > UpdateIcon ( ) ;
return true ;
} ,
[ ] ( MenuFuncData data ) {
Component < MenuItemItemButton > ( data . menu . GetType ( ) , " Item Icon " ) - > SetItem ( Item : : BLANK ) ;
Component < MenuItemItemButton > ( data . menu . GetType ( ) , " Item Icon " ) - > UpdateIcon ( ) ;
return true ;
} , { . padding = 1 , . size = { 137 , 28 } } ) END ;
if ( first ) {
merchantWindow - > S ( A : : LAST_INVENTORY_TYPE_OPENED ) = category ;
button - > onClick ( MenuFuncData { * merchantWindow , game , button } ) ; //Simulate a click of this button if it's the top one for an initial inventory display.
}
Menu : : AddInventoryListener ( inventoryDisplay , category ) ;
inventoryDisplay - > Enable ( first ) ;
inventoryDisplay - > SetCompactDescriptions ( false ) ;
yOffset + = 20 ;
first = false ;
}
# pragma endregion
# pragma region Inventory Description
float inventoryDescriptionWidth = merchantWindow - > pos . x + merchantWindow - > size . x - 26 - 224 ;
merchantWindow - > ADD ( " Item Description Outline " , MenuLabel ) ( { { 224 , 28 } , { inventoryDescriptionWidth , merchantWindow - > size . y - 44 } } , " " , 1 , ComponentAttr : : LEFT_ALIGN | ComponentAttr : : OUTLINE | ComponentAttr : : BACKGROUND ) END ;
@ -117,4 +214,6 @@ void Menu::InitializeMerchantWindow(){
Menu : : CloseMenu ( ) ;
return true ;
} , { 2 , 2 } ) END ;
buyTab - > onClick ( MenuFuncData { * merchantWindow , game , buyTab } ) ;
}