diff --git a/olcCodeJam2023Entry/Constant.cpp b/olcCodeJam2023Entry/Constant.cpp index a1284fd..8d91440 100644 --- a/olcCodeJam2023Entry/Constant.cpp +++ b/olcCodeJam2023Entry/Constant.cpp @@ -33,4 +33,7 @@ int CONSTANT::MEMORY_ALLOCATOR_COST=5; float CONSTANT::UNIT_BUILD_TIME=10; int CONSTANT::STARTING_RESOURCE_COUNT=5; -Pixel CONSTANT::MESSAGE_BOX_DEFAULT_BACKCOL=VERY_DARK_GREEN; \ No newline at end of file +Pixel CONSTANT::MESSAGE_BOX_DEFAULT_BACKCOL=VERY_DARK_GREEN; + +std::string CONSTANT::MEMORY_ALLOCATOR_BOX_DISPLAY_STRING="Creates a memory allocator, which are used for making new units.\n\nCosts 5 resources."; +std::string CONSTANT::MEMORY_ALLOCATOR_BOX_HEADER_STRING="Memory Allocator"; \ No newline at end of file diff --git a/olcCodeJam2023Entry/Constant.h b/olcCodeJam2023Entry/Constant.h index abf7b0a..397bbc9 100644 --- a/olcCodeJam2023Entry/Constant.h +++ b/olcCodeJam2023Entry/Constant.h @@ -38,4 +38,6 @@ public: static int STARTING_RESOURCE_COUNT; static Pixel MESSAGE_BOX_DEFAULT_BACKCOL; + static std::string MEMORY_ALLOCATOR_BOX_DISPLAY_STRING; + static std::string MEMORY_ALLOCATOR_BOX_HEADER_STRING; }; \ No newline at end of file diff --git a/olcCodeJam2023Entry/Textbox.cpp b/olcCodeJam2023Entry/Textbox.cpp index aa36946..ca97f43 100644 --- a/olcCodeJam2023Entry/Textbox.cpp +++ b/olcCodeJam2023Entry/Textbox.cpp @@ -31,6 +31,7 @@ void Textbox::SetDefaults(){ } void Textbox::Update(PixelGameEngine*pge){ + if(!visible)return; lastLetterTime-=pge->GetElapsedTime(); if(lastLetterTime<=0){ if(textboxMarker>&SOUNDS){ SOUNDS[Sound::HUM]->Stop(soundHandle); } -void RAMBank::UpdateGUIState(TileTransformedView&game,Resources&player_resources){ +void RAMBank::UpdateGUIState(TileTransformedView&game,Resources&player_resources,Textbox&displayBox,bool&hovered){ allocatorManager.Update(game); auto TotalResources=[&](){ return player_resources.atkSpd+player_resources.health+player_resources.moveSpd+player_resources.procedure+player_resources.range; }; - allocatorButton->Enable(IsSelected()&&TotalResources()>=5); + bool buttonEnabled=IsSelected()&&TotalResources()>=5; + + if(buttonEnabled&&allocatorButton->bHover){ + displayBox.Initialize(CONSTANT::MEMORY_ALLOCATOR_BOX_DISPLAY_STRING,{},CONSTANT::MEMORY_ALLOCATOR_BOX_HEADER_STRING); + //displayBox.SetVisible(true); + hovered=true; + } + + allocatorButton->Enable(buttonEnabled); } bool RAMBank::ClickHandled(TileTransformedView&game,Resources&player_resources,std::vector>&units,std::map>&IMAGES){ @@ -792,7 +801,7 @@ bool Unit::ClickHandled(TileTransformedView&game,Resources&player_resources,std: return false; }; -void Unit::UpdateGUIState(TileTransformedView&game,Resources&player_resources){}; +void Unit::UpdateGUIState(TileTransformedView&game,Resources&player_resources,Textbox&displayBox,bool&hovered){}; bool Unit::IsAllocator(){ return isAllocator&&attachedPoint.expired()&&buildTime<=0; diff --git a/olcCodeJam2023Entry/Unit.h b/olcCodeJam2023Entry/Unit.h index f2c0db6..ace58a4 100644 --- a/olcCodeJam2023Entry/Unit.h +++ b/olcCodeJam2023Entry/Unit.h @@ -12,6 +12,8 @@ #include "Resources.h" #include "olcPGEX_QuickGUI.h" +class Textbox; + struct Marker{ size_t index; size_t size; @@ -70,7 +72,7 @@ public: bool CanMove(); void SetTargetCollectionPoint(std::weak_ptrtargetCP,std::weak_ptrself_ptr); Pixel GetUnitColor(); - virtual void UpdateGUIState(TileTransformedView&game,Resources&player_resources); + virtual void UpdateGUIState(TileTransformedView&game,Resources&player_resources,Textbox&displayBox,bool&hovered); virtual bool ClickHandled(TileTransformedView&game,Resources&player_resources,std::vector>&units,std::map>&IMAGES); //If you return true here, then the left click does not pass back to the main Virus Attack class. bool IsAllocator(); void SetBuildUnit(float buildTime,std::unique_ptrfinalUnit); @@ -222,7 +224,7 @@ struct RAMBank:Unit{ void Draw(TileTransformedView&game,std::map>&IMAGES)override; void OnDeath(std::map>&SOUNDS)override; bool ClickHandled(TileTransformedView&game,Resources&player_resources,std::vector>&units,std::map>&IMAGES)override; - void UpdateGUIState(TileTransformedView&game,Resources&player_resources)override; + void UpdateGUIState(TileTransformedView&game,Resources&player_resources,Textbox&displayBox,bool&hovered)override; void DrawHud(TileTransformedView&game,std::map>&IMAGES)override; static std::vector resourceCost; static std::string unitName; diff --git a/olcCodeJam2023Entry/VirusAttack.cpp b/olcCodeJam2023Entry/VirusAttack.cpp index 705b0a9..c37b954 100644 --- a/olcCodeJam2023Entry/VirusAttack.cpp +++ b/olcCodeJam2023Entry/VirusAttack.cpp @@ -63,6 +63,8 @@ bool VirusAttack::OnUserCreate(){ unitCreationBox.SetVisible(false); testBox.Initialize("Hello world, this is a test of the textbox system.\nMaybe even with some newline characters snuck in there.",{}); testBox.SetVisible(false); + memoryAllocatorBox.Initialize(CONSTANT::MEMORY_ALLOCATOR_BOX_DISPLAY_STRING,{},CONSTANT::MEMORY_ALLOCATOR_BOX_HEADER_STRING); + memoryAllocatorBox.SetVisible(false); IMAGES[MINIMAP_OUTLINE]=std::make_unique(); IMAGES[MINIMAP_OUTLINE]->Create(64,64); @@ -183,12 +185,14 @@ void VirusAttack::UpdateUnitCreationListGUI(bool allocatorSelected){ void VirusAttack::HandleDraggingSelection(){ auto NotClickingOnMinimap=[&](){return !(GetMouseX()>=ScreenWidth()-64&&GetMouseY()>=ScreenHeight()-64);}; bool allocatorSelected=false; + bool memoryAllocatorBoxHovered=false; for(auto&u:units){ - u->UpdateGUIState(game,player_resources); + u->UpdateGUIState(game,player_resources,memoryAllocatorBox,memoryAllocatorBoxHovered); if(u->IsSelected()&&u->IsAllocator()){ allocatorSelected=true; } } + if(!memoryAllocatorBoxHovered)memoryAllocatorBox.SetVisible(false); UpdateUnitCreationListGUI(allocatorSelected); if(GetMouse(0).bPressed){ if(NotClickingOnMinimap()){ @@ -540,8 +544,9 @@ bool VirusAttack::OnUserUpdate(float fElapsedTime){ DrawMinimap(); - unitCreationBox.UpdateAndDraw(GetMousePos(),this,player_resources,IMAGES); + 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); 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 f6eb507..ea155ab 100644 --- a/olcCodeJam2023Entry/VirusAttack.h +++ b/olcCodeJam2023Entry/VirusAttack.h @@ -38,7 +38,7 @@ private: TileTransformedView game; - Textbox unitCreationBox,testBox; + Textbox unitCreationBox,testBox,memoryAllocatorBox; QuickGUI::Manager unitCreationList; QuickGUI::ImageButton*leftShifterButton; diff --git a/olcCodeJam2023Entry/olcPGEX_QuickGUI.h b/olcCodeJam2023Entry/olcPGEX_QuickGUI.h index d1b1cc2..95b8327 100644 --- a/olcCodeJam2023Entry/olcPGEX_QuickGUI.h +++ b/olcCodeJam2023Entry/olcPGEX_QuickGUI.h @@ -579,7 +579,7 @@ namespace olc::QuickGUI { olc::vf2d vMouse = pge.GetPGE()->GetMousePos(); - bHover = vMouse.x >= vPos.x && vMouse.x < vPos.x + vSize.x && + bHover = bVisible&&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; @@ -700,7 +700,7 @@ 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 && + bHover = bVisible&&vMouse.x >= vPos.x && vMouse.x < vPos.x + vSize.x && vMouse.y >= vPos.y && vMouse.y < vPos.y + vSize.y; bPressed = false; bReleased = false; @@ -746,7 +746,7 @@ namespace olc::QuickGUI void Button::Update(PixelGameEngine*pge) { olc::vf2d vMouse = pge->GetMousePos(); - bHover = vMouse.x >= vPos.x && vMouse.x < vPos.x + vSize.x && + bHover = bVisible&&vMouse.x >= vPos.x && vMouse.x < vPos.x + vSize.x && vMouse.y >= vPos.y && vMouse.y < vPos.y + vSize.y; bPressed = false; bReleased = false; @@ -994,7 +994,7 @@ namespace olc::QuickGUI { 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); + bHover = bVisible&&(vMouse - vSliderPos).mag2() <= int32_t(m_manager.fGrabRad) * int32_t(m_manager.fGrabRad); if (m_state == State::Disabled || !bVisible) return;