⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 groupsdlg.cpp

📁 3D游戏场景编辑器
💻 CPP
📖 第 1 页 / 共 2 页
字号:
/****************************************************************************************/
/*  GroupsDlg.cpp																		*/
/*                                                                                      */
/*  Author:       Tom Morris															*/
/*  Description:  Group Control															*/
/*                                                                                      */
/*  The contents of this file are subject to the Genesis3D Public License               */
/*  Version 1.01 (the "License"); you may not use this file except in                   */
/*  compliance with the License. You may obtain a copy of the License at                */
/*  http://www.genesis3d.com                                                            */
/*                                                                                      */
/*  Software distributed under the License is distributed on an "AS IS"                 */
/*  basis, WITHOUT WARRANTY OF ANY KIND, either express or implied.  See                */
/*  the License for the specific language governing rights and limitations              */
/*  under the License.                                                                  */
/*                                                                                      */
/*  The Original Code is Genesis3D, released March 25, 1999.                            */
/*	Genesis3D Version 1.1 released November 15, 1999				                    */
/*  Copyright (C) 1999 WildTangent, Inc. All Rights Reserved							*/
/*                                                                                      */
/*  Modified by Tom Morris for GenEdit-Classic ver. 0.58, April 23, 2001				*/
/****************************************************************************************/


#include "stdafx.h"

#include "genedit.h"
#include "GroupsDlg.h"
#include "Globals.h"
#include "keyeditdlg.h"
#include "assert.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

/////////////////////////////////////////////////////////////////////////////
// CGroupsDlg dialog


CGroupsDlg::CGroupsDlg(CWnd* pParent /*=NULL*/)
	: CDialog(CGroupsDlg::IDD, pParent)
{
	//{{AFX_DATA_INIT(CGroupsDlg)
		// NOTE: the ClassWizard will add member initialization here
	//}}AFX_DATA_INIT
}


void CGroupsDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CGroupsDlg)
	DDX_Control(pDX, IDC_DESELECTBRUSHES, m_bDeselctBrushesBtn);
	DDX_Control(pDX, IDC_GROUPCOMBO, m_cGroupCombo);
	DDX_Control(pDX, IDC_SELECTBRUSHES, m_bSelectAllBrushesBtn);
	DDX_Control(pDX, IDC_REMOVEGROUP, m_bRemoveGroupBtn);
	DDX_Control(pDX, IDC_CREATENEWGROUP, m_bCreateNewGroupBtn);
	DDX_Control(pDX, IDC_REMOVEFROMCURRENT, m_bRemoveFromCurrentBtn);
	DDX_Control(pDX, IDC_ADDTOCURRENT, m_bAddtoCurrentBtn);
	DDX_Control(pDX, IDC_BRUSHLOCK, m_BrushLock);
	DDX_Control(pDX, IDC_VISIBLE, m_Visible);
	DDX_Control(pDX, IDC_BRUSHLIST, m_BrushList);
	DDX_Control(pDX, IDC_COLOURBUTTON, m_ColorButton);
	//}}AFX_DATA_MAP
}


BEGIN_MESSAGE_MAP(CGroupsDlg, CDialog)
	//{{AFX_MSG_MAP(CGroupsDlg)
	ON_BN_CLICKED(IDC_SELECTBRUSHES, OnSelectbrushes)
	ON_BN_CLICKED(IDC_DESELECTBRUSHES, OnDeselectbrushes)
	ON_BN_CLICKED(IDC_CREATENEWGROUP, OnCreateNewGroup)
	ON_BN_CLICKED(IDC_ADDTOCURRENT, OnAddToCurrent)
	ON_CBN_SELCHANGE(IDC_GROUPCOMBO, OnSelChangeGroupCombo)
	ON_BN_CLICKED(IDC_VISIBLE, OnVisible)
	ON_BN_CLICKED(IDC_REMOVEFROMCURRENT, OnRemovefromcurrent)
	ON_BN_CLICKED(IDC_BRUSHLOCK, OnBrushlock)
	ON_LBN_SELCHANGE(IDC_BRUSHLIST, OnSelchangeBrushlist)
	ON_BN_CLICKED(IDC_REMOVEGROUP, OnRemovegroup)
	ON_MESSAGE(CPN_SELCHANGE, OnChangeColor)		// g3dc using CColorButton
	ON_WM_PAINT()
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CGroupsDlg message handlers

BOOL CGroupsDlg::OnInitDialog() 
{
	
	CGlobals::PositionDialogUnderTabs(this);

	m_ColorButton.TrackSelection = TRUE;

	CDialog::OnInitDialog();
	

	return TRUE;  // return TRUE unless you set the focus to a control
	              // EXCEPTION: OCX Property Pages should return FALSE
}


bool	CGroupsDlg::SetupGroupDialog(CGenEditDoc *pDoc)
{
	BOOL	bEnableWindow ;
	
//	CButton * pBut = (CButton*)GetDlgItem( IDC_ADDTOCURRENT ) ;
	bEnableWindow = ( pDoc->mCurrentGroup == 0 ) ? FALSE : TRUE ;
//	pBut->EnableWindow( bEnableWindow ) ;
	m_bAddtoCurrentBtn.EnableWindow(bEnableWindow);

	if (pDoc != NULL)
	{
		GroupListType *Groups = Level_GetGroups (pDoc->pLevel);
		if( Groups )
		{
			if( Group_GetCount( Groups ) )
			{					//	fill the combo on the group control bar
				pDoc->FillBrushGroupCombo( pDoc->mpMainFrame->m_wndGroupBar.m_comboBox ) ;
								//	fill the combo on this dialog
				pDoc->FillBrushGroupCombo(m_cGroupCombo);
			}
		}
	}
	return true;
}



typedef struct
{
	CListBox	*BrushListbox;
	CGenEditDoc *pDoc;
	geBoolean	ItemsInLB;
} lbAddData;



static geBoolean ListboxAddBrushes (Brush *pBrush, void *lParam)
{
	lbAddData	*pData;
	char		szTempString[32];
	int			Index;

//	pData->pDoc = CGlobals::GetActiveDocument();

	pData = (lbAddData *)lParam;

	if (Brush_GetGroupId (pBrush) == pData->pDoc->mCurrentGroup)
	{
		sprintf( szTempString, "(B) %s", Brush_GetName( pBrush ) ) ;
		Index = pData->BrushListbox->AddString( szTempString ) ;
		pData->ItemsInLB = GE_TRUE;
		if( Index >= 0 ) /* LB_ERR is -1, LB_ERRSPACE  is -2 */
		{
			pData->BrushListbox->SetItemData( Index, (DWORD)pBrush ) ;
			if( pData->pDoc->BrushIsSelected( pBrush ) )
			{
				pData->BrushListbox->SetSel( Index, TRUE );
			}
		}
	}
	return GE_TRUE;
}



static geBoolean ListboxAddEntities (CEntity &Ent, void *lParam)
{
	lbAddData *pData = (lbAddData *)lParam;


	if (Ent.GetGroupId () == pData->pDoc->mCurrentGroup)
	{
		char	szTempString[32];
		int Index;

		sprintf( szTempString, "(E) %s", Ent.GetName() ) ;

		Index = pData->BrushListbox->AddString (szTempString);
		pData->ItemsInLB = GE_TRUE;

		if( Index >= 0 )	/* LB_ERR is -1, LB_ERRSPACE  is -2 */
		{
			pData->BrushListbox->SetItemData( Index, (DWORD)&Ent ) ;
			if( Ent.IsSelected() )
			{
				pData->BrushListbox->SetSel( Index, TRUE );
			}
		}
	}
	return GE_TRUE;
}

bool CGroupsDlg::UpdateGroups(CGenEditDoc* NewDoc)
{
	BOOL			bItemsInLB = TRUE ;
	GroupListType	*Groups;
	lbAddData		CallbackData;

	CGenEditDoc	*	pDoc	=NewDoc;
	Groups = Level_GetGroups (pDoc->pLevel);



	if ((pDoc->mModeTool == ID_GENERALSELECT) && (pDoc->mAdjustMode == ADJUST_MODE_FACE))
	{
		m_BrushList.EnableWindow(FALSE);
		return true;
	}
	else
	{
		m_BrushList.EnableWindow(TRUE);
	}

	if( Group_GetCount( Groups ) == 0 )	// Hack for while doc's are switching without built groups
		return false;

	BOOL	bEnableWindow ;
	
	bEnableWindow = ( pDoc->mCurrentGroup == 0 ) ? FALSE : TRUE ;
	m_bAddtoCurrentBtn.EnableWindow(bEnableWindow);


	m_Visible.EnableWindow(1);
	m_bSelectAllBrushesBtn.EnableWindow(TRUE);	// new g3dc
	m_bDeselctBrushesBtn.EnableWindow(TRUE);	//	new g3dc

	if(pDoc->mCurrentGroup)
	{
		m_bRemoveGroupBtn.EnableWindow(TRUE);	//	new g3dc
		m_ColorButton.EnableWindow(TRUE);
	}
	else
	{
		m_BrushLock.EnableWindow(FALSE);
		m_bRemoveGroupBtn.EnableWindow(FALSE);
	}

	// fill in name
//	char const *Name = Group_GetNameFromId (Groups, pDoc->mCurrentGroup);

	if(Group_IsVisible (Groups, pDoc->mCurrentGroup))
	{
		m_Visible.SetCheck (1);
	}
	else
	{
		m_Visible.SetCheck (0);
	}

	if(Group_IsLocked (Groups, pDoc->mCurrentGroup))
	{
		m_BrushLock.SetCheck (1);
	}
	else
	{
		m_BrushLock.SetCheck (0);
	}

				//	fill brush list box with names of current brushes and entities
	m_BrushList.ResetContent();

	CallbackData.BrushListbox = &m_BrushList;
	CallbackData.pDoc = pDoc;
	CallbackData.ItemsInLB = GE_FALSE;

	Level_EnumBrushes (pDoc->pLevel, &CallbackData, ::ListboxAddBrushes);
	Level_EnumEntities (pDoc->pLevel, &CallbackData, ::ListboxAddEntities);

				//	put the topmost selection at the top of the list box
	int	tempIndex;
	m_BrushList.GetSelItems(1, &tempIndex);
	if (tempIndex != -1)
	{
		m_BrushList.SetTopIndex(tempIndex);
	}
	
	LoadComboBox() ;

	if( pDoc->mCurrentGroup == 0 )
		bItemsInLB = FALSE ;	// Never let them remove from the default group

	m_bAddtoCurrentBtn.EnableWindow(TRUE);	// new g3dc
	m_bRemoveFromCurrentBtn.EnableWindow(bItemsInLB);	// new g3dc

	UpdateGroupSelection();

			//	Restore focus to active view
	CMDIChildWnd *pMDIChild	=(CMDIChildWnd *)pDoc->mpMainFrame->MDIGetActive();
	if(pMDIChild)
	{
		CView	*cv	=(CView *)pMDIChild->GetActiveView();
		if( cv)
			cv->SetFocus();
	}




	return true;
}


// fill the combo box with the list of groups and ids
void CGroupsDlg::LoadComboBox(void)
{
//	CComboBox		*GCombo	=(CComboBox *)GetDlgItem(IDC_GROUPCOMBO);
	COLORREF		Color ;
	const GE_RGBA * pGeColor ;
	CGenEditDoc	*pDoc = CGlobals::GetActiveDocument();

	GroupListType	*Groups = Level_GetGroups (pDoc->pLevel);

	assert(m_cGroupCombo);
	assert(pDoc->mpMainFrame->m_wndGroupBar.m_comboBox);
									//	this doesn't seem to be working
//	GroupList_FillCombobox (Groups, &m_cGroupCombo, pDoc->mCurrentGroup);
//	GroupList_FillCombobox(Groups, &pDoc->mpMainFrame->m_wndGroupBar.m_comboBox, pDoc->mCurrentGroup);
	
	pDoc->FillBrushGroupCombo( pDoc->mpMainFrame->m_wndGroupBar.m_comboBox ) ;
	pDoc->FillBrushGroupCombo(m_cGroupCombo);


	pGeColor = Group_GetColor( Groups, pDoc->mCurrentGroup ) ;
	Color = RGB( pGeColor->r, pGeColor->g, pGeColor->b ) ;
//		Color = RGB( 255, 255, 255 ) ;

	m_ColorButton.SetColor( Color ) ;

}/* CGroupsDlg::LoadComboBox */


void CGroupsDlg::OnOK() 
{
	CGenEditDoc	*pDoc = CGlobals::GetActiveDocument();


	GroupListType *Groups = Level_GetGroups (pDoc->pLevel);
	BrushList *BList = Level_GetBrushes (pDoc->pLevel);
	CEntityArray *Entities = Level_GetEntities (pDoc->pLevel);

	// Set visible and lock state on all group brushes/entities
	if (m_Visible.GetCheck ())
	{
		Group_Show (Groups, pDoc->mCurrentGroup, BList, Entities);
	}
	else
	{
		Group_Hide (Groups, pDoc->mCurrentGroup, BList, Entities);
	}

	if (m_BrushLock.GetCheck ())
	{
		Group_Lock (Groups, pDoc->mCurrentGroup, BList, Entities);
	}
	else
	{
		Group_Unlock (Groups, pDoc->mCurrentGroup, BList, Entities);
	}
	//	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);

	if (this->IsWindowVisible())	//	post 0.57
	{

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -