parent
2914aa1972
commit
3723835cc7
@ -1,22 +0,0 @@ |
||||
#include "Crawler.h" |
||||
#include "Menu.h" |
||||
|
||||
MenuButton::MenuButton(geom2d::rect<float>rect,std::string label,Decal*icon,MenuFunc onClick) |
||||
:rect(rect),label(label),menuDest(MenuType::ENUM_END),icon(icon),onClick(onClick),hoverEffect(0){} |
||||
|
||||
MenuButton::MenuButton(geom2d::rect<float>rect,std::string label,MenuType menuDest,Decal*icon,MenuFunc onClick) |
||||
:rect(rect),label(label),menuDest(menuDest),icon(icon),onClick(onClick),hoverEffect(0){} |
||||
|
||||
void MenuButton::Update(Crawler*game){ |
||||
if(hovered){ |
||||
hoverEffect=std::min(1.f,hoverEffect+game->GetElapsedTime()); |
||||
}else{ |
||||
hoverEffect=std::max(0.f,hoverEffect-game->GetElapsedTime()); |
||||
} |
||||
} |
||||
|
||||
void MenuButton::Draw(Crawler*game,vf2d parentPos){ |
||||
game->FillRectDecal(rect.pos+parentPos,rect.size,PixelLerp(VERY_DARK_BLUE,CYAN,hoverEffect)); |
||||
game->DrawRectDecal(rect.pos+parentPos,rect.size,GREY); |
||||
game->DrawStringPropDecal(rect.pos+parentPos+rect.size/2-game->GetTextSizeProp(label)/2,label); |
||||
} |
@ -1,24 +0,0 @@ |
||||
#pragma once |
||||
#include "olcUTIL_Geometry2D.h" |
||||
#include "MenuType.h" |
||||
#include <functional> |
||||
|
||||
class Menu; |
||||
class Crawler; |
||||
|
||||
class MenuButton{ |
||||
friend class Menu; |
||||
MenuType menuDest; |
||||
geom2d::rect<float>rect; |
||||
std::string label; |
||||
Decal*icon; |
||||
MenuFunc onClick; |
||||
bool hovered=false; |
||||
private: |
||||
float hoverEffect=0; |
||||
public: |
||||
MenuButton(geom2d::rect<float>rect,std::string label,Decal*icon,MenuFunc onClick); |
||||
MenuButton(geom2d::rect<float>rect,std::string label,MenuType menuDest,Decal* icon,MenuFunc onClick); |
||||
void Update(Crawler*game); |
||||
void Draw(Crawler*game,vf2d parentPos); |
||||
}; |
@ -0,0 +1,22 @@ |
||||
#include "Crawler.h" |
||||
#include "Menu.h" |
||||
|
||||
MenuComponent::MenuComponent(geom2d::rect<float>rect,std::string label,MenuFunc onClick) |
||||
:rect(rect),label(label),menuDest(MenuType::ENUM_END),onClick(onClick),hoverEffect(0){} |
||||
|
||||
MenuComponent::MenuComponent(geom2d::rect<float>rect,std::string label,MenuType menuDest,MenuFunc onClick) |
||||
:rect(rect),label(label),menuDest(menuDest),onClick(onClick),hoverEffect(0){} |
||||
|
||||
void MenuComponent::Update(Crawler*game){ |
||||
if(hovered){ |
||||
hoverEffect=std::min(1.f,hoverEffect+game->GetElapsedTime()); |
||||
}else{ |
||||
hoverEffect=std::max(0.f,hoverEffect-game->GetElapsedTime()); |
||||
} |
||||
} |
||||
|
||||
void MenuComponent::Draw(Crawler*game,vf2d parentPos){ |
||||
game->FillRectDecal(rect.pos+parentPos,rect.size,PixelLerp(VERY_DARK_BLUE,CYAN,hoverEffect)); |
||||
game->DrawRectDecal(rect.pos+parentPos,rect.size,GREY); |
||||
game->DrawStringPropDecal(rect.pos+parentPos+rect.size/2-game->GetTextSizeProp(label)/2,label); |
||||
} |
@ -0,0 +1,34 @@ |
||||
#pragma once |
||||
#include "olcUTIL_Geometry2D.h" |
||||
#include "MenuType.h" |
||||
#include <functional> |
||||
|
||||
class Menu; |
||||
class Crawler; |
||||
|
||||
class MenuComponent{ |
||||
friend class Menu; |
||||
MenuType menuDest; |
||||
std::string label; |
||||
MenuFunc onClick; |
||||
bool hovered=false; |
||||
private: |
||||
float hoverEffect=0; |
||||
protected: |
||||
geom2d::rect<float>rect; |
||||
public: |
||||
MenuComponent(geom2d::rect<float>rect,std::string label,MenuFunc onClick); |
||||
MenuComponent(geom2d::rect<float>rect,std::string label,MenuType menuDest,MenuFunc onClick); |
||||
virtual void Update(Crawler*game); |
||||
virtual void Draw(Crawler*game,vf2d parentPos); |
||||
}; |
||||
|
||||
class MenuIconButton:public MenuComponent{ |
||||
private: |
||||
Decal*icon; |
||||
public: |
||||
MenuIconButton(geom2d::rect<float>rect,Decal*icon,MenuFunc onClick); |
||||
protected: |
||||
virtual void Update(Crawler*game)override; |
||||
virtual void Draw(Crawler*game,vf2d parentPos)override; |
||||
}; |
@ -0,0 +1,15 @@ |
||||
#include "MenuComponent.h" |
||||
#include "Crawler.h" |
||||
|
||||
MenuIconButton::MenuIconButton(geom2d::rect<float>rect,Decal*icon,MenuFunc onClick) |
||||
:MenuComponent(rect,"",onClick),icon(icon) |
||||
{} |
||||
|
||||
void MenuIconButton::Update(Crawler*game){ |
||||
MenuComponent::Update(game); |
||||
} |
||||
|
||||
void MenuIconButton::Draw(Crawler*game,vf2d parentPos){ |
||||
MenuComponent::Draw(game,parentPos); |
||||
game->DrawRotatedDecal(parentPos+rect.middle(),icon,0,icon->sprite->Size()/2); |
||||
} |
@ -1,20 +1,31 @@ |
||||
#include "Crawler.h" |
||||
#include "Menu.h" |
||||
#include "DEFINES.h" |
||||
#include "olcPixelGameEngine.h" |
||||
#include "safemap.h" |
||||
|
||||
INCLUDE_GFX |
||||
|
||||
const Menu Menu::InitializeTestSubMenu(){ |
||||
Menu testSubMenu({24*4,24*5}); |
||||
|
||||
MenuFunc goBack=[](Menu&menu,Crawler*game){ |
||||
MenuFunc goBack=MENUFUNC{ |
||||
menu.stack.pop_back(); |
||||
}; |
||||
|
||||
testSubMenu.AddButton(MenuButton({{24*1,24*1},{24*2,24*1}},"Go Back",nullptr,goBack)); |
||||
testSubMenu.AddComponent(new MenuComponent({{24*1,24*1},{24*2,24*1}},"Go Back",goBack)); |
||||
|
||||
MenuFunc quitWindow=[](Menu&menu,Crawler*game){ |
||||
MenuFunc quitWindow=MENUFUNC{ |
||||
menu.stack.clear(); |
||||
}; |
||||
|
||||
testSubMenu.AddButton(MenuButton({{24*1,24*3},{24*3,24*1}},"Close Window",nullptr,quitWindow)); |
||||
testSubMenu.AddComponent(new MenuComponent({{24*1,24*3},{24*3,24*1}},"Close Window",quitWindow)); |
||||
|
||||
MenuFunc restoreMana=MENUFUNC{ |
||||
game->GetPlayer()->SetMana(game->GetPlayer()->GetMaxMana()); |
||||
}; |
||||
|
||||
testSubMenu.AddComponent(new MenuIconButton({{24*0,24*3},{24*1,24*2}},GFX["mana.png"].Decal(),restoreMana)); |
||||
|
||||
return testSubMenu; |
||||
} |
Loading…
Reference in new issue