radialprogressbar.c 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. // -----------------------------------------------------------
  2. class RadialProgressBar
  3. {
  4. reference float speed;
  5. reference float start_rotation;
  6. protected string m_BarHider;
  7. protected string m_BarPart;
  8. protected Widget m_Root;
  9. protected ref AnimatorTimer m_Anim;
  10. protected float x, y, z;
  11. protected float rotation = 0;
  12. protected int stage = 0;
  13. // -----------------------------------------------------------
  14. void RadialProgressBar()
  15. {
  16. m_Anim = new AnimatorTimer();
  17. GetGame().GetUpdateQueue(CALL_CATEGORY_GUI).Insert(this.Update);
  18. }
  19. // -----------------------------------------------------------
  20. void ~RadialProgressBar()
  21. {
  22. GetGame().GetUpdateQueue(CALL_CATEGORY_GUI).Remove(this.Update);
  23. }
  24. void SetProgress( float progress )
  25. {
  26. if( progress < 50 )
  27. {
  28. stage = 0;
  29. }
  30. rotation = 360 * ( progress / 100 );
  31. }
  32. // -----------------------------------------------------------
  33. protected void Update(float tDelta)
  34. {
  35. m_Anim.Tick(tDelta);
  36. Widget child = m_Root.GetChildren();
  37. int index = 0;
  38. while ( child )
  39. {
  40. UpdateChild( child, index );
  41. index++;
  42. child = child.GetSibling();
  43. }
  44. }
  45. protected void UpdateChild( Widget child, int index )
  46. {
  47. float rotation_value = ( m_Anim.GetTargetValue() * Math.RAD2DEG );
  48. if( child.GetName() == m_BarHider )
  49. {
  50. if( stage == 0 )
  51. {
  52. if( rotation > 0 )
  53. {
  54. child.GetChildren().Show(true);
  55. }
  56. else
  57. {
  58. child.GetChildren().Show(false);
  59. }
  60. child.GetChildren().SetRotation( 0, 0, start_rotation + rotation);
  61. if( rotation > 180 )
  62. {
  63. stage = 1;
  64. child.GetChildren().SetRotation(0, 0, 360);
  65. }
  66. }
  67. }
  68. else if( child.GetName() == m_BarPart )
  69. {
  70. if( stage == 0 )
  71. child.Show( false );
  72. if( stage == 1 )
  73. {
  74. child.Show( true );
  75. child.SetRotation( 0, 0, start_rotation + rotation );
  76. if( rotation > 360 )
  77. {
  78. stage = 2;
  79. child.SetRotation( 0, 0, 180 );
  80. }
  81. }
  82. }
  83. }
  84. // -----------------------------------------------------------
  85. void OnWidgetScriptInit( Widget w )
  86. {
  87. m_Root = w;
  88. m_BarHider = "BarHider_" + m_Root.GetName();
  89. m_BarPart = "BarPart2_" + m_Root.GetName();
  90. m_Anim.AnimateLoop( speed );
  91. }
  92. };