The old method had the lobby code dig around inside the palette modification machinery, which was a giant hack preventing necessary streamlining.
98 lines
3.1 KiB
C#
98 lines
3.1 KiB
C#
#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 System.Linq;
|
|
using OpenRA.Graphics;
|
|
using OpenRA.Traits;
|
|
using OpenRA.Widgets;
|
|
|
|
namespace OpenRA.Mods.Cnc.Widgets.Logic
|
|
{
|
|
public class CncIngameMenuLogic
|
|
{
|
|
Widget menu;
|
|
|
|
[ObjectCreator.UseCtor]
|
|
public CncIngameMenuLogic(Widget widget, World world, Action onExit, WorldRenderer worldRenderer)
|
|
{
|
|
var resumeDisabled = false;
|
|
menu = widget.Get("INGAME_MENU");
|
|
var mpe = world.WorldActor.Trait<CncMenuPaletteEffect>();
|
|
mpe.Fade(CncMenuPaletteEffect.EffectType.Desaturated);
|
|
|
|
menu.Get<LabelWidget>("VERSION_LABEL").GetText = WidgetUtils.ActiveModVersion;
|
|
|
|
bool hideButtons = false;
|
|
menu.Get("MENU_BUTTONS").IsVisible = () => !hideButtons;
|
|
|
|
// TODO: Create a mechanism to do things like this cleaner. Also needed for scripted missions
|
|
Action onQuit = () =>
|
|
{
|
|
Sound.PlayNotification(null, "Speech", "Leave", null);
|
|
resumeDisabled = true;
|
|
Game.RunAfterDelay(1200, () => mpe.Fade(CncMenuPaletteEffect.EffectType.Black));
|
|
Game.RunAfterDelay(1200 + 40 * mpe.Info.FadeLength, () =>
|
|
{
|
|
Game.Disconnect();
|
|
Ui.ResetAll();
|
|
Game.LoadShellMap();
|
|
});
|
|
};
|
|
|
|
Action doNothing = () => {};
|
|
|
|
menu.Get<ButtonWidget>("QUIT_BUTTON").OnClick = () =>
|
|
CncWidgetUtils.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<ButtonWidget>("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);
|
|
|
|
menu.Get<ButtonWidget>("MUSIC_BUTTON").OnClick = () =>
|
|
{
|
|
hideButtons = true;
|
|
Ui.OpenWindow("MUSIC_PANEL", new WidgetArgs()
|
|
{
|
|
{ "onExit", () => hideButtons = false },
|
|
});
|
|
};
|
|
|
|
menu.Get<ButtonWidget>("SETTINGS_BUTTON").OnClick = () =>
|
|
{
|
|
hideButtons = true;
|
|
Ui.OpenWindow("SETTINGS_PANEL", new WidgetArgs()
|
|
{
|
|
{ "world", world },
|
|
{ "worldRenderer", worldRenderer },
|
|
{ "onExit", () => hideButtons = false },
|
|
});
|
|
};
|
|
|
|
var resumeButton = menu.Get<ButtonWidget>("RESUME_BUTTON");
|
|
resumeButton.IsDisabled = () => resumeDisabled;
|
|
resumeButton.OnClick = () =>
|
|
{
|
|
Ui.CloseWindow();
|
|
Ui.Root.RemoveChild(menu);
|
|
world.WorldActor.Trait<CncMenuPaletteEffect>().Fade(CncMenuPaletteEffect.EffectType.None);
|
|
onExit();
|
|
};
|
|
|
|
// Mission objectives panel
|
|
var iop = world.WorldActor.TraitsImplementing<IObjectivesPanel>().FirstOrDefault();
|
|
if (iop != null && iop.ObjectivesPanel != null)
|
|
Game.OpenWindow(world, iop.ObjectivesPanel);
|
|
}
|
|
}
|
|
}
|