xywnd.cpp

来自「quake3工具源码。包括生成bsp文件」· C++ 代码 · 共 2,569 行 · 第 1/5 页

CPP
2,569 行
字号
			  qglVertex3fv (g_Clip2);
      if (g_Clip3.Set())
			  qglVertex3fv (g_Clip3);
		  qglEnd ();
		  qglPointSize (1);

      CString strMsg;
      if (g_Clip1.Set())
      {
        qglRasterPos3f (g_Clip1.m_ptClip[0]+2, g_Clip1.m_ptClip[1]+2, g_Clip1.m_ptClip[2]+2);
        strMsg = "1";
        //strMsg.Format("1 (%f, %f, %f)", g_Clip1[0], g_Clip1[1], g_Clip1[2]);
	      qglCallLists (strMsg.GetLength(), GL_UNSIGNED_BYTE, strMsg);
      }
      if (g_Clip2.Set())
      {
        qglRasterPos3f (g_Clip2.m_ptClip[0]+2, g_Clip2.m_ptClip[1]+2, g_Clip2.m_ptClip[2]+2);
        strMsg = "2";
        //strMsg.Format("2 (%f, %f, %f)", g_Clip2[0], g_Clip2[1], g_Clip2[2]);
	      qglCallLists (strMsg.GetLength(), GL_UNSIGNED_BYTE, strMsg);
      }
      if (g_Clip3.Set())
      {
        qglRasterPos3f (g_Clip3.m_ptClip[0]+2, g_Clip3.m_ptClip[1]+2, g_Clip3.m_ptClip[2]+2);
        strMsg = "3";
        //strMsg.Format("3 (%f, %f, %f)", g_Clip3[0], g_Clip3[1], g_Clip3[2]);
	      qglCallLists (strMsg.GetLength(), GL_UNSIGNED_BYTE, strMsg);
      }
      if (g_Clip1.Set() && g_Clip2.Set())
      {
        ProduceSplitLists();
        brush_t* pBrush;
        brush_t* pList = ( (m_nViewType == XZ) ? !g_bSwitch : g_bSwitch) ? &g_brBackSplits : &g_brFrontSplits;
	      for (pBrush = pList->next ; pBrush != NULL && pBrush != pList ; pBrush=pBrush->next)
        {
		      qglColor3f (1,1,0);
	        face_t *face;
	        int order;
	        for (face = pBrush->brush_faces,order = 0 ; face ; face=face->next, order++)
	        {
		        winding_t* w = face->face_winding;
		        if (!w)
			        continue;
		        // draw the polygon
		        qglBegin(GL_LINE_LOOP);
            for (int i=0 ; i<w->numpoints ; i++)
		          qglVertex3fv(w->points[i]);
		        qglEnd();
	        }
        }
      }

    }



    if (PathMode())
    {
      qglPointSize (4);
		  qglColor3fv(g_qeglobals.d_savedinfo.colors[COLOR_CLIPPER]);
		  qglBegin (GL_POINTS);

      for (int n = 0; n < g_nPathCount; n++)
        qglVertex3fv(g_PathPoints[n]);
		  qglEnd ();
		  qglPointSize (1);

      CString strMsg;
      for (n = 0; n < g_nPathCount; n++)
      {
        qglRasterPos3f (g_PathPoints[n].m_ptClip[0]+2, g_PathPoints[n].m_ptClip[1]+2, g_PathPoints[n].m_ptClip[2]+2);
        strMsg.Format("%i", n+1);
	      qglCallLists (strMsg.GetLength(), GL_UNSIGNED_BYTE, strMsg);
      }

    }
    if (m_nViewType != XY)
      qglPopMatrix();

		qwglSwapBuffers(dc.m_hDC);
    TRACE("XY Paint\n");
  }
 }

void CXYWnd::OnKeyDown(UINT nChar, UINT nRepCnt, UINT nFlags) 
{
  g_pParentWnd->HandleKey(nChar, nRepCnt, nFlags);
}



// FIXME: the brush_t *pBrush is never used. ( Entity_Create uses selected_brushes )
void CreateEntityFromName(char* pName, brush_t* pBrush)
{
	eclass_t *pecNew;
	entity_t *petNew;
	if (stricmp(pName, "worldspawn") == 0)
	{
		MessageBox(g_qeglobals.d_hwndMain, "Can't create an entity with worldspawn.", "info", 0);
		return;
	}
	
	pecNew = Eclass_ForName(pName, false);
	
	// create it
	petNew = Entity_Create(pecNew);
	if (petNew == NULL)
	{
		if (!((selected_brushes.next == &selected_brushes)||(selected_brushes.next->next != &selected_brushes)))
		{
			brush_t* b = selected_brushes.next;
			if (b->owner != world_entity && b->owner->eclass->fixedsize && pecNew->fixedsize)
			{
				vec3_t mins, maxs;
				vec3_t origin;
				for (int i=0 ; i<3 ; i++)
					origin[i] = b->mins[i] - pecNew->mins[i];
				
				VectorAdd (pecNew->mins, origin, mins);
				VectorAdd (pecNew->maxs, origin, maxs);
				brush_t* nb = Brush_Create (mins, maxs, &pecNew->texdef);
				Entity_LinkBrush (b->owner, nb);
				nb->owner->eclass = pecNew;
				SetKeyValue (nb->owner, "classname", pName);
				Brush_Free(b);
				Brush_Build(nb);
				Brush_AddToList (nb, &active_brushes);
				Select_Brush(nb);
				return;
			}
		}
		MessageBox(g_qeglobals.d_hwndMain, "Failed to create entity.", "info", 0);
		return;
	}
	
	Select_Deselect ();
	//entity_t* pEntity = world_entity;
	//if (selected_brushes.next != &selected_brushes)
	//	pEntity = selected_brushes.next->owner;
	Select_Brush (petNew->brushes.onext);
	
	if (stricmp(pName, "misc_model") == 0)
	{
		SetInspectorMode(W_ENTITY);
		PostMessage(g_qeglobals.d_hwndEntity, WM_COMMAND, IDC_BTN_ASSIGNMODEL, 0);
	}
	
}


brush_t* CreateEntityBrush(int x, int y, CXYWnd* pWnd)
{
	vec3_t	mins, maxs;
	int		i;
	float	temp;
	brush_t	*n;

	pWnd->SnapToPoint (x, y, mins);
  x += 32;
  y += 32;
	pWnd->SnapToPoint (x, y, maxs);

  int nDim = (pWnd->GetViewType() == XY) ? 2 : (pWnd->GetViewType() == YZ) ? 0 : 1;
	mins[nDim] = g_qeglobals.d_gridsize * ((int)(g_qeglobals.d_new_brush_bottom_z/g_qeglobals.d_gridsize));
	maxs[nDim] = g_qeglobals.d_gridsize * ((int)(g_qeglobals.d_new_brush_top_z/g_qeglobals.d_gridsize));

  if (maxs[nDim] <= mins[nDim])
		maxs[nDim] = mins[nDim] + g_qeglobals.d_gridsize;

	for (i=0 ; i<3 ; i++)
	{
		if (mins[i] == maxs[i])
			maxs[i] += 16;	// don't create a degenerate brush
		if (mins[i] > maxs[i])
		{
			temp = mins[i];
			mins[i] = maxs[i];
			maxs[i] = temp;
		}
	}

	n = Brush_Create (mins, maxs, &g_qeglobals.d_texturewin.texdef);
	if (!n)
		return NULL;

	Brush_AddToList (n, &selected_brushes);
	Entity_LinkBrush (world_entity, n);
	Brush_Build( n );
  return n;
}

void CreateRightClickEntity(CXYWnd* pWnd, int x, int y, char* pName)
{
  CRect rctZ;
  pWnd->GetClientRect(rctZ);
  brush_t* pBrush = (selected_brushes.next == &selected_brushes) ? CreateEntityBrush(x, rctZ.Height() - 1 - y, pWnd) : selected_brushes.next;
  CreateEntityFromName(pName, pBrush);
  //Select_Brush(pBrush);
}

brush_t* CreateSmartBrush(vec3_t v)
{
	vec3_t	mins, maxs;
	int		i;
	brush_t	*n;

	for (i=0 ; i<3 ; i++)
	{
    mins[i] = v[i] - 16;
    maxs[i] = v[i] + 16;
  }

	n = Brush_Create (mins, maxs, &g_qeglobals.d_texturewin.texdef);
	if (!n)
		return NULL;

	Brush_AddToList(n, &selected_brushes);
	//Entity_LinkBrush(world_entity, n);
	Brush_Build(n);
  return n;
}




CString g_strSmartEntity;
int g_nSmartX;
int g_nSmartY;
bool g_bSmartWaiting;
void _SmartPointDone(bool b, int n)
{
  g_bSmartWaiting = false;
}

void CreateSmartEntity(CXYWnd* pWnd, int x, int y, const char* pName)
{
  g_nSmartX = x;
  g_nSmartY = y;
  g_strSmartEntity = pName;
  if (g_strSmartEntity.Find("Smart_Train") >= 0)
  {
    ShowInfoDialog("Select the path of the train by left clicking in XY, YZ and/or XZ views. You can move an already dropped point by grabbing and moving it. When you are finished, press ENTER to accept and create the entity and path(s), press ESC to abandon the creation");
    g_bPathMode = true;
    g_nPathLimit = 0;
    g_nPathCount = 0;
    g_bSmartGo = true;
  }
  else
  if (g_strSmartEntity.Find("Smart_Monster...") >= 0)
  {
    g_bPathMode = true;
    g_nPathLimit = 0;
    g_nPathCount = 0;
  }
  else
  if (g_strSmartEntity.Find("Smart_Rotating") >= 0)
  {
    g_bSmartWaiting = true;
    ShowInfoDialog("Left click to specify the rotation origin");
    AcquirePath(1, &_SmartPointDone);
    while (g_bSmartWaiting)
    {
      MSG msg;
      if (::PeekMessage( &msg, NULL, 0, 0, PM_REMOVE )) 
      { 
        TranslateMessage(&msg);
        DispatchMessage(&msg);
      }
    }
    HideInfoDialog();
    CPtrArray array;
    g_bScreenUpdates = false;
    CreateRightClickEntity(g_pParentWnd->ActiveXY(), g_nSmartX, g_nSmartY, "func_rotating");
    array.Add(reinterpret_cast<void*>(selected_brushes.next));
    Select_Deselect();
    brush_t* pBrush = CreateSmartBrush(g_PathPoints[0]);
    array.Add(pBrush);
    Select_Deselect();
    Select_Brush(reinterpret_cast<brush_t*>(array.GetAt(0)));
    Select_Brush(reinterpret_cast<brush_t*>(array.GetAt(1)));
    ConnectEntities();
    g_bScreenUpdates = true;
  }
}


void FinishSmartCreation()
{
  CPtrArray array;
  HideInfoDialog();
  brush_t* pEntities = NULL;
  if (g_strSmartEntity.Find("Smart_Train") >= 0)
  {
    g_bScreenUpdates = false;
    CreateRightClickEntity(g_pParentWnd->ActiveXY(), g_nSmartX, g_nSmartY, "func_train");
    array.Add(reinterpret_cast<void*>(selected_brushes.next));
    for (int n = 0; n < g_nPathCount; n++)
    {
      Select_Deselect();
      CreateRightClickEntity(g_pParentWnd->ActiveXY(), g_PathPoints[n].m_ptScreen.x,g_PathPoints[n].m_ptScreen.y, "path_corner");
      array.Add(reinterpret_cast<void*>(selected_brushes.next));
    }

    for (n = 0; n < g_nPathCount; n++)
    {
      Select_Deselect();
      Select_Brush(reinterpret_cast<brush_t*>(array.GetAt(n)));
      Select_Brush(reinterpret_cast<brush_t*>(array.GetAt(n+1)));
      ConnectEntities();
    }
    g_bScreenUpdates = true;

  }
  g_nPathCount = 0;
  g_bPathMode = false;
  Sys_UpdateWindows(W_ALL);
}

void CXYWnd::KillPathMode()
{
  g_bSmartGo = false;
  g_bPathMode = false;
  if (g_pPathFunc)
    g_pPathFunc(false, g_nPathCount);
  g_nPathCount = 0;
  g_pPathFunc = NULL;
  Sys_UpdateWindows(W_ALL);
}

// gets called for drop down menu messages
// TIP: it's not always about EntityCreate
void CXYWnd::OnEntityCreate(unsigned int nID) 
{
  if (m_mnuDrop.GetSafeHmenu())
  {
    CString strItem;
    m_mnuDrop.GetMenuString(nID, strItem, MF_BYCOMMAND);

		if (strItem.CompareNoCase("Add to...") == 0)
		{
			//++timo TODO: fill the menu with current groups?
			// this one is for adding to existing groups only
			Sys_Printf("TODO: Add to... in CXYWnd::OnEntityCreate\n");
		}
		else if (strItem.CompareNoCase("Remove") == 0)
		{
			// remove selected brushes from their current group
			brush_t *b;
			for( b = selected_brushes.next; b != &selected_brushes; b = b->next )
			{
				
			}
		}

		//++timo FIXME: remove when all hooks are in
		if (strItem.CompareNoCase("Add to...") == 0
			|| strItem.CompareNoCase("Remove") == 0
			|| strItem.CompareNoCase("Name...") == 0
			|| strItem.CompareNoCase("New group...") == 0)
		{
			Sys_Printf("TODO: hook drop down group menu\n");
			return;
		}
		
    if (strItem.Find("Smart_") >= 0)
    {
      CreateSmartEntity(this, m_ptDown.x, m_ptDown.y, strItem);
    }
    else
    {
      CreateRightClickEntity(this, m_ptDown.x, m_ptDown.y, strItem.GetBuffer(0));
    }
		
    Sys_UpdateWindows(W_ALL);
    //OnLButtonDown((MK_LBUTTON | MK_SHIFT), CPoint(m_ptDown.x+2, m_ptDown.y+2));
  }
}


void CXYWnd::HandleDrop()
{
  if (g_PrefsDlg.m_bRightClick == false)
    return;
  if (!m_mnuDrop.GetSafeHmenu()) // first time, load it up
  {
    m_mnuDrop.CreatePopupMenu();
    int nID = ID_ENTITY_START;

    CMenu* pChild2 = new CMenu;
    pChild2->CreateMenu();
    pChild2->AppendMenu(MF_STRING, ID_SELECTION_SELECTCOMPLETETALL, "Select Complete Tall");
    pChild2->AppendMenu(MF_STRING, ID_SELECTION_SELECTTOUCHING, "Select Touching");
    pChild2->AppendMenu(MF_STRING, ID_SELECTION_SELECTPARTIALTALL, "Select Partial Tall");
    pChild2->AppendMenu(MF_STRING, ID_SELECTION_SELECTINSIDE, "Select Inside");
    m_mnuDrop.AppendMenu(MF_POPUP, reinterpret_cast<unsigned int>(pChild2->GetSafeHmenu()), "Select");
    m_mnuDrop.AppendMenu(MF_SEPARATOR, nID++, "");

    CMenu* pChild3 = new CMenu;
    pChild3->CreateMenu();
    pChild3->AppendMenu(MF_STRING, ID_DROP_GROUP_ADDTO, "Add to...");
    pChild3->AppendMenu(MF_STRING, ID_DROP_GROUP_REMOVE, "Remove");
    pChild3->AppendMenu(MF_STRING, ID_DROP_GROUP_NAME, "Name...");
    pChild3->AppendMenu(MF_SEPARATOR, nID++, "");
    pChild3->AppendMenu(MF_STRING, ID_DROP_GROUP_NEWGROUP, "New Group...");
    m_mnuDrop.AppendMenu(MF_POPUP, reinterpret_cast<unsigned int>(pChild3->GetSafeHmenu()), "Group");
    m_mnuDrop.AppendMenu(MF_SEPARATOR, nID++, "");

    m_mnuDrop.AppendMenu(MF_STRING, ID_SELECTION_UNGROUPENTITY, "Ungroup Entity");
    m_mnuDrop.AppendMenu(MF_STRING, ID_SELECTION_MAKE_DETAIL, "Make Detail");
    m_mnuDrop.AppendMenu(MF_STRING, ID_SELECTION_MAKE_STRUCTURAL, "Make Structural");
    m_mnuDrop.AppendMenu(MF_SEPARATOR, nID++, "");

    CMenu* pChild = new CMenu;
    pChild->CreateMenu();
    pChild->AppendMenu(MF_STRING, nID++, "Smart_Train");
    //pChild->AppendMenu(MF_STRING, nID++, "Smart_Rotating");
    m_mnuDrop.AppendMenu(MF_POPUP, reinterpret_cast<unsigned int>(pChild->GetSafeHmenu()), "Smart Entities");
    m_mnuDrop.AppendMenu(MF_SEPARATOR, nID++, "");

    pChild = NULL;
	  eclass_t	*e;
    CString strActive;
    CString strLast;
    CString strName;
	  for (e=eclass ; e ; e=e->next)
    {
      strLast = strName;
      strName = e->name;
      int n_ = strName.Find("_");
      if (n_ > 0)
      {
        CString strLeft = strName.Left(n_);
        CString strRight = strName.Right(strName.GetLength() - n_ - 1);
        if (strLeft == strActive) // this is a child
        {
          ASSERT(pChild);
          pChild->AppendMenu(MF_STRING, nID++, strName);
        }
        else
        {
          if (pChild)
          {
            m_mnuDrop.AppendMenu(MF_POPUP, reinterpret_cast<unsigned int>(pChild->GetSafeHmenu()), strActive);
            g_ptrMenus.Add(pChild);
            //pChild->DestroyMenu();
            //delete pChild;
            pChild = NULL;
          }
          strActive = strLeft;
          pChild = new CMenu;
          pChild->CreateMenu();
          pChild->AppendMenu(MF_STRING, nID++, strName);
        }
      }
      else
      {
        if (pChild)
        {
          m_mnuDrop.AppendMenu(MF_POPUP, reinterpret_cast<unsigned int>(pChild->GetSafeHmenu()), strActive);
          g_ptrMenus.Add(pChild);
          //pChild->DestroyMenu();
          //delete pChild;
          pChild = NULL;
        }
        strActive = "";
        m_mnuDrop.AppendMenu(MF_STRING, nID++, strName);
      }
    }
  }

  CPoint ptMouse;
  GetCursorPos(&ptMouse);
  m_mnuDrop.TrackPopupMenu(TPM_LEFTALIGN | TPM_LEFTBUTTON | TPM_RIGHTBUTTON, ptMouse.x, ptMouse.y, this);
}

void CXYWnd::XY_Init()
{
	m_vOrigin[0] = 0;
	m_vOrigin[1] = 20;
  m_vOrigin[2] = 46;
  m_fScale = 1;
}

void CXYWnd::SnapToPoint (int x, int y, vec3_t point)
{
  if (g_PrefsDlg.m_bNoClamp)
  {
    XY_ToPoint(x, y, point);
  }
  else
  {
    XY_ToGridPoint(x, y, point);
  }
//--  else
//--    XY_ToPoint(x, y, point);
//--    //XY_ToPoint(x, y, point);
}


void CXYWnd::XY_ToPoint (int x, int y, vec3_t point)
{
  float fx = x;
  float fy = y;
  float fw = m_nWidth;
  float fh = m_nHeight;
  if (m_nViewType == XY)
  {
	  point[0] = m_vOrigin[0] + (fx - fw / 2) / m_fScale;
	  point[1] = m_vOrigin[1] + (fy - fh / 2) / m_fScale;
	  //point[2] = 0;
  }
  else if (m_nViewType == YZ)
  {
    ////point[0] = 0;

⌨️ 快捷键说明

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