mirror of
https://github.com/ClassiCube/ClassiCube.git
synced 2025-09-16 02:56:09 -04:00
Show warning screen for first time a texture pack is sent to the client. Fix bugs with being able to press B in both error and map loading screens.
This commit is contained in:
parent
4f546b80d5
commit
97a38f3cf4
@ -1,5 +1,6 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Drawing;
|
using System.Drawing;
|
||||||
|
using OpenTK.Input;
|
||||||
|
|
||||||
namespace ClassicalSharp {
|
namespace ClassicalSharp {
|
||||||
|
|
||||||
@ -52,5 +53,19 @@ namespace ClassicalSharp {
|
|||||||
public override bool HidesHud {
|
public override bool HidesHud {
|
||||||
get { return true; }
|
get { return true; }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public override bool HandlesKeyDown( Key key ) { return true; }
|
||||||
|
|
||||||
|
public override bool HandlesKeyPress( char key ) { return true; }
|
||||||
|
|
||||||
|
public override bool HandlesKeyUp( Key key ) { return true; }
|
||||||
|
|
||||||
|
public override bool HandlesMouseClick( int mouseX, int mouseY, MouseButton button ) { return true; }
|
||||||
|
|
||||||
|
public override bool HandlesMouseMove( int mouseX, int mouseY ) { return true; }
|
||||||
|
|
||||||
|
public override bool HandlesMouseScroll( int delta ) { return true; }
|
||||||
|
|
||||||
|
public override bool HandlesMouseUp( int mouseX, int mouseY, MouseButton button ) { return true; }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Drawing;
|
using System.Drawing;
|
||||||
|
using OpenTK.Input;
|
||||||
|
|
||||||
namespace ClassicalSharp {
|
namespace ClassicalSharp {
|
||||||
|
|
||||||
@ -77,5 +78,19 @@ namespace ClassicalSharp {
|
|||||||
public override bool HidesHud {
|
public override bool HidesHud {
|
||||||
get { return true; }
|
get { return true; }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public override bool HandlesKeyDown( Key key ) { return true; }
|
||||||
|
|
||||||
|
public override bool HandlesKeyPress( char key ) { return true; }
|
||||||
|
|
||||||
|
public override bool HandlesKeyUp( Key key ) { return true; }
|
||||||
|
|
||||||
|
public override bool HandlesMouseClick( int mouseX, int mouseY, MouseButton button ) { return true; }
|
||||||
|
|
||||||
|
public override bool HandlesMouseMove( int mouseX, int mouseY ) { return true; }
|
||||||
|
|
||||||
|
public override bool HandlesMouseScroll( int delta ) { return true; }
|
||||||
|
|
||||||
|
public override bool HandlesMouseUp( int mouseX, int mouseY, MouseButton button ) { return true; }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,13 +1,23 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Drawing;
|
using System.Drawing;
|
||||||
|
using OpenTK.Input;
|
||||||
|
|
||||||
namespace ClassicalSharp {
|
namespace ClassicalSharp {
|
||||||
|
|
||||||
// TODO: get and set activescreen.
|
|
||||||
public sealed class WarningScreen : MenuScreen {
|
public sealed class WarningScreen : MenuScreen {
|
||||||
|
|
||||||
public WarningScreen( Game game ) : base( game ) {
|
public WarningScreen( Game game, object metadata, Action<object> yesClick,
|
||||||
|
Action<object> noClick, string title, params string[] body ) : base( game ) {
|
||||||
|
this.Metadata = metadata;
|
||||||
|
this.yesClick = yesClick;
|
||||||
|
this.noClick = noClick;
|
||||||
|
this.title = title;
|
||||||
|
this.body = body;
|
||||||
}
|
}
|
||||||
|
internal Screen lastScreen;
|
||||||
|
internal bool lastCursorVisible;
|
||||||
|
readonly string title;
|
||||||
|
readonly string[] body;
|
||||||
|
|
||||||
public override void Init() {
|
public override void Init() {
|
||||||
titleFont = new Font( "Arial", 16, FontStyle.Bold );
|
titleFont = new Font( "Arial", 16, FontStyle.Bold );
|
||||||
@ -19,21 +29,41 @@ namespace ClassicalSharp {
|
|||||||
ButtonWidget.Create( game, 60, 30, 60, 20, "No", Anchor.Centre,
|
ButtonWidget.Create( game, 60, 30, 60, 20, "No", Anchor.Centre,
|
||||||
Anchor.Centre, titleFont, OnNoClick ),
|
Anchor.Centre, titleFont, OnNoClick ),
|
||||||
};
|
};
|
||||||
labels = new TextWidget[] {
|
|
||||||
TextWidget.Create( game, 0, -120, "Do you want to XYZ?",
|
labels = new TextWidget[body.Length + 1];
|
||||||
Anchor.Centre, Anchor.Centre, titleFont ),
|
labels[0] = TextWidget.Create( game, 0, -120, title,
|
||||||
TextWidget.Create( game, 0, -70, "Warning text here",
|
Anchor.Centre, Anchor.Centre, titleFont );
|
||||||
Anchor.Centre, Anchor.Centre, regularFont ),
|
for( int i = 0; i < body.Length; i++ ) {
|
||||||
};
|
labels[i + 1] = TextWidget.Create( game, 0, -70 + 20 * i, body[i],
|
||||||
|
Anchor.Centre, Anchor.Centre, regularFont );
|
||||||
|
}
|
||||||
}
|
}
|
||||||
TextWidget[] labels;
|
TextWidget[] labels;
|
||||||
|
Action<object> yesClick, noClick;
|
||||||
|
|
||||||
void OnYesClick( Game g, Widget w ) {
|
void OnYesClick( Game g, Widget w ) {
|
||||||
game.SetNewScreen( null );
|
if( yesClick != null )
|
||||||
|
yesClick( Metadata );
|
||||||
|
Dispose();
|
||||||
|
CloseScreen();
|
||||||
}
|
}
|
||||||
|
|
||||||
void OnNoClick( Game g, Widget w ) {
|
void OnNoClick( Game g, Widget w ) {
|
||||||
game.SetNewScreen( null );
|
if( noClick != null )
|
||||||
|
noClick( Metadata );
|
||||||
|
Dispose();
|
||||||
|
CloseScreen();
|
||||||
|
}
|
||||||
|
|
||||||
|
void CloseScreen() {
|
||||||
|
game.WarningScreens.RemoveAt( 0 );
|
||||||
|
if( game.WarningScreens.Count > 0 ) {
|
||||||
|
game.activeScreen = game.WarningScreens[0];
|
||||||
|
} else {
|
||||||
|
game.activeScreen = lastScreen;
|
||||||
|
if( game.CursorVisible != lastCursorVisible )
|
||||||
|
game.CursorVisible = lastCursorVisible;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public override void Render( double delta ) {
|
public override void Render( double delta ) {
|
||||||
@ -50,5 +80,11 @@ namespace ClassicalSharp {
|
|||||||
for( int i = 0; i < labels.Length; i++ )
|
for( int i = 0; i < labels.Length; i++ )
|
||||||
labels[i].OnResize( oldWidth, oldHeight, width, height );
|
labels[i].OnResize( oldWidth, oldHeight, width, height );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public override void Dispose() {
|
||||||
|
base.Dispose();
|
||||||
|
for( int i = 0; i < labels.Length; i++ )
|
||||||
|
labels[i].Dispose();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -211,6 +211,7 @@
|
|||||||
<Compile Include="Singleplayer\Commands.cs" />
|
<Compile Include="Singleplayer\Commands.cs" />
|
||||||
<Compile Include="Singleplayer\Physics.cs" />
|
<Compile Include="Singleplayer\Physics.cs" />
|
||||||
<Compile Include="Singleplayer\Server.cs" />
|
<Compile Include="Singleplayer\Server.cs" />
|
||||||
|
<Compile Include="TexturePack\AcceptedUrls.cs" />
|
||||||
<Compile Include="TexturePack\Animations.cs" />
|
<Compile Include="TexturePack\Animations.cs" />
|
||||||
<Compile Include="TexturePack\TextureCache.cs" />
|
<Compile Include="TexturePack\TextureCache.cs" />
|
||||||
<Compile Include="TexturePack\TerrainAtlas1D.cs" />
|
<Compile Include="TexturePack\TerrainAtlas1D.cs" />
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
using System;
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
using System.Drawing;
|
using System.Drawing;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
using System.Net;
|
using System.Net;
|
||||||
@ -75,6 +76,8 @@ namespace ClassicalSharp {
|
|||||||
internal int CloudsTextureId, RainTextureId, SnowTextureId;
|
internal int CloudsTextureId, RainTextureId, SnowTextureId;
|
||||||
internal bool screenshotRequested;
|
internal bool screenshotRequested;
|
||||||
public Bitmap FontBitmap;
|
public Bitmap FontBitmap;
|
||||||
|
internal List<WarningScreen> WarningScreens = new List<WarningScreen>();
|
||||||
|
internal AcceptedUrls AcceptedUrls = new AcceptedUrls();
|
||||||
|
|
||||||
string defTexturePack = "default.zip";
|
string defTexturePack = "default.zip";
|
||||||
public string DefaultTexturePack {
|
public string DefaultTexturePack {
|
||||||
@ -109,6 +112,7 @@ namespace ClassicalSharp {
|
|||||||
Players = new EntityList( this );
|
Players = new EntityList( this );
|
||||||
|
|
||||||
Options.Load();
|
Options.Load();
|
||||||
|
AcceptedUrls.Load();
|
||||||
ViewDistance = Options.GetInt( OptionsKey.ViewDist, 16, 4096, 512 );
|
ViewDistance = Options.GetInt( OptionsKey.ViewDist, 16, 4096, 512 );
|
||||||
InputHandler = new InputHandler( this );
|
InputHandler = new InputHandler( this );
|
||||||
Chat = new ChatLog( this );
|
Chat = new ChatLog( this );
|
||||||
@ -192,11 +196,6 @@ namespace ClassicalSharp {
|
|||||||
UpdateProjection();
|
UpdateProjection();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void RefreshHud() {
|
|
||||||
hudScreen.Dispose();
|
|
||||||
hudScreen.Init();
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary> Gets whether the active screen handles all input. </summary>
|
/// <summary> Gets whether the active screen handles all input. </summary>
|
||||||
public bool ScreenLockedInput {
|
public bool ScreenLockedInput {
|
||||||
get { return activeScreen == null ? hudScreen.HandlesAllInput :
|
get { return activeScreen == null ? hudScreen.HandlesAllInput :
|
||||||
@ -335,6 +334,18 @@ namespace ClassicalSharp {
|
|||||||
|
|
||||||
internal Screen activeScreen;
|
internal Screen activeScreen;
|
||||||
public void SetNewScreen( Screen screen ) {
|
public void SetNewScreen( Screen screen ) {
|
||||||
|
// don't switch to the new screen immediately if the user
|
||||||
|
// is currently looking at a warning dialog.
|
||||||
|
if( activeScreen is WarningScreen ) {
|
||||||
|
WarningScreen warning = (WarningScreen)activeScreen;
|
||||||
|
if( warning.lastScreen != null )
|
||||||
|
warning.lastScreen.Dispose();
|
||||||
|
|
||||||
|
warning.lastScreen = screen;
|
||||||
|
if( warning.lastScreen != null )
|
||||||
|
screen.Init();
|
||||||
|
return;
|
||||||
|
}
|
||||||
InputHandler.ScreenChanged( activeScreen, screen );
|
InputHandler.ScreenChanged( activeScreen, screen );
|
||||||
if( activeScreen != null )
|
if( activeScreen != null )
|
||||||
activeScreen.Dispose();
|
activeScreen.Dispose();
|
||||||
@ -350,6 +361,25 @@ namespace ClassicalSharp {
|
|||||||
activeScreen = screen;
|
activeScreen = screen;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void RefreshHud() {
|
||||||
|
hudScreen.Dispose();
|
||||||
|
hudScreen.Init();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void ShowWarning( WarningScreen screen ) {
|
||||||
|
if( !(activeScreen is WarningScreen) ) {
|
||||||
|
screen.lastScreen = activeScreen;
|
||||||
|
activeScreen = screen;
|
||||||
|
|
||||||
|
screen.lastCursorVisible = CursorVisible;
|
||||||
|
if( !CursorVisible) CursorVisible = true;
|
||||||
|
} else {
|
||||||
|
screen.lastCursorVisible = WarningScreens[0].lastCursorVisible;
|
||||||
|
}
|
||||||
|
WarningScreens.Add( screen );
|
||||||
|
screen.Init();
|
||||||
|
}
|
||||||
|
|
||||||
public void SetCamera( bool thirdPerson ) {
|
public void SetCamera( bool thirdPerson ) {
|
||||||
PerspectiveCamera oldCam = (PerspectiveCamera)Camera;
|
PerspectiveCamera oldCam = (PerspectiveCamera)Camera;
|
||||||
Camera = (thirdPerson && CanUseThirdPersonCamera) ?
|
Camera = (thirdPerson && CanUseThirdPersonCamera) ?
|
||||||
|
@ -290,16 +290,29 @@ namespace ClassicalSharp {
|
|||||||
TexturePackExtractor extractor = new TexturePackExtractor();
|
TexturePackExtractor extractor = new TexturePackExtractor();
|
||||||
extractor.Extract( game.DefaultTexturePack, game );
|
extractor.Extract( game.DefaultTexturePack, game );
|
||||||
} else if( Utils.IsUrlPrefix( url ) ) {
|
} else if( Utils.IsUrlPrefix( url ) ) {
|
||||||
|
if( !game.AcceptedUrls.HasAccepted( url ) ) {
|
||||||
|
game.ShowWarning( new WarningScreen(
|
||||||
|
game, url, DownloadTexturePack, null,
|
||||||
|
"Do you want to download the server's texture pack?",
|
||||||
|
"The texture pack is located at:", url ) );
|
||||||
|
} else {
|
||||||
|
DownloadTexturePack( url );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Utils.LogDebug( "Image url: " + url );
|
||||||
|
}
|
||||||
|
|
||||||
|
void DownloadTexturePack( object metadata ) {
|
||||||
|
string url = (string)metadata;
|
||||||
game.Animations.Dispose();
|
game.Animations.Dispose();
|
||||||
DateTime lastModified = TextureCache.GetLastModifiedFromCache( url );
|
DateTime lastModified = TextureCache.GetLastModifiedFromCache( url );
|
||||||
|
if( !game.AcceptedUrls.HasAccepted( url ) )
|
||||||
|
game.AcceptedUrls.AddAccepted( url );
|
||||||
|
|
||||||
if( usingTexturePack )
|
if( usingTexturePack )
|
||||||
game.AsyncDownloader.DownloadData( url, true, "texturePack", lastModified );
|
game.AsyncDownloader.DownloadData( url, true, "texturePack", lastModified );
|
||||||
else
|
else
|
||||||
game.AsyncDownloader.DownloadImage( url, true, "terrain", lastModified );
|
game.AsyncDownloader.DownloadImage( url, true, "terrain", lastModified );
|
||||||
|
|
||||||
}
|
|
||||||
Utils.LogDebug( "Image url: " + url );
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void HandleCpeEnvWeatherType() {
|
void HandleCpeEnvWeatherType() {
|
||||||
|
59
ClassicalSharp/TexturePack/AcceptedUrls.cs
Normal file
59
ClassicalSharp/TexturePack/AcceptedUrls.cs
Normal file
@ -0,0 +1,59 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.IO;
|
||||||
|
|
||||||
|
namespace ClassicalSharp {
|
||||||
|
|
||||||
|
public sealed class AcceptedUrls {
|
||||||
|
|
||||||
|
List<string> acceptedUrls = new List<string>();
|
||||||
|
const string folder = "texturecache", file = "acceptedurls.txt";
|
||||||
|
|
||||||
|
public void AddAccepted( string url ) {
|
||||||
|
acceptedUrls.Add( url );
|
||||||
|
Save();
|
||||||
|
}
|
||||||
|
|
||||||
|
public bool HasAccepted( string url ) {
|
||||||
|
return acceptedUrls.Contains( url );
|
||||||
|
}
|
||||||
|
|
||||||
|
public bool Load() {
|
||||||
|
try {
|
||||||
|
using( Stream fs = File.OpenRead( Path.Combine( folder, file ) ) )
|
||||||
|
using( StreamReader reader = new StreamReader( fs, false ) )
|
||||||
|
{
|
||||||
|
string line;
|
||||||
|
while( (line = reader.ReadLine()) != null ) {
|
||||||
|
if( line.Length == 0 && line[0] == '#' ) continue;
|
||||||
|
acceptedUrls.Add( line );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
} catch( FileNotFoundException ) {
|
||||||
|
return true;
|
||||||
|
} catch( IOException ex ) {
|
||||||
|
ErrorHandler.LogError( "loading accepted urls", ex );
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public bool Save() {
|
||||||
|
try {
|
||||||
|
if( !Directory.Exists( folder ) )
|
||||||
|
Directory.CreateDirectory( folder );
|
||||||
|
|
||||||
|
using( Stream fs = File.Create( Path.Combine( folder, file ) ) )
|
||||||
|
using( StreamWriter writer = new StreamWriter( fs ) )
|
||||||
|
{
|
||||||
|
foreach( string value in acceptedUrls )
|
||||||
|
writer.WriteLine( value );
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
} catch( IOException ex ) {
|
||||||
|
ErrorHandler.LogError( "saving accepted urls", ex );
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user