📄 templatesdlg.cpp
字号:
/****************************************************************************************/
/* TemplatesDlg.cpp */
/* */
/* Author: Tom Morris */
/* Description: Template selection */
/* */
/* 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 "genedit.h"
#include "TemplatesDlg.h"
#include "FilePath.h"
//#include "SkyDialog.h" // commented out post 0.5 release
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CTemplatesDlg dialog
CTemplatesDlg::CTemplatesDlg(CWnd* pParent /*=NULL*/)
: CDialog(CTemplatesDlg::IDD, pParent)
{
//{{AFX_DATA_INIT(CTemplatesDlg)
//}}AFX_DATA_INIT
}
void CTemplatesDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CTemplatesDlg)
DDX_Control(pDX, IDC_TEMPLATE_APPLY, m_templateApplyBtn);
DDX_Control(pDX, IDC_SKYBUTTON, m_skyBtn);
DDX_Control(pDX, IDC_ENTITY_BTN, m_entitiesButton);
DDX_Control(pDX, IDC_ENTITIES_COMBO, m_entitiesCombo);
DDX_Control(pDX, IDC_CURRENT_PREFAB, m_currentPrefabName);
DDX_Control(pDX, IDC_PREFAB_LIST, m_prefabList);
DDX_Control(pDX, IDC_BUTTON_SPHERE, m_sphere_template_btn);
DDX_Control(pDX, IDC_BUTTON_CUBE, m_cube_template_btn);
DDX_Control(pDX, IDC_BUTTON_CYLINDER, m_cylinder_template_btn);
DDX_Control(pDX, IDC_BUTTON_STAIRS, m_stairs_template_btn);
DDX_Control(pDX, IDC_BUTTON_CONE, m_cone_template_btn);
DDX_Control(pDX, IDC_BUTTON_ARCH, m_arch_template_btn);
DDX_Control(pDX, IDC_PREFAB_BTN, m_prefabButton);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CTemplatesDlg, CDialog)
//{{AFX_MSG_MAP(CTemplatesDlg)
ON_BN_CLICKED(IDC_BUTTON_SPHERE, OnButtonSphere)
ON_BN_CLICKED(IDC_BUTTON_CUBE, OnButtonCube)
ON_BN_CLICKED(IDC_BUTTON_CYLINDER, OnButtonCylinder)
ON_BN_CLICKED(IDC_BUTTON_STAIRS, OnButtonStairs)
ON_BN_CLICKED(IDC_BUTTON_CONE, OnButtonCone)
ON_BN_CLICKED(IDC_BUTTON_ARCH, OnButtonArch)
ON_LBN_SELCHANGE(IDC_PREFAB_LIST, OnSelchangePrefabList)
ON_BN_CLICKED(IDC_PREFAB_BTN, OnPrefabBtn)
ON_BN_CLICKED(IDC_ENTITY_BTN, OnEntityBtn)
ON_CBN_SELCHANGE(IDC_ENTITIES_COMBO, OnSelchangeEntitiesCombo)
ON_BN_CLICKED(IDC_SKYBUTTON, OnSkybutton)
ON_LBN_DBLCLK(IDC_PREFAB_LIST, OnDblclkPrefabList)
ON_BN_CLICKED(IDC_TEMPLATE_APPLY, OnTemplateApply)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CTemplatesDlg message handlers
BOOL CTemplatesDlg::OnInitDialog()
{
// setup some constants for spacing our owner-draw buttons
const int Xleft = 0;
const int Xright = 40;
const int Ybutton_height = 40;
const int Ybutton_space = 1;
// position this dialog box on the command panel tab
CGlobals::PositionDialogUnderTabs(this);
// MessageBox("TemplateDlg Initializing");
CRect Button1Rect, Button2Rect, Button3Rect, Button4Rect, Button5Rect, Button6Rect,
CubeRect, SphereRect, CylRect, StairRect, ConeRect, ArchRect;
// setup generic rect locations
Button1Rect.SetRect(Xleft,Ybutton_height,Xright,2*Ybutton_height);
Button2Rect.SetRect(Xleft, Button1Rect.bottom+Ybutton_space, Xright, Button1Rect.bottom+Ybutton_space+Ybutton_height);
Button3Rect.SetRect(Xleft, Button2Rect.bottom+Ybutton_space, Xright, Button2Rect.bottom+Ybutton_space+Ybutton_height);
Button4Rect.SetRect(Xleft, Button3Rect.bottom+Ybutton_space, Xright, Button3Rect.bottom+Ybutton_space+Ybutton_height);
Button5Rect.SetRect(Xleft, Button4Rect.bottom+Ybutton_space, Xright, Button4Rect.bottom+Ybutton_space+Ybutton_height);
Button6Rect.SetRect(Xleft, Button5Rect.bottom+Ybutton_space, Xright, Button5Rect.bottom+Ybutton_space+Ybutton_height);
// assign button order as desired
CubeRect = Button1Rect;
SphereRect = Button2Rect;
CylRect = Button3Rect;
StairRect = Button4Rect;
ConeRect = Button5Rect;
ArchRect = Button6Rect;
// create our owner-draw buttons and put them where we want
m_cube_template_btn.Create(_T(""),WS_CHILD | WS_VISIBLE | BS_ICON, CubeRect, this, IDC_BUTTON_CUBE);
m_cube_template_btn.SetIcon(AfxGetApp()->LoadIcon(IDI_CUBE_ICON));
m_sphere_template_btn.Create(_T(""),WS_CHILD | WS_VISIBLE | BS_ICON, SphereRect, this, IDC_BUTTON_SPHERE);
m_sphere_template_btn.SetIcon(AfxGetApp()->LoadIcon(IDI_SPHERE_ICON));
m_cylinder_template_btn.Create(_T(""), WS_CHILD | WS_VISIBLE | BS_ICON, CylRect, this, IDC_BUTTON_CYLINDER);
m_cylinder_template_btn.SetIcon(AfxGetApp()->LoadIcon(IDI_CYLINDER_ICON));
m_stairs_template_btn.Create(_T(""), WS_CHILD | WS_VISIBLE | BS_ICON, StairRect, this, IDC_BUTTON_STAIRS);
m_stairs_template_btn.SetIcon(AfxGetApp()->LoadIcon(IDI_STAIRS_ICON));
m_cone_template_btn.Create(_T(""), WS_CHILD |WS_VISIBLE | BS_ICON, ConeRect, this, IDC_BUTTON_CONE);
m_cone_template_btn.SetIcon(AfxGetApp()->LoadIcon(IDI_CONE_ICON));
m_arch_template_btn.Create(_T(""), WS_CHILD |WS_VISIBLE | BS_ICON, ArchRect, this, IDC_BUTTON_ARCH);
m_arch_template_btn.SetIcon(AfxGetApp()->LoadIcon(IDI_ARCH_ICON));
m_bEntitiesInitialized = false;
m_bPrefabsInitialized = false;
CDialog::OnInitDialog();
return TRUE; // return TRUE unless you set the focus to a control
// EXCEPTION: OCX Property Pages should return FALSE
}
bool CTemplatesDlg::InitializeEntitiesCombo(CGenEditDoc* pDoc)
{
m_entitiesCombo.ResetContent();
// here we need to add the entity types from the CDialog info to the combo box...
EntityTypeList *pList = EntityTable_GetAvailableEntityTypes (Level_GetEntityDefs (pDoc->pLevel));
if (pList != NULL)
{
for (int i = 0; i < pList->nTypes; i++)
{
if( strcmp( pList->TypeNames[i], "Camera" ) ) // Exclude Camera entity
m_entitiesCombo.AddString(pList->TypeNames[i]);
}
EntityTable_ReleaseEntityTypes (pList);
}
if (m_iCurrentEntity >0)
m_entitiesCombo.SetCurSel(m_iCurrentEntity);
else
m_entitiesCombo.SetCurSel(0);
m_bEntitiesInitialized = true;
return true;
}
bool CTemplatesDlg::InitializePrefabList(CGenEditDoc* pDoc)
{
char ObjectsDir[MAX_PATH];
const char *pObjDir;
CString strObjectsDir;
BOOL FileWasFound;
char Name[MAX_PATH];
WIN32_FIND_DATA FindData;
HANDLE FindHandle;
const Prefs *pPrefs = pDoc->GetPrefs();
// get Objects directory from INI
pObjDir = Prefs_GetObjectsDir (pPrefs);
::FilePath_AppendName (pObjDir, "*.3dt", ObjectsDir);
m_prefabList.ResetContent();
FindHandle = ::FindFirstFile (ObjectsDir, &FindData);
FileWasFound = (FindHandle != INVALID_HANDLE_VALUE);
while (FileWasFound)
{
::FilePath_GetName (FindData.cFileName, Name);
m_prefabList.AddString (Name);
FileWasFound = ::FindNextFile (FindHandle, &FindData);
}
::FindClose (FindHandle);
// keep the previously-selected item after this Update()
if (m_iCurrentPrefab > 0)
m_prefabList.SetCurSel (m_iCurrentPrefab);
else
if (m_prefabList.SetCurSel (0) == CB_ERR)
{
// couldn't set it...probably nothing in there
// EnablePlaceObjectButton (FALSE);
}
m_bPrefabsInitialized = true;
return true;
}
bool CTemplatesDlg::UpdateTemplates( CGenEditDoc* pDoc )
{
m_pDoc = pDoc;
// if (!m_bEntitiesInitialized)
// {
if (!InitializeEntitiesCombo(pDoc))
{
AfxMessageBox("Update Failed to initialize Entities Combo");
}
// }
if (!m_bPrefabsInitialized)
{
if (!InitializePrefabList(pDoc))
{
AfxMessageBox("Update Failed to initialize Prefab list");
}
}
if(m_pDoc->mModeTool==ID_TOOLS_TEMPLATE)
{
//enable all
m_cube_template_btn.EnableWindow(TRUE);
m_sphere_template_btn.EnableWindow(TRUE);
m_cylinder_template_btn.EnableWindow(TRUE);
m_stairs_template_btn.EnableWindow(TRUE);
m_arch_template_btn.EnableWindow(TRUE);
m_cone_template_btn.EnableWindow(TRUE);
m_prefabButton.EnableWindow(TRUE);
m_prefabList.EnableWindow(TRUE);
m_currentPrefabName.EnableWindow(TRUE);
m_entitiesButton.EnableWindow (TRUE);
m_entitiesCombo.EnableWindow(TRUE);
m_templateApplyBtn.EnableWindow(TRUE);
m_skyBtn.EnableWindow(TRUE);
// enable the object placement button
// EnablePlaceObjectButton( TRUE );
}
else
{
//grey all
m_cube_template_btn.EnableWindow(FALSE);
m_sphere_template_btn.EnableWindow(FALSE);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -