Refactor menucomponent internal draw function a little bit for code organizing.

pull/28/head
sigonasr2 1 year ago
parent fe8cbb022a
commit c82a3c5980
  1. 8
      Crawler/Menu.cpp
  2. 14
      Crawler/MenuComponent.cpp
  3. 2
      Crawler/MenuComponent.h
  4. 1
      Crawler/State_OverworldMap.cpp
  5. 2
      Crawler/Version.h

@ -276,13 +276,13 @@ void Menu::Draw(Crawler*game){
game->Clear(BLANK); game->Clear(BLANK);
for(auto&component:displayComponents){ for(auto&component:displayComponents){
if(component->renderInMain){ if(component->renderInMain){
component->_Draw(game,{0,0}); component->_Draw(game);
} }
} }
for(auto&key:buttons){ for(auto&key:buttons){
for(auto&button:key.second){ for(auto&button:key.second){
if(button->renderInMain){ if(button->renderInMain){
button->_Draw(game,{0,0}); button->_Draw(game);
} }
} }
} }
@ -292,13 +292,13 @@ void Menu::Draw(Crawler*game){
game->DrawDecal(pos,r.Decal()); game->DrawDecal(pos,r.Decal());
for(auto&component:displayComponents){ for(auto&component:displayComponents){
if(component->renderInMain){ if(component->renderInMain){
component->_DrawDecal(game,{0,0},this==Menu::stack.back()); component->_DrawDecal(game,this==Menu::stack.back());
} }
} }
for(auto&key:buttons){ for(auto&key:buttons){
for(auto&button:key.second){ for(auto&button:key.second){
if(button->renderInMain){ if(button->renderInMain){
button->_DrawDecal(game,{0,0},this==Menu::stack.back()); button->_DrawDecal(game,this==Menu::stack.back());
} }
} }
} }

@ -45,16 +45,20 @@ void MenuComponent::_Update(Crawler*game){
void MenuComponent::Draw(Crawler*game,vf2d parentPos){ void MenuComponent::Draw(Crawler*game,vf2d parentPos){
if(background){ if(background){
game->FillRect(rect.pos+parentPos,rect.size,PixelLerp(Menu::themes[Menu::themeSelection].GetButtonCol(),Menu::themes[Menu::themeSelection].GetHighlightCol(),hoverEffect/"ThemeGlobal.HighlightTime"_F)); game->FillRect(rect.pos,rect.size,PixelLerp(Menu::themes[Menu::themeSelection].GetButtonCol(),Menu::themes[Menu::themeSelection].GetHighlightCol(),hoverEffect/"ThemeGlobal.HighlightTime"_F));
} }
if(border){ if(border){
game->DrawRect(rect.pos+parentPos,rect.size); game->DrawRect(rect.pos,rect.size);
} }
if(showDefaultLabel){ if(showDefaultLabel){
game->DrawStringProp(rect.pos+parentPos+rect.size/2-game->GetTextSizeProp(label)/2,label); game->DrawStringProp(rect.pos+rect.size/2-game->GetTextSizeProp(label)/2,label);
} }
} }
void MenuComponent::_Draw(Crawler*game){
_Draw(game,{0,0});
}
void MenuComponent::_Draw(Crawler*game,vf2d parentPos){ void MenuComponent::_Draw(Crawler*game,vf2d parentPos){
if(!disabled){ if(!disabled){
Draw(game,parentPos); Draw(game,parentPos);
@ -63,6 +67,10 @@ void MenuComponent::_Draw(Crawler*game,vf2d parentPos){
void MenuComponent::DrawDecal(Crawler*game,vf2d parentPos,bool focused){} void MenuComponent::DrawDecal(Crawler*game,vf2d parentPos,bool focused){}
void MenuComponent::_DrawDecal(Crawler*game,bool focused){
_DrawDecal(game,{0,0},focused);
}
void MenuComponent::_DrawDecal(Crawler*game,vf2d parentPos,bool focused){ void MenuComponent::_DrawDecal(Crawler*game,vf2d parentPos,bool focused){
if(!disabled){ if(!disabled){
DrawDecal(game,parentPos,focused); DrawDecal(game,parentPos,focused);

@ -40,7 +40,9 @@ public:
MenuComponent(MenuType parent,geom2d::rect<float>rect,std::string label,MenuType menuDest,MenuFunc onClick,bool selectable=true,bool selectableViaKeyboard=true); MenuComponent(MenuType parent,geom2d::rect<float>rect,std::string label,MenuType menuDest,MenuFunc onClick,bool selectable=true,bool selectableViaKeyboard=true);
virtual ~MenuComponent(); virtual ~MenuComponent();
void _Update(Crawler*game); void _Update(Crawler*game);
void _Draw(Crawler*game);
void _Draw(Crawler*game,vf2d parentPos); void _Draw(Crawler*game,vf2d parentPos);
void _DrawDecal(Crawler*game,bool focused);
void _DrawDecal(Crawler*game,vf2d parentPos,bool focused); void _DrawDecal(Crawler*game,vf2d parentPos,bool focused);
vf2d GetPos(); vf2d GetPos();
//We picked up a draggable component, we should make a copy and return it here. If a nullptr is returned here, the pickup is not allowed. //We picked up a draggable component, we should make a copy and return it here. If a nullptr is returned here, the pickup is not allowed.

@ -38,7 +38,6 @@ void State_OverworldMap::OnUserUpdate(Crawler*game){
for(ConnectionPoint&cp:connections){ for(ConnectionPoint&cp:connections){
if(game->GetMouse(Mouse::LEFT).bPressed&&geom2d::overlaps(game->GetWorldMousePos(),cp.rect)){ if(game->GetMouse(Mouse::LEFT).bPressed&&geom2d::overlaps(game->GetWorldMousePos(),cp.rect)){
Menu::OpenMenu(MenuType::INVENTORY);
for(int neighborInd:currentConnectionPoint->neighbors){ for(int neighborInd:currentConnectionPoint->neighbors){
if(neighborInd==-1)continue; if(neighborInd==-1)continue;
ConnectionPoint&neighbor=ConnectionPointFromIndex(neighborInd); ConnectionPoint&neighbor=ConnectionPointFromIndex(neighborInd);

@ -2,7 +2,7 @@
#define VERSION_MAJOR 0 #define VERSION_MAJOR 0
#define VERSION_MINOR 2 #define VERSION_MINOR 2
#define VERSION_PATCH 1 #define VERSION_PATCH 1
#define VERSION_BUILD 2536 #define VERSION_BUILD 2541
#define stringify(a) stringify_(a) #define stringify(a) stringify_(a)
#define stringify_(a) #a #define stringify_(a) #a

Loading…
Cancel
Save