
WndWiki.cpp:
Code:
#include "stdafx.h"
#ifdef __WIKI
#include "WndWiki.h"
#include "resdata.h"
#include "DPClient.h"
#ifdef __MODEL_VIEW
#include "WndModelView.h"
#endif
extern CDPClient g_DPlay;
DWORD WINAPI __SortThread(LPVOID lpParam)
{
CWndWiki *pWiki = (CWndWiki*)lpParam;
pWiki->Sort();
return 0;
}
CWndWiki::CWndWiki()
{
m_vecItems.clear();
m_bUpperCase = false;
m_cSortType = 0;
m_hSortThread = INVALID_HANDLE_VALUE;
m_pCreate = NULL;
}
CWndWiki::~CWndWiki()
{
m_vecItems.clear();
TerminateThread(m_hSortThread,0);
SAFE_DELETE(m_pCreate);
}
BOOL CWndWiki::Initialize(CWndBase *pWndParent, DWORD dwStyle)
{
return CWndNeuz::InitDialog(g_Neuz.GetSafeHwnd(),APP_WIKI,0,0,pWndParent);
}
void CWndWiki::OnInitialUpdate()
{
CWndNeuz::OnInitialUpdate();
m_pListItems = (CWndListBox*)GetDlgItem(WIDC_LISTBOX1);
m_pComboKind = (CWndComboBox*)GetDlgItem(WIDC_COMBOBOX1);
m_pComboJob = (CWndComboBox*)GetDlgItem(WIDC_COMBOBOX2);
m_pEditFilter = (CWndEdit*)GetDlgItem(WIDC_EDIT1);
int nIdx = 0;
for( int i = 0; i < MAX_JOB; ++i )
{
if( i == JOB_PUPPETEER || i == JOB_DOPPLER || i == JOB_GATEKEEPER )
continue;
nIdx = m_pComboJob->AddString(prj.m_aJob[i].szName);
m_pComboJob->SetItemData(nIdx,i);
}
m_pComboJob->SetCurSel(0);
nIdx = m_pComboKind->AddString("All");
m_pComboKind->SetItemData(nIdx,NULL_ID);
nIdx = m_pComboKind->AddString("Weapon");
m_pComboKind->SetItemData(nIdx,IK1_WEAPON);
nIdx = m_pComboKind->AddString("Armor");
m_pComboKind->SetItemData(nIdx,IK1_ARMOR);
nIdx = m_pComboKind->AddString("Ride");
m_pComboKind->SetItemData(nIdx,IK1_RIDE);
nIdx = m_pComboKind->AddString("Furniture");
m_pComboKind->SetItemData(nIdx,IK1_HOUSING);
m_pComboKind->SetCurSel(0);
UpdateList();
MoveParentCenter();
}
BOOL CWndWiki::OnChildNotify(UINT message, UINT nID, LRESULT *pLResult)
{
if( message == WNM_CLICKED )
{
switch( nID )
{
case WIDC_BUTTON2:
{
TerminateThread(m_hSortThread,0);
m_cSortType = 0;
m_bUpperCase = !m_bUpperCase;
m_hSortThread = CreateThread(0,0,__SortThread,this,0,0);
}
break;
case WIDC_BUTTON3:
{
TerminateThread(m_hSortThread,0);
m_cSortType = 1;
m_bUpperCase = !m_bUpperCase;
m_hSortThread = CreateThread(0,0,__SortThread,this,0,0);
}
break;
case WIDC_BUTTON4:
{
TerminateThread(m_hSortThread,0);
m_cSortType = 2;
m_bUpperCase = !m_bUpperCase;
m_hSortThread = CreateThread(0,0,__SortThread,this,0,0);
}
break;
case WIDC_BUTTON1:
{
UpdateList();
}
break;
}
}
else if( message == WNM_SELCHANGE )
{
if( nID == WIDC_COMBOBOX1 || nID == WIDC_COMBOBOX2 )
UpdateList();
}
else if( message == EN_CHANGE )
{
if( nID == WIDC_EDIT1 )
UpdateList();
}
else if( message == WNM_DBLCLK )
{
if( nID == WIDC_LISTBOX1 )
{
#ifdef __MODEL_VIEW
if( m_pListItems->GetCurSel() != -1 )
{
if( g_pPlayer->m_dwAuthorization >= AUTH_ADMINISTRATOR && GetAsyncKeyState(VK_SHIFT) & 0x8000 )
{
SAFE_DELETE(m_pCreate);
m_pCreate = new CWndWikiCreate();
m_pCreate->Initialize(this);
m_pCreate->SetItem(m_vecItems[m_pListItems->GetCurSel()]);
}else
{
ItemProp *pProp = m_vecItems[m_pListItems->GetCurSel()];
if( pProp )
{
CWndModelView *pWndViewer = (CWndModelView*)g_WndMng.GetApplet(APP_MODEL_VIEW);
if( !pWndViewer )
{
pWndViewer = (CWndModelView*)g_WndMng.CreateApplet(APP_MODEL_VIEW);
if( pWndViewer )
{
if( !pWndViewer->SetPart(pProp) )
pWndViewer->Destroy();
}
}else
pWndViewer->SetPart(pProp);
}
}
}
#endif
}
}
return CWndNeuz::OnChildNotify(message,nID,pLResult);
}
void CWndWiki::UpdateList()
{
const static DWORD dwItems [] = { II_SYS_SYS_SCR_PERIN };
DWORD dwJob = m_pComboJob->GetSelectedItemData();
DWORD dwFilter = m_pComboKind->GetSelectedItemData();
CString strFilter = m_pEditFilter->GetString();
m_vecItems.clear();
m_pListItems->ResetContent();
for( int i = 0; i < prj.m_aPropItem.GetSize(); ++i )
{
ItemProp *pProp = prj.m_aPropItem.GetAt(i);
if( pProp )
{
bool bInArray = false;
for( int j = 0; j < sizeof(dwItems) / sizeof(dwItems[0]); ++j )
{
if( pProp->dwID == dwItems[j] )
{
bInArray = true;
break;
}
}
if( strstr(pProp->szName,"?") )
continue;
if( pProp->dwLimitLevel1 > MAX_CHARACTER_LEVEL && pProp->dwLimitLevel1 != NULL_ID )
continue;
if( !strlen(pProp->szName) )
continue;
if( !strlen(pProp->szIcon) )
continue;
if( bInArray )
continue;
if( dwJob != JOB_VAGRANT )
{
if( pProp->dwItemJob != dwJob )
continue;
}
if( dwFilter != NULL_ID )
{
if( pProp->dwItemKind1 != dwFilter )
continue;
}
if( strFilter.GetLength() )
{
CString strName = pProp->szName;
if( !strstr(strName.MakeLower(),strFilter.MakeLower()) )
continue;
}
m_vecItems.push_back(pProp);
m_pListItems->AddString("");
}
}
}
bool SortByNameUpper(const ItemProp *pPropLeft, const ItemProp *pPropRight)
{
std::string strLeft = pPropLeft->szName;
std::string strRight = pPropRight->szName;
return (strLeft < strRight);
}
bool SortByNameLower(const ItemProp *pPropLeft, const ItemProp *pPropRight)
{
std::string strLeft = pPropLeft->szName;
std::string strRight = pPropRight->szName;
return (strLeft > strRight);
}
bool SortByLevelUpper(const ItemProp *pPropLeft, const ItemProp *pPropRight)
{
int nLevelLeft = (pPropLeft->dwLimitLevel1 == NULL_ID ? 1 : pPropLeft->dwLimitLevel1);
int nLevelRight = (pPropRight->dwLimitLevel1 == NULL_ID ? 1 : pPropRight->dwLimitLevel1);
return (nLevelLeft < nLevelRight);
}
bool SortByLevelLower(const ItemProp *pPropLeft, const ItemProp *pPropRight)
{
int nLevelLeft = (pPropLeft->dwLimitLevel1 == NULL_ID ? 1 : pPropLeft->dwLimitLevel1);
int nLevelRight = (pPropRight->dwLimitLevel1 == NULL_ID ? 1 : pPropRight->dwLimitLevel1);
return (nLevelLeft > nLevelRight);
}
bool SortByJobUpper(const ItemProp *pPropLeft, const ItemProp *pPropRight)
{
return (pPropLeft->dwItemJob < pPropRight->dwItemJob);
}
bool SortByJobLower(const ItemProp *pPropLeft, const ItemProp *pPropRight)
{
return (pPropLeft->dwItemJob > pPropRight->dwItemJob);
}
void CWndWiki::SortByName()
{
if( m_bUpperCase )
std::sort(m_vecItems.begin(),m_vecItems.end(), SortByNameUpper);
else
std::sort(m_vecItems.begin(),m_vecItems.end(), SortByNameLower);
}
void CWndWiki::SortByLevel()
{
if( m_bUpperCase )
std::sort(m_vecItems.begin(),m_vecItems.end(), SortByLevelUpper);
else
std::sort(m_vecItems.begin(),m_vecItems.end(), SortByLevelLower);
}
void CWndWiki::SortByJob()
{
if( m_bUpperCase )
std::sort(m_vecItems.begin(),m_vecItems.end(), SortByJobUpper);
else
std::sort(m_vecItems.begin(),m_vecItems.end(), SortByJobLower);
}
void CWndWiki::Sort()
{
m_pListItems->EnableWindow(FALSE);
switch( m_cSortType )
{
case 0: SortByName(); break;
case 1: SortByJob(); break;
case 2: SortByLevel(); break;
}
m_pListItems->EnableWindow(TRUE);
}
CWndWikiCreate::CWndWikiCreate()
{
m_pPropCreate = NULL;
}
BOOL CWndWikiCreate::Initialize(CWndBase *pWndParent, DWORD dwStyle)
{
return CWndNeuz::InitDialog(g_Neuz.GetSafeHwnd(),APP_WIKICI,WBS_MODAL,0,pWndParent);
}
void CWndWikiCreate::OnInitialUpdate()
{
CWndNeuz::OnInitialUpdate();
m_pStcName = (CWndStatic*)GetDlgItem(WIDC_STATIC1);
m_pDrawCtrl = GetWndCtrl(WIDC_STATIC4);
m_pEditAmount = (CWndEdit*)GetDlgItem(WIDC_EDIT1);
m_pEditAmount->AddWndStyle(EBS_NUMBER);
m_pEditAmount->SetString("1");
m_pEditName = (CWndEdit*)GetDlgItem(WIDC_EDIT2);
MoveParentCenter();
}
void CWndWikiCreate::OnDraw(C2DRender *p2DRender)
{
CWndNeuz::OnDraw(p2DRender);
if( m_pPropCreate )
{
CTexture *pTex = CWndBase::m_textureMng.AddTexture(p2DRender->m_pd3dDevice, MakePath(DIR_ITEM,m_pPropCreate->szIcon), 0xffff00ff);
if( pTex )
pTex->Render(p2DRender,CPoint(m_pDrawCtrl->rect.left+6,m_pDrawCtrl->rect.top+6));
}
}
BOOL CWndWikiCreate::OnChildNotify(UINT message, UINT nID, LRESULT *pLResult)
{
if( nID == WIDC_BUTTON1 )
{
if( m_pPropCreate )
{
int nAmount = atoi(m_pEditAmount->GetString());
if( nAmount > 0 && nAmount < 100 )
{
g_DPlay.SendWikiCreateItem(m_pPropCreate,nAmount,m_pEditName->GetString());
Destroy();
}
}
}else if( nID == WIDC_BUTTON2 )
{
Destroy();
}
return CWndNeuz::OnChildNotify(message,nID,pLResult);
}
void CWndWikiCreate::OnMouseWndSurface(CPoint point)
{
if( m_pDrawCtrl->rect.PtInRect(point) )
{
if( m_pPropCreate )
{
CItemElem itemElem;
CRect rect = m_pDrawCtrl->rect;
itemElem.m_dwItemId = m_pPropCreate->dwID;
ClientToScreen(&point);
ClientToScreen(&rect);
g_WndMng.PutToolTip_Item(&itemElem,point,&rect);
}
}
}
void CWndWikiCreate::SetItem(ItemProp *pPropCreate)
{
m_pPropCreate = pPropCreate;
if( m_pPropCreate )
m_pStcName->SetTitle(m_pPropCreate->szName);
else
m_pStcName->SetTitle("");
}
#endif // __WIKI
WndWiki.h
Code:
#pragma once
#ifdef __WIKI
class CWndWikiCreate;
class CWndWiki : public CWndNeuz
{
private:
CWndWikiCreate *m_pCreate;
vector<ItemProp*> m_vecItems;
CWndListBox *m_pListItems;
CWndComboBox *m_pComboKind;
CWndComboBox *m_pComboJob;
CWndEdit *m_pEditFilter;
HANDLE m_hSortThread;
bool m_bUpperCase;
char m_cSortType;
public:
CWndWiki();
~CWndWiki();
virtual BOOL Initialize(CWndBase *pWndParent = NULL, DWORD dwStyle = 0);
virtual void OnInitialUpdate();
virtual BOOL OnChildNotify(UINT message, UINT nID, LRESULT *pLResult);
vector<ItemProp*>* GetItemList(){ return &m_vecItems; }
void UpdateList();
void SortByName();
void SortByLevel();
void SortByJob();
void Sort();
};
class CWndWikiCreate : public CWndNeuz
{
private:
ItemProp *m_pPropCreate;
CWndEdit *m_pEditAmount;
CWndEdit *m_pEditName;
LPWNDCTRL m_pDrawCtrl;
CWndStatic *m_pStcName;
public:
CWndWikiCreate();
virtual BOOL Initialize(CWndBase *pWndParent = NULL, DWORD dwStyle = 0);
virtual void OnInitialUpdate();
virtual void OnDraw(C2DRender *p2DRender);
virtual BOOL OnChildNotify(UINT message,UINT nID,LRESULT *pLResult);
void OnMouseWndSurface(CPoint point);
void SetItem(ItemProp *pPropCreate);
};
#endif // __WIKI






