Add in structures to deal with custom menu navigation setups.
This commit is contained in:
parent
97ce43ed21
commit
cbb277cab2
@ -97,6 +97,10 @@ InputGroup AiL::KEY_DOWN;
|
||||
InputGroup AiL::KEY_ATTACK;
|
||||
InputGroup AiL::KEY_CONFIRM;
|
||||
InputGroup AiL::KEY_MENU;
|
||||
InputGroup AiL::KEY_SCROLLUP;
|
||||
InputGroup AiL::KEY_SCROLLDOWN;
|
||||
InputGroup AiL::KEY_BACK;
|
||||
|
||||
#ifndef __EMSCRIPTEN__
|
||||
::discord::Core*Discord{};
|
||||
#endif
|
||||
@ -2368,13 +2372,28 @@ void AiL::InitializeDefaultKeybinds(){
|
||||
KEY_DOWN.AddKeybind({KEY,S});
|
||||
KEY_DOWN.AddKeybind({CONTROLLER,static_cast<int>(GPButtons::DPAD_D)});
|
||||
KEY_CONFIRM.AddKeybind({MOUSE,Mouse::LEFT});
|
||||
KEY_CONFIRM.AddKeybind({CONTROLLER,static_cast<int>(GPButtons::FACE_D)});
|
||||
KEY_CONFIRM.AddKeybind({CONTROLLER,static_cast<int>(GPButtons::FACE_R)});
|
||||
KEY_CONFIRM.AddKeybind({CONTROLLER,static_cast<int>(GPButtons::START)});
|
||||
KEY_CONFIRM.AddKeybind({KEY,SPACE});
|
||||
KEY_CONFIRM.AddKeybind({KEY,ENTER});
|
||||
KEY_CONFIRM.AddKeybind({KEY,Z});
|
||||
KEY_BACK.AddKeybind({KEY,X});
|
||||
KEY_BACK.AddKeybind({KEY,SHIFT});
|
||||
KEY_BACK.AddKeybind({KEY,ESCAPE});
|
||||
KEY_BACK.AddKeybind({CONTROLLER,static_cast<int>(GPButtons::FACE_D)});
|
||||
KEY_MENU.AddKeybind({KEY,ESCAPE});
|
||||
KEY_MENU.AddKeybind({CONTROLLER,static_cast<int>(GPButtons::START)});
|
||||
|
||||
KEY_SCROLLUP.AddKeybind({KEY,Q});
|
||||
KEY_SCROLLUP.AddKeybind({KEY,PGUP});
|
||||
KEY_SCROLLUP.AddKeybind({KEY,NP8});
|
||||
KEY_SCROLLUP.AddKeybind({CONTROLLER,static_cast<int>(GPButtons::L2)});
|
||||
KEY_SCROLLUP.AddKeybind({CONTROLLER,static_cast<int>(GPButtons::L1)});
|
||||
KEY_SCROLLDOWN.AddKeybind({KEY,E});
|
||||
KEY_SCROLLDOWN.AddKeybind({KEY,PGDN});
|
||||
KEY_SCROLLDOWN.AddKeybind({KEY,NP2});
|
||||
KEY_SCROLLDOWN.AddKeybind({CONTROLLER,static_cast<int>(GPButtons::R2)});
|
||||
KEY_SCROLLDOWN.AddKeybind({CONTROLLER,static_cast<int>(GPButtons::R1)});
|
||||
}
|
||||
|
||||
void AiL::SetBossNameDisplay(std::string name,float time){
|
||||
|
@ -73,6 +73,9 @@ class AiL : public olc::PixelGameEngine
|
||||
SplashScreen splash;
|
||||
public:
|
||||
Pathfinding pathfinder;
|
||||
static InputGroup KEY_SCROLLUP;
|
||||
static InputGroup KEY_SCROLLDOWN;
|
||||
static InputGroup KEY_BACK;
|
||||
static InputGroup KEY_CONFIRM;
|
||||
static InputGroup KEY_ATTACK;
|
||||
static InputGroup KEY_LEFT;
|
||||
|
@ -338,4 +338,8 @@ void Input::StopVibration(){
|
||||
gamepad->stopVibration();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
const bool operator<(const InputGroup&group1,const InputGroup&group2){
|
||||
return &group1<&group2;
|
||||
}
|
@ -84,4 +84,6 @@ public:
|
||||
class GenericKey{
|
||||
public:
|
||||
static std::map<std::pair<InputType,int>,std::string>keyLiteral; //The displayed text for a given key for a given input type.
|
||||
};
|
||||
};
|
||||
|
||||
const bool operator<(const InputGroup&group1,const InputGroup&group2);
|
@ -87,4 +87,20 @@ void Menu::InitializeMainMenuWindow(){
|
||||
}else{
|
||||
mainMenuWindow->SetDefaultButton(newGameButton);
|
||||
}
|
||||
|
||||
mainMenuWindow->SetupKeyboardNavigation(
|
||||
{
|
||||
{game->KEY_BACK,{"",[](MenuType type){}}},
|
||||
}
|
||||
,{
|
||||
{"New Game Button",{
|
||||
.up="Quit Game Button",
|
||||
.down="Load Game Button",}},
|
||||
{"Load Game Button",{
|
||||
.up="New Game Button",
|
||||
.down="Quit Game Button",}},
|
||||
{"Quit Game Button",{
|
||||
.up="Load Game Button",
|
||||
.down="New Game Button",}},
|
||||
});
|
||||
}
|
@ -320,6 +320,36 @@ void Menu::SetDefaultButton(std::weak_ptr<MenuComponent>button){
|
||||
|
||||
void Menu::KeyboardButtonNavigation(AiL*game,vf2d menuPos){
|
||||
std::weak_ptr<MenuComponent>prevSelection=selection;
|
||||
|
||||
std::string selectionButtonName=selection.lock()->GetName();
|
||||
if(navigationGroups.count(selectionButtonName)){
|
||||
Navigation nav=navigationGroups[selectionButtonName];
|
||||
|
||||
if(game->KEY_UP.Pressed()){
|
||||
SetMouseNavigation(false);
|
||||
if(std::holds_alternative<std::string>(nav.up)&&std::get<std::string>(nav.up).length()>0)selection=components[std::get<std::string>(nav.up)];
|
||||
else
|
||||
if(std::holds_alternative<MenuDataFunc>(nav.up))std::get<MenuDataFunc>(nav.up)(type);
|
||||
}
|
||||
if(game->KEY_DOWN.Pressed()){
|
||||
SetMouseNavigation(false);
|
||||
if(std::holds_alternative<std::string>(nav.down)&&std::get<std::string>(nav.down).length()>0)selection=components[std::get<std::string>(nav.down)];
|
||||
else
|
||||
if(std::holds_alternative<MenuDataFunc>(nav.down))std::get<MenuDataFunc>(nav.down)(type);
|
||||
}
|
||||
if(game->KEY_LEFT.Pressed()){
|
||||
SetMouseNavigation(false);
|
||||
if(std::holds_alternative<std::string>(nav.left)&&std::get<std::string>(nav.left).length()>0)selection=components[std::get<std::string>(nav.left)];
|
||||
else
|
||||
if(std::holds_alternative<MenuDataFunc>(nav.left))std::get<MenuDataFunc>(nav.left)(type);
|
||||
}
|
||||
if(game->KEY_RIGHT.Pressed()){
|
||||
SetMouseNavigation(false);
|
||||
if(std::holds_alternative<std::string>(nav.right)&&std::get<std::string>(nav.right).length()>0)selection=components[std::get<std::string>(nav.right)];
|
||||
else
|
||||
if(std::holds_alternative<MenuDataFunc>(nav.right))std::get<MenuDataFunc>(nav.right)(type);
|
||||
}
|
||||
}
|
||||
|
||||
if(game->KEY_CONFIRM.Pressed()){
|
||||
SetMouseNavigation(game->GetMouse(0).bPressed); //If a click occurs we use mouse controls.
|
||||
@ -574,4 +604,17 @@ void Menu::AddChapterListener(std::weak_ptr<MenuComponent>component){
|
||||
|
||||
|
||||
MenuFuncData::MenuFuncData(Menu&menu,AiL*const game,std::weak_ptr<MenuComponent>component,std::weak_ptr<ScrollableWindowComponent>parentComponent)
|
||||
:menu(menu),game(game),component(component),parentComponent(parentComponent){}
|
||||
:menu(menu),game(game),component(component),parentComponent(parentComponent){}
|
||||
|
||||
void Menu::SetSelection(std::weak_ptr<MenuComponent>button){
|
||||
selection=button;
|
||||
}
|
||||
|
||||
void Menu::SetupKeyboardNavigation(MenuInputGroups inputGroups,ButtonNavigationGroups navigationGroups){
|
||||
this->inputGroups=inputGroups;
|
||||
this->navigationGroups=navigationGroups;
|
||||
}
|
||||
|
||||
const std::weak_ptr<MenuComponent>Menu::GetSelection()const{
|
||||
return selection;
|
||||
}
|
@ -43,11 +43,25 @@ All rights reserved.
|
||||
#include "Attributable.h"
|
||||
#include "olcUTIL_Geometry2D.h"
|
||||
#include "olcPGEX_ViewPort.h"
|
||||
#include "Key.h"
|
||||
|
||||
class AiL;
|
||||
class MenuComponent;
|
||||
class ScrollableWindowComponent;
|
||||
|
||||
struct Navigation;
|
||||
|
||||
class Menu;
|
||||
|
||||
struct MenuFuncData{
|
||||
Menu&menu;
|
||||
AiL*const game;
|
||||
const std::weak_ptr<MenuComponent> component;
|
||||
const std::weak_ptr<ScrollableWindowComponent> parentComponent={};
|
||||
MenuFuncData(Menu&menu,AiL*const game,std::weak_ptr<MenuComponent> component,std::weak_ptr<ScrollableWindowComponent>parentComponent={});
|
||||
};
|
||||
|
||||
using MenuFunc=std::function<bool(MenuFuncData)>;
|
||||
//Add a component to a menu using this macro. Follow-up with END at the end of it.
|
||||
#define ADD(key,componentType) _AddComponent<componentType>(key,std::make_shared<componentType>
|
||||
#define END )
|
||||
@ -85,6 +99,21 @@ enum MenuType{
|
||||
///////////////////////////////////////////////////////////
|
||||
};
|
||||
|
||||
using MenuDataFunc=std::function<void(MenuType)>;
|
||||
|
||||
using InputGroupActionDisplayName=std::string;
|
||||
using ButtonName=std::string;
|
||||
using MenuInputGroups=std::map<InputGroup,std::pair<InputGroupActionDisplayName,std::variant<ButtonName,MenuDataFunc>>>;
|
||||
using ButtonNavigationGroups=std::map<ButtonName,Navigation>;
|
||||
|
||||
|
||||
struct Navigation{
|
||||
std::variant<std::string,MenuDataFunc>up;
|
||||
std::variant<std::string,MenuDataFunc>down;
|
||||
std::variant<std::string,MenuDataFunc>left;
|
||||
std::variant<std::string,MenuDataFunc>right;
|
||||
};
|
||||
|
||||
class Menu:public IAttributable{
|
||||
static void InitializeConsumableInventoryWindow();
|
||||
static void InitializeClassInfoWindow();
|
||||
@ -188,6 +217,8 @@ public:
|
||||
void RecalculateComponentCount();
|
||||
|
||||
void SetDefaultButton(std::weak_ptr<MenuComponent>button);
|
||||
void SetSelection(std::weak_ptr<MenuComponent>button);
|
||||
const std::weak_ptr<MenuComponent>GetSelection()const;
|
||||
private:
|
||||
Menu(vf2d pos,vf2d size);
|
||||
std::weak_ptr<MenuComponent>defaultButton;
|
||||
@ -198,7 +229,8 @@ private:
|
||||
void CheckClickAndPerformMenuSelect(AiL*game);
|
||||
//Mandatory before any menu operations! This creates and sets up the menu in memory.
|
||||
static Menu*CreateMenu(MenuType type,vf2d pos,vf2d size);
|
||||
|
||||
|
||||
void SetupKeyboardNavigation(MenuInputGroups inputGroups,ButtonNavigationGroups navigationGroups);
|
||||
void KeyboardButtonNavigation(AiL*game,vf2d menuPos);
|
||||
static void DrawScaledWindowBackground(AiL*game,vf2d menuPos,vf2d size,Pixel renderColor);
|
||||
static void DrawTiledWindowBackground(AiL*game,vf2d menuPos,vf2d size,Pixel renderColor);
|
||||
@ -210,6 +242,8 @@ private:
|
||||
|
||||
Pixel GetRenderColor();
|
||||
MenuType type;
|
||||
MenuInputGroups inputGroups;
|
||||
ButtonNavigationGroups navigationGroups;
|
||||
|
||||
static bool MOUSE_NAVIGATION;
|
||||
bool cover; //A black cover for when a menu pops up to fade out the stuff behind it.
|
||||
@ -218,14 +252,4 @@ private:
|
||||
template<typename T>
|
||||
std::shared_ptr<T>Component(MenuType menu,std::string componentName){
|
||||
return DYNAMIC_POINTER_CAST<T>(Menu::menus[menu]->components[componentName]);
|
||||
}
|
||||
|
||||
struct MenuFuncData{
|
||||
Menu&menu;
|
||||
AiL*const game;
|
||||
const std::weak_ptr<MenuComponent> component;
|
||||
const std::weak_ptr<ScrollableWindowComponent> parentComponent={};
|
||||
MenuFuncData(Menu&menu,AiL*const game,std::weak_ptr<MenuComponent> component,std::weak_ptr<ScrollableWindowComponent>parentComponent={});
|
||||
};
|
||||
|
||||
using MenuFunc=std::function<bool(MenuFuncData)>;
|
||||
}
|
@ -30,4 +30,19 @@ Story proofreading/correcting/storyboarding
|
||||
|
||||
|
||||
|
||||
- Emscripten _DEBUG flag add as an option when building
|
||||
- Emscripten _DEBUG flag add as an option when building
|
||||
|
||||
|
||||
mainMenuWindow->SetupKeyboardNavigation(
|
||||
{
|
||||
{game->KEY_BACK,{"","Quit Game Button"}},
|
||||
{game->KEY_BACK,{"",[](MenuFuncData data){}}},
|
||||
}
|
||||
,{
|
||||
{"New Game Button",{
|
||||
.up="Quit Game Button",
|
||||
.down="Load Game Button",}},
|
||||
{"Load Game Button",{
|
||||
.up="New Game Button",
|
||||
.down="Quit Game Button",}},
|
||||
});
|
@ -39,7 +39,7 @@ All rights reserved.
|
||||
#define VERSION_MAJOR 0
|
||||
#define VERSION_MINOR 2
|
||||
#define VERSION_PATCH 1
|
||||
#define VERSION_BUILD 5958
|
||||
#define VERSION_BUILD 5966
|
||||
|
||||
#define stringify(a) stringify_(a)
|
||||
#define stringify_(a) #a
|
||||
|
Loading…
x
Reference in New Issue
Block a user