diff --git a/OpenRa.Game/Chrome.cs b/OpenRa.Game/Chrome.cs index fee25e94b0..0d4c6a5606 100644 --- a/OpenRa.Game/Chrome.cs +++ b/OpenRa.Game/Chrome.cs @@ -1191,5 +1191,13 @@ namespace OpenRa renderer.DrawText(sp.Info.LongDesc.Replace("\\n", "\n"), pos, Color.White); } } + + public void SetCurrentTab(string produces) + { + if (!paletteOpen) + paletteAnimating = true; + paletteOpen = true; + currentTab = produces; + } } } diff --git a/OpenRa.Game/OpenRa.Game.csproj b/OpenRa.Game/OpenRa.Game.csproj index 0f5e772675..d90d1bacc1 100644 --- a/OpenRa.Game/OpenRa.Game.csproj +++ b/OpenRa.Game/OpenRa.Game.csproj @@ -118,6 +118,7 @@ + diff --git a/OpenRa.Game/Traits/ChoosePaletteOnSelect.cs b/OpenRa.Game/Traits/ChoosePaletteOnSelect.cs new file mode 100644 index 0000000000..95bd9d386c --- /dev/null +++ b/OpenRa.Game/Traits/ChoosePaletteOnSelect.cs @@ -0,0 +1,27 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; + +namespace OpenRa.Traits +{ + class ChoosePaletteOnSelectInfo : StatelessTraitInfo { } + + class ChoosePaletteOnSelect : INotifySelection + { + public void SelectionChanged() + { + var firstItem = Game.controller.selection.Actors.FirstOrDefault( + a => a.World.LocalPlayer == a.Owner && a.traits.Contains()); + + if (firstItem == null) + return; + + var produces = firstItem.Info.Traits.Get().Produces.FirstOrDefault(); + if (produces == null) + return; + + Game.chrome.SetCurrentTab(produces); + } + } +} diff --git a/mods/ra/rules.yaml b/mods/ra/rules.yaml index 854f8bf9b4..6ccd281a36 100644 --- a/mods/ra/rules.yaml +++ b/mods/ra/rules.yaml @@ -71,6 +71,7 @@ World: LightPaletteRotator: BuildingInfluence: UnitInfluence: + ChoosePaletteOnSelect: PaletteFromFile@terrain_temperat: Name: terrain Filename: temperat.pal