Separate ChooseModeScreen into ChooseModeScreen and ChooseModeView.

This commit is contained in:
UnknownShadow200 2016-05-09 14:23:54 +10:00
parent acc8823a01
commit d0f88ab5e1
8 changed files with 109 additions and 82 deletions

View File

@ -8,22 +8,31 @@ using OpenTK.Input;
namespace Launcher {
public abstract class ChooseModeScreen : LauncherScreen {
public sealed class ChooseModeScreen : LauncherScreen {
protected Font titleFont, infoFont;
public ChooseModeScreen( LauncherWindow game ) : base( game ) {
ChooseModeView view;
public ChooseModeScreen( LauncherWindow game, bool firstTime ) : base( game ) {
game.Window.Mouse.Move += MouseMove;
game.Window.Mouse.ButtonDown += MouseButtonDown;
titleFont = new Font( game.FontName, 16, FontStyle.Bold );
infoFont = new Font( game.FontName, 14, FontStyle.Regular );
buttonFont = titleFont;
widgets = new LauncherWidget[14];
view = new ChooseModeView( game );
view.FirstTime = firstTime;
widgets = view.widgets;
}
public override void Init() {
game.Window.Keyboard.KeyDown += KeyDown;
game.Window.Keyboard.KeyUp += KeyUp;
view.Init();
widgets[view.nIndex].OnClick = (x, y) => ModeClick( false, false );
widgets[view.clIndex ].OnClick = (x, y) => ModeClick( true, false );
widgets[view.clHaxIndex].OnClick = (x, y) => ModeClick( true, true );
if( view.backIndex >= 0 ) {
widgets[view.backIndex].OnClick = (x, y)
=> game.SetScreen( new MainScreen( game ) );
}
Resize();
}
@ -45,50 +54,10 @@ namespace Launcher {
}
public override void Resize() {
MakeWidgets();
RedrawAllButtonBackgrounds();
using( drawer ) {
drawer.SetBitmap( game.Framebuffer );
RedrawAll();
FastColour col = LauncherSkin.ButtonBorderCol;
int middle = game.Height / 2;
game.Drawer.DrawRect( col, game.Width / 2 - 250, middle - 35, 490, 1 );
game.Drawer.DrawRect( col, game.Width / 2 - 250, middle + 35, 490, 1 );
}
view.DrawAll();
Dirty = true;
}
void MakeWidgets() {
widgetIndex = 0;
int middle = game.Width / 2;
MakeLabelAt("&fChoose game mode", titleFont, Anchor.Centre, Anchor.Centre, 0, -135 );
MakeButtonAt( "Normal", 145, 35, titleFont, Anchor.LeftOrTop, Anchor.Centre, middle - 250, -72,
(x, y) => ModeClick( false, false ) );
MakeLabelAt( "&eEnables custom blocks, env settings,",
infoFont, Anchor.LeftOrTop, Anchor.Centre, middle - 85, -72 - 12 );
MakeLabelAt( "&elonger messages, and more",
infoFont, Anchor.LeftOrTop, Anchor.Centre, middle - 85, -72 + 12 );
MakeButtonAt( "Classic", 145, 35, titleFont, Anchor.LeftOrTop, Anchor.Centre, middle - 250, 0,
(x, y) => ModeClick( true, false ) );
MakeLabelAt( "&eOnly uses blocks and features from",
infoFont, Anchor.LeftOrTop, Anchor.Centre, middle - 85, 0 - 12 );
MakeLabelAt( "&ethe original minecraft classic",
infoFont, Anchor.LeftOrTop, Anchor.Centre, middle - 85, 0 + 12 );
MakeButtonAt( "Classic +hax", 145, 35, titleFont, Anchor.LeftOrTop, Anchor.Centre, middle - 250, 72,
(x, y) => ModeClick( true, true ) );
MakeLabelAt( "&eSame as Classic mode, except that",
infoFont, Anchor.LeftOrTop, Anchor.Centre, middle - 85, 72 - 12 );
MakeLabelAt( "&ehacks (noclip/fly/speed) are enabled",
infoFont, Anchor.LeftOrTop, Anchor.Centre, middle - 85, 72 + 12 );
MakeOtherWidgets();
}
protected virtual void MakeOtherWidgets() { }
void ModeClick( bool classic, bool classicHacks ) {
game.ClassicBackground = classic;
Options.Load();
@ -113,29 +82,7 @@ namespace Launcher {
game.Window.Keyboard.KeyUp -= KeyUp;
game.Window.Mouse.Move -= MouseMove;
game.Window.Mouse.ButtonDown -= MouseButtonDown;
titleFont.Dispose();
infoFont.Dispose();
}
}
public sealed class ChooseModeNormalScreen : ChooseModeScreen {
public ChooseModeNormalScreen( LauncherWindow game ) : base( game ) { }
protected override void MakeOtherWidgets() {
MakeButtonAt( "Back", 80, 35, titleFont, Anchor.Centre,
0, 175, (x, y) => game.SetScreen( new MainScreen( game ) ) );
}
}
public sealed class ChooseModeFirstTimeScreen : ChooseModeScreen {
public ChooseModeFirstTimeScreen( LauncherWindow game ) : base( game ) { }
protected override void MakeOtherWidgets() {
MakeLabelAt( "&eClick &fNormal &eif you are unsure which mode to choose.",
infoFont, Anchor.Centre, Anchor.Centre, 0, 160 );
view.Dispose();
}
}
}

View File

@ -35,6 +35,11 @@ namespace Launcher {
Dirty = true;
}
public override void Dispose() {
view.Dispose();
base.Dispose();
}
protected override void MouseWheelChanged( object sender, MouseWheelEventArgs e ) {
AdjustSelectedColour( e.Delta );
}

View File

@ -83,7 +83,7 @@ namespace Launcher {
(x, y) => game.SetScreen( new UpdatesScreen( game ) ) );
MakeButtonAt( "Choose mode", 200, buttonHeight, buttonFont,
Anchor.Centre, Anchor.BottomOrRight, 0, -10,
(x, y) => game.SetScreen( new ChooseModeNormalScreen( game ) ) );
(x, y) => game.SetScreen( new ChooseModeScreen( game, false ) ) );
MakeLabelAt( updateText, updateFont, Anchor.BottomOrRight,
Anchor.BottomOrRight, -10, -50 );

View File

@ -146,7 +146,7 @@ namespace Launcher {
if( File.Exists( "options.txt" ) )
game.SetScreen( new MainScreen( game ) );
else
game.SetScreen( new ChooseModeFirstTimeScreen( game ) );
game.SetScreen( new ChooseModeScreen( game, true ) );
}
void SetStatus( string text ) {

View File

@ -0,0 +1,76 @@
// ClassicalSharp copyright 2014-2016 UnknownShadow200 | Licensed under MIT
using System;
using System.Drawing;
using System.IO;
using ClassicalSharp;
using Launcher.Updater;
using OpenTK.Input;
namespace Launcher {
public sealed class ChooseModeView : IView {
public bool FirstTime = true;
internal int backIndex = -1, nIndex, clIndex, clHaxIndex;
public ChooseModeView( LauncherWindow game ) : base( game ) {
widgets = new LauncherWidget[14];
}
public override void Init() {
titleFont = new Font( game.FontName, 16, FontStyle.Bold );
inputFont = new Font( game.FontName, 14, FontStyle.Regular );
UpdateWidgets();
}
public override void DrawAll() {
UpdateWidgets();
RedrawAllButtonBackgrounds();
using( drawer ) {
drawer.SetBitmap( game.Framebuffer );
RedrawAll();
FastColour col = LauncherSkin.ButtonBorderCol;
int middle = game.Height / 2;
game.Drawer.DrawRect( col, game.Width / 2 - 250, middle - 35, 490, 1 );
game.Drawer.DrawRect( col, game.Width / 2 - 250, middle + 35, 490, 1 );
}
}
void UpdateWidgets() {
widgetIndex = 0;
int middle = game.Width / 2;
MakeLabelAt( "&fChoose game mode", titleFont, Anchor.Centre, Anchor.Centre, 0, -135 );
nIndex = widgetIndex;
MakeButtonAt( "Normal", 145, 35, titleFont, Anchor.LeftOrTop, Anchor.Centre, middle - 250, -72 );
MakeLabelAt( "&eEnables custom blocks, env settings,",
inputFont, Anchor.LeftOrTop, Anchor.Centre, middle - 85, -72 - 12 );
MakeLabelAt( "&elonger messages, and more",
inputFont, Anchor.LeftOrTop, Anchor.Centre, middle - 85, -72 + 12 );
clIndex = widgetIndex;
MakeButtonAt( "Classic", 145, 35, titleFont, Anchor.LeftOrTop, Anchor.Centre, middle - 250, 0 );
MakeLabelAt( "&eOnly uses blocks and features from",
inputFont, Anchor.LeftOrTop, Anchor.Centre, middle - 85, 0 - 12 );
MakeLabelAt( "&ethe original minecraft classic",
inputFont, Anchor.LeftOrTop, Anchor.Centre, middle - 85, 0 + 12 );
clHaxIndex = widgetIndex;
MakeButtonAt( "Classic +hax", 145, 35, titleFont, Anchor.LeftOrTop, Anchor.Centre, middle - 250, 72 );
MakeLabelAt( "&eSame as Classic mode, except that",
inputFont, Anchor.LeftOrTop, Anchor.Centre, middle - 85, 72 - 12 );
MakeLabelAt( "&ehacks (noclip/fly/speed) are enabled",
inputFont, Anchor.LeftOrTop, Anchor.Centre, middle - 85, 72 + 12 );
if( FirstTime ) {
backIndex = -1;
MakeLabelAt( "&eClick &fNormal &eif you are unsure which mode to choose.",
inputFont, Anchor.Centre, Anchor.Centre, 0, 160 );
} else {
backIndex = widgetIndex;
MakeButtonAt( "Back", 80, 35, titleFont, Anchor.Centre, 0, 175 );
}
}
}
}

View File

@ -25,7 +25,9 @@ namespace Launcher {
}
public override void Init() {
base.Init();
titleFont = new Font( game.FontName, 15, FontStyle.Bold );
inputFont = new Font( game.FontName, 14, FontStyle.Regular );
inputHintFont = new Font( game.FontName, 12, FontStyle.Italic );
UpdateWidgets();
}

View File

@ -21,20 +21,16 @@ namespace Launcher {
}
/// <summary> Function called to setup the widgets and other data for this view. </summary>
public virtual void Init() {
titleFont = new Font( game.FontName, 15, FontStyle.Bold );
inputFont = new Font( game.FontName, 14, FontStyle.Regular );
inputHintFont = new Font( game.FontName, 12, FontStyle.Italic );
}
public abstract void Init();
/// <summary> Function called to redraw all widgets in this view. </summary>
public abstract void DrawAll();
/// <summary> Cleans up all native resources held by this view. </summary>
public virtual void Dispose() {
titleFont.Dispose();
inputFont.Dispose();
inputHintFont.Dispose();
if( titleFont != null ) titleFont.Dispose();
if( inputFont != null ) inputFont.Dispose();
if( inputHintFont != null ) inputHintFont.Dispose();
}
protected void RedrawAllButtonBackgrounds() {

View File

@ -73,6 +73,7 @@
<Compile Include="Gui\TableWidget\LauncherTableWidget.cs" />
<Compile Include="Gui\TableWidget\LauncherTableWidget.Drawing.cs" />
<Compile Include="Gui\TableWidget\LauncherTableWidget.Input.cs" />
<Compile Include="Gui\Views\ChooseModeView.cs" />
<Compile Include="Gui\Views\ColoursView.cs" />
<Compile Include="Gui\Views\IView.cs" />
<Compile Include="Gui\Widgets\LauncherBooleanWidget.cs" />