fixed remove/hide main-menu when sub-menus are closed

This commit is contained in:
Matthias Mailänder
2013-04-25 18:01:16 +02:00
committed by Scott_NZ
parent 3ce68d2f7d
commit 4470d67617
3 changed files with 43 additions and 9 deletions

View File

@@ -14,33 +14,62 @@ namespace OpenRA.Mods.RA.Widgets.Logic
{
public class MainMenuButtonsLogic
{
enum MenuType { Main, None }
MenuType Menu = MenuType.Main;
Widget rootMenu;
[ObjectCreator.UseCtor]
public MainMenuButtonsLogic(Widget widget)
{
rootMenu = widget;
rootMenu.IsVisible = () => Menu == MenuType.Main;
Game.modData.WidgetLoader.LoadWidget( new WidgetArgs(), Ui.Root, "PERF_BG" );
widget.Get<ButtonWidget>("MAINMENU_BUTTON_JOIN").OnClick = () => OpenGamePanel("JOINSERVER_BG");
widget.Get<ButtonWidget>("MAINMENU_BUTTON_CREATE").OnClick = () => OpenGamePanel("CREATESERVER_BG");
widget.Get<ButtonWidget>("MAINMENU_BUTTON_DIRECTCONNECT").OnClick = () => OpenGamePanel("DIRECTCONNECT_BG");
widget.Get<ButtonWidget>("MAINMENU_BUTTON_SETTINGS").OnClick = () => Ui.OpenWindow("SETTINGS_MENU");
widget.Get<ButtonWidget>("MAINMENU_BUTTON_MUSIC").OnClick = () => Ui.OpenWindow("MUSIC_MENU");
widget.Get<ButtonWidget>("MAINMENU_BUTTON_SETTINGS").OnClick = () =>
{
Menu = MenuType.None;
Ui.OpenWindow("SETTINGS_MENU", new WidgetArgs()
{
{ "onExit", () => Menu = MenuType.Main }
});
};
widget.Get<ButtonWidget>("MAINMENU_BUTTON_MUSIC").OnClick = () =>
{
Menu = MenuType.None;
Ui.OpenWindow("MUSIC_MENU", new WidgetArgs()
{
{ "onExit", () => Menu = MenuType.Main }
});
};
widget.Get<ButtonWidget>("MAINMENU_BUTTON_MODS").OnClick = () =>
{
Menu = MenuType.None;
Ui.OpenWindow("MODS_PANEL", new WidgetArgs()
{
{ "onExit", () => {} },
{ "onExit", () => Menu = MenuType.Main },
{ "onSwitch", RemoveShellmapUI }
});
};
widget.Get<ButtonWidget>("MAINMENU_BUTTON_REPLAY_VIEWER").OnClick = () =>
{
Menu = MenuType.None;
Ui.OpenWindow("REPLAYBROWSER_BG", new WidgetArgs()
{
{ "onExit", () => {} },
{ "onExit", () => Menu = MenuType.Main },
{ "onStart", RemoveShellmapUI }
});
};
widget.Get<ButtonWidget>("MAINMENU_BUTTON_QUIT").OnClick = () => Game.Exit();
}
@@ -51,18 +80,20 @@ namespace OpenRA.Mods.RA.Widgets.Logic
void OpenGamePanel(string id)
{
Menu = MenuType.None;
Ui.OpenWindow(id, new WidgetArgs()
{
{ "onExit", () => {} },
{ "onExit", () => Menu = MenuType.Main },
{ "openLobby", () => OpenLobbyPanel() }
});
}
void OpenLobbyPanel()
{
Menu = MenuType.None;
Game.OpenWindow("SERVER_LOBBY", new WidgetArgs()
{
{ "onExit", () => { Game.Disconnect(); } },
{ "onExit", () => { Game.Disconnect(); Menu = MenuType.Main; } },
{ "onStart", RemoveShellmapUI },
{ "addBots", false }
});

View File

@@ -32,7 +32,8 @@ namespace OpenRA.Mods.RA.Widgets.Logic
() => Play( Game.Settings.Sound.Repeat ? CurrentSong : GetNextSong() ));
}
public MusicPlayerLogic()
[ObjectCreator.UseCtor]
public MusicPlayerLogic(Action onExit)
{
bg = Ui.Root.Get("MUSIC_MENU");
CurrentSong = GetNextSong();
@@ -41,7 +42,7 @@ namespace OpenRA.Mods.RA.Widgets.Logic
bg.Get( "BUTTON_PLAY" ).IsVisible = () => !Sound.MusicPlaying;
bg.Get<ButtonWidget>("BUTTON_CLOSE").OnClick =
() => { Game.Settings.Save(); Ui.CloseWindow(); };
() => { Game.Settings.Save(); Ui.CloseWindow(); onExit(); };
bg.Get("BUTTON_INSTALL").IsVisible = () => false;

View File

@@ -21,7 +21,8 @@ namespace OpenRA.Mods.RA.Widgets.Logic
{
Widget bg;
public SettingsMenuLogic()
[ObjectCreator.UseCtor]
public SettingsMenuLogic(Action onExit)
{
bg = Ui.Root.Get<BackgroundWidget>("SETTINGS_MENU");
var tabs = bg.Get<ContainerWidget>("TAB_CONTAINER");
@@ -247,6 +248,7 @@ namespace OpenRA.Mods.RA.Widgets.Logic
int.TryParse(maxFrameRate.Text, out gs.MaxFramerate);
Game.Settings.Save();
Ui.CloseWindow();
onExit();
};
}