diff --git a/Crawler/Crawler.cpp b/Crawler/Crawler.cpp index f6c92f4a..38666622 100644 --- a/Crawler/Crawler.cpp +++ b/Crawler/Crawler.cpp @@ -356,7 +356,7 @@ void Crawler::HandleUserInput(float fElapsedTime){ } if(GetKey(I).bPressed){ - Menu::OpenMenu(TEST); + Menu::OpenMenu(INVENTORY); } } diff --git a/Crawler/InventoryWindow.cpp b/Crawler/InventoryWindow.cpp index 91b6388c..6fbd174f 100644 --- a/Crawler/InventoryWindow.cpp +++ b/Crawler/InventoryWindow.cpp @@ -18,16 +18,18 @@ const Menu Menu::InitializeInventoryWindow(){ constexpr int buttonSize=24; constexpr int totalSpacing=buttonSize+itemSpacing; - Menu inventoryWindow(CENTERED,{totalSpacing*invWidth,totalSpacing*(invHeight+1)}); + Menu inventoryWindow(CENTERED,{totalSpacing*invWidth-itemSpacing,totalSpacing*(invHeight+1)-itemSpacing}); MenuFunc useItemFunc=[](MenuFuncData data){ - + MenuItemButton*button=(MenuItemButton*)data.component; + button->UseItem(); }; for(int y=0;yinv=sortedInv.at(category); auto index1=std::find(inv.begin(),inv.end(),it); auto index2=std::find(inv.begin(),inv.end(),it2); + int largestSlot=std::max(index1-inv.begin(),index2-inv.begin()); + if(inv.size()GetElapsedTime(); + if(draggingComponent!=nullptr&&(!MOUSE_NAVIGATION||game->GetMouse(Mouse::LEFT).bHeld)){ + buttonHoldTime+=game->GetElapsedTime(); + } HoverMenuSelect(game); diff --git a/Crawler/MenuComponent.h b/Crawler/MenuComponent.h index 9b6d00ea..2073f406 100644 --- a/Crawler/MenuComponent.h +++ b/Crawler/MenuComponent.h @@ -7,13 +7,13 @@ class MenuComponent{ MenuFunc onClick; bool hovered=false; bool selectable=true; - bool draggable=false; private: float hoverEffect=0; protected: geom2d::rectrect; std::string label; bool border=true; + bool draggable=false; public: MenuComponent(geom2d::rectrect,std::string label,MenuFunc onClick,bool selectable=true); MenuComponent(geom2d::rectrect,std::string label,MenuType menuDest,MenuFunc onClick,bool selectable=true); diff --git a/Crawler/MenuIconButton.h b/Crawler/MenuIconButton.h index bb844bc9..3d4db499 100644 --- a/Crawler/MenuIconButton.h +++ b/Crawler/MenuIconButton.h @@ -12,11 +12,13 @@ public: inline MenuIconButton(geom2d::rectrect,Decal*icon,MenuFunc onClick) :MenuComponent(rect,"",onClick),icon(icon){} protected: - virtual void inline Update(Crawler*game)override{ + virtual inline void Update(Crawler*game)override{ MenuComponent::Update(game); } - virtual void inline Draw(Crawler*game,vf2d parentPos,bool focused)override{ + virtual inline void Draw(Crawler*game,vf2d parentPos,bool focused)override{ MenuComponent::Draw(game,parentPos,focused); - game->DrawRotatedDecal(parentPos+rect.middle(),icon,0,icon->sprite->Size()/2,{1,1},focused?WHITE:WHITE*"ThemeGlobal.MenuUnfocusedColorMult"_F); + if(icon!=nullptr){ + game->DrawRotatedDecal(parentPos+rect.middle(),icon,0,icon->sprite->Size()/2,{1,1},focused?WHITE:WHITE*"ThemeGlobal.MenuUnfocusedColorMult"_F); + } } }; \ No newline at end of file diff --git a/Crawler/MenuItemButton.h b/Crawler/MenuItemButton.h index aa1d77de..848358b7 100644 --- a/Crawler/MenuItemButton.h +++ b/Crawler/MenuItemButton.h @@ -14,13 +14,21 @@ private: int inventoryIndex=0; public: inline MenuItemButton(geom2d::rectrect,std::vector&invRef,int invIndex,MenuFunc onClick) - :MenuIconButton(rect,ITEM_DATA.at(invRef[invIndex]).Decal(),onClick),invRef(invRef),inventoryIndex(invIndex){} + :MenuIconButton(rect,invRef.size()>invIndex?ITEM_DATA.at(invRef[invIndex]).Decal():nullptr,onClick),invRef(invRef),inventoryIndex(invIndex){ + draggable=true; + } + inline Item GetItem(){ + return Inventory::GetItem(invRef.at(inventoryIndex)); + } + inline void UseItem(uint32_t amt=1){ + if(invRef.size()<=inventoryIndex)return; + return Inventory::UseItem(invRef.at(inventoryIndex),amt); + } protected: - virtual void inline Update(Crawler*game)override{ + virtual inline void Update(Crawler*game)override{ MenuIconButton::Update(game); } - virtual void inline Draw(Crawler*game,vf2d parentPos,bool focused)override{ + virtual inline void Draw(Crawler*game,vf2d parentPos,bool focused)override{ MenuIconButton::Draw(game,parentPos,focused); - game->DrawRotatedDecal(parentPos+rect.middle(),icon,0,icon->sprite->Size()/2,{1,1},focused?WHITE:WHITE*"ThemeGlobal.MenuUnfocusedColorMult"_F); } }; \ No newline at end of file diff --git a/Crawler/Version.h b/Crawler/Version.h index 51bed69b..ac8cfc06 100644 --- a/Crawler/Version.h +++ b/Crawler/Version.h @@ -2,7 +2,7 @@ #define VERSION_MAJOR 0 #define VERSION_MINOR 2 #define VERSION_PATCH 0 -#define VERSION_BUILD 1839 +#define VERSION_BUILD 1848 #define stringify(a) stringify_(a) #define stringify_(a) #a