Fix up all menu components to integrate with new view port system.

pull/28/head
sigonasr2 1 year ago
parent 44fcbc80cd
commit 38729877b8
  1. 28
      Crawler/CharacterMenuWindow.cpp
  2. 1
      Crawler/EncountersSpawnListScrollableWindowComponent.h
  3. 2
      Crawler/InventoryConsumableWindow.cpp
  4. 2
      Crawler/MenuIconButton.h
  5. 2
      Crawler/MenuItemItemButton.h
  6. 11
      Crawler/PopupMenuLabel.h
  7. 10
      Crawler/ScrollableWindowComponent.h
  8. 2
      Crawler/Version.h
  9. BIN
      x64/Release/Crawler.exe

@ -53,12 +53,12 @@ INCLUDE_GFX
void Menu::InitializeCharacterMenuWindow(){ void Menu::InitializeCharacterMenuWindow(){
static bool equipmentWindowOpened=false; static bool equipmentWindowOpened=false;
vf2d windowSize=game->GetScreenSize()-vf2d{52,52}; vf2d windowSize=game->GetScreenSize()-vf2d{52,0};
Menu*characterMenuWindow=CreateMenu(CHARACTER_MENU,CENTERED,windowSize); Menu*characterMenuWindow=CreateMenu(CHARACTER_MENU,CENTERED,windowSize);
characterMenuWindow->ADD("Character Label",MenuLabel)({{0,-4},{float(windowSize.x)-1,24}},"Character",2,ComponentAttr::SHADOW|ComponentAttr::OUTLINE|ComponentAttr::BACKGROUND)END; characterMenuWindow->ADD("Character Label",MenuLabel)({{0,2},{float(windowSize.x)-1,24}},"Character",2,ComponentAttr::SHADOW|ComponentAttr::OUTLINE|ComponentAttr::BACKGROUND)END;
characterMenuWindow->ADD("Equip Slot Outline",MenuComponent)({{0,28},{120,windowSize.y-37}},"",DO_NOTHING,ButtonAttr::UNSELECTABLE)END; characterMenuWindow->ADD("Equip Slot Outline",MenuComponent)({{0,28},{120,windowSize.y-48}},"",DO_NOTHING,ButtonAttr::UNSELECTABLE)END;
characterMenuWindow->ADD("Character Rotating Display",CharacterRotatingDisplay)({{135,28},{90,windowSize.y-37}},GFX[classutils::GetClassInfo(game->GetPlayer()->GetClassName()).classFullImgName].Decal())END; characterMenuWindow->ADD("Character Rotating Display",CharacterRotatingDisplay)({{135,28},{90,windowSize.y-48}},GFX[classutils::GetClassInfo(game->GetPlayer()->GetClassName()).classFullImgName].Decal())END;
const static std::array<ItemAttribute,7>displayAttrs{ const static std::array<ItemAttribute,7>displayAttrs{
ItemAttribute::health, ItemAttribute::health,
@ -71,13 +71,13 @@ void Menu::InitializeCharacterMenuWindow(){
}; };
characterMenuWindow->ADD("Equip Selection Outline",MenuComponent)({{123,28},{120,windowSize.y-37}},"",DO_NOTHING,ButtonAttr::UNSELECTABLE)END characterMenuWindow->ADD("Equip Selection Outline",MenuComponent)({{123,28},{120,windowSize.y-48}},"",DO_NOTHING,ButtonAttr::UNSELECTABLE)END
->Enable(false); ->Enable(false);
characterMenuWindow->ADD("Equip List",ScrollableWindowComponent)({{123,28},{120,windowSize.y-37-24}})DEPTH -1 END characterMenuWindow->ADD("Equip List",ScrollableWindowComponent)({{123,28},{120,windowSize.y-48-24}})DEPTH -1 END
->Enable(false); ->Enable(false);
characterMenuWindow->ADD("Equip Selection Bottom Outline",MenuComponent)({{123,28+(windowSize.y-37-24)},{120,24}},"",DO_NOTHING,ButtonAttr::UNSELECTABLE)END characterMenuWindow->ADD("Equip Selection Bottom Outline",MenuComponent)({{123,28+(windowSize.y-48-24)},{120,24}},"",DO_NOTHING,ButtonAttr::UNSELECTABLE)END
->Enable(false); ->Enable(false);
auto equipSelectionSelectButton=characterMenuWindow->ADD("Equip Selection Select Button",MenuComponent)({{123+12,28+(windowSize.y-37-24)+6},{96,12}},"Select", auto equipSelectionSelectButton=characterMenuWindow->ADD("Equip Selection Select Button",MenuComponent)({{123+12,28+(windowSize.y-48-24)+6},{96,12}},"Select",
[](MenuFuncData data){ [](MenuFuncData data){
Component<MenuComponent>(data.component->parentMenu,"Equip Selection Outline")->Enable(false); Component<MenuComponent>(data.component->parentMenu,"Equip Selection Outline")->Enable(false);
Component<ScrollableWindowComponent>(data.component->parentMenu,"Equip List")->Enable(false); Component<ScrollableWindowComponent>(data.component->parentMenu,"Equip List")->Enable(false);
@ -218,7 +218,7 @@ void Menu::InitializeCharacterMenuWindow(){
Menu::AddEquipStatListener(equipmentSlot); Menu::AddEquipStatListener(equipmentSlot);
} }
characterMenuWindow->ADD("Stat Display Outline",MenuComponent)({{245,28},{62,windowSize.y-37}},"",DO_NOTHING,ButtonAttr::UNSELECTABLE)END; characterMenuWindow->ADD("Stat Display Outline",MenuComponent)({{245,28},{62,windowSize.y-48}},"",DO_NOTHING,ButtonAttr::UNSELECTABLE)END;
int yOffset=0; int yOffset=0;
for(ItemAttribute attribute:displayAttrs){ for(ItemAttribute attribute:displayAttrs){
@ -229,13 +229,15 @@ void Menu::InitializeCharacterMenuWindow(){
yOffset+=20; yOffset+=20;
} }
characterMenuWindow->ADD("Back button",MenuComponent)({{windowSize.x/2-64,windowSize.y},{128,12}},"Back",[](MenuFuncData data){Menu::stack.pop_back();return true;})END; characterMenuWindow->ADD("Back button",MenuComponent)({{windowSize.x/2-64,windowSize.y-16},{128,12}},"Back",[](MenuFuncData data){Menu::stack.pop_back();return true;})END;
auto itemNameDisplay=characterMenuWindow->ADD("Item Name",MenuLabel)({{0,28},{120,12}},"",1,ComponentAttr::BACKGROUND|ComponentAttr::LEFT_ALIGN|ComponentAttr::OUTLINE|ComponentAttr::SHADOW)END; auto itemNameDisplay=characterMenuWindow->ADD("Item Name",MenuLabel)({{0,28},{120,12}},"",1,ComponentAttr::BACKGROUND|ComponentAttr::LEFT_ALIGN|ComponentAttr::OUTLINE|ComponentAttr::SHADOW)END;
auto itemDescriptionDisplay=characterMenuWindow->ADD("Item Description",MenuLabel)({{0,40},{120,windowSize.y-49}},"",1,ComponentAttr::BACKGROUND|ComponentAttr::LEFT_ALIGN|ComponentAttr::OUTLINE|ComponentAttr::SHADOW)END; auto itemDescriptionDisplay=characterMenuWindow->ADD("Item Description",MenuLabel)({{0,40},{120,windowSize.y-60}},"",1,ComponentAttr::BACKGROUND|ComponentAttr::LEFT_ALIGN|ComponentAttr::OUTLINE|ComponentAttr::SHADOW)END;
characterMenuWindow->ADD("Item Equip Name",MenuLabel)({{123,28},{120,12}},"",1,ComponentAttr::BACKGROUND|ComponentAttr::LEFT_ALIGN|ComponentAttr::OUTLINE|ComponentAttr::SHADOW)END; auto itemEquipNameDisplay=characterMenuWindow->ADD("Item Equip Name",MenuLabel)({{123,28},{120,12}},"",1,ComponentAttr::BACKGROUND|ComponentAttr::LEFT_ALIGN|ComponentAttr::OUTLINE|ComponentAttr::SHADOW)END;
characterMenuWindow->ADD("Item Equip Description",MenuLabel)({{123,40},{120,windowSize.y-49}},"",1,ComponentAttr::BACKGROUND|ComponentAttr::LEFT_ALIGN|ComponentAttr::OUTLINE|ComponentAttr::SHADOW)END; auto itemEquipDescriptionDisplay=characterMenuWindow->ADD("Item Equip Description",MenuLabel)({{123,40},{120,windowSize.y-60}},"",1,ComponentAttr::BACKGROUND|ComponentAttr::LEFT_ALIGN|ComponentAttr::OUTLINE|ComponentAttr::SHADOW)END;
itemNameDisplay->Enable(false); itemNameDisplay->Enable(false);
itemDescriptionDisplay->Enable(false); itemDescriptionDisplay->Enable(false);
itemEquipNameDisplay->Enable(false);
itemEquipDescriptionDisplay->Enable(false);
} }

@ -61,7 +61,6 @@ public:
} }
return false;}); return false;});
int offsetY=0; int offsetY=0;
vf2d parentPos=Menu::menus.at(OVERWORLD_LEVEL_SELECT)->pos;
vf2d parentSize=Menu::menus.at(OVERWORLD_LEVEL_SELECT)->size; vf2d parentSize=Menu::menus.at(OVERWORLD_LEVEL_SELECT)->size;
for(int spawn:spawns){ for(int spawn:spawns){
ADD("Spawn "+std::to_string(spawn),SpawnEncounterLabel)({vf2d{0,float(offsetY)},{parentSize.x,12}},MONSTER_DATA.at(spawn-1).GetDisplayName(),spawn-1)END; ADD("Spawn "+std::to_string(spawn),SpawnEncounterLabel)({vf2d{0,float(offsetY)},{parentSize.x,12}},MONSTER_DATA.at(spawn-1).GetDisplayName(),spawn-1)END;

@ -49,7 +49,7 @@ void Menu::InitializeConsumableInventoryWindow(){
int itemSpacing=24; int itemSpacing=24;
int totalSpacing=32; int totalSpacing=32;
vf2d windowSize={float(160+16),float(96+64)}; //Need space for the button. vf2d windowSize={float(160+16),float(96+78)}; //Need space for the button.
Menu*inventoryWindow=CreateMenu(INVENTORY_CONSUMABLES,CENTERED,windowSize); Menu*inventoryWindow=CreateMenu(INVENTORY_CONSUMABLES,CENTERED,windowSize);

@ -63,7 +63,7 @@ protected:
MenuComponent::DrawDecal(window,parentPos,focused); MenuComponent::DrawDecal(window,parentPos,focused);
if(icon!=nullptr){ if(icon!=nullptr){
vf2d iconScale=rect.size/24.f; vf2d iconScale=rect.size/24.f;
window.DrawDecal(Menu::menus[parentMenu]->pos+parentPos+rect.middle()-icon->sprite->Size()*iconScale/2,icon,iconScale); window.DrawDecal(parentPos+rect.middle()-icon->sprite->Size()*iconScale/2,icon,iconScale);
} }
} }
}; };

@ -137,7 +137,7 @@ protected:
std::string quantityText="x"+std::to_string(itemRef.get().Amt()); std::string quantityText="x"+std::to_string(itemRef.get().Amt());
vf2d quantityTextScale=rect.size/48.f; vf2d quantityTextScale=rect.size/48.f;
vf2d textSize=vf2d(game->GetTextSizeProp(quantityText))*quantityTextScale; vf2d textSize=vf2d(game->GetTextSizeProp(quantityText))*quantityTextScale;
vf2d drawPos=Menu::menus[parentMenu]->pos+parentPos+rect.pos+rect.size-textSize; vf2d drawPos=parentPos+rect.pos+rect.size-textSize;
geom2d::rect<float>boundingBox={drawPos,textSize}; geom2d::rect<float>boundingBox={drawPos,textSize};
window.DrawShadowStringDecal(drawPos,quantityText,WHITE,BLACK,quantityTextScale,quantityTextScale.x); window.DrawShadowStringDecal(drawPos,quantityText,WHITE,BLACK,quantityTextScale,quantityTextScale.x);
} }

@ -59,20 +59,19 @@ protected:
} }
virtual void inline DrawDecal(ViewPort&window,vf2d parentPos,bool focused)override{ virtual void inline DrawDecal(ViewPort&window,vf2d parentPos,bool focused)override{
if(label.length()>0){ if(label.length()>0){
MenuLabel::DrawDecal(window,parentPos,focused);
std::string wrappedText=util::WrapText(game,label,int(rect.size.x-1),true,scale); std::string wrappedText=util::WrapText(game,label,int(rect.size.x-1),true,scale);
vf2d drawPos=Menu::menus.at(parentMenu)->pos+parentPos+rect.middle()-vf2d{game->GetTextSizeProp(wrappedText)}*scale/2; //Assume centered. vf2d drawPos=parentPos+rect.middle()-vf2d{game->GetTextSizeProp(wrappedText)}*scale/2; //Assume centered.
if(!centered){ if(!centered){
drawPos=Menu::menus.at(parentMenu)->pos+vf2d{rect.pos.x+2,rect.middle().y-game->GetTextSizeProp(wrappedText).y/2}+parentPos; //We should at least vertically align here. drawPos=vf2d{rect.pos.x+2,rect.middle().y-game->GetTextSizeProp(wrappedText).y/2}+parentPos; //We should at least vertically align here.
} }
if(background){ if(background){
window.FillRectDecal(Menu::menus.at(parentMenu)->pos+rect.pos+parentPos,rect.size,PixelLerp(Menu::themes[Menu::themeSelection].GetButtonCol(),Menu::themes[Menu::themeSelection].GetHighlightCol(),hoverEffect/"ThemeGlobal.HighlightTime"_F)); window.FillRectDecal(rect.pos+parentPos,rect.size,PixelLerp(Menu::themes[Menu::themeSelection].GetButtonCol(),Menu::themes[Menu::themeSelection].GetHighlightCol(),hoverEffect/"ThemeGlobal.HighlightTime"_F));
} }
if(border){ if(border){
window.DrawRectDecal(Menu::menus.at(parentMenu)->pos+rect.pos+parentPos,rect.size); window.DrawRectDecal(rect.pos+parentPos,rect.size);
} }
if(showDefaultLabel){ if(showDefaultLabel){
window.DrawStringPropDecal(Menu::menus.at(parentMenu)->pos+rect.pos+parentPos+rect.size/2-game->GetTextSizeProp(label)/2,label); window.DrawStringPropDecal(rect.pos+parentPos+rect.size/2-game->GetTextSizeProp(label)/2,label);
} }
if(shadow){ if(shadow){
window.DrawShadowStringPropDecal(drawPos,wrappedText,WHITE,BLACK,scale); window.DrawShadowStringPropDecal(drawPos,wrappedText,WHITE,BLACK,scale);

@ -63,7 +63,6 @@ public:
:MenuComponent(rect,"",[](MenuFuncData data){return true;},ButtonAttr::UNSELECTABLE|ButtonAttr::UNSELECTABLE_VIA_KEYBOARD){ :MenuComponent(rect,"",[](MenuFuncData data){return true;},ButtonAttr::UNSELECTABLE|ButtonAttr::UNSELECTABLE_VIA_KEYBOARD){
background=attributes&ComponentAttr::BACKGROUND; background=attributes&ComponentAttr::BACKGROUND;
border=attributes&ComponentAttr::OUTLINE; border=attributes&ComponentAttr::OUTLINE;
subWindow=ViewPort::rectViewPort({},rect.size,rect.pos);
} }
virtual inline void RemoveAllComponents(){ virtual inline void RemoveAllComponents(){
while(components.size()>0){ while(components.size()>0){
@ -99,6 +98,9 @@ protected:
//Let's use the internal name of this component to add unique names for sub-components. //Let's use the internal name of this component to add unique names for sub-components.
upButton=Menu::menus[parentMenu]->ADD(name+vf2d(rect.pos+vf2d{rect.size.x-12,0}).str()+"_"+vf2d(12,12).str(),MenuComponent)({rect.pos+vf2d{rect.size.x-12,0},{12,12}},"^",[&](MenuFuncData dat){V(A::SCROLL_OFFSET).y+="ThemeGlobal.MenuButtonScrollSpeed"_I;return true;},ButtonAttr::UNSELECTABLE_VIA_KEYBOARD)DEPTH -1 END; upButton=Menu::menus[parentMenu]->ADD(name+vf2d(rect.pos+vf2d{rect.size.x-12,0}).str()+"_"+vf2d(12,12).str(),MenuComponent)({rect.pos+vf2d{rect.size.x-12,0},{12,12}},"^",[&](MenuFuncData dat){V(A::SCROLL_OFFSET).y+="ThemeGlobal.MenuButtonScrollSpeed"_I;return true;},ButtonAttr::UNSELECTABLE_VIA_KEYBOARD)DEPTH -1 END;
downButton=Menu::menus[parentMenu]->ADD(name+vf2d(rect.pos+rect.size-vf2d{12,12}).str()+"_"+vf2d(12,12).str(),MenuComponent)({rect.pos+rect.size-vf2d{12,12},{12,12}},"v",[&](MenuFuncData dat){V(A::SCROLL_OFFSET).y-="ThemeGlobal.MenuButtonScrollSpeed"_I;return true;},ButtonAttr::UNSELECTABLE_VIA_KEYBOARD)DEPTH -1 END; downButton=Menu::menus[parentMenu]->ADD(name+vf2d(rect.pos+rect.size-vf2d{12,12}).str()+"_"+vf2d(12,12).str(),MenuComponent)({rect.pos+rect.size-vf2d{12,12},{12,12}},"v",[&](MenuFuncData dat){V(A::SCROLL_OFFSET).y-="ThemeGlobal.MenuButtonScrollSpeed"_I;return true;},ButtonAttr::UNSELECTABLE_VIA_KEYBOARD)DEPTH -1 END;
subWindow=ViewPort::rectViewPort({},rect.size,Menu::menus[parentMenu]->pos+rect.pos);
if(upButton){upButton->Enable(!disabled);}
if(downButton){downButton->Enable(!disabled);}
} }
virtual inline void BeforeUpdate(Crawler*game)override{ virtual inline void BeforeUpdate(Crawler*game)override{
for(MenuComponent*component:components){ for(MenuComponent*component:components){
@ -181,12 +183,12 @@ protected:
virtual inline void DrawDecal(ViewPort&window,vf2d parentPos,bool focused)override{ virtual inline void DrawDecal(ViewPort&window,vf2d parentPos,bool focused)override{
MenuComponent::DrawDecal(window,parentPos,focused); MenuComponent::DrawDecal(window,parentPos,focused);
if(border){ if(border){
game->DrawRectDecal(rect.pos+Menu::menus[parentMenu]->pos,rect.size); window.DrawRectDecal(rect.pos,rect.size);
} }
for(MenuComponent*component:components){ for(MenuComponent*component:components){
component->_DrawDecal(subWindow,rect.pos+Menu::menus[parentMenu]->pos+V(A::SCROLL_OFFSET),focused); component->_DrawDecal(subWindow,V(A::SCROLL_OFFSET),focused);
} }
DrawScrollbar(window,Menu::menus[parentMenu]->pos,focused); DrawScrollbar(window,{},focused);
} }
virtual bool GetHoverState(Crawler*game,MenuComponent*child)override{ virtual bool GetHoverState(Crawler*game,MenuComponent*child)override{
return geom2d::overlaps(geom2d::rect<float>{Menu::menus[parentMenu]->pos+rect.pos+child->rect.pos+V(A::SCROLL_OFFSET),child->rect.size},game->GetMousePos()); return geom2d::overlaps(geom2d::rect<float>{Menu::menus[parentMenu]->pos+rect.pos+child->rect.pos+V(A::SCROLL_OFFSET),child->rect.size},game->GetMousePos());

@ -39,7 +39,7 @@ All rights reserved.
#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 3909 #define VERSION_BUILD 3937
#define stringify(a) stringify_(a) #define stringify(a) stringify_(a)
#define stringify_(a) #a #define stringify_(a) #a

Binary file not shown.
Loading…
Cancel
Save