mirror of
https://github.com/ClassiCube/ClassiCube.git
synced 2025-09-17 03:25:14 -04:00
Show progress bar for fetching resources in the launcher.
This commit is contained in:
parent
b08917f116
commit
d8e8d32340
@ -139,12 +139,12 @@ namespace ClassicalSharp {
|
||||
}
|
||||
|
||||
int progress = game.AsyncDownloader.CurrentItemProgress;
|
||||
if( progress == lastDownloadStatus ) return;
|
||||
if( progress == lastDownloadStatus ) return;
|
||||
lastDownloadStatus = progress;
|
||||
SetTexturePackMessage( progress );
|
||||
SetFetchStatus( progress );
|
||||
}
|
||||
|
||||
void SetTexturePackMessage( int progress ) {
|
||||
void SetFetchStatus( int progress ) {
|
||||
lastDownload.Clear();
|
||||
int index = 0;
|
||||
if( progress == -2 )
|
||||
|
@ -20,8 +20,8 @@ namespace ClassicalSharp.Network {
|
||||
Dictionary<string, DownloadedItem> downloaded = new Dictionary<string, DownloadedItem>();
|
||||
string skinServer = null;
|
||||
|
||||
internal Request CurrentItem;
|
||||
internal int CurrentItemProgress = -3;
|
||||
public Request CurrentItem;
|
||||
public int CurrentItemProgress = -3;
|
||||
|
||||
public AsyncDownloader( string skinServer ) {
|
||||
this.skinServer = skinServer;
|
||||
@ -268,7 +268,7 @@ namespace ClassicalSharp.Network {
|
||||
|
||||
public enum RequestType { Bitmap, String, ByteArray, ContentLength }
|
||||
|
||||
internal sealed class Request {
|
||||
public sealed class Request {
|
||||
|
||||
public string Url;
|
||||
public string Identifier;
|
||||
|
@ -26,6 +26,7 @@ namespace Launcher {
|
||||
bool failed;
|
||||
public override void Tick() {
|
||||
if( fetcher == null || failed ) return;
|
||||
CheckCurrentProgress();
|
||||
|
||||
if( !fetcher.Check( SetStatus ) )
|
||||
failed = true;
|
||||
@ -44,18 +45,92 @@ namespace Launcher {
|
||||
|
||||
public override void Resize() {
|
||||
MakeWidgets();
|
||||
RedrawAllButtonBackgrounds();
|
||||
|
||||
using( drawer ) {
|
||||
drawer.SetBitmap( game.Framebuffer );
|
||||
drawer.Clear( clearCol );
|
||||
drawer.Clear( backCol, game.Width / 2 - 175, game.Height / 2 - 70, 175 * 2, 70 * 2 );
|
||||
drawer.Clear( backCol, game.Width / 2 - 190, game.Height / 2 - 70, 190 * 2, 70 * 2 );
|
||||
}
|
||||
|
||||
RedrawAllButtonBackgrounds();
|
||||
using( drawer ) {
|
||||
drawer.SetBitmap( game.Framebuffer );
|
||||
RedrawAll();
|
||||
}
|
||||
Dirty = true;
|
||||
}
|
||||
|
||||
int lastProgress = int.MinValue;
|
||||
void CheckCurrentProgress() {
|
||||
Request item = fetcher.downloader.CurrentItem;
|
||||
if( item == null ) {
|
||||
lastProgress = int.MinValue; return;
|
||||
}
|
||||
|
||||
int progress = fetcher.downloader.CurrentItemProgress;
|
||||
if( progress == lastProgress ) return;
|
||||
lastProgress = progress;
|
||||
SetFetchStatus( progress );
|
||||
}
|
||||
|
||||
void SetFetchStatus( int progress ) {
|
||||
if( progress >= 0 && progress <= 100 )
|
||||
DrawProgressBox( progress );
|
||||
}
|
||||
|
||||
static FastColour progBack = new FastColour( 220, 220, 220 );
|
||||
static FastColour progFront = new FastColour( 0, 220, 0 );
|
||||
void DrawProgressBox( int progress ) {
|
||||
progress = (200 * progress) / 100;
|
||||
using( drawer ) {
|
||||
drawer.SetBitmap( game.Framebuffer );
|
||||
drawer.DrawRect( progBack, game.Width / 2 - 100, game.Height / 2 + 10, 200, 4 );
|
||||
drawer.DrawRect( progFront, game.Width / 2 - 100, game.Height / 2 + 10, progress, 4 );
|
||||
Dirty = true;
|
||||
}
|
||||
}
|
||||
|
||||
ResourceFetcher fetcher;
|
||||
Font textFont;
|
||||
static FastColour backCol = new FastColour( 120, 85, 151 );
|
||||
static readonly string mainText = "Some required resources weren't found" +
|
||||
Environment.NewLine + "Okay to download them?";
|
||||
static readonly string format = "&eDownload size: {0} megabytes";
|
||||
static FastColour clearCol = new FastColour( 12, 12, 12 );
|
||||
bool useStatus;
|
||||
|
||||
void MakeWidgets() {
|
||||
widgetIndex = 0;
|
||||
if( useStatus ) {
|
||||
MakeLabelAt( widgets[0].Text, statusFont, Anchor.Centre, Anchor.Centre, 0, -10 );
|
||||
} else {
|
||||
float dataSize = game.fetcher.DownloadSize;
|
||||
string text = String.Format( format, dataSize.ToString( "F2" ) );
|
||||
MakeLabelAt( text, statusFont, Anchor.Centre, Anchor.Centre, 0, 10 );
|
||||
}
|
||||
|
||||
// Clear the entire previous widgets state.
|
||||
for( int i = 1; i < widgets.Length; i++ ) {
|
||||
widgets[i] = null;
|
||||
selectedWidget = null;
|
||||
lastClicked = null;
|
||||
}
|
||||
|
||||
if( fetcher == null ) {
|
||||
MakeLabelAt( mainText, infoFont, Anchor.Centre, Anchor.Centre, 0, -40 );
|
||||
MakeButtonAt( "Yes", 70, 35, textFont, Anchor.Centre,
|
||||
-70, 45, DownloadResources );
|
||||
|
||||
MakeButtonAt( "No", 70, 35, textFont, Anchor.Centre,
|
||||
70, 45, (x, y) => GotoNextMenu() );
|
||||
} else {
|
||||
MakeButtonAt( "Cancel", 120, 35, textFont, Anchor.Centre,
|
||||
0, 45, (x, y) => GotoNextMenu() );
|
||||
}
|
||||
|
||||
if( lastProgress >= 0 && lastProgress <= 100 )
|
||||
DrawProgressBox( lastProgress );
|
||||
}
|
||||
|
||||
void DownloadResources( int mouseX, int mouseY ) {
|
||||
if( game.Downloader == null )
|
||||
game.Downloader = new AsyncDownloader( "null" );
|
||||
@ -67,41 +142,6 @@ namespace Launcher {
|
||||
Resize();
|
||||
}
|
||||
|
||||
Font textFont;
|
||||
static FastColour backCol = new FastColour( 120, 85, 151 );
|
||||
static readonly string mainText = "Some required resources weren't found" +
|
||||
Environment.NewLine + "Okay to download them?";
|
||||
static readonly string format = "Download size: {0} megabytes";
|
||||
static FastColour clearCol = new FastColour( 12, 12, 12 );
|
||||
|
||||
void MakeWidgets() {
|
||||
widgetIndex = 0;
|
||||
|
||||
float dataSize = game.fetcher.DownloadSize;
|
||||
string text = widgets[0] != null ? widgets[0].Text
|
||||
: String.Format( format, dataSize.ToString( "F2" ) );
|
||||
MakeLabelAt( text, statusFont, Anchor.Centre, Anchor.Centre, 0, 5 );
|
||||
|
||||
// Clear the entire previous widgets state.
|
||||
for( int i = 1; i < widgets.Length; i++ ) {
|
||||
widgets[i] = null;
|
||||
selectedWidget = null;
|
||||
lastClicked = null;
|
||||
}
|
||||
|
||||
if( fetcher == null ) {
|
||||
MakeLabelAt( mainText, infoFont, Anchor.Centre, Anchor.Centre, 0, -30 );
|
||||
MakeButtonAt( "Yes", 60, 30, textFont, Anchor.Centre,
|
||||
-50, 40, DownloadResources );
|
||||
|
||||
MakeButtonAt( "No", 60, 30, textFont, Anchor.Centre,
|
||||
50, 40, (x, y) => GotoNextMenu() );
|
||||
} else {
|
||||
MakeButtonAt( "Cancel", 120, 30, textFont, Anchor.Centre,
|
||||
0, 40, (x, y) => GotoNextMenu() );
|
||||
}
|
||||
}
|
||||
|
||||
void GotoNextMenu() {
|
||||
if( File.Exists( "options.txt" ) )
|
||||
game.SetScreen( new MainScreen( game ) );
|
||||
@ -110,11 +150,12 @@ namespace Launcher {
|
||||
}
|
||||
|
||||
void SetStatus( string text ) {
|
||||
useStatus = true;
|
||||
LauncherLabelWidget widget = (LauncherLabelWidget)widgets[0];
|
||||
using( drawer ) {
|
||||
drawer.SetBitmap( game.Framebuffer );
|
||||
drawer.Clear( backCol, widget.X, widget.Y, widget.Width, widget.Height );
|
||||
widget.SetDrawData( drawer, text, statusFont, Anchor.Centre, Anchor.Centre, 0, 5 );
|
||||
widget.SetDrawData( drawer, text, statusFont, Anchor.Centre, Anchor.Centre, 0, -10 );
|
||||
widget.Redraw( drawer );
|
||||
Dirty = true;
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user