Add in selection indices that respect menus with multiple columns while scrolling through.
This commit is contained in:
parent
fd1f762e20
commit
6778ffc72d
@ -86,6 +86,18 @@ void Menu::InitializeConsumableInventoryWindow(){
|
||||
|
||||
auto okButton=inventoryWindow->ADD("OK Button",MenuComponent)(geom2d::rect<float>{{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<InventoryScrollableWindowComponent>(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",{
|
||||
|
@ -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_ptr<MenuComponent>component){
|
||||
return geom2d::overlaps(geom2d::rect<float>{{},rect.size},geom2d::rect<float>{component.lock()->rect.pos+vf2d{2,2},component.lock()->rect.size-vf2d{2,2}});
|
||||
@ -105,10 +106,14 @@ public:
|
||||
geom2d::overlaps(geom2d::rect<float>{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{
|
||||
|
@ -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
|
||||
|
Binary file not shown.
Loading…
x
Reference in New Issue
Block a user