mirror of
https://github.com/ClassiCube/ClassiCube.git
synced 2025-09-13 09:35:23 -04:00
Implement new key mapping gui.
This commit is contained in:
parent
eccf108a90
commit
df80b95714
@ -50,12 +50,12 @@ namespace ClassicalSharp {
|
||||
g => ((int)g.Map.Weather).ToString(),
|
||||
(g, v) => g.Map.SetWeather( (Weather)Int32.Parse( v ) ) ),
|
||||
|
||||
Make( 140, 50, "Water level", Docking.Centre,OnWidgetClick,
|
||||
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 PauseScreen( g ) ), null, null ),
|
||||
(g, w) => g.SetNewScreen( new PauseScreen( g ) ), null, null ),
|
||||
null,
|
||||
};
|
||||
|
||||
@ -72,7 +72,8 @@ namespace ClassicalSharp {
|
||||
okayIndex = buttons.Length - 1;
|
||||
}
|
||||
|
||||
ButtonWidget Make( int x, int y, string text, Docking vDocking, Action<Game> onClick, Func<Game, string> getter, Action<Game, string> setter ) {
|
||||
ButtonWidget Make( int x, int y, string text, Docking vDocking, Action<Game, ButtonWidget> 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;
|
||||
|
@ -11,41 +11,84 @@ namespace ClassicalSharp {
|
||||
|
||||
public override void Render( double delta ) {
|
||||
base.Render( delta );
|
||||
statusWidget.Render( delta );
|
||||
}
|
||||
|
||||
Font keyFont;
|
||||
TextWidget statusWidget;
|
||||
static string[] keyNames;
|
||||
static string[] descriptions = new [] { "Forward", "Back", "Left", "Right", "Jump", "Respawn",
|
||||
"Set spawn", "Open chat", "Send chat", "Pause", "Open inventory", "Take screenshot",
|
||||
"Toggle fullscreen", "Toggle 3rd person", "Cycle view distance", "Toggle fly", "Speed",
|
||||
"Toggle noclip", "Fly up", "Fly down", "Display player list", "Hide gui" };
|
||||
|
||||
public override void Init() {
|
||||
if( keyNames == null )
|
||||
keyNames = Enum.GetNames( typeof( Key ) );
|
||||
keyFont = new Font( "Arial", 14, FontStyle.Bold );
|
||||
regularFont = new Font( "Arial", 14, FontStyle.Italic );
|
||||
titleFont = new Font( "Arial", 16, FontStyle.Bold );
|
||||
string[] descriptionsLeft = { "Forward", "Back", "Left", "Right", "Jump", "Respawn", "Set spawn",
|
||||
"Open chat", "Send chat", "Pause", "Open inventory" };
|
||||
string[] descriptionsRight = { "Take screenshot", "Toggle fullscreen", "Toggle 3rd person camera", "Change view distance",
|
||||
"Toggle fly", "Speed", "Toggle noclip", "Fly up", "Fly down", "Display player list", "Hide gui" };
|
||||
buttons = new ButtonWidget[descriptionsLeft.Length + descriptionsRight.Length + 1];
|
||||
buttons = new ButtonWidget[descriptions.Length + 1];
|
||||
|
||||
MakeKeys( KeyMapping.Forward, descriptionsLeft, -140 );
|
||||
MakeKeys( KeyMapping.Screenshot, descriptionsRight, 140 );
|
||||
buttons[index] = Make( 0, 5, "Back to menu", Docking.BottomOrRight, g => g.SetNewScreen( new PauseScreen( g ) ) );
|
||||
MakeKeys( 0, 11, -140 );
|
||||
MakeKeys( 11, 11, 140 );
|
||||
buttons[index] = Make( 0, 5, "Back to menu", Docking.BottomOrRight, (g, w) => g.SetNewScreen( new PauseScreen( g ) ) );
|
||||
statusWidget = TextWidget.Create( game, 0, 150, "", Docking.Centre, Docking.Centre, regularFont );
|
||||
}
|
||||
|
||||
int index;
|
||||
void MakeKeys( KeyMapping start, string[] descriptions, int x ) {
|
||||
void MakeKeys( int start, int len, int x ) {
|
||||
int y = -180;
|
||||
for( int i = 0; i < descriptions.Length; i++ ) {
|
||||
int width = x < 0 ? 180 : 240;
|
||||
buttons[index++] = ButtonWidget.Create( game, x, y, width, 25, descriptions[i],
|
||||
Docking.Centre, Docking.Centre, keyFont, g => { } );
|
||||
for( int i = 0; i < len; i++ ) {
|
||||
KeyMapping mapping = (KeyMapping)( (int)start + i );
|
||||
string text = descriptions[start + i] + ": " + keyNames[(int)game.Keys[mapping]];
|
||||
|
||||
buttons[index++] = ButtonWidget.Create( game, x, y, 240, 25, text,
|
||||
Docking.Centre, Docking.Centre, keyFont, OnWidgetClick );
|
||||
y += 30;
|
||||
}
|
||||
}
|
||||
|
||||
ButtonWidget Make( int x, int y, string text, Docking vDocking, Action<Game> onClick ) {
|
||||
ButtonWidget widget;
|
||||
void OnWidgetClick( Game game, ButtonWidget widget ) {
|
||||
this.widget = widget;
|
||||
int index = Array.IndexOf<ButtonWidget>( buttons, widget );
|
||||
statusWidget.Dispose();
|
||||
|
||||
string text = "Press new key binding for " + descriptions[index] + ":";
|
||||
statusWidget = TextWidget.Create( game, 0, 150, text, Docking.Centre, Docking.Centre, regularFont );
|
||||
}
|
||||
|
||||
public override bool HandlesKeyDown( Key key ) {
|
||||
if( widget != null ) {
|
||||
int index = Array.IndexOf<ButtonWidget>( buttons, widget );
|
||||
KeyMapping mapping = (KeyMapping)index;
|
||||
Key oldKey = game.Keys[mapping];
|
||||
string reason;
|
||||
|
||||
if( !game.Keys.IsKeyOkay( oldKey, key, out reason ) ) {
|
||||
const string format = "&eFailed to change mapping \"{0}\". &c({1})";
|
||||
statusWidget.SetText( String.Format( format, descriptions[index], reason ) );
|
||||
} else {
|
||||
const string format = "&eChanged mapping \"{0}\" from &7{1} &eto &7{2}&e.";
|
||||
statusWidget.SetText( String.Format( format, descriptions[index], oldKey, key ) );
|
||||
string text = descriptions[index] + " : " + keyNames[(int)key];
|
||||
widget.SetText( text );
|
||||
game.Keys[mapping] = key;
|
||||
}
|
||||
widget = null;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
ButtonWidget Make( int x, int y, string text, Docking vDocking, Action<Game, ButtonWidget> onClick ) {
|
||||
return ButtonWidget.Create( game, x, y, 240, 35, text, Docking.Centre, vDocking, keyFont, onClick );
|
||||
}
|
||||
|
||||
public override void Dispose() {
|
||||
keyFont.Dispose();
|
||||
base.Dispose();
|
||||
statusWidget.Dispose();
|
||||
}
|
||||
}
|
||||
}
|
@ -70,8 +70,8 @@ namespace ClassicalSharp {
|
||||
descWidget = TextWidget.Create( game, 0, 100, text, Docking.Centre, Docking.Centre, regularFont );
|
||||
}
|
||||
|
||||
protected void OnWidgetClick( Game game ) {
|
||||
if( selectedWidget == buttons[okayIndex] ) {
|
||||
protected void OnWidgetClick( Game game, ButtonWidget widget ) {
|
||||
if( widget == buttons[okayIndex] ) {
|
||||
string text = inputWidget.GetText();
|
||||
if( inputWidget.Validator.IsValidValue( text ) )
|
||||
targetWidget.SetValue( game, text );
|
||||
@ -88,9 +88,9 @@ namespace ClassicalSharp {
|
||||
inputWidget.Dispose();
|
||||
targetWidget = selectedWidget;
|
||||
|
||||
int index = Array.IndexOf<ButtonWidget>( buttons, selectedWidget );
|
||||
int index = Array.IndexOf<ButtonWidget>( buttons, widget );
|
||||
MenuInputValidator validator = validators[index];
|
||||
inputWidget = MenuInputWidget.Create( game, 0, 150, 400, 25, selectedWidget.GetValue( game ),
|
||||
inputWidget = MenuInputWidget.Create( game, 0, 150, 400, 25, widget.GetValue( game ),
|
||||
Docking.Centre, Docking.Centre, regularFont, titleFont,
|
||||
hintFont, validator );
|
||||
buttons[okayIndex] = ButtonWidget.Create( game, 240, 150, 30, 30, "OK",
|
||||
|
@ -47,7 +47,8 @@ namespace ClassicalSharp {
|
||||
for( int i = 0; i < buttons.Length; i++ ) {
|
||||
ButtonWidget widget = buttons[i];
|
||||
if( widget != null && widget.ContainsPoint( mouseX, mouseY ) ) {
|
||||
widget.OnClick( game );
|
||||
if( widget.OnClick != null )
|
||||
widget.OnClick( game, widget );
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
@ -19,31 +19,26 @@ namespace ClassicalSharp {
|
||||
|
||||
buttons = new ButtonWidget[] {
|
||||
Make( -140, -50, "Use animations", Docking.Centre, OnWidgetClick,
|
||||
g => g.Animations.Enabled ? "yes" : "no",
|
||||
(g, v) => g.Animations.Enabled = v == "yes" ),
|
||||
g => g.Animations.Enabled ? "y" : "n",
|
||||
(g, v) => g.Animations.Enabled = v == "y" ),
|
||||
|
||||
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.Graphics.SetVSync( g, v == "yes" ) ),
|
||||
g => g.VSync ? "y" : "n",
|
||||
(g, v) => g.Graphics.SetVSync( g, v == "y" ) ),
|
||||
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 ) );
|
||||
} ),
|
||||
(g, v) => g.ChatFontSize = Int32.Parse( v ) ),
|
||||
|
||||
Make( 0, 5, "Back to menu", Docking.BottomOrRight,
|
||||
g => g.SetNewScreen( new PauseScreen( g ) ), null, null ),
|
||||
(g, w) => g.SetNewScreen( new PauseScreen( g ) ), null, null ),
|
||||
null,
|
||||
};
|
||||
validators = new MenuInputValidator[] {
|
||||
@ -56,7 +51,8 @@ namespace ClassicalSharp {
|
||||
okayIndex = buttons.Length - 1;
|
||||
}
|
||||
|
||||
ButtonWidget Make( int x, int y, string text, Docking vDocking, Action<Game> onClick, Func<Game, string> getter, Action<Game, string> setter ) {
|
||||
ButtonWidget Make( int x, int y, string text, Docking vDocking, Action<Game, ButtonWidget> 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;
|
||||
|
@ -12,15 +12,15 @@ namespace ClassicalSharp {
|
||||
public override void Init() {
|
||||
titleFont = new Font( "Arial", 16, FontStyle.Bold );
|
||||
buttons = new ButtonWidget[] {
|
||||
Make( 0, -50, "Options", Docking.Centre, g => g.SetNewScreen( new OptionsScreen( g ) ) ),
|
||||
Make( 0, 0, "Environment settings", Docking.Centre, g => g.SetNewScreen( new EnvSettingsScreen( g ) ) ),
|
||||
Make( 0, 50, "Key mappings", Docking.Centre, g => g.SetNewScreen( new OldPauseScreen( g ) ) ), // TODO: Temp fix
|
||||
Make( 0, 55, "Back to game", Docking.BottomOrRight, g => g.SetNewScreen( new NormalScreen( g ) ) ),
|
||||
Make( 0, 5, "Exit", Docking.BottomOrRight, g => g.Exit() ),
|
||||
Make( 0, -50, "Options", Docking.Centre, (g, w) => g.SetNewScreen( new OptionsScreen( g ) ) ),
|
||||
Make( 0, 0, "Environment settings", Docking.Centre, (g, w) => g.SetNewScreen( new EnvSettingsScreen( g ) ) ),
|
||||
Make( 0, 50, "Key mappings", Docking.Centre, (g, w) => g.SetNewScreen( new KeyMappingsScreen( g ) ) ), // TODO: Temp fix
|
||||
Make( 0, 55, "Back to game", Docking.BottomOrRight, (g, w) => g.SetNewScreen( new NormalScreen( g ) ) ),
|
||||
Make( 0, 5, "Exit", Docking.BottomOrRight, (g, w) => g.Exit() ),
|
||||
};
|
||||
}
|
||||
|
||||
ButtonWidget Make( int x, int y, string text, Docking vDocking, Action<Game> onClick ) {
|
||||
ButtonWidget Make( int x, int y, string text, Docking vDocking, Action<Game, ButtonWidget> onClick ) {
|
||||
return ButtonWidget.Create( game, x, y, 240, 35, text, Docking.Centre, vDocking, titleFont, onClick );
|
||||
}
|
||||
}
|
||||
|
@ -1,206 +0,0 @@
|
||||
using System;
|
||||
using System.Drawing;
|
||||
using OpenTK.Input;
|
||||
|
||||
namespace ClassicalSharp {
|
||||
|
||||
public class OldPauseScreen : Screen {
|
||||
|
||||
public OldPauseScreen( Game game ) : base( game ) {
|
||||
}
|
||||
|
||||
TextWidget controlsWidget, gameWidget, keyStatusWidget;
|
||||
KeyMapWidget[] keysLeft, keysRight;
|
||||
KeyMapWidget widgetToChange;
|
||||
|
||||
public override void Render( double delta ) {
|
||||
graphicsApi.Draw2DQuad( 0, 0, game.Width, game.Height, new FastColour( 255, 255, 255, 100 ) );
|
||||
graphicsApi.Texturing = true;
|
||||
controlsWidget.Render( delta );
|
||||
gameWidget.Render( delta );
|
||||
keyStatusWidget.Render( delta );
|
||||
for( int i = 0; i < keysLeft.Length; i++ ) {
|
||||
keysLeft[i].Render( delta );
|
||||
}
|
||||
for( int i = 0; i < keysRight.Length; i++ ) {
|
||||
keysRight[i].Render( delta );
|
||||
}
|
||||
graphicsApi.Texturing = false;
|
||||
}
|
||||
|
||||
Font titleFont, keyStatusFont, textFont;
|
||||
static string[] keyNames;
|
||||
public override void Init() {
|
||||
if( keyNames == null ) {
|
||||
keyNames = Enum.GetNames( typeof( Key ) );
|
||||
}
|
||||
titleFont = new Font( "Arial", 16, FontStyle.Bold );
|
||||
keyStatusFont = new Font( "Arial", 13, FontStyle.Italic );
|
||||
textFont = new Font( "Arial", 14, FontStyle.Bold );
|
||||
controlsWidget = TextWidget.Create( game, 0, 20, "&eControls list", Docking.Centre, Docking.LeftOrTop, titleFont );
|
||||
keyStatusWidget = TextWidget.Create( game, 0, 70, "", Docking.Centre, Docking.BottomOrRight, keyStatusFont );
|
||||
gameWidget = TextWidget.Create( game, 0, 40, "&eBack to menu", Docking.Centre, Docking.BottomOrRight, titleFont );
|
||||
|
||||
string[] descriptionsLeft = { "Forward", "Back", "Left", "Right", "Jump", "Respawn", "Set spawn",
|
||||
"Open chat", "Send chat", "Pause", "Open inventory", "Take screenshot" };
|
||||
MakeKeys( KeyMapping.Forward, descriptionsLeft, 10, out keysLeft );
|
||||
leftEnd = CalculateMaxWidth( keysLeft );
|
||||
|
||||
string[] descriptionsRight = { "Toggle VSync", "Toggle fullscreen", "Toggle 3rd person camera", "Change view distance",
|
||||
"Toggle fly", "Speed", "Toggle noclip", "Fly up", "Fly down", "Display player list", "Hide gui" };
|
||||
MakeKeys( KeyMapping.VSync, descriptionsRight, leftEnd + 30, out keysRight );
|
||||
}
|
||||
|
||||
int leftEnd;
|
||||
void MakeKeys( KeyMapping start, string[] descriptions, int offset, out KeyMapWidget[] widgets ) {
|
||||
int startY = controlsWidget.BottomRight.Y + 5;
|
||||
widgets = new KeyMapWidget[descriptions.Length];
|
||||
|
||||
for( int i = 0; i < widgets.Length; i++ ) {
|
||||
KeyMapping mapping = (KeyMapping)( (int)start + i );
|
||||
Key tkKey = game.Keys[mapping];
|
||||
string text = descriptions[i] + ": " + keyNames[(int)tkKey];
|
||||
TextWidget widget = TextWidget.Create( game, offset, startY, text, Docking.LeftOrTop, Docking.LeftOrTop, textFont );
|
||||
widgets[i] = new KeyMapWidget( widget, mapping, descriptions[i] );
|
||||
startY += widget.Height + 5;
|
||||
}
|
||||
}
|
||||
|
||||
public override void Dispose() {
|
||||
textFont.Dispose();
|
||||
titleFont.Dispose();
|
||||
keyStatusFont.Dispose();
|
||||
keyStatusWidget.Dispose();
|
||||
gameWidget.Dispose();
|
||||
controlsWidget.Dispose();
|
||||
for( int i = 0; i < keysLeft.Length; i++ ) {
|
||||
keysLeft[i].Dispose();
|
||||
}
|
||||
for( int i = 0; i < keysRight.Length; i++ ) {
|
||||
keysRight[i].Dispose();
|
||||
}
|
||||
}
|
||||
|
||||
public override void OnResize( int oldWidth, int oldHeight, int width, int height ) {
|
||||
gameWidget.OnResize( oldWidth, oldHeight, width, height );
|
||||
controlsWidget.OnResize( oldWidth, oldHeight, width, height );
|
||||
keyStatusWidget.OnResize( oldWidth, oldHeight, width, height );
|
||||
for( int i = 0; i < keysLeft.Length; i++ ) {
|
||||
keysLeft[i].OnResize( oldWidth, oldHeight, width, height );
|
||||
}
|
||||
for( int i = 0; i < keysRight.Length; i++ ) {
|
||||
keysRight[i].OnResize( oldWidth, oldHeight, width, height );
|
||||
}
|
||||
}
|
||||
|
||||
public override bool HandlesAllInput {
|
||||
get { return true; }
|
||||
}
|
||||
|
||||
public override bool HandlesKeyDown( Key key ) {
|
||||
if( key == game.Keys[KeyMapping.PauseOrExit] ) {
|
||||
game.SetNewScreen( new NormalScreen( game ) );
|
||||
return true;
|
||||
}
|
||||
if( widgetToChange != null ) {
|
||||
KeyMapWidget widget = widgetToChange;
|
||||
widgetToChange = null;
|
||||
string reason;
|
||||
if( !game.Keys.IsKeyOkay( key, out reason ) ) {
|
||||
const string format = "&eFailed to change mapping \"{0}\". &c({1})";
|
||||
keyStatusWidget.SetText( String.Format( format, widget.Description, reason ) );
|
||||
} else {
|
||||
Key oldKey = game.Keys[widget.Mapping];
|
||||
const string format = "&eChanged mapping \"{0}\" from &7{1} &eto &7{2}&e.";
|
||||
keyStatusWidget.SetText( String.Format( format, widget.Description, oldKey, key ) );
|
||||
game.Keys[widget.Mapping] = key;
|
||||
widget.Widget.SetText( widget.Description + ": " + key );
|
||||
if( Array.IndexOf( keysLeft, widget ) >= 0 ) {
|
||||
ResizeKeysRight();
|
||||
}
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
void ResizeKeysRight() {
|
||||
int newLeftEnd = CalculateMaxWidth( keysLeft );
|
||||
if( newLeftEnd != leftEnd ) {
|
||||
int diff = newLeftEnd - leftEnd;
|
||||
for( int i = 0; i < keysRight.Length; i++ ) {
|
||||
TextWidget textWidget = keysRight[i].Widget;
|
||||
textWidget.XOffset = newLeftEnd + 30;
|
||||
textWidget.MoveTo( textWidget.X + diff, textWidget.Y );
|
||||
}
|
||||
}
|
||||
leftEnd = newLeftEnd;
|
||||
}
|
||||
|
||||
int CalculateMaxWidth( KeyMapWidget[] widgets ) {
|
||||
int maxWidth = 0;
|
||||
for( int i = 0; i < widgets.Length; i++ ) {
|
||||
maxWidth = Math.Max( widgets[i].Widget.Width, maxWidth );
|
||||
}
|
||||
return maxWidth;
|
||||
}
|
||||
|
||||
public override bool HandlesMouseClick( int mouseX, int mouseY, MouseButton button ) {
|
||||
if( button != MouseButton.Left ) return true;
|
||||
if( gameWidget.ContainsPoint( mouseX, mouseY ) ) {
|
||||
game.SetNewScreen( new PauseScreen( game ) );
|
||||
} else if( widgetToChange == null ) {
|
||||
for( int i = 0; i < keysLeft.Length; i++ ) {
|
||||
KeyMapWidget widget = keysLeft[i];
|
||||
if( widget.Widget.ContainsPoint( mouseX, mouseY ) ) {
|
||||
SetWidgetToChange( widget );
|
||||
return true;
|
||||
}
|
||||
}
|
||||
for( int i = 0; i < keysRight.Length; i++ ) {
|
||||
KeyMapWidget widget = keysRight[i];
|
||||
if( widget.Widget.ContainsPoint( mouseX, mouseY ) ) {
|
||||
SetWidgetToChange( widget );
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
void SetWidgetToChange( KeyMapWidget widget ) {
|
||||
Key oldKey = game.Keys[widget.Mapping];
|
||||
if( oldKey != Key.Escape && oldKey != Key.F12 ) {
|
||||
const string format = "&ePress new key for \"{0}\".";
|
||||
keyStatusWidget.SetText( String.Format( format, widget.Description ) );
|
||||
widgetToChange = widget;
|
||||
} else {
|
||||
const string format = "&cCannot change mapping of &e\"{0}\".";
|
||||
keyStatusWidget.SetText( String.Format( format, widget.Description ) );
|
||||
}
|
||||
}
|
||||
|
||||
class KeyMapWidget {
|
||||
public TextWidget Widget;
|
||||
public KeyMapping Mapping;
|
||||
public string Description;
|
||||
|
||||
public KeyMapWidget( TextWidget widget, KeyMapping mapping, string desc ) {
|
||||
Widget = widget;
|
||||
Mapping = mapping;
|
||||
Description = desc;
|
||||
}
|
||||
|
||||
public void Render( double delta ) {
|
||||
Widget.Render( delta );
|
||||
}
|
||||
|
||||
public void OnResize( int oldWidth, int oldHeight, int width, int height ) {
|
||||
Widget.OnResize( oldWidth, oldHeight, width, height );
|
||||
}
|
||||
|
||||
public void Dispose() {
|
||||
Widget.Dispose();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -13,7 +13,7 @@ namespace ClassicalSharp {
|
||||
}
|
||||
|
||||
public static ButtonWidget Create( Game game, int x, int y, int width, int height, string text, Docking horizontal,
|
||||
Docking vertical, Font font, Action<Game> onClick ) {
|
||||
Docking vertical, Font font, Action<Game, ButtonWidget> onClick ) {
|
||||
ButtonWidget widget = new ButtonWidget( game, font );
|
||||
widget.Init();
|
||||
widget.HorizontalDocking = horizontal;
|
||||
@ -77,7 +77,7 @@ namespace ClassicalSharp {
|
||||
Y = newY;
|
||||
}
|
||||
|
||||
public Action<Game> OnClick;
|
||||
public Action<Game, ButtonWidget> OnClick;
|
||||
public Func<Game, string> GetValue;
|
||||
public Action<Game, string> SetValue;
|
||||
public bool Active;
|
||||
|
@ -95,19 +95,19 @@ namespace ClassicalSharp {
|
||||
public sealed class BooleanValidator : MenuInputValidator {
|
||||
|
||||
public BooleanValidator() {
|
||||
Range = "&7(yes or no)";
|
||||
Range = "&7(y or n)";
|
||||
}
|
||||
|
||||
public override bool IsValidChar( char c ) {
|
||||
return c >= 'a' && c <= 'z';
|
||||
return c == 'y' || c == 'n';
|
||||
}
|
||||
|
||||
public override bool IsValidString( string s ) {
|
||||
return s.Length <= 3;
|
||||
return s.Length <= 1;
|
||||
}
|
||||
|
||||
public override bool IsValidValue( string s ) {
|
||||
return s == "yes" || s == "no";
|
||||
return s == "y" || s == "n";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -78,7 +78,6 @@
|
||||
<Compile Include="2D\Screens\Menu\PauseScreen.cs" />
|
||||
<Compile Include="2D\Screens\Menu\OptionsScreen.cs" />
|
||||
<Compile Include="2D\Screens\NormalScreen.cs" />
|
||||
<Compile Include="2D\Screens\OldPauseScreen.cs" />
|
||||
<Compile Include="2D\Screens\Screen.cs" />
|
||||
<Compile Include="2D\Texture.cs" />
|
||||
<Compile Include="2D\Utils2D.cs" />
|
||||
|
@ -112,8 +112,6 @@ namespace ClassicalSharp {
|
||||
} else if( key == Keys[KeyMapping.ThirdPersonCamera] ) {
|
||||
bool useThirdPerson = Camera is FirstPersonCamera;
|
||||
SetCamera( useThirdPerson );
|
||||
} else if( key == Keys[KeyMapping.VSync] ) {
|
||||
Graphics.SetVSync( this, !VSync );
|
||||
} else if( key == Keys[KeyMapping.ViewDistance] ) {
|
||||
for( int i = 0; i < viewDistances.Length; i++ ) {
|
||||
int newDist = viewDistances[i];
|
||||
@ -195,7 +193,7 @@ namespace ClassicalSharp {
|
||||
|
||||
public enum KeyMapping {
|
||||
Forward, Back, Left, Right, Jump, Respawn, SetSpawn, OpenChat,
|
||||
SendChat, PauseOrExit, OpenInventory, Screenshot, VSync, Fullscreen,
|
||||
SendChat, PauseOrExit, OpenInventory, Screenshot, Fullscreen,
|
||||
ThirdPersonCamera, ViewDistance, Fly, Speed, NoClip, FlyUp,
|
||||
FlyDown, PlayerList, HideGui,
|
||||
}
|
||||
@ -215,9 +213,14 @@ namespace ClassicalSharp {
|
||||
(key >= Key.Number0 && key <= Key.Number9); // block hotbar
|
||||
}
|
||||
|
||||
public bool IsKeyOkay( Key key, out string reason ) {
|
||||
public bool IsKeyOkay( Key oldKey, Key key, out string reason ) {
|
||||
if( oldKey == Key.Escape || oldKey == Key.F12 ) {
|
||||
reason = "This mapping is locked";
|
||||
return false;
|
||||
}
|
||||
|
||||
if( IsReservedKey( key ) ) {
|
||||
reason = "Given key is reserved for gui";
|
||||
reason = "New key is reserved";
|
||||
return false;
|
||||
}
|
||||
reason = null;
|
||||
@ -229,18 +232,18 @@ namespace ClassicalSharp {
|
||||
#if !__MonoCS__
|
||||
Keys = new Key[] {
|
||||
Key.W, Key.S, Key.A, Key.D, Key.Space, Key.R, Key.Y, Key.T,
|
||||
Key.Enter, Key.Escape, Key.B, Key.F12, Key.F7, Key.F11,
|
||||
Key.Enter, Key.Escape, Key.B, Key.F12, Key.F11,
|
||||
Key.F5, Key.F, Key.Z, Key.ShiftLeft, Key.X, Key.Q,
|
||||
Key.E, Key.Tab, Key.F1 };
|
||||
#else
|
||||
Keys = new Key[23];
|
||||
Keys = new Key[22];
|
||||
Keys[0] = Key.W; Keys[1] = Key.S; Keys[2] = Key.A; Keys[3] = Key.D;
|
||||
Keys[4] = Key.Space; Keys[5] = Key.R; Keys[6] = Key.Y; Keys[7] = Key.T;
|
||||
Keys[8] = Key.Enter; Keys[9] = Key.Escape; Keys[10] = Key.B;
|
||||
Keys[11] = Key.F12; Keys[12] = Key.F7; Keys[13] = Key.F11;
|
||||
Keys[14] = Key.F5; Keys[15] = Key.F; Keys[16] = Key.Z;
|
||||
Keys[17] = Key.ShiftLeft; Keys[18] = Key.X; Keys[19] = Key.Q;
|
||||
Keys[20] = Key.E; Keys[21] = Key.Tab; Keys[22] = Key.F1;
|
||||
Keys[11] = Key.F12; Keys[12] = Key.F11; Keys[13] = Key.F5;
|
||||
Keys[14] = Key.F; Keys[15] = Key.Z; Keys[16] = Key.ShiftLeft;
|
||||
Keys[17] = Key.X; Keys[18] = Key.Q; Keys[19] = Key.E;
|
||||
Keys[20] = Key.Tab; Keys[21] = Key.F1;
|
||||
#endif
|
||||
LoadKeyBindings();
|
||||
}
|
||||
|
@ -13,7 +13,7 @@ namespace ClassicalSharp.TexturePack {
|
||||
Bitmap bmp;
|
||||
FastBitmap fastBmp;
|
||||
List<AnimationData> animations = new List<AnimationData>();
|
||||
public bool Enabled;
|
||||
public bool Enabled = true;
|
||||
|
||||
public Animations( Game game ) {
|
||||
this.game = game;
|
||||
|
Loading…
x
Reference in New Issue
Block a user