DlgOptItemPriority.cpp
资源名称:ROA3.40.rar [点击查看]
上传用户:tianheyiqi
上传日期:2010-04-16
资源大小:282k
文件大小:9k
源码类别:
外挂编程
开发平台:
Visual C++
- // DlgOptItemPriority.cpp : implementation file
- //
- #include "stdafx.h"
- #include "ROA.h"
- #include "DlgOptItemPriority.h"
- #ifdef _DEBUG
- #define new DEBUG_NEW
- #undef THIS_FILE
- static char THIS_FILE[] = __FILE__;
- #endif
- /////////////////////////////////////////////////////////////////////////////
- // CDlgOptItemPriority dialog
- typedef struct tagItemInfo
- {
- LPCTSTR lpszDesc;
- COLORREF colFore;
- COLORREF colBk;
- }ITEMINFO;
- ITEMINFO iteminfo[eIpMax] =
- {
- {"0 - 抢夺", RGB(255, 255, 255), RGB(255, 0, 0)},
- {"1 - 收集", RGB(255, 255, 255), RGB(0, 0, 255)},
- {"2 - 捡取", RGB(0, 0, 0), RGB(255, 255, 0)},
- {"3 - 忽略", RGB(0, 0, 0), RGB(255, 255, 255)}
- };
- CDlgOptItemPriority::CDlgOptItemPriority(CWnd* pParent /*=NULL*/)
- : CDialog(CDlgOptItemPriority::IDD, pParent)
- {
- //{{AFX_DATA_INIT(CDlgOptItemPriority)
- m_ID = _T("");
- m_Name = _T("");
- //}}AFX_DATA_INIT
- }
- void CDlgOptItemPriority::DoDataExchange(CDataExchange* pDX)
- {
- CDialog::DoDataExchange(pDX);
- //{{AFX_DATA_MAP(CDlgOptItemPriority)
- DDX_Control(pDX, IDC_ITEM_TYPE, m_Type);
- DDX_Control(pDX, IDC_CHOISE, m_Choise);
- DDX_Control(pDX, IDC_LIST, m_ItemList);
- DDX_Text(pDX, IDC_ITEM_ID, m_ID);
- DDX_Text(pDX, IDC_ITEM_NAME, m_Name);
- //}}AFX_DATA_MAP
- }
- BEGIN_MESSAGE_MAP(CDlgOptItemPriority, CDialog)
- //{{AFX_MSG_MAP(CDlgOptItemPriority)
- ON_CBN_SELCHANGE(IDC_CHOISE, OnSelchangeChoise)
- ON_NOTIFY(NM_CLICK, IDC_LIST, OnClickList)
- ON_NOTIFY(LVN_COLUMNCLICK, IDC_LIST, OnColumnclickList)
- ON_CBN_SELCHANGE(IDC_ITEM_TYPE, OnSelchangeItemType)
- ON_EN_CHANGE(IDC_ITEM_NAME, OnChangeItemName)
- //}}AFX_MSG_MAP
- END_MESSAGE_MAP()
- /////////////////////////////////////////////////////////////////////////////
- // CDlgOptItemPriority message handlers
- BOOL CDlgOptItemPriority::OnInitDialog()
- {
- CDialog::OnInitDialog();
- CRect rect;
- CString strTotal, strTypeId, strTypeName;
- POSITION pos;
- int i;
- m_ItemList.GetClientRect(&rect);
- m_ItemList.InsertColumn(0, "物品ID", LVCFMT_LEFT, 50);
- m_ItemList.InsertColumn(1, "名称", LVCFMT_LEFT, 100);
- m_ItemList.InsertColumn(2, "类型", LVCFMT_LEFT, 100);
- m_ItemList.InsertColumn(3, "优先级", LVCFMT_LEFT, rect.Width() - 270);
- ListView_SetExtendedListViewStyleEx(m_ItemList.m_hWnd, LVS_EX_GRIDLINES | LVS_EX_FULLROWSELECT, 0xFFFFFFFF);
- //Fill choise priority
- for(i=0; i<eIpMax; i++)
- {
- m_Choise.InsertString(i, iteminfo[i].lpszDesc);
- m_Choise.SetItemData(i, i);
- }
- //Fill choise type
- pos = mapEquipType.GetStartPosition();
- while (pos)
- {
- mapEquipType.GetNextAssoc(pos, strTypeId, strTypeName);
- m_Type.AddString(strTypeName);
- }
- FillItemList();
- strTotal.Format("总数: %d", m_ItemList.GetItemCount());
- SetDlgItemText(IDC_TOTAL, strTotal);
- /* NM_LISTVIEW NMListView;
- NMListView.iSubItem = 0;
- OnColumnclickList((NMHDR*)&NMListView, NULL);
- */
- long wParam;
- //Sort item list by IDs
- wParam = 0;
- m_ItemList.SortItems(SortData, wParam);
- //after sort,item pos has changed,so must refresh color of item
- RefreshColors();
- return TRUE; // return TRUE unless you set the focus to a control
- // EXCEPTION: OCX Property Pages should return FALSE
- }
- void CDlgOptItemPriority::FillItemList()
- {
- int nIndex = 0;
- CString strItemId, strItem, strPriority;
- BOOL bFound;
- m_ItemList.DeleteAllItems();
- POSITION pos = mapItem.GetStartPosition();
- while (pos != NULL)
- {
- mapItem.GetNextAssoc(pos, strItemId, strItem);
- strItemId.TrimLeft();
- strItemId.TrimRight();
- strPriority = mapItem.FindValue(strItemId, eItemPriority, &bFound);
- if(bFound)
- {
- nIndex = m_ItemList.InsertItem(m_ItemList.GetItemCount(), strItemId);
- m_ItemList.SetItemText(nIndex, 1, mapItem.FindValue(strItemId, eItemName));
- m_ItemList.SetItemText(nIndex, 2, mapEquipType.FindValue(atoi(mapItem.FindValue(strItemId, eItemSlots))));
- m_ItemList.SetItemText(nIndex, 3, strPriority);
- m_ItemList.SetItemData(nIndex, (atoi(strItemId)));
- }
- }
- RefreshColors();
- }
- void CDlgOptItemPriority::OnSelchangeChoise()
- {
- CString strPriority;
- DWORD data = m_Choise.GetItemData(m_Choise.GetCurSel());
- int nIndex;
- strPriority.Format("%d", data);
- CString strItemId, strTemp;
- POSITION pos = m_ItemList.GetFirstSelectedItemPosition();
- while (pos != NULL)
- {
- nIndex = m_ItemList.GetNextSelectedItem(pos);
- m_ItemList.SetItemText(nIndex, 3, strPriority);
- strItemId = m_ItemList.GetItemText(nIndex, 0);
- // strTemp.Format("%d", atoi(strItemId));
- // mapItemPriority.SetAt(strTemp, strPriority);
- }
- RefreshColors();
- }
- void CDlgOptItemPriority::OnOK()
- {
- if (m_ItemList.GetItemCount())
- {
- SaveToFile();
- utlLogout2("载入[物品信息]......", eLogCommon, false);
- BOOL bDone = mapItem.init(ROA_MAP_ITEMS, "物品");
- utlLogout3(bDone?"成功":"失败", eLogCommon, false);
- }
- CDialog::OnOK();
- }
- void CDlgOptItemPriority::SaveToFile()
- {
- CFile file;
- int i;
- int nCount = m_ItemList.GetItemCount();
- CString strItemId, strName, strTypeName, strTypeID, Priority, strTemp;
- long wParam;
- //Sort item list by IDs
- wParam = 0;
- m_ItemList.SortItems(SortData, wParam);
- do
- {
- if(file.Open(ROA_MAP_ITEMS, CFile::modeWrite|CFile::modeCreate))
- {
- CArchive arc(&file, CArchive::store);
- for (i = 0; i < nCount; ++i)
- {
- //Get Item ID
- strItemId = m_ItemList.GetItemText(i, 0);
- //Get Item Name
- strName = m_ItemList.GetItemText(i, 1);
- //Get Item Type ID
- POSITION pos = mapEquipType.GetStartPosition();
- while (pos)
- {
- mapEquipType.GetNextAssoc(pos, strTypeID, strTypeName);
- if (strTypeName == m_ItemList.GetItemText(i, 2))
- {
- break;
- }
- }
- //Get Item Priority
- Priority = m_ItemList.GetItemText(i, 3);
- strTemp.Format("%d %s %d %srn", atoi(strItemId), strName, atoi(strTypeID), Priority);
- arc.WriteString(strTemp);
- }
- arc.Close();
- file.Close();
- }
- }while(0);
- }
- void CDlgOptItemPriority::OnClickList(NMHDR* pNMHDR, LRESULT* pResult)
- {
- CString strType;
- m_ID = "ID: ";
- m_Name = "";
- if(m_ItemList.GetSelectedCount() == 1)
- {
- POSITION pos = m_ItemList.GetFirstSelectedItemPosition();
- int nIndex = m_ItemList.GetNextSelectedItem(pos);
- //Get Cur Priority
- m_Choise.SetCurSel(atoi(m_ItemList.GetItemText(nIndex, 3)));
- //Get Cur Name
- GetDlgItem(IDC_ITEM_NAME)->EnableWindow(true);
- m_Name = m_ItemList.GetItemText(nIndex, 1);
- //Get Cur ID
- m_ID += m_ItemList.GetItemText(nIndex, 0);
- //Get Cur Type
- for (int i = 0; i < m_Type.GetCount(); ++i)
- {
- m_Type.GetLBText(i, strType);
- if (strType == m_ItemList.GetItemText(nIndex, 2))
- {
- m_Type.SetCurSel(i);
- break;
- }
- }
- }
- else
- {
- GetDlgItem(IDC_ITEM_NAME)->EnableWindow(false);
- m_Type.SetCurSel(-1);
- m_Choise.SetCurSel(-1);
- }
- UpdateData(false);
- *pResult = 0;
- }
- void CDlgOptItemPriority::OnColumnclickList(NMHDR* pNMHDR, LRESULT* pResult)
- {
- NM_LISTVIEW* pNMListView = (NM_LISTVIEW*)pNMHDR;
- static BOOL bCol[4] = {false, false, false, false};
- int nIndex = pNMListView->iSubItem;
- long wParam;
- wParam = nIndex + bCol[nIndex]*256;
- m_ItemList.SortItems(SortData, wParam);
- bCol[nIndex] = !bCol[nIndex];
- RefreshColors();
- if(pResult)
- *pResult = 0;
- }
- int CALLBACK CDlgOptItemPriority::SortData(LPARAM lParam1, LPARAM lParam2, LPARAM lParamSort)
- {
- CString strTemp1, strTemp2, strSort1, strSort2;
- BOOL bSort = lParamSort / 256;
- BOOL nCol = lParamSort & 0xFF;
- BOOL bCompare;
- strTemp1.Format("%d", lParam1);
- strTemp2.Format("%d", lParam2);
- switch(nCol)
- {
- case 0:
- bCompare = (atoi(strTemp1) < atoi(strTemp2));
- break;
- case 1:
- strSort1 = mapItem.FindValue(strTemp1, eItemName);
- strSort2 = mapItem.FindValue(strTemp2, eItemName);
- bCompare = (strSort1 < strSort2);
- break;
- case 2:
- strSort1 = mapEquipType.FindValue(atoi(mapItem.FindValue(strTemp1, eItemSlots)));
- strSort2 = mapEquipType.FindValue(atoi(mapItem.FindValue(strTemp2, eItemSlots)));
- bCompare = (strSort1 < strSort2);
- break;
- case 3:
- strSort1 = mapItem.FindValue(strTemp1, eItemPriority);
- strSort2 = mapItem.FindValue(strTemp2, eItemPriority);
- bCompare = (strSort1 < strSort2);
- break;
- }
- return(bSort?bCompare:!bCompare);
- }
- void CDlgOptItemPriority::RefreshColors()
- {
- int i;
- int nPriority;
- for(i=0; i<m_ItemList.GetItemCount(); i++)
- {
- nPriority = atoi(m_ItemList.GetItemText(i, 3));
- m_ItemList.SetRowColor(i, iteminfo[nPriority].colBk, iteminfo[nPriority].colFore);
- }
- }
- void CDlgOptItemPriority::OnSelchangeItemType()
- {
- CString strType;
- m_Type.GetLBText(m_Type.GetCurSel(), strType);
- int nIndex;
- CString strTemp;
- POSITION pos = m_ItemList.GetFirstSelectedItemPosition();
- while (pos != NULL)
- {
- nIndex = m_ItemList.GetNextSelectedItem(pos);
- m_ItemList.SetItemText(nIndex, 2, strType);
- }
- }
- void CDlgOptItemPriority::OnChangeItemName()
- {
- UpdateData(true);
- int nIndex;
- POSITION pos = m_ItemList.GetFirstSelectedItemPosition();
- while (pos != NULL)
- {
- nIndex = m_ItemList.GetNextSelectedItem(pos);
- m_ItemList.SetItemText(nIndex, 1, m_Name);
- }
- }