Convert lobby checkboxes to new options backend.

This commit is contained in:
Paul Chote
2016-04-20 08:08:38 +02:00
parent 3e92c1944a
commit eb884ca76f
14 changed files with 134 additions and 328 deletions

View File

@@ -191,20 +191,12 @@ namespace OpenRA.Network
public int Timestep = 40;
public int OrderLatency = 3; // net tick frames (x 120 = ms)
public int RandomSeed = 0;
public bool AllowCheats = false;
public bool AllowSpectators = true;
public bool Dedicated;
public string Difficulty;
public bool Crates = true;
public bool Creeps = true;
public bool Shroud = true;
public bool Fog = true;
public bool AllyBuildRadius = true;
public int StartingCash = 5000;
public string TechLevel;
public string StartingUnitsClass;
public string GameSpeedType = "default";
public bool ShortGame = true;
public bool AllowVersionMismatch;
public string GameUid;
public bool DisableSingleplayer;

View File

@@ -149,7 +149,6 @@ namespace OpenRA.Server
RandomSeed = randomSeed,
Map = settings.Map,
ServerName = settings.Name,
Dedicated = dedicated,
DisableSingleplayer = settings.DisableSinglePlayer,
}
};

View File

@@ -9,10 +9,12 @@
*/
#endregion
using System.Collections.Generic;
namespace OpenRA.Traits
{
[Desc("Attach this to the player actor.")]
public class DeveloperModeInfo : ITraitInfo
public class DeveloperModeInfo : ITraitInfo, ILobbyOptions
{
[Desc("Default value of the developer mode checkbox in the lobby.")]
public bool Enabled = false;
@@ -56,6 +58,11 @@ namespace OpenRA.Traits
[Desc("Enable the actor tags overlay by default.")]
public bool ShowActorTags;
IEnumerable<LobbyOption> ILobbyOptions.LobbyOptions(Ruleset rules)
{
yield return new LobbyBooleanOption("cheats", "Debug Menu", Enabled, Locked);
}
public object Create(ActorInitializer init) { return new DeveloperMode(this); }
}
@@ -106,7 +113,8 @@ namespace OpenRA.Traits
void INotifyCreated.Created(Actor self)
{
Enabled = self.World.LobbyInfo.GlobalSettings.AllowCheats || self.World.LobbyInfo.IsSinglePlayer;
Enabled = self.World.LobbyInfo.IsSinglePlayer || self.World.LobbyInfo.GlobalSettings
.OptionOrDefault("cheats", info.Enabled);
}
public void ResolveOrder(Actor self, Order order)

View File

@@ -12,11 +12,12 @@
using System;
using System.Collections.Generic;
using System.Linq;
using OpenRA.Network;
namespace OpenRA.Traits
{
[Desc("Required for shroud and fog visibility checks. Add this to the player actor.")]
public class ShroudInfo : ITraitInfo
public class ShroudInfo : ITraitInfo, ILobbyOptions
{
[Desc("Default value of the fog checkbox in the lobby.")]
public bool FogEnabled = true;
@@ -30,7 +31,13 @@ namespace OpenRA.Traits
[Desc("Prevent the explore map enabled state from being changed in the lobby.")]
public bool ExploredMapLocked = false;
public object Create(ActorInitializer init) { return new Shroud(init.Self); }
IEnumerable<LobbyOption> ILobbyOptions.LobbyOptions(Ruleset rules)
{
yield return new LobbyBooleanOption("explored", "Explored Map", ExploredMapEnabled, ExploredMapLocked);
yield return new LobbyBooleanOption("fog", "Fog of War", FogEnabled, FogLocked);
}
public object Create(ActorInitializer init) { return new Shroud(init.Self, this); }
}
public class Shroud : ISync, INotifyCreated
@@ -38,6 +45,7 @@ namespace OpenRA.Traits
public event Action<IEnumerable<PPos>> CellsChanged;
readonly Actor self;
readonly ShroudInfo info;
readonly Map map;
readonly CellLayer<short> visibleCount;
@@ -72,9 +80,10 @@ namespace OpenRA.Traits
public int Hash { get; private set; }
public Shroud(Actor self)
public Shroud(Actor self, ShroudInfo info)
{
this.self = self;
this.info = info;
map = self.World.Map;
visibleCount = new CellLayer<short>(map);
@@ -84,9 +93,11 @@ namespace OpenRA.Traits
void INotifyCreated.Created(Actor self)
{
fogEnabled = self.World.LobbyInfo.GlobalSettings.Fog;
var shroudEnabled = self.World.LobbyInfo.GlobalSettings.Shroud;
if (!shroudEnabled)
var gs = self.World.LobbyInfo.GlobalSettings;
fogEnabled = gs.OptionOrDefault("fog", info.FogEnabled);
var exploreMap = gs.OptionOrDefault("explored", info.ExploredMapEnabled);
if (exploreMap)
self.World.AddFrameEndTask(w => ExploreAll());
}