MainDlg.cpp 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359
  1. // MainDlg.cpp : implementation of the CMainDlg class
  2. //
  3. /////////////////////////////////////////////////////////////////////////////
  4. #include "stdafx.h"
  5. #include "MainDlg.h"
  6. #include "StabtypeControl.h"
  7. #include "CLashConfig.h"
  8. CMainDlg::CMainDlg() : SHostWnd(_T("LAYOUT:XML_MAINWND")), m_base_clash(nullptr), pNodeAdapter(nullptr)
  9. {
  10. m_bLayoutInited = FALSE;
  11. }
  12. CMainDlg::~CMainDlg()
  13. {
  14. if (m_base_clash)
  15. {
  16. delete m_base_clash;
  17. m_base_clash = nullptr;
  18. }
  19. }
  20. int CMainDlg::OnCreate(LPCREATESTRUCT lpCreateStruct)
  21. {
  22. SetMsgHandled(FALSE);
  23. return 0;
  24. }
  25. BOOL CMainDlg::OnInitDialog(HWND hWnd, LPARAM lParam)
  26. {
  27. m_bLayoutInited = TRUE;
  28. Init();
  29. OnConnecting_UdateUi(false, CONNECT_NODE_MSG,L"");
  30. /*CManageNetWork m_manageNetwork;
  31. m_manageNetwork.GetNodeList();*/
  32. CManageNetWork::getSingletonPtr()->GetNodeList();
  33. return 0;
  34. }
  35. void CMainDlg::Init()
  36. {
  37. CApp::getSingletonPtr()->SetupDataDirectory();
  38. //FindChildByName2<STabCtrl>(L"tabmain");
  39. if (!m_base_clash)
  40. {
  41. m_base_clash = new CLashConfig();
  42. m_base_clash->InitClash();
  43. m_base_clash->StartClash();
  44. }
  45. SysMode list;
  46. list.id = 0;
  47. list.name = L"系统代理";
  48. list.proxy_mode = PROXY_MODE::sys_mode;
  49. SysMode list1;
  50. list1.id = 1;
  51. list1.name = L"网卡代理";
  52. list1.proxy_mode = PROXY_MODE::tun_mode;
  53. m_sysmode_vctor.push_back(list);
  54. m_sysmode_vctor.push_back(list1);
  55. RouteMode route;
  56. route.id = 0;
  57. route.name = L"智能";
  58. route.route_mode = ROUT_MODE::cn_mode;
  59. RouteMode route2;
  60. route2.id = 1;
  61. route2.name = L"全局";
  62. route2.route_mode = ROUT_MODE::qg_mode;
  63. m_route_vctor.push_back(route);
  64. m_route_vctor.push_back(route2);
  65. StabtypeControl* tabtype = FindChildByName2<StabtypeControl>(L"sysmode");
  66. if (tabtype)
  67. {
  68. for (auto i = 0; i < m_sysmode_vctor.size(); i++)
  69. {
  70. tabtype->ItemCreateChildren(m_sysmode_vctor[i].id, m_sysmode_vctor[i].name,i == 0 ? true : false );
  71. }
  72. if (m_sysmode_vctor.size() > 0)
  73. {
  74. CApp::getSingletonPtr()->SetSysMode(m_sysmode_vctor[0].proxy_mode);
  75. }
  76. tabtype->GetEventSet()->subscribeEvent(EVT_TABTYPE_CONTROL,
  77. Subscriber(&CMainDlg::OnSysModeType, this));
  78. }
  79. StabtypeControl* routetype = FindChildByName2<StabtypeControl>(L"routemode");
  80. if (routetype)
  81. {
  82. for (auto i = 0; i < m_route_vctor.size(); i++)
  83. {
  84. routetype->ItemCreateChildren(m_route_vctor[i].id, m_route_vctor[i].name, i == 0 ? true : false);
  85. }
  86. if (m_route_vctor.size() > 0)
  87. {
  88. CApp::getSingletonPtr()->SetRouteMode(m_route_vctor[0].route_mode);
  89. }
  90. routetype->GetEventSet()->subscribeEvent(EVT_TABTYPE_CONTROL,
  91. Subscriber(&CMainDlg::OnRouteModeType, this));
  92. }
  93. auto funRecent2 = std::bind(&CMainDlg::ShowView, this, std::placeholders::_1, std::placeholders::_2);
  94. auto funRecent3 = std::bind(&CMainDlg::ItemRClick, this, std::placeholders::_1);
  95. STileView* pTileView = FindChildByName2<STileView>("nodeList");
  96. if (pTileView)
  97. {
  98. /*std::vector<SStringT> vctInfo{ L"Test1",L"Fun1", L"Ming", L"Get" };*/
  99. pNodeAdapter = new CNodeAdapter(pTileView);
  100. pTileView->SetAdapter(pNodeAdapter);
  101. pNodeAdapter->SetShowView(funRecent2);
  102. pNodeAdapter->SetItemClickCallBack(funRecent3);
  103. //pNodeAdapter->Release();
  104. }
  105. }
  106. void CMainDlg::OnNode()
  107. {
  108. STabCtrl* m_tab_main = FindChildByName2<STabCtrl>(L"tabmain");
  109. if (m_tab_main)
  110. {
  111. m_tab_main->SetCurSel(1);
  112. m_tab_main->Invalidate();
  113. }
  114. }
  115. void CMainDlg::OnBackNode()
  116. {
  117. STabCtrl* m_tab_main = FindChildByName2<STabCtrl>(L"tabmain");
  118. if (m_tab_main)
  119. {
  120. m_tab_main->SetCurSel(0);
  121. m_tab_main->Invalidate();
  122. }
  123. }
  124. bool CMainDlg::OnSysModeType(SOUI::EventArgs* pEvt)
  125. {
  126. SOUI::EventTabtypeControl* pTestControlEvent =
  127. SOUI::sobj_cast<SOUI::EventTabtypeControl>(pEvt);
  128. if (!pTestControlEvent)
  129. {
  130. return false;
  131. }
  132. CApp::getSingletonPtr()->SetSysMode(m_sysmode_vctor[pTestControlEvent->nIndex].proxy_mode);
  133. return true;
  134. }
  135. bool CMainDlg::OnRouteModeType(SOUI::EventArgs* pEvt)
  136. {
  137. SOUI::EventTabtypeControl* pTestControlEvent =
  138. SOUI::sobj_cast<SOUI::EventTabtypeControl>(pEvt);
  139. if (!pTestControlEvent)
  140. {
  141. return false;
  142. }
  143. CApp::getSingletonPtr()->SetRouteMode(m_route_vctor[pTestControlEvent->nIndex].route_mode);
  144. return true;
  145. }
  146. void CMainDlg::OnServerListFinish(SOUI::EventArgs* pEvt)
  147. {
  148. EventNodeList* e2 = sobj_cast<EventNodeList>(pEvt);
  149. if (!e2)
  150. {
  151. return;
  152. }
  153. if (e2->status == 0)
  154. {
  155. UPdateMsgStatus(e2->msg);
  156. }
  157. else if (e2->status == -1)
  158. {
  159. UPdateMsgStatus(e2->msg);
  160. }
  161. else if (e2->status == 200)
  162. {
  163. OnConnecting_UdateUi(TRUE, SUEECS_NODE_MSG);
  164. //更新 节点数据
  165. if (pNodeAdapter)
  166. {
  167. pNodeAdapter->SetCount(CApp::getSingletonPtr()->GetServerList()->vectlistmode.size());
  168. }
  169. }
  170. }
  171. void CMainDlg::OnClashPreoceeQutFinish(SOUI::EventArgs* pEvt)
  172. {
  173. if (m_base_clash)
  174. {
  175. m_base_clash->StartClash();
  176. }
  177. }
  178. void CMainDlg::UPdateMsgStatus(SStringW msg)
  179. {
  180. //text_touch
  181. SStatic* text_touch = FindChildByName2<SStatic>(L"text_touch");
  182. if (text_touch)
  183. {
  184. text_touch->SetWindowTextW(msg);
  185. text_touch->EnableWindow(FALSE);
  186. text_touch->Invalidate();
  187. }
  188. }
  189. void CMainDlg::ShowView(int nItem, SWindow* pItem)
  190. {
  191. if (!pNodeAdapter)
  192. {
  193. return;
  194. }
  195. auto vectorserverlist = CApp::getSingletonPtr()->GetServerList()->vectlistmode;
  196. SStatic* servername = pItem->FindChildByName2<SStatic>(L"servername");
  197. if (servername)
  198. {
  199. servername->SetWindowTextW(S_CA2W(vectorserverlist[nItem].name.c_str(),CP_UTF8));
  200. }
  201. SStatic* serverms = pItem->FindChildByName2<SStatic>(L"serverms");
  202. if (serverms)
  203. {
  204. SStringW msg = L"推荐";
  205. SStringW color = L"";
  206. SLOG_DEBUG(vectorserverlist[nItem].online_users);
  207. if(vectorserverlist[nItem].online_users < 21 || vectorserverlist[nItem].online_users < 30) { //空闲
  208. msg = L"空闲";
  209. color = L"#6aa84f";
  210. }
  211. else if (vectorserverlist[nItem].online_users < 31 || vectorserverlist[nItem].online_users < 80) { //繁忙
  212. msg = L"繁忙";
  213. color = L"#7c7c7c";
  214. }
  215. else if (vectorserverlist[nItem].online_users < 81 || vectorserverlist[nItem].online_users < 150) { //拥挤
  216. msg = L"拥挤";
  217. color = L"#f50061";
  218. }
  219. else if (vectorserverlist[nItem].online_users < 151 || vectorserverlist[nItem].online_users < 500) { //爆满
  220. msg = L"拥挤";
  221. color = L"#585858";
  222. }
  223. serverms->SetWindowTextW(msg);
  224. serverms->SetAttribute(L"colorText", color);
  225. }
  226. }
  227. void CMainDlg::ItemRClick(int nItem)
  228. {
  229. }
  230. //连接状态 更新UI
  231. void CMainDlg::OnConnecting_UdateUi(bool b,SStringW msg,SStringW acc_msg)
  232. {
  233. SWindow* selectnode = FindChildByName2<SWindow>(L"selectnode");
  234. if (selectnode)
  235. {
  236. selectnode->EnableWindow(b);
  237. selectnode->Invalidate();
  238. }
  239. SStatic* text_touch = FindChildByName2<SStatic>(L"text_touch");
  240. if (text_touch)
  241. {
  242. text_touch->SetWindowTextW(msg);
  243. text_touch->EnableWindow(b);
  244. text_touch->Invalidate();
  245. }
  246. SImageButton* connect_touch = FindChildByName2<SImageButton>(L"connect_touch");
  247. if (connect_touch)
  248. {
  249. connect_touch->EnableWindow(b);
  250. connect_touch->Invalidate();
  251. }
  252. }
  253. //TODO:消息映射
  254. void CMainDlg::OnClose()
  255. {
  256. OnMinimize();
  257. }
  258. void CMainDlg::OnMaximize()
  259. {
  260. SendMessage(WM_SYSCOMMAND, SC_MAXIMIZE);
  261. }
  262. void CMainDlg::OnRestore()
  263. {
  264. SendMessage(WM_SYSCOMMAND, SC_RESTORE);
  265. }
  266. void CMainDlg::OnMinimize()
  267. {
  268. SendMessage(WM_SYSCOMMAND, SC_MINIMIZE);
  269. }
  270. void ShowConsoleWindow(bool show) {
  271. const HWND hWnd = CProcessManager::getSingletonPtr()->GetConsoleWindow();
  272. if (hWnd)
  273. {
  274. ShowWindow(hWnd, show ? SW_SHOW : SW_HIDE);
  275. if (show)
  276. SetForegroundWindow(hWnd);
  277. }
  278. }
  279. void CMainDlg::OnCommand(UINT uNotifyCode, int nID, HWND wndCtl) {
  280. if (uNotifyCode == 0)
  281. {
  282. if (nID == 2)
  283. {
  284. const HWND hWndConsole = CProcessManager::getSingletonPtr()->GetConsoleWindow();
  285. if (hWndConsole)
  286. {
  287. ShowConsoleWindow(!::IsWindowVisible(hWndConsole));
  288. }
  289. else
  290. ShowConsoleWindow(false);
  291. }
  292. else if (nID == 6) {
  293. if (m_base_clash)
  294. {
  295. m_base_clash->StopClash();
  296. delete m_base_clash;
  297. m_base_clash = nullptr;
  298. }
  299. CSimpleWnd::DestroyWindow();
  300. }
  301. }
  302. }