Implement new key mapping gui.

This commit is contained in:
UnknownShadow200 2015-09-24 15:38:56 +10:00
parent eccf108a90
commit df80b95714
12 changed files with 102 additions and 265 deletions

View File

@ -55,7 +55,7 @@ namespace ClassicalSharp {
(g, v) => g.Map.SetWaterLevel( Int32.Parse( v ) ) ), (g, v) => g.Map.SetWaterLevel( Int32.Parse( v ) ) ),
Make( 0, 5, "Back to menu", Docking.BottomOrRight, 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, null,
}; };
@ -72,7 +72,8 @@ namespace ClassicalSharp {
okayIndex = buttons.Length - 1; 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 ); ButtonWidget widget = ButtonWidget.Create( game, x, y, 240, 35, text, Docking.Centre, vDocking, titleFont, onClick );
widget.GetValue = getter; widget.GetValue = getter;
widget.SetValue = setter; widget.SetValue = setter;

View File

@ -11,41 +11,84 @@ namespace ClassicalSharp {
public override void Render( double delta ) { public override void Render( double delta ) {
base.Render( delta ); base.Render( delta );
statusWidget.Render( delta );
} }
Font keyFont; Font keyFont;
public override void Init() { TextWidget statusWidget;
keyFont = new Font( "Arial", 14, FontStyle.Bold ); static string[] keyNames;
titleFont = new Font( "Arial", 16, FontStyle.Bold ); static string[] descriptions = new [] { "Forward", "Back", "Left", "Right", "Jump", "Respawn",
string[] descriptionsLeft = { "Forward", "Back", "Left", "Right", "Jump", "Respawn", "Set spawn", "Set spawn", "Open chat", "Send chat", "Pause", "Open inventory", "Take screenshot",
"Open chat", "Send chat", "Pause", "Open inventory" }; "Toggle fullscreen", "Toggle 3rd person", "Cycle view distance", "Toggle fly", "Speed",
string[] descriptionsRight = { "Take screenshot", "Toggle fullscreen", "Toggle 3rd person camera", "Change view distance", "Toggle noclip", "Fly up", "Fly down", "Display player list", "Hide gui" };
"Toggle fly", "Speed", "Toggle noclip", "Fly up", "Fly down", "Display player list", "Hide gui" };
buttons = new ButtonWidget[descriptionsLeft.Length + descriptionsRight.Length + 1];
MakeKeys( KeyMapping.Forward, descriptionsLeft, -140 ); public override void Init() {
MakeKeys( KeyMapping.Screenshot, descriptionsRight, 140 ); if( keyNames == null )
buttons[index] = Make( 0, 5, "Back to menu", Docking.BottomOrRight, g => g.SetNewScreen( new PauseScreen( g ) ) ); 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 );
buttons = new ButtonWidget[descriptions.Length + 1];
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; int index;
void MakeKeys( KeyMapping start, string[] descriptions, int x ) { void MakeKeys( int start, int len, int x ) {
int y = -180; int y = -180;
for( int i = 0; i < descriptions.Length; i++ ) { for( int i = 0; i < len; i++ ) {
int width = x < 0 ? 180 : 240; KeyMapping mapping = (KeyMapping)( (int)start + i );
buttons[index++] = ButtonWidget.Create( game, x, y, width, 25, descriptions[i], string text = descriptions[start + i] + ": " + keyNames[(int)game.Keys[mapping]];
Docking.Centre, Docking.Centre, keyFont, g => { } );
buttons[index++] = ButtonWidget.Create( game, x, y, 240, 25, text,
Docking.Centre, Docking.Centre, keyFont, OnWidgetClick );
y += 30; 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 ); return ButtonWidget.Create( game, x, y, 240, 35, text, Docking.Centre, vDocking, keyFont, onClick );
} }
public override void Dispose() { public override void Dispose() {
keyFont.Dispose(); keyFont.Dispose();
base.Dispose(); base.Dispose();
statusWidget.Dispose();
} }
} }
} }

View File

@ -70,8 +70,8 @@ namespace ClassicalSharp {
descWidget = TextWidget.Create( game, 0, 100, text, Docking.Centre, Docking.Centre, regularFont ); descWidget = TextWidget.Create( game, 0, 100, text, Docking.Centre, Docking.Centre, regularFont );
} }
protected void OnWidgetClick( Game game ) { protected void OnWidgetClick( Game game, ButtonWidget widget ) {
if( selectedWidget == buttons[okayIndex] ) { if( widget == buttons[okayIndex] ) {
string text = inputWidget.GetText(); string text = inputWidget.GetText();
if( inputWidget.Validator.IsValidValue( text ) ) if( inputWidget.Validator.IsValidValue( text ) )
targetWidget.SetValue( game, text ); targetWidget.SetValue( game, text );
@ -88,9 +88,9 @@ namespace ClassicalSharp {
inputWidget.Dispose(); inputWidget.Dispose();
targetWidget = selectedWidget; targetWidget = selectedWidget;
int index = Array.IndexOf<ButtonWidget>( buttons, selectedWidget ); int index = Array.IndexOf<ButtonWidget>( buttons, widget );
MenuInputValidator validator = validators[index]; 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, Docking.Centre, Docking.Centre, regularFont, titleFont,
hintFont, validator ); hintFont, validator );
buttons[okayIndex] = ButtonWidget.Create( game, 240, 150, 30, 30, "OK", buttons[okayIndex] = ButtonWidget.Create( game, 240, 150, 30, 30, "OK",

View File

@ -47,7 +47,8 @@ namespace ClassicalSharp {
for( int i = 0; i < buttons.Length; i++ ) { for( int i = 0; i < buttons.Length; i++ ) {
ButtonWidget widget = buttons[i]; ButtonWidget widget = buttons[i];
if( widget != null && widget.ContainsPoint( mouseX, mouseY ) ) { if( widget != null && widget.ContainsPoint( mouseX, mouseY ) ) {
widget.OnClick( game ); if( widget.OnClick != null )
widget.OnClick( game, widget );
return true; return true;
} }
} }

View File

@ -19,31 +19,26 @@ namespace ClassicalSharp {
buttons = new ButtonWidget[] { buttons = new ButtonWidget[] {
Make( -140, -50, "Use animations", Docking.Centre, OnWidgetClick, Make( -140, -50, "Use animations", Docking.Centre, OnWidgetClick,
g => g.Animations.Enabled ? "yes" : "no", g => g.Animations.Enabled ? "y" : "n",
(g, v) => g.Animations.Enabled = v == "yes" ), (g, v) => g.Animations.Enabled = v == "y" ),
Make( -140, 0, "View distance", Docking.Centre, OnWidgetClick, Make( -140, 0, "View distance", Docking.Centre, OnWidgetClick,
g => g.ViewDistance.ToString(), g => g.ViewDistance.ToString(),
(g, v) => g.SetViewDistance( Int32.Parse( v ) ) ), (g, v) => g.SetViewDistance( Int32.Parse( v ) ) ),
Make( -140, 50, "VSync active", Docking.Centre, OnWidgetClick, Make( -140, 50, "VSync active", Docking.Centre, OnWidgetClick,
g => g.VSync ? "yes" : "no", g => g.VSync ? "y" : "n",
(g, v) => g.Graphics.SetVSync( g, v == "yes" ) ), (g, v) => g.Graphics.SetVSync( g, v == "y" ) ),
Make( 140, -50, "Mouse sensitivity", Docking.Centre, OnWidgetClick, Make( 140, -50, "Mouse sensitivity", Docking.Centre, OnWidgetClick,
g => g.MouseSensitivity.ToString(), g => g.MouseSensitivity.ToString(),
(g, v) => g.MouseSensitivity = Int32.Parse( v ) ), (g, v) => g.MouseSensitivity = Int32.Parse( v ) ),
Make( 140, 0, "Chat font size", Docking.Centre, OnWidgetClick, Make( 140, 0, "Chat font size", Docking.Centre, OnWidgetClick,
g => g.ChatFontSize.ToString(), g => g.ChatFontSize.ToString(),
(g, v) => { (g, v) => g.ChatFontSize = Int32.Parse( 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, 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, null,
}; };
validators = new MenuInputValidator[] { validators = new MenuInputValidator[] {
@ -56,7 +51,8 @@ namespace ClassicalSharp {
okayIndex = buttons.Length - 1; 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 ); ButtonWidget widget = ButtonWidget.Create( game, x, y, 240, 35, text, Docking.Centre, vDocking, titleFont, onClick );
widget.GetValue = getter; widget.GetValue = getter;
widget.SetValue = setter; widget.SetValue = setter;

View File

@ -12,15 +12,15 @@ namespace ClassicalSharp {
public override void Init() { public override void Init() {
titleFont = new Font( "Arial", 16, FontStyle.Bold ); titleFont = new Font( "Arial", 16, FontStyle.Bold );
buttons = new ButtonWidget[] { buttons = new ButtonWidget[] {
Make( 0, -50, "Options", Docking.Centre, g => g.SetNewScreen( new OptionsScreen( g ) ) ), Make( 0, -50, "Options", Docking.Centre, (g, w) => g.SetNewScreen( new OptionsScreen( g ) ) ),
Make( 0, 0, "Environment settings", Docking.Centre, g => g.SetNewScreen( new EnvSettingsScreen( g ) ) ), Make( 0, 0, "Environment settings", Docking.Centre, (g, w) => g.SetNewScreen( new EnvSettingsScreen( g ) ) ),
Make( 0, 50, "Key mappings", Docking.Centre, g => g.SetNewScreen( new OldPauseScreen( g ) ) ), // TODO: Temp fix 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 => g.SetNewScreen( new NormalScreen( g ) ) ), Make( 0, 55, "Back to game", Docking.BottomOrRight, (g, w) => g.SetNewScreen( new NormalScreen( g ) ) ),
Make( 0, 5, "Exit", Docking.BottomOrRight, g => g.Exit() ), 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 ); return ButtonWidget.Create( game, x, y, 240, 35, text, Docking.Centre, vDocking, titleFont, onClick );
} }
} }

View File

@ -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();
}
}
}
}

View File

@ -13,7 +13,7 @@ namespace ClassicalSharp {
} }
public static ButtonWidget Create( Game game, int x, int y, int width, int height, string text, Docking horizontal, 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 ); ButtonWidget widget = new ButtonWidget( game, font );
widget.Init(); widget.Init();
widget.HorizontalDocking = horizontal; widget.HorizontalDocking = horizontal;
@ -77,7 +77,7 @@ namespace ClassicalSharp {
Y = newY; Y = newY;
} }
public Action<Game> OnClick; public Action<Game, ButtonWidget> OnClick;
public Func<Game, string> GetValue; public Func<Game, string> GetValue;
public Action<Game, string> SetValue; public Action<Game, string> SetValue;
public bool Active; public bool Active;

View File

@ -95,19 +95,19 @@ namespace ClassicalSharp {
public sealed class BooleanValidator : MenuInputValidator { public sealed class BooleanValidator : MenuInputValidator {
public BooleanValidator() { public BooleanValidator() {
Range = "&7(yes or no)"; Range = "&7(y or n)";
} }
public override bool IsValidChar( char c ) { public override bool IsValidChar( char c ) {
return c >= 'a' && c <= 'z'; return c == 'y' || c == 'n';
} }
public override bool IsValidString( string s ) { public override bool IsValidString( string s ) {
return s.Length <= 3; return s.Length <= 1;
} }
public override bool IsValidValue( string s ) { public override bool IsValidValue( string s ) {
return s == "yes" || s == "no"; return s == "y" || s == "n";
} }
} }
} }

View File

@ -78,7 +78,6 @@
<Compile Include="2D\Screens\Menu\PauseScreen.cs" /> <Compile Include="2D\Screens\Menu\PauseScreen.cs" />
<Compile Include="2D\Screens\Menu\OptionsScreen.cs" /> <Compile Include="2D\Screens\Menu\OptionsScreen.cs" />
<Compile Include="2D\Screens\NormalScreen.cs" /> <Compile Include="2D\Screens\NormalScreen.cs" />
<Compile Include="2D\Screens\OldPauseScreen.cs" />
<Compile Include="2D\Screens\Screen.cs" /> <Compile Include="2D\Screens\Screen.cs" />
<Compile Include="2D\Texture.cs" /> <Compile Include="2D\Texture.cs" />
<Compile Include="2D\Utils2D.cs" /> <Compile Include="2D\Utils2D.cs" />

View File

@ -112,8 +112,6 @@ namespace ClassicalSharp {
} else if( key == Keys[KeyMapping.ThirdPersonCamera] ) { } else if( key == Keys[KeyMapping.ThirdPersonCamera] ) {
bool useThirdPerson = Camera is FirstPersonCamera; bool useThirdPerson = Camera is FirstPersonCamera;
SetCamera( useThirdPerson ); SetCamera( useThirdPerson );
} else if( key == Keys[KeyMapping.VSync] ) {
Graphics.SetVSync( this, !VSync );
} else if( key == Keys[KeyMapping.ViewDistance] ) { } else if( key == Keys[KeyMapping.ViewDistance] ) {
for( int i = 0; i < viewDistances.Length; i++ ) { for( int i = 0; i < viewDistances.Length; i++ ) {
int newDist = viewDistances[i]; int newDist = viewDistances[i];
@ -195,7 +193,7 @@ namespace ClassicalSharp {
public enum KeyMapping { public enum KeyMapping {
Forward, Back, Left, Right, Jump, Respawn, SetSpawn, OpenChat, 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, ThirdPersonCamera, ViewDistance, Fly, Speed, NoClip, FlyUp,
FlyDown, PlayerList, HideGui, FlyDown, PlayerList, HideGui,
} }
@ -215,9 +213,14 @@ namespace ClassicalSharp {
(key >= Key.Number0 && key <= Key.Number9); // block hotbar (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 ) ) { if( IsReservedKey( key ) ) {
reason = "Given key is reserved for gui"; reason = "New key is reserved";
return false; return false;
} }
reason = null; reason = null;
@ -229,18 +232,18 @@ namespace ClassicalSharp {
#if !__MonoCS__ #if !__MonoCS__
Keys = new Key[] { Keys = new Key[] {
Key.W, Key.S, Key.A, Key.D, Key.Space, Key.R, Key.Y, Key.T, 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.F5, Key.F, Key.Z, Key.ShiftLeft, Key.X, Key.Q,
Key.E, Key.Tab, Key.F1 }; Key.E, Key.Tab, Key.F1 };
#else #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[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[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[8] = Key.Enter; Keys[9] = Key.Escape; Keys[10] = Key.B;
Keys[11] = Key.F12; Keys[12] = Key.F7; Keys[13] = Key.F11; Keys[11] = Key.F12; Keys[12] = Key.F11; Keys[13] = Key.F5;
Keys[14] = Key.F5; Keys[15] = Key.F; Keys[16] = Key.Z; Keys[14] = Key.F; Keys[15] = Key.Z; Keys[16] = Key.ShiftLeft;
Keys[17] = Key.ShiftLeft; Keys[18] = Key.X; Keys[19] = Key.Q; Keys[17] = Key.X; Keys[18] = Key.Q; Keys[19] = Key.E;
Keys[20] = Key.E; Keys[21] = Key.Tab; Keys[22] = Key.F1; Keys[20] = Key.Tab; Keys[21] = Key.F1;
#endif #endif
LoadKeyBindings(); LoadKeyBindings();
} }

View File

@ -13,7 +13,7 @@ namespace ClassicalSharp.TexturePack {
Bitmap bmp; Bitmap bmp;
FastBitmap fastBmp; FastBitmap fastBmp;
List<AnimationData> animations = new List<AnimationData>(); List<AnimationData> animations = new List<AnimationData>();
public bool Enabled; public bool Enabled = true;
public Animations( Game game ) { public Animations( Game game ) {
this.game = game; this.game = game;