Add scrolling in block hotbar.

This commit is contained in:
UnknownShadow200 2015-04-04 17:50:11 +11:00
parent 81ae1012ee
commit c7bfbc8567
2 changed files with 11 additions and 3 deletions

View File

@ -18,7 +18,8 @@ namespace ClassicalSharp {
public virtual void Tick( double elapsed ) { public virtual void Tick( double elapsed ) {
} }
public virtual void MouseZoom( MouseWheelEventArgs e ) { public virtual bool MouseZoom( MouseWheelEventArgs e ) {
return false;
} }
public abstract void RegrabMouse(); public abstract void RegrabMouse();
@ -104,9 +105,10 @@ namespace ClassicalSharp {
} }
float distance = 3; float distance = 3;
public override void MouseZoom( MouseWheelEventArgs e ) { public override bool MouseZoom( MouseWheelEventArgs e ) {
distance -= e.DeltaPrecise; distance -= e.DeltaPrecise;
if( distance < 2 ) distance = 2; if( distance < 2 ) distance = 2;
return true;
} }
public override Matrix4 GetView() { public override Matrix4 GetView() {

View File

@ -61,7 +61,13 @@ namespace ClassicalSharp {
} }
void MouseWheelChanged( object sender, MouseWheelEventArgs e ) { void MouseWheelChanged( object sender, MouseWheelEventArgs e ) {
Camera.MouseZoom( e ); if( !Camera.MouseZoom( e ) && CanChangeHeldBlock ) {
int diffIndex = -e.Delta % BlocksHotbar.Length;
int newIndex = HeldBlockIndex + diffIndex;
if( newIndex < 0 ) newIndex += BlocksHotbar.Length;
if( newIndex >= BlocksHotbar.Length ) newIndex -= BlocksHotbar.Length;
HeldBlockIndex = newIndex;
}
} }
void KeyPressHandler( object sender, KeyPressEventArgs e ) { void KeyPressHandler( object sender, KeyPressEventArgs e ) {