mirror of
https://github.com/ClassiCube/ClassiCube.git
synced 2025-09-16 11:06:06 -04:00
Make new launcher use dirt from current texture pack for background.
This commit is contained in:
parent
ddad12c442
commit
522a09547b
@ -31,7 +31,7 @@ namespace ClassicalSharp {
|
|||||||
/// <summary> Clears the entire bound bitmap to the specified colour. </summary>
|
/// <summary> Clears the entire bound bitmap to the specified colour. </summary>
|
||||||
public abstract void Clear( FastColour colour );
|
public abstract void Clear( FastColour colour );
|
||||||
|
|
||||||
/// <summary> Clears the entire bound bitmap to the specified colour. </summary>
|
/// <summary> Clears the entire given area to the specified colour. </summary>
|
||||||
public abstract void Clear( FastColour colour, int x, int y, int width, int height );
|
public abstract void Clear( FastColour colour, int x, int y, int width, int height );
|
||||||
|
|
||||||
/// <summary> Disposes of any resources used by this class that are associated with the underlying bitmap. </summary>
|
/// <summary> Disposes of any resources used by this class that are associated with the underlying bitmap. </summary>
|
||||||
|
@ -112,8 +112,7 @@ namespace Launcher2 {
|
|||||||
drawer.SetBitmap( game.Framebuffer );
|
drawer.SetBitmap( game.Framebuffer );
|
||||||
LauncherLabelWidget widget = (LauncherLabelWidget)widgets[6];
|
LauncherLabelWidget widget = (LauncherLabelWidget)widgets[6];
|
||||||
|
|
||||||
drawer.Clear( game.clearColour, widget.X, widget.Y,
|
game.ClearArea( widget.X, widget.Y, widget.Width, widget.Height );
|
||||||
widget.Width, widget.Height );
|
|
||||||
widget.DrawAt( drawer, text, inputFont, Anchor.Centre, Anchor.Centre, 0, 50 );
|
widget.DrawAt( drawer, text, inputFont, Anchor.Centre, Anchor.Centre, 0, 50 );
|
||||||
Dirty = true;
|
Dirty = true;
|
||||||
}
|
}
|
||||||
|
@ -54,7 +54,10 @@ namespace Launcher2 {
|
|||||||
public override void Resize() {
|
public override void Resize() {
|
||||||
using( drawer ) {
|
using( drawer ) {
|
||||||
drawer.SetBitmap( game.Framebuffer );
|
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();
|
Draw();
|
||||||
LauncherTableWidget table = (LauncherTableWidget)widgets[tableIndex];
|
LauncherTableWidget table = (LauncherTableWidget)widgets[tableIndex];
|
||||||
table.ClampIndex();
|
table.ClampIndex();
|
||||||
|
@ -90,8 +90,7 @@ namespace Launcher2 {
|
|||||||
using( drawer ) {
|
using( drawer ) {
|
||||||
drawer.SetBitmap( game.Framebuffer );
|
drawer.SetBitmap( game.Framebuffer );
|
||||||
LauncherLabelWidget widget = (LauncherLabelWidget)widgets[8];
|
LauncherLabelWidget widget = (LauncherLabelWidget)widgets[8];
|
||||||
drawer.Clear( game.clearColour, widget.X, widget.Y,
|
game.ClearArea( widget.X, widget.Y, widget.Width, widget.Height );
|
||||||
widget.Width, widget.Height );
|
|
||||||
widget.DrawAt( drawer, text, inputFont, Anchor.Centre, Anchor.Centre, 0, 100 );
|
widget.DrawAt( drawer, text, inputFont, Anchor.Centre, Anchor.Centre, 0, 100 );
|
||||||
Dirty = true;
|
Dirty = true;
|
||||||
}
|
}
|
||||||
|
@ -69,7 +69,7 @@ namespace Launcher2 {
|
|||||||
using( drawer ) {
|
using( drawer ) {
|
||||||
drawer.SetBitmap( game.Framebuffer );
|
drawer.SetBitmap( game.Framebuffer );
|
||||||
if( lastInput.Width > lastInput.ButtonWidth )
|
if( lastInput.Width > lastInput.ButtonWidth )
|
||||||
drawer.Clear( game.clearColour, lastInput.X, lastInput.Y,
|
game.ClearArea( lastInput.X, lastInput.Y,
|
||||||
lastInput.Width + 1, lastInput.Height + 1 );
|
lastInput.Width + 1, lastInput.Height + 1 );
|
||||||
lastInput.Redraw( drawer, lastInput.Text, inputFont );
|
lastInput.Redraw( drawer, lastInput.Text, inputFont );
|
||||||
Dirty = true;
|
Dirty = true;
|
||||||
|
@ -27,6 +27,7 @@ namespace Launcher2 {
|
|||||||
if( fetcher.Done ) {
|
if( fetcher.Done ) {
|
||||||
ResourcePatcher patcher = new ResourcePatcher( fetcher );
|
ResourcePatcher patcher = new ResourcePatcher( fetcher );
|
||||||
patcher.Run();
|
patcher.Run();
|
||||||
|
game.TryLoadTexturePack();
|
||||||
game.SetScreen( new MainScreen( game ) );
|
game.SetScreen( new MainScreen( game ) );
|
||||||
fetcher = null;
|
fetcher = null;
|
||||||
}
|
}
|
||||||
|
@ -1,12 +1,45 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Drawing;
|
using System.Drawing;
|
||||||
|
using System.IO;
|
||||||
using ClassicalSharp;
|
using ClassicalSharp;
|
||||||
|
using ClassicalSharp.TexturePack;
|
||||||
|
|
||||||
namespace Launcher2 {
|
namespace Launcher2 {
|
||||||
|
|
||||||
public sealed partial class LauncherWindow {
|
public sealed partial class LauncherWindow {
|
||||||
|
|
||||||
internal FastColour clearColour = new FastColour( 30, 30, 30 );
|
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() {
|
public void MakeBackground() {
|
||||||
if( Framebuffer != null )
|
if( Framebuffer != null )
|
||||||
Framebuffer.Dispose();
|
Framebuffer.Dispose();
|
||||||
@ -14,8 +47,10 @@ namespace Launcher2 {
|
|||||||
Framebuffer = new Bitmap( Width, Height );
|
Framebuffer = new Bitmap( Width, Height );
|
||||||
using( IDrawer2D drawer = Drawer ) {
|
using( IDrawer2D drawer = Drawer ) {
|
||||||
drawer.SetBitmap( Framebuffer );
|
drawer.SetBitmap( Framebuffer );
|
||||||
//ClearDirtTexture( drawer );
|
if( useTexture )
|
||||||
ClearColour( drawer );
|
ClearDirt( 0, 0, Width, Height );
|
||||||
|
else
|
||||||
|
Drawer.Clear( clearColour );
|
||||||
|
|
||||||
DrawTextArgs args1 = new DrawTextArgs( "&eClassical", logoItalicFont, true );
|
DrawTextArgs args1 = new DrawTextArgs( "&eClassical", logoItalicFont, true );
|
||||||
Size size1 = drawer.MeasureSize( ref args1 );
|
Size size1 = drawer.MeasureSize( ref args1 );
|
||||||
@ -29,26 +64,27 @@ namespace Launcher2 {
|
|||||||
Dirty = true;
|
Dirty = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void ClearColour( IDrawer2D drawer ) {
|
public void ClearArea( int x, int y, int width, int height ) {
|
||||||
drawer.Clear( clearColour );
|
if( useTexture )
|
||||||
|
ClearDirt( x, y, width, height );
|
||||||
|
else
|
||||||
|
Drawer.Clear( clearColour, x, y, width, height );
|
||||||
}
|
}
|
||||||
|
|
||||||
void ClearDirtTexture( IDrawer2D drawer ) {
|
void ClearDirt( int x, int y, int width, int height ) {
|
||||||
Bitmap bmp = new Bitmap( "dirt.png" );
|
using( FastBitmap dst = new FastBitmap( Framebuffer, true ) ) {
|
||||||
drawer.ConvertTo32Bpp( ref bmp );
|
Rectangle srcRect = new Rectangle( 0, 0, elementSize, elementSize );
|
||||||
|
int tileSize = 64;
|
||||||
|
int xMax = x + width, xOrig = x, yMax = y + height;
|
||||||
|
|
||||||
using( FastBitmap dst = new FastBitmap( Framebuffer, true ),
|
for( ; y < yMax; y += tileSize ) {
|
||||||
src = new FastBitmap( bmp, true ) ) {
|
for( x = xOrig; x < xMax; x += tileSize ) {
|
||||||
Rectangle srcRect = new Rectangle( 0, 0, 16, 16 );
|
int x2 = Math.Min( x + tileSize, Math.Min( x + width, Width ) );
|
||||||
const int tileSize = 64;
|
int y2 = Math.Min( y + tileSize, Math.Min( y + height, Height ) );
|
||||||
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 );
|
|
||||||
|
|
||||||
Size size = new Size( tileSize, tileSize );
|
Size size = new Size( tileSize, tileSize );
|
||||||
Rectangle dstRect = new Rectangle( x, y, x2 - x, y2 - y );
|
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 );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -100,6 +100,7 @@ namespace Launcher2 {
|
|||||||
Window.Visible = true;
|
Window.Visible = true;
|
||||||
Drawer = new GdiPlusDrawer2D( null );
|
Drawer = new GdiPlusDrawer2D( null );
|
||||||
Init();
|
Init();
|
||||||
|
TryLoadTexturePack();
|
||||||
platformDrawer.Init( Window.WindowInfo );
|
platformDrawer.Init( Window.WindowInfo );
|
||||||
|
|
||||||
if( !ResourceFetcher.CheckAllResourcesExist() ) {
|
if( !ResourceFetcher.CheckAllResourcesExist() ) {
|
||||||
|
@ -56,11 +56,8 @@ namespace Launcher2 {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static float EstimateDownloadSize() {
|
public static float EstimateDownloadSize() {
|
||||||
float sum = 0;
|
return (291 + 4621 + 7) / 1024f;
|
||||||
if( !File.Exists( "classic.jar" ) ) sum += 291 / 1024f;
|
// clasic.jar + 1.6.2.jar + terrain-patch.png
|
||||||
if( !File.Exists( "1.6.2.jar" ) ) sum += 4621 / 1024f;
|
|
||||||
if( !File.Exists( "terrain-patch.png" ) ) sum += 7 / 1024f;
|
|
||||||
return sum;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -4,7 +4,6 @@ using System.Drawing.Imaging;
|
|||||||
using System.IO;
|
using System.IO;
|
||||||
using ClassicalSharp;
|
using ClassicalSharp;
|
||||||
using ClassicalSharp.TexturePack;
|
using ClassicalSharp.TexturePack;
|
||||||
using OpenTK;
|
|
||||||
|
|
||||||
namespace Launcher2 {
|
namespace Launcher2 {
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user