split sprite-based and line-based things in Selectable into two traits
This commit is contained in:
@@ -205,6 +205,7 @@
|
|||||||
<Compile Include="Widgets\ListLayout.cs" />
|
<Compile Include="Widgets\ListLayout.cs" />
|
||||||
<Compile Include="Widgets\GridLayout.cs" />
|
<Compile Include="Widgets\GridLayout.cs" />
|
||||||
<Compile Include="Network\Replay.cs" />
|
<Compile Include="Network\Replay.cs" />
|
||||||
|
<Compile Include="Traits\SelectionDecorations.cs" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<ProjectReference Include="..\OpenRA.FileFormats\OpenRA.FileFormats.csproj">
|
<ProjectReference Include="..\OpenRA.FileFormats\OpenRA.FileFormats.csproj">
|
||||||
|
|||||||
@@ -23,10 +23,6 @@ namespace OpenRA.Traits
|
|||||||
|
|
||||||
public class Selectable : IPostRenderSelection
|
public class Selectable : IPostRenderSelection
|
||||||
{
|
{
|
||||||
// depends on the order of pips in TraitsInterfaces.cs!
|
|
||||||
static readonly string[] pipStrings = { "pip-empty", "pip-green", "pip-yellow", "pip-red", "pip-gray", "pip-blue" };
|
|
||||||
static readonly string[] tagStrings = { "", "tag-fake", "tag-primary" };
|
|
||||||
|
|
||||||
public void RenderAfterWorld (WorldRenderer wr, Actor self)
|
public void RenderAfterWorld (WorldRenderer wr, Actor self)
|
||||||
{
|
{
|
||||||
var bounds = self.Bounds.Value;
|
var bounds = self.Bounds.Value;
|
||||||
@@ -37,11 +33,8 @@ namespace OpenRA.Traits
|
|||||||
|
|
||||||
wr.DrawSelectionBox(self, Color.White);
|
wr.DrawSelectionBox(self, Color.White);
|
||||||
DrawHealthBar(self, xy, Xy);
|
DrawHealthBar(self, xy, Xy);
|
||||||
DrawControlGroup(wr, self, xy);
|
|
||||||
DrawPips(wr, self, xY);
|
|
||||||
DrawTags(wr, self, new float2(.5f * (bounds.Left + bounds.Right), bounds.Top));
|
|
||||||
DrawUnitPath(self);
|
|
||||||
DrawExtraBars(self, xy, Xy);
|
DrawExtraBars(self, xy, Xy);
|
||||||
|
DrawUnitPath(self);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void DrawRollover(WorldRenderer wr, Actor self)
|
public void DrawRollover(WorldRenderer wr, Actor self)
|
||||||
@@ -138,83 +131,6 @@ namespace OpenRA.Traits
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void DrawControlGroup(WorldRenderer wr, Actor self, float2 basePosition)
|
|
||||||
{
|
|
||||||
var group = self.World.Selection.GetControlGroupForActor(self);
|
|
||||||
if (group == null) return;
|
|
||||||
|
|
||||||
var pipImages = new Animation("pips");
|
|
||||||
pipImages.PlayFetchIndex("groups", () => (int)group);
|
|
||||||
pipImages.Tick();
|
|
||||||
pipImages.Image.DrawAt(wr, basePosition + new float2(-8, 1), "chrome");
|
|
||||||
}
|
|
||||||
|
|
||||||
void DrawPips(WorldRenderer wr, Actor self, float2 basePosition)
|
|
||||||
{
|
|
||||||
if (self.Owner != self.World.LocalPlayer) return;
|
|
||||||
|
|
||||||
var pipSources = self.TraitsImplementing<IPips>();
|
|
||||||
if (pipSources.Count() == 0)
|
|
||||||
return;
|
|
||||||
|
|
||||||
var pipImages = new Animation("pips");
|
|
||||||
pipImages.PlayRepeating(pipStrings[0]);
|
|
||||||
|
|
||||||
var pipSize = pipImages.Image.size;
|
|
||||||
var pipxyBase = basePosition + new float2(1, -pipSize.Y);
|
|
||||||
var pipxyOffset = new float2(0, 0); // Correct for offset due to multiple columns/rows
|
|
||||||
|
|
||||||
foreach (var pips in pipSources)
|
|
||||||
{
|
|
||||||
var thisRow = pips.GetPips(self);
|
|
||||||
if (thisRow == null)
|
|
||||||
continue;
|
|
||||||
|
|
||||||
var width = self.Bounds.Value.Width;
|
|
||||||
|
|
||||||
foreach (var pip in thisRow)
|
|
||||||
{
|
|
||||||
if (pipxyOffset.X + pipSize.X >= width)
|
|
||||||
{
|
|
||||||
pipxyOffset.X = 0;
|
|
||||||
pipxyOffset.Y -= pipSize.Y;
|
|
||||||
}
|
|
||||||
pipImages.PlayRepeating(pipStrings[(int)pip]);
|
|
||||||
pipImages.Image.DrawAt(wr, pipxyBase + pipxyOffset, "chrome");
|
|
||||||
pipxyOffset += new float2(pipSize.X, 0);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Increment row
|
|
||||||
pipxyOffset.X = 0;
|
|
||||||
pipxyOffset.Y -= pipSize.Y + 1;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void DrawTags(WorldRenderer wr, Actor self, float2 basePosition)
|
|
||||||
{
|
|
||||||
if (self.Owner != self.World.LocalPlayer) return;
|
|
||||||
|
|
||||||
// If a mod wants to implement a unit with multiple tags, then they are placed on multiple rows
|
|
||||||
var tagxyBase = basePosition + new float2(-16, 2); // Correct for the offset in the shp file
|
|
||||||
var tagxyOffset = new float2(0, 0); // Correct for offset due to multiple rows
|
|
||||||
|
|
||||||
foreach (var tags in self.TraitsImplementing<ITags>())
|
|
||||||
{
|
|
||||||
foreach (var tag in tags.GetTags())
|
|
||||||
{
|
|
||||||
if (tag == TagType.None)
|
|
||||||
continue;
|
|
||||||
|
|
||||||
var tagImages = new Animation("pips");
|
|
||||||
tagImages.PlayRepeating(tagStrings[(int)tag]);
|
|
||||||
tagImages.Image.DrawAt(wr, tagxyBase + tagxyOffset, "chrome");
|
|
||||||
|
|
||||||
// Increment row
|
|
||||||
tagxyOffset.Y += 8;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void DrawUnitPath(Actor self)
|
void DrawUnitPath(Actor self)
|
||||||
{
|
{
|
||||||
if (self.World.LocalPlayer == null ||!self.World.LocalPlayer.PlayerActor.Trait<DeveloperMode>().PathDebug) return;
|
if (self.World.LocalPlayer == null ||!self.World.LocalPlayer.PlayerActor.Trait<DeveloperMode>().PathDebug) return;
|
||||||
|
|||||||
116
OpenRA.Game/Traits/SelectionDecorations.cs
Normal file
116
OpenRA.Game/Traits/SelectionDecorations.cs
Normal file
@@ -0,0 +1,116 @@
|
|||||||
|
#region Copyright & License Information
|
||||||
|
/*
|
||||||
|
* Copyright 2007-2011 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. For more information,
|
||||||
|
* see COPYING.
|
||||||
|
*/
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
using System.Drawing;
|
||||||
|
using System.Linq;
|
||||||
|
using OpenRA.Graphics;
|
||||||
|
|
||||||
|
namespace OpenRA.Traits
|
||||||
|
{
|
||||||
|
public class SelectionDecorationsInfo : TraitInfo<SelectionDecorations> {}
|
||||||
|
|
||||||
|
public class SelectionDecorations : IPostRenderSelection
|
||||||
|
{
|
||||||
|
// depends on the order of pips in TraitsInterfaces.cs!
|
||||||
|
static readonly string[] pipStrings = { "pip-empty", "pip-green", "pip-yellow", "pip-red", "pip-gray", "pip-blue" };
|
||||||
|
static readonly string[] tagStrings = { "", "tag-fake", "tag-primary" };
|
||||||
|
|
||||||
|
public void RenderAfterWorld (WorldRenderer wr, Actor self)
|
||||||
|
{
|
||||||
|
var bounds = self.Bounds.Value;
|
||||||
|
|
||||||
|
var xy = new float2(bounds.Left, bounds.Top);
|
||||||
|
var xY = new float2(bounds.Left, bounds.Bottom);
|
||||||
|
|
||||||
|
DrawControlGroup(wr, self, xy);
|
||||||
|
DrawPips(wr, self, xY);
|
||||||
|
DrawTags(wr, self, new float2(.5f * (bounds.Left + bounds.Right), bounds.Top));
|
||||||
|
}
|
||||||
|
|
||||||
|
void DrawControlGroup(WorldRenderer wr, Actor self, float2 basePosition)
|
||||||
|
{
|
||||||
|
var group = self.World.Selection.GetControlGroupForActor(self);
|
||||||
|
if (group == null) return;
|
||||||
|
|
||||||
|
var pipImages = new Animation("pips");
|
||||||
|
pipImages.PlayFetchIndex("groups", () => (int)group);
|
||||||
|
pipImages.Tick();
|
||||||
|
pipImages.Image.DrawAt(wr, basePosition + new float2(-8, 1), "chrome");
|
||||||
|
}
|
||||||
|
|
||||||
|
void DrawPips(WorldRenderer wr, Actor self, float2 basePosition)
|
||||||
|
{
|
||||||
|
if (self.Owner != self.World.LocalPlayer) return;
|
||||||
|
|
||||||
|
var pipSources = self.TraitsImplementing<IPips>();
|
||||||
|
if (pipSources.Count() == 0)
|
||||||
|
return;
|
||||||
|
|
||||||
|
var pipImages = new Animation("pips");
|
||||||
|
pipImages.PlayRepeating(pipStrings[0]);
|
||||||
|
|
||||||
|
var pipSize = pipImages.Image.size;
|
||||||
|
var pipxyBase = basePosition + new float2(1, -pipSize.Y);
|
||||||
|
var pipxyOffset = new float2(0, 0); // Correct for offset due to multiple columns/rows
|
||||||
|
|
||||||
|
foreach (var pips in pipSources)
|
||||||
|
{
|
||||||
|
var thisRow = pips.GetPips(self);
|
||||||
|
if (thisRow == null)
|
||||||
|
continue;
|
||||||
|
|
||||||
|
var width = self.Bounds.Value.Width;
|
||||||
|
|
||||||
|
foreach (var pip in thisRow)
|
||||||
|
{
|
||||||
|
if (pipxyOffset.X + pipSize.X >= width)
|
||||||
|
{
|
||||||
|
pipxyOffset.X = 0;
|
||||||
|
pipxyOffset.Y -= pipSize.Y;
|
||||||
|
}
|
||||||
|
pipImages.PlayRepeating(pipStrings[(int)pip]);
|
||||||
|
pipImages.Image.DrawAt(wr, pipxyBase + pipxyOffset, "chrome");
|
||||||
|
pipxyOffset += new float2(pipSize.X, 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Increment row
|
||||||
|
pipxyOffset.X = 0;
|
||||||
|
pipxyOffset.Y -= pipSize.Y + 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void DrawTags(WorldRenderer wr, Actor self, float2 basePosition)
|
||||||
|
{
|
||||||
|
if (self.Owner != self.World.LocalPlayer) return;
|
||||||
|
|
||||||
|
// If a mod wants to implement a unit with multiple tags, then they are placed on multiple rows
|
||||||
|
var tagxyBase = basePosition + new float2(-16, 2); // Correct for the offset in the shp file
|
||||||
|
var tagxyOffset = new float2(0, 0); // Correct for offset due to multiple rows
|
||||||
|
|
||||||
|
foreach (var tags in self.TraitsImplementing<ITags>())
|
||||||
|
{
|
||||||
|
foreach (var tag in tags.GetTags())
|
||||||
|
{
|
||||||
|
if (tag == TagType.None)
|
||||||
|
continue;
|
||||||
|
|
||||||
|
var tagImages = new Animation("pips");
|
||||||
|
tagImages.PlayRepeating(tagStrings[(int)tag]);
|
||||||
|
tagImages.Image.DrawAt(wr, tagxyBase + tagxyOffset, "chrome");
|
||||||
|
|
||||||
|
// Increment row
|
||||||
|
tagxyOffset.Y += 8;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@@ -10,6 +10,7 @@
|
|||||||
BlueTiberium: 40
|
BlueTiberium: 40
|
||||||
Beach: 40
|
Beach: 40
|
||||||
ROT: 5
|
ROT: 5
|
||||||
|
SelectionDecorations:
|
||||||
Selectable:
|
Selectable:
|
||||||
Voice: VehicleVoice
|
Voice: VehicleVoice
|
||||||
TargetableUnit:
|
TargetableUnit:
|
||||||
@@ -43,6 +44,7 @@
|
|||||||
BlueTiberium: 70
|
BlueTiberium: 70
|
||||||
Beach: 70
|
Beach: 70
|
||||||
ROT: 5
|
ROT: 5
|
||||||
|
SelectionDecorations:
|
||||||
Selectable:
|
Selectable:
|
||||||
Voice: VehicleVoice
|
Voice: VehicleVoice
|
||||||
TargetableUnit:
|
TargetableUnit:
|
||||||
@@ -69,6 +71,7 @@
|
|||||||
UseLocation: yes
|
UseLocation: yes
|
||||||
TargetableUnit:
|
TargetableUnit:
|
||||||
TargetTypes: Air
|
TargetTypes: Air
|
||||||
|
SelectionDecorations:
|
||||||
Selectable:
|
Selectable:
|
||||||
Voice: VehicleVoice
|
Voice: VehicleVoice
|
||||||
Helicopter:
|
Helicopter:
|
||||||
@@ -106,6 +109,7 @@
|
|||||||
BlueTiberium: 70
|
BlueTiberium: 70
|
||||||
PathingCost: 1000
|
PathingCost: 1000
|
||||||
Beach: 80
|
Beach: 80
|
||||||
|
SelectionDecorations:
|
||||||
Selectable:
|
Selectable:
|
||||||
Voice: GenericVoice
|
Voice: GenericVoice
|
||||||
TargetableUnit:
|
TargetableUnit:
|
||||||
@@ -135,6 +139,7 @@
|
|||||||
-TakeCover:
|
-TakeCover:
|
||||||
-RenderInfantryProne:
|
-RenderInfantryProne:
|
||||||
AppearsOnRadar:
|
AppearsOnRadar:
|
||||||
|
SelectionDecorations:
|
||||||
Selectable:
|
Selectable:
|
||||||
Voice: CivilianMaleVoice
|
Voice: CivilianMaleVoice
|
||||||
Bounds: 12,17,0,-9
|
Bounds: 12,17,0,-9
|
||||||
@@ -162,6 +167,7 @@
|
|||||||
^Plane:
|
^Plane:
|
||||||
AppearsOnRadar:
|
AppearsOnRadar:
|
||||||
UseLocation: yes
|
UseLocation: yes
|
||||||
|
SelectionDecorations:
|
||||||
Selectable:
|
Selectable:
|
||||||
Voice: GenericVoice
|
Voice: GenericVoice
|
||||||
TargetableUnit:
|
TargetableUnit:
|
||||||
@@ -179,6 +185,7 @@
|
|||||||
Crushes: crate
|
Crushes: crate
|
||||||
TerrainSpeeds:
|
TerrainSpeeds:
|
||||||
Water: 100
|
Water: 100
|
||||||
|
SelectionDecorations:
|
||||||
Selectable:
|
Selectable:
|
||||||
Voice: GenericVoice
|
Voice: GenericVoice
|
||||||
TargetableUnit:
|
TargetableUnit:
|
||||||
@@ -193,6 +200,7 @@
|
|||||||
|
|
||||||
^Building:
|
^Building:
|
||||||
AppearsOnRadar:
|
AppearsOnRadar:
|
||||||
|
SelectionDecorations:
|
||||||
Selectable:
|
Selectable:
|
||||||
Priority: 3
|
Priority: 3
|
||||||
TargetableBuilding:
|
TargetableBuilding:
|
||||||
@@ -304,6 +312,7 @@
|
|||||||
CrushSound: sandbag2.aud
|
CrushSound: sandbag2.aud
|
||||||
LineBuild:
|
LineBuild:
|
||||||
Range: 8
|
Range: 8
|
||||||
|
SelectionDecorations:
|
||||||
Selectable:
|
Selectable:
|
||||||
Priority: 1
|
Priority: 1
|
||||||
RenderBuildingWall:
|
RenderBuildingWall:
|
||||||
|
|||||||
@@ -9,6 +9,7 @@
|
|||||||
Ore: 70
|
Ore: 70
|
||||||
Beach: 40
|
Beach: 40
|
||||||
ROT: 5
|
ROT: 5
|
||||||
|
SelectionDecorations:
|
||||||
Selectable:
|
Selectable:
|
||||||
Voice: VehicleVoice
|
Voice: VehicleVoice
|
||||||
TargetableUnit:
|
TargetableUnit:
|
||||||
@@ -43,6 +44,7 @@
|
|||||||
Ore: 70
|
Ore: 70
|
||||||
Beach: 70
|
Beach: 70
|
||||||
ROT: 5
|
ROT: 5
|
||||||
|
SelectionDecorations:
|
||||||
Selectable:
|
Selectable:
|
||||||
Voice: VehicleVoice
|
Voice: VehicleVoice
|
||||||
TargetableUnit:
|
TargetableUnit:
|
||||||
@@ -83,6 +85,7 @@
|
|||||||
Road: 100
|
Road: 100
|
||||||
Ore: 80
|
Ore: 80
|
||||||
Beach: 80
|
Beach: 80
|
||||||
|
SelectionDecorations:
|
||||||
Selectable:
|
Selectable:
|
||||||
Voice: GenericVoice
|
Voice: GenericVoice
|
||||||
TargetableUnit:
|
TargetableUnit:
|
||||||
@@ -115,6 +118,7 @@
|
|||||||
Crushes: crate
|
Crushes: crate
|
||||||
TerrainSpeeds:
|
TerrainSpeeds:
|
||||||
Water: 100
|
Water: 100
|
||||||
|
SelectionDecorations:
|
||||||
Selectable:
|
Selectable:
|
||||||
Voice: ShipVoice
|
Voice: ShipVoice
|
||||||
TargetableUnit:
|
TargetableUnit:
|
||||||
@@ -138,6 +142,7 @@
|
|||||||
^Plane:
|
^Plane:
|
||||||
AppearsOnRadar:
|
AppearsOnRadar:
|
||||||
UseLocation: yes
|
UseLocation: yes
|
||||||
|
SelectionDecorations:
|
||||||
Selectable:
|
Selectable:
|
||||||
Voice: GenericVoice
|
Voice: GenericVoice
|
||||||
TargetableAircraft:
|
TargetableAircraft:
|
||||||
@@ -169,6 +174,7 @@
|
|||||||
|
|
||||||
^Building:
|
^Building:
|
||||||
AppearsOnRadar:
|
AppearsOnRadar:
|
||||||
|
SelectionDecorations:
|
||||||
Selectable:
|
Selectable:
|
||||||
Priority: 3
|
Priority: 3
|
||||||
TargetableBuilding:
|
TargetableBuilding:
|
||||||
@@ -216,6 +222,7 @@
|
|||||||
CrushClasses: wall
|
CrushClasses: wall
|
||||||
LineBuild:
|
LineBuild:
|
||||||
Range: 8
|
Range: 8
|
||||||
|
SelectionDecorations:
|
||||||
Selectable:
|
Selectable:
|
||||||
Priority: 1
|
Priority: 1
|
||||||
TargetableBuilding:
|
TargetableBuilding:
|
||||||
|
|||||||
Reference in New Issue
Block a user