"Battle control terminated"

This commit is contained in:
Paul Chote
2011-05-19 19:25:36 +12:00
parent 18c9a719ac
commit aaecd6ce92
3 changed files with 32 additions and 14 deletions

View File

@@ -15,21 +15,26 @@ using OpenRA.Traits;
namespace OpenRA.Mods.Cnc namespace OpenRA.Mods.Cnc
{ {
class CncMenuPaletteEffectInfo : TraitInfo<CncMenuPaletteEffect> { } public class CncMenuPaletteEffectInfo : ITraitInfo
{
public readonly int FadeLength = 10;
public object Create(ActorInitializer init) { return new CncMenuPaletteEffect(this); }
}
public class CncMenuPaletteEffect : IPaletteModifier, ITick public class CncMenuPaletteEffect : IPaletteModifier, ITick
{ {
public enum EffectType { None, Black, Desaturated } public enum EffectType { None, Black, Desaturated }
public readonly CncMenuPaletteEffectInfo Info;
const int effectLength = 10;
int remainingFrames;
int remainingFrames;
EffectType from = EffectType.Black; EffectType from = EffectType.Black;
EffectType to = EffectType.Black; EffectType to = EffectType.Black;
public CncMenuPaletteEffect(CncMenuPaletteEffectInfo info) { Info = info; }
public void Fade(EffectType type) public void Fade(EffectType type)
{ {
remainingFrames = effectLength; remainingFrames = Info.FadeLength;
from = to; from = to;
to = type; to = type;
} }
@@ -76,7 +81,7 @@ namespace OpenRA.Mods.Cnc
else else
{ {
var f = ColorForEffect(from, orig); var f = ColorForEffect(from, orig);
pal.Value.SetColor(x, OpenRA.Graphics.Util.Lerp((float)remainingFrames / effectLength, t, f)); pal.Value.SetColor(x, OpenRA.Graphics.Util.Lerp((float)remainingFrames / Info.FadeLength, t, f));
} }
} }
} }

View File

@@ -12,6 +12,7 @@ using System;
using System.Drawing; using System.Drawing;
using OpenRA.Mods.RA; using OpenRA.Mods.RA;
using OpenRA.Widgets; using OpenRA.Widgets;
using OpenRA.Mods.RA.Activities;
namespace OpenRA.Mods.Cnc.Widgets namespace OpenRA.Mods.Cnc.Widgets
{ {
@@ -94,23 +95,34 @@ namespace OpenRA.Mods.Cnc.Widgets
[ObjectCreator.Param] World world, [ObjectCreator.Param] World world,
[ObjectCreator.Param] Action onExit) [ObjectCreator.Param] Action onExit)
{ {
var resumeDisabled = false;
menu = widget.GetWidget("INGAME_MENU"); menu = widget.GetWidget("INGAME_MENU");
world.WorldActor.Trait<CncMenuPaletteEffect>().Fade(CncMenuPaletteEffect.EffectType.Desaturated); var mpe = world.WorldActor.Trait<CncMenuPaletteEffect>();
mpe.Fade(CncMenuPaletteEffect.EffectType.Desaturated);
bool hideButtons = false; bool hideButtons = false;
menu.GetWidget("MENU_BUTTONS").IsVisible = () => !hideButtons; menu.GetWidget("MENU_BUTTONS").IsVisible = () => !hideButtons;
// TODO: Create a mechanism to do things like this cleaner. Also needed for scripted missions
Action onQuit = () => Action onQuit = () =>
{ {
Game.DisconnectOnly(); Sound.Play("batlcon1.aud");
Widget.RootWidget.RemoveChildren(); resumeDisabled = true;
Game.LoadShellMap(); world.WorldActor.QueueActivity(new Wait(30));
world.WorldActor.QueueActivity(new CallFunc(() => mpe.Fade(CncMenuPaletteEffect.EffectType.Black)));
world.WorldActor.QueueActivity(new Wait(mpe.Info.FadeLength));
world.WorldActor.QueueActivity(new CallFunc(() =>
{
Game.DisconnectOnly();
Widget.RootWidget.RemoveChildren();
Game.LoadShellMap();
}));
}; };
Action doNothing = () => {}; Action doNothing = () => {};
menu.GetWidget<ButtonWidget>("QUIT_BUTTON").OnClick = () => menu.GetWidget<ButtonWidget>("QUIT_BUTTON").OnClick = () =>
PromptConfirmAction("Quit", "Are you sure you want to quit?", onQuit, doNothing); PromptConfirmAction("Abort Mission", "Leave this game and return to the menu?", onQuit, doNothing);
Action onSurrender = () => world.IssueOrder(new Order("Surrender", world.LocalPlayer.PlayerActor, false)); Action onSurrender = () => world.IssueOrder(new Order("Surrender", world.LocalPlayer.PlayerActor, false));
var surrenderButton = menu.GetWidget<ButtonWidget>("SURRENDER_BUTTON"); var surrenderButton = menu.GetWidget<ButtonWidget>("SURRENDER_BUTTON");
@@ -137,7 +149,9 @@ namespace OpenRA.Mods.Cnc.Widgets
}); });
}; };
menu.GetWidget<ButtonWidget>("RESUME_BUTTON").OnClick = () => var resumeButton = menu.GetWidget<ButtonWidget>("RESUME_BUTTON");
resumeButton.IsDisabled = () => resumeDisabled;
resumeButton.OnClick = () =>
{ {
Widget.RootWidget.RemoveChild(menu); Widget.RootWidget.RemoveChild(menu);
world.WorldActor.Trait<CncMenuPaletteEffect>().Fade(CncMenuPaletteEffect.EffectType.None); world.WorldActor.Trait<CncMenuPaletteEffect>().Fade(CncMenuPaletteEffect.EffectType.None);

View File

@@ -32,7 +32,7 @@ Container@INGAME_MENU:
Y:0 Y:0
Width:140 Width:140
Height:35 Height:35
Text:Quit Text:Abort Mission
Button@SURRENDER_BUTTON: Button@SURRENDER_BUTTON:
Id:SURRENDER_BUTTON Id:SURRENDER_BUTTON
X:150 X:150
@@ -87,7 +87,6 @@ Container@INGAME_MENU:
Width:PARENT_RIGHT Width:PARENT_RIGHT
Height:25 Height:25
Font:Bold Font:Bold
WordWrap:true
Align:Center Align:Center
Button@CANCEL_BUTTON: Button@CANCEL_BUTTON:
Id:CANCEL_BUTTON Id:CANCEL_BUTTON