mirror of
https://github.com/ClassiCube/ClassiCube.git
synced 2025-09-16 19:15:14 -04:00
Make warning dialogs less hacky.
This commit is contained in:
parent
7c88855491
commit
3efd2365e1
@ -11,9 +11,10 @@ namespace ClassicalSharp.Gui {
|
|||||||
}
|
}
|
||||||
protected Widget[] widgets;
|
protected Widget[] widgets;
|
||||||
protected Font titleFont, regularFont;
|
protected Font titleFont, regularFont;
|
||||||
|
protected FastColour backCol = new FastColour( 60, 60, 60, 160 );
|
||||||
|
|
||||||
protected void RenderMenuBounds() {
|
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 ) {
|
protected void RenderMenuWidgets( double delta ) {
|
||||||
|
@ -20,8 +20,6 @@ namespace ClassicalSharp.Gui {
|
|||||||
this.showAlways = showAlways;
|
this.showAlways = showAlways;
|
||||||
}
|
}
|
||||||
|
|
||||||
internal Screen lastScreen;
|
|
||||||
internal bool wasCursorVisible;
|
|
||||||
string title, lastTitle;
|
string title, lastTitle;
|
||||||
string[] body, lastBody;
|
string[] body, lastBody;
|
||||||
bool confirmNo, confirmMode, showAlways;
|
bool confirmNo, confirmMode, showAlways;
|
||||||
@ -29,6 +27,7 @@ namespace ClassicalSharp.Gui {
|
|||||||
public override void Init() {
|
public override void Init() {
|
||||||
titleFont = new Font( game.FontName, 16, FontStyle.Bold );
|
titleFont = new Font( game.FontName, 16, FontStyle.Bold );
|
||||||
regularFont = new Font( game.FontName, 16, FontStyle.Regular );
|
regularFont = new Font( game.FontName, 16, FontStyle.Regular );
|
||||||
|
backCol.A = 210;
|
||||||
InitStandardButtons();
|
InitStandardButtons();
|
||||||
SetText( title, body );
|
SetText( title, body );
|
||||||
}
|
}
|
||||||
@ -66,15 +65,9 @@ namespace ClassicalSharp.Gui {
|
|||||||
TextWidget[] labels;
|
TextWidget[] labels;
|
||||||
|
|
||||||
void CloseScreen() {
|
void CloseScreen() {
|
||||||
game.WarningScreens.RemoveAt( 0 );
|
game.WarningOverlays.RemoveAt( 0 );
|
||||||
if( game.WarningScreens.Count > 0 ) {
|
if( game.WarningOverlays.Count == 0 )
|
||||||
game.activeScreen = game.WarningScreens[0];
|
game.CursorVisible = game.realVisible;
|
||||||
} else {
|
|
||||||
game.activeScreen = lastScreen;
|
|
||||||
game.CursorVisible = wasCursorVisible;
|
|
||||||
if( game.activeScreen == null && game.CursorVisible )
|
|
||||||
game.CursorVisible = false;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public override void Render( double delta ) {
|
public override void Render( double delta ) {
|
||||||
|
@ -94,7 +94,7 @@ namespace ClassicalSharp.Entities {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void HandleInput( ref float xMoving, ref float zMoving ) {
|
void HandleInput( ref float xMoving, ref float zMoving ) {
|
||||||
if( game.ScreenLockedInput ) {
|
if( game.ActiveScreen.HandlesAllInput ) {
|
||||||
physics.jumping = Hacks.Speeding = Hacks.FlyingUp = Hacks.FlyingDown = false;
|
physics.jumping = Hacks.Speeding = Hacks.FlyingUp = Hacks.FlyingDown = false;
|
||||||
} else {
|
} else {
|
||||||
if( game.IsKeyDown( KeyBinding.Forward ) ) xMoving -= 0.98f;
|
if( game.IsKeyDown( KeyBinding.Forward ) ) xMoving -= 0.98f;
|
||||||
|
@ -104,6 +104,8 @@ namespace ClassicalSharp {
|
|||||||
|
|
||||||
public List<IGameComponent> Components = new List<IGameComponent>();
|
public List<IGameComponent> Components = new List<IGameComponent>();
|
||||||
|
|
||||||
|
public List<WarningScreen> WarningOverlays = new List<WarningScreen>();
|
||||||
|
|
||||||
/// <summary> Account username of the player. </summary>
|
/// <summary> Account username of the player. </summary>
|
||||||
public string Username;
|
public string Username;
|
||||||
|
|
||||||
@ -164,7 +166,6 @@ namespace ClassicalSharp {
|
|||||||
public Animations Animations;
|
public Animations Animations;
|
||||||
internal int CloudsTexId, RainTexId, SnowTexId, GuiTexId, GuiClassicTexId;
|
internal int CloudsTexId, RainTexId, SnowTexId, GuiTexId, GuiClassicTexId;
|
||||||
internal bool screenshotRequested;
|
internal bool screenshotRequested;
|
||||||
internal List<WarningScreen> WarningScreens = new List<WarningScreen>();
|
|
||||||
internal UrlsList AcceptedUrls = new UrlsList( "acceptedurls.txt" ), DeniedUrls = new UrlsList( "deniedurls.txt" );
|
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>
|
/// <summary> Calculates the amount that the hotbar widget should be scaled by when rendered. </summary>
|
||||||
@ -226,9 +227,14 @@ namespace ClassicalSharp {
|
|||||||
}
|
}
|
||||||
|
|
||||||
bool visible = true;
|
bool visible = true;
|
||||||
|
internal bool realVisible = true;
|
||||||
public bool CursorVisible {
|
public bool CursorVisible {
|
||||||
get { return visible; }
|
get { return visible; }
|
||||||
set {
|
set {
|
||||||
|
// Defer mouse visibility changes.
|
||||||
|
realVisible = value;
|
||||||
|
if( WarningOverlays.Count > 0 ) return;
|
||||||
|
|
||||||
// Only set the value when it has changes.
|
// Only set the value when it has changes.
|
||||||
if( visible == value ) return;
|
if( visible == value ) return;
|
||||||
window.CursorVisible = value;
|
window.CursorVisible = value;
|
||||||
|
@ -211,13 +211,10 @@ namespace ClassicalSharp {
|
|||||||
UpdateProjection();
|
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>
|
/// <summary> Gets the screen that the user is currently interacting with. </summary>
|
||||||
public Screen ActiveScreen {
|
public Screen ActiveScreen {
|
||||||
get { return activeScreen == null ? hudScreen : activeScreen; }
|
get { return WarningOverlays.Count > 0 ? WarningOverlays[0]
|
||||||
|
: activeScreen == null ? hudScreen : activeScreen; }
|
||||||
}
|
}
|
||||||
|
|
||||||
Stopwatch frameTimer = new Stopwatch();
|
Stopwatch frameTimer = new Stopwatch();
|
||||||
@ -229,7 +226,7 @@ namespace ClassicalSharp {
|
|||||||
Graphics.BindIb( defaultIb );
|
Graphics.BindIb( defaultIb );
|
||||||
accumulator += delta;
|
accumulator += delta;
|
||||||
Vertices = 0;
|
Vertices = 0;
|
||||||
if( !Focused && !ScreenLockedInput )
|
if( !Focused && !ActiveScreen.HandlesAllInput )
|
||||||
SetNewScreen( new PauseScreen( this ) );
|
SetNewScreen( new PauseScreen( this ) );
|
||||||
CheckZoomFov();
|
CheckZoomFov();
|
||||||
|
|
||||||
@ -299,6 +296,9 @@ namespace ClassicalSharp {
|
|||||||
activeScreen.Render( delta );
|
activeScreen.Render( delta );
|
||||||
if( activeScreen != null && !activeScreen.HidesHud && activeScreen.RenderHudAfter )
|
if( activeScreen != null && !activeScreen.HidesHud && activeScreen.RenderHudAfter )
|
||||||
hudScreen.Render( delta );
|
hudScreen.Render( delta );
|
||||||
|
|
||||||
|
if( WarningOverlays.Count > 0)
|
||||||
|
WarningOverlays[0].Render( delta );
|
||||||
Graphics.Mode3D( EnvRenderer is StandardEnvRenderer );
|
Graphics.Mode3D( EnvRenderer is StandardEnvRenderer );
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -392,18 +392,6 @@ namespace ClassicalSharp {
|
|||||||
public void SetNewScreen( Screen screen ) { SetNewScreen( screen, true ); }
|
public void SetNewScreen( Screen screen ) { SetNewScreen( screen, true ); }
|
||||||
|
|
||||||
public void SetNewScreen( Screen screen, bool disposeOld ) {
|
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 );
|
InputHandler.ScreenChanged( activeScreen, screen );
|
||||||
if( activeScreen != null && disposeOld )
|
if( activeScreen != null && disposeOld )
|
||||||
activeScreen.Dispose();
|
activeScreen.Dispose();
|
||||||
@ -422,16 +410,11 @@ namespace ClassicalSharp {
|
|||||||
public void RefreshHud() { hudScreen.Recreate(); }
|
public void RefreshHud() { hudScreen.Recreate(); }
|
||||||
|
|
||||||
public void ShowWarning( WarningScreen screen ) {
|
public void ShowWarning( WarningScreen screen ) {
|
||||||
if( !(activeScreen is WarningScreen) ) {
|
bool cursorVis = CursorVisible;
|
||||||
screen.lastScreen = activeScreen;
|
if( WarningOverlays.Count == 0 ) CursorVisible = true;
|
||||||
activeScreen = screen;
|
WarningOverlays.Add( screen );
|
||||||
|
if( WarningOverlays.Count == 1 ) CursorVisible = cursorVis;
|
||||||
screen.wasCursorVisible = CursorVisible;
|
// Save cursor visibility state
|
||||||
CursorVisible = true;
|
|
||||||
} else {
|
|
||||||
screen.wasCursorVisible = WarningScreens[0].wasCursorVisible;
|
|
||||||
}
|
|
||||||
WarningScreens.Add( screen );
|
|
||||||
screen.Init();
|
screen.Init();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -516,6 +499,8 @@ namespace ClassicalSharp {
|
|||||||
Graphics.DeleteTexture( ref SnowTexId );
|
Graphics.DeleteTexture( ref SnowTexId );
|
||||||
Graphics.DeleteTexture( ref GuiTexId );
|
Graphics.DeleteTexture( ref GuiTexId );
|
||||||
Graphics.DeleteTexture( ref GuiClassicTexId );
|
Graphics.DeleteTexture( ref GuiClassicTexId );
|
||||||
|
foreach( WarningScreen screen in WarningOverlays )
|
||||||
|
screen.Dispose();
|
||||||
|
|
||||||
if( Options.HasChanged ) {
|
if( Options.HasChanged ) {
|
||||||
Options.Load();
|
Options.Load();
|
||||||
|
@ -24,7 +24,7 @@ namespace ClassicalSharp {
|
|||||||
lastClick = now;
|
lastClick = now;
|
||||||
Inventory inv = game.Inventory;
|
Inventory inv = game.Inventory;
|
||||||
|
|
||||||
if( game.Network.UsingPlayerClick && !game.ScreenLockedInput ) {
|
if( game.Network.UsingPlayerClick && !game.ActiveScreen.HandlesAllInput ) {
|
||||||
byte targetId = game.Players.GetClosetPlayer( game.LocalPlayer );
|
byte targetId = game.Players.GetClosetPlayer( game.LocalPlayer );
|
||||||
input.ButtonStateChanged( MouseButton.Left, left, targetId );
|
input.ButtonStateChanged( MouseButton.Left, left, targetId );
|
||||||
input.ButtonStateChanged( MouseButton.Right, right, targetId );
|
input.ButtonStateChanged( MouseButton.Right, right, targetId );
|
||||||
@ -32,7 +32,8 @@ namespace ClassicalSharp {
|
|||||||
}
|
}
|
||||||
|
|
||||||
int buttonsDown = (left ? 1 : 0) + (right ? 1 : 0) + (middle ? 1 : 0);
|
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.
|
// always play delete animations, even if we aren't picking a block.
|
||||||
if( left ) game.BlockHandRenderer.SetAnimationClick( true );
|
if( left ) game.BlockHandRenderer.SetAnimationClick( true );
|
||||||
|
@ -27,7 +27,7 @@ namespace ClassicalSharp.Generator {
|
|||||||
blocks = new byte[width * height * length];
|
blocks = new byte[width * height * length];
|
||||||
rnd = new Random( seed );
|
rnd = new Random( seed );
|
||||||
|
|
||||||
CreateHeightmap();
|
CreateHeightmap();
|
||||||
CreateStrata();
|
CreateStrata();
|
||||||
CarveCaves();
|
CarveCaves();
|
||||||
CarveOreVeins( 0.9f, "coal ore", (byte)Block.CoalOre );
|
CarveOreVeins( 0.9f, "coal ore", (byte)Block.CoalOre );
|
||||||
|
@ -105,7 +105,7 @@ namespace ClassicalSharp {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public override void Tick( double elapsed ) {
|
public override void Tick( double elapsed ) {
|
||||||
if( game.ScreenLockedInput ) return;
|
if( game.ActiveScreen.HandlesAllInput ) return;
|
||||||
CentreMousePosition();
|
CentreMousePosition();
|
||||||
UpdateMouseRotation();
|
UpdateMouseRotation();
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user