AccountStatistik.cpp 11 KB

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