Continue fixing up new menu navigation structure
Co-authored-by: sigonasr2 <sigonasr2@gmail.com>
This commit is contained in:
parent
21965b3c90
commit
210a46a5f9
@ -30,7 +30,7 @@ CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
|
||||
ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
SUCH DAMAGE.
|
||||
|
||||
Portions of this software are copyright © 2023 The FreeType
|
||||
Portions of this software are copyright <EFBFBD> 2023 The FreeType
|
||||
Project (www.freetype.org). Please see LICENSE_FT.txt for more information.
|
||||
All rights reserved.
|
||||
*/
|
||||
@ -45,4 +45,35 @@ void Menu::InitializeLoadGameWindow(){
|
||||
loadGameWindow->ADD("Game Files Label",MenuLabel)(geom2d::rect<float>{{-8,-12},{112,12}},"Load Game",1.0f,ComponentAttr::SHADOW|ComponentAttr::OUTLINE|ComponentAttr::BACKGROUND)END;
|
||||
loadGameWindow->ADD("Game Files List",ScrollableWindowComponent)(geom2d::rect<float>{{-8,4},{112,116}})END;
|
||||
loadGameWindow->ADD("Go Back Button",MenuComponent)(geom2d::rect<float>{{24,124},{48,12}},"Back",[](MenuFuncData menu){Menu::CloseMenu();return true;})END;
|
||||
|
||||
loadGameWindow->SetupKeyboardNavigation(
|
||||
[](MenuType type){ //On Open
|
||||
if(SaveFile::GetSaveFileCount()>0){
|
||||
Menu::menus[type]->SetSelection(Component<ScrollableWindowComponent>(type,"Game Files List")->GetComponents()[0]);
|
||||
}else{
|
||||
Menu::menus[type]->SetSelection("Go Back Button");
|
||||
}
|
||||
},
|
||||
{ //Button Key
|
||||
{game->KEY_START,{"Load File",[](MenuType type){
|
||||
Menu::menus[type]->GetSelection().lock()->Click();
|
||||
}}},
|
||||
{game->KEY_SELECT,{"Return to Title Screen",[](MenuType type){
|
||||
Component<MenuComponent>(type,"Back Button")->Click();
|
||||
}}},
|
||||
}
|
||||
,{ //Button Navigation Rules
|
||||
{"Game Files List",{
|
||||
.up=[](MenuType type){
|
||||
auto&selection=Menu::menus[type]->GetSelection();
|
||||
auto&gameFilesList=Component<ScrollableWindowComponent>(type,"Game Files List")->GetComponents();
|
||||
if(std::find_if(gameFilesList.begin(),gameFilesList.end(),[&](auto&comp){return comp.lock()==selection.lock();})==gameFilesList.begin()){
|
||||
|
||||
}
|
||||
},
|
||||
.down="Back Button",}},
|
||||
{"Go Back Button",{
|
||||
.left="Continue Button",
|
||||
.right="Continue Button",}},
|
||||
});
|
||||
}
|
@ -82,18 +82,19 @@ void Menu::InitializeMainMenuWindow(){
|
||||
return true;
|
||||
})END;
|
||||
|
||||
if(SaveFile::GetSaveFileCount()>0){
|
||||
mainMenuWindow->SetDefaultButton(loadGameButton);
|
||||
}else{
|
||||
mainMenuWindow->SetDefaultButton(newGameButton);
|
||||
}
|
||||
|
||||
mainMenuWindow->SetupKeyboardNavigation(
|
||||
{
|
||||
[](MenuType type){ //On Open
|
||||
if(SaveFile::GetSaveFileCount()>0){
|
||||
Menu::menus[type]->SetSelection("Load Game Button");
|
||||
}else{
|
||||
Menu::menus[type]->SetSelection("New Game Button");
|
||||
}
|
||||
},
|
||||
{ //Button Key
|
||||
{game->KEY_CONFIRM,{"Select",[](MenuType type){}}},
|
||||
{game->KEY_BACK,{"Back",[](MenuType type){}}},
|
||||
}
|
||||
,{
|
||||
,{ //Button Navigation Rules
|
||||
{"New Game Button",{
|
||||
.up="Quit Game Button",
|
||||
.down="Load Game Button",}},
|
||||
|
@ -150,7 +150,7 @@ void Menu::CheckClickAndPerformMenuSelect(AiL*game){
|
||||
}
|
||||
|
||||
void Menu::HoverMenuSelect(AiL*game){
|
||||
if(!game->IsFocused()||selection.expired()||selection.lock()->disabled)return;
|
||||
if(!game->IsFocused()||selection.expired()||selection.lock()->disabled||selection.lock()->grayedOut)return;
|
||||
|
||||
if(selection.lock()->draggable){
|
||||
if(buttonHoldTime<"ThemeGlobal.MenuHoldTime"_F){
|
||||
@ -311,7 +311,7 @@ void Menu::Draw(AiL*game){
|
||||
|
||||
void Menu::OpenMenu(MenuType menu,bool cover){
|
||||
menus[menu]->cover=cover;
|
||||
menus[menu]->selection=menus[menu]->defaultButton;
|
||||
menus[menu]->onOpenFunc(menu);
|
||||
stack.push_back(menus[menu]);
|
||||
}
|
||||
|
||||
@ -324,6 +324,10 @@ void Menu::KeyboardButtonNavigation(AiL*game,vf2d menuPos){
|
||||
|
||||
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.
|
||||
selectionButtonName=selection.lock()->parentComponent.lock()->GetName();
|
||||
}
|
||||
|
||||
if(navigationGroups.count(selectionButtonName)){
|
||||
Navigation nav=navigationGroups[selectionButtonName];
|
||||
|
||||
@ -613,7 +617,8 @@ void Menu::SetSelection(std::weak_ptr<MenuComponent>button){
|
||||
selection=button;
|
||||
}
|
||||
|
||||
void Menu::SetupKeyboardNavigation(MenuInputGroups inputGroups,ButtonNavigationGroups navigationGroups){
|
||||
void Menu::SetupKeyboardNavigation(MenuDataFunc onOpen,MenuInputGroups inputGroups,ButtonNavigationGroups navigationGroups){
|
||||
this->onOpenFunc=onOpen;
|
||||
this->inputGroups=inputGroups;
|
||||
this->navigationGroups=navigationGroups;
|
||||
}
|
||||
@ -621,3 +626,8 @@ void Menu::SetupKeyboardNavigation(MenuInputGroups inputGroups,ButtonNavigationG
|
||||
const std::weak_ptr<MenuComponent>Menu::GetSelection()const{
|
||||
return selection;
|
||||
}
|
||||
|
||||
|
||||
void Menu::SetSelection(std::string_view button){
|
||||
selection=Component<MenuComponent>(type,button);
|
||||
}
|
@ -141,7 +141,6 @@ class Menu:public IAttributable{
|
||||
friend class EntityStats;
|
||||
|
||||
float buttonHoldTime=0;
|
||||
std::weak_ptr<MenuComponent>selection;
|
||||
vi2d lastActiveMousePos={};
|
||||
int componentCount=0;
|
||||
|
||||
@ -217,12 +216,11 @@ public:
|
||||
static Renderable&GetPatchPart(int x,int y);
|
||||
void RecalculateComponentCount();
|
||||
|
||||
void SetDefaultButton(std::weak_ptr<MenuComponent>button);
|
||||
void SetSelection(std::string_view 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;
|
||||
static MenuType lastMenuTypeCreated;
|
||||
static std::string lastRegisteredComponent;
|
||||
void HoverMenuSelect(AiL*game);
|
||||
@ -231,7 +229,7 @@ private:
|
||||
//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 SetupKeyboardNavigation(MenuDataFunc onOpen,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);
|
||||
@ -245,6 +243,7 @@ private:
|
||||
MenuType type;
|
||||
MenuInputGroups inputGroups;
|
||||
ButtonNavigationGroups navigationGroups;
|
||||
MenuOpenFunc onOpenFunc;
|
||||
|
||||
static bool MOUSE_NAVIGATION;
|
||||
bool cover; //A black cover for when a menu pops up to fade out the stuff behind it.
|
||||
|
@ -55,15 +55,18 @@ void Menu::InitializeSaveFileWindow(){
|
||||
|
||||
|
||||
saveFileWindow->SetupKeyboardNavigation(
|
||||
{
|
||||
{game->KEY_START,{"Confirm Name",[](MenuType type){
|
||||
[](MenuType type){ //On Open
|
||||
Menu::menus[type]->SetSelection("Continue Button");
|
||||
},
|
||||
{ //Button Key
|
||||
{game->KEY_START,{"Confirm Filename",[](MenuType type){
|
||||
Component<MenuComponent>(type,"Continue Button")->Click();
|
||||
}}},
|
||||
{game->KEY_SELECT,{"Return to Title Screen",[](MenuType type){
|
||||
Component<MenuComponent>(type,"Back Button")->Click();
|
||||
}}},
|
||||
}
|
||||
,{
|
||||
,{ //Button Navigation Rules
|
||||
{"Continue Button",{
|
||||
.left="Back Button",
|
||||
.right="Back Button",}},
|
||||
|
Loading…
x
Reference in New Issue
Block a user