Ability to dynamically add panels, all objects move around as needed. Custom close button.
This commit is contained in:
parent
0bf8df4c74
commit
db5fca18fe
@ -11,9 +11,25 @@ using namespace olc::QuickGUI;
|
|||||||
int PANEL_WIDTH=620;
|
int PANEL_WIDTH=620;
|
||||||
int PANEL_HEIGHT=240;
|
int PANEL_HEIGHT=240;
|
||||||
|
|
||||||
|
class Recipe{
|
||||||
|
std::string ProduceIndex;
|
||||||
|
std::string DisplayName;
|
||||||
|
std::string Product;
|
||||||
|
int amt;
|
||||||
|
std::vector<std::pair<std::string,int>>requiredItems;
|
||||||
|
int expGained;
|
||||||
|
int requiredExp;
|
||||||
|
};
|
||||||
|
|
||||||
|
std::vector<Recipe>PotionProdRecipes;
|
||||||
|
std::vector<Recipe>StoneProdRecipes;
|
||||||
|
std::vector<Recipe>ScrollProdRecipes;
|
||||||
|
std::vector<Recipe>CompRecipes;
|
||||||
|
std::vector<Recipe>DecompRecipes;
|
||||||
|
|
||||||
class FiestaCraftingCalculator : public olc::PixelGameEngine
|
class FiestaCraftingCalculator : public olc::PixelGameEngine
|
||||||
{
|
{
|
||||||
static Renderable ProdIcon;
|
static Renderable ProdIcon,CloseIcon,CloseBackIcon;
|
||||||
class Calculator{
|
class Calculator{
|
||||||
Manager manager;
|
Manager manager;
|
||||||
vf2d displayPos={10,10};
|
vf2d displayPos={10,10};
|
||||||
@ -22,35 +38,72 @@ class FiestaCraftingCalculator : public olc::PixelGameEngine
|
|||||||
ImageCheckBox*ScrollProd;
|
ImageCheckBox*ScrollProd;
|
||||||
ImageCheckBox*CompProd;
|
ImageCheckBox*CompProd;
|
||||||
ImageCheckBox*DecompProd;
|
ImageCheckBox*DecompProd;
|
||||||
|
CustomButton*CloseButton;
|
||||||
|
ListBox*RecipeList;
|
||||||
|
std::string DisplayProdText;
|
||||||
|
std::string SelectedProdText;
|
||||||
public:
|
public:
|
||||||
Calculator(vf2d displayPos)
|
Calculator(){
|
||||||
:displayPos(displayPos){
|
|
||||||
PotionProd=new ImageCheckBox(manager,FiestaCraftingCalculator::ProdIcon,false,displayPos+vi2d{10,10},{40,40},{192,128},{32,32});
|
PotionProd=new ImageCheckBox(manager,FiestaCraftingCalculator::ProdIcon,false,displayPos+vi2d{10,10},{40,40},{192,128},{32,32});
|
||||||
StoneProd=new ImageCheckBox(manager,FiestaCraftingCalculator::ProdIcon,false,displayPos+vi2d{55,10},{40,40},{0,160},{32,32});
|
StoneProd=new ImageCheckBox(manager,FiestaCraftingCalculator::ProdIcon,false,displayPos+vi2d{55,10},{40,40},{0,160},{32,32});
|
||||||
ScrollProd=new ImageCheckBox(manager,FiestaCraftingCalculator::ProdIcon,false,displayPos+vi2d{100,10},{40,40},{224,128},{32,32});
|
ScrollProd=new ImageCheckBox(manager,FiestaCraftingCalculator::ProdIcon,false,displayPos+vi2d{100,10},{40,40},{224,128},{32,32});
|
||||||
CompProd=new ImageCheckBox(manager,FiestaCraftingCalculator::ProdIcon,false,displayPos+vi2d{145,10},{40,40},{96,160},{32,32});
|
CompProd=new ImageCheckBox(manager,FiestaCraftingCalculator::ProdIcon,false,displayPos+vi2d{145,10},{40,40},{96,160},{32,32});
|
||||||
DecompProd=new ImageCheckBox(manager,FiestaCraftingCalculator::ProdIcon,false,displayPos+vi2d{190,10},{40,40},{64,160},{32,32});
|
DecompProd=new ImageCheckBox(manager,FiestaCraftingCalculator::ProdIcon,false,displayPos+vi2d{190,10},{40,40},{64,160},{32,32});
|
||||||
|
CloseButton=new CustomButton(manager,FiestaCraftingCalculator::CloseIcon,FiestaCraftingCalculator::CloseBackIcon,displayPos+vf2d{PANEL_WIDTH-30.f,0},{26,26},{0,0},{26,26});
|
||||||
}
|
}
|
||||||
void Update(FiestaCraftingCalculator*pge){
|
bool Update(FiestaCraftingCalculator*pge,int panelNumber){
|
||||||
|
displayPos=vf2d{float(10+panelNumber%2*PANEL_WIDTH),float(10+panelNumber/2*PANEL_HEIGHT)};
|
||||||
|
PotionProd->vPos=displayPos+vi2d{10,10};
|
||||||
|
StoneProd->vPos=displayPos+vi2d{55,10};
|
||||||
|
ScrollProd->vPos=displayPos+vi2d{100,10};
|
||||||
|
CompProd->vPos=displayPos+vi2d{145,10};
|
||||||
|
DecompProd->vPos=displayPos+vi2d{190,10};
|
||||||
|
CloseButton->vPos=displayPos+vf2d{PANEL_WIDTH-30.f,0};
|
||||||
manager.Update(pge);
|
manager.Update(pge);
|
||||||
|
DisplayProdText=SelectedProdText;
|
||||||
|
if(CloseButton->bPressed){
|
||||||
|
return false;
|
||||||
|
}
|
||||||
if(PotionProd->bPressed){
|
if(PotionProd->bPressed){
|
||||||
StoneProd->bChecked=ScrollProd->bChecked=CompProd->bChecked=DecompProd->bChecked=false;
|
StoneProd->bChecked=ScrollProd->bChecked=CompProd->bChecked=DecompProd->bChecked=false;
|
||||||
|
SelectedProdText="Potion Production";
|
||||||
|
}
|
||||||
|
if(PotionProd->bHovered){
|
||||||
|
DisplayProdText="Potion Production";
|
||||||
}
|
}
|
||||||
if(StoneProd->bPressed){
|
if(StoneProd->bPressed){
|
||||||
PotionProd->bChecked=ScrollProd->bChecked=CompProd->bChecked=DecompProd->bChecked=false;
|
PotionProd->bChecked=ScrollProd->bChecked=CompProd->bChecked=DecompProd->bChecked=false;
|
||||||
|
SelectedProdText="Stone Production";
|
||||||
|
}
|
||||||
|
if(StoneProd->bHovered){
|
||||||
|
DisplayProdText="Stone Production";
|
||||||
}
|
}
|
||||||
if(ScrollProd->bPressed){
|
if(ScrollProd->bPressed){
|
||||||
StoneProd->bChecked=PotionProd->bChecked=CompProd->bChecked=DecompProd->bChecked=false;
|
StoneProd->bChecked=PotionProd->bChecked=CompProd->bChecked=DecompProd->bChecked=false;
|
||||||
|
SelectedProdText="Scroll Production";
|
||||||
|
}
|
||||||
|
if(ScrollProd->bHovered){
|
||||||
|
DisplayProdText="Scroll Production";
|
||||||
}
|
}
|
||||||
if(CompProd->bPressed){
|
if(CompProd->bPressed){
|
||||||
StoneProd->bChecked=ScrollProd->bChecked=PotionProd->bChecked=DecompProd->bChecked=false;
|
StoneProd->bChecked=ScrollProd->bChecked=PotionProd->bChecked=DecompProd->bChecked=false;
|
||||||
|
SelectedProdText="Material Composition";
|
||||||
|
}
|
||||||
|
if(CompProd->bHovered){
|
||||||
|
DisplayProdText="Material Composition";
|
||||||
}
|
}
|
||||||
if(DecompProd->bPressed){
|
if(DecompProd->bPressed){
|
||||||
StoneProd->bChecked=ScrollProd->bChecked=CompProd->bChecked=PotionProd->bChecked=false;
|
StoneProd->bChecked=ScrollProd->bChecked=CompProd->bChecked=PotionProd->bChecked=false;
|
||||||
|
SelectedProdText="Material Decomposition";
|
||||||
|
}
|
||||||
|
if(DecompProd->bHovered){
|
||||||
|
DisplayProdText="Material Decomposition";
|
||||||
}
|
}
|
||||||
pge->GradientFillRectDecal(displayPos-vf2d{2,2},{float(PANEL_WIDTH),float(PANEL_HEIGHT)},{49, 32, 61,216},{0,0,0,216},{0,0,0,216},{49, 32, 61,216});
|
pge->GradientFillRectDecal(displayPos-vf2d{2,2},{float(PANEL_WIDTH),float(PANEL_HEIGHT)},{49, 32, 61,216},{0,0,0,216},{0,0,0,216},{49, 32, 61,216});
|
||||||
pge->DrawRectDecal(displayPos-vf2d{1,1},{float(PANEL_WIDTH),float(PANEL_HEIGHT)},{131, 90, 161});
|
pge->DrawRectDecal(displayPos-vf2d{1,1},{float(PANEL_WIDTH),float(PANEL_HEIGHT)},{131, 90, 161});
|
||||||
|
pge->DrawStringPropDecal(displayPos+vf2d{10,10+60},DisplayProdText,WHITE,{2,2});
|
||||||
manager.DrawDecal(pge);
|
manager.DrawDecal(pge);
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
std::vector<Calculator*>calculators;
|
std::vector<Calculator*>calculators;
|
||||||
@ -65,31 +118,41 @@ public:
|
|||||||
bool OnUserCreate() override
|
bool OnUserCreate() override
|
||||||
{
|
{
|
||||||
// Called once at the start, so create things here
|
// Called once at the start, so create things here
|
||||||
ProdIcon.Load("assets/production_icons.png");
|
ProdIcon.Load("assets/production_icons.png",nullptr,true);
|
||||||
Karen.Load("assets/AdlF_Karen.png");
|
Karen.Load("assets/AdlF_Karen.png",nullptr,true);
|
||||||
calculators.push_back(new Calculator({10,10}));
|
CloseIcon.Load("assets/close_button.png",nullptr,true);
|
||||||
|
CloseBackIcon.Load("assets/button_mask.png",nullptr,true);
|
||||||
|
calculators.push_back(new Calculator());
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool OnUserUpdate(float fElapsedTime) override
|
bool OnUserUpdate(float fElapsedTime) override
|
||||||
{
|
{
|
||||||
if(GetKey(SPACE).bPressed){
|
if(GetKey(SPACE).bPressed){
|
||||||
calculators.push_back(new Calculator(vf2d{float(10+calculators.size()%2*PANEL_WIDTH),float(10+calculators.size()/2*PANEL_HEIGHT)}));
|
calculators.push_back(new Calculator());
|
||||||
}
|
}
|
||||||
DrawDecal({float(ScreenWidth()-Karen.Sprite()->width),float(ScreenHeight()-Karen.Sprite()->height)},Karen.Decal());
|
DrawDecal({float(ScreenWidth()-Karen.Sprite()->width),float(ScreenHeight()-Karen.Sprite()->height)},Karen.Decal());
|
||||||
for(Calculator*c:calculators){
|
int panelNumber=0;
|
||||||
c->Update(this);
|
for(auto it=calculators.begin();it!=calculators.end();++it){
|
||||||
|
Calculator*c=*it;
|
||||||
|
if (!c->Update(this,panelNumber)){
|
||||||
|
it=calculators.erase(it);
|
||||||
|
if(it==calculators.end()){
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
++panelNumber;
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
Renderable FiestaCraftingCalculator::ProdIcon;
|
Renderable FiestaCraftingCalculator::ProdIcon,FiestaCraftingCalculator::CloseIcon,FiestaCraftingCalculator::CloseBackIcon;
|
||||||
|
|
||||||
int main()
|
int main()
|
||||||
{
|
{
|
||||||
FiestaCraftingCalculator calculator;
|
FiestaCraftingCalculator calculator;
|
||||||
if (calculator.Construct(PROGRAM_WIDTH, 960, 1, 1))
|
if (calculator.Construct(PROGRAM_WIDTH, 980, 1, 1))
|
||||||
calculator.Start();
|
calculator.Start();
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
BIN
FiestaCraftingCalculator/assets/button_mask.png
Normal file
BIN
FiestaCraftingCalculator/assets/button_mask.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 652 B |
BIN
FiestaCraftingCalculator/assets/close_button.png
Normal file
BIN
FiestaCraftingCalculator/assets/close_button.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 1.7 KiB |
@ -100,6 +100,8 @@ namespace olc::QuickGUI
|
|||||||
bool bHeld = false;
|
bool bHeld = false;
|
||||||
// True on single frame control ceases being manipulated
|
// True on single frame control ceases being manipulated
|
||||||
bool bReleased = false;
|
bool bReleased = false;
|
||||||
|
// true on all frames control is being hovered over
|
||||||
|
bool bHovered = false;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
// Updates the controls behvaiour
|
// Updates the controls behvaiour
|
||||||
@ -262,6 +264,27 @@ namespace olc::QuickGUI
|
|||||||
void DrawDecal(olc::PixelGameEngine* pge) override;
|
void DrawDecal(olc::PixelGameEngine* pge) override;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
class CustomButton : public Button
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
CustomButton(olc::QuickGUI::Manager& manager, // Associate with a Manager
|
||||||
|
const olc::Renderable &icon, // Text to display
|
||||||
|
const olc::Renderable &back_icon, // The image that appears behind the button, to be blended.
|
||||||
|
const olc::vf2d& pos, // Location of button top-left
|
||||||
|
const olc::vf2d& size,
|
||||||
|
const olc::vi2d& sprOffset,
|
||||||
|
const olc::vi2d& sprSize); // Size of button
|
||||||
|
|
||||||
|
public:
|
||||||
|
const olc::Renderable& pIcon;
|
||||||
|
const olc::Renderable& pBackIcon;
|
||||||
|
olc::vi2d sprOffset;
|
||||||
|
olc::vi2d sprSize;
|
||||||
|
|
||||||
|
public:
|
||||||
|
void DrawDecal(olc::PixelGameEngine* pge) override;
|
||||||
|
};
|
||||||
|
|
||||||
class ImageButton : public Button
|
class ImageButton : public Button
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
@ -687,6 +710,7 @@ namespace olc::QuickGUI
|
|||||||
{
|
{
|
||||||
m_fTransition += fElapsedTime * m_manager.fHoverSpeedOn;
|
m_fTransition += fElapsedTime * m_manager.fHoverSpeedOn;
|
||||||
m_state = State::Hover;
|
m_state = State::Hover;
|
||||||
|
bHovered = true;
|
||||||
|
|
||||||
bPressed = pge->GetMouse(olc::Mouse::LEFT).bPressed;
|
bPressed = pge->GetMouse(olc::Mouse::LEFT).bPressed;
|
||||||
if (bPressed)
|
if (bPressed)
|
||||||
@ -700,6 +724,7 @@ namespace olc::QuickGUI
|
|||||||
{
|
{
|
||||||
m_fTransition -= fElapsedTime * m_manager.fHoverSpeedOff;
|
m_fTransition -= fElapsedTime * m_manager.fHoverSpeedOff;
|
||||||
m_state = State::Normal;
|
m_state = State::Normal;
|
||||||
|
bHovered = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@ -763,6 +788,33 @@ namespace olc::QuickGUI
|
|||||||
}
|
}
|
||||||
#pragma endregion
|
#pragma endregion
|
||||||
|
|
||||||
|
#pragma region CustomButton
|
||||||
|
CustomButton::CustomButton(olc::QuickGUI::Manager& manager, const olc::Renderable& icon,const olc::Renderable& back_icon, const olc::vf2d& pos, const olc::vf2d& size,const olc::vi2d& sprOffset,const olc::vi2d& sprSize)
|
||||||
|
: Button(manager, "", pos, size), pIcon(icon), pBackIcon(back_icon), sprOffset(sprOffset), sprSize(sprSize)
|
||||||
|
{}
|
||||||
|
|
||||||
|
void CustomButton::DrawDecal(olc::PixelGameEngine* pge)
|
||||||
|
{
|
||||||
|
if (!bVisible)
|
||||||
|
return;
|
||||||
|
|
||||||
|
switch (m_state)
|
||||||
|
{
|
||||||
|
case State::Disabled:
|
||||||
|
pge->DrawPartialDecal(vPos,pBackIcon.Decal(),sprOffset,sprSize,{1.0,1.0},m_manager.colDisable);
|
||||||
|
break;
|
||||||
|
case State::Normal:
|
||||||
|
case State::Hover:
|
||||||
|
pge->DrawPartialDecal(vPos,pBackIcon.Decal(),sprOffset,sprSize,{1.0,1.0},olc::PixelLerp(m_manager.colNormal, m_manager.colHover, m_fTransition));
|
||||||
|
break;
|
||||||
|
case State::Click:
|
||||||
|
pge->DrawPartialDecal(vPos,pBackIcon.Decal(),sprOffset,sprSize,{1.0,1.0},m_manager.colClick);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
pge->DrawPartialDecal(vPos,pIcon.Decal(),sprOffset,sprSize,{1.0,1.0},WHITE);
|
||||||
|
}
|
||||||
|
#pragma endregion
|
||||||
|
|
||||||
|
|
||||||
#pragma region ImageButton
|
#pragma region ImageButton
|
||||||
ImageButton::ImageButton(olc::QuickGUI::Manager& manager, const olc::Renderable& icon, const olc::vf2d& pos, const olc::vf2d& size,const olc::vi2d& sprOffset,const olc::vi2d& sprSize)
|
ImageButton::ImageButton(olc::QuickGUI::Manager& manager, const olc::Renderable& icon, const olc::vf2d& pos, const olc::vf2d& size,const olc::vi2d& sprOffset,const olc::vi2d& sprSize)
|
||||||
@ -939,14 +991,17 @@ namespace olc::QuickGUI
|
|||||||
{
|
{
|
||||||
m_fTransition += fElapsedTime * m_manager.fHoverSpeedOn;
|
m_fTransition += fElapsedTime * m_manager.fHoverSpeedOn;
|
||||||
m_state = State::Hover;
|
m_state = State::Hover;
|
||||||
|
bHovered = true;
|
||||||
if (pge->GetMouse(olc::Mouse::LEFT).bPressed)
|
if (pge->GetMouse(olc::Mouse::LEFT).bPressed)
|
||||||
{
|
{
|
||||||
m_state = State::Click;
|
m_state = State::Click;
|
||||||
bPressed = true;
|
bPressed = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else {
|
||||||
m_state = State::Normal;
|
m_state = State::Normal;
|
||||||
|
bHovered = false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (pge->GetMouse(olc::Mouse::LEFT).bReleased)
|
if (pge->GetMouse(olc::Mouse::LEFT).bReleased)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user