diff --git a/2D/Screens/ChatScreen.cs b/2D/Screens/ChatScreen.cs index 637f86007..dd4dec997 100644 --- a/2D/Screens/ChatScreen.cs +++ b/2D/Screens/ChatScreen.cs @@ -44,17 +44,18 @@ namespace ClassicalSharp { } public override void Init() { - textInput = new TextInputWidget( Window ); + int fontSize = Window.ChatFontSize; + textInput = new TextInputWidget( Window, fontSize ); textInput.ChatInputYOffset = ChatInputYOffset; - status = new TextGroupWidget( Window, 3 ); + status = new TextGroupWidget( Window, 3, fontSize ); status.VerticalDocking = Docking.LeftOrTop; status.HorizontalDocking = Docking.BottomOrRight; status.Init(); - bottomRight = new TextGroupWidget( Window, 3 ); + bottomRight = new TextGroupWidget( Window, 3, fontSize ); bottomRight.VerticalDocking = Docking.BottomOrRight; bottomRight.HorizontalDocking = Docking.BottomOrRight; bottomRight.Init(); - normalChat = new TextGroupWidget( Window, chatLines ); + normalChat = new TextGroupWidget( Window, chatLines, fontSize ); normalChat.XOffset = 10; normalChat.YOffset = ChatLogYOffset; normalChat.HorizontalDocking = Docking.LeftOrTop; diff --git a/2D/Widgets/TextGroupWidget.cs b/2D/Widgets/TextGroupWidget.cs index cf24b29bd..87875d060 100644 --- a/2D/Widgets/TextGroupWidget.cs +++ b/2D/Widgets/TextGroupWidget.cs @@ -6,19 +6,21 @@ namespace ClassicalSharp { public sealed class TextGroupWidget : Widget { - public TextGroupWidget( Game window, int elementsCount ) : base( window ) { + public TextGroupWidget( Game window, int elementsCount, int fontSize ) : base( window ) { ElementsCount = elementsCount; + this.fontSize = fontSize; } Texture[] textures; string[] textCache; int ElementsCount, defaultHeight; public int XOffset = 0, YOffset = 0; + readonly int fontSize; public override void Init() { textures = new Texture[ElementsCount]; textCache = new string[ElementsCount]; - defaultHeight = Utils2D.MeasureSize( "I", "Arial", 12, true ).Height; + defaultHeight = Utils2D.MeasureSize( "I", "Arial", fontSize, true ).Height; for( int i = 0; i < textures.Length; i++ ) { textures[i].Height = defaultHeight; } @@ -31,13 +33,13 @@ namespace ClassicalSharp { Size size = new Size( 0, defaultHeight ); if( !String.IsNullOrEmpty( text ) ) { parts = Utils.SplitText( GraphicsApi, text, true ); - size = Utils2D.MeasureSize( Utils.StripColours( text ), "Arial", 12, true ); + size = Utils2D.MeasureSize( Utils.StripColours( text ), "Arial", fontSize, true ); } int x = HorizontalDocking == Docking.LeftOrTop ? XOffset : Window.Width - size.Width - XOffset; int y = CalcY( index, size.Height ); if( !String.IsNullOrEmpty( text ) ) { - textures[index] = Utils2D.MakeTextTexture( parts, "Arial", 12, size, x, y ); + textures[index] = Utils2D.MakeTextTexture( parts, "Arial", fontSize, size, x, y ); } else { textures[index] = new Texture( -1, 0, 0, 0, defaultHeight, 0, 0 ); } diff --git a/2D/Widgets/TextInputWidget.cs b/2D/Widgets/TextInputWidget.cs index 834e9f593..90536a5aa 100644 --- a/2D/Widgets/TextInputWidget.cs +++ b/2D/Widgets/TextInputWidget.cs @@ -7,7 +7,7 @@ namespace ClassicalSharp { public sealed class TextInputWidget : Widget { - public TextInputWidget( Game window ) : base( window ) { + public TextInputWidget( Game window, int fontSize ) : base( window ) { HorizontalDocking = Docking.LeftOrTop; VerticalDocking = Docking.BottomOrRight; handlers[0] = new InputHandler( BackspaceKey, Key.BackSpace, 10 ); @@ -17,6 +17,7 @@ namespace ClassicalSharp { handlers[4] = new InputHandler( UpKey, Key.Up, 5 ); handlers[5] = new InputHandler( DownKey, Key.Down, 5 ); typingLogPos = Window.ChatInputLog.Count; // Index of newest entry + 1. + this.fontSize = fontSize; } Texture chatInputTexture, chatCaretTexture; @@ -25,6 +26,7 @@ namespace ClassicalSharp { int typingLogPos = 0; public int ChatInputYOffset; public string chatInputText = ""; + readonly int fontSize; public override void Render( double delta ) { chatInputTexture.Render( GraphicsApi ); @@ -35,20 +37,20 @@ namespace ClassicalSharp { public override void Init() { X = 10; DrawTextArgs caretArgs = new DrawTextArgs( GraphicsApi, "_", Color.White, false ); - chatCaretTexture = Utils2D.MakeTextTexture( "Arial", 12, FontStyle.Bold, 0, 0, caretArgs ); + chatCaretTexture = Utils2D.MakeTextTexture( "Arial", fontSize, FontStyle.Bold, 0, 0, caretArgs ); if( chatInputText.Length == 0 ) { caretPos = -1; } - Size size = Utils2D.MeasureSize( chatInputText, "Arial", 12, false ); + Size size = Utils2D.MeasureSize( chatInputText, "Arial", fontSize, false ); if( caretPos == -1 ) { chatCaretTexture.X1 = 10 + size.Width; size.Width += chatCaretTexture.Width; } else { - Size trimmedSize = Utils2D.MeasureSize( chatInputText.Substring( 0, caretPos ), "Arial", 12, false ); + Size trimmedSize = Utils2D.MeasureSize( chatInputText.Substring( 0, caretPos ), "Arial", fontSize, false ); chatCaretTexture.X1 = 10 + trimmedSize.Width; - Size charSize = Utils2D.MeasureSize( chatInputText.Substring( caretPos, 1 ), "Arial", 12, false ); + Size charSize = Utils2D.MeasureSize( chatInputText.Substring( caretPos, 1 ), "Arial", fontSize, false ); chatCaretTexture.Width = charSize.Width; } size.Height = Math.Max( size.Height, chatCaretTexture.Height ); @@ -58,7 +60,7 @@ namespace ClassicalSharp { using( Graphics g = Graphics.FromImage( bmp ) ) { Utils2D.DrawRect( g, backColour, bmp.Width, bmp.Height ); DrawTextArgs args = new DrawTextArgs( GraphicsApi, chatInputText, Color.White, false ); - Utils2D.DrawText( g, "Arial", 12, args ); + Utils2D.DrawText( g, "Arial", fontSize, args ); } chatInputTexture = Utils2D.Make2DTexture( GraphicsApi, bmp, 10, y ); } diff --git a/2D/Widgets/TextWidget.cs b/2D/Widgets/TextWidget.cs index 87a56e96a..571c09499 100644 --- a/2D/Widgets/TextWidget.cs +++ b/2D/Widgets/TextWidget.cs @@ -4,9 +4,8 @@ using System.Drawing; namespace ClassicalSharp { - public sealed class TextWidget : Widget { + public sealed class TextWidget : Widget { - int fontSize; public TextWidget( Game window, int fontSize ) : base( window ) { this.fontSize = fontSize; } @@ -16,6 +15,7 @@ namespace ClassicalSharp { public int XOffset = 0, YOffset = 0; public FontStyle Style = FontStyle.Regular; int defaultHeight; + readonly int fontSize; public override void Init() { defaultHeight = Utils2D.MeasureSize( "I", "Arial", fontSize, Style, true ).Height; diff --git a/Commands/CommandManager.cs b/Commands/CommandManager.cs index 626a78cd9..cebcd1102 100644 --- a/Commands/CommandManager.cs +++ b/Commands/CommandManager.cs @@ -18,6 +18,7 @@ namespace ClassicalSharp.Commands { RegisterCommand( new EnvCommand() ); RegisterCommand( new InfoCommand() ); RegisterCommand( new RenderTypeCommand() ); + RegisterCommand( new ChatFontSizeCommand() ); } void RegisterCommand( Command command ) { diff --git a/Commands/DefaultCommands.cs b/Commands/DefaultCommands.cs index 5a7d74f0d..7302b2455 100644 --- a/Commands/DefaultCommands.cs +++ b/Commands/DefaultCommands.cs @@ -229,4 +229,41 @@ namespace ClassicalSharp.Commands { game.EnvRenderer.Init(); } } + + public sealed class ChatFontSizeCommand : Command { + + public override string Name { + get { return "ChatSize"; } + } + + public override string[] Help { + get { + return new [] { + "&a/client chatsize [fontsize]", + "&fontsize: &eWhole number specifying the new font size for chat.", + "&blegacy: &eMay be slightly slower than normal, but produces the same environmental effects.", + "&blegacyfast: &eSacrifices clouds, fog and overhead sky for faster performance.", + }; + } + } + + public override void Execute( CommandReader reader ) { + int fontSize; + if( !reader.NextInt( out fontSize ) ) { + Window.AddChat( "&e/client chatsize: &cInvalid font size." ); + } else { + if( fontSize < 6 ) { + Window.AddChat( "&e/client chatsize: &cFont size too small." ); + return; + } else if( fontSize > 30 ) { + Window.AddChat( "&e/client chatsize: &cFont size too big." ); + return; + } + Window.ChatFontSize = fontSize; + Window.SetNewScreen( null ); + Window.chatInInputBuffer = null; + Window.SetNewScreen( new NormalScreen( Window ) ); + } + } + } } diff --git a/Game/Game.Chat.cs b/Game/Game.Chat.cs index 464ee6cd0..b4d0a663b 100644 --- a/Game/Game.Chat.cs +++ b/Game/Game.Chat.cs @@ -20,6 +20,8 @@ namespace ClassicalSharp { public List ChatInputLog = new List(); + public int ChatFontSize = 12; + public void SendChat( string text ) { if( String.IsNullOrEmpty( text ) ) return;