diff --git a/FiestaCraftingCalculator/FiestaCraftingCalculator.cpp b/FiestaCraftingCalculator/FiestaCraftingCalculator.cpp index 3067efa..70cb9da 100644 --- a/FiestaCraftingCalculator/FiestaCraftingCalculator.cpp +++ b/FiestaCraftingCalculator/FiestaCraftingCalculator.cpp @@ -11,9 +11,25 @@ using namespace olc::QuickGUI; int PANEL_WIDTH=620; int PANEL_HEIGHT=240; +class Recipe{ + std::string ProduceIndex; + std::string DisplayName; + std::string Product; + int amt; + std::vector>requiredItems; + int expGained; + int requiredExp; +}; + +std::vectorPotionProdRecipes; +std::vectorStoneProdRecipes; +std::vectorScrollProdRecipes; +std::vectorCompRecipes; +std::vectorDecompRecipes; + class FiestaCraftingCalculator : public olc::PixelGameEngine { - static Renderable ProdIcon; + static Renderable ProdIcon,CloseIcon,CloseBackIcon; class Calculator{ Manager manager; vf2d displayPos={10,10}; @@ -22,35 +38,72 @@ class FiestaCraftingCalculator : public olc::PixelGameEngine ImageCheckBox*ScrollProd; ImageCheckBox*CompProd; ImageCheckBox*DecompProd; + CustomButton*CloseButton; + ListBox*RecipeList; + std::string DisplayProdText; + std::string SelectedProdText; public: - Calculator(vf2d displayPos) - :displayPos(displayPos){ + Calculator(){ 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}); 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}); 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); + DisplayProdText=SelectedProdText; + if(CloseButton->bPressed){ + return false; + } if(PotionProd->bPressed){ StoneProd->bChecked=ScrollProd->bChecked=CompProd->bChecked=DecompProd->bChecked=false; + SelectedProdText="Potion Production"; + } + if(PotionProd->bHovered){ + DisplayProdText="Potion Production"; } if(StoneProd->bPressed){ PotionProd->bChecked=ScrollProd->bChecked=CompProd->bChecked=DecompProd->bChecked=false; + SelectedProdText="Stone Production"; + } + if(StoneProd->bHovered){ + DisplayProdText="Stone Production"; } if(ScrollProd->bPressed){ StoneProd->bChecked=PotionProd->bChecked=CompProd->bChecked=DecompProd->bChecked=false; + SelectedProdText="Scroll Production"; + } + if(ScrollProd->bHovered){ + DisplayProdText="Scroll Production"; } if(CompProd->bPressed){ StoneProd->bChecked=ScrollProd->bChecked=PotionProd->bChecked=DecompProd->bChecked=false; + SelectedProdText="Material Composition"; + } + if(CompProd->bHovered){ + DisplayProdText="Material Composition"; } if(DecompProd->bPressed){ 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->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); + return true; } }; std::vectorcalculators; @@ -65,31 +118,41 @@ public: bool OnUserCreate() override { // Called once at the start, so create things here - ProdIcon.Load("assets/production_icons.png"); - Karen.Load("assets/AdlF_Karen.png"); - calculators.push_back(new Calculator({10,10})); + ProdIcon.Load("assets/production_icons.png",nullptr,true); + Karen.Load("assets/AdlF_Karen.png",nullptr,true); + CloseIcon.Load("assets/close_button.png",nullptr,true); + CloseBackIcon.Load("assets/button_mask.png",nullptr,true); + calculators.push_back(new Calculator()); return true; } bool OnUserUpdate(float fElapsedTime) override { 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()); - for(Calculator*c:calculators){ - c->Update(this); + int panelNumber=0; + 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; } }; -Renderable FiestaCraftingCalculator::ProdIcon; +Renderable FiestaCraftingCalculator::ProdIcon,FiestaCraftingCalculator::CloseIcon,FiestaCraftingCalculator::CloseBackIcon; int main() { FiestaCraftingCalculator calculator; - if (calculator.Construct(PROGRAM_WIDTH, 960, 1, 1)) + if (calculator.Construct(PROGRAM_WIDTH, 980, 1, 1)) calculator.Start(); return 0; diff --git a/FiestaCraftingCalculator/assets/button_mask.png b/FiestaCraftingCalculator/assets/button_mask.png new file mode 100644 index 0000000..1d2feb5 Binary files /dev/null and b/FiestaCraftingCalculator/assets/button_mask.png differ diff --git a/FiestaCraftingCalculator/assets/close_button.png b/FiestaCraftingCalculator/assets/close_button.png new file mode 100644 index 0000000..aa470c3 Binary files /dev/null and b/FiestaCraftingCalculator/assets/close_button.png differ diff --git a/FiestaCraftingCalculator/olcPGEX_QuickGUI.h b/FiestaCraftingCalculator/olcPGEX_QuickGUI.h index 4453b8f..cbfcd60 100644 --- a/FiestaCraftingCalculator/olcPGEX_QuickGUI.h +++ b/FiestaCraftingCalculator/olcPGEX_QuickGUI.h @@ -100,6 +100,8 @@ namespace olc::QuickGUI bool bHeld = false; // True on single frame control ceases being manipulated bool bReleased = false; + // true on all frames control is being hovered over + bool bHovered = false; public: // Updates the controls behvaiour @@ -262,6 +264,27 @@ namespace olc::QuickGUI 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 { public: @@ -687,6 +710,7 @@ namespace olc::QuickGUI { m_fTransition += fElapsedTime * m_manager.fHoverSpeedOn; m_state = State::Hover; + bHovered = true; bPressed = pge->GetMouse(olc::Mouse::LEFT).bPressed; if (bPressed) @@ -700,6 +724,7 @@ namespace olc::QuickGUI { m_fTransition -= fElapsedTime * m_manager.fHoverSpeedOff; m_state = State::Normal; + bHovered = false; } } else @@ -763,6 +788,33 @@ namespace olc::QuickGUI } #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 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_state = State::Hover; + bHovered = true; if (pge->GetMouse(olc::Mouse::LEFT).bPressed) { m_state = State::Click; bPressed = true; } } - else + else { m_state = State::Normal; + bHovered = false; + } } if (pge->GetMouse(olc::Mouse::LEFT).bReleased)