home *** CD-ROM | disk | FTP | other *** search
/ Xentax forum attachments archive / xentax.7z / 8090 / ModelEdit.7z / PieceMaterialDlg.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  2006-03-08  |  6.5 KB  |  263 lines

  1. // PieceMaterialDlg.cpp : implementation file
  2. //
  3.  
  4. #include "precompile.h"
  5. #include "stdafx.h"
  6. #include "modeledit.h"
  7. #include "PieceMaterialDlg.h"
  8.  
  9. #ifdef _DEBUG
  10. #define new DEBUG_NEW
  11. #undef THIS_FILE
  12. static char THIS_FILE[] = __FILE__;
  13. #endif
  14.  
  15. /////////////////////////////////////////////////////////////////////////////
  16. // CPieceMaterialDlg dialog
  17.  
  18. CPieceMaterialDlg::CPieceMaterialDlg( const vector<PieceLODInfo>& selection, CWnd* pParent )
  19.     : CDialog(CPieceMaterialDlg::IDD, pParent), m_Selection( selection ), m_LODDistChanged( false ), m_StartDist( -1.0f )
  20. {
  21.     //{{AFX_DATA_INIT(CPieceMaterialDlg)
  22.         // NOTE: the ClassWizard will add member initialization here
  23.     //}}AFX_DATA_INIT
  24. }
  25.  
  26.  
  27. // so texture indices can be set in a loop
  28. int textureDlgItems[] =
  29. {
  30.     IDC_TEXTUREINDEX0,
  31.     IDC_TEXTUREINDEX1,
  32.     IDC_TEXTUREINDEX2,
  33.     IDC_TEXTUREINDEX3
  34. };
  35.  
  36. int textureSpinners[] =
  37. {
  38.     IDC_SPIN5,
  39.     IDC_SPIN6,
  40.     IDC_SPIN7,
  41.     IDC_SPIN8
  42. };
  43.  
  44.  
  45. void CPieceMaterialDlg::DoDataExchange(CDataExchange* pDX)
  46. {
  47.     CDialog::DoDataExchange(pDX);
  48.     //{{AFX_DATA_MAP(CPieceMaterialDlg)
  49.         // NOTE: the ClassWizard will add DDX and DDV calls here
  50.     //}}AFX_DATA_MAP
  51.  
  52.     // load the dialog data
  53.     if (!pDX->m_bSaveAndValidate)
  54.     {
  55.         // get the first piece LOD info to compare others against
  56.         float lodDistance = m_Selection[0].m_ModelPiece->GetLODDist( m_Selection[0].m_LODNum );
  57.         int numTextures = m_Selection[0].m_PieceLOD->m_nNumTextures;
  58.         int renderStyle = m_Selection[0].m_PieceLOD->m_iRenderStyle;
  59.         int renderPriority = m_Selection[0].m_PieceLOD->m_nRenderPriority;
  60.         int textureIndices[MAX_PIECE_TEXTURES];
  61.  
  62.         for( int i = 0; i < MAX_PIECE_TEXTURES; i++ )
  63.         {
  64.             textureIndices[i] = m_Selection[0].m_PieceLOD->m_iTextures[i];
  65.         }
  66.  
  67.         // if any of the values don't match the first piece, flag them with a negative value
  68.         for( i = 1; i < m_Selection.size(); i++ )
  69.         {
  70.             PieceLOD* curLOD = m_Selection[i].m_PieceLOD;
  71.             ASSERT( curLOD );
  72.  
  73.             if( m_Selection[i].m_ModelPiece->GetLODDist( m_Selection[i].m_LODNum ) != lodDistance )
  74.                 lodDistance = -1.0f;
  75.             if( curLOD->m_nNumTextures != numTextures )
  76.                 numTextures = -1;
  77.             if( curLOD->m_iRenderStyle != renderStyle )
  78.                 renderStyle = -1;
  79.             if( curLOD->m_nRenderPriority != renderPriority )
  80.                 renderPriority = -1;
  81.             
  82.             for( int j = 0; j < MAX_PIECE_TEXTURES; j++ )
  83.             {
  84.                 if( curLOD->m_iTextures[j] != textureIndices[j] )
  85.                     textureIndices[j] = -1;
  86.             }
  87.         }
  88.         
  89.         CString sVal;
  90.  
  91.         sVal.Empty();
  92.         if( lodDistance >= 0.0f )
  93.         {
  94.             sVal.Format("%0.2f", lodDistance );
  95.             m_StartDist = (float)atof( sVal );
  96.         }
  97.         GetDlgItem(IDC_LODDISTANCE)->SetWindowText( sVal );
  98.  
  99.         ((CComboBox*)GetDlgItem(IDC_NUMTEXTURES))->SetCurSel( numTextures );
  100.  
  101.         sVal.Empty();
  102.         if( renderStyle >= 0 )
  103.             sVal.Format("%d", renderStyle );
  104.         GetDlgItem(IDC_RENDERSTYLEINDEX)->SetWindowText( sVal );
  105.  
  106.         sVal.Empty();
  107.         if( renderPriority >= 0 )
  108.             sVal.Format("%d", renderPriority );
  109.         GetDlgItem(IDC_RENDERPRIORITY)->SetWindowText( sVal );
  110.  
  111.         for( i = 0; i < MAX_PIECE_TEXTURES; i++ )
  112.         {
  113.             sVal.Empty();
  114.             if( textureIndices[i] >= 0 )
  115.                 sVal.Format("%d", textureIndices[i] );
  116.             GetDlgItem( textureDlgItems[i] )->SetWindowText( sVal );
  117.         }
  118.  
  119.         //read in the NULL checkbox state
  120.         ((CButton*)GetDlgItem(IDC_CHECK_NULL_LOD))->SetCheck(m_Selection[0].m_PieceLOD->NumVerts() ? 0 : 1);
  121.     }
  122.     // retrieve the dialog data
  123.     else
  124.     {
  125.         float lodDistance;
  126.         int numTextures;
  127.         int renderStyle;
  128.         int renderPriority;
  129.         int textureIndices[MAX_PIECE_TEXTURES];
  130.  
  131.         CString str;
  132.  
  133.         // get values for any controls that aren't empty
  134.         GetDlgItem(IDC_LODDISTANCE)->GetWindowText( str );
  135.         if( str.IsEmpty() )
  136.             lodDistance = -1.0f;
  137.         else
  138.         {
  139.             lodDistance = (float)atof( str );
  140.             if( lodDistance == m_StartDist )
  141.                 lodDistance = -1.0f;
  142.         }
  143.  
  144.         numTextures = ((CComboBox*)GetDlgItem(IDC_NUMTEXTURES))->GetCurSel();
  145.         if( numTextures == CB_ERR )
  146.             numTextures = -1;
  147.  
  148.         GetDlgItem(IDC_RENDERSTYLEINDEX)->GetWindowText( str );
  149.         if( str.IsEmpty() )
  150.             renderStyle = -1;
  151.         else
  152.             renderStyle = atoi( str );
  153.  
  154.         GetDlgItem(IDC_RENDERPRIORITY)->GetWindowText( str );
  155.         if( str.IsEmpty() )
  156.             renderPriority = -1;
  157.         else
  158.             renderPriority = min(255, max(0, atoi( str )));
  159.  
  160.         for( int i = 0; i < MAX_PIECE_TEXTURES; i++ )
  161.         {
  162.             GetDlgItem( textureDlgItems[i] )->GetWindowText( str );
  163.             if( str.IsEmpty() )
  164.                 textureIndices[i] = -1;
  165.             else
  166.                 textureIndices[i] = atoi( str );
  167.         }
  168.  
  169.         // update the piece LODs with the changed values
  170.         for( i = 0; i < m_Selection.size(); i++ )
  171.         {
  172.             PieceLOD* curLOD = m_Selection[i].m_PieceLOD;
  173.             ASSERT( curLOD );
  174.  
  175.             if( lodDistance >= 0.0f )
  176.             {
  177.                 m_Selection[i].m_ModelPiece->SetLODDist( m_Selection[i].m_LODNum, lodDistance );
  178.                 m_LODDistChanged = true;
  179.             }
  180.  
  181.             if( numTextures >= 0 )
  182.                 curLOD->m_nNumTextures = numTextures;
  183.  
  184.             if( renderStyle >= 0 )
  185.                 curLOD->m_iRenderStyle = renderStyle;
  186.  
  187.             if( renderPriority >= 0 )
  188.                 curLOD->m_nRenderPriority = renderPriority;
  189.  
  190.             for( int j = 0; j < MAX_PIECE_TEXTURES; j++ )
  191.             {
  192.                 if( textureIndices[j] >= 0 )
  193.                     curLOD->m_iTextures[j] = textureIndices[j];
  194.             }
  195.         }
  196.     }
  197. }
  198.  
  199.  
  200. BEGIN_MESSAGE_MAP(CPieceMaterialDlg, CDialog)
  201.     //{{AFX_MSG_MAP(CPieceMaterialDlg)
  202.     ON_CBN_SELCHANGE(IDC_NUMTEXTURES, OnSelNumTextures)
  203.     //}}AFX_MSG_MAP
  204. END_MESSAGE_MAP()
  205.  
  206. /////////////////////////////////////////////////////////////////////////////
  207. // CPieceMaterialDlg message handlers
  208.  
  209. void CPieceMaterialDlg::OnSelNumTextures()
  210. {
  211.     UpdateEnabledStatus();
  212. }
  213.  
  214.  
  215. BOOL CPieceMaterialDlg::OnInitDialog() 
  216. {
  217.     CDialog::OnInitDialog();
  218.  
  219.     CSpinButtonCtrl* pSpin;
  220.     CComboBox* box = (CComboBox*)GetDlgItem(IDC_NUMTEXTURES);
  221.     char curNum[10];
  222.     
  223.     for(int i=0; i <= MAX_PIECE_TEXTURES; i++)
  224.     {
  225.         sprintf( curNum, "%d", i );
  226.         box->AddString( curNum );
  227.  
  228.     }
  229.     
  230.     for(i = 0; i < MAX_PIECE_TEXTURES; i++)
  231.     {
  232.         pSpin = (CSpinButtonCtrl*)GetDlgItem( textureSpinners[i] );
  233.         pSpin->SetRange32( 0, 32 );
  234.     }
  235.  
  236.     pSpin = (CSpinButtonCtrl*)GetDlgItem(IDC_SPIN1);
  237.     pSpin->SetRange32( 0, 9 );
  238.  
  239.     pSpin = (CSpinButtonCtrl*)GetDlgItem(IDC_SPINRENDERPRIORITY);
  240.     pSpin->SetRange32( 0, 255 );
  241.  
  242.     UpdateData( FALSE );
  243.     UpdateEnabledStatus();
  244.  
  245.     return TRUE;
  246. }
  247.  
  248.  
  249. void CPieceMaterialDlg::UpdateEnabledStatus()
  250. {
  251.     CComboBox* box = (CComboBox*)GetDlgItem(IDC_NUMTEXTURES);
  252.     int numTextures = box->GetCurSel();
  253.  
  254.     if( numTextures == CB_ERR )
  255.         numTextures = 0;
  256.  
  257.     // update the texture index controls
  258.     for( int i = 0; i < MAX_PIECE_TEXTURES; i++ )
  259.     {
  260.         GetDlgItem( textureDlgItems[i] )->EnableWindow( numTextures > i );
  261.     }
  262. }
  263.