KartenKaufen.cpp 26 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055
  1. #include "KartenKaufen.h"
  2. #include <Rahmen.h>
  3. #include <Punkt.h>
  4. #include "../../../Global/Initialisierung.h"
  5. #include "../../../Global/Variablen.h"
  6. #include <DateiSystem.h>
  7. #include <AlphaFeld.h>
  8. #include <KSGTDatei.h>
  9. void KarteKaufenKSGSAktion( void *p, RCArray< KSGSVariable > *parameter, KSGSVariable **retVal )
  10. {
  11. if( !p )
  12. return;
  13. ( (KartenKaufenAuswahl*)p )->ksgsAktion( parameter, retVal );
  14. }
  15. // Inhalt der KartenKaufenAuswahl Klasse aus KartenKaufen.h
  16. // Konstruktor
  17. KartenKaufenAuswahl::KartenKaufenAuswahl( Schrift *zSchrift )
  18. {
  19. karteId = 0;
  20. alpha = 0;
  21. ksgs = dllDateien->ladeDLL( "KSGScript.dll", "data/bin/KSGScript.dll" );
  22. if( ksgs )
  23. {
  24. KSGSGetZeichnung getKSGScript = (KSGSGetZeichnung)GetProcAddress( ksgs, KSGS_START_FUNKTION );
  25. if( getKSGScript )
  26. {
  27. fenster = getKSGScript();
  28. fenster->setSchriftZ( zSchrift->getThis() );
  29. fenster->setSize( 555, 380 );
  30. fenster->setRückrufParam( this );
  31. fenster->setRückrufFunktion( KarteKaufenKSGSAktion );
  32. }
  33. else
  34. {
  35. fenster = 0;
  36. nachLogin->zNachrichtenListe()->addNachricht( new Text( "Fehler" ),
  37. new Text( "Der Einstiegspunkt '" KSGS_START_FUNKTION "' in der DLL-Datei "
  38. "'data/bin/KSGScript.dll' konnte nicht gefunden werden." ),
  39. new Text( "Ok" ), 0, NachrichtType::nachricht, 0 );
  40. }
  41. }
  42. else
  43. {
  44. fenster = 0;
  45. nachLogin->zNachrichtenListe()->addNachricht( new Text( "Fehler" ),
  46. new Text( "Die DLL-Datei 'data/bin/KSGScript.dll' konnte nicht geladen werden." ),
  47. new Text( "Ok" ), 0, NachrichtType::nachricht, 0 );
  48. }
  49. ram = new LRahmen();
  50. ram->setSize( 555, 380 );
  51. ram->setFarbe( 0xFFFFFFFF );
  52. laden = ( Framework::Animation2D* )ladeAnimation->dublizieren();
  53. laden->setPosition( 252, 165 );
  54. laden->setSichtbar( 0 );
  55. pos = Punkt( 220, 10 );
  56. aktion = 0;
  57. ref = 1;
  58. }
  59. // Destruktor
  60. KartenKaufenAuswahl::~KartenKaufenAuswahl()
  61. {
  62. if( run )
  63. warteAufThread( 2000 );
  64. if( run )
  65. ende();
  66. if( fenster )
  67. {
  68. fenster->zurücksetzen();
  69. fenster->release();
  70. }
  71. ram->release();
  72. laden->release();
  73. if( ksgs )
  74. dllDateien->releaseDLL( "KSGScript.dll" );
  75. }
  76. // nicht constant
  77. void KartenKaufenAuswahl::ladeKarteSeite( int id )
  78. {
  79. if( run )
  80. warteAufThread( 2000 );
  81. if( run )
  82. return;
  83. karteId = id;
  84. aktion = 1;
  85. start();
  86. }
  87. void KartenKaufenAuswahl::reset()
  88. {
  89. if( run )
  90. warteAufThread( 2000 );
  91. if( run )
  92. return;
  93. aktion = 0;
  94. start();
  95. }
  96. void KartenKaufenAuswahl::thread()
  97. {
  98. laden->setSichtbar( 1 );
  99. if( !aktion || karteId )
  100. {
  101. while( alpha )
  102. Sleep( 100 );
  103. if( !aktion )
  104. karteId = 0;
  105. if( fenster )
  106. fenster->zurücksetzen();
  107. }
  108. if( aktion )
  109. {
  110. while( alpha )
  111. Sleep( 100 );
  112. shopKlient->ladeKarteSeite( karteId );
  113. Text *pfad = new Text( "data/tmp/shop/kaufen/karten/" );
  114. pfad->append( karteId );
  115. pfad->append( "/seite.ksgs" );
  116. if( fenster )
  117. {
  118. fenster->setScriptDatei( pfad );
  119. fenster->neuLaden();
  120. }
  121. }
  122. laden->setSichtbar( 0 );
  123. run = 0;
  124. }
  125. void KartenKaufenAuswahl::ksgsAktion( RCArray< KSGSVariable > *parameter, KSGSVariable **retVal )
  126. {
  127. KSGSVariable *befehl = parameter->z( 0 );
  128. if( !befehl )
  129. return;
  130. Text *b = befehl->getText();
  131. if( !b )
  132. return;
  133. if( b->istGleich( "GetBesitzStatus" ) )
  134. {
  135. int besitz = shopKlient->getKarteBesitzStatus( karteId );
  136. KSGSGetVariable getKSGSVariable = (KSGSGetVariable)GetProcAddress( ksgs, KSGS_VARIABLE_FUNKTION );
  137. if( getKSGSVariable )
  138. {
  139. KSGSVariableDef def = { KSGS_INT, 0, 3, ( Text() += besitz ).getText() };
  140. *retVal = getKSGSVariable( fenster, &def );
  141. }
  142. else
  143. {
  144. nachLogin->zNachrichtenListe()->addNachricht( new Text( "Fehler" ),
  145. new Text( "Der Einstiegspunkt '" KSGS_VARIABLE_FUNKTION "' in der DLL-Datei "
  146. "'data/bin/KSGScript.dll' konnte nicht gefunden werden." ),
  147. new Text( "Ok" ), 0, NachrichtType::nachricht, 0 );
  148. }
  149. b->release();
  150. return;
  151. }
  152. if( b->istGleich( "GetPreis" ) )
  153. {
  154. KSGSVariable *version = parameter->z( 1 );
  155. if( !version )
  156. {
  157. nachLogin->zNachrichtenListe()->addNachricht( new Text( "Fehler" ),
  158. new Text( "Auf dieser Seite befindet sich ein Fehler im KSG-Script. "
  159. "Sie könnte eventuell nicht richtig funktionieren." ),
  160. new Text( "Ok" ), 0, NachrichtType::nachricht, 0 );
  161. }
  162. else
  163. {
  164. bool testVersion = !version->getInt();
  165. int preis = shopKlient->getKartePreis( karteId, testVersion );
  166. KSGSGetVariable getKSGSVariable = (KSGSGetVariable)GetProcAddress( ksgs, KSGS_VARIABLE_FUNKTION );
  167. if( getKSGSVariable )
  168. {
  169. KSGSVariableDef def = { KSGS_INT, 0, 3, ( Text() += preis ).getText() };
  170. *retVal = getKSGSVariable( fenster, &def );
  171. }
  172. else
  173. {
  174. nachLogin->zNachrichtenListe()->addNachricht( new Text( "Fehler" ),
  175. new Text( "Der Einstiegspunkt '" KSGS_VARIABLE_FUNKTION "' in der DLL-Datei "
  176. "'data/bin/KSGScript.dll' konnte nicht gefunden werden." ),
  177. new Text( "Ok" ), 0, NachrichtType::nachricht, 0 );
  178. }
  179. }
  180. b->release();
  181. return;
  182. }
  183. if( b->istGleich( "GetTestVersionVerbleibend" ) )
  184. {
  185. int verbleibend = shopKlient->getKarteTestversion( karteId );
  186. KSGSGetVariable getKSGSVariable = (KSGSGetVariable)GetProcAddress( ksgs, KSGS_VARIABLE_FUNKTION );
  187. if( getKSGSVariable )
  188. {
  189. KSGSVariableDef def = { KSGS_INT, 0, 3, ( Text() += verbleibend ).getText() };
  190. *retVal = getKSGSVariable( fenster, &def );
  191. }
  192. else
  193. {
  194. nachLogin->zNachrichtenListe()->addNachricht( new Text( "Fehler" ),
  195. new Text( "Der Einstiegspunkt '" KSGS_VARIABLE_FUNKTION "' in der DLL-Datei "
  196. "'data/bin/KSGScript.dll' konnte nicht gefunden werden." ),
  197. new Text( "Ok" ), 0, NachrichtType::nachricht, 0 );
  198. }
  199. b->release();
  200. return;
  201. }
  202. if( b->istGleich( "GetErwerbbarStatus" ) )
  203. {
  204. int erwerbbar = shopKlient->istKarteErwerbbar( karteId );
  205. KSGSGetVariable getKSGSVariable = (KSGSGetVariable)GetProcAddress( ksgs, KSGS_VARIABLE_FUNKTION );
  206. if( getKSGSVariable )
  207. {
  208. KSGSVariableDef def = { KSGS_INT, 0, 3, ( Text() += erwerbbar ).getText() };
  209. *retVal = getKSGSVariable( fenster, &def );
  210. }
  211. else
  212. {
  213. nachLogin->zNachrichtenListe()->addNachricht( new Text( "Fehler" ),
  214. new Text( "Der Einstiegspunkt '" KSGS_VARIABLE_FUNKTION "' in der DLL-Datei "
  215. "'data/bin/KSGScript.dll' konnte nicht gefunden werden." ),
  216. new Text( "Ok" ), 0, NachrichtType::nachricht, 0 );
  217. }
  218. b->release();
  219. return;
  220. }
  221. if( b->istGleich( "GetKupfer" ) )
  222. {
  223. int kupfer = infoKlient->getKupfer();
  224. KSGSGetVariable getKSGSVariable = (KSGSGetVariable)GetProcAddress( ksgs, KSGS_VARIABLE_FUNKTION );
  225. if( getKSGSVariable )
  226. {
  227. KSGSVariableDef def = { KSGS_INT, 0, 3, ( Text() += kupfer ).getText() };
  228. *retVal = getKSGSVariable( fenster, &def );
  229. }
  230. else
  231. {
  232. nachLogin->zNachrichtenListe()->addNachricht( new Text( "Fehler" ),
  233. new Text( "Der Einstiegspunkt '" KSGS_VARIABLE_FUNKTION "' in der DLL-Datei "
  234. "'data/bin/KSGScript.dll' konnte nicht gefunden werden." ),
  235. new Text( "Ok" ), 0, NachrichtType::nachricht, 0 );
  236. }
  237. b->release();
  238. return;
  239. }
  240. if( b->istGleich( "Kaufen" ) )
  241. {
  242. KSGSVariable *version = parameter->z( 1 );
  243. if( !version )
  244. {
  245. nachLogin->zNachrichtenListe()->addNachricht( new Text( "Fehler" ),
  246. new Text( "Auf dieser Seite befindet sich ein Fehler im KSG-Script. "
  247. "Sie könnte eventuell nicht richtig funktionieren." ),
  248. new Text( "Ok" ), 0, NachrichtType::nachricht, 0 );
  249. }
  250. else
  251. {
  252. bool testVersion = !version->getInt();
  253. if( !shopKlient->karteErwerben( karteId, testVersion ) )
  254. {
  255. nachLogin->zNachrichtenListe()->addNachricht( new Text( "Fehler" ),
  256. new Text( "Die Karte konnte nicht erworben werden." ),
  257. new Text( "Ok" ), 0, NachrichtType::nachricht, 0 );
  258. }
  259. if( run )
  260. warteAufThread( 2000 );
  261. if( run )
  262. {
  263. b->release();
  264. return;
  265. }
  266. aktion = 1;
  267. start();
  268. }
  269. b->release();
  270. return;
  271. }
  272. if( b->istGleich( "GetBild" ) )
  273. {
  274. KSGSVariable *pfad = parameter->z( 1 );
  275. KSGSVariable *name = parameter->z( 2 );
  276. if( !pfad || !name )
  277. {
  278. nachLogin->zNachrichtenListe()->addNachricht( new Text( "Fehler" ),
  279. new Text( "Auf dieser Seite befindet sich ein Fehler im KSG-Script. "
  280. "Sie könnte eventuell nicht richtig funktionieren." ),
  281. new Text( "Ok" ), 0, NachrichtType::nachricht, 0 );
  282. }
  283. else
  284. {
  285. Text *pf = pfad->getText();
  286. Text *n = name->getText();
  287. if( !pf || !n )
  288. {
  289. nachLogin->zNachrichtenListe()->addNachricht( new Text( "Fehler" ),
  290. new Text( "Auf dieser Seite befindet sich ein Fehler im KSG-Script. "
  291. "Sie könnte eventuell nicht richtig funktionieren." ),
  292. new Text( "Ok" ), 0, NachrichtType::nachricht, 0 );
  293. }
  294. else
  295. {
  296. KSGSGetVariable getKSGSVariable = (KSGSGetVariable)GetProcAddress( ksgs, KSGS_VARIABLE_FUNKTION );
  297. if( getKSGSVariable )
  298. {
  299. int p = n->positionVon( ".ltdb/" );
  300. if( p < 0 )
  301. p = 0;
  302. else
  303. p += 6;
  304. Bild *b = bilder->get( *n );
  305. if( !b )
  306. {
  307. LTDBDatei *dat = new LTDBDatei();
  308. dat->setDatei( pf->getThis() );
  309. dat->leseDaten( 0 );
  310. b = dat->laden( 0, n->getTeilText( p, n->getLength() ) );
  311. dat->release();
  312. if( b )
  313. bilder->add( *n, b->getThis() );
  314. }
  315. if( b )
  316. {
  317. KSGSVariableDef def = { KSGS_BILD, 0, 3, "" };
  318. KSGSVariable *ret = getKSGSVariable( fenster, &def );
  319. KSGSSetBild setKSGSBild = (KSGSSetBild)GetProcAddress( ksgs, KSGS_SET_BILD_FUNKTION );
  320. if( !setKSGSBild )
  321. {
  322. nachLogin->zNachrichtenListe()->addNachricht( new Text( "Fehler" ),
  323. new Text( "Der Einstiegspunkt '" KSGS_SET_BILD_FUNKTION "' in der DLL-Datei "
  324. "'data/bin/KSGScript.dll' konnte nicht gefunden werden." ),
  325. new Text( "Ok" ), 0, NachrichtType::nachricht, 0 );
  326. b->release();
  327. }
  328. else
  329. setKSGSBild( ret, b );
  330. *retVal = ret;
  331. }
  332. }
  333. else
  334. {
  335. nachLogin->zNachrichtenListe()->addNachricht( new Text( "Fehler" ),
  336. new Text( "Der Einstiegspunkt '" KSGS_VARIABLE_FUNKTION "' in der DLL-Datei "
  337. "'data/bin/KSGScript.dll' konnte nicht gefunden werden." ),
  338. new Text( "Ok" ), 0, NachrichtType::nachricht, 0 );
  339. }
  340. }
  341. if( pf )
  342. pf->release();
  343. if( n )
  344. n->release();
  345. }
  346. b->release();
  347. return;
  348. }
  349. }
  350. void KartenKaufenAuswahl::doMausEreignis( MausEreignis &me )
  351. {
  352. if( run )
  353. return;
  354. me.mx -= pos.x;
  355. me.my -= pos.y;
  356. if( fenster )
  357. fenster->doMausEreignis( me );
  358. me.mx += pos.x;
  359. me.my += pos.y;
  360. }
  361. void KartenKaufenAuswahl::doTastaturEreignis( TastaturEreignis &te )
  362. {
  363. if( run )
  364. return;
  365. if( fenster )
  366. fenster->doTastaturEreignis( te );
  367. }
  368. bool KartenKaufenAuswahl::tick( double zeit )
  369. {
  370. bool rend = ( fenster && !run ) ? fenster->tick( zeit ) : 0;
  371. rend |= laden->tick( zeit );
  372. if( ( run || !karteId ) && alpha > 0 )
  373. {
  374. if( alpha - zeit * 150 < 0 )
  375. alpha = 0;
  376. else
  377. alpha -= (unsigned char)( zeit * 150 );
  378. rend = 1;
  379. }
  380. if( !run && karteId && alpha < 255 )
  381. {
  382. if( alpha + zeit * 150 > 255 )
  383. alpha = 255;
  384. else
  385. alpha += (unsigned char)( zeit * 150 );
  386. rend = 1;
  387. }
  388. return rend;
  389. }
  390. void KartenKaufenAuswahl::render( Bild &zRObj )
  391. {
  392. if( !zRObj.setDrawOptions( pos.x, pos.y, ram->getBreite(), ram->getHeight() ) )
  393. return;
  394. zRObj.setAlpha( alpha );
  395. ram->render( zRObj );
  396. if( fenster )
  397. fenster->render( zRObj );
  398. zRObj.releaseAlpha();
  399. laden->render( zRObj );
  400. zRObj.releaseDrawOptions();
  401. }
  402. // constant
  403. // Reference Counting
  404. KartenKaufenAuswahl *KartenKaufenAuswahl::getThis()
  405. {
  406. ref++;
  407. return this;
  408. }
  409. KartenKaufenAuswahl *KartenKaufenAuswahl::release()
  410. {
  411. ref--;
  412. if( !ref )
  413. delete this;
  414. return 0;
  415. }
  416. // Inhalt der KartenKaufenListeEintrag Klasse aus KartenKaufen.h
  417. // Konstruktor
  418. KartenKaufenListeEintrag::KartenKaufenListeEintrag( int id, Schrift *schrift )
  419. {
  420. karteId = id;
  421. auswählen = initKnopf( 173, 73, 22, 22, 0, 0, "" );
  422. auswählen->setStyle( Knopf::Style::Sichtbar | Knopf::Style::Erlaubt | Knopf::Style::Rahmen | Knopf::Style::Hintergrund | Knopf::Style::HBild | Knopf::Style::KlickBuffer );
  423. auswählen->setHintergrundBildZ( bilder->get( "shop.ltdb/weiter.png" ) );
  424. initToolTip( auswählen, "Karte auswählen.", schrift, hauptScreen );
  425. auswählen->setLinienRahmenBreite( 1 );
  426. LTDBDatei *datei = new LTDBDatei();
  427. Text *bdpf = new Text( "data/tmp/shop/kaufen/karten/" );
  428. bdpf->append( id );
  429. bdpf->append( "/titelbg.ltdb" );
  430. datei->setDatei( bdpf );
  431. hintergrund = datei->laden( 0, new Text( "auswbg.jpg" ) );
  432. datei->release();
  433. ausgewählt = new AlphaFeld();
  434. ausgewählt->setPosition( 1, 1 );
  435. ausgewählt->setSize( 198, 98 );
  436. ausgewählt->setFarbe( 0x0000FF00 );
  437. ausgewählt->setStrength( 10 );
  438. ram = new LRahmen();
  439. ram->setSize( 200, 100 );
  440. ram->setFarbe( 0xFFFFFFFF );
  441. ausw = 0;
  442. rend = 0;
  443. ref = 1;
  444. }
  445. // Destruktor
  446. KartenKaufenListeEintrag::~KartenKaufenListeEintrag()
  447. {
  448. auswählen->release();
  449. if( hintergrund )
  450. hintergrund->release();
  451. ausgewählt->release();
  452. ram->release();
  453. }
  454. // nicht constant
  455. void KartenKaufenListeEintrag::resetAuswahl()
  456. {
  457. ausw = 0;
  458. }
  459. bool KartenKaufenListeEintrag::doMausEreignis( MausEreignis &me )
  460. {
  461. bool vera = me.verarbeitet;
  462. auswählen->doMausEreignis( me );
  463. if( !vera && me.verarbeitet && me.id == ME_RLinks )
  464. {
  465. ausw = 1;
  466. return 1;
  467. }
  468. return 0;
  469. }
  470. bool KartenKaufenListeEintrag::tick( double zeit )
  471. {
  472. rend |= ausgewählt->tick( zeit );
  473. rend |= auswählen->tick( zeit );
  474. int a = ( ausgewählt->getFarbe() >> 24 ) & 0xFF;
  475. if( ausw && a < 255 )
  476. {
  477. if( a + 150 * zeit > 255 )
  478. a = 255;
  479. else
  480. a += (int)( zeit * 150 );
  481. ausgewählt->setFarbe( ( ( a << 24 ) & 0xFF000000 ) | ( ausgewählt->getFarbe() & 0xFFFFFF ) );
  482. rend = 1;
  483. }
  484. if( !ausw && a > 0 )
  485. {
  486. if( a - 150 * zeit < 0 )
  487. a = 0;
  488. else
  489. a += (int)( zeit * 150 );
  490. ausgewählt->setFarbe( ( ( a << 24 ) & 0xFF000000 ) | ( ausgewählt->getFarbe() & 0xFFFFFF ) );
  491. rend = 1;
  492. }
  493. bool ret = rend;
  494. rend = 0;
  495. return ret;
  496. }
  497. void KartenKaufenListeEintrag::render( int yOff, Bild &zRObj )
  498. {
  499. if( !zRObj.setDrawOptions( 0, yOff, 200, 100 ) )
  500. return;
  501. ram->render( zRObj );
  502. if( hintergrund )
  503. zRObj.drawBild( 1, 1, 198, 98, *hintergrund );
  504. ausgewählt->render( zRObj );
  505. auswählen->render( zRObj );
  506. zRObj.releaseDrawOptions();
  507. }
  508. // constant
  509. int KartenKaufenListeEintrag::getKarteId() const
  510. {
  511. return karteId;
  512. }
  513. // Reference Counting
  514. KartenKaufenListeEintrag *KartenKaufenListeEintrag::getThis()
  515. {
  516. ref++;
  517. return this;
  518. }
  519. KartenKaufenListeEintrag *KartenKaufenListeEintrag::release()
  520. {
  521. ref--;
  522. if( !ref )
  523. delete this;
  524. return 0;
  525. }
  526. // Inhalt der KartenKaufenListe Klasse aus KartenKaufen.h
  527. // Konstruktor
  528. KartenKaufenListe::KartenKaufenListe( Schrift *schrift )
  529. {
  530. s = schrift;
  531. pos = Punkt( 5, 55 );
  532. ram = new LRahmen();
  533. ram->setSize( 215, 380 );
  534. ram->setFarbe( 0xFFFFFFFF );
  535. einträge = new RCArray< KartenKaufenListeEintrag >();
  536. vScroll = new VScrollBar();
  537. vScroll->setKlickScroll( 10 );
  538. vScroll->update( 0, 380 );
  539. rend = 0;
  540. ref = 1;
  541. }
  542. // Destruktor
  543. KartenKaufenListe::~KartenKaufenListe()
  544. {
  545. s->release();
  546. ram->release();
  547. einträge->release();
  548. vScroll->release();
  549. }
  550. // nicht constant
  551. void KartenKaufenListe::ladeKarten( Array< int > *karten )
  552. {
  553. leeren();
  554. int anz = karten->getEintragAnzahl();
  555. for( int i = 0; i < anz; i++ )
  556. {
  557. if( shopKlient->ladeKarteTitel( karten->hat( i ) ? karten->get( i ) : 0 ) )
  558. einträge->add( new KartenKaufenListeEintrag( karten->hat( i ) ? karten->get( i ) : 0, s->getThis() ) );
  559. }
  560. vScroll->update( anz * 100, 380 );
  561. rend = 1;
  562. }
  563. void KartenKaufenListe::leeren()
  564. {
  565. cs.lock();
  566. einträge->leeren();
  567. cs.unlock();
  568. vScroll->update( 0, 380 );
  569. rend = 1;
  570. }
  571. int KartenKaufenListe::doMausEreignis( MausEreignis &me )
  572. {
  573. int mx = me.mx;
  574. int my = me.my;
  575. me.mx -= pos.x;
  576. me.my -= pos.y;
  577. vScroll->doMausMessage( 200, 0, 15, 380, me );
  578. me.my += vScroll->getScroll();
  579. int ret = 0;
  580. cs.lock();
  581. int anz = einträge->getEintragAnzahl();
  582. for( int i = 0; i < anz; i++ )
  583. {
  584. if( einträge->z( i )->doMausEreignis( me ) )
  585. ret = einträge->z( i )->getKarteId();
  586. me.my += 100;
  587. }
  588. if( ret )
  589. {
  590. for( int i = 0; i < anz; i++ )
  591. {
  592. if( einträge->z( i )->getKarteId() != ret )
  593. einträge->z( i )->resetAuswahl();
  594. }
  595. }
  596. cs.unlock();
  597. me.mx = mx;
  598. me.my = my;
  599. return ret;
  600. }
  601. bool KartenKaufenListe::tick( double zeit )
  602. {
  603. rend |= vScroll->getRend();
  604. cs.lock();
  605. int anz = einträge->getEintragAnzahl();
  606. for( int i = 0; i < anz; i++ )
  607. rend |= einträge->z( i )->tick( zeit );
  608. cs.unlock();
  609. bool ret = rend;
  610. rend = 0;
  611. return ret;
  612. }
  613. void KartenKaufenListe::render( Bild &zRObj )
  614. {
  615. int br = ram->getBreite();
  616. int hö = ram->getHeight();
  617. if( !zRObj.setDrawOptions( pos.x, pos.y, br, hö ) )
  618. return;
  619. ram->render( zRObj );
  620. cs.lock();
  621. int anz = einträge->getEintragAnzahl();
  622. for( int i = 0; i < anz; i++ )
  623. einträge->z( i )->render( i * 100 - vScroll->getScroll(), zRObj );
  624. cs.unlock();
  625. vScroll->render( 200, 0, 15, 380, zRObj );
  626. zRObj.releaseDrawOptions();
  627. }
  628. // constant
  629. int KartenKaufenListe::getEintragAnzahl()
  630. {
  631. return einträge->getEintragAnzahl();
  632. }
  633. // Reference Counting
  634. KartenKaufenListe *KartenKaufenListe::getThis()
  635. {
  636. ref++;
  637. return this;
  638. }
  639. KartenKaufenListe *KartenKaufenListe::release()
  640. {
  641. ref--;
  642. if( !ref )
  643. delete this;
  644. return 0;
  645. }
  646. // Inhalt der KartenKaufen Klasse aus KartenKaufen.h
  647. // Konstruktor
  648. KartenKaufen::KartenKaufen( Schrift *zSchrift )
  649. : Thread()
  650. {
  651. Bild *shopZurück = bilder->get( "shop.ltdb/zurück.png" );
  652. if( !shopZurück )
  653. {
  654. LTDBDatei *datei = new LTDBDatei();
  655. datei->setDatei( new Text( "data/client/bilder/shop.ltdb" ) );
  656. datei->leseDaten( 0 );
  657. shopZurück = datei->laden( 0, new Text( "zurück.png" ) );
  658. datei->release();
  659. bilder->add( "shop.ltdb/zurück.png", shopZurück->getThis() );
  660. }
  661. Bild *shopWeiter = bilder->get( "shop.ltdb/weiter.png" );
  662. if( !shopWeiter )
  663. {
  664. LTDBDatei *datei = new LTDBDatei();
  665. datei->setDatei( new Text( "data/client/bilder/shop.ltdb" ) );
  666. datei->leseDaten( 0 );
  667. shopWeiter = datei->laden( 0, new Text( "weiter.png" ) );
  668. datei->release();
  669. bilder->add( "shop.ltdb/weiter.png", shopWeiter->getThis() );
  670. }
  671. alpha = 255;
  672. sichtbar = 0;
  673. suchText = new Text( "" );
  674. ram = new LRahmen();
  675. ram->setSize( 780, 440 );
  676. ram->setFarbe( 0xFFFFFFFF );
  677. pos = Punkt( 10, 50 );
  678. spielArt = new AuswahlBox();
  679. spielArt->setStyle( AuswahlBox::Style::AuswahlBuffer | AuswahlBox::Style::MausBuffer | AuswahlBox::Style::Erlaubt | AuswahlBox::Style::Hintergrund |
  680. AuswahlBox::Style::Rahmen | AuswahlBox::Style::Sichtbar | AuswahlBox::Style::VScroll | AuswahlBox::Style::MaxHeight );
  681. spielArt->setSize( 200, 20 );
  682. spielArt->setPosition( 5, 5 );
  683. spielArt->setLinienRahmenFarbe( 0xFFFFFFFF );
  684. spielArt->setLinienRahmenBreite( 1 );
  685. spielArt->setMaxAuskappHeight( 100 );
  686. spielArt->setSchriftZ( zSchrift->getThis() );
  687. spielArt->setHintergrundFarbe( 0xFF000000 );
  688. spielArt->setMausEreignis( _ret1ME );
  689. spielArt->setAuswAlphaFeldFarbe( 0x5000FF00 );
  690. spielArt->setAuswAlphaFeldStrength( -10 );
  691. spielArt->setMausAlphaFeldFarbe( 0x1000FF00 );
  692. spielArt->setMausAlphaFeldStrength( -10 );
  693. spielArt->setEintragHeight( 20 );
  694. spielArt->addEintrag( "Spiel Art wählen" );
  695. suchFilterT = initTextFeld( 210, 5, 70, 20, zSchrift, TextFeld::Style::Text, "Suchfilter:" );
  696. suchFilter = initTextFeld( 285, 5, 225, 20, zSchrift, TextFeld::Style::TextFeld, "" );
  697. initToolTip( suchFilter, "Gebe etwas vom Namen der Karte ein, nach der du suchst.", zSchrift->getThis(), hauptScreen );
  698. suchen = initKnopf( 515, 5, 100, 20, zSchrift, Knopf::Style::Sichtbar, "suchen" );
  699. seiten = initTextFeld( 55, 30, 250, 20, zSchrift, TextFeld::Style::Text | TextFeld::Style::VCenter, "Seite 0 von 0, 0 Funde." );
  700. zurück = initKnopf( 5, 30, 20, 20, 0, 0, "" );
  701. zurück->setStyle( Knopf::Style::Sichtbar | Knopf::Style::Hintergrund | Knopf::Style::HBild | Knopf::Style::KlickBuffer );
  702. zurück->setHintergrundBildZ( shopZurück );
  703. initToolTip( zurück, "Seite zurück blättern.", zSchrift->getThis(), hauptScreen );
  704. weiter = initKnopf( 30, 30, 20, 20, 0, 0, "" );
  705. weiter->setStyle( Knopf::Style::Sichtbar | Knopf::Style::Hintergrund | Knopf::Style::HBild | Knopf::Style::KlickBuffer );
  706. weiter->setHintergrundBildZ( shopWeiter );
  707. initToolTip( weiter, "Seite weiter blättern.", zSchrift->getThis(), hauptScreen );
  708. liste = new KartenKaufenListe( zSchrift->getThis() );
  709. auswahl = new KartenKaufenAuswahl( zSchrift );
  710. laden = ( Framework::Animation2D* )ladeAnimation->dublizieren();
  711. laden->setPosition( 365, 195 );
  712. laden->setSichtbar( 0 );
  713. tickVal = 0;
  714. seite = 0;
  715. maxSeite = 0;
  716. rend = 0;
  717. aktion = 0;
  718. ref = 1;
  719. start();
  720. }
  721. // Destruktor
  722. KartenKaufen::~KartenKaufen()
  723. {
  724. if( run )
  725. warteAufThread( 1000 );
  726. if( run )
  727. ende();
  728. spielArt->release();
  729. suchText->release();
  730. ram->release();
  731. suchFilterT->release();
  732. suchFilter->release();
  733. suchen->release();
  734. seiten->release();
  735. weiter->release();
  736. zurück->release();
  737. liste->release();
  738. auswahl->release();
  739. laden->release();
  740. }
  741. // nicht constant
  742. void KartenKaufen::setSichtbar( bool sicht )
  743. {
  744. sichtbar = sicht;
  745. if( !run && sichtbar )
  746. {
  747. aktion = 0;
  748. start();
  749. }
  750. }
  751. void KartenKaufen::thread()
  752. {
  753. laden->setSichtbar( 1 );
  754. if( !aktion )
  755. {
  756. Array< int > *saList = infoKlient->getAccountSpielArtListe();
  757. if( saList )
  758. {
  759. RCArray< Text > *saNamen = new RCArray< Text >();
  760. int anz = saList->getEintragAnzahl();
  761. for( int i = 0; i < anz; i++ )
  762. {
  763. if( !saList->hat( i ) )
  764. continue;
  765. Text *name = infoKlient->getSpielName( saList->hat( i ) ? saList->get( i ) : 0 );
  766. if( name )
  767. saNamen->add( name );
  768. }
  769. spielArt->lockZeichnung();
  770. spielArt->setAuswahl( 0 );
  771. anz = spielArt->getEintragAnzahl();
  772. for( int i = 1; i < anz; i++ )
  773. spielArt->removeEintrag( 1 );
  774. anz = saNamen->getEintragAnzahl();
  775. for( int i = 0; i < anz; i++ )
  776. {
  777. if( saNamen->z( i ) )
  778. spielArt->addEintrag( saNamen->z( i )->getText() );
  779. }
  780. spielArt->unlockZeichnung();
  781. saNamen->release();
  782. saList->release();
  783. }
  784. if( !liste->getEintragAnzahl() )
  785. {
  786. hauptScreen->lock();
  787. suchText->setText( suchFilter->zText()->getText() );
  788. seite = 1;
  789. maxSeite = 1;
  790. aktion = 1;
  791. hauptScreen->unlock();
  792. }
  793. if( !aktion )
  794. {
  795. laden->setSichtbar( 0 );
  796. return;
  797. }
  798. }
  799. int spielArtId = 0;
  800. if( spielArt->getAuswahl() > 0 )
  801. spielArtId = infoKlient->getSpielId( spielArt->zEintrag( spielArt->getAuswahl() )->zText()->getText() );
  802. Array< int > *list = shopKlient->suchKarten( suchText->getText(), spielArtId );
  803. if( !list )
  804. {
  805. laden->setSichtbar( 0 );
  806. run = 0;
  807. return;
  808. }
  809. Array< int > *slist = new Array< int >();
  810. int anz = list->getEintragAnzahl();
  811. maxSeite = anz / 10 + 1;
  812. if( !( anz % 10 ) )
  813. maxSeite--;
  814. while( anz <= seite * 10 && seite > 0 )
  815. seite--;
  816. for( int i = seite * 10; i < anz && i < seite * 10 + 10; i++ )
  817. slist->add( list->hat( i ) ? list->get( i ) : 0 );
  818. list->release();
  819. auswahl->reset();
  820. liste->ladeKarten( slist );
  821. slist->release();
  822. Text *t = new Text( "Seite " );
  823. t->append( maxSeite ? seite + 1 : 0 );
  824. t->append( " von " );
  825. t->append( maxSeite );
  826. t->append( ", " );
  827. t->append( anz );
  828. if( anz == 1 )
  829. t->append( " Fund." );
  830. else
  831. t->append( " Funde." );
  832. seiten->setText( t );
  833. zurück->setStyle( TextFeld::Style::Erlaubt, seite > 0 );
  834. weiter->setStyle( TextFeld::Style::Erlaubt, seite + 1 < maxSeite );
  835. laden->setSichtbar( 0 );
  836. }
  837. void KartenKaufen::doMausEreignis( MausEreignis &me )
  838. {
  839. if( !sichtbar || run )
  840. return;
  841. int mx = me.mx;
  842. int my = me.my;
  843. me.mx -= pos.x;
  844. me.my -= pos.y;
  845. spielArt->doMausEreignis( me );
  846. suchFilter->doMausEreignis( me );
  847. int auswId = liste->doMausEreignis( me );
  848. if( auswId )
  849. auswahl->ladeKarteSeite( auswId );
  850. auswahl->doMausEreignis( me );
  851. int ak = 0;
  852. bool tmp = me.verarbeitet;
  853. suchen->doMausEreignis( me );
  854. ak = me.verarbeitet ? 1 : 0;
  855. zurück->doMausEreignis( me );
  856. ak = me.verarbeitet && !ak ? 2 : ak;
  857. weiter->doMausEreignis( me );
  858. ak = me.verarbeitet && !ak ? 3 : ak;
  859. if( tmp )
  860. ak = 0;
  861. if( me.id == ME_RLinks )
  862. {
  863. switch( ak )
  864. {
  865. case 1: // Suchen
  866. suchText->setText( suchFilter->zText()->getText() );
  867. seite = 1;
  868. maxSeite = 1;
  869. aktion = 1;
  870. start();
  871. break;
  872. case 2: // Seite zurück blättern
  873. seite--;
  874. if( seite < 1 )
  875. seite = 1;
  876. aktion = 1;
  877. start();
  878. break;
  879. case 3: // Seite vorwärts blättern
  880. seite++;
  881. if( seite > maxSeite )
  882. seite = maxSeite;
  883. aktion = 1;
  884. start();
  885. break;
  886. }
  887. }
  888. me.mx = mx;
  889. me.my = my;
  890. }
  891. void KartenKaufen::doTastaturEreignis( TastaturEreignis &te )
  892. {
  893. if( !sichtbar || run )
  894. return;
  895. bool vera = te.verarbeitet;
  896. suchFilter->doTastaturEreignis( te );
  897. if( !vera && te.verarbeitet && te.taste == T_Enter && te.id == TE_Release )
  898. {
  899. MausEreignis me;
  900. me.id = ME_RLinks;
  901. me.verarbeitet = 0;
  902. me.mx = suchen->getX() + 1 + pos.x;
  903. me.my = suchen->getY() + 1 + pos.y;
  904. doMausEreignis( me );
  905. }
  906. auswahl->doTastaturEreignis( te );
  907. }
  908. bool KartenKaufen::tick( double zeit )
  909. {
  910. rend |= spielArt->tick( zeit );
  911. rend |= suchFilter->tick( zeit );
  912. rend |= suchen->tick( zeit );
  913. rend |= weiter->tick( zeit );
  914. rend |= zurück->tick( zeit );
  915. rend |= liste->tick( zeit );
  916. rend |= auswahl->tick( zeit );
  917. rend |= laden->tick( zeit );
  918. tickVal += zeit * 250;
  919. int val = (int)tickVal;
  920. if( val < 1 )
  921. {
  922. bool ret = rend;
  923. rend = 0;
  924. return ret;
  925. }
  926. if( val > 10 )
  927. val = 10;
  928. tickVal -= val;
  929. if( sichtbar && alpha != 255 && !run )
  930. {
  931. if( alpha + val > 255 )
  932. alpha = 255;
  933. else
  934. alpha += val;
  935. rend = 1;
  936. }
  937. if( sichtbar && alpha != 125 && run )
  938. {
  939. if( alpha > 125 )
  940. {
  941. if( alpha - val < 125 )
  942. alpha = 125;
  943. else
  944. alpha -= val;
  945. rend = 1;
  946. }
  947. else
  948. {
  949. if( alpha + val > 125 )
  950. alpha = 125;
  951. else
  952. alpha += 125;
  953. rend = 1;
  954. }
  955. }
  956. if( !sichtbar && alpha != 0 )
  957. {
  958. if( alpha - val < 0 )
  959. alpha = 0;
  960. else
  961. alpha -= val;
  962. rend = 1;
  963. }
  964. bool ret = rend;
  965. rend = 0;
  966. return ret;
  967. }
  968. void KartenKaufen::render( Bild &zRObj )
  969. {
  970. if( !alpha )
  971. return;
  972. int br = ram->getBreite();
  973. int hö = ram->getHeight();
  974. if( !zRObj.setDrawOptions( pos.x, pos.y, br, hö ) )
  975. return;
  976. zRObj.setAlpha( alpha );
  977. ram->render( zRObj );
  978. suchFilterT->render( zRObj );
  979. suchFilter->render( zRObj );
  980. suchen->render( zRObj );
  981. seiten->render( zRObj );
  982. weiter->render( zRObj );
  983. zurück->render( zRObj );
  984. liste->render( zRObj );
  985. auswahl->render( zRObj );
  986. spielArt->render( zRObj );
  987. zRObj.releaseAlpha();
  988. laden->render( zRObj );
  989. zRObj.releaseDrawOptions();
  990. }
  991. // constant
  992. bool KartenKaufen::istSichtbar() const
  993. {
  994. return sichtbar;
  995. }
  996. // Reference Counting
  997. KartenKaufen *KartenKaufen::getThis()
  998. {
  999. ref++;
  1000. return this;
  1001. }
  1002. KartenKaufen *KartenKaufen::release()
  1003. {
  1004. ref--;
  1005. if( !ref )
  1006. delete this;
  1007. return 0;
  1008. }