Add a mission objectives GUI panel

This commit is contained in:
Oliver Brakmann
2014-07-27 13:25:58 +02:00
parent 2c22e5099f
commit 8cec848a0f
46 changed files with 1252 additions and 886 deletions

View File

@@ -1,4 +1,4 @@
#region Copyright & License Information
#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
@@ -9,19 +9,34 @@
#endregion
using System;
using System.Linq;
using OpenRA.Graphics;
using OpenRA.Mods.RA;
using OpenRA.Mods.RA.Widgets;
using OpenRA.Traits;
using OpenRA.Widgets;
namespace OpenRA.Mods.RA.Widgets.Logic
{
class IngameMenuLogic
public class IngameMenuLogic
{
Widget menu;
[ObjectCreator.UseCtor]
public IngameMenuLogic(Widget widget, World world, Action onExit, WorldRenderer worldRenderer, bool transient)
public IngameMenuLogic(Widget widget, World world, Action onExit, WorldRenderer worldRenderer, IngameInfoPanel activePanel)
{
var resumeDisabled = false;
menu = widget.Get("INGAME_MENU");
var mpe = world.WorldActor.TraitOrDefault<MenuPaletteEffect>();
if (mpe != null)
mpe.Fade(mpe.Info.MenuEffect);
menu.Get<LabelWidget>("VERSION_LABEL").Text = Game.modData.Manifest.Mod.Version;
var hideMenu = false;
menu.Get("MENU_BUTTONS").IsVisible = () => !hideMenu;
// TODO: Create a mechanism to do things like this cleaner. Also needed for scripted missions
Action onQuit = () =>
{
Sound.PlayNotification(world.Map.Rules, null, "Speech", "Leave", world.LocalPlayer == null ? null : world.LocalPlayer.Country.Race);
@@ -33,7 +48,6 @@ namespace OpenRA.Mods.RA.Widgets.Logic
Game.RunAfterDelay(exitDelay, () => mpe.Fade(MenuPaletteEffect.EffectType.Black));
exitDelay += 40 * mpe.Info.FadeLength;
}
Game.RunAfterDelay(exitDelay, () =>
{
Game.Disconnect();
@@ -42,62 +56,68 @@ namespace OpenRA.Mods.RA.Widgets.Logic
});
};
Action onSurrender = () =>
Action closeMenu = () =>
{
world.IssueOrder(new Order("Surrender", world.LocalPlayer.PlayerActor, false));
Ui.CloseWindow();
Ui.Root.RemoveChild(menu);
if (mpe != null)
mpe.Fade(MenuPaletteEffect.EffectType.None);
onExit();
};
widget.Get<ButtonWidget>("DISCONNECT").OnClick = () =>
Action showMenu = () => hideMenu = false;
menu.Get<ButtonWidget>("ABORT_MISSION").OnClick = () =>
{
widget.Visible = false;
ConfirmationDialogs.PromptConfirmAction("Abort Mission", "Leave this game and return to the menu?", onQuit, () => widget.Visible = true);
hideMenu = true;
ConfirmationDialogs.PromptConfirmAction("Abort Mission", "Leave this game and return to the menu?", onQuit, showMenu);
};
widget.Get<ButtonWidget>("SETTINGS").OnClick = () =>
Action onSurrender = () =>
{
widget.Visible = false;
Ui.OpenWindow("SETTINGS_PANEL", new WidgetArgs()
{
{ "onExit", () => widget.Visible = true },
{ "worldRenderer", worldRenderer },
});
world.IssueOrder(new Order("Surrender", world.LocalPlayer.PlayerActor, false));
closeMenu();
};
widget.Get<ButtonWidget>("MUSIC").OnClick = () =>
var surrenderButton = menu.Get<ButtonWidget>("SURRENDER");
surrenderButton.IsDisabled = () => (world.LocalPlayer == null || world.LocalPlayer.WinState != WinState.Undefined);
surrenderButton.OnClick = () =>
{
widget.Visible = false;
Ui.OpenWindow("MUSIC_PANEL", new WidgetArgs
hideMenu = true;
ConfirmationDialogs.PromptConfirmAction("Surrender", "Are you sure you want to surrender?", onSurrender, showMenu);
};
widget.Get("SURRENDER").IsVisible = () => world.LocalPlayer != null && world.LocalPlayer.WinState == WinState.Undefined;
menu.Get<ButtonWidget>("MUSIC").OnClick = () =>
{
hideMenu = true;
Ui.OpenWindow("MUSIC_PANEL", new WidgetArgs()
{
{ "onExit", () => { widget.Visible = true; } },
{ "onExit", () => hideMenu = false },
{ "world", world }
});
};
var resumeButton = widget.Get<ButtonWidget>("RESUME");
resumeButton.IsDisabled = () => resumeDisabled;
resumeButton.OnClick = () =>
menu.Get<ButtonWidget>("SETTINGS").OnClick = () =>
{
if (transient)
hideMenu = true;
Ui.OpenWindow("SETTINGS_PANEL", new WidgetArgs()
{
Ui.CloseWindow();
Ui.Root.RemoveChild(widget);
}
onExit();
{ "world", world },
{ "worldRenderer", worldRenderer },
{ "onExit", () => hideMenu = false },
});
};
widget.Get<ButtonWidget>("SURRENDER").OnClick = () =>
var resumeButton = menu.Get<ButtonWidget>("RESUME");
resumeButton.IsDisabled = () => resumeDisabled;
resumeButton.OnClick = closeMenu;
// Game info panel
var gameInfoPanel = Game.LoadWidget(world, "GAME_INFO_PANEL", menu, new WidgetArgs()
{
widget.Visible = false;
ConfirmationDialogs.PromptConfirmAction(
"Surrender",
"Are you sure you want to surrender?",
onSurrender,
() => widget.Visible = true,
"Surrender");
};
widget.Get("SURRENDER").IsVisible = () => world.LocalPlayer != null && world.LocalPlayer.WinState == WinState.Undefined;
{ "activePanel", activePanel }
});
gameInfoPanel.IsVisible = () => !hideMenu;
}
}
}