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

📄 geneditdoc.cpp

📁 3D游戏场景编辑器
💻 CPP
📖 第 1 页 / 共 5 页
字号:
	}
	// get fully-qualified path name to texture library
	WadPath = Level_GetWadPath (NewLevel);

	if (!Level_LoadWad (NewLevel))
	{
		CString Msg;

		AfxFormatString1 (Msg, IDS_CANTLOADTXL, WadPath);
		AfxMessageBox (Msg);
	}
	Level_EnumLeafBrushes (NewLevel, NewLevel, Level_FaceFixupCallback);

	if (pLevel != NULL)
	{
		Level_Destroy (&pLevel);
	}
	pLevel = NewLevel;

	// Validate data, groups are read after entities and brushes, so this must be last
	if( ValidateEntities( ) == FALSE || ValidateBrushes( ) == FALSE )
	{
//		SelectTab( CONSOLE_TAB ) ;  //old GEdit
//		SelectTab(PROPERTIES_PANEL_CONSOLE);	//	new G3D Classic
		ShowConsole();							//	new g3dc
		
		AfxMessageBox( IDS_LOAD_WARNING ) ;

		if (ValidateEntities( ) == FALSE)	//	post 0.55
			OnLeveloptions();	// open up level options dialog right away

	}

	GroupIterator gi;
	GroupListType *Groups;

	Groups = Level_GetGroups (pLevel);
	mCurrentGroup = Group_GetFirstId (Groups, &gi);
	AddCameraEntityToLevel ();

	{
		Brush *pBox = BrushTemplate_CreateBox (Level_GetBoxTemplate (pLevel));
		if (pBox != NULL)
		{
			CreateNewTemplateBrush (pBox);
		}
	}

	// update entity visibility info
	pEntityView	=Level_GetEntityVisibilityInfo (pLevel);
	for (i = 0; i < pEntityView->nEntries; ++i)
	{
		Level_EnumEntities (pLevel, &pEntityView->pEntries[i], ::fdocSetEntityVisibility);
	}

	return GE_TRUE;
LoadError:
	if (NewLevel != NULL)
	{
		Level_Destroy (&NewLevel);
	}
	AfxMessageBox (Errmsg);
	return GE_FALSE;
}

struct fdocFaceScales
{
	float DrawScale;
	float LightmapScale;
};

static geBoolean fdocSetFaceScales (Face *pFace, void *lParam)
{
	fdocFaceScales *pScales = (fdocFaceScales *)lParam;

	Face_SetTextureScale (pFace, pScales->DrawScale, pScales->DrawScale);
	Face_SetLightScale (pFace, pScales->LightmapScale, pScales->LightmapScale);
	return GE_TRUE;
}


// play a sound from a resource
geBoolean CGenEditDoc::PlayResource (char const * pName) 
{     
	BOOL bRtn;
	char * lpRes; 
	HGLOBAL hRes;
	HRSRC hResInfo;
	HINSTANCE hInst = AfxGetInstanceHandle ();

	// Find the WAVE resource.
    hResInfo = ::FindResource (hInst, pName, "WAVE");
	if (hResInfo == NULL)
	{
        return FALSE;
	}

	// Load the WAVE resource.  
    hRes = ::LoadResource(hInst, hResInfo);     
	if (hRes == NULL)
	{
        return FALSE;
	}

	// Lock the WAVE resource and play it.  
    lpRes = (char *)::LockResource(hRes);     
	if (lpRes != NULL) 
	{
        bRtn = (::sndPlaySound(lpRes, SND_MEMORY | SND_SYNC | SND_NODEFAULT) != 0);
		::UnlockResource(hRes);
	}
	else 
	{
        bRtn = GE_FALSE;
	}

	// Free the WAVE resource and return success or failure. 
    FreeResource (hRes);
	return bRtn; 
}



//	called by AddBrushToWorld
void CGenEditDoc::OnBrushAddtoworld() 
{
	geBoolean Placed;
	
	if(mModeTool!=ID_TOOLS_TEMPLATE)
		return;
	
	Placed = GE_FALSE;
	if(TempEnt)
	{
		// here we check to see if the user is placing prefab templates down
		if ( PlaceObjectFlag )
		{
			geBoolean GotName;
			char ObjectName[MAX_PATH];
			
			// get the current object from the library and place it down
			//	GotName = mpMainFrame->m_wndTabControls->m_pBrushEntityDialog->GetCurrentObjectName (ObjectName);	//	old GEdit
			GotName = mpMainFrame->m_TemplatesTab.GetCurrentTemplateName(ObjectName);	//	new GenEdit-Classic
			if (GotName)
			{
				Placed = PlaceObject (ObjectName, &mRegularEntity.mOrigin);
				PlayResource ("SND_WHOOSH");
				//	Be very careful when speccing flags for UpdateAllViews()
				//	The wrong flags at the wrong time will totally screw things up
				//	g3dc tuning comment
				//	SetMode() has its own UpdateMainControls() 
				//	and ConfigureCurrentTool() calls	
				//UpdateAllViews(UAV_ALL3DVIEWS, NULL);
				
				//	need to SetMode because a DoGeneralSelect() was performed in the
				//	chain above. DoGeneralSelect() sets the mode to ID_GENERALSELECT,
				//	and sets the edit tool to NULL. But we want to continue to
				//	place prefabs. So we call SetMode to bring us back into
				//	ID_TOOLS_TEMPLATE mode and set the move/rotate button. :-)
				//	SetMode() has its own UpdateMainControls() 
				//	and ConfigureCurrentTool() calls	
				SetMode(MAINFRM_COMMANDPANEL_TEMPLATES);	//	new g3dc

//				mpMainFrame->UpdateMainControls();	// new g3dc
			}
		}
	
		else	//	we are placing an entity
		{
		// now create a new entity of the currently-selected type
		//			GotName = mpMainFrame->m_wndTabControls->m_pBrushEntityDialog->GetCurrentEntityName (EntityName); // old gedit
			geBoolean	GotName;
			CEntity		NewEnt;
			char		EntityName[MAX_PATH];
			
			mRegularEntity.DoneMove (1, Level_GetEntityDefs (pLevel));
			
			// now create a new entity of the currently-selected type
			//			GotName = mpMainFrame->m_wndTabControls->m_pBrushEntityDialog->GetCurrentEntityName (EntityName); // old gedit
			GotName = mpMainFrame->m_TemplatesTab.GetCurrentEntityName(EntityName);	// new g3dc
			if (GotName)
			{	
				if (CreateEntityFromName (EntityName, NewEnt))
				{
					geVec3d org;
					org = mRegularEntity.mOrigin;
					// set the new entity's origin
					NewEnt.SetOrigin (org.X, org.Y, org.Z, Level_GetEntityDefs (pLevel));
					// add to current group
					NewEnt.SetGroupId (mCurrentGroup);
					Level_AddEntity (pLevel, NewEnt);
					Placed = GE_TRUE;
					PlayResource ("SND_WHOOSH");
					//	Be very careful when speccing flags for UpdateAllViews()
					//	The wrong flags at the wrong time will totally screw things up
					UpdateAllViews(UAV_ALL3DVIEWS, NULL);
					
					mpMainFrame->UpdateMainControls();	// new g3dc
					
				}
			}
		}
	}
	else	// if it's a brush and not an entity or prefab
	{
		Brush	*nb;
		geVec3d *pTemplatePos;
		
		nb	=Brush_Clone(CurBrush);
		
		SetDefaultBrushTexInfo(nb);
		Brush_Bound (nb);
		pTemplatePos = Level_GetTemplatePos (pLevel);
		Brush_Center (nb, pTemplatePos);
		// add to current group
		Brush_SetGroupId (nb, mCurrentGroup);
		
		{
			// set draw scale and lightmap scale defaults for all faces
			fdocFaceScales Scales;
			
			Scales.DrawScale = Level_GetDrawScale (pLevel);
			Scales.LightmapScale = Level_GetLightmapScale (pLevel);
			Brush_EnumFaces (nb, &Scales, ::fdocSetFaceScales);
			
		}
		
		Level_AppendBrush (pLevel, nb);
		
		PlayResource ("SND_WHOOSH");
		if(!Brush_IsHollow(nb) && !Brush_IsMulti(nb))
		{
			mWorldBsp	=Node_AddBrushToTree(mWorldBsp, nb);
			//	Be very careful when speccing flags for UpdateAllViews()
			//	The wrong flags at the wrong time will totally screw things up
			UpdateAllViews(UAV_ALL3DVIEWS, NULL);
		}
		else
		{
			//	Be very careful when speccing flags for UpdateAllViews()
			//	The wrong flags at the wrong time will totally screw things up
			UpdateAllViews(UAV_ALL3DVIEWS | REBUILD_QUICK, NULL, TRUE);
		}
		
		mpMainFrame->UpdateMainControls();	// new g3dc
		
		Placed = GE_TRUE;
	}

	//	post 0.57
	//	this cluster of code fixes a problem that occurs when placing prefabs that contain
	//	entities. The problem is that the origin values for the included entities are not
	//	set, and when the user later selects the prefab or just the entity, the entitiy
	//	moves to 0,0,0 -- level center.
	//	This code surveys the level for all entities --including those that have accompanied
	//	recently-added prefabs. It gets each entity's origin values (from the entities
	//	themselves,then sets their origins based on their internal origin values.
	geVec3d			org;
	CEntityArray	*Entities;
	Entities = Level_GetEntities (pLevel);
	for( int Ent = 0; Ent < Entities->GetSize(); Ent++ )
	{
		org = (*Entities)[ Ent ].mOrigin;
		((*Entities)[ Ent ].SetOrigin(org.X, org.Y, org.Z, Level_GetEntityDefs (pLevel)));
	}			


	if (Placed)
	{
		SetModifiedFlag();
	}

}

// This code is STILL called from the toolbar button, but the "correct"
// interface is now on the Brush Attributes Dialog
void CGenEditDoc::OnBrushSubtractfromworld() 
{
	Brush	*nb;
	BrushList *BList = Level_GetBrushes (pLevel);

	if ((mModeTool==ID_GENERALSELECT) && (BrushList_Count (BList, BRUSH_COUNT_MULTI | BRUSH_COUNT_LEAF) < 2))
	{
		// cuts shouldn't start the list
		return;
	}

	SetModifiedFlag();

	if(mModeTool==ID_GENERALSELECT)
	{
		// put the brush at the very end of the list
		BrushList_Remove (BList, CurBrush);
		Brush_SetSubtract(CurBrush, GE_TRUE);

		SelBrushList_RemoveAll (pSelBrushes);
		BrushList_Append (BList, CurBrush);
	}
	else
	{
		nb	=Brush_Clone(CurBrush);

		SetDefaultBrushTexInfo(nb);
		Brush_Bound (nb);
		BrushList_Append (BList, nb);
	}
	UpdateSelected();	//	calls UpdateMainControls)()
	//	Be very careful when speccing flags for UpdateAllViews()
	//	The wrong flags at the wrong time will totally screw things up
	UpdateAllViews(UAV_ALL3DVIEWS | REBUILD_QUICK, NULL, TRUE);
}

void CGenEditDoc::CopySelectedBrushes(void)
{
	int		i;
	int		NumSelBrushes;

	NumSelBrushes = SelBrushList_GetSize (pSelBrushes);

	if( NumSelBrushes )
	{
		// create copies of the selected brushes
		for(i=0;i < NumSelBrushes;i++)
		{
			// clone the brush, add copy to level,
			// add copy to select list, and remove original from
			// select list.
			Brush *pBrush;
			Brush *pClone;

			pBrush = SelBrushList_GetBrush (pSelBrushes, 0);
			pClone = Brush_Clone (pBrush);
			Level_AppendBrush (pLevel, pClone);
			SelBrushList_Add (pSelBrushes, pClone);
			SelBrushList_Remove (pSelBrushes, pBrush);
		}
	}// Duplicate selected and delesect original Brushes


	CEntity  TEnt;
	CEntityArray *Entities;
	int cnt;

	Entities = Level_GetEntities (pLevel);

	cnt = Entities->GetSize() ;
	for( i=0 ; i < cnt; i++ )
	{
		CEntity *pEnt = &(*Entities)[i];
		if( pEnt->IsCamera() == GE_FALSE  )	// Exclude Cameras
		{
			if (pEnt->IsSelected ())
			{
				DeselectEntity (pEnt);
				/*
				  There really is a reason for this oddity.
				  Because Level_AddEntity might cause the entities array to grow,
				  dereferencing the data in the array can cause problems because
				  growing the array might cause the dereferenced data to move.
				  (Fun, huh?)  So I create a temporary entity, copy the contents
				  there, and then use that as cloning material.
				*/
				CEntity WorkingEntity;
				int		Index ;

				WorkingEntity = *pEnt;
				Index = Level_AddEntity (pLevel, WorkingEntity);

				SelectEntity( &(*Entities)[Index] );
			}
		}
	}

//	ConPrintf("Cloned %d Brushes, %d Entities.\n", NumSelBrushes, NumSelEntities);	// old Gedit
	mpMainFrame->ConPrintf("Cloned %d Brushes, %d Entities.\n", NumSelBrushes, NumSelEntities);	// new g3dc
	// Copying items places the new items in the same group, so we must update the UI

//	mpMainFrame->m_wndTabControls->GrpTab->UpdateTabDisplay( this ) ;	// old gedit
//	mpMainFrame->m_GroupsTab.UpdateTabDisplay( this ) ;	// new g3dc
	mpMainFrame->UpdateMainControls();
	UpdateSelected();
	//	Be very careful when speccing flags for UpdateAllViews()
	//	The wrong flags at the wrong time will totally screw things up
	UpdateAllViews( UAV_ALL3DVIEWS, NULL );
}

void CGenEditDoc::MakeSelectedBrushNewest(void)
{
	if(GetSelState()==ONEBRUSHONLY)
	{
		Level_RemoveBrush (pLevel, CurBrush);
		Level_AppendBrush (pLevel, CurBrush);
	}
}


void CGenEditDoc::TempCopySelectedBrushes(void)
{
	int		i;
	int NumSelBrushes;

	NumSelBrushes = SelBrushList_GetSize (pSelBrushes);

	SelBrushList_RemoveAll (pTempSelBrushes);

	// make copies of selected brushes
	for(i=0;i < NumSelBrushes;i++)
	{
		Brush	*pBrush, *pClone;

		pBrush = SelBrushList_GetBrush (pSelBrushes, i);
		pClone = Brush_Clone (pBrush);
		Level_AppendBrush (pLevel, pClone);
		SelBrushList_Add (pTempSelBrushes, pClone);
	}
}

typedef struct
{
	CGenEditDoc *pDoc;
	const char *TexName;
} BrushTexSetData;

static geBoolean	BrushTexSetCB (Brush *b, void *lParam)
{
	int			i;
	BrushTexSetData *pData;

	pData = (BrushTexSetData *)lParam;

	Brush_SetName(b, pData->TexName);
	char const * const BrushName = Brush_GetName (b);
	const int NumFaces = Brush_GetNumFaces (b);

	//copy face TexInfos
	for(i=0;i < NumFaces;i++)
	{
		Face	*f	=Brush_GetFace(b, i);
		WadFileEntry *pbmp;

		Face_SetTextureName(f, BrushName);
		Face_SetTextureDibId(f, Level_GetDibId (pData->pDoc->pLevel, BrushName));
		pbmp = Level_GetWadBitmap (pData->pDoc->pLevel, BrushName);
		if (pbmp != NULL)
		{
			Face_SetTextureSize (f, pbmp->Width, pbmp->Height);
		}
	}
	Brush_SetFaceListDirty(b);
	return GE_TRUE ;
}

void CGenEditDoc::SetDefaultBrushTexInfo(Brush *b)
{
	const char *TexName;
	BrushTexSetData CallbackData;

	if (b == NULL)	//	post 0.55
	{
		MessageBox(NULL, "Brush == NULL", "GenEditDoc SetDefaultBrushTexInfo", MB_OK);
		return;
	}

//	TexName = mpMainFrame->m_wndTabControls->GetCurrentTexture();
	TexName = mpMainFrame->m_TexturesTab.GetCurrentTexture();
	CallbackData.pDoc = this;
	CallbackData.TexName = TexName;

⌨️ 快捷键说明

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