UpdateGUI.cpp 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298
  1. #include "../../Global/Initialisierung.h"
  2. #include <MausEreignis.h>
  3. #include "../../Global/Variablen.h"
  4. // Inhalt der UpdateGUI klasse aus UpdateGUI.h
  5. // Konstruktor
  6. UpdateGUI::UpdateGUI( Schrift *zSchrift, int spielId, int dg )
  7. : Thread()
  8. {
  9. p = 0;
  10. updateStatus = initTextFeld( 0, 0, 302, 20, zSchrift, TextFeld::Style::Text | TextFeld::Style::VCenter, "Neuste Version Herunterladen" );
  11. updateStarten = initKnopf( 302, 0, 100, 20, zSchrift, Knopf::Style::Sichtbar, "Herunterladen" );
  12. updateFortschritt = initFBalken( 0, 25, 402, 22, zSchrift, FBalken::Style::Sichtbar | FBalken::Style::Hintergrund | FBalken::Style::HBild |
  13. FBalken::Style::FBild | FBalken::Style::Rahmen | FBalken::Style::Prozent | FBalken::Style::L_R );
  14. updateAbbrechen = 1;
  15. sichtbar = 0;
  16. alpha = 0;
  17. this->spielId = spielId;
  18. this->dg = dg;
  19. ref = 1;
  20. }
  21. // Destruktor
  22. UpdateGUI::~UpdateGUI()
  23. {
  24. if( läuft() )
  25. {
  26. updateAbbrechen = 1;
  27. warteAufThread( 5000 );
  28. if( läuft() )
  29. ende();
  30. }
  31. updateStatus->release();
  32. updateStarten->release();
  33. updateFortschritt->release();
  34. if( p )
  35. p->release();
  36. }
  37. // nicht constant
  38. void UpdateGUI::setSichtbar( bool sichtbar )
  39. {
  40. this->sichtbar = sichtbar;
  41. }
  42. void UpdateGUI::doMausEreignis( MausEreignis &me, Patcher *zP )
  43. {
  44. bool vera = me.verarbeitet;
  45. updateStarten->doMausEreignis( me );
  46. if( !vera && me.verarbeitet && me.id == ME_RLinks )
  47. {
  48. if( updateAbbrechen )
  49. {
  50. updateAbbrechen = 0;
  51. if( !p )
  52. p = zP->getThis();
  53. updateStarten->setText( "Abbrechen" );
  54. start();
  55. }
  56. else
  57. {
  58. updateAbbrechen = 1;
  59. if( läuft() )
  60. warteAufThread( 5000 );
  61. if( läuft() )
  62. ende();
  63. updateStatus->setText( "Neuste Version Herunterladen" );
  64. updateStarten->setText( "Herunterladen" );
  65. updateFortschritt->reset();
  66. }
  67. }
  68. }
  69. bool UpdateGUI::tick( double zeit )
  70. {
  71. bool ret = updateStatus->tick( zeit );
  72. ret |= updateStarten->tick( zeit );
  73. ret |= updateFortschritt->tick( zeit );
  74. if( !alpha )
  75. ret = 0;
  76. if( sichtbar && alpha != 255 )
  77. {
  78. alpha += (int)( zeit * 150 );
  79. if( alpha > 255 )
  80. alpha = 255;
  81. ret = 1;
  82. }
  83. if( !sichtbar && alpha )
  84. {
  85. alpha -= (int)( zeit * 150 );
  86. if( alpha < 0 )
  87. alpha = 0;
  88. ret = 1;
  89. }
  90. return ret;
  91. }
  92. void UpdateGUI::render( int xOff, int yOff, Bild &zRObj )
  93. {
  94. if( !zRObj.setDrawOptions( xOff, yOff, 402, 50 ) )
  95. return;
  96. zRObj.setAlpha( (unsigned char)alpha );
  97. updateStatus->render( zRObj );
  98. updateStarten->render( zRObj );
  99. updateFortschritt->render( zRObj );
  100. zRObj.releaseAlpha();
  101. zRObj.releaseDrawOptions();
  102. }
  103. void UpdateGUI::thread()
  104. {
  105. int dgId = dg;
  106. if( spielId )
  107. dgId = infoKlient->getDateiGruppeIdVonSpiel( spielId );
  108. Text err;
  109. if( !p->update( dgId, &updateAbbrechen, updateFortschritt->getThis(), updateStatus->getThis(), &err ) )
  110. {
  111. if( nachLogin && nachLogin->zNachrichtenListe() )
  112. nachLogin->zNachrichtenListe()->addNachricht( new Text( "Fehler" ), err.getThis(), new Text( "Ok" ) );
  113. }
  114. updateStatus->setText( "Neuste Version Herunterladen" );
  115. updateStarten->setText( "Herunterladen" );
  116. updateFortschritt->reset();
  117. updateAbbrechen = 1;
  118. run = 0;
  119. if( nachLogin && nachLogin->zSpielenFenster() && spielId )
  120. nachLogin->zSpielenFenster()->updateErlaubt();
  121. if( nachLogin && nachLogin->zMGFenster() && dg )
  122. nachLogin->zMGFenster()->setAktuell( 1 );
  123. }
  124. // constant
  125. bool UpdateGUI::istGleich( int spielId, int dg )
  126. {
  127. return this->spielId == spielId && this->dg == dg;
  128. }
  129. // Reference Counting
  130. UpdateGUI *UpdateGUI::getThis()
  131. {
  132. ref++;
  133. return this;
  134. }
  135. UpdateGUI *UpdateGUI::release()
  136. {
  137. ref--;
  138. if( !ref )
  139. delete this;
  140. return 0;
  141. }
  142. // inhalt der UpdateHandler Klasse aus UpdateGUI.h
  143. // Konstruktor
  144. UpdateHandler::UpdateHandler()
  145. {
  146. patcher = new Patcher();
  147. updates = new RCArray< UpdateGUI >();
  148. InitializeCriticalSection( &cs );
  149. ref = 1;
  150. }
  151. // Destruktor
  152. UpdateHandler::~UpdateHandler()
  153. {
  154. updates->release();
  155. patcher->release();
  156. DeleteCriticalSection( &cs );
  157. }
  158. // privat
  159. void UpdateHandler::lock()
  160. {
  161. EnterCriticalSection( &cs );
  162. }
  163. void UpdateHandler::unlock()
  164. {
  165. LeaveCriticalSection( &cs );
  166. }
  167. // nicht constant
  168. void UpdateHandler::erstellen( Schrift *zSchrift, int spiel, int dg )
  169. {
  170. lock();
  171. updates->add( new UpdateGUI( zSchrift, spiel, dg ) );
  172. unlock();
  173. }
  174. void UpdateHandler::setSichtbar( int spiel, bool sichtbar, int dg )
  175. {
  176. lock();
  177. int anz = updates->getEintragAnzahl();
  178. for( int i = 0; i < anz; i++ )
  179. {
  180. if( updates->z( i )->istGleich( spiel, dg ) )
  181. {
  182. updates->z( i )->setSichtbar( sichtbar );
  183. break;
  184. }
  185. }
  186. unlock();
  187. }
  188. void UpdateHandler::doMausEreignis( int spiel, MausEreignis &me, int dg )
  189. {
  190. lock();
  191. int anz = updates->getEintragAnzahl();
  192. for( int i = 0; i < anz; i++ )
  193. {
  194. if( updates->z( i )->istGleich( spiel, dg ) )
  195. {
  196. updates->z( i )->doMausEreignis( me, patcher );
  197. break;
  198. }
  199. }
  200. unlock();
  201. }
  202. bool UpdateHandler::tick( int spiel, double zeit, int dg )
  203. {
  204. lock();
  205. bool ret = 0;
  206. int anz = updates->getEintragAnzahl();
  207. for( int i = 0; i < anz; i++ )
  208. {
  209. if( updates->z( i )->istGleich( spiel, dg ) )
  210. {
  211. ret = updates->z( i )->tick( zeit );
  212. break;
  213. }
  214. }
  215. unlock();
  216. return ret;
  217. }
  218. void UpdateHandler::render( int spiel, int xOff, int yOff, Bild &zRObj, int dg )
  219. {
  220. lock();
  221. int anz = updates->getEintragAnzahl();
  222. for( int i = 0; i < anz; i++ )
  223. {
  224. if( updates->z( i )->istGleich( spiel, dg ) )
  225. {
  226. updates->z( i )->render( xOff, yOff, zRObj );
  227. break;
  228. }
  229. }
  230. unlock();
  231. }
  232. void UpdateHandler::lösche( int spiel, int dg )
  233. {
  234. lock();
  235. int anz = updates->getEintragAnzahl();
  236. for( int i = 0; i < anz; i++ )
  237. {
  238. if( updates->z( i )->istGleich( spiel, dg ) )
  239. {
  240. updates->lösche( i );
  241. break;
  242. }
  243. }
  244. unlock();
  245. }
  246. bool UpdateHandler::hat( int spiel, int dg )
  247. {
  248. lock();
  249. bool ret = 0;
  250. int anz = updates->getEintragAnzahl();
  251. for( int i = 0; i < anz; i++ )
  252. {
  253. if( updates->z( i )->istGleich( spiel, dg ) )
  254. {
  255. ret = 1;
  256. break;
  257. }
  258. }
  259. unlock();
  260. return ret;
  261. }
  262. // Reference Counting
  263. UpdateHandler *UpdateHandler::getThis()
  264. {
  265. ref++;
  266. return this;
  267. }
  268. UpdateHandler *UpdateHandler::release()
  269. {
  270. ref--;
  271. if( !ref )
  272. delete this;
  273. return 0;
  274. }