From e05c1a14ed1ff20217a90b8606c7ecbfe94c1878 Mon Sep 17 00:00:00 2001 From: UnknownShadow200 Date: Thu, 12 May 2016 16:13:08 +1000 Subject: [PATCH] More work on EnvMapAppearance v3. --- ClassicalSharp/2D/Drawing/IDrawer2D.TextMC.cs | 2 +- ClassicalSharp/2D/Screens/ChatScreen.cs | 20 +++++++--------- .../2D/Screens/Menu/GraphicsOptionsScreen.cs | 2 -- .../2D/Widgets/Chat/TextInputWidget.cs | 4 ++-- .../Widgets/PlayerList/ExtPlayerListWidget.cs | 2 +- ClassicalSharp/Events/WorldEvents.cs | 4 ++-- ClassicalSharp/Map/WorldEnv.cs | 22 ++++++++---------- .../Network/NetworkProcessor.CPE.cs | 23 ++++++++++++++++++- ClassicalSharp/Rendering/WeatherRenderer.cs | 3 +-- 9 files changed, 46 insertions(+), 36 deletions(-) diff --git a/ClassicalSharp/2D/Drawing/IDrawer2D.TextMC.cs b/ClassicalSharp/2D/Drawing/IDrawer2D.TextMC.cs index 7393aefdf..db9951ac2 100644 --- a/ClassicalSharp/2D/Drawing/IDrawer2D.TextMC.cs +++ b/ClassicalSharp/2D/Drawing/IDrawer2D.TextMC.cs @@ -145,7 +145,7 @@ namespace ClassicalSharp { void DrawUnderline( FastBitmap dst, int x, int yOffset, ref DrawTextArgs args, bool shadowCol ) { int point = Utils.Floor( args.Font.Size ); int padding = CellSize( point ) - AdjTextSize( point ); - int height = AdjTextSize( point ) + Utils.CeilDiv(padding, 2); + int height = AdjTextSize( point ) + Utils.CeilDiv( padding, 2 ); int offset = ShadowOffset( args.Font.Size ); int col = FastColour.White.ToArgb(); diff --git a/ClassicalSharp/2D/Screens/ChatScreen.cs b/ClassicalSharp/2D/Screens/ChatScreen.cs index 3a8abe7a2..5b8157633 100644 --- a/ClassicalSharp/2D/Screens/ChatScreen.cs +++ b/ClassicalSharp/2D/Screens/ChatScreen.cs @@ -23,15 +23,13 @@ namespace ClassicalSharp.Gui { int chatIndex; int blockSize; - Font chatFont, chatBoldFont, chatItalicFont, chatUnderlineFont, announcementFont; + Font chatFont, chatUrlFont, announcementFont; public override void Init() { float textScale = game.Drawer2D.UseBitmappedChat ? 1.25f : 1; int fontSize = (int)(12 * game.GuiChatScale * textScale); Utils.Clamp( ref fontSize, 8, 60 ); chatFont = new Font( game.FontName, fontSize ); - chatBoldFont = new Font( game.FontName, fontSize, FontStyle.Bold ); - chatItalicFont = new Font( game.FontName, fontSize, FontStyle.Italic ); - chatUnderlineFont = new Font( game.FontName, fontSize, FontStyle.Underline ); + chatUrlFont = new Font( game.FontName, fontSize, FontStyle.Underline ); fontSize = (int)(14 * game.GuiChatScale); Utils.Clamp( ref fontSize, 8, 60 ); @@ -51,24 +49,24 @@ namespace ClassicalSharp.Gui { } void ConstructWidgets() { - textInput = new TextInputWidget( game, chatFont, chatBoldFont ); + textInput = new TextInputWidget( game, chatFont ); textInput.YOffset = blockSize + 5; - status = new TextGroupWidget( game, 5, chatFont, chatUnderlineFont, + status = new TextGroupWidget( game, 5, chatFont, chatUrlFont, Anchor.BottomOrRight, Anchor.LeftOrTop ); status.Init(); status.SetUsePlaceHolder( 0, false ); status.SetUsePlaceHolder( 1, false ); - bottomRight = new TextGroupWidget( game, 3, chatFont, chatUnderlineFont, + bottomRight = new TextGroupWidget( game, 3, chatFont, chatUrlFont, Anchor.BottomOrRight, Anchor.BottomOrRight ); bottomRight.YOffset = blockSize * 3 / 2; bottomRight.Init(); - normalChat = new TextGroupWidget( game, chatLines, chatFont, chatUnderlineFont, + normalChat = new TextGroupWidget( game, chatLines, chatFont, chatUrlFont, Anchor.LeftOrTop, Anchor.BottomOrRight ); normalChat.XOffset = 10; normalChat.YOffset = blockSize * 2 + 15; normalChat.Init(); clientStatus = new TextGroupWidget( game, game.Chat.ClientStatus.Length, chatFont, - chatUnderlineFont, Anchor.LeftOrTop, Anchor.BottomOrRight ); + chatUrlFont, Anchor.LeftOrTop, Anchor.BottomOrRight ); clientStatus.XOffset = 10; clientStatus.YOffset = blockSize * 2 + 15; clientStatus.Init(); @@ -252,9 +250,7 @@ namespace ClassicalSharp.Gui { game.chatInInputBuffer = null; } chatFont.Dispose(); - chatItalicFont.Dispose(); - chatBoldFont.Dispose(); - chatUnderlineFont.Dispose(); + chatUrlFont.Dispose(); announcementFont.Dispose(); normalChat.Dispose(); diff --git a/ClassicalSharp/2D/Screens/Menu/GraphicsOptionsScreen.cs b/ClassicalSharp/2D/Screens/Menu/GraphicsOptionsScreen.cs index c44cff1a7..405e771d5 100644 --- a/ClassicalSharp/2D/Screens/Menu/GraphicsOptionsScreen.cs +++ b/ClassicalSharp/2D/Screens/Menu/GraphicsOptionsScreen.cs @@ -13,7 +13,6 @@ namespace ClassicalSharp.Gui { public override void Init() { base.Init(); - INetworkProcessor network = game.Network; extHelpY = 50; widgets = new Widget[] { @@ -49,7 +48,6 @@ namespace ClassicalSharp.Gui { } void MakeValidators() { - INetworkProcessor network = game.Network; validators = new MenuInputValidator[] { new EnumValidator( typeof(FpsLimitMethod) ), new IntegerValidator( 16, 4096 ), diff --git a/ClassicalSharp/2D/Widgets/Chat/TextInputWidget.cs b/ClassicalSharp/2D/Widgets/Chat/TextInputWidget.cs index 68bc2439b..aefba5c76 100644 --- a/ClassicalSharp/2D/Widgets/Chat/TextInputWidget.cs +++ b/ClassicalSharp/2D/Widgets/Chat/TextInputWidget.cs @@ -8,13 +8,13 @@ namespace ClassicalSharp.Gui { const int lines = 3; internal AltTextInputWidget altText; - public TextInputWidget( Game game, Font font, Font boldFont ) : base( game ) { + public TextInputWidget( Game game, Font font ) : base( game ) { HorizontalAnchor = Anchor.LeftOrTop; VerticalAnchor = Anchor.BottomOrRight; typingLogPos = game.Chat.InputLog.Count; // Index of newest entry + 1. buffer = new WrappableStringBuffer( 64 * lines ); - DrawTextArgs args = new DrawTextArgs( "_", boldFont, true ); + DrawTextArgs args = new DrawTextArgs( "_", font, true ); caretTex = game.Drawer2D.MakeChatTextTexture( ref args, 0, 0 ); caretTex.Width = (caretTex.Width * 3) / 4; defaultCaretWidth = caretTex.Width; diff --git a/ClassicalSharp/2D/Widgets/PlayerList/ExtPlayerListWidget.cs b/ClassicalSharp/2D/Widgets/PlayerList/ExtPlayerListWidget.cs index e4ad61bd6..50b43b0b2 100644 --- a/ClassicalSharp/2D/Widgets/PlayerList/ExtPlayerListWidget.cs +++ b/ClassicalSharp/2D/Widgets/PlayerList/ExtPlayerListWidget.cs @@ -10,7 +10,7 @@ namespace ClassicalSharp.Gui { public ExtPlayerListWidget( Game game, Font font ) : base( game, font ) { textures = new Texture[512]; - titleFont = new Font( game.FontName, font.Size, FontStyle.Italic ); + titleFont = new Font( game.FontName, font.Size ); elementOffset = 10; } diff --git a/ClassicalSharp/Events/WorldEvents.cs b/ClassicalSharp/Events/WorldEvents.cs index 46b40bf96..fcdc97ed0 100644 --- a/ClassicalSharp/Events/WorldEvents.cs +++ b/ClassicalSharp/Events/WorldEvents.cs @@ -51,7 +51,7 @@ namespace ClassicalSharp.Events { SunlightColour, ShadowlightColour, - RainSpeed, - SnowSpeed, + WeatherSpeed, + WeatherFade, } } diff --git a/ClassicalSharp/Map/WorldEnv.cs b/ClassicalSharp/Map/WorldEnv.cs index 703e7cb07..a1b848292 100644 --- a/ClassicalSharp/Map/WorldEnv.cs +++ b/ClassicalSharp/Map/WorldEnv.cs @@ -28,11 +28,8 @@ namespace ClassicalSharp.Map { /// Modifier of how fast clouds travel across the world, defaults to 1. public float CloudsSpeed = 1; - /// Modifier of how fast rain falls, defaults to 1. - public float RainSpeed = 1; - - /// Modifier of how fast snow falls, defaults to 1. - public float SnowSpeed = 1; + /// Modifier of how fast rain/snow falls, defaults to 1. + public float WeatherSpeed = 1; /// Modifier of how fast rain/snow fades, defaults to 1. public float WeatherFade = 1; @@ -76,8 +73,7 @@ namespace ClassicalSharp.Map { EdgeBlock = Block.StillWater; SidesBlock = Block.Bedrock; CloudsSpeed = 1; - RainSpeed = 1; - SnowSpeed = 1; + WeatherSpeed = 1; WeatherFade = 1; ResetLight(); @@ -128,13 +124,13 @@ namespace ClassicalSharp.Map { /// event with variable 'CloudsSpeed'. public void SetCloudsSpeed( float speed ) { Set( speed, ref CloudsSpeed, EnvVar.CloudsSpeed ); } - /// Sets rain speed and raises EnvVariableChanged - /// event with variable 'RainSpeed'. - public void SetRainSpeed( float speed ) { Set( speed, ref RainSpeed, EnvVar.RainSpeed ); } + /// Sets weather speed, and raises EnvVariableChanged + /// event with variable 'WeatherSpeed'. + public void SetWeatherSpeed( float speed ) { Set( speed, ref WeatherSpeed, EnvVar.WeatherSpeed ); } - /// Sets snow speed, and raises EnvVariableChanged - /// event with variable 'SnowSpeed'. - public void SetSnowSpeed( float speed ) { Set( speed, ref SnowSpeed, EnvVar.SnowSpeed ); } + /// Sets weather fade rate, and raises EnvVariableChanged + /// event with variable 'WeatherFade'. + public void SetWeatherFade( float rate ) { Set( rate, ref WeatherFade, EnvVar.WeatherFade ); } /// Sets height of the map edges in world space, and raises /// EnvVariableChanged event with variable 'EdgeLevel'. diff --git a/ClassicalSharp/Network/NetworkProcessor.CPE.cs b/ClassicalSharp/Network/NetworkProcessor.CPE.cs index 58ab0503d..ae81dda92 100644 --- a/ClassicalSharp/Network/NetworkProcessor.CPE.cs +++ b/ClassicalSharp/Network/NetworkProcessor.CPE.cs @@ -377,9 +377,30 @@ namespace ClassicalSharp.Network { internal void HandleSetEnvMapProperty() { byte type = reader.ReadUInt8(); int value = reader.ReadInt32(); + WorldEnv env = game.World.Env; + Utils.Clamp( ref value, short.MinValue, short.MaxValue ); switch( type ) { - // TODO: Property list + case 0: + Utils.Clamp( ref value, byte.MinValue, byte.MaxValue ); + env.SetSidesBlock( (Block)value ); break; + case 1: + Utils.Clamp( ref value, byte.MinValue, byte.MaxValue ); + env.SetEdgeBlock( (Block)value ); break; + case 2: + env.SetEdgeLevel( value ); break; + case 3: + env.SetCloudsLevel( value ); break; + case 4: + game.MaxViewDistance = value <= 0 ? 32768 : value; + game.SetViewDistance( game.UserViewDistance, false ); break; + case 5: + env.SetCloudsSpeed( value / 256f ); break; + case 6: + env.SetWeatherSpeed( value / 256f ); break; + case 7: + Utils.Clamp( ref value, byte.MinValue, byte.MaxValue ); + env.SetWeatherFade( value / 256f ); break; } } } diff --git a/ClassicalSharp/Rendering/WeatherRenderer.cs b/ClassicalSharp/Rendering/WeatherRenderer.cs index d728bf47c..e2a8f2f7e 100644 --- a/ClassicalSharp/Rendering/WeatherRenderer.cs +++ b/ClassicalSharp/Rendering/WeatherRenderer.cs @@ -45,8 +45,7 @@ namespace ClassicalSharp.Renderers { lastPos = pos; WorldEnv env = game.World.Env; - float speed = weather == Weather.Rainy ? - 1.0f * env.RainSpeed : 0.2f * env.SnowSpeed; + float speed = (weather == Weather.Rainy ? 1.0f : 0.2f) * env.WeatherSpeed; vOffset = -(float)game.accumulator * speed; rainAcc += deltaTime; bool particles = weather == Weather.Rainy;