AccountStatistik.cpp 9.6 KB

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