📄 wizard.cpp
字号:
// Manager.cpp : implementation file
//
#include "stdafx.h"
#include "GsTools.h"
#include "Wizard.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CWizard
CWizard::CWizard()
{
m_hti_root = TVI_ROOT;
m_hti_sys = TVI_ROOT;
m_hti_select_root = TVI_ROOT;
}
CWizard::~CWizard()
{
}
void CWizard::Clear()
{
DeleteAllItems();
m_map_item.clear();
}
BEGIN_MESSAGE_MAP(CWizard, SECTreeCtrl)
//{{AFX_MSG_MAP(CWizard)
// ON_NOTIFY_REFLECT(NM_CLICK, OnClick)
// ON_NOTIFY_REFLECT(NM_DBLCLK, OnDblclk)
ON_NOTIFY_REFLECT(TVN_ITEMEXPANDED, OnItemexpanded)
ON_NOTIFY_REFLECT(TVN_ITEMEXPANDING, OnItemexpanding)
ON_NOTIFY_REFLECT(TVN_ENDLABELEDIT, OnEndlabeledit)
ON_WM_CREATE()
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CWizard message handlers
//void CWizard::OnClick(NMHDR* pNMHDR, LRESULT* pResult)
//{
// // TODO: Add your control notification handler code here
//
// *pResult = 0;
//}
//void CWizard::OnDblclk(NMHDR* pNMHDR, LRESULT* pResult)
//{
// // TODO: Add your control notification handler code here
// //AfxMessageBox(GetItemPath(GetFirstSelectedItem()));
// if(this==g_pWizard /*&& GetCurrentFFT()==TFT_ANIMATION*/)
// {
// g_pMainFrame->ShowControlBar(g_pToolsCtl, g_pToolsCtl->IsEnable(), TRUE);
// }
// *pResult = 0;
//}
void CWizard::OnItemexpanded(NMHDR* pNMHDR, LRESULT* pResult)
{
NM_TREEVIEW* pNMTreeView = (NM_TREEVIEW*)pNMHDR;
// TODO: Add your control notification handler code here
TV_ITEM tvi2, tvi3, _tvi;
tvi2 = pNMTreeView->itemNew;
_tvi.hItem = tvi2.hItem;
_tvi.mask = TVIF_IMAGE;
GetItem(&_tvi);
// if the tree item is expanded and
// current icon == closed folder
// change icon to open folder
if(_tvi.iImage == 0 || _tvi.iImage == 1)
{
if (pNMTreeView->action == TVE_EXPAND)
{
tvi3.hItem = tvi2.hItem;
tvi3.mask = TVIF_IMAGE | TVIF_SELECTEDIMAGE | TVIF_HANDLE;
tvi3.iImage = 1;
tvi3.iSelectedImage = 1;
SetItem(&tvi3);
}
// if the tree item is collapsed and
// current icon == openfolder
// change icon to closedfolder
else /* if ((pNMTreeView->action == TVE_COLLAPSE)&& (_tvi.iImage == m_idiFolderOpen)) */
{
tvi3.hItem = tvi2.hItem;
tvi3.mask = TVIF_IMAGE | TVIF_SELECTEDIMAGE | TVIF_HANDLE;
tvi3.iImage = 0;
tvi3.iSelectedImage = 0;
SetItem(&tvi3);
}
}
*pResult = 0;
}
void CWizard::OnItemexpanding(NMHDR* pNMHDR, LRESULT* pResult)
{
NM_TREEVIEW* pNMTreeView = (NM_TREEVIEW*)pNMHDR;
// TODO: Add your control notification handler code here
*pResult = 0;
}
void CWizard::OnEndlabeledit(NMHDR* pNMHDR, LRESULT* pResult)
{
TV_DISPINFO* pTVDispInfo = (TV_DISPINFO*)pNMHDR;
// TODO: Add your control notification handler code here
*pResult = 0;
}
VOID CWizard::InitImageList()
{
/*
// TODO: create and load your image lists
CBitmap bmp;
// normal tree images
m_tree_icon.Create(16,
16,
TRUE,
8, // number of initial images
8);
ASSERT(m_tree_icon.m_hImageList);
HICON hIcon;
//0 文件夹
hIcon = ::LoadIcon (AfxGetResourceHandle(), MAKEINTRESOURCE(IDI_FOLDER_CLOSE));
ASSERT( hIcon );
m_tree_icon.Add(hIcon);
//1 打开文件夹
hIcon = ::LoadIcon (AfxGetResourceHandle(), MAKEINTRESOURCE(IDI_FOLDER_OPEN));
ASSERT( hIcon );
m_tree_icon.Add(hIcon);
//2 纹理
hIcon = ::LoadIcon (AfxGetResourceHandle(), MAKEINTRESOURCE(IDI_TEXTURE));
ASSERT( hIcon );
m_tree_icon.Add(hIcon);
//3 动画
hIcon = ::LoadIcon (AfxGetResourceHandle(), MAKEINTRESOURCE(IDI_IMAGELIST));
ASSERT( hIcon );
m_tree_icon.Add(hIcon);
//4 音效
hIcon = ::LoadIcon (AfxGetResourceHandle(), MAKEINTRESOURCE(IDI_WAVE));
ASSERT( hIcon );
m_tree_icon.Add(hIcon);
// bmp.LoadBitmap(IDB_PROJWSP);
// m_tree_icon.Add( &bmp, RGB(255,255,255));
// bmp.DeleteObject();
*/
}
VOID CWizard::InitTree()
{
// TODO: load the tree with real data
// AddFile("Graphics\\Textures\\magics\\lighting.tex", GSF_TEX);
// AddFile("Graphics\\Textures\\magics\\fireball.tex", GSF_TEX);
// AddPath("Audios\\music");
m_hti_sys = InsertItem(g_config.GetString("KEY", "system_resource"), 2, 2, TVI_ROOT);
}
int CWizard::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
if (SECTreeCtrl::OnCreate(lpCreateStruct) == -1)
return -1;
// TODO: Add your specialized creation code here
InitImageList();
// add a client edge
ModifyStyleEx( 0, WS_EX_CLIENTEDGE, SWP_NOMOVE | SWP_NOSIZE | SWP_NOZORDER | SWP_FRAMECHANGED);
// set the normal image list. This would cover overlay and selected/expanded images too.
// you will need a separate image list for state images, if you use them.
SetImageList(&g_icon_list_small, TVSIL_NORMAL);
// add a few items, just for example
//InitTree();
return 0;
}
HTREEITEM CWizard::AddPath(const char* szPath)
{
if(szPath==NULL || szPath[0]==0)
return NULL;
char szAddPath[PATH_SIZE];
char szItem[PATH_SIZE];
CGsFunc::Path_RectifyPath(szAddPath, szPath);
HTREEITEM hi = FindPath(szAddPath);
if(hi==NULL)
{
char szTemp[PATH_SIZE];
strcpy(szTemp, szAddPath);
char* sz = strrchr(szTemp, '\\');
if(sz)
{
strcpy(szItem, sz+1);
strcpy(sz,"");
hi = FindPath(szTemp);
}
else
{
strcpy(szItem, szTemp);
hi = m_hti_root;
}
if(hi==NULL)
hi = AddPath(szTemp);
hi = InsertItem(szItem, 0, 0, hi);
RedrawWindow();
szAddPath[strlen(szAddPath)]='\\';
m_map_item.insert(MAP_ITEM::value_type(KEY(szAddPath), t_item(hi, GSF_FOLDER)));
// g_manager.AddFile(szAddPath, TFT_FOLDER);
}
return hi;
}
HTREEITEM CWizard::AddFile(const char* szFile, FFT type)
{
HTREEITEM hi;
if(CGsFunc::Path_IsSysPath(szFile))
{
hi = InsertItem(szFile, GetFFTIcon(type), GetFFTIcon(type), m_hti_sys);
m_map_item.insert(MAP_ITEM::value_type(KEY(szFile), t_item(hi, type)));
}
else
{
if(szFile==NULL || szFile[0]==0)
return NULL;
char szTemp[PATH_SIZE];
char szItem[PATH_SIZE];
char szAddFile[PATH_SIZE];
CGsFunc::Path_RectifyPath(szAddFile, szFile);
strcpy(szTemp, szAddFile);
if(type==GSF_FOLDER)
{
return AddPath(szAddFile);
}
char* sz;
sz = strrchr(szTemp, '\\');
if(sz)
{
strcpy(szItem, sz+1);
strcpy(sz,"");
hi = AddPath(szTemp);
}
else
{
strcpy(szItem, szTemp);
hi = m_hti_root;
}
hi = InsertItem(szItem, GetFFTIcon(type), GetFFTIcon(type), hi);
m_map_item.insert(MAP_ITEM::value_type(KEY(szAddFile), t_item(hi, type)));
// g_manager.AddFile(szAddFile, type);
}
RedrawWindow();
return hi;
}
HTREEITEM CWizard::FindPath(const char* szPath)
{
if(szPath[0]==0)
return m_hti_root;
char szTemp[PATH_SIZE];
CGsFunc::Path_RectifyPath(szTemp, szPath);
szTemp[strlen(szTemp)]='\\';
MAP_ITEM::iterator it = m_map_item.find(KEY(szTemp));
if(it==m_map_item.end())
return NULL;
return it->second.hti;
}
HTREEITEM CWizard::FindFile(const char *szPath)
{
char szTemp[PATH_SIZE];
CGsFunc::Path_RectifyPath(szTemp, szPath);
MAP_ITEM::iterator it = m_map_item.find(KEY(szTemp));
if(it==m_map_item.end())
return m_hti_root;
return it->second.hti;
}
CString CWizard::GetItemPath(HTREEITEM hti)
{
if(hti==m_hti_root || hti==m_hti_sys )
return CString("");
int i1, i2;
GetItemImage(hti, i1, i2);
if(GetParentItem(hti)==TVI_ROOT || GetParentItem(hti)==NULL || GetParentItem(hti)==m_hti_root)
{
if(i1==0 || i1==1)
return GetItemText(hti) + _T("\\");
else
return GetItemText(hti);
}
if(i1==0 || i1==1)
return GetItemPath(GetParentItem(hti))+GetItemText(hti)+_T("\\");
else
return GetItemPath(GetParentItem(hti))+GetItemText(hti);
}
CString CWizard::GetCurrentItemPath()
{
HTREEITEM hti = GetFirstSelectedItem();
return GetItemPath(hti);
}
void CWizard::LoadTree()
{
Clear();
// m_hti_root = InsertItem(g_szWorkData, 2, 2, TVI_ROOT);
//
// MAP_FILE::iterator it = g_manager.m_map.begin();
// while(it!=g_manager.m_map.end())
// {
// AddFile(it->first.c_str(), it->second.type);
// it++;
// }
// Expand(m_hti_root,TVE_EXPAND);
// UpdateSelect();
}
void CWizard::UpdateSelect()
{
if(!g_pMainFrame)
return;
g_pGSEView->SetGame(NULL);
SAFE_DELETE(g_ptr_game);
HTREEITEM hti = GetFirstSelectedItem();
if(hti==NULL || hti == m_hti_root || hti == m_hti_sys)
{
m_hti_select_root = hti;
g_pWork->SetWorkWnd("list_view");
CGsFunc::Path_RectifyPath(g_szWizardPath, "");
g_pWndFolder->UpdateItems();
g_pToolsCtl->UpdateTools();
return;
}
CString str = GetItemPath(hti);
CGsFunc::Path_RectifyPath(g_szWizardPath, str);
switch(GetPathFFT((LPCSTR)str))
{
case GSF_FOLDER:
{
g_pWork->SetWorkWnd("list_view");
g_pWndFolder->UpdateItems();
g_pToolsCtl->UpdateTools();
break;
}
case GSF_TXT:
case GSF_INI:
{
CGsFunc::Path_GetParentPath(g_szWizardPath, (LPCSTR)str);
g_pWork->SetWorkWnd("text_view");
break;
}
case GSF_TEX:
case GSF_JPG:
case GSF_BMP:
case GSF_TGA:
case GSF_PGM:
case GSF_TXG:
case GSF_PGG:
case GSF_DDS:
{
CGsFunc::Path_GetParentPath(g_szWizardPath, (LPCSTR)str);
GSEView* pGSEV = dynamic_cast<GSEView*>(g_pWork->SetWorkWnd("texture_view"));
if(pGSEV==NULL)
return;
g_ptr_game = new GSG_TXG(pGSEV);
pGSEV->SetGame(g_ptr_game);
break;
}
case GSF_WAV:
{
CGsFunc::Path_GetParentPath(g_szWizardPath, (LPCSTR)str);
GSEView* pGSEV = dynamic_cast<GSEView*>(g_pWork->SetWorkWnd("texture_view"));
if(pGSEV==NULL)
return;
g_ptr_game = new GSG_Sound(pGSEV);
pGSEV->SetGame(g_ptr_game);
break;
}
//video type
case GSF_AVI:
case GSF_MPG:
case GSF_MPEG:
case GSF_WMV:
//audio type
case GSF_MP3:
case GSF_MIDI:
case GSF_WMA:
{
CGsFunc::Path_GetParentPath(g_szWizardPath, (LPCSTR)str);
GSEView* pGSEV = dynamic_cast<GSEView*>(g_pWork->SetWorkWnd("texture_view"));
if(pGSEV==NULL)
return;
g_ptr_game = new GSG_Media(pGSEV);
pGSEV->SetGame(g_ptr_game);
break;
}
case GSF_MAP:
{
CGsFunc::Path_GetParentPath(g_szWizardPath, (LPCSTR)str);
GSEView* pGSEV = dynamic_cast<GSEView*>(g_pWork->SetWorkWnd("texture_view"));
if(pGSEV==NULL)
return;
g_ptr_game = new GSG_MapEditor(pGSEV);
pGSEV->SetGame(g_ptr_game);
CControlBar* pBar = g_pMainFrame->GetControlBar(ID_TOOLBAR_MAP);
ASSERT(pBar != NULL);
ASSERT_KINDOF(SECControlBar, pBar);
g_pMainFrame->ShowControlBar(pBar, true, FALSE);
break;
}
case GSF_FNT:
case GSF_FON:
case GSF_TTF:
case GSF_FOT:
break;
default:
{
CGsFunc::Path_GetParentPath(g_szWizardPath, (LPCSTR)str);
g_pWork->SetWorkWnd("text_view");
break;
}
// {
// CGsFunc::Path_GetParentPath(g_szWizardPath, (LPCSTR)str);
// CWnd* pWnd = g_pWork->SetWorkWnd("texture_view");
// //if(pWnd)
// // pWnd->SetFocus();
// CGsFunc::Path_GetParentPath(g_szWizardPath, (LPCSTR)str);
// break;
// }
}
}
BOOL CWizard::SelectPath(const char* szPath)
{
return SelectSetFirstVisible(FindPath(szPath));
}
BOOL CWizard::SelectFile(const char *szPath)
{
return SelectSetFirstVisible(FindFile(szPath));
}
FFT CWizard::GetPathFFT(const char *szPath)
{
MAP_ITEM::iterator it = m_map_item.find(szPath);
if(it!=m_map_item.end())
return it->second.fft;
else
return GSF_UNKNOWN;
}
FFT CWizard::GetCurrentFFT()
{
return GetPathFFT((LPCSTR)GetCurrentItemPath());
}
VOID CWizard::SetRoot(const char *strRoot, BOOL isFolder)
{
Clear();
if(isFolder)
m_hti_root = InsertItem(strRoot, 0, 0, TVI_ROOT);
else
m_hti_root = InsertItem(strRoot, 2, 2, TVI_ROOT);
m_hti_sys = InsertItem(g_config.GetString("KEY", "system_resource"), 2, 2, TVI_ROOT);
}
BOOL CWizard::ExpandFolder(const char *strFolder, UINT nCode)
{
if(strFolder==NULL)
{
return Expand(m_hti_root,nCode);
}
else
{
return Expand(FindPath(strFolder), nCode);
}
}
VOID CWizard::AddItem(const char *strItem, FFT type)
{
AddFile(strItem, type);
}
VOID CWizard::DeleteFile(const char *szPath)
{
char szTemp[PATH_SIZE];
CGsFunc::Path_RectifyPath(szTemp, szPath);
MAP_ITEM::iterator it = m_map_item.find(KEY(szTemp));
if(it!=m_map_item.end())
{
DeleteItem(it->second.hti);
m_map_item.erase(it);
}
}
VOID CWizard::DeleteItems(const char* strItem)
{
MAP_ITEM::iterator it;
CString str;
if(NULL==strItem)
{
str = GetCurrentItemPath();
strItem = (LPCSTR)str;
}
it = m_map_item.find(KEY(strItem));
if(it!=m_map_item.end())
DeleteItem(it->second.hti);
while(it!=m_map_item.end())
{
it = m_map_item.erase(it);
if(it==m_map_item.end() || it->first.find(strItem, 0)!=0 || it->first.at(strlen(strItem))=='\\')
{
break;
}
}
}
BOOL CWizard::HitTestSelectItem()
{
HTREEITEM hti = GetFirstSelectedItem();
if(hti==NULL)
return FALSE;
CRect rc;
GetWindowRect(&rc);
CPoint point;
::GetCursorPos(&point);
point -= rc.TopLeft();
GetItemRect(hti, &rc, LVIR_LABEL );
CRect rc1;
// if(rc.PtInRect(point))
// return TRUE;
GetItemRect(hti, &rc1, LVIR_ICON );
// if(rc1.PtInRect(point))
// return TRUE;
rc.left = rc1.left;
return rc.PtInRect(point);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -