From 266f691d06934e316c7d267a9477e5ef67f4c5ce Mon Sep 17 00:00:00 2001 From: UnknownShadow200 Date: Mon, 9 May 2016 20:25:36 +1000 Subject: [PATCH] Some code cleanup in the launcher. --- Launcher2/Gui/Screens/ColoursScreen.cs | 5 ---- Launcher2/Gui/Screens/LauncherScreen.cs | 38 ++---------------------- Launcher2/Gui/Screens/ResourcesScreen.cs | 35 ++++++---------------- Launcher2/Gui/Views/ResourcesView.cs | 34 ++++++++++++++++++++- 4 files changed, 45 insertions(+), 67 deletions(-) diff --git a/Launcher2/Gui/Screens/ColoursScreen.cs b/Launcher2/Gui/Screens/ColoursScreen.cs index 90fd75792..689d56050 100644 --- a/Launcher2/Gui/Screens/ColoursScreen.cs +++ b/Launcher2/Gui/Screens/ColoursScreen.cs @@ -76,11 +76,6 @@ namespace Launcher { void ResetColours() { LauncherSkin.ResetToDefault(); view.MakeAllRGBTriplets( true ); - - using( drawer ) { - drawer.SetBitmap( game.Framebuffer ); - RedrawAll(); - } game.MakeBackground(); Resize(); } diff --git a/Launcher2/Gui/Screens/LauncherScreen.cs b/Launcher2/Gui/Screens/LauncherScreen.cs index 214ee69fc..c889e4318 100644 --- a/Launcher2/Gui/Screens/LauncherScreen.cs +++ b/Launcher2/Gui/Screens/LauncherScreen.cs @@ -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 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 onClick ) { WidgetConstructors.MakeButtonAt( game, widgets, ref widgetIndex, - text, width, height, font, horAnchor, + text, width, height, font, Anchor.Centre, verAnchor, x, y, onClick ); } diff --git a/Launcher2/Gui/Screens/ResourcesScreen.cs b/Launcher2/Gui/Screens/ResourcesScreen.cs index d66496212..93da3a3b0 100644 --- a/Launcher2/Gui/Screens/ResourcesScreen.cs +++ b/Launcher2/Gui/Screens/ResourcesScreen.cs @@ -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(); } } } diff --git a/Launcher2/Gui/Views/ResourcesView.cs b/Launcher2/Gui/Views/ResourcesView.cs index 05131cb56..1cfe23222 100644 --- a/Launcher2/Gui/Views/ResourcesView.cs +++ b/Launcher2/Gui/Views/ResourcesView.cs @@ -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 );