123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274 |
- #include "Editor.h"
- #include <AsynchronCall.h>
- #include "Interface\Dialogs\Frage.h"
- #include "Interface\Dialogs\Nachricht.h"
- #include <iostream>
- #include <Bild.h>
- 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( (EditorKlient *)klient->getThis() );
- i->setDaten( (KarteDaten *)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;
- Punkt mS = windowSize;
- if( windowSize != Punkt() )
- {
- EditorKlient *k = klient->getThis();
- TextRenderer *zS = new TextRenderer( schrift->getThis() );
- 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->getIterator(); i && i._; i++ )
- i->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();
- TextRenderer *zS = new TextRenderer( 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->getIterator(); i && i._; i++ )
- i->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->getIterator(); i && i._; i++ )
- rend |= i->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;
- }
|