From 4ac42fbd7e773222c2e0746aedaaed46873728f3 Mon Sep 17 00:00:00 2001 From: sigonasr2 Date: Sat, 9 Dec 2023 01:58:46 -0600 Subject: [PATCH] Implemented menucomponent depth property. Fixed equipment menu labels interacting with hover events. --- Crawler/CharacterMenuWindow.cpp | 13 +++++++--- Crawler/ClassSelectionWindow.cpp | 2 +- Crawler/EquipSlotButton.h | 4 +-- Crawler/Item.cpp | 10 +++++--- Crawler/Item.h | 4 +-- Crawler/ItemLoadoutWindow.cpp | 6 ++--- Crawler/Menu.cpp | 38 ++++++++++++++++------------- Crawler/Menu.h | 8 +++++- Crawler/MenuComponent.h | 1 + Crawler/MenuItemItemButton.h | 37 ++++++++++++++++++++++------ Crawler/ScrollableWindowComponent.h | 8 +++--- Crawler/Version.h | 2 +- 12 files changed, 89 insertions(+), 44 deletions(-) diff --git a/Crawler/CharacterMenuWindow.cpp b/Crawler/CharacterMenuWindow.cpp index 9ee3c75f..74bc510b 100644 --- a/Crawler/CharacterMenuWindow.cpp +++ b/Crawler/CharacterMenuWindow.cpp @@ -96,7 +96,7 @@ void Menu::InitializeCharacterMenuWindow(){ equipSelectionSelectButton->Enable(false); characterMenuWindow->AddComponent("Equip Selection Outline",equipSelectionOutline); - characterMenuWindow->AddComponent("Equip List",equipmentList); + characterMenuWindow->AddComponent("Equip List",equipmentList,-1); characterMenuWindow->AddComponent("Equip Selection Bottom Outline",equipSelectionBottomOutline); characterMenuWindow->AddComponent("Equip Selection Select Button",equipSelectionSelectButton); @@ -185,7 +185,7 @@ void Menu::InitializeCharacterMenuWindow(){ counter++; } return true; - }); + },"Item Name","Item Description"); equip->I(Attribute::EQUIP_TYPE)=int(slot); if(Inventory::GetEquip(slot)==&itemInvRef){ equip->SetSelected(true); @@ -200,7 +200,7 @@ void Menu::InitializeCharacterMenuWindow(){ Component(data.component->parentMenu,"Equip Selection Select Button")->Enable(true); Component(data.component->parentMenu,"Character Rotating Display")->Enable(false); return true; - },DO_NOTHING,DO_NOTHING); + },DO_NOTHING,DO_NOTHING,"Item Name","Item Description"); PopupMenuLabel*equipmentLabel=NEW PopupMenuLabel(CHARACTER_MENU,{{labelX,labelY},{29,16}},slotNames[i],{0.5,1},ComponentAttr::SHADOW); equipmentSlot->I(Attribute::EQUIP_TYPE)=int(slot); equipmentSlot->I(Attribute::INDEXED_THEME)=i; @@ -228,4 +228,11 @@ void Menu::InitializeCharacterMenuWindow(){ MenuComponent*backButton=NEW MenuComponent(CHARACTER_MENU,{{windowSize.x/2-64,windowSize.y},{128,12}},"Back",[](MenuFuncData data){Menu::stack.pop_back();return true;}); backButton->decal=true; characterMenuWindow->AddComponent("Back button",backButton); + + MenuLabel*itemNameDisplay=NEW MenuLabel(CHARACTER_MENU,{{32,windowSize.y-32},{windowSize.x-64,12}},"",1,ComponentAttr::BACKGROUND|ComponentAttr::LEFT_ALIGN|ComponentAttr::OUTLINE|ComponentAttr::SHADOW); + itemNameDisplay->decal=true; + MenuLabel*itemDescriptionDisplay=NEW MenuLabel(CHARACTER_MENU,{{32,windowSize.y-20},{windowSize.x-64,32}},"",1,ComponentAttr::BACKGROUND|ComponentAttr::LEFT_ALIGN|ComponentAttr::OUTLINE|ComponentAttr::SHADOW); + itemDescriptionDisplay->decal=true; + characterMenuWindow->AddComponent("Item Name",itemNameDisplay); + characterMenuWindow->AddComponent("Item Description",itemDescriptionDisplay); } \ No newline at end of file diff --git a/Crawler/ClassSelectionWindow.cpp b/Crawler/ClassSelectionWindow.cpp index 4d750d09..2d112408 100644 --- a/Crawler/ClassSelectionWindow.cpp +++ b/Crawler/ClassSelectionWindow.cpp @@ -127,8 +127,8 @@ void Menu::InitializeClassSelectionWindow(){ return true; }); classSprite->S(A::CLASS_SELECTION)=classButton->S(A::CLASS_SELECTION)=className; - classSelectionWindow->AddComponent(className+" Button",classButton); classSelectionWindow->AddComponent(className+" Background",backgroundOutline); + classSelectionWindow->AddComponent(className+" Button",classButton); classSelectionWindow->AddComponent(className+" Label",classLabel); classSelectionWindow->AddComponent(className+" Icon",classSprite); } diff --git a/Crawler/EquipSlotButton.h b/Crawler/EquipSlotButton.h index 8ac1f3cd..d9a66f0a 100644 --- a/Crawler/EquipSlotButton.h +++ b/Crawler/EquipSlotButton.h @@ -47,8 +47,8 @@ class EquipSlotButton:public MenuItemItemButton{ private: EquipSlot slot; public: - inline EquipSlotButton(MenuType parent,geom2d::rectrect,EquipSlot slot,MenuType menuDest,MenuFunc onClick,MenuFunc onHover,MenuFunc onMouseOut) - :MenuItemItemButton(parent,rect,Item::BLANK,menuDest,onClick,onHover,onMouseOut),slot(slot){} + inline EquipSlotButton(MenuType parent,geom2d::rectrect,EquipSlot slot,MenuType menuDest,MenuFunc onClick,MenuFunc onHover,MenuFunc onMouseOut,std::string itemNameLabelName="",std::string itemDescriptionLabelName="") + :MenuItemItemButton(parent,rect,Item::BLANK,menuDest,onClick,onHover,onMouseOut,itemNameLabelName,itemDescriptionLabelName),slot(slot){} inline void OnEquipStatsUpdate()override{ Item&equip=*Inventory::GetEquip(slot); if(!equip.IsBlank()){ diff --git a/Crawler/Item.cpp b/Crawler/Item.cpp index cb736e5f..f0e0a7a2 100644 --- a/Crawler/Item.cpp +++ b/Crawler/Item.cpp @@ -177,7 +177,7 @@ void ItemInfo::InitializeItems(){ props.customProps=&data[key]; } it.useFunc=scriptName; - } + } }; ReadItems(DATA["ItemDatabase"]); @@ -187,6 +187,10 @@ void ItemInfo::InitializeItems(){ ITEM_CATEGORIES.SetInitialized(); Menu::inventoryListeners.SetInitialized(); + for(auto&[name,info]:ITEM_DATA){ + if(info.description.length()==0)ERR("WARNING! Item "<ItemInfo::ItemSet()const{ +const std::optionalItemInfo::ItemSet()const{ if(ItemSet::sets.count(set)){ return &ItemSet::sets[set]; } @@ -565,6 +569,6 @@ const size_t EnhancementInfo::size()const{ return enhancementStats.size(); }; -const std::optionalItem::ItemSet()const{ +const const const std::optionalItem::ItemSet()const const const{ //I was bored, okay? return it->ItemSet(); }; \ No newline at end of file diff --git a/Crawler/Item.h b/Crawler/Item.h index 794f4098..9a92f7ad 100644 --- a/Crawler/Item.h +++ b/Crawler/Item.h @@ -133,7 +133,7 @@ public: bool IsBlank(); static Item BLANK; bool operator==(const Item&rhs)const; - const std::optionalItemSet()const; + const std::optionalItemSet()const; }; class Inventory{ @@ -219,7 +219,7 @@ public: float CastTime(); float CooldownTime(); EquipSlot Slot(); - const std::optionalItemSet()const; + const std::optionalItemSet()const; }; class ItemOverlay{ diff --git a/Crawler/ItemLoadoutWindow.cpp b/Crawler/ItemLoadoutWindow.cpp index 1290ec3a..d33fda85 100644 --- a/Crawler/ItemLoadoutWindow.cpp +++ b/Crawler/ItemLoadoutWindow.cpp @@ -57,9 +57,9 @@ void Menu::InitializeItemLoadoutWindow(){ float buttonBorderPadding=64; - MenuItemItemButton*loadoutItem1=NEW MenuItemItemButton(ITEM_LOADOUT,{{64,96},{48,48}},game->GetLoadoutItem(0),INVENTORY,[](MenuFuncData data){Menu::menus.at(INVENTORY)->I(A::LOADOUT_SLOT)=0; return true;},ITEM_LOADOUT,"Item Name Label","Item Description"); - MenuItemItemButton*loadoutItem2=NEW MenuItemItemButton(ITEM_LOADOUT,{{itemLoadoutWindowWidth/2-24,96},{48,48}},game->GetLoadoutItem(1),INVENTORY,[](MenuFuncData data){Menu::menus.at(INVENTORY)->I(A::LOADOUT_SLOT)=1;return true;},ITEM_LOADOUT,"Item Name Label","Item Description"); - MenuItemItemButton*loadoutItem3=NEW MenuItemItemButton(ITEM_LOADOUT,{{itemLoadoutWindowWidth-48-64,96},{48,48}},game->GetLoadoutItem(2),INVENTORY,[](MenuFuncData data){Menu::menus.at(INVENTORY)->I(A::LOADOUT_SLOT)=2;return true;},ITEM_LOADOUT,"Item Name Label","Item Description"); + MenuItemItemButton*loadoutItem1=NEW MenuItemItemButton(ITEM_LOADOUT,{{64,96},{48,48}},game->GetLoadoutItem(0),INVENTORY,[](MenuFuncData data){Menu::menus.at(INVENTORY)->I(A::LOADOUT_SLOT)=0; return true;},"Item Name Label","Item Description"); + MenuItemItemButton*loadoutItem2=NEW MenuItemItemButton(ITEM_LOADOUT,{{itemLoadoutWindowWidth/2-24,96},{48,48}},game->GetLoadoutItem(1),INVENTORY,[](MenuFuncData data){Menu::menus.at(INVENTORY)->I(A::LOADOUT_SLOT)=1;return true;},"Item Name Label","Item Description"); + MenuItemItemButton*loadoutItem3=NEW MenuItemItemButton(ITEM_LOADOUT,{{itemLoadoutWindowWidth-48-64,96},{48,48}},game->GetLoadoutItem(2),INVENTORY,[](MenuFuncData data){Menu::menus.at(INVENTORY)->I(A::LOADOUT_SLOT)=2;return true;},"Item Name Label","Item Description"); //TODO: Make these two do something. MenuLabel*itemNameLabel=NEW MenuLabel(ITEM_LOADOUT,{{0,158},{itemLoadoutWindowWidth,12}},"",1,ComponentAttr::SHADOW); diff --git a/Crawler/Menu.cpp b/Crawler/Menu.cpp index 97b07219..225616ed 100644 --- a/Crawler/Menu.cpp +++ b/Crawler/Menu.cpp @@ -132,7 +132,12 @@ Menu*Menu::CreateMenu(MenuType type,vf2d pos,vf2d size){ return menus.at(type); } -void Menu::AddComponent(std::string key,MenuComponent*button){ +void Menu::AddComponent(std::string key,MenuComponent*button,int depth){ + if(depth==DEFAULT_DEPTH){ + button->depth=STARTING_DEPTH-componentCount; + }else{ + button->depth=depth; + } if(button->selectable){ buttons.Unlock(); if(buttons.count(int(button->rect.pos.y))){ @@ -165,6 +170,9 @@ void Menu::AddComponent(std::string key,MenuComponent*button){ }else{ displayComponents.push_back(button); } + + RecalculateComponentCount(); + if(components.count(key)){ ERR("WARNING! Key "<GetPixelMode(); game->SetPixelMode(Pixel::MASK); game->Clear(BLANK); - for(auto&component:displayComponents){ + std::vectorallComponents; + std::copy(displayComponents.begin(),displayComponents.end(),std::back_inserter(allComponents)); + std::for_each(buttons.begin(),buttons.end(),[&](auto&pair){std::copy(pair.second.begin(),pair.second.end(),std::back_inserter(allComponents));}); + std::sort(allComponents.begin(),allComponents.end(),[](MenuComponent*c1,MenuComponent*c2){return c1->depth>c2->depth;}); + for(const auto&component:allComponents){ if(component->renderInMain){ component->_Draw(game); } } - for(auto&[key,value]:buttons){ - for(auto&button:value){ - if(button->renderInMain){ - button->_Draw(game); - } - } - } + game->SetPixelMode(prevMode); game->SetDrawTarget(nullptr); @@ -352,18 +358,11 @@ void Menu::Draw(Crawler*game){ r.Decal()->Update(); game->DrawDecal(pos,r.Decal()); - for(auto&component:displayComponents){ + for(const auto&component:allComponents){ if(component->renderInMain){ component->_DrawDecal(game,this==Menu::stack.back()); } } - for(auto&[key,value]:buttons){ - for(auto&button:value){ - if(button->renderInMain){ - button->_DrawDecal(game,this==Menu::stack.back()); - } - } - } if(draggingComponent!=nullptr){ game->SetDrawTarget(overlay.Sprite()); @@ -738,3 +737,8 @@ void Menu::DrawThemedWindow(vf2d menuPos,vf2d size,Pixel renderColor){ DrawTiledWindowBorder(game,menuPos,size,renderColor); } } + + +void Menu::RecalculateComponentCount(){ + componentCount=displayComponents.size()+buttons.size(); +} \ No newline at end of file diff --git a/Crawler/Menu.h b/Crawler/Menu.h index 0bc6934e..cf0a52c2 100644 --- a/Crawler/Menu.h +++ b/Crawler/Menu.h @@ -47,6 +47,9 @@ class Crawler; class MenuComponent; class ScrollableWindowComponent; +#define DEFAULT_DEPTH -999999 +#define STARTING_DEPTH 999999 + enum MenuType{ TEST, TEST_2, @@ -73,6 +76,7 @@ class Menu:public IAttributable{ float buttonHoldTime=0; vi2d selection={-1,-1}; vi2d lastActiveMousePos={}; + int componentCount; MenuComponent*draggingComponent=nullptr; Renderable r,overlay; @@ -82,7 +86,7 @@ public: //The constructor is private. Use CreateMenu() instead! Menu()=default; ~Menu(); - void AddComponent(std::string key,MenuComponent*button); + void AddComponent(std::string key,MenuComponent*button,int depth=DEFAULT_DEPTH); void Update(Crawler*game); void Draw(Crawler*game); static void InitializeMenus(); @@ -119,6 +123,7 @@ public: //X (0-2), Y (0-2) for specific 9-patch tile (tiled version). static Renderable&GetPatchPart(int x,int y); + void RecalculateComponentCount(); private: Menu(vf2d pos,vf2d size); static MenuType lastMenuTypeCreated; @@ -151,6 +156,7 @@ private: bool HandleOutsideDisabledButtonSelection(MenuComponent*disabledButton); Pixel GetRenderColor(); + static bool MOUSE_NAVIGATION; bool cover; //A black cover for when a menu pops up to fade out the stuff behind it. }; diff --git a/Crawler/MenuComponent.h b/Crawler/MenuComponent.h index b83f6c70..fee289dd 100644 --- a/Crawler/MenuComponent.h +++ b/Crawler/MenuComponent.h @@ -70,6 +70,7 @@ private: void _DrawDecal(Crawler*game,bool focused); void _DrawDecal(Crawler*game,vf2d parentPos,bool focused); protected: + int depth=0; float hoverEffect=0; std::string name=""; geom2d::rectrect; diff --git a/Crawler/MenuItemItemButton.h b/Crawler/MenuItemItemButton.h index f65afc0b..0aa05928 100644 --- a/Crawler/MenuItemItemButton.h +++ b/Crawler/MenuItemItemButton.h @@ -52,7 +52,6 @@ INCLUDE_ITEM_DATA class MenuItemItemButton:public MenuIconButton{ private: std::reference_wrapperitemRef; - MenuType itemDescriptionMenu; std::string itemNameLabelName; std::string itemDescriptionLabelName; bool runHoverFunctions=false; @@ -62,13 +61,13 @@ private: bool selected=false; bool hideQty=false; public: - inline MenuItemItemButton(MenuType parent,geom2d::rectrect,Item&itemRef,MenuType menuDest,MenuFunc onClick,MenuType itemDescriptionMenu,std::string itemNameLabelName,std::string itemDescriptionLabelName) - :MenuIconButton(parent,rect,(!itemRef.IsBlank())?itemRef.Decal():nullptr,menuDest,onClick),itemRef(itemRef),itemDescriptionMenu(itemDescriptionMenu),itemNameLabelName(itemNameLabelName),itemDescriptionLabelName(itemDescriptionLabelName),onHover(DO_NOTHING){ + inline MenuItemItemButton(MenuType parent,geom2d::rectrect,Item&itemRef,MenuType menuDest,MenuFunc onClick,std::string itemNameLabelName,std::string itemDescriptionLabelName) + :MenuIconButton(parent,rect,(!itemRef.IsBlank())?itemRef.Decal():nullptr,menuDest,onClick),itemRef(itemRef),itemNameLabelName(itemNameLabelName),itemDescriptionLabelName(itemDescriptionLabelName),onHover(DO_NOTHING){ draggable=false; valid=!itemRef.IsBlank(); } - inline MenuItemItemButton(MenuType parent,geom2d::rectrect,Item&itemRef,MenuType menuDest,MenuFunc onClick,MenuFunc onHover,MenuFunc onMouseOut) - :MenuIconButton(parent,rect,(!itemRef.IsBlank())?itemRef.Decal():nullptr,menuDest,onClick),itemRef(itemRef),itemDescriptionMenu(MenuType::ENUM_END),itemNameLabelName(""),itemDescriptionLabelName(""),onHover(onHover),onMouseOut(onMouseOut){ + inline MenuItemItemButton(MenuType parent,geom2d::rectrect,Item&itemRef,MenuType menuDest,MenuFunc onClick,MenuFunc onHover,MenuFunc onMouseOut,std::string itemNameLabelName="",std::string itemDescriptionLabelName="") + :MenuIconButton(parent,rect,(!itemRef.IsBlank())?itemRef.Decal():nullptr,menuDest,onClick),itemRef(itemRef),itemNameLabelName(itemNameLabelName),itemDescriptionLabelName(itemDescriptionLabelName),onHover(onHover),onMouseOut(onMouseOut){ runHoverFunctions=true; draggable=false; valid=!itemRef.IsBlank(); @@ -89,9 +88,23 @@ protected: virtual inline void BeforeUpdate(Crawler*game)override{ if(!hovered&&runHoverFunctions&&hoverState){ hoverState=false; + if(itemNameLabelName!=""){ + Component(parentMenu,itemNameLabelName)->Enable(false); + } + if(itemDescriptionLabelName!=""){ + Component(parentMenu,itemDescriptionLabelName)->Enable(false); + } onMouseOut(MenuFuncData{*Menu::menus[parentMenu],game,this,(ScrollableWindowComponent*)(parentComponent)}); } } + virtual inline void AfterCreate()override{ + if(itemNameLabelName!=""){ + Component(parentMenu,itemNameLabelName)->Enable(false); + } + if(itemDescriptionLabelName!=""){ + Component(parentMenu,itemDescriptionLabelName)->Enable(false); + } + } virtual inline void Update(Crawler*game)override{ MenuIconButton::Update(game); valid=!itemRef.get().IsBlank(); @@ -108,12 +121,20 @@ protected: } if(hovered){ - if(itemDescriptionMenu!=MenuType::ENUM_END){ - Component(itemDescriptionMenu,itemNameLabelName)->label=labelNameText; - Component(itemDescriptionMenu,itemDescriptionLabelName)->label=labelDescriptionText; + if(itemNameLabelName!=""){ + Component(parentMenu,itemNameLabelName)->label=labelNameText; + } + if(itemDescriptionLabelName!=""){ + Component(parentMenu,itemDescriptionLabelName)->label=labelDescriptionText; } if(runHoverFunctions&&!hoverState){ hoverState=true; + if(itemNameLabelName!=""&&labelNameText.length()>0){ + Component(parentMenu,itemNameLabelName)->Enable(true); + } + if(itemDescriptionLabelName!=""&&labelDescriptionText.length()>0){ + Component(parentMenu,itemDescriptionLabelName)->Enable(true); + } onHover(MenuFuncData{*Menu::menus[parentMenu],game,this,(ScrollableWindowComponent*)(parentComponent)}); } } diff --git a/Crawler/ScrollableWindowComponent.h b/Crawler/ScrollableWindowComponent.h index 22f51f74..c1c6a691 100644 --- a/Crawler/ScrollableWindowComponent.h +++ b/Crawler/ScrollableWindowComponent.h @@ -67,8 +67,8 @@ public: upButton=NEW MenuComponent(parentMenu,{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); downButton=NEW MenuComponent(parentMenu,{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); //Let's use the internal name of this component to add unique names for sub-components. - Menu::menus[parentMenu]->AddComponent(name+upButton->rect.pos.str()+"_"+upButton->rect.size.str(),upButton); - Menu::menus[parentMenu]->AddComponent(name+downButton->rect.pos.str()+"_"+downButton->rect.size.str(),downButton); + Menu::menus[parentMenu]->AddComponent(name+upButton->rect.pos.str()+"_"+upButton->rect.size.str(),upButton,-1); + Menu::menus[parentMenu]->AddComponent(name+downButton->rect.pos.str()+"_"+downButton->rect.size.str(),downButton,-1); } virtual inline void RemoveAllComponents(){ while(components.size()>0){ @@ -96,6 +96,7 @@ public: } Menu::menus[button->parentMenu]->components.erase(button->GetName()); components.erase(std::find(components.begin(),components.end(),button)); + Menu::menus[button->parentMenu]->RecalculateComponentCount(); delete button; } protected: @@ -148,7 +149,8 @@ protected: }else{ V(A::SCROLL_OFFSET).y=0; } - + + std::sort(components.begin(),components.end(),[](MenuComponent*c1,MenuComponent*c2){return c1->depth>c2->depth;}); for(MenuComponent*component:components){ component->disabled=!OnScreen(component); component->_Update(game); diff --git a/Crawler/Version.h b/Crawler/Version.h index a0e8b0ce..9ac8f76a 100644 --- a/Crawler/Version.h +++ b/Crawler/Version.h @@ -39,7 +39,7 @@ All rights reserved. #define VERSION_MAJOR 0 #define VERSION_MINOR 2 #define VERSION_PATCH 1 -#define VERSION_BUILD 3623 +#define VERSION_BUILD 3653 #define stringify(a) stringify_(a) #define stringify_(a) #a