#include "ResourceDialog.h" #include "../../../Initialisierung/Initialisierung.h" using namespace Editor; // Konstructor // tr: Ein Zeiger auf den zu verwendenden TextRenderer // typ: Beschreibt was der nutzer alles auswählen kann // daten: Ein Zeiger auf die Karte, welche alle möglichen resouren enthält // onClose: Eine Funktion die aufgerufen wird, sobald der Dialog geschlossen wird. Es wird der ausgewählte Pfad oder 0 übergeben. // screenSize: Die größe des Bildschirms zum positionieren des dialogs ResourceDialog::ResourceDialog( TextRenderer *tr, ResourceDialogType typ, Editor::KarteDaten *daten, std::function< void( const char *path ) > onClose, Punkt screenSize ) : Dialog( tr ) { setTitel( "Resource Auswahl" ); this->daten = daten; setSize( 400, 468 ); setPosition( screenSize / 2 - getSize() / 2 ); m2v = new M2DVorschau(); m2v->setStyle( M2DVorschau::Style::Rahmen | M2DVorschau::Style::UsrRot | M2DVorschau::Style::UsrMove ); m2v->setSize( 390, 390 ); m2v->setPosition( 5, 30 ); bv = initBildZ( 5, 30, 390, 390, BildZ::Style::normal & ~Zeichnung::Style::Sichtbar, 0 ); paths = initAuswahlBox( 5, 5, 390, 20, tr->zSchrift(), AuswahlBox::Style::Normal | AuswahlBox::Style::Hintergrund, {} ); if( ( typ | ALLOW_RESOURCES ) == typ ) { int anz = daten->getResourceAnzahl(); for( int i = 0; i < anz; i++ ) { ResourceDaten *r = daten->getResource( i ); if( r->path.hat( ".ltdb/" ) && ( typ | TEXTUR ) == typ ) paths->addEintrag( r->path ); if( r->path.hat( ".m2/" ) && ( typ | MODEL2D ) == typ ) paths->addEintrag( r->path ); } } if( ( typ | ALLOW_NEW_RESOURCES ) == typ ) { daten->loadUnusedResourcePaths( [ this, typ ]( RCArray< Text > * unusedPaths ) { for( auto p = unusedPaths->getIterator(); p; p++ ) { if( p->hat( ".ltdb/" ) && ( typ | TEXTUR ) == typ ) paths->addEintrag( p->getText() ); if( p->hat( ".m2/" ) && ( typ | MODEL2D ) == typ ) paths->addEintrag( p->getText() ); } unusedPaths->release(); } ); } if( paths->getEintragAnzahl() ) { Text path = paths->zEintragText( 0 )->getText(); if( path.hat( ".ltdb/" ) ) { m2v->removeStyle( Zeichnung::Style::Sichtbar ); bv->setBild( this->daten->loadBildFromPath( path.getText() ) ); bv->addStyle( Zeichnung::Style::Sichtbar ); } else if( path.hat( ".m2/" ) ) { bv->removeStyle( Zeichnung::Style::Sichtbar ); m2v->setModel2D( this->daten->loadModelFromPath( path.getText() ) ); m2v->addStyle( Zeichnung::Style::Sichtbar ); } else { m2v->removeStyle( Zeichnung::Style::Sichtbar ); bv->removeStyle( Zeichnung::Style::Sichtbar ); } } paths->setEventAktion( [ this ]( void *p, AuswahlBox * a, int unused, int auswahl ) { Text path = paths->zEintragText( paths->getAuswahl() )->getText(); if( path.hat( ".ltdb/" ) ) { m2v->removeStyle( Zeichnung::Style::Sichtbar ); bv->setBild( this->daten->loadBildFromPath( path.getText() ) ); bv->addStyle( Zeichnung::Style::Sichtbar ); } else if( path.hat( ".m2/" ) ) { bv->removeStyle( Zeichnung::Style::Sichtbar ); m2v->setModel2D( this->daten->loadModelFromPath( path.getText() ) ); m2v->addStyle( Zeichnung::Style::Sichtbar ); } else { m2v->removeStyle( Zeichnung::Style::Sichtbar ); bv->removeStyle( Zeichnung::Style::Sichtbar ); } } ); Knopf *ok = initKnopf( 295, 425, 100, 20, tr->zSchrift(), Knopf::Style::Normal, "ok" ); addMember( ok ); ok->setMausEreignis( [ this, onClose ]( void *p, void *o, MausEreignis me ) { if( me.id == ME_RLinks ) { removeStyle( Fenster::Style::Sichtbar ); onClose( paths->zEintragText( paths->getAuswahl() )->getText() ); } return 1; } ); Knopf *abbrechen = initKnopf( 5, 425, 100, 20, tr->zSchrift(), Knopf::Style::Normal, "abbrechen" ); addMember( abbrechen ); auto abbruchAction = [ this, onClose ]( void *p, void *o, MausEreignis me ) { if( me.id == ME_RLinks ) { removeStyle( Fenster::Style::Sichtbar ); onClose( 0 ); } return 1; }; abbrechen->setMausEreignis( abbruchAction ); setClosingMe( abbruchAction ); bool *verl = &verlassen; addMember( paths->getThis() ); if( !paths->getEintragAnzahl() ) { removeStyle( Zeichnung::Style::Sichtbar ); onClose( 0 ); } } // Destruktor ResourceDialog::~ResourceDialog() { paths->release(); m2v->release(); bv->release(); daten->release(); }