Allow changing colour scheme through launcher gui.

This commit is contained in:
UnknownShadow200 2015-12-29 00:02:29 +11:00
parent 140ed90269
commit 2adff37838
7 changed files with 130 additions and 11 deletions

View File

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

View File

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

View File

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

View File

@ -22,6 +22,9 @@ namespace Launcher2 {
/// <summary> Filter applied to text received from the clipboard. Can be null. </summary>
public Func<string, string> ClipboardFilter;
/// <summary> Delegate invoked when the text changes. </summary>
public Action<LauncherInputWidget> 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;
}
}

View File

@ -59,6 +59,7 @@
<Compile Include="Gui\Drawer2DExt.cs" />
<Compile Include="Gui\PlatformDrawer.cs" />
<Compile Include="Gui\Screens\ClassiCubeServersScreen.cs" />
<Compile Include="Gui\Screens\ColoursScreen.cs" />
<Compile Include="Gui\Screens\DirectConnectScreen.cs" />
<Compile Include="Gui\Screens\LauncherInputScreen.cs" />
<Compile Include="Gui\Screens\LauncherScreen.cs" />

View File

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

View File

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