#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 System.Linq; using OpenRA.Traits; using OpenRA.Widgets; namespace OpenRA.Mods.RA.Widgets { class LeaveMapLogic { [ObjectCreator.UseCtor] public LeaveMapLogic(Widget widget, World world) { widget.Get("VERSION_LABEL").Text = Game.modData.Manifest.Mod.Version; var panelName = "LEAVE_RESTART_SIMPLE"; var iop = world.WorldActor.TraitsImplementing().FirstOrDefault(); var showObjectives = iop != null && iop.PanelName != null && world.LocalPlayer != null; if (showObjectives) panelName = "LEAVE_RESTART_FULL"; var showStats = false; var dialog = widget.Get(panelName); dialog.IsVisible = () => !showStats; widget.IsVisible = () => Ui.CurrentWindow() == null; var statsButton = dialog.Get("STATS_BUTTON"); statsButton.OnClick = () => { showStats = true; Game.LoadWidget(world, "INGAME_OBSERVERSTATS_BG", Ui.Root, new WidgetArgs() { { "onExit", () => showStats = false } }); }; var leaveButton = dialog.Get("LEAVE_BUTTON"); leaveButton.OnClick = () => { leaveButton.Disabled = true; var mpe = world.WorldActor.TraitOrDefault(); Sound.PlayNotification(world.Map.Rules, null, "Speech", "Leave", world.LocalPlayer == null ? null : world.LocalPlayer.Country.Race); 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(); }); }; if (showObjectives) { var objectivesContainer = dialog.Get("OBJECTIVES"); Game.LoadWidget(world, iop.PanelName, objectivesContainer, new WidgetArgs()); } } } }