Add bindings to ProgressBarWidget.

This commit is contained in:
Paul Chote
2014-03-16 18:02:15 +13:00
parent e2e0728e20
commit 6b199d3376
2 changed files with 28 additions and 17 deletions

View File

@@ -8,6 +8,7 @@
*/
#endregion
using System;
using System.Drawing;
namespace OpenRA.Widgets
@@ -17,45 +18,57 @@ namespace OpenRA.Widgets
public int Percentage = 0;
public bool Indeterminate = false;
public Func<int> GetPercentage;
public Func<bool> IsIndeterminate;
// Indeterminant bar properties
float offset = 0f;
float tickStep = 0.04f;
public ProgressBarWidget() {}
protected ProgressBarWidget(ProgressBarWidget widget)
: base(widget)
public ProgressBarWidget()
{
Percentage = widget.Percentage;
GetPercentage = () => Percentage;
IsIndeterminate = () => Indeterminate;
}
protected ProgressBarWidget(ProgressBarWidget other)
: base(other)
{
Percentage = other.Percentage;
GetPercentage = other.GetPercentage;
IsIndeterminate = other.IsIndeterminate;
}
public override void Draw()
{
var rb = RenderBounds;
var percentage = GetPercentage();
WidgetUtils.DrawPanel("progressbar-bg", rb);
Rectangle barRect = Indeterminate ?
Rectangle barRect = wasIndeterminate ?
new Rectangle(rb.X + 2 + (int)(0.75*offset*(rb.Width - 4)), rb.Y + 2, (rb.Width - 4) / 4, rb.Height - 4) :
new Rectangle(rb.X + 2, rb.Y + 2, Percentage * (rb.Width - 4) / 100, rb.Height - 4);
new Rectangle(rb.X + 2, rb.Y + 2, percentage * (rb.Width - 4) / 100, rb.Height - 4);
if (barRect.Width > 0)
WidgetUtils.DrawPanel("progressbar-thumb", barRect);
}
bool wasIndeterminate;
public override void Tick()
{
if (Indeterminate)
var indeterminate = IsIndeterminate();
if (indeterminate != wasIndeterminate)
offset = 0f;
if (indeterminate)
{
offset += tickStep;
offset = offset.Clamp(0f, 1f);
if (offset == 0f || offset == 1f)
tickStep *= -1;
}
}
public void SetIndeterminate(bool value)
{
Indeterminate = value;
offset = 0f;
wasIndeterminate = indeterminate;
}
public override Widget Clone() { return new ProgressBarWidget(this); }

View File

@@ -43,7 +43,7 @@ namespace OpenRA.Mods.RA.Widgets.Logic
void ShowDownloadDialog()
{
statusLabel.GetText = () => "Initializing...";
progressBar.SetIndeterminate(true);
progressBar.Indeterminate = true;
var retryButton = panel.Get<ButtonWidget>("RETRY_BUTTON");
retryButton.IsVisible = () => false;
@@ -55,9 +55,7 @@ namespace OpenRA.Mods.RA.Widgets.Logic
Action<DownloadProgressChangedEventArgs> onDownloadProgress = i =>
{
if (progressBar.Indeterminate)
progressBar.SetIndeterminate(false);
progressBar.Indeterminate = false;
progressBar.Percentage = i.ProgressPercentage;
statusLabel.GetText = () => "Downloading {1}/{2} kB ({0}%)".F(i.ProgressPercentage, i.BytesReceived / 1024, i.TotalBytesToReceive / 1024);
};
@@ -91,7 +89,7 @@ namespace OpenRA.Mods.RA.Widgets.Logic
// Automatically extract
statusLabel.GetText = () => "Extracting...";
progressBar.SetIndeterminate(true);
progressBar.Indeterminate = true;
if (InstallUtils.ExtractZip(file, dest, onExtractProgress, onError))
{
Game.RunAfterTick(() =>