ResourceDialog.cpp 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  1. #include "ResourceDialog.h"
  2. #include "../../../Initialisierung/Initialisierung.h"
  3. using namespace Editor;
  4. // Konstructor
  5. // tr: Ein Zeiger auf den zu verwendenden TextRenderer
  6. // typ: Beschreibt was der nutzer alles auswählen kann
  7. // daten: Ein Zeiger auf die Karte, welche alle möglichen resouren enthält
  8. // onClose: Eine Funktion die aufgerufen wird, sobald der Dialog geschlossen wird. Es wird der ausgewählte Pfad oder 0 übergeben.
  9. // screenSize: Die größe des Bildschirms zum positionieren des dialogs
  10. ResourceDialog::ResourceDialog( TextRenderer *tr, ResourceDialogType typ, Editor::KarteDaten *daten, std::function< void( const char *path ) > onClose, Punkt screenSize )
  11. : Dialog( tr )
  12. {
  13. setTitel( "Resource Auswahl" );
  14. this->daten = daten;
  15. setSize( 400, 468 );
  16. setPosition( screenSize / 2 - getSize() / 2 );
  17. m2v = new M2DVorschau();
  18. m2v->setStyle( M2DVorschau::Style::Rahmen | M2DVorschau::Style::UsrRot | M2DVorschau::Style::UsrMove );
  19. m2v->setSize( 390, 390 );
  20. m2v->setPosition( 5, 30 );
  21. bv = initBildZ( 5, 30, 390, 390, BildZ::Style::normal & ~Zeichnung::Style::Sichtbar, 0 );
  22. addMember( bv->getThis() );
  23. addMember( m2v->getThis() );
  24. paths = initAuswahlBox( 5, 5, 390, 20, tr->zSchrift(), AuswahlBox::Style::Normal | AuswahlBox::Style::Hintergrund, {} );
  25. if( ( typ | ALLOW_RESOURCES ) == typ )
  26. {
  27. int anz = daten->getResourceAnzahl();
  28. for( int i = 0; i < anz; i++ )
  29. {
  30. ResourceDaten *r = daten->getResource( i );
  31. if( r->path.hat( ".ltdb/" ) && ( typ | TEXTUR ) == typ )
  32. paths->addEintrag( r->path );
  33. if( r->path.hat( ".m2/" ) && ( typ | MODEL2D ) == typ )
  34. paths->addEintrag( r->path );
  35. }
  36. }
  37. if( ( typ | ALLOW_NEW_RESOURCES ) == typ )
  38. {
  39. daten->loadUnusedResourcePaths( [ this, typ ]( RCArray< Text > * unusedPaths )
  40. {
  41. for( auto p = unusedPaths->getIterator(); p; p++ )
  42. {
  43. if( p->hat( ".ltdb/" ) && ( typ | TEXTUR ) == typ )
  44. paths->addEintrag( p->getText() );
  45. if( p->hat( ".m2/" ) && ( typ | MODEL2D ) == typ )
  46. paths->addEintrag( p->getText() );
  47. }
  48. unusedPaths->release();
  49. } );
  50. }
  51. if( paths->getEintragAnzahl() )
  52. {
  53. Text path = paths->zEintragText( 0 )->getText();
  54. if( path.hat( ".ltdb/" ) )
  55. {
  56. m2v->removeStyle( Zeichnung::Style::Sichtbar );
  57. bv->setBild( this->daten->loadBildFromPath( path.getText() ) );
  58. bv->addStyle( Zeichnung::Style::Sichtbar );
  59. }
  60. else if( path.hat( ".m2/" ) )
  61. {
  62. bv->removeStyle( Zeichnung::Style::Sichtbar );
  63. m2v->setModel2D( this->daten->loadModelFromPath( path.getText() ) );
  64. m2v->zModel()->addStyle( Model2D::Style::Sichtbar | Model2D::Style::Mesh | Model2D::Style::Erlaubt );
  65. m2v->zModel()->setFarbe( 0xFFFFFFFF );
  66. m2v->addStyle( Zeichnung::Style::Sichtbar );
  67. }
  68. else
  69. {
  70. m2v->removeStyle( Zeichnung::Style::Sichtbar );
  71. bv->removeStyle( Zeichnung::Style::Sichtbar );
  72. }
  73. }
  74. paths->setEventAktion( [ this ]( void *p, AuswahlBox * a, int unused, int auswahl )
  75. {
  76. Text path = paths->zEintragText( paths->getAuswahl() )->getText();
  77. if( path.hat( ".ltdb/" ) )
  78. {
  79. m2v->removeStyle( Zeichnung::Style::Sichtbar );
  80. bv->setBild( this->daten->loadBildFromPath( path.getText() ) );
  81. bv->addStyle( Zeichnung::Style::Sichtbar );
  82. }
  83. else if( path.hat( ".m2/" ) )
  84. {
  85. bv->removeStyle( Zeichnung::Style::Sichtbar );
  86. m2v->setModel2D( this->daten->loadModelFromPath( path.getText() ) );
  87. m2v->addStyle( Zeichnung::Style::Sichtbar );
  88. }
  89. else
  90. {
  91. m2v->removeStyle( Zeichnung::Style::Sichtbar );
  92. bv->removeStyle( Zeichnung::Style::Sichtbar );
  93. }
  94. } );
  95. Knopf *ok = initKnopf( 295, 425, 100, 20, tr->zSchrift(), Knopf::Style::Normal, "ok" );
  96. addMember( ok );
  97. ok->setMausEreignis( [ this, onClose ]( void *p, void *o, MausEreignis me )
  98. {
  99. if( me.id == ME_RLinks )
  100. {
  101. removeStyle( Fenster::Style::Sichtbar );
  102. onClose( paths->zEintragText( paths->getAuswahl() )->getText() );
  103. }
  104. return 1;
  105. } );
  106. Knopf *abbrechen = initKnopf( 5, 425, 100, 20, tr->zSchrift(), Knopf::Style::Normal, "abbrechen" );
  107. addMember( abbrechen );
  108. auto abbruchAction = [ this, onClose ]( void *p, void *o, MausEreignis me )
  109. {
  110. if( me.id == ME_RLinks )
  111. {
  112. removeStyle( Fenster::Style::Sichtbar );
  113. onClose( 0 );
  114. }
  115. return 1;
  116. };
  117. abbrechen->setMausEreignis( abbruchAction );
  118. setClosingMe( abbruchAction );
  119. bool *verl = &verlassen;
  120. addMember( paths->getThis() );
  121. if( !paths->getEintragAnzahl() )
  122. {
  123. removeStyle( Zeichnung::Style::Sichtbar );
  124. onClose( 0 );
  125. }
  126. }
  127. // Destruktor
  128. ResourceDialog::~ResourceDialog()
  129. {
  130. paths->release();
  131. m2v->release();
  132. bv->release();
  133. daten->release();
  134. }