Added a bunch of TraitLocationAttributes
Also moved a few traits to their proper subfolders.
This commit is contained in:
committed by
Matthias Mailänder
parent
67598dd151
commit
f056cbba13
@@ -26,6 +26,7 @@ namespace OpenRA.Mods.Common.Traits
|
||||
CPos Location { get; }
|
||||
}
|
||||
|
||||
[TraitLocation(SystemActors.World)]
|
||||
class BridgeLayerInfo : TraitInfo
|
||||
{
|
||||
public override object Create(ActorInitializer init) { return new BridgeLayer(init.World); }
|
||||
|
||||
@@ -17,6 +17,7 @@ namespace OpenRA.Mods.Common.Traits
|
||||
{
|
||||
[Desc("Sets a custom terrain type for cells that are obscured by back-facing cliffs.",
|
||||
"This trait replicates the default CliffBackImpassability=2 behaviour from the TS/RA2 rules.ini.")]
|
||||
[TraitLocation(SystemActors.World | SystemActors.EditorWorld)]
|
||||
class CliffBackImpassabilityLayerInfo : TraitInfo
|
||||
{
|
||||
public readonly string TerrainType = "Impassable";
|
||||
|
||||
@@ -18,6 +18,7 @@ using OpenRA.Traits;
|
||||
|
||||
namespace OpenRA.Mods.Common.Traits
|
||||
{
|
||||
[TraitLocation(SystemActors.World)]
|
||||
[Desc("Configuration options for the lobby player color picker. Attach this to the world actor.")]
|
||||
public class ColorPickerManagerInfo : TraitInfo<ColorPickerManager>, IRulesetLoaded
|
||||
{
|
||||
|
||||
@@ -16,6 +16,7 @@ using OpenRA.Traits;
|
||||
|
||||
namespace OpenRA.Mods.Common.Traits
|
||||
{
|
||||
[TraitLocation(SystemActors.World)]
|
||||
public class ElevatedBridgeLayerInfo : TraitInfo, Requires<DomainIndexInfo>, ILobbyCustomRulesIgnore
|
||||
{
|
||||
[Desc("Terrain type used by cells outside any elevated bridge footprint.")]
|
||||
|
||||
@@ -18,6 +18,7 @@ namespace OpenRA.Mods.Common.Traits
|
||||
|
||||
[Desc("Placeholder to make static elevated bridges work.",
|
||||
"Define individual trait instances for each elevated bridge footprint in the map.")]
|
||||
[TraitLocation(SystemActors.World)]
|
||||
public class ElevatedBridgePlaceholderInfo : TraitInfo<ElevatedBridgePlaceholder>, Requires<ElevatedBridgeLayerInfo>, ILobbyCustomRulesIgnore
|
||||
{
|
||||
[FieldLoader.Require]
|
||||
|
||||
@@ -15,6 +15,7 @@ using OpenRA.Traits;
|
||||
|
||||
namespace OpenRA.Mods.Common.Traits
|
||||
{
|
||||
[TraitLocation(SystemActors.World)]
|
||||
public class ExitsDebugOverlayManagerInfo : TraitInfo
|
||||
{
|
||||
[Desc("The font used to draw cell vectors. Should match the value as-is in the Fonts section of the mod manifest (do not convert to lowercase).")]
|
||||
|
||||
@@ -1,66 +0,0 @@
|
||||
#region Copyright & License Information
|
||||
/*
|
||||
* Copyright 2007-2021 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, either version 3 of
|
||||
* the License, or (at your option) any later version. For more
|
||||
* information, see COPYING.
|
||||
*/
|
||||
#endregion
|
||||
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using OpenRA.Graphics;
|
||||
using OpenRA.Traits;
|
||||
|
||||
namespace OpenRA.Mods.Common.Traits
|
||||
{
|
||||
[TraitLocation(SystemActors.Player)]
|
||||
public class GameSaveViewportManagerInfo : TraitInfo
|
||||
{
|
||||
public override object Create(ActorInitializer init) { return new GameSaveViewportManager(); }
|
||||
}
|
||||
|
||||
public class GameSaveViewportManager : IWorldLoaded, IGameSaveTraitData
|
||||
{
|
||||
WorldRenderer worldRenderer;
|
||||
|
||||
void IWorldLoaded.WorldLoaded(World w, WorldRenderer wr) { worldRenderer = wr; }
|
||||
|
||||
List<MiniYamlNode> IGameSaveTraitData.IssueTraitData(Actor self)
|
||||
{
|
||||
// HACK: Store the viewport state for the skirmish observer on the first bot's trait
|
||||
// TODO: This won't make sense for MP saves
|
||||
var localPlayer = worldRenderer.World.LocalPlayer;
|
||||
if ((localPlayer != null && localPlayer.PlayerActor != self) ||
|
||||
(localPlayer == null && self.Owner != self.World.Players.FirstOrDefault(p => p.IsBot)))
|
||||
return null;
|
||||
|
||||
var nodes = new List<MiniYamlNode>()
|
||||
{
|
||||
new MiniYamlNode("Viewport", FieldSaver.FormatValue(worldRenderer.Viewport.CenterPosition))
|
||||
};
|
||||
|
||||
var renderPlayer = worldRenderer.World.RenderPlayer;
|
||||
if (localPlayer == null && renderPlayer != null)
|
||||
nodes.Add(new MiniYamlNode("RenderPlayer", FieldSaver.FormatValue(renderPlayer.PlayerActor.ActorID)));
|
||||
|
||||
return nodes;
|
||||
}
|
||||
|
||||
void IGameSaveTraitData.ResolveTraitData(Actor self, List<MiniYamlNode> data)
|
||||
{
|
||||
var viewportNode = data.FirstOrDefault(n => n.Key == "Viewport");
|
||||
if (viewportNode != null)
|
||||
worldRenderer.Viewport.Center(FieldLoader.GetValue<WPos>("Viewport", viewportNode.Value.Value));
|
||||
|
||||
var renderPlayerNode = data.FirstOrDefault(n => n.Key == "RenderPlayer");
|
||||
if (renderPlayerNode != null)
|
||||
{
|
||||
var renderPlayerActorID = FieldLoader.GetValue<uint>("RenderPlayer", renderPlayerNode.Value.Value);
|
||||
worldRenderer.World.RenderPlayer = worldRenderer.World.GetActorById(renderPlayerActorID).Owner;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -15,6 +15,7 @@ using OpenRA.Traits;
|
||||
|
||||
namespace OpenRA.Mods.Common.Traits
|
||||
{
|
||||
[TraitLocation(SystemActors.World)]
|
||||
public class JumpjetActorLayerInfo : TraitInfo
|
||||
{
|
||||
[Desc("Terrain type of the airborne layer.")]
|
||||
|
||||
@@ -10,9 +10,11 @@
|
||||
#endregion
|
||||
|
||||
using System.Collections.Generic;
|
||||
using OpenRA.Traits;
|
||||
|
||||
namespace OpenRA.Mods.Common.Traits
|
||||
{
|
||||
[TraitLocation(SystemActors.World | SystemActors.EditorWorld)]
|
||||
[Desc("Used by Mobile. Required for jumpjet actors. Attach these to the world actor. You can have multiple variants by adding @suffixes.")]
|
||||
public class JumpjetLocomotorInfo : LocomotorInfo
|
||||
{
|
||||
|
||||
@@ -1,78 +0,0 @@
|
||||
#region Copyright & License Information
|
||||
/*
|
||||
* Copyright 2007-2021 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, either version 3 of
|
||||
* the License, or (at your option) any later version. For more
|
||||
* information, see COPYING.
|
||||
*/
|
||||
#endregion
|
||||
|
||||
using System.Collections.Generic;
|
||||
using OpenRA.Traits;
|
||||
|
||||
namespace OpenRA.Mods.Common.Traits
|
||||
{
|
||||
[TraitLocation(SystemActors.Player)]
|
||||
[Desc("Enables defined prerequisites at game start for all players if the checkbox is enabled.")]
|
||||
public class LobbyPrerequisiteCheckboxInfo : TraitInfo, ILobbyOptions, ITechTreePrerequisiteInfo
|
||||
{
|
||||
[FieldLoader.Require]
|
||||
[Desc("Internal id for this checkbox.")]
|
||||
public readonly string ID = null;
|
||||
|
||||
[FieldLoader.Require]
|
||||
[Desc("Display name for this checkbox.")]
|
||||
public readonly string Label = null;
|
||||
|
||||
[Desc("Description name for this checkbox.")]
|
||||
public readonly string Description = null;
|
||||
|
||||
[Desc("Default value of the checkbox in the lobby.")]
|
||||
public readonly bool Enabled = false;
|
||||
|
||||
[Desc("Prevent the checkbox from being changed from its default value.")]
|
||||
public readonly bool Locked = false;
|
||||
|
||||
[Desc("Display the checkbox in the lobby.")]
|
||||
public readonly bool Visible = true;
|
||||
|
||||
[Desc("Display order for the checkbox in the lobby.")]
|
||||
public readonly int DisplayOrder = 0;
|
||||
|
||||
[FieldLoader.Require]
|
||||
[Desc("Prerequisites to grant when this checkbox is enabled.")]
|
||||
public readonly HashSet<string> Prerequisites = new HashSet<string>();
|
||||
|
||||
IEnumerable<string> ITechTreePrerequisiteInfo.Prerequisites(ActorInfo info) { return Prerequisites; }
|
||||
|
||||
IEnumerable<LobbyOption> ILobbyOptions.LobbyOptions(MapPreview map)
|
||||
{
|
||||
yield return new LobbyBooleanOption(ID, Label, Description,
|
||||
Visible, DisplayOrder, Enabled, Locked);
|
||||
}
|
||||
|
||||
public override object Create(ActorInitializer init) { return new LobbyPrerequisiteCheckbox(this); }
|
||||
}
|
||||
|
||||
public class LobbyPrerequisiteCheckbox : INotifyCreated, ITechTreePrerequisite
|
||||
{
|
||||
readonly LobbyPrerequisiteCheckboxInfo info;
|
||||
HashSet<string> prerequisites = new HashSet<string>();
|
||||
|
||||
public LobbyPrerequisiteCheckbox(LobbyPrerequisiteCheckboxInfo info)
|
||||
{
|
||||
this.info = info;
|
||||
}
|
||||
|
||||
void INotifyCreated.Created(Actor self)
|
||||
{
|
||||
var enabled = self.World.LobbyInfo.GlobalSettings.OptionOrDefault(info.ID, info.Enabled);
|
||||
if (enabled)
|
||||
prerequisites = info.Prerequisites;
|
||||
}
|
||||
|
||||
IEnumerable<string> ITechTreePrerequisite.ProvidesPrerequisites => prerequisites;
|
||||
}
|
||||
}
|
||||
@@ -14,6 +14,7 @@ using OpenRA.Traits;
|
||||
namespace OpenRA.Mods.Common.Traits
|
||||
{
|
||||
[Desc("Defines the FMVs that can be played by missions.")]
|
||||
[TraitLocation(SystemActors.World)]
|
||||
public class MissionDataInfo : TraitInfo<MissionData>
|
||||
{
|
||||
[Desc("Briefing text displayed in the mission browser.")]
|
||||
|
||||
@@ -15,6 +15,7 @@ using OpenRA.Traits;
|
||||
namespace OpenRA.Mods.Common.Traits
|
||||
{
|
||||
[Desc("Controls the map difficulty, tech level, and short game lobby options.")]
|
||||
[TraitLocation(SystemActors.World)]
|
||||
public class ScriptLobbyDropdownInfo : TraitInfo, ILobbyOptions
|
||||
{
|
||||
[FieldLoader.Require]
|
||||
|
||||
@@ -15,6 +15,7 @@ using OpenRA.Traits;
|
||||
|
||||
namespace OpenRA.Mods.Common.Traits
|
||||
{
|
||||
[TraitLocation(SystemActors.World)]
|
||||
public class SubterraneanActorLayerInfo : TraitInfo
|
||||
{
|
||||
[Desc("Terrain type of the underground layer.")]
|
||||
|
||||
@@ -10,10 +10,12 @@
|
||||
#endregion
|
||||
|
||||
using System.Collections.Generic;
|
||||
using OpenRA.Traits;
|
||||
|
||||
namespace OpenRA.Mods.Common.Traits
|
||||
{
|
||||
[Desc("Used by Mobile. Required for subterranean actors. Attach these to the world actor. You can have multiple variants by adding @suffixes.")]
|
||||
[TraitLocation(SystemActors.World | SystemActors.EditorWorld)]
|
||||
public class SubterraneanLocomotorInfo : LocomotorInfo
|
||||
{
|
||||
[Desc("Pathfinding cost for submerging or reemerging.")]
|
||||
|
||||
141
OpenRA.Mods.Common/Traits/World/TerrainLighting.cs
Normal file
141
OpenRA.Mods.Common/Traits/World/TerrainLighting.cs
Normal file
@@ -0,0 +1,141 @@
|
||||
#region Copyright & License Information
|
||||
/*
|
||||
* Copyright 2007-2021 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, either version 3 of
|
||||
* the License, or (at your option) any later version. For more
|
||||
* information, see COPYING.
|
||||
*/
|
||||
#endregion
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using OpenRA.Primitives;
|
||||
using OpenRA.Support;
|
||||
using OpenRA.Traits;
|
||||
|
||||
namespace OpenRA.Mods.Common.Traits
|
||||
{
|
||||
[TraitLocation(SystemActors.World | SystemActors.EditorWorld)]
|
||||
[Desc("Add to the world actor to apply a global lighting tint and allow actors using the TerrainLightSource to add localised lighting.")]
|
||||
public class TerrainLightingInfo : TraitInfo, ILobbyCustomRulesIgnore
|
||||
{
|
||||
public readonly float Intensity = 1;
|
||||
public readonly float HeightStep = 0;
|
||||
public readonly float RedTint = 1;
|
||||
public readonly float GreenTint = 1;
|
||||
public readonly float BlueTint = 1;
|
||||
|
||||
[Desc("Size of light source partition bins (cells)")]
|
||||
public readonly int BinSize = 10;
|
||||
|
||||
public override object Create(ActorInitializer init) { return new TerrainLighting(init.World, this); }
|
||||
}
|
||||
|
||||
public sealed class TerrainLighting : ITerrainLighting
|
||||
{
|
||||
class LightSource
|
||||
{
|
||||
public readonly WPos Pos;
|
||||
public readonly CPos Cell;
|
||||
public readonly WDist Range;
|
||||
public readonly float Intensity;
|
||||
public readonly float3 Tint;
|
||||
|
||||
public LightSource(WPos pos, CPos cell, WDist range, float intensity, in float3 tint)
|
||||
{
|
||||
Pos = pos;
|
||||
Cell = cell;
|
||||
Range = range;
|
||||
Intensity = intensity;
|
||||
Tint = tint;
|
||||
}
|
||||
}
|
||||
|
||||
readonly TerrainLightingInfo info;
|
||||
readonly Map map;
|
||||
readonly Dictionary<int, LightSource> lightSources = new Dictionary<int, LightSource>();
|
||||
readonly SpatiallyPartitioned<LightSource> partitionedLightSources;
|
||||
readonly float3 globalTint;
|
||||
int nextLightSourceToken = 1;
|
||||
|
||||
public event Action<MPos> CellChanged = null;
|
||||
|
||||
public TerrainLighting(World world, TerrainLightingInfo info)
|
||||
{
|
||||
this.info = info;
|
||||
map = world.Map;
|
||||
globalTint = new float3(info.RedTint, info.GreenTint, info.BlueTint);
|
||||
|
||||
var cellSize = map.Grid.Type == MapGridType.RectangularIsometric ? 1448 : 1024;
|
||||
partitionedLightSources = new SpatiallyPartitioned<LightSource>(
|
||||
(map.MapSize.X + 1) * cellSize,
|
||||
(map.MapSize.Y + 1) * cellSize,
|
||||
info.BinSize * cellSize);
|
||||
}
|
||||
|
||||
Rectangle Bounds(LightSource source)
|
||||
{
|
||||
var c = source.Pos;
|
||||
var r = source.Range.Length;
|
||||
return new Rectangle(c.X - r, c.Y - r, 2 * r, 2 * r);
|
||||
}
|
||||
|
||||
public int AddLightSource(WPos pos, WDist range, float intensity, in float3 tint)
|
||||
{
|
||||
var token = nextLightSourceToken++;
|
||||
var source = new LightSource(pos, map.CellContaining(pos), range, intensity, tint);
|
||||
var bounds = Bounds(source);
|
||||
lightSources.Add(token, source);
|
||||
partitionedLightSources.Add(source, bounds);
|
||||
|
||||
if (CellChanged != null)
|
||||
foreach (var c in map.FindTilesInCircle(source.Cell, (source.Range.Length + 1023) / 1024))
|
||||
CellChanged(c.ToMPos(map));
|
||||
|
||||
return token;
|
||||
}
|
||||
|
||||
public void RemoveLightSource(int token)
|
||||
{
|
||||
if (!lightSources.TryGetValue(token, out var source))
|
||||
return;
|
||||
|
||||
lightSources.Remove(token);
|
||||
partitionedLightSources.Remove(source);
|
||||
if (CellChanged != null)
|
||||
foreach (var c in map.FindTilesInCircle(source.Cell, (source.Range.Length + 1023) / 1024))
|
||||
CellChanged(c.ToMPos(map));
|
||||
}
|
||||
|
||||
float3 ITerrainLighting.TintAt(WPos pos)
|
||||
{
|
||||
using (new PerfSample("terrain_lighting"))
|
||||
{
|
||||
var uv = map.CellContaining(pos).ToMPos(map);
|
||||
var tint = globalTint;
|
||||
if (!map.Height.Contains(uv))
|
||||
return tint;
|
||||
|
||||
var intensity = info.Intensity + info.HeightStep * map.Height[uv];
|
||||
if (lightSources.Count > 0)
|
||||
{
|
||||
foreach (var source in partitionedLightSources.At(new int2(pos.X, pos.Y)))
|
||||
{
|
||||
var range = source.Range.Length;
|
||||
var distance = (source.Pos - pos).Length;
|
||||
if (distance > range)
|
||||
continue;
|
||||
|
||||
var falloff = (range - distance) * 1f / range;
|
||||
intensity += falloff * source.Intensity;
|
||||
tint += falloff * source.Tint;
|
||||
}
|
||||
}
|
||||
|
||||
return intensity * tint;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -15,6 +15,7 @@ using OpenRA.Traits;
|
||||
|
||||
namespace OpenRA.Mods.Common.Traits
|
||||
{
|
||||
[TraitLocation(SystemActors.World)]
|
||||
public class TerrainTunnelInfo : TraitInfo<TerrainTunnel>, Requires<TerrainTunnelLayerInfo>, ILobbyCustomRulesIgnore
|
||||
{
|
||||
[FieldLoader.Require]
|
||||
|
||||
@@ -16,6 +16,7 @@ using OpenRA.Traits;
|
||||
|
||||
namespace OpenRA.Mods.Common.Traits
|
||||
{
|
||||
[TraitLocation(SystemActors.World)]
|
||||
public class TerrainTunnelLayerInfo : TraitInfo, Requires<DomainIndexInfo>, ILobbyCustomRulesIgnore
|
||||
{
|
||||
[Desc("Terrain type used by cells outside any tunnel footprint.")]
|
||||
|
||||
178
OpenRA.Mods.Common/Traits/World/TimeLimitManager.cs
Normal file
178
OpenRA.Mods.Common/Traits/World/TimeLimitManager.cs
Normal file
@@ -0,0 +1,178 @@
|
||||
#region Copyright & License Information
|
||||
/*
|
||||
* Copyright 2007-2021 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, either version 3 of
|
||||
* the License, or (at your option) any later version. For more
|
||||
* information, see COPYING.
|
||||
*/
|
||||
#endregion
|
||||
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using OpenRA.Mods.Common.Widgets;
|
||||
using OpenRA.Traits;
|
||||
using OpenRA.Widgets;
|
||||
|
||||
namespace OpenRA.Mods.Common.Traits
|
||||
{
|
||||
[TraitLocation(SystemActors.World)]
|
||||
[Desc("This trait allows setting a time limit on matches. Attach this to the World actor.")]
|
||||
public class TimeLimitManagerInfo : TraitInfo, ILobbyOptions, IRulesetLoaded
|
||||
{
|
||||
[Desc("Label that will be shown for the time limit option in the lobby.")]
|
||||
public readonly string TimeLimitLabel = "Time Limit";
|
||||
|
||||
[Desc("Tooltip description that will be shown for the time limit option in the lobby.")]
|
||||
public readonly string TimeLimitDescription = "Player or team with the highest score after this time wins";
|
||||
|
||||
[Desc("Time Limit options that will be shown in the lobby dropdown. Values are in minutes.")]
|
||||
public readonly int[] TimeLimitOptions = { 0, 10, 20, 30, 40, 60, 90 };
|
||||
|
||||
[Desc("List of remaining minutes of game time when a text and optional speech notification should be made to players.")]
|
||||
public readonly Dictionary<int, string> TimeLimitWarnings = new Dictionary<int, string>
|
||||
{
|
||||
{ 1, null },
|
||||
{ 2, null },
|
||||
{ 3, null },
|
||||
{ 4, null },
|
||||
{ 5, null },
|
||||
{ 10, null },
|
||||
};
|
||||
|
||||
[Desc("Default selection for the time limit option in the lobby. Needs to use one of the TimeLimitOptions.")]
|
||||
public readonly int TimeLimitDefault = 0;
|
||||
|
||||
[Desc("Prevent the time limit option from being changed in the lobby.")]
|
||||
public readonly bool TimeLimitLocked = false;
|
||||
|
||||
[Desc("Whether to display the options dropdown in the lobby.")]
|
||||
public readonly bool TimeLimitDropdownVisible = true;
|
||||
|
||||
[Desc("Display order for the time limit dropdown in the lobby.")]
|
||||
public readonly int TimeLimitDisplayOrder = 0;
|
||||
|
||||
[Desc("Notification text for time limit warnings. The string '{0}' will be replaced by the remaining time in minutes, '{1}' is used for the plural form.")]
|
||||
public readonly string Notification = "{0} minute{1} remaining.";
|
||||
|
||||
[Desc("ID of the LabelWidget used to display a text ingame that will be updated every second.")]
|
||||
public readonly string CountdownLabel = null;
|
||||
|
||||
[Desc("Text to be shown using the CountdownLabel. The string '{0}' will be replaced by the time in hh:mm:ss format.")]
|
||||
public readonly string CountdownText = null;
|
||||
|
||||
[Desc("Will prevent showing/playing the built-in time limit warnings when set to true.")]
|
||||
public readonly bool SkipTimeRemainingNotifications = false;
|
||||
|
||||
[Desc("Will prevent showing/playing the built-in timer expired notification when set to true.")]
|
||||
public readonly bool SkipTimerExpiredNotification = false;
|
||||
|
||||
void IRulesetLoaded<ActorInfo>.RulesetLoaded(Ruleset rules, ActorInfo info)
|
||||
{
|
||||
if (!TimeLimitOptions.Contains(TimeLimitDefault))
|
||||
throw new YamlException("TimeLimitDefault must be a value from TimeLimitOptions");
|
||||
}
|
||||
|
||||
IEnumerable<LobbyOption> ILobbyOptions.LobbyOptions(MapPreview map)
|
||||
{
|
||||
var timelimits = TimeLimitOptions.ToDictionary(c => c.ToString(), c =>
|
||||
{
|
||||
if (c == 0)
|
||||
return "No limit";
|
||||
else
|
||||
return c.ToString() + $" minute{(c > 1 ? "s" : null)}";
|
||||
});
|
||||
|
||||
yield return new LobbyOption("timelimit", TimeLimitLabel, TimeLimitDescription, TimeLimitDropdownVisible, TimeLimitDisplayOrder,
|
||||
timelimits, TimeLimitDefault.ToString(), TimeLimitLocked);
|
||||
}
|
||||
|
||||
public override object Create(ActorInitializer init) { return new TimeLimitManager(init.Self, this); }
|
||||
}
|
||||
|
||||
public class TimeLimitManager : INotifyTimeLimit, ITick, IWorldLoaded
|
||||
{
|
||||
readonly TimeLimitManagerInfo info;
|
||||
readonly int ticksPerSecond;
|
||||
MapOptions mapOptions;
|
||||
LabelWidget countdownLabel;
|
||||
CachedTransform<int, string> countdown;
|
||||
int ticksRemaining;
|
||||
|
||||
public int TimeLimit;
|
||||
public string Notification;
|
||||
|
||||
public TimeLimitManager(Actor self, TimeLimitManagerInfo info)
|
||||
{
|
||||
this.info = info;
|
||||
Notification = info.Notification;
|
||||
ticksPerSecond = 1000 / self.World.Timestep;
|
||||
|
||||
var tl = self.World.LobbyInfo.GlobalSettings.OptionOrDefault("timelimit", info.TimeLimitDefault.ToString());
|
||||
if (!int.TryParse(tl, out TimeLimit))
|
||||
TimeLimit = info.TimeLimitDefault;
|
||||
|
||||
// Convert from minutes to ticks
|
||||
TimeLimit *= 60 * ticksPerSecond;
|
||||
}
|
||||
|
||||
void IWorldLoaded.WorldLoaded(World w, OpenRA.Graphics.WorldRenderer wr)
|
||||
{
|
||||
mapOptions = w.WorldActor.Trait<MapOptions>();
|
||||
if (string.IsNullOrWhiteSpace(info.CountdownLabel) || string.IsNullOrWhiteSpace(info.CountdownText))
|
||||
return;
|
||||
|
||||
countdownLabel = Ui.Root.GetOrNull<LabelWidget>(info.CountdownLabel);
|
||||
if (countdownLabel != null)
|
||||
{
|
||||
countdown = new CachedTransform<int, string>(t =>
|
||||
info.CountdownText.F(WidgetUtils.FormatTime(t, true, w.Timestep)));
|
||||
countdownLabel.GetText = () => countdown.Update(ticksRemaining);
|
||||
}
|
||||
}
|
||||
|
||||
void ITick.Tick(Actor self)
|
||||
{
|
||||
if (TimeLimit <= 0)
|
||||
return;
|
||||
|
||||
ticksRemaining = TimeLimit - self.World.WorldTick;
|
||||
|
||||
if (ticksRemaining == 0)
|
||||
{
|
||||
foreach (var ntl in self.TraitsImplementing<INotifyTimeLimit>())
|
||||
ntl.NotifyTimerExpired(self);
|
||||
|
||||
foreach (var p in self.World.Players)
|
||||
foreach (var ntl in p.PlayerActor.TraitsImplementing<INotifyTimeLimit>())
|
||||
ntl.NotifyTimerExpired(p.PlayerActor);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
if (ticksRemaining < 0 || info.SkipTimeRemainingNotifications)
|
||||
return;
|
||||
|
||||
foreach (var m in info.TimeLimitWarnings.Keys)
|
||||
{
|
||||
if (ticksRemaining == m * 60 * ticksPerSecond)
|
||||
{
|
||||
TextNotificationsManager.AddSystemLine(Notification.F(m, m > 1 ? "s" : null));
|
||||
|
||||
var faction = self.World.LocalPlayer == null ? null : self.World.LocalPlayer.Faction.InternalName;
|
||||
Game.Sound.PlayNotification(self.World.Map.Rules, self.World.LocalPlayer, "Speech", info.TimeLimitWarnings[m], faction);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void INotifyTimeLimit.NotifyTimerExpired(Actor self)
|
||||
{
|
||||
if (countdownLabel != null)
|
||||
countdownLabel.GetText = () => null;
|
||||
|
||||
if (!info.SkipTimerExpiredNotification)
|
||||
TextNotificationsManager.AddSystemLine("Time limit has expired.");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -18,6 +18,7 @@ using OpenRA.Traits;
|
||||
namespace OpenRA.Mods.Common.Traits
|
||||
{
|
||||
[Desc("Adds a particle-based overlay.")]
|
||||
[TraitLocation(SystemActors.World | SystemActors.EditorWorld)]
|
||||
public class WeatherOverlayInfo : TraitInfo, ILobbyCustomRulesIgnore
|
||||
{
|
||||
[Desc("Average number of particles per 100x100 px square.")]
|
||||
|
||||
Reference in New Issue
Block a user