Implement button navigation rules for gamepads. Fix mouse click / gamepad transition key conflicting. Fix how a pointer is generated for components via the Component<> reference template. Since we sometimes want to dynamic cast it, it loses all its typing data if we make a new shared pointer instead.

pull/35/head
sigonasr2 11 months ago
parent aec9646d40
commit dfa014b0a9
  1. 4
      Adventures in Lestoria/Error.h
  2. 6
      Adventures in Lestoria/Key.cpp
  3. 6
      Adventures in Lestoria/Key.h
  4. 5
      Adventures in Lestoria/LoadGameWindow.cpp
  5. 28
      Adventures in Lestoria/Menu.cpp
  6. 2
      Adventures in Lestoria/Menu.h
  7. 2
      Adventures in Lestoria/MenuComponent.cpp
  8. 2
      Adventures in Lestoria/Version.h

@ -88,13 +88,13 @@ type DYNAMIC_CAST(auto variable){
template<typename T,typename U>
std::shared_ptr<T>DYNAMIC_POINTER_CAST(const std::shared_ptr<U>&variable){
std::shared_ptr<T> newVariable=dynamic_pointer_cast<T>(variable);
if(!newVariable)ERR("Could not dynamic cast to pointer type "<<typeid(variable).name()<<"!");
if(!newVariable)ERR("Could not dynamic cast to pointer type "<<typeid(newVariable).name()<<"!");
return newVariable;
}
template<typename T,typename U>
std::shared_ptr<T>DYNAMIC_POINTER_CAST(const std::weak_ptr<U>&variable){
std::shared_ptr<T> newVariable=dynamic_pointer_cast<T>(variable.lock());
if(!newVariable)ERR("Could not dynamic cast to pointer type "<<typeid(variable).name()<<"!");
if(!newVariable)ERR("Could not dynamic cast to pointer type "<<typeid(newVariable).name()<<"!");
return newVariable;
}

@ -139,21 +139,21 @@ void InputGroup::RemoveKeybind(Input bind){
keys.erase(bind);
}
bool InputGroup::Pressed(){
const bool InputGroup::Pressed()const{
for(Input input:keys){
if(input.Pressed())return true;
}
return false;
}
bool InputGroup::Held(){
const bool InputGroup::Held()const{
for(Input input:keys){
if(input.Held())return true;
}
return false;
}
bool InputGroup::Released(){
const bool InputGroup::Released()const{
for(Input input:keys){
if(input.Released())return true;
}

@ -75,9 +75,9 @@ public:
InputGroup();
void AddKeybind(Input bind);
void RemoveKeybind(Input bind);
bool Pressed();
bool Held();
bool Released();
const bool Pressed()const;
const bool Held()const;
const bool Released()const;
std::string GetDisplayName();
};

@ -56,11 +56,8 @@ void Menu::InitializeLoadGameWindow(){
}
},
{ //Button Key
{game->KEY_START,{"Load File",[](MenuType type){
Menu::menus[type]->GetSelection().lock()->Click();
}}},
{game->KEY_BACK,{"Back to Title Screen",[](MenuType type){
Component<MenuComponent>(type,"Back Button")->Click();
Component<MenuComponent>(type,"Go Back Button")->Click();
}}},
}
,{ //Button Navigation Rules

@ -116,10 +116,8 @@ Menu*Menu::CreateMenu(MenuType type,vf2d pos,vf2d size){
}
void Menu::CheckClickAndPerformMenuSelect(AiL*game){
if(game->KEY_CONFIRM.Released()){
if(ignoreInputs){
ignoreInputs=false;
}else{
if(game->KEY_CONFIRM.Released()&&(MOUSE_NAVIGATION||(!MOUSE_NAVIGATION&&!game->GetMouse(Mouse::LEFT).bReleased&&!game->GetMouse(Mouse::RIGHT).bReleased&&!game->GetMouse(Mouse::MIDDLE).bReleased))){
if(!GetSelection().expired()){ //If we are on controller/gamepad it's possible we haven't highlighted a button yet, so don't click this button right away.
MenuSelect(game);
}
}
@ -298,6 +296,19 @@ void Menu::OpenMenu(MenuType menu,bool cover){
void Menu::KeyboardButtonNavigation(AiL*game,vf2d menuPos){
std::weak_ptr<MenuComponent>prevSelection=selection;
for(auto&[input,data]:inputGroups){
if(input.Released()){
SetMouseNavigation(false);
auto&action=data.second;
if(std::holds_alternative<ButtonName>(action))Component<MenuComponent>(type,std::get<ButtonName>(action))->Click();
else
if(std::holds_alternative<std::function<void(MenuType)>>(action))std::get<std::function<void(MenuType)>>(action)(type);
else{
ERR("WARNING! Navigation data has an unrecognized type or is empty! This should not be happening!")
}
}
}
if(!selection.expired()){
std::string selectionButtonName=selection.lock()->GetName();
if(!selection.lock()->parentComponent.expired()){ //If a component has a parent, then we use the parent as the identifier for what should happen next.
@ -350,10 +361,10 @@ void Menu::KeyboardButtonNavigation(AiL*game,vf2d menuPos){
}
}
if(game->KEY_UP.Pressed()||game->KEY_RIGHT.Pressed()||game->KEY_LEFT.Pressed()||game->KEY_DOWN.Pressed()||
game->KEY_BACK.Pressed()||game->KEY_CONFIRM.Pressed()||game->KEY_START.Pressed()||game->KEY_SELECT.Pressed()||
game->KEY_SCROLLDOWN.Pressed()||game->KEY_SCROLLUP.Pressed()){
SetMouseNavigation(game->GetMouse(Mouse::LEFT).bPressed||game->GetMouse(Mouse::RIGHT).bPressed||game->GetMouse(Mouse::MIDDLE).bPressed); //If a click occurs we use mouse controls.
if(game->KEY_UP.Released()||game->KEY_RIGHT.Released()||game->KEY_LEFT.Released()||game->KEY_DOWN.Released()||
game->KEY_BACK.Released()||game->KEY_CONFIRM.Released()||game->KEY_START.Released()||game->KEY_SELECT.Released()||
game->KEY_SCROLLDOWN.Released()||game->KEY_SCROLLUP.Released()){
SetMouseNavigation(game->GetMouse(Mouse::LEFT).bReleased||game->GetMouse(Mouse::RIGHT).bReleased||game->GetMouse(Mouse::MIDDLE).bReleased); //If a click occurs we use mouse controls.
buttonHoldTime=0;
}
if(&*prevSelection.lock()!=&*selection.lock()){
@ -473,7 +484,6 @@ 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.
lastActiveMousePos=game->GetMousePos();
ignoreInputs=true;
if(!keyboardSelection.expired()){
SetSelection(keyboardSelection);
}

@ -250,8 +250,6 @@ private:
std::weak_ptr<MenuComponent>selection;
std::weak_ptr<MenuComponent>keyboardSelection;
bool ignoreInputs=false; //We set this to true because on the next button release, we don't want buttons to cause menu navigation. This is for when the player needs to activate the cursor via keyboard/gamepad and nothing is highlighted. It gets reset to false once a button has been released.
static bool MOUSE_NAVIGATION;
bool cover; //A black cover for when a menu pops up to fade out the stuff behind it.
};

@ -246,5 +246,5 @@ void MenuComponent::OnPlayerMoneyUpdate(uint32_t newMoney){}
void MenuComponent::OnChapterUpdate(uint8_t newChapter){}
void MenuComponent::Click(){
onClick(MenuFuncData{*Menu::menus[parentMenu],game,std::make_shared<MenuComponent>(*this)});
onClick(MenuFuncData{*Menu::menus[parentMenu],game,Menu::menus[parentMenu]->components[name]});
}

@ -39,7 +39,7 @@ All rights reserved.
#define VERSION_MAJOR 0
#define VERSION_MINOR 2
#define VERSION_PATCH 1
#define VERSION_BUILD 6020
#define VERSION_BUILD 6033
#define stringify(a) stringify_(a)
#define stringify_(a) #a

Loading…
Cancel
Save