Resource displays implemented.

CorrectiveAction
sigonasr2 1 year ago
parent 3a995a7a05
commit 87c65f5e20
  1. 2
      olcCodeJam2023Entry/Constant.cpp
  2. 2
      olcCodeJam2023Entry/Constant.h
  3. 49
      olcCodeJam2023Entry/Textbox.cpp
  4. 6
      olcCodeJam2023Entry/Textbox.h
  5. 1
      olcCodeJam2023Entry/Unit.h
  6. 11
      olcCodeJam2023Entry/VirusAttack.cpp
  7. 20
      olcCodeJam2023Entry/olcPGEX_QuickGUI.h
  8. 2
      olcCodeJam2023Entry/olcPixelGameEngine.h
  9. 48
      olcCodeJam2023Entry/util.cpp
  10. 7
      olcCodeJam2023Entry/util.h

@ -32,3 +32,5 @@ 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;

@ -36,4 +36,6 @@ public:
static float UNIT_BUILD_TIME;
static int STARTING_RESOURCE_COUNT;
static Pixel MESSAGE_BOX_DEFAULT_BACKCOL;
};

@ -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<Image,std::unique_ptr<Renderable>>&IMAGES){
if(visible){
geom2d::rect<float>boxRect={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::rect<float>resourceBoxRect={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(resourceAmt<cost){
pge->FillRectDecal(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<Image,std::unique_ptr<Renderable>>&IMAGES){
UpdatePosition(pos);
Update(pge);
Draw(pge,resources);
Draw(pge,resources,IMAGES);
}
vf2d Textbox::GetSize(){
return maxSize;
}
void Textbox::SetBackgroundColor(Pixel col){
backCol=col;
}

@ -20,17 +20,19 @@ class Textbox{
std::string lastHeaderWord="";
std::vector<Memory> 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::vector<Memory>resourceCost={},float letterDisplayDelay=0.01);
void UpdateAndDraw(vf2d pos,PixelGameEngine*pge,Resources&resources);
void UpdateAndDraw(vf2d pos,PixelGameEngine*pge,Resources&resources,std::map<Image,std::unique_ptr<Renderable>>&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<Image,std::unique_ptr<Renderable>>&IMAGES);
void SetDefaults();
};

@ -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"

@ -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<float>(u1->GetGhostPos(),GetWorldMousePos()).length();

@ -577,14 +577,16 @@ 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)
{

@ -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)
{

@ -20,4 +20,52 @@ namespace util{
pge->SetDrawTarget(nullptr);
r.Decal()->Update();
};
bool CanAfford(Resources&resources,std::vector<Memory>&unitCosts){
for(Memory&mem:unitCosts){
switch(mem.type){
case HEALTH:{
if(resources.health<mem.size)return false;
}break;
case ATKSPD:{
if(resources.atkSpd<mem.size)return false;
}break;
case MOVESPD:{
if(resources.moveSpd<mem.size)return false;
}break;
case RANGE:{
if(resources.range<mem.size)return false;
}break;
case PROCEDURE:{
if(resources.procedure<mem.size)return false;
}break;
}
}
return true;
}
int GetHealthCost(std::vector<Memory>&unitCosts){
for(Memory&mem:unitCosts){
if(mem.type==HEALTH)return mem.size;
}
};
int GetAtkSpdCost(std::vector<Memory>&unitCosts){
for(Memory&mem:unitCosts){
if(mem.type==ATKSPD)return mem.size;
}
};
int GetMoveSpdCost(std::vector<Memory>&unitCosts){
for(Memory&mem:unitCosts){
if(mem.type==MOVESPD)return mem.size;
}
};
int GetRangeCost(std::vector<Memory>&unitCosts){
for(Memory&mem:unitCosts){
if(mem.type==RANGE)return mem.size;
}
};
int GetProcedureCost(std::vector<Memory>&unitCosts){
for(Memory&mem:unitCosts){
if(mem.type==PROCEDURE)return mem.size;
}
};
}

@ -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<Renderable>&matrixImg);
bool CanAfford(Resources&resources,std::vector<Memory>&unitCosts);
int GetHealthCost(std::vector<Memory>&unitCosts);
int GetAtkSpdCost(std::vector<Memory>&unitCosts);
int GetMoveSpdCost(std::vector<Memory>&unitCosts);
int GetRangeCost(std::vector<Memory>&unitCosts);
int GetProcedureCost(std::vector<Memory>&unitCosts);
}
Loading…
Cancel
Save