diff --git a/olcCodeJam2023Entry/Constant.cpp b/olcCodeJam2023Entry/Constant.cpp index e960992..9d7fcae 100644 --- a/olcCodeJam2023Entry/Constant.cpp +++ b/olcCodeJam2023Entry/Constant.cpp @@ -26,4 +26,6 @@ Pixel CONSTANT::HEALER_ATTACK_COL={91, 222, 104, 220}; float CONSTANT::DEBUFFICON_LIFETIME=0.8; -float CONSTANT::COLLECTION_WAIT_TIME=8; \ No newline at end of file +float CONSTANT::COLLECTION_WAIT_TIME=8; + +int CONSTANT::MEMORY_ALLOCATOR_COST=5; \ No newline at end of file diff --git a/olcCodeJam2023Entry/Constant.h b/olcCodeJam2023Entry/Constant.h index 1dbd810..ed2e8b2 100644 --- a/olcCodeJam2023Entry/Constant.h +++ b/olcCodeJam2023Entry/Constant.h @@ -31,4 +31,6 @@ public: static float DEBUFFICON_LIFETIME; static float COLLECTION_WAIT_TIME; + + static int MEMORY_ALLOCATOR_COST; }; \ No newline at end of file diff --git a/olcCodeJam2023Entry/Unit.cpp b/olcCodeJam2023Entry/Unit.cpp index a0d49e5..778e3f3 100644 --- a/olcCodeJam2023Entry/Unit.cpp +++ b/olcCodeJam2023Entry/Unit.cpp @@ -3,6 +3,7 @@ #include "TileManager.h" #include "util.h" #include "DebuffIcon.h" +#include "olcPGEX_QuickGUI.h" BasicUnit::BasicUnit(PixelGameEngine*pge,vf2d pos,std::map>&IMAGES,bool friendly,bool moveable) :Unit(pge,{ @@ -139,7 +140,9 @@ MemoryAllocator::MemoryAllocator(PixelGameEngine*pge,vf2d pos,std::map>&otherUnits){ @@ -161,6 +164,21 @@ RAMBank::RAMBank(PixelGameEngine*pge,vf2d pos,std::mapClear(BLANK); pge->DrawSprite({0,0},IMAGES[RAM_BANK]->Sprite()); pge->SetDrawTarget(nullptr); + /* + olc::Pixel colNormal = olc::DARK_BLUE; + olc::Pixel colHover = olc::BLUE; + olc::Pixel colClick = olc::CYAN; + olc::Pixel colDisable = olc::DARK_GREY; + olc::Pixel colBorder = olc::WHITE; + olc::Pixel colText = olc::WHITE; + */ + allocatorManager.colNormal = olc::VERY_DARK_GREEN; + allocatorManager.colHover = olc::GREEN; + allocatorManager.colClick = olc::YELLOW; + allocatorManager.colDisable = olc::DARK_GREY; + allocatorManager.colBorder = olc::YELLOW; + allocatorManager.colText = olc::WHITE; + allocatorButton = new QuickGUI::ImageButton(allocatorManager,*IMAGES[UNIT_ALLOCATOR],{0.5f,0.5f},pos-vf2d{8,48},{20,20}); } void RAMBank::Attack(Unit&victim,std::vector>&otherUnits){ @@ -185,6 +203,12 @@ void RAMBank::Update(PixelGameEngine*pge,std::map>& pge->SetDrawTarget(nullptr); } +void RAMBank::DrawHud(TileTransformedView&game,std::map>&IMAGES){ + if(IsSelected()){ + allocatorManager.DrawDecal(game); + } +} + void RAMBank::Draw(TileTransformedView&game,std::map>&IMAGES){ game.DrawRotatedDecal(GetGhostPos(),img.Decal(),0,img.Sprite()->Size()/2,{1,1},GetUnitColor()); if(IsSelected()){ @@ -196,6 +220,50 @@ void RAMBank::OnDeath(std::map>&SOUNDS){ SOUNDS[Sound::HUM]->Stop(soundHandle); } +void RAMBank::UpdateGUIState(TileTransformedView&game,Resources&player_resources){ + allocatorManager.Update(game); + + auto TotalResources=[&](){ + return player_resources.atkSpd+player_resources.health+player_resources.moveSpd+player_resources.procedure+player_resources.range; + }; + + allocatorButton->Enable(IsSelected()&&TotalResources()>=5); +} + +bool RAMBank::ClickHandled(TileTransformedView&game,Resources&player_resources,std::vector>&units,std::map>&IMAGES){ + if(allocatorButton->bPressed){ + //First try to take one of each. + if(player_resources.atkSpd>0&&player_resources.health>0&&player_resources.moveSpd>0&&player_resources.procedure>0&&player_resources.range>0){ + player_resources.atkSpd--; + player_resources.health--; + player_resources.moveSpd--; + player_resources.procedure--; + player_resources.range--; + } else { + //Remove from the highest resource amount until 5 are removed. + for(int i=0;i<5;i++){ + int*maxAmt=&player_resources.atkSpd; + if(player_resources.health>*maxAmt){ + maxAmt=&player_resources.health; + } + if(player_resources.moveSpd>*maxAmt){ + maxAmt=&player_resources.moveSpd; + } + if(player_resources.procedure>*maxAmt){ + maxAmt=&player_resources.procedure; + } + if(player_resources.range>*maxAmt){ + maxAmt=&player_resources.range; + } + (*maxAmt)--; + } + } + units.push_back(std::make_shared(game.GetPGE(),GetPos()+vf2d{0,24},IMAGES,friendly)); + return true; + } + return false; +} + Unit::Unit(PixelGameEngine*pge,std::vectormemory,vf2d pos,float radius,Renderable&img,Pixel targetLineColor,Pixel attackingLineColor,bool friendly,bool moveable,bool friendlyInteractable,bool enemyInteractable) :pos(pos),radius(radius),ghostPos(pos),img(img),targetLineCol(targetLineColor),attackingLineCol(attackingLineColor),friendly(friendly),moveable(moveable),friendlyInteractable(friendlyInteractable),enemyInteractable(enemyInteractable){ int marker=0; @@ -276,7 +344,10 @@ void Unit::Draw(TileTransformedView&game,std::map>&IMAGES){ +void Unit::DrawHud(TileTransformedView&game,std::map>&IMAGES){} + +void Unit::_DrawHud(TileTransformedView&game,std::map>&IMAGES){ + DrawHud(game,IMAGES); int initialBarX=ghostPos.x-GetMemorySize()/2*CONSTANT::BAR_SQUARE_SIZE.x-CONSTANT::BAR_SQUARE_SIZE.x/2; int initialBarY=ghostPos.y-CONSTANT::BAR_SQUARE_SIZE.y-img.Sprite()->height/2-2; Pixel col=0; @@ -443,7 +514,7 @@ void Unit::_Update(PixelGameEngine*pge,std::map>&SO if(dist>24){ SetPos(GetPos()+(targetLoc-pos).norm()*GetMoveSpd()*24*pge->GetElapsedTime()); } else { - if(willAttachWhenReachingDestination&&!attachTarget.expired()){ + if(willAttachWhenReachingDestination&&!attachTarget.expired()&&attachTarget.lock()->attachedUnit.expired()){ attachedPoint=attachTarget; attachedPoint.lock()->attachedUnit=self_ptr; } @@ -715,4 +786,14 @@ Pixel Unit::GetUnitColor(){ } else { return friendly?Pixel{192,192,255}:Pixel{255,192,192}; } +} + +bool Unit::ClickHandled(TileTransformedView&game,Resources&player_resources,std::vector>&units,std::map>&IMAGES){ + return false; +}; + +void Unit::UpdateGUIState(TileTransformedView&game,Resources&player_resources){}; + +bool Unit::IsAllocator(){ + return isAllocator; } \ No newline at end of file diff --git a/olcCodeJam2023Entry/Unit.h b/olcCodeJam2023Entry/Unit.h index 896f105..f1e2739 100644 --- a/olcCodeJam2023Entry/Unit.h +++ b/olcCodeJam2023Entry/Unit.h @@ -11,6 +11,7 @@ #include "CollectionPoint.h" #include "MemoryType.h" #include "Resources.h" +#include "olcPGEX_QuickGUI.h" struct Marker{ size_t index; @@ -37,6 +38,7 @@ public: virtual void Attack(Unit&victim,std::vector>&otherUnits)=0; virtual void Draw(TileTransformedView&game,std::map>&IMAGES); virtual void DrawHud(TileTransformedView&game,std::map>&IMAGES); + void _DrawHud(TileTransformedView&game,std::map>&IMAGES); virtual void OnDeath(std::map>&SOUNDS); bool IsFriendly(); bool IsSelected(); @@ -69,6 +71,9 @@ public: bool CanMove(); void SetTargetCollectionPoint(std::weak_ptrtargetCP,std::weak_ptrself_ptr); Pixel GetUnitColor(); + virtual void UpdateGUIState(TileTransformedView&game,Resources&player_resources); + virtual bool ClickHandled(TileTransformedView&game,Resources&player_resources,std::vector>&units,std::map>&IMAGES); //If you return true here, then the left click does not pass back to the main Virus Attack class. + bool IsAllocator(); std::vector& operator <<=(const int n){ for(int i=0;i>&IMAGES,bool friendly=false); void Update(PixelGameEngine*pge,std::map>&SOUNDS)override; void Attack(Unit&victim,std::vector>&otherUnits)override; void Draw(TileTransformedView&game,std::map>&IMAGES)override; void OnDeath(std::map>&SOUNDS)override; + bool ClickHandled(TileTransformedView&game,Resources&player_resources,std::vector>&units,std::map>&IMAGES)override; + void UpdateGUIState(TileTransformedView&game,Resources&player_resources)override; + void DrawHud(TileTransformedView&game,std::map>&IMAGES)override; }; \ No newline at end of file diff --git a/olcCodeJam2023Entry/VirusAttack.cpp b/olcCodeJam2023Entry/VirusAttack.cpp index 905f892..2d611e4 100644 --- a/olcCodeJam2023Entry/VirusAttack.cpp +++ b/olcCodeJam2023Entry/VirusAttack.cpp @@ -3,6 +3,7 @@ #define OLC_PGEX_TRANSFORMEDVIEW #define AUDIO_LISTENER_IMPLEMENTATION #define AUDIO_SOURCE_IMPLEMENTATION +#define OLC_PGEX_QUICKGUI #include "olcUTIL_Geometry2D.h" #include "TileManager.h" #include "util.h" @@ -67,6 +68,8 @@ bool VirusAttack::OnUserCreate(){ AL.AudioSystemInit(); InitializeSounds(); + InitializeUnitCreationGUI(); + units.push_back(std::make_unique(this,vf2d{128,128},IMAGES,true)); units.push_back(std::make_unique(this,vf2d{129,129},IMAGES,true)); units.push_back(std::make_unique(this,vf2d{130,130},IMAGES,true)); @@ -91,6 +94,21 @@ bool VirusAttack::OnUserCreate(){ return true; } +void VirusAttack::InitializeUnitCreationGUI(){ + unitCreationList.colNormal = olc::DARK_GREEN; + unitCreationList.colHover = olc::GREEN; + unitCreationList.colClick = olc::YELLOW; + unitCreationList.colDisable = olc::DARK_GREY; + unitCreationList.colBorder = olc::YELLOW; + unitCreationList.colText = olc::WHITE; + leftShifterButton=new QuickGUI::ImageButton(unitCreationList,*IMAGES[LEFT_SHIFTER],{0.5,0.5},{16.f+32*0,float(ScreenHeight()-32)},{20,20}); + rightShifterButton=new QuickGUI::ImageButton(unitCreationList,*IMAGES[RIGHT_SHIFTER],{0.5,0.5},{16.f+32*1,float(ScreenHeight()-32)},{20,20}); + bitRestorerButton=new QuickGUI::ImageButton(unitCreationList,*IMAGES[BIT_RESTORER],{0.5,0.5},{16.f+32*2,float(ScreenHeight()-32)},{20,20}); + memorySwapperButton=new QuickGUI::ImageButton(unitCreationList,*IMAGES[MEMORY_SWAPPER],{0.5,0.5},{16.f+32*3,float(ScreenHeight()-32)},{20,20}); + corrupterButton=new QuickGUI::ImageButton(unitCreationList,*IMAGES[CORRUPTER],{0.5,0.5},{16.f+32*4,float(ScreenHeight()-32)},{20,20}); + platformButton=new QuickGUI::ImageButton(unitCreationList,*IMAGES[UNIT_ALLOCATOR],{0.5,0.5},{16.f+32*5,float(ScreenHeight()-32)},{20,20}); +} + void VirusAttack::InitializeSounds(){ int soundIndex=0; auto LoadSound=[&](Sound sound,std::string soundFilename){ @@ -103,10 +121,49 @@ void VirusAttack::InitializeSounds(){ LoadSound(Sound::HUM,"machine2.wav"); } +bool VirusAttack::UnitCreationClickHandled(){ + if(leftShifterButton->bPressed){ + return true; + } + if(rightShifterButton->bPressed){ + return true; + } + if(bitRestorerButton->bPressed){ + return true; + } + if(memorySwapperButton->bPressed){ + return true; + } + if(corrupterButton->bPressed){ + return true; + } + if(platformButton->bPressed){ + return true; + } + return false; +}; + void VirusAttack::HandleDraggingSelection(){ auto NotClickingOnMinimap=[&](){return !(GetMouseX()>=ScreenWidth()-64&&GetMouseY()>=ScreenHeight()-64);}; + bool allocatorSelected=false; + for(auto&u:units){ + u->UpdateGUIState(game,player_resources); + if(u->IsSelected()&&u->IsAllocator()){ + allocatorSelected=true; + } + } + unitCreationList.DisplayAllControls(allocatorSelected); + unitCreationList.Update(this); if(GetMouse(0).bPressed){ if(NotClickingOnMinimap()){ + for(auto&u:units){ + if(u->ClickHandled(game,player_resources,units,IMAGES)){ + goto skipLeftClick; //Break out early because this instance reported it handled a click for us. + } + } + if(UnitCreationClickHandled()){ + goto skipLeftClick; + } for(auto&u:units){ u->Deselect(); } @@ -115,6 +172,7 @@ void VirusAttack::HandleDraggingSelection(){ } } } + skipLeftClick: if(GetMouse(0).bReleased&&startingDragPos!=CONSTANT::UNSELECTED){ vf2d endDragPos=GetWorldMousePos(); if(endDragPos.xu,std::shared_ptr u->SetPos(u->GetPos()-dir*dist/2); } if(u2->IsMoveable()){ - u2->SetPos(u2->GetPos()+dir*dist/2); + u2->SetPos(u2->GetPos()+dir*(dist+0.001)/2); } } } @@ -429,11 +487,14 @@ bool VirusAttack::OnUserUpdate(float fElapsedTime){ std::erase_if(debuffIcons,[](DebuffIcon&icon){return icon.lifetime<=0;}); for(auto&u:units){ - u->DrawHud(game,IMAGES); + u->_DrawHud(game,IMAGES); } DrawSelectionRectangle(); RenderFogOfWar(); + + unitCreationList.DrawDecal(this); + DrawResourceBar(); DrawMinimap(); diff --git a/olcCodeJam2023Entry/VirusAttack.h b/olcCodeJam2023Entry/VirusAttack.h index 44ba55f..3883755 100644 --- a/olcCodeJam2023Entry/VirusAttack.h +++ b/olcCodeJam2023Entry/VirusAttack.h @@ -36,6 +36,14 @@ private: TileTransformedView game; + QuickGUI::Manager unitCreationList; + QuickGUI::ImageButton*leftShifterButton; + QuickGUI::ImageButton*rightShifterButton; + QuickGUI::ImageButton*bitRestorerButton; + QuickGUI::ImageButton*memorySwapperButton; + QuickGUI::ImageButton*corrupterButton; + QuickGUI::ImageButton*platformButton; + float matrixTimer=0; float updatePixelsTimer=0; const std::arraymatrixLetters={'0','1','2','3','4','5','6','7','8','9','A','B','C','D','E','F',}; @@ -57,6 +65,8 @@ private: void RenderFogOfWar(); void InitializeSounds(); void DrawResourceBar(); + bool UnitCreationClickHandled(); + void InitializeUnitCreationGUI(); public: VirusAttack(); diff --git a/olcCodeJam2023Entry/olcPGEX_QuickGUI.h b/olcCodeJam2023Entry/olcPGEX_QuickGUI.h index 6b0c4ef..a21deef 100644 --- a/olcCodeJam2023Entry/olcPGEX_QuickGUI.h +++ b/olcCodeJam2023Entry/olcPGEX_QuickGUI.h @@ -75,6 +75,7 @@ #define OLC_PGEX_QUICKGUI_H #include "olcPixelGameEngine.h" +#include "olcPGEX_TransformedView.h" namespace olc::QuickGUI @@ -103,11 +104,13 @@ namespace olc::QuickGUI public: // Updates the controls behvaiour - virtual void Update(olc::PixelGameEngine* pge) = 0; + virtual void Update(TileTransformedView&pge) = 0; // Draws the control using "sprite" based CPU operations - virtual void Draw(olc::PixelGameEngine* pge) = 0; + virtual void Draw(TileTransformedView&pge) = 0; // Draws the control using "decal" based GPU operations - virtual void DrawDecal(olc::PixelGameEngine* pge) = 0; + virtual void DrawDecal(TileTransformedView&pge) = 0; + virtual void Update(PixelGameEngine*pge); + virtual void DrawDecal(PixelGameEngine*pge); protected: // Controls are related to a manager, where the theme resides @@ -139,18 +142,22 @@ namespace olc::QuickGUI // Add a gui element derived form BaseControl to this manager void AddControl(BaseControl* control); // Updates all controls this manager operates - void Update(olc::PixelGameEngine* pge); + void Update(TileTransformedView&pge); + void Update(PixelGameEngine*pge); // Draws as "sprite" all controls this manager operates - void Draw(olc::PixelGameEngine* pge); + void Draw(TileTransformedView&pge); // Draws as "decal" all controls this manager operates - void DrawDecal(olc::PixelGameEngine* pge); + void DrawDecal(TileTransformedView&pge); + void DrawDecal(PixelGameEngine*pge); + + void DisplayAllControls(bool displayState); public: // This managers "Theme" can be set here // Various element colours olc::Pixel colNormal = olc::DARK_BLUE; olc::Pixel colHover = olc::BLUE; olc::Pixel colClick = olc::CYAN; - olc::Pixel colDisable = olc::DARK_GREY; + olc::Pixel colDisable = olc::VERY_DARK_GREY; olc::Pixel colBorder = olc::WHITE; olc::Pixel colText = olc::WHITE; // Speed to transiton from Normal -> Hover @@ -195,9 +202,9 @@ namespace olc::QuickGUI {Left, Centre, Right} nAlign = Alignment::Centre; public: // BaseControl overrides - void Update(olc::PixelGameEngine* pge) override; - void Draw(olc::PixelGameEngine* pge) override; - void DrawDecal(olc::PixelGameEngine* pge) override; + void Update(TileTransformedView&pge) override; + void Draw(TileTransformedView&pge) override; + void DrawDecal(TileTransformedView&pge) override; }; class TextBox : public Label @@ -209,9 +216,9 @@ namespace olc::QuickGUI const olc::vf2d& size); // Size of text box public: // BaseControl overrides - void Update(olc::PixelGameEngine* pge) override; - void Draw(olc::PixelGameEngine* pge) override; - void DrawDecal(olc::PixelGameEngine* pge) override; + void Update(TileTransformedView&pge) override; + void Draw(TileTransformedView&pge) override; + void DrawDecal(TileTransformedView&pge) override; protected: bool m_bTextEdit = false; @@ -236,9 +243,11 @@ namespace olc::QuickGUI std::string sText; public: // BaseControl overrides - void Update(olc::PixelGameEngine* pge) override; - void Draw(olc::PixelGameEngine* pge) override; - void DrawDecal(olc::PixelGameEngine* pge) override; + void Update(TileTransformedView&pge) override; + void Update(PixelGameEngine*pge) override; + void Draw(TileTransformedView&pge) override; + void DrawDecal(TileTransformedView&pge) override; + void DrawDecal(PixelGameEngine*pge) override; }; // Creates a Button Control - a clickable, labelled rectangle @@ -255,9 +264,9 @@ namespace olc::QuickGUI bool bChecked = false; public: // BaseControl overrides - void Update(olc::PixelGameEngine* pge) override; - void Draw(olc::PixelGameEngine* pge) override; - void DrawDecal(olc::PixelGameEngine* pge) override; + void Update(TileTransformedView&pge) override; + void Draw(TileTransformedView&pge) override; + void DrawDecal(TileTransformedView&pge) override; }; class ImageButton : public Button @@ -265,15 +274,18 @@ namespace olc::QuickGUI public: ImageButton(olc::QuickGUI::Manager& manager, // Associate with a Manager const olc::Renderable &icon, // Text to display + const olc::vf2d& iconScale, const olc::vf2d& pos, // Location of button top-left const olc::vf2d& size); // Size of button public: const olc::Renderable& pIcon; + olc::vf2d iconScale; public: - void Draw(olc::PixelGameEngine* pge) override; - void DrawDecal(olc::PixelGameEngine* pge) override; + void Draw(TileTransformedView&pge) override; + void DrawDecal(TileTransformedView&pge) override; + void DrawDecal(PixelGameEngine*pge) override; }; class ImageCheckBox : public ImageButton @@ -289,9 +301,9 @@ namespace olc::QuickGUI bool bChecked = false; public: - void Update(olc::PixelGameEngine* pge) override; - void Draw(olc::PixelGameEngine* pge) override; - void DrawDecal(olc::PixelGameEngine* pge) override; + void Update(TileTransformedView&pge) override; + void Draw(TileTransformedView&pge) override; + void DrawDecal(TileTransformedView&pge) override; }; @@ -320,9 +332,9 @@ namespace olc::QuickGUI olc::vf2d vPosMax; public: // BaseControl overrides - void Update(olc::PixelGameEngine* pge) override; - void Draw(olc::PixelGameEngine* pge) override; - void DrawDecal(olc::PixelGameEngine* pge) override; + void Update(TileTransformedView&pge) override; + void Draw(TileTransformedView&pge) override; + void DrawDecal(TileTransformedView&pge) override; }; @@ -357,9 +369,9 @@ namespace olc::QuickGUI bool bSelectionChanged = false; public: // BaseControl overrides - void Update(olc::PixelGameEngine* pge) override; - void Draw(olc::PixelGameEngine* pge) override; - void DrawDecal(olc::PixelGameEngine* pge) override; + void Update(TileTransformedView&pge) override; + void Draw(TileTransformedView&pge) override; + void DrawDecal(TileTransformedView&pge) override; }; @@ -410,6 +422,10 @@ namespace olc::QuickGUI { m_state = bEnable ? State::Normal : State::Disabled; } + + void BaseControl::Update(PixelGameEngine*pge){}; + void BaseControl::DrawDecal(PixelGameEngine*pge){}; + #pragma endregion #pragma region Manager @@ -432,21 +448,34 @@ namespace olc::QuickGUI m_vControls.push_back(control); } - void Manager::Update(olc::PixelGameEngine* pge) + void Manager::Update(TileTransformedView&pge) + { + for (auto& p : m_vControls) p->Update(pge); + } + + void Manager::Update(PixelGameEngine*pge) { for (auto& p : m_vControls) p->Update(pge); } - void Manager::Draw(olc::PixelGameEngine* pge) + void Manager::Draw(TileTransformedView&pge) { for (auto& p : m_vControls) p->Draw(pge); } - void Manager::DrawDecal(olc::PixelGameEngine* pge) + void Manager::DrawDecal(TileTransformedView&pge) + { + for (auto& p : m_vControls) p->DrawDecal(pge); + } + void Manager::DrawDecal(PixelGameEngine*pge) { for (auto& p : m_vControls) p->DrawDecal(pge); } + void Manager::DisplayAllControls(bool displayState){ + for (auto& p : m_vControls) p->bVisible=displayState; + } + void Manager::CopyThemeFrom(const Manager& manager) { this->colBorder = manager.colBorder; @@ -468,67 +497,67 @@ namespace olc::QuickGUI vPos = pos; vSize = size; sText = text; } - void Label::Update(olc::PixelGameEngine* pge) + void Label::Update(TileTransformedView&pge) { } - void Label::Draw(olc::PixelGameEngine* pge) + void Label::Draw(TileTransformedView&pge) { if (!bVisible) return; if (bHasBackground) { - pge->FillRect(vPos + olc::vf2d(1, 1), vSize - olc::vf2d(2, 2), m_manager.colNormal); + pge.FillRect(vPos + olc::vf2d(1, 1), vSize - olc::vf2d(2, 2), m_manager.colNormal); } if(bHasBorder) - pge->DrawRect(vPos, vSize - olc::vf2d(1, 1), m_manager.colBorder); + pge.DrawRect(vPos, vSize - olc::vf2d(1, 1), m_manager.colBorder); - olc::vf2d vText = pge->GetTextSizeProp(sText); + olc::vf2d vText = pge.GetPGE()->GetTextSize(sText); switch (nAlign) { case Alignment::Left: - pge->DrawStringProp(olc::vf2d( vPos.x + 2.0f, vPos.y + (vSize.y - vText.y) * 0.5f ), sText, m_manager.colText); + pge.DrawString(olc::vf2d( vPos.x + 2.0f, vPos.y + (vSize.y - vText.y) * 0.5f ), sText, m_manager.colText,{1,1}); break; case Alignment::Centre: - pge->DrawStringProp(vPos + (vSize - vText) * 0.5f, sText, m_manager.colText); + pge.DrawString(vPos + (vSize - vText) * 0.5f, sText, m_manager.colText,{1,1}); break; case Alignment::Right: - pge->DrawStringProp(olc::vf2d{ vPos.x + vSize.x - vText.x - 2.0f, vPos.y + (vSize.y - vText.y) * 0.5f }, sText, m_manager.colText); + pge.DrawString(olc::vf2d{ vPos.x + vSize.x - vText.x - 2.0f, vPos.y + (vSize.y - vText.y) * 0.5f }, sText, m_manager.colText,{1,1}); break; } } - void Label::DrawDecal(olc::PixelGameEngine* pge) + void Label::DrawDecal(TileTransformedView&pge) { if (!bVisible) return; if (bHasBackground) { - pge->FillRectDecal(vPos + olc::vf2d(1, 1), vSize - olc::vf2d(2, 2), m_manager.colNormal); + pge.FillRectDecal(vPos + olc::vf2d(1, 1), vSize - olc::vf2d(2, 2), m_manager.colNormal); } if (bHasBorder) { - pge->SetDecalMode(olc::DecalMode::WIREFRAME); - pge->FillRectDecal(vPos + olc::vf2d(1, 1), vSize - olc::vf2d(2,2), m_manager.colBorder); - pge->SetDecalMode(olc::DecalMode::NORMAL); + pge.GetPGE()->SetDecalMode(olc::DecalMode::WIREFRAME); + pge.FillRectDecal(vPos + olc::vf2d(1, 1), vSize - olc::vf2d(2,2), m_manager.colBorder); + pge.GetPGE()->SetDecalMode(olc::DecalMode::NORMAL); } - olc::vf2d vText = pge->GetTextSizeProp(sText); + olc::vf2d vText = pge.GetPGE()->GetTextSizeProp(sText); switch (nAlign) { case Alignment::Left: - pge->DrawStringPropDecal({ vPos.x + 2.0f, vPos.y + (vSize.y - vText.y) * 0.5f }, sText, m_manager.colText); + pge.DrawStringPropDecal({ vPos.x + 2.0f, vPos.y + (vSize.y - vText.y) * 0.5f }, sText, m_manager.colText); break; case Alignment::Centre: - pge->DrawStringPropDecal(vPos + (vSize - vText) * 0.5f, sText, m_manager.colText); + pge.DrawStringPropDecal(vPos + (vSize - vText) * 0.5f, sText, m_manager.colText); break; case Alignment::Right: - pge->DrawStringPropDecal({ vPos.x + vSize.x - vText.x - 2.0f, vPos.y + (vSize.y - vText.y) * 0.5f }, sText, m_manager.colText); + pge.DrawStringPropDecal({ vPos.x + vSize.x - vText.x - 2.0f, vPos.y + (vSize.y - vText.y) * 0.5f }, sText, m_manager.colText); break; } } @@ -544,7 +573,7 @@ namespace olc::QuickGUI bHasBackground = false; } - void TextBox::Update(olc::PixelGameEngine* pge) + void TextBox::Update(TileTransformedView&pge) { if (m_state == State::Disabled || !bVisible) return; @@ -552,106 +581,106 @@ namespace olc::QuickGUI bPressed = false; bReleased = false; - olc::vf2d vMouse = pge->GetMousePos(); + 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) { // Released inside box does nothing to me, but i may have // to finish off the neighbours... oo err - bPressed = pge->GetMouse(olc::Mouse::LEFT).bPressed; - bReleased = pge->GetMouse(olc::Mouse::LEFT).bReleased; + bPressed = pge.GetPGE()->GetMouse(olc::Mouse::LEFT).bPressed; + bReleased = pge.GetPGE()->GetMouse(olc::Mouse::LEFT).bReleased; - if (bPressed && pge->IsTextEntryEnabled() && !m_bTextEdit) + if (bPressed && pge.GetPGE()->IsTextEntryEnabled() && !m_bTextEdit) { - pge->TextEntryEnable(false); + pge.GetPGE()->TextEntryEnable(false); } - if (bPressed && !pge->IsTextEntryEnabled() && !m_bTextEdit) + if (bPressed && !pge.GetPGE()->IsTextEntryEnabled() && !m_bTextEdit) { - pge->TextEntryEnable(true, sText); + pge.GetPGE()->TextEntryEnable(true, sText); m_bTextEdit = true; } - bHeld = pge->GetMouse(olc::Mouse::LEFT).bHeld; + bHeld = pge.GetPGE()->GetMouse(olc::Mouse::LEFT).bHeld; } else { // Released outside box - bPressed = pge->GetMouse(olc::Mouse::LEFT).bPressed; - bReleased = pge->GetMouse(olc::Mouse::LEFT).bReleased; - bHeld = pge->GetMouse(olc::Mouse::LEFT).bHeld; + bPressed = pge.GetPGE()->GetMouse(olc::Mouse::LEFT).bPressed; + bReleased = pge.GetPGE()->GetMouse(olc::Mouse::LEFT).bReleased; + bHeld = pge.GetPGE()->GetMouse(olc::Mouse::LEFT).bHeld; if (bPressed && m_bTextEdit) { - sText = pge->TextEntryGetString(); - pge->TextEntryEnable(false); + sText = pge.GetPGE()->TextEntryGetString(); + pge.GetPGE()->TextEntryEnable(false); m_bTextEdit = false; } } - if (m_bTextEdit && pge->IsTextEntryEnabled()) - sText = pge->TextEntryGetString(); + if (m_bTextEdit && pge.GetPGE()->IsTextEntryEnabled()) + sText = pge.GetPGE()->TextEntryGetString(); } - void TextBox::Draw(olc::PixelGameEngine* pge) + void TextBox::Draw(TileTransformedView&pge) { if (!bVisible) return; if (bHasBackground) { - pge->FillRect(vPos + olc::vf2d(1, 1), vSize - olc::vf2d(2, 2), m_manager.colNormal); + pge.FillRect(vPos + olc::vf2d(1, 1), vSize - olc::vf2d(2, 2), m_manager.colNormal); } if (bHasBorder) - pge->DrawRect(vPos, vSize - olc::vf2d(1, 1), m_manager.colBorder); + pge.DrawRect(vPos, vSize - olc::vf2d(1, 1), m_manager.colBorder); - if (m_bTextEdit && pge->IsTextEntryEnabled()) + if (m_bTextEdit && pge.GetPGE()->IsTextEntryEnabled()) { // Draw Cursor - int32_t i = pge->TextEntryGetCursor(); - olc::vf2d vCursorPos = pge->GetTextSizeProp(sText.substr(0, i)); - pge->FillRect(olc::vf2d(vPos.x + 2.0f + vCursorPos.x, (vPos.y + (vSize.y - 10.0f) * 0.5f)), { 2, 10 }, m_manager.colText); + int32_t i = pge.GetPGE()->TextEntryGetCursor(); + olc::vf2d vCursorPos = pge.GetPGE()->GetTextSize(sText.substr(0, i)); + pge.FillRect(olc::vf2d(vPos.x + 2.0f + vCursorPos.x, (vPos.y + (vSize.y - 10.0f) * 0.5f)), { 2, 10 }, m_manager.colText); } // Draw Text - olc::vf2d vText = pge->GetTextSizeProp(sText); - pge->DrawStringProp(olc::vf2d(vPos.x + 2.0f, vPos.y + (vSize.y - vText.y) * 0.5f), sText, m_manager.colText); + olc::vf2d vText = pge.GetPGE()->GetTextSize(sText); + pge.DrawString(olc::vf2d(vPos.x + 2.0f, vPos.y + (vSize.y - vText.y) * 0.5f), sText, m_manager.colText,{1,1}); } - void TextBox::DrawDecal(olc::PixelGameEngine* pge) + void TextBox::DrawDecal(TileTransformedView&pge) { if (!bVisible) return; if (bHasBackground) { - pge->FillRectDecal(vPos + olc::vf2d(1, 1), vSize - olc::vf2d(2, 2), m_manager.colNormal); + pge.FillRectDecal(vPos + olc::vf2d(1, 1), vSize - olc::vf2d(2, 2), m_manager.colNormal); } if (bHasBorder) { - pge->SetDecalMode(olc::DecalMode::WIREFRAME); - pge->FillRectDecal(vPos + olc::vf2d(1, 1), vSize - olc::vf2d(2, 2), m_manager.colBorder); - pge->SetDecalMode(olc::DecalMode::NORMAL); + pge.GetPGE()->SetDecalMode(olc::DecalMode::WIREFRAME); + pge.FillRectDecal(vPos + olc::vf2d(1, 1), vSize - olc::vf2d(2, 2), m_manager.colBorder); + pge.GetPGE()->SetDecalMode(olc::DecalMode::NORMAL); } - if (m_bTextEdit && pge->IsTextEntryEnabled()) + if (m_bTextEdit && pge.GetPGE()->IsTextEntryEnabled()) { // Draw Cursor - int32_t i = pge->TextEntryGetCursor(); - olc::vf2d vCursorPos = pge->GetTextSizeProp(sText.substr(0, i)); - pge->FillRectDecal(olc::vf2d(vPos.x + 2.0f + vCursorPos.x, (vPos.y + (vSize.y - 10.0f) * 0.5f)), { 2, 10 }, m_manager.colText); + int32_t i = pge.GetPGE()->TextEntryGetCursor(); + olc::vf2d vCursorPos = pge.GetPGE()->GetTextSizeProp(sText.substr(0, i)); + pge.FillRectDecal(olc::vf2d(vPos.x + 2.0f + vCursorPos.x, (vPos.y + (vSize.y - 10.0f) * 0.5f)), { 2, 10 }, m_manager.colText); } // Draw Text - olc::vf2d vText = pge->GetTextSizeProp(sText); - pge->DrawStringPropDecal(olc::vf2d(vPos.x + 2.0f, vPos.y + (vSize.y - vText.y) * 0.5f), sText, m_manager.colText); + olc::vf2d vText = pge.GetPGE()->GetTextSizeProp(sText); + pge.DrawStringPropDecal(olc::vf2d(vPos.x + 2.0f, vPos.y + (vSize.y - vText.y) * 0.5f), sText, m_manager.colText); } #pragma endregion @@ -662,7 +691,49 @@ namespace olc::QuickGUI vPos = pos; vSize = size; sText = text; } - void Button::Update(olc::PixelGameEngine* pge) + void Button::Update(TileTransformedView&pge) + { + if (m_state == State::Disabled || !bVisible) + return; + + bPressed = false; + bReleased = false; + 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 && + vMouse.y >= vPos.y && vMouse.y < vPos.y + vSize.y) + { + m_fTransition += fElapsedTime * m_manager.fHoverSpeedOn; + m_state = State::Hover; + + bPressed = pge.GetPGE()->GetMouse(olc::Mouse::LEFT).bPressed; + if (bPressed) + { + m_state = State::Click; + } + + bHeld = pge.GetPGE()->GetMouse(olc::Mouse::LEFT).bHeld; + } + else + { + m_fTransition -= fElapsedTime * m_manager.fHoverSpeedOff; + m_state = State::Normal; + } + } + else + { + bHeld = pge.GetPGE()->GetMouse(olc::Mouse::LEFT).bHeld; + bReleased = pge.GetPGE()->GetMouse(olc::Mouse::LEFT).bReleased; + if (bReleased) m_state = State::Normal; + } + + m_fTransition = std::clamp(m_fTransition, 0.0f, 1.0f); + } + + void Button::Update(PixelGameEngine*pge) { if (m_state == State::Disabled || !bVisible) return; @@ -704,7 +775,7 @@ namespace olc::QuickGUI m_fTransition = std::clamp(m_fTransition, 0.0f, 1.0f); } - void Button::Draw(olc::PixelGameEngine* pge) + void Button::Draw(TileTransformedView&pge) { if (!bVisible) return; @@ -712,23 +783,49 @@ namespace olc::QuickGUI switch (m_state) { case State::Disabled: - pge->FillRect(vPos, vSize, m_manager.colDisable); + pge.FillRect(vPos, vSize, m_manager.colDisable); break; case State::Normal: case State::Hover: - pge->FillRect(vPos, vSize, olc::PixelLerp(m_manager.colNormal, m_manager.colHover, m_fTransition)); + pge.FillRect(vPos, vSize, olc::PixelLerp(m_manager.colNormal, m_manager.colHover, m_fTransition)); break; case State::Click: - pge->FillRect(vPos, vSize, m_manager.colClick); + pge.FillRect(vPos, vSize, m_manager.colClick); break; } - pge->DrawRect(vPos, vSize - olc::vf2d(1, 1), m_manager.colBorder); - olc::vf2d vText = pge->GetTextSizeProp(sText); - pge->DrawStringProp(vPos + (vSize - vText) * 0.5f, sText, m_manager.colText); + pge.DrawRect(vPos, vSize - olc::vf2d(1, 1), m_manager.colBorder); + olc::vf2d vText = pge.GetPGE()->GetTextSize(sText); + pge.DrawString(vPos + (vSize - vText) * 0.5f, sText, m_manager.colText,{1,1}); + } + + void Button::DrawDecal(TileTransformedView&pge) + { + if (!bVisible) + return; + + switch (m_state) + { + case State::Disabled: + pge.FillRectDecal(vPos + olc::vf2d(1, 1), vSize - olc::vf2d(2, 2), m_manager.colDisable); + break; + case State::Normal: + case State::Hover: + pge.FillRectDecal(vPos + olc::vf2d(1, 1), vSize - olc::vf2d(2, 2), olc::PixelLerp(m_manager.colNormal, m_manager.colHover, m_fTransition)); + break; + case State::Click: + pge.FillRectDecal(vPos + olc::vf2d(1, 1), vSize - olc::vf2d(2, 2), m_manager.colClick); + break; + } + pge.GetPGE()->SetDecalMode(olc::DecalMode::WIREFRAME); + pge.FillRectDecal(vPos + olc::vf2d(1, 1), vSize - olc::vf2d(2, 2), m_manager.colBorder); + pge.GetPGE()->SetDecalMode(olc::DecalMode::NORMAL); + + olc::vf2d vText = pge.GetPGE()->GetTextSizeProp(sText); + pge.DrawStringPropDecal(vPos + (vSize - vText) * 0.5f, sText, m_manager.colText); } - void Button::DrawDecal(olc::PixelGameEngine* pge) + void Button::DrawDecal(PixelGameEngine*pge) { if (!bVisible) return; @@ -757,34 +854,40 @@ namespace olc::QuickGUI #pragma region ImageButton - ImageButton::ImageButton(olc::QuickGUI::Manager& manager, const olc::Renderable& icon, const olc::vf2d& pos, const olc::vf2d& size) - : Button(manager, "", pos, size), pIcon(icon) + ImageButton::ImageButton(olc::QuickGUI::Manager& manager, const olc::Renderable& icon, const olc::vf2d& iconScale, const olc::vf2d& pos, const olc::vf2d& size) + : Button(manager, "", pos, size), pIcon(icon), iconScale(iconScale) { } - void ImageButton::Draw(olc::PixelGameEngine* pge) + void ImageButton::Draw(TileTransformedView&pge) { Button::Draw(pge); - pge->DrawSprite(vPos + olc::vi2d(4, 4), pIcon.Sprite()); + pge.DrawSprite(vPos + olc::vi2d(4, 4), pIcon.Sprite()); } - void ImageButton::DrawDecal(olc::PixelGameEngine* pge) - { + void ImageButton::DrawDecal(TileTransformedView&pge){ + if (!bVisible) return; Button::DrawDecal(pge); - pge->DrawDecal(vPos + olc::vi2d(4, 4), pIcon.Decal()); + pge.DrawDecal(vPos + olc::vi2d(4, 4), pIcon.Decal(), iconScale,m_state!=State::Disabled?WHITE:WHITE/4); } + + void ImageButton::DrawDecal(PixelGameEngine*pge){ + if (!bVisible) return; + Button::DrawDecal(pge); + pge->DrawDecal(vPos + olc::vi2d(4, 4), pIcon.Decal(), iconScale,m_state!=State::Disabled?WHITE:WHITE/4); + }; #pragma endregion #pragma region ImageCheckBox ImageCheckBox::ImageCheckBox(olc::QuickGUI::Manager& manager, const olc::Renderable& gfx, const bool check, const olc::vf2d& pos, const olc::vf2d& size) - : ImageButton(manager, gfx, pos, size) + : ImageButton(manager, gfx,{1,1}, pos, size) { bChecked = check; } - void ImageCheckBox::Update(olc::PixelGameEngine* pge) + void ImageCheckBox::Update(TileTransformedView&pge) { if (m_state == State::Disabled || !bVisible) return; @@ -793,28 +896,29 @@ namespace olc::QuickGUI if (bPressed) bChecked = !bChecked; } - void ImageCheckBox::Draw(olc::PixelGameEngine* pge) + void ImageCheckBox::Draw(TileTransformedView&pge) { ImageButton::Draw(pge); if (bChecked) - pge->DrawRect(vPos + olc::vf2d(2, 2), vSize - olc::vi2d(5, 5), m_manager.colBorder); + pge.DrawRect(vPos + olc::vf2d(2, 2), vSize - olc::vi2d(5, 5), m_manager.colBorder); } - void ImageCheckBox::DrawDecal(olc::PixelGameEngine* pge) + void ImageCheckBox::DrawDecal(TileTransformedView&pge) { if (!bVisible) return; ImageButton::DrawDecal(pge); - pge->SetDecalMode(olc::DecalMode::WIREFRAME); - pge->FillRectDecal(vPos + olc::vf2d(2, 2), vSize - olc::vf2d(4, 4), m_manager.colBorder); - pge->SetDecalMode(olc::DecalMode::NORMAL); + pge.GetPGE()->SetDecalMode(olc::DecalMode::WIREFRAME); + pge.FillRectDecal(vPos + olc::vf2d(2, 2), vSize - olc::vf2d(4, 4), m_manager.colBorder); + pge.GetPGE()->SetDecalMode(olc::DecalMode::NORMAL); - olc::vf2d vText = pge->GetTextSizeProp(sText); - pge->DrawStringPropDecal(vPos + (vSize - vText) * 0.5f, sText, m_manager.colText); + olc::vf2d vText = pge.GetPGE()->GetTextSizeProp(sText); + pge.DrawStringPropDecal(vPos + (vSize - vText) * 0.5f, sText, m_manager.colText); } + #pragma endregion @@ -825,7 +929,7 @@ namespace olc::QuickGUI bChecked = check; } - void CheckBox::Update(olc::PixelGameEngine* pge) + void CheckBox::Update(TileTransformedView&pge) { if (m_state == State::Disabled || !bVisible) return; @@ -835,7 +939,7 @@ namespace olc::QuickGUI bChecked = !bChecked; } - void CheckBox::Draw(olc::PixelGameEngine* pge) + void CheckBox::Draw(TileTransformedView&pge) { if (!bVisible) return; @@ -843,10 +947,10 @@ namespace olc::QuickGUI Button::Draw(pge); if (bChecked) - pge->DrawRect(vPos + olc::vf2d(2, 2), vSize - olc::vi2d(5, 5), m_manager.colBorder); + pge.DrawRect(vPos + olc::vf2d(2, 2), vSize - olc::vi2d(5, 5), m_manager.colBorder); } - void CheckBox::DrawDecal(olc::PixelGameEngine* pge) + void CheckBox::DrawDecal(TileTransformedView&pge) { if (!bVisible) return; @@ -855,13 +959,13 @@ namespace olc::QuickGUI if (bChecked) { - pge->SetDecalMode(olc::DecalMode::WIREFRAME); - pge->FillRectDecal(vPos + olc::vf2d(2, 2), vSize - olc::vf2d(4, 4), m_manager.colBorder); - pge->SetDecalMode(olc::DecalMode::NORMAL); + pge.GetPGE()->SetDecalMode(olc::DecalMode::WIREFRAME); + pge.FillRectDecal(vPos + olc::vf2d(2, 2), vSize - olc::vf2d(4, 4), m_manager.colBorder); + pge.GetPGE()->SetDecalMode(olc::DecalMode::NORMAL); } - olc::vf2d vText = pge->GetTextSizeProp(sText); - pge->DrawStringPropDecal(vPos + (vSize - vText) * 0.5f, sText, m_manager.colText); + olc::vf2d vText = pge.GetPGE()->GetTextSizeProp(sText); + pge.DrawStringPropDecal(vPos + (vSize - vText) * 0.5f, sText, m_manager.colText); } #pragma endregion @@ -872,14 +976,14 @@ namespace olc::QuickGUI vPosMin = posmin; vPosMax = posmax; fMin = valmin; fMax = valmax; fValue = value; } - void Slider::Update(olc::PixelGameEngine* pge) + void Slider::Update(TileTransformedView&pge) { if (m_state == State::Disabled || !bVisible) return; - float fElapsedTime = pge->GetElapsedTime(); + float fElapsedTime = pge.GetPGE()->GetElapsedTime(); - olc::vf2d vMouse = pge->GetMousePos(); + olc::vf2d vMouse = pge.GetPGE()->GetMousePos(); bHeld = false; if (m_state == State::Click) { @@ -895,7 +999,7 @@ namespace olc::QuickGUI { m_fTransition += fElapsedTime * m_manager.fHoverSpeedOn; m_state = State::Hover; - if (pge->GetMouse(olc::Mouse::LEFT).bPressed) + if (pge.GetPGE()->GetMouse(olc::Mouse::LEFT).bPressed) { m_state = State::Click; bPressed = true; @@ -905,7 +1009,7 @@ namespace olc::QuickGUI m_state = State::Normal; } - if (pge->GetMouse(olc::Mouse::LEFT).bReleased) + if (pge.GetPGE()->GetMouse(olc::Mouse::LEFT).bReleased) { m_state = State::Normal; bReleased = true; @@ -922,57 +1026,57 @@ namespace olc::QuickGUI m_fTransition = std::clamp(m_fTransition, 0.0f, 1.0f); } - void Slider::Draw(olc::PixelGameEngine* pge) + void Slider::Draw(TileTransformedView&pge) { if (!bVisible) return; - pge->DrawLine(vPosMin, vPosMax, m_manager.colBorder); + pge.DrawLine(vPosMin, vPosMax, m_manager.colBorder); olc::vf2d vSliderPos = vPosMin + (vPosMax - vPosMin) * ((fValue - fMin) / (fMax - fMin)); switch (m_state) { case State::Disabled: - pge->FillCircle(vSliderPos, int32_t(m_manager.fGrabRad), m_manager.colDisable); + pge.FillCircle(vSliderPos, int32_t(m_manager.fGrabRad), m_manager.colDisable); break; case State::Normal: case State::Hover: - pge->FillCircle(vSliderPos, int32_t(m_manager.fGrabRad), olc::PixelLerp(m_manager.colNormal, m_manager.colHover, m_fTransition)); + pge.FillCircle(vSliderPos, int32_t(m_manager.fGrabRad), olc::PixelLerp(m_manager.colNormal, m_manager.colHover, m_fTransition)); break; case State::Click: - pge->FillCircle(vSliderPos, int32_t(m_manager.fGrabRad), m_manager.colClick); + pge.FillCircle(vSliderPos, int32_t(m_manager.fGrabRad), m_manager.colClick); break; } - pge->DrawCircle(vSliderPos, int32_t(m_manager.fGrabRad), m_manager.colBorder); + pge.DrawCircle(vSliderPos, int32_t(m_manager.fGrabRad), m_manager.colBorder); } - void Slider::DrawDecal(olc::PixelGameEngine* pge) + void Slider::DrawDecal(TileTransformedView&pge) { if (!bVisible) return; - pge->DrawLineDecal(vPosMin, vPosMax, m_manager.colBorder); + pge.DrawLineDecal(vPosMin, vPosMax, m_manager.colBorder); olc::vf2d vSliderPos = vPosMin + (vPosMax - vPosMin) * ((fValue - fMin) / (fMax - fMin)); switch (m_state) { case State::Disabled: - pge->FillRectDecal(vSliderPos - olc::vf2d(m_manager.fGrabRad, m_manager.fGrabRad), olc::vf2d(m_manager.fGrabRad, m_manager.fGrabRad) * 2.0f, m_manager.colDisable); + pge.FillRectDecal(vSliderPos - olc::vf2d(m_manager.fGrabRad, m_manager.fGrabRad), olc::vf2d(m_manager.fGrabRad, m_manager.fGrabRad) * 2.0f, m_manager.colDisable); break; case State::Normal: case State::Hover: - pge->FillRectDecal(vSliderPos - olc::vf2d(m_manager.fGrabRad, m_manager.fGrabRad), olc::vf2d(m_manager.fGrabRad, m_manager.fGrabRad) * 2.0f, olc::PixelLerp(m_manager.colNormal, m_manager.colHover, m_fTransition)); + pge.FillRectDecal(vSliderPos - olc::vf2d(m_manager.fGrabRad, m_manager.fGrabRad), olc::vf2d(m_manager.fGrabRad, m_manager.fGrabRad) * 2.0f, olc::PixelLerp(m_manager.colNormal, m_manager.colHover, m_fTransition)); break; case State::Click: - pge->FillRectDecal(vSliderPos - olc::vf2d(m_manager.fGrabRad, m_manager.fGrabRad), olc::vf2d(m_manager.fGrabRad, m_manager.fGrabRad) * 2.0f, m_manager.colClick); + pge.FillRectDecal(vSliderPos - olc::vf2d(m_manager.fGrabRad, m_manager.fGrabRad), olc::vf2d(m_manager.fGrabRad, m_manager.fGrabRad) * 2.0f, m_manager.colClick); break; } - pge->SetDecalMode(olc::DecalMode::WIREFRAME); - pge->FillRectDecal(vSliderPos - olc::vf2d(m_manager.fGrabRad, m_manager.fGrabRad), olc::vf2d(m_manager.fGrabRad, m_manager.fGrabRad) * 2.0f, m_manager.colBorder); - pge->SetDecalMode(olc::DecalMode::NORMAL); + pge.GetPGE()->SetDecalMode(olc::DecalMode::WIREFRAME); + pge.FillRectDecal(vSliderPos - olc::vf2d(m_manager.fGrabRad, m_manager.fGrabRad), olc::vf2d(m_manager.fGrabRad, m_manager.fGrabRad) * 2.0f, m_manager.colBorder); + pge.GetPGE()->SetDecalMode(olc::DecalMode::NORMAL); } @@ -989,15 +1093,15 @@ namespace olc::QuickGUI { pos.x + size.x - m_manager.fGrabRad - 1, pos.y + size.y - m_manager.fGrabRad - 1 }, 0, float(m_vList.size()), 0); } - void ListBox::Update(olc::PixelGameEngine* pge) + void ListBox::Update(TileTransformedView&pge) { if (m_state == State::Disabled || !bVisible) return; nPreviouslySelectedItem = nSelectedItem; - olc::vf2d vMouse = pge->GetMousePos() - vPos + olc::vi2d(2,0); - if (pge->GetMouse(olc::Mouse::LEFT).bPressed) + olc::vf2d vMouse = pge.GetPGE()->GetMousePos() - vPos + olc::vi2d(2,0); + if (pge.GetPGE()->GetMouse(olc::Mouse::LEFT).bPressed) { if (vMouse.x >= 0 && vMouse.x < vSize.x - (m_group.fGrabRad * 2) && vMouse.y >= 0 && vMouse.y < vSize.y) { @@ -1015,18 +1119,18 @@ namespace olc::QuickGUI m_group.Update(pge); } - void ListBox::Draw(olc::PixelGameEngine* pge) + void ListBox::Draw(TileTransformedView&pge) { if (!bVisible) return; if (bHasBackground) { - pge->FillRect(vPos + olc::vf2d(1, 1), vSize - olc::vf2d(2, 2), m_manager.colNormal); + pge.FillRect(vPos + olc::vf2d(1, 1), vSize - olc::vf2d(2, 2), m_manager.colNormal); } if (bHasBorder) - pge->DrawRect(vPos, vSize - olc::vf2d(1, 1), m_manager.colBorder); + pge.DrawRect(vPos, vSize - olc::vf2d(1, 1), m_manager.colBorder); size_t idx0 = size_t(m_pSlider->fValue); @@ -1036,21 +1140,21 @@ namespace olc::QuickGUI for (size_t idx = idx0; idx < idx1; idx++) { if (idx == nSelectedItem) - pge->FillRect(vTextPos - olc::vi2d(1,1), {int32_t(vSize.x - m_group.fGrabRad * 2), 10}, m_group.colHover); - pge->DrawStringProp(vTextPos, m_vList[idx]); + pge.FillRect(vTextPos - olc::vi2d(1,1), {float(vSize.x - m_group.fGrabRad * 2), 10.f}, m_group.colHover); + pge.GetPGE()->DrawStringProp(vTextPos, m_vList[idx]); vTextPos.y += 10; } m_group.Draw(pge); } - void ListBox::DrawDecal(olc::PixelGameEngine* pge) + void ListBox::DrawDecal(TileTransformedView&pge) { if (!bVisible) return; if (bHasBackground) - pge->FillRectDecal(vPos + olc::vf2d(1, 1), vSize - olc::vf2d(2, 2), m_manager.colNormal); + pge.FillRectDecal(vPos + olc::vf2d(1, 1), vSize - olc::vf2d(2, 2), m_manager.colNormal); size_t idx0 = size_t(m_pSlider->fValue); size_t idx1 = std::min(idx0 + size_t((vSize.y - 4) / 10), m_vList.size()); @@ -1059,16 +1163,16 @@ namespace olc::QuickGUI for (size_t idx = idx0; idx < idx1; idx++) { if (idx == nSelectedItem) - pge->FillRectDecal(vTextPos - olc::vi2d(1, 1), { vSize.x - m_group.fGrabRad * 2.0f, 10.0f }, m_group.colHover); - pge->DrawStringPropDecal(vTextPos, m_vList[idx]); + pge.FillRectDecal(vTextPos - olc::vi2d(1, 1), { vSize.x - m_group.fGrabRad * 2.0f, 10.0f }, m_group.colHover); + pge.DrawStringPropDecal(vTextPos, m_vList[idx]); vTextPos.y += 10; } if (bHasBorder) { - pge->SetDecalMode(olc::DecalMode::WIREFRAME); - pge->FillRectDecal(vPos + olc::vf2d(1, 1), vSize - olc::vf2d(2, 2), m_manager.colBorder); - pge->SetDecalMode(olc::DecalMode::NORMAL); + pge.GetPGE()->SetDecalMode(olc::DecalMode::WIREFRAME); + pge.FillRectDecal(vPos + olc::vf2d(1, 1), vSize - olc::vf2d(2, 2), m_manager.colBorder); + pge.GetPGE()->SetDecalMode(olc::DecalMode::NORMAL); } m_group.DrawDecal(pge); @@ -1106,7 +1210,7 @@ namespace olc::QuickGUI { if(!m_bShowDialog) return false; - m_manFileSelect.Update(this->pge); + //m_manFileSelect.Update(pge); if (pge->GetKey(olc::Key::BACK).bPressed) { @@ -1146,20 +1250,16 @@ namespace olc::QuickGUI } - pge->DrawStringDecal({ 0,0 }, m_path.string()); + //pge.DrawStringDecal({ 0,0 }, m_path.string()); - m_manFileSelect.DrawDecal(this->pge); + //m_manFileSelect.DrawDecal(this->pge); - if (pge->GetKey(olc::Key::ESCAPE).bPressed) - { - m_bShowDialog = false; - return false; - } + return true; }