mirror of
https://github.com/ClassiCube/ClassiCube.git
synced 2025-09-17 11:35:08 -04:00
Store last entered text in new launcher, more comments in new launcher, don't scroll past last server unless the launcher can show all servers in the table.
This commit is contained in:
parent
bc92278291
commit
c2bd4c7971
@ -1,7 +1,7 @@
|
||||
using System;
|
||||
using System.Drawing;
|
||||
using ClassicalSharp.GraphicsAPI;
|
||||
using OpenTK.Input;
|
||||
using System;
|
||||
using System.Drawing;
|
||||
using ClassicalSharp.GraphicsAPI;
|
||||
using OpenTK.Input;
|
||||
|
||||
namespace ClassicalSharp {
|
||||
|
||||
|
@ -47,7 +47,7 @@ namespace ClassicalSharp {
|
||||
for( int i = 0; i < hotbarCount; i++ ) {
|
||||
int x = X + i * blockSize;
|
||||
IsometricBlockDrawer.Draw( game, (byte)game.Inventory.Hotbar[i], 10,
|
||||
x + blockSize / 2, game.Height - 18 );
|
||||
x + blockSize / 2, game.Height - 19 );
|
||||
if( i == game.Inventory.HeldBlockIndex )
|
||||
selectedBlock.X1 = x;
|
||||
}
|
||||
|
@ -1,7 +1,7 @@
|
||||
using System;
|
||||
using System.Drawing;
|
||||
using System.Drawing.Imaging;
|
||||
using OpenTK;
|
||||
using System;
|
||||
using System.Drawing;
|
||||
using System.Drawing.Imaging;
|
||||
using OpenTK;
|
||||
|
||||
namespace ClassicalSharp.GraphicsAPI {
|
||||
|
||||
|
@ -8,16 +8,22 @@ namespace ClassicalSharp {
|
||||
|
||||
/// <summary> Minimum world coordinates of the block's bounding box. </summary>
|
||||
public Vector3 Min;
|
||||
|
||||
/// <summary> Maximum world coordinates of the block's bounding box. </summary>
|
||||
public Vector3 Max;
|
||||
public Vector3 Max;
|
||||
|
||||
/// <summary> Integer world coordinates of the block. </summary>
|
||||
public Vector3I BlockPos;
|
||||
public Vector3I BlockPos;
|
||||
|
||||
/// <summary> Integer world coordinates of the neighbouring block that is closest to the client.</summary>
|
||||
public Vector3I TranslatedPos;
|
||||
public Vector3I TranslatedPos;
|
||||
|
||||
/// <summary> Whether this instance actually has a selected block currently. </summary>
|
||||
public bool Valid = true;
|
||||
public bool Valid = true;
|
||||
|
||||
/// <summary> Face of the picked block that is closet to the client. </summary>
|
||||
public CpeBlockFace BlockFace;
|
||||
public CpeBlockFace BlockFace;
|
||||
|
||||
/// <summary> Block type of this selected block. </summary>
|
||||
public byte BlockType;
|
||||
|
||||
|
@ -1,12 +1,12 @@
|
||||
using System;
|
||||
using System.Drawing;
|
||||
using OpenTK;
|
||||
using ClassicalSharp;
|
||||
using OpenTK.Platform;
|
||||
using OpenTK.Platform.X11;
|
||||
using ClassicalSharp;
|
||||
|
||||
namespace Launcher2 {
|
||||
|
||||
/// <summary> Platform specific class used to transfer a bitmap directly to the screen. </summary>
|
||||
public abstract class PlatformDrawer {
|
||||
|
||||
public abstract void Init( IWindowInfo info );
|
||||
@ -48,7 +48,7 @@ namespace Launcher2 {
|
||||
}
|
||||
|
||||
public override void Draw( IWindowInfo info, Bitmap framebuffer ) {
|
||||
X11WindowInfo x11Info = info as X11WindowInfo;
|
||||
X11WindowInfo x11Info = (X11WindowInfo)info;
|
||||
using( FastBitmap fastBmp = new FastBitmap( framebuffer, true ) ) {
|
||||
IntPtr image = API.XCreateImage( API.DefaultDisplay, x11Info.VisualInfo.Visual,
|
||||
24, ImageFormat.ZPixmap, 0, fastBmp.Scan0,
|
||||
|
@ -1,4 +1,5 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Drawing;
|
||||
using System.IO;
|
||||
using System.Net;
|
||||
@ -44,11 +45,22 @@ namespace Launcher2 {
|
||||
}
|
||||
|
||||
void LoadSavedInfo( IDrawer2D drawer ) {
|
||||
Dictionary<string, object> metadata;
|
||||
// restore what user last typed into the various fields
|
||||
if( game.ScreenMetadata.TryGetValue( "screen-CC", out metadata ) ) {
|
||||
Set( 2, (string)metadata["user"] );
|
||||
Set( 3, (string)metadata["pass"] );
|
||||
} else {
|
||||
LoadFromOptions();
|
||||
}
|
||||
}
|
||||
|
||||
void LoadFromOptions() {
|
||||
if( !Options.Load() )
|
||||
return;
|
||||
|
||||
string user = Options.Get( "launcher-cc-username" ) ?? "";
|
||||
string pass = Options.Get( "launcher-cc-password" ) ?? "";
|
||||
string user = Options.Get( "launcher-cc-username" ) ?? "UserXYZ";
|
||||
string pass = Options.Get( "launcher-cc-password" ) ?? "PassXYZ";
|
||||
pass = Secure.Decode( pass, user );
|
||||
|
||||
Set( 2, user );
|
||||
@ -166,5 +178,21 @@ namespace Launcher2 {
|
||||
SetStatus( text );
|
||||
}
|
||||
}
|
||||
|
||||
public override void Dispose() {
|
||||
StoreFields();
|
||||
base.Dispose();
|
||||
}
|
||||
|
||||
void StoreFields() {
|
||||
Dictionary<string, object> metadata;
|
||||
if( !game.ScreenMetadata.TryGetValue( "screen-CC", out metadata ) ) {
|
||||
metadata = new Dictionary<string, object>();
|
||||
game.ScreenMetadata["screen-CC"] = metadata;
|
||||
}
|
||||
|
||||
metadata["user"] = Get( 2 );
|
||||
metadata["pass"] = Get( 3 );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -39,7 +39,7 @@ namespace Launcher2 {
|
||||
if( lastInput == widgets[1] ) {
|
||||
LauncherTableWidget table = (LauncherTableWidget)widgets[tableIndex];
|
||||
table.FilterEntries( lastInput.Text );
|
||||
ClampIndex();
|
||||
table.ClampIndex();
|
||||
Resize();
|
||||
}
|
||||
}
|
||||
@ -56,6 +56,9 @@ namespace Launcher2 {
|
||||
drawer.SetBitmap( game.Framebuffer );
|
||||
drawer.Clear( game.clearColour );
|
||||
Draw();
|
||||
LauncherTableWidget table = (LauncherTableWidget)widgets[tableIndex];
|
||||
table.ClampIndex();
|
||||
table.Redraw( drawer, inputFont, titleFont );
|
||||
}
|
||||
Dirty = true;
|
||||
}
|
||||
@ -85,7 +88,7 @@ namespace Launcher2 {
|
||||
|
||||
void MakeTableWidget() {
|
||||
if( widgets[tableIndex] != null ) {
|
||||
LauncherTableWidget table = widgets[tableIndex] as LauncherTableWidget;
|
||||
LauncherTableWidget table = (LauncherTableWidget)widgets[tableIndex];
|
||||
table.Redraw( drawer, inputFont, titleFont );
|
||||
return;
|
||||
}
|
||||
@ -115,18 +118,10 @@ namespace Launcher2 {
|
||||
void MouseWheelChanged( object sender, MouseWheelEventArgs e ) {
|
||||
LauncherTableWidget table = (LauncherTableWidget)widgets[tableIndex];
|
||||
table.CurrentIndex -= e.Delta;
|
||||
ClampIndex();
|
||||
table.ClampIndex();
|
||||
Resize();
|
||||
}
|
||||
|
||||
void ClampIndex() {
|
||||
LauncherTableWidget table = (LauncherTableWidget)widgets[tableIndex];
|
||||
if( table.CurrentIndex >= table.Count )
|
||||
table.CurrentIndex = table.Count - 1;
|
||||
if( table.CurrentIndex < 0 )
|
||||
table.CurrentIndex = 0;
|
||||
}
|
||||
|
||||
string HashFilter( string input ) {
|
||||
// Server url look like http://www.classicube.net/server/play/aaaaa/
|
||||
|
||||
|
@ -1,4 +1,5 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Drawing;
|
||||
using System.IO;
|
||||
using System.Net;
|
||||
@ -20,7 +21,7 @@ namespace Launcher2 {
|
||||
Resize();
|
||||
using( drawer ) {
|
||||
drawer.SetBitmap( game.Framebuffer );
|
||||
LoadSavedInfo( drawer );
|
||||
LoadSavedInfo();
|
||||
}
|
||||
}
|
||||
|
||||
@ -28,11 +29,23 @@ namespace Launcher2 {
|
||||
}
|
||||
|
||||
bool ccSkins;
|
||||
void LoadSavedInfo( IDrawer2D drawer ) {
|
||||
void LoadSavedInfo() {
|
||||
Dictionary<string, object> metadata;
|
||||
// restore what user last typed into the various fields
|
||||
if( game.ScreenMetadata.TryGetValue( "screen-DC", out metadata ) ) {
|
||||
Set( 3, (string)metadata["user"] );
|
||||
Set( 4, (string)metadata["address"] );
|
||||
Set( 5, (string)metadata["mppass"] );
|
||||
} else {
|
||||
LoadFromOptions();
|
||||
}
|
||||
}
|
||||
|
||||
void LoadFromOptions() {
|
||||
if( !Options.Load() )
|
||||
return;
|
||||
|
||||
string user = Options.Get( "launcher-username" ) ?? "";
|
||||
string user = Options.Get( "launcher-username" ) ?? "UserXYZ";
|
||||
string ip = Options.Get( "launcher-ip" ) ?? "127.0.0.1";
|
||||
string port = Options.Get( "launcher-port" ) ?? "25565";
|
||||
ccSkins = Options.GetBool( "launcher-ccskins", false );
|
||||
@ -130,5 +143,22 @@ namespace Launcher2 {
|
||||
ClientStartData data = new ClientStartData( Get( 3 ), mppass, ipPart, portPart );
|
||||
Client.Start( data, ccSkins );
|
||||
}
|
||||
|
||||
public override void Dispose() {
|
||||
StoreFields();
|
||||
base.Dispose();
|
||||
}
|
||||
|
||||
void StoreFields() {
|
||||
Dictionary<string, object> metadata;
|
||||
if( !game.ScreenMetadata.TryGetValue( "screen-DC", out metadata ) ) {
|
||||
metadata = new Dictionary<string, object>();
|
||||
game.ScreenMetadata["screen-DC"] = metadata;
|
||||
}
|
||||
|
||||
metadata["user"] = Get( 3 );
|
||||
metadata["address"] = Get( 4 );
|
||||
metadata["mppass"] = Get( 5 );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -84,11 +84,11 @@ namespace Launcher2 {
|
||||
|
||||
protected string Get( int index ) {
|
||||
LauncherWidget widget = widgets[index];
|
||||
return widget == null ? "" : ((widget as LauncherInputWidget)).Text;
|
||||
return widget == null ? "" : ((LauncherInputWidget)widget).Text;
|
||||
}
|
||||
|
||||
protected void Set( int index, string text ) {
|
||||
(widgets[index] as LauncherInputWidget)
|
||||
((LauncherInputWidget)widgets[index])
|
||||
.Redraw( drawer, text, inputFont );
|
||||
}
|
||||
|
||||
|
@ -13,14 +13,14 @@ namespace Launcher2 {
|
||||
}
|
||||
|
||||
protected override void UnselectWidget( LauncherWidget widget ) {
|
||||
LauncherButtonWidget button = widget as LauncherButtonWidget;
|
||||
LauncherButtonWidget button = (LauncherButtonWidget)widget;
|
||||
button.Active = false;
|
||||
button.Redraw( drawer, button.Text, textFont );
|
||||
Dirty = true;
|
||||
}
|
||||
|
||||
protected override void SelectWidget( LauncherWidget widget ) {
|
||||
LauncherButtonWidget button = widget as LauncherButtonWidget;
|
||||
LauncherButtonWidget button = (LauncherButtonWidget)widget;
|
||||
button.Active = true;
|
||||
button.Redraw( drawer, button.Text, textFont );
|
||||
Dirty = true;
|
||||
@ -59,14 +59,14 @@ namespace Launcher2 {
|
||||
Font textFont;
|
||||
void Draw() {
|
||||
widgetIndex = 0;
|
||||
MakeButtonAt( "Direct connect", Anchor.Centre, Anchor.Centre,
|
||||
buttonWidth, buttonHeight, 0, -100,
|
||||
(x, y) => game.SetScreen( new DirectConnectScreen( game ) ) );
|
||||
|
||||
MakeButtonAt( "ClassiCube.net", Anchor.Centre, Anchor.Centre,
|
||||
buttonWidth, buttonHeight, 0, -50,
|
||||
buttonWidth, buttonHeight, 0, -100,
|
||||
(x, y) => game.SetScreen( new ClassiCubeScreen( game ) ) );
|
||||
|
||||
MakeButtonAt( "Direct connect", Anchor.Centre, Anchor.Centre,
|
||||
buttonWidth, buttonHeight, 0, -50,
|
||||
(x, y) => game.SetScreen( new DirectConnectScreen( game ) ) );
|
||||
|
||||
MakeButtonAt( "Singleplayer", Anchor.LeftOrTop, Anchor.BottomOrRight,
|
||||
sideButtonWidth, buttonHeight, 10, -10,
|
||||
(x, y) => Client.Start( "default.zip" ) );
|
||||
|
@ -86,7 +86,7 @@ namespace Launcher2 {
|
||||
|
||||
string text = widgets[0] == null ?
|
||||
String.Format( format, ResourceFetcher.EstimateDownloadSize().ToString( "F2" ) )
|
||||
: (widgets[0] as LauncherLabelWidget).Text;
|
||||
: ((LauncherLabelWidget)widgets[0]).Text;
|
||||
MakeTextAt( statusFont, text, 0, 5 );
|
||||
|
||||
// Clear the entire previous widgets state.
|
||||
@ -110,7 +110,7 @@ namespace Launcher2 {
|
||||
}
|
||||
|
||||
void SetStatus( string text ) {
|
||||
LauncherLabelWidget widget = widgets[0] as LauncherLabelWidget;
|
||||
LauncherLabelWidget widget = (LauncherLabelWidget)widgets[0];
|
||||
using( drawer ) {
|
||||
drawer.SetBitmap( game.Framebuffer );
|
||||
drawer.Clear( backCol, widget.X, widget.Y, widget.Width, widget.Height );
|
||||
|
@ -17,16 +17,16 @@ namespace Launcher2 {
|
||||
return;
|
||||
}
|
||||
|
||||
if( mouseY >= HeaderStartY && mouseY < HeaderEndY ) {
|
||||
if( mouseX < ColumnWidths[0] - 10 ) {
|
||||
nameComp.Invert = !nameComp.Invert;
|
||||
if( mouseY >= headerStartY && mouseY < headerEndY ) {
|
||||
if( mouseX < ColumnWidths[0] - 10 ) {
|
||||
Array.Sort( usedEntries, 0, Count, nameComp );
|
||||
Array.Sort( entries, 0, entries.Length, nameComp );
|
||||
nameComp.Invert = !nameComp.Invert;
|
||||
NeedRedraw();
|
||||
} else if( mouseX > ColumnWidths[0] + 10 ) {
|
||||
playerComp.Invert = !playerComp.Invert;
|
||||
} else if( mouseX > ColumnWidths[0] + 10 ) {
|
||||
Array.Sort( usedEntries, 0, Count, playerComp );
|
||||
Array.Sort( entries, 0, entries.Length, playerComp );
|
||||
playerComp.Invert = !playerComp.Invert;
|
||||
NeedRedraw();
|
||||
} else {
|
||||
DraggingWidth = true;
|
||||
|
@ -81,12 +81,12 @@ namespace Launcher2 {
|
||||
DrawTextArgs args = new DrawTextArgs( header, titleFont, true );
|
||||
TableEntry headerEntry = default( TableEntry );
|
||||
DrawColumnEntry( drawer, ref args, maxWidth, x, ref y, ref headerEntry );
|
||||
MaxIndex = Count;
|
||||
maxIndex = Count;
|
||||
|
||||
for( int i = CurrentIndex; i < Count; i++ ) {
|
||||
args = new DrawTextArgs( filter( usedEntries[i] ), font, true );
|
||||
if( !DrawColumnEntry( drawer, ref args, maxWidth, x, ref y, ref usedEntries[i] ) ) {
|
||||
MaxIndex = i;
|
||||
maxIndex = i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
@ -112,36 +112,46 @@ namespace Launcher2 {
|
||||
return true;
|
||||
}
|
||||
|
||||
int HeaderStartY, HeaderEndY;
|
||||
int headerStartY, headerEndY;
|
||||
int numEntries = 0;
|
||||
void DrawGrid( IDrawer2D drawer, Font font, Font titleFont ) {
|
||||
DrawTextArgs args = new DrawTextArgs( "I", titleFont, true );
|
||||
Size size = drawer.MeasureSize( ref args );
|
||||
drawer.DrawRect( foreCol, 0, Y, Window.Width, 5 );
|
||||
drawer.DrawRect( foreCol, 0, Y + size.Height + 10, Window.Width, 3 );
|
||||
HeaderStartY = Y;
|
||||
HeaderEndY = Y + size.Height + 10;
|
||||
headerStartY = Y;
|
||||
headerEndY = Y + size.Height + 10;
|
||||
|
||||
args = new DrawTextArgs( "I", font, true );
|
||||
int y = Y + size.Height + 10;
|
||||
size = drawer.MeasureSize( ref args );
|
||||
|
||||
for( ; ; ) {
|
||||
numEntries = 0;
|
||||
for( ; ; ) {
|
||||
if( y + size.Height > Window.Height ) break;
|
||||
numEntries++;
|
||||
drawer.DrawRect( foreCol, 0, y, Window.Width, 1 );
|
||||
y += size.Height + 5;
|
||||
}
|
||||
}
|
||||
|
||||
int MaxIndex;
|
||||
int maxIndex;
|
||||
void DrawScrollbar( IDrawer2D drawer ) {
|
||||
drawer.DrawRect( backCol, Window.Width - 10, Y, 10, Window.Height - Y );
|
||||
float scale = (Window.Height - 10 - Y) / (float)Count;
|
||||
|
||||
int y1 = (int)(Y + CurrentIndex * scale);
|
||||
int height = (int)((MaxIndex - CurrentIndex) * scale);
|
||||
int height = (int)((maxIndex - CurrentIndex) * scale);
|
||||
drawer.DrawRect( scrollCol, Window.Width - 10, y1, 10, height );
|
||||
}
|
||||
|
||||
public void ClampIndex() {
|
||||
if( CurrentIndex >= Count - numEntries )
|
||||
CurrentIndex = Count - numEntries;
|
||||
if( CurrentIndex < 0 )
|
||||
CurrentIndex = 0;
|
||||
}
|
||||
|
||||
class NameComparer : IComparer<TableEntry> {
|
||||
|
||||
public bool Invert = false;
|
||||
|
@ -1,28 +1,50 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Drawing;
|
||||
using System.Net;
|
||||
using System.Threading;
|
||||
using ClassicalSharp;
|
||||
using ClassicalSharp.Network;
|
||||
using OpenTK;
|
||||
using OpenTK.Graphics;
|
||||
using System.Net;
|
||||
|
||||
namespace Launcher2 {
|
||||
|
||||
public sealed class LauncherWindow {
|
||||
|
||||
/// <summary> Underlying native window instance. </summary>
|
||||
public NativeWindow Window;
|
||||
|
||||
/// <summary> Platform specific class used to draw 2D elements,
|
||||
/// such as text, rounded rectangles and lines. </summary>
|
||||
public IDrawer2D Drawer;
|
||||
public LauncherScreen screen;
|
||||
|
||||
/// <summary> Currently active screen. </summary>
|
||||
public LauncherScreen Screen;
|
||||
|
||||
/// <summary> Whether the client drawing area needs to be redrawn/presented to the screen. </summary>
|
||||
public bool Dirty;
|
||||
|
||||
/// <summary> Currently active logged in session with classicube.net. </summary>
|
||||
public ClassicubeSession Session = new ClassicubeSession();
|
||||
|
||||
/// <summary> Queue used to download resources asynchronously. </summary>
|
||||
public AsyncDownloader Downloader;
|
||||
|
||||
/// <summary> Returns the width of the client drawing area. </summary>
|
||||
public int Width { get { return Window.Width; } }
|
||||
|
||||
/// <summary> Returns the height of the client drawing area. </summary>
|
||||
public int Height { get { return Window.Height; } }
|
||||
|
||||
/// <summary> Bitmap that contains the entire array of pixels that describe the client drawing area. </summary>
|
||||
public Bitmap Framebuffer;
|
||||
|
||||
/// <summary> Contains metadata attached for different screen instances,
|
||||
/// typically used to save 'last text entered' text when a screen is disposed. </summary>
|
||||
public Dictionary<string, Dictionary<string, object>> ScreenMetadata =
|
||||
new Dictionary<string, Dictionary<string, object>>();
|
||||
|
||||
Font logoFont, logoItalicFont;
|
||||
PlatformDrawer platformDrawer;
|
||||
public void Init() {
|
||||
@ -42,21 +64,21 @@ namespace Launcher2 {
|
||||
|
||||
void FocusedChanged( object sender, EventArgs e ) {
|
||||
MakeBackground();
|
||||
screen.Resize();
|
||||
Screen.Resize();
|
||||
}
|
||||
|
||||
void Resize( object sender, EventArgs e ) {
|
||||
platformDrawer.Resize( Window.WindowInfo );
|
||||
MakeBackground();
|
||||
screen.Resize();
|
||||
Screen.Resize();
|
||||
}
|
||||
|
||||
public void SetScreen( LauncherScreen screen ) {
|
||||
if( this.screen != null )
|
||||
this.screen.Dispose();
|
||||
if( this.Screen != null )
|
||||
this.Screen.Dispose();
|
||||
|
||||
MakeBackground();
|
||||
this.screen = screen;
|
||||
this.Screen = screen;
|
||||
screen.Init();
|
||||
}
|
||||
|
||||
@ -90,8 +112,8 @@ namespace Launcher2 {
|
||||
Window.ProcessEvents();
|
||||
if( !Window.Exists ) break;
|
||||
|
||||
screen.Tick();
|
||||
if( Dirty || screen.Dirty )
|
||||
Screen.Tick();
|
||||
if( Dirty || Screen.Dirty )
|
||||
Display();
|
||||
Thread.Sleep( 1 );
|
||||
}
|
||||
@ -99,7 +121,7 @@ namespace Launcher2 {
|
||||
|
||||
void Display() {
|
||||
Dirty = false;
|
||||
screen.Dirty = false;
|
||||
Screen.Dirty = false;
|
||||
platformDrawer.Draw( Window.WindowInfo, Framebuffer );
|
||||
}
|
||||
|
||||
|
@ -536,7 +536,8 @@ namespace OpenTK.Platform.Windows
|
||||
icon = value;
|
||||
if (window.WindowHandle != IntPtr.Zero)
|
||||
{
|
||||
API.SendMessage(window.WindowHandle, WindowMessage.SETICON, (IntPtr)0, icon == null ? IntPtr.Zero : value.Handle);
|
||||
Icon small = new Icon( value, 16, 16 );
|
||||
API.SendMessage(window.WindowHandle, WindowMessage.SETICON, (IntPtr)0, icon == null ? IntPtr.Zero : small.Handle);
|
||||
API.SendMessage(window.WindowHandle, WindowMessage.SETICON, (IntPtr)1, icon == null ? IntPtr.Zero : value.Handle);
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user