continuousactionprogress.c 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  1. class ContinuousActionProgress extends ScriptedWidgetEventHandler
  2. {
  3. reference string RadialBarWidgetName;
  4. protected PlayerBase m_Player;
  5. protected ActionBase m_Action;
  6. protected int m_ActionState;
  7. protected ActionManagerBase m_AM;
  8. protected ref WidgetFadeTimer m_FadeTimer;
  9. protected bool m_Faded;
  10. protected float m_InitProgress;
  11. protected float m_Speed;
  12. protected Widget m_Root;
  13. protected Widget m_RadialWidget;
  14. protected ImageWidget m_LoaderImage;
  15. ref RadialProgressBar m_Radial;
  16. void ContinuousActionProgress()
  17. {
  18. m_Action = null;
  19. m_ActionState = -1;
  20. m_AM = null;
  21. m_RadialWidget = null;
  22. m_LoaderImage = null;
  23. m_Radial = null;
  24. m_Speed = 0;
  25. m_InitProgress = 100;
  26. m_FadeTimer = new WidgetFadeTimer;
  27. m_Faded = true;
  28. GetGame().GetUpdateQueue(CALL_CATEGORY_GUI).Insert(Update);
  29. }
  30. void ~ContinuousActionProgress()
  31. {
  32. GetGame().GetUpdateQueue(CALL_CATEGORY_GUI).Remove(Update);
  33. }
  34. protected void OnWidgetScriptInit(Widget w)
  35. {
  36. m_Root = w;
  37. m_Root.SetHandler(this);
  38. m_Root.Show(false);
  39. m_RadialWidget = m_Root.FindAnyWidget("PBRadial1");
  40. m_LoaderImage = ImageWidget.Cast( m_Root.FindAnyWidget("cap_init_loader") );
  41. if(m_RadialWidget)
  42. m_RadialWidget.GetScript(m_Radial);
  43. m_Root.Update();
  44. }
  45. protected void Update()
  46. {
  47. //! don't show continuous action progressif it's disabled in profile OR soft-disabled by the '~' keyhold
  48. Mission mission = GetGame().GetMission();
  49. IngameHud hud = IngameHud.Cast(mission.GetHud());
  50. if (hud && hud.GetHudVisibility().IsContextFlagActive(IngameHudVisibility.HUD_HIDE_FLAGS))
  51. {
  52. m_Root.Show(false);
  53. return;
  54. }
  55. if(m_Player && !m_Player.IsAlive()) // handle respawn
  56. {
  57. m_Player = null;
  58. m_AM = null;
  59. }
  60. if(!m_Player) GetPlayer();
  61. if(!m_AM) GetActionManager();
  62. GetActions();
  63. if(m_Action && m_Action.HasProgress() && m_ActionState != UA_NONE && GetGame().GetUIManager().GetMenu() == null)
  64. {
  65. if(m_ActionState == UA_INITIALIZE || m_ActionState == UA_AM_PENDING)
  66. {
  67. m_Speed += 0.02;
  68. m_LoaderImage.SetRotation(0, 0, m_Speed * Math.RAD2DEG);
  69. m_LoaderImage.Show(true);
  70. }
  71. else
  72. {
  73. m_Speed = 0.0;
  74. m_LoaderImage.SetRotation(0, 0, 0);
  75. m_LoaderImage.Show(false);
  76. }
  77. if(m_ActionState == UA_PROCESSING)
  78. {
  79. m_InitProgress = 100;
  80. m_LoaderImage.SetRotation(0, 0, 0);
  81. SetProgress(Math.AbsFloat(m_AM.GetActionComponentProgress() * 100 * m_AM.GetACProgressWidgetMultiplier()));
  82. }
  83. m_Root.Show(true);
  84. }
  85. else
  86. {
  87. m_Speed = 0.0;
  88. m_Root.Show(false);
  89. m_LoaderImage.Show(false);
  90. SetProgress(0.0);
  91. m_LoaderImage.SetRotation(0, 0, 0);
  92. }
  93. }
  94. // getters
  95. private void GetPlayer()
  96. {
  97. Class.CastTo(m_Player, GetGame().GetPlayer());
  98. }
  99. private void GetActionManager()
  100. {
  101. if( m_Player && m_Player.IsPlayerSelected() )
  102. {
  103. Class.CastTo(m_AM, m_Player.GetActionManager());
  104. }
  105. else
  106. m_AM = null;
  107. }
  108. private void GetActions()
  109. {
  110. if(!m_AM) return;
  111. m_Action = null;
  112. m_ActionState = -1;
  113. m_Action = m_AM.GetRunningAction();
  114. if(m_Action && m_Action.GetInput().GetInputType() == ActionInputType.AIT_CONTINUOUS)
  115. m_ActionState = m_AM.GetActionState(m_Action);
  116. else
  117. m_Action = null;
  118. }
  119. private void SetProgress(float progress)
  120. {
  121. if(m_Radial)
  122. m_Radial.SetProgress(progress);
  123. }
  124. }