Keyboard/Controller input left direction bugfix. Using setter/getter for mouse navigation to handl storing of position whenever mouse navigation is called.
This commit is contained in:
parent
340690a26b
commit
6656e3d036
@ -100,6 +100,10 @@ void Menu::Update(Crawler*game){
|
|||||||
HoverMenuSelect(game);
|
HoverMenuSelect(game);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if(!UsingMouseNavigation()&&geom2d::line<float>(lastActiveMousePos,game->GetMousePos()).length()>="ThemeGlobal.MouseActivationDistance"_F||UsingMouseNavigation()){
|
||||||
|
SetMouseNavigation(true);
|
||||||
|
}
|
||||||
|
|
||||||
for(auto&key:buttons){
|
for(auto&key:buttons){
|
||||||
for(auto&button:key.second){
|
for(auto&button:key.second){
|
||||||
if(!button->disabled){
|
if(!button->disabled){
|
||||||
@ -110,7 +114,7 @@ void Menu::Update(Crawler*game){
|
|||||||
|
|
||||||
bool itemHovered=false;
|
bool itemHovered=false;
|
||||||
|
|
||||||
if(!MOUSE_NAVIGATION){
|
if(!UsingMouseNavigation()){
|
||||||
if(selection!=vi2d{-1,-1}){
|
if(selection!=vi2d{-1,-1}){
|
||||||
buttons[selection.y][selection.x]->hovered=true;
|
buttons[selection.y][selection.x]->hovered=true;
|
||||||
itemHovered=true;
|
itemHovered=true;
|
||||||
@ -133,7 +137,7 @@ void Menu::Update(Crawler*game){
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if(itemHovered&&draggingComponent==nullptr&&selection!=vi2d{-1,-1}&&(((!MOUSE_NAVIGATION&&(game->GetKey(ENTER).bHeld)||game->GetKey(SPACE).bHeld))||game->GetMouse(Mouse::LEFT).bHeld)){
|
if(itemHovered&&draggingComponent==nullptr&&selection!=vi2d{-1,-1}&&(((!UsingMouseNavigation()&&(game->GetKey(ENTER).bHeld)||game->GetKey(SPACE).bHeld))||game->GetMouse(Mouse::LEFT).bHeld)){
|
||||||
buttonHoldTime+=game->GetElapsedTime();
|
buttonHoldTime+=game->GetElapsedTime();
|
||||||
}else{
|
}else{
|
||||||
buttonHoldTime=0;
|
buttonHoldTime=0;
|
||||||
@ -151,7 +155,7 @@ void Menu::Update(Crawler*game){
|
|||||||
draggingComponent=nullptr;
|
draggingComponent=nullptr;
|
||||||
};
|
};
|
||||||
|
|
||||||
if(!MOUSE_NAVIGATION){
|
if(!UsingMouseNavigation()){
|
||||||
if(game->GetKey(ENTER).bReleased||game->GetKey(SPACE).bReleased){
|
if(game->GetKey(ENTER).bReleased||game->GetKey(SPACE).bReleased){
|
||||||
if(selectedComponent==nullptr){//Dropping over an empty area.
|
if(selectedComponent==nullptr){//Dropping over an empty area.
|
||||||
ClearDraggingComponent();
|
ClearDraggingComponent();
|
||||||
@ -239,7 +243,7 @@ void Menu::Draw(Crawler*game){
|
|||||||
game->SetPixelMode(Pixel::MASK);
|
game->SetPixelMode(Pixel::MASK);
|
||||||
game->Clear(BLANK);
|
game->Clear(BLANK);
|
||||||
vf2d offsetPos=draggingComponent->rect.pos;
|
vf2d offsetPos=draggingComponent->rect.pos;
|
||||||
if(!MOUSE_NAVIGATION){
|
if(!UsingMouseNavigation()){
|
||||||
MenuComponent*selectedComponent=buttons[selection.y][selection.x];
|
MenuComponent*selectedComponent=buttons[selection.y][selection.x];
|
||||||
vf2d drawOffset{};
|
vf2d drawOffset{};
|
||||||
if(selectedComponent->parentComponent!=nullptr){
|
if(selectedComponent->parentComponent!=nullptr){
|
||||||
@ -253,7 +257,7 @@ void Menu::Draw(Crawler*game){
|
|||||||
game->SetDrawTarget(nullptr);
|
game->SetDrawTarget(nullptr);
|
||||||
overlay.Decal()->Update();
|
overlay.Decal()->Update();
|
||||||
game->DrawDecal({0,0},overlay.Decal());
|
game->DrawDecal({0,0},overlay.Decal());
|
||||||
if(!MOUSE_NAVIGATION){
|
if(!UsingMouseNavigation()){
|
||||||
MenuComponent*selectedComponent=buttons[selection.y][selection.x];
|
MenuComponent*selectedComponent=buttons[selection.y][selection.x];
|
||||||
vf2d drawOffset{};
|
vf2d drawOffset{};
|
||||||
if(selectedComponent->parentComponent!=nullptr){
|
if(selectedComponent->parentComponent!=nullptr){
|
||||||
@ -275,17 +279,18 @@ void Menu::KeyboardButtonNavigation(Crawler*game,vf2d menuPos){
|
|||||||
vi2d prevSelection=selection;
|
vi2d prevSelection=selection;
|
||||||
if(game->GetKey(RIGHT).bPressed){
|
if(game->GetKey(RIGHT).bPressed){
|
||||||
if(selection==vi2d{-1,-1})return;
|
if(selection==vi2d{-1,-1})return;
|
||||||
MOUSE_NAVIGATION=false;
|
SetMouseNavigation(false);
|
||||||
selection.x=(size_t(selection.x)+1)%keyboardButtons[selection.y].size();
|
selection.x=(size_t(selection.x)+1)%keyboardButtons[selection.y].size();
|
||||||
}
|
}
|
||||||
if(game->GetKey(LEFT).bPressed){
|
if(game->GetKey(LEFT).bPressed){
|
||||||
if(selection==vi2d{-1,-1})return;
|
if(selection==vi2d{-1,-1})return;
|
||||||
selection.x--;
|
selection.x--;
|
||||||
|
SetMouseNavigation(false);
|
||||||
if(selection.x<0)selection.x+=keyboardButtons[selection.y].size();
|
if(selection.x<0)selection.x+=keyboardButtons[selection.y].size();
|
||||||
}
|
}
|
||||||
if(game->GetKey(DOWN).bPressed||game->GetKey(UP).bPressed){
|
if(game->GetKey(DOWN).bPressed||game->GetKey(UP).bPressed){
|
||||||
if(game->GetKey(DOWN).bPressed){
|
if(game->GetKey(DOWN).bPressed){
|
||||||
MOUSE_NAVIGATION=false;
|
SetMouseNavigation(false);
|
||||||
bool found=false;
|
bool found=false;
|
||||||
bool selectedItem=false;
|
bool selectedItem=false;
|
||||||
if(selection==vi2d{-1,-1}){
|
if(selection==vi2d{-1,-1}){
|
||||||
@ -310,7 +315,9 @@ void Menu::KeyboardButtonNavigation(Crawler*game,vf2d menuPos){
|
|||||||
selectedItem=true;
|
selectedItem=true;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
if(key.first==selection.y){
|
if(key.first==selection.y&&
|
||||||
|
//It's entirely possible this button was selected from the button selection list and may be out-of-bounds here.
|
||||||
|
selection.x>=0&&selection.x<keyboardButtons[selection.y].size()){
|
||||||
found=true;
|
found=true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -323,8 +330,7 @@ void Menu::KeyboardButtonNavigation(Crawler*game,vf2d menuPos){
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
if(game->GetKey(UP).bPressed){
|
if(game->GetKey(UP).bPressed){
|
||||||
MOUSE_NAVIGATION=false;
|
SetMouseNavigation(false);
|
||||||
|
|
||||||
if(selection==vi2d{-1,-1}){
|
if(selection==vi2d{-1,-1}){
|
||||||
//Highlight last item.
|
//Highlight last item.
|
||||||
for(auto&key:keyboardButtons){
|
for(auto&key:keyboardButtons){
|
||||||
@ -333,7 +339,9 @@ void Menu::KeyboardButtonNavigation(Crawler*game,vf2d menuPos){
|
|||||||
}else{
|
}else{
|
||||||
int prevInd=-1;
|
int prevInd=-1;
|
||||||
for(auto&key:keyboardButtons){
|
for(auto&key:keyboardButtons){
|
||||||
if(key.first==selection.y){
|
if(key.first==selection.y&&
|
||||||
|
//It's entirely possible this button was selected from the button selection list and may be out-of-bounds here.
|
||||||
|
selection.x>=0&&selection.x<keyboardButtons[selection.y].size()){
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
prevInd=key.first;
|
prevInd=key.first;
|
||||||
@ -366,8 +374,8 @@ void Menu::KeyboardButtonNavigation(Crawler*game,vf2d menuPos){
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
if(game->GetMouse(0).bPressed||game->GetKey(ENTER).bPressed||game->GetKey(SPACE).bPressed){
|
if(game->GetMouse(0).bPressed||game->GetKey(ENTER).bPressed||game->GetKey(SPACE).bPressed){
|
||||||
MOUSE_NAVIGATION=game->GetMouse(0).bPressed; //If a click occurs we use mouse controls.
|
SetMouseNavigation(game->GetMouse(0).bPressed); //If a click occurs we use mouse controls.
|
||||||
if(!MOUSE_NAVIGATION){
|
if(!UsingMouseNavigation()){
|
||||||
buttonHoldTime=0;
|
buttonHoldTime=0;
|
||||||
//Key presses automatically highlight the first button if it's not highlighted.
|
//Key presses automatically highlight the first button if it's not highlighted.
|
||||||
if(selection==vi2d{-1,-1}&&buttons.size()>0){
|
if(selection==vi2d{-1,-1}&&buttons.size()>0){
|
||||||
@ -403,7 +411,7 @@ 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){
|
||||||
bool handled=false;
|
bool handled=false;
|
||||||
if(!MOUSE_NAVIGATION){
|
if(!UsingMouseNavigation()){
|
||||||
//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.
|
//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 we return false, then we handled it ourselves, no need to go back to the previous selection.
|
||||||
if(HandleOutsideDisabledButtonSelection(buttons[selection.y][selection.x])){
|
if(HandleOutsideDisabledButtonSelection(buttons[selection.y][selection.x])){
|
||||||
@ -508,3 +516,16 @@ bool Menu::HandleOutsideDisabledButtonSelection(MenuComponent*disabledButton){
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
bool Menu::UsingMouseNavigation(){
|
||||||
|
return MOUSE_NAVIGATION;
|
||||||
|
};
|
||||||
|
void Menu::SetMouseNavigation(bool mouseNavigation){
|
||||||
|
if(MOUSE_NAVIGATION&&!mouseNavigation){
|
||||||
|
//When mouse navigation was enabled and now needs to be disabled, we store the mouse position.
|
||||||
|
INCLUDE_game
|
||||||
|
lastActiveMousePos=game->GetMousePos();
|
||||||
|
}
|
||||||
|
MOUSE_NAVIGATION=mouseNavigation;
|
||||||
|
};
|
@ -23,13 +23,13 @@ enum MenuType{
|
|||||||
class Menu:IAttributable{
|
class Menu:IAttributable{
|
||||||
friend class Crawler;
|
friend class Crawler;
|
||||||
friend class Player;
|
friend class Player;
|
||||||
static bool MOUSE_NAVIGATION;
|
|
||||||
|
|
||||||
float buttonHoldTime=0;
|
float buttonHoldTime=0;
|
||||||
std::map<int/*Y*/,std::vector<MenuComponent*>>buttons; //Buttons are stored in rows followed by their column order.
|
std::map<int/*Y*/,std::vector<MenuComponent*>>buttons; //Buttons are stored in rows followed by their column order.
|
||||||
std::map<int/*Y*/,std::vector<MenuComponent*>>keyboardButtons; //Button ordered storage for keyboard/menu
|
std::map<int/*Y*/,std::vector<MenuComponent*>>keyboardButtons; //Button ordered storage for keyboard/menu
|
||||||
std::vector<MenuComponent*>displayComponents; //Components that are only for displaying purposes.
|
std::vector<MenuComponent*>displayComponents; //Components that are only for displaying purposes.
|
||||||
vi2d selection={-1,-1};
|
vi2d selection={-1,-1};
|
||||||
|
vi2d lastActiveMousePos={};
|
||||||
|
|
||||||
MenuComponent*draggingComponent=nullptr;
|
MenuComponent*draggingComponent=nullptr;
|
||||||
Renderable r,overlay;
|
Renderable r,overlay;
|
||||||
@ -52,6 +52,8 @@ public:
|
|||||||
vf2d size; //Size in tiles (24x24), every menu will be tile-based
|
vf2d size; //Size in tiles (24x24), every menu will be tile-based
|
||||||
|
|
||||||
static Theme&GetCurrentTheme();
|
static Theme&GetCurrentTheme();
|
||||||
|
bool UsingMouseNavigation();
|
||||||
|
void SetMouseNavigation(bool mouseNavigation);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Menu(vf2d pos,vf2d size);
|
Menu(vf2d pos,vf2d size);
|
||||||
@ -76,6 +78,7 @@ private:
|
|||||||
bool HandleOutsideDisabledButtonSelection(MenuComponent*disabledButton);
|
bool HandleOutsideDisabledButtonSelection(MenuComponent*disabledButton);
|
||||||
|
|
||||||
Pixel GetRenderColor();
|
Pixel GetRenderColor();
|
||||||
|
static bool MOUSE_NAVIGATION;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct MenuFuncData{
|
struct MenuFuncData{
|
||||||
|
@ -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 2121
|
#define VERSION_BUILD 2127
|
||||||
|
|
||||||
#define stringify(a) stringify_(a)
|
#define stringify(a) stringify_(a)
|
||||||
#define stringify_(a) #a
|
#define stringify_(a) #a
|
||||||
|
@ -10,6 +10,9 @@ ThemeGlobal
|
|||||||
MenuScrollWheelSpeed = 8
|
MenuScrollWheelSpeed = 8
|
||||||
# How fast the menu scrolls via clicking the Scroll Arrow Buttons
|
# How fast the menu scrolls via clicking the Scroll Arrow Buttons
|
||||||
MenuButtonScrollSpeed = 16
|
MenuButtonScrollSpeed = 16
|
||||||
|
|
||||||
|
# How far the mouse has to move before mouse mode becomes active from keyboard/controller input mode.
|
||||||
|
MouseActivationDistance = 8
|
||||||
}
|
}
|
||||||
|
|
||||||
Themes
|
Themes
|
||||||
|
Loading…
x
Reference in New Issue
Block a user