mirror of
https://github.com/ClassiCube/ClassiCube.git
synced 2025-09-14 10:05:44 -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>
|
||||
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 );
|
||||
|
||||
/// <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 );
|
||||
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;
|
||||
}
|
||||
|
@ -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();
|
||||
|
@ -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;
|
||||
}
|
||||
|
@ -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 );
|
||||
|
@ -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;
|
||||
}
|
||||
|
@ -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 );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -100,6 +100,7 @@ namespace Launcher2 {
|
||||
Window.Visible = true;
|
||||
Drawer = new GdiPlusDrawer2D( null );
|
||||
Init();
|
||||
TryLoadTexturePack();
|
||||
platformDrawer.Init( Window.WindowInfo );
|
||||
|
||||
if( !ResourceFetcher.CheckAllResourcesExist() ) {
|
||||
|
@ -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
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -4,7 +4,6 @@ using System.Drawing.Imaging;
|
||||
using System.IO;
|
||||
using ClassicalSharp;
|
||||
using ClassicalSharp.TexturePack;
|
||||
using OpenTK;
|
||||
|
||||
namespace Launcher2 {
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user