fix indents everywhere

This commit is contained in:
Chris Forbes
2011-10-18 15:10:17 +13:00
parent 227bbc109e
commit bc6af1841b
180 changed files with 2707 additions and 2707 deletions

View File

@@ -82,7 +82,7 @@ namespace OpenRA
// auto size from render
var firstSprite = TraitsImplementing<IRender>().SelectMany(ApplyIRender).FirstOrDefault();
if (firstSprite.Sprite == null) return int2.Zero;
return (firstSprite.Sprite.size * firstSprite.Scale).ToInt2();
return (firstSprite.Sprite.size * firstSprite.Scale).ToInt2();
});
ApplyIRender = x => x.Render(this);
@@ -105,7 +105,7 @@ namespace OpenRA
get { return currentActivity == null; }
}
OpenRA.FileFormats.Lazy<int2> Size;
OpenRA.FileFormats.Lazy<int2> Size;
// note: these delegates are cached to avoid massive allocation.
Func<IRender, IEnumerable<Renderable>> ApplyIRender;

View File

@@ -23,29 +23,29 @@ namespace OpenRA
public ActorInfo( string name, MiniYaml node, Dictionary<string, MiniYaml> allUnits )
{
try
{
var mergedNode = MergeWithParent(node, allUnits).NodesDict;
try
{
var mergedNode = MergeWithParent(node, allUnits).NodesDict;
Name = name;
foreach (var t in mergedNode)
if (t.Key != "Inherits" && !t.Key.StartsWith("-"))
Traits.Add(LoadTraitInfo(t.Key.Split('@')[0], t.Value));
}
catch (YamlException e)
{
throw new YamlException("Actor type {0}: {1}".F(name, e.Message));
}
Name = name;
foreach (var t in mergedNode)
if (t.Key != "Inherits" && !t.Key.StartsWith("-"))
Traits.Add(LoadTraitInfo(t.Key.Split('@')[0], t.Value));
}
catch (YamlException e)
{
throw new YamlException("Actor type {0}: {1}".F(name, e.Message));
}
}
static IEnumerable<MiniYaml> GetInheritanceChain(MiniYaml node, Dictionary<string, MiniYaml> allUnits)
{
while (node != null)
{
yield return node;
node = GetParent(node, allUnits);
}
}
static IEnumerable<MiniYaml> GetInheritanceChain(MiniYaml node, Dictionary<string, MiniYaml> allUnits)
{
while (node != null)
{
yield return node;
node = GetParent(node, allUnits);
}
}
static MiniYaml GetParent( MiniYaml node, Dictionary<string, MiniYaml> allUnits )
{
@@ -56,9 +56,9 @@ namespace OpenRA
MiniYaml parent;
allUnits.TryGetValue( inherits.Value, out parent );
if (parent == null)
throw new InvalidOperationException(
"Bogus inheritance -- actor type {0} does not exist".F(inherits.Value));
if (parent == null)
throw new InvalidOperationException(
"Bogus inheritance -- actor type {0} does not exist".F(inherits.Value));
return parent;
}
@@ -66,14 +66,14 @@ namespace OpenRA
static MiniYaml MergeWithParent( MiniYaml node, Dictionary<string, MiniYaml> allUnits )
{
var parent = GetParent( node, allUnits );
if (parent != null)
{
var result = MiniYaml.MergeStrict(node, MergeWithParent(parent, allUnits));
if (parent != null)
{
var result = MiniYaml.MergeStrict(node, MergeWithParent(parent, allUnits));
// strip the '-'
result.Nodes.RemoveAll(a => a.Key.StartsWith("-"));
return result;
}
// strip the '-'
result.Nodes.RemoveAll(a => a.Key.StartsWith("-"));
return result;
}
return node;
}

View File

@@ -49,7 +49,7 @@ namespace OpenRA.GameRules
public bool PerfText = false;
public bool PerfGraph = false;
public float LongTickThreshold = 0.001f;
public bool SanityCheckUnsyncedCode = false;
public bool SanityCheckUnsyncedCode = false;
public int Samples = 25;
}
@@ -79,7 +79,7 @@ namespace OpenRA.GameRules
public class PlayerSettings
{
public string Name = "Newbie";
public ColorRamp ColorRamp = new ColorRamp(75, 255, 180, 25);
public ColorRamp ColorRamp = new ColorRamp(75, 255, 180, 25);
public string LastServer = "localhost:1234";
}
@@ -91,8 +91,8 @@ namespace OpenRA.GameRules
public bool TeamChatToggle = false;
public bool ViewportEdgeScroll = true;
public MouseScrollType MouseScroll = MouseScrollType.Standard;
public bool ViewportEdgeScroll = true;
public MouseScrollType MouseScroll = MouseScrollType.Standard;
public float ViewportEdgeScrollStep = 10f;
// Internal game settings

View File

@@ -60,10 +60,10 @@ namespace OpenRA.Graphics
Game.Renderer.WorldSpriteRenderer.DrawSprite( this, location, paletteIndex, this.size );
}
public void DrawAt(float2 location, int paletteIndex, float scale)
{
Game.Renderer.WorldSpriteRenderer.DrawSprite(this, location, paletteIndex, this.size * scale);
}
public void DrawAt(float2 location, int paletteIndex, float scale)
{
Game.Renderer.WorldSpriteRenderer.DrawSprite(this, location, paletteIndex, this.size * scale);
}
public void DrawAt( float2 location, int paletteIndex, float2 size )
{

View File

@@ -70,18 +70,18 @@ namespace OpenRA.Graphics
}
}
public void DrawTextWithContrast(string text, float2 location, Color fg, Color bg, int offset)
{
if (offset > 0)
{
DrawText(text, location + new float2(-offset, 0), bg);
DrawText(text, location + new float2(offset, 0), bg);
DrawText(text, location + new float2(0, -offset), bg);
DrawText(text, location + new float2(0, offset), bg);
}
public void DrawTextWithContrast(string text, float2 location, Color fg, Color bg, int offset)
{
if (offset > 0)
{
DrawText(text, location + new float2(-offset, 0), bg);
DrawText(text, location + new float2(offset, 0), bg);
DrawText(text, location + new float2(0, -offset), bg);
DrawText(text, location + new float2(0, offset), bg);
}
DrawText(text, location, fg);
}
DrawText(text, location, fg);
}
public int2 Measure(string text)
{

View File

@@ -22,7 +22,7 @@ namespace OpenRA.Graphics
sprites = new Cache<string, Sprite[]>( LoadSprites );
}
readonly SheetBuilder SheetBuilder;
readonly SheetBuilder SheetBuilder;
readonly Cache<string, Sprite[]> sprites;
readonly string[] exts;

View File

@@ -44,9 +44,9 @@ namespace OpenRA.Graphics
get
{
return new Rectangle(scrollPosition.X / Game.CellSize,
scrollPosition.Y / Game.CellSize,
(int)(screenSize.X / Zoom / Game.CellSize),
(int)(screenSize.Y / Zoom / Game.CellSize));
scrollPosition.Y / Game.CellSize,
(int)(screenSize.X / Zoom / Game.CellSize),
(int)(screenSize.Y / Zoom / Game.CellSize));
}
}
@@ -70,9 +70,9 @@ namespace OpenRA.Graphics
var viewBR = (Game.CellSize*new float2(mapBounds.Right, mapBounds.Bottom)).ToInt2();
var border = (.5f/Zoom * screenSize.ToFloat2()).ToInt2();
scrollLimits = Rectangle.FromLTRB(viewTL.X - border.X,
viewTL.Y - border.Y,
viewBR.X - border.X,
viewBR.Y - border.Y);
viewTL.Y - border.Y,
viewBR.X - border.X,
viewBR.Y - border.Y);
// Re-center viewport
scrollPosition = NormalizeScrollPosition((oldCenter - 0.5f / Zoom * screenSize.ToFloat2()).ToInt2());
}
@@ -135,13 +135,13 @@ namespace OpenRA.Graphics
{
Widget.DoDraw();
var cursorName = Widget.RootWidget.GetCursorOuter(Viewport.LastMousePos) ?? "default";
var cursorSequence = CursorProvider.GetCursorSequence(cursorName);
var cursorSequence = CursorProvider.GetCursorSequence(cursorName);
var cursorSprite = cursorSequence.GetSprite((int)cursorFrame);
renderer.SpriteRenderer.DrawSprite(cursorSprite,
Viewport.LastMousePos - cursorSequence.Hotspot,
Game.modData.Palette.GetPaletteIndex(cursorSequence.Palette),
cursorSprite.size);
Viewport.LastMousePos - cursorSequence.Hotspot,
Game.modData.Palette.GetPaletteIndex(cursorSequence.Palette),
cursorSprite.size);
}
using( new PerfSample("render_flip") )

View File

@@ -29,7 +29,7 @@ namespace OpenRA
public string Uid { get; protected set; }
public int MapFormat;
public bool Selectable;
public bool UseAsShellmap;
public bool UseAsShellmap;
public string RequiresMod;
public string Title;
@@ -120,7 +120,7 @@ namespace OpenRA
var yaml = new MiniYaml( null, MiniYaml.FromStream(Container.GetContent("map.yaml")) );
FieldLoader.Load(this, yaml);
Uid = ComputeHash();
Uid = ComputeHash();
// 'Simple' metadata
FieldLoader.Load( this, yaml );
@@ -394,16 +394,16 @@ namespace OpenRA
}
string ComputeHash()
{
// UID is calculated by taking an SHA1 of the yaml and binary data
// Read the relevant data into a buffer
var data = Container.GetContent("map.yaml").ReadAllBytes()
.Concat(Container.GetContent("map.bin").ReadAllBytes()).ToArray();
{
// UID is calculated by taking an SHA1 of the yaml and binary data
// Read the relevant data into a buffer
var data = Container.GetContent("map.yaml").ReadAllBytes()
.Concat(Container.GetContent("map.bin").ReadAllBytes()).ToArray();
// Take the SHA1
using (var csp = SHA1.Create())
return new string(csp.ComputeHash(data).SelectMany(a => a.ToString("x2")).ToArray());
}
// Take the SHA1
using (var csp = SHA1.Create())
return new string(csp.ComputeHash(data).SelectMany(a => a.ToString("x2")).ToArray());
}
public void MakeDefaultPlayers()
{

View File

@@ -82,21 +82,21 @@ namespace OpenRA
return map;
}
public static IEnumerable<string> FindMapsIn(string dir)
{
string[] NoMaps = { };
public static IEnumerable<string> FindMapsIn(string dir)
{
string[] NoMaps = { };
if (!Directory.Exists(dir))
return NoMaps;
if (!Directory.Exists(dir))
return NoMaps;
return Directory.GetDirectories(dir)
.Concat(Directory.GetFiles(dir, "*.zip"))
.Concat(Directory.GetFiles(dir, "*.oramap"));
}
return Directory.GetDirectories(dir)
.Concat(Directory.GetFiles(dir, "*.zip"))
.Concat(Directory.GetFiles(dir, "*.oramap"));
}
Dictionary<string, Map> FindMaps(string[] mods)
{
var paths = mods.SelectMany(p => FindMapsIn("mods{0}{1}{0}maps{0}".F(Path.DirectorySeparatorChar, p)))
var paths = mods.SelectMany(p => FindMapsIn("mods{0}{1}{0}maps{0}".F(Path.DirectorySeparatorChar, p)))
.Concat(mods.SelectMany(p => FindMapsIn("{1}maps{0}{2}{0}".F(Path.DirectorySeparatorChar, Platform.SupportDir, p))));
var ret = new Dictionary<string, Map>();

View File

@@ -18,7 +18,7 @@ using OpenRA.Support;
namespace OpenRA.Network
{
public enum ConnectionState
public enum ConnectionState
{
PreConnecting,
NotConnected,
@@ -26,7 +26,7 @@ namespace OpenRA.Network
Connected,
}
public interface IConnection : IDisposable
public interface IConnection : IDisposable
{
int LocalClientId { get; }
ConnectionState ConnectionState { get; }

View File

@@ -44,17 +44,17 @@ namespace OpenRA.Network
frameData.Add( clientId, orders );
}
public bool IsReadyForFrame(int frame)
{
return !ClientsNotReadyForFrame(frame).Any();
}
public bool IsReadyForFrame(int frame)
{
return !ClientsNotReadyForFrame(frame).Any();
}
public IEnumerable<int> ClientsNotReadyForFrame(int frame)
{
var frameData = framePackets.GetOrAdd(frame);
return ClientsPlayingInFrame(frame)
.Where(client => !frameData.ContainsKey(client));
}
public IEnumerable<int> ClientsNotReadyForFrame(int frame)
{
var frameData = framePackets.GetOrAdd(frame);
return ClientsPlayingInFrame(frame)
.Where(client => !frameData.ContainsKey(client));
}
public IEnumerable<ClientOrder> OrdersForFrame( World world, int frame )
{

View File

@@ -67,7 +67,7 @@ namespace OpenRA
public Order(string orderstring, Order order)
: this(orderstring, order.Subject, order.TargetActor, order.TargetLocation,
order.TargetString, order.Queued, order.ExtraLocation) {}
order.TargetString, order.Queued, order.ExtraLocation) {}
public byte[] Serialize()
{
@@ -85,7 +85,7 @@ namespace OpenRA
{
// Format:
// u8 : orderID.
// 0xFF: Full serialized order.
// 0xFF: Full serialized order.
// varies: rest of order.
default:
// TODO: specific serializers for specific orders.

View File

@@ -16,7 +16,7 @@ using OpenRA.FileFormats;
namespace OpenRA.Network
{
public class OrderManager : IDisposable
public class OrderManager : IDisposable
{
readonly SyncReport syncReport;
readonly FrameData frameData = new FrameData();
@@ -157,17 +157,17 @@ namespace OpenRA.Network
get { return NetFrameNumber >= 1 && frameData.IsReadyForFrame( NetFrameNumber ); }
}
static readonly IEnumerable<Session.Client> NoClients = new Session.Client[] {};
public IEnumerable<Session.Client> GetClientsNotReadyForNextFrame
{
get
{
return NetFrameNumber >= 1
? frameData.ClientsNotReadyForFrame(NetFrameNumber)
.Select(a => LobbyInfo.ClientWithIndex(a))
: NoClients;
}
}
static readonly IEnumerable<Session.Client> NoClients = new Session.Client[] {};
public IEnumerable<Session.Client> GetClientsNotReadyForNextFrame
{
get
{
return NetFrameNumber >= 1
? frameData.ClientsNotReadyForFrame(NetFrameNumber)
.Select(a => LobbyInfo.ClientWithIndex(a))
: NoClients;
}
}
public void Tick()
{

View File

@@ -47,7 +47,7 @@ namespace OpenRA.Network
public class Client
{
public int Index;
public ColorRamp ColorRamp;
public ColorRamp ColorRamp;
public string Country;
public int SpawnPoint;
public string Name;

View File

@@ -65,8 +65,8 @@ namespace OpenRA.Network
a.ActorID,
a.Type,
a.Owner,
a.Trait,
a.Hash
a.Trait,
a.Hash
));
return;
}

View File

@@ -68,7 +68,7 @@ namespace OpenRA.Network
if (world == null)
{
if (client.Team == orderManager.LocalClient.Team)
Game.AddChatLine(client.ColorRamp.GetColor(0), client.Name + " (Team)",
Game.AddChatLine(client.ColorRamp.GetColor(0), client.Name + " (Team)",
order.TargetString);
}
else
@@ -85,7 +85,7 @@ namespace OpenRA.Network
var suffix = (player != null && player.WinState == WinState.Lost)
? " (Dead)"
: " (Team)";
Game.AddChatLine(client.ColorRamp.GetColor(0), client.Name + suffix, order.TargetString);
Game.AddChatLine(client.ColorRamp.GetColor(0), client.Name + suffix, order.TargetString);
}
}
}

View File

@@ -19,21 +19,21 @@ namespace OpenRA.Orders
{
public IEnumerable<Order> Order( World world, int2 xy, MouseInput mi )
{
var underCursor = world.FindUnitsAtMouse(mi.Location)
.Where(a => a.HasTrait<ITargetable>())
.OrderByDescending(
a =>
a.Info.Traits.Contains<SelectableInfo>()
? a.Info.Traits.Get<SelectableInfo>().Priority
: int.MinValue)
.FirstOrDefault();
var underCursor = world.FindUnitsAtMouse(mi.Location)
.Where(a => a.HasTrait<ITargetable>())
.OrderByDescending(
a =>
a.Info.Traits.Contains<SelectableInfo>()
? a.Info.Traits.Get<SelectableInfo>().Priority
: int.MinValue)
.FirstOrDefault();
var orders = world.Selection.Actors
.Select(a => OrderForUnit(a, xy, mi, underCursor))
.Where(o => o != null)
.ToArray();
var orders = world.Selection.Actors
.Select(a => OrderForUnit(a, xy, mi, underCursor))
.Where(o => o != null)
.ToArray();
var actorsInvolved = orders.Select(o => o.self).Distinct();
var actorsInvolved = orders.Select(o => o.self).Distinct();
if (actorsInvolved.Any())
yield return new Order("CreateGroup", actorsInvolved.First().Owner.PlayerActor, false)
{
@@ -41,8 +41,8 @@ namespace OpenRA.Orders
};
foreach (var o in orders)
yield return CheckSameOrder(o.iot, o.trait.IssueOrder(o.self, o.iot, o.target, mi.Modifiers.HasModifier(Modifiers.Shift)));
foreach (var o in orders)
yield return CheckSameOrder(o.iot, o.trait.IssueOrder(o.self, o.iot, o.target, mi.Modifiers.HasModifier(Modifiers.Shift)));
}
public void Tick( World world ) { }

View File

@@ -60,7 +60,7 @@ namespace OpenRA
if (client != null)
{
ClientIndex = client.Index;
ColorRamp = client.ColorRamp;
ColorRamp = client.ColorRamp;
PlayerName = client.Name;
botType = client.Bot;
Country = ChooseCountry(world, client.Country);

View File

@@ -133,7 +133,7 @@ namespace OpenRA.Server
{
for (var i = 0; i < 256; i++)
if (conns.All(c => c.PlayerIndex != i) && preConns.All(c => c.PlayerIndex != i)
&& lobbyInfo.Clients.All(c => c.Index != i))
&& lobbyInfo.Clients.All(c => c.Index != i))
return i;
throw new InvalidOperationException("Already got 256 players");
@@ -198,9 +198,9 @@ namespace OpenRA.Server
// Check that the client has compatable mods
var valid = mods.All( m => m.Contains('@')) && //valid format
mods.Count() == Game.CurrentMods.Count() && //same number
mods.Select( m => Pair.New(m.Split('@')[0], m.Split('@')[1])).All(kv => Game.CurrentMods.ContainsKey(kv.First) &&
(kv.Second == "{DEV_VERSION}" || Game.CurrentMods[kv.First].Version == "{DEV_VERSION}" || kv.Second == Game.CurrentMods[kv.First].Version));
mods.Count() == Game.CurrentMods.Count() && //same number
mods.Select( m => Pair.New(m.Split('@')[0], m.Split('@')[1])).All(kv => Game.CurrentMods.ContainsKey(kv.First) &&
(kv.Second == "{DEV_VERSION}" || Game.CurrentMods[kv.First].Version == "{DEV_VERSION}" || kv.Second == Game.CurrentMods[kv.First].Version));
if (!valid)
{
Log.Write("server", "Rejected connection from {0}; mods do not match.",
@@ -241,7 +241,7 @@ namespace OpenRA.Server
if (pr == null)
return;
if (pr.LockColor)
c.ColorRamp = pr.ColorRamp;
c.ColorRamp = pr.ColorRamp;
if (pr.LockRace)
c.Country = pr.Race;
if (pr.LockSpawn)
@@ -319,15 +319,15 @@ namespace OpenRA.Server
new ServerOrder(order, data).Serialize());
}
public void SendChat(Connection asConn, string text)
{
DispatchOrders(asConn, 0, new ServerOrder("Chat", text).Serialize());
}
public void SendChat(Connection asConn, string text)
{
DispatchOrders(asConn, 0, new ServerOrder("Chat", text).Serialize());
}
public void SendDisconnected(Connection asConn)
{
DispatchOrders(asConn, 0, new ServerOrder("Disconnected", "").Serialize());
}
public void SendDisconnected(Connection asConn)
{
DispatchOrders(asConn, 0, new ServerOrder("Disconnected", "").Serialize());
}
void InterpretServerOrder(Connection conn, ServerOrder so)
{
@@ -374,8 +374,8 @@ namespace OpenRA.Server
conns.Remove(toDrop);
SendChat(toDrop, "Connection Dropped");
if (GameStarted)
SendDisconnected(toDrop); /* Report disconnection */
if (GameStarted)
SendDisconnected(toDrop); /* Report disconnection */
lobbyInfo.Clients.RemoveAll(c => c.Index == toDrop.PlayerIndex);

View File

@@ -29,7 +29,7 @@ namespace OpenRA
static ISoundSource LoadSound(string filename)
{
return LoadSoundRaw(AudLoader.LoadSound(FileSystem.Open(filename)));
return LoadSoundRaw(AudLoader.LoadSound(FileSystem.Open(filename)));
}
static ISoundSource LoadSoundRaw(byte[] rawData)

View File

@@ -142,7 +142,7 @@ namespace OpenRA
public static T CheckSyncUnchanged<T>( World world, Func<T> fn )
{
if( world == null ) return fn();
var shouldCheckSync = Game.Settings.Debug.SanityCheckUnsyncedCode;
var shouldCheckSync = Game.Settings.Debug.SanityCheckUnsyncedCode;
int sync = shouldCheckSync ? world.SyncHash() : 0;
bool prevInUnsyncedCode = inUnsyncedCode;
inUnsyncedCode = true;

View File

@@ -36,8 +36,8 @@ namespace OpenRA.Traits
Info = info;
MaxHP = info.HP;
hp = init.Contains<HealthInit>() ? (int)(init.Get<HealthInit, float>() * MaxHP) : MaxHP;
DisplayHp = hp;
hp = init.Contains<HealthInit>() ? (int)(init.Get<HealthInit, float>() * MaxHP) : MaxHP;
DisplayHp = hp;
}
public int HP { get { return hp; } }
@@ -75,7 +75,7 @@ namespace OpenRA.Traits
var oldState = this.DamageState;
/* apply the damage modifiers, if we have any. */
var modifier = (float)self.TraitsImplementing<IDamageModifier>()
var modifier = (float)self.TraitsImplementing<IDamageModifier>()
.Concat(self.Owner.PlayerActor.TraitsImplementing<IDamageModifier>())
.Select(t => t.GetDamageModifier(attacker, warhead)).Product();
@@ -93,8 +93,8 @@ namespace OpenRA.Traits
Warhead = warhead,
};
foreach (var nd in self.TraitsImplementing<INotifyDamage>()
.Concat(self.Owner.PlayerActor.TraitsImplementing<INotifyDamage>()))
foreach (var nd in self.TraitsImplementing<INotifyDamage>()
.Concat(self.Owner.PlayerActor.TraitsImplementing<INotifyDamage>()))
nd.Damaged(self, ai);
if (DamageState != oldState)
@@ -103,7 +103,7 @@ namespace OpenRA.Traits
if (attacker != null && attacker.IsInWorld && !attacker.IsDead())
foreach (var nd in attacker.TraitsImplementing<INotifyAppliedDamage>()
.Concat(attacker.Owner.PlayerActor.TraitsImplementing<INotifyAppliedDamage>()))
.Concat(attacker.Owner.PlayerActor.TraitsImplementing<INotifyAppliedDamage>()))
nd.AppliedDamage(attacker, self, ai);
if (hp == 0)
@@ -112,7 +112,7 @@ namespace OpenRA.Traits
self.Owner.Deaths++;
foreach (var nd in self.TraitsImplementing<INotifyKilled>()
.Concat(self.Owner.PlayerActor.TraitsImplementing<INotifyKilled>()))
.Concat(self.Owner.PlayerActor.TraitsImplementing<INotifyKilled>()))
nd.Killed(self, ai);
if( RemoveOnDeath )

View File

@@ -20,7 +20,7 @@ namespace OpenRA.Traits
public bool DisableShroud = false;
public bool PathDebug = false;
public bool UnlimitedPower;
public bool BuildAnywhere;
public bool BuildAnywhere;
public object Create (ActorInitializer init) { return new DeveloperMode(this); }
}
@@ -34,7 +34,7 @@ namespace OpenRA.Traits
[Sync] public bool DisableShroud;
[Sync] public bool PathDebug;
[Sync] public bool UnlimitedPower;
[Sync] public bool BuildAnywhere;
[Sync] public bool BuildAnywhere;
public DeveloperMode(DeveloperModeInfo info)
{
@@ -44,7 +44,7 @@ namespace OpenRA.Traits
DisableShroud = info.DisableShroud;
PathDebug = info.PathDebug;
UnlimitedPower = info.UnlimitedPower;
BuildAnywhere = info.BuildAnywhere;
BuildAnywhere = info.BuildAnywhere;
}
public void ResolveOrder (Actor self, Order order)
@@ -96,11 +96,11 @@ namespace OpenRA.Traits
UnlimitedPower ^= true;
break;
}
case "DevBuildAnywhere":
{
BuildAnywhere ^= true;
break;
}
case "DevBuildAnywhere":
{
BuildAnywhere ^= true;
break;
}
default:
return;
}

View File

@@ -136,7 +136,7 @@ namespace OpenRA.Traits
var eva = self.World.WorldActor.Info.Traits.Get<EvaAlertsInfo>();
OreCapacity = self.World.ActorsWithTrait<IStoreOre>()
.Where(a => a.Actor.Owner == Owner)
.Where(a => a.Actor.Owner == Owner)
.Sum(a => a.Trait.Capacity);
if (Ore > OreCapacity)

View File

@@ -18,117 +18,117 @@ using OpenRA.Network;
namespace OpenRA.Traits
{
// depends on the order of pips in WorldRenderer.cs!
public enum PipType { Transparent, Green, Yellow, Red, Gray, Blue };
public enum TagType { None, Fake, Primary };
public enum Stance { Enemy, Neutral, Ally };
// depends on the order of pips in WorldRenderer.cs!
public enum PipType { Transparent, Green, Yellow, Red, Gray, Blue };
public enum TagType { None, Fake, Primary };
public enum Stance { Enemy, Neutral, Ally };
public class AttackInfo
{
public Actor Attacker;
public WarheadInfo Warhead;
public int Damage;
public DamageState DamageState;
public DamageState PreviousDamageState;
}
public class AttackInfo
{
public Actor Attacker;
public WarheadInfo Warhead;
public int Damage;
public DamageState DamageState;
public DamageState PreviousDamageState;
}
public interface ITick { void Tick(Actor self); }
public interface IRender { IEnumerable<Renderable> Render(Actor self); }
public interface ITick { void Tick(Actor self); }
public interface IRender { IEnumerable<Renderable> Render(Actor self); }
public interface IIssueOrder
{
IEnumerable<IOrderTargeter> Orders { get; }
Order IssueOrder(Actor self, IOrderTargeter order, Target target, bool queued);
}
public interface IIssueOrder
{
IEnumerable<IOrderTargeter> Orders { get; }
Order IssueOrder(Actor self, IOrderTargeter order, Target target, bool queued);
}
public interface IOrderTargeter
{
string OrderID { get; }
int OrderPriority { get; }
bool CanTargetActor(Actor self, Actor target, bool forceAttack, bool forceQueue, ref string cursor);
bool CanTargetLocation(Actor self, int2 location, List<Actor> actorsAtLocation, bool forceAttack, bool forceQueue, ref string cursor);
bool IsQueued { get; }
}
public interface IOrderTargeter
{
string OrderID { get; }
int OrderPriority { get; }
bool CanTargetActor(Actor self, Actor target, bool forceAttack, bool forceQueue, ref string cursor);
bool CanTargetLocation(Actor self, int2 location, List<Actor> actorsAtLocation, bool forceAttack, bool forceQueue, ref string cursor);
bool IsQueued { get; }
}
public interface IResolveOrder { void ResolveOrder(Actor self, Order order); }
public interface IValidateOrder { bool OrderValidation(OrderManager orderManager, World world, int clientId, Order order); }
public interface IOrderVoice { string VoicePhraseForOrder(Actor self, Order order); }
public interface INotifySold { void Selling(Actor self); void Sold(Actor self); }
public interface INotifyDamage { void Damaged(Actor self, AttackInfo e); }
public interface INotifyDamageStateChanged { void DamageStateChanged(Actor self, AttackInfo e); }
public interface INotifyKilled { void Killed(Actor self, AttackInfo e); }
public interface INotifyAppliedDamage { void AppliedDamage(Actor self, Actor damaged, AttackInfo e); }
public interface INotifyBuildComplete { void BuildingComplete(Actor self); }
public interface INotifyProduction { void UnitProduced(Actor self, Actor other, int2 exit); }
public interface INotifyCapture { void OnCapture(Actor self, Actor captor, Player oldOwner, Player newOwner); }
public interface INotifyOtherCaptured { void OnActorCaptured(Actor self, Actor captured, Actor captor, Player oldOwner, Player newOwner); }
public interface IAcceptSpy { void OnInfiltrate(Actor self, Actor spy); }
public interface IStoreOre { int Capacity { get; } }
public interface IToolTip
{
string Name();
Player Owner();
Stance Stance();
}
public interface IResolveOrder { void ResolveOrder(Actor self, Order order); }
public interface IValidateOrder { bool OrderValidation(OrderManager orderManager, World world, int clientId, Order order); }
public interface IOrderVoice { string VoicePhraseForOrder(Actor self, Order order); }
public interface INotifySold { void Selling(Actor self); void Sold(Actor self); }
public interface INotifyDamage { void Damaged(Actor self, AttackInfo e); }
public interface INotifyDamageStateChanged { void DamageStateChanged(Actor self, AttackInfo e); }
public interface INotifyKilled { void Killed(Actor self, AttackInfo e); }
public interface INotifyAppliedDamage { void AppliedDamage(Actor self, Actor damaged, AttackInfo e); }
public interface INotifyBuildComplete { void BuildingComplete(Actor self); }
public interface INotifyProduction { void UnitProduced(Actor self, Actor other, int2 exit); }
public interface INotifyCapture { void OnCapture(Actor self, Actor captor, Player oldOwner, Player newOwner); }
public interface INotifyOtherCaptured { void OnActorCaptured(Actor self, Actor captured, Actor captor, Player oldOwner, Player newOwner); }
public interface IAcceptSpy { void OnInfiltrate(Actor self, Actor spy); }
public interface IStoreOre { int Capacity { get; } }
public interface IToolTip
{
string Name();
Player Owner();
Stance Stance();
}
public interface IDisable { bool Disabled { get; } }
public interface IExplodeModifier { bool ShouldExplode(Actor self); }
public interface IHuskModifier { string HuskActor(Actor self); }
public interface INudge { void OnNudge(Actor self, Actor nudger, bool force); }
public interface IDisable { bool Disabled { get; } }
public interface IExplodeModifier { bool ShouldExplode(Actor self); }
public interface IHuskModifier { string HuskActor(Actor self); }
public interface INudge { void OnNudge(Actor self, Actor nudger, bool force); }
public interface IRadarSignature
{
IEnumerable<int2> RadarSignatureCells(Actor self);
Color RadarSignatureColor(Actor self);
}
public interface IRadarSignature
{
IEnumerable<int2> RadarSignatureCells(Actor self);
Color RadarSignatureColor(Actor self);
}
public interface IVisibilityModifier { bool IsVisible(Actor self); }
public interface IRadarColorModifier { Color RadarColorOverride(Actor self); }
public interface IVisibilityModifier { bool IsVisible(Actor self); }
public interface IRadarColorModifier { Color RadarColorOverride(Actor self); }
public interface IHasLocation { int2 PxPosition { get; } }
public interface IOccupySpace : IHasLocation
{
int2 TopLeft { get; }
IEnumerable<Pair<int2, SubCell>> OccupiedCells();
}
public interface IOccupySpace : IHasLocation
{
int2 TopLeft { get; }
IEnumerable<Pair<int2, SubCell>> OccupiedCells();
}
public static class IOccupySpaceExts
{
public static int2 NearestCellTo(this IOccupySpace ios, int2 other)
{
var nearest = ios.TopLeft;
var nearestDistance = int.MaxValue;
foreach (var cell in ios.OccupiedCells())
{
var dist = (other - cell.First).LengthSquared;
if (dist < nearestDistance)
{
nearest = cell.First;
nearestDistance = dist;
}
}
return nearest;
}
}
public static class IOccupySpaceExts
{
public static int2 NearestCellTo(this IOccupySpace ios, int2 other)
{
var nearest = ios.TopLeft;
var nearestDistance = int.MaxValue;
foreach (var cell in ios.OccupiedCells())
{
var dist = (other - cell.First).LengthSquared;
if (dist < nearestDistance)
{
nearest = cell.First;
nearestDistance = dist;
}
}
return nearest;
}
}
public interface INotifyAttack { void Attacking(Actor self, Target target); }
public interface IRenderModifier { IEnumerable<Renderable> ModifyRender(Actor self, IEnumerable<Renderable> r); }
public interface IDamageModifier { float GetDamageModifier(Actor attacker, WarheadInfo warhead); }
public interface ISpeedModifier { decimal GetSpeedModifier(); }
public interface IFirepowerModifier { float GetFirepowerModifier(); }
public interface IPalette { void InitPalette(WorldRenderer wr); }
public interface IPaletteModifier { void AdjustPalette(Dictionary<string, Palette> b); }
public interface IPips { IEnumerable<PipType> GetPips(Actor self); }
public interface ITags { IEnumerable<TagType> GetTags(); }
public interface ISelectionBar { float GetValue(); Color GetColor(); }
public interface INotifyAttack { void Attacking(Actor self, Target target); }
public interface IRenderModifier { IEnumerable<Renderable> ModifyRender(Actor self, IEnumerable<Renderable> r); }
public interface IDamageModifier { float GetDamageModifier(Actor attacker, WarheadInfo warhead); }
public interface ISpeedModifier { decimal GetSpeedModifier(); }
public interface IFirepowerModifier { float GetFirepowerModifier(); }
public interface IPalette { void InitPalette(WorldRenderer wr); }
public interface IPaletteModifier { void AdjustPalette(Dictionary<string, Palette> b); }
public interface IPips { IEnumerable<PipType> GetPips(Actor self); }
public interface ITags { IEnumerable<TagType> GetTags(); }
public interface ISelectionBar { float GetValue(); Color GetColor(); }
public interface ITeleportable : IHasLocation /* crap name! */
{
bool CanEnterCell(int2 location);
void SetPosition(Actor self, int2 cell);
void SetPxPosition(Actor self, int2 px);
void AdjustPxPosition(Actor self, int2 px); /* works like SetPxPosition, but visual only */
}
public interface ITeleportable : IHasLocation /* crap name! */
{
bool CanEnterCell(int2 location);
void SetPosition(Actor self, int2 cell);
void SetPxPosition(Actor self, int2 px);
void AdjustPxPosition(Actor self, int2 px); /* works like SetPxPosition, but visual only */
}
public interface IMove : ITeleportable { int Altitude { get; set; } }
@@ -141,86 +141,86 @@ namespace OpenRA.Traits
public interface IFacingInfo {} /* tag interface for infoclasses whose corresponding trait has IFacing */
public interface ICrushable
{
void OnCrush(Actor crusher);
public interface ICrushable
{
void OnCrush(Actor crusher);
void WarnCrush(Actor crusher);
bool CrushableBy(string[] crushClasses, Player owner);
}
}
public struct Renderable
{
public readonly Sprite Sprite;
public readonly float2 Pos;
public readonly string Palette;
public readonly int Z;
public readonly int ZOffset;
public float Scale;
public struct Renderable
{
public readonly Sprite Sprite;
public readonly float2 Pos;
public readonly string Palette;
public readonly int Z;
public readonly int ZOffset;
public float Scale;
public Renderable(Sprite sprite, float2 pos, string palette, int z, int zOffset, float scale)
{
Sprite = sprite;
Pos = pos;
Palette = palette;
Z = z;
ZOffset = zOffset;
Scale = scale; /* default */
}
public Renderable(Sprite sprite, float2 pos, string palette, int z, int zOffset, float scale)
{
Sprite = sprite;
Pos = pos;
Palette = palette;
Z = z;
ZOffset = zOffset;
Scale = scale; /* default */
}
public Renderable(Sprite sprite, float2 pos, string palette, int z)
: this(sprite, pos, palette, z, 0, 1f) { }
public Renderable(Sprite sprite, float2 pos, string palette, int z)
: this(sprite, pos, palette, z, 0, 1f) { }
public Renderable(Sprite sprite, float2 pos, string palette, int z, float scale)
: this(sprite, pos, palette, z, 0, scale) { }
public Renderable(Sprite sprite, float2 pos, string palette, int z, float scale)
: this(sprite, pos, palette, z, 0, scale) { }
public Renderable WithScale(float newScale) { return new Renderable(Sprite, Pos, Palette, Z, ZOffset, newScale); }
public Renderable WithPalette(string newPalette) { return new Renderable(Sprite, Pos, newPalette, Z, ZOffset, Scale); }
public Renderable WithZOffset(int newOffset) { return new Renderable(Sprite, Pos, Palette, Z, newOffset, Scale); }
public Renderable WithPos(float2 newPos) { return new Renderable(Sprite, newPos, Palette, Z, ZOffset, Scale); }
}
public Renderable WithScale(float newScale) { return new Renderable(Sprite, Pos, Palette, Z, ZOffset, newScale); }
public Renderable WithPalette(string newPalette) { return new Renderable(Sprite, Pos, newPalette, Z, ZOffset, Scale); }
public Renderable WithZOffset(int newOffset) { return new Renderable(Sprite, Pos, Palette, Z, newOffset, Scale); }
public Renderable WithPos(float2 newPos) { return new Renderable(Sprite, newPos, Palette, Z, ZOffset, Scale); }
}
public interface ITraitInfo { object Create(ActorInitializer init); }
public interface ITraitInfo { object Create(ActorInitializer init); }
public class TraitInfo<T> : ITraitInfo where T : new() { public virtual object Create(ActorInitializer init) { return new T(); } }
public class TraitInfo<T> : ITraitInfo where T : new() { public virtual object Create(ActorInitializer init) { return new T(); } }
public interface Requires<T> where T : class { }
public interface Requires<T> where T : class { }
public interface INotifySelection { void SelectionChanged(); }
public interface IWorldLoaded { void WorldLoaded(World w); }
public interface ICreatePlayers { void CreatePlayers(World w); }
public interface INotifySelection { void SelectionChanged(); }
public interface IWorldLoaded { void WorldLoaded(World w); }
public interface ICreatePlayers { void CreatePlayers(World w); }
public interface IBotInfo { string Name { get; } }
public interface IBot
{
void Activate(Player p);
IBotInfo Info { get; }
}
public interface IBotInfo { string Name { get; } }
public interface IBot
{
void Activate(Player p);
IBotInfo Info { get; }
}
public interface IRenderOverlay { void Render(WorldRenderer wr); }
public interface INotifyIdle { void TickIdle(Actor self); }
public interface IRenderOverlay { void Render(WorldRenderer wr); }
public interface INotifyIdle { void TickIdle(Actor self); }
public interface IBlocksBullets { }
public interface IBlocksBullets { }
public interface IPostRender { void RenderAfterWorld(WorldRenderer wr, Actor self); }
public interface IPostRender { void RenderAfterWorld(WorldRenderer wr, Actor self); }
public interface IPostRenderSelection { void RenderAfterWorld(WorldRenderer wr, Actor self); }
public interface IPreRenderSelection { void RenderBeforeWorld(WorldRenderer wr, Actor self); }
public interface IRenderAsTerrain { IEnumerable<Renderable> RenderAsTerrain(Actor self); }
public interface IPostRenderSelection { void RenderAfterWorld(WorldRenderer wr, Actor self); }
public interface IPreRenderSelection { void RenderBeforeWorld(WorldRenderer wr, Actor self); }
public interface IRenderAsTerrain { IEnumerable<Renderable> RenderAsTerrain(Actor self); }
public interface ITargetable
{
string[] TargetTypes { get; }
IEnumerable<int2> TargetableCells(Actor self);
bool TargetableBy(Actor self, Actor byActor);
}
public interface ITargetable
{
string[] TargetTypes { get; }
IEnumerable<int2> TargetableCells(Actor self);
bool TargetableBy(Actor self, Actor byActor);
}
public interface INotifyStanceChanged
{
void StanceChanged(Actor self, Player a, Player b,
Stance oldStance, Stance newStance);
}
public interface INotifyStanceChanged
{
void StanceChanged(Actor self, Player a, Player b,
Stance oldStance, Stance newStance);
}
public interface ILintPass { void Run(Action<string> emitError, Action<string> emitWarning); }
public interface ILintPass { void Run(Action<string> emitError, Action<string> emitWarning); }
public interface IObjectivesPanel { string ObjectivesPanel { get; } }
}

View File

@@ -122,17 +122,17 @@ namespace OpenRA.Traits
public static int2 CellContaining(float2 pos) { return (1f / Game.CellSize * pos).ToInt2(); }
/* pretty crap */
public static IEnumerable<T> Shuffle<T>(this IEnumerable<T> ts, Thirdparty.Random random)
{
var items = ts.ToList();
while (items.Count > 0)
{
var t = items.Random(random);
yield return t;
items.Remove(t);
}
}
/* pretty crap */
public static IEnumerable<T> Shuffle<T>(this IEnumerable<T> ts, Thirdparty.Random random)
{
var items = ts.ToList();
while (items.Count > 0)
{
var t = items.Random(random);
yield return t;
items.Remove(t);
}
}
static IEnumerable<int2> Neighbours(int2 c, bool allowDiagonal)
{

View File

@@ -15,10 +15,10 @@ namespace OpenRA.Traits
{
public class ValidateOrderInfo : TraitInfo<ValidateOrder> { }
public class ValidateOrder : IValidateOrder
{
public bool OrderValidation(OrderManager orderManager, World world, int clientId, Order order)
{
public class ValidateOrder : IValidateOrder
{
public bool OrderValidation(OrderManager orderManager, World world, int clientId, Order order)
{
if (order.Subject == null || order.Subject.Owner == null)
return true;
@@ -36,12 +36,12 @@ namespace OpenRA.Traits
// Drop exploiting orders
if (subjectClientId != clientId && !isBotOrder)
{
Game.Debug("Detected exploit order from client {0}: {1}", clientId, order.OrderString);
return false;
}
{
Game.Debug("Detected exploit order from client {0}: {1}", clientId, order.OrderString);
return false;
}
return true;
}
}
return true;
}
}
}

View File

@@ -37,7 +37,7 @@ namespace OpenRA.Traits
{
var paletteName = "{0}{1}".F( info.BaseName, owner.InternalName );
var newpal = new Palette(wr.GetPalette(info.BasePalette),
new PlayerColorRemap(owner.ColorRamp, info.PaletteFormat));
new PlayerColorRemap(owner.ColorRamp, info.PaletteFormat));
wr.AddPalette(paletteName, newpal);
}
}

View File

@@ -64,16 +64,16 @@ namespace OpenRA.Traits
for (int x = map.Bounds.Left; x < map.Bounds.Right; x++)
for (int y = map.Bounds.Top; y < map.Bounds.Bottom; y++)
{
var type = resourceTypes.FirstOrDefault(
var type = resourceTypes.FirstOrDefault(
r => r.info.ResourceType == w.Map.MapResources.Value[x, y].type);
if (type == null)
continue;
if (type == null)
continue;
if (!AllowResourceAt(type, new int2(x,y)))
continue;
content[x, y].type = type;
content[x, y].type = type;
content[x, y].image = ChooseContent(type);
}
@@ -86,13 +86,13 @@ namespace OpenRA.Traits
}
}
public bool AllowResourceAt(ResourceType rt, int2 a)
{
if (!world.Map.IsInMap(a.X, a.Y)) return false;
if (!rt.info.AllowedTerrainTypes.Contains(world.GetTerrainInfo(a).Type)) return false;
if (!rt.info.AllowUnderActors && world.ActorMap.AnyUnitsAt(a)) return false;
return true;
}
public bool AllowResourceAt(ResourceType rt, int2 a)
{
if (!world.Map.IsInMap(a.X, a.Y)) return false;
if (!rt.info.AllowedTerrainTypes.Contains(world.GetTerrainInfo(a).Type)) return false;
if (!rt.info.AllowUnderActors && world.ActorMap.AnyUnitsAt(a)) return false;
return true;
}
Sprite[] ChooseContent(ResourceType t)
{

View File

@@ -22,8 +22,8 @@ namespace OpenRA.Traits
public readonly string Name = null;
public readonly string TerrainType = "Ore";
public readonly string[] AllowedTerrainTypes = { };
public readonly bool AllowUnderActors = false;
public readonly string[] AllowedTerrainTypes = { };
public readonly bool AllowUnderActors = false;
public Sprite[][] Sprites;
public int PaletteIndex;

View File

@@ -19,7 +19,7 @@ namespace OpenRA.Traits
public class ScreenShaker : ITick
{
int ticks = 0;
List<ShakeEffect> shakeEffects = new List<ShakeEffect>();
List<ShakeEffect> shakeEffects = new List<ShakeEffect>();
public void Tick (Actor self)
{

View File

@@ -78,7 +78,7 @@ namespace OpenRA.Traits
return;
if (a.Owner == null || a.Owner.World.LocalPlayer == null
|| a.Owner.Stances[a.Owner.World.LocalPlayer] != Stance.Ally) return;
|| a.Owner.Stances[a.Owner.World.LocalPlayer] != Stance.Ally) return;
if (vis.ContainsKey(a))
{
@@ -160,7 +160,7 @@ namespace OpenRA.Traits
public void UpdateActor(Actor a)
{
if (a.Owner == null || a.Owner.World.LocalPlayer == null
|| a.Owner.Stances[a.Owner.World.LocalPlayer] != Stance.Ally) return;
|| a.Owner.Stances[a.Owner.World.LocalPlayer] != Stance.Ally) return;
RemoveActor(a); AddActor(a);
}

View File

@@ -27,7 +27,7 @@ namespace OpenRA.Widgets
public Func<string> GetText;
public Func<bool> IsDisabled = () => false;
public Action<MouseInput> OnMouseDown = _ => {};
public Action<MouseInput> OnMouseUp = _ => {};
public Action<MouseInput> OnMouseUp = _ => {};
// Equivalent to OnMouseUp, but without an input arg
public Action OnClick = () => {};
@@ -130,7 +130,7 @@ namespace OpenRA.Widgets
DrawBackground(rb, disabled, Depressed, Widget.MouseOverWidget == this);
font.DrawText(text, new int2(rb.X + (UsableWidth - s.X)/ 2, rb.Y + (Bounds.Height - s.Y) / 2) + stateOffset,
disabled ? Color.Gray : Color.White);
disabled ? Color.Gray : Color.White);
}
public override Widget Clone() { return new ButtonWidget(this); }

View File

@@ -17,7 +17,7 @@ namespace OpenRA.Widgets
public class ChatDisplayWidget : Widget
{
public readonly int RemoveTime = 0;
public readonly bool UseContrast = false;
public readonly bool UseContrast = false;
const int logLength = 9;
public string Notification = "";
@@ -55,11 +55,11 @@ namespace OpenRA.Widgets
inset = font.Measure(owner).X + 10;
font.DrawTextWithContrast(owner, chatpos,
line.Color, Color.Black, UseContrast ? 1 : 0);
line.Color, Color.Black, UseContrast ? 1 : 0);
}
font.DrawTextWithContrast(line.Text, chatpos + new int2(inset, 0),
Color.White, Color.Black, UseContrast ? 1 : 0);
font.DrawTextWithContrast(line.Text, chatpos + new int2(inset, 0),
Color.White, Color.Black, UseContrast ? 1 : 0);
}
Game.Renderer.DisableScissor();

View File

@@ -21,7 +21,7 @@ namespace OpenRA.Widgets
string content = "";
bool composing = false;
bool teamChat = false;
public readonly bool UseContrast = false;
public readonly bool UseContrast = false;
readonly OrderManager orderManager;

View File

@@ -104,27 +104,27 @@ namespace OpenRA.Widgets
}
public class MaskWidget : Widget
{
public Action<MouseInput> OnMouseDown = _ => {};
{
public Action<MouseInput> OnMouseDown = _ => {};
public MaskWidget() : base() { }
public MaskWidget(MaskWidget other)
: base(other)
public MaskWidget(MaskWidget other)
: base(other)
{
OnMouseDown = other.OnMouseDown;
}
public override bool HandleMouseInput(MouseInput mi)
{
if (mi.Event != MouseInputEvent.Down && mi.Event != MouseInputEvent.Up)
{
if (mi.Event != MouseInputEvent.Down && mi.Event != MouseInputEvent.Up)
return false;
if (mi.Event == MouseInputEvent.Down)
OnMouseDown(mi);
return true;
}
}
public override string GetCursor(int2 pos) { return null; }
public override Widget Clone() { return new MaskWidget(this); }
}
public override string GetCursor(int2 pos) { return null; }
public override Widget Clone() { return new MaskWidget(this); }
}
}

View File

@@ -38,16 +38,16 @@ namespace OpenRA.Widgets
public override Widget Clone() { return new MapPreviewWidget(this); }
public override bool HandleMouseInput(MouseInput mi)
{
{
if (IgnoreMouseInput)
return base.HandleMouseInput(mi);
if (mi.Event != MouseInputEvent.Down)
return false;
OnMouseDown(mi);
return true;
}
OnMouseDown(mi);
return true;
}
public int2 ConvertToPreview(Map map, int2 point)
{

View File

@@ -27,7 +27,7 @@ namespace OpenRA.Widgets
Game.Renderer.LineRenderer.DrawLine(origin, origin + new float2(100, 0) * basis, Color.White, Color.White);
Game.Renderer.LineRenderer.DrawLine(origin + new float2(100, 0) * basis, origin + new float2(100, 100) * basis, Color.White, Color.White);
int k = 0;
int k = 0;
foreach (var item in PerfHistory.items.Values.ToArray())
{
int n = 0;
@@ -41,19 +41,19 @@ namespace OpenRA.Widgets
return b;
});
var u = new float2(rect.Left, rect.Top);
var u = new float2(rect.Left, rect.Top);
Game.Renderer.LineRenderer.DrawLine(
u + new float2(10, 10 * k + 5),
u + new float2(12, 10 * k + 5),
item.c, item.c);
Game.Renderer.LineRenderer.DrawLine(
u + new float2(10, 10 * k + 5),
u + new float2(12, 10 * k + 5),
item.c, item.c);
Game.Renderer.LineRenderer.DrawLine(
u + new float2(10, 10 * k + 4),
u + new float2(12, 10 * k + 4),
item.c, item.c);
Game.Renderer.LineRenderer.DrawLine(
u + new float2(10, 10 * k + 4),
u + new float2(12, 10 * k + 4),
item.c, item.c);
++k;
++k;
}
k = 0;

View File

@@ -105,17 +105,17 @@ namespace OpenRA.Widgets
if(Keyboard != ScrollDirection.None || Edge != ScrollDirection.None)
{
var scroll = new float2(0, 0);
var scroll = new float2(0, 0);
// Modified to use the ViewportEdgeScrollStep setting - Gecko
if (Keyboard.Includes(ScrollDirection.Up) || Edge.Includes(ScrollDirection.Up))
scroll += new float2(0, -1);
if (Keyboard.Includes(ScrollDirection.Right) || Edge.Includes(ScrollDirection.Right))
scroll += new float2(1, 0);
if (Keyboard.Includes(ScrollDirection.Down) || Edge.Includes(ScrollDirection.Down))
scroll += new float2(0, 1);
if (Keyboard.Includes(ScrollDirection.Left) || Edge.Includes(ScrollDirection.Left))
scroll += new float2(-1, 0);
// Modified to use the ViewportEdgeScrollStep setting - Gecko
if (Keyboard.Includes(ScrollDirection.Up) || Edge.Includes(ScrollDirection.Up))
scroll += new float2(0, -1);
if (Keyboard.Includes(ScrollDirection.Right) || Edge.Includes(ScrollDirection.Right))
scroll += new float2(1, 0);
if (Keyboard.Includes(ScrollDirection.Down) || Edge.Includes(ScrollDirection.Down))
scroll += new float2(0, 1);
if (Keyboard.Includes(ScrollDirection.Left) || Edge.Includes(ScrollDirection.Left))
scroll += new float2(-1, 0);
float length = Math.Max(1, scroll.Length);
scroll.X = (scroll.X / length) * Game.Settings.Game.ViewportEdgeScrollStep;

View File

@@ -17,75 +17,75 @@ using OpenRA.Graphics;
namespace OpenRA.Widgets
{
public abstract class Widget
{
public static Widget RootWidget
{
get { return rootWidget; }
set { rootWidget = value; }
}
public abstract class Widget
{
public static Widget RootWidget
{
get { return rootWidget; }
set { rootWidget = value; }
}
static Widget rootWidget = new ContainerWidget();
static Widget rootWidget = new ContainerWidget();
static Stack<Widget> WindowList = new Stack<Widget>();
public static Widget SelectedWidget;
public static Widget SelectedWidget;
public static Widget MouseOverWidget;
public static void CloseWindow()
{
if (WindowList.Count > 0)
{
if (WindowList.Count > 0)
RootWidget.RemoveChild(WindowList.Pop());
if (WindowList.Count > 0)
rootWidget.AddChild(WindowList.Peek());
}
if (WindowList.Count > 0)
rootWidget.AddChild(WindowList.Peek());
}
public static Widget OpenWindow(string id)
{
return OpenWindow(id, new WidgetArgs());
}
public static Widget OpenWindow(string id)
{
return OpenWindow(id, new WidgetArgs());
}
public static Widget OpenWindow(string id, WidgetArgs args)
{
var window = Game.modData.WidgetLoader.LoadWidget(args, rootWidget, id);
if (WindowList.Count > 0)
rootWidget.RemoveChild(WindowList.Peek());
WindowList.Push(window);
return window;
}
public static Widget OpenWindow(string id, WidgetArgs args)
{
var window = Game.modData.WidgetLoader.LoadWidget(args, rootWidget, id);
if (WindowList.Count > 0)
rootWidget.RemoveChild(WindowList.Peek());
WindowList.Push(window);
return window;
}
public static Widget LoadWidget(string id, Widget parent, WidgetArgs args)
{
return Game.modData.WidgetLoader.LoadWidget(args, parent, id);
}
{
return Game.modData.WidgetLoader.LoadWidget(args, parent, id);
}
public static void DoTick()
{
RootWidget.TickOuter();
}
public static void DoTick()
{
RootWidget.TickOuter();
}
public static void DoDraw()
{
RootWidget.DrawOuter();
}
public static void DoDraw()
{
RootWidget.DrawOuter();
}
public static bool DoHandleInput(MouseInput mi)
{
var wasMouseOver = MouseOverWidget;
{
var wasMouseOver = MouseOverWidget;
if (mi.Event == MouseInputEvent.Move)
MouseOverWidget = null;
bool handled = false;
if (SelectedWidget != null && SelectedWidget.HandleMouseInputOuter(mi))
handled = true;
if (SelectedWidget != null && SelectedWidget.HandleMouseInputOuter(mi))
handled = true;
if (!handled && RootWidget.HandleMouseInputOuter(mi))
handled = true;
if (!handled && RootWidget.HandleMouseInputOuter(mi))
handled = true;
if (mi.Event == MouseInputEvent.Move)
{
Viewport.LastMousePos = mi.Location;
Viewport.TicksSinceLastMove = 0;
}
if (mi.Event == MouseInputEvent.Move)
{
Viewport.LastMousePos = mi.Location;
Viewport.TicksSinceLastMove = 0;
}
if (wasMouseOver != MouseOverWidget)
{
@@ -96,18 +96,18 @@ namespace OpenRA.Widgets
MouseOverWidget.MouseEntered();
}
return handled;
}
return handled;
}
public static bool DoHandleKeyPress(KeyInput e)
{
if (SelectedWidget != null)
return SelectedWidget.HandleKeyPressOuter(e);
{
if (SelectedWidget != null)
return SelectedWidget.HandleKeyPressOuter(e);
if (RootWidget.HandleKeyPressOuter(e))
return true;
return false;
}
if (RootWidget.HandleKeyPressOuter(e))
return true;
return false;
}
public static void ResetAll()
{
@@ -118,59 +118,59 @@ namespace OpenRA.Widgets
}
// Info defined in YAML
public string Id = null;
public string X = "0";
public string Y = "0";
public string Width = "0";
public string Height = "0";
public string Logic = null;
public string Id = null;
public string X = "0";
public string Y = "0";
public string Width = "0";
public string Height = "0";
public string Logic = null;
public object LogicObject { get; private set; }
public bool Visible = true;
public bool Visible = true;
public bool IgnoreMouseOver;
public bool IgnoreChildMouseOver;
// Calculated internally
public Rectangle Bounds;
public Widget Parent = null;
// Calculated internally
public Rectangle Bounds;
public Widget Parent = null;
public Func<bool> IsVisible;
public Widget() { IsVisible = () => Visible; }
public readonly List<Widget> Children = new List<Widget>();
public Widget() { IsVisible = () => Visible; }
public readonly List<Widget> Children = new List<Widget>();
public Widget(Widget widget)
{
Id = widget.Id;
X = widget.X;
Y = widget.Y;
Width = widget.Width;
Height = widget.Height;
Logic = widget.Logic;
Visible = widget.Visible;
public Widget(Widget widget)
{
Id = widget.Id;
X = widget.X;
Y = widget.Y;
Width = widget.Width;
Height = widget.Height;
Logic = widget.Logic;
Visible = widget.Visible;
Bounds = widget.Bounds;
Parent = widget.Parent;
Bounds = widget.Bounds;
Parent = widget.Parent;
IsVisible = widget.IsVisible;
IsVisible = widget.IsVisible;
IgnoreChildMouseOver = widget.IgnoreChildMouseOver;
foreach (var child in widget.Children)
AddChild(child.Clone());
}
foreach (var child in widget.Children)
AddChild(child.Clone());
}
public virtual Widget Clone()
{
throw new InvalidOperationException("Widget type `{0}` is not cloneable.".F(GetType().Name));
}
public virtual Widget Clone()
{
throw new InvalidOperationException("Widget type `{0}` is not cloneable.".F(GetType().Name));
}
public virtual int2 RenderOrigin
{
get
{
var offset = (Parent == null) ? int2.Zero : Parent.ChildOrigin;
return new int2(Bounds.X, Bounds.Y) + offset;
}
}
public virtual int2 RenderOrigin
{
get
{
var offset = (Parent == null) ? int2.Zero : Parent.ChildOrigin;
return new int2(Bounds.X, Bounds.Y) + offset;
}
}
public virtual int2 ChildOrigin { get { return RenderOrigin; } }
public virtual int2 ChildOrigin { get { return RenderOrigin; } }
public virtual Rectangle RenderBounds
{
@@ -181,120 +181,120 @@ namespace OpenRA.Widgets
}
}
public virtual void Initialize(WidgetArgs args)
{
// Parse the YAML equations to find the widget bounds
var parentBounds = (Parent == null)
? new Rectangle(0, 0, Game.viewport.Width, Game.viewport.Height)
: Parent.Bounds;
public virtual void Initialize(WidgetArgs args)
{
// Parse the YAML equations to find the widget bounds
var parentBounds = (Parent == null)
? new Rectangle(0, 0, Game.viewport.Width, Game.viewport.Height)
: Parent.Bounds;
var substitutions = args.ContainsKey("substitutions") ?
new Dictionary<string, int>((Dictionary<string, int>)args["substitutions"]) :
new Dictionary<string, int>();
substitutions.Add("WINDOW_RIGHT", Game.viewport.Width);
substitutions.Add("WINDOW_BOTTOM", Game.viewport.Height);
substitutions.Add("PARENT_RIGHT", parentBounds.Width);
substitutions.Add("PARENT_LEFT", parentBounds.Left);
substitutions.Add("PARENT_TOP", parentBounds.Top);
substitutions.Add("PARENT_BOTTOM", parentBounds.Height);
int width = Evaluator.Evaluate(Width, substitutions);
int height = Evaluator.Evaluate(Height, substitutions);
substitutions.Add("WINDOW_RIGHT", Game.viewport.Width);
substitutions.Add("WINDOW_BOTTOM", Game.viewport.Height);
substitutions.Add("PARENT_RIGHT", parentBounds.Width);
substitutions.Add("PARENT_LEFT", parentBounds.Left);
substitutions.Add("PARENT_TOP", parentBounds.Top);
substitutions.Add("PARENT_BOTTOM", parentBounds.Height);
int width = Evaluator.Evaluate(Width, substitutions);
int height = Evaluator.Evaluate(Height, substitutions);
substitutions.Add("WIDTH", width);
substitutions.Add("HEIGHT", height);
substitutions.Add("WIDTH", width);
substitutions.Add("HEIGHT", height);
Bounds = new Rectangle(Evaluator.Evaluate(X, substitutions),
Evaluator.Evaluate(Y, substitutions),
width,
height);
}
Bounds = new Rectangle(Evaluator.Evaluate(X, substitutions),
Evaluator.Evaluate(Y, substitutions),
width,
height);
}
public void PostInit(WidgetArgs args)
{
if (Logic == null)
return;
public void PostInit(WidgetArgs args)
{
if (Logic == null)
return;
args["widget"] = this;
args["widget"] = this;
LogicObject = Game.modData.ObjectCreator.CreateObject<object>(Logic, args);
var iwd = LogicObject as ILogicWithInit;
if (iwd != null)
iwd.Init();
LogicObject = Game.modData.ObjectCreator.CreateObject<object>(Logic, args);
var iwd = LogicObject as ILogicWithInit;
if (iwd != null)
iwd.Init();
args.Remove("widget");
}
args.Remove("widget");
}
public virtual Rectangle EventBounds { get { return RenderBounds; } }
public virtual Rectangle GetEventBounds()
{
return Children
.Where(c => c.IsVisible())
.Select(c => c.GetEventBounds())
.Aggregate(EventBounds, Rectangle.Union);
}
public virtual Rectangle EventBounds { get { return RenderBounds; } }
public virtual Rectangle GetEventBounds()
{
return Children
.Where(c => c.IsVisible())
.Select(c => c.GetEventBounds())
.Aggregate(EventBounds, Rectangle.Union);
}
public bool Focused { get { return SelectedWidget == this; } }
public virtual bool TakeFocus(MouseInput mi)
{
if (Focused)
return true;
public bool Focused { get { return SelectedWidget == this; } }
public virtual bool TakeFocus(MouseInput mi)
{
if (Focused)
return true;
if (SelectedWidget != null && !SelectedWidget.LoseFocus(mi))
return false;
if (SelectedWidget != null && !SelectedWidget.LoseFocus(mi))
return false;
SelectedWidget = this;
return true;
}
SelectedWidget = this;
return true;
}
// Remove focus from this widget; return false if you don't want to give it up
public virtual bool LoseFocus(MouseInput mi)
{
// Some widgets may need to override focus depending on mouse click
return LoseFocus();
}
// Remove focus from this widget; return false if you don't want to give it up
public virtual bool LoseFocus(MouseInput mi)
{
// Some widgets may need to override focus depending on mouse click
return LoseFocus();
}
public virtual bool LoseFocus()
{
if (SelectedWidget == this)
SelectedWidget = null;
public virtual bool LoseFocus()
{
if (SelectedWidget == this)
SelectedWidget = null;
return true;
}
return true;
}
public virtual string GetCursor(int2 pos) { return "default"; }
public string GetCursorOuter(int2 pos)
{
// Is the cursor on top of us?
if (!(IsVisible() && GetEventBounds().Contains(pos)))
return null;
public virtual string GetCursor(int2 pos) { return "default"; }
public string GetCursorOuter(int2 pos)
{
// Is the cursor on top of us?
if (!(IsVisible() && GetEventBounds().Contains(pos)))
return null;
// Do any of our children specify a cursor?
foreach (var child in Children.OfType<Widget>().Reverse())
{
var cc = child.GetCursorOuter(pos);
if (cc != null)
return cc;
}
// Do any of our children specify a cursor?
foreach (var child in Children.OfType<Widget>().Reverse())
{
var cc = child.GetCursorOuter(pos);
if (cc != null)
return cc;
}
return EventBounds.Contains(pos) ? GetCursor(pos) : null;
}
return EventBounds.Contains(pos) ? GetCursor(pos) : null;
}
public virtual void MouseEntered() {}
public virtual void MouseExited() {}
public virtual bool HandleMouseInput(MouseInput mi) { return false; }
public bool HandleMouseInputOuter(MouseInput mi)
{
public bool HandleMouseInputOuter(MouseInput mi)
{
// Are we able to handle this event?
if (!(Focused || (IsVisible() && GetEventBounds().Contains(mi.Location))))
return false;
if (!(Focused || (IsVisible() && GetEventBounds().Contains(mi.Location))))
return false;
var oldMouseOver = MouseOverWidget;
// Send the event to the deepest children first and bubble up if unhandled
foreach (var child in Children.OfType<Widget>().Reverse())
if (child.HandleMouseInputOuter(mi))
return true;
// Send the event to the deepest children first and bubble up if unhandled
foreach (var child in Children.OfType<Widget>().Reverse())
if (child.HandleMouseInputOuter(mi))
return true;
if (IgnoreChildMouseOver)
MouseOverWidget = oldMouseOver;
@@ -302,58 +302,58 @@ namespace OpenRA.Widgets
if (mi.Event == MouseInputEvent.Move && MouseOverWidget == null && !IgnoreMouseOver)
MouseOverWidget = this;
return HandleMouseInput(mi);
}
return HandleMouseInput(mi);
}
public virtual bool HandleKeyPress(KeyInput e) { return false; }
public virtual bool HandleKeyPress(KeyInput e) { return false; }
public virtual bool HandleKeyPressOuter(KeyInput e)
{
if (!IsVisible())
return false;
public virtual bool HandleKeyPressOuter(KeyInput e)
{
if (!IsVisible())
return false;
// Can any of our children handle this?
// Can any of our children handle this?
foreach (var child in Children.OfType<Widget>().Reverse())
if (child.HandleKeyPressOuter(e))
return true;
if (child.HandleKeyPressOuter(e))
return true;
// Do any widgety behavior (enter text etc)
var handled = HandleKeyPress(e);
// Do any widgety behavior (enter text etc)
var handled = HandleKeyPress(e);
return handled;
}
return handled;
}
public virtual void Draw() {}
public virtual void Draw() {}
public virtual void DrawOuter()
{
if (IsVisible())
{
Draw();
foreach (var child in Children)
child.DrawOuter();
}
}
public virtual void DrawOuter()
{
if (IsVisible())
{
Draw();
foreach (var child in Children)
child.DrawOuter();
}
}
public virtual void Tick() {}
public virtual void TickOuter()
{
if (IsVisible())
public virtual void TickOuter()
{
if (IsVisible())
{
Tick();
foreach (var child in Children)
child.TickOuter();
foreach (var child in Children)
child.TickOuter();
}
}
}
public virtual void AddChild(Widget child)
{
child.Parent = this;
Children.Add(child);
}
public virtual void AddChild(Widget child)
{
child.Parent = this;
Children.Add(child);
}
public virtual void RemoveChild(Widget child)
public virtual void RemoveChild(Widget child)
{
Children.Remove(child);
child.Removed();
@@ -371,36 +371,36 @@ namespace OpenRA.Widgets
c.Removed();
}
public Widget GetWidget(string id)
{
if (this.Id == id)
return this;
public Widget GetWidget(string id)
{
if (this.Id == id)
return this;
foreach (var child in Children)
{
var w = child.GetWidget(id);
if (w != null)
return w;
}
return null;
}
foreach (var child in Children)
{
var w = child.GetWidget(id);
if (w != null)
return w;
}
return null;
}
public T GetWidget<T>(string id) where T : Widget
{
var widget = GetWidget(id);
return (widget != null) ? (T)widget : null;
}
}
public T GetWidget<T>(string id) where T : Widget
{
var widget = GetWidget(id);
return (widget != null) ? (T)widget : null;
}
}
public class ContainerWidget : Widget
{
public ContainerWidget() : base() { IgnoreMouseOver = true; }
public ContainerWidget(ContainerWidget other)
: base(other) { IgnoreMouseOver = true; }
public class ContainerWidget : Widget
{
public ContainerWidget() : base() { IgnoreMouseOver = true; }
public ContainerWidget(ContainerWidget other)
: base(other) { IgnoreMouseOver = true; }
public override string GetCursor(int2 pos) { return null; }
public override Widget Clone() { return new ContainerWidget(this); }
}
public override string GetCursor(int2 pos) { return null; }
public override Widget Clone() { return new ContainerWidget(this); }
}
public class WidgetArgs : Dictionary<string, object>
{
@@ -411,8 +411,8 @@ namespace OpenRA.Widgets
// TODO: you should use this anywhere you want to do
// something in a logic ctor, but retain debuggability.
public interface ILogicWithInit
{
void Init();
}
public interface ILogicWithInit
{
void Init();
}
}

View File

@@ -34,17 +34,17 @@ namespace OpenRA.Widgets
public override void Draw()
{
var selbox = SelectionBox;
if (selbox == null)
{
foreach (var u in SelectActorsInBox(world, dragStart, dragStart))
worldRenderer.DrawRollover(u);
if (selbox == null)
{
foreach (var u in SelectActorsInBox(world, dragStart, dragStart))
worldRenderer.DrawRollover(u);
return;
}
return;
}
Game.Renderer.WorldLineRenderer.DrawRect( selbox.Value.First, selbox.Value.Second, Color.White );
foreach (var u in SelectActorsInBox(world, selbox.Value.First, selbox.Value.Second))
worldRenderer.DrawRollover(u);
foreach (var u in SelectActorsInBox(world, selbox.Value.First, selbox.Value.Second))
worldRenderer.DrawRollover(u);
}
int2 dragStart, dragEnd;
@@ -159,7 +159,7 @@ namespace OpenRA.Widgets
return false;
}
static readonly Actor[] NoActors = {};
static readonly Actor[] NoActors = {};
IEnumerable<Actor> SelectActorsInBox(World world, int2 a, int2 b)
{
return world.FindUnits(a, b)

View File

@@ -209,10 +209,10 @@ namespace OpenRA
}
}
public IEnumerable<TraitPair<T>> ActorsWithTrait<T>()
{
return traitDict.ActorsWithTraitMultiple<T>(this);
}
public IEnumerable<TraitPair<T>> ActorsWithTrait<T>()
{
return traitDict.ActorsWithTraitMultiple<T>(this);
}
}
public struct TraitPair<T>