UpdateGUI.cpp 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296
  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( isRunning() )
  25. {
  26. updateAbbrechen = 1;
  27. warteAufThread( 5000 );
  28. if( isRunning() )
  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( isRunning() )
  60. warteAufThread( 5000 );
  61. if( isRunning() )
  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. ref = 1;
  149. }
  150. // Destruktor
  151. UpdateHandler::~UpdateHandler()
  152. {
  153. updates->release();
  154. patcher->release();
  155. }
  156. // privat
  157. void UpdateHandler::lock()
  158. {
  159. cs.lock();
  160. }
  161. void UpdateHandler::unlock()
  162. {
  163. cs.unlock();
  164. }
  165. // nicht constant
  166. void UpdateHandler::erstellen( Schrift *zSchrift, int spiel, int dg )
  167. {
  168. lock();
  169. updates->add( new UpdateGUI( zSchrift, spiel, dg ) );
  170. unlock();
  171. }
  172. void UpdateHandler::setSichtbar( int spiel, bool sichtbar, int dg )
  173. {
  174. lock();
  175. int anz = updates->getEintragAnzahl();
  176. for( int i = 0; i < anz; i++ )
  177. {
  178. if( updates->z( i )->istGleich( spiel, dg ) )
  179. {
  180. updates->z( i )->setSichtbar( sichtbar );
  181. break;
  182. }
  183. }
  184. unlock();
  185. }
  186. void UpdateHandler::doMausEreignis( int spiel, MausEreignis &me, int dg )
  187. {
  188. lock();
  189. int anz = updates->getEintragAnzahl();
  190. for( int i = 0; i < anz; i++ )
  191. {
  192. if( updates->z( i )->istGleich( spiel, dg ) )
  193. {
  194. updates->z( i )->doMausEreignis( me, patcher );
  195. break;
  196. }
  197. }
  198. unlock();
  199. }
  200. bool UpdateHandler::tick( int spiel, double zeit, int dg )
  201. {
  202. lock();
  203. bool ret = 0;
  204. int anz = updates->getEintragAnzahl();
  205. for( int i = 0; i < anz; i++ )
  206. {
  207. if( updates->z( i )->istGleich( spiel, dg ) )
  208. {
  209. ret = updates->z( i )->tick( zeit );
  210. break;
  211. }
  212. }
  213. unlock();
  214. return ret;
  215. }
  216. void UpdateHandler::render( int spiel, int xOff, int yOff, Bild &zRObj, int dg )
  217. {
  218. lock();
  219. int anz = updates->getEintragAnzahl();
  220. for( int i = 0; i < anz; i++ )
  221. {
  222. if( updates->z( i )->istGleich( spiel, dg ) )
  223. {
  224. updates->z( i )->render( xOff, yOff, zRObj );
  225. break;
  226. }
  227. }
  228. unlock();
  229. }
  230. void UpdateHandler::remove( int spiel, int dg )
  231. {
  232. lock();
  233. int anz = updates->getEintragAnzahl();
  234. for( int i = 0; i < anz; i++ )
  235. {
  236. if( updates->z( i )->istGleich( spiel, dg ) )
  237. {
  238. updates->remove( i );
  239. break;
  240. }
  241. }
  242. unlock();
  243. }
  244. bool UpdateHandler::hat( int spiel, int dg )
  245. {
  246. lock();
  247. bool ret = 0;
  248. int anz = updates->getEintragAnzahl();
  249. for( int i = 0; i < anz; i++ )
  250. {
  251. if( updates->z( i )->istGleich( spiel, dg ) )
  252. {
  253. ret = 1;
  254. break;
  255. }
  256. }
  257. unlock();
  258. return ret;
  259. }
  260. // Reference Counting
  261. UpdateHandler *UpdateHandler::getThis()
  262. {
  263. ref++;
  264. return this;
  265. }
  266. UpdateHandler *UpdateHandler::release()
  267. {
  268. ref--;
  269. if( !ref )
  270. delete this;
  271. return 0;
  272. }