/// <summary> /// /// </summary> /// <param name="evt"></param> /// <returns></returns> public override bool KeyReleased( SharpInputSystem.KeyEventArgs evt ) { if ( !TrayManager.IsDialogVisible ) chara.InjectKeyUp( evt ); return base.KeyReleased( evt ); }
/// <summary> /// mouse pressed event override from SdkSample, calls MouseSelector's MousePressed method to start selection /// </summary> /// <param name="evt">MouseEventArgs</param> /// <param name="id">MouseButtonID</param> /// <returns>bool</returns> public override bool MousePressed( SharpInputSystem.MouseEventArgs evt, SharpInputSystem.MouseButtonID id ) { if ( initialized ) { _MouseSelector.MousePressed( evt, id ); } return base.MousePressed( evt, id ); }
/// <summary> /// /// </summary> /// <param name="evt"></param> /// <returns></returns> public override bool KeyPressed( SharpInputSystem.KeyEventArgs evt ) { // relay input events to character controller if ( !TrayManager.IsDialogVisible ) chara.InjectKeyDown( evt ); return base.KeyPressed( evt ); }
/// <summary> /// /// </summary> /// <param name="evt"></param> /// <returns></returns> public override bool KeyPressed( SIS.KeyEventArgs evt ) { if ( evt.Key == SIS.KeyCode.Key_H || evt.Key == SIS.KeyCode.Key_F1 ) // toggle visibility of help dialog { if ( !this.TrayManager.IsDialogVisible && Metadata[ "Help" ] != "" ) this.TrayManager.ShowOkDialog( "Help", Metadata[ "Help" ] ); else this.TrayManager.CloseDialog(); } if ( this.TrayManager.IsDialogVisible ) return true; // don't process any more keys if dialog is up if ( evt.Key == SIS.KeyCode.Key_F ) // toggle visibility of advanced frame stats { this.TrayManager.ToggleAdvancedFrameStats(); } else if ( evt.Key == SIS.KeyCode.Key_G ) // toggle visibility of even rarer debugging details { if ( this.DetailsPanel.TrayLocation == TrayLocation.None ) { this.TrayManager.MoveWidgetToTray( this.DetailsPanel, TrayLocation.TopRight, 0 ); this.DetailsPanel.Show(); } else { this.TrayManager.RemoveWidgetFromTray( this.DetailsPanel ); this.DetailsPanel.Hide(); } } else if ( evt.Key == SIS.KeyCode.Key_T ) // cycle polygon rendering mode { String newVal; TextureFiltering tfo; int aniso; switch ( this.DetailsPanel.GetParamValue( 9 )[ 0 ] ) { case 'B': newVal = "Trilinear"; tfo = TextureFiltering.Trilinear; aniso = 1; break; case 'T': newVal = "Anisotropic"; tfo = TextureFiltering.Anisotropic; aniso = 8; break; case 'A': newVal = "None"; tfo = TextureFiltering.None; aniso = 1; break; default: newVal = "Bilinear"; tfo = TextureFiltering.Bilinear; aniso = 1; break; } MaterialManager.Instance.SetDefaultTextureFiltering( tfo ); MaterialManager.Instance.DefaultAnisotropy = aniso; this.DetailsPanel.SetParamValue( 9, newVal ); } else if ( evt.Key == SIS.KeyCode.Key_R ) // cycle polygon rendering mode { String newVal; PolygonMode pm; switch ( this.Camera.PolygonMode ) { case PolygonMode.Solid: newVal = "Wireframe"; pm = PolygonMode.Wireframe; break; case PolygonMode.Wireframe: newVal = "Points"; pm = PolygonMode.Points; break; default: newVal = "Solid"; pm = PolygonMode.Solid; break; } this.Camera.PolygonMode = pm; this.DetailsPanel.SetParamValue( 10, newVal ); } else if ( evt.Key == SIS.KeyCode.Key_F5 ) // refresh all textures { TextureManager.Instance.ReloadAll(); } else if ( evt.Key == SIS.KeyCode.Key_F9 ) // take a screenshot { String path = "screenshots\\screenshot_"; Window.WriteContentsToFile( path + Root.CurrentFrameCount + ".jpg" ); } this.CameraManager.injectKeyDown( evt ); return true; }
/// <summary> /// /// </summary> /// <param name="evt"></param> /// <returns></returns> public override bool KeyReleased( SIS.KeyEventArgs evt ) { this.CameraManager.injectKeyUp( evt ); return true; }
/// <summary> /// /// </summary> /// <param name="evt"></param> /// <param name="id"></param> /// <returns></returns> public override bool MouseReleased( SIS.MouseEventArgs evt, SIS.MouseButtonID id ) { if ( this.TrayManager.InjectMouseUp( evt, id ) ) { return true; } try { return base.MouseReleased( evt, id ); } catch ( Exception ex ) { RunSample( null ); string msg = ex.Message + "\nSource: " + ex.InnerException; LogManager.Instance.Write( "[Samples] Error! " + msg ); this.TrayManager.ShowOkDialog( "Error!", msg ); } return true; }
/// <summary> /// Updates cursor position. Returns true if the event was <para></para> /// consumed and should not be passed on to other handlers. /// </summary> /// <param name="evt"></param> /// <returns></returns> public bool InjectMouseMove( SIS.MouseEventArgs evt ) { if ( !this.cursorLayer.IsVisible ) { return false; // don't process if cursor layer is invisible } this.cursor.SetPosition( evt.State.X.Absolute, evt.State.Y.Absolute ); var cursorPos = new Vector2( this.cursor.Left, this.cursor.Top ); if ( ExpandedMenu != null ) // only check top priority widget until it passes on { ExpandedMenu.OnCursorMoved( cursorPos ); return true; } if ( this.Dialog != null ) // only check top priority widget until it passes on { this.Dialog.OnCursorMoved( cursorPos ); if ( this.mOk != null ) { this.mOk.OnCursorMoved( cursorPos ); } else { this.mYes.OnCursorMoved( cursorPos ); this.mNo.OnCursorMoved( cursorPos ); } return true; } Widget w; for ( int i = 0; i < this.mTrays.Length; i++ ) { if ( !this.mTrays[ i ].IsVisible ) { continue; } for ( int j = 0; j < this.mWidgets[ i ].Count; j++ ) { w = this.mWidgets[ i ][ j ]; if ( !w.OverlayElement.IsVisible ) { continue; } w.OnCursorMoved( cursorPos ); // send event to widget } } if ( this.mTrayDrag ) { return true; // don't pass this event on if we're in the middle of a drag } return false; }
/// <summary> /// public method to call when the mouse is moved /// </summary> /// <param name="evt"></param> public void MouseMoved( SharpInputSystem.MouseEventArgs evt ) { if ( ( SelectionMode == SelectionModeType.SelectionBox ) && Selecting == true ) { _stop = new Vector2( evt.State.X.Absolute / (float)_Camera.Viewport.ActualWidth, evt.State.Y.Absolute / (float)_Camera.Viewport.ActualHeight ); _rect.SetCorners( _start, _stop ); } }
/// <summary> /// /// </summary> /// <param name="evt"></param> /// <returns></returns> public override bool KeyPressed( SIS.KeyEventArgs evt ) { if ( this.TrayManager.IsDialogVisible ) { return true; } switch ( evt.Key ) { case SIS.KeyCode.Key_ESCAPE: if ( this.TitleLabel.TrayLocation != TrayLocation.None ) { if ( CurrentSample != null ) { if ( IsSamplePaused ) { this.TrayManager.HideAll(); UnpauseCurrentSample(); } else { PauseCurrentSample(); this.TrayManager.ShowAll(); } } } else { OnButtonHit( this, (Button)this.TrayManager.GetWidget( "Back" ) ); } break; case SIS.KeyCode.Key_UP: case SIS.KeyCode.Key_DOWN: { //if ( evt.Key == SIS.KeyCode.Key_DOWN && TitleLabel.TrayLocation != TrayLocation.None ) //{ // break; //} int newIndex = this.SampleMenu.SelectionIndex + ( evt.Key == SIS.KeyCode.Key_UP ? -1 : 1 ); this.SampleMenu.SelectItem( Utility.Clamp<int>( newIndex, this.SampleMenu.ItemsCount - 1, 0 ) ); } break; case SIS.KeyCode.Key_RETURN: if ( !( this.LoadedSamples.Count == 0 ) && ( IsSamplePaused || CurrentSample == null ) ) { var newSample = (Sample)this.Thumbs[ this.SampleMenu.SelectionIndex ].UserData; RunSample( newSample == CurrentSample ? null : newSample ); } break; case SIS.KeyCode.Key_F9: // toggle full screen Configuration.ConfigOption option = Root.RenderSystem.ConfigOptions[ "Video Mode" ]; string[] vals = option.Value.Split( 'x' ); int w = int.Parse( vals[ 0 ] ); #if !(XBOX || XBOX360) int h = int.Parse( vals[ 1 ].Remove( vals[ 1 ].IndexOf( '@' ) ) ); #else int h = int.Parse(vals[1].Remove(vals[1].IndexOf('@'), 1)); #endif //RenderWindow.IsFullScreen = ...; break; case SIS.KeyCode.Key_R: if ( CurrentSample != null ) { switch ( RenderWindow.GetViewport( 0 ).Camera.PolygonMode ) { case PolygonMode.Points: RenderWindow.GetViewport( 0 ).Camera.PolygonMode = PolygonMode.Solid; break; case PolygonMode.Solid: RenderWindow.GetViewport( 0 ).Camera.PolygonMode = PolygonMode.Wireframe; break; case PolygonMode.Wireframe: RenderWindow.GetViewport( 0 ).Camera.PolygonMode = PolygonMode.Points; break; } } break; } try { return base.KeyPressed( evt ); } catch ( Exception ex ) { RunSample( null ); string msg = ex.Message + "\nSource: " + ex.InnerException; LogManager.Instance.Write( "[Samples] Error! " + msg ); this.TrayManager.ShowOkDialog( "Error!", msg ); } return true; }
/// <summary> /// Extendeded to setup a default tray interface and camera controller. /// </summary> /// <param name="window"></param> /// <param name="keyboard"></param> /// <param name="mouse"></param> protected internal override void Setup( RenderWindow window, SIS.Keyboard keyboard, SIS.Mouse mouse ) { Window = window; Keyboard = keyboard; Mouse = mouse; LocateResources(); CreateSceneManager(); SetupView(); this.TrayManager = new SdkTrayManager( "SampleControls", window, mouse, this as ISdkTrayListener ); // create a tray interface LoadResources(); ResourcesLoaded = true; // Show stats and logo and Hide the cursor this.TrayManager.ShowFrameStats( TrayLocation.BottomLeft ); this.TrayManager.ShowLogo( TrayLocation.BottomRight ); this.TrayManager.HideCursor(); // create a params panel for displaying sample details List<string> items = new List<string> { "cam.pX", "cam.pY", "cam.pZ", String.Empty, "cam.oW", "cam.oX", "cam.oY", "cam.oZ", String.Empty, "Filtering", "Poly Mode" }; this.DetailsPanel = this.TrayManager.CreateParamsPanel( TrayLocation.None, "DetailsPanel", 180, items ); this.DetailsPanel.SetParamValue( 9, "Bilinear" ); this.DetailsPanel.SetParamValue( 10, "Solid" ); this.DetailsPanel.Hide(); SetupContent(); ContentSetup = true; IsDone = false; }
/// <summary> /// Creates backdrop, cursor, and trays. /// </summary> /// <param name="name"></param> /// <param name="window"></param> /// <param name="mouse"></param> /// <param name="listener"></param> public SdkTrayManager( String name, RenderWindow window, SIS.Mouse mouse, ISdkTrayListener listener ) { this.mName = name; this.mWindow = window; this.Mouse = mouse; Listener = listener; this.mWidgetPadding = 8; this.mWidgetSpacing = 2; OverlayManager om = OverlayManager.Instance; String nameBase = this.mName + "/"; nameBase.Replace( ' ', '_' ); // create overlay layers for everything BackdropLayer = om.Create( nameBase + "BackdropLayer" ); this.mTraysLayer = om.Create( nameBase + "WidgetsLayer" ); this.mPriorityLayer = om.Create( nameBase + "PriorityLayer" ); this.cursorLayer = om.Create( nameBase + "CursorLayer" ); BackdropLayer.ZOrder = 100; this.mTraysLayer.ZOrder = 200; this.mPriorityLayer.ZOrder = 300; this.cursorLayer.ZOrder = 400; // make backdrop and cursor overlay containers this.cursor = (OverlayElementContainer)om.Elements.CreateElementFromTemplate( "SdkTrays/Cursor", "Panel", nameBase + "Cursor" ); this.cursorLayer.AddElement( this.cursor ); this.backdrop = (OverlayElementContainer)om.Elements.CreateElement( "Panel", nameBase + "Backdrop" ); BackdropLayer.AddElement( this.backdrop ); this.mDialogShade = (OverlayElementContainer)om.Elements.CreateElement( "Panel", nameBase + "DialogShade" ); this.mDialogShade.MaterialName = "SdkTrays/Shade"; this.mDialogShade.Hide(); this.mPriorityLayer.AddElement( this.mDialogShade ); String[] trayNames = { "TopLeft", "Top", "TopRight", "Left", "Center", "Right", "BottomLeft", "Bottom", "BottomRight" }; for ( int i = 0; i < 9; i++ ) // make the real trays { this.mTrays[ i ] = (OverlayElementContainer) om.Elements.CreateElementFromTemplate( "SdkTrays/Tray", "BorderPanel", nameBase + trayNames[ i ] + "Tray" ); this.mTraysLayer.AddElement( this.mTrays[ i ] ); this.trayWidgetAlign[ i ] = HorizontalAlignment.Center; // align trays based on location if ( i == (int)TrayLocation.Top || i == (int)TrayLocation.Center || i == (int)TrayLocation.Bottom ) { this.mTrays[ i ].HorizontalAlignment = HorizontalAlignment.Center; } if ( i == (int)TrayLocation.Left || i == (int)TrayLocation.Center || i == (int)TrayLocation.Right ) { this.mTrays[ i ].VerticalAlignment = VerticalAlignment.Center; } if ( i == (int)TrayLocation.TopRight || i == (int)TrayLocation.Right || i == (int)TrayLocation.BottomRight ) { this.mTrays[ i ].HorizontalAlignment = HorizontalAlignment.Right; } if ( i == (int)TrayLocation.BottomLeft || i == (int)TrayLocation.Bottom || i == (int)TrayLocation.BottomRight ) { this.mTrays[ i ].VerticalAlignment = VerticalAlignment.Bottom; } } // create the null tray for free-floating widgets this.mTrays[ 9 ] = (OverlayElementContainer)om.Elements.CreateElement( "Panel", nameBase + "NullTray" ); this.trayWidgetAlign[ 9 ] = HorizontalAlignment.Left; this.mTraysLayer.AddElement( this.mTrays[ 9 ] ); for ( int i = 0; i < this.mWidgets.Length; i++ ) { this.mWidgets[ i ] = new WidgetList(); } AdjustTrays(); ShowTrays(); ShowCursor(); }
/// <summary> /// key pressed selection event to have the ability to keep the current selection, sets the MouseSelector.KeepPreviousSelection /// if the right or left control key is pressed /// </summary> /// <param name="evt">KeyEventArgs</param> /// <returns>bool</returns> public override bool KeyPressed( SharpInputSystem.KeyEventArgs evt ) { if ( initialized ) { if ( evt.Key == SharpInputSystem.KeyCode.Key_LCONTROL || evt.Key == SharpInputSystem.KeyCode.Key_RCONTROL ) { _MouseSelector.KeepPreviousSelection = true; } } return base.KeyPressed( evt ); }
/// <summary> /// key pressed selection event to have the ability to keep the current selection, sets the MouseSelector.KeepPreviousSelection /// if the right or left control key is pressed /// </summary> /// <param name="evt">KeyEventArgs</param> /// <returns>bool</returns> public override bool KeyReleased( SharpInputSystem.KeyEventArgs evt ) { if ( initialized ) { _MouseSelector.KeepPreviousSelection = false; } return base.KeyReleased( evt ); }
public override bool KeyPressed( SIS.KeyEventArgs evt ) { switch ( evt.Key ) { case SIS.KeyCode.Key_S: // CTRL-S to save if ( Keyboard.IsKeyDown( SIS.KeyCode.Key_LCONTROL ) || Keyboard.IsKeyDown( SIS.KeyCode.Key_RCONTROL ) ) { SaveTerrains( true ); } else { return base.KeyPressed( evt ); } break; case SIS.KeyCode.Key_F10: //dump var tkey = 0; foreach ( var ts in this.terrainGroup.TerrainSlots ) { if ( ts.Instance != null && ts.Instance.IsLoaded ) { ts.Instance.DumpTextures( "terrain_" + tkey, ".png" ); } tkey++; } break; default: return base.KeyPressed( evt ); } return true; }
public override bool MousePressed( SharpInputSystem.MouseEventArgs evt, SharpInputSystem.MouseButtonID id ) { if ( TrayManager.InjectMouseDown( evt, id ) ) { return true; } this.mWiping = true; // wipe frost if user left clicks in the scene return true; }
public override bool MouseReleased( SharpInputSystem.MouseEventArgs evt, SharpInputSystem.MouseButtonID id ) { if ( TrayManager.InjectMouseUp( evt, id ) ) { return true; } this.mWiping = false; // stop wiping frost if user releases LMB return true; }
/// <summary> /// /// </summary> /// <remarks> /// IMPORTANT: When overriding this handler, remember to allow the tray manager /// to filter out any interface-related mouse events before processing them in your scene. /// If the tray manager handler returns true, the event was meant for the trays, not you. /// </remarks> /// <param name="evt"></param> /// <returns></returns> public override bool MouseMoved( SIS.MouseEventArgs evt ) { if ( this.TrayManager.InjectMouseMove( evt ) ) return true; this.CameraManager.injectMouseMove( evt ); return true; }
/// <summary> /// /// </summary> /// <param name="evt"></param> /// <param name="id"></param> /// <returns></returns> public override bool MousePressed( SharpInputSystem.MouseEventArgs evt, SharpInputSystem.MouseButtonID id ) { // relay input events to character controller if ( !TrayManager.IsDialogVisible ) { this.chara.InjectMouseDown( evt, id ); } return base.MousePressed( evt, id ); }
/// <summary> /// /// </summary> /// <remarks> /// IMPORTANT: When overriding this handler, remember to allow the tray manager /// to filter out any interface-related mouse events before processing them in your scene. /// If the tray manager handler returns true, the event was meant for the trays, not you. /// </remarks> /// <param name="evt"></param> /// <param name="id"></param> /// <returns></returns> public override bool MouseReleased( SIS.MouseEventArgs evt, SIS.MouseButtonID id ) { if ( this.TrayManager.InjectMouseUp( evt, id ) ) return true; this.CameraManager.injectMouseUp( evt, id ); return true; }
/// <summary> /// Creates backdrop, cursor, and trays. /// </summary> /// <param name="name"></param> /// <param name="window"></param> /// <param name="mouse"></param> public SdkTrayManager( String name, RenderWindow window, SIS.Mouse mouse ) : this( name, window, mouse, null ) { }
/// <summary> /// /// </summary> /// <param name="evt"></param> /// <returns></returns> public override bool MouseMoved( SharpInputSystem.MouseEventArgs evt ) { // relay input events to character controller if ( !TrayManager.IsDialogVisible ) { this.chara.InjectMouseMove( evt ); } return base.MouseMoved( evt ); }
/// <summary> /// mouse moved event override from SdkSample, calls the MouseSelector's MouseMoved event for SelectionBox /// </summary> /// <param name="evt">MouseEventArgs</param> /// <returns>bool</returns> public override bool MouseMoved( SharpInputSystem.MouseEventArgs evt ) { if ( initialized ) { _MouseSelector.MouseMoved( evt ); MouseLocationLabel.Caption = "(x:y) " + ( evt.State.X.Absolute / (float)Camera.Viewport.ActualWidth ).ToString() + ":" + ( evt.State.Y.Absolute / (float)Camera.Viewport.ActualHeight ).ToString(); } return base.MouseMoved( evt ); }
/// <summary> /// public method to call when the mouse is pressed /// </summary> /// <param name="evt">MouseEventArgs</param> /// <param name="id">MouseButtonID</param> public void MousePressed( SharpInputSystem.MouseEventArgs evt, SharpInputSystem.MouseButtonID id ) { if ( id == SharpInputSystem.MouseButtonID.Left ) { Selecting = true; Clear(); switch ( SelectionMode ) { case SelectionModeType.SelectionBox: Log( "MouseSelector: Selection starting for " + _name ); Clear(); _start = new Vector2( evt.State.X.Absolute / (float)_Camera.Viewport.ActualWidth, evt.State.Y.Absolute / (float)_Camera.Viewport.ActualHeight ); _stop = _start; _rect.IsVisible = true; Log( "MouseSelector: " + _name + " selecting from top(" + _start.x.ToString() + ";" + _start.y.ToString() + ")" ); _rect.SetCorners( _start, _stop ); break; case SelectionModeType.MouseClick: _start = new Vector2( evt.State.X.Absolute / (float)_Camera.Viewport.ActualWidth, evt.State.Y.Absolute / (float)_Camera.Viewport.ActualHeight ); break; } } }
/// <summary> /// /// </summary> /// <param name="e"></param> public void InjectKeyDown( SharpInputSystem.KeyEventArgs e ) { if ( e.Key == SharpInputSystem.KeyCode.Key_Q && ( topAnimID == AnimationID.IdleTop || topAnimID == AnimationID.RunTop ) ) { // take swords out (or put them back, since it's the same animation but reversed) SetTopAnimation( AnimationID.DrawSword, true ); timer = 0; } else if ( e.Key == SharpInputSystem.KeyCode.Key_E && !swordsDrawn ) { if ( topAnimID == AnimationID.IdleTop || topAnimID == AnimationID.RunTop ) { // start dancing SetBaseAnimation( AnimationID.Dance, true ); SetTopAnimation( AnimationID.None ); // disable hand animation because the dance controls hands anims[ (int)AnimationID.HandsRelaxed ].IsEnabled = false; } else if ( baseAnimID == AnimationID.Dance ) { // stop dancing SetBaseAnimation( AnimationID.IdleBase, true ); SetTopAnimation( AnimationID.IdleTop ); // re-enable hand animation anims[ (int)AnimationID.HandsRelaxed ].IsEnabled = true; } } // keep track of the player's intended direction else if ( e.Key == SharpInputSystem.KeyCode.Key_W ) keyDirection.z = -1; else if ( e.Key == SharpInputSystem.KeyCode.Key_A ) keyDirection.x = -1; else if ( e.Key == SharpInputSystem.KeyCode.Key_S ) keyDirection.z = 1; else if ( e.Key == SharpInputSystem.KeyCode.Key_D ) keyDirection.x = 1; else if ( e.Key == SharpInputSystem.KeyCode.Key_SPACE && ( topAnimID == AnimationID.IdleTop || topAnimID == AnimationID.RunTop ) ) { // jump if on ground SetBaseAnimation( AnimationID.JumpStart, true ); SetTopAnimation( AnimationID.None ); timer = 0; } if ( !keyDirection.IsZeroLength && baseAnimID == AnimationID.IdleBase ) { // start running if not already moving and the player wants to move SetBaseAnimation( AnimationID.RunBase, true ); if ( topAnimID == AnimationID.IdleTop ) SetTopAnimation( AnimationID.RunTop, true ); } }
/// <summary> /// public method to call when the mouse button is released /// </summary> /// <param name="evt"></param> /// <param name="id"></param> public void MouseReleased( SharpInputSystem.MouseEventArgs evt, SharpInputSystem.MouseButtonID id ) { if ( id == SharpInputSystem.MouseButtonID.Left && Selecting == true ) { switch ( SelectionMode ) { case SelectionModeType.SelectionBox: Log( "MouseSelector: " + _name + " selecting to bottom(" + _stop.x.ToString() + ";" + _stop.y.ToString() + ")" ); PerformSelectionWithSelectionBox( _start, _stop ); Selecting = false; _rect.IsVisible = false; Log( "MouseSelector: " + _name + " selection complete." ); break; case SelectionModeType.MouseClick: PerformSelectionWithMouseClick(); break; } Selecting = false; } }
/// <summary> /// /// </summary> /// <param name="e"></param> public void InjectKeyUp( SharpInputSystem.KeyEventArgs e ) { // keep track of the player's intended direction if ( e.Key == SharpInputSystem.KeyCode.Key_W && keyDirection.z == -1 ) keyDirection.z = 0; else if ( e.Key == SharpInputSystem.KeyCode.Key_A && keyDirection.x == -1 ) keyDirection.x = 0; else if ( e.Key == SharpInputSystem.KeyCode.Key_S && keyDirection.z == 1 ) keyDirection.z = 0; else if ( e.Key == SharpInputSystem.KeyCode.Key_D && keyDirection.x == 1 ) keyDirection.x = 0; if ( keyDirection.IsZeroLength && baseAnimID == AnimationID.RunBase ) { // start running if not already moving and the player wants to move SetBaseAnimation( AnimationID.IdleBase, true ); if ( topAnimID == AnimationID.RunTop ) SetTopAnimation( AnimationID.IdleTop, true ); } }
/// <summary> /// /// </summary> /// <param name="evt"></param> /// <param name="id"></param> /// <returns></returns> public override bool MousePressed( SIS.MouseEventArgs evt, SIS.MouseButtonID id ) { if ( this.TrayManager.InjectMouseDown( evt, id ) ) { return true; } if ( this.TitleLabel.TrayLocation != TrayLocation.None ) { for ( int i = 0; i < this.Thumbs.Count; i++ ) { if ( this.Thumbs[ i ].IsVisible && Widget.IsCursorOver( this.Thumbs[ i ], new Vector2( this.TrayManager.CursorContainer.Left, this.TrayManager.CursorContainer.Top ), 0 ) ) { this.SampleMenu.SelectItem( i ); break; } } } try { return base.MousePressed( evt, id ); } catch ( Exception ex ) { RunSample( null ); string msg = ex.Message + "\nSource: " + ex.InnerException; LogManager.Instance.Write( "[Samples] Error! " + msg ); this.TrayManager.ShowOkDialog( "Error!", msg ); } return true; }
/// <summary> /// /// </summary> /// <param name="e"></param> public void InjectMouseMove( SharpInputSystem.MouseEventArgs e ) { // update camera goal based on mouse movement UpdateCameraGoal( -0.05f * e.State.X.Relative, -0.05f * e.State.Y.Relative, -0.0005f * e.State.Z.Relative ); }
/// <summary> /// Extends mouseMoved to inject mouse position into tray manager, and checks /// for mouse wheel movements to slide the carousel, because we can. /// </summary> /// <param name="evt"></param> /// <returns></returns> public override bool MouseMoved( SIS.MouseEventArgs evt ) { if ( this.TrayManager.InjectMouseMove( evt ) ) { return true; } if ( !( CurrentSample != null && !IsSamplePaused ) && this.TitleLabel.TrayLocation != TrayLocation.None && evt.State.Z.Relative != 0 && this.SampleMenu.ItemsCount != 0 ) { var newIndex = (int)( this.SampleMenu.SelectionIndex - evt.State.Z.Relative/Utility.Abs( evt.State.Z.Relative ) ); this.SampleMenu.SelectItem( Utility.Clamp<int>( newIndex, this.SampleMenu.ItemsCount - 1, 0 ) ); } try { return base.MouseMoved( evt ); } catch ( Exception ex ) // show error and fall back to menu { RunSample( null ); string msg = ex.Message + "\nSource: " + ex.InnerException; LogManager.Instance.Write( "[Samples] Error! " + msg ); this.TrayManager.ShowOkDialog( "Error!", msg ); } return true; }
/// <summary> /// /// </summary> /// <param name="e"></param> /// <param name="id"></param> public void InjectMouseDown( SharpInputSystem.MouseEventArgs e, SharpInputSystem.MouseButtonID id ) { if ( swordsDrawn && ( topAnimID == AnimationID.IdleTop || topAnimID == AnimationID.RunTop ) ) { // if swords are out, and character's not doing something weird, then SLICE! if ( id == SharpInputSystem.MouseButtonID.Left ) SetTopAnimation( AnimationID.SliceVertical, true ); else if ( id == SharpInputSystem.MouseButtonID.Right ) SetTopAnimation( AnimationID.SliceHorizontal, true ); timer = 0; } }