Added keyboard/controller controls for scrollable menu components beyond bounds for disabled controls.

pull/28/head
sigonasr2 1 year ago
parent 958a1866c7
commit 340690a26b
  1. 22
      Crawler/Menu.cpp
  2. 3
      Crawler/Menu.h
  3. 6
      Crawler/MenuComponent.cpp
  4. 2
      Crawler/MenuComponent.h
  5. 8
      Crawler/ScrollableWindowComponent.h
  6. 2
      Crawler/Version.h

@ -402,9 +402,19 @@ void Menu::KeyboardButtonNavigation(Crawler*game,vf2d menuPos){
}
if(prevSelection!=selection){
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.
}
}
@ -489,4 +499,12 @@ Pixel Menu::GetRenderColor(){
col=WHITE*"ThemeGlobal.MenuUnfocusedColorMult"_F;
}
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 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();
};

@ -74,4 +74,8 @@ bool MenuComponent::PointWithinParent(MenuComponent*child,vi2d drawPos){
}else{
return true;
}
}
}
bool MenuComponent::HandleOutsideDisabledButtonSelection(MenuComponent*disabledButton){
return false;
};

@ -41,4 +41,6 @@ public:
virtual MenuComponent*PickUpDraggableItem();
//We are attempting to drop draggable onto this item. If it's not allowed, return false.
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;
private:
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:
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{
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_MINOR 2
#define VERSION_PATCH 0
#define VERSION_BUILD 2116
#define VERSION_BUILD 2121
#define stringify(a) stringify_(a)
#define stringify_(a) #a

Loading…
Cancel
Save