diff --git a/olcCodeJam2023Entry/Textbox.cpp b/olcCodeJam2023Entry/Textbox.cpp index 390158c..e8f41e8 100644 --- a/olcCodeJam2023Entry/Textbox.cpp +++ b/olcCodeJam2023Entry/Textbox.cpp @@ -52,11 +52,22 @@ void Textbox::Update(PixelGameEngine*pge){ void Textbox::Draw(PixelGameEngine*pge,Resources&resources){ if(visible){ - vf2d finalPos=pos; geom2d::rectboxRect={pos-vf2d{2,2},maxSize+vf2d{4,4}}; - pge->FillRectDecal(pos-vf2d{2,2},maxSize+vf2d{4,4},VERY_DARK_GREEN); - pge->DrawRectDecal(pos-vf2d{1,1},maxSize+vf2d{3,3},WHITE); - pge->DrawShadowStringPropDecal(pos+vf2d{1,1},displayText,{220,220,220}); + if(boxRect.bottom().start.y>=pge->ScreenHeight()){ + boxRect.pos-={0,boxRect.bottom().start.y-pge->ScreenHeight()}; + } + if(boxRect.right().start.x>=pge->ScreenWidth()){ + boxRect.pos-={boxRect.right().start.x-pge->ScreenWidth(),0}; + } + if(boxRect.top().start.y<0){ + boxRect.pos+={0,-boxRect.top().start.y}; + } + if(boxRect.left().start.x<0){ + boxRect.pos+={-boxRect.left().start.x,0}; + } + pge->FillRectDecal(boxRect.pos,maxSize+vf2d{4,4},VERY_DARK_GREEN); + pge->DrawRectDecal(boxRect.pos+vf2d{1,1},maxSize+vf2d{3,3},WHITE); + pge->DrawShadowStringPropDecal(boxRect.pos+vf2d{3,3},displayText,{220,220,220}); } } @@ -79,4 +90,8 @@ void Textbox::UpdateAndDraw(vf2d pos,PixelGameEngine*pge,Resources&resources){ UpdatePosition(pos); Update(pge); Draw(pge,resources); +} + +vf2d Textbox::GetSize(){ + return maxSize; } \ No newline at end of file diff --git a/olcCodeJam2023Entry/Textbox.h b/olcCodeJam2023Entry/Textbox.h index 9e95cf3..d83138f 100644 --- a/olcCodeJam2023Entry/Textbox.h +++ b/olcCodeJam2023Entry/Textbox.h @@ -24,6 +24,7 @@ public: void UpdateAndDraw(vf2d pos,PixelGameEngine*pge,Resources&resources); std::string&GetCurrentString(); void SetVisible(bool visible); + vf2d GetSize(); private: void Update(PixelGameEngine*pge); void UpdatePosition(vf2d newPos); diff --git a/olcCodeJam2023Entry/VirusAttack.cpp b/olcCodeJam2023Entry/VirusAttack.cpp index 3bfba1f..e281943 100644 --- a/olcCodeJam2023Entry/VirusAttack.cpp +++ b/olcCodeJam2023Entry/VirusAttack.cpp @@ -61,6 +61,7 @@ bool VirusAttack::OnUserCreate(){ unitCreationBox.Initialize("Hello world, this is a test of the textbox system.\nMaybe even with some newline characters snuck in there.", {}); unitCreationBox.SetVisible(false); + testBox.Initialize("Hello world, this is a test of the textbox system.\nMaybe even with some newline characters snuck in there.",{}); IMAGES[MINIMAP_OUTLINE]=std::make_unique(); IMAGES[MINIMAP_OUTLINE]->Create(64,64); @@ -534,6 +535,7 @@ bool VirusAttack::OnUserUpdate(float fElapsedTime){ DrawMinimap(); unitCreationBox.UpdateAndDraw(GetMousePos(),this,player_resources); + testBox.UpdateAndDraw(GetMousePos()-testBox.GetSize()/2,this,player_resources); std::sort(units.begin(),units.end(),[&](auto&u1,auto&u2){ float dist1=geom2d::line(u1->GetGhostPos(),GetWorldMousePos()).length(); diff --git a/olcCodeJam2023Entry/VirusAttack.h b/olcCodeJam2023Entry/VirusAttack.h index 847b996..f6eb507 100644 --- a/olcCodeJam2023Entry/VirusAttack.h +++ b/olcCodeJam2023Entry/VirusAttack.h @@ -38,7 +38,7 @@ private: TileTransformedView game; - Textbox unitCreationBox; + Textbox unitCreationBox,testBox; QuickGUI::Manager unitCreationList; QuickGUI::ImageButton*leftShifterButton;