HistorieStatistik.cpp 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209
  1. #include "HistorieStatistik.h"
  2. #include <Knopf.h>
  3. #include <MausEreignis.h>
  4. #include <Bildschirm.h>
  5. #include "../Initialisierung/Initialisierung.h"
  6. #include <InitDatei.h>
  7. #include <DateiSystem.h>
  8. #include "StatistikLeser.h"
  9. // Inhalt der HistorieStatistik Klasse aus HistorieStatistik.h
  10. // Konstruktor
  11. HistorieStatistik::HistorieStatistik()
  12. {
  13. schrift = 0;
  14. screen = 0;
  15. gss = new Array< SSDGesamtSpieler * >();
  16. gts = new Array< SSDGesamtTeam * >();
  17. rs = new Array< SSDRunde * >();
  18. runde = 0;
  19. tabelle = 0;
  20. fertig = 0;
  21. geladen = 0;
  22. geschlossen = 0;
  23. alpha = 0;
  24. sichtbar = 0;
  25. tickVal = 0;
  26. rend = 0;
  27. ref = 1;
  28. }
  29. // Destruktor
  30. HistorieStatistik::~HistorieStatistik()
  31. {
  32. if( schrift )
  33. schrift->release();
  34. if( !geladen )
  35. {
  36. gss->release();
  37. gts->release();
  38. rs->release();
  39. }
  40. else
  41. {
  42. int anz = gss->getEintragAnzahl();
  43. for( int i = 0; i < anz; i++ )
  44. {
  45. if( gss->hat( i ) )
  46. delete gss->get( i );
  47. }
  48. gss->release();
  49. anz = gts->getEintragAnzahl();
  50. for( int i = 0; i < anz; i++ )
  51. {
  52. if( gts->hat( i ) )
  53. delete gts->get( i );
  54. }
  55. gts->release();
  56. anz = rs->getEintragAnzahl();
  57. for( int i = 0; i < anz; i++ )
  58. {
  59. if( rs->hat( i ) )
  60. {
  61. int anz2 = rs->get( i )->spieler.getEintragAnzahl();
  62. for( int j = 0; j < anz2; j++ )
  63. {
  64. if( rs->get( i )->spieler.hat( j ) )
  65. delete rs->get( i )->spieler.get( j );
  66. }
  67. anz2 = rs->get( i )->teams.getEintragAnzahl();
  68. for( int j = 0; j < anz2; j++ )
  69. {
  70. if( rs->get( i )->teams.hat( j ) )
  71. delete rs->get( i )->teams.get( j );
  72. }
  73. delete rs->get( i );
  74. }
  75. }
  76. rs->release();
  77. }
  78. if( runde )
  79. runde->release();
  80. if( tabelle )
  81. tabelle->release();
  82. if( fertig )
  83. fertig->release();
  84. }
  85. // nicht constant
  86. void HistorieStatistik::setSchrift( Schrift *schrift )
  87. {
  88. if( this->schrift )
  89. this->schrift->release();
  90. this->schrift = schrift;
  91. }
  92. void HistorieStatistik::setBildschirm( Bildschirm *zScreen )
  93. {
  94. screen = zScreen;
  95. }
  96. void HistorieStatistik::ladeDaten( int spielId )
  97. {
  98. if( geladen )
  99. return;
  100. StatistikLeser *reader = new StatistikLeser( spielId );
  101. for( int i = 0; i < reader->getSpielerAnzahl(); i++ )
  102. gss->set( reader->getSSDGS( i ), i );
  103. for( int i = 0; i < reader->getTeamAnzahl(); i++ )
  104. gts->set( reader->getSSDGT( i ), i );
  105. for( int i = 0; i < reader->getRundenAnzahl(); i++ )
  106. rs->set( reader->getSSDR( i ), i );
  107. reader->release();
  108. tabelle = new StatistikTabelle( dynamic_cast<Array<SSDGesamtSpieler *> *>( gss->getThis() ), dynamic_cast<Array<SSDGesamtTeam *> *>( gts->getThis() ), dynamic_cast<Array<SSDRunde *> *>( rs->getThis() ), schrift, screen, 1 );
  109. runde = new StatistikRunde( schrift, dynamic_cast<Array<SSDRunde *> *>( rs->getThis() ), 1 );
  110. fertig = initKnopf( 600, 390, 100, 20, schrift, Knopf::Style::Sichtbar, "Zurück" );
  111. geladen = 1;
  112. }
  113. void HistorieStatistik::setSichtbar( bool sichtbar )
  114. {
  115. this->sichtbar = sichtbar;
  116. }
  117. void HistorieStatistik::doPublicMausEreignis( MausEreignis &me )
  118. {
  119. if( !geladen )
  120. return;
  121. tabelle->doPublicMausEreignis( me );
  122. runde->doPublicMausEreignis( me );
  123. bool vera = me.verarbeitet;
  124. fertig->doPublicMausEreignis( me );
  125. if( !vera && me.verarbeitet && me.id == ME_RLinks )
  126. geschlossen = 1;
  127. }
  128. void HistorieStatistik::doTastaturEreignis( TastaturEreignis &te )
  129. {}
  130. bool HistorieStatistik::tick( double tickVal )
  131. {
  132. if( !geladen )
  133. return 0;
  134. runde->setRunde( tabelle->getRunde() );
  135. rend |= tabelle->tick( tickVal );
  136. rend |= runde->tick( tickVal );
  137. rend |= fertig->tick( tickVal );
  138. this->tickVal += tickVal * 150;
  139. int val = (int)this->tickVal;
  140. this->tickVal -= val;
  141. if( val )
  142. {
  143. if( sichtbar && alpha != 255 )
  144. {
  145. if( alpha + val > 255 )
  146. alpha = 255;
  147. else
  148. alpha += val;
  149. rend = 1;
  150. }
  151. if( !sichtbar && alpha )
  152. {
  153. if( alpha - val < 0 )
  154. alpha = 0;
  155. else
  156. alpha -= val;
  157. rend = 1;
  158. }
  159. }
  160. bool ret = rend;
  161. rend = 0;
  162. return ret;
  163. }
  164. void HistorieStatistik::render( Bild &zRObj )
  165. {
  166. if( !geladen )
  167. return;
  168. zRObj.setAlpha( alpha );
  169. tabelle->render( zRObj );
  170. runde->render( zRObj );
  171. fertig->render( zRObj );
  172. zRObj.releaseAlpha();
  173. }
  174. // constant
  175. bool HistorieStatistik::istNochSichtbar() const
  176. {
  177. return alpha != 0 || sichtbar;
  178. }
  179. bool HistorieStatistik::wurdeGeschlossen() const
  180. {
  181. return geschlossen;
  182. }
  183. // Reference Counting
  184. AccountHistorieStatistikV *HistorieStatistik::getThis()
  185. {
  186. ref++;
  187. return this;
  188. }
  189. AccountHistorieStatistikV *HistorieStatistik::release()
  190. {
  191. ref--;
  192. if( !ref )
  193. delete this;
  194. return 0;
  195. }