Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions OpenRA.Mods.CA/Widgets/Logic/Ingame/ProductionTabsLogicCA.cs
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,24 @@ void SetupProductionGroupButton(ProductionTypeButtonWidget button)
var icon = button.Get<ImageWidget>("ICON");
icon.GetImageName = () => button.IsDisabled() ? chromeName + "-disabled" :
tabs.Groups[button.ProductionGroup].Alert ? chromeName + "-alert" : chromeName;

var defaultIsVisible = icon.IsVisible;
icon.IsVisible = () =>
{
if (!defaultIsVisible())
return false;

var group = tabs.Groups[button.ProductionGroup];
if (!group.Alert && group.HasIdleFactories
&& tabs.QueueGroup != button.ProductionGroup
&& Game.Settings.Game.IdleFactoryAlert)
{
// Blink by toggling visibility using sine wave
return Math.Sin(Game.LocalTick * tabs.IdleAlertBlinkRate * 2 * Math.PI) > -0.3;
}

return true;
};
}

[ObjectCreator.UseCtor]
Expand Down
59 changes: 58 additions & 1 deletion OpenRA.Mods.CA/Widgets/ProductionTabsCAWidget.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,16 @@ public class ProductionTabCA
public string Name;
public ProductionQueue Queue;
public Actor Actor;
public int IdleTicks;
public bool IsIdle;
}

public class ProductionTabGroupCA
{
public List<ProductionTabCA> Tabs = new List<ProductionTabCA>();
public string Group;
public bool Alert { get { return Tabs.Any(t => t.Queue.AllQueued().Any(i => i.Done)); } }
public bool HasIdleFactories { get { return Tabs.Any(t => t.IsIdle); } }

public void Update(IEnumerable<ProductionQueue> allQueues)
{
Expand Down Expand Up @@ -96,6 +99,12 @@ public class ProductionTabsCAWidget : Widget
public readonly Color TabColor = Color.White;
public readonly Color TabColorDone = Color.Gold;

public readonly int IdleAlertDelay = 250;

public readonly HashSet<string> IdleAlertGroups = new() { "Infantry", "Vehicle", "Aircraft", "Ship" };

public readonly float IdleAlertBlinkRate = 0.08f;

int contentWidth = 0;
bool leftPressed = false;
bool rightPressed = false;
Expand Down Expand Up @@ -257,7 +266,21 @@ public override void Draw()
// Draw number label
var textSize = font.Measure(tab.Name);
var position = new int2(rect.X + (rect.Width - textSize.X) / 2, (rect.Y + (rect.Height - textSize.Y) / 2) - 1);
font.DrawText(tab.Name, position, tab.Queue.AllQueued().Any(i => i.Done) ? TabColorDone : TabColor);

Color tabTextColor;
var showText = true;
if (tab.Queue.AllQueued().Any(i => i.Done))
tabTextColor = TabColorDone;
else if (tab.IsIdle && !highlighted)
{
tabTextColor = TabColor;
showText = Math.Sin(Game.LocalTick * IdleAlertBlinkRate * 2 * Math.PI) > -0.3;
}
else
tabTextColor = TabColor;

if (showText)
font.DrawText(tab.Name, position, tabTextColor);

tabsShown++;
}
Expand Down Expand Up @@ -348,6 +371,40 @@ public override void Tick()
if (shouldUpdateQueues)
foreach (var g in Groups.Values)
g.Update(cachedProductionQueueEnabledStates.Select(t => t.Queue));

// Track idle ticks for each tab in groups that support idle alerts
if (Game.Settings.Game.IdleFactoryAlert)
{
foreach (var g in Groups.Values)
{
if (!IdleAlertGroups.Contains(g.Group))
continue;

foreach (var tab in g.Tabs)
{
var currentItem = tab.Queue.CurrentItem();
if (currentItem == null || currentItem.Paused)
{
tab.IdleTicks++;
tab.IsIdle = tab.IdleTicks >= IdleAlertDelay;
}
else
{
tab.IdleTicks = 0;
tab.IsIdle = false;
}
}
}
}
else
{
foreach (var g in Groups.Values)
foreach (var tab in g.Tabs)
{
tab.IdleTicks = 0;
tab.IsIdle = false;
}
}
}

public override bool YieldMouseFocus(MouseInput mi)
Expand Down
3 changes: 3 additions & 0 deletions mods/ca/chrome/ingame-player.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -735,6 +735,9 @@ Container@PLAYER_WIDGETS:
TabWidth: 31
TabSpacing: 3
ArrowWidth: 17
IdleAlertDelay: 250
IdleAlertGroups: Infantry, Vehicle, Aircraft, Ship
IdleAlertBlinkRate: 0.08
Logic: AddFactionSuffixLogicCA, ProductionTabsLogicCA
PaletteWidget: PRODUCTION_PALETTE
TypesContainer: PRODUCTION_TYPES
Expand Down
11 changes: 11 additions & 0 deletions mods/ca/chrome/settings-display.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,17 @@ Container@DISPLAY_PANEL:
Text: Selected Unit Tooltip
TooltipText: When a single unit/structure is selected, show info about it in bottom right corner
TooltipContainer: SETTINGS_TOOLTIP_CONTAINER
Container@IDLE_FACTORY_ALERT_CHECKBOX_CONTAINER:
X: PARENT_WIDTH / 2 + 10
Width: PARENT_WIDTH / 2 - 10
Children:
Checkbox@IDLE_FACTORY_ALERT_CHECKBOX:
Width: PARENT_WIDTH
Height: 20
Font: Regular
Text: Idle Factory Alert
TooltipText: Flash production tabs and sidebar icons when a factory is idle
TooltipContainer: SETTINGS_TOOLTIP_CONTAINER
Container@SPACER:
Background@VIDEO_SECTION_HEADER:
X: 5
Expand Down