Add a mission objectives GUI panel
This commit is contained in:
@@ -1,76 +0,0 @@
|
||||
#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.Drawing;
|
||||
using System.Linq;
|
||||
using OpenRA.Mods.RA;
|
||||
using OpenRA.Widgets;
|
||||
|
||||
namespace OpenRA.Mods.Cnc.Widgets.Logic
|
||||
{
|
||||
public class CncConquestObjectivesLogic
|
||||
{
|
||||
[ObjectCreator.UseCtor]
|
||||
public CncConquestObjectivesLogic(Widget widget, World world)
|
||||
{
|
||||
var panel = widget.Get("CONQUEST_OBJECTIVES");
|
||||
panel.Get<LabelWidget>("TITLE").GetText = () => "Conquest: " + world.Map.Title;
|
||||
|
||||
var statusLabel = panel.Get<LabelWidget>("STATUS");
|
||||
statusLabel.IsVisible = () => world.LocalPlayer != null;
|
||||
|
||||
if (world.LocalPlayer != null)
|
||||
{
|
||||
var lp = world.LocalPlayer;
|
||||
var objectiveCheckbox = panel.Get<CheckboxWidget>("1");
|
||||
objectiveCheckbox.IsChecked = () => lp.WinState != WinState.Undefined;
|
||||
objectiveCheckbox.GetCheckType = () => lp.WinState == WinState.Won ?
|
||||
"checked" : "crossed";
|
||||
|
||||
statusLabel.GetText = () => lp.WinState == WinState.Won ? "Complete" :
|
||||
lp.WinState == WinState.Lost ? "Failed" : "Incomplete";
|
||||
statusLabel.GetColor = () => lp.WinState == WinState.Won ? Color.Green :
|
||||
lp.WinState == WinState.Lost ? Color.Red : Color.White;
|
||||
}
|
||||
|
||||
var scrollpanel = panel.Get<ScrollPanelWidget>("PLAYER_LIST");
|
||||
var itemTemplate = scrollpanel.Get("PLAYER_TEMPLATE");
|
||||
scrollpanel.RemoveChildren();
|
||||
|
||||
foreach (var p in world.Players.Where(a => !a.NonCombatant))
|
||||
{
|
||||
var pp = p;
|
||||
var item = itemTemplate.Clone();
|
||||
var nameLabel = item.Get<LabelWidget>("NAME");
|
||||
nameLabel.GetText = () => pp.WinState == WinState.Lost ? pp.PlayerName + " (Dead)" : pp.PlayerName;
|
||||
nameLabel.GetColor = () => pp.Color.RGB;
|
||||
|
||||
var flag = item.Get<ImageWidget>("FACTIONFLAG");
|
||||
flag.GetImageName = () => pp.Country.Race;
|
||||
flag.GetImageCollection = () => "flags";
|
||||
item.Get<LabelWidget>("FACTION").GetText = () => pp.Country.Name;
|
||||
|
||||
var team = item.Get<LabelWidget>("TEAM");
|
||||
var client = world.LobbyInfo.ClientWithIndex(pp.ClientIndex);
|
||||
var teamNumber = (client == null) ? 0 : client.Team;
|
||||
team.GetText = () => (teamNumber == 0) ? "-" : teamNumber.ToString();
|
||||
scrollpanel.AddChild(item);
|
||||
|
||||
var stats = pp.PlayerActor.TraitOrDefault<PlayerStatistics>();
|
||||
if (stats == null)
|
||||
break;
|
||||
var totalKills = stats.UnitsKilled + stats.BuildingsKilled;
|
||||
var totalDeaths = stats.UnitsDead + stats.BuildingsDead;
|
||||
item.Get<LabelWidget>("KILLS").GetText = () => totalKills.ToString();
|
||||
item.Get<LabelWidget>("DEATHS").GetText = () => totalDeaths.ToString();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,131 +0,0 @@
|
||||
#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;
|
||||
using System.Linq;
|
||||
using OpenRA.Graphics;
|
||||
using OpenRA.Mods.RA;
|
||||
using OpenRA.Mods.RA.Widgets;
|
||||
using OpenRA.Traits;
|
||||
using OpenRA.Widgets;
|
||||
|
||||
namespace OpenRA.Mods.Cnc.Widgets.Logic
|
||||
{
|
||||
public class CncIngameMenuLogic
|
||||
{
|
||||
Widget menu;
|
||||
|
||||
enum PanelType { Objectives, Debug }
|
||||
|
||||
[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<MenuPaletteEffect>();
|
||||
mpe.Fade(MenuPaletteEffect.EffectType.Desaturated);
|
||||
|
||||
menu.Get<LabelWidget>("VERSION_LABEL").Text = Game.modData.Manifest.Mod.Version;
|
||||
|
||||
var 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(world.Map.Rules, null, "Speech", "Leave", null);
|
||||
resumeDisabled = true;
|
||||
Game.RunAfterDelay(1200, () => mpe.Fade(MenuPaletteEffect.EffectType.Black));
|
||||
Game.RunAfterDelay(1200 + 40 * mpe.Info.FadeLength, () =>
|
||||
{
|
||||
Game.Disconnect();
|
||||
Ui.ResetAll();
|
||||
Game.LoadShellMap();
|
||||
});
|
||||
};
|
||||
|
||||
Action doNothing = () => { };
|
||||
|
||||
menu.Get<ButtonWidget>("QUIT_BUTTON").OnClick = () =>
|
||||
ConfirmationDialogs.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 = () =>
|
||||
ConfirmationDialogs.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 },
|
||||
{ "world", world }
|
||||
});
|
||||
};
|
||||
|
||||
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<MenuPaletteEffect>().Fade(MenuPaletteEffect.EffectType.None);
|
||||
onExit();
|
||||
};
|
||||
|
||||
// Menu panels - ordered from lowest to highest priority
|
||||
var panelParent = Game.OpenWindow(world, "INGAME_MENU_PANEL");
|
||||
var panelType = PanelType.Objectives;
|
||||
var visibleButtons = 0;
|
||||
|
||||
// Debug / Cheats panel
|
||||
var debugButton = panelParent.Get<ButtonWidget>("DEBUG_BUTTON");
|
||||
debugButton.OnClick = () => panelType = PanelType.Debug;
|
||||
debugButton.IsHighlighted = () => panelType == PanelType.Debug;
|
||||
|
||||
if (world.LocalPlayer != null && world.LobbyInfo.GlobalSettings.AllowCheats)
|
||||
{
|
||||
panelType = PanelType.Debug;
|
||||
visibleButtons++;
|
||||
var debugPanel = Game.LoadWidget(world, "DEBUG_PANEL", panelParent, new WidgetArgs() { { "onExit", doNothing }, { "transient", true } });
|
||||
debugPanel.IsVisible = () => panelType == PanelType.Debug;
|
||||
debugButton.IsVisible = () => visibleButtons > 1;
|
||||
}
|
||||
|
||||
// Mission objectives
|
||||
var iop = world.WorldActor.TraitsImplementing<IObjectivesPanel>().FirstOrDefault();
|
||||
var objectivesButton = panelParent.Get<ButtonWidget>("OBJECTIVES_BUTTON");
|
||||
objectivesButton.OnClick = () => panelType = PanelType.Objectives;
|
||||
objectivesButton.IsHighlighted = () => panelType == PanelType.Objectives;
|
||||
|
||||
if (iop != null && iop.ObjectivesPanel != null)
|
||||
{
|
||||
panelType = PanelType.Objectives;
|
||||
visibleButtons++;
|
||||
var objectivesPanel = Game.LoadWidget(world, iop.ObjectivesPanel, panelParent, new WidgetArgs());
|
||||
objectivesPanel.IsVisible = () => panelType == PanelType.Objectives;
|
||||
objectivesButton.IsVisible = () => visibleButtons > 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user