diff --git a/Crawler/InventoryConsumableWindow.cpp b/Crawler/InventoryConsumableWindow.cpp index 9de6c427..66eba0d9 100644 --- a/Crawler/InventoryConsumableWindow.cpp +++ b/Crawler/InventoryConsumableWindow.cpp @@ -46,20 +46,16 @@ All rights reserved. using A=Attribute; void Menu::InitializeConsumableInventoryWindow(){ - int invWidth="ThemeGlobal.InventoryWidth"_I; - int initialInvHeight="ThemeGlobal.InventoryHeight"_I; + int itemSpacing=24; + int totalSpacing=32; - int itemSpacing="ThemeGlobal.InventoryItemSpacing"_I; - int buttonSize="ThemeGlobal.InventoryButtonSize"_I; - int totalSpacing=buttonSize+itemSpacing; - - vf2d windowSize={float(totalSpacing*invWidth-itemSpacing+2+24),float(totalSpacing*(3+1)-itemSpacing+64)}; //Need space for the button. + vf2d windowSize={float(160+16),float(96+64)}; //Need space for the button. Menu*inventoryWindow=CreateMenu(INVENTORY_CONSUMABLES,CENTERED,windowSize); inventoryWindow->I(A::LOADOUT_SLOT)=0; - inventoryWindow->ADD("inventory",InventoryScrollableWindowComponent)({{1,20},{windowSize.x,float(totalSpacing*3-itemSpacing)}},"Consumables","itemName","itemDescription", + inventoryWindow->ADD("inventory",InventoryScrollableWindowComponent)({{1,20},{windowSize.x,96.f}},"Consumables","itemName","itemDescription", [&](MenuFuncData data){ MenuItemButton*button=(MenuItemButton*)data.component; data.game->ClearLoadoutItem(data.menu.I(A::LOADOUT_SLOT)); @@ -84,9 +80,9 @@ void Menu::InitializeConsumableInventoryWindow(){ //We don't have to actually populate the inventory list because now when an item gets added, it will automatically add the correct component in for us. inventoryWindow->ADD("Inventory Type Label",MenuLabel)({{0,0},{windowSize.x-1,18}},"Consumables",2,ComponentAttr::SHADOW|ComponentAttr::BACKGROUND|ComponentAttr::OUTLINE)END; - inventoryWindow->ADD("itemName",MenuLabel)(geom2d::rect(vf2d{2,float(initialInvHeight*totalSpacing+itemSpacing-16)},{windowSize.x-4,windowSize.y-108}),"",1,ComponentAttr::SHADOW)END; - float itemDescriptionLabelY=float(initialInvHeight*totalSpacing+itemSpacing); - inventoryWindow->ADD("itemDescription",MenuLabel)(geom2d::rect(vf2d{2,itemDescriptionLabelY},{windowSize.x-4,windowSize.y-108}),"",1,ComponentAttr::SHADOW)END; + inventoryWindow->ADD("itemName",MenuLabel)(geom2d::rect(vf2d{2,100.f},{windowSize.x-4,windowSize.y-108}),"",1,ComponentAttr::SHADOW)END; + inventoryWindow->ADD("itemDescription",MenuLabel)(geom2d::rect(vf2d{2,112.f},{windowSize.x-4,windowSize.y-108}),"",1,ComponentAttr::SHADOW)END; - inventoryWindow->ADD("OK Button",MenuComponent)({{windowSize.x/2-24,itemDescriptionLabelY+56},{48,12}},"Ok",[](MenuFuncData data){Menu::CloseMenu();return true;})END; + auto okButton=inventoryWindow->ADD("OK Button",MenuComponent)({{windowSize.x/2-24,158.f},{48,12}},"Ok",[](MenuFuncData data){Menu::CloseMenu();return true;})END; + okButton->decal=true; } \ No newline at end of file diff --git a/Crawler/InventoryScrollableWindowComponent.h b/Crawler/InventoryScrollableWindowComponent.h index 446838d7..27ce779c 100644 --- a/Crawler/InventoryScrollableWindowComponent.h +++ b/Crawler/InventoryScrollableWindowComponent.h @@ -44,18 +44,24 @@ All rights reserved. using A=Attribute; +struct InventoryWindowOptions{ + int padding=8; + int size=24; +}; + class InventoryScrollableWindowComponent:public ScrollableWindowComponent{ private: std::string itemNameLabelName; std::string itemDescriptionLabelName; bool inventoryButtonsActive=true; std::functioninventoryButtonClickAction; + InventoryWindowOptions options; protected: ITCategory inventoryType; public: - inline InventoryScrollableWindowComponent(geom2d::rectrect,ITCategory invType,std::string itemNameLabelName,std::string itemDescriptionLabelName,std::functioninventoryButtonClickAction,bool inventoryButtonsActive=true,ComponentAttr attributes=ComponentAttr::BACKGROUND|ComponentAttr::OUTLINE) + inline InventoryScrollableWindowComponent(geom2d::rectrect,ITCategory invType,std::string itemNameLabelName,std::string itemDescriptionLabelName,std::functioninventoryButtonClickAction,InventoryWindowOptions options={.padding=8,.size=24},bool inventoryButtonsActive=true,ComponentAttr attributes=ComponentAttr::BACKGROUND|ComponentAttr::OUTLINE) :ScrollableWindowComponent(rect,attributes),inventoryType(invType),itemNameLabelName(itemNameLabelName),itemDescriptionLabelName(itemDescriptionLabelName), - inventoryButtonClickAction(inventoryButtonClickAction),inventoryButtonsActive(inventoryButtonsActive){ + options(options),inventoryButtonClickAction(inventoryButtonClickAction),inventoryButtonsActive(inventoryButtonsActive){ Menu::AddInventoryListener(this,invType); } virtual inline void Update(Crawler*game)override{ @@ -72,9 +78,6 @@ public: if(itemDescriptionLabelName.length()>0)Component(parentMenu,itemDescriptionLabelName)->SetLabel(""); } } - virtual inline void SetInventoryType(ITCategory inventoryType){ - this->inventoryType=inventoryType; - } protected: inline void RemoveEmptySlots(){ //Algorithm will iterate through all slots, finding blank slots. Each time a blank slot is found, all items will shift over by one, and then the last item will be removed. Repeat until all slots iterated through. @@ -100,13 +103,13 @@ protected: size_t invSize=Inventory::get(cat).size(); //We only want to refresh the inventory slots if the component count no longer matches what's actually in our inventory. if(components.size()GetScreenSize()-vi2d{52,52}); inventoryWindow->ADD("Inventory Label",MenuLabel)({{0,0},{inventoryWindow->size.x-1,24}},"Inventory",2,SHADOW|OUTLINE|BACKGROUND)END; @@ -61,11 +63,6 @@ void Menu::InitializeInventoryWindow(){ categories.push_back({category,DATA["ItemCategory"][category].GetInt(0)}); //We assume the first value becomes the sort order we wish to use. } std::sort(categories.begin(),categories.end(),[](std::pair&cat1,std::pair&cat2){return cat1.secondADD("Inventory Display",InventoryScrollableWindowComponent)({{72,28},{150,inventoryWindow->size.y-44}},categories[0].first,"","",DO_NOTHING)END; - #pragma endregion #pragma region Inventory Tabs bool first=true; @@ -76,15 +73,25 @@ void Menu::InitializeInventoryWindow(){ auto button=inventoryWindow->ADD(category+" Inventory Tab",MenuComponent)({{2,30+yOffset},{68,16}},category,MenuType::ENUM_END, [&](MenuFuncData data){ - Component(data.menu.GetType(),"Inventory Display")->SetInventoryType(data.component->S(A::CATEGORY_NAME)); + //Close the old inventory window and show the proper one. + Component(data.menu.GetType(),"Inventory Display - "+lastInventoryTypeOpened)->Enable(false); + Component(data.menu.GetType(),lastInventoryTypeOpened+" Inventory Tab")->SetSelected(false); + Component(data.menu.GetType(),"Inventory Display - "+data.component->S(A::CATEGORY_NAME))->Enable(true); + Component(data.menu.GetType(),data.component->S(A::CATEGORY_NAME)+" Inventory Tab")->SetSelected(true); + lastInventoryTypeOpened=data.component->S(A::CATEGORY_NAME); return true; },{textScaling,1.f})END; - + button->SetSelectionType(HIGHLIGHT); button->S(A::CATEGORY_NAME)=category; + auto inventoryDisplay=inventoryWindow->ADD("Inventory Display - "+category,InventoryScrollableWindowComponent)({{72,28},{150,inventoryWindow->size.y-44}},category,"","",DO_NOTHING)END; + if(first){ + lastInventoryTypeOpened=category; button->onClick(MenuFuncData{*inventoryWindow,game,button}); //Simulate a click of this button if it's the top one for an initial inventory display. } + + inventoryDisplay->Enable(first); yOffset+=20; first=false; diff --git a/Crawler/MenuComponent.cpp b/Crawler/MenuComponent.cpp index eb0de926..f49758d3 100644 --- a/Crawler/MenuComponent.cpp +++ b/Crawler/MenuComponent.cpp @@ -37,6 +37,8 @@ All rights reserved. #pragma endregion #include "Crawler.h" #include "MenuComponent.h" +#include "drawutil.h" +#include "util.h" using A=Attribute; @@ -95,12 +97,23 @@ void MenuComponent::Draw(Crawler*game,vf2d parentPos){ if(background){ game->FillRect(rect.pos+parentPos,rect.size,PixelLerp(Menu::themes[Menu::themeSelection].GetButtonCol(),Menu::themes[Menu::themeSelection].GetHighlightCol(),hoverEffect/"ThemeGlobal.HighlightTime"_F)); } + if(selected&&selectionType==HIGHLIGHT){ + game->FillRect(rect.pos+parentPos,rect.size,PixelLerp(Menu::themes[Menu::themeSelection].GetButtonCol(),Menu::themes[Menu::themeSelection].GetHighlightCol(),util::lerp(0.75f,1.0f,hoverEffect/"ThemeGlobal.HighlightTime"_F))); + } if(border){ game->DrawRect(rect.pos+parentPos,rect.size); } if(showDefaultLabel){ game->DrawStringProp(rect.pos+parentPos+rect.size/2-game->GetTextSizeProp(label)/2,label); } + if(selected){ + switch(selectionType){ + case CROSSHAIR:drawutil::DrawCrosshair(game,{parentPos+rect.pos,rect.size},0);break; + case INNER_BOX:game->DrawRect(rect.pos+parentPos+vi2d{1,1},rect.size-vi2d{2,2});break; + case HIGHLIGHT:break;//Not used. + default:ERR("Undefined selection type selected: "<FillRectDecal(rect.pos+parentPos,rect.size,PixelLerp(Menu::themes[Menu::themeSelection].GetButtonCol(),Menu::themes[Menu::themeSelection].GetHighlightCol(),hoverEffect/"ThemeGlobal.HighlightTime"_F)); } + if(selected&&selectionType==HIGHLIGHT){ + game->FillRectDecal(rect.pos+parentPos,rect.size,PixelLerp(Menu::themes[Menu::themeSelection].GetButtonCol(),Menu::themes[Menu::themeSelection].GetHighlightCol(),util::lerp(0.75f,1.0f,hoverEffect/"ThemeGlobal.HighlightTime"_F))); + } if(border){ game->FillRectDecal(rect.pos+parentPos,{rect.size.x,1}); game->FillRectDecal(rect.pos+parentPos,{1,rect.size.y}); @@ -131,6 +147,14 @@ void MenuComponent::DrawDecal(Crawler*game,vf2d parentPos,bool focused){ if(showDefaultLabel){ game->DrawStringPropDecal(rect.pos+parentPos+rect.size/2-vf2d(game->GetTextSizeProp(label))/2.f*labelScaling,label,WHITE,labelScaling); } + if(selected){ + switch(selectionType){ + case CROSSHAIR:drawutil::DrawCrosshairDecal(game,{parentPos+rect.pos,rect.size},0);break; + case INNER_BOX:game->DrawRectDecal(rect.pos+parentPos+vi2d{1,1},rect.size-vi2d{2,2});break; + case HIGHLIGHT:break;//Not used. + default:ERR("Undefined selection type selected: "<selected=selected; +} + +void MenuComponent::SetSelectionType(SelectionType selectionType){ + this->selectionType=selectionType; } \ No newline at end of file diff --git a/Crawler/MenuComponent.h b/Crawler/MenuComponent.h index 499e124f..aa79f0c9 100644 --- a/Crawler/MenuComponent.h +++ b/Crawler/MenuComponent.h @@ -53,6 +53,14 @@ enum class ComponentAttr{ BACKGROUND=0b1000, //Renders the background of the menu theme for this component. }; +enum class SelectionType{ + CROSSHAIR, + HIGHLIGHT, + INNER_BOX, +}; + +using enum SelectionType; + class MenuComponent:public IAttributable{ friend class Menu; friend class MenuItemButton; @@ -69,6 +77,8 @@ private: void _Draw(Crawler*game,vf2d parentPos); void _DrawDecal(Crawler*game,bool focused); void _DrawDecal(Crawler*game,vf2d parentPos,bool focused); + bool selected=false; + SelectionType selectionType=CROSSHAIR; protected: int depth=0; float hoverEffect=0; @@ -116,6 +126,8 @@ public: virtual void OnEquipStatsUpdate(); std::string GetLabel(); std::string GetName(); + virtual void SetSelected(bool selected)final; + virtual void SetSelectionType(SelectionType selectionType)final; virtual void Enable(bool enabled); virtual void Cleanup(); }; \ No newline at end of file diff --git a/Crawler/MenuItemItemButton.h b/Crawler/MenuItemItemButton.h index ca435e43..8d41eb92 100644 --- a/Crawler/MenuItemItemButton.h +++ b/Crawler/MenuItemItemButton.h @@ -44,7 +44,6 @@ All rights reserved. #include "Item.h" #include "safemap.h" #include "olcPGEX_Graphics2D.h" -#include "drawutil.h" INCLUDE_game INCLUDE_ITEM_DATA @@ -58,7 +57,6 @@ private: MenuFunc onHover; MenuFunc onMouseOut; bool hoverState=false; - bool selected=false; bool hideQty=false; CompactText compact=COMPACT; public: @@ -79,9 +77,6 @@ public: inline Item&SetItem(Item&newItem){ return itemRef=std::reference_wrapper(newItem); } - inline void SetSelected(bool selected){ - this->selected=selected; - } inline void SetShowQuantity(bool show){ this->hideQty=!show; } @@ -146,9 +141,6 @@ protected: } virtual inline void Draw(Crawler*game,vf2d parentPos)override{ MenuIconButton::Draw(game,parentPos); - if(selected){ - drawutil::DrawCrosshair(game,{parentPos+rect.pos,rect.size},0); - } } virtual inline void DrawDecal(Crawler*game,vf2d parentPos,bool focused)override{ MenuIconButton::DrawDecal(game,parentPos,focused); diff --git a/Crawler/Version.h b/Crawler/Version.h index 06e386e9..1bf2685d 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 3744 +#define VERSION_BUILD 3761 #define stringify(a) stringify_(a) #define stringify_(a) #a diff --git a/Crawler/assets/config/gfx/themes.txt b/Crawler/assets/config/gfx/themes.txt index 26598738..59cc4d9e 100644 --- a/Crawler/assets/config/gfx/themes.txt +++ b/Crawler/assets/config/gfx/themes.txt @@ -13,15 +13,6 @@ ThemeGlobal # How far the mouse has to move before mouse mode becomes active from keyboard/controller input mode. MouseActivationDistance = 8 - - # How many slots wide the inventory list is. - InventoryWidth = 5 - # How tall the view is for the inventory window (before scrolling) - InventoryHeight = 3 - # Space between each item slot. - InventoryItemSpacing = 8 - # Size of each button. - InventoryButtonSize = 24 } Themes