@ -47,22 +47,31 @@ class RowItemDisplay:public MenuComponent{
std : : string itemNameLabelName ;
std : : string itemDescriptionLabelName ;
CompactText compact = NON_COMPACT ;
bool showQuantity = true ;
public :
inline RowItemDisplay ( geom2d : : rect < float > rect , Item & itemRef , MenuFunc onClick , std : : string itemNameLabelName , std : : string itemDescriptionLabelName , ButtonAttr attributes = ButtonAttr : : NONE )
: MenuComponent ( rect , " " , onClick , attributes ) , itemNameLabelName ( itemNameLabelName ) , itemDescriptionLabelName ( itemDescriptionLabelName ) , itemRef ( itemRef ) {
}
: MenuComponent ( rect , " " , onClick , attributes ) , itemNameLabelName ( itemNameLabelName ) , itemDescriptionLabelName ( itemDescriptionLabelName ) , itemRef ( itemRef ) { }
virtual inline void DrawDecal ( ViewPort & window , bool focused ) final {
float scaleFactor = rect . size . y / 24 ;
MenuComponent : : DrawDecal ( window , focused ) ;
float scaleFactor = ( rect . size . y - 4 ) / 24 ;
vf2d iconSize = vf2d { scaleFactor , scaleFactor } * 24.f ;
window . DrawDecal ( rect . pos + vf2d { 2 , 2 } , itemRef . Decal ( ) , { scaleFactor , scaleFactor } ) ;
window . DrawRectDecal ( rect . pos + vf2d { 2 , 2 } , iconSize ) ;
window . DrawShadowStringPropDecal ( rect . pos + vf2d { 4 , 4 } + iconSize , itemRef . Name ( ) ) ;
std : : string itemName = itemRef . Name ( ) ;
vf2d scaledSize = { std : : min ( 1.f , ( rect . size . x - 6 - iconSize . x ) / game - > GetTextSizeProp ( itemName ) . x ) , 1 } ;
window . DrawShadowStringPropDecal ( rect . pos + vf2d { 4 , 4 } + vf2d { iconSize . x , iconSize . y / 2 - 4 } , itemName , WHITE , BLACK , scaledSize ) ;
if ( showQuantity ) {
std : : string quantityText = std : : format ( " x{} " , itemRef . Amt ( ) ) ;
vf2d qtyTextSize = game - > GetTextSizeProp ( quantityText ) ;
window . DrawShadowStringPropDecal ( rect . pos + rect . size - vf2d { 2 , 2 } + vf2d { - qtyTextSize . x , qtyTextSize . y } , quantityText ) ;
window . DrawShadowStringPropDecal ( rect . pos + rect . size - vf2d { 2 , 2 } + vf2d { - qtyTextSize . x , 0 } , quantityText ) ;
}
if ( selected ) {
window . DrawShadowStringDecal ( rect . pos + vf2d { 2 , 2 } + iconSize - vf2d { 8 , 8 } , " E " , GREEN , VERY_DARK_GREEN ) ;
}
}
inline void SetCompactDescriptions ( bool compact ) {
if ( compact ) this - > compact = COMPACT ;
@ -76,7 +85,14 @@ public:
Component < MenuLabel > ( parentMenu , itemDescriptionLabelName ) - > Enable ( false ) ;
}
}
virtual inline void OnHover ( ) override {
virtual inline void SetShowQuantity ( bool showQuantity ) {
this - > showQuantity = showQuantity ;
}
virtual inline Item & GetItem ( ) {
return itemRef ;
}
void UpdateLabel ( ) {
if ( itemRef . IsBlank ( ) ) return ;
std : : string labelNameText ;
std : : string labelDescriptionText ;
if ( valid ) {
@ -95,4 +111,7 @@ public:
Component < MenuLabel > ( parentMenu , itemDescriptionLabelName ) - > Enable ( true ) ;
}
}
virtual inline void OnHover ( ) override {
UpdateLabel ( ) ;
}
} ;