AccountStatistik.cpp 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403
  1. #include "AccountStatistik.h"
  2. #include "../../../Global/Initialisierung.h"
  3. #include "../../../Global/Variablen.h"
  4. #include <DateiSystem.h>
  5. // Inhalt der AccountStatistik Klasse aus AccountStatistik.h
  6. // Konstruktor
  7. AccountStatistik::AccountStatistik( Schrift *zSchrift )
  8. : Thread(),
  9. schrift( zSchrift->getThis() ),
  10. statistikF( initFenster( 810, 40, 780, 450, zSchrift, Fenster::Style::Sichtbar | Fenster::Style::Titel | Fenster::Style::TitelBuffered | Fenster::Style::Rahmen | Fenster::Style::Erlaubt, "Statistik von " ) ),
  11. sortSpalte( initAuswahlBox( 10, 10, 150, 20, zSchrift, ABSTYLE, { "Name", "Spiele", "Gewonnen", "Verloren", "Punkte", "BW0", "BW1", "BW2", "BW3", "BW4", "BW5" } ) ),
  12. sortRichtung( initAuswahlBox( 170, 10, 150, 20, zSchrift, ABSTYLE, { "Aufwärts", "Abwärts" } ) ),
  13. zurück( initKnopf( 590, 10, 20, 20, 0, 0, "" ) ),
  14. vor( initKnopf( 750, 10, 20, 20, 0, 0, "" ) ),
  15. seiteTF( initTextFeld( 620, 10, 120, 20, zSchrift, TextFeld::Style::Text | TextFeld::Style::Center, "Seite 0 von 0" ) ),
  16. tabelle( initObjTabelle( 10, 40, 760, 400, zSchrift, OTSTYLE, { { "Name", 108, 0, 0 }, { "Spiele", 70, 0, 0 }, { "Gewonnen", 70, 0, 0 },
  17. { "Verloren", 70, 0, 0 }, { "Punkte", 70, 0, 0 }, { "BW0", 60, 0, 0 }, { "BW1", 60, 0, 0 }, { "BW2", 60, 0, 0 }, { "BW3", 60, 0, 0 },
  18. { "BW4", 60, 0, 0 }, { "BW5", 60, 0, 0 } }, 20 ) ),
  19. laden( (Animation2D*)ladeAnimation->dublizieren() ),
  20. seite( 0 ),
  21. maxSeite( 0 ),
  22. status( 0 ),
  23. accId( 0 ),
  24. animation( 0 ),
  25. alpha( 255 ),
  26. tickVal( 0 ),
  27. rend( 0 ),
  28. ref( 1 )
  29. {
  30. initToolTip( sortSpalte, "Wähle aus, nach welcher Spalte die\nTabelle sortiert werden soll.", zSchrift->getThis(), hauptScreen );
  31. initToolTip( sortRichtung, "Wähle aus, ob Aufwärts oder Abwärts\nsortiert werden soll.", zSchrift->getThis(), hauptScreen );
  32. Bild *zurückB = bilder->get( "shop.ltdb/zurück.png" );
  33. if( !zurückB )
  34. {
  35. LTDBDatei *datei = new LTDBDatei();
  36. datei->setDatei( new Text( "data/client/bilder/shop.ltdb" ) );
  37. datei->leseDaten( 0 );
  38. zurückB = datei->laden( 0, new Text( "zurück.png" ) );
  39. datei->release();
  40. bilder->add( "shop.ltdb/zurück.png", zurückB->getThis() );
  41. }
  42. Bild *weiterB = bilder->get( "shop.ltdb/weiter.png" );
  43. if( !weiterB )
  44. {
  45. LTDBDatei *datei = new LTDBDatei();
  46. datei->setDatei( new Text( "data/client/bilder/shop.ltdb" ) );
  47. datei->leseDaten( 0 );
  48. weiterB = datei->laden( 0, new Text( "weiter.png" ) );
  49. datei->release();
  50. bilder->add( "shop.ltdb/weiter.png", weiterB->getThis() );
  51. }
  52. laden->setSichtbar( 0 );
  53. laden->setPosition( 365, 200 );
  54. zurück->setStyle( Knopf::Style::Sichtbar | Knopf::Style::Hintergrund | Knopf::Style::HBild | Knopf::Style::KlickBuffer );
  55. zurück->setHintergrundBildZ( zurückB );
  56. initToolTip( zurück, "Eine Seite zurück blättern.", zSchrift->getThis(), hauptScreen );
  57. vor->setStyle( Knopf::Style::Sichtbar | Knopf::Style::Hintergrund | Knopf::Style::HBild | Knopf::Style::KlickBuffer );
  58. vor->setHintergrundBildZ( weiterB );
  59. initToolTip( vor, "Eine Seite weiter blättern.", zSchrift->getThis(), hauptScreen );
  60. statistikF->addMember( tabelle );
  61. statistikF->addMember( zurück );
  62. statistikF->addMember( seiteTF );
  63. statistikF->addMember( vor );
  64. statistikF->addMember( sortSpalte );
  65. statistikF->addMember( sortRichtung );
  66. statistikF->setMausEreignis( _ret1ME );
  67. vor->setMausEreignis( accountStatistikVorME );
  68. zurück->setMausEreignis( accountStatistikZurückME );
  69. }
  70. // Destruktor
  71. AccountStatistik::~AccountStatistik()
  72. {
  73. reset( 1 );
  74. statistikF->release();
  75. sortSpalte->release();
  76. sortRichtung->release();
  77. zurück->release();
  78. vor->release();
  79. seiteTF->release();
  80. tabelle->release();
  81. laden->release();
  82. schrift->release();
  83. }
  84. // nicht constant
  85. void AccountStatistik::reset( bool überschrift )
  86. {
  87. statistikF->lockZeichnung();
  88. int zAnz = tabelle->getZeilenAnzahl();
  89. int sAnz = tabelle->getSpaltenAnzahl();
  90. for( int i = !überschrift; i < zAnz; i++ )
  91. {
  92. for( int j = 0; j < sAnz; j++ )
  93. {
  94. if( !tabelle->zZeichnung( j, !überschrift ) )
  95. continue;
  96. ( (TextFeld*)tabelle->zZeichnung( j, !überschrift ) )->release();
  97. }
  98. tabelle->removeZeile( !überschrift );
  99. }
  100. statistikF->unlockZeichnung();
  101. }
  102. void AccountStatistik::ladeStatistik( int accId )
  103. {
  104. if( this->accId == accId )
  105. return;
  106. this->status = 0;
  107. if( run )
  108. {
  109. warteAufThread( 1000 );
  110. ende();
  111. }
  112. if( ( animation | 0x1 ) == animation )
  113. {
  114. animation |= 0x4;
  115. this->accId = accId;
  116. this->status = 1;
  117. return;
  118. }
  119. this->accId = accId;
  120. start();
  121. this->status = 1;
  122. }
  123. void AccountStatistik::thread()
  124. {
  125. laden->setSichtbar( 1 );
  126. reset();
  127. Text *name = infoKlient->getSpielerName( accId );
  128. if( name )
  129. {
  130. name->insert( 0, "Statistik von " );
  131. statistikF->setTitel( *name );
  132. name->release();
  133. }
  134. RCArray< Array< int > > *values = new RCArray< Array< int > >();
  135. RCArray< Text > *namen = new RCArray< Text >();
  136. if( infoKlient->getStatistikListe( accId, &seite, &maxSeite, sortSpalte->getAuswahl(), sortRichtung->getAuswahl(), values, namen ) )
  137. {
  138. statistikF->lockZeichnung();
  139. seiteTF->setText( "Seite " );
  140. seiteTF->zText()->append( seite );
  141. seiteTF->zText()->append( " von " );
  142. seiteTF->zText()->append( maxSeite );
  143. statistikF->unlockZeichnung();
  144. zurück->setStyle( Knopf::Style::Erlaubt, seite > 1 );
  145. vor->setStyle( Knopf::Style::Erlaubt, seite < maxSeite );
  146. int zAnz = values->getEintragAnzahl();
  147. if( zAnz )
  148. {
  149. int sAnz = values->z( 0 )->getEintragAnzahl();
  150. for( int i = 0; i < zAnz; i++ )
  151. {
  152. if( sAnz )
  153. {
  154. tabelle->addZeile( Text() += values->z( i )->get( 0 ) );
  155. Text *name = namen->z( i );
  156. if( name )
  157. {
  158. TextFeld *tf = initTextFeld( 0, 0, 0, 0, schrift, TextFeld::Style::Text | TextFeld::Style::Center, *name );
  159. tabelle->setZeichnungZ( 0, i + 1, tf );
  160. }
  161. }
  162. for( int j = 1; j < sAnz; j++ )
  163. {
  164. if( j < 1 )
  165. {
  166. TextFeld *tf = initTextFeld( 0, 0, 0, 0, schrift, TextFeld::Style::Text | TextFeld::Style::Center, "" );
  167. tf->zText()->append( values->z( i )->get( j ) );
  168. tabelle->setZeichnungZ( j, i + 1, tf );
  169. }
  170. if( j > 1 )
  171. {
  172. TextFeld *tf = initTextFeld( 0, 0, 0, 0, schrift, TextFeld::Style::Text | TextFeld::Style::Center, "" );
  173. tf->zText()->append( values->z( i )->get( j ) );
  174. tabelle->setZeichnungZ( j - 1, i + 1, tf );
  175. }
  176. }
  177. }
  178. }
  179. }
  180. else
  181. nachLogin->zNachrichtenListe()->addNachricht( new Text( "Fehler" ), new Text( "Die Statistiken dieses Spielers konnten nicht abgerufen werden." ), new Text( "Ok" ) );
  182. values->release();
  183. namen->release();
  184. laden->setSichtbar( 0 );
  185. animation &= ~0x4;
  186. status = 2;
  187. run = 0;
  188. }
  189. void AccountStatistik::setSichtbar( bool sichtbar, bool nachRechts )
  190. {
  191. if( sichtbar )
  192. {
  193. if( ( animation | 0x1 ) != animation || ( ( nachRechts && ( animation | 0x2 ) != animation ) || !nachRechts && ( animation | 0x2 ) == animation ) )
  194. {
  195. if( nachRechts )
  196. statistikF->setPosition( -810, 40 );
  197. else
  198. statistikF->setPosition( 810, 40 );
  199. }
  200. animation |= 0x1;
  201. }
  202. else
  203. animation &= ~0x1;
  204. if( nachRechts )
  205. animation |= 0x2;
  206. else
  207. animation &= ~0x2;
  208. }
  209. bool AccountStatistik::vorME( MausEreignis &me )
  210. {
  211. if( me.id == ME_RLinks )
  212. {
  213. seite++;
  214. start();
  215. }
  216. return 1;
  217. }
  218. bool AccountStatistik::zurückME( MausEreignis &me )
  219. {
  220. if( me.id == ME_RLinks )
  221. {
  222. seite--;
  223. start();
  224. }
  225. return 1;
  226. }
  227. bool AccountStatistik::tick( double zeit )
  228. {
  229. statistikF->lockZeichnung();
  230. rend |= statistikF->tick( zeit );
  231. statistikF->unlockZeichnung();
  232. rend |= laden->tick( zeit );
  233. tickVal += zeit;
  234. int valA = (int)( tickVal * 150 );
  235. int valB = (int)( tickVal * 500 );
  236. tickVal -= valA / 150.0;
  237. if( valA )
  238. {
  239. if( ( animation | 0x4 ) == animation && alpha )
  240. {
  241. if( alpha - valA <= 0 )
  242. alpha = 0;
  243. else
  244. alpha -= valA;
  245. rend = 1;
  246. if( !alpha )
  247. {
  248. reset();
  249. start();
  250. }
  251. }
  252. if( ( animation | 0x4 ) != animation && alpha != 255 )
  253. {
  254. if( alpha + valA >= 255 )
  255. alpha = 255;
  256. else
  257. alpha += valA;
  258. rend = 1;
  259. }
  260. }
  261. if( valB )
  262. {
  263. if( ( animation | 0x1 ) == animation )
  264. { // Sichtbar
  265. if( ( animation | 0x2 ) == animation )
  266. { // Nach Rechts
  267. if( statistikF->getX() != 10 )
  268. {
  269. if( statistikF->getX() + valB > 10 )
  270. statistikF->setPosition( 10, statistikF->getY() );
  271. else
  272. statistikF->setPosition( statistikF->getX() + valB, statistikF->getY() );
  273. rend = 1;
  274. }
  275. }
  276. else
  277. { // Nach Links
  278. if( statistikF->getX() != 10 )
  279. {
  280. if( statistikF->getX() - valB < 10 )
  281. statistikF->setPosition( 10, statistikF->getY() );
  282. else
  283. statistikF->setPosition( statistikF->getX() - valB, statistikF->getY() );
  284. rend = 1;
  285. }
  286. }
  287. }
  288. else
  289. { // Unsichtbar
  290. if( ( animation | 0x2 ) == animation )
  291. { // Nach Rechts
  292. if( statistikF->getX() != 810 )
  293. {
  294. if( statistikF->getX() + valB > 810 )
  295. statistikF->setPosition( 810, statistikF->getY() );
  296. else
  297. statistikF->setPosition( statistikF->getX() + valB, statistikF->getY() );
  298. rend = 1;
  299. }
  300. }
  301. else
  302. { // Nach Links
  303. if( statistikF->getX() != -810 )
  304. {
  305. if( statistikF->getX() - valB < -810 )
  306. statistikF->setPosition( -810, statistikF->getY() );
  307. else
  308. statistikF->setPosition( statistikF->getX() - valB, statistikF->getY() );
  309. rend = 1;
  310. }
  311. }
  312. }
  313. }
  314. bool ret = rend;
  315. rend = 0;
  316. return ret;
  317. }
  318. void AccountStatistik::doMausEreignis( MausEreignis &me )
  319. {
  320. if( run )
  321. return;
  322. bool starten = 0;
  323. int sortSpalteS = sortSpalte->getAuswahl();
  324. int sortRichtungS = sortRichtung->getAuswahl();
  325. statistikF->lockZeichnung();
  326. statistikF->doMausEreignis( me );
  327. statistikF->unlockZeichnung();
  328. if( sortSpalte->getAuswahl() != sortSpalteS )
  329. {
  330. sortSpalte->einklappen();
  331. starten = 1;
  332. }
  333. if( sortRichtung->getAuswahl() != sortRichtungS )
  334. {
  335. sortRichtung->einklappen();
  336. starten = 1;
  337. }
  338. if( starten )
  339. start();
  340. }
  341. void AccountStatistik::render( Bild &zRObj )
  342. {
  343. zRObj.setAlpha( alpha );
  344. statistikF->lockZeichnung();
  345. statistikF->render( zRObj );
  346. statistikF->unlockZeichnung();
  347. if( !zRObj.setDrawOptions( statistikF->getPosition(), statistikF->getSize() ) )
  348. {
  349. zRObj.releaseAlpha();
  350. return;
  351. }
  352. laden->render( zRObj );
  353. zRObj.releaseAlpha();
  354. zRObj.releaseDrawOptions();
  355. }
  356. // constant
  357. int AccountStatistik::getStatus() const
  358. {
  359. return status;
  360. }
  361. // Reference Counting
  362. AccountStatistik *AccountStatistik::getThis()
  363. {
  364. ref++;
  365. return this;
  366. }
  367. AccountStatistik *AccountStatistik::release()
  368. {
  369. ref--;
  370. if( !ref )
  371. delete this;
  372. return 0;
  373. }
  374. // Ereignisse
  375. bool accountStatistikVorME( void *p, void *o, MausEreignis me )
  376. {
  377. if( p )
  378. return ( (AccountStatistik*)p )->vorME( me );
  379. return 1;
  380. }
  381. bool accountStatistikZurückME( void *p, void *o, MausEreignis me )
  382. {
  383. if( p )
  384. return ( (AccountStatistik*)p )->zurückME( me );
  385. return 1;
  386. }