If you click on a chatline in the normal chat widget while the text input bar is open, the chatline will be added to the text input bar.

This commit is contained in:
UnknownShadow200 2015-11-14 15:47:35 +11:00
parent 70a2fc868f
commit 4f546b80d5
2 changed files with 28 additions and 2 deletions

View File

@ -28,7 +28,7 @@ namespace ClassicalSharp {
if( HandlesAllInput )
normalChat.Render( delta );
else
RenderRecentChat( now, delta );
RenderRecentChat( now, delta );
if( announcementTex.IsValid )
announcementTex.Render( graphicsApi );
@ -235,7 +235,7 @@ namespace ClassicalSharp {
suppressNextPress = false;
if( HandlesAllInput ) { // text input bar
if( key == game.Mapping( KeyBinding.SendChat )
if( key == game.Mapping( KeyBinding.SendChat )
|| key == game.Mapping( KeyBinding.PauseOrExit ) ) {
HandlesAllInput = false;
if( game.CursorVisible )
@ -282,6 +282,18 @@ namespace ClassicalSharp {
public override bool HandlesMouseClick( int mouseX, int mouseY, MouseButton button ) {
if( !HandlesAllInput ) return false;
if( normalChat.Bounds.Contains( mouseX, mouseY ) ) {
int height = normalChat.GetUsedHeight();
int y = normalChat.Y + normalChat.Height - height;
if( new Rectangle( normalChat.X, y, normalChat.Width, height ).Contains( mouseX, mouseY ) ) {
string text = normalChat.GetSelected( mouseX, mouseY );
if( text != null ) {
textInput.AppendText(text);
return true;
}
}
return false;
}
return textInput.HandlesMouseClick( mouseX, mouseY, button );
}

View File

@ -12,12 +12,14 @@ namespace ClassicalSharp {
}
public Texture[] Textures;
string[] lines;
int ElementsCount, defaultHeight;
public int XOffset = 0, YOffset = 0;
readonly Font font;
public override void Init() {
Textures = new Texture[ElementsCount];
lines = new string[ElementsCount];
DrawTextArgs args = new DrawTextArgs( "I", font, true );
defaultHeight = game.Drawer2D.MeasureChatSize( ref args ).Height;
@ -38,8 +40,10 @@ namespace ClassicalSharp {
tex.X1 = CalcOffset( game.Width, tex.Width, XOffset, HorizontalAnchor );
tex.Y1 = CalcY( index, tex.Height );
Textures[index] = tex;
lines[index] = text;
} else {
Textures[index] = new Texture( -1, 0, 0, 0, defaultHeight, 0, 0 );
lines[index] = null;
}
UpdateDimensions();
}
@ -49,6 +53,7 @@ namespace ClassicalSharp {
graphicsApi.DeleteTexture( ref Textures[0] );
for( int i = 0; i < Textures.Length - 1; i++ ) {
Textures[i] = Textures[i + 1];
lines[i] = lines[i + 1];
Textures[i].Y1 = y;
y += Textures[i].Height;
}
@ -123,5 +128,14 @@ namespace ClassicalSharp {
}
X = newX; Y = newY;
}
public string GetSelected( int mouseX, int mouseY ) {
for( int i = 0; i < Textures.Length; i++ ) {
if( Textures[i].IsValid &&
Textures[i].Bounds.Contains( mouseX, mouseY ) )
return lines[i];
}
return null;
}
}
}