mirror of
https://github.com/ClassiCube/ClassiCube.git
synced 2025-09-08 14:56:12 -04:00
Add command (/client chatsize) to change font size of chat.
This commit is contained in:
parent
adc784d2e7
commit
0fb7924f89
@ -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;
|
||||
|
@ -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 );
|
||||
}
|
||||
|
@ -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 );
|
||||
}
|
||||
|
@ -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;
|
||||
|
@ -18,6 +18,7 @@ namespace ClassicalSharp.Commands {
|
||||
RegisterCommand( new EnvCommand() );
|
||||
RegisterCommand( new InfoCommand() );
|
||||
RegisterCommand( new RenderTypeCommand() );
|
||||
RegisterCommand( new ChatFontSizeCommand() );
|
||||
}
|
||||
|
||||
void RegisterCommand( Command command ) {
|
||||
|
@ -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 ) );
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -20,6 +20,8 @@ namespace ClassicalSharp {
|
||||
|
||||
public List<string> ChatInputLog = new List<string>();
|
||||
|
||||
public int ChatFontSize = 12;
|
||||
|
||||
public void SendChat( string text ) {
|
||||
if( String.IsNullOrEmpty( text ) ) return;
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user