diff --git a/Adventures in Lestoria/InventoryConsumableWindow.cpp b/Adventures in Lestoria/InventoryConsumableWindow.cpp index fd916e38..462cda9e 100644 --- a/Adventures in Lestoria/InventoryConsumableWindow.cpp +++ b/Adventures in Lestoria/InventoryConsumableWindow.cpp @@ -85,7 +85,19 @@ void Menu::InitializeConsumableInventoryWindow(){ inventoryWindow->ADD("itemDescription",MenuLabel)(geom2d::rect(vf2d{2,117.f},{windowSize.x-4,windowSize.y-108}),"",1,ComponentAttr::SHADOW)END; auto okButton=inventoryWindow->ADD("OK Button",MenuComponent)(geom2d::rect{{windowSize.x/2-24,173.f},{48,12}},"Ok",[](MenuFuncData data){Menu::CloseMenu();return true;})END; - + + #pragma region ScrollWindow macro lambda + #define ScrollWindow(amount) \ + [](MenuType type){ \ + auto scrollWindow=Component(type,"inventory"); \ + scrollWindow->Scroll(amount); \ + int invWidth=int((scrollWindow->rect.size.x-12)/(float(scrollWindow->options.size.x)+scrollWindow->options.padding)); /*The inventory width determines how many items to skip at a time.*/ \ + scrollWindow->SetSelectionSkipIncrement(invWidth); \ + float scrollAmt=amount*game->GetElapsedTime()*"Interface.AnalogScrollSpeed"_F; \ + scrollWindow->IncreaseSelectionIndex(scrollAmt/24.f); \ + } + #pragma endregion + inventoryWindow->SetupKeyboardNavigation( [](MenuType type,Data&returnData){ //On Open //Try to find the component that matches the loadout item we have on us. @@ -111,6 +123,9 @@ void Menu::InitializeConsumableInventoryWindow(){ {game->KEY_BACK,{"Back",[](MenuType type){ Menu::CloseMenu(); }}}, + {{game->KEY_SCROLL,Analog},{"Scroll",ScrollWindow(game->KEY_SCROLL.Analog())}}, + {{game->KEY_SCROLLUP,Held},{"Scroll Up",ScrollWindow(-1.0f)}}, + {{game->KEY_SCROLLDOWN,Held},{"Scroll Down",ScrollWindow(1.0f)}}, } ,{ //Button Navigation Rules {"OK Button",{ diff --git a/Adventures in Lestoria/ScrollableWindowComponent.h b/Adventures in Lestoria/ScrollableWindowComponent.h index b180b77c..d5a63b7c 100644 --- a/Adventures in Lestoria/ScrollableWindowComponent.h +++ b/Adventures in Lestoria/ScrollableWindowComponent.h @@ -59,6 +59,7 @@ protected: vf2d targetScrollOffset{}; float lastScrollUpdate=0.f; float selectionIndex=0.f; + int selectionSkipIncrement=1; //How many items are on each row. This determines the increments that we skip by while scrolling. protected: inline bool OnScreen(std::weak_ptrcomponent){ return geom2d::overlaps(geom2d::rect{{},rect.size},geom2d::rect{component.lock()->rect.pos+vf2d{2,2},component.lock()->rect.size-vf2d{2,2}}); @@ -105,10 +106,14 @@ public: geom2d::overlaps(geom2d::rect{Menu::menus[parentMenu]->pos+rect.pos+child->rect.pos,child->rect.size},game->GetMousePos()); } + inline void SetSelectionSkipIncrement(const int selectionSkipIncrement){ + this->selectionSkipIncrement=selectionSkipIncrement; + } + inline void IncreaseSelectionIndex(const float val){ - float prevIndex=selectionIndex; + float prevIndex=selectionIndex/selectionSkipIncrement; selectionIndex=std::clamp(selectionIndex+val,0.f,float(components.size()-1)); - if(size_t(prevIndex)!=size_t(selectionIndex)){Menu::menus[parentMenu]->SetSelection(components[size_t(selectionIndex)],false);} + if(size_t(prevIndex)!=size_t(selectionIndex/selectionSkipIncrement)){Menu::menus[parentMenu]->SetSelection(components[size_t(selectionIndex)],false);} } protected: virtual inline vf2d GetScrollAmount()const{ diff --git a/Adventures in Lestoria/Version.h b/Adventures in Lestoria/Version.h index 67136688..d2c0fc1a 100644 --- a/Adventures in Lestoria/Version.h +++ b/Adventures in Lestoria/Version.h @@ -39,7 +39,7 @@ All rights reserved. #define VERSION_MAJOR 0 #define VERSION_MINOR 3 #define VERSION_PATCH 0 -#define VERSION_BUILD 6907 +#define VERSION_BUILD 6915 #define stringify(a) stringify_(a) #define stringify_(a) #a diff --git a/x64/Release/Adventures in Lestoria.exe b/x64/Release/Adventures in Lestoria.exe index 09de122c..129953d1 100644 Binary files a/x64/Release/Adventures in Lestoria.exe and b/x64/Release/Adventures in Lestoria.exe differ