mirror of
https://github.com/ClassiCube/ClassiCube.git
synced 2025-09-09 23:41:09 -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() {
|
public override void Init() {
|
||||||
textInput = new TextInputWidget( Window );
|
int fontSize = Window.ChatFontSize;
|
||||||
|
textInput = new TextInputWidget( Window, fontSize );
|
||||||
textInput.ChatInputYOffset = ChatInputYOffset;
|
textInput.ChatInputYOffset = ChatInputYOffset;
|
||||||
status = new TextGroupWidget( Window, 3 );
|
status = new TextGroupWidget( Window, 3, fontSize );
|
||||||
status.VerticalDocking = Docking.LeftOrTop;
|
status.VerticalDocking = Docking.LeftOrTop;
|
||||||
status.HorizontalDocking = Docking.BottomOrRight;
|
status.HorizontalDocking = Docking.BottomOrRight;
|
||||||
status.Init();
|
status.Init();
|
||||||
bottomRight = new TextGroupWidget( Window, 3 );
|
bottomRight = new TextGroupWidget( Window, 3, fontSize );
|
||||||
bottomRight.VerticalDocking = Docking.BottomOrRight;
|
bottomRight.VerticalDocking = Docking.BottomOrRight;
|
||||||
bottomRight.HorizontalDocking = Docking.BottomOrRight;
|
bottomRight.HorizontalDocking = Docking.BottomOrRight;
|
||||||
bottomRight.Init();
|
bottomRight.Init();
|
||||||
normalChat = new TextGroupWidget( Window, chatLines );
|
normalChat = new TextGroupWidget( Window, chatLines, fontSize );
|
||||||
normalChat.XOffset = 10;
|
normalChat.XOffset = 10;
|
||||||
normalChat.YOffset = ChatLogYOffset;
|
normalChat.YOffset = ChatLogYOffset;
|
||||||
normalChat.HorizontalDocking = Docking.LeftOrTop;
|
normalChat.HorizontalDocking = Docking.LeftOrTop;
|
||||||
|
@ -6,19 +6,21 @@ namespace ClassicalSharp {
|
|||||||
|
|
||||||
public sealed class TextGroupWidget : Widget {
|
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;
|
ElementsCount = elementsCount;
|
||||||
|
this.fontSize = fontSize;
|
||||||
}
|
}
|
||||||
|
|
||||||
Texture[] textures;
|
Texture[] textures;
|
||||||
string[] textCache;
|
string[] textCache;
|
||||||
int ElementsCount, defaultHeight;
|
int ElementsCount, defaultHeight;
|
||||||
public int XOffset = 0, YOffset = 0;
|
public int XOffset = 0, YOffset = 0;
|
||||||
|
readonly int fontSize;
|
||||||
|
|
||||||
public override void Init() {
|
public override void Init() {
|
||||||
textures = new Texture[ElementsCount];
|
textures = new Texture[ElementsCount];
|
||||||
textCache = new string[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++ ) {
|
for( int i = 0; i < textures.Length; i++ ) {
|
||||||
textures[i].Height = defaultHeight;
|
textures[i].Height = defaultHeight;
|
||||||
}
|
}
|
||||||
@ -31,13 +33,13 @@ namespace ClassicalSharp {
|
|||||||
Size size = new Size( 0, defaultHeight );
|
Size size = new Size( 0, defaultHeight );
|
||||||
if( !String.IsNullOrEmpty( text ) ) {
|
if( !String.IsNullOrEmpty( text ) ) {
|
||||||
parts = Utils.SplitText( GraphicsApi, text, true );
|
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 x = HorizontalDocking == Docking.LeftOrTop ? XOffset : Window.Width - size.Width - XOffset;
|
||||||
int y = CalcY( index, size.Height );
|
int y = CalcY( index, size.Height );
|
||||||
if( !String.IsNullOrEmpty( text ) ) {
|
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 {
|
} else {
|
||||||
textures[index] = new Texture( -1, 0, 0, 0, defaultHeight, 0, 0 );
|
textures[index] = new Texture( -1, 0, 0, 0, defaultHeight, 0, 0 );
|
||||||
}
|
}
|
||||||
|
@ -7,7 +7,7 @@ namespace ClassicalSharp {
|
|||||||
|
|
||||||
public sealed class TextInputWidget : Widget {
|
public sealed class TextInputWidget : Widget {
|
||||||
|
|
||||||
public TextInputWidget( Game window ) : base( window ) {
|
public TextInputWidget( Game window, int fontSize ) : base( window ) {
|
||||||
HorizontalDocking = Docking.LeftOrTop;
|
HorizontalDocking = Docking.LeftOrTop;
|
||||||
VerticalDocking = Docking.BottomOrRight;
|
VerticalDocking = Docking.BottomOrRight;
|
||||||
handlers[0] = new InputHandler( BackspaceKey, Key.BackSpace, 10 );
|
handlers[0] = new InputHandler( BackspaceKey, Key.BackSpace, 10 );
|
||||||
@ -17,6 +17,7 @@ namespace ClassicalSharp {
|
|||||||
handlers[4] = new InputHandler( UpKey, Key.Up, 5 );
|
handlers[4] = new InputHandler( UpKey, Key.Up, 5 );
|
||||||
handlers[5] = new InputHandler( DownKey, Key.Down, 5 );
|
handlers[5] = new InputHandler( DownKey, Key.Down, 5 );
|
||||||
typingLogPos = Window.ChatInputLog.Count; // Index of newest entry + 1.
|
typingLogPos = Window.ChatInputLog.Count; // Index of newest entry + 1.
|
||||||
|
this.fontSize = fontSize;
|
||||||
}
|
}
|
||||||
|
|
||||||
Texture chatInputTexture, chatCaretTexture;
|
Texture chatInputTexture, chatCaretTexture;
|
||||||
@ -25,6 +26,7 @@ namespace ClassicalSharp {
|
|||||||
int typingLogPos = 0;
|
int typingLogPos = 0;
|
||||||
public int ChatInputYOffset;
|
public int ChatInputYOffset;
|
||||||
public string chatInputText = "";
|
public string chatInputText = "";
|
||||||
|
readonly int fontSize;
|
||||||
|
|
||||||
public override void Render( double delta ) {
|
public override void Render( double delta ) {
|
||||||
chatInputTexture.Render( GraphicsApi );
|
chatInputTexture.Render( GraphicsApi );
|
||||||
@ -35,20 +37,20 @@ namespace ClassicalSharp {
|
|||||||
public override void Init() {
|
public override void Init() {
|
||||||
X = 10;
|
X = 10;
|
||||||
DrawTextArgs caretArgs = new DrawTextArgs( GraphicsApi, "_", Color.White, false );
|
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 ) {
|
if( chatInputText.Length == 0 ) {
|
||||||
caretPos = -1;
|
caretPos = -1;
|
||||||
}
|
}
|
||||||
Size size = Utils2D.MeasureSize( chatInputText, "Arial", 12, false );
|
Size size = Utils2D.MeasureSize( chatInputText, "Arial", fontSize, false );
|
||||||
|
|
||||||
if( caretPos == -1 ) {
|
if( caretPos == -1 ) {
|
||||||
chatCaretTexture.X1 = 10 + size.Width;
|
chatCaretTexture.X1 = 10 + size.Width;
|
||||||
size.Width += chatCaretTexture.Width;
|
size.Width += chatCaretTexture.Width;
|
||||||
} else {
|
} 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;
|
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;
|
chatCaretTexture.Width = charSize.Width;
|
||||||
}
|
}
|
||||||
size.Height = Math.Max( size.Height, chatCaretTexture.Height );
|
size.Height = Math.Max( size.Height, chatCaretTexture.Height );
|
||||||
@ -58,7 +60,7 @@ namespace ClassicalSharp {
|
|||||||
using( Graphics g = Graphics.FromImage( bmp ) ) {
|
using( Graphics g = Graphics.FromImage( bmp ) ) {
|
||||||
Utils2D.DrawRect( g, backColour, bmp.Width, bmp.Height );
|
Utils2D.DrawRect( g, backColour, bmp.Width, bmp.Height );
|
||||||
DrawTextArgs args = new DrawTextArgs( GraphicsApi, chatInputText, Color.White, false );
|
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 );
|
chatInputTexture = Utils2D.Make2DTexture( GraphicsApi, bmp, 10, y );
|
||||||
}
|
}
|
||||||
|
@ -4,9 +4,8 @@ using System.Drawing;
|
|||||||
|
|
||||||
namespace ClassicalSharp {
|
namespace ClassicalSharp {
|
||||||
|
|
||||||
public sealed class TextWidget : Widget {
|
public sealed class TextWidget : Widget {
|
||||||
|
|
||||||
int fontSize;
|
|
||||||
public TextWidget( Game window, int fontSize ) : base( window ) {
|
public TextWidget( Game window, int fontSize ) : base( window ) {
|
||||||
this.fontSize = fontSize;
|
this.fontSize = fontSize;
|
||||||
}
|
}
|
||||||
@ -16,6 +15,7 @@ namespace ClassicalSharp {
|
|||||||
public int XOffset = 0, YOffset = 0;
|
public int XOffset = 0, YOffset = 0;
|
||||||
public FontStyle Style = FontStyle.Regular;
|
public FontStyle Style = FontStyle.Regular;
|
||||||
int defaultHeight;
|
int defaultHeight;
|
||||||
|
readonly int fontSize;
|
||||||
|
|
||||||
public override void Init() {
|
public override void Init() {
|
||||||
defaultHeight = Utils2D.MeasureSize( "I", "Arial", fontSize, Style, true ).Height;
|
defaultHeight = Utils2D.MeasureSize( "I", "Arial", fontSize, Style, true ).Height;
|
||||||
|
@ -18,6 +18,7 @@ namespace ClassicalSharp.Commands {
|
|||||||
RegisterCommand( new EnvCommand() );
|
RegisterCommand( new EnvCommand() );
|
||||||
RegisterCommand( new InfoCommand() );
|
RegisterCommand( new InfoCommand() );
|
||||||
RegisterCommand( new RenderTypeCommand() );
|
RegisterCommand( new RenderTypeCommand() );
|
||||||
|
RegisterCommand( new ChatFontSizeCommand() );
|
||||||
}
|
}
|
||||||
|
|
||||||
void RegisterCommand( Command command ) {
|
void RegisterCommand( Command command ) {
|
||||||
|
@ -229,4 +229,41 @@ namespace ClassicalSharp.Commands {
|
|||||||
game.EnvRenderer.Init();
|
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 List<string> ChatInputLog = new List<string>();
|
||||||
|
|
||||||
|
public int ChatFontSize = 12;
|
||||||
|
|
||||||
public void SendChat( string text ) {
|
public void SendChat( string text ) {
|
||||||
if( String.IsNullOrEmpty( text ) ) return;
|
if( String.IsNullOrEmpty( text ) ) return;
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user