From c7bfbc8567be05007c755ca1f69875a88826c326 Mon Sep 17 00:00:00 2001 From: UnknownShadow200 Date: Sat, 4 Apr 2015 17:50:11 +1100 Subject: [PATCH] Add scrolling in block hotbar. --- Camera.cs | 6 ++++-- Game/Game.InputHandling.cs | 8 +++++++- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/Camera.cs b/Camera.cs index ac86548ec..6f6a00a7f 100644 --- a/Camera.cs +++ b/Camera.cs @@ -18,7 +18,8 @@ namespace ClassicalSharp { public virtual void Tick( double elapsed ) { } - public virtual void MouseZoom( MouseWheelEventArgs e ) { + public virtual bool MouseZoom( MouseWheelEventArgs e ) { + return false; } public abstract void RegrabMouse(); @@ -104,9 +105,10 @@ namespace ClassicalSharp { } float distance = 3; - public override void MouseZoom( MouseWheelEventArgs e ) { + public override bool MouseZoom( MouseWheelEventArgs e ) { distance -= e.DeltaPrecise; if( distance < 2 ) distance = 2; + return true; } public override Matrix4 GetView() { diff --git a/Game/Game.InputHandling.cs b/Game/Game.InputHandling.cs index 9ba84f465..4eeaaeee8 100644 --- a/Game/Game.InputHandling.cs +++ b/Game/Game.InputHandling.cs @@ -61,7 +61,13 @@ namespace ClassicalSharp { } 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 ) {