mainmenubuttoneffect.c 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. class MainMenuButtonEffect : ScriptedWidgetEventHandler
  2. {
  3. reference float speed;
  4. reference float amount;
  5. protected float m_textProportion;
  6. protected float m_textProportion2;
  7. protected ButtonWidget m_root;
  8. protected ref AnimatorTimer m_anim;
  9. // -----------------------------------------------------------
  10. void MainMenuButtonEffect()
  11. {
  12. if ( GetGame() )
  13. {
  14. GetGame().GetUpdateQueue(CALL_CATEGORY_GUI).Insert(this.Update);
  15. }
  16. m_anim = new AnimatorTimer();
  17. }
  18. // -----------------------------------------------------------
  19. void ~MainMenuButtonEffect()
  20. {
  21. if ( GetGame() && GetGame().GetUpdateQueue(CALL_CATEGORY_GUI) )
  22. {
  23. GetGame().GetUpdateQueue(CALL_CATEGORY_GUI).Remove(this.Update);
  24. }
  25. }
  26. // -----------------------------------------------------------
  27. void OnWidgetScriptInit(ButtonWidget w)
  28. {
  29. m_root = w;
  30. m_root.SetHandler(this);
  31. }
  32. // -----------------------------------------------------------
  33. protected void Update(float tDelta)
  34. {
  35. m_anim.Tick(tDelta);
  36. float p = amount * m_anim.GetValue();
  37. //m_root.SetTextProportion( m_textProportion + (p * 0.5) );
  38. m_root.SetTextOffset( p * 4, 0 );
  39. float c = 1.0 - m_anim.GetValue();
  40. m_root.SetTextColor(ARGBF(1, 1, c, c));
  41. }
  42. // -----------------------------------------------------------
  43. override bool OnFocus(Widget w, int x, int y)
  44. {
  45. //if ( !m_anim.IsRunning() ) m_textProportion = m_root.GetTextProportion();
  46. if ( !m_anim.IsRunning() )
  47. {
  48. m_root.GetPos( m_textProportion, m_textProportion2 );
  49. }
  50. m_anim.Animate(1.0, speed);
  51. return false;
  52. }
  53. // -----------------------------------------------------------
  54. override bool OnFocusLost(Widget w, int x, int y)
  55. {
  56. m_anim.Animate(0.0, speed);
  57. return false;
  58. }
  59. };