Add in memory allocator popup.

CorrectiveAction
sigonasr2 1 year ago
parent 87c65f5e20
commit 18e6c68b75
  1. 5
      olcCodeJam2023Entry/Constant.cpp
  2. 2
      olcCodeJam2023Entry/Constant.h
  3. 1
      olcCodeJam2023Entry/Textbox.cpp
  4. 2
      olcCodeJam2023Entry/Textbox.h
  5. 15
      olcCodeJam2023Entry/Unit.cpp
  6. 6
      olcCodeJam2023Entry/Unit.h
  7. 9
      olcCodeJam2023Entry/VirusAttack.cpp
  8. 2
      olcCodeJam2023Entry/VirusAttack.h
  9. 8
      olcCodeJam2023Entry/olcPGEX_QuickGUI.h

@ -33,4 +33,7 @@ int CONSTANT::MEMORY_ALLOCATOR_COST=5;
float CONSTANT::UNIT_BUILD_TIME=10; float CONSTANT::UNIT_BUILD_TIME=10;
int CONSTANT::STARTING_RESOURCE_COUNT=5; int CONSTANT::STARTING_RESOURCE_COUNT=5;
Pixel CONSTANT::MESSAGE_BOX_DEFAULT_BACKCOL=VERY_DARK_GREEN; 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";

@ -38,4 +38,6 @@ public:
static int STARTING_RESOURCE_COUNT; static int STARTING_RESOURCE_COUNT;
static Pixel MESSAGE_BOX_DEFAULT_BACKCOL; static Pixel MESSAGE_BOX_DEFAULT_BACKCOL;
static std::string MEMORY_ALLOCATOR_BOX_DISPLAY_STRING;
static std::string MEMORY_ALLOCATOR_BOX_HEADER_STRING;
}; };

@ -31,6 +31,7 @@ void Textbox::SetDefaults(){
} }
void Textbox::Update(PixelGameEngine*pge){ void Textbox::Update(PixelGameEngine*pge){
if(!visible)return;
lastLetterTime-=pge->GetElapsedTime(); lastLetterTime-=pge->GetElapsedTime();
if(lastLetterTime<=0){ if(lastLetterTime<=0){
if(textboxMarker<int(text.length()-1)){ if(textboxMarker<int(text.length()-1)){

@ -1,8 +1,8 @@
#pragma once #pragma once
#include "olcPixelGameEngine.h" #include "olcPixelGameEngine.h"
#include "Unit.h"
#include "olcPGEX_TransformedView.h" #include "olcPGEX_TransformedView.h"
#include "Resources.h" #include "Resources.h"
#include "Unit.h"
class Textbox{ class Textbox{
std::string headerText=""; //If a textbox has a header, it displays at the top in a special color. std::string headerText=""; //If a textbox has a header, it displays at the top in a special color.

@ -4,6 +4,7 @@
#include "util.h" #include "util.h"
#include "DebuffIcon.h" #include "DebuffIcon.h"
#include "olcPGEX_QuickGUI.h" #include "olcPGEX_QuickGUI.h"
#include "Textbox.h"
std::string BasicUnit::unitName=""; std::string BasicUnit::unitName="";
std::string BasicUnit::unitDescription=""; std::string BasicUnit::unitDescription="";
@ -218,14 +219,22 @@ void RAMBank::OnDeath(std::map<Sound,std::unique_ptr<Audio>>&SOUNDS){
SOUNDS[Sound::HUM]->Stop(soundHandle); 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); allocatorManager.Update(game);
auto TotalResources=[&](){ auto TotalResources=[&](){
return player_resources.atkSpd+player_resources.health+player_resources.moveSpd+player_resources.procedure+player_resources.range; 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<std::shared_ptr<Unit>>&units,std::map<Image,std::unique_ptr<Renderable>>&IMAGES){ bool RAMBank::ClickHandled(TileTransformedView&game,Resources&player_resources,std::vector<std::shared_ptr<Unit>>&units,std::map<Image,std::unique_ptr<Renderable>>&IMAGES){
@ -792,7 +801,7 @@ bool Unit::ClickHandled(TileTransformedView&game,Resources&player_resources,std:
return false; 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(){ bool Unit::IsAllocator(){
return isAllocator&&attachedPoint.expired()&&buildTime<=0; return isAllocator&&attachedPoint.expired()&&buildTime<=0;

@ -12,6 +12,8 @@
#include "Resources.h" #include "Resources.h"
#include "olcPGEX_QuickGUI.h" #include "olcPGEX_QuickGUI.h"
class Textbox;
struct Marker{ struct Marker{
size_t index; size_t index;
size_t size; size_t size;
@ -70,7 +72,7 @@ public:
bool CanMove(); bool CanMove();
void SetTargetCollectionPoint(std::weak_ptr<CollectionPoint>targetCP,std::weak_ptr<Unit>self_ptr); void SetTargetCollectionPoint(std::weak_ptr<CollectionPoint>targetCP,std::weak_ptr<Unit>self_ptr);
Pixel GetUnitColor(); 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<std::shared_ptr<Unit>>&units,std::map<Image,std::unique_ptr<Renderable>>&IMAGES); //If you return true here, then the left click does not pass back to the main Virus Attack class. virtual bool ClickHandled(TileTransformedView&game,Resources&player_resources,std::vector<std::shared_ptr<Unit>>&units,std::map<Image,std::unique_ptr<Renderable>>&IMAGES); //If you return true here, then the left click does not pass back to the main Virus Attack class.
bool IsAllocator(); bool IsAllocator();
void SetBuildUnit(float buildTime,std::unique_ptr<Unit>finalUnit); void SetBuildUnit(float buildTime,std::unique_ptr<Unit>finalUnit);
@ -222,7 +224,7 @@ struct RAMBank:Unit{
void Draw(TileTransformedView&game,std::map<Image,std::unique_ptr<Renderable>>&IMAGES)override; void Draw(TileTransformedView&game,std::map<Image,std::unique_ptr<Renderable>>&IMAGES)override;
void OnDeath(std::map<Sound,std::unique_ptr<Audio>>&SOUNDS)override; void OnDeath(std::map<Sound,std::unique_ptr<Audio>>&SOUNDS)override;
bool ClickHandled(TileTransformedView&game,Resources&player_resources,std::vector<std::shared_ptr<Unit>>&units,std::map<Image,std::unique_ptr<Renderable>>&IMAGES)override; bool ClickHandled(TileTransformedView&game,Resources&player_resources,std::vector<std::shared_ptr<Unit>>&units,std::map<Image,std::unique_ptr<Renderable>>&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<Image,std::unique_ptr<Renderable>>&IMAGES)override; void DrawHud(TileTransformedView&game,std::map<Image,std::unique_ptr<Renderable>>&IMAGES)override;
static std::vector<Memory> resourceCost; static std::vector<Memory> resourceCost;
static std::string unitName; static std::string unitName;

@ -63,6 +63,8 @@ bool VirusAttack::OnUserCreate(){
unitCreationBox.SetVisible(false); 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.Initialize("Hello world, this is a test of the textbox system.\nMaybe even with some newline characters snuck in there.",{});
testBox.SetVisible(false); 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<Renderable>(); IMAGES[MINIMAP_OUTLINE]=std::make_unique<Renderable>();
IMAGES[MINIMAP_OUTLINE]->Create(64,64); IMAGES[MINIMAP_OUTLINE]->Create(64,64);
@ -183,12 +185,14 @@ void VirusAttack::UpdateUnitCreationListGUI(bool allocatorSelected){
void VirusAttack::HandleDraggingSelection(){ void VirusAttack::HandleDraggingSelection(){
auto NotClickingOnMinimap=[&](){return !(GetMouseX()>=ScreenWidth()-64&&GetMouseY()>=ScreenHeight()-64);}; auto NotClickingOnMinimap=[&](){return !(GetMouseX()>=ScreenWidth()-64&&GetMouseY()>=ScreenHeight()-64);};
bool allocatorSelected=false; bool allocatorSelected=false;
bool memoryAllocatorBoxHovered=false;
for(auto&u:units){ for(auto&u:units){
u->UpdateGUIState(game,player_resources); u->UpdateGUIState(game,player_resources,memoryAllocatorBox,memoryAllocatorBoxHovered);
if(u->IsSelected()&&u->IsAllocator()){ if(u->IsSelected()&&u->IsAllocator()){
allocatorSelected=true; allocatorSelected=true;
} }
} }
if(!memoryAllocatorBoxHovered)memoryAllocatorBox.SetVisible(false);
UpdateUnitCreationListGUI(allocatorSelected); UpdateUnitCreationListGUI(allocatorSelected);
if(GetMouse(0).bPressed){ if(GetMouse(0).bPressed){
if(NotClickingOnMinimap()){ if(NotClickingOnMinimap()){
@ -540,8 +544,9 @@ bool VirusAttack::OnUserUpdate(float fElapsedTime){
DrawMinimap(); 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); 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){ std::sort(units.begin(),units.end(),[&](auto&u1,auto&u2){
float dist1=geom2d::line<float>(u1->GetGhostPos(),GetWorldMousePos()).length(); float dist1=geom2d::line<float>(u1->GetGhostPos(),GetWorldMousePos()).length();

@ -38,7 +38,7 @@ private:
TileTransformedView game; TileTransformedView game;
Textbox unitCreationBox,testBox; Textbox unitCreationBox,testBox,memoryAllocatorBox;
QuickGUI::Manager unitCreationList; QuickGUI::Manager unitCreationList;
QuickGUI::ImageButton*leftShifterButton; QuickGUI::ImageButton*leftShifterButton;

@ -579,7 +579,7 @@ namespace olc::QuickGUI
{ {
olc::vf2d vMouse = pge.GetPGE()->GetMousePos(); 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; vMouse.y >= vPos.y && vMouse.y < vPos.y + vSize.y;
if (m_state == State::Disabled || !bVisible) if (m_state == State::Disabled || !bVisible)
return; return;
@ -700,7 +700,7 @@ namespace olc::QuickGUI
void Button::Update(TileTransformedView&pge) void Button::Update(TileTransformedView&pge)
{ {
olc::vf2d vMouse = pge.ScreenToWorld(pge.GetPGE()->GetMousePos()); 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; vMouse.y >= vPos.y && vMouse.y < vPos.y + vSize.y;
bPressed = false; bPressed = false;
bReleased = false; bReleased = false;
@ -746,7 +746,7 @@ namespace olc::QuickGUI
void Button::Update(PixelGameEngine*pge) void Button::Update(PixelGameEngine*pge)
{ {
olc::vf2d vMouse = pge->GetMousePos(); 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; vMouse.y >= vPos.y && vMouse.y < vPos.y + vSize.y;
bPressed = false; bPressed = false;
bReleased = false; bReleased = false;
@ -994,7 +994,7 @@ namespace olc::QuickGUI
{ {
olc::vf2d vMouse = pge.GetPGE()->GetMousePos(); olc::vf2d vMouse = pge.GetPGE()->GetMousePos();
olc::vf2d vSliderPos = vPosMin + (vPosMax - vPosMin) * ((fValue - fMin) / (fMax - fMin)); 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) if (m_state == State::Disabled || !bVisible)
return; return;

Loading…
Cancel
Save