📄 entitiesdialog.cpp
字号:
if( Left.Left(LeftLen) == Right.Left(RightLen) )
{
return LeftVal - RightVal ;
}
return Left.Compare( Right ) ;
}/* ::compare */
void CEntitiesDialog::FillInDialog()
{
int CurrentEnt;
int NumberOfEnts = (*mEntityArray).GetSize();
// int RealIndex = 0;
int ArrayIndex = 0 ;
geBoolean bValidSelection = FALSE ;
int VisibleEnt = 0 ;
PSortStruct pSortArray ;
int Index ;
CString EntityName;
// clear our main stuff
m_EntityCombo.ResetContent();
// Get a qualified list count
for( CurrentEnt = 0; CurrentEnt < NumberOfEnts; CurrentEnt++ )
{
CEntity *pEnt;
// get the name
pEnt = &((*mEntityArray)[CurrentEnt]);
if( pEnt->IsVisible() )
{
VisibleEnt++ ;
}
}
pSortArray = (PSortStruct)geRam_Allocate(sizeof(SSortStruct)*VisibleEnt);
if( pSortArray == NULL )
return ; //We're called from OnInitDialog--the best err handling we can do is leave
// Get a qualified list
for( CurrentEnt = 0; CurrentEnt < NumberOfEnts; CurrentEnt++ )
{
CEntity *pEnt;
// get the name
pEnt = &((*mEntityArray)[CurrentEnt]);
if( pEnt->IsVisible() )
{
pSortArray[ArrayIndex].pEnt = pEnt ;
pSortArray[ArrayIndex].nItem = CurrentEnt ;
ArrayIndex++ ;
}
}// Qualified List
qsort( pSortArray, VisibleEnt, sizeof( SSortStruct ), compare ) ;
for( CurrentEnt=0; CurrentEnt < VisibleEnt; CurrentEnt++ )
{
EntityName = pSortArray[CurrentEnt].pEnt->GetName() ;
if (EntityName == "")
{
EntityName = "Unnamed";
}
// strip quotes from the entity name
stripQuotes (EntityName);
Index = m_EntityCombo.AddString( EntityName );
m_EntityCombo.SetItemData (Index, pSortArray[CurrentEnt].nItem );
if( pSortArray[CurrentEnt].nItem == mCurrentEntity )
{
m_EntityCombo.SetCurSel( Index );
bValidSelection = TRUE ;
}
}// Fill the list
// if we have no entities set to nothing.
if( !NumberOfEnts )
{
mCurrentEntity = LB_ERR;
}
else if( bValidSelection == FALSE ) // None of the entities populated were selected
{
m_EntityCombo.SetCurSel( 0 ); // Select the first one
mCurrentEntity = m_EntityCombo.GetItemData( m_EntityCombo.GetCurSel( ) ) ;
if( mCurrentEntity != LB_ERR )
pDoc->SetSelectedEntity( mCurrentEntity ) ;
}
geRam_Free ( pSortArray ) ;
// fill in the key/value stuff for the current entity
FillInKeyValuePairs (0);
}/* CEntitiesDialog::FillInDialog */
//================================================================================
// This function fills in the key value pairs for the current dialog.
//================================================================================
void CEntitiesDialog::FillInKeyValuePairs(int Selection)
{
// now get the actual entity number from that
int Entity ;
//ASSERT( m_EntityCombo.GetItemData( m_EntityCombo.GetCurSel( ) ) == (DWORD)Entity ) ;
Entity = m_EntityCombo.GetItemData( m_EntityCombo.GetCurSel( ) ) ; // old gedit
// Entity = pDoc->mCurrentEntity; // g3dc experiment
// now go through that entity and add key/value pairs
// to the dialog
m_PropertiesList.ResetContent();
// what do we have here?
if( Entity == LB_ERR )
{
mCurrentKey = LB_ERR;
return;
}
CEntity *Ent = &((*mEntityArray)[Entity]);
EntityPropertiesList const *pProps;
// Get sorted list of published key/value pairs
CString EntityClassname = Ent->GetClassname ();
pProps = EntityTable_GetEntityPropertiesFromName (Level_GetEntityDefs (pDoc->pLevel), EntityClassname, ET_PUBLISHED);
if (pProps != NULL)
{
// Add key/value pairs to the listbox
for (int iProp = 0; iProp < pProps->NumProps; iProp++)
{
EntityProperty const *p;
p = &(pProps->Props[iProp]);
if (p->KeyNum == -1)
{
// a key number of -1 indicates the end of valid keys...
break;
}
// if this key doesn't exist for this entity, then add it
// and its default value...
CString TheVal;
if (!Ent->GetKeyValue (p->pKey, TheVal))
{
Ent->SetKeyValue (p->pKey, p->pValue);
}
if (p->published)
{
// add it to the listbox
m_PropertiesList.AddString (p->pKey);
}
}
EntityTable_ReleaseEntityProperties (pProps);
}
else
{
/*
We know nothing about this entity's type.
We have the key/value pairs, but we don't know what's supposed
to be published. So we'll display "unknown type".
*/
m_PropertiesList.AddString ("Unknown Entity Type");
Selection = LB_ERR;
}
// set the current
m_PropertiesList.SetCurSel (Selection);
}
void CEntitiesDialog::OnSelchangeEntitylist()
{
// get the current selection from the entity list
int CurrentSelection = m_EntityCombo.GetCurSel();
// we have an error
if( CurrentSelection == LB_ERR )
{
mCurrentEntity = LB_ERR;
}
else
{
// now get the actual entity number from that
mCurrentEntity = m_EntityCombo.GetItemData( CurrentSelection );
// Set this as the current entity...
pDoc->SetSelectedEntity( mCurrentEntity ) ;
// Be very careful when speccing flags for UpdateAllViews()
// The wrong flags at the wrong time will totally screw things up
pDoc->UpdateAllViews( UAV_ALL3DVIEWS, NULL );
}
// FillInKeyValuePairs (0);
}
void CEntitiesDialog::OnDblclkPropertieslist()
{
// Double-click on the item...Edit it.
mCurrentKey = m_PropertiesList.GetCurSel ();
if (mCurrentKey != LB_ERR)
{
CEntity *Ent = &((*mEntityArray)[mCurrentEntity]);
CString EntityTypeName = Ent->GetClassname ();
CString KeyName;
CString TheValue;
m_PropertiesList.GetText (mCurrentKey, KeyName);
Ent->GetKeyValue (KeyName, TheValue);
TopType eType;
if (EntityTable_GetEntityPropertyType (Level_GetEntityDefs (pDoc->pLevel), EntityTypeName, KeyName, &eType))
{
CDialog *pEditDialog = NULL;
// Create the dialog that's appropriate for this type....
switch (eType)
{
case T_INT :
pEditDialog = new CIntKeyEditDlg (this, KeyName, &TheValue);
break;
case T_FLOAT :
pEditDialog = new CFloatKeyEditDlg (this, KeyName, &TheValue);
break;
case T_COLOR :
pEditDialog = new CColorKeyEditDlg (this, KeyName, &TheValue);
break;
case T_POINT :
pEditDialog = new CPointKeyEditDlg (this, KeyName, &TheValue);
break;
case T_STRING :
pEditDialog = new CKeyEditDlg (this, KeyName, &TheValue);
break;
case T_MODEL :
pEditDialog = new CModelKeyEditDlg (this, Level_GetModelInfo (pDoc->pLevel)->Models, KeyName, &TheValue);
break;
case T_STRUCT :
pEditDialog = new CStructKeyEditDlg (this, *Ent, KeyName, mEntityArray, &TheValue, Level_GetEntityDefs (pDoc->pLevel));
break;
case T_BOOLEAN :
pEditDialog = new CBoolKeyEditDlg (this, KeyName, &TheValue);
break;
case T_PTR :
default :
// bad or unknown type
assert (0);
break;
}
if (pEditDialog != NULL)
{
int ModalResult = pEditDialog->DoModal ();
delete pEditDialog;
if (ModalResult == IDOK)
{
if (MultiEntityFlag)
{
// multiple entities--change this property on all of them
int i;
for (i = 0; i < mEntityArray->GetSize (); ++i)
{
CEntity *pEnt;
pEnt = &(*mEntityArray)[i];
if (pEnt->IsSelected ())
{
pEnt->SetKeyValue (KeyName, TheValue);
}
}
}
else
{
// update
Ent->SetKeyValue (KeyName, TheValue);
}
FillInKeyValuePairs(mCurrentKey);
}
}
}
}
}
int CEntitiesDialog::OnVKeyToItem(UINT nKey, CListBox* pListBox, UINT nIndex)
{
switch (nKey)
{
case VK_SPACE :
case VK_RETURN :
this->OnDblclkPropertieslist ();
return -2;
default :
return CDialog::OnVKeyToItem(nKey, pListBox, nIndex);
}
}
void CEntitiesDialog::OnOK (void)
{
this->OnDblclkPropertieslist ();
}
void CEntitiesDialog::OnCancel()
{
return;
}
static void FillTextBuffer
(
HDC hdc,
char *Buffer,
char const *Text,
int MaxWidth
)
{
int len = strlen (Text);
SIZE size;
do
{
::GetTextExtentPoint32 (hdc, Text, len, &size);
if (size.cy > MaxWidth)
{
--len;
}
} while ((size.cy > MaxWidth) && (len > 0));
if (len > 0)
{
strncpy (Buffer, Text, len);
}
Buffer[len] = '\0';
}
void CEntitiesDialog::OnDrawItem(int nIDCtl, LPDRAWITEMSTRUCT lpdis)
{
if (nIDCtl != IDC_PROPERTIESLIST)
{
CDialog::OnDrawItem(nIDCtl, lpdis);
return;
}
// don't worry about invalid items (yet)
if (lpdis->itemID == -1)
{
// Don't call CDialog::OnDrawItem with an invalid item...
// it will crash.
// CDialog::OnDrawItem(nIDCtl, lpdis);
return;
}
// we'll start out by just drawing the entire item every time
char KeyText[255];
char ValueText[255];
int rectWidth = lpdis->rcItem.right - lpdis->rcItem.left;
int halfWidth = rectWidth/2;
int maxTextWidth = halfWidth - 2; // 2 pixels on each side...
int leftX = lpdis->rcItem.left + 2;
int rightX = leftX + halfWidth + 2;
RECT rectKey = lpdis->rcItem;
rectKey.right = rightX - 2;
RECT rectValue = lpdis->rcItem;
rectValue.left = rightX - 2;
// opaque inside of the box...
++(rectKey.left);
++(rectKey.top);
// --(rectKey.right);
--(rectKey.bottom);
// ++(rectValue.left);
++(rectValue.top);
--(rectValue.right);
--(rectValue.bottom);
CEntity *pEnt = &((*mEntityArray)[mCurrentEntity]);
CString KeyName, Value;
m_PropertiesList.GetText (lpdis->itemID, KeyName);
pEnt->GetKeyValue (KeyName, Value);
FillTextBuffer (lpdis->hDC, KeyText, KeyName, maxTextWidth);
FillTextBuffer (lpdis->hDC, ValueText, Value, maxTextWidth);
COLORREF OldBkColor;
COLORREF OldTextColor;
// draw the text
if (lpdis->itemState & ODS_SELECTED)
{
// need to do inverted text...
OldTextColor = ::SetTextColor (lpdis->hDC, GetSysColor (COLOR_HIGHLIGHTTEXT));
OldBkColor = ::SetBkColor (lpdis->hDC, GetSysColor (COLOR_HIGHLIGHT));
}
else
{
OldTextColor = ::SetTextColor (lpdis->hDC, GetSysColor (COLOR_WINDOWTEXT));
OldBkColor = ::SetBkColor (lpdis->hDC, GetSysColor (COLOR_WINDOW));
}
int fuOptions = (ETO_CLIPPED | ETO_OPAQUE);
::ExtTextOut (lpdis->hDC, leftX, lpdis->rcItem.top+1, fuOptions, &rectKey, KeyText, strlen (KeyText), NULL);
::ExtTextOut (lpdis->hDC, rightX, lpdis->rcItem.top+1, fuOptions, &rectValue, ValueText, strlen(ValueText), NULL);
::SetTextColor (lpdis->hDC, OldTextColor);
::SetBkColor (lpdis->hDC, OldBkColor);
// and the rectangles
HBRUSH OldBrush = (HBRUSH)(::SelectObject (lpdis->hDC, GetStockObject (NULL_BRUSH)));
::Rectangle (lpdis->hDC, lpdis->rcItem.left, lpdis->rcItem.top, lpdis->rcItem.right, lpdis->rcItem.bottom);
::Rectangle (lpdis->hDC, lpdis->rcItem.left, lpdis->rcItem.top, lpdis->rcItem.left+halfWidth, lpdis->rcItem.bottom);
::SelectObject (lpdis->hDC, OldBrush);
}
/* EOF: EntitiesDialog.cpp */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -