mirror of
https://github.com/ClassiCube/ClassiCube.git
synced 2025-09-14 10:05:44 -04:00
Much more work on new client gui.
This commit is contained in:
parent
057859dcda
commit
fde7eef0db
@ -1,35 +1,82 @@
|
||||
using System;
|
||||
using System.Drawing;
|
||||
using OpenTK.Input;
|
||||
using ClassicalSharp.Renderers;
|
||||
|
||||
namespace ClassicalSharp {
|
||||
|
||||
public class EnvSettingsScreen : MenuScreen {
|
||||
public class EnvSettingsScreen : MenuInputScreen {
|
||||
|
||||
public EnvSettingsScreen( Game game ) : base( game ) {
|
||||
}
|
||||
|
||||
public override void Render( double delta ) {
|
||||
base.Render( delta );
|
||||
}
|
||||
|
||||
public override void Init() {
|
||||
titleFont = new Font( "Arial", 16, FontStyle.Bold );
|
||||
regularFont = new Font( "Arial", 16, FontStyle.Regular );
|
||||
hintFont = new Font( "Arial", 14, FontStyle.Italic );
|
||||
|
||||
buttons = new ButtonWidget[] {
|
||||
Make( -140, -100, "Clouds colour", Docking.Centre, g => { } ),
|
||||
Make( -140, -50, "Sky colour", Docking.Centre, g => { } ),
|
||||
Make( -140, 0, "Fog colour", Docking.Centre, g => { } ),
|
||||
Make( -140, 50, "Clouds speed", Docking.Centre, g => { } ),
|
||||
Make( 140, -100, "Sunlight colour", Docking.Centre, g => { } ),
|
||||
Make( 140, -50, "Shadow colour", Docking.Centre, g => { } ),
|
||||
Make( 140, 0, "Weather", Docking.Centre, g => { } ),
|
||||
Make( 140, 50, "Cloud offset", Docking.Centre, g => { } ),
|
||||
Make( 0, 5, "Back to menu", Docking.BottomOrRight, g => g.SetNewScreen( new NewPauseScreen( g ) ) ),
|
||||
Make( -140, -100, "Clouds colour", Docking.Centre, OnWidgetClick,
|
||||
g => g.Map.CloudsCol.ToRGBHexString(),
|
||||
(g, v) => g.Map.SetCloudsColour( FastColour.Parse( v ) ) ),
|
||||
|
||||
Make( -140, -50, "Sky colour", Docking.Centre, OnWidgetClick,
|
||||
g => g.Map.SkyCol.ToRGBHexString(),
|
||||
(g, v) => g.Map.SetSkyColour( FastColour.Parse( v ) ) ),
|
||||
|
||||
Make( -140, 0, "Fog colour", Docking.Centre, OnWidgetClick,
|
||||
g => g.Map.FogCol.ToRGBHexString(),
|
||||
(g, v) => g.Map.SetFogColour( FastColour.Parse( v ) ) ),
|
||||
|
||||
Make( -140, 50, "Clouds speed", Docking.Centre, OnWidgetClick,
|
||||
g => {
|
||||
StandardEnvRenderer env = game.EnvRenderer as StandardEnvRenderer;
|
||||
return env == null ? "(not active)" : env.CloudsSpeed.ToString();
|
||||
},
|
||||
(g, v) => {
|
||||
StandardEnvRenderer env = game.EnvRenderer as StandardEnvRenderer;
|
||||
if( env != null )
|
||||
env.CloudsSpeed = Single.Parse( v );
|
||||
} ),
|
||||
|
||||
Make( 140, -100, "Sunlight colour", Docking.Centre, OnWidgetClick,
|
||||
g => g.Map.Sunlight.ToRGBHexString(),
|
||||
(g, v) => g.Map.SetSunlight( FastColour.Parse( v ) ) ),
|
||||
|
||||
Make( 140, -50, "Shadow colour", Docking.Centre, OnWidgetClick,
|
||||
g => g.Map.Shadowlight.ToRGBHexString(),
|
||||
(g, v) => g.Map.SetShadowlight( FastColour.Parse( v ) ) ),
|
||||
|
||||
Make( 140, 0, "Weather", Docking.Centre, OnWidgetClick,
|
||||
g => ((int)g.Map.Weather).ToString(),
|
||||
(g, v) => g.Map.SetWeather( (Weather)Int32.Parse( v ) ) ),
|
||||
|
||||
Make( 140, 50, "Water level", Docking.Centre,OnWidgetClick,
|
||||
g => g.Map.WaterHeight.ToString(),
|
||||
(g, v) => g.Map.SetWaterLevel( Int32.Parse( v ) ) ),
|
||||
|
||||
Make( 0, 5, "Back to menu", Docking.BottomOrRight,
|
||||
g => g.SetNewScreen( new NewPauseScreen( g ) ), null, null ),
|
||||
null,
|
||||
};
|
||||
|
||||
validators = new MenuInputValidator[] {
|
||||
new HexColourValidator(),
|
||||
new HexColourValidator(),
|
||||
new HexColourValidator(),
|
||||
new RealValidator( 0, 1000 ),
|
||||
new HexColourValidator(),
|
||||
new HexColourValidator(),
|
||||
new IntegerValidator( 0, 2 ),
|
||||
new IntegerValidator( -2048, 2048 ),
|
||||
};
|
||||
okayIndex = buttons.Length - 1;
|
||||
}
|
||||
|
||||
ButtonWidget Make( int x, int y, string text, Docking vDocking, Action<Game> onClick ) {
|
||||
return ButtonWidget.Create( game, x, y, 240, 35, text, Docking.Centre, vDocking, titleFont, onClick );
|
||||
ButtonWidget Make( int x, int y, string text, Docking vDocking, Action<Game> onClick, Func<Game, string> getter, Action<Game, string> setter ) {
|
||||
ButtonWidget widget = ButtonWidget.Create( game, x, y, 240, 35, text, Docking.Centre, vDocking, titleFont, onClick );
|
||||
widget.GetValue = getter;
|
||||
widget.SetValue = setter;
|
||||
return widget;
|
||||
}
|
||||
}
|
||||
}
|
101
ClassicalSharp/2D/Screens/Menu/MenuInputScreen.cs
Normal file
101
ClassicalSharp/2D/Screens/Menu/MenuInputScreen.cs
Normal file
@ -0,0 +1,101 @@
|
||||
using System;
|
||||
using System.Drawing;
|
||||
using OpenTK.Input;
|
||||
|
||||
namespace ClassicalSharp {
|
||||
|
||||
public abstract class MenuInputScreen : MenuScreen {
|
||||
|
||||
public MenuInputScreen( Game game ) : base( game ) {
|
||||
}
|
||||
|
||||
protected MenuInputWidget inputWidget;
|
||||
protected MenuInputValidator[] validators;
|
||||
protected TextWidget descWidget;
|
||||
protected Font hintFont;
|
||||
protected int okayIndex;
|
||||
|
||||
public override void Render( double delta ) {
|
||||
base.Render( delta );
|
||||
if( inputWidget != null )
|
||||
inputWidget.Render( delta );
|
||||
if( descWidget != null )
|
||||
descWidget.Render( delta );
|
||||
}
|
||||
|
||||
public override bool HandlesKeyPress( char key ) {
|
||||
return inputWidget.HandlesKeyPress( key );
|
||||
}
|
||||
|
||||
public override bool HandlesKeyDown( Key key ) {
|
||||
return inputWidget.HandlesKeyDown( key );
|
||||
}
|
||||
|
||||
public override bool HandlesKeyUp( Key key ) {
|
||||
return inputWidget.HandlesKeyUp( key );
|
||||
}
|
||||
|
||||
public override void OnResize( int oldWidth, int oldHeight, int width, int height ) {
|
||||
if( descWidget != null )
|
||||
descWidget.OnResize( oldWidth, oldHeight, width, height );
|
||||
if( inputWidget != null )
|
||||
inputWidget.OnResize( oldWidth, oldHeight, width, height );
|
||||
base.OnResize( oldWidth, oldHeight, width, height );
|
||||
}
|
||||
|
||||
public override void Dispose() {
|
||||
if( descWidget != null )
|
||||
descWidget.Dispose();
|
||||
if( inputWidget != null )
|
||||
inputWidget.Dispose();
|
||||
hintFont.Dispose();
|
||||
base.Dispose();
|
||||
}
|
||||
|
||||
ButtonWidget selectedWidget, targetWidget;
|
||||
protected override void WidgetSelected( ButtonWidget widget ) {
|
||||
if( selectedWidget == widget || widget == null ||
|
||||
widget == buttons[buttons.Length - 2] ) return;
|
||||
|
||||
selectedWidget = widget;
|
||||
if( targetWidget != null ) return;
|
||||
UpdateDescription( selectedWidget );
|
||||
}
|
||||
|
||||
protected void UpdateDescription( ButtonWidget widget ) {
|
||||
if( descWidget != null )
|
||||
descWidget.Dispose();
|
||||
|
||||
string text = widget.Text + " : " + widget.GetValue( game );
|
||||
descWidget = TextWidget.Create( game, 0, 100, text, Docking.Centre, Docking.Centre, regularFont );
|
||||
}
|
||||
|
||||
protected void OnWidgetClick( Game game ) {
|
||||
if( selectedWidget == buttons[okayIndex] ) {
|
||||
string text = inputWidget.GetText();
|
||||
if( inputWidget.Validator.IsValidValue( text ) )
|
||||
targetWidget.SetValue( game, text );
|
||||
inputWidget.Dispose();
|
||||
inputWidget = null;
|
||||
UpdateDescription( targetWidget );
|
||||
targetWidget = null;
|
||||
buttons[okayIndex].Dispose();
|
||||
buttons[okayIndex] = null;
|
||||
return;
|
||||
}
|
||||
|
||||
if( inputWidget != null )
|
||||
inputWidget.Dispose();
|
||||
targetWidget = selectedWidget;
|
||||
|
||||
int index = Array.IndexOf<ButtonWidget>( buttons, selectedWidget );
|
||||
MenuInputValidator validator = validators[index];
|
||||
inputWidget = MenuInputWidget.Create( game, 0, 150, 400, 25, selectedWidget.GetValue( game ),
|
||||
Docking.Centre, Docking.Centre, regularFont, titleFont,
|
||||
hintFont, validator );
|
||||
buttons[okayIndex] = ButtonWidget.Create( game, 240, 150, 30, 30, "OK",
|
||||
Docking.Centre, Docking.Centre, titleFont, OnWidgetClick );
|
||||
UpdateDescription( targetWidget );
|
||||
}
|
||||
}
|
||||
}
|
@ -9,26 +9,34 @@ namespace ClassicalSharp {
|
||||
public MenuScreen( Game game ) : base( game ) {
|
||||
}
|
||||
protected ButtonWidget[] buttons;
|
||||
protected Font titleFont;
|
||||
protected Font titleFont, regularFont;
|
||||
|
||||
public override void Render( double delta ) {
|
||||
graphicsApi.Draw2DQuad( 0, 0, game.Width, game.Height, new FastColour( 255, 255, 255, 100 ) );
|
||||
graphicsApi.Draw2DQuad( 0, 0, game.Width, game.Height, new FastColour( 60, 60, 60, 160 ) );
|
||||
graphicsApi.Texturing = true;
|
||||
for( int i = 0; i < buttons.Length; i++ )
|
||||
for( int i = 0; i < buttons.Length; i++ ) {
|
||||
if( buttons[i] == null ) continue;
|
||||
buttons[i].Render( delta );
|
||||
}
|
||||
graphicsApi.Texturing = false;
|
||||
}
|
||||
|
||||
public override void Dispose() {
|
||||
for( int i = 0; i < buttons.Length; i++ )
|
||||
for( int i = 0; i < buttons.Length; i++ ) {
|
||||
if( buttons[i] == null ) continue;
|
||||
buttons[i].Dispose();
|
||||
}
|
||||
titleFont.Dispose();
|
||||
if( regularFont != null )
|
||||
regularFont.Dispose();
|
||||
}
|
||||
|
||||
public override void OnResize( int oldWidth, int oldHeight, int width, int height ) {
|
||||
for( int i = 0; i < buttons.Length; i++ )
|
||||
for( int i = 0; i < buttons.Length; i++ ) {
|
||||
if( buttons[i] == null ) continue;
|
||||
buttons[i].OnResize( oldWidth, oldHeight, width, height );
|
||||
}
|
||||
}
|
||||
|
||||
public override bool HandlesAllInput {
|
||||
get { return true; }
|
||||
@ -38,7 +46,7 @@ namespace ClassicalSharp {
|
||||
if( button != MouseButton.Left ) return false;
|
||||
for( int i = 0; i < buttons.Length; i++ ) {
|
||||
ButtonWidget widget = buttons[i];
|
||||
if( widget.ContainsPoint( mouseX, mouseY ) ) {
|
||||
if( widget != null && widget.ContainsPoint( mouseX, mouseY ) ) {
|
||||
widget.OnClick( game );
|
||||
return true;
|
||||
}
|
||||
@ -47,16 +55,36 @@ namespace ClassicalSharp {
|
||||
}
|
||||
|
||||
public override bool HandlesMouseMove( int mouseX, int mouseY ) {
|
||||
for( int i = 0; i < buttons.Length; i++ )
|
||||
for( int i = 0; i < buttons.Length; i++ ) {
|
||||
if( buttons[i] == null ) continue;
|
||||
buttons[i].Active = false;
|
||||
}
|
||||
|
||||
for( int i = 0; i < buttons.Length; i++ ) {
|
||||
ButtonWidget widget = buttons[i];
|
||||
if( widget.ContainsPoint( mouseX, mouseY ) ) {
|
||||
if( widget != null && widget.ContainsPoint( mouseX, mouseY ) ) {
|
||||
widget.Active = true;
|
||||
WidgetSelected( widget );
|
||||
return true;
|
||||
}
|
||||
}
|
||||
WidgetSelected( null );
|
||||
return false;
|
||||
}
|
||||
|
||||
public override bool HandlesKeyPress( char key ) {
|
||||
return true;
|
||||
}
|
||||
|
||||
public override bool HandlesKeyDown( Key key ) {
|
||||
return true;
|
||||
}
|
||||
|
||||
public override bool HandlesKeyUp( Key key ) {
|
||||
return true;
|
||||
}
|
||||
|
||||
protected virtual void WidgetSelected( ButtonWidget widget ) {
|
||||
}
|
||||
}
|
||||
}
|
@ -1,10 +1,9 @@
|
||||
using System;
|
||||
using System.Drawing;
|
||||
using OpenTK.Input;
|
||||
|
||||
namespace ClassicalSharp {
|
||||
|
||||
public class OptionsScreen : MenuScreen {
|
||||
public class OptionsScreen : MenuInputScreen {
|
||||
|
||||
public OptionsScreen( Game game ) : base( game ) {
|
||||
}
|
||||
@ -15,18 +14,53 @@ namespace ClassicalSharp {
|
||||
|
||||
public override void Init() {
|
||||
titleFont = new Font( "Arial", 16, FontStyle.Bold );
|
||||
regularFont = new Font( "Arial", 16, FontStyle.Regular );
|
||||
hintFont = new Font( "Arial", 14, FontStyle.Italic );
|
||||
|
||||
buttons = new ButtonWidget[] {
|
||||
Make( -140, -50, "Use animations", Docking.Centre, g => { } ),
|
||||
Make( -140, 0, "View distance", Docking.Centre, g => { } ),
|
||||
Make( -140, 50, "VSync active", Docking.Centre, g => { } ),
|
||||
Make( 140, -50, "Mouse sensitivity", Docking.Centre, g => { } ),
|
||||
Make( 140, 0, "Chat font size", Docking.Centre, g => { } ),
|
||||
Make( 0, 5, "Back to menu", Docking.BottomOrRight, g => g.SetNewScreen( new NewPauseScreen( g ) ) ),
|
||||
Make( -140, -50, "Use animations", Docking.Centre, OnWidgetClick,
|
||||
g => g.Animations.Enabled ? "yes" : "no",
|
||||
(g, v) => g.Animations.Enabled = v == "yes" ),
|
||||
|
||||
Make( -140, 0, "View distance", Docking.Centre, OnWidgetClick,
|
||||
g => g.ViewDistance.ToString(),
|
||||
(g, v) => g.SetViewDistance( Int32.Parse( v ) ) ),
|
||||
|
||||
Make( -140, 50, "VSync active", Docking.Centre, OnWidgetClick,
|
||||
g => g.VSync ? "yes" : "no",
|
||||
(g, v) => g.VSync = v == "yes" ),
|
||||
Make( 140, -50, "Mouse sensitivity", Docking.Centre, OnWidgetClick,
|
||||
g => g.MouseSensitivity.ToString(),
|
||||
(g, v) => g.MouseSensitivity = Int32.Parse( v ) ),
|
||||
|
||||
Make( 140, 0, "Chat font size", Docking.Centre, OnWidgetClick,
|
||||
g => g.ChatFontSize.ToString(),
|
||||
(g, v) => {
|
||||
g.ChatFontSize = Int32.Parse( v );
|
||||
g.SetNewScreen( null );
|
||||
g.chatInInputBuffer = null;
|
||||
g.SetNewScreen( new NormalScreen( game ) );
|
||||
} ),
|
||||
|
||||
Make( 0, 5, "Back to menu", Docking.BottomOrRight,
|
||||
g => g.SetNewScreen( new NewPauseScreen( g ) ), null, null ),
|
||||
null,
|
||||
};
|
||||
validators = new MenuInputValidator[] {
|
||||
new BooleanValidator(),
|
||||
new IntegerValidator( 16, 8192 ),
|
||||
new BooleanValidator(),
|
||||
new IntegerValidator( 1, 100 ),
|
||||
new IntegerValidator( 6, 30 ),
|
||||
};
|
||||
okayIndex = buttons.Length - 1;
|
||||
}
|
||||
|
||||
ButtonWidget Make( int x, int y, string text, Docking vDocking, Action<Game> onClick ) {
|
||||
return ButtonWidget.Create( game, x, y, 240, 35, text, Docking.Centre, vDocking, titleFont, onClick );
|
||||
ButtonWidget Make( int x, int y, string text, Docking vDocking, Action<Game> onClick, Func<Game, string> getter, Action<Game, string> setter ) {
|
||||
ButtonWidget widget = ButtonWidget.Create( game, x, y, 240, 35, text, Docking.Centre, vDocking, titleFont, onClick );
|
||||
widget.GetValue = getter;
|
||||
widget.SetValue = setter;
|
||||
return widget;
|
||||
}
|
||||
}
|
||||
}
|
@ -40,8 +40,10 @@ namespace ClassicalSharp {
|
||||
|
||||
static FastColour boxCol = new FastColour( 169, 143, 192 ), shadowCol = new FastColour( 97, 81, 110 );
|
||||
//static FastColour boxCol = new FastColour( 29, 126, 192 ), shadowCol = new FastColour( 16, 72, 109 );
|
||||
public string Text;
|
||||
public void SetText( string text ) {
|
||||
graphicsApi.DeleteTexture( ref texture );
|
||||
Text = text;
|
||||
if( String.IsNullOrEmpty( text ) ) {
|
||||
texture = new Texture();
|
||||
Height = defaultHeight;
|
||||
@ -76,6 +78,8 @@ namespace ClassicalSharp {
|
||||
}
|
||||
|
||||
public Action<Game> OnClick;
|
||||
public Func<Game, string> GetValue;
|
||||
public Action<Game, string> SetValue;
|
||||
public bool Active;
|
||||
|
||||
void MakeTexture( string text ) {
|
||||
|
113
ClassicalSharp/2D/Widgets/Menu/MenuInputValidator.cs
Normal file
113
ClassicalSharp/2D/Widgets/Menu/MenuInputValidator.cs
Normal file
@ -0,0 +1,113 @@
|
||||
using System;
|
||||
|
||||
namespace ClassicalSharp {
|
||||
|
||||
public abstract class MenuInputValidator {
|
||||
|
||||
public string Range;
|
||||
|
||||
public abstract bool IsValidChar( char c );
|
||||
|
||||
public abstract bool IsValidString( string s );
|
||||
|
||||
public virtual bool IsValidValue( string s ) {
|
||||
return IsValidString( s );
|
||||
}
|
||||
|
||||
protected void MakeRange( string min, string max ) {
|
||||
Range = "&7(" + min + " - " + max + ")";
|
||||
}
|
||||
}
|
||||
|
||||
public sealed class HexColourValidator : MenuInputValidator {
|
||||
|
||||
public HexColourValidator() {
|
||||
Range = "&7(#000000 - #FFFFFF)";
|
||||
}
|
||||
|
||||
public override bool IsValidChar( char c ) {
|
||||
return (c >= '0' && c <= '9') || (c >= 'A' && c <= 'F' )
|
||||
|| (c >= 'a' && c <= 'f' ) || c == '#';
|
||||
}
|
||||
|
||||
public override bool IsValidString( string s ) {
|
||||
return s.Length <= 7;
|
||||
}
|
||||
|
||||
public override bool IsValidValue( string s ) {
|
||||
FastColour col;
|
||||
return FastColour.TryParse( s, out col );
|
||||
}
|
||||
}
|
||||
|
||||
public sealed class IntegerValidator : MenuInputValidator {
|
||||
|
||||
int min, max;
|
||||
public IntegerValidator( int min, int max ) {
|
||||
this.min = min;
|
||||
this.max = max;
|
||||
MakeRange( min.ToString(), max.ToString() );
|
||||
}
|
||||
|
||||
public override bool IsValidChar( char c ) {
|
||||
return (c >= '0' && c <= '9') || c == '-';
|
||||
}
|
||||
|
||||
public override bool IsValidString( string s ) {
|
||||
int value;
|
||||
if( s.Length == 1 && s[0] == '-' ) return true;
|
||||
return Int32.TryParse( s, out value );
|
||||
}
|
||||
|
||||
public override bool IsValidValue( string s ) {
|
||||
int value;
|
||||
if( !Int32.TryParse( s, out value ) ) return false;
|
||||
return min <= value && value <= max;
|
||||
}
|
||||
}
|
||||
|
||||
public sealed class RealValidator : MenuInputValidator {
|
||||
|
||||
float min, max;
|
||||
public RealValidator( float min, float max ) {
|
||||
this.min = min;
|
||||
this.max = max;
|
||||
MakeRange( min.ToString(), max.ToString() );
|
||||
}
|
||||
|
||||
public override bool IsValidChar( char c ) {
|
||||
return (c >= '0' && c <= '9') || c == '-' || c == '.' || c == ',';
|
||||
}
|
||||
|
||||
public override bool IsValidString( string s ) {
|
||||
float value;
|
||||
if( s.Length == 1 && IsValidChar( s[0] ) ) return true;
|
||||
return Single.TryParse( s, out value );
|
||||
}
|
||||
|
||||
public override bool IsValidValue( string s ) {
|
||||
float value;
|
||||
if( !Single.TryParse( s, out value ) ) return false;
|
||||
return min <= value && value <= max;
|
||||
}
|
||||
}
|
||||
|
||||
public sealed class BooleanValidator : MenuInputValidator {
|
||||
|
||||
public BooleanValidator() {
|
||||
Range = "&7(yes or no)";
|
||||
}
|
||||
|
||||
public override bool IsValidChar( char c ) {
|
||||
return c >= 'a' && c <= 'z';
|
||||
}
|
||||
|
||||
public override bool IsValidString( string s ) {
|
||||
return s.Length <= 3;
|
||||
}
|
||||
|
||||
public override bool IsValidValue( string s ) {
|
||||
return s == "yes" || s == "no";
|
||||
}
|
||||
}
|
||||
}
|
140
ClassicalSharp/2D/Widgets/Menu/MenuInputWidget.cs
Normal file
140
ClassicalSharp/2D/Widgets/Menu/MenuInputWidget.cs
Normal file
@ -0,0 +1,140 @@
|
||||
using System;
|
||||
using System.Drawing;
|
||||
using OpenTK.Input;
|
||||
|
||||
namespace ClassicalSharp {
|
||||
|
||||
public sealed class MenuInputWidget : Widget {
|
||||
|
||||
public MenuInputWidget( Game game, Font font, Font boldFont, Font hintFont ) : base( game ) {
|
||||
HorizontalDocking = Docking.LeftOrTop;
|
||||
VerticalDocking = Docking.BottomOrRight;
|
||||
this.font = font;
|
||||
this.boldFont = boldFont;
|
||||
this.hintFont = hintFont;
|
||||
chatInputText = new StringBuffer( 64 );
|
||||
}
|
||||
|
||||
public static MenuInputWidget Create( Game game, int x, int y, int width, int height, string text, Docking horizontal,
|
||||
Docking vertical, Font font, Font tildeFont, Font hintFont, MenuInputValidator validator ) {
|
||||
MenuInputWidget widget = new MenuInputWidget( game, font, tildeFont, hintFont );
|
||||
|
||||
widget.HorizontalDocking = horizontal;
|
||||
widget.VerticalDocking = vertical;
|
||||
widget.XOffset = x;
|
||||
widget.YOffset = y;
|
||||
widget.DesiredMaxWidth = width;
|
||||
widget.DesiredMaxHeight = height;
|
||||
widget.chatInputText.Append( 0, text );
|
||||
widget.Validator = validator;
|
||||
widget.Init();
|
||||
return widget;
|
||||
}
|
||||
|
||||
Texture chatInputTexture, chatCaretTexture;
|
||||
Color backColour = Color.FromArgb( 200, 30, 30, 30 );
|
||||
readonly Font font, boldFont, hintFont;
|
||||
StringBuffer chatInputText;
|
||||
public int XOffset = 0, YOffset = 0;
|
||||
public int DesiredMaxWidth, DesiredMaxHeight;
|
||||
public MenuInputValidator Validator;
|
||||
|
||||
double accumulator;
|
||||
public override void Render( double delta ) {
|
||||
chatInputTexture.Render( graphicsApi );
|
||||
if( (accumulator % 1) >= 0.5 )
|
||||
chatCaretTexture.Render( graphicsApi );
|
||||
accumulator += delta;
|
||||
}
|
||||
|
||||
public override void Init() {
|
||||
DrawTextArgs caretArgs = new DrawTextArgs( graphicsApi, "_", Color.White, false );
|
||||
chatCaretTexture = Utils2D.MakeTextTexture( boldFont, 0, 0, ref caretArgs );
|
||||
SetText( chatInputText.GetString() );
|
||||
}
|
||||
|
||||
public void SetText( string value ) {
|
||||
chatInputText.Append( 0, value );
|
||||
Size textSize = Utils2D.MeasureSize( value, font, false );
|
||||
Size size = new Size( Math.Max( textSize.Width, DesiredMaxWidth ),
|
||||
Math.Max( textSize.Height, DesiredMaxHeight ) );
|
||||
|
||||
using( Bitmap bmp = Utils2D.CreatePow2Bitmap( size ) ) {
|
||||
using( Graphics g = Graphics.FromImage( bmp ) ) {
|
||||
Utils2D.DrawRect( g, backColour, 0, 0, size.Width, size.Height );
|
||||
DrawTextArgs args = new DrawTextArgs( graphicsApi, value, Color.White, false );
|
||||
args.SkipPartsCheck = true;
|
||||
Utils2D.DrawText( g, font, ref args, 0, 0 );
|
||||
|
||||
string range = Validator.Range;
|
||||
Size hintSize = Utils2D.MeasureSize( range, hintFont, true );
|
||||
args = new DrawTextArgs( graphicsApi, range, Color.White, false );
|
||||
args.SkipPartsCheck = true;
|
||||
Utils2D.DrawText( g, hintFont, ref args, size.Width - hintSize.Width, 0 );
|
||||
}
|
||||
chatInputTexture = Utils2D.Make2DTexture( graphicsApi, bmp, size, 0, 0 );
|
||||
}
|
||||
|
||||
X = CalcOffset( game.Width, size.Width, XOffset, HorizontalDocking );
|
||||
Y = CalcOffset( game.Height, size.Height, YOffset, VerticalDocking );
|
||||
chatCaretTexture.X1 = chatInputTexture.X1 = X;
|
||||
chatCaretTexture.X1 += textSize.Width;
|
||||
chatCaretTexture.Y1 = chatInputTexture.Y1 = Y;
|
||||
chatCaretTexture.Y1 = (Y + size.Height) - chatCaretTexture.Height;
|
||||
Width = size.Width;
|
||||
Height = size.Height;
|
||||
}
|
||||
|
||||
public string GetText() {
|
||||
return chatInputText.GetString();
|
||||
}
|
||||
|
||||
public override void Dispose() {
|
||||
graphicsApi.DeleteTexture( ref chatCaretTexture );
|
||||
graphicsApi.DeleteTexture( ref chatInputTexture );
|
||||
}
|
||||
|
||||
public override void MoveTo( int newX, int newY ) {
|
||||
int deltaX = newX - X;
|
||||
int deltaY = newY - Y;
|
||||
X = newX; Y = newY;
|
||||
chatCaretTexture.X1 += deltaX;
|
||||
chatCaretTexture.Y1 += deltaY;
|
||||
chatInputTexture.X1 += deltaX;
|
||||
chatInputTexture.Y1 += deltaY;
|
||||
}
|
||||
|
||||
static bool IsInvalidChar( char c ) {
|
||||
// Make sure we're in the printable text range from 0x20 to 0x7E
|
||||
return c < ' ' || c == '&' || c > '~';
|
||||
}
|
||||
|
||||
public override bool HandlesKeyPress( char key ) {
|
||||
if( chatInputText.Length < 64 && !IsInvalidChar( key ) ) {
|
||||
if( !Validator.IsValidChar( key ) ) return true;
|
||||
chatInputText.Append( chatInputText.Length, key );
|
||||
|
||||
if( !Validator.IsValidString( chatInputText.GetString() ) ) {
|
||||
chatInputText.DeleteAt( chatInputText.Length - 1 );
|
||||
return true;
|
||||
}
|
||||
graphicsApi.DeleteTexture( ref chatInputTexture );
|
||||
SetText( chatInputText.ToString() );
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public override bool HandlesKeyDown( Key key ) {
|
||||
if( key == Key.BackSpace && !chatInputText.Empty ) {
|
||||
chatInputText.DeleteAt( chatInputText.Length - 1 );
|
||||
graphicsApi.DeleteTexture( ref chatInputTexture );
|
||||
SetText( chatInputText.ToString() );
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public override bool HandlesKeyUp( Key key ) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
@ -79,7 +79,7 @@ namespace ClassicalSharp {
|
||||
chatCaretTexture.Y1 = chatInputTexture.Y1;
|
||||
Y = y;
|
||||
Width = size.Width;
|
||||
Width = size.Height;
|
||||
Height = size.Height;
|
||||
}
|
||||
|
||||
public override void Dispose() {
|
||||
|
@ -73,6 +73,7 @@
|
||||
<Compile Include="2D\Screens\LoadingMapScreen.cs" />
|
||||
<Compile Include="2D\Screens\Menu\EnvSettingsScreen.cs" />
|
||||
<Compile Include="2D\Screens\Menu\KeyMappingsScreen.cs" />
|
||||
<Compile Include="2D\Screens\Menu\MenuInputScreen.cs" />
|
||||
<Compile Include="2D\Screens\Menu\MenuScreen.cs" />
|
||||
<Compile Include="2D\Screens\Menu\NewPauseScreen.cs" />
|
||||
<Compile Include="2D\Screens\Menu\OptionsScreen.cs" />
|
||||
@ -83,6 +84,8 @@
|
||||
<Compile Include="2D\Utils2D.cs" />
|
||||
<Compile Include="2D\Widgets\BlockHotbarWidget.cs" />
|
||||
<Compile Include="2D\Widgets\ExtPlayerListWidget.cs" />
|
||||
<Compile Include="2D\Widgets\Menu\MenuInputValidator.cs" />
|
||||
<Compile Include="2D\Widgets\Menu\MenuInputWidget.cs" />
|
||||
<Compile Include="2D\Widgets\NormalPlayerListWidget.cs" />
|
||||
<Compile Include="2D\Widgets\ButtonWidget.cs" />
|
||||
<Compile Include="2D\Widgets\PlayerListWidget.cs" />
|
||||
@ -193,6 +196,7 @@
|
||||
<Folder Include="2D\Screens" />
|
||||
<Folder Include="2D\Screens\Menu" />
|
||||
<Folder Include="2D\Widgets" />
|
||||
<Folder Include="2D\Widgets\Menu" />
|
||||
<Folder Include="Blocks" />
|
||||
<Folder Include="Entities\Particles" />
|
||||
<Folder Include="GraphicsAPI" />
|
||||
|
@ -38,25 +38,7 @@ namespace ClassicalSharp.Commands {
|
||||
}
|
||||
|
||||
public bool NextHexColour( out FastColour value ) {
|
||||
value = default( FastColour );
|
||||
string next = Next();
|
||||
if( String.IsNullOrEmpty( next ) || next.Length < 6 ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
try {
|
||||
int offset = next.Length > 6 ? 1 : 0;
|
||||
if( next.Length > 6 && ( next[0] != '#' || next.Length > 7 ) ) {
|
||||
return false;
|
||||
}
|
||||
int r = Utils.ParseHex( next[offset + 0] ) * 16 + Utils.ParseHex( next[offset + 1] );
|
||||
int g = Utils.ParseHex( next[offset + 2] ) * 16 + Utils.ParseHex( next[offset + 3] );
|
||||
int b = Utils.ParseHex( next[offset + 4] ) * 16 + Utils.ParseHex( next[offset + 5] );
|
||||
value = new FastColour( r, g, b );
|
||||
return true;
|
||||
} catch( FormatException ) {
|
||||
return false;
|
||||
}
|
||||
return FastColour.TryParse( Next(), out value );
|
||||
}
|
||||
|
||||
public bool NextOf<T>( out T value, TryParseFunc<T> parser ) {
|
||||
|
@ -13,6 +13,7 @@ namespace ClassicalSharp.TexturePack {
|
||||
Bitmap bmp;
|
||||
FastBitmap fastBmp;
|
||||
List<AnimationData> animations = new List<AnimationData>();
|
||||
public bool Enabled;
|
||||
|
||||
public Animations( Game game ) {
|
||||
this.game = game;
|
||||
@ -35,7 +36,7 @@ namespace ClassicalSharp.TexturePack {
|
||||
}
|
||||
|
||||
public void Tick( double delta ) {
|
||||
if( animations.Count == 0 ) return;
|
||||
if( animations.Count == 0 || !Enabled ) return;
|
||||
|
||||
foreach( AnimationData anim in animations ) {
|
||||
ApplyAnimation( anim );
|
||||
|
@ -112,5 +112,33 @@ namespace ClassicalSharp {
|
||||
public static FastColour Yellow = new FastColour( 255, 255, 0 );
|
||||
public static FastColour Magenta = new FastColour( 255, 0, 255 );
|
||||
public static FastColour Cyan = new FastColour( 0, 255, 255 );
|
||||
|
||||
public static bool TryParse( string input, out FastColour value ) {
|
||||
value = default( FastColour );
|
||||
if( input == null || input.Length < 6 ) return false;
|
||||
|
||||
try {
|
||||
int i = input.Length > 6 ? 1 : 0;
|
||||
if( input.Length > 6 && (input[0] != '#' || input.Length > 7) )
|
||||
return false;
|
||||
|
||||
int r = Utils.ParseHex( input[i + 0] ) * 16 + Utils.ParseHex( input[i + 1] );
|
||||
int g = Utils.ParseHex( input[i + 2] ) * 16 + Utils.ParseHex( input[i + 3] );
|
||||
int b = Utils.ParseHex( input[i + 4] ) * 16 + Utils.ParseHex( input[i + 5] );
|
||||
value = new FastColour( r, g, b );
|
||||
return true;
|
||||
} catch( FormatException ) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public static FastColour Parse( string input ) {
|
||||
int i = input.Length > 6 ? 1 : 0;
|
||||
|
||||
int r = Utils.ParseHex( input[i + 0] ) * 16 + Utils.ParseHex( input[i + 1] );
|
||||
int g = Utils.ParseHex( input[i + 2] ) * 16 + Utils.ParseHex( input[i + 3] );
|
||||
int b = Utils.ParseHex( input[i + 4] ) * 16 + Utils.ParseHex( input[i + 5] );
|
||||
return new FastColour( r, g, b );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user