GUIList.cpp 32 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883
  1. #include "GUIList.h"
  2. #include "GUIWidget.h"
  3. #include "GUIButton.h"
  4. #include "..\Utils\InterfaceUtils.h"
  5. #include "..\ProgressBar\csProgressBar.h"
  6. #include "BaseGUICursor.h"
  7. GUIList::GUIList(void) : lines(_FL_)
  8. {
  9. m_restart = false;
  10. drawLevel = ML_GUI2;
  11. curLine = -1;
  12. curItem = -1;
  13. befLine = -1;
  14. befItem = -1; maxItem = 0;
  15. scroll_x = 0.0f;
  16. scroll_y = 0.0f;
  17. maxWidth = 0;
  18. nativeShow = true;
  19. }
  20. GUIList::~GUIList(void)
  21. {
  22. }
  23. void GUIList::Restart()
  24. {
  25. Show(false);
  26. m_restart = true;
  27. ReCreate();
  28. }
  29. void GUIList::SkipMOPs(MOPReader & reader)
  30. {
  31. reader.Float(); // m_clipWidth
  32. reader.Float(); // m_clipHeight
  33. reader.Bool(); // m_useClipping
  34. reader.String().c_str(); // m_texture
  35. reader.Float(); // m_texAlpha
  36. drawPriority = reader.Long();
  37. for( int i = 0 ; i < 2 ; i++ )
  38. {
  39. reader.String().c_str(); // prog name
  40. }
  41. int ln = reader.Array();
  42. for( int i = 0 ; i < ln ; i++ )
  43. {
  44. Line &line = lines[i];
  45. int in = reader.Array();
  46. for( int j = 0 ; j < in ; j++ )
  47. {
  48. Item &item = line.items[j];
  49. reader.String().c_str(); // item name
  50. item.onFoc.Init(reader);
  51. item.onLea.Init(reader);
  52. item.onSel.Init(reader);
  53. }
  54. }
  55. if( ln )
  56. {
  57. curLine = 0;
  58. if( lines[curLine].items )
  59. {
  60. curItem = 0;
  61. // lines[curLine].items[curItem].onFoc.Activate(Mission(),false);
  62. }
  63. }
  64. else
  65. {
  66. curLine = -1;
  67. curItem = -1;
  68. }
  69. reader.Long(); // startLine
  70. reader.Long(); // startItem
  71. befLine = curLine;
  72. befItem = curItem; maxItem = curItem;
  73. reader.Float(); // itemWidth
  74. reader.Float(); // itemHeight
  75. reader.Bool(); // centered
  76. if( curLine >= 0 && curItem >= 0 && centered )
  77. {
  78. Rect r; GetRect(r,false);
  79. ScrollTo(
  80. 0.5f*(r.r - r.l - itemWidth),
  81. 0.5f*(r.b - r.t - itemHeight));
  82. }
  83. for( int i = 0 ; i < 4 ; i++ )
  84. {
  85. reader.String().c_str(); // butt name
  86. }
  87. reader.Float(); // btnWidth
  88. reader.Float(); // btnHeight
  89. BaseGUIElement::Activate(reader.Bool());
  90. // Show (reader.Bool());
  91. nativeShow = reader.Bool();
  92. // MissionObject::Show(nativeShow);
  93. m_alphaOriginal = GetNativeAlpha();
  94. m_fadeAlpha = 1.0f;
  95. m_clipX = GetX();
  96. m_clipY = GetY();
  97. m_state = Normal;
  98. // ResetItems();
  99. }
  100. void GUIList::ReadMOPs(MOPReader & reader)
  101. {
  102. m_clipWidth = reader.Float();
  103. m_clipHeight = reader.Float();
  104. SizeTo(m_clipWidth,m_clipHeight);
  105. m_useClipping = reader.Bool();
  106. SetClipping(m_useClipping);
  107. m_texture = reader.String().c_str();
  108. m_texAlpha = reader.Float();
  109. drawPriority = reader.Long();
  110. m_quadRender.SetTexture(m_texture);
  111. ReleaseItems();
  112. for( int i = 0 ; i < 2 ; i++ )
  113. {
  114. Progress &prog = progs[i];
  115. prog.name = reader.String();
  116. if( FindObject(prog.name,prog.p))
  117. {
  118. if( !prog.p.Ptr()->Is(InterfaceUtils::GetPbarId()))
  119. prog.p.Reset();
  120. }
  121. }
  122. lines.DelAll();
  123. maxWidth = 0;
  124. int ln = reader.Array();
  125. for( int i = 0 ; i < ln ; i++ )
  126. {
  127. Line &line = lines[lines.Add()];
  128. int in = reader.Array();
  129. for( int j = 0 ; j < in ; j++ )
  130. {
  131. Item &item = line.items[line.items.Add()];
  132. item.name = reader.String();
  133. if( FindObject(item.name,item.p))
  134. {
  135. if( !item.p.Ptr()->Is(InterfaceUtils::GetBaseId()))
  136. item.p.Reset();
  137. }
  138. BaseGUIElement *p = (BaseGUIElement *)item.p.Ptr();
  139. if( p )
  140. {
  141. p->data_a = i;
  142. p->data_b = j;
  143. }
  144. item.onFoc.Init(reader);
  145. item.onLea.Init(reader);
  146. item.onSel.Init(reader);
  147. }
  148. if( maxWidth < in )
  149. maxWidth = in;
  150. }
  151. if( ln )
  152. {
  153. curLine = 0;
  154. if( lines[curLine].items )
  155. {
  156. curItem = 0;
  157. // lines[curLine].items[curItem].onFoc.Activate(Mission(),false);
  158. }
  159. }
  160. else
  161. {
  162. curLine = -1;
  163. curItem = -1;
  164. }
  165. startLine = reader.Long();
  166. startItem = reader.Long();
  167. befLine = curLine;
  168. befItem = curItem; maxItem = curItem;
  169. itemWidth = reader.Float()*m_aspect;
  170. itemHeight = reader.Float();
  171. centered = reader.Bool();
  172. if( curLine >= 0 && curItem >= 0 && centered )
  173. {
  174. Rect r; GetRect(r,false);
  175. ScrollTo(
  176. 0.5f*(r.r - r.l - itemWidth),
  177. 0.5f*(r.b - r.t - itemHeight));
  178. }
  179. for( int i = 0 ; i < 4 ; i++ )
  180. {
  181. Button &butt = butts[i];
  182. butt.name = reader.String();
  183. if( FindObject(butt.name,butt.p))
  184. {
  185. if( !butt.p.Ptr()->Is(InterfaceUtils::GetButtonId()))
  186. butt.p.Reset();
  187. }
  188. }
  189. btnWidth = reader.Float()*m_aspect;
  190. btnHeight = reader.Float();
  191. BaseGUIElement::Activate(reader.Bool());
  192. // Show (reader.Bool());
  193. nativeShow = reader.Bool();
  194. // MissionObject::Show(nativeShow);
  195. m_alphaOriginal = GetNativeAlpha();
  196. m_fadeAlpha = 1.0f;
  197. m_clipX = GetX();
  198. m_clipY = GetY();
  199. m_state = Normal;
  200. m_cursor = null;
  201. ResetItems();
  202. }
  203. bool GUIList::Create (MOPReader &reader)
  204. {
  205. if( m_restart )
  206. {
  207. RestartObject(reader);
  208. }
  209. else
  210. {
  211. EditMode_Update(reader);
  212. }
  213. return true;
  214. }
  215. void _cdecl GUIList::InitFunc(float, long)
  216. {
  217. if( m_restart )
  218. {
  219. m_restart = false;
  220. // ;
  221. ResetItems();
  222. }
  223. else
  224. {
  225. BaseGUIElement *parent = GetParent();
  226. if( BaseGUIElement *newParent = FindParent())
  227. {
  228. newParent->Register(this);
  229. }
  230. else
  231. {
  232. if( parent )
  233. parent->UnRegister(this);
  234. }
  235. // Show(IsShow());
  236. // BaseGUIElement::Show(nativeShow);
  237. // Show(nativeShow);
  238. if( EditMode_IsOn())
  239. DelUpdate(&GUIList::Work);
  240. }
  241. BaseGUIElement::Show(nativeShow);
  242. if( IsShow())
  243. {
  244. SetUpdate(&GUIList::Work,drawLevel + drawPriority);
  245. // SetUpdate(&GUIList::Draw,drawLevel + drawPriority + 2000);
  246. }
  247. // if( IsActive() && IsShow())
  248. {
  249. if( curLine >= 0 && curItem >= 0 )
  250. {
  251. if( curLine <= 0 )
  252. {
  253. if( startLine >= 0 && startLine < lines )
  254. curLine = startLine;
  255. befLine = 0;
  256. }
  257. else
  258. befLine = curLine;
  259. if( curItem <= 0 )
  260. {
  261. if( startItem >= 0 && startItem < lines[curLine].items )
  262. {
  263. maxItem = curItem = startItem;
  264. }
  265. befItem = 0;
  266. }
  267. else
  268. befItem = curItem;
  269. Item &item = lines[curLine].items[curItem];
  270. BaseGUIElement *p = (BaseGUIElement *)item.p.Ptr();
  271. if( p && p->Is(InterfaceUtils::GetButtonId()))
  272. p->SetFocus();
  273. else
  274. {
  275. LogicDebug("Item [%d,%d]: getFocus trugger",curLine,curItem);
  276. item.onFoc.Activate(Mission(),false);
  277. }
  278. // befLine = 0;
  279. // befItem = 0;
  280. UpdatePos(true);
  281. }
  282. }
  283. DelUpdate(&GUIList::InitFunc);
  284. }
  285. bool GUIList::RestartObject(MOPReader &reader)
  286. {
  287. BaseGUIElement::SkipMOPs(reader);
  288. SkipMOPs(reader);
  289. NotifyChildren(ParentChanged);
  290. SetUpdate(&GUIList::InitFunc,ML_GUI5 - 1);
  291. return true;
  292. }
  293. bool GUIList::EditMode_Update(MOPReader &reader)
  294. {
  295. BaseGUIElement::EditMode_Update(reader);
  296. ReadMOPs (reader);
  297. NotifyChildren(ParentChanged);
  298. SetUpdate(&GUIList::InitFunc,ML_GUI5 - 1);
  299. return true;
  300. }
  301. inline float cubic_curve(float t)
  302. {
  303. float t2 = t*t; return 3*t2 - 2*t2*t;
  304. }
  305. #ifdef not_def
  306. void _cdecl GUIList::Work(float deltaTime, long)
  307. {
  308. if( EditMode_IsOn())
  309. {
  310. bool reset = false;
  311. for( int i = 0 ; i < lines ; i++ )
  312. {
  313. Line &line = lines[i];
  314. for( int j = 0 ; j < line.items ; j++ )
  315. {
  316. Item &item = line.items[j];
  317. if(!item.p || !ValidatePointer(item.p,item.hash))
  318. {
  319. item.p = (BaseGUIElement *)FindObject(item.name);
  320. if( item.p )
  321. {
  322. ValidatePointer(item.p,item.hash);
  323. reset = true;
  324. }
  325. }
  326. else
  327. {
  328. if( strcmp(item.name,item.p->GetObjectID().c_str()))
  329. {
  330. item.p->Restrict(preserveNone);
  331. item.p->ReCreate();
  332. item.p = (BaseGUIElement *)FindObject(item.name);
  333. }
  334. }
  335. if( item.p )
  336. {
  337. item.p->data_a = i;
  338. item.p->data_b = j;
  339. }
  340. }
  341. }
  342. // if( reset )
  343. // ResetItems();
  344. for( int i = 0 ; i < 2 ; i++ )
  345. {
  346. Progress &prog = progs[i];
  347. if(!prog.p || !ValidatePointer(prog.p,prog.hash))
  348. {
  349. prog.p = (csProgressBar *)FindObject(prog.name);
  350. if( prog.p )
  351. {
  352. ValidatePointer(prog.p,prog.hash);
  353. reset = true;
  354. }
  355. }
  356. else
  357. {
  358. if( strcmp(prog.name,prog.p->GetObjectID().c_str()))
  359. {
  360. prog.p->Restrict(preserveNone);
  361. prog.p->ReCreate();
  362. prog.p = (csProgressBar *)FindObject(prog.name);
  363. }
  364. }
  365. }
  366. for( int i = 0 ; i < 4 ; i++ )
  367. {
  368. Button &butt = butts[i];
  369. if(!butt.p || !ValidatePointer(butt.p,butt.hash))
  370. {
  371. butt.p = (GUIButton *)FindObject(butt.name);
  372. if( butt.p )
  373. {
  374. ValidatePointer(butt.p,butt.hash);
  375. reset = true;
  376. }
  377. }
  378. else
  379. {
  380. if( strcmp(butt.name,butt.p->GetObjectID().c_str()))
  381. {
  382. butt.p->Restrict(preserveNone);
  383. butt.p->ReCreate();
  384. butt.p = (GUIButton *)FindObject(butt.name);
  385. }
  386. }
  387. }
  388. if( reset )
  389. ResetItems();
  390. }
  391. Rect r; GetRect(r,false);
  392. float x = r.l; float width = r.r - r.l;
  393. float y = r.t; float height = r.b - r.t;
  394. if( m_texture[0] )
  395. {
  396. m_quadRender.DrawQuad(x,y,width,height,0.0f,0.0f,
  397. 1.0f,1.0f,10.0f + m_alphaOriginal*m_texAlpha);
  398. }
  399. if( EditMode_IsOn() && m_useClipping && !m_texture[0] )
  400. {
  401. m_helperQuad.DrawQuad(x,y,width,height,0.0f,0.0f,
  402. 0.0f,0.0f,10.3f);
  403. }
  404. if( GetFadeState() == BaseGUIElement::FadingIn )
  405. {
  406. m_fadeAlpha += (deltaTime/m_fadeTime)*m_alphaOriginal;
  407. if( m_fadeAlpha > m_alphaOriginal )
  408. {
  409. m_fadeAlpha = m_alphaOriginal;
  410. SetFadeState(FadingFinished);
  411. }
  412. }
  413. else
  414. if( GetFadeState() == BaseGUIElement::FadingOut )
  415. {
  416. m_fadeAlpha -= (deltaTime/m_fadeTime)*m_alphaOriginal;
  417. if( m_fadeAlpha < 0 )
  418. {
  419. m_fadeAlpha = 0.0f;
  420. SetFadeState(FadingFinished);
  421. Show(false);
  422. }
  423. }
  424. SetAlpha(m_fadeAlpha);
  425. const float AccelerationFactor = 1.0f;
  426. if( m_state != Normal )
  427. {
  428. m_curScrollTime += deltaTime;
  429. if( m_curScrollTime > m_scrollTime )
  430. {
  431. m_curScrollTime = m_scrollTime;
  432. m_state = Normal;
  433. }
  434. float k = m_curScrollTime/m_scrollTime;
  435. float x = Lerp(m_from.x,m_to.x,k);
  436. float y = Lerp(m_from.y,m_to.y,k);
  437. ScrollTo(x,y);
  438. }
  439. }
  440. #endif
  441. void _cdecl GUIList::Work(float deltaTime, long level)
  442. {
  443. if( EditMode_IsOn() && !EditMode_IsVisible())
  444. return;
  445. Draw();
  446. Update(deltaTime);
  447. Draw(deltaTime,level);
  448. }
  449. void GUIList::Update(float deltaTime)
  450. {
  451. if( EditMode_IsOn())
  452. {
  453. bool reset = false;
  454. for( int i = 0 ; i < lines ; i++ )
  455. {
  456. Line &line = lines[i];
  457. for( int j = 0 ; j < line.items ; j++ )
  458. {
  459. Item &item = line.items[j];
  460. if(!item.p.Validate())
  461. {
  462. if( FindObject(item.name,item.p))
  463. {
  464. if( item.p.Ptr()->Is(InterfaceUtils::GetBaseId()))
  465. {
  466. reset = true;
  467. }
  468. else
  469. item.p.Reset();
  470. }
  471. }
  472. else
  473. {
  474. BaseGUIElement *p = (BaseGUIElement *)item.p.Ptr();
  475. if( item.name != p->GetObjectID() )
  476. {
  477. p->Restrict(preserveNone);
  478. p->ReCreate();
  479. if( FindObject(item.name,item.p))
  480. {
  481. if( !item.p.Ptr()->Is(InterfaceUtils::GetBaseId()))
  482. item.p.Reset();
  483. }
  484. }
  485. }
  486. BaseGUIElement *p = (BaseGUIElement *)item.p.Ptr();
  487. if( p )
  488. {
  489. p->data_a = i;
  490. p->data_b = j;
  491. }
  492. }
  493. }
  494. // if( reset )
  495. // ResetItems();
  496. for( int i = 0 ; i < 2 ; i++ )
  497. {
  498. Progress &prog = progs[i];
  499. if(!prog.p.Validate())
  500. {
  501. if( FindObject(prog.name,prog.p))
  502. {
  503. if( prog.p.Ptr()->Is(InterfaceUtils::GetPbarId()))
  504. {
  505. reset = true;
  506. }
  507. else
  508. prog.p.Reset();
  509. }
  510. }
  511. else
  512. {
  513. csProgressBar *p = (csProgressBar *)prog.p.Ptr();
  514. if( prog.name != p->GetObjectID() )
  515. {
  516. p->Restrict(preserveNone);
  517. p->ReCreate();
  518. if( FindObject(prog.name,prog.p))
  519. {
  520. if( !prog.p.Ptr()->Is(InterfaceUtils::GetPbarId()))
  521. prog.p.Reset();
  522. }
  523. }
  524. }
  525. }
  526. for( int i = 0 ; i < 4 ; i++ )
  527. {
  528. Button &butt = butts[i];
  529. if(!butt.p.Validate())
  530. {
  531. if( FindObject(butt.name,butt.p))
  532. {
  533. if( butt.p.Ptr()->Is(InterfaceUtils::GetButtonId()))
  534. reset = true;
  535. else
  536. butt.p.Reset();
  537. }
  538. }
  539. else
  540. {
  541. GUIButton *p = (GUIButton *)butt.p.Ptr();
  542. if( butt.name != p->GetObjectID() )
  543. {
  544. p->Restrict(preserveNone);
  545. p->ReCreate();
  546. if( FindObject(butt.name,butt.p))
  547. {
  548. if( !butt.p.Ptr()->Is(InterfaceUtils::GetButtonId()))
  549. butt.p.Reset();
  550. }
  551. }
  552. }
  553. }
  554. if( reset )
  555. ResetItems();
  556. }
  557. if( GetFadeState() == BaseGUIElement::FadingIn )
  558. {
  559. m_fade -= deltaTime;
  560. if( m_fade < 0.0f )
  561. {
  562. SetFadeState(FadingFinished);
  563. m_fade = 0.0f;
  564. }
  565. m_fadeAlpha = 1.0f - m_fade/m_fadeTime;
  566. SetAlpha(m_fadeAlpha*m_alphaOriginal);
  567. }
  568. else
  569. if( GetFadeState() == BaseGUIElement::FadingOut )
  570. {
  571. m_fade -= deltaTime;
  572. if( m_fade < 0.0f )
  573. {
  574. SetFadeState(FadingFinished); Show(false);
  575. m_fade = 0.0f;
  576. }
  577. m_fadeAlpha = m_fade/m_fadeTime;
  578. SetAlpha(m_fadeAlpha*m_alphaOriginal);
  579. }
  580. // SetAlpha(m_fadeAlpha);
  581. const float AccelerationFactor = 1.0f;
  582. if( m_state != Normal )
  583. {
  584. m_curScrollTime += deltaTime;
  585. if( m_curScrollTime > m_scrollTime )
  586. {
  587. m_curScrollTime = m_scrollTime;
  588. m_state = Normal;
  589. }
  590. float k = m_curScrollTime/m_scrollTime;
  591. float x = Lerp(m_from.x,m_to.x,k);
  592. float y = Lerp(m_from.y,m_to.y,k);
  593. ScrollTo(x,y);
  594. }
  595. }
  596. void GUIList::Draw()
  597. {
  598. if( InterfaceUtils::IsHide())
  599. return;
  600. Rect r; GetRect(r,false);
  601. float x = r.l; float width = r.r - r.l;
  602. float y = r.t; float height = r.b - r.t;
  603. if( m_texture[0] )
  604. {
  605. m_quadRender.DrawQuad(x,y,width,height,0.0f,0.0f,
  606. 1.0f,1.0f,10.0f + GetAlpha()*m_texAlpha);
  607. }
  608. if( EditMode_IsOn() && m_useClipping && !m_texture[0] )
  609. {
  610. m_helperQuad.DrawQuad(x,y,width,height,0.0f,0.0f,
  611. 0.0f,0.0f,10.3f);
  612. }
  613. }
  614. void _cdecl GUIList::Draw(float deltaTime, long)
  615. {
  616. if( EditMode_IsOn())
  617. return;
  618. if( curLine >= 0 && curItem >= 0 )
  619. {
  620. const Item &item = lines[curLine].items[curItem];
  621. BaseGUIElement *p = (BaseGUIElement *)item.p.Ptr();
  622. if( p )
  623. {
  624. bool b = p->Is(InterfaceUtils::GetButtonId());
  625. if( m_state != Normal )
  626. {
  627. float a = m_curScrollTime/m_scrollTime;
  628. if( !b )
  629. p->SetAlpha(0.6f + a*0.4f);
  630. /* if( befLine >= 0 && befItem >= 0 )
  631. {
  632. const Item &prev = lines[befLine].items[befItem];
  633. if( prev.p && !prev.p->Is(InterfaceUtils::GetButtonId()))
  634. prev.p->SetAlpha(1.0f - a*0.4f);
  635. }*/
  636. }
  637. else
  638. {
  639. if( !b )
  640. p->SetAlpha(1.0f);
  641. }
  642. }
  643. if( m_state != Normal )
  644. {
  645. float a = m_curScrollTime/m_scrollTime;
  646. if( befLine >= 0 && befItem >= 0 )
  647. {
  648. const Item &prev = lines[befLine].items[befItem];
  649. BaseGUIElement *p = (BaseGUIElement *)prev.p.Ptr();
  650. if( p && !p->Is(InterfaceUtils::GetButtonId()))
  651. p->SetAlpha(1.0f - a*0.4f);
  652. }
  653. }
  654. }
  655. if( Controls().GetControlStateType("Menu_Select") == CST_ACTIVATED )
  656. {
  657. if( curLine >= 0 && curItem >= 0 )
  658. {
  659. Item &item = lines[curLine].items[curItem];
  660. BaseGUIElement *p = (BaseGUIElement *)item.p.Ptr();
  661. if( p && p->Is(InterfaceUtils::GetButtonId()))
  662. ;
  663. else
  664. {
  665. LogicDebug("Item [%d,%d]: select trugger",curLine,curItem);
  666. item.onSel.Activate(Mission(),false);
  667. }
  668. }
  669. }
  670. //// обработка мыши ////
  671. if( EditMode_IsOn())
  672. return;
  673. if( !IsActive())
  674. return;
  675. if( m_state != Normal )
  676. return;
  677. if( !m_cursor )
  678. {
  679. MOSafePointer sp;
  680. FindObject(InterfaceUtils::GetCursorName(),sp);
  681. m_cursor = (BaseGUICursor *)sp.Ptr();
  682. }
  683. if( !m_cursor || m_cursor->IsHided())
  684. return;
  685. float x,y; m_cursor->GetPosition(x,y);
  686. float _x = x;
  687. float _y = y;
  688. Rect rect; GetClipRect(rect);
  689. x *= 100;
  690. y *= 100;
  691. if( !PointInRect(x,y,rect))
  692. return;
  693. x -= GetX(false);
  694. y -= GetY(false);
  695. float sx = 0.0f;
  696. float sy = 0.0f;
  697. /* Rect r; GetRect(r);
  698. float width = r.r - r.l;
  699. float height = r.b - r.t;
  700. if( centered )
  701. {
  702. // sx = -0.5f*(width - itemWidth );
  703. // sy = -0.5f*(height - itemHeight);
  704. }*/
  705. int i = int((y - GetOffsetY() - sy)/itemHeight);
  706. int j = int((x - GetOffsetX() - sx)/itemWidth );
  707. if( i >= 0 && i < lines )
  708. {
  709. Line &line = lines[i];
  710. if( j >= 0 && j < line.items )
  711. {
  712. bool en = true; BaseGUIElement *p = (BaseGUIElement *)lines[i].items[j].p.Ptr();
  713. if( p && p->Is(InterfaceUtils::GetButtonId()))
  714. {
  715. Rect r; p->GetRect(r);
  716. if( PointInRect(_x*100.0f,_y*100.0f,r))
  717. en = false;
  718. }
  719. if( en )
  720. {
  721. if( i != curLine || j != curItem || scroll_x != 0.0f || scroll_y != 0.0f )
  722. {
  723. if( Controls().GetControlStateType("LeftMouseButton") == CST_ACTIVATED )
  724. {
  725. befLine = curLine;
  726. curLine = i;
  727. befItem = curItem;
  728. curItem = j;
  729. maxItem = curItem;
  730. UpdatePos();
  731. }
  732. }
  733. if( Controls().GetControlStateType("LeftMouseDbl") == CST_ACTIVATED )
  734. {
  735. Item &item = lines[i].items[j];
  736. if( item.p.Ptr()->Is(InterfaceUtils::GetButtonId()))
  737. ;
  738. else
  739. {
  740. LogicDebug("Item [%d,%d]: select trugger",i,j);
  741. item.onSel.Activate(Mission(),false);
  742. }
  743. }
  744. }
  745. }
  746. }
  747. }
  748. void GUIList::ReleaseItems()
  749. {
  750. for( int i = 0 ; i < lines ; i++ )
  751. {
  752. Line &line = lines[i];
  753. for( int j = 0 ; j < line.items ; j++ )
  754. {
  755. Item &item = line.items[j];
  756. BaseGUIElement *p = (BaseGUIElement *)item.p.Ptr();
  757. if( p )
  758. {
  759. p->Restrict(preserveNone);
  760. p->ReCreate();
  761. }
  762. }
  763. }
  764. UnRegisterAll();
  765. for( int i = 0 ; i < 2 ; i++ )
  766. {
  767. Progress &prog = progs[i];
  768. csProgressBar *p = (csProgressBar *)prog.p.Ptr();
  769. if( p )
  770. {
  771. p->Restrict(preserveNone);
  772. p->ReCreate();
  773. }
  774. }
  775. for( int i = 0 ; i < 4 ; i++ )
  776. {
  777. Button &butt = butts[i];
  778. GUIButton *p = (GUIButton *)butt.p.Ptr();
  779. if( p )
  780. {
  781. p->Restrict(preserveNone);
  782. p->ReCreate();
  783. }
  784. }
  785. }
  786. void GUIList::ResetItems()
  787. {
  788. UnRegisterAll();
  789. float y = 0.0f;
  790. for( int i = 0 ; i < lines ; i++ )
  791. {
  792. Line &line = lines[i];
  793. float x = 0.0f;
  794. for( int j = 0 ; j < line.items ; j++ )
  795. {
  796. Item &item = line.items[j];
  797. BaseGUIElement *p = (BaseGUIElement *)item.p.Ptr();
  798. if( p )
  799. {
  800. p->SetParent(GetObjectID());
  801. if( p->Is(InterfaceUtils::GetButtonId()))
  802. {
  803. p->MoveTo(
  804. x + (itemWidth - p->GetWidth ())*0.5f,
  805. y + (itemHeight - p->GetHeight())*0.5f);
  806. }
  807. else
  808. {
  809. p->MoveTo(x,y);
  810. p->SizeTo(itemWidth/m_aspect,itemHeight);
  811. p->SetAlpha(0.6f);
  812. if( p->Is(InterfaceUtils::GetWidgetId()))
  813. {
  814. ((GUIWidget *)p)->SetAlphaOriginal(0.6f);
  815. }
  816. }
  817. p->SetShiftAspect(false);
  818. p->SetWidthAspect(false);
  819. p->SetLayout(OnLeft);
  820. p->Restrict(preservePos|preserveSize|preserveParent|preserveLayout);
  821. Register(p);
  822. }
  823. x += itemWidth/m_aspect;
  824. }
  825. y += itemHeight;
  826. }
  827. Rect r; GetRect(r,false);
  828. float x = r.l;
  829. y = r.t;
  830. float w = r.r - r.l;
  831. float h = r.b - r.t;
  832. float bw = btnWidth;
  833. float bh = btnHeight;
  834. for( int i = 0 ; i < 2 ; i++ )
  835. {
  836. Progress &prog = progs[i];
  837. csProgressBar *p = (csProgressBar *)prog.p.Ptr();
  838. if( p )
  839. {
  840. p->SetParent(ConstString());
  841. float px,py,pw,ph; p->GetNatRect(px,py,pw,ph);
  842. switch( i )
  843. {
  844. case 0:
  845. {
  846. float off = px*m_aspect;
  847. p->SizeTo(
  848. w - (bw + off)*2,
  849. ph);
  850. p->MoveTo(
  851. (x + bw + off)/m_aspect,
  852. y + h + (bh - ph)*0.5f);
  853. p->SetMax((float)0);
  854. p->SetPos((float)0);
  855. } break;
  856. case 1:
  857. {
  858. if( lines.Size() < 2 )
  859. {
  860. p->SizeTo( 0.0f, 0.0f);
  861. p->MoveTo(100.0f,100.0f);
  862. }
  863. else
  864. {
  865. p->SizeTo(
  866. pw*m_aspect,
  867. h - (bh + py)*2);
  868. p->MoveTo(
  869. (x + w + (bw - pw)*0.5f)/m_aspect,
  870. y + bh + py);
  871. }
  872. p->SetMax((float)(lines.Size() - 1));
  873. p->SetPos((float)(curLine));
  874. } break;
  875. }
  876. p->SetLayout(OnLeft);
  877. p->Restrict(preservePos|preserveSize|preserveParent);
  878. }
  879. }
  880. for( int i = 0 ; i < 4 ; i++ )
  881. {
  882. Button &butt = butts[i];
  883. GUIButton *p = (GUIButton *)butt.p.Ptr();
  884. if( p )
  885. {
  886. p->SetParent(ConstString());
  887. switch( i )
  888. {
  889. case 0:
  890. if( lines.Size() < 2 )
  891. p->MoveTo(100.0f,100.0f);
  892. else
  893. p->MoveTo((x + w)/m_aspect,y);
  894. break;
  895. case 1:
  896. if( lines.Size() < 2 )
  897. p->MoveTo(100.0f,100.0f);
  898. else
  899. p->MoveTo((x + w)/m_aspect,y + h - bh);
  900. break;
  901. case 2:
  902. if( lines.Size() < 2 && !progs[0].p.Ptr())
  903. p->MoveTo(
  904. (x - bw)/m_aspect,
  905. y + (h - bh)*0.5f);
  906. else
  907. p->MoveTo(x/m_aspect,y + h);
  908. break;
  909. case 3:
  910. if( lines.Size() < 2 && !progs[0].p.Ptr())
  911. p->MoveTo(
  912. (x + w)/m_aspect,
  913. y + (h - bh)*0.5f);
  914. else
  915. p->MoveTo((x + w - bw)/m_aspect,y + h);
  916. break;
  917. }
  918. p->SizeTo(btnWidth/m_aspect,btnHeight);
  919. p->SetLayout(OnLeft);
  920. p->Restrict(preservePos|preserveSize|preserveParent);
  921. }
  922. }
  923. }
  924. void GUIList::Show(bool isShow)
  925. {
  926. bool sh = IsShow();
  927. BaseGUIElement::Show(isShow);
  928. DelUpdate(&GUIList::Work);
  929. // DelUpdate(&GUIList::Draw);
  930. if( IsShow())
  931. {
  932. // SetUpdate(&GUIList::Work,drawLevel);
  933. // SetUpdate(&GUIList::Draw,drawLevel + 2000);
  934. // BaseGUIElement *parent = GetParent();
  935. long level = drawLevel;
  936. /* if( parent )
  937. level = parent->GetDrawLevel() + 100;*/
  938. if( GetAlpha() > 0.0f )
  939. {
  940. SetUpdate(&GUIList::Work,level + drawPriority);
  941. // SetUpdate(&GUIList::Draw,level + drawPriority + 2000);
  942. }
  943. }
  944. if( !IsActive())
  945. return;
  946. if( isShow != sh )
  947. {
  948. if( lines > 0 && curLine >= 0 && curLine < lines )
  949. {
  950. if( lines[curLine].items > 0 && curItem >= 0 && curItem < lines[curLine].items )
  951. {
  952. if( isShow )
  953. {
  954. LogicDebug("Item [%d,%d]: getFocus trugger",curLine,curItem);
  955. lines[curLine].items[curItem].onFoc.Activate(Mission(),false);
  956. }
  957. else
  958. {
  959. LogicDebug("Item [%d,%d]: losFocus trugger",curLine,curItem);
  960. lines[curLine].items[curItem].onLea.Activate(Mission(),false);
  961. }
  962. }
  963. }
  964. }
  965. }
  966. void GUIList::Activate(bool isActive)
  967. {
  968. bool act = IsActive();
  969. BaseGUIElement::Activate(isActive);
  970. if( !IsShow())
  971. return;
  972. if( isActive != act )
  973. {
  974. if( lines > 0 && curLine >= 0 && curLine < lines )
  975. {
  976. if( lines[curLine].items > 0 && curItem >= 0 && curItem < lines[curLine].items )
  977. {
  978. if( isActive )
  979. {
  980. LogicDebug("Item [%d,%d]: getFocus trugger",curLine,curItem);
  981. lines[curLine].items[curItem].onFoc.Activate(Mission(),false);
  982. }
  983. else
  984. {
  985. LogicDebug("Item [%d,%d]: losFocus trugger",curLine,curItem);
  986. lines[curLine].items[curItem].onLea.Activate(Mission(),false);
  987. }
  988. }
  989. }
  990. }
  991. }
  992. void GUIList::ScrollHor(float dx)
  993. {
  994. m_from.x = GetOffsetX();
  995. m_from.y = GetOffsetY();
  996. m_state = HScrolling;
  997. float k = fabsf(dx)/itemWidth;
  998. if( k == 0.0f )
  999. k = 0.5f;
  1000. m_scrollLength = dx;
  1001. m_scrollTime = 0.3f*k;
  1002. m_curScrollTime = 0.0f;
  1003. m_to = m_from;
  1004. m_to.x += m_scrollLength;
  1005. m_rect = GetFullRect(); Rect r; GetRect(r,false);
  1006. float width = r.r - r.l;
  1007. float height = r.b - r.t;
  1008. if( centered )
  1009. {
  1010. float sx = 0.5f*(width - itemWidth);
  1011. float sy = 0.5f*(height - itemHeight);
  1012. m_rect.l -= sx;
  1013. m_rect.r += sx;
  1014. m_rect.t -= sy;
  1015. m_rect.b += sy;
  1016. }
  1017. if( m_to.x > -m_rect.l )
  1018. m_to.x = -m_rect.l;
  1019. if( m_to.x < -m_rect.r + width )
  1020. m_to.x = -m_rect.r + width;
  1021. csProgressBar *p = (csProgressBar *)progs[0].p.Ptr();
  1022. if( p )
  1023. {
  1024. p->SetMax((float)(lines[curLine].items.Size() - 1));
  1025. p->SetPos((float)(curItem));
  1026. }
  1027. }
  1028. void GUIList::ScrollVer(float dy)
  1029. {
  1030. if( dy == 0.0f )
  1031. {
  1032. csProgressBar *p = (csProgressBar *)progs[1].p.Ptr();
  1033. if( p )
  1034. {
  1035. p->SetMax((float)(lines.Size() - 1));
  1036. p->SetPos((float)(curLine));
  1037. }
  1038. return;
  1039. }
  1040. m_from.x = GetOffsetX();
  1041. m_from.y = GetOffsetY();
  1042. m_state = VScrolling;
  1043. float k = fabsf(dy)/itemHeight;
  1044. if( k == 0.0f )
  1045. k = 0.5f;
  1046. m_scrollLength = dy;
  1047. float time = 0.3f*k;
  1048. if( m_scrollTime < time )
  1049. m_scrollTime = time;
  1050. m_to.y += m_scrollLength;
  1051. m_rect = GetFullRect();
  1052. // ;
  1053. m_rect.b = lines.Size()*itemHeight;
  1054. Rect r; GetRect(r,false);
  1055. float width = r.r - r.l;
  1056. float height = r.b - r.t;
  1057. if( centered )
  1058. {
  1059. float sx = 0.5f*(width - itemWidth);
  1060. float sy = 0.5f*(height - itemHeight);
  1061. m_rect.l -= sx;
  1062. m_rect.r += sx;
  1063. m_rect.t -= sy;
  1064. m_rect.b += sy;
  1065. }
  1066. if( m_to.y > -m_rect.t )
  1067. m_to.y = -m_rect.t;
  1068. if( m_to.y < -m_rect.b + height )
  1069. m_to.y = -m_rect.b + height;
  1070. csProgressBar *p = (csProgressBar *)progs[1].p.Ptr();
  1071. if( p )
  1072. {
  1073. p->SetMax((float)(lines.Size() - 1));
  1074. p->SetPos((float)(curLine));
  1075. }
  1076. }
  1077. void GUIList::UpdatePos(bool init)
  1078. {
  1079. Rect r; GetRect(r);
  1080. float px = r.l + curItem*itemWidth;
  1081. float py = r.t + curLine*itemHeight;
  1082. float rx = GetX(false);
  1083. float ry = GetY(false);
  1084. float dx = 0.0f;
  1085. float dy = 0.0f;
  1086. float width = r.r - r.l;
  1087. float height = r.b - r.t;
  1088. if( centered )
  1089. {
  1090. dx = (befItem - curItem)*itemWidth;
  1091. dy = (befLine - curLine)*itemHeight;
  1092. dx += scroll_x;
  1093. dy += scroll_y;
  1094. scroll_x = 0.0f;
  1095. scroll_y = 0.0f;
  1096. }
  1097. else
  1098. {
  1099. if( px < rx )
  1100. {
  1101. dx = rx - px;
  1102. }
  1103. else
  1104. if( px + itemWidth > rx + width)
  1105. {
  1106. dx = rx + width - (px + itemWidth);
  1107. }
  1108. if( py < ry )
  1109. {
  1110. dy = ry - py;
  1111. }
  1112. else
  1113. if( py + itemHeight > ry + height)
  1114. {
  1115. dy = ry + height - (py + itemHeight);
  1116. }
  1117. }
  1118. if( init )
  1119. {
  1120. Scroll(dx,dy);
  1121. csProgressBar *p0 = (csProgressBar *)progs[0].p.Ptr();
  1122. if( p0 )
  1123. {
  1124. p0->SetMax((float)(lines[curLine].items.Size() - 1));
  1125. p0->SetPos((float)(curItem));
  1126. }
  1127. csProgressBar *p1 = (csProgressBar *)progs[1].p.Ptr();
  1128. if( p1 )
  1129. {
  1130. p1->SetMax((float)(lines.Size() - 1));
  1131. p1->SetPos((float)(curLine));
  1132. }
  1133. }
  1134. else
  1135. {
  1136. ScrollHor(dx);
  1137. ScrollVer(dy);
  1138. if( curLine != befLine ||
  1139. curItem != befItem )
  1140. {
  1141. if( befLine >= 0 && befItem >= 0 )
  1142. {
  1143. Item &prev = lines[befLine].items[befItem];
  1144. // ;
  1145. SetElementInFocus(this);
  1146. BaseGUIElement *p = (BaseGUIElement *)prev.p.Ptr();
  1147. if( p && p->Is(InterfaceUtils::GetButtonId()))
  1148. {
  1149. // if( GetElementInFocus() == prev.p )
  1150. // SetElementInFocus(this);
  1151. }
  1152. else
  1153. {
  1154. LogicDebug("Item [%d,%d]: losFocus trugger",befLine,befItem);
  1155. prev.onLea.Activate(Mission(),false);
  1156. }
  1157. }
  1158. Item &item = lines[curLine].items[curItem];
  1159. BaseGUIElement *p = (BaseGUIElement *)item.p.Ptr();
  1160. if( p && p->Is(InterfaceUtils::GetButtonId()))
  1161. p->SetFocus();
  1162. else
  1163. {
  1164. LogicDebug("Item [%d,%d]: getFocus trugger",curLine,curItem);
  1165. item.onFoc.Activate(Mission(),false);
  1166. }
  1167. }
  1168. }
  1169. }
  1170. void GUIList::OnChildNotify(BaseGUIElement *p, ChildNotification event)
  1171. {
  1172. Assert(p)
  1173. if( event == ChildSelected )
  1174. {
  1175. int i = p->data_a;
  1176. int j = p->data_b;
  1177. if( i == curLine && j == curItem )
  1178. return;
  1179. if( i >= 0 && i < lines && j >= 0 && j < lines[i].items )
  1180. {
  1181. scroll_x -= (j - curItem)*itemWidth;
  1182. scroll_y -= (i - curLine)*itemHeight;
  1183. befLine = curLine;
  1184. befItem = curItem;
  1185. curLine = i;
  1186. curItem = j;
  1187. Item &prev = lines[befLine].items[befItem];
  1188. BaseGUIElement *p = (BaseGUIElement *)prev.p.Ptr();
  1189. if( p && p->Is(InterfaceUtils::GetButtonId()))
  1190. {
  1191. // if( GetElementInFocus() == prev.p )
  1192. // SetElementInFocus(this);
  1193. }
  1194. else
  1195. {
  1196. LogicDebug("Item [%d,%d]: losFocus trugger",befLine,befItem);
  1197. prev.onLea.Activate(Mission(),false);
  1198. }
  1199. m_state = HScrolling;
  1200. m_from.x = m_to.x = GetOffsetX();
  1201. m_from.y = m_to.y = GetOffsetY();
  1202. m_scrollTime = 0.2f; m_curScrollTime = 0.0f;
  1203. // UpdatePos();
  1204. }
  1205. }
  1206. }
  1207. void GUIList::Command(const char *id, dword numParams, const char **params)
  1208. {
  1209. if( !IsActive())
  1210. return;
  1211. if( string::IsEmpty(id))
  1212. return;
  1213. if( string::IsEqual(id,"fadein"))
  1214. {
  1215. Show(true);
  1216. SetFadeState(FadingIn);
  1217. m_fadeTime = 2.0f;
  1218. if( numParams > 0 )
  1219. m_fadeTime = (float)atof(params[0]);
  1220. m_fade = m_fadeTime;
  1221. return;
  1222. }
  1223. else
  1224. {
  1225. if( !IsShow())
  1226. return;
  1227. if( string::IsEqual(id,"fadeout"))
  1228. {
  1229. SetFadeState(FadingOut);
  1230. m_fadeTime = 2.0f;
  1231. if( numParams > 0 )
  1232. m_fadeTime = (float)atof(params[0]);
  1233. m_fade = m_fadeTime;
  1234. m_alphaOriginal = GetNativeAlpha();
  1235. return;
  1236. }
  1237. else
  1238. if( string::IsEqual(id,"up"))
  1239. {
  1240. if( m_state != Normal )
  1241. {
  1242. if( curLine >= 0 && curItem >= 0 )
  1243. {
  1244. BaseGUIElement *p = (BaseGUIElement *)lines[curLine].items[curItem].p.Ptr();
  1245. if( p->Is(InterfaceUtils::GetButtonId()))
  1246. p->SetFocus();
  1247. }
  1248. return;
  1249. }
  1250. if( curLine >= 0 )
  1251. {
  1252. if( curLine )
  1253. {
  1254. befItem = curItem;
  1255. befLine = curLine;
  1256. curLine--;
  1257. curItem = maxItem;
  1258. if( curItem > lines[curLine].items - 1 )
  1259. curItem = lines[curLine].items - 1;
  1260. UpdatePos();
  1261. }
  1262. else if( curItem >= 0 )
  1263. {
  1264. BaseGUIElement *p = (BaseGUIElement *)lines[0].items[curItem].p.Ptr();
  1265. if( p->Is(InterfaceUtils::GetButtonId()))
  1266. p->SetFocus();
  1267. }
  1268. }
  1269. }
  1270. else
  1271. if( string::IsEqual(id,"down"))
  1272. {
  1273. if( m_state != Normal )
  1274. {
  1275. if( curLine >= 0 && curItem >= 0 )
  1276. {
  1277. BaseGUIElement *p = (BaseGUIElement *)lines[curLine].items[curItem].p.Ptr();
  1278. if( p->Is(InterfaceUtils::GetButtonId()))
  1279. p->SetFocus();
  1280. }
  1281. return;
  1282. }
  1283. if( curLine >= 0 )
  1284. {
  1285. if( curLine < lines - 1 )
  1286. {
  1287. befItem = curItem;
  1288. befLine = curLine;
  1289. curLine++;
  1290. curItem = maxItem;
  1291. if( curItem > lines[curLine].items - 1 )
  1292. curItem = lines[curLine].items - 1;
  1293. UpdatePos();
  1294. }
  1295. else if( curItem >= 0 )
  1296. {
  1297. BaseGUIElement *p = (BaseGUIElement *)lines.LastE().items[curItem].p.Ptr();
  1298. if( p->Is(InterfaceUtils::GetButtonId()))
  1299. p->SetFocus();
  1300. }
  1301. }
  1302. }
  1303. else
  1304. if( string::IsEqual(id,"left"))
  1305. {
  1306. if( m_state != Normal )
  1307. {
  1308. if( curLine >= 0 && curItem >= 0 )
  1309. {
  1310. BaseGUIElement *p = (BaseGUIElement *)lines[curLine].items[curItem].p.Ptr();
  1311. if( p->Is(InterfaceUtils::GetButtonId()))
  1312. p->SetFocus();
  1313. }
  1314. return;
  1315. }
  1316. if( curLine >= 0 )
  1317. {
  1318. if( curItem >= 0 )
  1319. maxItem = curItem;
  1320. if( curItem >= 0 )
  1321. {
  1322. if( curItem )
  1323. {
  1324. befLine = curLine;
  1325. befItem = curItem;
  1326. curItem--;
  1327. maxItem = curItem;
  1328. UpdatePos();
  1329. }
  1330. else
  1331. {
  1332. BaseGUIElement *p = (BaseGUIElement *)lines[curLine].items[curItem].p.Ptr();
  1333. if( p->Is(InterfaceUtils::GetButtonId()))
  1334. p->SetFocus();
  1335. }
  1336. }
  1337. }
  1338. }
  1339. else
  1340. if( string::IsEqual(id,"right"))
  1341. {
  1342. if( m_state != Normal )
  1343. {
  1344. if( curLine >= 0 && curItem >= 0 )
  1345. {
  1346. BaseGUIElement *p = (BaseGUIElement *)lines[curLine].items[curItem].p.Ptr();
  1347. if( p->Is(InterfaceUtils::GetButtonId()))
  1348. p->SetFocus();
  1349. }
  1350. return;
  1351. }
  1352. if( curLine >= 0 )
  1353. {
  1354. if( curItem >= 0 )
  1355. maxItem = curItem;
  1356. if( curItem >= 0 )
  1357. {
  1358. if( curItem < lines[curLine].items - 1 )
  1359. {
  1360. befLine = curLine;
  1361. befItem = curItem;
  1362. curItem++;
  1363. maxItem = curItem;
  1364. UpdatePos();
  1365. }
  1366. else
  1367. {
  1368. BaseGUIElement *p = (BaseGUIElement *)lines[curLine].items[curItem].p.Ptr();
  1369. if( p->Is(InterfaceUtils::GetButtonId()))
  1370. p->SetFocus();
  1371. }
  1372. }
  1373. }
  1374. }
  1375. else
  1376. {
  1377. BaseGUIElement::Command(id,numParams,params);
  1378. }
  1379. }
  1380. }
  1381. static char GUIDescription[] =
  1382. "GUI List.\n\n"
  1383. " Use it to make list of GUI items\n"
  1384. " NOTE: all sizes-positions are relative (not pixel sizes-positions)\n\n"
  1385. "Commands:\n\n"
  1386. " left, right - scrolls list horizontally\n"
  1387. " up, down - scrolls list vertically\n\n"
  1388. " fadein [time] - fades list in\n"
  1389. " fadeout [time] - fades list out";
  1390. MOP_BEGINLISTCG(GUIList, "GUI List", '1.00', 2000, GUIDescription, "Interface")
  1391. // MOP_GROUPBEG("Wide screen layout")
  1392. // MOP_BOOL("Use shift aspect", false)
  1393. // MOP_BOOL("Use width aspect", true)
  1394. MOP_ENUMBEG("Layout")
  1395. MOP_ENUMELEMENT("Left")
  1396. MOP_ENUMELEMENT("Center")
  1397. MOP_ENUMELEMENT("Right")
  1398. MOP_ENUMEND
  1399. MOP_ENUM("Layout", "Layout")
  1400. // MOP_GROUPEND()
  1401. MOP_FLOAT("X position", 25.0f)
  1402. MOP_FLOAT("Y position", 25.0f)
  1403. // MOP_FLOAT("Alpha", 1.0f)
  1404. MOP_FLOATEX("Alpha", 1.0f, 0.0f, 1.0f)
  1405. MOP_STRING("Parent id", "")
  1406. MOP_FLOAT("Clip rect width" , 50.0f)
  1407. MOP_FLOAT("Clip rect height", 50.0f)
  1408. MOP_BOOL("Use clip rect", false)
  1409. MOP_STRING("Back texture", "")
  1410. MOP_FLOAT ("Back alpha", 1.0f)
  1411. MOP_LONG("Draw priority", 0)
  1412. MOP_STRING("Hor bar", "")
  1413. MOP_STRING("Ver bar", "")
  1414. MOP_ARRAYBEG("Lines", 0, 100)
  1415. MOP_ARRAYBEG("Items", 0, 100)
  1416. MOP_STRING("Name", "")
  1417. MOP_MISSIONTRIGGER("OnFocus" )
  1418. MOP_MISSIONTRIGGER("OnLeave" )
  1419. MOP_MISSIONTRIGGER("OnSelect")
  1420. MOP_ARRAYEND
  1421. MOP_ARRAYEND
  1422. MOP_LONG("Start line", -1)
  1423. MOP_LONG("Start item", -1)
  1424. MOP_FLOAT("Item width" , 25.0f)
  1425. MOP_FLOAT("Item height", 5.0f)
  1426. MOP_BOOL("Centered", false)
  1427. MOP_GROUPBEG("Controls")
  1428. MOP_STRING("Up" , "")
  1429. MOP_STRING("Down" , "")
  1430. MOP_STRING("Left" , "")
  1431. MOP_STRING("Right", "")
  1432. MOP_GROUPEND()
  1433. MOP_FLOAT("Button width" , 4.1f)
  1434. MOP_FLOAT("Button height", 5.0f)
  1435. MOP_BOOL("Active" , true)
  1436. MOP_BOOL("Visible", true)
  1437. MOP_ENDLIST(GUIList)