Launcher: Allow darkening inactive label widgets.

This commit is contained in:
UnknownShadow200 2016-09-26 18:24:22 +10:00
parent 25a376dee4
commit 6fe3d9650e
6 changed files with 42 additions and 27 deletions

View file

@ -67,24 +67,31 @@ namespace Launcher.Gui.Screens {
/// <summary> Called when the user has moved their mouse away from a previously selected widget. </summary>
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 );
}
/// <summary> Called when user has moved their mouse over a given widget. </summary>
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 );
}
}
/// <summary>Redraws the given widget and marks the window as needing to be redrawn. </summary>
protected void RedrawWidget( LauncherWidget widget ) {
using( drawer ) {
drawer.SetBitmap( game.Framebuffer );

View file

@ -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;

View file

@ -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 )

View file

@ -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;

View file

@ -8,6 +8,9 @@ namespace Launcher.Gui.Widgets {
/// <summary> Represents text that cannot be modified by the user. </summary>
public sealed class LauncherLabelWidget : LauncherWidget {
/// <summary> Whether text should be drawn in a darker manner when this widget is not active. </summary>
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 );
}
}

View file

@ -28,6 +28,9 @@ namespace Launcher.Gui.Widgets {
/// <summary> Whether this widget should be rendered and interactable with. </summary>
public bool Visible = true;
/// <summary> Whether this widget is the active widget selected by the user. </summary>
public bool Active = false;
public Action<int, int> OnClick;
public LauncherWidget( LauncherWindow window ) {