Added keyboard/controller controls for scrollable menu components beyond bounds for disabled controls.
This commit is contained in:
parent
958a1866c7
commit
340690a26b
@ -402,9 +402,19 @@ void Menu::KeyboardButtonNavigation(Crawler*game,vf2d menuPos){
|
|||||||
}
|
}
|
||||||
if(prevSelection!=selection){
|
if(prevSelection!=selection){
|
||||||
if(selection!=vi2d{-1,-1}&&buttons[selection.y][selection.x]->disabled){
|
if(selection!=vi2d{-1,-1}&&buttons[selection.y][selection.x]->disabled){
|
||||||
selection=prevSelection;
|
bool handled=false;
|
||||||
|
if(!MOUSE_NAVIGATION){
|
||||||
|
//Let's transfer some information about our selection being off the screen. Our intention with keyboard controls is that the screen will scroll to the correct location instead.
|
||||||
|
//If we return false, then we handled it ourselves, no need to go back to the previous selection.
|
||||||
|
if(HandleOutsideDisabledButtonSelection(buttons[selection.y][selection.x])){
|
||||||
|
handled=true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if(!handled){
|
||||||
|
// If the new selection of a button on this frame is disabled for some reason and we didn't handle it, we need to go back to what we had selected before.
|
||||||
|
selection=prevSelection;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
// If the new selection of a button on this frame is disabled for some reason, we need to go back to what we had selected before.
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -490,3 +500,11 @@ Pixel Menu::GetRenderColor(){
|
|||||||
}
|
}
|
||||||
return col;
|
return col;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool Menu::HandleOutsideDisabledButtonSelection(MenuComponent*disabledButton){
|
||||||
|
if(disabledButton->parentComponent!=nullptr){
|
||||||
|
return disabledButton->parentComponent->HandleOutsideDisabledButtonSelection(disabledButton);
|
||||||
|
}else{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
@ -72,6 +72,9 @@ private:
|
|||||||
void DrawScaledWindowBorder(Crawler*game,vf2d menuPos);
|
void DrawScaledWindowBorder(Crawler*game,vf2d menuPos);
|
||||||
void DrawTiledWindowBorder(Crawler*game,vf2d menuPos);
|
void DrawTiledWindowBorder(Crawler*game,vf2d menuPos);
|
||||||
|
|
||||||
|
//This triggers if we use a keyboard/controller input to try and select some off-screen menu item. We should ideally follow the menu cursor.
|
||||||
|
bool HandleOutsideDisabledButtonSelection(MenuComponent*disabledButton);
|
||||||
|
|
||||||
Pixel GetRenderColor();
|
Pixel GetRenderColor();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -75,3 +75,7 @@ bool MenuComponent::PointWithinParent(MenuComponent*child,vi2d drawPos){
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool MenuComponent::HandleOutsideDisabledButtonSelection(MenuComponent*disabledButton){
|
||||||
|
return false;
|
||||||
|
};
|
@ -41,4 +41,6 @@ public:
|
|||||||
virtual MenuComponent*PickUpDraggableItem();
|
virtual MenuComponent*PickUpDraggableItem();
|
||||||
//We are attempting to drop draggable onto this item. If it's not allowed, return false.
|
//We are attempting to drop draggable onto this item. If it's not allowed, return false.
|
||||||
virtual bool DropDraggableItem(MenuComponent*draggable);
|
virtual bool DropDraggableItem(MenuComponent*draggable);
|
||||||
|
//A notification that a button outside the region has been selected. Return false if it's not allowed.
|
||||||
|
virtual bool HandleOutsideDisabledButtonSelection(MenuComponent*disabledButton);
|
||||||
};
|
};
|
@ -18,7 +18,7 @@ protected:
|
|||||||
float scrollBarHoverTime=0;
|
float scrollBarHoverTime=0;
|
||||||
private:
|
private:
|
||||||
inline bool OnScreen(MenuComponent*component){
|
inline bool OnScreen(MenuComponent*component){
|
||||||
return geom2d::overlaps(rect,geom2d::rect<float>{component->rect.pos+V(A::SCROLL_OFFSET),component->rect.size});
|
return geom2d::overlaps(rect,geom2d::rect<float>{component->rect.pos+V(A::SCROLL_OFFSET)+vf2d{2,2},component->rect.size-vf2d{2,2}});
|
||||||
}
|
}
|
||||||
public:
|
public:
|
||||||
inline ScrollableWindowComponent(MenuType parent,geom2d::rect<float>rect,Decal*icon,MenuFunc onClick)
|
inline ScrollableWindowComponent(MenuType parent,geom2d::rect<float>rect,Decal*icon,MenuFunc onClick)
|
||||||
@ -157,4 +157,10 @@ public:
|
|||||||
virtual inline bool PointWithinParent(MenuComponent*child,vi2d drawPos)override{
|
virtual inline bool PointWithinParent(MenuComponent*child,vi2d drawPos)override{
|
||||||
return geom2d::overlaps(geom2d::rect<float>{Menu::menus[parentMenu]->pos+rect.pos,rect.size},drawPos);
|
return geom2d::overlaps(geom2d::rect<float>{Menu::menus[parentMenu]->pos+rect.pos,rect.size},drawPos);
|
||||||
}
|
}
|
||||||
|
virtual inline bool HandleOutsideDisabledButtonSelection(MenuComponent*disabledButton)override{
|
||||||
|
//Set the offset so the center is highlighted by this button.
|
||||||
|
V(A::SCROLL_OFFSET).y=-(disabledButton->rect.pos.y-disabledButton->rect.size.y/2);
|
||||||
|
V(A::SCROLL_OFFSET).y+=rect.size.y/2;
|
||||||
|
return true;
|
||||||
|
};
|
||||||
};
|
};
|
@ -2,7 +2,7 @@
|
|||||||
#define VERSION_MAJOR 0
|
#define VERSION_MAJOR 0
|
||||||
#define VERSION_MINOR 2
|
#define VERSION_MINOR 2
|
||||||
#define VERSION_PATCH 0
|
#define VERSION_PATCH 0
|
||||||
#define VERSION_BUILD 2116
|
#define VERSION_BUILD 2121
|
||||||
|
|
||||||
#define stringify(a) stringify_(a)
|
#define stringify(a) stringify_(a)
|
||||||
#define stringify_(a) #a
|
#define stringify_(a) #a
|
||||||
|
Loading…
x
Reference in New Issue
Block a user