diff --git a/ClassicalSharp/2D/Drawing/IDrawer2D.cs b/ClassicalSharp/2D/Drawing/IDrawer2D.cs
index 8067e1d75..bfe1e28ad 100644
--- a/ClassicalSharp/2D/Drawing/IDrawer2D.cs
+++ b/ClassicalSharp/2D/Drawing/IDrawer2D.cs
@@ -31,7 +31,7 @@ namespace ClassicalSharp {
/// Clears the entire bound bitmap to the specified colour.
public abstract void Clear( FastColour colour );
- /// Clears the entire bound bitmap to the specified colour.
+ /// Clears the entire given area to the specified colour.
public abstract void Clear( FastColour colour, int x, int y, int width, int height );
/// Disposes of any resources used by this class that are associated with the underlying bitmap.
diff --git a/Launcher2/Gui/Screens/ClassiCubeScreen.cs b/Launcher2/Gui/Screens/ClassiCubeScreen.cs
index e16ca49e7..0b003a338 100644
--- a/Launcher2/Gui/Screens/ClassiCubeScreen.cs
+++ b/Launcher2/Gui/Screens/ClassiCubeScreen.cs
@@ -112,8 +112,7 @@ namespace Launcher2 {
drawer.SetBitmap( game.Framebuffer );
LauncherLabelWidget widget = (LauncherLabelWidget)widgets[6];
- drawer.Clear( game.clearColour, widget.X, widget.Y,
- widget.Width, widget.Height );
+ game.ClearArea( widget.X, widget.Y, widget.Width, widget.Height );
widget.DrawAt( drawer, text, inputFont, Anchor.Centre, Anchor.Centre, 0, 50 );
Dirty = true;
}
diff --git a/Launcher2/Gui/Screens/ClassiCubeServersScreen.cs b/Launcher2/Gui/Screens/ClassiCubeServersScreen.cs
index 826b3debe..fa5f38be9 100644
--- a/Launcher2/Gui/Screens/ClassiCubeServersScreen.cs
+++ b/Launcher2/Gui/Screens/ClassiCubeServersScreen.cs
@@ -54,7 +54,10 @@ namespace Launcher2 {
public override void Resize() {
using( drawer ) {
drawer.SetBitmap( game.Framebuffer );
- drawer.Clear( game.clearColour );
+ game.ClearArea( 0, 0, game.Width, 100 );
+ drawer.Clear( game.clearColour, 0, 100,
+ game.Width, game.Height - 100 );
+
Draw();
LauncherTableWidget table = (LauncherTableWidget)widgets[tableIndex];
table.ClampIndex();
diff --git a/Launcher2/Gui/Screens/DirectConnectScreen.cs b/Launcher2/Gui/Screens/DirectConnectScreen.cs
index b109c0c0e..9c6052ef8 100644
--- a/Launcher2/Gui/Screens/DirectConnectScreen.cs
+++ b/Launcher2/Gui/Screens/DirectConnectScreen.cs
@@ -90,8 +90,7 @@ namespace Launcher2 {
using( drawer ) {
drawer.SetBitmap( game.Framebuffer );
LauncherLabelWidget widget = (LauncherLabelWidget)widgets[8];
- drawer.Clear( game.clearColour, widget.X, widget.Y,
- widget.Width, widget.Height );
+ game.ClearArea( widget.X, widget.Y, widget.Width, widget.Height );
widget.DrawAt( drawer, text, inputFont, Anchor.Centre, Anchor.Centre, 0, 100 );
Dirty = true;
}
diff --git a/Launcher2/Gui/Screens/LauncherInputScreen.cs b/Launcher2/Gui/Screens/LauncherInputScreen.cs
index 4bca863fc..c67f61071 100644
--- a/Launcher2/Gui/Screens/LauncherInputScreen.cs
+++ b/Launcher2/Gui/Screens/LauncherInputScreen.cs
@@ -69,8 +69,8 @@ namespace Launcher2 {
using( drawer ) {
drawer.SetBitmap( game.Framebuffer );
if( lastInput.Width > lastInput.ButtonWidth )
- drawer.Clear( game.clearColour, lastInput.X, lastInput.Y,
- lastInput.Width + 1, lastInput.Height + 1 );
+ game.ClearArea( lastInput.X, lastInput.Y,
+ lastInput.Width + 1, lastInput.Height + 1 );
lastInput.Redraw( drawer, lastInput.Text, inputFont );
Dirty = true;
}
@@ -128,7 +128,7 @@ namespace Launcher2 {
}
protected void MakeInput( string text, int width, Anchor verAnchor, bool password,
- int x, int y, int maxChars ) {
+ int x, int y, int maxChars ) {
if( widgets[widgetIndex] != null ) {
LauncherInputWidget input = (LauncherInputWidget)widgets[widgetIndex];
input.DrawAt( drawer, text, inputFont, Anchor.Centre, verAnchor, width, 30, x, y );
diff --git a/Launcher2/Gui/Screens/ResourcesScreen.cs b/Launcher2/Gui/Screens/ResourcesScreen.cs
index 05aac9da5..3fa41ffd5 100644
--- a/Launcher2/Gui/Screens/ResourcesScreen.cs
+++ b/Launcher2/Gui/Screens/ResourcesScreen.cs
@@ -27,6 +27,7 @@ namespace Launcher2 {
if( fetcher.Done ) {
ResourcePatcher patcher = new ResourcePatcher( fetcher );
patcher.Run();
+ game.TryLoadTexturePack();
game.SetScreen( new MainScreen( game ) );
fetcher = null;
}
diff --git a/Launcher2/LauncherWindow.Background.cs b/Launcher2/LauncherWindow.Background.cs
index 753680a22..291671e41 100644
--- a/Launcher2/LauncherWindow.Background.cs
+++ b/Launcher2/LauncherWindow.Background.cs
@@ -1,12 +1,45 @@
using System;
using System.Drawing;
+using System.IO;
using ClassicalSharp;
+using ClassicalSharp.TexturePack;
namespace Launcher2 {
public sealed partial class LauncherWindow {
internal FastColour clearColour = new FastColour( 30, 30, 30 );
+
+ bool useTexture = false;
+ internal void TryLoadTexturePack() {
+ if( !File.Exists( "default.zip" ) ) return;
+
+ using( Stream fs = new FileStream( "default.zip", FileMode.Open, FileAccess.Read, FileShare.Read ) ) {
+ ZipReader reader = new ZipReader();
+
+ reader.ShouldProcessZipEntry = (f) => f == "terrain.png";
+ reader.ProcessZipEntry = ProcessZipEntry;
+ reader.Extract( fs );
+ }
+ }
+
+ Bitmap dirtBmp;
+ FastBitmap dirtFastBmp;
+ int elementSize;
+
+ void ProcessZipEntry( string filename, byte[] data, ZipEntry entry ) {
+ MemoryStream stream = new MemoryStream( data );
+ using( Bitmap bmp = new Bitmap( stream ) ) {
+ using( FastBitmap fastBmp = new FastBitmap( bmp, true ) ) {
+ elementSize = bmp.Width / 16;
+ dirtBmp = new Bitmap( elementSize, elementSize );
+ dirtFastBmp = new FastBitmap( dirtBmp, true );
+ FastBitmap.MovePortion( elementSize * 2, 0, 0, 0, fastBmp, dirtFastBmp, elementSize );
+ }
+ }
+ useTexture = true;
+ }
+
public void MakeBackground() {
if( Framebuffer != null )
Framebuffer.Dispose();
@@ -14,8 +47,10 @@ namespace Launcher2 {
Framebuffer = new Bitmap( Width, Height );
using( IDrawer2D drawer = Drawer ) {
drawer.SetBitmap( Framebuffer );
- //ClearDirtTexture( drawer );
- ClearColour( drawer );
+ if( useTexture )
+ ClearDirt( 0, 0, Width, Height );
+ else
+ Drawer.Clear( clearColour );
DrawTextArgs args1 = new DrawTextArgs( "&eClassical", logoItalicFont, true );
Size size1 = drawer.MeasureSize( ref args1 );
@@ -29,26 +64,27 @@ namespace Launcher2 {
Dirty = true;
}
- void ClearColour( IDrawer2D drawer ) {
- drawer.Clear( clearColour );
+ public void ClearArea( int x, int y, int width, int height ) {
+ if( useTexture )
+ ClearDirt( x, y, width, height );
+ else
+ Drawer.Clear( clearColour, x, y, width, height );
}
- void ClearDirtTexture( IDrawer2D drawer ) {
- Bitmap bmp = new Bitmap( "dirt.png" );
- drawer.ConvertTo32Bpp( ref bmp );
-
- using( FastBitmap dst = new FastBitmap( Framebuffer, true ),
- src = new FastBitmap( bmp, true ) ) {
- Rectangle srcRect = new Rectangle( 0, 0, 16, 16 );
- const int tileSize = 64;
- for( int y = 0; y < Height; y += tileSize ) {
- for( int x = 0; x < Width; x += tileSize ) {
- int x2 = Math.Min( x + tileSize, Width );
- int y2 = Math.Min( y + tileSize, Height );
+ void ClearDirt( int x, int y, int width, int height ) {
+ using( FastBitmap dst = new FastBitmap( Framebuffer, true ) ) {
+ Rectangle srcRect = new Rectangle( 0, 0, elementSize, elementSize );
+ int tileSize = 64;
+ int xMax = x + width, xOrig = x, yMax = y + height;
+
+ for( ; y < yMax; y += tileSize ) {
+ for( x = xOrig; x < xMax; x += tileSize ) {
+ int x2 = Math.Min( x + tileSize, Math.Min( x + width, Width ) );
+ int y2 = Math.Min( y + tileSize, Math.Min( y + height, Height ) );
Size size = new Size( tileSize, tileSize );
Rectangle dstRect = new Rectangle( x, y, x2 - x, y2 - y );
- FastBitmap.CopyScaledPixels( src, dst, size, srcRect, dstRect, 128 );
+ FastBitmap.CopyScaledPixels( dirtFastBmp, dst, size, srcRect, dstRect, 128 );
}
}
}
diff --git a/Launcher2/LauncherWindow.cs b/Launcher2/LauncherWindow.cs
index 9ccafab13..3fd57d785 100644
--- a/Launcher2/LauncherWindow.cs
+++ b/Launcher2/LauncherWindow.cs
@@ -100,6 +100,7 @@ namespace Launcher2 {
Window.Visible = true;
Drawer = new GdiPlusDrawer2D( null );
Init();
+ TryLoadTexturePack();
platformDrawer.Init( Window.WindowInfo );
if( !ResourceFetcher.CheckAllResourcesExist() ) {
diff --git a/Launcher2/Patcher/ResourceFetcher.cs b/Launcher2/Patcher/ResourceFetcher.cs
index afadea1fb..208de776a 100644
--- a/Launcher2/Patcher/ResourceFetcher.cs
+++ b/Launcher2/Patcher/ResourceFetcher.cs
@@ -56,11 +56,8 @@ namespace Launcher2 {
}
public static float EstimateDownloadSize() {
- float sum = 0;
- if( !File.Exists( "classic.jar" ) ) sum += 291 / 1024f;
- if( !File.Exists( "1.6.2.jar" ) ) sum += 4621 / 1024f;
- if( !File.Exists( "terrain-patch.png" ) ) sum += 7 / 1024f;
- return sum;
+ return (291 + 4621 + 7) / 1024f;
+ // clasic.jar + 1.6.2.jar + terrain-patch.png
}
}
}
diff --git a/Launcher2/Patcher/ResourcePatcher.cs b/Launcher2/Patcher/ResourcePatcher.cs
index ee575ecf3..fedab10d8 100644
--- a/Launcher2/Patcher/ResourcePatcher.cs
+++ b/Launcher2/Patcher/ResourcePatcher.cs
@@ -4,7 +4,6 @@ using System.Drawing.Imaging;
using System.IO;
using ClassicalSharp;
using ClassicalSharp.TexturePack;
-using OpenTK;
namespace Launcher2 {