//-----------------------------------------------------------------------------
// Purpose: Links to any matching Source entities
//-----------------------------------------------------------------------------
void CEntityConnection::LinkSourceEntities()
{
	// Empty out the existing entity list
	m_pSourceEntityList->RemoveAll();

	// Get a list of all the entities in the world
	CMapDoc *pDoc = CMapDoc::GetActiveMapDoc();

	if (pDoc)
	{
		CMapWorld *pWorld = pDoc->GetMapWorld();

		if (pWorld)
		{
			CMapEntityList matches;
			pWorld->FindEntitiesByName( matches, m_szSourceEntity, false );
		
			for ( int i = 0; i < matches.Count(); i++ )
			{
				CMapEntity *pEntity = matches.Element( i );

				m_pSourceEntityList->AddToTail( pEntity );
				//pEntity->Connection_Add( this ); // This should already be true on creation, investigate need for this func
			}
		}
	}
}
//-----------------------------------------------------------------------------
// Purpose: Constructor. Initializes data members.
//-----------------------------------------------------------------------------
CMapClass::CMapClass(void)
{
	m_pSafeObject = CSafeObject<CMapClass>::Create( this );
	
	//
	// The document manages the unique object IDs. Eventually all object construction
	// should be done through the document, eliminating the need for CMapClass to know
	// about CMapDoc.
	//
	CMapDoc *pDoc = CMapDoc::GetActiveMapDoc();
	if (pDoc != NULL)
	{
		m_nID = pDoc->GetNextMapObjectID();
	}
	else
	{
		m_nID = 0;
	}

	dwKept = 0;
	m_bTemporary = FALSE;

	m_bVisible = true;
	m_bVisible2D = true;
	m_bVisGroupShown = true;
	m_bVisGroupAutoShown = true;
	m_pColorVisGroup = NULL;

	r = g = b = 220;
	m_pParent = NULL;
	m_nRenderFrame = 0;
	m_pEditorKeys = NULL;
	m_Dependents.Purge();
}
Exemple #3
0
void CMapView::DrawMegaTile(CDC* pDC, int x, int y)
{
    CMapDoc* pDoc = GetDocument();
    ASSERT_VALID(pDoc);

    int r = y * pDoc->GetWidth() + x;
    CTile Tile = pDoc->GetTile(r);

    if (m_ViewMode == VIEW_MODE_TILES)
    {
        for (int ye = 0; ye < 4; ye++)
        {
            for (int xe = 0; xe < 4; xe++)
            {
                DrawTile(pDC, x,y,xe,ye, Tile);
            }
        }
    }
    else
    {
        ASSERT(m_ViewMode == VIEW_MODE_ELEVATION);

        BYTE v = (BYTE)(Tile.Elevation);
        v = (BYTE)min(255, v*5); // make difference in color more noticable
        pDC->FillSolidRect(x*40, y*40, 40,40, RGB(v,v,v));
    }
}
//-----------------------------------------------------------------------------
// Purpose: Invokes the texture replace dialog.
//-----------------------------------------------------------------------------
void CFaceEditMaterialPage::OnReplace( void )
{
	// Set the material tool current.
	SetMaterialPageTool( MATERIALPAGETOOL_MATERIAL );

	//
	// get active map doc
	//
	CMapDoc *pDoc = CMapDoc::GetActiveMapDoc();
	if( !pDoc )
		return;

	// ready the replace dialog
	CReplaceTexDlg dlg( pDoc->GetSelection()->GetCount() );

	// get the texture to replace -- the default texture?!
	dlg.m_strFind = GetDefaultTextureName();

	//
	// open replace dialog -- modal
	//
	if( dlg.DoModal() != IDOK )
		return;
	
	// mark undo position
	GetHistory()->MarkUndoPosition( pDoc->GetSelection()->GetList(), "Replace Textures" );

	if( dlg.m_bMarkOnly )
	{
		pDoc->SelectObject( NULL, scClear );	// clear selection first
	}

	dlg.DoReplaceTextures();
}
//-----------------------------------------------------------------------------
// Purpose: Constructor. Initializes data members.
//-----------------------------------------------------------------------------
CMapClass::CMapClass(void)
{
	//
	// The document manages the unique object IDs. Eventually all object construction
	// should be done through the document, eliminating the need for CMapClass to know
	// about CMapDoc.
	//
	CMapDoc *pDoc = CMapDoc::GetActiveMapDoc();
	if (pDoc != NULL)
	{
		m_nID = pDoc->GetNextMapObjectID();
	}
	else
	{
		m_nID = 0;
	}

	dwKept = 0;
	m_bVisible = true;
	m_bVisible2D = true;

	m_bTemporary = FALSE;
	m_pVisGroup = NULL;
	r = g = b = 220;
	Parent = NULL;
	m_nRenderFrame = 0;
	m_bShouldSerialize = TRUE;
	m_pEditorKeys = NULL;
}
Exemple #6
0
void CMapView::OnRButtonDown(UINT, CPoint point)
{
    CPoint pt = point + GetScrollPosition();

    int x  = pt.x / 40;
    int y  = pt.y / 40;
    int xe = (pt.x % 40) / 10;
    int ye = (pt.y % 40) / 10;

    CMapDoc* pDoc = GetDocument();
    ASSERT_VALID(pDoc);
    int w = pDoc->GetWidth();
    int h = pDoc->GetHeight();

    if (w > 0 && h > 0 && x >= 0 && y >= 0 && x < w && y < h && xe >= 0 && xe < 4 && ye >= 0 && ye < 4)
    {
        int r = y*w + x;
        int e = ye*4 + xe;

        CTile Tile = pDoc->GetTile(r);
        g_Tile = Tile.E[e];
        g_Elevation = Tile.Elevation;

        CString str;
        str.Format("Select %s (%dm) from %d [%d]", g_App.m_Elements[g_Tile].Name, g_Elevation, r,e);
        g_App.PrintStatus(str);
    }
}
//-----------------------------------------------------------------------------
// Purpose: Invokes the replace texture dialog.
//-----------------------------------------------------------------------------
void CTextureBrowser::OnReplace(void)
{
	CMapDoc *pDoc = CMapDoc::GetActiveMapDoc();
	if(!pDoc)
		return;

	CReplaceTexDlg dlg(pDoc->GetSelection()->GetCount());

	dlg.m_strFind = m_cTextureWindow.szCurTexture;

	if(dlg.DoModal() != IDOK)
		return;
	
	// mark undo position
	GetHistory()->MarkUndoPosition(pDoc->GetSelection()->GetList(), "Replace Textures");

	if(dlg.m_bMarkOnly)
	{
		pDoc->SelectObject(NULL, scClear);	// clear selection first
	}

	dlg.DoReplaceTextures();

	//EndDialog(IDOK);

	if (m_bUsed)
	{
		SetUsed(TRUE);
	}
}
//-----------------------------------------------------------------------------
// Purpose: Special implementation of UpdateChild for the world object. This
//			notifies the document that an object's bounding box has changed.
// Input  : pChild - 
//-----------------------------------------------------------------------------
void CMapWorld::UpdateChild(CMapClass *pChild)
{
	if ( CMapClass::s_bLoadingVMF )
		return;
	
	// Recalculate the bounds of this child's branch.
	pChild->CalcBounds(TRUE);

	// Recalculate own bounds
	CalcBounds( FALSE );

	//
	// Relink the child in the culling tree.
	//
	if (m_pCullTree != NULL)
	{
		m_pCullTree->UpdateCullTreeObjectRecurse(pChild);
	}

	//
	// Notify the document that an object in the world has changed.
	//
	if (!IsTemporary()) // HACK: check to avoid prefab objects ending up in the doc's update list
	{
		CMapDoc *pDoc = CMapDoc::GetActiveMapDoc();
		if (pDoc != NULL)
		{
			pDoc->UpdateObject(pChild);
		}
	}
}
Exemple #9
0
void CMapView::OnLButtonDown(UINT nFlags, CPoint point)
{
    if (m_HandDown)
    {
        m_Tracking = true;
        SetCapture();
        m_LastPoint = point;
    }
    else
    {
        CPoint pt = point + GetScrollPosition();

        int x  = pt.x / 40;
        int y  = pt.y / 40;
        int xe = (pt.x % 40) / 10;
        int ye = (pt.y % 40) / 10;

        CMapDoc* pDoc = GetDocument();
        ASSERT_VALID(pDoc);
        int w = pDoc->GetWidth();
        int h = pDoc->GetHeight();

        if (w > 0 && h > 0 && x >= 0 && y >= 0 && x < w && y < h && xe >= 0 && xe < 4 && ye >= 0 && ye < 4)
        {
            int r = y*w + x;
            int e = ye*4 + xe;

            if (m_ViewMode == VIEW_MODE_ELEVATION)
            {
                pDoc->SetTileElevation(r, g_Elevation);
                CString str;
                str.Format("Change %d to %dm", r, g_Elevation);
                g_App.PrintStatus(str);

                CRect rect(CPoint(x*40, y*40), CSize(40,40));
                rect.OffsetRect(-GetScrollPosition());
                InvalidateRect(rect, FALSE);
            }
            else
            {
                pDoc->SetTile(r,e, g_Tile);
                CString str;
                str.Format("Change %d [%d] to %s", r,e, g_App.m_Elements[g_Tile].Name);
                g_App.PrintStatus(str);

                CRect rect(CPoint(x*40 + xe*10, y*40 + ye*10), CSize(10,10));
                rect.OffsetRect(-GetScrollPosition());
                InvalidateRect(rect, FALSE);
            }

            m_Tracking = true;
            SetCapture();
        }
    }

    Inherited::OnLButtonDown(nFlags, point);
}
//-----------------------------------------------------------------------------
// Purpose: 
//-----------------------------------------------------------------------------
void CTextureBrowser::OnMark(void)
{
	CMapDoc *pDoc = CMapDoc::GetActiveMapDoc();
	if (pDoc != NULL)
	{
		pDoc->ReplaceTextures(m_cTextureWindow.szCurTexture, "", TRUE, 0x100, FALSE, FALSE);
		EndDialog(IDOK);
	}
}
CToolManager* ToolManager()
{
	CMapDoc *pDoc = CMapDoc::GetActiveMapDoc();

	if ( pDoc )
		return pDoc->GetTools();

	return &s_DummyToolmanager;
}
Exemple #12
0
void CMapView::OnInitialUpdate()
{
    Inherited::OnInitialUpdate();

    CMapDoc* pDoc = GetDocument();
    ASSERT_VALID(pDoc);
    int h = pDoc->GetHeight();
    int w = pDoc->GetWidth();

    SetScrollSizes(MM_TEXT, CSize(w*40, h*40));
}
//-----------------------------------------------------------------------------
// Purpose: 
//-----------------------------------------------------------------------------
void CMapCheckDlg::OnSelchangeErrors() 
{
	// change description to match error
	int iSel = m_Errors.GetCurSel();

	if(iSel == LB_ERR)
	{
		m_Fix.EnableWindow(FALSE);
		m_cFixAll.EnableWindow(FALSE);
		m_Go.EnableWindow(FALSE);
	}

	CString str;
	MapError *pError;
	pError = (MapError*) m_Errors.GetItemDataPtr(iSel);

	str.LoadString(ID_DESCRIPTIONS_START + pError->Type);
	m_Description.SetSel(0, -1);
	m_Description.ReplaceSel(str);

	m_Go.EnableWindow(pError->pObjects[0] != NULL);

	// set state of fix button
	m_Fix.EnableWindow(pError->Fix == NeedsFix);
	m_cFixAll.EnableWindow(pError->Fix != CantFix);

	// set text of fix button
	switch(pError->Fix)
	{
	case NeedsFix:
		m_Fix.SetWindowText("&Fix");
		break;
	case CantFix:
		m_Fix.SetWindowText("Can't fix");
		break;
	case Fixed:
		m_Fix.SetWindowText("(fixed)");
		break;
	}

	CMapDoc *pDoc = CMapDoc::GetActiveMapDoc();

	pDoc->Selection_SetMode(selectObjects);
	
	if (pError->pObjects[0])
	{
		pDoc->SelectObject(pError->pObjects[0], CMapDoc::scClear | CMapDoc::scSelect | CMapDoc::scUpdateDisplay);
	}
	else
	{
		pDoc->SelectObject(NULL, CMapDoc::scClear | CMapDoc::scUpdateDisplay);
	}
}
//-----------------------------------------------------------------------------
// Purpose: 
//-----------------------------------------------------------------------------
void COP_Groups::UpdateGrouplist(void)
{
	CMapDoc *pDoc = CMapDoc::GetActiveMapDoc();
	if (pDoc == NULL)
	{
		return;
	}

	if(!::IsWindow(m_cGroups.m_hWnd))
		return;

	int iSel = m_cGroups.GetCurSel();
	DWORD oldselid = 0xffffffff;
	if(iSel != LB_ERR)
		oldselid = m_cGroups.GetItemData(iSel);

	m_cGroups.ResetContent();

	if (IsMultiEdit())
	{
		m_cGroups.InsertString(0, VALUE_DIFFERENT_STRING);
		m_cGroups.SetItemData(0, VALUE_DIFFERENT_ID);
	}

	m_cGroups.InsertString(0, NO_GROUP_STRING);
	m_cGroups.SetItemData(0, NO_GROUP_ID);

	POSITION pos = pDoc->VisGroups_GetHeadPosition();
	while (pos != NULL)
	{
		CVisGroup *pGroup = pDoc->VisGroups_GetNext(pos);

		int iIndex = m_cGroups.AddString(pGroup->GetName());
		m_cGroups.SetItemData(iIndex, pGroup->GetID());
	}

	// restore old selection based on stored id
	iSel = 0;
	int iSize = m_cGroups.GetCount();
	for(int i = 0; i < iSize; i++)
	{
		if(m_cGroups.GetItemData(i) == oldselid)
		{
			iSel = i;
			break;
		}
	}

	m_cGroups.SetCurSel(iSel);
	m_cGroups.Invalidate();
}
void CPrefabsDlg::EditObjectData()
{
	// get application
	CHammer *pApp = (CHammer*) AfxGetApp();

	if(bCurLibraryModified)
	{
		CPrefabLibrary *pLibrary = GetCurrentLibrary();
		if(pLibrary)
			pLibrary->Save();
	}

	CMapDoc *pDoc = (CMapDoc*) pApp->pMapDocTemplate->OpenDocumentFile(NULL);
	pDoc->EditPrefab3D(GetCurrentObject()->GetID());
	EndDialog(IDOK);
}
//-----------------------------------------------------------------------------
// Purpose: 
// Input  : pView - 
//			nFlags - 
//			point - 
// Output : Returns true on success, false on failure.
//-----------------------------------------------------------------------------
bool Marker3D::OnLMouseDown2D(CMapView2D *pView, UINT nFlags, CPoint point)
{
	CMapDoc *pDoc = pView->GetDocument();
	if (pDoc == NULL)
	{
		return true;
	}

	CMapWorld *pWorld = pDoc->GetMapWorld();

	m_bLButtonDown = true;

	pView->SetCapture();

	//
	// Convert to some odd coordinate space that the base tools code uses.
	//
  	CPoint ptScreen = point;
	ptScreen.x += pView->GetScrollPos(SB_HORZ);
	ptScreen.y += pView->GetScrollPos(SB_VERT);
	
	//
	// Convert point to world coords.
	//
	pView->ClientToWorld(point);

	Vector ptOrg = vec3_origin;
	ptOrg[axHorz] = point.x;
	ptOrg[axVert] = point.y;

	//
	// Snap starting position to grid.
	//
	if (!(GetAsyncKeyState(VK_MENU) & 0x8000))
	{
		pDoc->Snap(ptOrg);
	}

	StartNew(ptOrg);
	pView->SetUpdateFlag(CMapView2D::updTool);

	return true;
}
//-----------------------------------------------------------------------------
// Purpose: 
// Input  : pView - 
//			nFlags - 
//			point - 
// Output : Returns true if the message was handled, false if not.
//-----------------------------------------------------------------------------
bool CToolMaterial::OnLMouseDown2D(CMapView2D *pView, UINT nFlags, CPoint point)
{
	CMapDoc *pDoc = pView->GetDocument();
	CMapWorld *pWorld = pDoc->GetMapWorld();

	if (nFlags & MK_CONTROL)
	{
		//
		// CONTROL is down, perform selection only.
		//
		pView->SelectAt(point, FALSE, true);
	}
	else
	{
		pView->SelectAt(point, TRUE, true);
	}

	return (true);
}
//-----------------------------------------------------------------------------
// Purpose: Handles left mouse button down events in the 3D view.
// Input  : Per CWnd::OnLButtonDown.
// Output : Returns true if the message was handled, false if not.
//-----------------------------------------------------------------------------
bool CToolMaterial::OnLMouseDown3D(CMapView3D *pView, UINT nFlags, CPoint point) 
{
	CMapDoc *pDoc = pView->GetDocument();
	if (pDoc == NULL)
	{
		return false;
	}

	bool bShift = ((GetAsyncKeyState(VK_SHIFT) & 0x8000) != 0);

	ULONG ulFace;
	CMapClass *pObject = pView->NearestObjectAt(point, ulFace);

	if ((pObject != NULL) && (pObject->IsMapClass(MAPCLASS_TYPE(CMapSolid))))
	{
		CMapSolid *pSolid = (CMapSolid *)pObject;

		int cmd = CMapDoc::scToggle | CMapDoc::scClear | CMapDoc::scUpdateDisplay;

		// No clear if CTRL pressed.
		if (GetAsyncKeyState(VK_CONTROL) & 0x8000)
		{
			cmd &= ~CMapDoc::scClear;	
		}

		// If they are holding down SHIFT, select the entire solid.
		if (bShift)
		{
			pDoc->SelectFace(pSolid, -1, cmd);
		}
		// Otherwise, select a single face.
		else
		{
			pDoc->SelectFace(pSolid, ulFace, cmd);
		}
	}

	// Update the controls given new information (ie. new faces).
	GetMainWnd()->m_pFaceEditSheet->UpdateControls();

	return true;
}
//-----------------------------------------------------------------------------
// Purpose: Causes all objects in the world to update any object dependencies (pointers)
//			that they might be holding. This is a static function.
//-----------------------------------------------------------------------------
void CMapClass::UpdateAllDependencies(CMapClass *pObject)
{
	//
	// Try to locate the world object.
	//
	CMapWorld *pWorld;
	if (pObject == NULL)
	{
		CMapDoc *pDoc = CMapDoc::GetActiveMapDoc();
		if ((pDoc == NULL) || (pDoc->IsLoading()))
		{
			return;
		}
		
		pWorld = pDoc->GetMapWorld();
	}
	else
	{
		pWorld = pObject->GetWorldObject(pObject);
	}

	if (pWorld == NULL)
	{
		return;
	}

	//
	// We found the world. Tell all its children to update their dependencies
	// because of the given object.
	//
	EnumChildrenPos_t pos;
	CMapClass *pChild = pWorld->GetFirstDescendent(pos);
	while (pChild != NULL)
	{
		pChild->UpdateDependencies(pWorld, pObject);
		pChild = pWorld->GetNextDescendent(pos);
	}
}
//-----------------------------------------------------------------------------
// Purpose: 
//-----------------------------------------------------------------------------
void CMapCheckDlg::OnGo() 
{
	CMapDoc *pDoc = CMapDoc::GetActiveMapDoc();

	// change description to match error
	int iSel = m_Errors.GetCurSel();

	if(iSel == LB_ERR)
		return;	// no sel

	MapError *pError;
	pError = (MapError*) m_Errors.GetItemDataPtr(iSel);

	VIEW2DINFO vi;
	vi.wFlags = VI_CENTER;

	// get centerpoint
	pError->pObjects[0]->GetBoundsCenter(vi.ptCenter);
	g_pToolManager->SetTool(TOOL_POINTER);
	pDoc->SelectObject(pError->pObjects[0], CMapDoc::scClear | 
		CMapDoc::scSelect | CMapDoc::scUpdateDisplay);
	pDoc->SetView2dInfo(vi);
}
//-----------------------------------------------------------------------------
// Purpose: Called any time we are hidden or shown.
// Input  : bShow - 
//			nStatus - 
//-----------------------------------------------------------------------------
void CSearchReplaceDlg::OnShowWindow(BOOL bShow, UINT nStatus)
{
	if (bShow)
	{
		m_bNewSearch = true;
		GetDlgItem(IDCANCEL)->SetWindowText("Cancel");

		m_nFindIn = FindInWorld;
		CMapDoc *pDoc = CMapDoc::GetActiveMapDoc();
		if (pDoc)
		{
			if (pDoc->Selection_GetCount() > 0)
			{
				m_nFindIn = FindInSelection;
			}
		}

		// Populate the controls with the current data.
		UpdateData(FALSE);
	}

	CDialog::OnShowWindow(bShow, nStatus);
}
//-----------------------------------------------------------------------------
// Purpose: 
// Input  : nChar - 
//			nRepCnt - 
//			nFlags - 
//-----------------------------------------------------------------------------
bool Clipper3D::OnKeyDown2D(CMapView2D *pView, UINT nChar, UINT nRepCnt, UINT nFlags) 
{
	switch (nChar)
	{
		case 'O':
		{
			//
			// Toggle the rendering of measurements.
			//
			ToggleMeasurements();
			CMapDoc *pDoc = pView->GetDocument();
			pDoc->ToolUpdateViews(CMapView2D::updTool);
			return true;
		}

		case VK_RETURN:
		{
			//
			// Do the clip.
			//
			if (!IsEmpty() )
			{
				SaveClipResults();
			}
			return true;
		}

		case VK_ESCAPE:
		{
			OnEscape();
			return true;
		}
	}

	return false;	
}
//-----------------------------------------------------------------------------
// Purpose: 
// Input  : *pView - 
//			nFlags - 
//			point - 
// Output : Returns true on success, false on failure.
//-----------------------------------------------------------------------------
bool Marker3D::OnLMouseDown3D(CMapView3D *pView, UINT nFlags, CPoint point)
{
	ULONG ulFace;
	CMapClass *pObject = pView->NearestObjectAt(point, ulFace);
	if (pObject != NULL)
	{
		CMapSolid *pSolid = dynamic_cast <CMapSolid *> (pObject);
		if (pSolid == NULL)
		{
			// Clicked on a point entity - do nothing.
			return true;
		}

		CMapDoc *pDoc = pView->GetDocument();

		//
		// Build a ray to trace against the face that they clicked on to
		// find the point of intersection.
		//			
		Vector Start;
		Vector End;
		pView->BuildRay(point, Start, End);

		Vector HitPos, HitNormal;
		CMapFace *pFace = pSolid->GetFace(ulFace);
		if (pFace->TraceLine(HitPos, HitNormal, Start, End))
		{
			if (GetMainWnd()->m_ObjectBar.IsEntityToolCreatingPrefab())
			{
				//
				// Prefab creation.
				//
				pDoc->Snap(HitPos);

				GetHistory()->MarkUndoPosition(pDoc->Selection_GetList(), "New Prefab");

				// Get prefab object
				CMapClass *pPrefabObject = GetMainWnd()->m_ObjectBar.BuildPrefabObjectAtPoint(HitPos);

				//
				// Add prefab to the world.
				//
				CMapWorld *pWorld = pDoc->GetMapWorld();
				pDoc->ExpandObjectKeywords(pPrefabObject, pWorld);
				pDoc->AddObjectToWorld(pPrefabObject);
				GetHistory()->KeepNew(pPrefabObject);

				//
				// Select the new object.
				//
				pDoc->SelectObject(pPrefabObject, CMapDoc::scClear | CMapDoc::scSelect | CMapDoc::scUpdateDisplay);

				//
				// Update world bounds.
				//
				UpdateBox ub;
				CMapObjectList ObjectList;
				ObjectList.AddTail(pPrefabObject);
				ub.Objects = &ObjectList;

				Vector mins;
				Vector maxs;
				pPrefabObject->GetRender2DBox(mins, maxs);
				ub.Box.SetBounds(mins, maxs);

				pDoc->UpdateAllViews(NULL, MAPVIEW_UPDATE_OBJECTS, &ub);
				
				pDoc->SetModifiedFlag();
			}
			else if (GetMainWnd()->m_ObjectBar.IsEntityToolCreatingEntity())
			{
				//
				// Entity creation.
				//
				GetHistory()->MarkUndoPosition(pDoc->Selection_GetList(), "New Entity");
				
				CMapEntity *pEntity = new CMapEntity;
				pEntity->SetPlaceholder(TRUE);
				pEntity->SetOrigin(HitPos);
				pEntity->SetClass(CObjectBar::GetDefaultEntityClass());
				
				//Align the entity on the plane properly
				//				pEntity->AlignOnPlane(HitPos, &pFace->plane, (pFace->plane.normal[2] > 0.0f) ? CMapEntity::ALIGN_BOTTOM : CMapEntity::ALIGN_TOP);
				pEntity->AlignOnPlane(HitPos, &pFace->plane, (HitNormal[2] > 0.0f) ? CMapEntity::ALIGN_BOTTOM : CMapEntity::ALIGN_TOP);
									
				CMapWorld *pWorld = pDoc->GetMapWorld();
				pDoc->AddObjectToWorld(pEntity);
				
				GetHistory()->KeepNew(pEntity);

				//
				// Select the new object.
				//
				pDoc->SelectObject(pEntity, CMapDoc::scClear | CMapDoc::scSelect | CMapDoc::scUpdateDisplay);
				
 				UpdateBox ub;
				CMapObjectList ObjectList;
				ObjectList.AddTail(pEntity);
				ub.Objects = &ObjectList;

				Vector mins;
				Vector maxs;
				pEntity->GetRender2DBox(mins, maxs);
				ub.Box.SetBounds(mins, maxs);

				pDoc->UpdateAllViews(NULL, MAPVIEW_UPDATE_OBJECTS, &ub);
			
				pDoc->SetModifiedFlag();
			}
		}
	}

	return true;
}
//-----------------------------------------------------------------------------
// Purpose: Handles left mouse button down events in the 2D view.
// Input  : Per CWnd::OnLButtonDown.
// Output : Returns true if the message was handled, false if not.
//-----------------------------------------------------------------------------
bool Clipper3D::OnLMouseDown2D(CMapView2D *pView, UINT nFlags, CPoint point)
{
	CMapDoc *pDoc = pView->GetDocument();
	CMapWorld *pWorld = pDoc->GetMapWorld();

	m_ptLDownClient = point;
	m_bLButtonDown = true;

	pView->SetCapture();

	//
	// Convert to some odd coordinate space that the base tools code uses.
	//
  	CPoint ptScreen = point;
	ptScreen.x += pView->GetScrollPos(SB_HORZ);
	ptScreen.y += pView->GetScrollPos(SB_VERT);
	
	//
	// Convert point to world coords.
	//
	pView->ClientToWorld(point);

	Vector ptOrg( COORD_NOTINIT, COORD_NOTINIT, COORD_NOTINIT );
	ptOrg[axHorz] = point.x;
	ptOrg[axVert] = point.y;

	// getvisiblepoint fills in any coord that's still set to COORD_NOTINIT:
	pDoc->GetBestVisiblePoint(ptOrg);

	// snap starting position to grid
	if (!(GetAsyncKeyState(VK_MENU) & 0x8000))
	{
		pDoc->Snap(ptOrg);
	}
	
	BOOL bStarting = FALSE;

	// if the tool is not empty, and shift is not held down (to
	//  start a new camera), don't do anything.
	if(!IsEmpty())
	{
		if(!StartTranslation(ptScreen))
		{
			if (nFlags & MK_SHIFT)
			{
				SetEmpty();
				bStarting = TRUE;
			}
			else
			{
				goto _DoNothing;
			}
		}
	}
	else
	{
		bStarting = TRUE;
	}

	SetClipObjects(pDoc->Selection_GetList());

	if (bStarting)
	{
		StartNew(ptOrg);
		pView->SetUpdateFlag(CMapView2D::updTool);
	}

_DoNothing:

	return true;
}
Exemple #25
0
void CMapView::OnDraw(CDC* pDC)
{
    CMapDoc* pDoc = GetDocument();
    ASSERT_VALID(pDoc);
    int h = pDoc->GetHeight();
    int w = pDoc->GetWidth();

    CRect r;
    pDC->GetClipBox(&r);
    pDC->FillSolidRect(r, GetSysColor(COLOR_3DFACE));

    if (w > 0 && h > 0)
    {
        // calculate the bounding box that is needed to be draw
        CRect r;
        pDC->GetClipBox(&r);
        int ys = r.top    / 40;
        int ye = r.bottom / 40;
        int xs = r.left   / 40;
        int xe = r.right  / 40;
        ye = min(ye+1,h);
        xe = min(xe+1,w);

        if (m_ViewMode == VIEW_MODE_GRAPHICS)
        {
			if (pDoc->m_pMapImage)
			{
				pDC->SetStretchBltMode(COLORONCOLOR);
				CRect r(0,0,pDoc->m_pMapImage->GetWidth(), pDoc->m_pMapImage->GetHeight());
				pDoc->m_pMapImage->Draw(pDC, r,r);
			}
        }
        else
        {
            for (int y = ys; y < ye; y++)
            {
                for (int x = xs; x < xe; x++)
                {
                    DrawMegaTile(pDC, x,y);
                }
            }
        }

        if (m_GridMode)
        {
            // draw major grid lines
            {
                CPen Pen;
                Pen.CreateStockObject(BLACK_PEN);
                CPen* pOldPen = pDC->SelectObject(&Pen);
                for (int y = ys; y <= ye; y++)
                {
                    pDC->MoveTo(xs*40,y*40);
                    pDC->LineTo(xe*40,y*40);

                }
                for (int x = xs; x <= xe; x++)
                {
                    pDC->MoveTo(x*40,ys*40);
                    pDC->LineTo(x*40,ye*40);
                }
                pDC->SelectObject(pOldPen);
            }
        }
    }
}
Exemple #26
0
void CMapView::OnMouseMove(UINT, CPoint point)
{
    if (m_HandDown && m_Tracking)
    {
        CPoint Delta = m_LastPoint - point;
        CPoint NewPoint = GetScrollPosition() + Delta;
        ScrollToPosition(NewPoint);
        m_LastPoint = point;
    }
    else
    {
        point += GetScrollPosition();

        int x  = point.x / 40;
        int y  = point.y / 40;
        int xe = (point.x % 40) / 10;
        int ye = (point.y % 40) / 10;

        CMapDoc* pDoc = GetDocument();
        ASSERT_VALID(pDoc);
        int w = pDoc->GetWidth();
        int h = pDoc->GetHeight();

        CString str;
        if (w > 0 && h > 0 && x >= 0 && y >= 0 && x < w && y < h && xe >= 0 && xe < 4 && ye >= 0 && ye < 4)
        {
            int r = y*w + x;
            int e = ye*4 + xe;

            CTile Tile = pDoc->GetTile(r);
            int Elevation = Tile.Elevation;
            CElement Element = g_App.m_Elements[Tile.E[e]];

            str.Format("%s (%d)", Element.Name, Element.Type);
            g_App.PrintStatus(str,1);

            str.Format("%dm", Elevation);
            g_App.PrintStatus(str,2);

            str.Format("%d,%d (%d,%d)", x,y, xe,ye);
            g_App.PrintStatus(str,3);

            str.Format("%d E%d", r,e);
            g_App.PrintStatus(str,4);

            if (m_Tracking)
            {
                if (m_ViewMode == VIEW_MODE_ELEVATION)
                {
                    pDoc->SetTileElevation(r, g_Elevation);
                    CString str;
                    str.Format("Change %d to %dm", r, g_Elevation);
                    g_App.PrintStatus(str);


                    CRect rect(CPoint(x*40, y*40), CSize(40,40));
                    rect.OffsetRect(-GetScrollPosition());
                    InvalidateRect(rect, FALSE);
                }
                else
                {
                    pDoc->SetTile(r,e, g_Tile);
                    CString str;
                    str.Format("Change %d [%d] to %s", r,e, g_App.m_Elements[g_Tile].Name);
                    g_App.PrintStatus(str);

                    CRect rect(CPoint(x*40 + xe*10, y*40 + ye*10), CSize(10,10));
                    rect.OffsetRect(-GetScrollPosition());
                    InvalidateRect(rect, FALSE);
                }
            }
        }
        else
        {
            str.Empty();
            g_App.PrintStatus(str,1);
            g_App.PrintStatus(str,2);
            g_App.PrintStatus(str,3);
            g_App.PrintStatus(str,4);
        }
        str.Format("%d,%d", point.x,point.y);
        g_App.PrintStatus(str,5,true);
    }
}
//-----------------------------------------------------------------------------
// Purpose: 
// Input  : pView - 
//			nFlags - 
//			point - 
// Output : Returns true on success, false on failure.
//-----------------------------------------------------------------------------
bool Marker3D::OnMouseMove2D(CMapView2D *pView, UINT nFlags, CPoint point)
{
	CMapDoc *pDoc = pView->GetDocument();
	if (!pDoc)
	{
		return false;
	}

	bool bCursorSet = false;
	unsigned int uConstraints = 0;
	if ((GetAsyncKeyState(VK_MENU) & 0x8000))
	{
		uConstraints |= Tool3D::constrainNosnap;
	}
					    
	//
	// Make sure the point is visible.
	//
	if (m_bLButtonDown)
	{
		pView->ToolScrollToPoint(point);
	}

	//
	// Convert to some odd coordinate space that the base tools code uses.
	//
  	CPoint ptHitTest = point;
	ptHitTest.x += pView->GetScrollPos(SB_HORZ);
	ptHitTest.y += pView->GetScrollPos(SB_VERT);

	//
	// Convert to world coords.
	//
	Vector vecWorld;
	pView->ClientToWorld(vecWorld, point);
	point.x = vecWorld[axHorz];
	point.y = vecWorld[axVert];

	//
	// Update status bar position display.
	//
	char szBuf[128];
	m_pDocument->Snap(vecWorld);
	sprintf(szBuf, " @%.0f, %.0f ", vecWorld[axHorz], vecWorld[axVert]);
	SetStatusText(SBI_COORDS, szBuf);

	//
	// If we are currently dragging the marker, update that operation based on
	// the current cursor position and keyboard state.
	//
	if (IsTranslating())
	{
		if (UpdateTranslation(point, uConstraints, CSize(0,0)))
		{
			pDoc->ToolUpdateViews(CMapView2D::updTool);
			pDoc->Update3DViews();
		}

		// Don't change the cursor while dragging - it should remain a cross.
		bCursorSet = true;
		SetCursor(AfxGetApp()->LoadStandardCursor(IDC_CROSS));
	}
	else if (!IsEmpty())
	{
		// Don't change the cursor while dragging - it should remain a cross.
		bCursorSet = true;
		SetCursor(AfxGetApp()->LoadStandardCursor(IDC_CROSS));
	}

	if (!bCursorSet)
	{
		SetCursor(s_hcurEntity);
	}

	return true;
}
//-----------------------------------------------------------------------------
// Purpose: creates a new keyframe at the specified time
// Input  : time - 
// Output : Returns true on success, false on failure.
//-----------------------------------------------------------------------------
CMapEntity *CMapAnimator::CreateNewKeyFrame( float time )
{
	// work out where we are in the animation
	CMapKeyFrame *key;
	CMapKeyFrame *pPrevKey;
	float partialTime = GetKeyFramesAtTime( time, key, pPrevKey );

	CMapEntity *pCurrentEnt = dynamic_cast<CMapEntity*>( key->Parent );

	// check to see if we're direction on a key frame
	Vector posOffset( 0, 0, 0 );
	if ( partialTime == 0 )
	{
		// create this new key frame slightly after the current one, and offset
		posOffset[0] = 64;
	}

	// get our orientation and position at this time
	Vector vOrigin;
	QAngle angles;
	Quaternion qAngles;
	GetAnimationAtTime( key, pPrevKey, partialTime, vOrigin, qAngles, m_iPositionInterpolator, m_iRotationInterpolator );
	QuaternionAngles( qAngles, angles );

	// create the new map entity
	CMapDoc *pDoc = CMapDoc::GetActiveMapDoc();
	CMapWorld *pWorld = pDoc->GetMapWorld();

	CMapEntity *pNewEntity = new CMapEntity;

	Vector newPos;
	VectorAdd( vOrigin, posOffset, newPos );
	pNewEntity->SetPlaceholder( TRUE );
	pNewEntity->SetOrigin( newPos );
	pNewEntity->SetClass( "keyframe_track" );

	char buf[128];
	sprintf( buf, "%f %f %f", angles[0], angles[1], angles[2] );
	pNewEntity->SetKeyValue( "angles", buf );

	// link it into the keyframe list

	// take over this existing next keyframe pointer
	const char *nextKeyName = pCurrentEnt->GetKeyValue( "NextKey" );
	if ( nextKeyName )
	{
		pNewEntity->SetKeyValue( "NextKey", nextKeyName );
	}
		
	// create a new unique name for this ent
	char newName[128];
	const char *oldName = pCurrentEnt->GetKeyValue( "targetname" );
	if ( !oldName || oldName[0] == 0 )
		oldName = "keyframe";

	CMapEntity::GenerateNewTargetname( oldName, newName, 127 );
	pNewEntity->SetKeyValue( "targetname", newName );

	// point the current entity at the newly created one
	pCurrentEnt->SetKeyValue( "NextKey", newName );

	// copy any relevant values
	const char *keyValue = pCurrentEnt->GetKeyValue( "parentname" );
	if ( keyValue )
		pNewEntity->SetKeyValue( "parentname", keyValue );

	keyValue = pCurrentEnt->GetKeyValue( "MoveSpeed" );
	if ( keyValue )
		pNewEntity->SetKeyValue( "MoveSpeed", keyValue );

	return(pNewEntity);
}
//-----------------------------------------------------------------------------
// Purpose: Called when they hit the Find, the Replace, or the Replace All button.
// Input  : uCmd - The ID of the button the user hit, IDC_FIND_NEXT or IDC_REPLACE.
// Output : Returns TRUE to indicate that the message was handled.
//-----------------------------------------------------------------------------
BOOL CSearchReplaceDlg::OnFindReplace(UINT uCmd)
{
	CMapDoc *pDoc = CMapDoc::GetActiveMapDoc();
	if (!pDoc)
	{
		return TRUE;
	}

	static FindObject_t FindObject;
	static CMapClass *pLastFound = NULL;
	static nReplaceCount = 0;

	bool bDone = false;

	do
	{
		CMapClass *pObject = NULL;

		if (m_bNewSearch)
		{
			//
			// New search. Fetch the data from the controls.
			//
			UpdateData();
			GetFindCriteria(FindObject, pDoc);

			//
			// We have to keep track of the last object in the iteration for replacement,
			// because replacement is done when me advance to the next object.
			//
			pLastFound = NULL;
			nReplaceCount = 0;

			pObject = FindFirstObject(FindObject);
		}
		else
		{
			pObject = FindNextObject(FindObject);
		}

		//
		// Replace All is undone as single operation. Mark the undo position the first time
		// we find a match during a Replace All.
		//
		if (m_bNewSearch && (uCmd == IDC_REPLACE_ALL) && pObject)
		{
			GetHistory()->MarkUndoPosition(pDoc->Selection_GetList(), "Replace Text");
		}

		//
		// If we have an object to do the replace on, do the replace.
		//
		if (pLastFound && ((uCmd == IDC_REPLACE) || (uCmd == IDC_REPLACE_ALL)))
		{
			if (uCmd == IDC_REPLACE)
			{
				// Allow for undo each time we do a Replace.
				GetHistory()->MarkUndoPosition(NULL, "Replace Text");
			}

			//
			// Do the replace on the last matching object we found. This lets the user see what
			// object will be modified before it is done.
			//
			GetHistory()->Keep(pLastFound);
			nReplaceCount += FindReplace((CMapEntity *)pLastFound, FindObject, m_strReplaceText);

			GetDlgItem(IDCANCEL)->SetWindowText("Close");
		}

		if (pObject)
		{
			//
			// We found an object that satisfies our search.
			//
			if ((uCmd == IDC_FIND_NEXT) || (uCmd == IDC_REPLACE))
			{
				//
				// Highlight the match.
				//
				pDoc->SelectObject(pObject, CMapDoc::scClear | CMapDoc::scSelect);
				pDoc->CenterSelection();
			}

			//
			// Stop after one match unless we are doing a Replace All.
			//
			if (uCmd != IDC_REPLACE_ALL)
			{
				bDone = true;
			}

			m_bNewSearch = false;
			pLastFound = pObject;
		}
		else
		{
			//
			// No more objects in the search set match our criteria.
			//
			if ((m_bNewSearch) || (uCmd != IDC_REPLACE_ALL))
			{
				CString str;
				str.Format("Finished searching for '%s'.", m_strFindText);
				MessageBox(str, "Find/Replace Text", MB_OK);

				// TODO: put the old selection back
			}
			else if (uCmd == IDC_REPLACE_ALL)
			{
				CString str;
				str.Format("Replaced %d occurrences of the string '%s' with '%s'.", nReplaceCount, m_strFindText, m_strReplaceText);
				MessageBox(str, "Find/Replace Text", MB_OK);
			}

			m_bNewSearch = true;
			bDone = true;
		}

	} while (!bDone);

	return TRUE;
}
//-----------------------------------------------------------------------------
// Purpose: Handles mouse move events in the 2D view.
// Input  : Per CWnd::OnMouseMove.
// Output : Returns true if the message was handled, false if not.
//-----------------------------------------------------------------------------
bool Clipper3D::OnMouseMove2D(CMapView2D *pView, UINT nFlags, CPoint point)
{
	CMapDoc *pDoc = pView->GetDocument();
	if (!pDoc)
	{
		return false;
	}

	bool bCursorSet = false;
	BOOL bDisableSnap = (GetAsyncKeyState(VK_MENU) & 0x8000) ? TRUE : FALSE;
					    
	//
	// Make sure the point is visible.
	//
	if (m_bLButtonDown)
	{
		pView->ToolScrollToPoint(point);
	}

	//
	// Convert to some odd coordinate space that the base tools code uses.
	//
  	CPoint ptScreen = point;
	ptScreen.x += pView->GetScrollPos(SB_HORZ);
	ptScreen.y += pView->GetScrollPos(SB_VERT);

	//
	// Convert to world coords.
	//
	Vector vecWorld;
	pView->ClientToWorld(vecWorld, point);
	point.x = vecWorld[axHorz];
	point.y = vecWorld[axVert];

	//
	// Update status bar position display.
	//
	char szBuf[128];
	m_pDocument->Snap(vecWorld);
	sprintf(szBuf, " @%.0f, %.0f ", vecWorld[axHorz], vecWorld[axVert]);
	SetStatusText(SBI_COORDS, szBuf);
	
	if (IsTranslating())
	{
		// cursor is cross here
		bCursorSet = true;

		UINT uConstraints = 0;

		if (bDisableSnap)
		{
			uConstraints |= Tool3D::constrainNosnap;
		}

		if(nFlags & MK_CONTROL)
		{
			uConstraints |= Clipper3D::constrainMoveBoth;
		}

		if (UpdateTranslation(point, uConstraints, CSize(0,0)))
		{
			pDoc->ToolUpdateViews(CMapView2D::updTool);
			pDoc->Update3DViews();
		}
	}
	else if (!IsEmpty())
	{
		//
		// If the cursor is on a handle, set it to a cross.
		//
		if (HitTest(ptScreen, TRUE) != -1)
		{
			SetCursor(AfxGetApp()->LoadStandardCursor(IDC_CROSS));
			bCursorSet = true;
		}
	}

	if (!bCursorSet)
	{
		SetCursor(AfxGetApp()->LoadStandardCursor(IDC_ARROW));
	}

	return true;
}