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

📄 createcyldialog.cpp

📁 3D游戏场景编辑器
💻 CPP
📖 第 1 页 / 共 2 页
字号:
/****************************************************************************************/
/*  CreateCylDialog.cpp                                                                 */
/*                                                                                      */
/*  Author:       Jim Mischel, Ken Baird, John Moore                                    */
/*  Description:  Dialog code for templates                                             */
/*                                                                                      */
/*  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.57, Feb. 3, 2001					*/
/****************************************************************************************/
#include "stdafx.h"
#include "Globals.h"
#include "CreateCylDialog.h"
#include <math.h>
#include "units.h"

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

CCreateCylDialog::CCreateCylDialog(CWnd* pParent /*=NULL*/)
	: CDialog(CCreateCylDialog::IDD, pParent)
{
	//{{AFX_DATA_INIT(CCreateCylDialog)
	m_BotXOffset = 0.0;			//	must match defaults in BrushTemplate.c
	m_BotXSize = 128.0;
	m_BotZOffset = 0.0;
	m_BotZSize = 128.0;
	m_Solid = 1;				//	0=solid  1=hollow
	m_TopXOffset = 0.0;
	m_TopXSize = 128.0;
	m_TopZOffset = 0.0;
	m_TopZSize = 128.0;
	m_YSize = 512.0;
	m_RingLength = 3.0;
	m_TCut = FALSE;
	m_VerticalStripes = 8;
	m_Thickness = 16.0f;
	m_customizeCylBtn = FALSE;
	//}}AFX_DATA_INIT
	m_minMaxErrorString.Format("Value must be between %d and %d",
		BRUSH_MIN, BRUSH_MAX);
	m_wallThicknessErrorString.Format("Value must be between %d and %d", 
		WALL_THICK_MIN, WALL_THICK_MAX);

	pCyl = NULL;
	m_recentCyl = NULL;

}


void CCreateCylDialog::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CCreateCylDialog)
	DDX_Control(pDX, IDC_APPLY_CYL_BTN, m_applyCylBTN);
	DDX_Text(pDX, IDC_BOTXOFF, m_BotXOffset);
	DDX_Text(pDX, IDC_BOTXSIZE, m_BotXSize);
	DDX_Text(pDX, IDC_BOTZOFF, m_BotZOffset);
	DDX_Text(pDX, IDC_BOTZSIZE, m_BotZSize);
	DDX_Radio(pDX, IDC_SOLID, m_Solid);
	DDX_Text(pDX, IDC_TOPXOFF, m_TopXOffset);
	DDX_Text(pDX, IDC_TOPXSIZE, m_TopXSize);
	DDX_Text(pDX, IDC_TOPZOFF, m_TopZOffset);
	DDX_Text(pDX, IDC_TOPZSIZE, m_TopZSize);
	DDX_Text(pDX, IDC_YSIZE, m_YSize);
	DDX_Text(pDX, IDC_RINGLENGTH, m_RingLength);
	DDX_Check(pDX, IDC_TCUT, m_TCut);
	DDX_Text(pDX, IDC_VERTSTRIPES, m_VerticalStripes);
	DDX_Text(pDX, IDC_THICKNESS, m_Thickness);
	DDX_Check(pDX, IDC_CUSTOMIZE_CYL_BTN, m_customizeCylBtn);
	//}}AFX_DATA_MAP
}


BEGIN_MESSAGE_MAP(CCreateCylDialog, CDialog)
	//{{AFX_MSG_MAP(CCreateCylDialog)
	ON_BN_CLICKED(IDC_Defaults, OnDefaults)
	ON_BN_CLICKED(IDC_CUSTOMIZE_CYL_BTN, OnCustomizeCylBtn)
	ON_BN_CLICKED(IDC_APPLY_CYL_BTN, OnApplyCylBtn)
	ON_EN_KILLFOCUS(IDC_TOPXSIZE, OnKillfocusTopxsize)
	ON_EN_KILLFOCUS(IDC_TOPXOFF, OnKillfocusTopxoff)
	ON_EN_KILLFOCUS(IDC_TOPZSIZE, OnKillfocusTopzsize)
	ON_EN_KILLFOCUS(IDC_TOPZOFF, OnKillfocusTopzoff)
	ON_EN_KILLFOCUS(IDC_BOTXSIZE, OnKillfocusBotxsize)
	ON_EN_KILLFOCUS(IDC_BOTXOFF, OnKillfocusBotxoff)
	ON_EN_KILLFOCUS(IDC_BOTZSIZE, OnKillfocusBotzsize)
	ON_EN_KILLFOCUS(IDC_BOTZOFF, OnKillfocusBotzoff)
	ON_EN_KILLFOCUS(IDC_YSIZE, OnKillfocusYsize)
	ON_EN_KILLFOCUS(IDC_VERTSTRIPES, OnKillfocusVertstripes)
	ON_EN_KILLFOCUS(IDC_THICKNESS, OnKillfocusThickness)
	ON_EN_KILLFOCUS(IDC_RINGLENGTH, OnKillfocusRinglength)
	ON_BN_CLICKED(IDC_SOLID, OnSolid)
	ON_BN_CLICKED(IDC_HOLLOW, OnHollow)
	ON_BN_CLICKED(IDC_RING, OnRing)
	ON_BN_CLICKED(IDC_TCUT, OnTcut)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/*	// old gedit
int	CCreateCylDialog::DoModal(geBoolean ConvertToMetric, BrushTemplate_Cylinder *pCylTemplate)
{
	m_ConvertToMetric	=ConvertToMetric;
	m_pCylTemplate = pCylTemplate;

	m_BotXOffset	= m_pCylTemplate->BotXOffset;
	m_BotXSize		= m_pCylTemplate->BotXSize;
	m_BotZOffset	= m_pCylTemplate->BotZOffset;
	m_BotZSize		= m_pCylTemplate->BotZSize;
	m_Solid			= m_pCylTemplate->Solid;
	m_Thickness		= m_pCylTemplate->Thickness;
	m_TopXOffset	= m_pCylTemplate->TopXOffset;
	m_TopXSize		= m_pCylTemplate->TopXSize;
	m_TopZOffset	= m_pCylTemplate->TopZOffset;
	m_TopZSize		= m_pCylTemplate->TopZSize;
	m_VerticalStripes	= m_pCylTemplate->VerticalStripes;
	m_YSize			= m_pCylTemplate->YSize;
	m_RingLength	= m_pCylTemplate->RingLength;
	m_TCut			= m_pCylTemplate->TCut;

	if(m_ConvertToMetric)
	{
		dlgFieldsToCentimeters();
	}

	return CDialog::DoModal();
}

*/

// new g3dc
void CCreateCylDialog::ShowDialog(geBoolean ConvertToMetric, BrushTemplate_Cylinder *pCylTemplate, CGenEditDoc *pDoc)
{
	m_ConvertToMetric	=ConvertToMetric;
	m_pCylTemplate = pCylTemplate;
	m_pDoc = pDoc;

	m_customTemplate = false;

			//	toggle switch so we render our brush and NOT the Entitiy template box	
	pDoc->TempEnt = FALSE; 

	this->GetDlgItem(IDC_TOPXSIZE)->EnableWindow(FALSE);
	this->GetDlgItem(IDC_TOPXOFF)->EnableWindow(FALSE);
	this->GetDlgItem(IDC_TOPZSIZE)->EnableWindow(FALSE);
	this->GetDlgItem(IDC_TOPZOFF)->EnableWindow(FALSE);
	this->GetDlgItem(IDC_BOTXSIZE)->EnableWindow(FALSE);
	this->GetDlgItem(IDC_BOTXOFF)->EnableWindow(FALSE);
	this->GetDlgItem(IDC_BOTZSIZE)->EnableWindow(FALSE);
	this->GetDlgItem(IDC_BOTZOFF)->EnableWindow(FALSE);
	this->GetDlgItem(IDC_YSIZE)->EnableWindow(FALSE);
	this->GetDlgItem(IDC_VERTSTRIPES)->EnableWindow(FALSE);
	this->GetDlgItem(IDC_THICKNESS)->EnableWindow(FALSE);
	this->GetDlgItem(IDC_RINGLENGTH)->EnableWindow(FALSE);
	this->GetDlgItem(IDC_SOLID)->EnableWindow(FALSE);
	this->GetDlgItem(IDC_HOLLOW)->EnableWindow(FALSE);
	this->GetDlgItem(IDC_RING)->EnableWindow(FALSE);
	this->GetDlgItem(IDC_TCUT)->EnableWindow(FALSE);
	this->GetDlgItem(IDC_Defaults)->EnableWindow(FALSE);

	
	pDoc->mpMainFrame->HideAllPropDialogsBut(this);

	if(m_ConvertToMetric)
	{
		dlgFieldsToCentimeters();
	}

	if (!strcmp(pDoc->m_currentTemplateName, "Cylinder"))
	{
		if (pDoc->CurBrush)
		{
			pCyl = m_pDoc->CurBrush;	
		}
	}

		//	if the current template name is NOT Cylinder, we probly have
		//	come here from another template type.
	else if (strcmp(pDoc->m_currentTemplateName, "Cylinder"))
	{
		//	check to see if there is a previous cylinder brush from the last visit
		if (pDoc->m_recentCyl)	//	post 0.55
		{			//	reset name 'cause sometimes it gets changed
			Brush_SetName((Brush*)pDoc->m_recentCyl, "Cylinder");				
			pDoc->CurBrush = (Brush*)pDoc->m_recentCyl;
				//	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 no modified Cyl brush from the previous visit
		if (!pDoc->m_recentCyl)
		{
			pCyl = BrushTemplate_CreateCylinder(m_pCylTemplate);
			
			if (pCyl != NULL)
			{
				pDoc->CreateNewTemplateBrush ((Brush*)pCyl);
				pDoc->m_recentCyl = Brush_Clone(pCyl);
				Brush_SetName(pDoc->CurBrush, "Cylinder");				
			}	
		}	//post 0.55
	}		

	SetWindowPos(NULL,5,10,0,0,SWP_NOZORDER|SWP_NOSIZE);
	this->ShowWindow(SW_SHOW);

	//	set this now so we can come back later
	pDoc->m_currentTemplateName = "Cylinder";


	UpdateData(TRUE);
}

bool	CCreateCylDialog::UpdateCreateCylDlg(CGenEditDoc *pDoc)
{
	m_pDoc = pDoc;
		//	post 0.55
		//	if the current template name IS Cylinder...
	if (!strcmp(pDoc->m_currentTemplateName, "Cylinder"))
	{
		if ((pDoc->CurBrush != NULL) && !strcmp(Brush_GetName(pDoc->CurBrush), "Cylinder")
									&& pDoc->CurBrush != pDoc->m_recentCyl)
		{
				// update the template brush as a clone of pDoc->CurBrush
			pDoc->m_recentCyl = Brush_Clone(pDoc->CurBrush);
		}
	}
	//	post 0.55	
		
	BrushTemplate_Cylinder *pCylTemplate = Level_GetCylinderTemplate (pDoc->pLevel);
	m_pCylTemplate = pCylTemplate;

	if (!m_customTemplate)
	{
	this->GetDlgItem(IDC_TOPXSIZE)->EnableWindow(FALSE);
	this->GetDlgItem(IDC_TOPXOFF)->EnableWindow(FALSE);
	this->GetDlgItem(IDC_TOPZSIZE)->EnableWindow(FALSE);
	this->GetDlgItem(IDC_TOPZOFF)->EnableWindow(FALSE);
	this->GetDlgItem(IDC_BOTXSIZE)->EnableWindow(FALSE);
	this->GetDlgItem(IDC_BOTXOFF)->EnableWindow(FALSE);
	this->GetDlgItem(IDC_BOTZSIZE)->EnableWindow(FALSE);
	this->GetDlgItem(IDC_BOTZOFF)->EnableWindow(FALSE);
	this->GetDlgItem(IDC_YSIZE)->EnableWindow(FALSE);
	this->GetDlgItem(IDC_VERTSTRIPES)->EnableWindow(FALSE);
	this->GetDlgItem(IDC_THICKNESS)->EnableWindow(FALSE);
	this->GetDlgItem(IDC_RINGLENGTH)->EnableWindow(FALSE);
	this->GetDlgItem(IDC_SOLID)->EnableWindow(FALSE);
	this->GetDlgItem(IDC_HOLLOW)->EnableWindow(FALSE);
	this->GetDlgItem(IDC_RING)->EnableWindow(FALSE);
	this->GetDlgItem(IDC_TCUT)->EnableWindow(FALSE);
	this->GetDlgItem(IDC_Defaults)->EnableWindow(FALSE);

	m_applyCylBTN.EnableWindow(TRUE);
	m_customizeCylBtn = FALSE;

	}

	else
	{
	this->GetDlgItem(IDC_TOPXSIZE)->EnableWindow(TRUE);
	this->GetDlgItem(IDC_TOPXOFF)->EnableWindow(TRUE);
	this->GetDlgItem(IDC_TOPZSIZE)->EnableWindow(TRUE);
	this->GetDlgItem(IDC_TOPZOFF)->EnableWindow(TRUE);
	this->GetDlgItem(IDC_BOTXSIZE)->EnableWindow(TRUE);
	this->GetDlgItem(IDC_BOTXOFF)->EnableWindow(TRUE);
	this->GetDlgItem(IDC_BOTZSIZE)->EnableWindow(TRUE);
	this->GetDlgItem(IDC_BOTZOFF)->EnableWindow(TRUE);
	this->GetDlgItem(IDC_YSIZE)->EnableWindow(TRUE);
	this->GetDlgItem(IDC_VERTSTRIPES)->EnableWindow(TRUE);
	this->GetDlgItem(IDC_THICKNESS)->EnableWindow(TRUE);
	this->GetDlgItem(IDC_RINGLENGTH)->EnableWindow(TRUE);
	this->GetDlgItem(IDC_SOLID)->EnableWindow(TRUE);
	this->GetDlgItem(IDC_HOLLOW)->EnableWindow(TRUE);
	this->GetDlgItem(IDC_RING)->EnableWindow(TRUE);
	this->GetDlgItem(IDC_TCUT)->EnableWindow(TRUE);
	this->GetDlgItem(IDC_Defaults)->EnableWindow(TRUE);

	m_applyCylBTN.EnableWindow(FALSE);
	m_customizeCylBtn = TRUE;

	}

	m_BotXOffset	= m_pCylTemplate->BotXOffset;
	m_BotXSize		= m_pCylTemplate->BotXSize;
	m_BotZOffset	= m_pCylTemplate->BotZOffset;
	m_BotZSize		= m_pCylTemplate->BotZSize;
	m_Solid			= m_pCylTemplate->Solid;
	m_Thickness		= m_pCylTemplate->Thickness;
	m_TopXOffset	= m_pCylTemplate->TopXOffset;
	m_TopXSize		= m_pCylTemplate->TopXSize;
	m_TopZOffset	= m_pCylTemplate->TopZOffset;
	m_TopZSize		= m_pCylTemplate->TopZSize;
	m_VerticalStripes	= m_pCylTemplate->VerticalStripes;
	m_YSize			= m_pCylTemplate->YSize;
	m_RingLength	= m_pCylTemplate->RingLength;
	m_TCut			= m_pCylTemplate->TCut;

	UpdateData(TRUE);


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


	return true;
}

void	CCreateCylDialog::dlgFieldsToTexels(void)
{
	m_BotXOffset	=Units_CentimetersToEngine(m_BotXOffset);
	m_BotXSize		=Units_CentimetersToEngine(m_BotXSize);
	m_BotZOffset	=Units_CentimetersToEngine(m_BotZOffset);
	m_BotZSize		=Units_CentimetersToEngine(m_BotZSize);
	m_Thickness		=Units_CentimetersToEngine(m_Thickness);
	m_TopXOffset	=Units_CentimetersToEngine(m_TopXOffset);
	m_TopXSize		=Units_CentimetersToEngine(m_TopXSize);
	m_TopZOffset	=Units_CentimetersToEngine(m_TopZOffset);
	m_TopZSize		=Units_CentimetersToEngine(m_TopZSize);
	m_YSize			=Units_CentimetersToEngine(m_YSize);
	m_RingLength	=Units_CentimetersToEngine(m_RingLength);
}

void	CCreateCylDialog::dlgFieldsToCentimeters(void)
{
	m_BotXOffset	=Units_FRound(Units_EngineToCentimeters(m_BotXOffset));
	m_BotXSize		=Units_FRound(Units_EngineToCentimeters(m_BotXSize));
	m_BotZOffset	=Units_FRound(Units_EngineToCentimeters(m_BotZOffset));
	m_BotZSize		=Units_FRound(Units_EngineToCentimeters(m_BotZSize));
	m_Thickness		=Units_FRound(Units_EngineToCentimeters(m_Thickness));
	m_TopXOffset	=Units_FRound(Units_EngineToCentimeters(m_TopXOffset));
	m_TopXSize		=Units_FRound(Units_EngineToCentimeters(m_TopXSize));
	m_TopZOffset	=Units_FRound(Units_EngineToCentimeters(m_TopZOffset));
	m_TopZSize		=Units_FRound(Units_EngineToCentimeters(m_TopZSize));
	m_YSize			=Units_FRound(Units_EngineToCentimeters(m_YSize));
	m_RingLength	=Units_FRound(Units_EngineToCentimeters(m_RingLength));
}


void CCreateCylDialog::Serialize(CArchive& ar) 
{
	if (ar.IsStoring())
	{	
		ar << m_BotXOffset;
		ar << m_BotXSize;
		ar << m_BotZOffset;
		ar << m_BotZSize;
		ar << m_Solid;
		ar << m_Thickness;
		ar << m_TopXOffset;
		ar << m_TopXSize;
		ar << m_TopZOffset;
		ar << m_TopZSize;
		ar << m_VerticalStripes;
		ar << m_YSize;
	}
	else
	{	// loading code
		ar >> m_BotXOffset;
		ar >> m_BotXSize;
		ar >> m_BotZOffset;
		ar >> m_BotZSize;
		ar >> m_Solid;
		ar >> m_Thickness;
		ar >> m_TopXOffset;
		ar >> m_TopXSize;
		ar >> m_TopZOffset;
		ar >> m_TopZSize;

⌨️ 快捷键说明

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