Merges LeaveMapLogic into GameInfoLogic.
Opens options menu when game ends. Closes settings or music window before opening options menu. Moves game end video playback logic from GameInfoLogic to LoadIngamePlayerOrObserverUILogic. Improves menu buttons. Stop video from playing on fatal lua script error
This commit is contained in:
@@ -586,7 +586,6 @@
|
||||
<Compile Include="Widgets\Logic\Ingame\IngamePowerCounterLogic.cs" />
|
||||
<Compile Include="Widgets\Logic\Ingame\IngameSiloBarLogic.cs" />
|
||||
<Compile Include="Widgets\Logic\Ingame\IngameRadarDisplayLogic.cs" />
|
||||
<Compile Include="Widgets\Logic\Ingame\LeaveMapLogic.cs" />
|
||||
<Compile Include="Widgets\Logic\Ingame\LoadIngamePlayerOrObserverUILogic.cs" />
|
||||
<Compile Include="Widgets\Logic\Ingame\LoadMapEditorLogic.cs" />
|
||||
<Compile Include="Widgets\Logic\Ingame\ObserverShroudSelectorLogic.cs" />
|
||||
|
||||
@@ -10,6 +10,7 @@
|
||||
|
||||
using System;
|
||||
using System.Linq;
|
||||
using OpenRA.Mods.Common.Scripting;
|
||||
using OpenRA.Traits;
|
||||
using OpenRA.Widgets;
|
||||
|
||||
@@ -28,8 +29,12 @@ namespace OpenRA.Mods.Common.Widgets.Logic
|
||||
widget.IsVisible = () => activePanel != IngameInfoPanel.AutoSelect;
|
||||
|
||||
// Objectives/Stats tab
|
||||
var scriptContext = world.WorldActor.TraitOrDefault<LuaScript>();
|
||||
var hasError = scriptContext != null && scriptContext.FatalErrorOccurred;
|
||||
var iop = world.WorldActor.TraitsImplementing<IObjectivesPanel>().FirstOrDefault();
|
||||
if (lp != null && iop != null && iop.PanelName != null)
|
||||
var hasObjectives = hasError || (lp != null && iop != null && iop.PanelName != null);
|
||||
|
||||
if (hasObjectives)
|
||||
{
|
||||
numTabs++;
|
||||
var objectivesTabButton = widget.Get<ButtonWidget>(string.Concat("BUTTON", numTabs.ToString()));
|
||||
@@ -38,10 +43,11 @@ namespace OpenRA.Mods.Common.Widgets.Logic
|
||||
objectivesTabButton.OnClick = () => activePanel = IngameInfoPanel.Objectives;
|
||||
objectivesTabButton.IsHighlighted = () => activePanel == IngameInfoPanel.Objectives;
|
||||
|
||||
var panel = hasError ? "SCRIPT_ERROR_PANEL" : iop.PanelName;
|
||||
var objectivesPanel = widget.Get<ContainerWidget>("OBJECTIVES_PANEL");
|
||||
objectivesPanel.IsVisible = () => activePanel == IngameInfoPanel.Objectives;
|
||||
|
||||
Game.LoadWidget(world, iop.PanelName, objectivesPanel, new WidgetArgs());
|
||||
Game.LoadWidget(world, panel, objectivesPanel, new WidgetArgs());
|
||||
|
||||
if (activePanel == IngameInfoPanel.AutoSelect)
|
||||
activePanel = IngameInfoPanel.Objectives;
|
||||
@@ -73,6 +79,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic
|
||||
var debugTabButton = widget.Get<ButtonWidget>(string.Concat("BUTTON", numTabs.ToString()));
|
||||
debugTabButton.Text = "Debug";
|
||||
debugTabButton.IsVisible = () => lp != null && world.LobbyInfo.GlobalSettings.AllowCheats && numTabs > 1;
|
||||
debugTabButton.IsDisabled = () => world.IsGameOver;
|
||||
debugTabButton.OnClick = () => activePanel = IngameInfoPanel.Debug;
|
||||
debugTabButton.IsHighlighted = () => activePanel == IngameInfoPanel.Debug;
|
||||
|
||||
|
||||
@@ -24,7 +24,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic
|
||||
[ObjectCreator.UseCtor]
|
||||
public IngameMenuLogic(Widget widget, World world, Action onExit, WorldRenderer worldRenderer, IngameInfoPanel activePanel)
|
||||
{
|
||||
var resumeDisabled = false;
|
||||
var leaving = false;
|
||||
menu = widget.Get("INGAME_MENU");
|
||||
var mpe = world.WorldActor.TraitOrDefault<MenuPaletteEffect>();
|
||||
if (mpe != null)
|
||||
@@ -41,7 +41,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic
|
||||
if (world.Type == WorldType.Regular)
|
||||
Sound.PlayNotification(world.Map.Rules, null, "Speech", "Leave", world.LocalPlayer == null ? null : world.LocalPlayer.Faction.InternalName);
|
||||
|
||||
resumeDisabled = true;
|
||||
leaving = true;
|
||||
|
||||
var iop = world.WorldActor.TraitsImplementing<IObjectivesPanel>().FirstOrDefault();
|
||||
var exitDelay = iop != null ? iop.ExitDelay : 0;
|
||||
@@ -71,8 +71,18 @@ namespace OpenRA.Mods.Common.Widgets.Logic
|
||||
|
||||
var abortMissionButton = menu.Get<ButtonWidget>("ABORT_MISSION");
|
||||
abortMissionButton.IsVisible = () => world.Type == WorldType.Regular;
|
||||
abortMissionButton.IsDisabled = () => leaving;
|
||||
if (world.IsGameOver)
|
||||
abortMissionButton.GetText = () => "Leave";
|
||||
|
||||
abortMissionButton.OnClick = () =>
|
||||
{
|
||||
if (world.IsGameOver)
|
||||
{
|
||||
onQuit();
|
||||
return;
|
||||
}
|
||||
|
||||
hideMenu = true;
|
||||
ConfirmationDialogs.PromptConfirmAction("Abort Mission", "Leave this game and return to the menu?", onQuit, showMenu);
|
||||
};
|
||||
@@ -116,7 +126,9 @@ namespace OpenRA.Mods.Common.Widgets.Logic
|
||||
});
|
||||
};
|
||||
|
||||
menu.Get<ButtonWidget>("MUSIC").OnClick = () =>
|
||||
var musicButton = menu.Get<ButtonWidget>("MUSIC");
|
||||
musicButton.IsDisabled = () => leaving;
|
||||
musicButton.OnClick = () =>
|
||||
{
|
||||
hideMenu = true;
|
||||
Ui.OpenWindow("MUSIC_PANEL", new WidgetArgs()
|
||||
@@ -127,6 +139,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic
|
||||
};
|
||||
|
||||
var settingsButton = widget.Get<ButtonWidget>("SETTINGS");
|
||||
settingsButton.IsDisabled = () => leaving;
|
||||
settingsButton.OnClick = () =>
|
||||
{
|
||||
hideMenu = true;
|
||||
@@ -139,7 +152,10 @@ namespace OpenRA.Mods.Common.Widgets.Logic
|
||||
};
|
||||
|
||||
var resumeButton = menu.Get<ButtonWidget>("RESUME");
|
||||
resumeButton.IsDisabled = () => resumeDisabled;
|
||||
resumeButton.IsDisabled = () => leaving;
|
||||
if (world.IsGameOver)
|
||||
resumeButton.GetText = () => "Return to map";
|
||||
|
||||
resumeButton.OnClick = closeMenu;
|
||||
|
||||
var panelRoot = widget.GetOrNull("PANEL_ROOT");
|
||||
|
||||
@@ -1,158 +0,0 @@
|
||||
#region Copyright & License Information
|
||||
/*
|
||||
* Copyright 2007-2015 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.Drawing;
|
||||
using System.Linq;
|
||||
using OpenRA.Mods.Common.Scripting;
|
||||
using OpenRA.Mods.Common.Traits;
|
||||
using OpenRA.Network;
|
||||
using OpenRA.Traits;
|
||||
using OpenRA.Widgets;
|
||||
|
||||
namespace OpenRA.Mods.Common.Widgets
|
||||
{
|
||||
class LeaveMapLogic
|
||||
{
|
||||
readonly OrderManager orderManager;
|
||||
|
||||
enum Tab { Objectives, Chat }
|
||||
Tab currentTab;
|
||||
|
||||
bool newChatMessage;
|
||||
|
||||
[ObjectCreator.UseCtor]
|
||||
public LeaveMapLogic(Widget widget, World world, OrderManager orderManager)
|
||||
{
|
||||
this.orderManager = orderManager;
|
||||
|
||||
var mpe = world.WorldActor.TraitOrDefault<MenuPaletteEffect>();
|
||||
if (mpe != null)
|
||||
mpe.Fade(mpe.Info.MenuEffect);
|
||||
|
||||
widget.Get<LabelWidget>("VERSION_LABEL").Text = Game.ModData.Manifest.Mod.Version;
|
||||
|
||||
var showStats = false;
|
||||
|
||||
var scriptContext = world.WorldActor.TraitOrDefault<LuaScript>();
|
||||
var iop = world.WorldActor.TraitsImplementing<IObjectivesPanel>().FirstOrDefault();
|
||||
var isMultiplayer = !world.LobbyInfo.IsSinglePlayer && !world.IsReplay;
|
||||
var hasError = scriptContext != null && scriptContext.FatalErrorOccurred;
|
||||
var hasObjectives = hasError || (iop != null && iop.PanelName != null && world.LocalPlayer != null);
|
||||
var showTabs = hasObjectives && isMultiplayer;
|
||||
currentTab = hasObjectives ? Tab.Objectives : Tab.Chat;
|
||||
|
||||
var panelName = hasObjectives || isMultiplayer ? "LEAVE_MAP_FULL" : "LEAVE_MAP_SIMPLE";
|
||||
var dialog = widget.Get<ContainerWidget>(panelName);
|
||||
dialog.IsVisible = () => !showStats;
|
||||
widget.IsVisible = () => Ui.CurrentWindow() == null;
|
||||
|
||||
if (hasObjectives || isMultiplayer)
|
||||
{
|
||||
var titleText = dialog.Get<LabelWidget>("GAME_ENDED_LABEL");
|
||||
var titleTextNoTabs = dialog.GetOrNull<LabelWidget>("GAME_ENDED_LABEL_NO_TABS");
|
||||
titleText.IsVisible = () => showTabs || (!showTabs && titleTextNoTabs == null);
|
||||
if (titleTextNoTabs != null)
|
||||
titleTextNoTabs.IsVisible = () => !showTabs;
|
||||
|
||||
var bg = dialog.Get<BackgroundWidget>("LEAVE_MAP_BG");
|
||||
var bgNoTabs = dialog.GetOrNull<BackgroundWidget>("LEAVE_MAP_BG_NO_TABS");
|
||||
bg.IsVisible = () => showTabs || (!showTabs && bgNoTabs == null);
|
||||
if (bgNoTabs != null)
|
||||
bgNoTabs.IsVisible = () => !showTabs;
|
||||
|
||||
var objButton = dialog.Get<ButtonWidget>("OBJECTIVES_BUTTON");
|
||||
objButton.IsVisible = () => showTabs;
|
||||
objButton.OnClick = () => currentTab = Tab.Objectives;
|
||||
objButton.IsHighlighted = () => currentTab == Tab.Objectives;
|
||||
|
||||
var chatButton = dialog.Get<ButtonWidget>("CHAT_BUTTON");
|
||||
chatButton.IsVisible = () => showTabs;
|
||||
chatButton.OnClick = () =>
|
||||
{
|
||||
currentTab = Tab.Chat;
|
||||
newChatMessage = false;
|
||||
};
|
||||
chatButton.IsHighlighted = () => currentTab == Tab.Chat || (newChatMessage && Game.LocalTick % 50 < 25);
|
||||
|
||||
Game.BeforeGameStart += UnregisterChatNotification;
|
||||
orderManager.AddChatLine += NotifyNewChatMessage;
|
||||
}
|
||||
|
||||
var statsButton = dialog.Get<ButtonWidget>("STATS_BUTTON");
|
||||
statsButton.IsVisible = () => !world.Map.Visibility.HasFlag(MapVisibility.MissionSelector) || world.IsReplay;
|
||||
statsButton.OnClick = () =>
|
||||
{
|
||||
showStats = true;
|
||||
Game.LoadWidget(world, "INGAME_OBSERVERSTATS_BG", Ui.Root, new WidgetArgs()
|
||||
{
|
||||
{ "onExit", () => showStats = false }
|
||||
});
|
||||
};
|
||||
|
||||
var leaveButton = dialog.Get<ButtonWidget>("LEAVE_BUTTON");
|
||||
leaveButton.OnClick = () =>
|
||||
{
|
||||
leaveButton.Disabled = true;
|
||||
|
||||
if (world.Type == WorldType.Regular)
|
||||
Sound.PlayNotification(world.Map.Rules, null, "Speech", "Leave",
|
||||
world.LocalPlayer == null ? null : world.LocalPlayer.Faction.InternalName);
|
||||
|
||||
var exitDelay = iop != null ? iop.ExitDelay : 0;
|
||||
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 (hasObjectives)
|
||||
{
|
||||
var panel = hasError ? "SCRIPT_ERROR_PANEL" : iop.PanelName;
|
||||
var objectivesContainer = dialog.Get<ContainerWidget>("OBJECTIVES_PANEL");
|
||||
Game.LoadWidget(world, panel, objectivesContainer, new WidgetArgs());
|
||||
objectivesContainer.IsVisible = () => currentTab == Tab.Objectives;
|
||||
|
||||
string video = null;
|
||||
if (world.LocalPlayer.WinState != WinState.Undefined)
|
||||
video = world.LocalPlayer.WinState == WinState.Won ? world.Map.Videos.GameWon : world.Map.Videos.GameLost;
|
||||
|
||||
if (!string.IsNullOrEmpty(video))
|
||||
Media.PlayFMVFullscreen(world, video, () => { });
|
||||
}
|
||||
|
||||
if (isMultiplayer)
|
||||
{
|
||||
var chatContainer = dialog.Get<ContainerWidget>("DIALOG_CHAT_PANEL");
|
||||
chatContainer.IsVisible = () => currentTab == Tab.Chat;
|
||||
}
|
||||
}
|
||||
|
||||
void NotifyNewChatMessage(Color c, string s1, string s2)
|
||||
{
|
||||
if (currentTab != Tab.Chat)
|
||||
newChatMessage = true;
|
||||
}
|
||||
|
||||
void UnregisterChatNotification()
|
||||
{
|
||||
orderManager.AddChatLine -= NotifyNewChatMessage;
|
||||
Game.BeforeGameStart -= UnregisterChatNotification;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -8,6 +8,7 @@
|
||||
*/
|
||||
#endregion
|
||||
|
||||
using OpenRA.Mods.Common.Scripting;
|
||||
using OpenRA.Widgets;
|
||||
|
||||
namespace OpenRA.Mods.Common.Widgets.Logic
|
||||
@@ -46,9 +47,21 @@ namespace OpenRA.Mods.Common.Widgets.Logic
|
||||
|
||||
world.GameOver += () =>
|
||||
{
|
||||
worldRoot.RemoveChildren();
|
||||
Ui.CloseWindow();
|
||||
menuRoot.RemoveChildren();
|
||||
Game.LoadWidget(world, "LEAVE_MAP_WIDGET", menuRoot, new WidgetArgs());
|
||||
|
||||
if (world.LocalPlayer != null)
|
||||
{
|
||||
var scriptContext = world.WorldActor.TraitOrDefault<LuaScript>();
|
||||
var video = world.LocalPlayer.WinState == WinState.Won ? world.Map.Videos.GameWon : world.Map.Videos.GameLost;
|
||||
|
||||
if (!string.IsNullOrEmpty(video) && !(scriptContext != null && scriptContext.FatalErrorOccurred))
|
||||
Media.PlayFMVFullscreen(world, video, () => { });
|
||||
}
|
||||
|
||||
var optionsButton = playerRoot.GetOrNull<MenuButtonWidget>("OPTIONS_BUTTON");
|
||||
if (optionsButton != null)
|
||||
optionsButton.OnClick();
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
@@ -33,9 +33,6 @@ namespace OpenRA.Mods.Common.Widgets.Logic
|
||||
worldRoot = Ui.Root.Get("WORLD_ROOT");
|
||||
menuRoot = Ui.Root.Get("MENU_ROOT");
|
||||
|
||||
Action removeCurrentWidget = () => menuRoot.RemoveChild(currentWidget);
|
||||
world.GameOver += removeCurrentWidget;
|
||||
|
||||
// System buttons
|
||||
var options = widget.GetOrNull<MenuButtonWidget>("OPTIONS_BUTTON");
|
||||
if (options != null)
|
||||
|
||||
Reference in New Issue
Block a user