Skip to content

Commit 2dfb5b9

Browse files
committed
Add button label offset for production icons
1 parent 16fd156 commit 2dfb5b9

4 files changed

Lines changed: 17 additions & 4 deletions

File tree

OpenRA.Mods.Common/Graphics/DefaultSpriteSequence.cs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,8 @@ public ReservationInfo(string filename, List<int> loadFrames, int[] frames, Mini
140140
protected static readonly SpriteSequenceField<ProductionButtonStyle> ButtonStyleField = new(nameof(ButtonStyle), ProductionButtonStyle.Ra2);
141141
protected static readonly SpriteSequenceField<string> ButtonLabelField = new(nameof(ButtonLabel), null);
142142
protected static readonly SpriteSequenceField<string> ButtonLabelFontField = new(nameof(ButtonLabelFont), null);
143+
[Desc("Offset applied to the button label bar in pixels.")]
144+
protected static readonly SpriteSequenceField<float2> ButtonLabelOffsetField = new(nameof(ButtonLabelOffset), float2.Zero);
143145
protected int tick;
144146

145147
[Desc("The total number of facings for the sequence. " +
@@ -234,6 +236,7 @@ public ReservationInfo(string filename, List<int> loadFrames, int[] frames, Mini
234236
protected ProductionButtonStyle buttonStyle;
235237
protected string buttonLabel;
236238
protected string buttonLabelFont;
239+
protected float2 buttonLabelOffset;
237240

238241
protected int zOffset;
239242
protected int shadowZOffset;
@@ -282,6 +285,7 @@ Rectangle ISpriteSequence.Bounds
282285
public ProductionButtonStyle ButtonStyle => buttonStyle;
283286
public string ButtonLabel => buttonLabel;
284287
public string ButtonLabelFont => buttonLabelFont;
288+
public float2 ButtonLabelOffset => buttonLabelOffset;
285289

286290

287291
protected static T LoadField<T>(string key, T fallback, MiniYaml data, MiniYaml defaults = null)
@@ -404,6 +408,7 @@ public DefaultSpriteSequence(SpriteCache cache, ISpriteSequenceLoader loader, st
404408
buttonStyle = LoadField(ButtonStyleField, data, defaults);
405409
buttonLabel = LoadField(ButtonLabelField, data, defaults);
406410
buttonLabelFont = LoadField(ButtonLabelFontField, data, defaults);
411+
buttonLabelOffset = LoadField(ButtonLabelOffsetField, data, defaults);
407412
interpolatedFacings = LoadField(InterpolatedFacings, data, defaults, out var interpolatedFacingsLocation);
408413

409414

@@ -661,5 +666,3 @@ protected virtual float GetScale()
661666

662667

663668

664-
665-

OpenRA.Mods.Common/Widgets/ObserverProductionIconsWidget.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,7 @@ public override void Draw()
166166
productionIcon.ButtonStyle = seq.ButtonStyle;
167167
productionIcon.ButtonLabel = seq.ButtonLabel;
168168
productionIcon.ButtonLabelFont = seq.ButtonLabelFont;
169+
productionIcon.ButtonLabelOffset = seq.ButtonLabelOffset;
169170
}
170171

171172
productionIcons.Add(productionIcon);

OpenRA.Mods.Common/Widgets/ProductionIconButtonizer.cs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,7 @@ public static void Draw(ProductionIcon icon, Rectangle rect, string fallbackText
9292
return;
9393

9494
var style = ResolveStyle(icon.ButtonStyle);
95+
9596
var fontName = icon.ButtonLabelFont ?? fallbackFont;
9697
var useOsFont = OsShpCameoFontRenderer.CanHandle(fontName);
9798
var frameRect = useOsFont
@@ -103,7 +104,14 @@ public static void Draw(ProductionIcon icon, Rectangle rect, string fallbackText
103104
if (string.IsNullOrEmpty(label))
104105
return;
105106

106-
DrawLabel(rect, label, fontName, fallbackFont, style);
107+
var labelRect = rect;
108+
if (icon.ButtonLabelOffset != float2.Zero)
109+
labelRect = new Rectangle(
110+
rect.Left + (int)icon.ButtonLabelOffset.X,
111+
rect.Top + (int)icon.ButtonLabelOffset.Y,
112+
rect.Width,
113+
rect.Height);
114+
DrawLabel(labelRect, label, fontName, fallbackFont, style);
107115
}
108116

109117
static ButtonVisualStyle ResolveStyle(ProductionButtonStyle style)

OpenRA.Mods.Common/Widgets/ProductionPaletteWidget.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ public class ProductionIcon
3939
public ProductionButtonStyle ButtonStyle;
4040
public string ButtonLabel;
4141
public string ButtonLabelFont;
42+
public float2 ButtonLabelOffset;
4243
public float2 Pos;
4344
public List<ProductionItem> Queued;
4445
public ProductionQueue ProductionQueue;
@@ -550,6 +551,7 @@ public void RefreshIcons()
550551
pi.ButtonStyle = seq.ButtonStyle;
551552
pi.ButtonLabel = seq.ButtonLabel;
552553
pi.ButtonLabelFont = seq.ButtonLabelFont;
554+
pi.ButtonLabelOffset = seq.ButtonLabelOffset;
553555
}
554556

555557
if (!icons.ContainsKey(rect))
@@ -667,4 +669,3 @@ public override string GetCursor(int2 pos)
667669

668670

669671

670-

0 commit comments

Comments
 (0)