#include "Editor.h" #include #include "Interface\Dialogs\Frage.h" #include "Interface\Dialogs\Nachricht.h" #include #include using namespace Editor; // Inhalt der Editor Klasse aus Editor.h // Konstruktor AsteroidsEditor::AsteroidsEditor() { schrift = 0; klient = 0; laden = 0; i = 0; alpha = 0; status = START; dialogs = new Array< Dialog* >(); sts = 0; rend = 1; daten = 0; ref = 1; } // Destruktor AsteroidsEditor::~AsteroidsEditor() { if( sts ) sts->release(); if( schrift ) schrift->release(); if( klient ) klient->release(); if( laden ) laden->release(); if( i ) i->release(); if( daten ) daten->release(); dialogs->release(); } void AsteroidsEditor::ladeKarte() { if( sts ) sts = (SpielerTeamStruktur*)sts->release(); sts = new SpielerTeamStruktur(); klient->getSpielerTeamStruktur( sts ); if( daten ) daten->release(); daten = new KarteDaten( klient->getThis() ); i->setDaten( daten->getThis() ); } // nicht constant void AsteroidsEditor::addDialog( Dialog *d ) { c.lock(); dialogs->add( d ); c.unlock(); } // nicht constant void AsteroidsEditor::setSchrift( Schrift *schrift ) { if( this->schrift ) this->schrift->release(); this->schrift = schrift; if( !i && windowSize != Punkt() ) i = new Interface( schrift, windowSize ); } void AsteroidsEditor::setKlient( KSGClient::EditorServerClient *ekv ) { if( klient ) klient->release(); klient = new EditorKlient( ekv ); } void AsteroidsEditor::setLadeAnimation( Animation2D *la ) { if( laden ) laden->release(); laden = la; } void AsteroidsEditor::setSichtbar() { status = START; EditorKlient *k = klient->getThis(); Schrift *zS = schrift->getThis(); Punkt mS = windowSize; if( windowSize != Punkt() ) { new AsynchronCall( [ this, k, zS, mS ]( void ) -> void { int ret = k->init(); if( ret == 2 ) { std::function< void() > wiederherstellen = [ this, k ] { status = START; ladeKarte(); this->status = INITIALIZED; }; std::function< void() > verwerfen = [ this, k, zS, mS ] { status = START; if( !k->sitzungVerwerfen() ) { Text t = "Fehler beim verwerfen der Sitzung: "; t += k->getLastError(); this->addDialog( new Nachricht( zS, t, mS, 0 ) ); } ladeKarte(); this->status = INITIALIZED; }; this->addDialog( new Frage( zS, "Es wurde eine alte ungespeicherte Sitzung gefunden. möchtest du sie Wiederherstellen?", "Ja", "Nein", wiederherstellen, verwerfen, verwerfen, mS ) ); this->status = INITIALIZED; } else if( ret == 1 ) { ladeKarte(); this->status = INITIALIZED; } else { Status *st = &status; this->status = INITIALIZED; this->addDialog( new Nachricht( zS, Text( "Fehler beim Initialisieren: " ) += k->getLastError(), mS, [ st ]() { *st = EXIT; } ) ); } zS->release(); k->release(); } ); } rend = 1; } void AsteroidsEditor::doMausEreignis( MausEreignis &me ) { c.lock(); for( auto i = dialogs->getArray(); i.set && i.var; i++ ) i.var->doMausEreignis( me ); bool dialogActive = dialogs->hat( 0 ); int anz = dialogs->getEintragAnzahl(); c.unlock(); if( anz == 0 ) { i->doMausEreignis( me ); if( i->hatVerlassen() && status == INITIALIZED && !dialogActive && me.id == ME_RLinks ) { status = WARTEND; EditorKlient *k = klient->getThis(); Schrift *zS = schrift->getThis(); Punkt mS = windowSize; new AsynchronCall( [ this, k, zS, mS ]( void ) -> void { if( !k->sitzungBeenden() ) { this->addDialog( new Nachricht( zS, Text( "Fehler beim Speichern: " ) += k->getLastError(), mS, 0 ) ); status = INITIALIZED; } else status = EXIT; zS->release(); k->release(); } ); } } } void AsteroidsEditor::doTastaturEreignis( TastaturEreignis &te ) { c.lock(); for( auto i = dialogs->getArray(); i.set && i.var; i++ ) i.var->doTastaturEreignis( te ); int anz = dialogs->getEintragAnzahl(); c.unlock(); if( anz == 0 ) i->doTastaturEreignis( te ); } bool AsteroidsEditor::tick( double z ) { if( ( status == WARTEND || status == START || ( daten && daten->hasAktions() ) ) && alpha != 100 ) { if( laden && !laden->istSichtbar() ) laden->setSichtbar( 1 ); if( alpha < 100 ) { alpha += (unsigned char)( 100 * z ); if( alpha > 100 ) alpha = 100; } else { alpha -= (unsigned char)( 100 * z ); if( alpha < 100 ) alpha = 100; } rend = 1; } else if( alpha != 255 ) { if( laden && laden->istSichtbar() ) laden->setSichtbar( 0 ); if( alpha + 100 * z > 255 ) alpha = 255; else alpha += (unsigned char)( 100 * z ); rend = 1; } if( laden ) rend |= laden->tick( z ); rend |= i->tick( z ); c.lock(); for( auto i = dialogs->getArray(); i.set && i.var; i++ ) rend |= i.var->tick( z ); c.unlock(); bool tmp = rend; rend = 0; return tmp; } void AsteroidsEditor::render( Bild &zRObj ) { if( windowSize == Punkt() ) { if( status != EXIT ) windowSize = zRObj.getSize(); setSichtbar(); if( !i && schrift ) i = new Interface( schrift, windowSize ); } zRObj.setAlpha( alpha ); i->render( zRObj ); c.lock(); for( int i = dialogs->getEintragAnzahl() - 1; i >= 0; i-- ) { dialogs->get( i )->render( zRObj ); if( dialogs->get( i )->hatVerlassen() ) { delete dialogs->get( i ); dialogs->remove( i ); } } c.unlock(); zRObj.releaseAlpha(); if( laden ) laden->render( zRObj ); } // constant bool AsteroidsEditor::hatVerlassen( bool jetzt ) const { return status == EXIT; } // Reference Counting EditorV *AsteroidsEditor::getThis() { ref++; return this; } EditorV *AsteroidsEditor::release() { ref--; if( !ref ) delete this; return 0; }