mirror of
https://github.com/ClassiCube/ClassiCube.git
synced 2025-09-14 18:15:28 -04:00
Able to bind mouse buttons to keyboard, fix various things with the launcher.
This commit is contained in:
parent
c1041b0c40
commit
a10fe0336f
@ -187,8 +187,8 @@ namespace ClassicalSharp {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public override bool HandlesKeyDown( Key key ) {
|
public override bool HandlesKeyDown( Key key ) {
|
||||||
if( key == game.Keys[KeyMapping.PauseOrExit] ||
|
if( key == game.Mapping( KeyMapping.PauseOrExit ) ||
|
||||||
key == game.Keys[KeyMapping.OpenInventory] ) {
|
key == game.Mapping( KeyMapping.OpenInventory ) ) {
|
||||||
game.SetNewScreen( new NormalScreen( game ) );
|
game.SetNewScreen( new NormalScreen( game ) );
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
|
@ -200,14 +200,15 @@ namespace ClassicalSharp {
|
|||||||
suppressNextPress = false;
|
suppressNextPress = false;
|
||||||
|
|
||||||
if( HandlesAllInput ) { // text input bar
|
if( HandlesAllInput ) { // text input bar
|
||||||
if( key == game.Keys[KeyMapping.SendChat] || key == game.Keys[KeyMapping.PauseOrExit] ) {
|
if( key == game.Mapping( KeyMapping.SendChat )
|
||||||
|
|| key == game.Mapping( KeyMapping.PauseOrExit ) ) {
|
||||||
HandlesAllInput = false;
|
HandlesAllInput = false;
|
||||||
if( game.CursorVisible )
|
if( game.CursorVisible )
|
||||||
game.CursorVisible = false;
|
game.CursorVisible = false;
|
||||||
game.Camera.RegrabMouse();
|
game.Camera.RegrabMouse();
|
||||||
game.Keyboard.KeyRepeat = false;
|
game.Keyboard.KeyRepeat = false;
|
||||||
|
|
||||||
if( key == game.Keys[KeyMapping.PauseOrExit] )
|
if( key == game.Mapping( KeyMapping.PauseOrExit ) )
|
||||||
textInput.chatInputText.Clear();
|
textInput.chatInputText.Clear();
|
||||||
textInput.SendTextInBufferAndReset();
|
textInput.SendTextInBufferAndReset();
|
||||||
} else if( key == Key.PageUp ) {
|
} else if( key == Key.PageUp ) {
|
||||||
@ -221,7 +222,7 @@ namespace ClassicalSharp {
|
|||||||
if( chatIndex > game.Chat.Log.Count - chatLines )
|
if( chatIndex > game.Chat.Log.Count - chatLines )
|
||||||
chatIndex = game.Chat.Log.Count - chatLines;
|
chatIndex = game.Chat.Log.Count - chatLines;
|
||||||
ResetChat();
|
ResetChat();
|
||||||
} else if( key == game.Keys[KeyMapping.HideGui] ) {
|
} else if( key == game.Mapping( KeyMapping.HideGui ) ) {
|
||||||
game.HideGui = !game.HideGui;
|
game.HideGui = !game.HideGui;
|
||||||
} else {
|
} else {
|
||||||
textInput.HandlesKeyDown( key );
|
textInput.HandlesKeyDown( key );
|
||||||
@ -229,7 +230,7 @@ namespace ClassicalSharp {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if( key == game.Keys[KeyMapping.OpenChat] ) {
|
if( key == game.Mapping( KeyMapping.OpenChat ) ) {
|
||||||
OpenTextInputBar( "" );
|
OpenTextInputBar( "" );
|
||||||
} else if( key == Key.Slash ) {
|
} else if( key == Key.Slash ) {
|
||||||
OpenTextInputBar( "/" );
|
OpenTextInputBar( "/" );
|
||||||
|
@ -44,7 +44,8 @@ namespace ClassicalSharp {
|
|||||||
int y = -180;
|
int y = -180;
|
||||||
for( int i = 0; i < len; i++ ) {
|
for( int i = 0; i < len; i++ ) {
|
||||||
KeyMapping mapping = (KeyMapping)( (int)start + i );
|
KeyMapping mapping = (KeyMapping)( (int)start + i );
|
||||||
string text = descriptions[start + i] + ": " + keyNames[(int)game.Keys[mapping]];
|
string text = descriptions[start + i] + ": "
|
||||||
|
+ keyNames[(int)game.Mapping( mapping )];
|
||||||
|
|
||||||
buttons[index++] = ButtonWidget.Create( game, x, y, 240, 25, text,
|
buttons[index++] = ButtonWidget.Create( game, x, y, 240, 25, text,
|
||||||
Anchor.Centre, Anchor.Centre, keyFont, OnWidgetClick );
|
Anchor.Centre, Anchor.Centre, keyFont, OnWidgetClick );
|
||||||
@ -68,18 +69,20 @@ namespace ClassicalSharp {
|
|||||||
} else if( widget != null ) {
|
} else if( widget != null ) {
|
||||||
int index = Array.IndexOf<ButtonWidget>( buttons, widget );
|
int index = Array.IndexOf<ButtonWidget>( buttons, widget );
|
||||||
KeyMapping mapping = (KeyMapping)index;
|
KeyMapping mapping = (KeyMapping)index;
|
||||||
Key oldKey = game.Keys[mapping];
|
KeyMap map = game.InputHandler.Keys;
|
||||||
|
Key oldKey = map[mapping];
|
||||||
string reason;
|
string reason;
|
||||||
|
|
||||||
if( !game.Keys.IsKeyOkay( oldKey, key, out reason ) ) {
|
if( !map.IsKeyOkay( oldKey, key, out reason ) ) {
|
||||||
const string format = "&eFailed to change mapping \"{0}\". &c({1})";
|
const string format = "&eFailed to change mapping \"{0}\". &c({1})";
|
||||||
statusWidget.SetText( String.Format( format, descriptions[index], reason ) );
|
statusWidget.SetText( String.Format( format, descriptions[index], reason ) );
|
||||||
} else {
|
} else {
|
||||||
const string format = "&eChanged mapping \"{0}\" from &7{1} &eto &7{2}&e.";
|
const string format = "&eChanged mapping \"{0}\" from &7{1} &eto &7{2}&e.";
|
||||||
statusWidget.SetText( String.Format( format, descriptions[index], oldKey, key ) );
|
statusWidget.SetText( String.Format( format, descriptions[index], oldKey, key ) );
|
||||||
string text = descriptions[index] + " : " + keyNames[(int)key];
|
string text = descriptions[index] + " : " + keyNames[(int)key];
|
||||||
|
|
||||||
widget.SetText( text );
|
widget.SetText( text );
|
||||||
game.Keys[mapping] = key;
|
map[mapping] = key;
|
||||||
}
|
}
|
||||||
widget = null;
|
widget = null;
|
||||||
}
|
}
|
||||||
|
@ -96,7 +96,7 @@ namespace ClassicalSharp {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public override bool HandlesKeyDown( Key key ) {
|
public override bool HandlesKeyDown( Key key ) {
|
||||||
if( key == game.Keys[KeyMapping.PlayerList] ) {
|
if( key == game.Mapping( KeyMapping.PlayerList ) ) {
|
||||||
if( playerList == null ) {
|
if( playerList == null ) {
|
||||||
if( game.Network.UsingExtPlayerList ) {
|
if( game.Network.UsingExtPlayerList ) {
|
||||||
playerList = new ExtPlayerListWidget( game, playerFont );
|
playerList = new ExtPlayerListWidget( game, playerFont );
|
||||||
@ -114,7 +114,7 @@ namespace ClassicalSharp {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public override bool HandlesKeyUp( Key key ) {
|
public override bool HandlesKeyUp( Key key ) {
|
||||||
if( key == game.Keys[KeyMapping.PlayerList] ) {
|
if( key == game.Mapping( KeyMapping.PlayerList ) ) {
|
||||||
if( playerList != null ) {
|
if( playerList != null ) {
|
||||||
playerList.Dispose();
|
playerList.Dispose();
|
||||||
playerList = null;
|
playerList = null;
|
||||||
|
@ -251,7 +251,8 @@ namespace ClassicalSharp {
|
|||||||
}
|
}
|
||||||
|
|
||||||
internal void HandleKeyDown( Key key ) {
|
internal void HandleKeyDown( Key key ) {
|
||||||
if( key == game.Keys[KeyMapping.Respawn] && canRespawn ) {
|
KeyMap keys = game.InputHandler.Keys;
|
||||||
|
if( key == keys[KeyMapping.Respawn] && canRespawn ) {
|
||||||
Vector3I p = Vector3I.Floor( SpawnPoint );
|
Vector3I p = Vector3I.Floor( SpawnPoint );
|
||||||
if( game.Map.IsValidPos( p ) ) {
|
if( game.Map.IsValidPos( p ) ) {
|
||||||
// Spawn player at highest valid position.
|
// Spawn player at highest valid position.
|
||||||
@ -268,11 +269,11 @@ namespace ClassicalSharp {
|
|||||||
Vector3 spawn = (Vector3)p + new Vector3( 0.5f, 0.01f, 0.5f );
|
Vector3 spawn = (Vector3)p + new Vector3( 0.5f, 0.01f, 0.5f );
|
||||||
LocationUpdate update = LocationUpdate.MakePos( spawn, false );
|
LocationUpdate update = LocationUpdate.MakePos( spawn, false );
|
||||||
SetLocation( update, false );
|
SetLocation( update, false );
|
||||||
} else if( key == game.Keys[KeyMapping.SetSpawn] && canRespawn ) {
|
} else if( key == keys[KeyMapping.SetSpawn] && canRespawn ) {
|
||||||
SpawnPoint = Position;
|
SpawnPoint = Position;
|
||||||
} else if( key == game.Keys[KeyMapping.Fly] && canFly ) {
|
} else if( key == keys[KeyMapping.Fly] && canFly ) {
|
||||||
flying = !flying;
|
flying = !flying;
|
||||||
} else if( key == game.Keys[KeyMapping.NoClip] && canNoclip ) {
|
} else if( key == keys[KeyMapping.NoClip] && canNoclip ) {
|
||||||
noClip = !noClip;
|
noClip = !noClip;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -85,23 +85,6 @@ namespace ClassicalSharp {
|
|||||||
Events.RaiseTerrainAtlasChanged();
|
Events.RaiseTerrainAtlasChanged();
|
||||||
}
|
}
|
||||||
|
|
||||||
public Game( string username, string mppass, string skinServer, string defaultTexPack )
|
|
||||||
#if USE_DX
|
|
||||||
: base( 640, 480, GraphicsMode.Default, Utils.AppName, true, 0, DisplayDevice.Default ) {
|
|
||||||
#else
|
|
||||||
: base( 640, 480, GraphicsMode.Default, Utils.AppName, false, 0, DisplayDevice.Default ) {
|
|
||||||
#endif
|
|
||||||
Username = username;
|
|
||||||
Mppass = mppass;
|
|
||||||
this.skinServer = skinServer;
|
|
||||||
this.defaultTexPack = defaultTexPack;
|
|
||||||
|
|
||||||
if( !File.Exists( defaultTexPack ) ) {
|
|
||||||
Utils.LogWarning( defaultTexPack + " not found" );
|
|
||||||
this.defaultTexPack = "default.zip";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
protected override void OnLoad( EventArgs e ) {
|
protected override void OnLoad( EventArgs e ) {
|
||||||
#if !USE_DX
|
#if !USE_DX
|
||||||
Graphics = new OpenGLApi();
|
Graphics = new OpenGLApi();
|
||||||
@ -114,7 +97,6 @@ namespace ClassicalSharp {
|
|||||||
Utils.LogWarning( "Unable to load options.txt" );
|
Utils.LogWarning( "Unable to load options.txt" );
|
||||||
}
|
}
|
||||||
ViewDistance = Options.GetInt( OptionsKey.ViewDist, 16, 4096, 512 );
|
ViewDistance = Options.GetInt( OptionsKey.ViewDist, 16, 4096, 512 );
|
||||||
Keys = new KeyMap();
|
|
||||||
InputHandler = new InputHandler( this );
|
InputHandler = new InputHandler( this );
|
||||||
Chat = new ChatLog( this );
|
Chat = new ChatLog( this );
|
||||||
Chat.FontSize = Options.GetInt( OptionsKey.FontSize, 6, 30, 12 );
|
Chat.FontSize = Options.GetInt( OptionsKey.FontSize, 6, 30, 12 );
|
||||||
@ -232,10 +214,7 @@ namespace ClassicalSharp {
|
|||||||
Picking.Render( e.Time, SelectedPos );
|
Picking.Render( e.Time, SelectedPos );
|
||||||
SelectionManager.Render( e.Time );
|
SelectionManager.Render( e.Time );
|
||||||
WeatherRenderer.Render( e.Time );
|
WeatherRenderer.Render( e.Time );
|
||||||
bool left = IsMousePressed( MouseButton.Left );
|
InputHandler.PickBlocks( true );
|
||||||
bool right = IsMousePressed( MouseButton.Right );
|
|
||||||
bool middle = IsMousePressed( MouseButton.Middle );
|
|
||||||
InputHandler.PickBlocks( true, left, right, middle );
|
|
||||||
} else {
|
} else {
|
||||||
SelectedPos.SetAsInvalid();
|
SelectedPos.SetAsInvalid();
|
||||||
}
|
}
|
||||||
@ -350,19 +329,13 @@ namespace ClassicalSharp {
|
|||||||
MapRenderer.RedrawBlock( x, y, z, block, oldHeight, newHeight );
|
MapRenderer.RedrawBlock( x, y, z, block, oldHeight, newHeight );
|
||||||
}
|
}
|
||||||
|
|
||||||
public KeyMap Keys;
|
public bool IsKeyDown( Key key ) { return InputHandler.IsKeyDown( key ); }
|
||||||
public bool IsKeyDown( Key key ) {
|
|
||||||
return Keyboard[key];
|
|
||||||
}
|
|
||||||
|
|
||||||
public bool IsKeyDown( KeyMapping mapping ) {
|
public bool IsKeyDown( KeyMapping mapping ) { return InputHandler.IsKeyDown( mapping ); }
|
||||||
Key key = Keys[mapping];
|
|
||||||
return Keyboard[key];
|
|
||||||
}
|
|
||||||
|
|
||||||
public bool IsMousePressed( MouseButton button ) {
|
public bool IsMousePressed( MouseButton button ) { return InputHandler.IsMousePressed( button ); }
|
||||||
return Mouse[button];
|
|
||||||
}
|
public Key Mapping( KeyMapping mapping ) { return InputHandler.Keys[mapping]; }
|
||||||
|
|
||||||
public override void Dispose() {
|
public override void Dispose() {
|
||||||
MapRenderer.Dispose();
|
MapRenderer.Dispose();
|
||||||
@ -405,6 +378,23 @@ namespace ClassicalSharp {
|
|||||||
return !(block == 0 || (BlockInfo.IsLiquid[block] &&
|
return !(block == 0 || (BlockInfo.IsLiquid[block] &&
|
||||||
!(Inventory.CanPlace[block] && Inventory.CanDelete[block])));
|
!(Inventory.CanPlace[block] && Inventory.CanDelete[block])));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Game( string username, string mppass, string skinServer, string defaultTexPack )
|
||||||
|
#if USE_DX
|
||||||
|
: base( 640, 480, GraphicsMode.Default, Utils.AppName, true, 0, DisplayDevice.Default ) {
|
||||||
|
#else
|
||||||
|
: base( 640, 480, GraphicsMode.Default, Utils.AppName, false, 0, DisplayDevice.Default ) {
|
||||||
|
#endif
|
||||||
|
Username = username;
|
||||||
|
Mppass = mppass;
|
||||||
|
this.skinServer = skinServer;
|
||||||
|
this.defaultTexPack = defaultTexPack;
|
||||||
|
|
||||||
|
if( !File.Exists( defaultTexPack ) ) {
|
||||||
|
Utils.LogWarning( defaultTexPack + " not found" );
|
||||||
|
this.defaultTexPack = "default.zip";
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public sealed class CpeListInfo {
|
public sealed class CpeListInfo {
|
||||||
|
@ -10,6 +10,8 @@ namespace ClassicalSharp {
|
|||||||
public InputHandler( Game game ) {
|
public InputHandler( Game game ) {
|
||||||
this.game = game;
|
this.game = game;
|
||||||
RegisterInputHandlers();
|
RegisterInputHandlers();
|
||||||
|
LoadMouseToKeyMappings();
|
||||||
|
Keys = new KeyMap();
|
||||||
}
|
}
|
||||||
|
|
||||||
void RegisterInputHandlers() {
|
void RegisterInputHandlers() {
|
||||||
@ -22,12 +24,44 @@ namespace ClassicalSharp {
|
|||||||
game.Mouse.ButtonUp += MouseButtonUp;
|
game.Mouse.ButtonUp += MouseButtonUp;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Key mapLeft, mapMiddle, mapRight;
|
||||||
|
void LoadMouseToKeyMappings() {
|
||||||
|
mapLeft = Options.GetKey( OptionsKey.MouseLeft, Key.Unknown );
|
||||||
|
mapMiddle = Options.GetKey( OptionsKey.MouseMiddle, Key.Unknown );
|
||||||
|
mapRight = Options.GetKey( OptionsKey.MouseRight, Key.Unknown );
|
||||||
|
}
|
||||||
|
|
||||||
|
public KeyMap Keys;
|
||||||
|
public bool IsKeyDown( Key key ) {
|
||||||
|
return game.Keyboard[key];
|
||||||
|
}
|
||||||
|
|
||||||
|
public bool IsKeyDown( KeyMapping mapping ) {
|
||||||
|
Key key = Keys[mapping];
|
||||||
|
return game.Keyboard[key];
|
||||||
|
}
|
||||||
|
|
||||||
|
public bool IsMousePressed( MouseButton button ) {
|
||||||
|
bool down = game.Mouse[button];
|
||||||
|
if( down ) return true;
|
||||||
|
|
||||||
|
// Key --> mouse mappings
|
||||||
|
if( button == MouseButton.Left && IsKeyDown( mapLeft ) ) return true;
|
||||||
|
if( button == MouseButton.Middle && IsKeyDown( mapMiddle ) ) return true;
|
||||||
|
if( button == MouseButton.Right && IsKeyDown( mapRight ) ) return true;
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
bool[] buttonsDown = new bool[3];
|
bool[] buttonsDown = new bool[3];
|
||||||
DateTime lastClick = DateTime.MinValue;
|
DateTime lastClick = DateTime.MinValue;
|
||||||
public void PickBlocks( bool cooldown, bool left, bool right, bool middle ) {
|
public void PickBlocks( bool cooldown ) {
|
||||||
|
bool left = game.IsMousePressed( MouseButton.Left );
|
||||||
|
bool right = game.IsMousePressed( MouseButton.Right );
|
||||||
|
bool middle = game.IsMousePressed( MouseButton.Middle );
|
||||||
DateTime now = DateTime.UtcNow;
|
DateTime now = DateTime.UtcNow;
|
||||||
double delta = ( now - lastClick ).TotalMilliseconds;
|
double delta = (now - lastClick).TotalMilliseconds;
|
||||||
if( cooldown && delta < 250 ) return; // 4 times per second
|
if( cooldown && delta < 250 ) return; // 4 times per second
|
||||||
|
|
||||||
lastClick = now;
|
lastClick = now;
|
||||||
Inventory inv = game.Inventory;
|
Inventory inv = game.Inventory;
|
||||||
|
|
||||||
@ -38,7 +72,7 @@ namespace ClassicalSharp {
|
|||||||
ButtonStateChanged( MouseButton.Middle, middle, targetId );
|
ButtonStateChanged( MouseButton.Middle, middle, targetId );
|
||||||
}
|
}
|
||||||
|
|
||||||
int buttonsDown = ( left ? 1 : 0 ) + ( right ? 1 : 0 ) + ( middle ? 1 : 0 );
|
int buttonsDown = (left ? 1 : 0) + (right ? 1 : 0) + (middle ? 1 : 0);
|
||||||
if( !game.SelectedPos.Valid || buttonsDown > 1 || game.ScreenLockedInput || inv.HeldBlock == Block.Air ) return;
|
if( !game.SelectedPos.Valid || buttonsDown > 1 || game.ScreenLockedInput || inv.HeldBlock == Block.Air ) return;
|
||||||
|
|
||||||
if( middle ) {
|
if( middle ) {
|
||||||
@ -131,10 +165,7 @@ namespace ClassicalSharp {
|
|||||||
|
|
||||||
void MouseButtonDown( object sender, MouseButtonEventArgs e ) {
|
void MouseButtonDown( object sender, MouseButtonEventArgs e ) {
|
||||||
if( game.activeScreen == null || !game.activeScreen.HandlesMouseClick( e.X, e.Y, e.Button ) ) {
|
if( game.activeScreen == null || !game.activeScreen.HandlesMouseClick( e.X, e.Y, e.Button ) ) {
|
||||||
bool left = e.Button == MouseButton.Left;
|
PickBlocks( false );
|
||||||
bool right = e.Button == MouseButton.Right;
|
|
||||||
bool middle = e.Button == MouseButton.Middle;
|
|
||||||
PickBlocks( false, left, right, middle );
|
|
||||||
} else {
|
} else {
|
||||||
lastClick = DateTime.UtcNow;
|
lastClick = DateTime.UtcNow;
|
||||||
}
|
}
|
||||||
@ -166,6 +197,8 @@ namespace ClassicalSharp {
|
|||||||
|
|
||||||
void KeyUpHandler( object sender, KeyboardKeyEventArgs e ) {
|
void KeyUpHandler( object sender, KeyboardKeyEventArgs e ) {
|
||||||
Key key = e.Key;
|
Key key = e.Key;
|
||||||
|
if( SimulateMouse( key, false ) ) return;
|
||||||
|
|
||||||
if( game.activeScreen == null || !game.activeScreen.HandlesKeyUp( key ) ) {
|
if( game.activeScreen == null || !game.activeScreen.HandlesKeyUp( key ) ) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -173,9 +206,11 @@ namespace ClassicalSharp {
|
|||||||
static int[] viewDistances = { 16, 32, 64, 128, 256, 512 };
|
static int[] viewDistances = { 16, 32, 64, 128, 256, 512 };
|
||||||
void KeyDownHandler( object sender, KeyboardKeyEventArgs e ) {
|
void KeyDownHandler( object sender, KeyboardKeyEventArgs e ) {
|
||||||
Key key = e.Key;
|
Key key = e.Key;
|
||||||
|
if( SimulateMouse( key, true ) ) return;
|
||||||
|
|
||||||
if( key == Key.F4 && (game.IsKeyDown( Key.AltLeft ) || game.IsKeyDown( Key.AltRight )) ) {
|
if( key == Key.F4 && (game.IsKeyDown( Key.AltLeft ) || game.IsKeyDown( Key.AltRight )) ) {
|
||||||
game.Exit();
|
game.Exit();
|
||||||
} else if( key == game.Keys[KeyMapping.Screenshot] ) {
|
} else if( key == Keys[KeyMapping.Screenshot] ) {
|
||||||
game.screenshotRequested = true;
|
game.screenshotRequested = true;
|
||||||
} else if( game.activeScreen == null || !game.activeScreen.HandlesKeyDown( key ) ) {
|
} else if( game.activeScreen == null || !game.activeScreen.HandlesKeyDown( key ) ) {
|
||||||
if( !HandleBuiltinKey( key ) ) {
|
if( !HandleBuiltinKey( key ) ) {
|
||||||
@ -184,27 +219,45 @@ namespace ClassicalSharp {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
MouseButtonEventArgs simArgs = new MouseButtonEventArgs();
|
||||||
|
bool SimulateMouse( Key key, bool pressed ) {
|
||||||
|
if( !(key == mapLeft || key == mapMiddle || key == mapRight ) )
|
||||||
|
return false;
|
||||||
|
simArgs.Button = key == mapLeft ? MouseButton.Left :
|
||||||
|
key == mapMiddle ? MouseButton.Middle : MouseButton.Right;
|
||||||
|
simArgs.X = game.Mouse.X;
|
||||||
|
simArgs.Y = game.Mouse.Y;
|
||||||
|
simArgs.IsPressed = pressed;
|
||||||
|
|
||||||
|
if( pressed ) {
|
||||||
|
MouseButtonDown( null, simArgs );
|
||||||
|
} else {
|
||||||
|
MouseButtonUp( null, simArgs );
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
bool HandleBuiltinKey( Key key ) {
|
bool HandleBuiltinKey( Key key ) {
|
||||||
if( key == game.Keys[KeyMapping.HideGui] ) {
|
if( key == Keys[KeyMapping.HideGui] ) {
|
||||||
game.HideGui = !game.HideGui;
|
game.HideGui = !game.HideGui;
|
||||||
} else if( key == game.Keys[KeyMapping.Fullscreen] ) {
|
} else if( key == Keys[KeyMapping.Fullscreen] ) {
|
||||||
WindowState state = game.WindowState;
|
WindowState state = game.WindowState;
|
||||||
if( state != WindowState.Minimized ) {
|
if( state != WindowState.Minimized ) {
|
||||||
game.WindowState = state == WindowState.Fullscreen ?
|
game.WindowState = state == WindowState.Fullscreen ?
|
||||||
WindowState.Normal : WindowState.Fullscreen;
|
WindowState.Normal : WindowState.Fullscreen;
|
||||||
}
|
}
|
||||||
} else if( key == game.Keys[KeyMapping.ThirdPersonCamera] ) {
|
} else if( key == Keys[KeyMapping.ThirdPersonCamera] ) {
|
||||||
bool useThirdPerson = !(game.Camera is ForwardThirdPersonCamera);
|
bool useThirdPerson = !(game.Camera is ForwardThirdPersonCamera);
|
||||||
game.SetCamera( useThirdPerson );
|
game.SetCamera( useThirdPerson );
|
||||||
} else if( key == game.Keys[KeyMapping.ViewDistance] ) {
|
} else if( key == Keys[KeyMapping.ViewDistance] ) {
|
||||||
if( game.IsKeyDown( Key.ShiftLeft ) || game.IsKeyDown( Key.ShiftRight ) ) {
|
if( game.IsKeyDown( Key.ShiftLeft ) || game.IsKeyDown( Key.ShiftRight ) ) {
|
||||||
CycleDistanceBackwards();
|
CycleDistanceBackwards();
|
||||||
} else {
|
} else {
|
||||||
CycleDistanceForwards();
|
CycleDistanceForwards();
|
||||||
}
|
}
|
||||||
} else if( key == game.Keys[KeyMapping.PauseOrExit] && !game.Map.IsNotLoaded ) {
|
} else if( key == Keys[KeyMapping.PauseOrExit] && !game.Map.IsNotLoaded ) {
|
||||||
game.SetNewScreen( new PauseScreen( game ) );
|
game.SetNewScreen( new PauseScreen( game ) );
|
||||||
} else if( key == game.Keys[KeyMapping.OpenInventory] ) {
|
} else if( key == Keys[KeyMapping.OpenInventory] ) {
|
||||||
game.SetNewScreen( new BlockSelectScreen( game ) );
|
game.SetNewScreen( new BlockSelectScreen( game ) );
|
||||||
} else {
|
} else {
|
||||||
return false;
|
return false;
|
||||||
|
@ -64,19 +64,7 @@ namespace ClassicalSharp {
|
|||||||
string[] names = KeyMapping.GetNames( typeof( KeyMapping ) );
|
string[] names = KeyMapping.GetNames( typeof( KeyMapping ) );
|
||||||
for( int i = 0; i < names.Length; i++ ) {
|
for( int i = 0; i < names.Length; i++ ) {
|
||||||
string key = "key-" + names[i];
|
string key = "key-" + names[i];
|
||||||
string value = Options.Get( key );
|
Key mapping = Options.GetKey( key, Keys[i] );
|
||||||
if( value == null ) {
|
|
||||||
Options.Set( key, Keys[i] );
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
Key mapping;
|
|
||||||
try {
|
|
||||||
mapping = (Key)Enum.Parse( typeof( Key ), value, true );
|
|
||||||
} catch( ArgumentException ) {
|
|
||||||
Options.Set( key, Keys[i] );
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
if( !IsReservedKey( mapping ) )
|
if( !IsReservedKey( mapping ) )
|
||||||
Keys[i] = mapping;
|
Keys[i] = mapping;
|
||||||
}
|
}
|
||||||
|
@ -1,6 +1,8 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
|
using OpenTK;
|
||||||
|
using OpenTK.Input;
|
||||||
|
|
||||||
namespace ClassicalSharp {
|
namespace ClassicalSharp {
|
||||||
|
|
||||||
@ -9,6 +11,10 @@ namespace ClassicalSharp {
|
|||||||
public const string FontSize = "chatfontsize";
|
public const string FontSize = "chatfontsize";
|
||||||
public const string Sensitivity = "mousesensitivity";
|
public const string Sensitivity = "mousesensitivity";
|
||||||
public const string Speed = "speedmultiplier";
|
public const string Speed = "speedmultiplier";
|
||||||
|
|
||||||
|
public const string MouseLeft = "mouseleft";
|
||||||
|
public const string MouseMiddle = "mousemiddle";
|
||||||
|
public const string MouseRight = "mouseright";
|
||||||
}
|
}
|
||||||
|
|
||||||
public static class Options {
|
public static class Options {
|
||||||
@ -41,6 +47,23 @@ namespace ClassicalSharp {
|
|||||||
return valueBool;
|
return valueBool;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static Key GetKey( string key, Key defValue ) {
|
||||||
|
string value = Options.Get( key );
|
||||||
|
if( value == null ) {
|
||||||
|
Set( key, defValue );
|
||||||
|
return defValue;
|
||||||
|
}
|
||||||
|
|
||||||
|
Key mapping;
|
||||||
|
try {
|
||||||
|
mapping = (Key)Enum.Parse( typeof( Key ), value, true );
|
||||||
|
} catch( ArgumentException ) {
|
||||||
|
Options.Set( key, defValue );
|
||||||
|
return defValue;
|
||||||
|
}
|
||||||
|
return mapping;
|
||||||
|
}
|
||||||
|
|
||||||
public static void Set( string key, string value ) {
|
public static void Set( string key, string value ) {
|
||||||
OptionsSet[key] = value;
|
OptionsSet[key] = value;
|
||||||
HasChanged = true;
|
HasChanged = true;
|
||||||
|
@ -19,6 +19,7 @@ namespace Launcher2 {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public override void Init() {
|
public override void Init() {
|
||||||
|
base.Init();
|
||||||
Resize();
|
Resize();
|
||||||
using( drawer ) {
|
using( drawer ) {
|
||||||
drawer.SetBitmap( game.Framebuffer );
|
drawer.SetBitmap( game.Framebuffer );
|
||||||
|
@ -14,10 +14,7 @@ namespace Launcher2 {
|
|||||||
titleFont = new Font( "Arial", 16, FontStyle.Bold );
|
titleFont = new Font( "Arial", 16, FontStyle.Bold );
|
||||||
inputFont = new Font( "Arial", 13, FontStyle.Regular );
|
inputFont = new Font( "Arial", 13, FontStyle.Regular );
|
||||||
enterIndex = 4;
|
enterIndex = 4;
|
||||||
|
|
||||||
widgets = new LauncherWidget[7];
|
widgets = new LauncherWidget[7];
|
||||||
game.Window.Mouse.WheelChanged += MouseWheelChanged;
|
|
||||||
game.Window.Mouse.ButtonUp += MouseButtonUp;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public override void Tick() {
|
public override void Tick() {
|
||||||
@ -49,7 +46,12 @@ namespace Launcher2 {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public override void Init() { Resize(); }
|
public override void Init() {
|
||||||
|
base.Init();
|
||||||
|
game.Window.Mouse.WheelChanged += MouseWheelChanged;
|
||||||
|
game.Window.Mouse.ButtonUp += MouseButtonUp;
|
||||||
|
Resize();
|
||||||
|
}
|
||||||
|
|
||||||
public override void Resize() {
|
public override void Resize() {
|
||||||
using( drawer ) {
|
using( drawer ) {
|
||||||
@ -135,14 +137,7 @@ namespace Launcher2 {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void ConnectToServer( int mouseX, int mouseY ) {
|
void ConnectToServer( int mouseX, int mouseY ) {
|
||||||
GameStartData data = null;
|
game.ConnectToServer( Get( 3 ) );
|
||||||
try {
|
|
||||||
data = game.Session.GetConnectInfo( Get( 3 ) );
|
|
||||||
} catch( WebException ex ) {
|
|
||||||
Program.LogException( ex );
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
Client.Start( data, true );
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void MouseWheelChanged( object sender, MouseWheelEventArgs e ) {
|
void MouseWheelChanged( object sender, MouseWheelEventArgs e ) {
|
||||||
|
@ -18,6 +18,7 @@ namespace Launcher2 {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public override void Init() {
|
public override void Init() {
|
||||||
|
base.Init();
|
||||||
Resize();
|
Resize();
|
||||||
using( drawer ) {
|
using( drawer ) {
|
||||||
drawer.SetBitmap( game.Framebuffer );
|
drawer.SetBitmap( game.Framebuffer );
|
||||||
|
@ -14,6 +14,9 @@ namespace Launcher2 {
|
|||||||
protected Font titleFont, inputFont;
|
protected Font titleFont, inputFont;
|
||||||
protected int enterIndex = -1;
|
protected int enterIndex = -1;
|
||||||
public LauncherInputScreen( LauncherWindow game ) : base( game ) {
|
public LauncherInputScreen( LauncherWindow game ) : base( game ) {
|
||||||
|
}
|
||||||
|
|
||||||
|
public override void Init() {
|
||||||
game.Window.Mouse.Move += MouseMove;
|
game.Window.Mouse.Move += MouseMove;
|
||||||
game.Window.Mouse.ButtonDown += MouseButtonDown;
|
game.Window.Mouse.ButtonDown += MouseButtonDown;
|
||||||
|
|
||||||
|
@ -27,6 +27,7 @@ namespace Launcher2 {
|
|||||||
if( fetcher.Done ) {
|
if( fetcher.Done ) {
|
||||||
ResourcePatcher patcher = new ResourcePatcher( fetcher );
|
ResourcePatcher patcher = new ResourcePatcher( fetcher );
|
||||||
patcher.Run();
|
patcher.Run();
|
||||||
|
game.SetScreen( new MainScreen( game ) );
|
||||||
fetcher = null;
|
fetcher = null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -12,7 +12,9 @@ namespace Launcher2 {
|
|||||||
|
|
||||||
void HandleOnClick( int mouseX, int mouseY ) {
|
void HandleOnClick( int mouseX, int mouseY ) {
|
||||||
if( mouseX >= Window.Width - 10 ) {
|
if( mouseX >= Window.Width - 10 ) {
|
||||||
ScrollbarClick( mouseY ); return;
|
ScrollbarClick( mouseY );
|
||||||
|
lastIndex = -10;
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if( mouseY >= HeaderStartY && mouseY < HeaderEndY ) {
|
if( mouseY >= HeaderStartY && mouseY < HeaderEndY ) {
|
||||||
@ -29,17 +31,23 @@ namespace Launcher2 {
|
|||||||
} else {
|
} else {
|
||||||
DraggingWidth = true;
|
DraggingWidth = true;
|
||||||
}
|
}
|
||||||
|
lastIndex = -10;
|
||||||
} else {
|
} else {
|
||||||
for( int i = 0; i < Count; i++ ) {
|
for( int i = 0; i < Count; i++ ) {
|
||||||
TableEntry entry = usedEntries[i];
|
TableEntry entry = usedEntries[i];
|
||||||
if( mouseY >= entry.Y && mouseY < entry.Y + entry.Height ) {
|
if( mouseY >= entry.Y && mouseY < entry.Y + entry.Height ) {
|
||||||
|
if( lastIndex == i ) {
|
||||||
|
Window.ConnectToServer( entry.Hash );
|
||||||
|
}
|
||||||
SelectedChanged( entry.Hash );
|
SelectedChanged( entry.Hash );
|
||||||
|
lastIndex = i;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int lastIndex = -10;
|
||||||
public void MouseMove( int deltaX, int deltaY ) {
|
public void MouseMove( int deltaX, int deltaY ) {
|
||||||
if( DraggingWidth ) {
|
if( DraggingWidth ) {
|
||||||
ColumnWidths[0] += deltaX;
|
ColumnWidths[0] += deltaX;
|
||||||
|
@ -5,6 +5,7 @@ using ClassicalSharp;
|
|||||||
using ClassicalSharp.Network;
|
using ClassicalSharp.Network;
|
||||||
using OpenTK;
|
using OpenTK;
|
||||||
using OpenTK.Graphics;
|
using OpenTK.Graphics;
|
||||||
|
using System.Net;
|
||||||
|
|
||||||
namespace Launcher2 {
|
namespace Launcher2 {
|
||||||
|
|
||||||
@ -59,6 +60,18 @@ namespace Launcher2 {
|
|||||||
screen.Init();
|
screen.Init();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public bool ConnectToServer( string hash ) {
|
||||||
|
GameStartData data = null;
|
||||||
|
try {
|
||||||
|
data = Session.GetConnectInfo( hash );
|
||||||
|
} catch( WebException ex ) {
|
||||||
|
Program.LogException( ex );
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
Client.Start( data, true );
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
public void Run() {
|
public void Run() {
|
||||||
Window = new NativeWindow( 480, 480, Program.AppName, 0,
|
Window = new NativeWindow( 480, 480, Program.AppName, 0,
|
||||||
GraphicsMode.Default, DisplayDevice.Default );
|
GraphicsMode.Default, DisplayDevice.Default );
|
||||||
|
Loading…
x
Reference in New Issue
Block a user