Пример #1
0
void GenerateTopologyMap (CUniverse &Universe, CXMLElement *pCmdLine)
	{
	int i, j;

	STopologyMapCtx Ctx;

	//	Initialize the output

	COutputChart Output;
	Output.SetStyleFont(STYLE_NAME, pCmdLine->GetAttribute(CONSTLIT("font")));
	Output.SetStyleColor(STYLE_NAME, CG32bitPixel(0xFF, 0xFF, 0xFF));

	Output.SetOutputFilespec(pCmdLine->GetAttribute(CONSTLIT("output")));

	//	Get the topology node

	CTopologyNode *pFirstNode = Universe.GetFirstTopologyNode();
	if (pFirstNode == NULL)
		{
		printf("ERROR: Unable to find topology node.\n");
		return;
		}

	//	Get the system map for the node

	Ctx.pMap = pFirstNode->GetDisplayPos();
	if (Ctx.pMap == NULL)
		{
		printf("ERROR: No system map for node %s.\n", pFirstNode->GetID().GetASCIIZPointer());
		return;
		}

	//	Create a background image

	CG32bitImage *pImage = Ctx.pMap->CreateBackgroundImage();

	//	Create the output

	Output.SetContentSize((pImage ? pImage->GetWidth() : 1024), (pImage ? pImage->GetHeight() : 1024));
	CG32bitImage &Dest = Output.GetOutputImage();

	//	Blt

	if (pImage)
		Dest.Blt(0, 0, pImage->GetWidth(), pImage->GetHeight(), *pImage, 0, 0);

	//	Done with background image

	delete pImage;
	pImage = NULL;

	//	Compute the size of the map (in pixels)

	Ctx.cxMap = Dest.GetWidth();
	Ctx.cyMap = Dest.GetHeight();
	Ctx.xCenter = Ctx.cxMap / 2;
	Ctx.yCenter = Ctx.cyMap / 2;

	//	Loop over all nodes and clear marks on the ones that we need to draw

	for (i = 0; i < Universe.GetTopologyNodeCount(); i++)
		{
		CTopologyNode *pNode = Universe.GetTopologyNode(i);
			
		int xPos, yPos;
		pNode->SetMarked(pNode->GetDisplayPos(&xPos, &yPos) != Ctx.pMap 
				|| pNode->IsEndGame());
		}

	//	Paint the nodes

	for (i = 0; i < Universe.GetTopologyNodeCount(); i++)
		{
		CTopologyNode *pNode = Universe.GetTopologyNode(i);
		if (!pNode->IsMarked())
			{
			int xPos, yPos;
			pNode->GetDisplayPos(&xPos, &yPos);

			//	Convert to view coordinates

			int x = Ctx.xCenter + xPos;
			int y = Ctx.yCenter - yPos;

			//	Draw gate connections

			for (j = 0; j < pNode->GetStargateCount(); j++)
				{
				CTopologyNode *pDestNode = pNode->GetStargateDest(j);
				if (pDestNode && !pDestNode->IsMarked())
					{
					int xPos, yPos;
					pDestNode->GetDisplayPos(&xPos, &yPos);

					int xDest = Ctx.xCenter + xPos;
					int yDest = Ctx.yCenter - yPos;

					Dest.DrawLine(x, y, xDest, yDest, STARGATE_LINE_WIDTH, STARGATE_LINE_COLOR);
					}
				}

			//	Draw star system

			DrawNode(Ctx, Output, pNode, x, y);

			pNode->SetMarked();
			}
		}

	//	Done

	Output.Output();
	}
Пример #2
0
ALERROR CGalacticMapSession::OnInit (CString *retsError)

//	OnInit
//
//	Initialize

	{
	const CVisualPalette &VI = m_HI.GetVisuals();
	const CG16bitFont &HeaderFont = VI.GetFont(fontHeader);
	const CG16bitFont &MediumFont = VI.GetFont(fontMedium);

    //  Refresh global objects

    if (g_pUniverse->GetCurrentSystem())
        g_pUniverse->GetGlobalObjects().Refresh(g_pUniverse->GetCurrentSystem());

	//	Compute some rects

    GetRect(m_rcView);

	//	Get the map

	CTopologyNode *pNode = g_pUniverse->GetCurrentTopologyNode();
	if (pNode == NULL)
		return NOERROR;

	m_pMap = pNode->GetDisplayPos(&m_xCenter, &m_yCenter);
	if (m_pMap == NULL)
		return NOERROR;

	//	Get basic map information

    int iScale;
    int iMinScale;
    int iMaxScale;
	m_pMap->GetScale(&iScale, &iMinScale, &iMaxScale);

    //  If we've got saved state, use that

    if (m_SavedState.iScale != 0)
        {
        iScale = m_SavedState.iScale;
        m_xCenter = m_SavedState.xCenter;
        m_yCenter = m_SavedState.yCenter;
        }

    //  Initialize

    m_Scale.Init(iScale, iMinScale, iMaxScale);

	//	Create a painter

	m_pPainter = new CGalacticMapPainter(m_HI.GetVisuals(), m_pMap, m_SystemMapThumbnails);
    m_pPainter->SetViewport(m_rcView);
    m_pPainter->SetScale(m_Scale.GetScale());

	//	Adjust the map position so we fit

	m_pPainter->AdjustCenter(m_xCenter, m_yCenter, m_Scale.GetTargetScale(), &m_xCenter, &m_yCenter);
    m_pPainter->SetPos(m_xCenter, m_yCenter);

    //  Initialize help pane

    m_HelpPainter.SetWidth(HELP_PANE_WIDTH);
    m_HelpPainter.SetTitle(m_pMap->GetName());
    m_HelpPainter.SetDesc(STR_HELP_DESC);

	//	Initialize animation

	m_xTargetCenter = m_xCenter;
	m_yTargetCenter = m_yCenter;
    SetTargetScale();

    //  Select something (but only if we're in the same node)

    if (m_SavedState.pSelected
            && pNode == m_SavedState.pCurNode)
        Select(m_SavedState.pSelected);
    else
        m_SavedState.pSelected = NULL;

    //  Remember our current node

    m_SavedState.pCurNode = pNode;

	return NOERROR;
	}
Пример #3
0
void CGalacticMapSession::OnKeyDown (int iVirtKey, DWORD dwKeyData)

//	OnKeyDown
//
//	KeyDown

	{
	switch (iVirtKey)
		{
		case 'C':
			if (uiIsControlDown() && m_pPainter)
				::CopyGalacticMapToClipboard(m_HI.GetHWND(), m_pPainter);
			break;

		case VK_ADD:
		case VK_OEM_PLUS:
            if (m_Scale.CanZoomIn())
                {
				g_pUniverse->PlaySound(NULL, g_pUniverse->FindSound(UNID_DEFAULT_SELECT));
                m_Scale.ZoomIn();
                SetTargetScale();
                }
			break;

		case VK_CONTROL:
			break;

		case VK_DOWN:
			m_pPainter->AdjustCenter(m_xCenter, m_yCenter - (100 * SCROLL_STEP / m_Scale.GetTargetScale()), m_Scale.GetTargetScale(), &m_xTargetCenter, &m_yTargetCenter);
			break;

        case VK_ESCAPE:
            SaveState();
			m_HI.ClosePopupSession();
            break;

		case VK_HOME:
		case VK_END:
			{
			CTopologyNode *pNode = g_pUniverse->GetCurrentTopologyNode();
			if (pNode)
				{
				pNode->GetDisplayPos(&m_xTargetCenter, &m_yTargetCenter);
				m_pPainter->AdjustCenter(m_xTargetCenter, m_yTargetCenter, m_Scale.GetTargetScale(), &m_xTargetCenter, &m_yTargetCenter);
				}
			break;
			}

		case VK_LEFT:
			m_pPainter->AdjustCenter(m_xCenter - (100 * SCROLL_STEP / m_Scale.GetTargetScale()), m_yCenter, m_Scale.GetTargetScale(), &m_xTargetCenter, &m_yTargetCenter);
			break;

		case VK_NEXT:
			m_pPainter->AdjustCenter(m_xCenter, m_yCenter - (300 * SCROLL_STEP / m_Scale.GetTargetScale()), m_Scale.GetTargetScale(), &m_xTargetCenter, &m_yTargetCenter);
			break;

		case VK_PRIOR:
			m_pPainter->AdjustCenter(m_xCenter, m_yCenter + (300 * SCROLL_STEP / m_Scale.GetTargetScale()), m_Scale.GetTargetScale(), &m_xTargetCenter, &m_yTargetCenter);
			break;

		case VK_RIGHT:
			m_pPainter->AdjustCenter(m_xCenter + (100 * SCROLL_STEP / m_Scale.GetTargetScale()), m_yCenter, m_Scale.GetTargetScale(), &m_xTargetCenter, &m_yTargetCenter);
			break;

		case VK_SUBTRACT:
		case VK_OEM_MINUS:
            if (m_Scale.CanZoomOut())
                {
				g_pUniverse->PlaySound(NULL, g_pUniverse->FindSound(UNID_DEFAULT_SELECT));
                m_Scale.ZoomOut();
                SetTargetScale();
                }
            break;

		case VK_UP:
			m_pPainter->AdjustCenter(m_xCenter, m_yCenter + (100 * SCROLL_STEP / m_Scale.GetTargetScale()), m_Scale.GetTargetScale(), &m_xTargetCenter, &m_yTargetCenter);
			break;
		}
	}
Пример #4
0
void GenerateTopologyMap (CUniverse &Universe, CXMLElement *pCmdLine)
	{
	int i;

	//	Some parameters

	int iScale = pCmdLine->GetAttributeIntegerBounded(CONSTLIT("scale"), 100, -1, -1);

	//	We need to create all systems so that the global object table is 
	//	initialized.

	for (i = 0; i < Universe.GetTopologyNodeCount(); i++)
		{
		CTopologyNode *pNode = Universe.GetTopologyNode(i);

		//	Do not try to create end game nodes

		if (pNode->IsEndGame())
			continue;

		//	Node is known

		pNode->SetKnown();

		//	Create this system

		CSystem *pNewSystem;
		CString sError;
		if (Universe.CreateStarSystem(pNode, &pNewSystem, &sError) != NOERROR)
			{
			printf("ERROR: creating system %s: %s\n", (LPSTR)pNode->GetSystemName(), (LPSTR)sError);
			continue;
			}

		//	Delete the system

		Universe.FlushStarSystem(pNode);
		}

	//	Initialize the output

	COutputChart Output;
	Output.SetStyleFont(STYLE_NAME, pCmdLine->GetAttribute(CONSTLIT("font")));
	Output.SetStyleColor(STYLE_NAME, CG32bitPixel(0xFF, 0xFF, 0xFF));

	Output.SetOutputFilespec(pCmdLine->GetAttribute(CONSTLIT("output")));

	//	Get the topology node

	CTopologyNode *pFirstNode = Universe.GetFirstTopologyNode();
	if (pFirstNode == NULL)
		{
		printf("ERROR: Unable to find topology node.\n");
		return;
		}

	//	Get the system map for the node

	CSystemMap *pMap = pFirstNode->GetDisplayPos();
	if (pMap == NULL)
		{
		printf("ERROR: No system map for node %s.\n", pFirstNode->GetID().GetASCIIZPointer());
		return;
		}

	//	If we didn't set a scale, use the map's initial scale

	if (iScale == -1)
		pMap->GetScale(&iScale);

	//	Initialize painting structures

	CSystemMapThumbnails Thumbs;
	Thumbs.Init(Universe.GetGlobalObjects());

	CGalacticMapPainter Painter(Universe, pMap, Thumbs);
	int cxMap = Painter.GetWidth() * iScale / 100;
	int cyMap = Painter.GetHeight() * iScale / 100;

	//	Compute the size of the map

	RECT rcView;
	rcView.left = 0;
	rcView.top = 0;
	rcView.right = cxMap;
	rcView.bottom = cyMap;

	//	Create the output

	Output.SetContentSize(cxMap, cyMap);
	CG32bitImage &Dest = Output.GetOutputImage();

	//	Paint

    Painter.SetViewport(rcView);
    Painter.SetScale(iScale);
    Painter.SetPos(0, 0);
	Painter.Paint(Dest);

	//	Done

	Output.Output();
	}