From 05eb56b1e22f4e140002438fe3374dd55cc2c5fd Mon Sep 17 00:00:00 2001 From: Paul Chote Date: Sun, 18 May 2014 18:04:36 +1200 Subject: [PATCH 1/3] Simplify MenuPaletteEffect activation. --- .../Widgets/Logic/CncIngameChromeLogic.cs | 3 --- OpenRA.Mods.RA/MenuPaletteEffect.cs | 11 ++++++++- OpenRA.Mods.RA/OpenRA.Mods.RA.csproj | 1 - .../Logic/ShellmapDesaturationLogic.cs | 23 ------------------- mods/cnc/chrome/mainmenu.yaml | 2 -- mods/cnc/maps/shellmap/map.yaml | 2 ++ 6 files changed, 12 insertions(+), 30 deletions(-) delete mode 100644 OpenRA.Mods.RA/Widgets/Logic/ShellmapDesaturationLogic.cs diff --git a/OpenRA.Mods.Cnc/Widgets/Logic/CncIngameChromeLogic.cs b/OpenRA.Mods.Cnc/Widgets/Logic/CncIngameChromeLogic.cs index 46b9c4af8f..a06607f830 100644 --- a/OpenRA.Mods.Cnc/Widgets/Logic/CncIngameChromeLogic.cs +++ b/OpenRA.Mods.Cnc/Widgets/Logic/CncIngameChromeLogic.cs @@ -28,9 +28,6 @@ namespace OpenRA.Mods.Cnc.Widgets.Logic public CncIngameChromeLogic(Widget widget, World world) { this.world = world; - world.WorldActor.Trait() - .Fade(MenuPaletteEffect.EffectType.None); - ingameRoot = widget.Get("INGAME_ROOT"); var playerRoot = ingameRoot.Get("PLAYER_ROOT"); diff --git a/OpenRA.Mods.RA/MenuPaletteEffect.cs b/OpenRA.Mods.RA/MenuPaletteEffect.cs index b9e6426077..074ed4197b 100644 --- a/OpenRA.Mods.RA/MenuPaletteEffect.cs +++ b/OpenRA.Mods.RA/MenuPaletteEffect.cs @@ -18,12 +18,16 @@ namespace OpenRA.Mods.RA { public class MenuPaletteEffectInfo : ITraitInfo { + [Desc("Time (in ticks) to fade between states")] public readonly int FadeLength = 10; + [Desc("Effect style to fade into")] + public readonly MenuPaletteEffect.EffectType Effect = MenuPaletteEffect.EffectType.None; + public object Create(ActorInitializer init) { return new MenuPaletteEffect(this); } } - public class MenuPaletteEffect : IPaletteModifier, ITickRender + public class MenuPaletteEffect : IPaletteModifier, ITickRender, IWorldLoaded { public enum EffectType { None, Black, Desaturated } public readonly MenuPaletteEffectInfo Info; @@ -84,5 +88,10 @@ namespace OpenRA.Mods.RA } } } + + public void WorldLoaded(World w, WorldRenderer wr) + { + Fade(Info.Effect); + } } } diff --git a/OpenRA.Mods.RA/OpenRA.Mods.RA.csproj b/OpenRA.Mods.RA/OpenRA.Mods.RA.csproj index 683a94eec1..6c7beaaf6b 100644 --- a/OpenRA.Mods.RA/OpenRA.Mods.RA.csproj +++ b/OpenRA.Mods.RA/OpenRA.Mods.RA.csproj @@ -411,7 +411,6 @@ - diff --git a/OpenRA.Mods.RA/Widgets/Logic/ShellmapDesaturationLogic.cs b/OpenRA.Mods.RA/Widgets/Logic/ShellmapDesaturationLogic.cs deleted file mode 100644 index cb340ad8ef..0000000000 --- a/OpenRA.Mods.RA/Widgets/Logic/ShellmapDesaturationLogic.cs +++ /dev/null @@ -1,23 +0,0 @@ -#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(); - if (paletteEffect != null) - paletteEffect.Fade(MenuPaletteEffect.EffectType.Desaturated); - } - } -} diff --git a/mods/cnc/chrome/mainmenu.yaml b/mods/cnc/chrome/mainmenu.yaml index 82d70d694e..6dbe0c17a8 100644 --- a/mods/cnc/chrome/mainmenu.yaml +++ b/mods/cnc/chrome/mainmenu.yaml @@ -3,8 +3,6 @@ Container@MENU_BACKGROUND: Height: WINDOW_BOTTOM Logic: CncMainMenuLogic Children: - Container@SHELLMAP_DESATURATION: - Logic: ShellmapDesaturationLogic Container@SHELLMAP_DECORATIONS: Children: Image@RETICLE: diff --git a/mods/cnc/maps/shellmap/map.yaml b/mods/cnc/maps/shellmap/map.yaml index d09caa5565..53db9c2490 100644 --- a/mods/cnc/maps/shellmap/map.yaml +++ b/mods/cnc/maps/shellmap/map.yaml @@ -990,6 +990,8 @@ Rules: -SpawnMPUnits: -MPStartLocations: -CrateSpawner: + MenuPaletteEffect: + Effect: Desaturated PlayMusicOnMapLoad: Music: map1 Loop: true From b3313be217f32e50f6fcdbf63cae51fbf50af038 Mon Sep 17 00:00:00 2001 From: Paul Chote Date: Sun, 18 May 2014 18:38:03 +1200 Subject: [PATCH 2/3] Remove the now-redundant CncWidgetUtils.cs --- OpenRA.Mods.Cnc/OpenRA.Mods.Cnc.csproj | 1 - OpenRA.Mods.Cnc/Widgets/CncWidgetUtils.cs | 37 ------------------- .../Widgets/Logic/CncIngameMenuLogic.cs | 5 ++- 3 files changed, 3 insertions(+), 40 deletions(-) delete mode 100644 OpenRA.Mods.Cnc/Widgets/CncWidgetUtils.cs diff --git a/OpenRA.Mods.Cnc/OpenRA.Mods.Cnc.csproj b/OpenRA.Mods.Cnc/OpenRA.Mods.Cnc.csproj index 6c0b3d50bc..ec7117f3eb 100644 --- a/OpenRA.Mods.Cnc/OpenRA.Mods.Cnc.csproj +++ b/OpenRA.Mods.Cnc/OpenRA.Mods.Cnc.csproj @@ -87,7 +87,6 @@ - diff --git a/OpenRA.Mods.Cnc/Widgets/CncWidgetUtils.cs b/OpenRA.Mods.Cnc/Widgets/CncWidgetUtils.cs deleted file mode 100644 index f95e3585cf..0000000000 --- a/OpenRA.Mods.Cnc/Widgets/CncWidgetUtils.cs +++ /dev/null @@ -1,37 +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; -using OpenRA.Widgets; - -namespace OpenRA.Mods.Cnc.Widgets -{ - public static class CncWidgetUtils - { - public static void PromptConfirmAction(string title, string text, Action onConfirm, Action onCancel) - { - var prompt = Ui.OpenWindow("CONFIRM_PROMPT"); - prompt.Get("PROMPT_TITLE").GetText = () => title; - prompt.Get("PROMPT_TEXT").GetText = () => text; - - prompt.Get("CONFIRM_BUTTON").OnClick = () => - { - Ui.CloseWindow(); - onConfirm(); - }; - - prompt.Get("CANCEL_BUTTON").OnClick = () => - { - Ui.CloseWindow(); - onCancel(); - }; - } - } -} diff --git a/OpenRA.Mods.Cnc/Widgets/Logic/CncIngameMenuLogic.cs b/OpenRA.Mods.Cnc/Widgets/Logic/CncIngameMenuLogic.cs index 40f11efcac..fc687b188b 100644 --- a/OpenRA.Mods.Cnc/Widgets/Logic/CncIngameMenuLogic.cs +++ b/OpenRA.Mods.Cnc/Widgets/Logic/CncIngameMenuLogic.cs @@ -12,6 +12,7 @@ using System; using System.Linq; using OpenRA.Graphics; using OpenRA.Mods.RA; +using OpenRA.Mods.RA.Widgets; using OpenRA.Traits; using OpenRA.Widgets; @@ -53,13 +54,13 @@ namespace OpenRA.Mods.Cnc.Widgets.Logic Action doNothing = () => { }; menu.Get("QUIT_BUTTON").OnClick = () => - CncWidgetUtils.PromptConfirmAction("Abort Mission", "Leave this game and return to the menu?", onQuit, doNothing); + ConfirmationDialogs.PromptConfirmAction("Abort Mission", "Leave this game and return to the menu?", onQuit, doNothing); Action onSurrender = () => world.IssueOrder(new Order("Surrender", world.LocalPlayer.PlayerActor, false)); var surrenderButton = menu.Get("SURRENDER_BUTTON"); surrenderButton.IsDisabled = () => (world.LocalPlayer == null || world.LocalPlayer.WinState != WinState.Undefined); surrenderButton.OnClick = () => - CncWidgetUtils.PromptConfirmAction("Surrender", "Are you sure you want to surrender?", onSurrender, doNothing); + ConfirmationDialogs.PromptConfirmAction("Surrender", "Are you sure you want to surrender?", onSurrender, doNothing); menu.Get("MUSIC_BUTTON").OnClick = () => { From cfdbc06a310744ef5712c070a995040db55d7b85 Mon Sep 17 00:00:00 2001 From: Paul Chote Date: Sun, 18 May 2014 18:09:31 +1200 Subject: [PATCH 3/3] Add fade in/out effects to RA and TS. The palette effect interacts badly with the multiplicative blending in D2K. --- OpenRA.Mods.RA/MenuPaletteEffect.cs | 3 +- .../Widgets/Logic/IngameMenuLogic.cs | 53 +++++++++---------- mods/ra/rules/world.yaml | 1 + mods/ts/rules/world.yaml | 1 + 4 files changed, 30 insertions(+), 28 deletions(-) diff --git a/OpenRA.Mods.RA/MenuPaletteEffect.cs b/OpenRA.Mods.RA/MenuPaletteEffect.cs index 074ed4197b..52b8451843 100644 --- a/OpenRA.Mods.RA/MenuPaletteEffect.cs +++ b/OpenRA.Mods.RA/MenuPaletteEffect.cs @@ -16,12 +16,13 @@ using OpenRA.Traits; namespace OpenRA.Mods.RA { + [Desc("Fades the world from/to black at the start/end of the game, and can (optionally) desaturate the world")] public class MenuPaletteEffectInfo : ITraitInfo { [Desc("Time (in ticks) to fade between states")] public readonly int FadeLength = 10; - [Desc("Effect style to fade into")] + [Desc("Effect style to fade to. Accepts values of None or Desaturated")] public readonly MenuPaletteEffect.EffectType Effect = MenuPaletteEffect.EffectType.None; public object Create(ActorInitializer init) { return new MenuPaletteEffect(this); } diff --git a/OpenRA.Mods.RA/Widgets/Logic/IngameMenuLogic.cs b/OpenRA.Mods.RA/Widgets/Logic/IngameMenuLogic.cs index 671b8fdd33..678a3ef6ec 100644 --- a/OpenRA.Mods.RA/Widgets/Logic/IngameMenuLogic.cs +++ b/OpenRA.Mods.RA/Widgets/Logic/IngameMenuLogic.cs @@ -19,11 +19,29 @@ namespace OpenRA.Mods.RA.Widgets.Logic [ObjectCreator.UseCtor] public IngameMenuLogic(Widget widget, World world, Action onExit, WorldRenderer worldRenderer) { + var resumeDisabled = false; + var mpe = world.WorldActor.TraitOrDefault(); + Action onQuit = () => { - onExit(); - LeaveGame(world); + Sound.PlayNotification(world.Map.Rules, null, "Speech", "Leave", world.LocalPlayer == null ? null : world.LocalPlayer.Country.Race); + resumeDisabled = true; + + var exitDelay = 1200; + if (mpe != null) + { + Game.RunAfterDelay(exitDelay, () => mpe.Fade(MenuPaletteEffect.EffectType.Black)); + exitDelay += 40 * mpe.Info.FadeLength; + } + + Game.RunAfterDelay(exitDelay, () => + { + Game.Disconnect(); + Ui.ResetAll(); + Game.LoadShellMap(); + }); }; + Action onSurrender = () => { world.IssueOrder(new Order("Surrender", world.LocalPlayer.PlayerActor, false)); @@ -32,22 +50,8 @@ namespace OpenRA.Mods.RA.Widgets.Logic widget.Get("DISCONNECT").OnClick = () => { - bool gameOver = world.LocalPlayer != null && world.LocalPlayer.WinState != WinState.Undefined; - - if (gameOver) - { - onQuit(); - } - else - { - widget.Visible = false; - ConfirmationDialogs.PromptConfirmAction( - "Abort Mission", - "Leave this game and return to the menu?", - onQuit, - () => widget.Visible = true, - "Abort"); - } + widget.Visible = false; + ConfirmationDialogs.PromptConfirmAction("Abort Mission", "Leave this game and return to the menu?", onQuit, () => widget.Visible = true); }; widget.Get("SETTINGS").OnClick = () => @@ -65,7 +69,10 @@ namespace OpenRA.Mods.RA.Widgets.Logic widget.Visible = false; Ui.OpenWindow("MUSIC_PANEL", new WidgetArgs { { "onExit", () => { widget.Visible = true; } } }); }; - widget.Get("RESUME").OnClick = () => onExit(); + + var resumeButton = widget.Get("RESUME"); + resumeButton.OnClick = () => onExit(); + resumeButton.IsDisabled = () => resumeDisabled; widget.Get("SURRENDER").OnClick = () => { @@ -79,13 +86,5 @@ namespace OpenRA.Mods.RA.Widgets.Logic }; widget.Get("SURRENDER").IsVisible = () => world.LocalPlayer != null && world.LocalPlayer.WinState == WinState.Undefined; } - - void LeaveGame(World world) - { - Sound.PlayNotification(world.Map.Rules, null, "Speech", "Leave", world.LocalPlayer == null ? null : world.LocalPlayer.Country.Race); - Game.Disconnect(); - Ui.CloseWindow(); - Game.LoadShellMap(); - } } } diff --git a/mods/ra/rules/world.yaml b/mods/ra/rules/world.yaml index f86e32085d..26d5a21173 100644 --- a/mods/ra/rules/world.yaml +++ b/mods/ra/rules/world.yaml @@ -8,6 +8,7 @@ World: LoadWidgetAtGameStart: Widget: INGAME_ROOT ScreenShaker: + MenuPaletteEffect: WaterPaletteRotation: ExcludePalettes: player, effect ChronoshiftPaletteEffect: diff --git a/mods/ts/rules/world.yaml b/mods/ts/rules/world.yaml index 3e346f1406..dcac7c751a 100644 --- a/mods/ts/rules/world.yaml +++ b/mods/ts/rules/world.yaml @@ -7,6 +7,7 @@ World: ActorMap: LoadWidgetAtGameStart: Widget: INGAME_ROOT + MenuPaletteEffect: BuildingInfluence: ChooseBuildTabOnSelect: PaletteFromFile@player: