Unify ra and cnc main menu logic and clean up the main menus.

Move a bunch of buttons into an Extras submenu and the server browser.
Move CncMenuPaletteEffect to ra so it can be used elsewhere and rename it to MenuPaletteEffect.
This commit is contained in:
ScottNZ
2014-01-31 23:29:59 +13:00
parent 81ec978a61
commit 1a3ec26a1e
25 changed files with 577 additions and 601 deletions

View File

@@ -1,133 +0,0 @@
#region Copyright & License Information
/*
* Copyright 2007-2013 The OpenRA Developers (see AUTHORS)
* This file is part of OpenRA, which is free software. It is made
* available to you under the terms of the GNU General Public License
* as published by the Free Software Foundation. For more information,
* see COPYING.
*/
#endregion
using OpenRA.Widgets;
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;
var versionLabel = Ui.Root.GetOrNull<LabelWidget>("VERSION_LABEL");
if (versionLabel != null)
versionLabel.Text = Game.modData.Manifest.Mod.Version;
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 = () =>
{
Menu = MenuType.None;
Game.OpenWindow("SETTINGS_PANEL", new WidgetArgs()
{
{ "onExit", () => Menu = MenuType.Main }
});
};
widget.Get<ButtonWidget>("MAINMENU_BUTTON_MUSIC").OnClick = () =>
{
Menu = MenuType.None;
Ui.OpenWindow("MUSIC_PANEL", new WidgetArgs()
{
{ "onExit", () => Menu = MenuType.Main }
});
};
widget.Get<ButtonWidget>("MAINMENU_BUTTON_MODS").OnClick = () =>
{
Menu = MenuType.None;
Ui.OpenWindow("MODS_PANEL", new WidgetArgs()
{
{ "onExit", () => Menu = MenuType.Main },
{ "onSwitch", RemoveShellmapUI }
});
};
widget.Get<ButtonWidget>("MAINMENU_BUTTON_CREDITS").OnClick = () =>
{
Menu = MenuType.None;
Ui.OpenWindow("CREDITS_PANEL", new WidgetArgs()
{
{ "onExit", () => Menu = MenuType.Main },
});
};
widget.Get<ButtonWidget>("MAINMENU_BUTTON_REPLAY_VIEWER").OnClick = () =>
{
Menu = MenuType.None;
Ui.OpenWindow("REPLAYBROWSER_BG", new WidgetArgs()
{
{ "onExit", () => Menu = MenuType.Main },
{ "onStart", RemoveShellmapUI }
});
};
var assetBrowserButton = widget.Get<ButtonWidget>("MAINMENU_BUTTON_ASSET_BROWSER");
assetBrowserButton.OnClick = () =>
{
Menu = MenuType.None;
Game.OpenWindow("ASSETBROWSER_BG", new WidgetArgs()
{
{ "onExit", () => Menu = MenuType.Main }
});
};
var quitButton = widget.Get<ButtonWidget>("MAINMENU_BUTTON_QUIT");
quitButton.OnClick = () => Game.Exit();
// Hide developer-specific buttons
if (Game.Settings.Debug.DeveloperMenu == false)
{
assetBrowserButton.IsVisible = () => false;
var offset = assetBrowserButton.Bounds.Y - quitButton.Bounds.Y;
quitButton.Bounds.Y += offset;
rootMenu.Bounds.Height += offset;
rootMenu.Bounds.Y -= offset/2;
}
}
void RemoveShellmapUI()
{
rootMenu.Parent.RemoveChild(rootMenu);
}
void OpenGamePanel(string id)
{
Menu = MenuType.None;
Ui.OpenWindow(id, new WidgetArgs()
{
{ "onExit", () => Menu = MenuType.Main },
{ "openLobby", () => OpenLobbyPanel() }
});
}
void OpenLobbyPanel()
{
Menu = MenuType.None;
Game.OpenWindow("SERVER_LOBBY", new WidgetArgs()
{
{ "onExit", () => { Game.Disconnect(); Menu = MenuType.Main; } },
{ "onStart", RemoveShellmapUI },
{ "addBots", false }
});
}
}
}

View File

@@ -0,0 +1,143 @@
#region Copyright & License Information
/*
* Copyright 2007-2014 The OpenRA Developers (see AUTHORS)
* This file is part of OpenRA, which is free software. It is made
* available to you under the terms of the GNU General Public License
* as published by the Free Software Foundation. For more information,
* see COPYING.
*/
#endregion
using System.Net;
using OpenRA.Widgets;
namespace OpenRA.Mods.RA.Widgets.Logic
{
public class MainMenuLogic
{
protected enum MenuType { Main, Extras, None }
protected MenuType menuType = MenuType.Main;
Widget rootMenu;
[ObjectCreator.UseCtor]
public MainMenuLogic(Widget widget, World world)
{
rootMenu = widget;
rootMenu.Get<LabelWidget>("VERSION_LABEL").Text = Game.modData.Manifest.Mod.Version;
// Menu buttons
var mainMenu = widget.Get("MAIN_MENU");
mainMenu.IsVisible = () => menuType == MenuType.Main;
mainMenu.Get<ButtonWidget>("SINGLEPLAYER_BUTTON").OnClick = StartSkirmishGame;
mainMenu.Get<ButtonWidget>("MULTIPLAYER_BUTTON").OnClick = () =>
{
menuType = MenuType.None;
Ui.OpenWindow("SERVERBROWSER_PANEL", new WidgetArgs
{
{ "onStart", RemoveShellmapUI },
{ "onExit", () => menuType = MenuType.Main }
});
};
mainMenu.Get<ButtonWidget>("MODS_BUTTON").OnClick = () =>
{
menuType = MenuType.None;
Ui.OpenWindow("MODS_PANEL", new WidgetArgs
{
{ "onExit", () => menuType = MenuType.Main },
{ "onSwitch", RemoveShellmapUI }
});
};
mainMenu.Get<ButtonWidget>("SETTINGS_BUTTON").OnClick = () =>
{
menuType = MenuType.None;
Game.OpenWindow("SETTINGS_PANEL", new WidgetArgs
{
{ "onExit", () => menuType = MenuType.Main }
});
};
mainMenu.Get<ButtonWidget>("EXTRAS_BUTTON").OnClick = () => menuType = MenuType.Extras;
mainMenu.Get<ButtonWidget>("QUIT_BUTTON").OnClick = Game.Exit;
// Extras menu
var extrasMenu = widget.Get("EXTRAS_MENU");
extrasMenu.IsVisible = () => menuType == MenuType.Extras;
extrasMenu.Get<ButtonWidget>("REPLAYS_BUTTON").OnClick = () =>
{
menuType = MenuType.None;
Ui.OpenWindow("REPLAYBROWSER_PANEL", new WidgetArgs
{
{ "onExit", () => menuType = MenuType.Extras },
{ "onStart", RemoveShellmapUI }
});
};
extrasMenu.Get<ButtonWidget>("MUSIC_BUTTON").OnClick = () =>
{
menuType = MenuType.None;
Ui.OpenWindow("MUSIC_PANEL", new WidgetArgs
{
{ "onExit", () => menuType = MenuType.Extras },
});
};
var assetBrowserButton = extrasMenu.GetOrNull<ButtonWidget>("ASSETBROWSER_BUTTON");
if (assetBrowserButton != null)
assetBrowserButton.OnClick = () =>
{
menuType = MenuType.None;
Game.OpenWindow("ASSETBROWSER_PANEL", new WidgetArgs
{
{ "onExit", () => menuType = MenuType.Extras },
});
};
extrasMenu.Get<ButtonWidget>("CREDITS_BUTTON").OnClick = () =>
{
menuType = MenuType.None;
Ui.OpenWindow("CREDITS_PANEL", new WidgetArgs
{
{ "onExit", () => menuType = MenuType.Extras },
});
};
extrasMenu.Get<ButtonWidget>("BACK_BUTTON").OnClick = () => menuType = MenuType.Main;
}
void RemoveShellmapUI()
{
rootMenu.Parent.RemoveChild(rootMenu);
}
void OpenSkirmishLobbyPanel()
{
menuType = MenuType.None;
Game.OpenWindow("SERVER_LOBBY", new WidgetArgs
{
{ "onExit", () => { Game.Disconnect(); menuType = MenuType.Main; } },
{ "onStart", RemoveShellmapUI },
{ "addBots", true }
});
}
void StartSkirmishGame()
{
var map = WidgetUtils.ChooseInitialMap(Game.Settings.Server.Map);
Game.Settings.Server.Map = map;
Game.Settings.Save();
ConnectionLogic.Connect(IPAddress.Loopback.ToString(),
Game.CreateLocalServer(map),
"",
OpenSkirmishLobbyPanel,
() => { Game.CloseServer(); menuType = MenuType.Main; });
}
}
}

View File

@@ -23,8 +23,9 @@ namespace OpenRA.Mods.RA.Widgets.Logic
{
GameServer currentServer;
ScrollItemWidget serverTemplate;
Action OpenLobby;
Action OnExit;
Action onStart;
Action onExit;
enum SearchStatus { Fetching, Failed, NoGames, Hidden }
SearchStatus searchStatus = SearchStatus.Fetching;
@@ -38,19 +39,20 @@ namespace OpenRA.Mods.RA.Widgets.Logic
{
switch (searchStatus)
{
case SearchStatus.Fetching: return "Fetching game list...";
case SearchStatus.Failed: return "Failed to contact master server.";
case SearchStatus.NoGames: return "No games found.";
default: return "";
case SearchStatus.Fetching: return "Fetching game list...";
case SearchStatus.Failed: return "Failed to contact master server.";
case SearchStatus.NoGames: return "No games found.";
default: return "";
}
}
[ObjectCreator.UseCtor]
public ServerBrowserLogic(Widget widget, Action openLobby, Action onExit)
public ServerBrowserLogic(Widget widget, Action onStart, Action onExit)
{
var panel = widget;
OpenLobby = openLobby;
OnExit = onExit;
this.onStart = onStart;
this.onExit = onExit;
var sl = panel.Get<ScrollPanelWidget>("SERVER_LIST");
// Menu buttons
@@ -58,6 +60,9 @@ namespace OpenRA.Mods.RA.Widgets.Logic
refreshButton.IsDisabled = () => searchStatus == SearchStatus.Fetching;
refreshButton.OnClick = () => ServerList.Query(games => RefreshServerList(panel, games));
panel.Get<ButtonWidget>("DIRECTCONNECT_BUTTON").OnClick = OpenDirectConnectPanel;
panel.Get<ButtonWidget>("CREATE_BUTTON").OnClick = OpenCreateServerPanel;
var join = panel.Get<ButtonWidget>("JOIN_BUTTON");
join.IsDisabled = () => currentServer == null || !currentServer.CanJoin();
join.OnClick = () => Join(currentServer);
@@ -106,6 +111,34 @@ namespace OpenRA.Mods.RA.Widgets.Logic
ServerList.Query(games => RefreshServerList(panel, games));
}
void OpenLobby()
{
Game.OpenWindow("SERVER_LOBBY", new WidgetArgs
{
{ "onExit", Game.Disconnect },
{ "onStart", onStart },
{ "addBots", false }
});
}
void OpenDirectConnectPanel()
{
Ui.OpenWindow("DIRECTCONNECT_PANEL", new WidgetArgs
{
{ "openLobby", OpenLobby },
{ "onExit", () => { } }
});
}
void OpenCreateServerPanel()
{
Ui.OpenWindow("CREATESERVER_PANEL", new WidgetArgs
{
{ "openLobby", OpenLobby },
{ "onExit", () => { } }
});
}
void Join(GameServer server)
{
if (server == null || !server.CanJoin())
@@ -114,8 +147,7 @@ namespace OpenRA.Mods.RA.Widgets.Logic
var host = server.Address.Split(':')[0];
var port = int.Parse(server.Address.Split(':')[1]);
Ui.CloseWindow();
ConnectionLogic.Connect(host, port, "", OpenLobby, OnExit);
ConnectionLogic.Connect(host, port, "", OpenLobby, onExit);
}
string GetPlayersLabel(GameServer game)
@@ -164,10 +196,10 @@ namespace OpenRA.Mods.RA.Widgets.Logic
{
if ((game.State == (int)ServerState.GameStarted) && !showStarted)
return true;
if ((game.State == (int)ServerState.WaitingPlayers) && !showWaiting)
return true;
if ((game.Players == 0) && !showEmpty)
return true;
@@ -230,7 +262,7 @@ namespace OpenRA.Mods.RA.Widgets.Logic
var state = item.Get<LabelWidget>("STATE");
state.GetText = () => GetStateLabel(game);
var ip = item.Get<LabelWidget>("IP");
ip.GetText = () => game.Address;

View File

@@ -356,7 +356,6 @@ namespace OpenRA.Mods.RA.Widgets.Logic
BindCheckboxPref(panel, "PERFGRAPH_CHECKBOX", ds, "PerfGraph");
BindCheckboxPref(panel, "CHECKUNSYNCED_CHECKBOX", ds, "SanityCheckUnsyncedCode");
BindCheckboxPref(panel, "BOTDEBUG_CHECKBOX", ds, "BotDebug");
BindCheckboxPref(panel, "DEVELOPER_MENU_CHECKBOX", ds, "DeveloperMenu");
BindCheckboxPref(panel, "CRASH_DIALOG_CHECKBOX", ds, "ShowFatalErrorDialog");
return () => { };
@@ -377,7 +376,6 @@ namespace OpenRA.Mods.RA.Widgets.Logic
ds.PerfGraph = dds.PerfGraph;
ds.SanityCheckUnsyncedCode = dds.SanityCheckUnsyncedCode;
ds.BotDebug = dds.BotDebug;
ds.DeveloperMenu = dds.DeveloperMenu;
ds.ShowFatalErrorDialog = dds.ShowFatalErrorDialog;
};
}

View File

@@ -0,0 +1,23 @@
#region Copyright & License Information
/*
* Copyright 2007-2014 The OpenRA Developers (see AUTHORS)
* This file is part of OpenRA, which is free software. It is made
* available to you under the terms of the GNU General Public License
* as published by the Free Software Foundation. For more information,
* see COPYING.
*/
#endregion
namespace OpenRA.Mods.RA.Widgets.Logic
{
public class ShellmapDesaturationLogic
{
[ObjectCreator.UseCtor]
public ShellmapDesaturationLogic(World world)
{
var paletteEffect = world.WorldActor.TraitOrDefault<MenuPaletteEffect>();
if (paletteEffect != null)
paletteEffect.Fade(MenuPaletteEffect.EffectType.Desaturated);
}
}
}