Convert lobby checkboxes to new options backend.
This commit is contained in:
@@ -54,7 +54,8 @@ namespace OpenRA.Mods.Common.Traits
|
||||
var map = init.World.Map;
|
||||
|
||||
// Explore map-placed actors if the "Explore Map" option is enabled
|
||||
var exploredMap = !init.World.LobbyInfo.GlobalSettings.Shroud;
|
||||
var shroudInfo = init.World.Map.Rules.Actors["player"].TraitInfo<ShroudInfo>();
|
||||
var exploredMap = init.World.LobbyInfo.GlobalSettings.OptionOrDefault("explored", shroudInfo.ExploredMapEnabled);
|
||||
startsRevealed = exploredMap && init.Contains<SpawnedByMapInit>() && !init.Contains<HiddenUnderFogInit>();
|
||||
var footprintCells = FootprintUtils.FrozenUnderFogTiles(init.Self).ToList();
|
||||
footprint = footprintCells.SelectMany(c => map.ProjectedCellsCovering(c.ToMPos(map))).ToArray();
|
||||
|
||||
@@ -13,12 +13,13 @@ using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using OpenRA.Mods.Common.Activities;
|
||||
using OpenRA.Network;
|
||||
using OpenRA.Primitives;
|
||||
using OpenRA.Traits;
|
||||
|
||||
namespace OpenRA.Mods.Common.Traits
|
||||
{
|
||||
public class CrateSpawnerInfo : ITraitInfo
|
||||
public class CrateSpawnerInfo : ITraitInfo, ILobbyOptions
|
||||
{
|
||||
[Desc("Default value of the crates checkbox in the lobby.")]
|
||||
public readonly bool Enabled = true;
|
||||
@@ -64,27 +65,39 @@ namespace OpenRA.Mods.Common.Traits
|
||||
[Desc("Spawn and remove the plane this far outside the map.")]
|
||||
public readonly WDist Cordon = new WDist(5120);
|
||||
|
||||
public object Create(ActorInitializer init) { return new CrateSpawner(this, init.Self); }
|
||||
IEnumerable<LobbyOption> ILobbyOptions.LobbyOptions(Ruleset rules)
|
||||
{
|
||||
yield return new LobbyBooleanOption("crates", "Crates", Enabled, Locked);
|
||||
}
|
||||
|
||||
public object Create(ActorInitializer init) { return new CrateSpawner(init.Self, this); }
|
||||
}
|
||||
|
||||
public class CrateSpawner : ITick
|
||||
public class CrateSpawner : ITick, INotifyCreated
|
||||
{
|
||||
readonly CrateSpawnerInfo info;
|
||||
readonly Actor self;
|
||||
int crates = 0;
|
||||
int ticks = 0;
|
||||
readonly CrateSpawnerInfo info;
|
||||
bool enabled;
|
||||
int crates;
|
||||
int ticks;
|
||||
|
||||
public CrateSpawner(CrateSpawnerInfo info, Actor self)
|
||||
public CrateSpawner(Actor self, CrateSpawnerInfo info)
|
||||
{
|
||||
this.info = info;
|
||||
this.self = self;
|
||||
this.info = info;
|
||||
|
||||
ticks = info.InitialSpawnDelay;
|
||||
}
|
||||
|
||||
void INotifyCreated.Created(Actor self)
|
||||
{
|
||||
enabled = self.World.LobbyInfo.GlobalSettings
|
||||
.OptionOrDefault("crates", info.Enabled);
|
||||
}
|
||||
|
||||
public void Tick(Actor self)
|
||||
{
|
||||
if (!self.World.LobbyInfo.GlobalSettings.Crates)
|
||||
if (!enabled)
|
||||
return;
|
||||
|
||||
if (--ticks <= 0)
|
||||
|
||||
@@ -15,22 +15,36 @@ using OpenRA.Traits;
|
||||
namespace OpenRA.Mods.Common.Traits
|
||||
{
|
||||
[Desc("Controls the build radius checkboxes in the lobby options.")]
|
||||
public class MapBuildRadiusInfo : TraitInfo<MapBuildRadius>
|
||||
public class MapBuildRadiusInfo : ITraitInfo, ILobbyOptions
|
||||
{
|
||||
[Desc("Default value of the ally build radius checkbox in the lobby.")]
|
||||
public readonly bool AllyBuildRadiusEnabled = true;
|
||||
|
||||
[Desc("Prevent the ally build radius state from being changed in the lobby.")]
|
||||
public readonly bool AllyBuildRadiusLocked = false;
|
||||
|
||||
IEnumerable<LobbyOption> ILobbyOptions.LobbyOptions(Ruleset rules)
|
||||
{
|
||||
yield return new LobbyBooleanOption("allybuild", "Build off Allies' ConYards", AllyBuildRadiusEnabled, AllyBuildRadiusLocked);
|
||||
}
|
||||
|
||||
public object Create(ActorInitializer init) { return new MapBuildRadius(this); }
|
||||
}
|
||||
|
||||
public class MapBuildRadius : INotifyCreated
|
||||
{
|
||||
readonly MapBuildRadiusInfo info;
|
||||
public bool AllyBuildRadiusEnabled { get; private set; }
|
||||
|
||||
public MapBuildRadius(MapBuildRadiusInfo info)
|
||||
{
|
||||
this.info = info;
|
||||
}
|
||||
|
||||
void INotifyCreated.Created(Actor self)
|
||||
{
|
||||
AllyBuildRadiusEnabled = self.World.LobbyInfo.GlobalSettings.AllyBuildRadius;
|
||||
AllyBuildRadiusEnabled = self.World.LobbyInfo.GlobalSettings
|
||||
.OptionOrDefault("allybuild", info.AllyBuildRadiusEnabled);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -15,22 +15,36 @@ using OpenRA.Traits;
|
||||
namespace OpenRA.Mods.Common.Traits
|
||||
{
|
||||
[Desc("Controls the 'Creeps' checkbox in the lobby options.")]
|
||||
public class MapCreepsInfo : TraitInfo<MapCreeps>
|
||||
public class MapCreepsInfo : ITraitInfo, ILobbyOptions
|
||||
{
|
||||
[Desc("Default value of the creeps checkbox in the lobby.")]
|
||||
public readonly bool Enabled = true;
|
||||
|
||||
[Desc("Prevent the creeps state from being changed in the lobby.")]
|
||||
public readonly bool Locked = false;
|
||||
|
||||
IEnumerable<LobbyOption> ILobbyOptions.LobbyOptions(Ruleset rules)
|
||||
{
|
||||
yield return new LobbyBooleanOption("creeps", "Worms", Enabled, Locked);
|
||||
}
|
||||
|
||||
public object Create(ActorInitializer init) { return new MapCreeps(this); }
|
||||
}
|
||||
|
||||
public class MapCreeps : INotifyCreated
|
||||
{
|
||||
readonly MapCreepsInfo info;
|
||||
public bool Enabled { get; private set; }
|
||||
|
||||
public MapCreeps(MapCreepsInfo info)
|
||||
{
|
||||
this.info = info;
|
||||
}
|
||||
|
||||
void INotifyCreated.Created(Actor self)
|
||||
{
|
||||
Enabled = self.World.LobbyInfo.GlobalSettings.Creeps;
|
||||
Enabled = self.World.LobbyInfo.GlobalSettings
|
||||
.OptionOrDefault("creeps", info.Enabled);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -15,7 +15,7 @@ using OpenRA.Traits;
|
||||
namespace OpenRA.Mods.Common.Traits
|
||||
{
|
||||
[Desc("Controls the map difficulty, tech level, and short game lobby options.")]
|
||||
public class MapOptionsInfo : TraitInfo<MapOptions>
|
||||
public class MapOptionsInfo : ITraitInfo, ILobbyOptions
|
||||
{
|
||||
[Desc("Default value of the short game checkbox in the lobby.")]
|
||||
public readonly bool ShortGameEnabled = true;
|
||||
@@ -37,15 +37,30 @@ namespace OpenRA.Mods.Common.Traits
|
||||
|
||||
[Desc("Prevent the difficulty from being changed in the lobby.")]
|
||||
public readonly bool DifficultyLocked = false;
|
||||
|
||||
IEnumerable<LobbyOption> ILobbyOptions.LobbyOptions(Ruleset rules)
|
||||
{
|
||||
yield return new LobbyBooleanOption("shortgame", "Short Game", ShortGameEnabled, ShortGameLocked);
|
||||
}
|
||||
|
||||
public object Create(ActorInitializer init) { return new MapOptions(this); }
|
||||
}
|
||||
|
||||
public class MapOptions : INotifyCreated
|
||||
{
|
||||
readonly MapOptionsInfo info;
|
||||
|
||||
public bool ShortGame { get; private set; }
|
||||
|
||||
public MapOptions(MapOptionsInfo info)
|
||||
{
|
||||
this.info = info;
|
||||
}
|
||||
|
||||
void INotifyCreated.Created(Actor self)
|
||||
{
|
||||
ShortGame = self.World.LobbyInfo.GlobalSettings.ShortGame;
|
||||
ShortGame = self.World.LobbyInfo.GlobalSettings
|
||||
.OptionOrDefault("shortgame", info.ShortGameEnabled);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user