KaufHistorie.cpp 8.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301
  1. #include "KaufHistorie.h"
  2. #include <Schrift.h>
  3. #include "../../../../Global/Variablen.h"
  4. #include "../../../../Global/Initialisierung.h"
  5. #include <Zeit.h>
  6. // Inhalt der KEKaufHistorie Klasse
  7. // Konstruktor
  8. KEKaufHistorie::KEKaufHistorie( int karte, Schrift *zSchrift )
  9. {
  10. schrift = zSchrift->getThis();
  11. Text *kName = infoClient->getKarteName( karte );
  12. Text titel = kName ? kName->getText() : "<Karte>";
  13. titel += " - Release";
  14. if( kName )
  15. kName->release();
  16. fenster = initFenster( 10, 40, 880, 550, zSchrift, Fenster::Style::Sichtbar | Fenster::Style::Titel | Fenster::Style::TitelBuffered | Fenster::Style::Erlaubt | Fenster::Style::Rahmen, titel );
  17. aktualisieren = initKnopf( 10, 10, 100, 20, zSchrift, Knopf::Style::Normal, "Aktualisieren" );
  18. aktualisieren->setMausEreignis( [ this ]( void *p, void *obj, MausEreignis me ) -> bool
  19. {
  20. if( me.id == ME_RLinks && me.verarbeitet == 0 )
  21. start();
  22. return 1;
  23. } );
  24. gesammtVerkauf = initTextFeld( 120, 10, 750, 20, zSchrift, TextFeld::Style::Text, "Gesammt verkauft: " );
  25. statistik = initLinienDiagramm( 10, 40, 860, 480, zSchrift, LDiag::Style::DatenRahmen, 0 );
  26. statistik->setHIntervallBreite( 36.8 );
  27. statistik->setDatenStyle( DiagDaten::Style::autoRaster | DiagDaten::Style::intervallTexte | DiagDaten::Style::intervalle | DiagDaten::Style::Sichtbar | DiagDaten::Style::autoIntervall );
  28. statistik->setRasterDicke( 1 );
  29. statistik->setRasterFarbe( 0xFF505050 );
  30. statistik->setHIntervallFarbe( 0xFFFFFFFF );
  31. statistik->setHIntervallName( "Tage" );
  32. statistik->setVIntervallFarbe( 0xFFFFFFFF );
  33. statistik->setVIntervallName( "Anzahl" );
  34. laden = (Animation2D*)ladeAnimation->dublizieren();
  35. laden->setPosition( 425, 275 );
  36. laden->setSichtbar( 0 );
  37. fenster->addMember( aktualisieren );
  38. fenster->addMember( gesammtVerkauf );
  39. fenster->addMember( statistik );
  40. animation = 0;
  41. tickVal = 0;
  42. sichtbar = 0;
  43. rechts = 0;
  44. xStart = 0;
  45. breite = 0;
  46. aktion = 0;
  47. this->karte = karte;
  48. alpha = 255;
  49. ref = 1;
  50. }
  51. // Destruktor
  52. KEKaufHistorie::~KEKaufHistorie()
  53. {
  54. if( run )
  55. {
  56. warteAufThread( 5000 );
  57. if( run )
  58. ende();
  59. }
  60. statistik->release();
  61. aktualisieren->release();
  62. gesammtVerkauf->release();
  63. fenster->release();
  64. laden->release();
  65. schrift->release();
  66. }
  67. // nicht constant
  68. void KEKaufHistorie::setSichtbar( bool s, bool vr )
  69. {
  70. animation = 1;
  71. sichtbar = s;
  72. rechts = vr;
  73. if( sichtbar )
  74. {
  75. if( vr )
  76. {
  77. xStart = 900;
  78. breite = 0;
  79. }
  80. else
  81. {
  82. xStart = 0;
  83. breite = 0;
  84. }
  85. if( !run )
  86. {
  87. aktion = 0;
  88. start();
  89. }
  90. }
  91. }
  92. void KEKaufHistorie::thread()
  93. {
  94. laden->setSichtbar( 1 );
  95. Array< int > einnahmen;
  96. Array< int > verkauf;
  97. Array< int > spiele;
  98. int gesammt = editorClient->getVerkaufStatistik( &verkauf, &einnahmen, &spiele );
  99. if( gesammt == 0 && einnahmen.getEintragAnzahl() == 0 )
  100. {
  101. nachLogin->zNachrichtenListe()->addNachricht( new Text( "Fehler" ), new Text( editorClient->getLetzterFehler() ), new Text( "Ok" ) );
  102. }
  103. else
  104. {
  105. fenster->lockZeichnung();
  106. gesammtVerkauf->setText( Text( "Gesammt Verkauft: " ) += gesammt );
  107. int wAnz = statistik->zDiagDaten()->werte->getEintragAnzahl();
  108. for( int i = 0; i < wAnz; i++ )
  109. statistik->removeWert( 0 );
  110. wAnz = statistik->zDiagDaten()->hIntervallWerte->getEintragAnzahl();
  111. for( int i = 0; i < wAnz; i++ )
  112. statistik->removeHIntervallText( statistik->zDiagDaten()->hIntervallWerte->get( 0 ) );
  113. wAnz = statistik->zDiagDaten()->vIntervallWerte->getEintragAnzahl();
  114. for( int i = 0; i < wAnz; i++ )
  115. statistik->removeVIntervallText( statistik->zDiagDaten()->vIntervallWerte->get( 0 ) );
  116. int anz = einnahmen.getEintragAnzahl();
  117. int maxS = 0;
  118. for( int i = 0; i < anz; i++ )
  119. {
  120. if( einnahmen.hat( i ) && einnahmen.get( i ) > maxS )
  121. maxS = einnahmen.get( i );
  122. if( verkauf.hat( i ) && verkauf.get( i ) > maxS )
  123. maxS = verkauf.get( i );
  124. if( spiele.hat( i ) && spiele.get( i ) > maxS )
  125. maxS = spiele.get( i );
  126. }
  127. maxS++;
  128. statistik->addVIntervallText( 0, Text() += 0 );
  129. statistik->addVIntervallText( maxS + 1, Text() += ( maxS + 1 ) );
  130. Datum *d = Framework::getDatum();
  131. d->minusTag( 30 );
  132. statistik->addHIntervallText( 0, d->getDatum( "y-m-d" ) );
  133. d->plusTag( 30 );
  134. statistik->addHIntervallText( anz - 1, d->getDatum( "y-m-d" ) );
  135. d->release();
  136. DiagWert *w = new DiagWert();
  137. w->farbe = 0xFF00FFFF;
  138. w->hintergrund = 0xFF205050;
  139. w->name->setText( "Einnahmen" );
  140. w->style = DiagWert::Style::Sichtbar | DiagWert::Style::Name | DiagWert::Style::Hintergrund;
  141. statistik->addWert( w );
  142. w = new DiagWert();
  143. w->farbe = 0xFF00FF00;
  144. w->hintergrund = 0xFF205020;
  145. w->name->setText( "Verkauft" );
  146. w->style = DiagWert::Style::Sichtbar | DiagWert::Style::Name | DiagWert::Style::Hintergrund;
  147. statistik->addWert( w );
  148. w = new DiagWert();
  149. w->farbe = 0xFFFF0000;
  150. w->hintergrund = 0xFF502020;
  151. w->name->setText( "Spiele" );
  152. w->style = DiagWert::Style::Sichtbar | DiagWert::Style::Name | DiagWert::Style::Hintergrund;
  153. statistik->addWert( w );
  154. for( int i = 0; i < anz; i++ )
  155. {
  156. statistik->addPunkt( 0, i, einnahmen.get( i ) );
  157. statistik->addPunkt( 1, i, verkauf.get( i ) );
  158. statistik->addPunkt( 2, i, spiele.get( i ) );
  159. }
  160. fenster->unlockZeichnung();
  161. }
  162. laden->setSichtbar( 0 );
  163. }
  164. void KEKaufHistorie::doMausEreignis( MausEreignis &me )
  165. {
  166. if( !run )
  167. fenster->doMausEreignis( me );
  168. }
  169. void KEKaufHistorie::doTastaturEreignis( TastaturEreignis &te )
  170. {
  171. if( !run )
  172. fenster->doTastaturEreignis( te );
  173. }
  174. bool KEKaufHistorie::tick( double z )
  175. {
  176. bool ret = laden->tick( z );
  177. tickVal += z * 150;
  178. int val = (int)tickVal;
  179. tickVal -= val;
  180. if( val )
  181. {
  182. if( run && alpha != 100 )
  183. {
  184. if( alpha - val < 100 )
  185. alpha = 100;
  186. else
  187. alpha -= val;
  188. ret = 1;
  189. }
  190. if( !run && alpha != 255 )
  191. {
  192. if( alpha + val > 255 )
  193. alpha = 255;
  194. else
  195. alpha += val;
  196. ret = 1;
  197. }
  198. val *= 3;
  199. if( sichtbar )
  200. {
  201. if( xStart != 0 || breite != 900 )
  202. {
  203. if( rechts )
  204. {
  205. if( xStart - val <= 0 )
  206. {
  207. xStart = 0;
  208. breite = 900;
  209. animation = 0;
  210. }
  211. else
  212. {
  213. xStart -= val;
  214. breite += val;
  215. }
  216. }
  217. else
  218. {
  219. if( breite + val >= 900 )
  220. {
  221. breite = 900;
  222. animation = 0;
  223. }
  224. else
  225. breite += val;
  226. }
  227. ret = 1;
  228. }
  229. }
  230. else
  231. {
  232. if( breite != 0 )
  233. {
  234. if( rechts )
  235. {
  236. if( breite - val <= 0 )
  237. {
  238. breite = 0;
  239. animation = 0;
  240. }
  241. else
  242. breite -= val;
  243. }
  244. else
  245. {
  246. if( breite - val <= 0 )
  247. {
  248. breite = 0;
  249. xStart = 900;
  250. animation = 0;
  251. }
  252. else
  253. {
  254. breite -= val;
  255. xStart += val;
  256. }
  257. }
  258. ret = 1;
  259. }
  260. }
  261. }
  262. return ret || fenster->tick( z );
  263. }
  264. void KEKaufHistorie::render( Bild &zRObj )
  265. {
  266. if( !zRObj.setDrawOptions( xStart, 0, breite, 600 ) )
  267. return;
  268. zRObj.setAlpha( alpha );
  269. fenster->render( zRObj );
  270. zRObj.releaseAlpha();
  271. laden->render( zRObj );
  272. zRObj.releaseDrawOptions();
  273. }
  274. // constant
  275. bool KEKaufHistorie::istSichtbar() const
  276. {
  277. return sichtbar || animation;
  278. }
  279. // Reference Counting
  280. KEKaufHistorie *KEKaufHistorie::getThis()
  281. {
  282. ref++;
  283. return this;
  284. }
  285. KEKaufHistorie *KEKaufHistorie::release()
  286. {
  287. if( !--ref )
  288. delete this;
  289. return 0;
  290. }