diff --git a/olcCodeJam2023Entry/Constant.cpp b/olcCodeJam2023Entry/Constant.cpp index 8adf792..a1284fd 100644 --- a/olcCodeJam2023Entry/Constant.cpp +++ b/olcCodeJam2023Entry/Constant.cpp @@ -31,4 +31,6 @@ float CONSTANT::COLLECTION_WAIT_TIME=8; int CONSTANT::MEMORY_ALLOCATOR_COST=5; float CONSTANT::UNIT_BUILD_TIME=10; -int CONSTANT::STARTING_RESOURCE_COUNT=5; \ No newline at end of file +int CONSTANT::STARTING_RESOURCE_COUNT=5; + +Pixel CONSTANT::MESSAGE_BOX_DEFAULT_BACKCOL=VERY_DARK_GREEN; \ No newline at end of file diff --git a/olcCodeJam2023Entry/Constant.h b/olcCodeJam2023Entry/Constant.h index 483de35..abf7b0a 100644 --- a/olcCodeJam2023Entry/Constant.h +++ b/olcCodeJam2023Entry/Constant.h @@ -36,4 +36,6 @@ public: static float UNIT_BUILD_TIME; static int STARTING_RESOURCE_COUNT; + + static Pixel MESSAGE_BOX_DEFAULT_BACKCOL; }; \ No newline at end of file diff --git a/olcCodeJam2023Entry/Textbox.cpp b/olcCodeJam2023Entry/Textbox.cpp index 8c8d553..aa36946 100644 --- a/olcCodeJam2023Entry/Textbox.cpp +++ b/olcCodeJam2023Entry/Textbox.cpp @@ -1,5 +1,6 @@ #include "Textbox.h" #include "olcUTIL_Geometry2D.h" +#include "util.h" Textbox::Textbox(){}; @@ -66,9 +67,13 @@ void Textbox::Update(PixelGameEngine*pge){ } -void Textbox::Draw(PixelGameEngine*pge,Resources&resources){ +void Textbox::Draw(PixelGameEngine*pge,Resources&resources,std::map>&IMAGES){ if(visible){ geom2d::rectboxRect={pos-vf2d{3,3},maxSize+vf2d{6,6}}; + if(resourceCost.size()>0){ + boxRect.size.x+=24; + boxRect.size.y=std::max(36.f,boxRect.size.y); + } if(boxRect.bottom().start.y>=pge->ScreenHeight()){ boxRect.pos-={0,boxRect.bottom().start.y-pge->ScreenHeight()}; } @@ -81,10 +86,42 @@ void Textbox::Draw(PixelGameEngine*pge,Resources&resources){ if(boxRect.left().start.x<0){ boxRect.pos+={-boxRect.left().start.x,0}; } - pge->FillRectDecal(boxRect.pos,maxSize+vf2d{6,6},VERY_DARK_GREEN); + pge->FillRectDecal(boxRect.pos,maxSize+vf2d{6,6},backCol); pge->DrawRectDecal(boxRect.pos+vf2d{1,1},maxSize+vf2d{4,4},WHITE); pge->DrawShadowStringPropDecal(boxRect.pos+vf2d{3,3},displayHeaderText,{245, 218, 66}); pge->DrawShadowStringPropDecal(boxRect.pos+vf2d{3.f,float(3+pge->GetTextSizeProp(displayHeaderText).y)},displayText,{220,220,220}); + if(resourceCost.size()>0){ + geom2d::rectresourceBoxRect={boxRect.pos+vf2d{6+maxSize.x,6},{36,36}}; + pge->FillRectDecal(resourceBoxRect.pos,resourceBoxRect.size,backCol); + pge->DrawRectDecal(resourceBoxRect.pos+vf2d{1,1},resourceBoxRect.size-vf2d{2,2},WHITE); + vf2d contentPos=resourceBoxRect.pos+vf2d{3,3}; + + Pixel drawcol=GREY,shadowCol={66, 164, 245}; + + auto DrawResourceAmount=[&](int index,int cost,int resourceAmt){ + drawcol=resourceAmt>=cost?GREY:RED; + shadowCol=drawcol==GREY?VERY_DARK_BLUE:VERY_DARK_RED; + vf2d textScale = {0.4,0.4}; + std::string displayString = std::to_string(resourceAmt)+" / "; + if(resourceAmtFillRectDecal(contentPos+vf2d{0,float(index*6)},vf2d{resourceBoxRect.size.x-6,6},{160,0,0,192}); + } + pge->DrawShadowStringDecal(contentPos+vf2d{12.f,float(index*6)+1},displayString,drawcol,shadowCol,textScale,0.6); + pge->DrawShadowStringDecal(contentPos+vf2d{12.f+pge->GetTextSize(displayString).x*textScale.x+2,float(index*6)+1},std::to_string(cost),drawcol,shadowCol,{0.4,0.4},0.6); + }; + + DrawResourceAmount(0,util::GetHealthCost(resourceCost),resources.health); + DrawResourceAmount(1,util::GetAtkSpdCost(resourceCost),resources.atkSpd); + DrawResourceAmount(2,util::GetMoveSpdCost(resourceCost),resources.moveSpd); + DrawResourceAmount(3,util::GetRangeCost(resourceCost),resources.range); + DrawResourceAmount(4,util::GetProcedureCost(resourceCost),resources.procedure); + + pge->DrawDecal(contentPos+vf2d{0,0*6},IMAGES[RESOURCE]->Decal(),{0.5,0.5},CONSTANT::HEALTH_COLOR); + pge->DrawDecal(contentPos+vf2d{0,1*6},IMAGES[RESOURCE]->Decal(),{0.5,0.5},CONSTANT::ATKSPD_COLOR); + pge->DrawDecal(contentPos+vf2d{0,2*6},IMAGES[RESOURCE]->Decal(),{0.5,0.5},CONSTANT::MOVESPD_COLOR); + pge->DrawDecal(contentPos+vf2d{0,3*6},IMAGES[RESOURCE]->Decal(),{0.5,0.5},CONSTANT::RANGE_COLOR); + pge->DrawDecal(contentPos+vf2d{0,4*6},IMAGES[RESOURCE]->Decal(),{0.5,0.5},CONSTANT::PROCEDURE_COLOR); + } } } @@ -103,12 +140,16 @@ void Textbox::SetVisible(bool visible){ } } -void Textbox::UpdateAndDraw(vf2d pos,PixelGameEngine*pge,Resources&resources){ +void Textbox::UpdateAndDraw(vf2d pos,PixelGameEngine*pge,Resources&resources,std::map>&IMAGES){ UpdatePosition(pos); Update(pge); - Draw(pge,resources); + Draw(pge,resources,IMAGES); } vf2d Textbox::GetSize(){ return maxSize; +} + +void Textbox::SetBackgroundColor(Pixel col){ + backCol=col; } \ No newline at end of file diff --git a/olcCodeJam2023Entry/Textbox.h b/olcCodeJam2023Entry/Textbox.h index e1c3165..55ba592 100644 --- a/olcCodeJam2023Entry/Textbox.h +++ b/olcCodeJam2023Entry/Textbox.h @@ -20,17 +20,19 @@ class Textbox{ std::string lastHeaderWord=""; std::vector resourceCost; //If resource cost is greater than 0, shows them. bool visible=true; + Pixel backCol=CONSTANT::MESSAGE_BOX_DEFAULT_BACKCOL; public: Textbox(); void Initialize(std::string text,vf2d pos={},std::string headerText="",vf2d maxSize={120,1},std::vectorresourceCost={},float letterDisplayDelay=0.01); - void UpdateAndDraw(vf2d pos,PixelGameEngine*pge,Resources&resources); + void UpdateAndDraw(vf2d pos,PixelGameEngine*pge,Resources&resources,std::map>&IMAGES); std::string&GetCurrentString(); void SetVisible(bool visible); vf2d GetSize(); + void SetBackgroundColor(Pixel col); private: void Update(PixelGameEngine*pge); void UpdatePosition(vf2d newPos); - void Draw(PixelGameEngine*pge,Resources&resources); + void Draw(PixelGameEngine*pge,Resources&resources,std::map>&IMAGES); void SetDefaults(); }; \ No newline at end of file diff --git a/olcCodeJam2023Entry/Unit.h b/olcCodeJam2023Entry/Unit.h index 9d0f6c2..f2c0db6 100644 --- a/olcCodeJam2023Entry/Unit.h +++ b/olcCodeJam2023Entry/Unit.h @@ -6,7 +6,6 @@ #include "Image.h" #include "Sound.h" #include "olcPGEX_AudioSource.h" -#include "util.h" #include "DebuffIcon.h" #include "CollectionPoint.h" #include "MemoryType.h" diff --git a/olcCodeJam2023Entry/VirusAttack.cpp b/olcCodeJam2023Entry/VirusAttack.cpp index 9539602..705b0a9 100644 --- a/olcCodeJam2023Entry/VirusAttack.cpp +++ b/olcCodeJam2023Entry/VirusAttack.cpp @@ -155,8 +155,13 @@ void VirusAttack::UpdateUnitCreationListGUI(bool allocatorSelected){ #define EnableAndHoverCheck(UnitClass,Button) \ Button->Enable(CanAfford(player_resources,UnitClass::resourceCost)); \ if (Button->bHover) { \ - unitCreationBox.Initialize(UnitClass::unitDescription, GetMousePos(), UnitClass::unitName); \ + unitCreationBox.Initialize(UnitClass::unitDescription, GetMousePos(), UnitClass::unitName,{120,36},UnitClass::resourceCost); \ hovering=true; \ + if(CanAfford(player_resources,UnitClass::resourceCost)){ \ + unitCreationBox.SetBackgroundColor(CONSTANT::MESSAGE_BOX_DEFAULT_BACKCOL); \ + } else { \ + unitCreationBox.SetBackgroundColor(VERY_DARK_GREY/2); \ + } \ } bool hovering=false; @@ -535,8 +540,8 @@ bool VirusAttack::OnUserUpdate(float fElapsedTime){ DrawMinimap(); - unitCreationBox.UpdateAndDraw(GetMousePos(),this,player_resources); - testBox.UpdateAndDraw(GetMousePos()-testBox.GetSize()/2,this,player_resources); + unitCreationBox.UpdateAndDraw(GetMousePos(),this,player_resources,IMAGES); + testBox.UpdateAndDraw(GetMousePos()-testBox.GetSize()/2,this,player_resources,IMAGES); std::sort(units.begin(),units.end(),[&](auto&u1,auto&u2){ float dist1=geom2d::line(u1->GetGhostPos(),GetWorldMousePos()).length(); diff --git a/olcCodeJam2023Entry/olcPGEX_QuickGUI.h b/olcCodeJam2023Entry/olcPGEX_QuickGUI.h index e9747a8..d1b1cc2 100644 --- a/olcCodeJam2023Entry/olcPGEX_QuickGUI.h +++ b/olcCodeJam2023Entry/olcPGEX_QuickGUI.h @@ -577,13 +577,15 @@ namespace olc::QuickGUI void TextBox::Update(TileTransformedView&pge) { + + olc::vf2d vMouse = pge.GetPGE()->GetMousePos(); + bHover = vMouse.x >= vPos.x && vMouse.x < vPos.x + vSize.x && + vMouse.y >= vPos.y && vMouse.y < vPos.y + vSize.y; if (m_state == State::Disabled || !bVisible) return; bPressed = false; bReleased = false; - - olc::vf2d vMouse = pge.GetPGE()->GetMousePos(); if (vMouse.x >= vPos.x && vMouse.x < vPos.x + vSize.x && vMouse.y >= vPos.y && vMouse.y < vPos.y + vSize.y) @@ -697,6 +699,9 @@ namespace olc::QuickGUI void Button::Update(TileTransformedView&pge) { + olc::vf2d vMouse = pge.ScreenToWorld(pge.GetPGE()->GetMousePos()); + bHover = vMouse.x >= vPos.x && vMouse.x < vPos.x + vSize.x && + vMouse.y >= vPos.y && vMouse.y < vPos.y + vSize.y; bPressed = false; bReleased = false; if (m_state == State::Disabled || !bVisible) @@ -704,7 +709,6 @@ namespace olc::QuickGUI float fElapsedTime = pge.GetPGE()->GetElapsedTime(); - olc::vf2d vMouse = pge.ScreenToWorld(pge.GetPGE()->GetMousePos()); if (m_state != State::Click) { if (vMouse.x >= vPos.x && vMouse.x < vPos.x + vSize.x && @@ -741,6 +745,9 @@ namespace olc::QuickGUI void Button::Update(PixelGameEngine*pge) { + olc::vf2d vMouse = pge->GetMousePos(); + bHover = vMouse.x >= vPos.x && vMouse.x < vPos.x + vSize.x && + vMouse.y >= vPos.y && vMouse.y < vPos.y + vSize.y; bPressed = false; bReleased = false; if (m_state == State::Disabled || !bVisible) @@ -748,7 +755,6 @@ namespace olc::QuickGUI float fElapsedTime = pge->GetElapsedTime(); - olc::vf2d vMouse = pge->GetMousePos(); if (m_state != State::Click) { if (vMouse.x >= vPos.x && vMouse.x < vPos.x + vSize.x && @@ -986,12 +992,14 @@ namespace olc::QuickGUI void Slider::Update(TileTransformedView&pge) { + olc::vf2d vMouse = pge.GetPGE()->GetMousePos(); + olc::vf2d vSliderPos = vPosMin + (vPosMax - vPosMin) * ((fValue - fMin) / (fMax - fMin)); + bHover = (vMouse - vSliderPos).mag2() <= int32_t(m_manager.fGrabRad) * int32_t(m_manager.fGrabRad); + if (m_state == State::Disabled || !bVisible) return; float fElapsedTime = pge.GetPGE()->GetElapsedTime(); - - olc::vf2d vMouse = pge.GetPGE()->GetMousePos(); bHeld = false; if (m_state == State::Click) { diff --git a/olcCodeJam2023Entry/olcPixelGameEngine.h b/olcCodeJam2023Entry/olcPixelGameEngine.h index a240e6a..260a7a3 100644 --- a/olcCodeJam2023Entry/olcPixelGameEngine.h +++ b/olcCodeJam2023Entry/olcPixelGameEngine.h @@ -3428,7 +3428,7 @@ namespace olc olc::vi2d PixelGameEngine::GetTextSizeProp(const std::string& s) { - olc::vi2d size = { 0,1 }; + olc::vi2d size = { 0,0 }; olc::vi2d pos = { 0,1 }; for (auto c : s) { diff --git a/olcCodeJam2023Entry/util.cpp b/olcCodeJam2023Entry/util.cpp index 0c113a5..779cadf 100644 --- a/olcCodeJam2023Entry/util.cpp +++ b/olcCodeJam2023Entry/util.cpp @@ -20,4 +20,52 @@ namespace util{ pge->SetDrawTarget(nullptr); r.Decal()->Update(); }; + bool CanAfford(Resources&resources,std::vector&unitCosts){ + for(Memory&mem:unitCosts){ + switch(mem.type){ + case HEALTH:{ + if(resources.health&unitCosts){ + for(Memory&mem:unitCosts){ + if(mem.type==HEALTH)return mem.size; + } + }; + int GetAtkSpdCost(std::vector&unitCosts){ + for(Memory&mem:unitCosts){ + if(mem.type==ATKSPD)return mem.size; + } + }; + int GetMoveSpdCost(std::vector&unitCosts){ + for(Memory&mem:unitCosts){ + if(mem.type==MOVESPD)return mem.size; + } + }; + int GetRangeCost(std::vector&unitCosts){ + for(Memory&mem:unitCosts){ + if(mem.type==RANGE)return mem.size; + } + }; + int GetProcedureCost(std::vector&unitCosts){ + for(Memory&mem:unitCosts){ + if(mem.type==PROCEDURE)return mem.size; + } + }; } \ No newline at end of file diff --git a/olcCodeJam2023Entry/util.h b/olcCodeJam2023Entry/util.h index de86488..d3c039b 100644 --- a/olcCodeJam2023Entry/util.h +++ b/olcCodeJam2023Entry/util.h @@ -1,7 +1,14 @@ #pragma once #include "olcPixelGameEngine.h" +#include "Unit.h" namespace util{ float random(float range); void ApplyMatrixEffect(PixelGameEngine*pge,Renderable&r,Renderable&originalImg,std::unique_ptr&matrixImg); + bool CanAfford(Resources&resources,std::vector&unitCosts); + int GetHealthCost(std::vector&unitCosts); + int GetAtkSpdCost(std::vector&unitCosts); + int GetMoveSpdCost(std::vector&unitCosts); + int GetRangeCost(std::vector&unitCosts); + int GetProcedureCost(std::vector&unitCosts); } \ No newline at end of file