csProgressBar.cpp 22 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150
  1. #include "..\..\..\common_h/mission/Mission.h"
  2. #include "csProgressBar.h"
  3. #include "..\Utils\InterfaceUtils.h"
  4. static const char TOP_LEFT [] = "Top-left";
  5. static const char TOP_RIGHT [] = "Top-right";
  6. static const char BOTTOM_LEFT [] = "Bottom-left";
  7. static const char BOTTOM_RIGHT[] = "Bottom-right";
  8. /*
  9. const float MaxAddDecEffectTime = 1.0f;
  10. const float MaxShowEffectTime = 0.8f;
  11. */
  12. csProgressBar::csProgressBar()
  13. {
  14. m_restart = false;
  15. m_fValue = 0.0f;
  16. m_fPrevValue = 0.0f;
  17. m_fPercent = 0.5f;
  18. m_pHPObject.Reset();
  19. MaxAddDecEffectTime = 1.0f;
  20. MaxShowEffectTime = 0.8f;
  21. m_fValue = 0.0f;
  22. m_showAddDecEffect = false;
  23. m_showEffectTime = 0.0f;
  24. pRS = (IRender*)api->GetService("DX9Render");
  25. Assert(pRS)
  26. barTexture = pRS->GetTechniqueGlobalVariable("interfaceTexture",_FL_);
  27. texture = NULL;
  28. drawLevel = ML_GUI2;
  29. }
  30. csProgressBar::~csProgressBar()
  31. {
  32. if( texture )
  33. {
  34. texture->Release();
  35. texture = null;
  36. }
  37. barTexture = null;
  38. }
  39. void csProgressBar::Restart()
  40. {
  41. m_restart = true;
  42. ReCreate();
  43. }
  44. // Вызывается в режиме игры после создания всех объектов
  45. void csProgressBar::PostCreate()
  46. {
  47. if( !m_pHPObject.Ptr() && !m_params.HPObject.IsEmpty())
  48. {
  49. FindObject(m_params.HPObject,m_pHPObject);
  50. if( m_pHPObject.Ptr())
  51. {
  52. m_fPrevValue = m_fValue = m_pHPObject.Ptr()->GetHP();
  53. }
  54. }
  55. m_pHPObject.Validate();
  56. }
  57. //Создание объекта
  58. bool csProgressBar::Create (MOPReader & reader)
  59. {
  60. if( !m_restart )
  61. {
  62. Render().GetShaderId("interfaceQuad",GUI_Quad_id);
  63. }
  64. EditMode_Update(reader);
  65. return true;
  66. }
  67. //Обновление параметров
  68. bool csProgressBar::EditMode_Update(MOPReader & reader)
  69. {
  70. ////////////////////////////////////////////////
  71. // BaseGUIElement::EditMode_Update(reader); //
  72. ////////////////////////////////////////////////
  73. if( !m_restart )
  74. {
  75. // m_aspect = InterfaceUtils::AspectRatio(Render());
  76. InitAspect();
  77. }
  78. Layout layout;
  79. switch( reader.Enum().c_str()[0] )
  80. {
  81. case 'C':
  82. layout = OnCenter;
  83. break;
  84. case 'L':
  85. layout = OnLeft;
  86. break;
  87. case 'R':
  88. layout = OnRight;
  89. break;
  90. };
  91. if( !Restricted(preserveLayout))
  92. m_layout = layout;
  93. m_natLay = layout;
  94. back_t = reader.String().c_str();
  95. fron_t = reader.String().c_str();
  96. if( !m_restart )
  97. {
  98. if( texture )
  99. texture->Release();
  100. // texture = (ITexture *)pRS->CreateTexture(_FL_,fron_t);
  101. texture = (ITexture *)pRS->CreateTextureFullQuality(_FL_,fron_t);
  102. m_backRender.SetTexture(back_t);
  103. m_frontRender.SetTexture(fron_t);
  104. }
  105. // m_params.fX = reader.Float();
  106. // m_params.fY = reader.Float();
  107. float x = reader.Float();
  108. float y = reader.Float();
  109. if( !Restricted(preservePos))
  110. MoveTo(x,y);
  111. m_natPos.x = x;
  112. m_natPos.y = y;
  113. // m_params.fWidth = reader.Float();
  114. // m_params.fHeight = reader.Float();
  115. float w = reader.Float();
  116. float h = reader.Float();
  117. if( !Restricted(preserveSize))
  118. SizeTo(w,h);
  119. m_natSize.w = w;
  120. m_natSize.h = h;
  121. m_fValue = m_params.fMaxValue = (float)reader.Long();
  122. m_fPrevValue = 0.0f;
  123. m_params.HPObject = reader.String();
  124. fMinBorder = reader.Float() * 0.01f;
  125. fMaxBorder = reader.Float() * 0.01f;
  126. m_params.fStartBar = reader.Float() * 0.01f;
  127. m_params.fEndBar = reader.Float() * 0.01f;
  128. m_params.drawPriority = reader.Long();
  129. m_res = reader.Enum().c_str();
  130. m_params.doShowEffect = reader.Bool();
  131. // Show(reader.Bool());
  132. nativeShow = reader.Bool();
  133. MaxAddDecEffectTime = reader.Float();
  134. MaxShowEffectTime = reader.Float();
  135. circular = reader.Bool();
  136. reverse = reader.Bool();
  137. vertical = reader.Bool();
  138. inverse = reader.Bool();
  139. // MoveTo(m_params.fX ,m_params.fY);
  140. // SizeTo(m_params.fWidth,m_params.fHeight);
  141. SetAlpha (reader.Float());
  142. SetParent(reader.String());
  143. // SetUpdate(&csProgressBar::InitFunc,ML_FIRST);
  144. SetUpdate(&csProgressBar::InitFunc,ML_FIRST + 2);
  145. return true;
  146. }
  147. void csProgressBar::OnParentNotify(Notification event)
  148. {
  149. BaseGUIElement::OnParentNotify(event);
  150. if( event == ParentChanged )
  151. Update();
  152. }
  153. // извращенный расчет ректа
  154. void csProgressBar::GetRect(Rect &rect, bool useOffset)// const
  155. {
  156. float x = m_X;
  157. float y = m_Y;
  158. float w = GetWidth ()*m_aspect;
  159. float h = GetHeight();
  160. if( w >= 0.0f )
  161. {
  162. rect.l = x;
  163. rect.t = y;
  164. rect.r = x + w;
  165. rect.b = y + h;
  166. }
  167. else
  168. {
  169. rect.l = x + w;
  170. rect.t = y;
  171. rect.r = x;
  172. rect.b = y + h;
  173. }
  174. }
  175. void _cdecl csProgressBar::InitFunc(float, long)
  176. {
  177. DelUpdate(&csProgressBar::InitFunc);
  178. if( m_restart )
  179. {
  180. m_restart = false;
  181. }
  182. else
  183. {
  184. BaseGUIElement *parent = GetParent();
  185. if( BaseGUIElement *newParent = FindParent())
  186. {
  187. newParent->Register(this);
  188. }
  189. else
  190. {
  191. if( parent )
  192. parent->UnRegister(this);
  193. }
  194. }
  195. Update();
  196. Show(nativeShow);
  197. }
  198. /*
  199. void csProgressBar::Update()
  200. {
  201. FindParent();
  202. Rect r; GetParentRect(r);
  203. parent_bottom = r.b;
  204. float x,y; GetNativePos (x,y);
  205. float w,h; GetNativeSize(w,h);
  206. x *= m_aspect;
  207. if( w < 0.0f )
  208. w = -w;
  209. if( string::IsEqual(m_res,TOP_LEFT))
  210. {
  211. m_X = x + r.l;
  212. m_Y = y + r.t;
  213. m_bottom = false;
  214. }
  215. if( string::IsEqual(m_res,BOTTOM_LEFT))
  216. {
  217. m_X = x + r.l;
  218. m_Y = r.b - h - y;
  219. m_bottom = true;
  220. }
  221. if( string::IsEqual(m_res,TOP_RIGHT))
  222. {
  223. m_X = r.r - x;
  224. m_Y = y + r.t;
  225. w = -w;
  226. m_bottom = false;
  227. }
  228. if( string::IsEqual(m_res,BOTTOM_RIGHT))
  229. {
  230. m_X = r.r - x;
  231. m_Y = r.b - h - y;
  232. w = -w;
  233. m_bottom = true;
  234. }
  235. SizeTo(w,h);
  236. }
  237. */
  238. void csProgressBar::Update()
  239. {
  240. FindParent();
  241. Rect r; GetParentRect(r);
  242. parent_bottom = r.b;
  243. float x,y; GetNativePos (x,y);
  244. float w,h; GetNativeSize(w,h);
  245. x *= m_aspect;
  246. if( w < 0.0f )
  247. w = -w;
  248. if( string::IsEqual(m_res,"Top"))
  249. {
  250. switch( m_layout )
  251. {
  252. case OnLeft:
  253. m_X = x + r.l;
  254. m_Y = y + r.t;
  255. break;
  256. case OnCenter:
  257. m_X = (r.l + r.r)*0.5f + x - w*m_aspect*0.5f;
  258. m_Y = y + r.t;
  259. break;
  260. case OnRight:
  261. m_X = r.r - x;
  262. m_Y = y + r.t; w = -w;
  263. break;
  264. }
  265. m_bottom = false;
  266. }
  267. else
  268. {
  269. switch( m_layout )
  270. {
  271. case OnLeft:
  272. m_X = x + r.l;
  273. m_Y = r.b - h - y;
  274. break;
  275. case OnCenter:
  276. m_X = (r.l + r.r)*0.5f + x - w*m_aspect*0.5f;
  277. m_Y = r.b - h - y;
  278. break;
  279. case OnRight:
  280. m_X = r.r - x;
  281. m_Y = r.b - h - y; w = -w;
  282. }
  283. m_bottom = true;
  284. }
  285. SizeTo(w,h);
  286. }
  287. static const float R1 = PI/4;
  288. static const float R2 = -R1;
  289. static const float R3 = -R1*3;
  290. static const float R4 = -R1*5;
  291. void csProgressBar::Calculate(float x, float y, float w, float h, Vertex &v, float ang, float a, float wk)
  292. {
  293. float s = sin(ang);
  294. float c = cos(ang);
  295. float xk = c/fabsf(s);
  296. float yk = s/fabsf(c);
  297. if( ang > R1 || ang <= R4 )
  298. {
  299. v.x = x + w*xk;
  300. v.y = y - h;
  301. v.a = a;
  302. v.u = 0.5f + 0.5f*xk*wk;
  303. v.v = 0.0f;
  304. }
  305. else
  306. if( ang > R2 )
  307. {
  308. v.x = x + w;
  309. v.y = y - h*yk;
  310. v.a = a;
  311. v.u = wk < 0.0f ? 0.0f : 1.0f;
  312. v.v = 0.5f - 0.5f*yk;
  313. }
  314. else
  315. if( ang > R3 )
  316. {
  317. v.x = x + w*xk;
  318. v.y = y + h;
  319. v.a = a;
  320. v.u = 0.5f + 0.5f*xk*wk;
  321. v.v = 1.0f;
  322. }
  323. else
  324. if( ang > R4 )
  325. {
  326. v.x = x - w;
  327. v.y = y - h*yk;
  328. v.a = a;
  329. v.u = wk < 0.0f ? 1.0f : 0.0f;
  330. v.v = 0.5f - 0.5f*yk;
  331. }
  332. }
  333. void csProgressBar::DrawBar(float wk, float x, float y, float w, float h, float beg, float end, float alpha, float xs, float ys)
  334. {
  335. if( reverse )
  336. {
  337. beg = 1.0f - beg;
  338. end = 1.0f - end;
  339. }
  340. if( end <= beg )
  341. // return;
  342. {
  343. float t = end;
  344. end = beg;
  345. beg = t;
  346. }
  347. x -= (w*xs - w)*0.5f;
  348. y -= (h*ys - h)*0.5f;
  349. w *= xs;
  350. h *= ys;
  351. w *= 0.5*0.01f;
  352. h *= 0.5*0.01f;
  353. x *= 0.01f;
  354. y *= 0.01f;
  355. x += w;
  356. y += h;
  357. beg = PI*0.5f - 2*PI*beg;
  358. end = PI*0.5f - 2*PI*end;
  359. Vertex b[7]; long n = 0;
  360. b[n].x = x;
  361. b[n].y = y;
  362. b[n].a = alpha;
  363. b[n].u = 0.5f;
  364. b[n].v = 0.5f;
  365. n++;
  366. float pos = PI/4; float step = PI/2;
  367. while( beg < pos )
  368. {
  369. // Calculate(x,y,w,h,b[n++],pos,alpha);
  370. pos -= step;
  371. }
  372. Calculate(x,y,w,h,b[n++],beg,alpha,wk);
  373. while( end < pos )
  374. {
  375. Calculate(x,y,w,h,b[n++],pos,alpha,wk);
  376. pos -= step;
  377. }
  378. Calculate(x,y,w,h,b[n++],end,alpha,wk);
  379. if( inverse )
  380. {
  381. for( int i = 0 ; i < n ; i++ )
  382. {
  383. b[i].x = b[i].x*2.0f - 1.0f;
  384. b[i].y = 1.0f - (y - (b[i].y - y))*2.0f;
  385. b[i].z = 1.0f;
  386. b[i].v = 1.0f - b[i].v;
  387. }
  388. }
  389. else
  390. {
  391. for( int i = 0 ; i < n ; i++ )
  392. {
  393. b[i].x = b[i].x*2.0f - 1.0f;
  394. b[i].y = 1.0f - b[i].y*2.0f;
  395. b[i].z = 1.0f;
  396. }
  397. }
  398. if( barTexture && texture )
  399. barTexture->SetTexture(texture);
  400. pRS->DrawPrimitiveUP(GUI_Quad_id, PT_TRIANGLEFAN,n - 2,b,6*sizeof(float));
  401. }
  402. void csProgressBar::Draw(float wScale, float hScale, float fMaximalVal, float globalAlpha)
  403. {
  404. bool edit_mode = EditMode_IsOn();
  405. float y = m_Y;
  406. float w = GetWidth ();
  407. float h = GetHeight();
  408. if( !Restricted(preserveSize))
  409. w *= m_aspect;
  410. if( m_bottom )
  411. y = parent_bottom - h - GetNativeY();
  412. float wk;
  413. float xx;
  414. if( circular && reverse )
  415. {
  416. wk = -1.0f;
  417. xx = GetWidth();
  418. }
  419. else
  420. {
  421. wk = 1.0f;
  422. xx = 0.0f;
  423. }
  424. if( edit_mode || back_t[0] )
  425. {
  426. float al = 1.0f;
  427. if( edit_mode && !back_t[0] )
  428. al = 0.5f;
  429. m_backRender.DrawQuad(
  430. m_X + xx,y,w*wk,h,0,0,1.0,1.0,10.0f + 1.0f*globalAlpha*al,wScale,hScale,vertical,true);
  431. }
  432. if( !edit_mode && !fron_t[0] )
  433. return;
  434. float al = 1.0f;
  435. if( edit_mode && !fron_t[0] )
  436. al = 0.5f;
  437. // рисуем спецэффект добавления/убавления жизней
  438. if( m_fPrevValue != m_fValue && !edit_mode )
  439. {
  440. m_showAddDecEffect = true;
  441. m_addDecEffectTime = MaxAddDecEffectTime;
  442. if( m_fPrevValue < m_fValue) m_effects |= AddHP;
  443. if( m_fPrevValue > m_fValue) m_effects |= DecHP;
  444. m_addDecEffectStartU = ScaleToBorder(m_fValue/fMaximalVal)*(m_params.fEndBar - m_params.fStartBar);
  445. m_addDecEffectEndU = ScaleToBorder(m_fPrevValue/fMaximalVal)*(m_params.fEndBar - m_params.fStartBar);
  446. }
  447. float off = 0.0f;
  448. if( m_showAddDecEffect && m_effects&AddHP )
  449. {
  450. float k = m_addDecEffectTime/MaxAddDecEffectTime;
  451. off = k*(m_addDecEffectEndU - m_addDecEffectStartU);
  452. }
  453. if( circular )
  454. {
  455. DrawBar(wk,m_X,y,w,h,
  456. m_params.fStartBar,
  457. // m_params.fStartBar + m_fPercent*(m_params.fEndBar - m_params.fStartBar),
  458. m_params.fStartBar + m_fPercent*(m_params.fEndBar - m_params.fStartBar) + off,
  459. 10.0f + 1.0f*globalAlpha*al,wScale,hScale);
  460. }
  461. else
  462. {
  463. if( vertical )
  464. {
  465. if( reverse )
  466. {
  467. m_frontRender.DrawQuad(
  468. // m_X,y + m_params.fStartBar*h,
  469. m_X,y + h - (1.0f - m_params.fEndBar)*h - (m_fPercent*(m_params.fEndBar - m_params.fStartBar) + off)*h,
  470. w,(m_fPercent*(m_params.fEndBar - m_params.fStartBar) + off)*h,
  471. // m_params.fStartBar,0,
  472. // m_fPercent*(m_params.fEndBar - m_params.fStartBar) + off,1.0f,
  473. // 0,m_params.fStartBar,
  474. 0,1.0f - (1.0f - m_params.fEndBar + m_fPercent*(m_params.fEndBar - m_params.fStartBar) + off),
  475. 1.0f,m_fPercent*(m_params.fEndBar - m_params.fStartBar) + off,
  476. 10.0f + 1.0f*globalAlpha*al,wScale,hScale,vertical,true);
  477. }
  478. else
  479. {
  480. m_frontRender.DrawQuad(
  481. m_X,y + m_params.fStartBar*h,
  482. w,(m_fPercent*(m_params.fEndBar - m_params.fStartBar) + off)*h,
  483. // m_params.fStartBar,0,
  484. // m_fPercent*(m_params.fEndBar - m_params.fStartBar) + off,1.0f,
  485. 0,m_params.fStartBar,
  486. 1.0f,m_fPercent*(m_params.fEndBar - m_params.fStartBar) + off,
  487. 10.0f + 1.0f*globalAlpha*al,wScale,hScale,vertical,true);
  488. }
  489. }
  490. else
  491. {
  492. if( reverse )
  493. {
  494. m_frontRender.DrawQuad(
  495. // m_X + m_params.fStartBar*w,y,
  496. m_X + w - (1.0f - m_params.fEndBar)*w - (m_fPercent*(m_params.fEndBar - m_params.fStartBar) + off)*w,y,
  497. (m_fPercent*(m_params.fEndBar - m_params.fStartBar) + off)*w,h,
  498. // m_params.fStartBar,0,
  499. 1.0f - (1.0f - m_params.fEndBar + m_fPercent*(m_params.fEndBar - m_params.fStartBar) + off),0,
  500. m_fPercent*(m_params.fEndBar - m_params.fStartBar) + off,1.0f,
  501. 10.0f + 1.0f*globalAlpha*al,wScale,hScale,vertical,true);
  502. }
  503. else
  504. {
  505. m_frontRender.DrawQuad(
  506. m_X + m_params.fStartBar*w,y,
  507. (m_fPercent*(m_params.fEndBar - m_params.fStartBar) + off)*w,h,
  508. m_params.fStartBar,0,
  509. m_fPercent*(m_params.fEndBar - m_params.fStartBar) + off,1.0f,
  510. 10.0f + 1.0f*globalAlpha*al,wScale,hScale,vertical,true);
  511. }
  512. }
  513. }
  514. if( m_showAddDecEffect )
  515. {
  516. float Bright = 10.0f;
  517. // if( m_effects&AddHP )
  518. if( m_effects&AddHP && circular )
  519. {
  520. // Bright *= 2.0f;
  521. }
  522. if( m_addDecEffectTime <= 0.0f )
  523. {
  524. m_addDecEffectTime = 0.0f;
  525. m_showAddDecEffect = false;
  526. m_effects &= ~AddHP;
  527. m_effects &= ~DecHP;
  528. }
  529. if( circular )
  530. {
  531. float k = m_addDecEffectTime/MaxAddDecEffectTime;
  532. if( m_effects&AddHP ) k = 1.0f - k;
  533. DrawBar(wk,m_X,y,w,h,
  534. m_params.fStartBar + m_addDecEffectStartU,
  535. m_params.fStartBar + m_addDecEffectStartU + m_addDecEffectTime*(m_addDecEffectEndU - m_addDecEffectStartU),
  536. Bright + globalAlpha*k*al,wScale,hScale);
  537. }
  538. else
  539. {
  540. float k = m_addDecEffectTime/MaxAddDecEffectTime;
  541. float delta = k*(m_addDecEffectEndU - m_addDecEffectStartU);
  542. if( m_effects&AddHP )
  543. k = 1.0f - k;
  544. if( vertical )
  545. {
  546. if( reverse )
  547. {
  548. m_frontRender.DrawQuad(
  549. // m_X,y + (m_params.fStartBar + m_addDecEffectStartU)*h + (h*hScale - h)*0.5f*0.5f,
  550. m_X,y + h - (1.0f - m_params.fEndBar + m_addDecEffectStartU)*h - (h*hScale - h)*0.5f*0.5f - delta*h,
  551. w,delta*h,
  552. // m_params.fStartBar + m_addDecEffectStartU,0,
  553. // delta,1.0f,
  554. // 0,m_params.fStartBar + m_addDecEffectStartU,
  555. 0,1.0f - (1.0f - m_params.fEndBar + m_addDecEffectStartU + delta),
  556. 1.0f,delta,
  557. Bright + globalAlpha*k*al,wScale,hScale,vertical,true);
  558. }
  559. else
  560. {
  561. m_frontRender.DrawQuad(
  562. m_X,y + (m_params.fStartBar + m_addDecEffectStartU)*h + (h*hScale - h)*0.5f*0.5f,
  563. w,delta*h,
  564. // m_params.fStartBar + m_addDecEffectStartU,0,
  565. // delta,1.0f,
  566. 0,m_params.fStartBar + m_addDecEffectStartU,
  567. 1.0f,delta,
  568. Bright + globalAlpha*k*al,wScale,hScale,vertical,true);
  569. }
  570. }
  571. else
  572. {
  573. if( reverse )
  574. {
  575. m_frontRender.DrawQuad(
  576. m_X + w - (1.0f - m_params.fEndBar + m_addDecEffectStartU)*w - (w*wScale - w)*0.5f*0.5f - delta*w,y,
  577. delta*w,h,
  578. // m_params.fStartBar + m_addDecEffectStartU,0,
  579. 1.0f - (1.0f - m_params.fEndBar + m_addDecEffectStartU + delta),0,
  580. delta,1.0f,
  581. Bright + globalAlpha*k*al,wScale,hScale,vertical,true);
  582. }
  583. else
  584. {
  585. m_frontRender.DrawQuad(
  586. m_X + (m_params.fStartBar + m_addDecEffectStartU)*w + (w*wScale - w)*0.5f*0.5f,y,
  587. delta*w,h,
  588. m_params.fStartBar + m_addDecEffectStartU,0,
  589. delta,1.0f,
  590. Bright + globalAlpha*k*al,wScale,hScale,vertical,true);
  591. }
  592. }
  593. }
  594. }
  595. }
  596. void _cdecl csProgressBar::Work(float dltTime, long level)
  597. {
  598. if( EditMode_IsOn() && !EditMode_IsVisible())
  599. return;
  600. Draw();
  601. Update(dltTime);
  602. }
  603. void csProgressBar::Update(float dltTime)
  604. {
  605. if(!EditMode_IsOn())
  606. {
  607. if( !m_pHPObject.Validate())
  608. {
  609. FindObject(m_params.HPObject,m_pHPObject);
  610. if( m_pHPObject.Ptr())
  611. {
  612. m_fPrevValue = m_fValue = m_pHPObject.Ptr()->GetHP();
  613. }
  614. }
  615. }
  616. if( m_showAddDecEffect )
  617. m_addDecEffectTime -= dltTime;
  618. if( m_effects&ShowBar )
  619. {
  620. m_showEffectTime -= dltTime;
  621. if( m_showEffectTime <= 0.0f )
  622. {
  623. m_showEffectTime = 0.0f;
  624. m_effects &= ~ShowBar;
  625. }
  626. }
  627. m_fPrevValue = m_fValue;
  628. }
  629. void csProgressBar::Draw()
  630. {
  631. if( InterfaceUtils::IsHide())
  632. return;
  633. float fMaximalVal = m_params.fMaxValue;
  634. if( m_pHPObject.Ptr())
  635. {
  636. float maxHP = m_pHPObject.Ptr()->GetMaxHP();
  637. if( maxHP > 0.0f )
  638. {
  639. fMaximalVal = maxHP;
  640. m_fValue = m_pHPObject.Ptr()->GetHP();
  641. }
  642. }
  643. m_fPercent = ScaleToBorder(m_fValue/fMaximalVal);
  644. // FIX ME!!!!
  645. if( m_fPercent > 1.0f )
  646. m_fPercent = 1.0f;
  647. // Draw(1.0f,1.0f,fMaximalVal,1.0f);
  648. Draw(1.0f,1.0f,fMaximalVal,GetAlpha());
  649. if( m_effects&ShowBar )
  650. {
  651. if( m_showEffectTime > 0.0f )
  652. {
  653. float FinalScales[] = {0.1f,0.2f,0.4f};
  654. for( dword k = 0 ; k < sizeof(FinalScales)/sizeof(FinalScales[0]) ; k++ )
  655. {
  656. Draw(1.0f + FinalScales[k]*(1.0f - m_showEffectTime/MaxShowEffectTime),
  657. 1.0f + FinalScales[k]*(1.0f - m_showEffectTime/MaxShowEffectTime),
  658. // fMaximalVal,m_showEffectTime/MaxShowEffectTime);
  659. fMaximalVal,m_showEffectTime/MaxShowEffectTime*GetAlpha());
  660. }
  661. }
  662. }
  663. }
  664. void csProgressBar::Show(bool isShow)
  665. {
  666. // MissionObject ::Show(isShow);
  667. BaseGUIElement::Show(isShow);
  668. BaseGUIElement *parent = GetParent();
  669. long level = drawLevel;
  670. /* if( parent )
  671. level = parent->GetDrawLevel() + 100;*/
  672. DelUpdate(&csProgressBar::Work);
  673. if( IsShow())
  674. {
  675. if( GetAlpha() > 0.0f )
  676. {
  677. SetUpdate(&csProgressBar::Work,level + m_params.drawPriority);
  678. }
  679. if( m_params.doShowEffect && !EditMode_IsOn())
  680. {
  681. m_effects |= ShowBar;
  682. m_showEffectTime = MaxShowEffectTime;
  683. }
  684. }
  685. }
  686. void csProgressBar::SetMax(float val)
  687. {
  688. if( m_params.fMaxValue == val )
  689. return;
  690. m_params.fMaxValue = val;
  691. //LogicDebug("Change progress bar max to %3.2f", m_params.fMaxValue);
  692. if( m_fValue > m_params.fMaxValue )
  693. m_fValue = m_params.fMaxValue;
  694. m_fPrevValue = m_fValue;
  695. }
  696. void csProgressBar::SetPos(float val)
  697. {
  698. if( m_fValue == val )
  699. return;
  700. m_fValue = val;
  701. if( m_fValue < 0.0f )
  702. m_fValue = 0.0f;
  703. if( m_fValue > m_params.fMaxValue )
  704. m_fValue = m_params.fMaxValue;
  705. }
  706. //Обработчик команд для объекта
  707. void csProgressBar::Command(const char *id, dword numParams, const char **params)
  708. {
  709. m_fPrevValue = m_fValue;
  710. if( string::IsEmpty(id))
  711. return;
  712. if( string::IsEqual(id,"Set"))
  713. {
  714. if( numParams > 0 )
  715. {
  716. float fVal = (float)atoi(params[0]);
  717. SetPos(fVal);
  718. }
  719. return;
  720. }
  721. if( string::IsEqual(id,"Inc"))
  722. {
  723. if( numParams > 0 )
  724. {
  725. float fInc = (float)atoi(params[0]);
  726. m_fValue += fInc;
  727. }
  728. else
  729. {
  730. m_fValue += 1.0f;
  731. }
  732. if( m_fValue > m_params.fMaxValue )
  733. m_fValue = m_params.fMaxValue;
  734. return;
  735. }
  736. if( string::IsEqual(id,"Dec"))
  737. {
  738. if( numParams > 0 )
  739. {
  740. float fDec = (float)atoi(params[0]);
  741. m_fValue -= fDec;
  742. }
  743. else
  744. {
  745. m_fValue -= 1.0f;
  746. }
  747. if( m_fValue < 0.0f )
  748. m_fValue = 0.0f;
  749. return;
  750. }
  751. if( string::IsEqual(id,"Zero"))
  752. {
  753. LogicDebug("Zero progress bar");
  754. m_fValue = 0;
  755. return;
  756. }
  757. if( string::IsEqual(id,"Full"))
  758. {
  759. LogicDebug("Full progress bar");
  760. float fMaximalVal = m_params.fMaxValue;
  761. if( m_pHPObject.Ptr())
  762. {
  763. float maxHP = m_pHPObject.Ptr()->GetMaxHP();
  764. if( maxHP > 0.0f )
  765. {
  766. fMaximalVal = maxHP;
  767. m_fValue = m_pHPObject.Ptr()->GetHP();
  768. }
  769. }
  770. m_fValue = fMaximalVal;
  771. return;
  772. }
  773. if( string::IsEqual(id,"SetMax"))
  774. {
  775. if( numParams > 0 )
  776. {
  777. float fVal = (float)atoi(params[0]);
  778. SetMax(fVal);
  779. }
  780. return;
  781. }
  782. if( string::IsEqual(id,"SetHP"))
  783. {
  784. if( numParams > 0 )
  785. {
  786. m_fValue = (float)atoi(params[0]);
  787. //LogicDebug("Change progress bar HP to %3.2f", m_fValue);
  788. if( m_fValue > m_params.fMaxValue )
  789. m_fValue = m_params.fMaxValue;
  790. if( m_fValue < 0 )
  791. m_fValue = 0;
  792. }
  793. return;
  794. }
  795. if( string::IsEqual(id,"SetMO"))
  796. {
  797. if( numParams > 0 )
  798. {
  799. m_pHPObject.Reset();
  800. m_params.HPObjectStr = params[0];
  801. m_params.HPObject.Set(m_params.HPObjectStr.c_str());
  802. }
  803. return;
  804. }
  805. BaseGUIElement::Command(id,numParams,params);
  806. }
  807. float csProgressBar::ScaleToBorder(float hp)
  808. {
  809. static float out_hp = 1.0f;
  810. if (hp<=fMinBorder)
  811. {
  812. out_hp = 0.0f;
  813. }
  814. else
  815. if (hp>=fMaxBorder)
  816. {
  817. out_hp = 1.0f;
  818. }
  819. else
  820. {
  821. out_hp = (hp - fMinBorder)/(fMaxBorder - fMinBorder);
  822. }
  823. return out_hp;
  824. }
  825. static const char *g_comment =
  826. "Object for some events at some count\n"
  827. " \n"
  828. "Commands list:\n"
  829. "----------------------------------------\n"
  830. " Increase progress value\n"
  831. "----------------------------------------\n"
  832. " command: inc\n"
  833. " parm: number value (without param number = 1)\n"
  834. " \n"
  835. "----------------------------------------\n"
  836. " Decrease progress value\n"
  837. "----------------------------------------\n"
  838. " command: dec\n"
  839. " parm: number value (without param number = 1)\n"
  840. " \n"
  841. "----------------------------------------\n"
  842. " Zero progress value\n"
  843. "----------------------------------------\n"
  844. " command: zero\n"
  845. " \n"
  846. "----------------------------------------\n"
  847. " Full progress value\n"
  848. "----------------------------------------\n"
  849. " command: full\n"
  850. " \n"
  851. "----------------------------------------\n"
  852. " Set progress maximum\n"
  853. "----------------------------------------\n"
  854. " command: SetMax\n"
  855. " parm: number value\n"
  856. " \n"
  857. " ";
  858. MOP_BEGINLISTCG(csProgressBar, "ProgressBar", '1.00', /*100*/50, g_comment, "Interface")
  859. MOP_ENUMBEG("Layout")
  860. MOP_ENUMELEMENT("Left")
  861. MOP_ENUMELEMENT("Center")
  862. MOP_ENUMELEMENT("Right")
  863. MOP_ENUMEND
  864. MOP_ENUM("Layout", "Layout")
  865. MOP_STRING("Background Texture", "")
  866. MOP_STRING("Progress Texture", "")
  867. MOP_FLOATEX("X", 0.0f, -50.0f, 100.0f);
  868. MOP_FLOATEX("Y", 0.0f, -50.0f, 100.0f);
  869. MOP_FLOATEX("Width" , 50.0f, 0.1f, 100.0f);
  870. MOP_FLOATEX("Height", 25.0f, 0.1f, 100.0f);
  871. MOP_LONGEX("Max value", 10000, 0, 10000000000);
  872. MOP_STRING("Show HP from", "")
  873. MOP_FLOATEX("Min HP Border", 0, 0, 100);
  874. MOP_FLOATEX("Max HP Border", 100, 0, 100);
  875. MOP_FLOATEX("Start Bar", 25.0f, 0.0f, 100.0f);
  876. MOP_FLOATEX("End Bar", 85.0f, 0.0f, 100.0f);
  877. MOP_LONG("Draw priority", 0)
  878. MOP_ENUMBEG("ControlAlign")
  879. /* MOP_ENUMELEMENT(TOP_LEFT)
  880. MOP_ENUMELEMENT(BOTTOM_LEFT)
  881. MOP_ENUMELEMENT(TOP_RIGHT)
  882. MOP_ENUMELEMENT(BOTTOM_RIGHT)*/
  883. MOP_ENUMELEMENT("Top")
  884. MOP_ENUMELEMENT("Bottom")
  885. MOP_ENUMEND
  886. MOP_ENUM("ControlAlign", "Align")
  887. MOP_BOOL("Do show effect", true)
  888. MOP_BOOL("Show", true)
  889. MOP_FLOAT("AddDecEffectTime", 1.0f)
  890. MOP_FLOAT("ShowEffectTime" , 0.8f)
  891. MOP_BOOL("Circular", false)
  892. // MOP_BOOLC("Reverse" , false, "инвертирует направление указателя в круговом режиме")
  893. MOP_BOOLC("Reverse" , false, "инвертирует направление индикатора")
  894. MOP_BOOL("Vertical", false)
  895. MOP_BOOLC("Inverse", false, "зеркалит по вертикали индикатор в круговом режиме")
  896. MOP_FLOAT ("Alpha", 1.0f)
  897. MOP_STRING("Parent id", "")
  898. MOP_ENDLIST(csProgressBar)