SpielAuswahl.cpp 29 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032
  1. #include "SpielAuswahl.h"
  2. #include <Datei.h>
  3. #include <Text.h>
  4. #include <Schrift.h>
  5. #include <Rahmen.h>
  6. #include <Punkt.h>
  7. #include <DateiSystem.h>
  8. #include "..\..\..\Global\Initialisierung.h"
  9. #include <AlphaFeld.h>
  10. #include <MausEreignis.h>
  11. #include <KSGTDatei.h>
  12. #include "..\..\..\Global\Variablen.h"
  13. void SpielAuswahlKSGSAktion( void *p, RCArray< KSGSVariable > *parameter, KSGSVariable **retVal )
  14. {
  15. if( !p )
  16. return;
  17. ( (SpielDaten*)p )->ksgsAktion( parameter, retVal );
  18. }
  19. // Inhalt der SpielDaten Klasse aus SpielAuswahl.h
  20. // Konstruktor
  21. SpielDaten::SpielDaten( Schrift *zSchrift, const char *name, int id )
  22. : Thread()
  23. {
  24. beenden = 0;
  25. this->name = new Text( name );
  26. hintergrund = 0;
  27. aAnimation = 0;
  28. beschreibung = 0;
  29. ksgs = 0;
  30. rahmen = new LRahmen();
  31. rahmen->setFarbe( 0xFFFFFFFF );
  32. rahmen->setRamenBreite( 1 );
  33. tickVal = 0;
  34. animation = 0;
  35. ausgewählt = 0;
  36. pos = Punkt( 0, 500 );
  37. gr = Punkt( 200, 100 );
  38. schrift = zSchrift->getThis();
  39. spielId = id;
  40. aktion = 1;
  41. geladen = 0;
  42. erlaubt = 0;
  43. auswahl = new AlphaFeld();
  44. auswahl->setFarbe( 0x0000FF00 );
  45. auswahl->setStrength( 8 );
  46. auswahl->setSize( 200, 100 );
  47. ladenBild = 0;
  48. rend = 0;
  49. ref = 1;
  50. alpha = 0;
  51. tAlpha = 0;
  52. start();
  53. }
  54. // Destruktor
  55. SpielDaten::~SpielDaten()
  56. {
  57. beenden = 1;
  58. if( run )
  59. this->warteAufThread( 5000 );
  60. if( run )
  61. ende();
  62. if( schrift )
  63. schrift->release();
  64. name->release();
  65. if( hintergrund )
  66. hintergrund->release();
  67. if( aAnimation )
  68. aAnimation->release();
  69. if( beschreibung )
  70. {
  71. beschreibung->zurücksetzen();
  72. beschreibung->release();
  73. }
  74. if( ksgs )
  75. {
  76. dllDateien->releaseDLL( "KSGScript.dll" );
  77. ksgs = 0;
  78. }
  79. rahmen->release();
  80. auswahl->release();
  81. }
  82. // nicht constant
  83. void SpielDaten::ksgsAktion( RCArray< KSGSVariable > *parameter, KSGSVariable **retVal )
  84. {}
  85. void SpielDaten::setSichtbar( bool sichtbar )
  86. {
  87. if( sichtbar )
  88. animation |= 0x1;
  89. else
  90. {
  91. animation &= ~0x1;
  92. setAuswahl( 0 );
  93. auswahl->setFarbe( auswahl->getFarbe() & 0xFFFFFF );
  94. }
  95. if( !erlaubt && sichtbar && ausgewählt )
  96. updateH->setSichtbar( spielId, 1 );
  97. hauptScreen->lock();
  98. if( run && aktion == (sichtbar ? 2 : 0) )
  99. {
  100. hauptScreen->unlock();
  101. rend = 1;
  102. return;
  103. }
  104. beenden = 1;
  105. if( run )
  106. this->warteAufThread( 1000 );
  107. if( run )
  108. ende();
  109. beenden = 0;
  110. aktion = sichtbar ? 2 : 0;
  111. start();
  112. hauptScreen->unlock();
  113. rend = 1;
  114. }
  115. void SpielDaten::setSichtbar()
  116. {
  117. animation |= 1;
  118. if( ausgewählt && geladen == 2 )
  119. {
  120. animation |= 0x4;
  121. beschreibung->setPosition( beschreibung->getX(), 0 );
  122. }
  123. if( !erlaubt && ausgewählt )
  124. updateH->setSichtbar( spielId, 1 );
  125. hauptScreen->lock();
  126. if( geladen != 2 && !( aktion == 2 && run ) )
  127. {
  128. beenden = 1;
  129. if( run )
  130. this->warteAufThread( 1000 );
  131. if( run )
  132. ende();
  133. beenden = 0;
  134. aktion = 2;
  135. start();
  136. }
  137. hauptScreen->unlock();
  138. rend = 1;
  139. }
  140. void SpielDaten::setAuswahl( bool auswahl )
  141. {
  142. if( ausgewählt == auswahl )
  143. return;
  144. ausgewählt = auswahl;
  145. if( auswahl )
  146. {
  147. if( aAnimation )
  148. aAnimation->setSichtbar( 1 );
  149. if( beschreibung && ksgs )
  150. beschreibung->neuLaden();
  151. animation |= 0x4;
  152. }
  153. else
  154. animation &= ~0x4;
  155. if( !erlaubt && ausgewählt )
  156. updateH->setSichtbar( spielId, 1 );
  157. if( !erlaubt && !ausgewählt )
  158. updateH->setSichtbar( spielId, 0 );
  159. rend = 1;
  160. }
  161. void SpielDaten::thread()
  162. {
  163. Text *pfad = new Text( "data/spiele/" );
  164. pfad->append( name->getText() );
  165. pfad->append( "/data/game.ini" );
  166. if( !DateiExistiert( pfad->getThis() ) )
  167. {
  168. if( !aktion )
  169. {
  170. if( aAnimation )
  171. aAnimation->setSichtbar( 0 );
  172. geladen = 0;
  173. ausgewählt = 0;
  174. hauptScreen->lock();
  175. if( aAnimation )
  176. aAnimation = aAnimation->release();
  177. hauptScreen->unlock();
  178. if( hintergrund )
  179. hintergrund = hintergrund->release();
  180. if( beschreibung )
  181. {
  182. beschreibung->zurücksetzen();
  183. beschreibung = beschreibung->release();
  184. }
  185. if( ksgs )
  186. {
  187. dllDateien->releaseDLL( "KSGScript.dll" );
  188. ksgs = 0;
  189. }
  190. }
  191. else
  192. {
  193. if( !hintergrund )
  194. hintergrund = new Bild();
  195. hintergrund->neuBild( 200, 100, 0xFF000000 );
  196. schrift->lock();
  197. schrift->setSchriftSize( 12 );
  198. schrift->setDrawPosition( 10, 10 );
  199. schrift->renderText( name, *hintergrund, 0xFFFFFFFF );
  200. schrift->unlock();
  201. if( !geladen )
  202. geladen = 1;
  203. rend = 1;
  204. int dgId = infoKlient->getDateiGruppeIdVonSpiel( spielId );
  205. if( dgId )
  206. {
  207. KSGTDatei *dg = new KSGTDatei( "data/dg.ksgt" );
  208. dg->laden();
  209. bool gefunden = 0;
  210. for( int i = 0; i < dg->getZeilenAnzahl(); i++ )
  211. {
  212. if( dg->zFeld( i, 0 ) && TextZuInt( dg->zFeld( i, 0 )->getText(), 10 ) == dgId )
  213. {
  214. gefunden = 1;
  215. break;
  216. }
  217. }
  218. if( !gefunden )
  219. {
  220. for( int i = 0; i < dg->getZeilenAnzahl(); i++ )
  221. {
  222. if( dg->zFeld( i, 3 ) && !dg->zFeld( i, 3 )->istGleich( "SOFORT" ) && !dg->zFeld( i, 3 )->istGleich( "NICHT" ) )
  223. {
  224. int platz = TextZuInt( dg->zFeld( i, 3 )->getText(), 10 ) + 1;
  225. Text *plT = new Text();
  226. plT->append( platz );
  227. dg->zFeld( i, 3 )->setText( plT );
  228. }
  229. }
  230. Text *idT = new Text();
  231. idT->append( dgId );
  232. Text *pfad = infoKlient->getDateiGruppePfad( dgId );
  233. if( pfad )
  234. {
  235. RCArray< Text > *zeile = new RCArray< Text >();
  236. zeile->add( idT );
  237. zeile->add( pfad );
  238. zeile->add( new Text( "0" ) );
  239. zeile->add( new Text( "0" ) );
  240. dg->addZeile( 4, zeile );
  241. zeile->release();
  242. }
  243. else
  244. idT->release();
  245. }
  246. dg->speichern();
  247. dg->release();
  248. }
  249. if( aktion == 2 && !beenden )
  250. {
  251. if( beschreibung )
  252. {
  253. beschreibung->zurücksetzen();
  254. beschreibung = beschreibung->release();
  255. }
  256. if( !ksgs )
  257. ksgs = dllDateien->ladeDLL( "KSGScript.dll", "data/bin/KSGScript.dll" );
  258. if( ksgs )
  259. {
  260. KSGSGetZeichnung getKSGScript = (KSGSGetZeichnung)GetProcAddress( ksgs, KSGS_START_FUNKTION );
  261. if( getKSGScript )
  262. {
  263. beschreibung = getKSGScript();
  264. beschreibung->setBildschirmZ( hauptScreen->getThis() );
  265. beschreibung->setSchriftZ( schrift->getThis() );
  266. beschreibung->setSize( 578, 428 );
  267. beschreibung->setRückrufParam( this );
  268. beschreibung->setRückrufFunktion( SpielAuswahlKSGSAktion );
  269. beschreibung->setScriptDatei( "data/script/SpielNichtAktuell.ksgs" );
  270. }
  271. else
  272. {
  273. nachLogin->zNachrichtenListe()->addNachricht( new Text( "Fehler" ),
  274. new Text( "Der Einstiegspunkt '" KSGS_START_FUNKTION "' in der DLL-Datei "
  275. "'data/bin/KSGScript.dll' konnte nicht gefunden werden." ),
  276. new Text( "Ok" ), 0, NachrichtType::nachricht, 0 );
  277. }
  278. }
  279. else
  280. {
  281. nachLogin->zNachrichtenListe()->addNachricht( new Text( "Fehler" ),
  282. new Text( "Die DLL-Datei 'data/bin/KSGScript.dll' konnte nicht geladen werden." ),
  283. new Text( "Ok" ), 0, NachrichtType::nachricht, 0 );
  284. }
  285. if( beschreibung )
  286. geladen = 2;
  287. if( beschreibung && ksgs && ausgewählt )
  288. beschreibung->neuLaden();
  289. }
  290. }
  291. pfad->release();
  292. rend = 1;
  293. run = 0;
  294. return;
  295. }
  296. Datei *ini = new Datei();
  297. ini->setDatei( pfad->getText() );
  298. ini->open( Datei::Style::lesen );
  299. if( !aktion )
  300. {
  301. if( aAnimation )
  302. aAnimation->setSichtbar( 0 );
  303. geladen = 0;
  304. ausgewählt = 0;
  305. hauptScreen->lock();
  306. if( aAnimation )
  307. aAnimation = aAnimation->release();
  308. hauptScreen->unlock();
  309. if( hintergrund )
  310. hintergrund = hintergrund->release();
  311. if( beschreibung )
  312. {
  313. beschreibung->zurücksetzen();
  314. beschreibung = beschreibung->release();
  315. }
  316. if( ksgs )
  317. {
  318. dllDateien->releaseDLL( "KSGScript.dll" );
  319. ksgs = 0;
  320. }
  321. rend = 1;
  322. }
  323. else
  324. {
  325. Text *pf = ini->leseZeile();
  326. pf->remove( pf->getLength() - 1 );
  327. pf->insert( 0, "/bilder/" );
  328. pf->insert( 0, name->getText() );
  329. pf->insert( 0, "data/spiele/" );
  330. if( pf->hat( ".ltdb/" ) )
  331. {
  332. if( !hintergrund )
  333. {
  334. LTDBDatei *bildDatei = new LTDBDatei();
  335. bildDatei->setDatei( pf->getTeilText( 0, pf->positionVon( ".ltdb" ) + 5 ) );
  336. bildDatei->leseDaten( 0 );
  337. hintergrund = bildDatei->laden( 0, pf->getTeilText( pf->positionVon( ".ltdb" ) + 6 ) );
  338. bildDatei->release();
  339. }
  340. }
  341. else
  342. {
  343. if( !hintergrund )
  344. {
  345. LTDBDatei *bildDatei = new LTDBDatei();
  346. bildDatei->setDatei( pf->getThis() );
  347. bildDatei->leseDaten( 0 );
  348. hintergrund = bildDatei->laden( 0, bildDatei->zBildListe()->get( 0 ) );
  349. bildDatei->release();
  350. }
  351. }
  352. pf->release();
  353. pf = ini->leseZeile();
  354. pf->release();
  355. pf = ini->leseZeile();
  356. pf->remove( pf->getLength() - 1 );
  357. pf->insert( 0, "/data/" );
  358. pf->insert( 0, name->getText() );
  359. pf->insert( 0, "data/spiele/" );
  360. Datei *idDatei = new Datei();
  361. idDatei->setDatei( pf->getText() );
  362. idDatei->open( Datei::Style::lesen );
  363. idDatei->lese( (char*)&spielId, 4 );
  364. idDatei->close();
  365. idDatei->release();
  366. pf->release();
  367. if( !geladen )
  368. geladen = 1;
  369. rend = 1;
  370. ini->setLPosition( 0, 0 );
  371. if( aktion == 2 && !beenden )
  372. {
  373. pf = ini->leseZeile();
  374. pf->remove( pf->getLength() - 1 );
  375. pf->insert( 0, "/bilder/" );
  376. pf->insert( 0, name->getText() );
  377. pf->insert( 0, "data/spiele/" );
  378. if( !pf->hat( ".ltdb/" ) )
  379. {
  380. hauptScreen->lock();
  381. if( aAnimation )
  382. aAnimation = aAnimation->release();
  383. hauptScreen->unlock();
  384. LTDBDatei *add = new LTDBDatei();
  385. add->setDatei( pf->getThis() );
  386. add->leseDaten( 0 );
  387. Animation2DData *ad = new Animation2DData();
  388. ad->ladeAnimation( add );
  389. ad->setWiederhohlend( 1 );
  390. ad->setFPS( 30 );
  391. aAnimation = new Animation2D();
  392. aAnimation->setSize( 200, 100 );
  393. aAnimation->setPosition( 0, 0 );
  394. aAnimation->setAnimationDataZ( ad );
  395. }
  396. pf->release();
  397. pf = ini->leseZeile();
  398. pf->remove( pf->getLength() - 1 );
  399. pf->insert( 0, "/data/" );
  400. pf->insert( 0, name->getText() );
  401. pf->insert( 0, "data/spiele/" );
  402. if( beschreibung )
  403. {
  404. beschreibung->zurücksetzen();
  405. beschreibung = beschreibung->release();
  406. }
  407. if( !ksgs )
  408. ksgs = dllDateien->ladeDLL( "KSGScript.dll", "data/bin/KSGScript.dll" );
  409. if( ksgs )
  410. {
  411. KSGSGetZeichnung getKSGScript = (KSGSGetZeichnung)GetProcAddress( ksgs, KSGS_START_FUNKTION );
  412. if( getKSGScript )
  413. {
  414. beschreibung = getKSGScript();
  415. beschreibung->setBildschirmZ( hauptScreen->getThis() );
  416. beschreibung->setSchriftZ( schrift->getThis() );
  417. beschreibung->setSize( 578, 428 );
  418. beschreibung->setRückrufParam( this );
  419. beschreibung->setRückrufFunktion( SpielAuswahlKSGSAktion );
  420. beschreibung->setScriptDatei( pf->getText() );
  421. }
  422. else
  423. {
  424. nachLogin->zNachrichtenListe()->addNachricht( new Text( "Fehler" ),
  425. new Text( "Der Einstiegspunkt '" KSGS_START_FUNKTION "' in der DLL-Datei "
  426. "'data/bin/KSGScript.dll' konnte nicht gefunden werden." ),
  427. new Text( "Ok" ), 0, NachrichtType::nachricht, 0 );
  428. }
  429. }
  430. else
  431. {
  432. nachLogin->zNachrichtenListe()->addNachricht( new Text( "Fehler" ),
  433. new Text( "Die DLL-Datei 'data/bin/KSGScript.dll' konnte nicht geladen werden." ),
  434. new Text( "Ok" ), 0, NachrichtType::nachricht, 0 );
  435. }
  436. pf->release();
  437. if( beschreibung )
  438. geladen = 2;
  439. if( beschreibung && ksgs && ausgewählt )
  440. beschreibung->neuLaden();
  441. rend = 1;
  442. }
  443. }
  444. pfad->release();
  445. ini->close();
  446. ini->release();
  447. if( !erlaubt )
  448. updateErlaubt();
  449. aktion = 0;
  450. run = 0;
  451. rend = 1;
  452. }
  453. void SpielDaten::updateErlaubt()
  454. {
  455. bool update = erlaubt;
  456. erlaubt = 0;
  457. KSGTDatei *dgt = new KSGTDatei( "data/dg.ksgt" );
  458. dgt->laden();
  459. bool ak = 0;
  460. int dgId = infoKlient->getDateiGruppeIdVonSpiel( spielId );
  461. for( int i = 0; i < dgt->getZeilenAnzahl(); i++ )
  462. {
  463. if( dgt->zFeld( i, 0 ) && TextZuInt( dgt->zFeld( i, 0 )->getText(), 10 ) == dgId )
  464. {
  465. int lv = dgt->zFeld( i, 2 ) ? TextZuInt( dgt->zFeld( i, 2 )->getText(), 10 ) : 0;
  466. int ov = infoKlient->getSpielVersion( spielId );
  467. if( lv == ov )
  468. ak = 1;
  469. break;
  470. }
  471. }
  472. dgt->release();
  473. erlaubt = ak && infoKlient->istSpielErlaubt( spielId );
  474. if( !erlaubt && !updateH->hat( spielId ) )
  475. {
  476. updateH->erstellen( schrift, spielId );
  477. if( ausgewählt )
  478. updateH->setSichtbar( spielId, 1 );
  479. }
  480. if( erlaubt && updateH->hat( spielId ) )
  481. updateH->remove( spielId, 0 );
  482. }
  483. void SpielDaten::setPosition( int lPos )
  484. {
  485. pos.y = lPos * 100;
  486. rend = 1;
  487. }
  488. bool SpielDaten::tick( double tickVal )
  489. {
  490. if( beschreibung )
  491. rend |= beschreibung->tick( tickVal );
  492. if( !erlaubt )
  493. rend |= updateH->tick( spielId, tickVal );
  494. this->tickVal += tickVal * 500;
  495. int val = ( int ) this->tickVal;
  496. if( val < 1 )
  497. {
  498. bool ret = rend;
  499. rend = 0;
  500. return ret;
  501. }
  502. if( val > 17 )
  503. val = 17;
  504. this->tickVal -= val;
  505. if( aAnimation && geladen == 2 && aAnimation->istSichtbar() )
  506. {
  507. if( aAnimation->getJetzt() + 1 >= aAnimation->zAnimationData()->getBildAnzahl() )
  508. {
  509. rend |= aAnimation->tick( tickVal );
  510. if( aAnimation->getJetzt() + 1 < aAnimation->zAnimationData()->getBildAnzahl() )
  511. aAnimation->setSichtbar( 0 );
  512. }
  513. else
  514. rend |= aAnimation->tick( tickVal );
  515. }
  516. if( ausgewählt )
  517. {
  518. int a = ( auswahl->getFarbe() >> 24 ) & 0xFF;
  519. if( a != 150 )
  520. {
  521. if( a + val > 150 )
  522. a = 150;
  523. else
  524. a += val;
  525. auswahl->setFarbe( ( ( a << 24 ) & 0xFF000000 ) | ( auswahl->getFarbe() & 0xFFFFFF ) );
  526. rend = 1;
  527. }
  528. }
  529. else
  530. {
  531. int a = ( auswahl->getFarbe() >> 24 ) & 0xFF;
  532. if( a != 0 )
  533. {
  534. if( a - val < 0 )
  535. a = 0;
  536. else
  537. a -= val;
  538. auswahl->setFarbe( ( ( a << 24 ) & 0xFF000000 ) | ( auswahl->getFarbe() & 0xFFFFFF ) );
  539. rend = 1;
  540. }
  541. }
  542. if( ( animation | 0x1 ) == animation ) // sichtbar
  543. {
  544. if( tAlpha != 255 )
  545. {
  546. if( tAlpha + val > 255 )
  547. tAlpha = 255;
  548. else
  549. tAlpha += val;
  550. rend = 1;
  551. }
  552. }
  553. else // unsichtbar
  554. {
  555. if( tAlpha != 0 )
  556. {
  557. if( tAlpha - val < 0 )
  558. tAlpha = 0;
  559. else
  560. tAlpha -= val;
  561. rend = 1;
  562. }
  563. }
  564. if( geladen == 2 )
  565. {
  566. if( ( animation | 0x4 ) == animation ) // auswählen
  567. {
  568. if( beschreibung )
  569. {
  570. if( alpha != 255 )
  571. {
  572. if( alpha + val < 255 )
  573. alpha += val;
  574. else
  575. alpha = 255;
  576. rend = 1;
  577. }
  578. }
  579. }
  580. else // abwählen
  581. {
  582. int a = ( auswahl->getFarbe() >> 24 ) & 0xFF;
  583. if( a != 0 )
  584. {
  585. a -= val;
  586. if( a < 0 )
  587. a = 0;
  588. auswahl->setFarbe( ( ( a << 24 ) & 0xFF000000 ) | ( auswahl->getFarbe() & 0xFFFFFF ) );
  589. rend = 1;
  590. }
  591. if( beschreibung )
  592. {
  593. if( alpha != 0 )
  594. {
  595. if( alpha - val > 0 )
  596. alpha -= val;
  597. else
  598. alpha = 0;
  599. rend = 1;
  600. }
  601. }
  602. }
  603. }
  604. bool ret = rend;
  605. rend = 0;
  606. return ret;
  607. }
  608. void SpielDaten::doMausEreignis( MausEreignis &me )
  609. {
  610. if( !erlaubt && ausgewählt )
  611. {
  612. me.mx -= gr.x + 90;
  613. me.my -= 350;
  614. updateH->doMausEreignis( spielId, me );
  615. me.my += 350;
  616. me.mx += 90;
  617. if( beschreibung )
  618. beschreibung->doMausEreignis( me );
  619. me.mx += gr.x;
  620. }
  621. }
  622. void SpielDaten::render( Bild &zRObj )
  623. {
  624. int x = pos.x;
  625. int y = pos.y;
  626. int br = gr.x;
  627. int hö = gr.y;
  628. if( !zRObj.setDrawOptions( x, y, br, hö ) )
  629. return;
  630. zRObj.setAlpha( tAlpha );
  631. rahmen->setSize( br, hö );
  632. int rbr = rahmen->getRBreite();
  633. if( geladen && hintergrund && ( !( ausgewählt && geladen == 2 && aAnimation ) || !aAnimation->istSichtbar() ) )
  634. zRObj.drawBild( rbr, rbr, br - rbr * 2, hö - rbr * 2, *hintergrund );
  635. if( aAnimation )
  636. aAnimation->render( zRObj );
  637. rahmen->render( zRObj );
  638. if( auswahl && ( ( auswahl->getFarbe() >> 24 ) & 0xFF ) && ( !( ausgewählt && geladen == 2 && aAnimation ) || !aAnimation->istSichtbar() ) )
  639. {
  640. auswahl->setPosition( rbr, rbr );
  641. auswahl->setSize( br - rbr * 2, hö - rbr * 2 );
  642. auswahl->render( zRObj );
  643. }
  644. zRObj.releaseDrawOptions();
  645. x = br;
  646. y = 0;
  647. br = 580;
  648. hö = 480;
  649. if( !zRObj.setDrawOptions( x, y, br, hö ) )
  650. {
  651. zRObj.releaseAlpha();
  652. return;
  653. }
  654. if( geladen == 2 && beschreibung )
  655. {
  656. zRObj.setAlpha( alpha );
  657. beschreibung->render( zRObj );
  658. zRObj.releaseAlpha();
  659. }
  660. if( !erlaubt )
  661. updateH->render( spielId, 90, 350, zRObj );
  662. if( ausgewählt && geladen != 2 && ladeAnimation->zAnimationData() )
  663. {
  664. ladenBild++;
  665. if( ladenBild >= ladeAnimation->zAnimationData()->getBildAnzahl() )
  666. ladenBild = 0;
  667. zRObj.drawBild( 275, 195, 50, 50, *ladeAnimation->zAnimationData()->zBild( ladenBild ) );
  668. rend = 1;
  669. }
  670. zRObj.releaseDrawOptions();
  671. zRObj.releaseAlpha();
  672. }
  673. // constant
  674. int SpielDaten::getSpielId() const
  675. {
  676. return spielId;
  677. }
  678. bool SpielDaten::istausgewählt() const
  679. {
  680. return ausgewählt;
  681. }
  682. Text *SpielDaten::zName() const
  683. {
  684. return name;
  685. }
  686. bool SpielDaten::istErlaubt() const
  687. {
  688. return erlaubt;
  689. }
  690. // Reference Counting
  691. SpielDaten *SpielDaten::getThis()
  692. {
  693. ref++;
  694. return this;
  695. }
  696. SpielDaten *SpielDaten::release()
  697. {
  698. ref--;
  699. if( !ref )
  700. delete this;
  701. return 0;
  702. }
  703. // Inhalt der SpielAuswahl Klasse aus SpielAuswahl.h
  704. // Konstruktor
  705. SpielAuswahlFenster::SpielAuswahlFenster( Schrift *zSchrift )
  706. : Thread()
  707. {
  708. schrift = zSchrift->getThis();
  709. rahmen = new LRahmen();
  710. rahmen->setFarbe( 0xFFFFFFFF );
  711. rahmen->setRamenBreite( 1 );
  712. rahmen->setSize( 760, 500 );
  713. members = new RCArray< SpielDaten >();
  714. anzahl = 0;
  715. animation = 0;
  716. auswahl = -1;
  717. tickVal = 0;
  718. seite = 0;
  719. pos = Punkt( 10, 10 );
  720. gr = Punkt( 780, 430 );
  721. rend = 0;
  722. ref = 1;
  723. alpha = 0;
  724. start();
  725. }
  726. // Destruktor
  727. SpielAuswahlFenster::~SpielAuswahlFenster()
  728. {
  729. if( run )
  730. {
  731. warteAufThread( 5000 );
  732. ende();
  733. }
  734. if( schrift )
  735. schrift->release();
  736. if( rahmen )
  737. rahmen->release();
  738. if( members )
  739. members->release();
  740. }
  741. // nicht constant
  742. void SpielAuswahlFenster::setSichtbar( bool sichtbar )
  743. {
  744. if( sichtbar )
  745. {
  746. animation |= 0x1;
  747. start();
  748. }
  749. else
  750. {
  751. auswahl = -1;
  752. for( int i = seite * 4; i >= 0 && i < anzahl && i < seite * 4 + 4; i++ )
  753. members->z( i )->setSichtbar( 0 );
  754. animation &= ~0x1;
  755. }
  756. rend = 1;
  757. }
  758. void SpielAuswahlFenster::blättern( bool oben )
  759. {
  760. for( int i = seite * 4; i >= 0 && i < anzahl && i < seite * 4 + 4; i++ )
  761. members->z( i )->setSichtbar( 0 );
  762. seite += oben ? 1 : -1;
  763. for( int i = seite * 4; i >= 0 && i < anzahl && i < seite * 4 + 4; i++ )
  764. {
  765. members->z( i )->setPosition( i % 4 );
  766. members->z( i )->setSichtbar( 1 );
  767. }
  768. auswahl = -1;
  769. rend = 1;
  770. }
  771. void SpielAuswahlFenster::updateListe()
  772. {
  773. if( run )
  774. return;
  775. start();
  776. }
  777. void SpielAuswahlFenster::thread()
  778. {
  779. Array< int > *liste = infoKlient->getAccountSpielArtListe();
  780. if( !liste )
  781. {
  782. nachLogin->zNachrichtenListe()->addNachricht( new Text( "Fehler" ), new Text( infoKlient->getLetzterFehler() ),
  783. new Text( "Ok" ), 0, NachrichtType::nachricht, 0 );
  784. run = 0;
  785. return;
  786. }
  787. int anz = liste->getEintragAnzahl();
  788. for( int i = 0; i < anz; i++ )
  789. {
  790. Text *name = infoKlient->getSpielName( liste->hat( i ) ? liste->get( i ) : 0 );
  791. if( name )
  792. {
  793. bool gefunden = 0;
  794. for( int j = 0; j < anzahl; j++ )
  795. {
  796. SpielDaten *tmp = members->z( j );
  797. if( liste->hat( i ) && tmp->getSpielId() == liste->get( i ) )
  798. {
  799. gefunden = 1;
  800. break;
  801. }
  802. }
  803. if( !gefunden )
  804. {
  805. SpielDaten *tmp = new SpielDaten( schrift, name->getText(), liste->hat( i ) ? liste->get( i ) : 0 );
  806. members->add( tmp, anzahl );
  807. anzahl++;
  808. }
  809. name->release();
  810. }
  811. }
  812. if( liste )
  813. liste->release();
  814. for( int i = 0; i < anzahl; i++ )
  815. members->z( i )->updateErlaubt();
  816. for( int i = seite * 4; i < anzahl && i >= 0 && i < seite * 4 + 4; i++ )
  817. {
  818. members->z( i )->setPosition( i % 4 );
  819. members->z( i )->setSichtbar();
  820. }
  821. rend = 1;
  822. run = 0;
  823. }
  824. bool SpielAuswahlFenster::tick( double tickVal )
  825. {
  826. for( int i = 0; i < anzahl; i++ )
  827. rend |= members->z( i )->tick( tickVal );
  828. this->tickVal += tickVal * 750;
  829. int val = ( int )this->tickVal;
  830. if( val < 1 )
  831. {
  832. bool ret = rend;
  833. rend = 0;
  834. return ret;
  835. }
  836. if( val > 25 )
  837. val = 25;
  838. this->tickVal -= val;
  839. if( ( animation | 0x1 ) == animation ) // sichtbar
  840. {
  841. if( alpha < 255 )
  842. {
  843. if( alpha + val >= 255 )
  844. {
  845. alpha = 255;
  846. for( int i = seite * 4; i < anzahl && i >= 0 && i < seite * 4 + 4; i++ )
  847. {
  848. members->z( i )->setPosition( i % 4 );
  849. members->z( i )->setSichtbar( 1 );
  850. }
  851. }
  852. else
  853. alpha += val;
  854. rend = 1;
  855. }
  856. }
  857. else // unsichtbar
  858. {
  859. if( alpha > 0 )
  860. {
  861. if( alpha - val < 0 )
  862. alpha = 0;
  863. else
  864. alpha -= val;
  865. rend = 1;
  866. }
  867. }
  868. bool ret = rend;
  869. rend = 0;
  870. return ret;
  871. }
  872. void SpielAuswahlFenster::doMausEreignis( MausEreignis &me )
  873. {
  874. if( pos.x != 10 )
  875. return;
  876. me.mx -= pos.x;
  877. me.my -= pos.y;
  878. for( int i = 0; i < anzahl; i++ )
  879. members->z( i )->doMausEreignis( me );
  880. if( me.mx < 0 || me.my < 0 )
  881. {
  882. me.mx += pos.x;
  883. me.my += pos.y;
  884. return;
  885. }
  886. if( me.mx > 200 || me.my > getAnzahlAufSeite() * 100 )
  887. {
  888. me.mx += pos.x;
  889. me.my += pos.y;
  890. return;
  891. }
  892. if( me.id == ME_RLinks )
  893. {
  894. int treffer = me.my / 100 + seite * 4;
  895. if( treffer >= anzahl )
  896. {
  897. me.mx += pos.x;
  898. me.my += pos.y;
  899. return;
  900. }
  901. if( treffer == auswahl )
  902. {
  903. me.mx += pos.x;
  904. me.my += pos.y;
  905. return;
  906. }
  907. if( auswahl >= 0 )
  908. members->z( auswahl )->setAuswahl( 0 );
  909. members->z( treffer )->setAuswahl( 1 );
  910. auswahl = treffer;
  911. rend = 1;
  912. }
  913. me.mx += pos.x;
  914. me.my += pos.y;
  915. }
  916. void SpielAuswahlFenster::render( Bild &zrObj )
  917. {
  918. int x = pos.x;
  919. int y = pos.y;
  920. int br = gr.x;
  921. int hö = gr.y;
  922. if( !zrObj.setDrawOptions( x, y, br, hö ) )
  923. return;
  924. zrObj.setAlpha( alpha );
  925. rahmen->setSize( br, hö );
  926. rahmen->render( zrObj );
  927. int rbr = rahmen->getRBreite();
  928. if( !zrObj.setDrawOptions( rbr, rbr, br - rbr * 2, hö - rbr * 2 ) )
  929. {
  930. zrObj.releaseDrawOptions();
  931. zrObj.releaseAlpha();
  932. return;
  933. }
  934. for( int i = seite * 4; i >= 0 && i < anzahl && i < seite * 4 + 4; i++ )
  935. members->z( i )->render( zrObj );
  936. zrObj.releaseDrawOptions();
  937. if( !anzahl )
  938. {
  939. Text t = "Dieser Account besitzt momentan noch keine Spiele.\nBesuche den Shop um neue Spiele zu erwerben!";
  940. schrift->lock();
  941. schrift->setDrawPosition( 10, 10 );
  942. schrift->setSchriftSize( 12 );
  943. schrift->renderText( &t, zrObj, 0xFFFFFFFF );
  944. schrift->unlock();
  945. }
  946. zrObj.releaseDrawOptions();
  947. zrObj.releaseAlpha();
  948. }
  949. // constant
  950. int SpielAuswahlFenster::getAnzahl() const
  951. {
  952. return anzahl;
  953. }
  954. int SpielAuswahlFenster::getSeiteAnzahl() const
  955. {
  956. return ( anzahl / 4.0 == anzahl / 4 ) ? ( anzahl / 4 ) : ( anzahl / 4 + 1 );
  957. }
  958. int SpielAuswahlFenster::getSeite() const
  959. {
  960. return seite;
  961. }
  962. int SpielAuswahlFenster::getAnzahlAufSeite() const
  963. {
  964. return ( anzahl < seite * 4 + 4 ) ? ( anzahl - seite * 4 ) : 4;
  965. }
  966. bool SpielAuswahlFenster::hatAuswahl() const
  967. {
  968. return auswahl != -1;
  969. }
  970. SpielDaten *SpielAuswahlFenster::getAuswahl() const
  971. {
  972. return members->get( auswahl );
  973. }
  974. SpielDaten *SpielAuswahlFenster::zAuswahl() const
  975. {
  976. return members->z( auswahl );
  977. }
  978. bool SpielAuswahlFenster::istAuswahlErlubt() const
  979. {
  980. return auswahl != -1 && members->z( auswahl )->istErlaubt();
  981. }
  982. // Reference Counting
  983. SpielAuswahlFenster *SpielAuswahlFenster::getThis()
  984. {
  985. ref++;
  986. return this;
  987. }
  988. SpielAuswahlFenster *SpielAuswahlFenster::release()
  989. {
  990. ref--;
  991. if( !ref )
  992. delete this;
  993. return 0;
  994. }