From 4f546b80d5b922d7b28de5f632d27d2d876d15c3 Mon Sep 17 00:00:00 2001 From: UnknownShadow200 Date: Sat, 14 Nov 2015 15:47:35 +1100 Subject: [PATCH] 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. --- ClassicalSharp/2D/Screens/ChatScreen.cs | 16 ++++++++++++++-- .../2D/Widgets/Chat/TextGroupWidget.cs | 14 ++++++++++++++ 2 files changed, 28 insertions(+), 2 deletions(-) diff --git a/ClassicalSharp/2D/Screens/ChatScreen.cs b/ClassicalSharp/2D/Screens/ChatScreen.cs index bac8436ee..ddee33af0 100644 --- a/ClassicalSharp/2D/Screens/ChatScreen.cs +++ b/ClassicalSharp/2D/Screens/ChatScreen.cs @@ -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 ); } diff --git a/ClassicalSharp/2D/Widgets/Chat/TextGroupWidget.cs b/ClassicalSharp/2D/Widgets/Chat/TextGroupWidget.cs index c6906b3b0..3e8d2ebe9 100644 --- a/ClassicalSharp/2D/Widgets/Chat/TextGroupWidget.cs +++ b/ClassicalSharp/2D/Widgets/Chat/TextGroupWidget.cs @@ -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; + } } } \ No newline at end of file