#pragma once #include "MenuLabel.h" #include "DEFINES.h" #include "Crawler.h" #include "utils.h" #include "Ability.h" INCLUDE_game INCLUDE_GFX #define ICONPOS vi2d iconPos=parentPos+rect.pos+vi2d{5,5}; class CharacterAbilityPreviewComponent:public MenuLabel{ Ability*ability; public: inline CharacterAbilityPreviewComponent(MenuType parent,geom2d::rectrect,Ability*ability) :MenuLabel(parent,rect,"",1,true,false,true,true),ability(ability){} protected: virtual void inline Update(Crawler*game)override{ MenuLabel::Update(game); } virtual void inline Draw(Crawler*game,vf2d parentPos)override{ MenuLabel::Draw(game,parentPos); game->DrawRect(parentPos+rect.pos+vi2d{2,2},vi2d{int(rect.size.y)-4,int(rect.size.y)-4}); ICONPOS game->DrawSprite(iconPos,GFX[ability->icon].Sprite()); vi2d descriptionPos=iconPos+vi2d{int(rect.size.y)-2,1}; game->DrawShadowStringProp(descriptionPos,util::WrapText(game,ability->description,rect.size.x-(descriptionPos.x-rect.pos.x),true,{1,1})); } virtual void inline DrawDecal(Crawler*game,vf2d parentPos,bool focused)override{ ICONPOS vi2d textPos=iconPos+vi2d{12,12}; float textWidth=game->GetTextSizeProp(ability->input->GetDisplayName()).x*0.5+4; float boxWidth=rect.size.y-4; //No, the y is not a typo. It's a square, we use the y to determine the x. if(textWidth>boxWidth){ game->DrawShadowStringPropDecal(textPos,ability->input->GetDisplayName(),WHITE,BLACK,{boxWidth/textWidth*0.5f,0.5}); }else{ game->DrawShadowStringPropDecal(textPos,ability->input->GetDisplayName(),WHITE,BLACK,{0.5,0.5}); } } };