123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296 |
- #include "../../Global/Initialisierung.h"
- #include <MausEreignis.h>
- #include "../../Global/Variablen.h"
- UpdateGUI::UpdateGUI( Schrift *zSchrift, int spielId, int dg )
- : Thread()
- {
- p = 0;
- updateStatus = initTextFeld( 0, 0, 302, 20, zSchrift, TextFeld::Style::Text | TextFeld::Style::VCenter, "Neuste Version Herunterladen" );
- updateStarten = initKnopf( 302, 0, 100, 20, zSchrift, Knopf::Style::Sichtbar, "Herunterladen" );
- updateFortschritt = initFBalken( 0, 25, 402, 22, zSchrift, FBalken::Style::Sichtbar | FBalken::Style::Hintergrund | FBalken::Style::HBild |
- FBalken::Style::FBild | FBalken::Style::Rahmen | FBalken::Style::Prozent | FBalken::Style::L_R );
- updateAbbrechen = 1;
- sichtbar = 0;
- alpha = 0;
- this->spielId = spielId;
- this->dg = dg;
- ref = 1;
- }
- UpdateGUI::~UpdateGUI()
- {
- if( isRunning() )
- {
- updateAbbrechen = 1;
- warteAufThread( 5000 );
- if( isRunning() )
- ende();
- }
- updateStatus->release();
- updateStarten->release();
- updateFortschritt->release();
- if( p )
- p->release();
- }
- void UpdateGUI::setSichtbar( bool sichtbar )
- {
- this->sichtbar = sichtbar;
- }
- void UpdateGUI::doMausEreignis( MausEreignis &me, Patcher *zP )
- {
- bool vera = me.verarbeitet;
- updateStarten->doMausEreignis( me );
- if( !vera && me.verarbeitet && me.id == ME_RLinks )
- {
- if( updateAbbrechen )
- {
- updateAbbrechen = 0;
- if( !p )
- p = zP->getThis();
- updateStarten->setText( "Abbrechen" );
- start();
- }
- else
- {
- updateAbbrechen = 1;
- if( isRunning() )
- warteAufThread( 5000 );
- if( isRunning() )
- ende();
- updateStatus->setText( "Neuste Version Herunterladen" );
- updateStarten->setText( "Herunterladen" );
- updateFortschritt->reset();
- }
- }
- }
- bool UpdateGUI::tick( double zeit )
- {
- bool ret = updateStatus->tick( zeit );
- ret |= updateStarten->tick( zeit );
- ret |= updateFortschritt->tick( zeit );
- if( !alpha )
- ret = 0;
- if( sichtbar && alpha != 255 )
- {
- alpha += (int)( zeit * 150 );
- if( alpha > 255 )
- alpha = 255;
- ret = 1;
- }
- if( !sichtbar && alpha )
- {
- alpha -= (int)( zeit * 150 );
- if( alpha < 0 )
- alpha = 0;
- ret = 1;
- }
- return ret;
- }
- void UpdateGUI::render( int xOff, int yOff, Bild &zRObj )
- {
- if( !zRObj.setDrawOptions( xOff, yOff, 402, 50 ) )
- return;
- zRObj.setAlpha( (unsigned char)alpha );
- updateStatus->render( zRObj );
- updateStarten->render( zRObj );
- updateFortschritt->render( zRObj );
- zRObj.releaseAlpha();
- zRObj.releaseDrawOptions();
- }
- void UpdateGUI::thread()
- {
- int dgId = dg;
- if( spielId )
- dgId = infoKlient->getDateiGruppeIdVonSpiel( spielId );
- Text err;
- if( !p->update( dgId, &updateAbbrechen, updateFortschritt->getThis(), updateStatus->getThis(), &err ) )
- {
- if( nachLogin && nachLogin->zNachrichtenListe() )
- nachLogin->zNachrichtenListe()->addNachricht( new Text( "Fehler" ), err.getThis(), new Text( "Ok" ) );
- }
- updateStatus->setText( "Neuste Version Herunterladen" );
- updateStarten->setText( "Herunterladen" );
- updateFortschritt->reset();
- updateAbbrechen = 1;
- run = 0;
- if( nachLogin && nachLogin->zSpielenFenster() && spielId )
- nachLogin->zSpielenFenster()->updateErlaubt();
- if( nachLogin && nachLogin->zMGFenster() && dg )
- nachLogin->zMGFenster()->setAktuell( 1 );
- }
- bool UpdateGUI::istGleich( int spielId, int dg )
- {
- return this->spielId == spielId && this->dg == dg;
- }
- UpdateGUI *UpdateGUI::getThis()
- {
- ref++;
- return this;
- }
- UpdateGUI *UpdateGUI::release()
- {
- ref--;
- if( !ref )
- delete this;
- return 0;
- }
- UpdateHandler::UpdateHandler()
- {
- patcher = new Patcher();
- updates = new RCArray< UpdateGUI >();
- ref = 1;
- }
- UpdateHandler::~UpdateHandler()
- {
- updates->release();
- patcher->release();
- }
- void UpdateHandler::lock()
- {
- cs.lock();
- }
- void UpdateHandler::unlock()
- {
- cs.unlock();
- }
- void UpdateHandler::erstellen( Schrift *zSchrift, int spiel, int dg )
- {
- lock();
- updates->add( new UpdateGUI( zSchrift, spiel, dg ) );
- unlock();
- }
- void UpdateHandler::setSichtbar( int spiel, bool sichtbar, int dg )
- {
- lock();
- int anz = updates->getEintragAnzahl();
- for( int i = 0; i < anz; i++ )
- {
- if( updates->z( i )->istGleich( spiel, dg ) )
- {
- updates->z( i )->setSichtbar( sichtbar );
- break;
- }
- }
- unlock();
- }
- void UpdateHandler::doMausEreignis( int spiel, MausEreignis &me, int dg )
- {
- lock();
- int anz = updates->getEintragAnzahl();
- for( int i = 0; i < anz; i++ )
- {
- if( updates->z( i )->istGleich( spiel, dg ) )
- {
- updates->z( i )->doMausEreignis( me, patcher );
- break;
- }
- }
- unlock();
- }
- bool UpdateHandler::tick( int spiel, double zeit, int dg )
- {
- lock();
- bool ret = 0;
- int anz = updates->getEintragAnzahl();
- for( int i = 0; i < anz; i++ )
- {
- if( updates->z( i )->istGleich( spiel, dg ) )
- {
- ret = updates->z( i )->tick( zeit );
- break;
- }
- }
- unlock();
- return ret;
- }
- void UpdateHandler::render( int spiel, int xOff, int yOff, Bild &zRObj, int dg )
- {
- lock();
- int anz = updates->getEintragAnzahl();
- for( int i = 0; i < anz; i++ )
- {
- if( updates->z( i )->istGleich( spiel, dg ) )
- {
- updates->z( i )->render( xOff, yOff, zRObj );
- break;
- }
- }
- unlock();
- }
- void UpdateHandler::remove( int spiel, int dg )
- {
- lock();
- int anz = updates->getEintragAnzahl();
- for( int i = 0; i < anz; i++ )
- {
- if( updates->z( i )->istGleich( spiel, dg ) )
- {
- updates->remove( i );
- break;
- }
- }
- unlock();
- }
- bool UpdateHandler::hat( int spiel, int dg )
- {
- lock();
- bool ret = 0;
- int anz = updates->getEintragAnzahl();
- for( int i = 0; i < anz; i++ )
- {
- if( updates->z( i )->istGleich( spiel, dg ) )
- {
- ret = 1;
- break;
- }
- }
- unlock();
- return ret;
- }
- UpdateHandler *UpdateHandler::getThis()
- {
- ref++;
- return this;
- }
- UpdateHandler *UpdateHandler::release()
- {
- ref--;
- if( !ref )
- delete this;
- return 0;
- }
|