KaufHistorie.cpp 8.8 KB

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