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:
@@ -39,8 +39,8 @@ namespace OpenRA.Mods.Cnc.Widgets.Logic
|
||||
public CncIngameChromeLogic(Widget widget, World world)
|
||||
{
|
||||
this.world = world;
|
||||
world.WorldActor.Trait<CncMenuPaletteEffect>()
|
||||
.Fade(CncMenuPaletteEffect.EffectType.None);
|
||||
world.WorldActor.Trait<MenuPaletteEffect>()
|
||||
.Fade(MenuPaletteEffect.EffectType.None);
|
||||
|
||||
ingameRoot = widget.Get("INGAME_ROOT");
|
||||
var playerRoot = ingameRoot.Get("PLAYER_ROOT");
|
||||
|
||||
@@ -11,6 +11,7 @@
|
||||
using System;
|
||||
using System.Linq;
|
||||
using OpenRA.Graphics;
|
||||
using OpenRA.Mods.RA;
|
||||
using OpenRA.Traits;
|
||||
using OpenRA.Widgets;
|
||||
|
||||
@@ -27,8 +28,8 @@ namespace OpenRA.Mods.Cnc.Widgets.Logic
|
||||
{
|
||||
var resumeDisabled = false;
|
||||
menu = widget.Get("INGAME_MENU");
|
||||
var mpe = world.WorldActor.Trait<CncMenuPaletteEffect>();
|
||||
mpe.Fade(CncMenuPaletteEffect.EffectType.Desaturated);
|
||||
var mpe = world.WorldActor.Trait<MenuPaletteEffect>();
|
||||
mpe.Fade(MenuPaletteEffect.EffectType.Desaturated);
|
||||
|
||||
menu.Get<LabelWidget>("VERSION_LABEL").Text = Game.modData.Manifest.Mod.Version;
|
||||
|
||||
@@ -40,7 +41,7 @@ namespace OpenRA.Mods.Cnc.Widgets.Logic
|
||||
{
|
||||
Sound.PlayNotification(null, "Speech", "Leave", null);
|
||||
resumeDisabled = true;
|
||||
Game.RunAfterDelay(1200, () => mpe.Fade(CncMenuPaletteEffect.EffectType.Black));
|
||||
Game.RunAfterDelay(1200, () => mpe.Fade(MenuPaletteEffect.EffectType.Black));
|
||||
Game.RunAfterDelay(1200 + 40 * mpe.Info.FadeLength, () =>
|
||||
{
|
||||
Game.Disconnect();
|
||||
@@ -86,7 +87,7 @@ namespace OpenRA.Mods.Cnc.Widgets.Logic
|
||||
{
|
||||
Ui.CloseWindow();
|
||||
Ui.Root.RemoveChild(menu);
|
||||
world.WorldActor.Trait<CncMenuPaletteEffect>().Fade(CncMenuPaletteEffect.EffectType.None);
|
||||
world.WorldActor.Trait<MenuPaletteEffect>().Fade(MenuPaletteEffect.EffectType.None);
|
||||
onExit();
|
||||
};
|
||||
|
||||
|
||||
30
OpenRA.Mods.Cnc/Widgets/Logic/CncMainMenuLogic.cs
Normal file
30
OpenRA.Mods.Cnc/Widgets/Logic/CncMainMenuLogic.cs
Normal file
@@ -0,0 +1,30 @@
|
||||
#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 OpenRA.Mods.RA.Widgets.Logic;
|
||||
using OpenRA.Widgets;
|
||||
|
||||
namespace OpenRA.Mods.Cnc.Widgets.Logic
|
||||
{
|
||||
public class CncMainMenuLogic : MainMenuLogic
|
||||
{
|
||||
[ObjectCreator.UseCtor]
|
||||
public CncMainMenuLogic(Widget widget, World world)
|
||||
: base(widget, world)
|
||||
{
|
||||
var shellmapDecorations = widget.Get("SHELLMAP_DECORATIONS");
|
||||
shellmapDecorations.IsVisible = () => menuType != MenuType.None && Game.Settings.Game.ShowShellmap;
|
||||
shellmapDecorations.Get<ImageWidget>("RECBLOCK").IsVisible = () => world.FrameNumber / 25 % 2 == 0;
|
||||
|
||||
var shellmapDisabledDecorations = widget.Get("SHELLMAP_DISABLED_DECORATIONS");
|
||||
shellmapDisabledDecorations.IsVisible = () => !Game.Settings.Game.ShowShellmap;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,152 +0,0 @@
|
||||
#region Copyright & License Information
|
||||
/*
|
||||
* Copyright 2007-2011 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.Mods.RA.Widgets.Logic;
|
||||
using OpenRA.Widgets;
|
||||
|
||||
namespace OpenRA.Mods.Cnc.Widgets.Logic
|
||||
{
|
||||
public class CncMenuLogic
|
||||
{
|
||||
enum MenuType { Main, Multiplayer, Settings, None }
|
||||
|
||||
MenuType menuType = MenuType.Main;
|
||||
Widget rootMenu;
|
||||
|
||||
[ObjectCreator.UseCtor]
|
||||
public CncMenuLogic(Widget widget, World world)
|
||||
{
|
||||
world.WorldActor.Trait<CncMenuPaletteEffect>()
|
||||
.Fade(CncMenuPaletteEffect.EffectType.Desaturated);
|
||||
|
||||
rootMenu = widget.Get("MENU_BACKGROUND");
|
||||
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>("SOLO_BUTTON").OnClick = StartSkirmishGame;
|
||||
mainMenu.Get<ButtonWidget>("MULTIPLAYER_BUTTON").OnClick = () => menuType = MenuType.Multiplayer;
|
||||
|
||||
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.Settings;
|
||||
mainMenu.Get<ButtonWidget>("QUIT_BUTTON").OnClick = Game.Exit;
|
||||
|
||||
// Multiplayer menu
|
||||
var multiplayerMenu = widget.Get("MULTIPLAYER_MENU");
|
||||
multiplayerMenu.IsVisible = () => menuType == MenuType.Multiplayer;
|
||||
|
||||
multiplayerMenu.Get<ButtonWidget>("BACK_BUTTON").OnClick = () => menuType = MenuType.Main;
|
||||
multiplayerMenu.Get<ButtonWidget>("JOIN_BUTTON").OnClick = () => OpenGamePanel("SERVERBROWSER_PANEL");
|
||||
multiplayerMenu.Get<ButtonWidget>("CREATE_BUTTON").OnClick = () => OpenGamePanel("CREATESERVER_PANEL");
|
||||
multiplayerMenu.Get<ButtonWidget>("DIRECTCONNECT_BUTTON").OnClick = () => OpenGamePanel("DIRECTCONNECT_PANEL");
|
||||
|
||||
// Settings menu
|
||||
var settingsMenu = widget.Get("SETTINGS_MENU");
|
||||
settingsMenu.IsVisible = () => menuType == MenuType.Settings;
|
||||
|
||||
settingsMenu.Get<ButtonWidget>("REPLAYS_BUTTON").OnClick = () =>
|
||||
{
|
||||
menuType = MenuType.None;
|
||||
Ui.OpenWindow("REPLAYBROWSER_PANEL", new WidgetArgs()
|
||||
{
|
||||
{ "onExit", () => menuType = MenuType.Settings },
|
||||
{ "onStart", RemoveShellmapUI }
|
||||
});
|
||||
};
|
||||
|
||||
settingsMenu.Get<ButtonWidget>("MUSIC_BUTTON").OnClick = () =>
|
||||
{
|
||||
menuType = MenuType.None;
|
||||
Ui.OpenWindow("MUSIC_PANEL", new WidgetArgs()
|
||||
{
|
||||
{ "onExit", () => menuType = MenuType.Settings },
|
||||
});
|
||||
};
|
||||
|
||||
settingsMenu.Get<ButtonWidget>("CREDITS_BUTTON").OnClick = () =>
|
||||
{
|
||||
menuType = MenuType.None;
|
||||
Ui.OpenWindow("CREDITS_PANEL", new WidgetArgs()
|
||||
{
|
||||
{ "onExit", () => menuType = MenuType.Settings },
|
||||
});
|
||||
};
|
||||
|
||||
settingsMenu.Get<ButtonWidget>("SETTINGS_BUTTON").OnClick = () =>
|
||||
{
|
||||
menuType = MenuType.None;
|
||||
Game.OpenWindow("SETTINGS_PANEL", new WidgetArgs()
|
||||
{
|
||||
{ "onExit", () => menuType = MenuType.Settings },
|
||||
});
|
||||
};
|
||||
|
||||
settingsMenu.Get<ButtonWidget>("BACK_BUTTON").OnClick = () => menuType = MenuType.Main;
|
||||
|
||||
var shellmapDecorations = widget.Get("SHELLMAP_DECORATIONS");
|
||||
shellmapDecorations.IsVisible = () => menuType != MenuType.None && Game.Settings.Game.ShowShellmap;
|
||||
shellmapDecorations.Get<ImageWidget>("RECBLOCK").IsVisible = () => world.FrameNumber / 25 % 2 == 0;
|
||||
|
||||
var shellmapDisabledDecorations = widget.Get("SHELLMAP_DISABLED_DECORATIONS");
|
||||
shellmapDisabledDecorations.IsVisible = () => !Game.Settings.Game.ShowShellmap;
|
||||
}
|
||||
|
||||
void OpenGamePanel(string id)
|
||||
{
|
||||
menuType = MenuType.None;
|
||||
Ui.OpenWindow(id, new WidgetArgs()
|
||||
{
|
||||
{ "onExit", () => menuType = MenuType.Multiplayer },
|
||||
{ "openLobby", () => OpenLobbyPanel(MenuType.Multiplayer, false) }
|
||||
});
|
||||
}
|
||||
|
||||
void RemoveShellmapUI()
|
||||
{
|
||||
rootMenu.Parent.RemoveChild(rootMenu);
|
||||
}
|
||||
|
||||
void OpenLobbyPanel(MenuType menu, bool addBots)
|
||||
{
|
||||
menuType = MenuType.None;
|
||||
Game.OpenWindow("SERVER_LOBBY", new WidgetArgs()
|
||||
{
|
||||
{ "onExit", () => { Game.Disconnect(); menuType = menu; } },
|
||||
{ "onStart", RemoveShellmapUI },
|
||||
{ "addBots", addBots }
|
||||
});
|
||||
}
|
||||
|
||||
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),
|
||||
"",
|
||||
() => OpenLobbyPanel(MenuType.Main, true),
|
||||
() => { Game.CloseServer(); menuType = MenuType.Main; });
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user