From 6fe3d9650e8c0095c9a7718d75942a2504b380dc Mon Sep 17 00:00:00 2001 From: UnknownShadow200 Date: Mon, 26 Sep 2016 18:24:22 +1000 Subject: [PATCH] Launcher: Allow darkening inactive label widgets. --- Launcher2/Gui/Screens/LauncherScreen.cs | 23 ++++++++++----- Launcher2/Gui/Screens/ResourcesScreen.cs | 29 ++++++++----------- Launcher2/Gui/Views/ColoursView.cs | 4 +++ Launcher2/Gui/Widgets/LauncherButtonWidget.cs | 1 - Launcher2/Gui/Widgets/LauncherLabelWidget.cs | 9 +++++- Launcher2/Gui/Widgets/LauncherWidget.cs | 3 ++ 6 files changed, 42 insertions(+), 27 deletions(-) diff --git a/Launcher2/Gui/Screens/LauncherScreen.cs b/Launcher2/Gui/Screens/LauncherScreen.cs index c3895fc54..608e2edf6 100644 --- a/Launcher2/Gui/Screens/LauncherScreen.cs +++ b/Launcher2/Gui/Screens/LauncherScreen.cs @@ -67,24 +67,31 @@ namespace Launcher.Gui.Screens { /// Called when the user has moved their mouse away from a previously selected widget. protected virtual void UnselectWidget( LauncherWidget widget ) { - LauncherButtonWidget button = widget as LauncherButtonWidget; - if( button != null ) { - button.Active = false; - button.RedrawBackground(); - RedrawWidget( button ); - } + if( widget != null ) widget.Active = false; + ChangedActiveState( widget ); } /// Called when user has moved their mouse over a given widget. protected virtual void SelectWidget( LauncherWidget widget ) { + if( widget != null ) widget.Active = true; + ChangedActiveState( widget ); + } + + void ChangedActiveState( LauncherWidget widget ) { LauncherButtonWidget button = widget as LauncherButtonWidget; - if( button != null ) { - button.Active = true; + if( button != null ) { button.RedrawBackground(); RedrawWidget( button ); } + + LauncherLabelWidget label = widget as LauncherLabelWidget; + if( label != null && label.DarkenWhenInactive ) { + game.ResetArea( label.X, label.Y, label.Width, label.Height ); + RedrawWidget( label ); + } } + /// Redraws the given widget and marks the window as needing to be redrawn. protected void RedrawWidget( LauncherWidget widget ) { using( drawer ) { drawer.SetBitmap( game.Framebuffer ); diff --git a/Launcher2/Gui/Screens/ResourcesScreen.cs b/Launcher2/Gui/Screens/ResourcesScreen.cs index 39f741bc4..c6a6abb15 100644 --- a/Launcher2/Gui/Screens/ResourcesScreen.cs +++ b/Launcher2/Gui/Screens/ResourcesScreen.cs @@ -1,11 +1,8 @@ // ClassicalSharp copyright 2014-2016 UnknownShadow200 | Licensed under MIT using System; -using System.Drawing; using System.IO; -using ClassicalSharp; using ClassicalSharp.Network; using Launcher.Gui.Views; -using Launcher.Gui.Widgets; using Launcher.Patcher; namespace Launcher.Gui.Screens { @@ -26,11 +23,11 @@ namespace Launcher.Gui.Screens { SetWidgetHandlers(); Resize(); } - + void SetWidgetHandlers() { widgets[view.yesIndex].OnClick = DownloadResources; widgets[view.noIndex].OnClick = (x, y) => GotoNextMenu(); - widgets[view.cancelIndex].OnClick = (x, y) => GotoNextMenu(); + widgets[view.cancelIndex].OnClick = (x, y) => GotoNextMenu(); } bool failed; @@ -41,16 +38,16 @@ namespace Launcher.Gui.Screens { if( !fetcher.Check( SetStatus ) ) failed = true; - if( fetcher.Done ) { - if( ResourceList.Files.Count > 0 ) { - ResourcePatcher patcher = new ResourcePatcher( fetcher ); - patcher.Run(); - } - fetcher = null; - GC.Collect(); - game.TryLoadTexturePack(); - GotoNextMenu(); + if( !fetcher.Done ) return; + if( ResourceList.Files.Count > 0 ) { + ResourcePatcher patcher = new ResourcePatcher( fetcher ); + patcher.Run(); } + + fetcher = null; + GC.Collect(); + game.TryLoadTexturePack(); + GotoNextMenu(); } public override void Resize() { @@ -60,9 +57,7 @@ namespace Launcher.Gui.Screens { void CheckCurrentProgress() { Request item = fetcher.downloader.CurrentItem; - if( item == null ) { - view.lastProgress = int.MinValue; return; - } + if( item == null ) { view.lastProgress = int.MinValue; return; } int progress = fetcher.downloader.CurrentItemProgress; if( progress == view.lastProgress ) return; diff --git a/Launcher2/Gui/Views/ColoursView.cs b/Launcher2/Gui/Views/ColoursView.cs index 013aea6cb..feb7600f2 100644 --- a/Launcher2/Gui/Views/ColoursView.cs +++ b/Launcher2/Gui/Views/ColoursView.cs @@ -25,6 +25,7 @@ namespace Launcher.Gui.Views { protected override void MakeWidgets() { widgetIndex = 0; MakeAllRGBTriplets( false ); + int start = widgetIndex; Makers.Label( this, "Background", textFont ) .SetLocation( Anchor.Centre, Anchor.Centre, -60, -100 ); Makers.Label( this, "Button border", textFont ) @@ -36,6 +37,9 @@ namespace Launcher.Gui.Views { Makers.Label( this, "Active button", textFont ) .SetLocation( Anchor.Centre, Anchor.Centre, -70, 60 ); + //for( int i = start; i < widgetIndex; i++ ) + // ((LauncherLabelWidget)widgets[i]).DarkenWhenInactive = true; + Makers.Label( this, "Red", titleFont ) .SetLocation( Anchor.Centre, Anchor.Centre, 30, -130 ); Makers.Label( this, "Green", titleFont ) diff --git a/Launcher2/Gui/Widgets/LauncherButtonWidget.cs b/Launcher2/Gui/Widgets/LauncherButtonWidget.cs index 2bcc03e16..cb447e75c 100644 --- a/Launcher2/Gui/Widgets/LauncherButtonWidget.cs +++ b/Launcher2/Gui/Widgets/LauncherButtonWidget.cs @@ -8,7 +8,6 @@ namespace Launcher.Gui.Widgets { public sealed class LauncherButtonWidget : LauncherWidget { public bool Shadow = true; - public bool Active = false; const int border = 1; Size textSize; Font font; diff --git a/Launcher2/Gui/Widgets/LauncherLabelWidget.cs b/Launcher2/Gui/Widgets/LauncherLabelWidget.cs index 4136b51a7..2f81d8460 100644 --- a/Launcher2/Gui/Widgets/LauncherLabelWidget.cs +++ b/Launcher2/Gui/Widgets/LauncherLabelWidget.cs @@ -8,6 +8,9 @@ namespace Launcher.Gui.Widgets { /// Represents text that cannot be modified by the user. public sealed class LauncherLabelWidget : LauncherWidget { + /// Whether text should be drawn in a darker manner when this widget is not active. + public bool DarkenWhenInactive; + Font font; public LauncherLabelWidget( LauncherWindow window, Font font ) : base( window ) { this.font = font; @@ -24,7 +27,11 @@ namespace Launcher.Gui.Widgets { public override void Redraw( IDrawer2D drawer ) { if( Window.Minimised || !Visible ) return; - DrawTextArgs args = new DrawTextArgs( Text, font, true ); + string text = Text; + if( DarkenWhenInactive && !Active ) + text = "&7" + text; + + DrawTextArgs args = new DrawTextArgs( text, font, true ); drawer.DrawText( ref args, X, Y ); } } diff --git a/Launcher2/Gui/Widgets/LauncherWidget.cs b/Launcher2/Gui/Widgets/LauncherWidget.cs index 0b861e3ac..d79096793 100644 --- a/Launcher2/Gui/Widgets/LauncherWidget.cs +++ b/Launcher2/Gui/Widgets/LauncherWidget.cs @@ -28,6 +28,9 @@ namespace Launcher.Gui.Widgets { /// Whether this widget should be rendered and interactable with. public bool Visible = true; + /// Whether this widget is the active widget selected by the user. + public bool Active = false; + public Action OnClick; public LauncherWidget( LauncherWindow window ) {