ResourceDialog.cpp 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  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. paths = initAuswahlBox( 5, 5, 390, 20, tr->zSchrift(), AuswahlBox::Style::Normal | AuswahlBox::Style::Hintergrund, {} );
  23. if( ( typ | ALLOW_RESOURCES ) == typ )
  24. {
  25. int anz = daten->getResourceAnzahl();
  26. for( int i = 0; i < anz; i++ )
  27. {
  28. ResourceDaten *r = daten->getResource( i );
  29. if( r->path.hat( ".ltdb/" ) && ( typ | TEXTUR ) == typ )
  30. paths->addEintrag( r->path );
  31. if( r->path.hat( ".m2/" ) && ( typ | MODEL2D ) == typ )
  32. paths->addEintrag( r->path );
  33. }
  34. }
  35. if( ( typ | ALLOW_NEW_RESOURCES ) == typ )
  36. {
  37. daten->loadUnusedResourcePaths( [ this, typ ]( RCArray< Text > * unusedPaths )
  38. {
  39. for( auto p = unusedPaths->getIterator(); p; p++ )
  40. {
  41. if( p->hat( ".ltdb/" ) && ( typ | TEXTUR ) == typ )
  42. paths->addEintrag( p->getText() );
  43. if( p->hat( ".m2/" ) && ( typ | MODEL2D ) == typ )
  44. paths->addEintrag( p->getText() );
  45. }
  46. unusedPaths->release();
  47. } );
  48. }
  49. if( paths->getEintragAnzahl() )
  50. {
  51. Text path = paths->zEintragText( 0 )->getText();
  52. if( path.hat( ".ltdb/" ) )
  53. {
  54. m2v->removeStyle( Zeichnung::Style::Sichtbar );
  55. bv->setBild( this->daten->loadBildFromPath( path.getText() ) );
  56. bv->addStyle( Zeichnung::Style::Sichtbar );
  57. }
  58. else if( path.hat( ".m2/" ) )
  59. {
  60. bv->removeStyle( Zeichnung::Style::Sichtbar );
  61. m2v->setModel2D( this->daten->loadModelFromPath( path.getText() ) );
  62. m2v->addStyle( Zeichnung::Style::Sichtbar );
  63. }
  64. else
  65. {
  66. m2v->removeStyle( Zeichnung::Style::Sichtbar );
  67. bv->removeStyle( Zeichnung::Style::Sichtbar );
  68. }
  69. }
  70. paths->setEventAktion( [ this ]( void *p, AuswahlBox * a, int unused, int auswahl )
  71. {
  72. Text path = paths->zEintragText( paths->getAuswahl() )->getText();
  73. if( path.hat( ".ltdb/" ) )
  74. {
  75. m2v->removeStyle( Zeichnung::Style::Sichtbar );
  76. bv->setBild( this->daten->loadBildFromPath( path.getText() ) );
  77. bv->addStyle( Zeichnung::Style::Sichtbar );
  78. }
  79. else if( path.hat( ".m2/" ) )
  80. {
  81. bv->removeStyle( Zeichnung::Style::Sichtbar );
  82. m2v->setModel2D( this->daten->loadModelFromPath( path.getText() ) );
  83. m2v->addStyle( Zeichnung::Style::Sichtbar );
  84. }
  85. else
  86. {
  87. m2v->removeStyle( Zeichnung::Style::Sichtbar );
  88. bv->removeStyle( Zeichnung::Style::Sichtbar );
  89. }
  90. } );
  91. Knopf *ok = initKnopf( 295, 425, 100, 20, tr->zSchrift(), Knopf::Style::Normal, "ok" );
  92. addMember( ok );
  93. ok->setMausEreignis( [ this, onClose ]( void *p, void *o, MausEreignis me )
  94. {
  95. if( me.id == ME_RLinks )
  96. {
  97. removeStyle( Fenster::Style::Sichtbar );
  98. onClose( paths->zEintragText( paths->getAuswahl() )->getText() );
  99. }
  100. return 1;
  101. } );
  102. Knopf *abbrechen = initKnopf( 5, 425, 100, 20, tr->zSchrift(), Knopf::Style::Normal, "abbrechen" );
  103. addMember( abbrechen );
  104. auto abbruchAction = [ this, onClose ]( void *p, void *o, MausEreignis me )
  105. {
  106. if( me.id == ME_RLinks )
  107. {
  108. removeStyle( Fenster::Style::Sichtbar );
  109. onClose( 0 );
  110. }
  111. return 1;
  112. };
  113. abbrechen->setMausEreignis( abbruchAction );
  114. setClosingMe( abbruchAction );
  115. bool *verl = &verlassen;
  116. addMember( paths->getThis() );
  117. if( !paths->getEintragAnzahl() )
  118. {
  119. removeStyle( Zeichnung::Style::Sichtbar );
  120. onClose( 0 );
  121. }
  122. }
  123. // Destruktor
  124. ResourceDialog::~ResourceDialog()
  125. {
  126. paths->release();
  127. m2v->release();
  128. bv->release();
  129. daten->release();
  130. }