From db5fca18fe1d9b3496d226a0473a121865d40640 Mon Sep 17 00:00:00 2001 From: sigonasr2 Date: Thu, 29 Jun 2023 05:44:30 -0700 Subject: [PATCH] Ability to dynamically add panels, all objects move around as needed. Custom close button. --- .../FiestaCraftingCalculator.cpp | 87 +++++++++++++++--- .../assets/button_mask.png | Bin 0 -> 652 bytes .../assets/close_button.png | Bin 0 -> 1756 bytes FiestaCraftingCalculator/olcPGEX_QuickGUI.h | 57 +++++++++++- 4 files changed, 131 insertions(+), 13 deletions(-) create mode 100644 FiestaCraftingCalculator/assets/button_mask.png create mode 100644 FiestaCraftingCalculator/assets/close_button.png 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 0000000000000000000000000000000000000000..1d2feb5a2909837a5c1a5f26699ab710d3cd7c06 GIT binary patch literal 652 zcmV;70(1R|P)EX>4Tx04R}tkv&MmKpe$iTeU^14t5Z!kfAzR5EXHhDi*;)X)CnqU~=gfG-*gu zTpR`0f`cE6RRFSdL}hb93mEq9V~S)E9naHG;u^$RLb{e z9hNz7aaJld*19KuVKA?*q`6Krj5wB%KoSBZ)KEqRCZe>eq!>uie$2%`Z2ObslE_sC zBgX=&P$1fV@IUz7tx=eobdrKGp!>zLK1KomF3_x7*7vbxHBSKFGjOH0{nZ9A`$>Ae ztwoN2foPI3>F)8L4GFy000?uMObu0Z*6U5Zgc=ca%Ew3 zWn>_CX>@2HM@dakSAh-}0001ENklV>y`yWtuXTFOfRUJGMj@x{x0_a5J2_ my{(7OddjWk#9Fr$1@ZxiEj%J96gkEK0000EX>4Tx04R}tkv&MmKpe$iTeU^14t5Z!kfAzR5EXHhDi*;)X)CnqU~=gfG-*gu zTpR`0f`cE6RRFSdL}hb93mEq9V~S)E9naHG;u^$RLb{e z9hNz7aaJld*19KuVKA?*q`6Krj5wB%KoSBZ)KEqRCZe>eq!>uie$2%`Z2ObslE_sC zBgX=&P$1fV@IUz7tx=eobdrKGp!>zLK1KomF3_x7*7vbxHBSKFGjOH0{nZ9A`$>Ae ztwoN2foPI3>E_CX>@2HM@dakSAh-}000EDNklGohSSpTnxEEbErx3~8|=EAwV%S+eu{BvtbNm2b{wWFhBG@fea z+v8{GzdC#{Cnsl5OH0dNGZL9hrp!<%RK01VxolhI3oOpbV*D0_E)Mde_g9*K@bdF7 zJ^)s)G_dv=BTpNbp?N%wggMaN+eeL~ffG&V>NOh8PLIdaKaI#@vB-nLpmVFWuWY#sQPP; zI#1VYwOZ@#&L)Ynva&ube0Ig|y>D$tF(-khGi`kF)p4v=D}o^4cDr#n9Cw{SWo4x# ziXzcy6sOb4tFM%@aeY4VTjRX@ft}Oew;$~5>wEJq;Z3WTNv*CLX`rh~I&yfwR9svv z+3j}8YTY8ucB8D;Et1`Cmx_yvr6Y&;O9Nd^Qmd;*GOb=FX|>w2$&G5Yy6MoqUD7~T zljLfwk<4bZWVhR;f`Y=cRK8!{qZnyiM72gSZFJb_<+dYBdnRo{Ih9!)Qj9BEcSZr~gW)T3b=gy!;l=**a$I?#?v;hr=P$>-DsrI}bpfW)ZPiY_U8ZkE?FmO1m#G`A();$hzq+a<3df zc6K)Hz5oCj3l|WN$5nD3P{Y80J=h#Q7V<)^3>GSmNwr707R1k zuh)wxinHo8lRly-PGFb}0JQlokeZs>B3G-`F1M$H(a|xMYBHHWH<@TOip^%5v5T4V zHk(a~Mx)H1o6J&8CZnTcxIG=H)oPbK5D1*?xisi%Jk?B6q8wXA2~MXIQ53mf3lc>U zr_+h8qJ*SGIgO{9>A5uM3IqZt6#%)pxzX;Pi!T~iYI*XBECkiV)F1zj^73+&%H*nG zFt~R%Q!OpsL_Sa@n>VkjqoZT*RN;5**in_1mPTD&9b30-ptxWqx5mf$`0!CW y0v8W??nu!^wX+ZtGetMouse(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)