diff --git a/OpenRA.Mods.Cnc/Widgets/Logic/CncIngameChromeLogic.cs b/OpenRA.Mods.Cnc/Widgets/Logic/CncIngameChromeLogic.cs index b34b7b66dd..a4ecd7282f 100644 --- a/OpenRA.Mods.Cnc/Widgets/Logic/CncIngameChromeLogic.cs +++ b/OpenRA.Mods.Cnc/Widgets/Logic/CncIngameChromeLogic.cs @@ -152,6 +152,17 @@ namespace OpenRA.Mods.Cnc.Widgets.Logic InitObserverWidgets(world, playerRoot); }); }; + + var siloBar = playerWidgets.Get("SILOBAR"); + siloBar.GetProvided = () => playerResources.OreCapacity; + siloBar.GetUsed = () => playerResources.Ore; + siloBar.TooltipFormat = "Silo Usage: {0}/{1}"; + siloBar.GetBarColor = () => + { + if (playerResources.Ore == playerResources.OreCapacity) return Color.Red; + if (playerResources.Ore >= 0.8 * playerResources.OreCapacity) return Color.Orange; + return Color.LimeGreen; + }; } static void BindOrderButton(World world, Widget parent, string button, string icon) diff --git a/OpenRA.Mods.Cnc/Widgets/SiloBarWidget.cs b/OpenRA.Mods.Cnc/Widgets/SiloBarWidget.cs index 14f5bc2622..40b86106ab 100755 --- a/OpenRA.Mods.Cnc/Widgets/SiloBarWidget.cs +++ b/OpenRA.Mods.Cnc/Widgets/SiloBarWidget.cs @@ -27,21 +27,17 @@ namespace OpenRA.Mods.Cnc.Widgets EWMA providedLerp = new EWMA(0.3f); EWMA usedLerp = new EWMA(0.3f); - public Func GetProvided, GetUsed; - public string TooltipFormat = "Silo Usage: {0}/{1}"; + public Func GetProvided = () => 0; + public Func GetUsed = () => 0; + public string TooltipFormat = ""; public bool RightIndicator = false; - - readonly PlayerResources pr; + public Func GetBarColor = () => Color.White; [ObjectCreator.UseCtor] public SiloBarWidget(World world) { - pr = world.LocalPlayer.PlayerActor.Trait(); tooltipContainer = Lazy.New(() => Ui.Root.Get(TooltipContainer)); - - GetProvided = () => pr.OreCapacity; - GetUsed = () => pr.Ore; } public override void MouseEntered() @@ -84,12 +80,5 @@ namespace OpenRA.Mods.Cnc.Widgets Game.Renderer.RgbaSpriteRenderer.DrawSprite(indicator, pos); } - - Color GetBarColor() - { - if (pr.Ore == pr.OreCapacity) return Color.Red; - if (pr.Ore >= LowStorageThreshold * pr.OreCapacity) return Color.Orange; - return Color.LimeGreen; - } } } diff --git a/mods/cnc/chrome/ingame.yaml b/mods/cnc/chrome/ingame.yaml index d680ede48f..28057c5873 100644 --- a/mods/cnc/chrome/ingame.yaml +++ b/mods/cnc/chrome/ingame.yaml @@ -163,14 +163,14 @@ Container@PLAYER_WIDGETS: Width:PARENT_RIGHT-2 Height:PARENT_BOTTOM-2 TooltipContainer:TOOLTIP_CONTAINER - Background@SILOBAR: + Background@SILOBAR_PANEL: X:180 Y:5 Width:10 Height:168 Background:panel-black Children: - SiloBar: + SiloBar@SILOBAR: X:1 Y:1 Width:PARENT_RIGHT-2