mirror of
https://github.com/ClassiCube/ClassiCube.git
synced 2025-09-15 02:25:32 -04:00
Fix bug with initially scrolling in servers list, begin work on carets in text fields in the launcher.
This commit is contained in:
parent
c40c0d248e
commit
e3ce1d41f8
@ -177,6 +177,12 @@ namespace Launcher2 {
|
||||
boldInputFont.Dispose();
|
||||
tableFont.Dispose();
|
||||
game.Window.Mouse.WheelChanged -= MouseWheelChanged;
|
||||
|
||||
LauncherTableWidget table = widgets[tableIndex] as LauncherTableWidget;
|
||||
if( table != null ) {
|
||||
table.DraggingColumn = -1;
|
||||
table.DraggingScrollbar = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -29,26 +29,37 @@ namespace Launcher2 {
|
||||
}
|
||||
|
||||
protected virtual void KeyDown( object sender, KeyboardKeyEventArgs e ) {
|
||||
if( lastInput != null && e.Key == Key.BackSpace ) {
|
||||
if( lastInput.RemoveChar() ) {
|
||||
RedrawLastInput();
|
||||
OnRemovedChar();
|
||||
}
|
||||
} else if( e.Key == Key.Enter && enterIndex >= 0 ) {
|
||||
if( e.Key == Key.Enter && enterIndex >= 0 ) {
|
||||
LauncherWidget widget = (selectedWidget != null && mouseMoved) ?
|
||||
selectedWidget : widgets[enterIndex];
|
||||
if( widget.OnClick != null )
|
||||
widget.OnClick( 0, 0 );
|
||||
} else if( e.Key == Key.Tab ) {
|
||||
HandleTab();
|
||||
} else if( lastInput != null && e.Key == Key.C && ControlDown ) {
|
||||
}
|
||||
if( lastInput == null ) return;
|
||||
|
||||
|
||||
if( e.Key == Key.BackSpace && lastInput.BackspaceChar() ) {
|
||||
RedrawLastInput();
|
||||
OnRemovedChar();
|
||||
} else if( e.Key == Key.Delete && lastInput.DeleteChar() ) {
|
||||
RedrawLastInput();
|
||||
OnRemovedChar();
|
||||
} else if( e.Key == Key.C && ControlDown ) {
|
||||
lastInput.CopyToClipboard();
|
||||
} else if( lastInput != null && e.Key == Key.V && ControlDown ) {
|
||||
} else if( e.Key == Key.V && ControlDown ) {
|
||||
if( lastInput.CopyFromClipboard() )
|
||||
RedrawLastInput();
|
||||
} else if( lastInput != null && e.Key == Key.Escape ) {
|
||||
} else if( e.Key == Key.Escape ) {
|
||||
if( lastInput.ClearText() )
|
||||
RedrawLastInput();
|
||||
} else if( e.Key == Key.Left ) {
|
||||
lastInput.ChangeCursorPos( -1 );
|
||||
RedrawLastInput();
|
||||
} else if( e.Key == Key.Right ) {
|
||||
lastInput.ChangeCursorPos( +1 );
|
||||
RedrawLastInput();
|
||||
}
|
||||
}
|
||||
|
||||
@ -78,6 +89,7 @@ namespace Launcher2 {
|
||||
game.ClearArea( lastInput.X, lastInput.Y,
|
||||
lastInput.Width + 1, lastInput.Height + 1 );
|
||||
lastInput.Redraw( drawer, lastInput.Text, inputFont, inputHintFont );
|
||||
lastInput.DrawCursor( inputFont, drawer );
|
||||
Dirty = true;
|
||||
}
|
||||
}
|
||||
|
@ -76,7 +76,7 @@ namespace Launcher2 {
|
||||
protected override void SelectWidget( LauncherWidget widget ) {
|
||||
base.SelectWidget( widget );
|
||||
if( signingIn || !resumeValid || widget != widgets[4] ) return;
|
||||
const string format = "&eResume to {0}:{1}, with the name {2}";
|
||||
const string format = "&eResume to {0}:{1}, as {2}";
|
||||
SetStatusNoLock( String.Format( format, resumeIp, resumePort, resumeUser ) );
|
||||
}
|
||||
|
||||
|
@ -11,7 +11,7 @@ namespace Launcher2 {
|
||||
UptimeComparer uptimeComp = new UptimeComparer();
|
||||
SoftwareComparer softwareComp = new SoftwareComparer();
|
||||
public int DraggingColumn = -1;
|
||||
public bool DraggingScrollbar = true;
|
||||
public bool DraggingScrollbar = false;
|
||||
|
||||
void HandleOnClick( int mouseX, int mouseY ) {
|
||||
if( mouseX >= Window.Width - 10 ) {
|
||||
|
@ -31,10 +31,12 @@ namespace Launcher2 {
|
||||
/// <summary> Delegate that only lets certain characters be entered. </summary>
|
||||
public Func<char, bool> TextFilter;
|
||||
|
||||
public int CaretPos = -1;
|
||||
|
||||
public LauncherInputWidget( LauncherWindow window ) : base( window ) {
|
||||
}
|
||||
|
||||
public void DrawAt( IDrawer2D drawer, string text, Font font, Font hintFont,
|
||||
public void DrawAt( IDrawer2D drawer, string text, Font font, Font hintFont,
|
||||
Anchor horAnchor, Anchor verAnchor, int width, int height, int x, int y ) {
|
||||
ButtonWidth = width; ButtonHeight = height;
|
||||
Width = width; Height = height;
|
||||
@ -57,10 +59,11 @@ namespace Launcher2 {
|
||||
drawer.Clear( col, X + Width - 2, Y + 1, 2, Height - 2 );
|
||||
drawer.Clear( FastColour.Black, X + 2, Y + 2, Width - 4, Height - 4 );
|
||||
|
||||
args.SkipPartsCheck = true;
|
||||
args.SkipPartsCheck = true;
|
||||
if( Text.Length != 0 || HintText == null ) {
|
||||
int y = Y + 2 + (Height - size.Height) / 2;
|
||||
drawer.DrawText( ref args, X + 5, y );
|
||||
DrawCursor( font, drawer );
|
||||
} else {
|
||||
args.SkipPartsCheck = false;
|
||||
args.Text = HintText;
|
||||
@ -73,26 +76,87 @@ namespace Launcher2 {
|
||||
}
|
||||
}
|
||||
|
||||
public void DrawCursor( Font font, IDrawer2D drawer ) {
|
||||
string text = Text;
|
||||
if( Password )
|
||||
text = new String( '*', text.Length );
|
||||
|
||||
DrawTextArgs args = new DrawTextArgs( text, font, true );
|
||||
if( CaretPos == -1 ) {
|
||||
Size size = drawer.MeasureSize( ref args );
|
||||
drawer.Clear( FastColour.White, X + 5 + size.Width,
|
||||
Y + Height - 5, 10, 2 );
|
||||
} else {
|
||||
args.Text = text.Substring( 0, CaretPos );
|
||||
Size trimmedSize = drawer.MeasureChatSize( ref args );
|
||||
args.Text = new String( text[CaretPos], 1 );
|
||||
Size charSize = drawer.MeasureChatSize( ref args );
|
||||
|
||||
drawer.Clear( FastColour.White, X + 5 + trimmedSize.Width,
|
||||
Y + Height - 5, charSize.Width, 2 );
|
||||
}
|
||||
}
|
||||
|
||||
public void ChangeCursorPos( int dir ) {
|
||||
if( CaretPos == 0 && dir == -1 )
|
||||
return;
|
||||
if( CaretPos == -1 && dir == -1 )
|
||||
CaretPos = Text.Length;
|
||||
|
||||
CaretPos += dir;
|
||||
if( CaretPos < 0 || CaretPos >= Text.Length )
|
||||
CaretPos = -1;
|
||||
}
|
||||
|
||||
/// <summary> Appends a character to the end of the currently entered text. </summary>
|
||||
/// <returns> true if a redraw is necessary, false otherwise. </returns>
|
||||
public bool AppendChar( char c ) {
|
||||
if( TextFilter != null && !TextFilter( c ) )
|
||||
return false;
|
||||
if( c >= ' ' && c <= '~' && Text.Length < MaxTextLength ) {
|
||||
Text += c;
|
||||
if( c >= ' ' && c <= '~' && c != '&' && Text.Length < MaxTextLength ) {
|
||||
if( CaretPos == -1 ) {
|
||||
Text += c;
|
||||
} else {
|
||||
Text = Text.Insert( CaretPos, new String( c, 1 ) );
|
||||
CaretPos++;
|
||||
}
|
||||
if( TextChanged != null ) TextChanged( this );
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/// <summary> Removes the last character in the currently entered text. </summary>
|
||||
/// <summary> Removes the character preceding the caret in the currently entered text. </summary>
|
||||
/// <returns> true if a redraw is necessary, false otherwise. </returns>
|
||||
public bool RemoveChar() {
|
||||
public bool BackspaceChar() {
|
||||
if( Text.Length == 0 ) return false;
|
||||
|
||||
Text = Text.Substring( 0, Text.Length - 1 );
|
||||
if( CaretPos == -1 ) {
|
||||
Text = Text.Substring( 0, Text.Length - 1 );
|
||||
} else {
|
||||
if( CaretPos == 0 ) return false;
|
||||
Text = Text.Remove( CaretPos - 1, 1 );
|
||||
CaretPos--;
|
||||
if( CaretPos == -1 ) CaretPos = 0;
|
||||
}
|
||||
|
||||
if( TextChanged != null ) TextChanged( this );
|
||||
if( CaretPos >= Text.Length )
|
||||
CaretPos = -1;
|
||||
return true;
|
||||
}
|
||||
|
||||
/// <summary> Removes the haracter at the caret in the currently entered text. </summary>
|
||||
/// <returns> true if a redraw is necessary, false otherwise. </returns>
|
||||
public bool DeleteChar() {
|
||||
if( Text.Length == 0 || CaretPos == -1 ) return false;
|
||||
|
||||
Text = Text.Remove( CaretPos, 1 );
|
||||
if( CaretPos == -1 ) CaretPos = 0;
|
||||
|
||||
if( TextChanged != null ) TextChanged( this );
|
||||
if( CaretPos >= Text.Length )
|
||||
CaretPos = -1;
|
||||
return true;
|
||||
}
|
||||
|
||||
@ -103,6 +167,7 @@ namespace Launcher2 {
|
||||
|
||||
Text = "";
|
||||
if( TextChanged != null ) TextChanged( this );
|
||||
CaretPos = -1;
|
||||
return true;
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user