Initial implementation of nostalgia options - can turn off custom blocks, and can turn off using server textures.

This commit is contained in:
UnknownShadow200 2016-01-11 19:44:50 +11:00
parent dadaf54c29
commit a4c548cd14
10 changed files with 139 additions and 30 deletions

View File

@ -30,10 +30,10 @@ namespace ClassicalSharp {
g.RefreshHud(); g.RefreshHud();
} ), } ),
Make( -140, 0, "Use classic gui", OnWidgetClick, Make( -140, 0, "Tab auto-complete", OnWidgetClick,
g => g.UseClassicGui ? "yes" : "no", g => g.TabAutocomplete ? "yes" : "no",
(g, v) => { g.UseClassicGui = v == "yes"; (g, v) => { g.TabAutocomplete = v == "yes";
Options.Set( OptionsKey.UseClassicGui, v == "yes" ); Options.Set( OptionsKey.TabAutocomplete, v == "yes" );
} ), } ),
// Column 2 // Column 2
@ -73,13 +73,7 @@ namespace ClassicalSharp {
g.RefreshHud(); g.RefreshHud();
Recreate(); Recreate();
} ), } ),
Make( 140, 50, "Tab auto-complete", OnWidgetClick,
g => g.TabAutocomplete ? "yes" : "no",
(g, v) => { g.TabAutocomplete = v == "yes";
Options.Set( OptionsKey.TabAutocomplete, v == "yes" );
} ),
MakeBack( false, titleFont, MakeBack( false, titleFont,
(g, w) => g.SetNewScreen( new PauseScreen( g ) ) ), (g, w) => g.SetNewScreen( new PauseScreen( g ) ) ),
@ -93,8 +87,7 @@ namespace ClassicalSharp {
new BooleanValidator(), new BooleanValidator(),
new RealValidator( 0.25f, 5f ), new RealValidator( 0.25f, 5f ),
new IntegerValidator( 1, 30 ), new IntegerValidator( 1, 30 ),
new BooleanValidator(),
new BooleanValidator(), new BooleanValidator(),
}; };
okayIndex = buttons.Length - 1; okayIndex = buttons.Length - 1;

View File

@ -0,0 +1,89 @@
using System;
using System.Drawing;
using ClassicalSharp.Singleplayer;
namespace ClassicalSharp {
public sealed class NostalgiaScreen : MenuInputScreen {
TextWidget infoWidget;
public NostalgiaScreen( Game game ) : base( game ) {
}
public override void Init() {
base.Init();
INetworkProcessor network = game.Network;
buttons = new ButtonWidget[] {
// Column 1
Make( -140, -100, "Simple arms anim", OnWidgetClick,
g => g.SimpleArmsAnim? "yes" : "no",
(g, v) => { g.SimpleArmsAnim = v == "yes";
Options.Set( OptionsKey.SimpleArmsAnim, v == "yes" ); }),
Make( -140, -50, "Use classic gui", OnWidgetClick,
g => g.UseClassicGui ? "yes" : "no",
(g, v) => { g.UseClassicGui = v == "yes";
Options.Set( OptionsKey.UseClassicGui, v == "yes" );
} ),
// Column 2
Make( 140, -100, "Allow custom blocks", OnWidgetClick,
g => g.AllowCustomBlocks ? "yes" : "no",
(g, v) => { g.AllowCustomBlocks = v == "yes";
Options.Set( OptionsKey.AllowCustomBlocks, v == "yes" );
} ),
Make( 140, -50, "Allow CPE blocks", OnWidgetClick,
g => g.AllowCPEBlocks ? "yes" : "no",
(g, v) => { g.AllowCPEBlocks = v == "yes";
Options.Set( OptionsKey.AllowCPEBlocks, v == "yes" );
} ),
Make( 140, 0, "Allow server textures", OnWidgetClick,
g => g.AllowServerTextures ? "yes" : "no",
(g, v) => { g.AllowServerTextures = v == "yes";
Options.Set( OptionsKey.AllowServerTextures, v == "yes" );
} ),
MakeBack( false, titleFont,
(g, w) => g.SetNewScreen( new PauseScreen( g ) ) ),
null,
};
buttons[3].Disabled = true;
validators = new MenuInputValidator[] {
new BooleanValidator(),
new BooleanValidator(),
new BooleanValidator(),
new BooleanValidator(),
new BooleanValidator(),
};
okayIndex = buttons.Length - 1;
infoWidget = TextWidget.Create( game, 0, 150, "&eButtons on the right require a client restart.",
Anchor.Centre, Anchor.Centre, regularFont );
}
public override void Render( double delta ) {
base.Render( delta );
graphicsApi.Texturing = true;
infoWidget.Render( delta );
graphicsApi.Texturing = false;
}
public override void Dispose() {
base.Dispose();
infoWidget.Dispose();
}
ButtonWidget Make( int x, int y, string text, Action<Game, Widget> onClick,
Func<Game, string> getter, Action<Game, string> setter ) {
ButtonWidget widget = ButtonWidget.Create( game, x, y, 240, 35, text, Anchor.Centre,
Anchor.Centre, titleFont, onClick );
widget.GetValue = getter;
widget.SetValue = setter;
return widget;
}
}
}

View File

@ -26,24 +26,19 @@ namespace ClassicalSharp {
g.AudioPlayer.SetSound( g.UseSound ); g.AudioPlayer.SetSound( g.UseSound );
Options.Set( OptionsKey.UseSound, v == "yes" ); }), Options.Set( OptionsKey.UseSound, v == "yes" ); }),
Make( -140, -100, "Simple arms anim", OnWidgetClick, Make( -140, -100, "Names mode", OnWidgetClick,
g => g.SimpleArmsAnim? "yes" : "no",
(g, v) => { g.SimpleArmsAnim = v == "yes";
Options.Set( OptionsKey.SimpleArmsAnim, v == "yes" ); }),
Make( -140, -50, "Names mode", OnWidgetClick,
g => g.Players.NamesMode.ToString(), g => g.Players.NamesMode.ToString(),
(g, v) => { object raw = Enum.Parse( typeof(NameMode), v ); (g, v) => { object raw = Enum.Parse( typeof(NameMode), v );
g.Players.NamesMode = (NameMode)raw; g.Players.NamesMode = (NameMode)raw;
Options.Set( OptionsKey.NamesMode, v ); } ), Options.Set( OptionsKey.NamesMode, v ); } ),
Make( -140, 0, "FPS limit", OnWidgetClick, Make( -140, -50, "FPS limit", OnWidgetClick,
g => g.FpsLimit.ToString(), g => g.FpsLimit.ToString(),
(g, v) => { object raw = Enum.Parse( typeof(FpsLimitMethod), v ); (g, v) => { object raw = Enum.Parse( typeof(FpsLimitMethod), v );
g.SetFpsLimitMethod( (FpsLimitMethod)raw ); g.SetFpsLimitMethod( (FpsLimitMethod)raw );
Options.Set( OptionsKey.FpsLimit, v ); } ), Options.Set( OptionsKey.FpsLimit, v ); } ),
Make( -140, 50, "View distance", OnWidgetClick, Make( -140, 0, "View distance", OnWidgetClick,
g => g.ViewDistance.ToString(), g => g.ViewDistance.ToString(),
(g, v) => g.SetViewDistance( Int32.Parse( v ), true ) ), (g, v) => g.SetViewDistance( Int32.Parse( v ), true ) ),
@ -85,13 +80,12 @@ namespace ClassicalSharp {
(g, w) => g.SetNewScreen( new PauseScreen( g ) ) ), (g, w) => g.SetNewScreen( new PauseScreen( g ) ) ),
null, null,
}; };
buttons[3].Metadata = typeof(NameMode); buttons[2].Metadata = typeof(NameMode);
buttons[4].Metadata = typeof(FpsLimitMethod); buttons[3].Metadata = typeof(FpsLimitMethod);
validators = new MenuInputValidator[] { validators = new MenuInputValidator[] {
network.IsSinglePlayer ? new RealValidator(1, 1024) : null, network.IsSinglePlayer ? new RealValidator(1, 1024) : null,
new BooleanValidator(), new BooleanValidator(),
new BooleanValidator(),
new EnumValidator(), new EnumValidator(),
new EnumValidator(), new EnumValidator(),
new IntegerValidator( 16, 4096 ), new IntegerValidator( 16, 4096 ),

View File

@ -46,6 +46,9 @@ namespace ClassicalSharp {
Make( 140, 50, "Hotkeys", Anchor.Centre, Make( 140, 50, "Hotkeys", Anchor.Centre,
(g, w) => g.SetNewScreen( new HotkeyScreen( g ) ) ), (g, w) => g.SetNewScreen( new HotkeyScreen( g ) ) ),
Make( 0, 100, "Nostalgia options", Anchor.Centre,
(g, w) => g.SetNewScreen( new NostalgiaScreen( g ) ) ),
// Other // Other
MakeOther( 10, 5, 120, "Quit game", Anchor.BottomOrRight, MakeOther( 10, 5, 120, "Quit game", Anchor.BottomOrRight,
(g, w) => g.Exit() ), (g, w) => g.Exit() ),

View File

@ -103,6 +103,7 @@
<Compile Include="2D\Screens\Menu\LoadLevelScreen.cs" /> <Compile Include="2D\Screens\Menu\LoadLevelScreen.cs" />
<Compile Include="2D\Screens\Menu\MenuInputScreen.cs" /> <Compile Include="2D\Screens\Menu\MenuInputScreen.cs" />
<Compile Include="2D\Screens\Menu\MenuScreen.cs" /> <Compile Include="2D\Screens\Menu\MenuScreen.cs" />
<Compile Include="2D\Screens\Menu\NostalgiaScreen.cs" />
<Compile Include="2D\Screens\Menu\PauseScreen.cs" /> <Compile Include="2D\Screens\Menu\PauseScreen.cs" />
<Compile Include="2D\Screens\Menu\OptionsScreen.cs" /> <Compile Include="2D\Screens\Menu\OptionsScreen.cs" />
<Compile Include="2D\Screens\Menu\SaveLevelScreen.cs" /> <Compile Include="2D\Screens\Menu\SaveLevelScreen.cs" />

View File

@ -129,6 +129,8 @@ namespace ClassicalSharp {
public bool TabAutocomplete = false; public bool TabAutocomplete = false;
public bool AllowCustomBlocks, AllowCPEBlocks, AllowServerTextures;
public int ChatLines = 12; public int ChatLines = 12;
public bool ClickableChat = false, HideGui = false, ShowFPS = true; public bool ClickableChat = false, HideGui = false, ShowFPS = true;
internal float HudScale = 1.0f, ChatScale = 1.0f; internal float HudScale = 1.0f, ChatScale = 1.0f;

View File

@ -59,6 +59,9 @@ namespace ClassicalSharp {
MouseSensitivity = Options.GetInt( OptionsKey.Sensitivity, 1, 100, 30 ); MouseSensitivity = Options.GetInt( OptionsKey.Sensitivity, 1, 100, 30 );
UseClassicGui = Options.GetBool( OptionsKey.UseClassicGui, true ); UseClassicGui = Options.GetBool( OptionsKey.UseClassicGui, true );
TabAutocomplete = Options.GetBool( OptionsKey.TabAutocomplete, false ); TabAutocomplete = Options.GetBool( OptionsKey.TabAutocomplete, false );
AllowCustomBlocks = Options.GetBool( OptionsKey.AllowCustomBlocks, true );
AllowCPEBlocks = Options.GetBool( OptionsKey.AllowCPEBlocks, true );
AllowServerTextures = Options.GetBool( OptionsKey.AllowServerTextures, true );
BlockInfo = new BlockInfo(); BlockInfo = new BlockInfo();
BlockInfo.Init(); BlockInfo.Init();

View File

@ -105,15 +105,19 @@ namespace ClassicalSharp {
} }
void SendCpeExtInfoReply() { void SendCpeExtInfoReply() {
if( cpeServerExtensionsCount != 0) if( cpeServerExtensionsCount != 0 ) return;
return; int count = clientExtensions.Length;
MakeExtInfo( Program.AppName, clientExtensions.Length ); if( !game.AllowCustomBlocks ) count -= 2;
MakeExtInfo( Program.AppName, count );
SendPacket(); SendPacket();
for( int i = 0; i < clientExtensions.Length; i++ ) { for( int i = 0; i < clientExtensions.Length; i++ ) {
string name = clientExtensions[i]; string name = clientExtensions[i];
int ver = name == "ExtPlayerList" ? 2 : 1; int ver = name == "ExtPlayerList" ? 2 : 1;
if( name == "EnvMapAppearance" ) ver = envMapApperanceVer; if( name == "EnvMapAppearance" ) ver = envMapApperanceVer;
if( !game.AllowCustomBlocks && name.StartsWith( "BlockDefinitions" ) )
continue;
MakeExtEntry( name, ver ); MakeExtEntry( name, ver );
SendPacket(); SendPacket();
} }
@ -300,7 +304,9 @@ namespace ClassicalSharp {
string url = reader.ReadAsciiString(); string url = reader.ReadAsciiString();
game.Map.SetSidesBlock( (Block)reader.ReadUInt8() ); game.Map.SetSidesBlock( (Block)reader.ReadUInt8() );
game.Map.SetEdgeBlock( (Block)reader.ReadUInt8() ); game.Map.SetEdgeBlock( (Block)reader.ReadUInt8() );
game.Map.SetEdgeLevel( reader.ReadInt16() ); game.Map.SetEdgeLevel( reader.ReadInt16() );
if( !game.AllowServerTextures )
return;
if( url == String.Empty ) { if( url == String.Empty ) {
TexturePackExtractor extractor = new TexturePackExtractor(); TexturePackExtractor extractor = new TexturePackExtractor();
@ -386,6 +392,9 @@ namespace ClassicalSharp {
} }
void HandleCpeDefineBlock() { void HandleCpeDefineBlock() {
if( !game.AllowCustomBlocks ) {
SkipPacketData( PacketId.CpeDefineBlock ); return;
}
byte block = HandleCpeDefineBlockCommonStart(); byte block = HandleCpeDefineBlockCommonStart();
BlockInfo info = game.BlockInfo; BlockInfo info = game.BlockInfo;
byte shape = reader.ReadUInt8(); byte shape = reader.ReadUInt8();
@ -408,11 +417,17 @@ namespace ClassicalSharp {
} }
void HandleCpeRemoveBlockDefinition() { void HandleCpeRemoveBlockDefinition() {
if( !game.AllowCustomBlocks ) {
SkipPacketData( PacketId.CpeRemoveBlockDefinition ); return;
}
game.BlockInfo.ResetBlockInfo( reader.ReadUInt8(), true ); game.BlockInfo.ResetBlockInfo( reader.ReadUInt8(), true );
game.BlockInfo.InitLightOffsets(); game.BlockInfo.InitLightOffsets();
} }
void HandleCpeDefineBlockExt() { void HandleCpeDefineBlockExt() {
if( !game.AllowCustomBlocks ) {
SkipPacketData( PacketId.CpeDefineBlockExt ); return;
}
byte block = HandleCpeDefineBlockCommonStart(); byte block = HandleCpeDefineBlockCommonStart();
BlockInfo info = game.BlockInfo; BlockInfo info = game.BlockInfo;
Vector3 min, max; Vector3 min, max;

View File

@ -192,6 +192,10 @@ namespace ClassicalSharp {
handler(); handler();
} }
void SkipPacketData( PacketId opcode ) {
reader.Remove( packetSizes[(byte)opcode] - 1 );
}
Action[] handlers; Action[] handlers;
int maxHandledPacket; int maxHandledPacket;

View File

@ -8,6 +8,7 @@ using OpenTK.Input;
namespace ClassicalSharp { namespace ClassicalSharp {
public static class OptionsKey { public static class OptionsKey {
public const string ViewDist = "viewdist"; public const string ViewDist = "viewdist";
public const string HudScale = "hudscale"; public const string HudScale = "hudscale";
public const string ChatScale = "chatscale"; public const string ChatScale = "chatscale";
@ -23,7 +24,6 @@ namespace ClassicalSharp {
public const string UseSound = "usesound"; public const string UseSound = "usesound";
public const string HacksEnabled = "hacksenabled"; public const string HacksEnabled = "hacksenabled";
public const string NamesMode = "namesmode"; public const string NamesMode = "namesmode";
public const string SimpleArmsAnim = "simplearmsanim";
public const string MouseLeft = "mouseleft"; public const string MouseLeft = "mouseleft";
public const string MouseMiddle = "mousemiddle"; public const string MouseMiddle = "mousemiddle";
@ -37,9 +37,14 @@ namespace ClassicalSharp {
public const string InvertMouse = "invertmouse"; public const string InvertMouse = "invertmouse";
public const string NoclipSlide = "noclipslide"; public const string NoclipSlide = "noclipslide";
public const string CameraClipping = "cameraclipping"; public const string CameraClipping = "cameraclipping";
public const string UseClassicGui = "useclassictex";
public const string DoubleJump = "doublejump"; public const string DoubleJump = "doublejump";
public const string TabAutocomplete = "tab-autocomplete"; public const string TabAutocomplete = "tab-autocomplete";
public const string AllowCustomBlocks = "nostalgia-customblocks";
public const string AllowCPEBlocks = "nostalgia-cpeblocks";
public const string AllowServerTextures = "nostalgia-servertextures";
public const string UseClassicGui = "nostalgia-classicgui";
public const string SimpleArmsAnim = "nostalgia-simplearms";
} }
// TODO: implement this // TODO: implement this