From 260b16a1debe7dbc33982768a37dfd48ca34b248 Mon Sep 17 00:00:00 2001
From: chenluhua1980 <Chenluhua@qq.com>
Date: 星期五, 09 一月 2026 14:27:21 +0800
Subject: [PATCH] 1.EAP模拟器完善

---
 SourceCode/Bond/Servo/CEquipmentPage2.cpp |  173 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 171 insertions(+), 2 deletions(-)

diff --git a/SourceCode/Bond/Servo/CEquipmentPage2.cpp b/SourceCode/Bond/Servo/CEquipmentPage2.cpp
index c79ab1a..aef0b77 100644
--- a/SourceCode/Bond/Servo/CEquipmentPage2.cpp
+++ b/SourceCode/Bond/Servo/CEquipmentPage2.cpp
@@ -24,10 +24,17 @@
 void CEquipmentPage2::DoDataExchange(CDataExchange* pDX)
 {
 	CHMPropertyPage::DoDataExchange(pDX);
+	DDX_Control(pDX, IDC_LIST1, m_listCtrl);
 }
 
 
 BEGIN_MESSAGE_MAP(CEquipmentPage2, CHMPropertyPage)
+	ON_WM_CTLCOLOR()
+	ON_WM_DESTROY()
+	ON_WM_SIZE()
+	ON_NOTIFY(LVN_ITEMCHANGED, IDC_LIST1, &CEquipmentPage2::OnLvnItemchangedList1)
+	ON_BN_CLICKED(IDC_BUTTON_REMOVE, &CEquipmentPage2::OnBnClickedButtonRemove)
+	ON_BN_CLICKED(IDC_BUTTON_PUT, &CEquipmentPage2::OnBnClickedButtonPut)
 END_MESSAGE_MAP()
 
 
@@ -35,7 +42,6 @@
 void CEquipmentPage2::OnApply()
 {
 	__super::OnApply();
-	AfxMessageBox("CEquipmentPage2::OnApply()");
 }
 
 void CEquipmentPage2::setEquipment(SERVO::CEquipment* pEquipment)
@@ -48,8 +54,171 @@
 {
 	CHMPropertyPage::OnInitDialog();
 
-	AfxMessageBox(m_pEquipment->getClassName());
+	
+	// 璇诲嚭鍒楀
+	CString strIniFile, strItem;
+	strIniFile.Format(_T("%s\\configuration.ini"), (LPTSTR)(LPCTSTR)theApp.m_strAppDir);
+	int width[8] = { 0, 218, 180, 180, 180, 180, 180, 180 };
+	for (int i = 0; i < 8; i++) {
+		strItem.Format(_T("Col_%d_Width"), i);
+		width[i] = GetPrivateProfileInt("EquipmentPage2ListCtrl", strItem, width[i], strIniFile);
+	}
+
+
+	// 鎶ヨ〃鎺т欢
+	DWORD dwStyle = m_listCtrl.GetExtendedStyle();
+	dwStyle |= LVS_EX_FULLROWSELECT;
+	dwStyle |= LVS_EX_GRIDLINES;
+	m_listCtrl.SetExtendedStyle(dwStyle);
+
+	HIMAGELIST imageList = ImageList_Create(24, 24, ILC_COLOR24, 1, 1);
+	ListView_SetImageList(m_listCtrl.GetSafeHwnd(), imageList, LVSIL_SMALL);
+	m_listCtrl.InsertColumn(0, _T(""), LVCFMT_RIGHT, width[0]);
+	m_listCtrl.InsertColumn(1, _T("ID"), LVCFMT_LEFT, width[1]);
+	m_listCtrl.InsertColumn(2, _T("鍚嶇О"), LVCFMT_LEFT, width[2]);
+	m_listCtrl.InsertColumn(3, _T("Glass ID"), LVCFMT_LEFT, width[3]);
+	m_listCtrl.InsertColumn(4, _T("璐村悎Glass ID"), LVCFMT_LEFT, width[4]);
+	m_listCtrl.InsertColumn(5, _T("鏃堕棿"), LVCFMT_LEFT, width[5]);
+	m_listCtrl.SetColumnWidth(5, LVSCW_AUTOSIZE_USEHEADER);
+
+
+	ASSERT(m_pEquipment);
+	UpdateSlots();
 
 	return TRUE;  // return TRUE unless you set the focus to a control
 				  // 寮傚父: OCX 灞炴�ч〉搴旇繑鍥� FALSE
 }
+
+HBRUSH CEquipmentPage2::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor)
+{
+	HBRUSH hbr = CHMPropertyPage::OnCtlColor(pDC, pWnd, nCtlColor);
+
+	// TODO:  鍦ㄦ鏇存敼 DC 鐨勪换浣曠壒鎬�
+
+	// TODO:  濡傛灉榛樿鐨勪笉鏄墍闇�鐢荤瑪锛屽垯杩斿洖鍙︿竴涓敾绗�
+	return hbr;
+}
+
+void CEquipmentPage2::OnDestroy()
+{
+	CHMPropertyPage::OnDestroy();
+
+	// 淇濆瓨鍒楀
+	CString strIniFile, strItem, strTemp;
+	strIniFile.Format(_T("%s\\configuration.ini"), (LPTSTR)(LPCTSTR)theApp.m_strAppDir);
+	CHeaderCtrl* pHeader = m_listCtrl.GetHeaderCtrl();
+	for (int i = 0; i < pHeader->GetItemCount(); i++) {
+		RECT rect;
+		pHeader->GetItemRect(i, &rect);
+		strItem.Format(_T("Col_%d_Width"), i);
+		strTemp.Format(_T("%d"), rect.right - rect.left);
+		WritePrivateProfileString("EquipmentPage2ListCtrl", strItem, strTemp, strIniFile);
+	}
+}
+
+void CEquipmentPage2::OnSize(UINT nType, int cx, int cy)
+{
+	CHMPropertyPage::OnSize(nType, cx, cy);
+	if (GetDlgItem(IDC_LIST1) == nullptr) return;
+
+	CWnd* pItem;
+	CRect rcClient, rcItem;
+	GetClientRect(&rcClient);
+
+	int x = 12;
+	int x1 = x;
+	int y2 = rcClient.bottom - 12;
+	pItem = GetDlgItem(IDC_BUTTON_REMOVE);
+	pItem->GetWindowRect(&rcItem);
+	pItem->MoveWindow(x, y2 - rcItem.Height(), rcItem.Width(), rcItem.Height());
+	x1 += rcItem.Width();
+	x1 += 12;
+
+	pItem = GetDlgItem(IDC_BUTTON_PUT);
+	pItem->GetWindowRect(&rcItem);
+	pItem->MoveWindow(x1, y2 - rcItem.Height(), rcItem.Width(), rcItem.Height());
+	y2 -= rcItem.Height();
+	y2 -= 8;
+
+	m_listCtrl.MoveWindow(x, 58, rcClient.Width() - 24, y2 - 58);
+}
+
+void CEquipmentPage2::OnLvnItemchangedList1(NMHDR* pNMHDR, LRESULT* pResult)
+{
+	LPNMLISTVIEW pNMLV = reinterpret_cast<LPNMLISTVIEW>(pNMHDR);
+
+	if (LVIF_STATE == pNMLV->uChanged) {
+		int nItem = pNMLV->iItem;
+		GetDlgItem(IDC_BUTTON_REMOVE)->EnableWindow(GetSelectedItemIndex() >= 0);
+	}
+
+
+	*pResult = 0;
+}
+
+int CEquipmentPage2::GetSelectedItemIndex()
+{
+	POSITION pos = m_listCtrl.GetFirstSelectedItemPosition();
+	return m_listCtrl.GetNextSelectedItem(pos);
+}
+
+void CEquipmentPage2::OnBnClickedButtonRemove()
+{
+	int index = GetSelectedItemIndex();
+	if (index >= 0) {
+		SERVO::CSlot* pSlot = (SERVO::CSlot*)m_listCtrl.GetItemData(index);
+		ASSERT(pSlot);
+		if (theApp.m_model.getMaster().moveGlassToBuf(m_pEquipment->getID(),
+			pSlot->getNo())) {
+			UpdateSlots();
+			AfxMessageBox("鐗╂枡宸插彇鍑哄埌Buffer涓紒");
+		}
+	}
+}
+
+void CEquipmentPage2::OnBnClickedButtonPut()
+{
+	int index = GetSelectedItemIndex();
+	if (index >= 0) {
+		SERVO::CSlot* pSlot = (SERVO::CSlot*)m_listCtrl.GetItemData(index);
+		ASSERT(pSlot);
+		if (theApp.m_model.getMaster().moveGlassToSlot(m_pEquipment->getID(),
+			pSlot->getNo())) {
+			UpdateSlots();
+			AfxMessageBox("鐗╂枡宸叉斁鍏ユ寚瀹氫綅缃紒");
+		}
+	}
+}
+
+void CEquipmentPage2::UpdateSlots()
+{
+	m_listCtrl.DeleteAllItems();
+	for (int i = 0; i < SLOT_MAX; i++) {
+		SERVO::CSlot* pSlot = m_pEquipment->getSlot(i);
+		if (pSlot != nullptr && pSlot->isEnable()) {
+			int index = m_listCtrl.InsertItem(m_listCtrl.GetItemCount(), _T(""));
+			m_listCtrl.SetItemData(index, (DWORD_PTR)pSlot);
+			m_listCtrl.SetItemText(index, 1, std::to_string(pSlot->getNo()).c_str());
+			m_listCtrl.SetItemText(index, 2, pSlot->getName().c_str());
+
+			SERVO::CGlass* pGlass = (SERVO::CGlass*)pSlot->getContext();
+			if (pGlass != nullptr) {
+				CString strText;
+				if (pGlass->getType() == SERVO::MaterialsType::G1) {
+					strText.Format(_T("(G1)%s"), pGlass->getID().c_str());
+				}
+				else if (pGlass->getType() == SERVO::MaterialsType::G2) {
+					strText.Format(_T("(G2)%s"), pGlass->getID().c_str());
+				}
+				else {
+					strText.Format(_T("(%s"), pGlass->getID().c_str());
+				}
+				m_listCtrl.SetItemText(index, 3, strText);
+				SERVO::CGlass* pBuddy = pGlass->getBuddy();
+				if (pBuddy != nullptr) {
+					m_listCtrl.SetItemText(index, 4, pBuddy->getID().c_str());
+				}
+			}
+		}
+	}
+}

--
Gitblit v1.9.3