Add middle clicking, cleanup held block setting.

This commit is contained in:
UnknownShadow200 2015-04-04 17:43:38 +11:00
parent cbb301fc06
commit 81ae1012ee
4 changed files with 21 additions and 17 deletions

View File

@ -186,11 +186,7 @@ namespace ClassicalSharp {
public override bool HandlesMouseClick( int mouseX, int mouseY, MouseButton button ) {
if( button == MouseButton.Left && selectedIndex != -1 ) {
BlockDrawInfo info = blocksTable[selectedIndex];
try {
Window.HeldBlock = info.BlockId;
} catch( InvalidOperationException ) {
Window.AddChat( "&e/client: &cThe server has forbidden you from changing your held block." );
}
Window.HeldBlock = info.BlockId;
Window.SetNewScreen( new NormalScreen( Window ) );
}
return true;

View File

@ -18,11 +18,7 @@ namespace ClassicalSharp {
public override bool HandlesKeyDown( Key key ) {
if( key >= Key.Number1 && key <= Key.Number9 ) {
try {
Window.HeldBlockIndex = (int)key - (int)Key.Number1;
} catch( InvalidOperationException ) {
Window.AddChat( "&e/client: &cThe server has forbidden you from changing your held block." );
}
Window.HeldBlockIndex = (int)key - (int)Key.Number1;
return true;
}
return false;

View File

@ -38,9 +38,17 @@ namespace ClassicalSharp {
void MouseButtonDown( object sender, MouseButtonEventArgs e ) {
if( activeScreen == null || !activeScreen.HandlesMouseClick( e.X, e.Y, e.Button ) ) {
bool left = e.Button == MouseButton.Left;
bool right = e.Button == MouseButton.Right;
PickBlocks( false, left, right );
if( e.Button == MouseButton.Middle ) {
if( SelectedPos == null || !Map.IsValidPos( SelectedPos.BlockPos ) ) return;
byte block = Map.GetBlock( SelectedPos.BlockPos );
if( CanPlace[block] || CanDelete[block] ) {
HeldBlock = (Block)block;
}
} else {
bool left = e.Button == MouseButton.Left;
bool right = e.Button == MouseButton.Right;
PickBlocks( false, left, right );
}
} else {
lastClick = DateTime.UtcNow;
}

View File

@ -57,8 +57,10 @@ namespace ClassicalSharp {
public int HeldBlockIndex {
get { return hotbarIndex; }
set {
if( !CanChangeHeldBlock )
throw new InvalidOperationException( "Server has forbidden changing held block." );
if( !CanChangeHeldBlock ) {
AddChat( "&e/client: &cThe server has forbidden you from changing your held block." );
return;
}
hotbarIndex = value;
RaiseHeldBlockChanged();
}
@ -67,8 +69,10 @@ namespace ClassicalSharp {
public Block HeldBlock {
get { return BlocksHotbar[hotbarIndex]; }
set {
if( !CanChangeHeldBlock )
throw new InvalidOperationException( "Server has forbidden changing held block." );
if( !CanChangeHeldBlock ) {
AddChat( "&e/client: &cThe server has forbidden you from changing your held block." );
return;
}
BlocksHotbar[hotbarIndex] = value;
RaiseHeldBlockChanged();
}