Partially separate ResourcesScreen into ResourcesView and ResourcesScreen.

This commit is contained in:
UnknownShadow200 2016-05-09 18:45:33 +10:00
parent acf52aab8f
commit 61559c63f3
4 changed files with 66 additions and 37 deletions

View File

@ -178,13 +178,8 @@ namespace Launcher {
protected void MakeInput( string text, int width, Anchor verAnchor, bool password,
int x, int y, int maxChars, string hint ) {
MakeInput( text, width, Anchor.Centre, verAnchor, password, x, y, maxChars, hint );
}
protected void MakeInput( string text, int width, Anchor horAnchor, Anchor verAnchor,
bool password, int x, int y, int maxChars, string hint ) {
WidgetConstructors.MakeInput( game, widgets, ref widgetIndex,
text, width, horAnchor, verAnchor,
text, width, Anchor.Centre, verAnchor,
inputFont, inputHintFont, InputClick,
password, x, y, maxChars, hint );
}

View File

@ -10,6 +10,7 @@ namespace Launcher {
public sealed class ResourcesScreen : LauncherScreen {
Font infoFont, statusFont;
ResourcesView view;
public ResourcesScreen( LauncherWindow game ) : base( game ) {
game.Window.Mouse.Move += MouseMove;
game.Window.Mouse.ButtonDown += MouseButtonDown;
@ -18,10 +19,15 @@ namespace Launcher {
infoFont = new Font( game.FontName, 14, FontStyle.Regular );
statusFont = new Font( game.FontName, 13, FontStyle.Italic );
buttonFont = textFont;
widgets = new LauncherWidget[4];
view = new ResourcesView( game );
widgets = view.widgets;
}
public override void Init() { Resize(); }
public override void Init() {
view.Init();
MakeWidgets();
Resize();
}
bool failed;
public override void Tick() {
@ -45,46 +51,25 @@ namespace Launcher {
public override void Resize() {
MakeWidgets();
using( drawer ) {
drawer.SetBitmap( game.Framebuffer );
drawer.Clear( clearCol );
drawer.Clear( backCol, game.Width / 2 - 190, game.Height / 2 - 70, 190 * 2, 70 * 2 );
}
RedrawAllButtonBackgrounds();
using( drawer ) {
drawer.SetBitmap( game.Framebuffer );
RedrawAll();
}
view.DrawAll();
Dirty = true;
}
int lastProgress = int.MinValue;
void CheckCurrentProgress() {
Request item = fetcher.downloader.CurrentItem;
if( item == null ) {
lastProgress = int.MinValue; return;
view.lastProgress = int.MinValue; return;
}
int progress = fetcher.downloader.CurrentItemProgress;
if( progress == lastProgress ) return;
lastProgress = progress;
if( progress == view.lastProgress ) return;
view.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 );
if( progress >= 0 && progress <= 100 ) {
view.DrawProgressBox( progress );
Dirty = true;
}
}
@ -127,8 +112,10 @@ namespace Launcher {
0, 45, (x, y) => GotoNextMenu() );
}
if( lastProgress >= 0 && lastProgress <= 100 )
DrawProgressBox( lastProgress );
if( view.lastProgress >= 0 && view.lastProgress <= 100 ) {
view.DrawProgressBox( view.lastProgress );
Dirty = true;
}
}
void DownloadResources( int mouseX, int mouseY ) {

View File

@ -0,0 +1,46 @@
// ClassicalSharp copyright 2014-2016 UnknownShadow200 | Licensed under MIT
using System;
using ClassicalSharp;
namespace Launcher {
public sealed class ResourcesView : IView {
public ResourcesView( LauncherWindow game ) : base( game ) {
widgets = new LauncherWidget[4];
}
public override void Init() {
// TODO: figure out how to fix this.
}
public override void DrawAll() {
using( drawer ) {
drawer.SetBitmap( game.Framebuffer );
drawer.Clear( clearCol );
drawer.Clear( backCol, game.Width / 2 - 190, game.Height / 2 - 70, 190 * 2, 70 * 2 );
}
RedrawAllButtonBackgrounds();
using( drawer ) {
drawer.SetBitmap( game.Framebuffer );
RedrawAll();
}
}
internal 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 );
}
}
internal int lastProgress = int.MinValue;
static FastColour backCol = new FastColour( 120, 85, 151 );
static FastColour clearCol = new FastColour( 12, 12, 12 );
static FastColour progBack = new FastColour( 220, 220, 220 );
static FastColour progFront = new FastColour( 0, 220, 0 );
}
}

View File

@ -77,6 +77,7 @@
<Compile Include="Gui\Views\ColoursView.cs" />
<Compile Include="Gui\Views\DirectConnectView.cs" />
<Compile Include="Gui\Views\IView.cs" />
<Compile Include="Gui\Views\ResourcesView.cs" />
<Compile Include="Gui\Views\ServersView.cs" />
<Compile Include="Gui\Views\UpdatesView.cs" />
<Compile Include="Gui\Widgets\LauncherBoolWidget.cs" />