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() {
LauncherSkin.ResetToDefault();
view.MakeAllRGBTriplets( true );
using( drawer ) {
drawer.SetBitmap( game.Framebuffer );
RedrawAll();
}
game.MakeBackground();
Resize();
}

View File

@ -39,11 +39,9 @@ namespace Launcher {
protected LauncherWidget selectedWidget;
protected LauncherWidget[] widgets;
protected virtual void MouseMove( object sender, MouseMoveEventArgs e ) {
if( supressMove ) {
supressMove = false;
return;
}
if( supressMove ) { supressMove = false; return; }
mouseMoved = true;
for( int i = 0; i < widgets.Length; i++ ) {
LauncherWidget widget = widgets[i];
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 void MouseButtonDown( object sender, MouseButtonEventArgs e ) {
if( e.Button != MouseButton.Left ) return;
@ -175,13 +148,8 @@ namespace Launcher {
protected void MakeButtonAt( string text, int width, int height, Font font,
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,
text, width, height, font, horAnchor,
text, width, height, font, Anchor.Centre,
verAnchor, x, y, onClick );
}

View File

@ -9,7 +9,7 @@ namespace Launcher {
public sealed class ResourcesScreen : LauncherScreen {
Font infoFont, statusFont;
Font infoFont;
ResourcesView view;
public ResourcesScreen( LauncherWindow game ) : base( game ) {
game.Window.Mouse.Move += MouseMove;
@ -17,7 +17,6 @@ namespace Launcher {
textFont = new Font( game.FontName, 16, FontStyle.Bold );
infoFont = new Font( game.FontName, 14, FontStyle.Regular );
statusFont = new Font( game.FontName, 13, FontStyle.Italic );
view = new ResourcesView( game );
widgets = view.widgets;
}
@ -75,22 +74,13 @@ namespace Launcher {
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;
Environment.NewLine + "Okay to download them?";
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 );
}
view.UpdateStatus();
widgetIndex = 1;
// Clear the entire previous widgets state.
for( int i = 1; i < widgets.Length; i++ ) {
@ -136,24 +126,17 @@ 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, -10 );
widget.Redraw( drawer );
Dirty = true;
}
view.useStatus = true;
view.RedrawStatus( text );
Dirty = true;
}
public override void Dispose() {
game.Window.Mouse.Move -= MouseMove;
game.Window.Mouse.ButtonDown -= MouseButtonDown;
view.Dispose();
textFont.Dispose();
infoFont.Dispose();
statusFont.Dispose();
}
}
}

View File

@ -1,16 +1,19 @@
// ClassicalSharp copyright 2014-2016 UnknownShadow200 | Licensed under MIT
using System;
using System.Drawing;
using ClassicalSharp;
namespace Launcher {
public sealed class ResourcesView : IView {
Font statusFont;
public ResourcesView( LauncherWindow game ) : base( game ) {
widgets = new LauncherWidget[4];
}
public override void Init() {
statusFont = new Font( game.FontName, 13, FontStyle.Italic );
// TODO: figure out how to fix this.
}
@ -27,6 +30,31 @@ namespace Launcher {
RedrawAll();
}
}
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 ) {
progress = (200 * progress) / 100;
@ -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 clearCol = new FastColour( 12, 12, 12 );
static FastColour progBack = new FastColour( 220, 220, 220 );