move all databinding for the silobar into ui logic
This commit is contained in:
@@ -152,6 +152,17 @@ namespace OpenRA.Mods.Cnc.Widgets.Logic
|
|||||||
InitObserverWidgets(world, playerRoot);
|
InitObserverWidgets(world, playerRoot);
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
var siloBar = playerWidgets.Get<SiloBarWidget>("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<T>(World world, Widget parent, string button, string icon)
|
static void BindOrderButton<T>(World world, Widget parent, string button, string icon)
|
||||||
|
|||||||
@@ -27,21 +27,17 @@ namespace OpenRA.Mods.Cnc.Widgets
|
|||||||
EWMA providedLerp = new EWMA(0.3f);
|
EWMA providedLerp = new EWMA(0.3f);
|
||||||
EWMA usedLerp = new EWMA(0.3f);
|
EWMA usedLerp = new EWMA(0.3f);
|
||||||
|
|
||||||
public Func<float> GetProvided, GetUsed;
|
public Func<float> GetProvided = () => 0;
|
||||||
public string TooltipFormat = "Silo Usage: {0}/{1}";
|
public Func<float> GetUsed = () => 0;
|
||||||
|
public string TooltipFormat = "";
|
||||||
public bool RightIndicator = false;
|
public bool RightIndicator = false;
|
||||||
|
public Func<Color> GetBarColor = () => Color.White;
|
||||||
readonly PlayerResources pr;
|
|
||||||
|
|
||||||
[ObjectCreator.UseCtor]
|
[ObjectCreator.UseCtor]
|
||||||
public SiloBarWidget(World world)
|
public SiloBarWidget(World world)
|
||||||
{
|
{
|
||||||
pr = world.LocalPlayer.PlayerActor.Trait<PlayerResources>();
|
|
||||||
tooltipContainer = Lazy.New(() =>
|
tooltipContainer = Lazy.New(() =>
|
||||||
Ui.Root.Get<TooltipContainerWidget>(TooltipContainer));
|
Ui.Root.Get<TooltipContainerWidget>(TooltipContainer));
|
||||||
|
|
||||||
GetProvided = () => pr.OreCapacity;
|
|
||||||
GetUsed = () => pr.Ore;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public override void MouseEntered()
|
public override void MouseEntered()
|
||||||
@@ -84,12 +80,5 @@ namespace OpenRA.Mods.Cnc.Widgets
|
|||||||
|
|
||||||
Game.Renderer.RgbaSpriteRenderer.DrawSprite(indicator, pos);
|
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;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -163,14 +163,14 @@ Container@PLAYER_WIDGETS:
|
|||||||
Width:PARENT_RIGHT-2
|
Width:PARENT_RIGHT-2
|
||||||
Height:PARENT_BOTTOM-2
|
Height:PARENT_BOTTOM-2
|
||||||
TooltipContainer:TOOLTIP_CONTAINER
|
TooltipContainer:TOOLTIP_CONTAINER
|
||||||
Background@SILOBAR:
|
Background@SILOBAR_PANEL:
|
||||||
X:180
|
X:180
|
||||||
Y:5
|
Y:5
|
||||||
Width:10
|
Width:10
|
||||||
Height:168
|
Height:168
|
||||||
Background:panel-black
|
Background:panel-black
|
||||||
Children:
|
Children:
|
||||||
SiloBar:
|
SiloBar@SILOBAR:
|
||||||
X:1
|
X:1
|
||||||
Y:1
|
Y:1
|
||||||
Width:PARENT_RIGHT-2
|
Width:PARENT_RIGHT-2
|
||||||
|
|||||||
Reference in New Issue
Block a user