GUISelector.cpp 60 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473
  1. #include "GUISelector.h"
  2. #include "GUIWidget.h"
  3. #include "GUIButton.h"
  4. #include "..\Utils\InterfaceUtils.h"
  5. #include "..\ProgressBar\csProgressBar.h"
  6. #include "BaseGUICursor.h"
  7. GUISelector::GUISelector(void) : lines(_FL_),
  8. m_scales(_FL_),
  9. m_alphas(_FL_),
  10. m_drawps(_FL_)
  11. {
  12. m_restart = false;
  13. drawLevel = ML_GUI2;
  14. curLine = -1;
  15. curItem = -1;
  16. befLine = -1;
  17. befItem = -1; maxItem = 0;
  18. marker.Reset();
  19. scroll_x = 0.0f;
  20. scroll_y = 0.0f;
  21. maxWidth = 0;
  22. m_state = Normal;
  23. m_dx = 0.0f;
  24. m_dy = 0.0f;
  25. nativeShow = true;
  26. }
  27. GUISelector::~GUISelector(void)
  28. {
  29. }
  30. void GUISelector::Restart()
  31. {
  32. Show(false);
  33. m_restart = true;
  34. ReCreate();
  35. }
  36. void GUISelector::SkipMOPs(MOPReader & reader)
  37. {
  38. reader.Float(); // m_clipWidth
  39. reader.Float(); // m_clipHeight
  40. reader.Bool(); // m_useClipping
  41. reader.String().c_str(); // m_texture
  42. reader.Float(); // m_texAlpha
  43. drawPriority = reader.Long();
  44. m_quadRender.SetTexture(m_texture);
  45. int ln = reader.Array();
  46. for( int i = 0 ; i < ln ; i++ )
  47. {
  48. Line &line = lines[i];
  49. int in = reader.Array();
  50. for( int j = 0 ; j < in ; j++ )
  51. {
  52. Item &item = line.items[j];
  53. reader.String().c_str(); // item.normal.name
  54. reader.String().c_str(); // item.closed.name
  55. item.open = reader.Bool();
  56. BaseGUIElement *normal = (BaseGUIElement *)item.normal.p.Ptr();
  57. BaseGUIElement *closed = (BaseGUIElement *)item.closed.p.Ptr();
  58. item.onFoc.Init(reader);
  59. item.onLea.Init(reader);
  60. item.onSel.Init(reader);
  61. item.onTry.Init(reader);
  62. item.k = 1.0f;
  63. item.a = 0.6f;
  64. item.draw = 0;
  65. item.q = item.open ? normal : closed;
  66. if( normal )
  67. normal->Show( item.open);
  68. if( closed )
  69. closed->Show(!item.open);
  70. }
  71. }
  72. if( ln )
  73. {
  74. curLine = 0;
  75. if( lines[curLine].items )
  76. {
  77. curItem = 0;
  78. // lines[curLine].items[curItem].onFoc.Activate(Mission(),false);
  79. }
  80. }
  81. else
  82. {
  83. curLine = -1;
  84. curItem = -1;
  85. }
  86. reader.Long(); // startLine
  87. reader.Long(); // startItem
  88. befLine = curLine;
  89. befItem = curItem; maxItem = curItem;
  90. reader.String().c_str(); // markerName
  91. reader.Float(); // markerScale
  92. reader.Float(); // itemWidth
  93. reader.Float(); // itemHeight
  94. reader.Float(); // horSpace
  95. reader.Float(); // verSpace
  96. int sn = reader.Array();
  97. for( int i = 0 ; i < sn ; i++ )
  98. {
  99. reader.Float(); // scale
  100. reader.Float(); // alpha
  101. reader.Long(); // draw priority
  102. }
  103. reader.Float(); // m_scaleSpeed
  104. reader.Float(); // m_scrolSpeed
  105. reader.Float(); // m_delTime
  106. reader.Float(); // m_begTime
  107. reader.Float(); // m_endTime
  108. reader.Float(); // m_accTime
  109. reader.Bool(); // centered
  110. reader.Bool(); // m_isLooped
  111. reader.Enum(); // align (center/bottom)
  112. if( curLine >= 0 && curItem >= 0 && centered )
  113. {
  114. Rect r; GetRect(r,false);
  115. ScrollTo(
  116. 0.5f*(r.r - r.l - itemWidth),
  117. 0.5f*(r.b - r.t - itemHeight));
  118. }
  119. reader.String().c_str(); // m_up
  120. reader.String().c_str(); // m_down
  121. reader.String().c_str(); // m_left
  122. reader.String().c_str(); // m_right
  123. reader.String().c_str(); // m_sel
  124. BaseGUIElement::Activate(reader.Bool());
  125. // Show (reader.Bool());
  126. nativeShow = reader.Bool();
  127. reader.Bool(); // m_silentActivate
  128. // MissionObject::Show(nativeShow);
  129. m_alphaOriginal = GetNativeAlpha();
  130. m_fadeAlpha = 1.0f;
  131. m_clipX = GetX();
  132. m_clipY = GetY();
  133. m_state = Normal;
  134. // ResetItems();
  135. SetUpdate(&GUISelector::Pre_Func,ML_FIRST);
  136. }
  137. void GUISelector::ReadMOPs(MOPReader & reader)
  138. {
  139. m_isLooped = true;
  140. m_clipWidth = reader.Float();
  141. m_clipHeight = reader.Float();
  142. SizeTo(m_clipWidth,m_clipHeight);
  143. m_useClipping = reader.Bool();
  144. SetClipping(m_useClipping);
  145. m_texture = reader.String().c_str();
  146. m_texAlpha = reader.Float();
  147. drawPriority = reader.Long();
  148. m_quadRender.SetTexture(m_texture);
  149. ReleaseItems();
  150. /*
  151. Max: prog.name = ""; поэтому результате не найдёться ниодного объекта
  152. for( int i = 0 ; i < 2 ; i++ )
  153. {
  154. Progress &prog = progs[i];
  155. // prog.name = reader.String().c_str();
  156. prog.name = "";
  157. if( FindObject(prog.name,prog.p))
  158. {
  159. if( !prog.p.Ptr()->Is(InterfaceUtils::GetPbarId()))
  160. prog.p.Reset();
  161. }
  162. }
  163. */
  164. lines.DelAll();
  165. maxWidth = 0;
  166. int ln = reader.Array();
  167. for( int i = 0 ; i < ln ; i++ )
  168. {
  169. Line &line = lines[lines.Add()];
  170. int in = reader.Array();
  171. for( int j = 0 ; j < in ; j++ )
  172. {
  173. Item &item = line.items[line.items.Add()];
  174. item.normal.name = reader.String();
  175. item.closed.name = reader.String();
  176. item.open = reader.Bool();
  177. if( FindObject(item.normal.name,item.normal.p))
  178. {
  179. if( !item.normal.p.Ptr()->Is(InterfaceUtils::GetBaseId()))
  180. item.normal.p.Reset();
  181. }
  182. BaseGUIElement *normal = (BaseGUIElement *)item.normal.p.Ptr();
  183. if( normal )
  184. {
  185. normal->data_a = i;
  186. normal->data_b = j;
  187. }
  188. if( FindObject(item.closed.name,item.closed.p))
  189. {
  190. if( !item.closed.p.Ptr()->Is(InterfaceUtils::GetBaseId()))
  191. item.closed.p.Reset();
  192. }
  193. BaseGUIElement *closed = (BaseGUIElement *)item.closed.p.Ptr();
  194. if( closed )
  195. {
  196. closed->data_a = i;
  197. closed->data_b = j;
  198. }
  199. item.onFoc.Init(reader);
  200. item.onLea.Init(reader);
  201. item.onSel.Init(reader);
  202. item.onTry.Init(reader);
  203. item.k = 1.0f;
  204. item.a = 0.6f;
  205. item.draw = 0;
  206. item.q = item.open ? normal : closed;
  207. if( normal )
  208. normal->Show( item.open);
  209. if( closed )
  210. closed->Show(!item.open);
  211. }
  212. if( maxWidth < in )
  213. maxWidth = in;
  214. }
  215. if( ln )
  216. {
  217. curLine = 0;
  218. if( lines[curLine].items )
  219. {
  220. curItem = 0;
  221. // lines[curLine].items[curItem].onFoc.Activate(Mission(),false);
  222. }
  223. }
  224. else
  225. {
  226. curLine = -1;
  227. curItem = -1;
  228. }
  229. startLine = reader.Long();
  230. startItem = reader.Long();
  231. befLine = curLine;
  232. befItem = curItem; maxItem = curItem;
  233. markerName = reader.String();
  234. FindObject(markerName,marker);
  235. markerScale = reader.Float();
  236. itemWidth = reader.Float()*m_aspect;
  237. itemHeight = reader.Float();
  238. horSpace = reader.Float()*m_aspect;
  239. verSpace = reader.Float();
  240. m_scales.DelAll();
  241. m_alphas.DelAll();
  242. m_drawps.DelAll();
  243. int sn = reader.Array();
  244. for( int i = 0 ; i < sn ; i++ )
  245. {
  246. m_scales.Add(reader.Float());
  247. m_alphas.Add(reader.Float());
  248. m_drawps.Add(reader.Long());
  249. }
  250. m_scaleSpeed = reader.Float();
  251. m_scrolSpeed = reader.Float();
  252. m_delTime = reader.Float();
  253. m_begTime = reader.Float();
  254. m_endTime = reader.Float();
  255. m_accTime = reader.Float();
  256. centered = reader.Bool();
  257. m_isLooped = reader.Bool();
  258. switch( reader.Enum().c_str()[0] )
  259. {
  260. case 'C':
  261. m_bottom = false;
  262. break;
  263. case 'B':
  264. m_bottom = true;
  265. break;
  266. };
  267. if( curLine >= 0 && curItem >= 0 && centered )
  268. {
  269. Rect r; GetRect(r,false);
  270. ScrollTo(
  271. 0.5f*(r.r - r.l - itemWidth),
  272. 0.5f*(r.b - r.t - itemHeight));
  273. }
  274. /* for( int i = 0 ; i < 4 ; i++ )
  275. {
  276. Button &butt = butts[i];
  277. butt.name = reader.String().c_str();
  278. butt.p = (GUIButton *)FindObject(butt.name);
  279. butt.hash = -1;
  280. if( butt.p )
  281. {
  282. if( butt.p->Is(InterfaceUtils::GetButtonId()))
  283. ValidatePointer(butt.p,butt.hash);
  284. else
  285. butt.p = null;
  286. }
  287. }*/
  288. for( int i = 0 ; i < 4 ; i++ )
  289. {
  290. Button &butt = butts[i];
  291. butt.name.Empty();
  292. butt.p.Reset();
  293. }
  294. const char *name;
  295. name = reader.String().c_str(); m_up = Controls().FindControlByName(name);
  296. name = reader.String().c_str(); m_down = Controls().FindControlByName(name);
  297. name = reader.String().c_str(); m_left = Controls().FindControlByName(name);
  298. name = reader.String().c_str(); m_right = Controls().FindControlByName(name);
  299. name = reader.String().c_str(); m_sel = Controls().FindControlByName(name);
  300. // btnWidth = reader.Float()*m_aspect;
  301. // btnHeight = reader.Float();
  302. btnWidth = 20.0f;
  303. btnHeight = 20.0f;
  304. BaseGUIElement::Activate(reader.Bool());
  305. // Show (reader.Bool());
  306. nativeShow = reader.Bool();
  307. m_silentActivate = reader.Bool();
  308. // MissionObject::Show(nativeShow);
  309. m_alphaOriginal = GetNativeAlpha();
  310. m_fadeAlpha = 1.0f;
  311. m_clipX = GetX();
  312. m_clipY = GetY();
  313. m_state = Normal;
  314. m_cursor.Reset();
  315. ResetItems();
  316. }
  317. bool GUISelector::Create (MOPReader &reader)
  318. {
  319. if( m_restart )
  320. {
  321. RestartObject(reader);
  322. }
  323. else
  324. {
  325. EditMode_Update(reader);
  326. }
  327. return true;
  328. }
  329. void GUISelector::PostCreate()
  330. {
  331. FindObject(InterfaceUtils::GetCursorName(),m_cursor);
  332. /* if( IsShow() == false )
  333. {
  334. if( marker )
  335. marker->Notify(ParentHided);
  336. for( int i = 0 ; i < lines ; i++ )
  337. {
  338. for( int j = 0 ; j < lines[i].items ; j++ )
  339. {
  340. const Item &item = lines[i].items[j];
  341. if( item.q )
  342. item.q->Notify(ParentHided);
  343. }
  344. }
  345. }*/
  346. BaseGUIElement::Show(nativeShow);
  347. }
  348. void _cdecl GUISelector::Pre_Func(float, long)
  349. {
  350. DelUpdate(&GUISelector::Pre_Func);
  351. ResetItems();
  352. }
  353. void _cdecl GUISelector::InitFunc(float, long)
  354. {
  355. DelUpdate(&GUISelector::InitFunc);
  356. if( m_restart )
  357. {
  358. m_restart = false;
  359. BaseGUIElement::Show(nativeShow);
  360. if( IsShow())
  361. {
  362. SetUpdate(&GUISelector::Work,drawLevel + drawPriority);
  363. // SetUpdate(&GUISelector::Draw,drawLevel + drawPriority + 2000);
  364. }
  365. // if( IsActive() && IsShow())
  366. {
  367. if( curLine >= 0 && curItem >= 0 )
  368. {
  369. if( curLine <= 0 )
  370. {
  371. if( startLine >= 0 && startLine < lines )
  372. curLine = startLine;
  373. befLine = 0;
  374. }
  375. else
  376. befLine = curLine;
  377. if( curItem <= 0 )
  378. {
  379. if( startItem >= 0 && startItem < lines[curLine].items )
  380. {
  381. maxItem = curItem = startItem;
  382. }
  383. befItem = 0;
  384. }
  385. else
  386. befItem = curItem;
  387. if( curLine < lines && curItem < lines[curLine].items )
  388. {
  389. Item &item = lines[curLine].items[curItem];
  390. /* if( item.normal.p && item.normal.p->Is(InterfaceUtils::GetButtonId()))
  391. item.normal.p->SetFocus();
  392. else
  393. {
  394. if( startLine >= 0 && startItem >= 0 )
  395. {
  396. LogicDebug("Item [%d,%d]: getFocus trigger",curLine,curItem);
  397. item.onFoc.Activate(Mission(),false);
  398. }
  399. item.k = 1.0f;
  400. }*/
  401. item.k = 1.0f;
  402. }
  403. // befLine = 0;
  404. // befItem = 0;
  405. UpdatePos(false,false,true,startLine >= 0 && startItem >= 0 && IsShow() && IsActive());
  406. if( IsShow())
  407. {
  408. UpdateElements(0.0f,true);
  409. }
  410. }
  411. }
  412. return;
  413. }
  414. m_initComplete = true;
  415. BaseGUIElement *parent = GetParent();
  416. if( BaseGUIElement *newParent = FindParent())
  417. {
  418. newParent->Register(this);
  419. }
  420. else
  421. {
  422. if( parent )
  423. parent->UnRegister(this);
  424. }
  425. // Show(IsShow());
  426. // BaseGUIElement::Show(nativeShow);
  427. // Show(nativeShow);
  428. if( EditMode_IsOn())
  429. DelUpdate(&GUISelector::Work);
  430. BaseGUIElement::Show(nativeShow);
  431. if( IsShow())
  432. {
  433. SetUpdate(&GUISelector::Work,drawLevel + drawPriority);
  434. // SetUpdate(&GUISelector::Draw,drawLevel + drawPriority + 2000);
  435. }
  436. // if( IsActive() && IsShow())
  437. {
  438. if( curLine >= 0 && curItem >= 0 )
  439. {
  440. if( curLine <= 0 )
  441. {
  442. if( startLine >= 0 && startLine < lines )
  443. curLine = startLine;
  444. befLine = 0;
  445. }
  446. else
  447. befLine = curLine;
  448. if( curItem <= 0 )
  449. {
  450. if( startItem >= 0 && startItem < lines[curLine].items )
  451. {
  452. maxItem = curItem = startItem;
  453. }
  454. befItem = 0;
  455. }
  456. else
  457. befItem = curItem;
  458. if( curLine < lines && curItem < lines[curLine].items )
  459. {
  460. Item &item = lines[curLine].items[curItem];
  461. /* if( item.normal.p && item.normal.p->Is(InterfaceUtils::GetButtonId()))
  462. item.normal.p->SetFocus();
  463. else
  464. {
  465. if( startLine >= 0 && startItem >= 0 )
  466. {
  467. LogicDebug("Item [%d,%d]: getFocus trigger",curLine,curItem);
  468. item.onFoc.Activate(Mission(),false);
  469. }
  470. item.k = 1.0f;
  471. }*/
  472. item.k = 1.0f;
  473. }
  474. // befLine = 0;
  475. // befItem = 0;
  476. UpdatePos(false,false,true,startLine >= 0 && startItem >= 0 && IsShow() && IsActive());
  477. if( IsShow())
  478. {
  479. UpdateElements(0.0f,true);
  480. }
  481. }
  482. }
  483. }
  484. bool GUISelector::RestartObject(MOPReader &reader)
  485. {
  486. BaseGUIElement::SkipMOPs(reader);
  487. SkipMOPs(reader);
  488. NotifyChildren(ParentChanged);
  489. SetUpdate(&GUISelector::InitFunc,ML_GUI5 - 1);
  490. if( m_initComplete == false )
  491. {
  492. m_restart = false;
  493. }
  494. return true;
  495. }
  496. bool GUISelector::EditMode_Update(MOPReader &reader)
  497. {
  498. BaseGUIElement::EditMode_Update(reader);
  499. ReadMOPs (reader);
  500. NotifyChildren(ParentChanged);
  501. SetUpdate(&GUISelector::InitFunc,ML_GUI5 - 1);
  502. m_initComplete = false;
  503. return true;
  504. }
  505. inline float cubic_curve(float t)
  506. {
  507. float t2 = t*t; return 3*t2 - 2*t2*t;
  508. }
  509. void _cdecl GUISelector::Work(float deltaTime, long level)
  510. {
  511. if( EditMode_IsOn() && !EditMode_IsVisible())
  512. return;
  513. Draw();
  514. Update(deltaTime);
  515. Draw(deltaTime,level);
  516. }
  517. void GUISelector::Update(float deltaTime)
  518. {
  519. bool edit_mode = EditMode_IsOn();
  520. if( edit_mode )
  521. {
  522. bool reset = false;
  523. for( int i = 0 ; i < lines ; i++ )
  524. {
  525. Line &line = lines[i];
  526. for( int j = 0 ; j < line.items ; j++ )
  527. {
  528. Item &item = line.items[j];
  529. if(!item.normal.p.Validate())
  530. {
  531. if( FindObject(item.normal.name,item.normal.p))
  532. {
  533. reset = true;
  534. }
  535. }
  536. else
  537. {
  538. BaseGUIElement *normal = (BaseGUIElement *)item.normal.p.Ptr();
  539. if( item.normal.name != normal->GetObjectID() )
  540. {
  541. normal->Restrict(preserveNone);
  542. normal->ReCreate();
  543. FindObject(item.normal.name,item.normal.p);
  544. }
  545. }
  546. BaseGUIElement *normal = (BaseGUIElement *)item.normal.p.Ptr();
  547. if( normal )
  548. {
  549. normal->data_a = i;
  550. normal->data_b = j;
  551. }
  552. ////
  553. if(!item.closed.p.Validate())
  554. {
  555. if( FindObject(item.closed.name,item.closed.p))
  556. {
  557. reset = true;
  558. }
  559. }
  560. else
  561. {
  562. BaseGUIElement *closed = (BaseGUIElement *)item.closed.p.Ptr();
  563. if( item.closed.name != closed->GetObjectID() )
  564. {
  565. closed->Restrict(preserveNone);
  566. closed->ReCreate();
  567. FindObject(item.closed.name,item.closed.p);
  568. }
  569. }
  570. BaseGUIElement *closed = (BaseGUIElement *)item.closed.p.Ptr();
  571. if( closed )
  572. {
  573. closed->data_a = i;
  574. closed->data_b = j;
  575. }
  576. }
  577. }
  578. // if( reset )
  579. // ResetItems();
  580. for( int i = 0 ; i < 2 ; i++ )
  581. {
  582. Progress &prog = progs[i];
  583. if(!prog.p.Validate())
  584. {
  585. if( FindObject(prog.name,prog.p))
  586. {
  587. reset = true;
  588. }
  589. }
  590. else
  591. {
  592. csProgressBar *p = (csProgressBar *)prog.p.Ptr();
  593. if( prog.name != p->GetObjectID() )
  594. {
  595. p->Restrict(preserveNone);
  596. p->ReCreate();
  597. FindObject(prog.name,prog.p);
  598. }
  599. }
  600. }
  601. for( int i = 0 ; i < 4 ; i++ )
  602. {
  603. Button &butt = butts[i];
  604. if(!butt.p.Validate())
  605. {
  606. if( FindObject(butt.name,butt.p))
  607. {
  608. reset = true;
  609. }
  610. }
  611. else
  612. {
  613. GUIButton *p = (GUIButton *)butt.p.Ptr();
  614. if( butt.name != p->GetObjectID() )
  615. {
  616. p->Restrict(preserveNone);
  617. p->ReCreate();
  618. FindObject(butt.name,butt.p);
  619. }
  620. }
  621. }
  622. if( reset )
  623. ResetItems();
  624. if(!marker.Validate())
  625. {
  626. FindObject(markerName,marker);
  627. }
  628. }
  629. if( GetFadeState() == BaseGUIElement::FadingIn )
  630. {
  631. m_fade -= deltaTime;
  632. if( m_fade < 0.0f )
  633. {
  634. SetFadeState(FadingFinished);
  635. m_fade = 0.0f;
  636. }
  637. m_fadeAlpha = 1.0f - m_fade/m_fadeTime;
  638. SetAlpha(m_fadeAlpha*m_alphaOriginal);
  639. }
  640. else
  641. if( GetFadeState() == BaseGUIElement::FadingOut )
  642. {
  643. m_fade -= deltaTime;
  644. if( m_fade < 0.0f )
  645. {
  646. SetFadeState(FadingFinished); Show(false);
  647. m_fade = 0.0f;
  648. }
  649. m_fadeAlpha = m_fade/m_fadeTime;
  650. SetAlpha(m_fadeAlpha*m_alphaOriginal);
  651. }
  652. /*
  653. // const int kn = 3;
  654. int kn = m_scales;
  655. // static float _sk[kn] = {1.3f,1.15f,1.0f};
  656. // static float _ak[kn] = {1.0f,0.80f,0.6f};
  657. // const float upk = 0.02f;
  658. const float upk = 2.50f;
  659. // const float rek = 0.02f;
  660. if( curLine >= 0 && curItem >= 0 )
  661. {
  662. float px = GetOffsetX();
  663. float py = GetOffsetY();
  664. float et = m_state == Normal ? 0.0f : sqrtf((m_to.x - px)*(m_to.x - px) + (m_to.y - py)*(m_to.y - py));
  665. et *= 0.2f;
  666. float kk = deltaTime*upk*m_scaleSpeed;
  667. float dd = 1.0f/(0.5f + et*et);
  668. //////////////////////////////////////////////
  669. // Поддерживаем пока только одномерный лист //
  670. //////////////////////////////////////////////
  671. int n = lines[0].items;
  672. bool hor = n > 1;
  673. if( !hor )
  674. n = lines;
  675. int li = 0;
  676. int ii = 0;
  677. for( int i = 0 ; i < n ; i++ )
  678. {
  679. int k = 0;
  680. if( hor )
  681. {
  682. k = abs(ii - curItem);
  683. if( m_isLooped )
  684. {
  685. int t = curItem > ii ? n - curItem + ii : n - ii + curItem;
  686. if( k > t )
  687. k = t;
  688. }
  689. }
  690. else
  691. {
  692. k = abs(li - curLine);
  693. if( m_isLooped )
  694. {
  695. int t = curLine > li ? n - curLine + li : n - li + curLine;
  696. if( k > t )
  697. k = t;
  698. }
  699. }
  700. float sk = 1.0f;
  701. float ak = 1.0f;
  702. long draw = 0;
  703. if( kn > 0 )
  704. {
  705. if( k > kn - 1 )
  706. k = kn - 1;
  707. sk = m_scales[k];
  708. ak = m_alphas[k]; draw = m_drawps[k];
  709. }
  710. // float sk = _sk[k];
  711. // float ak = _ak[k];
  712. if( !lines[li].items )
  713. continue;
  714. Item &item = lines[li].items[ii];
  715. if( item.q )
  716. {
  717. if( item.k != sk || item.a != ak )
  718. {
  719. if( edit_mode )
  720. {
  721. item.k = sk;
  722. }
  723. else
  724. {
  725. float dk = (sk - item.k)*dd;
  726. dk = sign(dk)*sqrtf(fabsf(dk));
  727. dk *= kk;
  728. if( fabsf(dk) > fabsf(sk - item.k))
  729. dk = sk - item.k;
  730. item.k += dk;
  731. }
  732. float iw = itemWidth/m_aspect;
  733. float ih = itemHeight;
  734. float w = iw*item.k;
  735. float h = ih*item.k;
  736. item.q->SizeTo(w,h);
  737. float x = ii*(iw + horSpace/m_aspect);
  738. float y = li*(ih + verSpace);
  739. item.q->MoveTo(x - 0.5f*(w - iw),y - 0.5f*(h - ih));
  740. if( edit_mode )
  741. {
  742. item.a = ak;
  743. }
  744. else
  745. {
  746. float da = (ak - item.a)*kk;
  747. da = sign(da)*sqrtf(fabsf(da));
  748. if( fabsf(da) > fabsf(ak - item.a))
  749. da = ak - item.a;
  750. item.a += da;
  751. }
  752. item.q->SetAlpha(item.a);
  753. }
  754. if( item.draw != draw )
  755. {
  756. item.q->ResetDrawUpdate(item.draw = draw);
  757. }
  758. }
  759. if( hor )
  760. ii++;
  761. else
  762. li++;
  763. }
  764. if( curLine < lines && curItem < lines[curLine].items )
  765. {
  766. const Item &cur = lines[curLine].items[curItem];
  767. if( marker && cur.q )
  768. {
  769. float x,y;
  770. cur.q->GetNativePos(x,y);
  771. float w = markerScale*cur.q->GetWidth();
  772. float h = markerScale*cur.q->GetHeight();
  773. x -= 0.5f*(w - cur.q->GetWidth());
  774. y -= 0.5f*(h - cur.q->GetHeight());
  775. marker->MoveTo(x,y);
  776. marker->SizeTo(w,h);
  777. }
  778. }
  779. }
  780. */ UpdateElements(deltaTime,edit_mode);
  781. // SetAlpha(m_fadeAlpha);
  782. if( edit_mode )
  783. return;
  784. if( IsActive())
  785. {
  786. // const float rpTime = 0.65f;
  787. float rpTime = m_delTime;
  788. // const float ctTime = 0.35f;
  789. // const float mnTime = 0.15f;
  790. float ctTime = m_begTime;
  791. float mnTime = m_endTime;
  792. // const float reTime = 4.00f;
  793. float reTime = m_accTime;
  794. // const float k = 0.55f;
  795. ControlStateType stU = Controls().GetControlStateType(m_up);
  796. ControlStateType stD = Controls().GetControlStateType(m_down);
  797. ControlStateType stL = Controls().GetControlStateType(m_left);
  798. ControlStateType stR = Controls().GetControlStateType(m_right);
  799. int dx = 0;
  800. int dy = 0;
  801. switch( stU )
  802. {
  803. case CST_ACTIVATED:
  804. btU.start(rpTime); dy--;
  805. break;
  806. case CST_INACTIVATED:
  807. btU.en = false;
  808. break;
  809. case CST_ACTIVE:
  810. if( btU.en )
  811. {
  812. btU.time += deltaTime; btU.t += deltaTime;
  813. if( btU.time >= btU.timeMax )
  814. {
  815. btU.time = 0.0f; dy--;
  816. if( btU.timeMax >= rpTime )
  817. {
  818. btU.timeMax = ctTime; btU.t = 0.0f;
  819. }
  820. else
  821. btU.timeMax = Lerp(ctTime,mnTime,coremin(1.0f,btU.t/reTime));
  822. }
  823. }
  824. break;
  825. }
  826. switch( stD )
  827. {
  828. case CST_ACTIVATED:
  829. btD.start(rpTime); dy++;
  830. break;
  831. case CST_INACTIVATED:
  832. btD.en = false;
  833. break;
  834. case CST_ACTIVE:
  835. if( btD.en )
  836. {
  837. btD.time += deltaTime; btD.t += deltaTime;
  838. if( btD.time >= btD.timeMax )
  839. {
  840. btD.time = 0.0f; dy++;
  841. if( btD.timeMax >= rpTime )
  842. {
  843. btD.timeMax = ctTime; btD.t = 0.0f;
  844. }
  845. else
  846. btD.timeMax = Lerp(ctTime,mnTime,coremin(1.0f,btD.t/reTime));
  847. }
  848. }
  849. break;
  850. }
  851. switch( stL )
  852. {
  853. case CST_ACTIVATED:
  854. btL.start(rpTime); dx--;
  855. break;
  856. case CST_INACTIVATED:
  857. btL.en = false;
  858. break;
  859. case CST_ACTIVE:
  860. if( btL.en )
  861. {
  862. btL.time += deltaTime; btL.t += deltaTime;
  863. if( btL.time >= btL.timeMax )
  864. {
  865. btL.time = 0.0f; dx--;
  866. if( btL.timeMax >= rpTime )
  867. {
  868. btL.timeMax = ctTime; btL.t = 0.0f;
  869. }
  870. else
  871. btL.timeMax = Lerp(ctTime,mnTime,coremin(1.0f,btL.t/reTime));
  872. }
  873. }
  874. break;
  875. }
  876. switch( stR )
  877. {
  878. case CST_ACTIVATED:
  879. btR.start(rpTime); dx++;
  880. break;
  881. case CST_INACTIVATED:
  882. btR.en = false;
  883. break;
  884. case CST_ACTIVE:
  885. if( btR.en )
  886. {
  887. btR.time += deltaTime; btR.t += deltaTime;
  888. if( btR.time >= btR.timeMax )
  889. {
  890. btR.time = 0.0f; dx++;
  891. if( btR.timeMax >= rpTime )
  892. {
  893. btR.timeMax = ctTime; btR.t = 0.0f;
  894. }
  895. else
  896. btR.timeMax = Lerp(ctTime,mnTime,coremin(1.0f,btR.t/reTime));
  897. }
  898. }
  899. break;
  900. }
  901. if( dy )
  902. {
  903. if( dy < 0 )
  904. MoveUp();
  905. else
  906. MoveDown();
  907. }
  908. if( dx )
  909. {
  910. if( dx < 0 )
  911. MoveLeft();
  912. else
  913. MoveRight();
  914. }
  915. }
  916. const float AccelerationFactor = 1.0f;
  917. if( m_state != Normal )
  918. {
  919. /* m_curScrollTime += deltaTime;
  920. if( m_curScrollTime > m_scrollTime )
  921. {
  922. m_curScrollTime = m_scrollTime;
  923. m_state = Normal;
  924. }
  925. float k = m_curScrollTime/m_scrollTime;
  926. float x = Lerp(m_from.x,m_to.x,k);
  927. float y = Lerp(m_from.y,m_to.y,k);
  928. ScrollTo(x,y);*/
  929. float px = GetOffsetX();
  930. float py = GetOffsetY();
  931. float scr = sqrtf(m_scrolSpeed);
  932. // float k = deltaTime*20.0f*m_scrolSpeed;
  933. float k = deltaTime*20.0f*scr;
  934. float dx = (m_to.x - px);
  935. float dy = (m_to.y - py);
  936. dx = sign(dx)*sqrtf(fabsf(dx));
  937. dy = sign(dy)*sqrtf(fabsf(dy));
  938. dx *= k;
  939. dy *= k;
  940. if( fabsf(dx) >= fabsf(px - m_to.x))
  941. {
  942. dx = m_to.x - px;
  943. }
  944. if( fabsf(dy) >= fabsf(py - m_to.y))
  945. {
  946. dy = m_to.y - py;
  947. }
  948. px += dx;
  949. py += dy;
  950. // if( px == GetOffsetX() && py == GetOffsetY())
  951. if( px == m_to.x && py == m_to.y )
  952. m_state = Normal;
  953. ScrollTo(px,py);
  954. m_dx = m_to.x - px;
  955. m_dy = m_to.y - py;
  956. /* m_tt += deltaTime;
  957. if( m_tt >= m_tmax )
  958. m_tt = m_tmax;
  959. float px = GetOffsetX();
  960. float py = GetOffsetY();
  961. float t = m_tt;
  962. float t2 = t*t;
  963. float dx = m_xv*t + 0.5f*m_xa*t2;
  964. float dy = m_yv*t + 0.5f*m_ya*t2;
  965. // if( fabsf(dx) >= fabsf(px - m_to.x))
  966. // {
  967. // dx = m_to.x - px;
  968. // }
  969. // if( fabsf(dy) >= fabsf(py - m_to.y))
  970. // {
  971. // dy = m_to.y - py;
  972. // }
  973. px = m_from.x + dx;
  974. py = m_from.y + dy;
  975. // if( px == m_to.x && py == m_to.y )
  976. // if( fabsf(px - m_to.x) <= 1.0f && fabsf(py - m_to.y) <= 1.0f )
  977. if( m_tt >= m_tmax )
  978. m_state = Normal;
  979. ScrollTo(px,py);
  980. m_dx = m_to.x - px;
  981. m_dy = m_to.y - py;*/
  982. }
  983. }
  984. void GUISelector::UpdateElements(float deltaTime, bool instant)
  985. {
  986. // const int kn = 3;
  987. int kn = m_scales;
  988. // static float _sk[kn] = {1.3f,1.15f,1.0f};
  989. // static float _ak[kn] = {1.0f,0.80f,0.6f};
  990. // const float upk = 0.02f;
  991. const float upk = 2.50f;
  992. // const float rek = 0.02f;
  993. if( curLine >= 0 && curItem >= 0 )
  994. {
  995. float px = GetOffsetX();
  996. float py = GetOffsetY();
  997. float et = m_state == Normal ? 0.0f : sqrtf((m_to.x - px)*(m_to.x - px) + (m_to.y - py)*(m_to.y - py));
  998. et *= 0.2f;
  999. float kk = deltaTime*upk*m_scaleSpeed;
  1000. float dd = 1.0f/(0.5f + et*et);
  1001. //////////////////////////////////////////////
  1002. // Поддерживаем пока только одномерный лист //
  1003. //////////////////////////////////////////////
  1004. int n = lines[0].items;
  1005. bool hor = n > 1;
  1006. if( !hor )
  1007. n = lines;
  1008. int li = 0;
  1009. int ii = 0;
  1010. for( int i = 0 ; i < n ; i++ )
  1011. {
  1012. int k = 0;
  1013. if( hor )
  1014. {
  1015. k = abs(ii - curItem);
  1016. if( m_isLooped )
  1017. {
  1018. int t = curItem > ii ? n - curItem + ii : n - ii + curItem;
  1019. if( k > t )
  1020. k = t;
  1021. }
  1022. }
  1023. else
  1024. {
  1025. k = abs(li - curLine);
  1026. if( m_isLooped )
  1027. {
  1028. int t = curLine > li ? n - curLine + li : n - li + curLine;
  1029. if( k > t )
  1030. k = t;
  1031. }
  1032. }
  1033. float sk = 1.0f;
  1034. float ak = 1.0f;
  1035. float ck = 1.0f;
  1036. long draw = 0;
  1037. if( kn > 0 )
  1038. {
  1039. if( k > kn - 1 )
  1040. k = kn - 1;
  1041. sk = m_scales[k];
  1042. ak = m_alphas[k]; draw = m_drawps[k];
  1043. ck = m_scales[0];
  1044. }
  1045. // float sk = _sk[k];
  1046. // float ak = _ak[k];
  1047. if( !lines[li].items )
  1048. continue;
  1049. Item &item = lines[li].items[ii];
  1050. if( item.q )
  1051. {
  1052. if( item.k != sk || item.a != ak )
  1053. {
  1054. if( /*edit_mode*/instant )
  1055. {
  1056. item.k = sk;
  1057. }
  1058. else
  1059. {
  1060. float dk = (sk - item.k)*dd;
  1061. dk = sign(dk)*sqrtf(fabsf(dk));
  1062. dk *= kk;
  1063. if( fabsf(dk) > fabsf(sk - item.k))
  1064. dk = sk - item.k;
  1065. item.k += dk;
  1066. }
  1067. float iw = itemWidth/m_aspect;
  1068. float ih = itemHeight;
  1069. float w = iw*item.k;
  1070. float h = ih*item.k;
  1071. item.q->SizeTo(w,h);
  1072. item.q->SetFontScale(item.k);
  1073. float x = ii*(iw + horSpace/m_aspect);
  1074. float y = li*(ih + verSpace);
  1075. if( m_bottom && hor )
  1076. y += 0.5f*(ih*(ck - item.k) + (GetHeight() - ih*ck));
  1077. item.q->MoveTo(x - 0.5f*(w - iw),y - 0.5f*(h - ih));
  1078. if( /*edit_mode*/instant )
  1079. {
  1080. item.a = ak;
  1081. }
  1082. else
  1083. {
  1084. float da = (ak - item.a)*kk;
  1085. da = sign(da)*sqrtf(fabsf(da));
  1086. if( fabsf(da) > fabsf(ak - item.a))
  1087. da = ak - item.a;
  1088. item.a += da;
  1089. }
  1090. item.q->SetAlpha(item.a);
  1091. }
  1092. if( item.draw != draw )
  1093. {
  1094. item.q->ResetDrawUpdate(item.draw = draw);
  1095. }
  1096. }
  1097. if( hor )
  1098. ii++;
  1099. else
  1100. li++;
  1101. }
  1102. if( curLine < lines && curItem < lines[curLine].items )
  1103. {
  1104. const Item &cur = lines[curLine].items[curItem];
  1105. GUIWidget *mark = (GUIWidget *)marker.Ptr();
  1106. if( mark && cur.q )
  1107. {
  1108. float x,y;
  1109. cur.q->GetNativePos(x,y);
  1110. float w = markerScale*cur.q->GetWidth();
  1111. float h = markerScale*cur.q->GetHeight();
  1112. x -= 0.5f*(w - cur.q->GetWidth());
  1113. y -= 0.5f*(h - cur.q->GetHeight());
  1114. mark->MoveTo(x,y);
  1115. mark->SizeTo(w,h);
  1116. }
  1117. }
  1118. }
  1119. }
  1120. void GUISelector::Draw()
  1121. {
  1122. if( InterfaceUtils::IsHide())
  1123. return;
  1124. Rect r; GetRect(r,false);
  1125. float x = r.l; float width = r.r - r.l;
  1126. float y = r.t; float height = r.b - r.t;
  1127. if( m_texture[0] )
  1128. {
  1129. m_quadRender.DrawQuad(x,y,width,height,0.0f,0.0f,
  1130. 1.0f,1.0f,10.0f + GetAlpha()*m_texAlpha);
  1131. }
  1132. if( EditMode_IsOn() /*&& m_useClipping*/ && !m_texture[0] )
  1133. {
  1134. m_helperQuad.DrawQuad(x,y,width,height,0.0f,0.0f,
  1135. 0.0f,0.0f,10.3f);
  1136. }
  1137. }
  1138. void _cdecl GUISelector::Draw(float deltaTime, long)
  1139. {
  1140. if( EditMode_IsOn())
  1141. return;
  1142. /* if( curLine >= 0 && curItem >= 0 )
  1143. {
  1144. const Item &item = lines[curLine].items[curItem];
  1145. if( item.p )
  1146. {
  1147. bool b = item.p->Is(InterfaceUtils::GetButtonId());
  1148. if( m_state != Normal )
  1149. {
  1150. float a = m_curScrollTime/m_scrollTime;
  1151. if( !b )
  1152. item.p->SetAlpha(0.6f + a*0.4f);
  1153. // if( befLine >= 0 && befItem >= 0 )
  1154. // {
  1155. // const Item &prev = lines[befLine].items[befItem];
  1156. // if( prev.p && !prev.p->Is(InterfaceUtils::GetButtonId()))
  1157. // prev.p->SetAlpha(1.0f - a*0.4f);
  1158. // }
  1159. }
  1160. else
  1161. {
  1162. if( !b )
  1163. item.p->SetAlpha(1.0f);
  1164. }
  1165. }
  1166. if( m_state != Normal )
  1167. {
  1168. float a = m_curScrollTime/m_scrollTime;
  1169. if( befLine >= 0 && befItem >= 0 )
  1170. {
  1171. const Item &prev = lines[befLine].items[befItem];
  1172. if( prev.p && !prev.p->Is(InterfaceUtils::GetButtonId()))
  1173. prev.p->SetAlpha(1.0f - a*0.4f);
  1174. }
  1175. }
  1176. }*/
  1177. if( IsActive())
  1178. {
  1179. if( Controls().GetControlStateType(m_sel) == CST_ACTIVATED )
  1180. {
  1181. if( curLine >= 0 && curItem >= 0 )
  1182. {
  1183. Item &item = lines[curLine].items[curItem];
  1184. if( item.q && item.q->Is(InterfaceUtils::GetButtonId()))
  1185. ;
  1186. else
  1187. {
  1188. if( item.open )
  1189. {
  1190. LogicDebug("Item [%d,%d]: select trigger",curLine,curItem);
  1191. item.onSel.Activate(Mission(),false);
  1192. }
  1193. else
  1194. {
  1195. LogicDebug("Item [%d,%d]: try trigger",curLine,curItem);
  1196. item.onTry.Activate(Mission(),false);
  1197. }
  1198. }
  1199. }
  1200. }
  1201. }
  1202. /* //// обработка мыши ////
  1203. if( EditMode_IsOn())
  1204. return;
  1205. if( !IsActive())
  1206. return;
  1207. if( m_state != Normal )
  1208. return;
  1209. if( !m_cursor )
  1210. m_cursor = (BaseGUICursor *)FindObject(InterfaceUtils::GetCursorName());
  1211. if( !m_cursor || m_cursor->IsHided())
  1212. return;
  1213. float x,y; m_cursor->GetPosition(x,y);
  1214. float _x = x;
  1215. float _y = y;
  1216. Rect rect; GetClipRect(rect);
  1217. x *= 100;
  1218. y *= 100;
  1219. if( !PointInRect(x,y,rect))
  1220. return;
  1221. float _X = GetX(false);
  1222. float _Y = GetY(false);
  1223. x -= _X;
  1224. y -= _Y;
  1225. float sx = 0.0f;
  1226. float sy = 0.0f;
  1227. // Rect r; GetRect(r);
  1228. // float width = r.r - r.l;
  1229. // float height = r.b - r.t;
  1230. // if( centered )
  1231. // {
  1232. // // sx = -0.5f*(width - itemWidth );
  1233. // // sy = -0.5f*(height - itemHeight);
  1234. // }
  1235. int i = int((y - GetOffsetY() - sy)/itemHeight);
  1236. int j = int((x - GetOffsetX() - sx)/itemWidth );
  1237. if( i >= 0 && i < lines )
  1238. {
  1239. Line &line = lines[i];
  1240. if( line.items > 0 )
  1241. {
  1242. bool lsh = false;
  1243. bool rsh = false;
  1244. if( m_isLooped )
  1245. {
  1246. int last = line.items - 1;
  1247. if( j < 0 )
  1248. {
  1249. j = last; lsh = true;
  1250. }
  1251. else
  1252. if( j > last )
  1253. {
  1254. j = 0; rsh = true;
  1255. }
  1256. }
  1257. if( j >= 0 && j < line.items )
  1258. {
  1259. bool en = true; BaseGUIElement *q = lines[i].items[j].q;
  1260. if( q && q->Is(InterfaceUtils::GetButtonId()))
  1261. {
  1262. Rect r; q->GetRect(r);
  1263. if( PointInRect(_x*100.0f,_y*100.0f,r))
  1264. en = false;
  1265. }
  1266. if( en )
  1267. {
  1268. if( i != curLine || j != curItem || scroll_x != 0.0f || scroll_y != 0.0f )
  1269. {
  1270. if( Controls().GetControlStateType("LeftMouseButton") == CST_ACTIVATED )
  1271. {
  1272. float lb = _X + GetOffsetX() + curItem*itemWidth;
  1273. float tb = _Y + GetOffsetY() + curLine*itemHeight;
  1274. befLine = curLine;
  1275. curLine = i;
  1276. befItem = curItem;
  1277. curItem = j;
  1278. maxItem = curItem;
  1279. if( lsh )
  1280. {
  1281. ScrollTo(
  1282. GetOffsetX() - GetFullW(),
  1283. GetOffsetY());
  1284. }
  1285. else
  1286. if( rsh )
  1287. {
  1288. ScrollTo(
  1289. GetOffsetX() + GetFullW(),
  1290. GetOffsetY());
  1291. }
  1292. UpdatePos(_x*100.0f < lb,_y*100.0f < tb);
  1293. }
  1294. }
  1295. if( Controls().GetControlStateType("LeftMouseDbl") == CST_ACTIVATED )
  1296. {
  1297. Item &item = lines[i].items[j];
  1298. if( item.q->Is(InterfaceUtils::GetButtonId()))
  1299. ;
  1300. else
  1301. {
  1302. LogicDebug("Item [%d,%d]: select trigger",i,j);
  1303. item.onSel.Activate(Mission(),false);
  1304. }
  1305. }
  1306. }
  1307. }
  1308. }
  1309. }*/
  1310. }
  1311. void GUISelector::ReleaseItems()
  1312. {
  1313. for( int i = 0 ; i < lines ; i++ )
  1314. {
  1315. Line &line = lines[i];
  1316. for( int j = 0 ; j < line.items ; j++ )
  1317. {
  1318. Item &item = line.items[j];
  1319. BaseGUIElement *normal = (BaseGUIElement *)item.normal.p.Ptr();
  1320. if( normal )
  1321. {
  1322. normal->Restrict(preserveNone);
  1323. normal->ReCreate();
  1324. }
  1325. BaseGUIElement *closed = (BaseGUIElement *)item.closed.p.Ptr();
  1326. if( closed )
  1327. {
  1328. closed->Restrict(preserveNone);
  1329. closed->ReCreate();
  1330. }
  1331. item.q = null;
  1332. }
  1333. }
  1334. UnRegisterAll();
  1335. for( int i = 0 ; i < 2 ; i++ )
  1336. {
  1337. Progress &prog = progs[i];
  1338. csProgressBar *p = (csProgressBar *)prog.p.Ptr();
  1339. if( p )
  1340. {
  1341. p->Restrict(preserveNone);
  1342. p->ReCreate();
  1343. }
  1344. }
  1345. for( int i = 0 ; i < 4 ; i++ )
  1346. {
  1347. Button &butt = butts[i];
  1348. GUIButton *p = (GUIButton *)butt.p.Ptr();
  1349. if( p )
  1350. {
  1351. p->Restrict(preserveNone);
  1352. p->ReCreate();
  1353. }
  1354. }
  1355. GUIWidget *mark = (GUIWidget *)marker.Ptr();
  1356. if( mark )
  1357. {
  1358. mark->Restrict(preserveNone);
  1359. mark->ReCreate();
  1360. }
  1361. }
  1362. void GUISelector::ResetItems()
  1363. {
  1364. UnRegisterAll();
  1365. float y = 0.0f;
  1366. float cscal = m_scales ? m_scales[0] : 1.0f;
  1367. float scale = m_scales ? m_scales.LastE() : 1.0f;
  1368. float alpha = m_alphas ? m_alphas.LastE() : 1.0f;
  1369. long draw = m_drawps ? m_drawps.LastE() : 0;
  1370. float iw = itemWidth/m_aspect;
  1371. float ih = itemHeight;
  1372. float sw = scale*iw;
  1373. float sh = scale*ih;
  1374. float dx = 0.5f*(iw - sw);
  1375. float dy = 0.5f*(ih - sh);
  1376. bool hor = lines && lines[0].items > 1;
  1377. if( m_bottom && hor )
  1378. dy += 0.5f*(ih*(cscal - scale) + (GetHeight() - ih*cscal));
  1379. for( int i = 0 ; i < lines ; i++ )
  1380. {
  1381. Line &line = lines[i];
  1382. float x = 0.0f;
  1383. for( int j = 0 ; j < line.items ; j++ )
  1384. {
  1385. Item &item = line.items[j];
  1386. BaseGUIElement *normal = (BaseGUIElement *)item.normal.p.Ptr();
  1387. if( normal )
  1388. {
  1389. normal->SetParent(GetObjectID());
  1390. if( normal->Is(InterfaceUtils::GetButtonId()))
  1391. {
  1392. normal->MoveTo(
  1393. x + (itemWidth - normal->GetWidth ())*0.5f,
  1394. y + (itemHeight - normal->GetHeight())*0.5f);
  1395. }
  1396. else
  1397. {
  1398. normal->MoveTo(x + dx,y + dy);
  1399. normal->SizeTo(sw,sh);
  1400. normal->SetAlpha(alpha);
  1401. if( normal->Is(InterfaceUtils::GetWidgetId()))
  1402. {
  1403. ((GUIWidget *)normal)->SetAlphaOriginal(alpha);
  1404. }
  1405. // item.a = alpha;
  1406. // item.k = scale;
  1407. item.a = -1.0f;
  1408. item.k = -1.0f;
  1409. item.draw = draw;
  1410. }
  1411. normal->SetShiftAspect(false);
  1412. normal->SetWidthAspect(false);
  1413. normal->SetLayout(OnLeft);
  1414. normal->Restrict(preservePos|preserveSize|preserveParent|preserveLayout);
  1415. normal->Show( item.open);
  1416. Register(normal);
  1417. }
  1418. BaseGUIElement *closed = (BaseGUIElement *)item.closed.p.Ptr();
  1419. if( closed )
  1420. {
  1421. closed->SetParent(GetObjectID());
  1422. if( closed->Is(InterfaceUtils::GetButtonId()))
  1423. {
  1424. closed->MoveTo(
  1425. x + (itemWidth - closed->GetWidth ())*0.5f,
  1426. y + (itemHeight - closed->GetHeight())*0.5f);
  1427. }
  1428. else
  1429. {
  1430. closed->MoveTo(x + dx,y + dy);
  1431. closed->SizeTo(sw,sh);
  1432. closed->SetAlpha(alpha);
  1433. if( closed->Is(InterfaceUtils::GetWidgetId()))
  1434. {
  1435. ((GUIWidget *)closed)->SetAlphaOriginal(alpha);
  1436. }
  1437. // item.a = alpha;
  1438. // item.k = scale;
  1439. item.a = -1.0f;
  1440. item.k = -1.0f;
  1441. item.draw = draw;
  1442. }
  1443. closed->SetShiftAspect(false);
  1444. closed->SetWidthAspect(false);
  1445. closed->SetLayout(OnLeft);
  1446. closed->Restrict(preservePos|preserveSize|preserveParent|preserveLayout);
  1447. closed->Show(!item.open);
  1448. Register(closed);
  1449. }
  1450. item.q = item.open ? normal : closed;
  1451. x += (itemWidth + horSpace)/m_aspect;
  1452. }
  1453. y += itemHeight + verSpace;
  1454. }
  1455. Rect r; GetRect(r,false);
  1456. float x = r.l;
  1457. y = r.t;
  1458. float w = r.r - r.l;
  1459. float h = r.b - r.t;
  1460. float bw = btnWidth;
  1461. float bh = btnHeight;
  1462. for( int i = 0 ; i < 2 ; i++ )
  1463. {
  1464. Progress &prog = progs[i];
  1465. csProgressBar *p = (csProgressBar *)prog.p.Ptr();
  1466. if( p )
  1467. {
  1468. p->SetParent(ConstString());
  1469. switch( i )
  1470. {
  1471. case 0:
  1472. {
  1473. float off = p->GetNativeX()*m_aspect;
  1474. p->SizeTo(
  1475. w - (bw + off)*2,
  1476. p->GetHeight());
  1477. p->MoveTo(
  1478. (x + bw + off)/m_aspect,
  1479. y + h + (bh - p->GetHeight())*0.5f);
  1480. p->SetMax((float)0);
  1481. p->SetPos((float)0);
  1482. } break;
  1483. case 1:
  1484. {
  1485. if( lines.Size() < 2 )
  1486. {
  1487. p->SizeTo( 0.0f, 0.0f);
  1488. p->MoveTo(100.0f,100.0f);
  1489. }
  1490. else
  1491. {
  1492. p->SizeTo(
  1493. p->GetWidth()*m_aspect,
  1494. h - (bh + p->GetNativeY())*2);
  1495. p->MoveTo(
  1496. (x + w + (bw - p->GetWidth())*0.5f)/m_aspect,
  1497. y + bh + p->GetNativeY());
  1498. }
  1499. p->SetMax((float)(lines.Size() - 1));
  1500. p->SetPos((float)(curLine));
  1501. } break;
  1502. }
  1503. p->SetLayout(OnLeft);
  1504. p->Restrict(preservePos|preserveSize|preserveParent);
  1505. }
  1506. }
  1507. for( int i = 0 ; i < 4 ; i++ )
  1508. {
  1509. Button &butt = butts[i];
  1510. GUIButton *p = (GUIButton *)butt.p.Ptr();
  1511. if( p )
  1512. {
  1513. p->SetParent(ConstString());
  1514. switch( i )
  1515. {
  1516. case 0:
  1517. if( lines.Size() < 2 )
  1518. p->MoveTo(100.0f,100.0f);
  1519. else
  1520. p->MoveTo((x + w)/m_aspect,y);
  1521. break;
  1522. case 1:
  1523. if( lines.Size() < 2 )
  1524. p->MoveTo(100.0f,100.0f);
  1525. else
  1526. p->MoveTo((x + w)/m_aspect,y + h - bh);
  1527. break;
  1528. case 2:
  1529. if( lines.Size() < 2 && !progs[0].p.Ptr())
  1530. p->MoveTo(
  1531. (x - bw)/m_aspect,
  1532. y + (h - bh)*0.5f);
  1533. else
  1534. p->MoveTo(x/m_aspect,y + h);
  1535. break;
  1536. case 3:
  1537. if( lines.Size() < 2 && !progs[0].p.Ptr())
  1538. p->MoveTo(
  1539. (x + w)/m_aspect,
  1540. y + (h - bh)*0.5f);
  1541. else
  1542. p->MoveTo((x + w - bw)/m_aspect,y + h);
  1543. break;
  1544. }
  1545. p->SizeTo(btnWidth/m_aspect,btnHeight);
  1546. p->SetLayout(OnLeft);
  1547. p->Restrict(preservePos|preserveSize|preserveParent);
  1548. }
  1549. }
  1550. GUIWidget *mark = (GUIWidget *)marker.Ptr();
  1551. if( mark )
  1552. {
  1553. mark->SetParent(GetObjectID());
  1554. mark->SetLayout(OnLeft);
  1555. // mark->SizeTo(itemWidth/m_aspect,itemHeight);
  1556. mark->Restrict(preservePos/*|preserveSize*/|preserveParent);
  1557. }
  1558. }
  1559. void GUISelector::Show(bool isShow)
  1560. {
  1561. bool sh = IsShow();
  1562. BaseGUIElement::Show(isShow);
  1563. DelUpdate(&GUISelector::Work);
  1564. // DelUpdate(&GUISelector::Draw);
  1565. if( IsShow())
  1566. {
  1567. // SetUpdate(&GUISelector::Work,drawLevel);
  1568. // SetUpdate(&GUISelector::Draw,drawLevel + 2000);
  1569. // BaseGUIElement *parent = GetParent();
  1570. long level = drawLevel;
  1571. /* if( parent )
  1572. level = parent->GetDrawLevel() + 100;*/
  1573. if( GetAlpha() > 0.0f )
  1574. {
  1575. SetUpdate(&GUISelector::Work,level + drawPriority);
  1576. // SetUpdate(&GUISelector::Draw,level + drawPriority + 2000);
  1577. }
  1578. }
  1579. if( !IsActive())
  1580. return;
  1581. if( isShow != sh )
  1582. {
  1583. if( IsShow())
  1584. {
  1585. UpdateElements(0.0f,true);
  1586. }
  1587. if( lines > 0 && curLine >= 0 && curLine < lines )
  1588. {
  1589. if( lines[curLine].items > 0 && curItem >= 0 && curItem < lines[curLine].items )
  1590. {
  1591. if( isShow )
  1592. {
  1593. LogicDebug("Item [%d,%d]: getFocus trigger",curLine,curItem);
  1594. lines[curLine].items[curItem].onFoc.Activate(Mission(),false);
  1595. }
  1596. else
  1597. {
  1598. LogicDebug("Item [%d,%d]: losFocus trigger",curLine,curItem);
  1599. lines[curLine].items[curItem].onLea.Activate(Mission(),false);
  1600. }
  1601. }
  1602. }
  1603. }
  1604. }
  1605. void GUISelector::Activate(bool isActive)
  1606. {
  1607. bool act = IsActive();
  1608. BaseGUIElement::Activate(isActive);
  1609. if( !IsShow())
  1610. return;
  1611. if( isActive != act && !m_silentActivate )
  1612. {
  1613. if( lines > 0 && curLine >= 0 && curLine < lines )
  1614. {
  1615. if( lines[curLine].items > 0 && curItem >= 0 && curItem < lines[curLine].items )
  1616. {
  1617. if( isActive )
  1618. {
  1619. LogicDebug("Item [%d,%d]: getFocus trigger",curLine,curItem);
  1620. lines[curLine].items[curItem].onFoc.Activate(Mission(),false);
  1621. }
  1622. else
  1623. {
  1624. LogicDebug("Item [%d,%d]: losFocus trigger",curLine,curItem);
  1625. lines[curLine].items[curItem].onLea.Activate(Mission(),false);
  1626. }
  1627. }
  1628. }
  1629. }
  1630. }
  1631. void GUISelector::ScrollHor(float dx)
  1632. {
  1633. m_from.x = GetOffsetX();
  1634. m_from.y = GetOffsetY();
  1635. m_state = HScrolling;
  1636. float k = fabsf(dx)/itemWidth;
  1637. if( k == 0.0f )
  1638. k = 0.5f;
  1639. m_scrollLength = dx;
  1640. m_scrollTime = 0.3f*k;
  1641. m_curScrollTime = 0.0f;
  1642. m_to = m_from;
  1643. m_to.x += m_scrollLength;
  1644. /* m_rect = GetFullRect();*/ Rect r; GetRect(r,false);
  1645. m_rect.l = 0.0f;
  1646. m_rect.t = 0.0f;
  1647. float width = r.r - r.l;
  1648. float height = r.b - r.t;
  1649. float max_w = maxWidth*(itemWidth + horSpace);
  1650. float max_h = lines.Size()*(itemHeight + verSpace);
  1651. if( maxWidth > 0 )
  1652. max_w -= horSpace;
  1653. if( lines.Size() > 0 )
  1654. max_h -= verSpace;
  1655. if( max_w < width )
  1656. max_w = width;
  1657. if( max_h < height )
  1658. max_h = height;
  1659. m_rect.r = m_rect.l + max_w;
  1660. m_rect.b = m_rect.t + max_h;
  1661. if( centered )
  1662. {
  1663. float sx = 0.5f*(width - itemWidth);
  1664. float sy = 0.5f*(height - itemHeight);
  1665. m_rect.l -= sx;
  1666. m_rect.r += sx;
  1667. m_rect.t -= sy;
  1668. m_rect.b += sy;
  1669. }
  1670. if( m_isLooped == false )
  1671. {
  1672. if( m_to.x > -m_rect.l )
  1673. m_to.x = -m_rect.l;
  1674. if( m_to.x < -m_rect.r + width )
  1675. m_to.x = -m_rect.r + width;
  1676. }
  1677. // float R = m_to.x - m_from.x;
  1678. /* R = sign(R)*sqrtf(fabsf(R));
  1679. float K = 10.0f;
  1680. m_xv = K*R;
  1681. m_xa = -0.5f*K*K;*/
  1682. /* m_xa = -R*0.5f;
  1683. m_xv = R;*/
  1684. /* float R = m_to.x - m_from.x;
  1685. m_xv = R*3.0f*m_scrolSpeed;
  1686. float T = 2.0f*R/m_xv;
  1687. m_xa = 2.0f*(R - m_xv*T)/(T*T);
  1688. // m_xa = -(m_xv*m_xv)/(2.0f*R);
  1689. m_tt = 0.0f; m_tmax = T;*/
  1690. csProgressBar *p = (csProgressBar *)progs[0].p.Ptr();
  1691. if( p )
  1692. {
  1693. p->SetMax((float)(lines[curLine].items.Size() - 1));
  1694. p->SetPos((float)(curItem));
  1695. }
  1696. }
  1697. void GUISelector::ScrollVer(float dy)
  1698. {
  1699. if( dy == 0.0f )
  1700. {
  1701. csProgressBar *p = (csProgressBar *)progs[1].p.Ptr();
  1702. if( p )
  1703. {
  1704. p->SetMax((float)(lines.Size() - 1));
  1705. p->SetPos((float)(curLine));
  1706. }
  1707. return;
  1708. }
  1709. m_from.x = GetOffsetX();
  1710. m_from.y = GetOffsetY();
  1711. m_state = VScrolling;
  1712. float k = fabsf(dy)/itemHeight;
  1713. if( k == 0.0f )
  1714. k = 0.5f;
  1715. m_scrollLength = dy;
  1716. float time = 0.3f*k;
  1717. if( m_scrollTime < time )
  1718. m_scrollTime = time;
  1719. m_to.y += m_scrollLength;
  1720. /* m_rect = GetFullRect();*/ Rect r; GetRect(r,false);
  1721. m_rect.l = 0.0f;
  1722. m_rect.t = 0.0f;
  1723. float width = r.r - r.l;
  1724. float height = r.b - r.t;
  1725. float max_w = maxWidth*(itemWidth + horSpace);
  1726. float max_h = lines.Size()*(itemHeight + verSpace);
  1727. if( maxWidth > 0 )
  1728. max_w -= horSpace;
  1729. if( lines.Size() > 0 )
  1730. max_h -= verSpace;
  1731. if( max_w < width )
  1732. max_w = width;
  1733. if( max_h < height )
  1734. max_h = height;
  1735. m_rect.r = m_rect.l + max_w;
  1736. m_rect.b = m_rect.t + max_h;
  1737. if( centered )
  1738. {
  1739. float sx = 0.5f*(width - itemWidth);
  1740. float sy = 0.5f*(height - itemHeight);
  1741. m_rect.l -= sx;
  1742. m_rect.r += sx;
  1743. m_rect.t -= sy;
  1744. m_rect.b += sy;
  1745. }
  1746. if( m_isLooped == false )
  1747. {
  1748. if( m_to.y > -m_rect.t )
  1749. m_to.y = -m_rect.t;
  1750. if( m_to.y < -m_rect.b + height )
  1751. m_to.y = -m_rect.b + height;
  1752. }
  1753. // float R = m_to.y - m_from.y;
  1754. /* R = sign(R)*sqrtf(fabsf(R));
  1755. float K = 10.0f;
  1756. m_yv = K*R;
  1757. m_ya = -0.5f*K*K;*/
  1758. /* m_ya = -R*0.5f;
  1759. m_yv = R;*/
  1760. /* float R = m_to.y - m_from.y;
  1761. m_yv = R*3.0f*m_scrolSpeed;
  1762. float T = 2.0f*R/m_yv;
  1763. m_ya = 2.0f*(R - m_yv*T)/(T*T);
  1764. // m_ya = -(m_yv*m_yv)/(2.0f*R);
  1765. m_tt = 0.0f; m_tmax = T;*/
  1766. csProgressBar *p = (csProgressBar *)progs[1].p.Ptr();
  1767. if( p )
  1768. {
  1769. p->SetMax((float)(lines.Size() - 1));
  1770. p->SetPos((float)(curLine));
  1771. }
  1772. }
  1773. void GUISelector::UpdatePos(bool left, bool up, bool init, bool onFocActivate)
  1774. {
  1775. Rect r; GetRect(r);
  1776. float px = r.l + curItem*(itemWidth + horSpace);
  1777. float py = r.t + curLine*(itemHeight + verSpace);
  1778. float rx = GetX(false);
  1779. float ry = GetY(false);
  1780. float dx = 0.0f;
  1781. float dy = 0.0f;
  1782. float width = r.r - r.l;
  1783. float height = r.b - r.t;
  1784. if( centered )
  1785. {
  1786. int x_off = befItem - curItem;
  1787. int y_off = befLine - curLine;
  1788. if( x_off )
  1789. {
  1790. if( left )
  1791. {
  1792. if( x_off < 0 )
  1793. x_off = (maxWidth + x_off);
  1794. }
  1795. else
  1796. {
  1797. if( x_off > 0 )
  1798. x_off = -(maxWidth - x_off);
  1799. }
  1800. }
  1801. if( y_off )
  1802. {
  1803. if( up )
  1804. {
  1805. if( y_off < 0 )
  1806. y_off = (lines + y_off);
  1807. }
  1808. else
  1809. {
  1810. if( y_off > 0 )
  1811. y_off = -(lines - y_off);
  1812. }
  1813. }
  1814. dx = (x_off)*(itemWidth + horSpace);
  1815. dy = (y_off)*(itemHeight + verSpace);
  1816. if( m_state != Normal )
  1817. {
  1818. // dx += m_to.x - GetOffsetX();
  1819. // dy += m_to.y - GetOffsetY();
  1820. dx += m_dx;
  1821. dy += m_dy;
  1822. }
  1823. dx += scroll_x;
  1824. dy += scroll_y;
  1825. scroll_x = 0.0f;
  1826. scroll_y = 0.0f;
  1827. }
  1828. else
  1829. {
  1830. if( px < rx )
  1831. {
  1832. dx = rx - px;
  1833. }
  1834. else
  1835. if( px + itemWidth > rx + width)
  1836. {
  1837. dx = rx + width - (px + itemWidth);
  1838. }
  1839. if( py < ry )
  1840. {
  1841. dy = ry - py;
  1842. }
  1843. else
  1844. if( py + itemHeight > ry + height)
  1845. {
  1846. dy = ry + height - (py + itemHeight);
  1847. }
  1848. }
  1849. if( init )
  1850. {
  1851. Scroll(dx,dy);
  1852. csProgressBar *p0 = (csProgressBar *)progs[0].p.Ptr();
  1853. if( p0 )
  1854. {
  1855. p0->SetMax((float)(lines[curLine].items.Size() - 1));
  1856. p0->SetPos((float)(curItem));
  1857. }
  1858. csProgressBar *p1 = (csProgressBar *)progs[1].p.Ptr();
  1859. if( p1 )
  1860. {
  1861. p1->SetMax((float)(lines.Size() - 1));
  1862. p1->SetPos((float)(curLine));
  1863. }
  1864. if( curLine != befLine ||
  1865. curItem != befItem )
  1866. {
  1867. if( befLine >= 0 && befItem >= 0 )
  1868. {
  1869. Item &prev = lines[befLine].items[befItem];
  1870. if( prev.q && prev.q->Is(InterfaceUtils::GetButtonId()))
  1871. {
  1872. // if( GetElementInFocus() == prev.p )
  1873. // SetElementInFocus(this);
  1874. }
  1875. else
  1876. {
  1877. LogicDebug("Item [%d,%d]: losFocus trigger",befLine,befItem);
  1878. prev.onLea.Activate(Mission(),false);
  1879. }
  1880. }
  1881. }
  1882. if( curLine < lines && curItem < lines[curLine].items )
  1883. {
  1884. Item &item = lines[curLine].items[curItem];
  1885. if( item.q && item.q->Is(InterfaceUtils::GetButtonId()))
  1886. item.q->SetFocus();
  1887. else
  1888. {
  1889. if( onFocActivate )
  1890. {
  1891. LogicDebug("Item [%d,%d]: getFocus trigger",curLine,curItem);
  1892. item.onFoc.Activate(Mission(),false);
  1893. }
  1894. }
  1895. }
  1896. }
  1897. else
  1898. {
  1899. ScrollHor(dx);
  1900. ScrollVer(dy);
  1901. if( curLine != befLine ||
  1902. curItem != befItem )
  1903. {
  1904. if( befLine >= 0 && befItem >= 0 )
  1905. {
  1906. Item &prev = lines[befLine].items[befItem];
  1907. // ;
  1908. SetElementInFocus(this);
  1909. if( prev.q && prev.q->Is(InterfaceUtils::GetButtonId()))
  1910. {
  1911. // if( GetElementInFocus() == prev.p )
  1912. // SetElementInFocus(this);
  1913. }
  1914. else
  1915. {
  1916. LogicDebug("Item [%d,%d]: losFocus trigger",befLine,befItem);
  1917. prev.onLea.Activate(Mission(),false);
  1918. }
  1919. }
  1920. Item &item = lines[curLine].items[curItem];
  1921. if( item.q && item.q->Is(InterfaceUtils::GetButtonId()))
  1922. item.q->SetFocus();
  1923. else
  1924. {
  1925. if( onFocActivate )
  1926. {
  1927. LogicDebug("Item [%d,%d]: getFocus trigger",curLine,curItem);
  1928. item.onFoc.Activate(Mission(),false);
  1929. }
  1930. }
  1931. }
  1932. }
  1933. if( curLine >= 0 && curItem >= 0 )
  1934. {
  1935. GUIWidget *mark = (GUIWidget *)marker.Ptr();
  1936. if( mark && curLine < lines && curItem < lines[curLine].items )
  1937. {
  1938. if( lines[curLine].items[curItem].q )
  1939. {
  1940. const Item &cur = lines[curLine].items[curItem];
  1941. float x,y;
  1942. cur.q->GetPosition(x,y);
  1943. float w = cur.k*itemWidth/m_aspect;
  1944. float h = cur.k*itemHeight;
  1945. mark->SizeTo(w*markerScale,h*markerScale);
  1946. float dx = 0.5f*(mark->GetWidth () - w);
  1947. float dy = 0.5f*(mark->GetHeight() - h);
  1948. mark->MoveTo(x*100.0f - dx,y*100.0f - dy);
  1949. }
  1950. }
  1951. }
  1952. }
  1953. void GUISelector::OnChildNotify(BaseGUIElement *p, ChildNotification event)
  1954. {
  1955. Assert(p)
  1956. if( IsActive() == false )
  1957. return;
  1958. /* if( event == ChildSelected )
  1959. {
  1960. int i = p->data_a;
  1961. int j = p->data_b;
  1962. if( i == curLine && j == curItem )
  1963. return;
  1964. if( i >= 0 && i < lines && j >= 0 && j < lines[i].items )
  1965. {
  1966. scroll_x -= (j - curItem)*(itemWidth + horSpace);
  1967. scroll_y -= (i - curLine)*(itemHeight + verSpace);
  1968. befLine = curLine;
  1969. befItem = curItem;
  1970. curLine = i;
  1971. curItem = j;
  1972. Item &prev = lines[befLine].items[befItem];
  1973. if( prev.q && prev.q->Is(InterfaceUtils::GetButtonId()))
  1974. {
  1975. // if( GetElementInFocus() == prev.p )
  1976. // SetElementInFocus(this);
  1977. }
  1978. else
  1979. {
  1980. LogicDebug("Item [%d,%d]: losFocus trigger",befLine,befItem);
  1981. prev.onLea.Activate(Mission(),false);
  1982. }
  1983. m_state = HScrolling;
  1984. m_from.x = m_to.x = GetOffsetX();
  1985. m_from.y = m_to.y = GetOffsetY();
  1986. m_scrollTime = 0.2f; m_curScrollTime = 0.0f;
  1987. // UpdatePos();
  1988. }
  1989. }
  1990. else*/
  1991. if( event == ChildClicked )
  1992. {
  1993. int i = p->data_a;
  1994. int j = p->data_b;
  1995. if( i == curLine && j == curItem )
  1996. return;
  1997. if( i >= 0 && i < lines && j >= 0 && j < lines[i].items )
  1998. {
  1999. BaseGUICursor *cursor = (BaseGUICursor *)m_cursor.Ptr();
  2000. if( cursor )
  2001. {
  2002. float x,y; cursor->GetPosition(x,y);
  2003. x *= 100.0f;
  2004. y *= 100.0f;
  2005. const Item &cur = lines[i].items[j];
  2006. for( int m = 0 ; m < lines ; m++ )
  2007. {
  2008. for( int n = 0 ; n < lines[m].items ; n++ )
  2009. {
  2010. const Item &item = lines[m].items[n];
  2011. if( item.draw > cur.draw )
  2012. {
  2013. if( item.q )
  2014. {
  2015. Rect r; item.q->GetRect(r);
  2016. if( PointInRect(x,y,r))
  2017. return;
  2018. }
  2019. }
  2020. }
  2021. }
  2022. }
  2023. befLine = curLine;
  2024. befItem = curItem;
  2025. curLine = i;
  2026. curItem = j;
  2027. bool le = true;
  2028. bool up = true;
  2029. BaseGUIElement *bef = lines[befLine].items[befItem].q;
  2030. BaseGUIElement *cur = lines[curLine].items[curItem].q;
  2031. if( bef && cur )
  2032. {
  2033. Rect br; bef->GetRect(br);
  2034. Rect cr; cur->GetRect(cr);
  2035. if( cr.l > br.l )
  2036. le = false;
  2037. if( cr.t > br.t )
  2038. up = false;
  2039. }
  2040. if( up && curLine > befLine )
  2041. ScrollTo(
  2042. GetOffsetX(),
  2043. GetOffsetY() - GetFullH());
  2044. else
  2045. if( !up && curLine < befLine )
  2046. ScrollTo(
  2047. GetOffsetX(),
  2048. GetOffsetY() + GetFullH());
  2049. else
  2050. if( le && curItem > befItem )
  2051. ScrollTo(
  2052. GetOffsetX() - GetFullW(),
  2053. GetOffsetY());
  2054. else
  2055. if( !le && curItem < befItem )
  2056. ScrollTo(
  2057. GetOffsetX() + GetFullW(),
  2058. GetOffsetY());
  2059. UpdatePos(le,up);
  2060. }
  2061. }
  2062. else
  2063. if( event == ChildDblClicked )
  2064. {
  2065. if( m_state != Normal )
  2066. return;
  2067. int i = p->data_a;
  2068. int j = p->data_b;
  2069. if( i >= 0 && i < lines && j >= 0 && j < lines[i].items )
  2070. {
  2071. BaseGUICursor *cursor = (BaseGUICursor *)m_cursor.Ptr();
  2072. if( cursor )
  2073. {
  2074. float x,y; cursor->GetPosition(x,y);
  2075. x *= 100.0f;
  2076. y *= 100.0f;
  2077. const Item &cur = lines[i].items[j];
  2078. for( int m = 0 ; m < lines ; m++ )
  2079. {
  2080. for( int n = 0 ; n < lines[m].items ; n++ )
  2081. {
  2082. const Item &item = lines[m].items[n];
  2083. if( item.draw > cur.draw )
  2084. {
  2085. if( item.q )
  2086. {
  2087. Rect r; item.q->GetRect(r);
  2088. if( PointInRect(x,y,r))
  2089. return;
  2090. }
  2091. }
  2092. }
  2093. }
  2094. }
  2095. Item &item = lines[i].items[j];
  2096. if( item.q && item.q->Is(InterfaceUtils::GetButtonId()))
  2097. ;
  2098. else
  2099. {
  2100. if( item.open )
  2101. {
  2102. LogicDebug("Item [%d,%d]: select trigger",i,j);
  2103. item.onSel.Activate(Mission(),false);
  2104. }
  2105. else
  2106. {
  2107. LogicDebug("Item [%d,%d]: try trigger",i,j);
  2108. item.onTry.Activate(Mission(),false);
  2109. }
  2110. }
  2111. }
  2112. }
  2113. }
  2114. void GUISelector::MoveFocus (int i, int j, bool trigger)
  2115. {
  2116. bool up = i < curLine;
  2117. bool le = j < curItem;
  2118. befLine = curLine;
  2119. curLine = i;
  2120. befItem = curItem;
  2121. curItem = j;
  2122. maxItem = curItem;
  2123. ///////////////////////
  2124. if( m_state != Normal )
  2125. {
  2126. ScrollTo(m_to.x,m_to.y); m_state = Normal;
  2127. }
  2128. UpdateElements(0.0f,true);
  2129. ///////////////////////
  2130. UpdatePos(le,up,true,trigger);
  2131. }
  2132. void GUISelector::OpenElement(int i, int j, bool open)
  2133. {
  2134. Item &item = lines[i].items[j];
  2135. if( item.open == open )
  2136. return;
  2137. item.open = open;
  2138. BaseGUIElement *show;
  2139. BaseGUIElement *hide;
  2140. if( open )
  2141. {
  2142. show = (BaseGUIElement *)item.normal.p.Ptr();
  2143. hide = (BaseGUIElement *)item.closed.p.Ptr();
  2144. }
  2145. else
  2146. {
  2147. show = (BaseGUIElement *)item.closed.p.Ptr();
  2148. hide = (BaseGUIElement *)item.normal.p.Ptr();
  2149. }
  2150. if( item.closed.p.Ptr() == null ) // не задан виджет для закрытого состояния
  2151. {
  2152. if( item.q && item.q->Is(InterfaceUtils::GetWidgetId()))
  2153. {
  2154. ((GUIWidget *)item.q)->SetBlack(open == false);
  2155. }
  2156. return;
  2157. }
  2158. if( hide )
  2159. {
  2160. if( show )
  2161. {
  2162. show->Show(true);
  2163. float x,y; hide->GetNativePos(x,y);
  2164. show->MoveTo(x,y);
  2165. show->SizeTo(
  2166. ((BaseGUIElement *)item.normal.p.Ptr())->GetWidth(),
  2167. ((BaseGUIElement *)item.normal.p.Ptr())->GetHeight());
  2168. show->SetAlpha(hide->GetNativeAlpha());
  2169. }
  2170. hide->Show(false);
  2171. }
  2172. item.q = show;
  2173. item.k = 1.0f;
  2174. item.a = 0.6f;
  2175. item.draw -= 1000;
  2176. }
  2177. void GUISelector::MoveUp()
  2178. {
  2179. /* if( m_state != Normal )
  2180. {
  2181. if( curLine >= 0 && curItem >= 0 )
  2182. {
  2183. BaseGUIElement *p = lines[curLine].items[curItem].p;
  2184. if( p->Is(InterfaceUtils::GetButtonId()))
  2185. p->SetFocus();
  2186. }
  2187. return;
  2188. }*/
  2189. if( curLine >= 0 && lines > 1 )
  2190. {
  2191. if( curLine )
  2192. {
  2193. if( lines[curLine - 1].items < 1 )
  2194. return;
  2195. befItem = curItem;
  2196. befLine = curLine;
  2197. curLine--;
  2198. curItem = maxItem;
  2199. if( curItem > lines[curLine].items - 1 )
  2200. curItem = lines[curLine].items - 1;
  2201. UpdatePos(true,true);
  2202. }
  2203. else if( m_isLooped )
  2204. {
  2205. int last = lines.Size() - 1;
  2206. if( lines[last].items < 1 )
  2207. return;
  2208. befItem = curItem;
  2209. befLine = curLine;
  2210. curLine = last;
  2211. curItem = maxItem;
  2212. if( curItem > lines[curLine].items - 1 )
  2213. curItem = lines[curLine].items - 1;
  2214. ScrollTo(
  2215. GetOffsetX(),
  2216. GetOffsetY() - GetFullH());
  2217. UpdatePos(true,true);
  2218. }
  2219. else if( curItem >= 0 )
  2220. {
  2221. BaseGUIElement *q = lines[0].items[curItem].q;
  2222. if( q->Is(InterfaceUtils::GetButtonId()))
  2223. q->SetFocus();
  2224. }
  2225. }
  2226. }
  2227. void GUISelector::MoveDown()
  2228. {
  2229. /* if( m_state != Normal )
  2230. {
  2231. if( curLine >= 0 && curItem >= 0 )
  2232. {
  2233. BaseGUIElement *p = lines[curLine].items[curItem].p;
  2234. if( p->Is(InterfaceUtils::GetButtonId()))
  2235. p->SetFocus();
  2236. }
  2237. return;
  2238. }*/
  2239. if( curLine >= 0 && lines > 1 )
  2240. {
  2241. if( curLine < lines - 1 )
  2242. {
  2243. if( lines[curLine + 1].items < 1 )
  2244. return;
  2245. befItem = curItem;
  2246. befLine = curLine;
  2247. curLine++;
  2248. curItem = maxItem;
  2249. if( curItem > lines[curLine].items - 1 )
  2250. curItem = lines[curLine].items - 1;
  2251. UpdatePos(true,false);
  2252. }
  2253. else if( m_isLooped )
  2254. {
  2255. if( lines[0].items < 1 )
  2256. return;
  2257. befItem = curItem;
  2258. befLine = curLine;
  2259. curLine = 0;
  2260. curItem = maxItem;
  2261. if( curItem > lines[curLine].items - 1 )
  2262. curItem = lines[curLine].items - 1;
  2263. ScrollTo(
  2264. GetOffsetX(),
  2265. GetOffsetY() + GetFullH());
  2266. UpdatePos(true,false);
  2267. }
  2268. else if( curItem >= 0 )
  2269. {
  2270. BaseGUIElement *q = lines.LastE().items[curItem].q;
  2271. if( q->Is(InterfaceUtils::GetButtonId()))
  2272. q->SetFocus();
  2273. }
  2274. }
  2275. }
  2276. void GUISelector::MoveLeft()
  2277. {
  2278. /* if( m_state != Normal )
  2279. {
  2280. if( curLine >= 0 && curItem >= 0 )
  2281. {
  2282. BaseGUIElement *p = lines[curLine].items[curItem].p;
  2283. if( p->Is(InterfaceUtils::GetButtonId()))
  2284. p->SetFocus();
  2285. }
  2286. return;
  2287. }*/
  2288. if( curLine >= 0 )
  2289. {
  2290. if( curItem >= 0 )
  2291. maxItem = curItem;
  2292. if( curItem >= 0 && lines[curLine].items > 1 )
  2293. {
  2294. if( curItem )
  2295. {
  2296. befLine = curLine;
  2297. befItem = curItem;
  2298. curItem--;
  2299. maxItem = curItem;
  2300. UpdatePos(true,true);
  2301. }
  2302. else
  2303. if( m_isLooped )
  2304. {
  2305. befLine = curLine;
  2306. befItem = curItem;
  2307. curItem = lines[curLine].items - 1;
  2308. maxItem = curItem;
  2309. ScrollTo(
  2310. GetOffsetX() - GetFullW(),
  2311. GetOffsetY());
  2312. UpdatePos(true,true);
  2313. }
  2314. else
  2315. {
  2316. BaseGUIElement *q = lines[curLine].items[curItem].q;
  2317. if( q && q->Is(InterfaceUtils::GetButtonId()))
  2318. q->SetFocus();
  2319. }
  2320. }
  2321. }
  2322. }
  2323. void GUISelector::MoveRight()
  2324. {
  2325. /* if( m_state != Normal )
  2326. {
  2327. if( curLine >= 0 && curItem >= 0 )
  2328. {
  2329. BaseGUIElement *p = lines[curLine].items[curItem].p;
  2330. if( p->Is(InterfaceUtils::GetButtonId()))
  2331. p->SetFocus();
  2332. }
  2333. return;
  2334. }*/
  2335. if( curLine >= 0 )
  2336. {
  2337. if( curItem >= 0 )
  2338. maxItem = curItem;
  2339. if( curItem >= 0 && lines[curLine].items > 1 )
  2340. {
  2341. if( curItem < lines[curLine].items - 1 )
  2342. {
  2343. befLine = curLine;
  2344. befItem = curItem;
  2345. curItem++;
  2346. maxItem = curItem;
  2347. UpdatePos(false,true);
  2348. }
  2349. else
  2350. if( m_isLooped )
  2351. {
  2352. befLine = curLine;
  2353. befItem = curItem;
  2354. curItem = 0;
  2355. maxItem = curItem;
  2356. ScrollTo(
  2357. GetOffsetX() + GetFullW(),
  2358. GetOffsetY());
  2359. UpdatePos(false,true);
  2360. }
  2361. else
  2362. {
  2363. BaseGUIElement *q = lines[curLine].items[curItem].q;
  2364. if( q && q->Is(InterfaceUtils::GetButtonId()))
  2365. q->SetFocus();
  2366. }
  2367. }
  2368. }
  2369. }
  2370. void GUISelector::Command(const char *id, dword numParams, const char **params)
  2371. {
  2372. if( !IsActive())
  2373. return;
  2374. if( string::IsEmpty(id))
  2375. return;
  2376. if( string::IsEqual(id,"fadein"))
  2377. {
  2378. Show(true);
  2379. SetFadeState(FadingIn);
  2380. m_fadeTime = 2.0f;
  2381. if( numParams > 0 )
  2382. m_fadeTime = (float)atof(params[0]);
  2383. m_fade = m_fadeTime;
  2384. return;
  2385. }
  2386. else
  2387. if( string::IsEqual(id,"fadeout"))
  2388. {
  2389. if( !IsShow())
  2390. return;
  2391. SetFadeState(FadingOut);
  2392. m_fadeTime = 2.0f;
  2393. if( numParams > 0 )
  2394. m_fadeTime = (float)atof(params[0]);
  2395. m_fade = m_fadeTime;
  2396. m_alphaOriginal = GetNativeAlpha();
  2397. return;
  2398. }
  2399. else
  2400. if( string::IsEqual(id,"up"))
  2401. {
  2402. MoveUp();
  2403. }
  2404. else
  2405. if( string::IsEqual(id,"down"))
  2406. {
  2407. MoveDown();
  2408. }
  2409. else
  2410. if( string::IsEqual(id,"left"))
  2411. {
  2412. MoveLeft();
  2413. }
  2414. else
  2415. if( string::IsEqual(id,"right"))
  2416. {
  2417. MoveRight();
  2418. }
  2419. else
  2420. if( string::IsEqual(id,"focus"))
  2421. {
  2422. if( numParams < 2 )
  2423. {
  2424. LogicDebugError("Command <focus> error. Not enought parameters.");
  2425. return;
  2426. }
  2427. if( !params[0] )
  2428. {
  2429. LogicDebugError("Command <focus> error. Index not specified.");
  2430. return;
  2431. }
  2432. long index = atol(params[0]);
  2433. //////////////////////////////////////////////
  2434. // Поддерживаем пока только одномерный лист //
  2435. //////////////////////////////////////////////
  2436. if( !lines )
  2437. {
  2438. LogicDebugError("Command <focus> error. List is empty.");
  2439. return;
  2440. }
  2441. int n = lines[0].items;
  2442. bool hor = n > 1;
  2443. if( !hor )
  2444. n = lines;
  2445. if( index < n )
  2446. {
  2447. bool newState = false;
  2448. if( params[1] )
  2449. {
  2450. switch( params[1][0] )
  2451. {
  2452. case '1':
  2453. case 't':
  2454. case 'T':
  2455. newState = true;
  2456. break;
  2457. }
  2458. }
  2459. if( hor )
  2460. MoveFocus(0,index,newState);
  2461. else
  2462. MoveFocus(index,0,newState);
  2463. LogicDebug(
  2464. "Command <focus>. Element %i is now focused and %striggered.",index,newState ? "" : "not ");
  2465. }
  2466. else
  2467. {
  2468. LogicDebugError(
  2469. "Command <focus> error. Index value %i not in range [0, %i].",
  2470. index,n);
  2471. return;
  2472. }
  2473. }
  2474. else
  2475. if( string::IsEqual(id,"open"))
  2476. {
  2477. if( numParams < 2 )
  2478. {
  2479. LogicDebugError("Command <open> error. Not enought parameters.");
  2480. return;
  2481. }
  2482. if( !params[0] )
  2483. {
  2484. LogicDebugError("Command <open> error. Index not specified.");
  2485. return;
  2486. }
  2487. long index = atol(params[0]);
  2488. //////////////////////////////////////////////
  2489. // Поддерживаем пока только одномерный лист //
  2490. //////////////////////////////////////////////
  2491. if( !lines )
  2492. {
  2493. LogicDebugError("Command <open> error. List is empty.");
  2494. return;
  2495. }
  2496. int n = lines[0].items;
  2497. bool hor = n > 1;
  2498. if( !hor )
  2499. n = lines;
  2500. if( index < n )
  2501. {
  2502. bool newState = false;
  2503. if( params[1] )
  2504. {
  2505. switch( params[1][0] )
  2506. {
  2507. case '1':
  2508. case 't':
  2509. case 'T':
  2510. newState = true;
  2511. break;
  2512. }
  2513. }
  2514. if( hor )
  2515. OpenElement(0,index,newState);
  2516. else
  2517. OpenElement(index,0,newState);
  2518. LogicDebug(
  2519. "Command <open>. Element %i is now %s.",index,newState ? "opend" : "closed");
  2520. }
  2521. else
  2522. {
  2523. LogicDebugError(
  2524. "Command <open> error. Index value %i not in range [0, %i].",
  2525. index,n);
  2526. return;
  2527. }
  2528. }
  2529. else
  2530. {
  2531. BaseGUIElement::Command(id,numParams,params);
  2532. }
  2533. }
  2534. static char GUIDescription[] =
  2535. "GUI Selector.\n\n"
  2536. " Use it to make list of GUI items\n"
  2537. " NOTE: all sizes-positions are relative (not pixel sizes-positions)\n\n"
  2538. "Commands:\n\n"
  2539. " left, right - scrolls list horizontally\n"
  2540. " up, down - scrolls list vertically\n\n"
  2541. " focus [index] [1/0] - set focus to element and trigger or not (1/0)\n"
  2542. " open [index] [1/0] - open/close element\n\n"
  2543. " fadein [time] - fades list in\n"
  2544. " fadeout [time] - fades list out";
  2545. MOP_BEGINLISTCG(GUISelector, "GUI Selector", '1.00', 2000, GUIDescription, "Interface")
  2546. // MOP_GROUPBEG("Wide screen layout")
  2547. // MOP_BOOL("Use shift aspect", false)
  2548. // MOP_BOOL("Use width aspect", true)
  2549. MOP_ENUMBEG("Layout")
  2550. MOP_ENUMELEMENT("Left")
  2551. MOP_ENUMELEMENT("Center")
  2552. MOP_ENUMELEMENT("Right")
  2553. MOP_ENUMEND
  2554. MOP_ENUM("Layout", "Layout")
  2555. // MOP_GROUPEND()
  2556. MOP_FLOAT("X position", 25.0f)
  2557. MOP_FLOAT("Y position", 25.0f)
  2558. // MOP_FLOAT("Alpha", 1.0f)
  2559. MOP_FLOATEX("Alpha", 1.0f, 0.0f, 1.0f)
  2560. MOP_STRING("Parent id", "")
  2561. MOP_FLOAT("Clip rect width" , 50.0f)
  2562. MOP_FLOAT("Clip rect height", 50.0f)
  2563. MOP_BOOL("Use clip rect", false)
  2564. MOP_STRING("Back texture", "")
  2565. MOP_FLOAT ("Back alpha", 1.0f)
  2566. MOP_LONG("Draw priority", 0)
  2567. // MOP_STRING("Hor bar", "")
  2568. // MOP_STRING("Ver bar", "")
  2569. MOP_ARRAYBEG("Lines", 0, 100)
  2570. MOP_ARRAYBEG("Items", 0, 100)
  2571. MOP_STRING("Normal", "")
  2572. MOP_STRING("Closed", "")
  2573. MOP_BOOL("Open", true)
  2574. MOP_MISSIONTRIGGER("OnFocus" )
  2575. MOP_MISSIONTRIGGER("OnLeave" )
  2576. MOP_MISSIONTRIGGER("OnSelect")
  2577. MOP_MISSIONTRIGGER("OnTry")
  2578. MOP_ARRAYEND
  2579. MOP_ARRAYEND
  2580. MOP_LONG("Start line", -1)
  2581. MOP_LONG("Start item", -1)
  2582. MOP_STRING("Marker", "")
  2583. MOP_FLOAT ("Marker scale", 1.0f)
  2584. MOP_FLOAT("Item width" , 25.0f)
  2585. MOP_FLOAT("Item height", 5.0f)
  2586. MOP_FLOAT("Hor space", 5.0f)
  2587. MOP_FLOAT("Ver space", 5.0f)
  2588. MOP_ARRAYBEG("Scales", 0, 10)
  2589. MOP_FLOAT("Scale", 1.0f)
  2590. MOP_FLOAT("Alpha", 1.0f)
  2591. MOP_LONG("Draw", 0)
  2592. MOP_ARRAYEND
  2593. MOP_GROUPBEG("Values")
  2594. MOP_FLOATEX( "Scale speed", 1.0f, 1.0f, 10.0f)
  2595. MOP_FLOATEX("Scroll speed", 1.0f, 1.0f, 10.0f)
  2596. MOP_FLOATEXC("Delay time", 0.65f, 0.4f, 1.0f, "Задержка перед автоповтором")
  2597. MOP_FLOATEXC("Beg time", 0.35f, 0.15f, 0.35f, "Начальное время перехода между элементами")
  2598. MOP_FLOATEXC("End time", 0.15f, 0.15f, 0.35f, "Конечное время перехода между элементами")
  2599. MOP_FLOATEXC("Accel time", 4.0f, 1.0f, 10.0f, "Время ускорения")
  2600. MOP_GROUPEND()
  2601. MOP_BOOL("Centered", false)
  2602. MOP_BOOL("Looped", false)
  2603. MOP_ENUMBEG("Align")
  2604. MOP_ENUMELEMENT("Center")
  2605. MOP_ENUMELEMENT("Bottom")
  2606. MOP_ENUMEND
  2607. MOP_ENUM("Align", "Align")
  2608. MOP_GROUPBEG("Controls")
  2609. MOP_STRING("Up" , "")
  2610. MOP_STRING("Down" , "")
  2611. MOP_STRING("Left" , "")
  2612. MOP_STRING("Right", "")
  2613. MOP_STRING("Sel" , "")
  2614. MOP_GROUPEND()
  2615. // MOP_FLOAT("Button width" , 4.1f)
  2616. // MOP_FLOAT("Button height", 5.0f)
  2617. MOP_BOOL("Active" , true)
  2618. MOP_BOOL("Visible", true)
  2619. MOP_BOOL("Silent activate", false)
  2620. MOP_ENDLIST(GUISelector)