bleedingdrop.c 9.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293
  1. class BleedingIndicatorDropData
  2. {
  3. protected ImageWidget m_Widget;
  4. protected int m_Severity;
  5. protected float m_TimeTotal;
  6. protected float m_ProgressBreakpointTime;
  7. protected float m_ProgressFadingDuration; //remaining duration AFTER breakpoint
  8. protected float m_ProgressBreakpoint;
  9. protected float m_Duration;
  10. protected float m_SpeedCoef;
  11. protected int m_ScatterPx;
  12. protected float m_SlideDistance;
  13. protected float m_ColorAlphaStart;
  14. protected float m_ColorAlphaEnd;
  15. protected float m_ColorAlphaCurrent;
  16. protected float m_ImageBaseSizeX;
  17. protected float m_ImageBaseSizeY;
  18. protected float m_ImageStartingSizeX; //adjusted by percentage
  19. protected float m_ImageStartingSizeY; //adjusted by percentage
  20. protected float m_ImageEndSizeX; //adjusted by percentage
  21. protected float m_ImageEndSizeY; //adjusted by percentage
  22. protected float m_ImageMaxSizeX;
  23. protected float m_ImageMaxSizeY;
  24. protected float m_ImageBaseRotation;
  25. protected bool m_IsRunning;
  26. protected vector m_BasePosition;
  27. protected int m_ScreenSizeX;
  28. protected int m_ScreenSizeY;
  29. protected float m_PosX, m_PosY;
  30. protected float m_StartSizeCoef;
  31. protected float m_EndSizeCoef;
  32. protected float m_RandomSizeMin;
  33. protected float m_RandomSizeMax;
  34. //Written with relative positioning in mind
  35. void BleedingIndicatorDropData(ImageWidget image, int severity)
  36. {
  37. m_Widget = image;
  38. m_Severity = severity;
  39. m_TimeTotal = 0;
  40. m_IsRunning = false;
  41. #ifdef DIAG_DEVELOPER
  42. if (DbgBleedingIndicationStaticInfo.m_DbgUseOverrideValues)
  43. {
  44. m_Duration = DbgBleedingIndicationStaticInfo.m_DbgDropDurationBase;
  45. m_ProgressBreakpointTime = m_Duration * DbgBleedingIndicationStaticInfo.m_DbgDropProgressTreshold;
  46. m_ProgressBreakpoint = DbgBleedingIndicationStaticInfo.m_DbgDropProgressTreshold;
  47. m_StartSizeCoef = DbgBleedingIndicationStaticInfo.m_DbgDropStartSize;
  48. m_EndSizeCoef = DbgBleedingIndicationStaticInfo.m_DbgDropEndSize;
  49. m_RandomSizeMin = DbgBleedingIndicationStaticInfo.m_DbgDropSizeVariationMin;
  50. m_RandomSizeMax = DbgBleedingIndicationStaticInfo.m_DbgDropSizeVariationMax;
  51. m_ScatterPx = DbgBleedingIndicationStaticInfo.m_DbgDropScatter;
  52. m_SlideDistance = DbgBleedingIndicationStaticInfo.m_DbgDropSlideDistance;
  53. }
  54. else
  55. #endif
  56. {
  57. switch (m_Severity)
  58. {
  59. case BleedingIndicationConstants.INDICATOR_SEVERITY_LOW:
  60. {
  61. m_Duration = BleedingIndicationConstants.DROP_DURATION_LOW;
  62. m_StartSizeCoef = BleedingIndicationConstants.DROP_SIZE_START_LOW;
  63. m_EndSizeCoef = BleedingIndicationConstants.DROP_SIZE_END_LOW;
  64. m_RandomSizeMin = BleedingIndicationConstants.DROP_SIZE_VARIATION_MIN_LOW;
  65. m_RandomSizeMax = BleedingIndicationConstants.DROP_SIZE_VARIATION_MAX_LOW;
  66. m_ScatterPx = BleedingIndicationConstants.DROP_SCATTER_LOW;
  67. m_SlideDistance = BleedingIndicationConstants.DROP_SLIDE_DISTANCE_LOW;
  68. break;
  69. }
  70. case BleedingIndicationConstants.INDICATOR_SEVERITY_MEDIUM:
  71. {
  72. m_Duration = BleedingIndicationConstants.DROP_DURATION_MEDIUM;
  73. m_StartSizeCoef = BleedingIndicationConstants.DROP_SIZE_START_MEDIUM;
  74. m_EndSizeCoef = BleedingIndicationConstants.DROP_SIZE_END_MEDIUM;
  75. m_RandomSizeMin = BleedingIndicationConstants.DROP_SIZE_VARIATION_MIN_MEDIUM;
  76. m_RandomSizeMax = BleedingIndicationConstants.DROP_SIZE_VARIATION_MAX_MEDIUM;
  77. m_ScatterPx = BleedingIndicationConstants.DROP_SCATTER_MEDIUM;
  78. m_SlideDistance = BleedingIndicationConstants.DROP_SLIDE_DISTANCE_MEDIUM;
  79. break;
  80. }
  81. case BleedingIndicationConstants.INDICATOR_SEVERITY_HIGH:
  82. {
  83. m_Duration = BleedingIndicationConstants.DROP_DURATION_HIGH;
  84. m_StartSizeCoef = BleedingIndicationConstants.DROP_SIZE_START_HIGH;
  85. m_EndSizeCoef = BleedingIndicationConstants.DROP_SIZE_END_HIGH;
  86. m_RandomSizeMin = BleedingIndicationConstants.DROP_SIZE_VARIATION_MIN_HIGH;
  87. m_RandomSizeMax = BleedingIndicationConstants.DROP_SIZE_VARIATION_MAX_HIGH;
  88. m_ScatterPx = BleedingIndicationConstants.DROP_SCATTER_HIGH;
  89. m_SlideDistance = BleedingIndicationConstants.DROP_SLIDE_DISTANCE_HIGH;
  90. break;
  91. }
  92. }
  93. m_ProgressBreakpointTime = m_Duration * BleedingIndicationConstants.DROP_PROGRESS_THRESHOLD;
  94. m_ProgressBreakpoint = BleedingIndicationConstants.DROP_PROGRESS_THRESHOLD;
  95. }
  96. m_ProgressFadingDuration = Math.Max(0.0001, m_Duration - m_ProgressBreakpointTime);
  97. m_SpeedCoef = 1.0; //TODO ??
  98. #ifdef DIAG_DEVELOPER
  99. if (DbgBleedingIndicationStaticInfo.m_DbgUseOverrideValues)
  100. {
  101. m_ColorAlphaStart = DbgBleedingIndicationStaticInfo.m_DbgDropColorAlphaStart / 255;
  102. m_ColorAlphaEnd = DbgBleedingIndicationStaticInfo.m_DbgDropColorAlphaEnd / 255;
  103. }
  104. else
  105. #endif
  106. {
  107. m_ColorAlphaStart = BleedingIndicationConstants.DROP_COLOR_ALPHA_START / 255;
  108. m_ColorAlphaEnd = BleedingIndicationConstants.DROP_COLOR_ALPHA_END / 255;
  109. }
  110. InitImageScale();
  111. GetScreenSize(m_ScreenSizeX,m_ScreenSizeY);
  112. AdjustColorSaturation();
  113. }
  114. void ~BleedingIndicatorDropData()
  115. {
  116. }
  117. protected void InitImageScale()
  118. {
  119. m_Widget.GetSize(m_ImageBaseSizeX,m_ImageBaseSizeY);
  120. float randomScaleCoef = Math.RandomFloatInclusive(m_RandomSizeMin,m_RandomSizeMax);
  121. m_ImageStartingSizeX = m_ImageBaseSizeX * m_StartSizeCoef * randomScaleCoef;
  122. m_ImageEndSizeX = m_ImageBaseSizeX * m_EndSizeCoef * randomScaleCoef;
  123. m_ImageStartingSizeY = m_ImageBaseSizeY * m_StartSizeCoef * randomScaleCoef;
  124. m_ImageEndSizeY = m_ImageBaseSizeY * m_EndSizeCoef * randomScaleCoef;
  125. }
  126. void ScatterPosition(vector pos)
  127. {
  128. #ifdef DIAG_DEVELOPER
  129. if (DbgBleedingIndicationStaticInfo.m_DbgUseOverrideValues)
  130. {
  131. m_ScatterPx = DbgBleedingIndicationStaticInfo.m_DbgDropScatter;
  132. }
  133. #endif
  134. float rndRadius = Math.RandomFloatInclusive(0.0,m_ScatterPx);
  135. float rndPos = Math.RandomFloatInclusive(0.0,Math.PI2);
  136. m_PosX = pos[0];
  137. m_PosX = m_PosX + rndRadius * Math.Sin(rndPos);
  138. m_PosY = pos[1];
  139. m_PosY = m_PosY + rndRadius * Math.Cos(rndPos);
  140. }
  141. void StartDrop()
  142. {
  143. m_TimeTotal = 0;
  144. ScatterPosition(m_BasePosition);
  145. m_Widget.SetPos(m_PosX,m_PosY);
  146. #ifdef DIAG_DEVELOPER
  147. if (DbgBleedingIndicationStaticInfo.m_DbgUseOverrideValues && !DbgBleedingIndicationStaticInfo.m_DbgDropRotationRandom)
  148. {
  149. m_Widget.SetRotation(0,0,0);
  150. }
  151. else
  152. #endif
  153. {
  154. m_Widget.SetRotation(0,0,Math.RandomFloatInclusive(0.0,360.0));
  155. }
  156. m_Widget.Show(true);
  157. m_IsRunning = true;
  158. }
  159. void StopDrop()
  160. {
  161. m_IsRunning = false;
  162. m_Widget.SetSize(m_ImageBaseSizeX,m_ImageBaseSizeY); //resets image size
  163. m_Widget.Show(false);
  164. }
  165. void SetBasePosition(vector pos)
  166. {
  167. m_BasePosition = pos;
  168. m_BasePosition[0] = m_BasePosition[0] - m_ScreenSizeX/2;
  169. m_BasePosition[1] = m_BasePosition[1] - m_ScreenSizeY/2;
  170. }
  171. bool IsRunning()
  172. {
  173. return m_IsRunning;
  174. }
  175. ImageWidget GetImage()
  176. {
  177. return m_Widget;
  178. }
  179. void AdjustColorSaturation()
  180. {
  181. //color adjustment
  182. float r = BleedingIndicationConstants.DROP_COLOR_RED;
  183. float g = BleedingIndicationConstants.DROP_COLOR_GREEN;
  184. float b = BleedingIndicationConstants.DROP_COLOR_BLUE;
  185. float desaturationEnd = BleedingIndicationConstants.DROP_COLOR_DESATURATIONEND;
  186. #ifdef DIAG_DEVELOPER
  187. if (DbgBleedingIndicationStaticInfo.m_DbgUseOverrideValues)
  188. {
  189. r = DbgBleedingIndicationStaticInfo.m_DbgDropColorRed;
  190. g = DbgBleedingIndicationStaticInfo.m_DbgDropColorGreen;
  191. b = DbgBleedingIndicationStaticInfo.m_DbgDropColorBlue;
  192. desaturationEnd = DbgBleedingIndicationStaticInfo.m_DbgDesaturationEnd;
  193. }
  194. #endif
  195. //saturation adjustment
  196. #ifdef DIAG_DEVELOPER
  197. if (!DbgBleedingIndicationStaticInfo.m_DbgUseOverrideValues || (DbgBleedingIndicationStaticInfo.m_DbgUseOverrideValues && DbgBleedingIndicationStaticInfo.m_DbgDropDesaturate) )
  198. {
  199. #endif
  200. Param par = PPEManagerStatic.GetPPEManager().GetPostProcessCurrentValues(PostProcessEffectType.Glow,PPEGlow.PARAM_SATURATION);
  201. float saturationProgress = Param1<float>.Cast(par).param1;
  202. saturationProgress = Easing.EaseOutSine(saturationProgress);
  203. saturationProgress = Math.Lerp(desaturationEnd,1.0,saturationProgress);
  204. float lowest_channel = Math.Min(Math.Min(r,g),b);
  205. r = Math.Lerp(lowest_channel,r,saturationProgress);
  206. g = Math.Lerp(lowest_channel,g,saturationProgress);
  207. b = Math.Lerp(lowest_channel,b,saturationProgress);
  208. #ifdef DIAG_DEVELOPER
  209. }
  210. #endif
  211. int color = ARGB(0x00,r,g,b);
  212. m_Widget.SetColor(color);
  213. }
  214. void UpdateAlpha(float progress,float progressFade)
  215. {
  216. if (progress <= m_ProgressBreakpoint)
  217. {
  218. m_ColorAlphaCurrent = m_ColorAlphaStart;
  219. }
  220. else
  221. {
  222. m_ColorAlphaCurrent = Math.Lerp(m_ColorAlphaStart,m_ColorAlphaEnd,progressFade);
  223. }
  224. m_Widget.SetAlpha(m_ColorAlphaCurrent);
  225. }
  226. //! scaling and transformation
  227. void UpdateTransform(float progress, float progressFade)
  228. {
  229. float breakProgress = Math.Clamp(Math.InverseLerp(0.0,m_ProgressBreakpoint,progress),0,1);
  230. float sizeX = Math.Lerp(m_ImageStartingSizeX,m_ImageEndSizeX,breakProgress);
  231. float sizeY = Math.Lerp(m_ImageStartingSizeY,m_ImageEndSizeY,breakProgress);
  232. m_Widget.SetSize(sizeX,sizeY);
  233. if (progress <= m_ProgressBreakpoint)
  234. {
  235. //do stuff before breakpoint
  236. }
  237. else
  238. {
  239. //do stuff after breakpoint
  240. float posYTemp = Math.Lerp(m_PosY,m_PosY + m_SlideDistance, progressFade);
  241. m_Widget.SetPos(m_PosX,posYTemp);
  242. }
  243. }
  244. void Update(float timeSlice)
  245. {
  246. if (m_IsRunning)
  247. {
  248. float progress, progressFade;
  249. progress = m_TimeTotal / m_Duration;
  250. progressFade = (m_TimeTotal - m_ProgressBreakpointTime) / m_ProgressFadingDuration;
  251. //alpha
  252. UpdateAlpha(progress,progressFade);
  253. //transform + scaling
  254. UpdateTransform(progress,progressFade);
  255. m_TimeTotal += (timeSlice * m_SpeedCoef);
  256. if (m_TimeTotal >= m_Duration)
  257. {
  258. //deletes this;
  259. StopDrop();
  260. }
  261. }
  262. }
  263. }