mirror of
https://github.com/ClassiCube/ClassiCube.git
synced 2025-01-24 10:02:08 -05:00
Fix very rare crash when the server supports partial messages but the user's chat font has never changed and you try to paste text for all three lines. (Thanks MrGoober and tornato)
This commit is contained in:
parent
9f933ac1d6
commit
0b1e9af081
4 changed files with 19 additions and 14 deletions
|
@ -25,7 +25,8 @@ namespace ClassicalSharp.Gui {
|
|||
|
||||
Font chatFont, chatBoldFont, chatItalicFont, chatUnderlineFont, announcementFont;
|
||||
public override void Init() {
|
||||
int fontSize = (int)(12 * game.GuiChatScale);
|
||||
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 );
|
||||
|
|
|
@ -12,7 +12,7 @@ namespace ClassicalSharp.Gui {
|
|||
HorizontalAnchor = Anchor.LeftOrTop;
|
||||
VerticalAnchor = Anchor.BottomOrRight;
|
||||
typingLogPos = game.Chat.InputLog.Count; // Index of newest entry + 1.
|
||||
chatInputText = new WrappableStringBuffer( TotalChars );
|
||||
chatInputText = new WrappableStringBuffer( 64 * lines );
|
||||
|
||||
DrawTextArgs args = new DrawTextArgs( "_", boldFont, true );
|
||||
caretTex = game.Drawer2D.MakeChatTextTexture( ref args, 0, 0 );
|
||||
|
@ -72,7 +72,8 @@ namespace ClassicalSharp.Gui {
|
|||
|
||||
public override void Init() {
|
||||
X = 5;
|
||||
chatInputText.WordWrap( game.Drawer2D, ref parts, ref partLens, LineLength );
|
||||
chatInputText.WordWrap( game.Drawer2D, ref parts, ref partLens,
|
||||
LineLength, TotalChars );
|
||||
|
||||
for( int y = 0; y < sizes.Length; y++ )
|
||||
sizes[y] = Size.Empty;
|
||||
|
|
|
@ -52,10 +52,10 @@ namespace ClassicalSharp {
|
|||
width = 640; height = 480;
|
||||
|
||||
if( device.Width >= 1024 && device.Height >= 768 ) {
|
||||
//width = 800; height = 600;
|
||||
width = 800; height = 600;
|
||||
}
|
||||
if( device.Width >= 1920 && device.Height >= 1080 ) {
|
||||
//width = 1600; height = 900;
|
||||
width = 1600; height = 900;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -11,7 +11,8 @@ namespace ClassicalSharp {
|
|||
wrap = new char[capacity];
|
||||
}
|
||||
|
||||
public void WordWrap( IDrawer2D drawer, ref string[] lines, ref int[] lineLens, int lineSize ) {
|
||||
public void WordWrap( IDrawer2D drawer, ref string[] lines, ref int[] lineLens,
|
||||
int lineSize, int totalChars ) {
|
||||
int len = Length;
|
||||
for( int i = 0; i < lines.Length; i++ ) {
|
||||
lines[i] = null;
|
||||
|
@ -23,16 +24,16 @@ namespace ClassicalSharp {
|
|||
MakeWrapCopy();
|
||||
|
||||
int linesCount = 0;
|
||||
for( int index = 0; index < capacity; index += lineSize ) {
|
||||
for( int index = 0; index < totalChars; index += lineSize ) {
|
||||
if( value[index] == '\0' )
|
||||
break;
|
||||
|
||||
int lineEnd = index + (lineSize - 1);
|
||||
int nextLine = index + lineSize;
|
||||
int lineEnd = index + (lineSize - 1), nextLine = lineEnd + 1;
|
||||
linesCount++;
|
||||
|
||||
// Do we need word wrapping?
|
||||
bool needWrap = !IsWrapper( value[lineEnd] ) && nextLine < capacity && !IsWrapper( value[nextLine] );
|
||||
bool needWrap = !IsWrapper( value[lineEnd] )
|
||||
&& nextLine < totalChars && !IsWrapper( value[nextLine] );
|
||||
int wrappedLen = needWrap ? WrapLine( index, lineSize ) : lineSize;
|
||||
|
||||
// Calculate the maximum size of this line
|
||||
|
@ -45,7 +46,8 @@ namespace ClassicalSharp {
|
|||
}
|
||||
|
||||
// Output the used lines
|
||||
OutputLines( drawer, ref lines, linesCount, lineSize, lineLens );
|
||||
OutputLines( drawer, ref lines, lineLens,
|
||||
linesCount, lineSize, totalChars );
|
||||
value = realText;
|
||||
}
|
||||
|
||||
|
@ -59,12 +61,13 @@ namespace ClassicalSharp {
|
|||
value = wrap;
|
||||
}
|
||||
|
||||
void OutputLines( IDrawer2D drawer, ref string[] lines, int linesCount, int lineSize, int[] lineLens ) {
|
||||
for( int i = 0; i < capacity; i++ ) {
|
||||
void OutputLines( IDrawer2D drawer, ref string[] lines, int[] lineLens,
|
||||
int linesCount, int lineSize, int totalChars ) {
|
||||
for( int i = 0; i < totalChars; i++ ) {
|
||||
if( value[i] == '\0' ) value[i] = ' ';
|
||||
}
|
||||
// convert %0-f to &0-f for colour preview.
|
||||
for( int i = 0; i < capacity - 1; i++ ) {
|
||||
for( int i = 0; i < totalChars - 1; i++ ) {
|
||||
if( value[i] == '%' && drawer.ValidColour( value[i + 1] ) )
|
||||
value[i] = '&';
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue