//========================================================================================= /// <summary> /// Draw function. Draws all the floating scores. /// </summary> //========================================================================================= public override void OnDraw() { // If we have no font then abort: if ( m_font == null ) return; // Make a custom font settings struct for drawing: Font.CustomFontSettings settings = new Font.CustomFontSettings ( m_font.Size , m_font.Color , m_font.CharSpacing , m_font.LineSpacing , m_font.Effect ); // Get the view projection matrix of the camera: Matrix view_projection = Core.Level.Renderer.Camera.View * Core.Level.Renderer.Camera.Projection; // Run through all the nodes: LinkedList<FloatingScore>.Enumerator e = m_scores.GetEnumerator(); while ( e.MoveNext() ) { // Get the score: FloatingScore s = e.Current; // Calculate the alpha value we will give this score depending on. fade it out as it lives longer. float a = 1.0f - ( s.TimeAlive / m_score_live_time ); // Set the alpha for the font: settings.Color.W = a; // Good: now draw the score in it's position: m_font.DrawCustomStringCentered ( s.Score.ToString() , s.Position , view_projection , settings ); } }
//========================================================================================= /// <summary> /// Draws the text for the button. /// </summary> //========================================================================================= public override void OnDraw() { //------------------------------------------------------------------------------------- // Abort if we have no effect: //------------------------------------------------------------------------------------- if ( m_effect == null || m_fill_texture == null ) return; //------------------------------------------------------------------------------------- // GD Setup //------------------------------------------------------------------------------------- // Set vertex declaration: Core.Graphics.Device.VertexDeclaration = Core.Graphics.VertexPositionColorTextureDeclaration; // Get view camera transforms: Matrix view_projection = Core.Gui.Camera.View * Core.Gui.Camera.Projection; // Set the transform on the shader: { // Get the parameter: EffectParameter param_wvp = m_effect.Parameters[ "WorldViewProjection" ]; // Set it's value: if ( param_wvp != null ) param_wvp.SetValue( view_projection ); } //------------------------------------------------------------------------------------- // Figure out the expanded size of the bar: //------------------------------------------------------------------------------------- Vector2 s = Vector2.Zero; s.X = m_size.X + m_expansion.X * m_current_expansion_pc; s.Y = m_size.Y + m_expansion.Y * m_current_expansion_pc; //------------------------------------------------------------------------------------- // Draw the middle of the bar: //------------------------------------------------------------------------------------- // Only do if we have the texture: if ( m_bar_texture != null ) { // Fill in the vertices for the underneath of the bar: m_vertices[0].Position = new Vector3( Position.X - s.X , Position.Y + s.Y , -2 ); m_vertices[1].Position = new Vector3( Position.X - s.X , Position.Y - s.Y , -2 ); m_vertices[2].Position = new Vector3( Position.X , Position.Y + s.Y , -2 ); m_vertices[3].Position = new Vector3( Position.X , Position.Y - s.Y , -2 ); m_vertices[4].Position = new Vector3( Position.X + s.X , Position.Y + s.Y , -2 ); m_vertices[5].Position = new Vector3( Position.X + s.X , Position.Y - s.Y , -2 ); // Set the texture on the shader: EffectParameter param_tex = m_effect.Parameters[ "Texture" ]; if ( param_tex != null ) { param_tex.SetValue( m_bar_texture ); } // Begin drawing with shader: m_effect.Begin(); m_effect.CurrentTechnique.Passes[0].Begin(); // Draw the bar: Core.Graphics.Device.DrawUserPrimitives<VertexPositionColorTexture> ( PrimitiveType.TriangleStrip , m_vertices , 0 , 4 ); // End drawing with shader: m_effect.CurrentTechnique.Passes[0].End(); m_effect.End(); } //------------------------------------------------------------------------------------- // Figure out how much padding to apply to the bar: //------------------------------------------------------------------------------------- float xp = m_fill_padding.X * ( 1.0f + ( m_current_expansion_pc * m_expansion.X ) / m_size.X ); float yp = m_fill_padding.Y * ( 1.0f + ( m_current_expansion_pc * m_expansion.Y ) / m_size.Y ); //------------------------------------------------------------------------------------- // Figure out the width of the bar fill: //------------------------------------------------------------------------------------- // Get fully filled width of the bar: float fill_s = s.X * 2 - xp * 2; float fill_w = fill_s * (( m_current_value - m_minimum_value ) / ( m_maximum_value - m_minimum_value )); //------------------------------------------------------------------------------------- // Now set the positions of the vertices for the fill: //------------------------------------------------------------------------------------- m_vertices[0].Position = new Vector3( Position.X - s.X + xp , Position.Y + s.Y - yp , -2 ); m_vertices[1].Position = new Vector3( Position.X - s.X + xp , Position.Y - s.Y + yp , -2 ); m_vertices[2].Position = new Vector3( Position.X - s.X + xp + fill_w , Position.Y + s.Y - yp , -2 ); m_vertices[3].Position = new Vector3( Position.X - s.X + xp + fill_w , Position.Y - s.Y + yp , -2 ); //------------------------------------------------------------------------------------- // Draw the fill: //------------------------------------------------------------------------------------- if ( m_fill_texture != null ) { // Set the texture on the shader: EffectParameter param_tex = m_effect.Parameters[ "Texture" ]; if ( param_tex != null ) { param_tex.SetValue( m_fill_texture ); } // Begin drawing with shader: m_effect.Begin(); m_effect.CurrentTechnique.Passes[0].Begin(); // Draw the bar: Core.Graphics.Device.DrawUserPrimitives<VertexPositionColorTexture> ( PrimitiveType.TriangleStrip , m_vertices , 0 , 2 ); // End drawing with shader: m_effect.CurrentTechnique.Passes[0].End(); m_effect.End(); } //------------------------------------------------------------------------------------- // Draw the font string: //------------------------------------------------------------------------------------- if ( m_font != null && m_string_wobble_effect != null ) { // Set the wobble shader settings: // Time: { EffectParameter p = m_string_wobble_effect.Parameters["WobbleTime"]; if ( p != null ) { p.SetValue( m_highlight_wobble_time ); } } // Intensity: set to zero if not in focus { EffectParameter p = m_string_wobble_effect.Parameters["WobbleIntensity"]; if ( p != null ) { if ( InFocus ) { p.SetValue( m_highlight_wobble_intensity ); } else { p.SetValue( 0 ); } } } // Intensity: fade as we contract { EffectParameter p = m_string_wobble_effect.Parameters["WobbleSpeed"]; if ( p != null ) { p.SetValue( m_highlight_wobble_speed ); } } // Make up a custom font settings block: Font.CustomFontSettings custom_settings = new Font.CustomFontSettings ( m_font.Size + m_expansion.Y * m_current_expansion_pc , m_font.Color , m_font.CharSpacing , m_font.LineSpacing , m_string_wobble_effect ); // Draw the string m_font.DrawCustomStringCentered ( StringDatabase.GetString(m_string_name) , Position + Vector2.UnitY * m_string_offset_y , view_projection , custom_settings ); } }
//========================================================================================= /// <summary> /// Draws the text. /// </summary> //========================================================================================= public override void OnDraw() { // Abort if we do not have a font: if ( m_font == null ) return; // Grab the level rules object from the game: LevelRules level_rules = (LevelRules) Core.Level.Search.FindByType("LevelRules"); // If it's not there then abort: if ( level_rules == null ) return; // Now see if a phase change is underway, if not then abort: if ( level_rules.TimeSincePhaseChange >= LevelRules.PHASE_CHANGE_TIME ) return; // Decide on the phase change message, alpha, and font enlargen amountfrom the time since the phase change: string phase_change_message = null; float phase_change_message_a = 0.0f; float font_enlarge = 0.0f; if ( level_rules.TimeSincePhaseChange >= LevelRules.PHASE_CHANGE_TIME * 0.5f ) { // Show the ready message: phase_change_message = StringDatabase.GetString(m_ready_string_name); // Decide on alpha: if ( level_rules.TimeSincePhaseChange >= LevelRules.PHASE_CHANGE_TIME * 0.75f ) { phase_change_message_a = level_rules.TimeSincePhaseChange - LevelRules.PHASE_CHANGE_TIME * 0.75f; phase_change_message_a /= LevelRules.PHASE_CHANGE_TIME * 0.25f; phase_change_message_a = 1.0f - phase_change_message_a; } else { phase_change_message_a = level_rules.TimeSincePhaseChange - LevelRules.PHASE_CHANGE_TIME * 0.50f; phase_change_message_a /= LevelRules.PHASE_CHANGE_TIME * 0.25f; } } else { // Show the phase message and the current phase number: phase_change_message = StringDatabase.GetString(m_phase_string_name) + " " + (level_rules.CurrentPhase + 1 ).ToString(); // Decide on alpha: if ( level_rules.TimeSincePhaseChange >= LevelRules.PHASE_CHANGE_TIME * 0.25f ) { phase_change_message_a = level_rules.TimeSincePhaseChange - LevelRules.PHASE_CHANGE_TIME * 0.25f; phase_change_message_a /= LevelRules.PHASE_CHANGE_TIME * 0.25f; phase_change_message_a = 1.0f - phase_change_message_a; } else { phase_change_message_a = level_rules.TimeSincePhaseChange; phase_change_message_a /= LevelRules.PHASE_CHANGE_TIME * 0.25f; } } // Make the alpha have a non linear ramp up: phase_change_message_a = (float) Math.Sqrt( phase_change_message_a ); // Decide on font enlargening amount: font_enlarge = m_font_enlarge * ( 1.0f - phase_change_message_a ); // Get view camera transforms: Matrix view_projection = Core.Gui.Camera.View * Core.Gui.Camera.Projection; // Make up a custom font settings block: Font.CustomFontSettings settings = new Font.CustomFontSettings ( m_font.Size + font_enlarge , m_font.Color , m_font.CharSpacing , m_font.LineSpacing , m_font.Effect ); // Change the settings: settings.Color.W = phase_change_message_a; // Draw the font string: see if it is to be centered about it's position first though if ( m_center ) { // Draw centered at its position: m_font.DrawCustomStringCentered ( phase_change_message , Position , view_projection , settings ); } else { // Draw non centered: m_font.DrawCustomString ( phase_change_message , Position , view_projection , settings ); } }