diff --git a/Launcher2/Gui/Screens/ColoursScreen.cs b/Launcher2/Gui/Screens/ColoursScreen.cs new file mode 100644 index 000000000..482925b2c --- /dev/null +++ b/Launcher2/Gui/Screens/ColoursScreen.cs @@ -0,0 +1,98 @@ +using System; +using System.Drawing; +using ClassicalSharp; + +namespace Launcher2 { + + public sealed class ColoursScreen : LauncherInputScreen { + + public ColoursScreen( LauncherWindow game ) : base( game ) { + titleFont = new Font( "Arial", 15, FontStyle.Bold ); + inputFont = new Font( "Arial", 14, FontStyle.Regular ); + enterIndex = 6; + widgets = new LauncherWidget[12]; + } + + public override void Init() { + base.Init(); + Resize(); + } + + public override void Tick() { + } + + public override void Resize() { + using( drawer ) { + drawer.SetBitmap( game.Framebuffer ); + Draw(); + } + Dirty = true; + } + + string GetCol( FastColour defCol ) { + LauncherWidget widget = widgets[widgetIndex]; + return widget == null ? defCol.ToRGBHexString() : widget.Text; + } + + void Draw() { + widgetIndex = 0; + MakeLabelAt( "Background", titleFont, Anchor.Centre, Anchor.Centre, -70, -150 ); + MakeInput( GetCol( LauncherSkin.BackgroundCol ), 90, Anchor.Centre, false, 45, -150, 6 ); + + MakeLabelAt( "Button border", titleFont, Anchor.Centre, Anchor.Centre, -80, -110 ); + MakeInput( GetCol( LauncherSkin.ButtonBorderCol ), 90, Anchor.Centre, false, 45, -110, 6 ); + + MakeLabelAt( "Button highlight", titleFont, Anchor.Centre, Anchor.Centre, -90, -70 ); + MakeInput( GetCol( LauncherSkin.ButtonHighlightCol ), 90, Anchor.Centre, false, 45, -70, 6 ); + + MakeLabelAt( "Button foreground", titleFont, Anchor.Centre, Anchor.Centre, -100, -30 ); + MakeInput( GetCol( LauncherSkin.ButtonForeCol ), 90, Anchor.Centre, false, 45, -30, 6 ); + + MakeLabelAt( "Active button foreground", titleFont, Anchor.Centre, Anchor.Centre, -130, 10 ); + MakeInput( GetCol( LauncherSkin.ButtonForeActiveCol ), 90, Anchor.Centre, false, 45, 10, 6 ); + + MakeButtonAt( "Default colours", 160, 35, titleFont, Anchor.Centre, + 0, 70, (x, y) => ResetColours() ); + MakeButtonAt( "Back", 80, 35, titleFont, Anchor.Centre, + 0, 120, (x, y) => game.SetScreen( new MainScreen( game ) ) ); + for( int i = 0; i < widgets.Length; i++ ) { + LauncherInputWidget input = widgets[i] as LauncherInputWidget; + if( input != null ) input.TextChanged = TextChanged; + } + } + + void ResetColours() { + LauncherSkin.ResetToDefault(); + widgets[1].Text = LauncherSkin.BackgroundCol.ToRGBHexString(); + widgets[3].Text = LauncherSkin.ButtonBorderCol.ToRGBHexString(); + widgets[5].Text = LauncherSkin.ButtonHighlightCol.ToRGBHexString(); + widgets[7].Text = LauncherSkin.ButtonForeCol.ToRGBHexString(); + widgets[9].Text = LauncherSkin.ButtonForeActiveCol.ToRGBHexString(); + + game.MakeBackground(); + Resize(); + } + + void TextChanged( LauncherInputWidget widget ) { + bool changed = false; + if( widget == widgets[1] ) changed |= Parse( widget, ref LauncherSkin.BackgroundCol ); + else if( widget == widgets[3] ) changed |= Parse( widget, ref LauncherSkin.ButtonBorderCol ); + else if( widget == widgets[5] ) changed |= Parse( widget, ref LauncherSkin.ButtonHighlightCol ); + else if( widget == widgets[7] ) changed |= Parse( widget, ref LauncherSkin.ButtonForeCol ); + else if( widget == widgets[9] ) changed |= Parse( widget, ref LauncherSkin.ButtonForeActiveCol ); + + if( changed ) { + game.MakeBackground(); + Resize(); + } + } + + bool Parse( LauncherInputWidget widget, ref FastColour dst ) { + FastColour col; + if( !FastColour.TryParse( widget.Text, out col ) ) + return false; + dst = col; + return true; + } + } +} diff --git a/Launcher2/Gui/Screens/MainScreen.cs b/Launcher2/Gui/Screens/MainScreen.cs index 89044f808..bc7967e20 100644 --- a/Launcher2/Gui/Screens/MainScreen.cs +++ b/Launcher2/Gui/Screens/MainScreen.cs @@ -12,7 +12,7 @@ namespace Launcher2 { buttonFont = new Font( "Arial", 16, FontStyle.Bold ); inputFont = new Font( "Arial", 15, FontStyle.Regular ); enterIndex = 4; - widgets = new LauncherWidget[10]; + widgets = new LauncherWidget[11]; } public override void Resize() { @@ -35,6 +35,10 @@ namespace Launcher2 { Anchor.Centre, Anchor.Centre, 0, 100, (x, y) => Client.Start( "", ref game.ShouldExit ) ); + MakeButtonAt( "Colour scheme", buttonWidth - 40, buttonHeight, buttonFont, + Anchor.LeftOrTop, Anchor.BottomOrRight, 10, -10, + (x, y) => game.SetScreen( new ColoursScreen( game ) ) ); + MakeButtonAt( "Update check", buttonWidth - 40, buttonHeight, buttonFont, Anchor.BottomOrRight, Anchor.BottomOrRight, -10, -10, (x, y) => game.SetScreen( new UpdatesScreen( game ) ) ); diff --git a/Launcher2/Gui/Widgets/LauncherButtonWidget.cs b/Launcher2/Gui/Widgets/LauncherButtonWidget.cs index 0ff778207..5e40b97ce 100644 --- a/Launcher2/Gui/Widgets/LauncherButtonWidget.cs +++ b/Launcher2/Gui/Widgets/LauncherButtonWidget.cs @@ -27,7 +27,7 @@ namespace Launcher2 { Size size = drawer.MeasureSize( ref args ); int xOffset = Width - size.Width, yOffset = Height - size.Height; - FastColour backCol = LauncherSkin.ButtonBackCol; + FastColour backCol = LauncherSkin.ButtonBorderCol; drawer.Clear( backCol, X + 1, Y, Width - 2, border ); drawer.Clear( backCol, X + 1, Y + Height - border, Width - 2, border ); drawer.Clear( backCol, X, Y + 1, border, Height - 2 ); diff --git a/Launcher2/Gui/Widgets/LauncherInputWidget.cs b/Launcher2/Gui/Widgets/LauncherInputWidget.cs index bd5febc14..59a58d556 100644 --- a/Launcher2/Gui/Widgets/LauncherInputWidget.cs +++ b/Launcher2/Gui/Widgets/LauncherInputWidget.cs @@ -22,6 +22,9 @@ namespace Launcher2 { /// Filter applied to text received from the clipboard. Can be null. public Func ClipboardFilter; + /// Delegate invoked when the text changes. + public Action TextChanged; + public LauncherInputWidget( LauncherWindow window ) : base( window ) { } @@ -55,8 +58,9 @@ namespace Launcher2 { public bool AppendChar( char c ) { if( c >= ' ' && c <= '~' && Text.Length < MaxTextLength ) { Text += c; + if( TextChanged != null ) TextChanged( this ); return true; - } + } return false; } @@ -66,6 +70,7 @@ namespace Launcher2 { if( Text.Length == 0 ) return false; Text = Text.Substring( 0, Text.Length - 1 ); + if( TextChanged != null ) TextChanged( this ); return true; } @@ -75,6 +80,7 @@ namespace Launcher2 { if( Text.Length == 0 ) return false; Text = ""; + if( TextChanged != null ) TextChanged( this ); return true; } @@ -96,6 +102,7 @@ namespace Launcher2 { text = text.Substring( 0, MaxTextLength - Text.Length ); } Text += text; + if( TextChanged != null ) TextChanged( this ); return true; } } diff --git a/Launcher2/Launcher2.csproj b/Launcher2/Launcher2.csproj index dfca74d8e..5bd5daedb 100644 --- a/Launcher2/Launcher2.csproj +++ b/Launcher2/Launcher2.csproj @@ -59,6 +59,7 @@ + diff --git a/Launcher2/LauncherWindow.Background.cs b/Launcher2/LauncherWindow.Background.cs index f1b9a8b78..120394463 100644 --- a/Launcher2/LauncherWindow.Background.cs +++ b/Launcher2/LauncherWindow.Background.cs @@ -36,10 +36,11 @@ namespace Launcher2 { } public void MakeBackground() { - if( Framebuffer != null ) - Framebuffer.Dispose(); - - Framebuffer = new Bitmap( Width, Height ); + if( Framebuffer == null || (Framebuffer.Width != Width || Framebuffer.Height != Height) ) { + if( Framebuffer != null ) + Framebuffer.Dispose(); + Framebuffer = new Bitmap( Width, Height ); + } using( IDrawer2D drawer = Drawer ) { drawer.SetBitmap( Framebuffer ); ClearArea( 0, 0, Width, Height ); diff --git a/Launcher2/Utils/LauncherSkin.cs b/Launcher2/Utils/LauncherSkin.cs index 60019be31..139d5286c 100644 --- a/Launcher2/Utils/LauncherSkin.cs +++ b/Launcher2/Utils/LauncherSkin.cs @@ -6,17 +6,25 @@ namespace Launcher2 { public static class LauncherSkin { - public static FastColour BackgroundCol = new FastColour( 127, 107, 140 ); + public static FastColour BackgroundCol = new FastColour( 127, 107, 140 ); //new FastColour( 104, 87, 119 ); - public static FastColour ButtonBackCol = new FastColour( 97, 81, 110 ); + public static FastColour ButtonBorderCol = new FastColour( 97, 81, 110 ); public static FastColour ButtonForeActiveCol = new FastColour( 189, 168, 206 ); public static FastColour ButtonForeCol = new FastColour( 164, 138, 186 ); public static FastColour ButtonHighlightCol = new FastColour( 182, 158, 201 ); + public static void ResetToDefault() { + BackgroundCol = new FastColour( 127, 107, 140 ); + ButtonBorderCol = new FastColour( 97, 81, 110 ); + ButtonForeActiveCol = new FastColour( 189, 168, 206 ); + ButtonForeCol = new FastColour( 164, 138, 186 ); + ButtonHighlightCol = new FastColour( 182, 158, 201 ); + } + public static void LoadFromOptions() { Get( "launcher-backcol", ref BackgroundCol ); - Get( "launcher-button-backcol", ref ButtonBackCol ); + Get( "launcher-button-backcol", ref ButtonBorderCol ); Get( "launcher-button-foreactivecol", ref ButtonForeActiveCol ); Get( "launcher-button-forecol", ref ButtonForeCol ); Get( "launcher-button-highlightcol", ref ButtonHighlightCol ); @@ -24,7 +32,7 @@ namespace Launcher2 { public static void SaveToOptions() { Options.Set( "launcher-backcol", BackgroundCol.ToRGBHexString() ); - Options.Set( "launcher-button-backcol", ButtonBackCol.ToRGBHexString() ); + Options.Set( "launcher-button-backcol", ButtonBorderCol.ToRGBHexString() ); Options.Set( "launcher-button-foreactivecol", ButtonForeActiveCol.ToRGBHexString() ); Options.Set( "launcher-button-forecol", ButtonForeCol.ToRGBHexString() ); Options.Set( "launcher-button-highlightcol", ButtonHighlightCol.ToRGBHexString() );