Merge pull request #11176 from pchote/lobby-trait-checkbox-prep

Query lobby checkbox state via their owning traits.
This commit is contained in:
reaperrr
2016-05-16 19:00:35 +02:00
18 changed files with 194 additions and 148 deletions

View File

@@ -59,16 +59,26 @@ namespace OpenRA.Traits
public object Create(ActorInitializer init) { return new DeveloperMode(this); }
}
public class DeveloperMode : IResolveOrder, ISync
public class DeveloperMode : IResolveOrder, ISync, INotifyCreated
{
DeveloperModeInfo info;
[Sync] public bool FastCharge;
[Sync] public bool AllTech;
[Sync] public bool FastBuild;
[Sync] public bool DisableShroud;
[Sync] public bool PathDebug;
[Sync] public bool UnlimitedPower;
[Sync] public bool BuildAnywhere;
readonly DeveloperModeInfo info;
public bool Enabled { get; private set; }
[Sync] bool fastCharge;
[Sync] bool allTech;
[Sync] bool fastBuild;
[Sync] bool disableShroud;
[Sync] bool pathDebug;
[Sync] bool unlimitedPower;
[Sync] bool buildAnywhere;
public bool FastCharge { get { return Enabled && fastCharge; } }
public bool AllTech { get { return Enabled && allTech; } }
public bool FastBuild { get { return Enabled && fastBuild; } }
public bool DisableShroud { get { return Enabled && disableShroud; } }
public bool PathDebug { get { return Enabled && pathDebug; } }
public bool UnlimitedPower { get { return Enabled && unlimitedPower; } }
public bool BuildAnywhere { get { return Enabled && buildAnywhere; } }
// Client side only
public bool ShowCombatGeometry;
@@ -76,128 +86,131 @@ namespace OpenRA.Traits
public bool ShowDepthPreview;
public bool ShowActorTags;
public bool EnableAll;
bool enableAll;
public DeveloperMode(DeveloperModeInfo info)
{
this.info = info;
FastBuild = info.FastBuild;
FastCharge = info.FastCharge;
DisableShroud = info.DisableShroud;
PathDebug = info.PathDebug;
UnlimitedPower = info.UnlimitedPower;
BuildAnywhere = info.BuildAnywhere;
fastBuild = info.FastBuild;
fastCharge = info.FastCharge;
disableShroud = info.DisableShroud;
pathDebug = info.PathDebug;
unlimitedPower = info.UnlimitedPower;
buildAnywhere = info.BuildAnywhere;
ShowCombatGeometry = info.ShowCombatGeometry;
ShowDebugGeometry = info.ShowDebugGeometry;
ShowDepthPreview = info.ShowDepthPreview;
ShowActorTags = info.ShowActorTags;
}
void INotifyCreated.Created(Actor self)
{
Enabled = self.World.LobbyInfo.GlobalSettings.AllowCheats || self.World.LobbyInfo.IsSinglePlayer;
}
public void ResolveOrder(Actor self, Order order)
{
if (!self.World.AllowDevCommands)
if (!Enabled)
return;
switch (order.OrderString)
{
case "DevAll":
{
enableAll ^= true;
allTech = fastCharge = fastBuild = disableShroud = unlimitedPower = buildAnywhere = enableAll;
if (enableAll)
{
EnableAll ^= true;
AllTech = FastCharge = FastBuild = DisableShroud = UnlimitedPower = BuildAnywhere = EnableAll;
self.Owner.Shroud.ExploreAll();
if (EnableAll)
{
self.Owner.Shroud.ExploreAll(self.World);
var amount = order.ExtraData != 0 ? (int)order.ExtraData : info.Cash;
self.Trait<PlayerResources>().GiveCash(amount);
}
else
{
self.Owner.Shroud.ResetExploration();
}
self.Owner.Shroud.Disabled = DisableShroud;
if (self.World.LocalPlayer == self.Owner)
self.World.RenderPlayer = DisableShroud ? null : self.Owner;
break;
}
case "DevEnableTech":
{
AllTech ^= true;
break;
}
case "DevFastCharge":
{
FastCharge ^= true;
break;
}
case "DevFastBuild":
{
FastBuild ^= true;
break;
}
case "DevGiveCash":
{
var amount = order.ExtraData != 0 ? (int)order.ExtraData : info.Cash;
self.Trait<PlayerResources>().GiveCash(amount);
break;
}
else
self.Owner.Shroud.ResetExploration();
self.Owner.Shroud.Disabled = DisableShroud;
if (self.World.LocalPlayer == self.Owner)
self.World.RenderPlayer = DisableShroud ? null : self.Owner;
break;
}
case "DevEnableTech":
{
allTech ^= true;
break;
}
case "DevFastCharge":
{
fastCharge ^= true;
break;
}
case "DevFastBuild":
{
fastBuild ^= true;
break;
}
case "DevGiveCash":
{
var amount = order.ExtraData != 0 ? (int)order.ExtraData : info.Cash;
self.Trait<PlayerResources>().GiveCash(amount);
break;
}
case "DevGrowResources":
{
foreach (var a in self.World.ActorsWithTrait<ISeedableResource>())
{
for (var i = 0; i < info.ResourceGrowth; i++)
a.Trait.Seed(a.Actor);
}
{
foreach (var a in self.World.ActorsWithTrait<ISeedableResource>())
for (var i = 0; i < info.ResourceGrowth; i++)
a.Trait.Seed(a.Actor);
break;
}
break;
}
case "DevVisibility":
{
DisableShroud ^= true;
self.Owner.Shroud.Disabled = DisableShroud;
if (self.World.LocalPlayer == self.Owner)
self.World.RenderPlayer = DisableShroud ? null : self.Owner;
break;
}
{
disableShroud ^= true;
self.Owner.Shroud.Disabled = DisableShroud;
if (self.World.LocalPlayer == self.Owner)
self.World.RenderPlayer = DisableShroud ? null : self.Owner;
break;
}
case "DevPathDebug":
{
PathDebug ^= true;
break;
}
{
pathDebug ^= true;
break;
}
case "DevGiveExploration":
{
self.Owner.Shroud.ExploreAll(self.World);
break;
}
{
self.Owner.Shroud.ExploreAll();
break;
}
case "DevResetExploration":
{
self.Owner.Shroud.ResetExploration();
break;
}
{
self.Owner.Shroud.ResetExploration();
break;
}
case "DevUnlimitedPower":
{
UnlimitedPower ^= true;
break;
}
{
unlimitedPower ^= true;
break;
}
case "DevBuildAnywhere":
{
BuildAnywhere ^= true;
break;
}
{
buildAnywhere ^= true;
break;
}
default:
return;

View File

@@ -33,7 +33,7 @@ namespace OpenRA.Traits
public object Create(ActorInitializer init) { return new Shroud(init.Self); }
}
public class Shroud : ISync
public class Shroud : ISync, INotifyCreated
{
public event Action<IEnumerable<PPos>> CellsChanged;
@@ -67,6 +67,9 @@ namespace OpenRA.Traits
}
}
bool fogEnabled;
public bool FogEnabled { get { return !Disabled && fogEnabled; } }
public int Hash { get; private set; }
public Shroud(Actor self)
@@ -79,6 +82,14 @@ namespace OpenRA.Traits
explored = new CellLayer<bool>(map);
}
void INotifyCreated.Created(Actor self)
{
fogEnabled = self.World.LobbyInfo.GlobalSettings.Fog;
var shroudEnabled = self.World.LobbyInfo.GlobalSettings.Shroud;
if (!shroudEnabled)
self.World.AddFrameEndTask(w => ExploreAll());
}
void Invalidate(IEnumerable<PPos> changed)
{
if (CellsChanged != null)
@@ -241,7 +252,7 @@ namespace OpenRA.Traits
Invalidate(changed);
}
public void ExploreAll(World world)
public void ExploreAll()
{
var changed = new List<PPos>();
foreach (var puv in map.ProjectedCellBounds)
@@ -298,15 +309,13 @@ namespace OpenRA.Traits
public bool IsExplored(PPos puv)
{
if (!ShroudEnabled)
if (Disabled)
return map.Contains(puv);
var uv = (MPos)puv;
return explored.Contains(uv) && explored[uv] && (generatedShroudCount[uv] == 0 || visibleCount[uv] > 0);
}
public bool ShroudEnabled { get { return !Disabled; } }
public bool IsVisible(WPos pos)
{
return IsVisible(map.ProjectedCellCovering(pos));
@@ -339,8 +348,6 @@ namespace OpenRA.Traits
return visibleCount.Contains(uv) && visibleCount[uv] > 0;
}
public bool FogEnabled { get { return !Disabled && self.World.LobbyInfo.GlobalSettings.Fog; } }
public bool Contains(PPos uv)
{
// Check that uv is inside the map area. There is nothing special

View File

@@ -85,11 +85,6 @@ namespace OpenRA
get { return OrderManager.Connection is ReplayConnection; }
}
public bool AllowDevCommands
{
get { return LobbyInfo.GlobalSettings.AllowCheats || LobbyInfo.IsSinglePlayer; }
}
void SetLocalPlayer(Player localPlayer)
{
if (localPlayer == null)
@@ -184,10 +179,6 @@ namespace OpenRA
MapUid = Map.Uid,
MapTitle = Map.Title
};
if (!LobbyInfo.GlobalSettings.Shroud)
foreach (var player in Players)
player.Shroud.ExploreAll(this);
}
public void AddToMaps(Actor self, IOccupySpace ios)