123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344 |
- #include "Editor.h"
- #include <AsynchronCall.h>
- #include "Nachricht.h"
- #include "Frage.h"
- #include <Globals.h>
- #include <Bild.h>
- using namespace Editor;
- /*
- // Konstruktor
- SMWEditor::SMWEditor()
- : ReferenceCounter()
- {
- status = START;
- klient = 0;
- laden = 0;
- i = 0;
- dialogs = new Array< Dialog * >();
- sts = 0;
- daten = 0;
- moveObj = 0;
- rotObj = 0;
- alpha = 0;
- rend = 0;
- uiFactory.initParam.schrift = 0;
- }
- // Destruktor
- SMWEditor::~SMWEditor()
- {
- if( klient )
- klient->release();
- if( laden )
- laden->release();
- if( i )
- i->release();
- if( sts )
- sts->release();
- if( daten )
- daten->release();
- if( moveObj )
- moveObj->release();
- if( rotObj )
- rotObj->release();
- dialogs->release();
- }
- // private
- void SMWEditor::ladeKarte()
- {
- if( sts )
- sts = (SpielerTeamStruktur *)sts->release();
- sts = new SpielerTeamStruktur();
- klient->getSpielerTeamStruktur( sts );
- if( daten )
- daten->release();
- daten = new KarteDaten( dynamic_cast<EditorKlient *>( klient->getThis() ), sts );
- i->setDaten( dynamic_cast<KarteDaten *>( daten->getThis() ) );
- }
- // nicht constant
- void SMWEditor::addDialog( Dialog *d )
- {
- c.lock();
- dialogs->add( d );
- c.unlock();
- }
- void SMWEditor::setUIFactory( UIInit &uiFactory )
- {
- this->uiFactory = uiFactory;
- if( !i && windowSize != Punkt() )
- i = new Interface( uiFactory, windowSize );
- }
- void SMWEditor::setKlient( KSGClient::EditorServerClient *ekv )
- {
- if( klient )
- klient->release();
- klient = new EditorKlient( ekv );
- }
- void SMWEditor::setLadeAnimation( Animation2D *la )
- {
- if( laden )
- laden->release();
- laden = la;
- }
- void SMWEditor::setSichtbar()
- {
- status = START;
- Punkt mS = windowSize;
- if( windowSize != Punkt() )
- {
- EditorKlient *k = dynamic_cast<EditorKlient *>( klient->getThis() );
- TextRenderer *zS = new TextRenderer( dynamic_cast<Schrift *>( uiFactory.initParam.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( dynamic_cast<TextRenderer *>( zS->getThis() ), t, mS, 0 ) );
- }
- ladeKarte();
- this->status = INITIALIZED;
- };
- this->addDialog( new Frage( dynamic_cast<TextRenderer *>( zS->getThis() ), "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( dynamic_cast<TextRenderer *>( zS->getThis() ), Text( "Fehler beim Initialisieren: " ) += k->getLastError(), mS, [st]() { *st = EXIT; } ) );
- }
- zS->release();
- k->release();
- } );
- }
- rend = 1;
- }
- void SMWEditor::doPublicMausEreignis( MausEreignis &me )
- {
- //TODO
- c.lock();
- for( auto i = dialogs->getIterator(); i && i._; i++ )
- i->doPublicMausEreignis( me );
- bool dialogActive = dialogs->hat( 0 );
- int anz = dialogs->getEintragAnzahl();
- c.unlock();
- if( anz == 0 )
- {
- i->doPublicMausEreignis( me );
- if( i->hatVerlassen() && status == INITIALIZED && !dialogActive && me.id == ME_RLinks )
- {
- status = WARTEND;
- EditorKlient *k = dynamic_cast<EditorKlient *>( klient->getThis() );
- TextRenderer *zS = new TextRenderer( dynamic_cast<Schrift *>( uiFactory.initParam.schrift->getThis() ) );
- Punkt mS = windowSize;
- new AsynchronCall( [this, k, zS, mS]( void ) -> void
- {
- if( !k->sitzungBeenden() )
- {
- this->addDialog( new Nachricht( zS->getThis(), Text( "Fehler beim Speichern: " ) += k->getLastError(), mS, 0 ) );
- status = INITIALIZED;
- }
- else
- status = EXIT;
- zS->release();
- k->release();
- } );
- }
- }
- if( !me.verarbeitet )
- {
- if( me.id == ME_PLinks )
- {
- Vertex pos = kamera->getWorldCoordinates( Punkt( me.mx, me.my ) );
- moveObj = (EditorObject *)daten->zWelt()->zObjectAt( (int)pos.x, (int)pos.y, 1 );
- if( moveObj )
- me.verarbeitet = 1;
- }
- if( me.id == ME_PMitte )
- {
- Vertex pos = kamera->getWorldCoordinates( Punkt( me.mx, me.my ) );
- rotObj = (EditorObject *)daten->zWelt()->zObjectAt( (int)pos.x, (int)pos.y, 1 );
- if( rotObj )
- me.verarbeitet = 1;
- }
- if( me.id == ME_Bewegung )
- {
- if( moveObj )
- {
- moveObj->setPosition( moveObj->getPosition() + Punkt( me.mx, me.my ) - maus );
- rend = 1;
- me.verarbeitet = 1;
- }
- if( rotObj )
- {
- rotObj->addDrehung( ( me.mx - maus.x ) / 100.f );
- rend = 1;
- me.verarbeitet = 1;
- }
- }
- if( me.id == ME_RLinks )
- {
- if( moveObj )
- {
- moveObj->update();
- me.verarbeitet = 1;
- moveObj = 0;
- }
- }
- if( me.id == ME_RMitte )
- {
- if( rotObj )
- {
- rotObj->update();
- me.verarbeitet = 1;
- rotObj = 0;
- }
- }
- }
- if( !me.verarbeitet )
- {
- if( getMausStand( M_Links ) )
- {
- if( me.mx >= minimap->getX() && me.mx < minimap->getX() + minimap->getBreite() &&
- me.my >= minimap->getY() && me.my <= minimap->getY() + minimap->getHeight() )
- {
- kamera->lookAtWorldPos( minimap->getWorldCoordinates( Punkt( me.mx - minimap->getX(), me.my - minimap->getY() ) ) );
- }
- else
- {
- if( me.id == ME_Bewegung )
- kamera->lookAtWorldPos( kamera->getWorldPosition() + maus - Punkt( me.mx, me.my ) );
- }
- }
- if( me.id == ME_UScroll )
- kamera->setZoom( kamera->getZoom() / 0.9f );
- if( me.id == ME_DScroll )
- kamera->setZoom( kamera->getZoom() / 1.1f );
- }
- maus.x = me.mx;
- maus.y = me.my;
- }
- void SMWEditor::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 SMWEditor::tick( double z )
- {
- if( ( status == WARTEND || status == START || ( daten && daten->hasAktions() ) ) )
- {
- if( 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 );
- rend |= minimap->tick( z );
- rend |= kamera->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;
- return 0;
- }
- void SMWEditor::render( Bild &zRObj )
- {
- if( windowSize == Punkt() )
- {
- if( status != EXIT )
- windowSize = zRObj.getSize();
- setSichtbar();
- if( !i && uiFactory.initParam.schrift )
- i = new Interface( uiFactory, windowSize );
- }
- zRObj.setAlpha( alpha );
- kamera->setSize( zRObj.getSize() );
- kamera->render( zRObj );
- minimap->setPosition( 10, zRObj.getHeight() - 210 );
- minimap->render( zRObj );
- 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 SMWEditor::hatVerlassen( bool jetzt ) const
- {
- return status == EXIT;
- }
- */
|