tileview.cpp

来自「一个另类的坦克大战源程序」· C++ 代码 · 共 142 行

CPP
142
字号
// TileView.cpp : implementation file
//

#include "stdafx.h"
#include "MapEdit.h"
#include "Mainfrm.h"
#include "TileView.h"
#include "MapDoc.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

/////////////////////////////////////////////////////////////////////////////
// CTileView

IMPLEMENT_DYNCREATE(CTileView, CTreeView)

CTileView::CTileView()
{
	//m_CurrentTerrain = INVALID_TERRAIN;
	m_terrain_id=	INVALID_TERRAIN_ID;
	m_obstacle_id = INVALID_OBSTACLE_ID;
	m_TileType =	TT_INVALID;
}

CTileView::~CTileView()
{
}


BEGIN_MESSAGE_MAP(CTileView, CTreeView)
	//{{AFX_MSG_MAP(CTileView)
	ON_NOTIFY_REFLECT(TVN_SELCHANGED, OnSelchanged)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CTileView drawing

void CTileView::OnDraw(CDC* pDC)
{
	CDocument* pDoc = GetDocument();
	// TODO: add draw code here
}

/////////////////////////////////////////////////////////////////////////////
// CTileView diagnostics

#ifdef _DEBUG
void CTileView::AssertValid() const
{
	CTreeView::AssertValid();
}

void CTileView::Dump(CDumpContext& dc) const
{
	CTreeView::Dump(dc);
}
#endif //_DEBUG

/////////////////////////////////////////////////////////////////////////////
// CTileView message handlers

BOOL CTileView::Create(LPCTSTR lpszClassName, LPCTSTR lpszWindowName, DWORD dwStyle, const RECT& rect, CWnd* pParentWnd, UINT nID, CCreateContext* pContext) 
{
	// TODO: Add your specialized code here and/or call the base class
	dwStyle |= TVS_HASLINES|TVS_HASBUTTONS|TVS_LINESATROOT ;	
	return CWnd::Create(lpszClassName, lpszWindowName, dwStyle, rect, pParentWnd, nID, pContext);
}


void CTileView::OnInitialUpdate() 
{
	CTreeView::OnInitialUpdate();
	
	// TODO: Add your specialized code here and/or call the base class
	CMapDoc * pDoc = (CMapDoc*)GetDocument();

	CTreeCtrl& tree = GetTreeCtrl();
	
	tree.DeleteAllItems();
	
	TVINSERTSTRUCT tv;
	HTREEITEM item;

	item=tree.InsertItem("地形");
	tv.hParent = item;
	tv.hInsertAfter = TVI_LAST ;
	tv.item.mask = TVIF_PARAM|TVIF_TEXT ;

	int i=0;
	while(*g_terrain_name_table[i])
	{
		tv.item.pszText = g_terrain_name_table[i];
		tv.item.lParam = g_terrain_id_table[i++].TileID;
		tree.InsertItem(&tv);
	}

	item = tree.InsertItem("物体");
	tv.hParent = item;
	tv.hInsertAfter = TVI_LAST ;
	tv.item.mask = TVIF_PARAM|TVIF_TEXT;

	i=0;
	while(*g_obstacle_name_table[i])
	{
		tv.item.pszText = g_obstacle_name_table[i];
		tv.item.lParam = g_obstacle_id_table[i++];
		tree.InsertItem(&tv);
	}	
}

void CTileView::OnSelchanged(NMHDR* pNMHDR, LRESULT* pResult) 
{
	NM_TREEVIEW* pNMTreeView = (NM_TREEVIEW*)pNMHDR;
	// TODO: Add your control notification handler code here
	CMapDoc * pDoc = (CMapDoc*)GetDocument();
	CTreeCtrl& tree_ctrl = GetTreeCtrl();

	HTREEITEM tree_item = pNMTreeView->itemNew.hItem;
	HTREEITEM parent_item=GetTreeCtrl().GetParentItem(tree_item);
	
	if(parent_item==NULL)
		m_TileType = TT_INVALID;
	else if(tree_ctrl.GetItemText(parent_item)=="地形")
	{
		m_TileType = TT_TERRAIN;
		m_terrain_id.TileID = tree_ctrl.GetItemData(tree_item);
	}
	else if(tree_ctrl.GetItemText(parent_item)=="物体")
	{
		m_TileType = TT_OBSTACLE;
		m_obstacle_id = (OBSTACLE_ID)tree_ctrl.GetItemData(tree_item);
	}

	pDoc->UpdateAllViews(NULL,UPDATE_MINIVIEW);
	*pResult = 0;
}

⌨️ 快捷键说明

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