KaufHistorie.cpp 8.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279
  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 )
  9. : Thread()
  10. {
  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, Fenster::Style::Sichtbar | Fenster::Style::Titel | Fenster::Style::TitelBuffered | Fenster::Style::Erlaubt | Fenster::Style::Rahmen, titel );
  17. aktualisieren = initKnopf( 10, 10, 100, 20, 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, TextFeld::Style::Text, "Gesammt verkauft: " );
  25. statistik = initLinienDiagramm( 10, 40, 860, 480, 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( dynamic_cast<Zeichnung *>( aktualisieren->getThis() ) );
  38. fenster->addMember( dynamic_cast<Zeichnung *>( gesammtVerkauf->getThis() ) );
  39. fenster->addMember( dynamic_cast<Zeichnung *>( statistik->getThis() ) );
  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. }
  50. // Destruktor
  51. KEKaufHistorie::~KEKaufHistorie()
  52. {
  53. statistik->release();
  54. aktualisieren->release();
  55. gesammtVerkauf->release();
  56. fenster->release();
  57. laden->release();
  58. }
  59. // nicht constant
  60. void KEKaufHistorie::setSichtbar( bool s, bool vr )
  61. {
  62. animation = 1;
  63. sichtbar = s;
  64. rechts = vr;
  65. if( sichtbar )
  66. {
  67. if( vr )
  68. {
  69. xStart = 900;
  70. breite = 0;
  71. }
  72. else
  73. {
  74. xStart = 0;
  75. breite = 0;
  76. }
  77. if( !run )
  78. {
  79. aktion = 0;
  80. start();
  81. }
  82. }
  83. }
  84. void KEKaufHistorie::thread()
  85. {
  86. laden->setSichtbar( 1 );
  87. Array< int > einnahmen;
  88. Array< int > verkauf;
  89. Array< int > spiele;
  90. int gesammt = editorClient->getVerkaufStatistik( &verkauf, &einnahmen, &spiele );
  91. if( gesammt == 0 && einnahmen.getEintragAnzahl() == 0 )
  92. {
  93. nachLogin->zNachrichtenListe()->addNachricht( new Text( "Fehler" ), new Text( editorClient->getLetzterFehler() ), new Text( "Ok" ) );
  94. }
  95. else
  96. {
  97. fenster->lockZeichnung();
  98. gesammtVerkauf->setText( Text( "Gesammt Verkauft: " ) += gesammt );
  99. int wAnz = statistik->zDiagDaten()->werte->getEintragAnzahl();
  100. for( int i = 0; i < wAnz; i++ )
  101. statistik->removeWert( 0 );
  102. wAnz = statistik->zDiagDaten()->hIntervallWerte->getEintragAnzahl();
  103. for( int i = 0; i < wAnz; i++ )
  104. statistik->removeHIntervallText( statistik->zDiagDaten()->hIntervallWerte->get( 0 ) );
  105. wAnz = statistik->zDiagDaten()->vIntervallWerte->getEintragAnzahl();
  106. for( int i = 0; i < wAnz; i++ )
  107. statistik->removeVIntervallText( statistik->zDiagDaten()->vIntervallWerte->get( 0 ) );
  108. int anz = einnahmen.getEintragAnzahl();
  109. int maxS = 0;
  110. for( int i = 0; i < anz; i++ )
  111. {
  112. if( einnahmen.hat( i ) && einnahmen.get( i ) > maxS )
  113. maxS = einnahmen.get( i );
  114. if( verkauf.hat( i ) && verkauf.get( i ) > maxS )
  115. maxS = verkauf.get( i );
  116. if( spiele.hat( i ) && spiele.get( i ) > maxS )
  117. maxS = spiele.get( i );
  118. }
  119. maxS++;
  120. statistik->addVIntervallText( 0, Text() += 0 );
  121. statistik->addVIntervallText( maxS + 1, Text() += ( maxS + 1 ) );
  122. Datum *d = Framework::getDatum();
  123. d->minusTag( 30 );
  124. statistik->addHIntervallText( 0, d->getDatum( "y-m-d" ) );
  125. d->plusTag( 30 );
  126. statistik->addHIntervallText( anz - 1, d->getDatum( "y-m-d" ) );
  127. d->release();
  128. DiagWert *w = new DiagWert();
  129. w->farbe = 0xFF00FFFF;
  130. w->hintergrund = 0xFF205050;
  131. w->name->setText( "Einnahmen" );
  132. w->style = DiagWert::Style::Sichtbar | DiagWert::Style::Name | DiagWert::Style::Hintergrund;
  133. statistik->addWert( w );
  134. w = new DiagWert();
  135. w->farbe = 0xFF00FF00;
  136. w->hintergrund = 0xFF205020;
  137. w->name->setText( "Verkauft" );
  138. w->style = DiagWert::Style::Sichtbar | DiagWert::Style::Name | DiagWert::Style::Hintergrund;
  139. statistik->addWert( w );
  140. w = new DiagWert();
  141. w->farbe = 0xFFFF0000;
  142. w->hintergrund = 0xFF502020;
  143. w->name->setText( "Spiele" );
  144. w->style = DiagWert::Style::Sichtbar | DiagWert::Style::Name | DiagWert::Style::Hintergrund;
  145. statistik->addWert( w );
  146. for( int i = 0; i < anz; i++ )
  147. {
  148. statistik->addPunkt( 0, i, einnahmen.get( i ) );
  149. statistik->addPunkt( 1, i, verkauf.get( i ) );
  150. statistik->addPunkt( 2, i, spiele.get( i ) );
  151. }
  152. fenster->unlockZeichnung();
  153. }
  154. laden->setSichtbar( 0 );
  155. }
  156. void KEKaufHistorie::doPublicMausEreignis( MausEreignis &me )
  157. {
  158. if( !run )
  159. fenster->doPublicMausEreignis( me );
  160. }
  161. void KEKaufHistorie::doTastaturEreignis( TastaturEreignis &te )
  162. {
  163. if( !run )
  164. fenster->doTastaturEreignis( te );
  165. }
  166. bool KEKaufHistorie::tick( double z )
  167. {
  168. bool ret = laden->tick( z );
  169. tickVal += z * 150;
  170. int val = (int)tickVal;
  171. tickVal -= val;
  172. if( val )
  173. {
  174. if( run && alpha != 100 )
  175. {
  176. if( alpha - val < 100 )
  177. alpha = 100;
  178. else
  179. alpha -= val;
  180. ret = 1;
  181. }
  182. if( !run && alpha != 255 )
  183. {
  184. if( alpha + val > 255 )
  185. alpha = 255;
  186. else
  187. alpha += val;
  188. ret = 1;
  189. }
  190. val *= 3;
  191. if( sichtbar )
  192. {
  193. if( xStart != 0 || breite != 900 )
  194. {
  195. if( rechts )
  196. {
  197. if( xStart - val <= 0 )
  198. {
  199. xStart = 0;
  200. breite = 900;
  201. animation = 0;
  202. }
  203. else
  204. {
  205. xStart -= val;
  206. breite += val;
  207. }
  208. }
  209. else
  210. {
  211. if( breite + val >= 900 )
  212. {
  213. breite = 900;
  214. animation = 0;
  215. }
  216. else
  217. breite += val;
  218. }
  219. ret = 1;
  220. }
  221. }
  222. else
  223. {
  224. if( breite != 0 )
  225. {
  226. if( rechts )
  227. {
  228. if( breite - val <= 0 )
  229. {
  230. breite = 0;
  231. animation = 0;
  232. }
  233. else
  234. breite -= val;
  235. }
  236. else
  237. {
  238. if( breite - val <= 0 )
  239. {
  240. breite = 0;
  241. xStart = 900;
  242. animation = 0;
  243. }
  244. else
  245. {
  246. breite -= val;
  247. xStart += val;
  248. }
  249. }
  250. ret = 1;
  251. }
  252. }
  253. }
  254. return ret || fenster->tick( z );
  255. }
  256. void KEKaufHistorie::render( Bild &zRObj )
  257. {
  258. if( !zRObj.setDrawOptions( xStart, 0, breite, 600 ) )
  259. return;
  260. zRObj.setAlpha( alpha );
  261. fenster->render( zRObj );
  262. zRObj.releaseAlpha();
  263. laden->render( zRObj );
  264. zRObj.releaseDrawOptions();
  265. }
  266. // constant
  267. bool KEKaufHistorie::istSichtbar() const
  268. {
  269. return sichtbar || animation;
  270. }