Make warning dialogs less hacky.

This commit is contained in:
UnknownShadow200 2016-04-26 19:03:06 +10:00
parent 7c88855491
commit 3efd2365e1
8 changed files with 32 additions and 46 deletions

View File

@ -11,9 +11,10 @@ namespace ClassicalSharp.Gui {
}
protected Widget[] widgets;
protected Font titleFont, regularFont;
protected FastColour backCol = new FastColour( 60, 60, 60, 160 );
protected void RenderMenuBounds() {
api.Draw2DQuad( 0, 0, game.Width, game.Height, new FastColour( 60, 60, 60, 160 ) );
api.Draw2DQuad( 0, 0, game.Width, game.Height, backCol );
}
protected void RenderMenuWidgets( double delta ) {

View File

@ -20,8 +20,6 @@ namespace ClassicalSharp.Gui {
this.showAlways = showAlways;
}
internal Screen lastScreen;
internal bool wasCursorVisible;
string title, lastTitle;
string[] body, lastBody;
bool confirmNo, confirmMode, showAlways;
@ -29,6 +27,7 @@ namespace ClassicalSharp.Gui {
public override void Init() {
titleFont = new Font( game.FontName, 16, FontStyle.Bold );
regularFont = new Font( game.FontName, 16, FontStyle.Regular );
backCol.A = 210;
InitStandardButtons();
SetText( title, body );
}
@ -66,15 +65,9 @@ namespace ClassicalSharp.Gui {
TextWidget[] labels;
void CloseScreen() {
game.WarningScreens.RemoveAt( 0 );
if( game.WarningScreens.Count > 0 ) {
game.activeScreen = game.WarningScreens[0];
} else {
game.activeScreen = lastScreen;
game.CursorVisible = wasCursorVisible;
if( game.activeScreen == null && game.CursorVisible )
game.CursorVisible = false;
}
game.WarningOverlays.RemoveAt( 0 );
if( game.WarningOverlays.Count == 0 )
game.CursorVisible = game.realVisible;
}
public override void Render( double delta ) {

View File

@ -94,7 +94,7 @@ namespace ClassicalSharp.Entities {
}
void HandleInput( ref float xMoving, ref float zMoving ) {
if( game.ScreenLockedInput ) {
if( game.ActiveScreen.HandlesAllInput ) {
physics.jumping = Hacks.Speeding = Hacks.FlyingUp = Hacks.FlyingDown = false;
} else {
if( game.IsKeyDown( KeyBinding.Forward ) ) xMoving -= 0.98f;

View File

@ -104,6 +104,8 @@ namespace ClassicalSharp {
public List<IGameComponent> Components = new List<IGameComponent>();
public List<WarningScreen> WarningOverlays = new List<WarningScreen>();
/// <summary> Account username of the player. </summary>
public string Username;
@ -164,7 +166,6 @@ namespace ClassicalSharp {
public Animations Animations;
internal int CloudsTexId, RainTexId, SnowTexId, GuiTexId, GuiClassicTexId;
internal bool screenshotRequested;
internal List<WarningScreen> WarningScreens = new List<WarningScreen>();
internal UrlsList AcceptedUrls = new UrlsList( "acceptedurls.txt" ), DeniedUrls = new UrlsList( "deniedurls.txt" );
/// <summary> Calculates the amount that the hotbar widget should be scaled by when rendered. </summary>
@ -226,9 +227,14 @@ namespace ClassicalSharp {
}
bool visible = true;
internal bool realVisible = true;
public bool CursorVisible {
get { return visible; }
set {
// Defer mouse visibility changes.
realVisible = value;
if( WarningOverlays.Count > 0 ) return;
// Only set the value when it has changes.
if( visible == value ) return;
window.CursorVisible = value;

View File

@ -211,13 +211,10 @@ namespace ClassicalSharp {
UpdateProjection();
}
/// <summary> Gets whether the screen the user is currently interacting with
/// handles all input. </summary>
public bool ScreenLockedInput { get { return ActiveScreen.HandlesAllInput; } }
/// <summary> Gets the screen that the user is currently interacting with. </summary>
public Screen ActiveScreen {
get { return activeScreen == null ? hudScreen : activeScreen; }
get { return WarningOverlays.Count > 0 ? WarningOverlays[0]
: activeScreen == null ? hudScreen : activeScreen; }
}
Stopwatch frameTimer = new Stopwatch();
@ -229,7 +226,7 @@ namespace ClassicalSharp {
Graphics.BindIb( defaultIb );
accumulator += delta;
Vertices = 0;
if( !Focused && !ScreenLockedInput )
if( !Focused && !ActiveScreen.HandlesAllInput )
SetNewScreen( new PauseScreen( this ) );
CheckZoomFov();
@ -299,6 +296,9 @@ namespace ClassicalSharp {
activeScreen.Render( delta );
if( activeScreen != null && !activeScreen.HidesHud && activeScreen.RenderHudAfter )
hudScreen.Render( delta );
if( WarningOverlays.Count > 0)
WarningOverlays[0].Render( delta );
Graphics.Mode3D( EnvRenderer is StandardEnvRenderer );
}
@ -392,18 +392,6 @@ namespace ClassicalSharp {
public void SetNewScreen( Screen screen ) { SetNewScreen( screen, true ); }
public void SetNewScreen( Screen screen, bool disposeOld ) {
// 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 );
if( activeScreen != null && disposeOld )
activeScreen.Dispose();
@ -422,16 +410,11 @@ namespace ClassicalSharp {
public void RefreshHud() { hudScreen.Recreate(); }
public void ShowWarning( WarningScreen screen ) {
if( !(activeScreen is WarningScreen) ) {
screen.lastScreen = activeScreen;
activeScreen = screen;
screen.wasCursorVisible = CursorVisible;
CursorVisible = true;
} else {
screen.wasCursorVisible = WarningScreens[0].wasCursorVisible;
}
WarningScreens.Add( screen );
bool cursorVis = CursorVisible;
if( WarningOverlays.Count == 0 ) CursorVisible = true;
WarningOverlays.Add( screen );
if( WarningOverlays.Count == 1 ) CursorVisible = cursorVis;
// Save cursor visibility state
screen.Init();
}
@ -516,6 +499,8 @@ namespace ClassicalSharp {
Graphics.DeleteTexture( ref SnowTexId );
Graphics.DeleteTexture( ref GuiTexId );
Graphics.DeleteTexture( ref GuiClassicTexId );
foreach( WarningScreen screen in WarningOverlays )
screen.Dispose();
if( Options.HasChanged ) {
Options.Load();

View File

@ -24,7 +24,7 @@ namespace ClassicalSharp {
lastClick = now;
Inventory inv = game.Inventory;
if( game.Network.UsingPlayerClick && !game.ScreenLockedInput ) {
if( game.Network.UsingPlayerClick && !game.ActiveScreen.HandlesAllInput ) {
byte targetId = game.Players.GetClosetPlayer( game.LocalPlayer );
input.ButtonStateChanged( MouseButton.Left, left, targetId );
input.ButtonStateChanged( MouseButton.Right, right, targetId );
@ -32,7 +32,8 @@ namespace ClassicalSharp {
}
int buttonsDown = (left ? 1 : 0) + (right ? 1 : 0) + (middle ? 1 : 0);
if( buttonsDown > 1 || game.ScreenLockedInput || inv.HeldBlock == Block.Air ) return;
if( buttonsDown > 1 || game.ActiveScreen.HandlesAllInput ||
inv.HeldBlock == Block.Air ) return;
// always play delete animations, even if we aren't picking a block.
if( left ) game.BlockHandRenderer.SetAnimationClick( true );

View File

@ -27,7 +27,7 @@ namespace ClassicalSharp.Generator {
blocks = new byte[width * height * length];
rnd = new Random( seed );
CreateHeightmap();
CreateHeightmap();
CreateStrata();
CarveCaves();
CarveOreVeins( 0.9f, "coal ore", (byte)Block.CoalOre );

View File

@ -105,7 +105,7 @@ namespace ClassicalSharp {
}
public override void Tick( double elapsed ) {
if( game.ScreenLockedInput ) return;
if( game.ActiveScreen.HandlesAllInput ) return;
CentreMousePosition();
UpdateMouseRotation();
}