mirror of
https://github.com/ClassiCube/ClassiCube.git
synced 2025-09-17 03:25:14 -04:00
Separate DirectConnectScreen into DirectConnectScreen and DirectConnectView.
This commit is contained in:
parent
d22b9a4527
commit
cc57a1960a
@ -11,51 +11,38 @@ namespace Launcher {
|
||||
public sealed class DirectConnectScreen : LauncherInputScreen {
|
||||
|
||||
Font booleanFont;
|
||||
const int skinsIndex = 7;
|
||||
DirectConnectView view;
|
||||
public DirectConnectScreen( LauncherWindow game ) : base( game, true ) {
|
||||
booleanFont = new Font( game.FontName, 22, FontStyle.Regular );
|
||||
enterIndex = 3;
|
||||
widgets = new LauncherWidget[8];
|
||||
view = new DirectConnectView( game );
|
||||
widgets = view.widgets;
|
||||
}
|
||||
|
||||
public override void Init() {
|
||||
base.Init();
|
||||
MakeWidgets();
|
||||
RedrawAllButtonBackgrounds();
|
||||
|
||||
using( drawer ) {
|
||||
drawer.SetBitmap( game.Framebuffer );
|
||||
RedrawAll();
|
||||
LoadSavedInfo();
|
||||
}
|
||||
Dirty = true;
|
||||
view.Init();
|
||||
SetWidgetHandlers();
|
||||
Resize();
|
||||
}
|
||||
|
||||
public override void Resize() {
|
||||
MakeWidgets();
|
||||
RedrawAllButtonBackgrounds();
|
||||
|
||||
using( drawer ) {
|
||||
drawer.SetBitmap( game.Framebuffer );
|
||||
RedrawAll();
|
||||
}
|
||||
view.DrawAll();
|
||||
Dirty = true;
|
||||
}
|
||||
|
||||
void MakeWidgets() {
|
||||
widgetIndex = 0;
|
||||
void SetWidgetHandlers() {
|
||||
widgets[view.backIndex].OnClick =
|
||||
(x, y) => game.SetScreen( new MainScreen( game ) );
|
||||
widgets[view.connectIndex].OnClick = StartClient;
|
||||
widgets[view.ccSkinsIndex].OnClick = UseClassicubeSkinsClick;
|
||||
|
||||
MakeInput( Get(), 330, Anchor.Centre, false, 0, -100, 32, "&7Username.." );
|
||||
MakeInput( Get(), 330, Anchor.Centre, false, 0, -50, 64, "&7IP address:Port number.." );
|
||||
MakeInput( Get(), 330, Anchor.Centre, false, 0, 0, 32, "&7Mppass.." );
|
||||
|
||||
MakeButtonAt( "Connect", 110, 35, titleFont, Anchor.Centre, -110, 50, StartClient );
|
||||
MakeButtonAt( "Back", 80, 35, titleFont, Anchor.Centre,
|
||||
125, 50, (x, y) => game.SetScreen( new MainScreen( game ) ) );
|
||||
MakeLabelAt( "", titleFont, Anchor.Centre, Anchor.Centre, 0, 100 );
|
||||
MakeLabelAt( "Use classicube.net for skins", inputFont, Anchor.Centre, Anchor.Centre, 30, 130 );
|
||||
MakeBooleanAt( Anchor.Centre, Anchor.Centre, booleanFont, true,
|
||||
30, 30, -110, 130, UseClassicubeSkinsClick );
|
||||
for( int i = 0; i < widgets.Length; i++ ) {
|
||||
if( widgets[i] == null || !(widgets[i] is LauncherInputWidget) )
|
||||
continue;
|
||||
widgets[i].OnClick = InputClick;
|
||||
}
|
||||
LoadSavedInfo();
|
||||
}
|
||||
|
||||
void SetStatus( string text ) {
|
||||
@ -73,18 +60,13 @@ namespace Launcher {
|
||||
void UseClassicubeSkinsClick( int mouseX, int mouseY ) {
|
||||
using( drawer ) {
|
||||
game.Drawer.SetBitmap( game.Framebuffer );
|
||||
LauncherBooleanWidget widget = (LauncherBooleanWidget)widgets[skinsIndex];
|
||||
SetBool( !widget.Value );
|
||||
LauncherBoolWidget widget = (LauncherBoolWidget)widgets[view.ccSkinsIndex];
|
||||
widget.Value = !widget.Value;
|
||||
widget.Redraw( drawer );
|
||||
Dirty = true;
|
||||
}
|
||||
}
|
||||
|
||||
void SetBool( bool value ) {
|
||||
LauncherBooleanWidget widget = (LauncherBooleanWidget)widgets[skinsIndex];
|
||||
widget.Value = value;
|
||||
widget.Redraw( game.Drawer );
|
||||
Dirty = true;
|
||||
}
|
||||
|
||||
public override void Dispose() {
|
||||
StoreFields();
|
||||
base.Dispose();
|
||||
@ -95,9 +77,9 @@ namespace Launcher {
|
||||
Dictionary<string, object> metadata;
|
||||
// restore what user last typed into the various fields
|
||||
if( game.ScreenMetadata.TryGetValue( "screen-DC", out metadata ) ) {
|
||||
Set( 0, (string)metadata["user"] );
|
||||
Set( 1, (string)metadata["address"] );
|
||||
Set( 2, (string)metadata["mppass"] );
|
||||
SetText( 0, (string)metadata["user"] );
|
||||
SetText( 1, (string)metadata["address"] );
|
||||
SetText( 2, (string)metadata["mppass"] );
|
||||
SetBool( (bool)metadata["skins"] );
|
||||
} else {
|
||||
LoadFromOptions();
|
||||
@ -114,12 +96,11 @@ namespace Launcher {
|
||||
metadata["user"] = Get( 0 );
|
||||
metadata["address"] = Get( 1 );
|
||||
metadata["mppass"] = Get( 2 );
|
||||
metadata["skins"] = ((LauncherBooleanWidget)widgets[skinsIndex]).Value;
|
||||
metadata["skins"] = ((LauncherBoolWidget)widgets[view.ccSkinsIndex]).Value;
|
||||
}
|
||||
|
||||
void LoadFromOptions() {
|
||||
if( !Options.Load() )
|
||||
return;
|
||||
if( !Options.Load() ) return;
|
||||
|
||||
string user = Options.Get( "launcher-dc-username" ) ?? "";
|
||||
string ip = Options.Get( "launcher-dc-ip" ) ?? "127.0.0.1";
|
||||
@ -134,9 +115,9 @@ namespace Launcher {
|
||||
string mppass = Options.Get( "launcher-dc-mppass" );
|
||||
mppass = Secure.Decode( mppass, user );
|
||||
|
||||
Set( 0, user );
|
||||
Set( 1, ip + ":" + port );
|
||||
Set( 2, mppass );
|
||||
SetText( 0, user );
|
||||
SetText( 1, ip + ":" + port );
|
||||
SetText( 2, mppass );
|
||||
SetBool( ccSkins );
|
||||
}
|
||||
|
||||
@ -152,6 +133,14 @@ namespace Launcher {
|
||||
Options.Save();
|
||||
}
|
||||
|
||||
void SetText( int index, string text ) {
|
||||
((LauncherInputWidget)widgets[index]).SetDrawData( drawer, text );
|
||||
}
|
||||
|
||||
void SetBool( bool value ) {
|
||||
((LauncherBoolWidget)widgets[view.ccSkinsIndex]).Value = value;
|
||||
}
|
||||
|
||||
void StartClient( int mouseX, int mouseY ) {
|
||||
string address = Get( 1 );
|
||||
int index = address.LastIndexOf( ':' );
|
||||
@ -164,7 +153,7 @@ namespace Launcher {
|
||||
ClientStartData data = GetStartData( Get( 0 ), Get( 2 ), ipPart, portPart );
|
||||
if( data == null ) return;
|
||||
|
||||
bool ccSkins = ((LauncherBooleanWidget)widgets[skinsIndex]).Value;
|
||||
bool ccSkins = ((LauncherBoolWidget)widgets[view.ccSkinsIndex]).Value;
|
||||
SaveToOptions( data, ccSkins );
|
||||
Client.Start( data, ccSkins, ref game.ShouldExit );
|
||||
}
|
||||
|
@ -74,7 +74,7 @@ namespace Launcher {
|
||||
if( signingIn ) return;
|
||||
UpdateSignInInfo( Get( 0 ), Get( 1 ) );
|
||||
|
||||
LauncherBooleanWidget booleanWidget = widgets[skipSSLIndex] as LauncherBooleanWidget;
|
||||
LauncherBoolWidget booleanWidget = widgets[skipSSLIndex] as LauncherBoolWidget;
|
||||
if( booleanWidget != null && booleanWidget.Value ) {
|
||||
ServicePointManager.ServerCertificateValidationCallback = delegate { return true; };
|
||||
} else {
|
||||
@ -137,13 +137,13 @@ namespace Launcher {
|
||||
void SSLSkipValidationClick( int mouseX, int mouseY ) {
|
||||
using( drawer ) {
|
||||
drawer.SetBitmap( game.Framebuffer );
|
||||
LauncherBooleanWidget widget = (LauncherBooleanWidget)widgets[skipSSLIndex];
|
||||
LauncherBoolWidget widget = (LauncherBoolWidget)widgets[skipSSLIndex];
|
||||
SetBool( !widget.Value );
|
||||
}
|
||||
}
|
||||
|
||||
void SetBool( bool value ) {
|
||||
LauncherBooleanWidget widget = (LauncherBooleanWidget)widgets[skipSSLIndex];
|
||||
LauncherBoolWidget widget = (LauncherBoolWidget)widgets[skipSSLIndex];
|
||||
widget.Value = value;
|
||||
widget.Redraw( game.Drawer );
|
||||
Dirty = true;
|
||||
|
@ -21,7 +21,6 @@ namespace Launcher {
|
||||
drawer.SetBitmap( game.Framebuffer );
|
||||
RedrawAll();
|
||||
}
|
||||
Dirty = true;
|
||||
}
|
||||
|
||||
public override void Init() {
|
||||
|
68
Launcher2/Gui/Views/DirectConnectView.cs
Normal file
68
Launcher2/Gui/Views/DirectConnectView.cs
Normal file
@ -0,0 +1,68 @@
|
||||
// ClassicalSharp copyright 2014-2016 UnknownShadow200 | Licensed under MIT
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Drawing;
|
||||
using System.IO;
|
||||
using System.Net;
|
||||
using ClassicalSharp;
|
||||
|
||||
namespace Launcher {
|
||||
|
||||
public sealed class DirectConnectView : IView {
|
||||
|
||||
internal int connectIndex, backIndex, ccSkinsIndex;
|
||||
Font booleanFont;
|
||||
|
||||
public DirectConnectView( LauncherWindow game ) : base( game ) {
|
||||
widgets = new LauncherWidget[8];
|
||||
}
|
||||
|
||||
public override void Init() {
|
||||
booleanFont = new Font( game.FontName, 22, FontStyle.Regular );
|
||||
titleFont = new Font( game.FontName, 15, FontStyle.Bold );
|
||||
inputFont = new Font( game.FontName, 14, FontStyle.Regular );
|
||||
inputHintFont = new Font( game.FontName, 12, FontStyle.Italic );
|
||||
MakeWidgets();
|
||||
}
|
||||
|
||||
public override void DrawAll() {
|
||||
MakeWidgets();
|
||||
RedrawAllButtonBackgrounds();
|
||||
|
||||
using( drawer ) {
|
||||
drawer.SetBitmap( game.Framebuffer );
|
||||
RedrawAll();
|
||||
}
|
||||
}
|
||||
|
||||
void MakeWidgets() {
|
||||
widgetIndex = 0;
|
||||
|
||||
MakeInput( Get( 0 ), 330, Anchor.Centre, Anchor.Centre,
|
||||
false, 0, -100, 32, "&7Username.." );
|
||||
MakeInput( Get( 1 ), 330, Anchor.Centre, Anchor.Centre,
|
||||
false, 0, -50, 64, "&7IP address:Port number.." );
|
||||
MakeInput( Get( 2 ), 330, Anchor.Centre, Anchor.Centre,
|
||||
false, 0, 0, 32, "&7Mppass.." );
|
||||
|
||||
connectIndex = widgetIndex;
|
||||
MakeButtonAt( "Connect", 110, 35, titleFont, Anchor.Centre, -110, 50 );
|
||||
backIndex = widgetIndex;
|
||||
MakeButtonAt( "Back", 80, 35, titleFont, Anchor.Centre, 125, 50 );
|
||||
MakeLabelAt( "", titleFont, Anchor.Centre, Anchor.Centre, 0, 100 );
|
||||
MakeLabelAt( "Use classicube.net for skins", inputFont, Anchor.Centre, Anchor.Centre, 30, 130 );
|
||||
ccSkinsIndex = widgetIndex;
|
||||
MakeBooleanAt( Anchor.Centre, Anchor.Centre, booleanFont, true, 30, 30, -110, 130 );
|
||||
}
|
||||
|
||||
string Get( int index ) {
|
||||
LauncherWidget widget = widgets[index];
|
||||
return widget == null ? "" : widget.Text;
|
||||
}
|
||||
|
||||
public override void Dispose() {
|
||||
base.Dispose();
|
||||
booleanFont.Dispose();
|
||||
}
|
||||
}
|
||||
}
|
@ -10,7 +10,6 @@ namespace Launcher {
|
||||
protected internal LauncherWindow game;
|
||||
protected internal IDrawer2D drawer;
|
||||
|
||||
public bool Dirty;
|
||||
protected int widgetIndex;
|
||||
internal LauncherWidget[] widgets;
|
||||
protected Font titleFont, inputFont, inputHintFont;
|
||||
|
@ -35,7 +35,6 @@ namespace Launcher {
|
||||
game.Drawer.DrawRect( col, game.Width / 2 - 160, middle - 100, 320, 1 );
|
||||
game.Drawer.DrawRect( col, game.Width / 2 - 160, middle - 10, 320, 1 );
|
||||
}
|
||||
Dirty = true;
|
||||
}
|
||||
|
||||
const string dateFormat = "dd-MM-yyyy HH:mm";
|
||||
|
@ -1,38 +1,38 @@
|
||||
// ClassicalSharp copyright 2014-2016 UnknownShadow200 | Licensed under MIT
|
||||
using System;
|
||||
using System.Drawing;
|
||||
using ClassicalSharp;
|
||||
|
||||
namespace Launcher {
|
||||
|
||||
/// <summary> Widget that represents text can have modified by the user. </summary>
|
||||
public sealed class LauncherBooleanWidget : LauncherWidget {
|
||||
|
||||
public int BoxWidth, BoxHeight;
|
||||
public bool Value;
|
||||
Font font;
|
||||
|
||||
public LauncherBooleanWidget( LauncherWindow window, Font font, int width, int height ) : base( window ) {
|
||||
BoxWidth = width; BoxHeight = height;
|
||||
Width = width; Height = height;
|
||||
this.font = font;
|
||||
}
|
||||
|
||||
public void SetDrawData( IDrawer2D drawer, Anchor horAnchor, Anchor verAnchor, int x, int y ) {
|
||||
CalculateOffset( x, y, horAnchor, verAnchor );
|
||||
}
|
||||
|
||||
public override void Redraw( IDrawer2D drawer ) {
|
||||
if( Window.Minimised ) return;
|
||||
drawer.DrawRect( FastColour.Black, X, Y, Width, Height );
|
||||
if( Value ) {
|
||||
DrawTextArgs args = new DrawTextArgs( "X", font, false );
|
||||
Size size = drawer.MeasureSize( ref args );
|
||||
args.SkipPartsCheck = true;
|
||||
drawer.DrawText( ref args, X + (Width + 2 - size.Width) / 2, // account for border
|
||||
Y + (Height - size.Height) / 2 );
|
||||
}
|
||||
drawer.DrawRectBounds( FastColour.White, 2, X, Y, Width, Height );
|
||||
}
|
||||
}
|
||||
}
|
||||
// ClassicalSharp copyright 2014-2016 UnknownShadow200 | Licensed under MIT
|
||||
using System;
|
||||
using System.Drawing;
|
||||
using ClassicalSharp;
|
||||
|
||||
namespace Launcher {
|
||||
|
||||
/// <summary> Widget that represents text can have modified by the user. </summary>
|
||||
public sealed class LauncherBoolWidget : LauncherWidget {
|
||||
|
||||
public int BoxWidth, BoxHeight;
|
||||
public bool Value;
|
||||
Font font;
|
||||
|
||||
public LauncherBoolWidget( LauncherWindow window, Font font, int width, int height ) : base( window ) {
|
||||
BoxWidth = width; BoxHeight = height;
|
||||
Width = width; Height = height;
|
||||
this.font = font;
|
||||
}
|
||||
|
||||
public void SetDrawData( IDrawer2D drawer, Anchor horAnchor, Anchor verAnchor, int x, int y ) {
|
||||
CalculateOffset( x, y, horAnchor, verAnchor );
|
||||
}
|
||||
|
||||
public override void Redraw( IDrawer2D drawer ) {
|
||||
if( Window.Minimised ) return;
|
||||
drawer.DrawRect( FastColour.Black, X, Y, Width, Height );
|
||||
if( Value ) {
|
||||
DrawTextArgs args = new DrawTextArgs( "X", font, false );
|
||||
Size size = drawer.MeasureSize( ref args );
|
||||
args.SkipPartsCheck = true;
|
||||
drawer.DrawText( ref args, X + (Width + 2 - size.Width) / 2, // account for border
|
||||
Y + (Height - size.Height) / 2 );
|
||||
}
|
||||
drawer.DrawRectBounds( FastColour.White, 2, X, Y, Width, Height );
|
||||
}
|
||||
}
|
||||
}
|
@ -43,11 +43,11 @@ namespace Launcher {
|
||||
public static void MakeBooleanAt( LauncherWindow game, LauncherWidget[] widgets, ref int widgetIndex,
|
||||
Anchor horAnchor, Anchor verAnchor, Font font, bool initValue,
|
||||
int width, int height, int x, int y, Action<int, int> onClick ) {
|
||||
LauncherBooleanWidget widget;
|
||||
LauncherBoolWidget widget;
|
||||
if( widgets[widgetIndex] != null ) {
|
||||
widget = (LauncherBooleanWidget)widgets[widgetIndex];
|
||||
widget = (LauncherBoolWidget)widgets[widgetIndex];
|
||||
} else {
|
||||
widget = new LauncherBooleanWidget( game, font, width, height );
|
||||
widget = new LauncherBoolWidget( game, font, width, height );
|
||||
widget.Value = initValue;
|
||||
widget.OnClick = onClick;
|
||||
widgets[widgetIndex] = widget;
|
||||
|
@ -75,9 +75,10 @@
|
||||
<Compile Include="Gui\TableWidget\LauncherTableWidget.Input.cs" />
|
||||
<Compile Include="Gui\Views\ChooseModeView.cs" />
|
||||
<Compile Include="Gui\Views\ColoursView.cs" />
|
||||
<Compile Include="Gui\Views\DirectConnectView.cs" />
|
||||
<Compile Include="Gui\Views\IView.cs" />
|
||||
<Compile Include="Gui\Views\UpdatesView.cs" />
|
||||
<Compile Include="Gui\Widgets\LauncherBooleanWidget.cs" />
|
||||
<Compile Include="Gui\Widgets\LauncherBoolWidget.cs" />
|
||||
<Compile Include="Gui\Widgets\LauncherButtonWidget.cs" />
|
||||
<Compile Include="Gui\Widgets\LauncherInputWidget.cs" />
|
||||
<Compile Include="Gui\Widgets\LauncherLabelWidget.cs" />
|
||||
|
Loading…
x
Reference in New Issue
Block a user