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,88 +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.Collections.Generic;
using System.Drawing;
using OpenRA.FileFormats;
using OpenRA.Graphics;
using OpenRA.Traits;
namespace OpenRA.Mods.Cnc
{
public class CncMenuPaletteEffectInfo : ITraitInfo
{
public readonly int FadeLength = 10;
public object Create(ActorInitializer init) { return new CncMenuPaletteEffect(this); }
}
public class CncMenuPaletteEffect : IPaletteModifier, ITickRender
{
public enum EffectType { None, Black, Desaturated }
public readonly CncMenuPaletteEffectInfo Info;
int remainingFrames;
EffectType from = EffectType.Black;
EffectType to = EffectType.Black;
public CncMenuPaletteEffect(CncMenuPaletteEffectInfo info) { Info = info; }
public void Fade(EffectType type)
{
remainingFrames = Info.FadeLength;
from = to;
to = type;
}
public void TickRender(WorldRenderer wr, Actor self)
{
if (remainingFrames > 0)
remainingFrames--;
}
Color ColorForEffect(EffectType t, Color orig)
{
switch (t)
{
case EffectType.Black:
return Color.FromArgb(orig.A, Color.Black);
case EffectType.Desaturated:
var lum = (int)(255 * orig.GetBrightness());
return Color.FromArgb(orig.A, lum, lum, lum);
default:
case EffectType.None:
return orig;
}
}
public void AdjustPalette(Dictionary<string, Palette> palettes)
{
if (to == EffectType.None && remainingFrames == 0)
return;
foreach (var pal in palettes)
{
for (var x = 0; x < 256; x++)
{
var orig = pal.Value.GetColor(x);
var t = ColorForEffect(to, orig);
if (remainingFrames == 0)
pal.Value.SetColor(x, t);
else
{
var f = ColorForEffect(from, orig);
pal.Value.SetColor(x, Exts.ColorLerp((float)remainingFrames / Info.FadeLength, t, f));
}
}
}
}
}
}

View File

@@ -74,7 +74,6 @@
<ItemGroup>
<Compile Include="Activities\HarvesterDockSequence.cs" />
<Compile Include="CncLoadScreen.cs" />
<Compile Include="CncMenuPaletteEffect.cs" />
<Compile Include="Effects\IonCannon.cs" />
<Compile Include="IonCannonPower.cs" />
<Compile Include="PoisonedByTiberium.cs" />
@@ -90,7 +89,7 @@
<Compile Include="Widgets\Logic\CncIngameChromeLogic.cs" />
<Compile Include="Widgets\Logic\CncIngameMenuLogic.cs" />
<Compile Include="Widgets\Logic\CncInstallFromCDLogic.cs" />
<Compile Include="Widgets\Logic\CncMenuLogic.cs" />
<Compile Include="Widgets\Logic\CncMainMenuLogic.cs" />
<Compile Include="Widgets\Logic\ProductionTooltipLogic.cs" />
<Compile Include="Widgets\Logic\SupportPowerTooltipLogic.cs" />
<Compile Include="Widgets\ProductionPaletteWidget.cs" />

View File

@@ -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");

View File

@@ -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();
};

View 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;
}
}
}

View File

@@ -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; });
}
}
}