diff --git a/Crawler/CharacterMenuWindow.cpp b/Crawler/CharacterMenuWindow.cpp index 361770c2..09717f4a 100644 --- a/Crawler/CharacterMenuWindow.cpp +++ b/Crawler/CharacterMenuWindow.cpp @@ -46,6 +46,7 @@ All rights reserved. #include "EquipSlotButton.h" #include "Item.h" #include "ScrollableWindowComponent.h" +#include "RowItemDisplay.h" INCLUDE_game INCLUDE_GFX @@ -133,26 +134,37 @@ void Menu::InitializeCharacterMenuWindow(){ ScrollableWindowComponent*equipList=Component(data.component->parentMenu,"Equip List"); equipList->RemoveAllComponents(); for(int counter=0;Item&it:availableEquipment){ - float xOffset=(counter%3)*26; Item&itemInvRef=Inventory::GetItem(it.Name()); - auto equip=equipList->ADD("Equip Item "+std::to_string(counter),MenuItemItemButton)({{2+xOffset,2},{24,24}},itemInvRef,MenuType::ENUM_END, + auto equip=equipList->ADD("Equip Item "+std::to_string(counter),RowItemDisplay)({{2,2+counter*28.f},{120-12,28}},itemInvRef, [](MenuFuncData data){ - MenuItemItemButton*comp=(MenuItemItemButton*)data.component; - Inventory::EquipItem(comp->GetItem(),EquipSlot(comp->I(Attribute::EQUIP_TYPE))); - for(MenuComponent*button:((ScrollableWindowComponent*)data.parentComponent)->GetComponents()){ - MenuItemItemButton*comp=(MenuItemItemButton*)button; - comp->SetSelected(false); - } - comp->SetSelected(true); - for(int counter=0;ItemAttribute attribute:displayAttrs){ - StatLabel*statDisplayLabel=Component(CHARACTER_MENU,"Attribute "+ItemAttributable::GetDisplayInfo(attribute).name+" Label"); - statDisplayLabel->SetStatChangeAmt(0); + RowItemDisplay*comp=dynamic_cast(data.component); + if(comp!=nullptr){ + Inventory::EquipItem(comp->GetItem(),EquipSlot(comp->I(Attribute::EQUIP_TYPE))); + for(MenuComponent*button:((ScrollableWindowComponent*)data.parentComponent)->GetComponents()){ + RowItemDisplay*comp=dynamic_cast(button); + if(comp!=nullptr){ + comp->SetSelected(false); + }else{ + ERR("WARNING! Attempting to cast a button that isn't a RowItemDisplay!"); + } + } + comp->SetSelected(true); + for(int counter=0;ItemAttribute attribute:displayAttrs){ + StatLabel*statDisplayLabel=Component(CHARACTER_MENU,"Attribute "+ItemAttributable::GetDisplayInfo(attribute).name+" Label"); + statDisplayLabel->SetStatChangeAmt(0); + } + MenuItemItemButton*equipButton=Component(CHARACTER_MENU,"Equip Slot "+slotNames[data.parentComponent->I(A::INDEXED_THEME)]); + equipButton->SetItem(comp->GetItem()); + }else{ + ERR("WARNING! Attempting to cast a button that isn't a RowItemDisplay!"); } - MenuItemItemButton*equipButton=Component(CHARACTER_MENU,"Equip Slot "+slotNames[data.parentComponent->I(A::INDEXED_THEME)]); - equipButton->SetItem(comp->GetItem()); return true; - },[&](MenuFuncData data){ - MenuItemItemButton*button=(MenuItemItemButton*)data.component; + },"Item Name","Item Description")END; + + equip->SetHoverFunc( + [&](MenuFuncData data){ + RowItemDisplay*button=dynamic_cast(data.component); + if(button!=nullptr){ Item&buttonItem=button->GetItem(); std::vectorstatsBeforeEquip; EquipSlot slot=EquipSlot(button->I(Attribute::EQUIP_TYPE)); @@ -171,16 +183,24 @@ void Menu::InitializeCharacterMenuWindow(){ if(*equippedItem!=Item::BLANK){ Inventory::EquipItem(*equippedItem,slot); } + }else{ + ERR("WARNING! Attempting to cast a button that isn't a RowItemDisplay!"); + } return true; - },[](MenuFuncData data){ + }); + equip->SetMouseOutFunc( + [](MenuFuncData data){ for(int counter=0;ItemAttribute attribute:displayAttrs){ StatLabel*statDisplayLabel=Component(CHARACTER_MENU,"Attribute "+ItemAttributable::GetDisplayInfo(attribute).name+" Label"); statDisplayLabel->SetStatChangeAmt(0); counter++; } return true; - },"Item Name","Item Description")END; - + }); + + equip->SetShowQuantity(false); + equip->SetSelectionType(SelectionType::NONE); + equip->I(Attribute::EQUIP_TYPE)=int(slot); if(Inventory::GetEquip(slot)==&itemInvRef){ equip->SetSelected(true); diff --git a/Crawler/Menu.h b/Crawler/Menu.h index adf9f8a3..4cdbfcf9 100644 --- a/Crawler/Menu.h +++ b/Crawler/Menu.h @@ -231,7 +231,12 @@ private: template T*Component(MenuType menu,std::string componentName){ - return (T*)Menu::menus[menu]->components[componentName]; + T*tmp=dynamic_cast(Menu::menus[menu]->components[componentName]); + if(tmp!=nullptr){ + return tmp; + }else{ + ERR("WARNING! Attempting to cast a button that isn't a "<0){ + if(itemNameLabelName!=""){ Component(parentMenu,itemNameLabelName)->label=labelNameText; Component(parentMenu,itemNameLabelName)->Enable(true); } - if(itemDescriptionLabelName!=""&&labelDescriptionText.length()>0){ + if(itemDescriptionLabelName!=""){ Component(parentMenu,itemDescriptionLabelName)->label=labelDescriptionText; Component(parentMenu,itemDescriptionLabelName)->Enable(true); } diff --git a/Crawler/RowItemDisplay.h b/Crawler/RowItemDisplay.h index a22c3b97..58c19610 100644 --- a/Crawler/RowItemDisplay.h +++ b/Crawler/RowItemDisplay.h @@ -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::rectrect,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}; - 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+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,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(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(parentMenu,itemDescriptionLabelName)->Enable(true); } } + virtual inline void OnHover()override{ + UpdateLabel(); + } }; \ No newline at end of file diff --git a/Crawler/Version.h b/Crawler/Version.h index 72c4470a..144af1bf 100644 --- a/Crawler/Version.h +++ b/Crawler/Version.h @@ -39,7 +39,7 @@ All rights reserved. #define VERSION_MAJOR 0 #define VERSION_MINOR 2 #define VERSION_PATCH 1 -#define VERSION_BUILD 3990 +#define VERSION_BUILD 4009 #define stringify(a) stringify_(a) #define stringify_(a) #a