Some code cleanup in the launcher.

This commit is contained in:
UnknownShadow200 2016-05-09 20:25:36 +10:00
parent f5900a82cd
commit 266f691d06
4 changed files with 45 additions and 67 deletions

View File

@ -76,11 +76,6 @@ namespace Launcher {
void ResetColours() { void ResetColours() {
LauncherSkin.ResetToDefault(); LauncherSkin.ResetToDefault();
view.MakeAllRGBTriplets( true ); view.MakeAllRGBTriplets( true );
using( drawer ) {
drawer.SetBitmap( game.Framebuffer );
RedrawAll();
}
game.MakeBackground(); game.MakeBackground();
Resize(); Resize();
} }

View File

@ -39,11 +39,9 @@ namespace Launcher {
protected LauncherWidget selectedWidget; protected LauncherWidget selectedWidget;
protected LauncherWidget[] widgets; protected LauncherWidget[] widgets;
protected virtual void MouseMove( object sender, MouseMoveEventArgs e ) { protected virtual void MouseMove( object sender, MouseMoveEventArgs e ) {
if( supressMove ) { if( supressMove ) { supressMove = false; return; }
supressMove = false;
return;
}
mouseMoved = true; mouseMoved = true;
for( int i = 0; i < widgets.Length; i++ ) { for( int i = 0; i < widgets.Length; i++ ) {
LauncherWidget widget = widgets[i]; LauncherWidget widget = widgets[i];
if( widget == null ) continue; if( widget == null ) continue;
@ -92,31 +90,6 @@ namespace Launcher {
} }
} }
protected void RedrawAllButtonBackgrounds() {
int buttons = 0;
for( int i = 0; i < widgets.Length; i++ ) {
if( widgets[i] == null || !(widgets[i] is LauncherButtonWidget) ) continue;
buttons++;
}
if( buttons == 0 ) return;
using( FastBitmap dst = new FastBitmap( game.Framebuffer, true, false ) ) {
for( int i = 0; i < widgets.Length; i++ ) {
if( widgets[i] == null ) continue;
LauncherButtonWidget button = widgets[i] as LauncherButtonWidget;
if( button != null )
button.RedrawBackground( dst );
}
}
}
protected void RedrawAll() {
for( int i = 0; i < widgets.Length; i++ ) {
if( widgets[i] == null ) continue;
widgets[i].Redraw( drawer );
}
}
protected LauncherWidget lastClicked; protected LauncherWidget lastClicked;
protected void MouseButtonDown( object sender, MouseButtonEventArgs e ) { protected void MouseButtonDown( object sender, MouseButtonEventArgs e ) {
if( e.Button != MouseButton.Left ) return; if( e.Button != MouseButton.Left ) return;
@ -175,13 +148,8 @@ namespace Launcher {
protected void MakeButtonAt( string text, int width, int height, Font font, protected void MakeButtonAt( string text, int width, int height, Font font,
Anchor verAnchor, int x, int y, Action<int, int> onClick ) { Anchor verAnchor, int x, int y, Action<int, int> onClick ) {
MakeButtonAt( text, width, height, font, Anchor.Centre, verAnchor, x, y, onClick );
}
protected void MakeButtonAt( string text, int width, int height, Font font, Anchor horAnchor,
Anchor verAnchor, int x, int y, Action<int, int> onClick ) {
WidgetConstructors.MakeButtonAt( game, widgets, ref widgetIndex, WidgetConstructors.MakeButtonAt( game, widgets, ref widgetIndex,
text, width, height, font, horAnchor, text, width, height, font, Anchor.Centre,
verAnchor, x, y, onClick ); verAnchor, x, y, onClick );
} }

View File

@ -9,7 +9,7 @@ namespace Launcher {
public sealed class ResourcesScreen : LauncherScreen { public sealed class ResourcesScreen : LauncherScreen {
Font infoFont, statusFont; Font infoFont;
ResourcesView view; ResourcesView view;
public ResourcesScreen( LauncherWindow game ) : base( game ) { public ResourcesScreen( LauncherWindow game ) : base( game ) {
game.Window.Mouse.Move += MouseMove; game.Window.Mouse.Move += MouseMove;
@ -17,7 +17,6 @@ namespace Launcher {
textFont = new Font( game.FontName, 16, FontStyle.Bold ); textFont = new Font( game.FontName, 16, FontStyle.Bold );
infoFont = new Font( game.FontName, 14, FontStyle.Regular ); infoFont = new Font( game.FontName, 14, FontStyle.Regular );
statusFont = new Font( game.FontName, 13, FontStyle.Italic );
view = new ResourcesView( game ); view = new ResourcesView( game );
widgets = view.widgets; widgets = view.widgets;
} }
@ -75,22 +74,13 @@ namespace Launcher {
ResourceFetcher fetcher; ResourceFetcher fetcher;
Font textFont; Font textFont;
static FastColour backCol = new FastColour( 120, 85, 151 );
static readonly string mainText = "Some required resources weren't found" + static readonly string mainText = "Some required resources weren't found" +
Environment.NewLine + "Okay to download them?"; 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() { void MakeWidgets() {
widgetIndex = 0; widgetIndex = 0;
if( useStatus ) { view.UpdateStatus();
MakeLabelAt( widgets[0].Text, statusFont, Anchor.Centre, Anchor.Centre, 0, -10 ); widgetIndex = 1;
} 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. // Clear the entire previous widgets state.
for( int i = 1; i < widgets.Length; i++ ) { for( int i = 1; i < widgets.Length; i++ ) {
@ -136,24 +126,17 @@ namespace Launcher {
} }
void SetStatus( string text ) { void SetStatus( string text ) {
useStatus = true; view.useStatus = true;
LauncherLabelWidget widget = (LauncherLabelWidget)widgets[0]; view.RedrawStatus( text );
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, -10 );
widget.Redraw( drawer );
Dirty = true; Dirty = true;
} }
}
public override void Dispose() { public override void Dispose() {
game.Window.Mouse.Move -= MouseMove; game.Window.Mouse.Move -= MouseMove;
game.Window.Mouse.ButtonDown -= MouseButtonDown; game.Window.Mouse.ButtonDown -= MouseButtonDown;
view.Dispose();
textFont.Dispose(); textFont.Dispose();
infoFont.Dispose(); infoFont.Dispose();
statusFont.Dispose();
} }
} }
} }

View File

@ -1,16 +1,19 @@
// ClassicalSharp copyright 2014-2016 UnknownShadow200 | Licensed under MIT // ClassicalSharp copyright 2014-2016 UnknownShadow200 | Licensed under MIT
using System; using System;
using System.Drawing;
using ClassicalSharp; using ClassicalSharp;
namespace Launcher { namespace Launcher {
public sealed class ResourcesView : IView { public sealed class ResourcesView : IView {
Font statusFont;
public ResourcesView( LauncherWindow game ) : base( game ) { public ResourcesView( LauncherWindow game ) : base( game ) {
widgets = new LauncherWidget[4]; widgets = new LauncherWidget[4];
} }
public override void Init() { public override void Init() {
statusFont = new Font( game.FontName, 13, FontStyle.Italic );
// TODO: figure out how to fix this. // TODO: figure out how to fix this.
} }
@ -28,6 +31,31 @@ namespace Launcher {
} }
} }
internal int lastProgress = int.MinValue;
static readonly string format = "&eDownload size: {0} megabytes";
internal bool useStatus;
internal void UpdateStatus() {
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 );
}
}
internal void RedrawStatus( string text ) {
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, -10 );
widget.Redraw( drawer );
}
}
internal void DrawProgressBox( int progress ) { internal void DrawProgressBox( int progress ) {
progress = (200 * progress) / 100; progress = (200 * progress) / 100;
using( drawer ) { using( drawer ) {
@ -37,7 +65,11 @@ namespace Launcher {
} }
} }
internal int lastProgress = int.MinValue; public override void Dispose() {
base.Dispose();
statusFont.Dispose();
}
static FastColour backCol = new FastColour( 120, 85, 151 ); static FastColour backCol = new FastColour( 120, 85, 151 );
static FastColour clearCol = new FastColour( 12, 12, 12 ); static FastColour clearCol = new FastColour( 12, 12, 12 );
static FastColour progBack = new FastColour( 220, 220, 220 ); static FastColour progBack = new FastColour( 220, 220, 220 );