Add in size display and limit warning for textboxes.

CorrectiveAction
sigonasr2 1 year ago
parent fee862adf5
commit 1493faa8e5
  1. 13
      olcCodeJam2023Entry/Textbox.cpp
  2. 4
      olcCodeJam2023Entry/Textbox.h
  3. 8
      olcCodeJam2023Entry/VirusAttack.cpp

@ -68,7 +68,7 @@ void Textbox::Update(PixelGameEngine*pge){
}
void Textbox::Draw(PixelGameEngine*pge,Resources&resources,std::map<Image,std::unique_ptr<Renderable>>&IMAGES){
void Textbox::Draw(PixelGameEngine*pge,Resources&resources,std::map<Image,std::unique_ptr<Renderable>>&IMAGES,int totalUsedMemory,int memoryLimit){
if(visible){
geom2d::rect<float>boxRect={pos-vf2d{3,3},maxSize+vf2d{6,6}};
if(resourceCost.size()>0){
@ -145,7 +145,12 @@ void Textbox::Draw(PixelGameEngine*pge,Resources&resources,std::map<Image,std::u
}
std::string text="Size: "+std::to_string(totalCost)+" bytes";
vi2d size=pge->GetTextSizeProp(text);
pge->DrawShadowStringPropDecal(contentPos+vf2d{0,index*6.f+1},text,WHITE,BLACK,{30/float(size.x),0.5},0.6);
drawcol=WHITE;
if(totalCost+totalUsedMemory>memoryLimit){
pge->FillRectDecal(contentPos+vf2d{-1,float(index*6)},vf2d{resourceBoxRect.size.x-4,7},{160,0,0,192});
drawcol=RED;
}
pge->DrawShadowStringPropDecal(contentPos+vf2d{0,index*6.f+1},text,drawcol,BLACK,{30/float(size.x),0.5},0.6);
index++;
}
}
@ -166,10 +171,10 @@ void Textbox::SetVisible(bool visible){
}
}
void Textbox::UpdateAndDraw(vf2d pos,PixelGameEngine*pge,Resources&resources,std::map<Image,std::unique_ptr<Renderable>>&IMAGES){
void Textbox::UpdateAndDraw(vf2d pos,PixelGameEngine*pge,Resources&resources,std::map<Image,std::unique_ptr<Renderable>>&IMAGES,int totalUsedMemory,int memoryLimit){
UpdatePosition(pos);
Update(pge);
Draw(pge,resources,IMAGES);
Draw(pge,resources,IMAGES,totalUsedMemory,memoryLimit);
}
vf2d Textbox::GetSize(){

@ -25,7 +25,7 @@ public:
Textbox();
void Initialize(std::string text,vf2d pos={},std::string headerText="",vf2d maxSize={120,1},std::vector<Memory>resourceCost={},float letterDisplayDelay=0.01);
void UpdateAndDraw(vf2d pos,PixelGameEngine*pge,Resources&resources,std::map<Image,std::unique_ptr<Renderable>>&IMAGES);
void UpdateAndDraw(vf2d pos,PixelGameEngine*pge,Resources&resources,std::map<Image,std::unique_ptr<Renderable>>&IMAGES,int totalUsedMemory,int memoryLimit);
std::string&GetCurrentString();
void SetVisible(bool visible);
vf2d GetSize();
@ -34,6 +34,6 @@ public:
private:
void Update(PixelGameEngine*pge);
void UpdatePosition(vf2d newPos);
void Draw(PixelGameEngine*pge,Resources&resources,std::map<Image,std::unique_ptr<Renderable>>&IMAGES);
void Draw(PixelGameEngine*pge,Resources&resources,std::map<Image,std::unique_ptr<Renderable>>&IMAGES,int totalUsedMemory,int memoryLimit);
void SetDefaults();
};

@ -775,10 +775,10 @@ bool VirusAttack::OnUserUpdate(float fElapsedTime){
DrawMinimap();
currentLevel->scenario->_Draw();
unitCreationBox.UpdateAndDraw(GetMousePos()+vi2d{8,-28},this,player_resources,IMAGES);
testBox.UpdateAndDraw(GetMousePos()-testBox.GetSize()/2,this,player_resources,IMAGES);
memoryAllocatorBox.UpdateAndDraw(GetMousePos()+vi2d{8,-28},this,player_resources,IMAGES);
platformCreationBox.UpdateAndDraw(GetMousePos()+vi2d{8,-28},this,player_resources,IMAGES);
unitCreationBox.UpdateAndDraw(GetMousePos()+vi2d{8,-28},this,player_resources,IMAGES,GetTotalUsedMemory(),currentLevel->availableMemory);
testBox.UpdateAndDraw(GetMousePos()-testBox.GetSize()/2,this,player_resources,IMAGES,GetTotalUsedMemory(),currentLevel->availableMemory);
memoryAllocatorBox.UpdateAndDraw(GetMousePos()+vi2d{8,-28},this,player_resources,IMAGES,GetTotalUsedMemory(),currentLevel->availableMemory);
platformCreationBox.UpdateAndDraw(GetMousePos()+vi2d{8,-28},this,player_resources,IMAGES,GetTotalUsedMemory(),currentLevel->availableMemory);
std::sort(units.begin(),units.end(),[&](auto&u1,auto&u2){
float dist1=geom2d::line<float>(u1->GetGhostPos(),GetWorldMousePos()).length();

Loading…
Cancel
Save