UiTaskNote.cpp
上传用户:dzyhzl
上传日期:2019-04-29
资源大小:56270k
文件大小:8k
源码类别:

模拟服务器

开发平台:

C/C++

  1.  /* 
  2.  * File:     UiTaskNote.cpp
  3.  * Desc:     任务记事窗口
  4.  * Author:   flying
  5.  * Creation: 2003/7/18
  6.  * 好多好多的mm哦,咔咔,以后每次都要去
  7.  */
  8. //-----------------------------------------------------------------------------
  9. #pragma once
  10. #include "KWin32.h"
  11. #include "KIniFile.h"
  12. #include <time.h>
  13. #include "../Elem/wnds.h"
  14. #include "../Elem/WndMessage.h"
  15. #include "../UiSoundSetting.h"
  16. #include "UiTaskNote.h"
  17. #include "UiTaskDataFile.h"
  18. #include "../../Represent/iRepresent/iRepresentShell.h"
  19. #include "../../../core/src/CoreShell.h"
  20. #include "../../../core/src/gamedatadef.h"
  21. #include "../../../Engine/src/Text.h"
  22. #include "../../../Engine/src/KDebug.h"
  23. #include "../UiBase.h"
  24. extern iRepresentShell* g_pRepresentShell;
  25. #define  SCHEME_INI_TASKNOTE "任务记事.ini"
  26. #define  SCHEME_INI_SYSTEM "任务记事-系统任务分页.ini"
  27. #define  SCHEME_INI_PERSONAL "任务记事-个人记事分页.ini"
  28. //////////////////////////////////////////////////////////////////////////
  29. // Editor
  30. //////////////////////////////////////////////////////////////////////////
  31. KTaskEdit::KTaskEdit()
  32. {
  33. m_Text[0] = m_Text[sizeof(m_Text) - 1] = 0;
  34. SetTextPtr(m_Text, sizeof(m_Text));
  35. }
  36. //////////////////////////////////////////////////////////////////////////
  37. // Page: Personal
  38. //////////////////////////////////////////////////////////////////////////
  39. void KUiTaskNote_Personal::Initialize()
  40. {
  41. AddChild(&m_BtnSave);
  42. AddChild(&m_Editor);
  43. AddChild(&m_ScrollBar);
  44. }
  45. void KUiTaskNote_Personal::LoadScheme(const char* pScheme)
  46. {
  47. char Buff[128];
  48. KIniFile Ini;
  49. sprintf(Buff, "%s\%s", pScheme, SCHEME_INI_PERSONAL);
  50. if (Ini.Load(Buff))
  51. {
  52. KWndPage::Init(&Ini, "Main");
  53. m_BtnSave.Init(&Ini, "SaveBtn");
  54. m_Editor.Init(&Ini, "Editor");
  55. m_ScrollBar.Init(&Ini, "EditorScroll");
  56. }
  57. }
  58. void KUiTaskNote_Personal::UpdateView()
  59. {
  60. char cBuffer[2048];
  61. if (KTaskDataFile::GetPersonalRecord(cBuffer, sizeof(cBuffer)))
  62. m_Editor.SetText(cBuffer);
  63. else
  64. m_Editor.ClearText(false);
  65. }
  66. void KUiTaskNote_Personal::UpdateData()
  67. {
  68. OnSave();
  69. }
  70. int KUiTaskNote_Personal::WndProc(unsigned int uMsg, unsigned int uParam, int nParam)
  71. {
  72. int nResult = false;
  73. if (uMsg ==  WND_N_BUTTON_CLICK &&
  74. uParam == (unsigned int)(KWndWindow*)&m_BtnSave)
  75. {
  76. OnSave();
  77. nResult = true;
  78. }
  79. else
  80. {
  81. nResult = KWndPage::WndProc(uMsg, uParam, nParam);
  82. }
  83. return nResult;
  84. }
  85. void KUiTaskNote_Personal::Show()
  86. {
  87. Wnd_SetFocusWnd(&m_Editor);
  88. KWndPage::Show();
  89. }
  90. void KUiTaskNote_Personal::Hide()
  91. {
  92. Wnd_SetFocusWnd(NULL);
  93. KWndPage::Hide();
  94. }
  95. // Save information to file.
  96. void KUiTaskNote_Personal::OnSave()
  97. {
  98. char szRecord[2048];
  99. int nLen = m_Editor.GetText(szRecord, sizeof(szRecord), false);
  100. KTaskDataFile::SetPersonalRecord(szRecord, nLen);
  101. }
  102. //////////////////////////////////////////////////////////////////////////
  103. // Page: System
  104. //////////////////////////////////////////////////////////////////////////
  105. // constructor
  106. void KUiTaskNote_System::Initialize()
  107. {
  108. AddChild(&m_BtnDelete);
  109. AddChild(&m_RecordList);
  110. }
  111. void KUiTaskNote_System::LoadScheme(const char* pScheme)
  112. {
  113. char Buff[128];
  114. KIniFile Ini;
  115. sprintf(Buff, "%s\%s", pScheme, SCHEME_INI_SYSTEM);
  116. if (Ini.Load(Buff))
  117. {
  118. KWndPage::Init(&Ini, "Main");
  119. m_BtnDelete.Init(&Ini, "DeleteBtn");
  120. m_RecordList.Init(&Ini, "List");
  121. }
  122. }
  123. int KUiTaskNote_System::WndProc(unsigned int uMsg, unsigned int uParam, int nParam)
  124. {
  125. int nResult = 0;
  126. switch (uMsg)
  127. {
  128. case WND_N_LIST_ITEM_SEL:
  129. if (uParam == (unsigned int)(KWndWindow*)&m_RecordList)
  130. m_BtnDelete.Enable(nParam >= 0);
  131. nResult = 1;
  132. break;
  133. case WND_N_BUTTON_CLICK:
  134. if (uParam == (unsigned int)(KWndWindow*)&m_BtnDelete)
  135. {
  136. OnDelete(m_RecordList.GetMessageListBox()->GetCurSel());
  137. nResult = 1;
  138. }
  139. break;
  140. default:
  141. nResult = KWndPage::WndProc(uMsg, uParam, nParam);
  142. break;
  143. }
  144. return nResult;
  145. }
  146. void KUiTaskNote_System::OnDelete(int nIndex)
  147. {
  148. if (KTaskDataFile::RemoveSystemRecord(nIndex))
  149. {
  150. m_RecordList.GetMessageListBox()->RemoveAMessage(nIndex);
  151. if (nIndex >= m_RecordList.GetMessageListBox()->GetMsgCount())
  152. {
  153. nIndex--;
  154. }
  155. m_RecordList.GetMessageListBox()->SetCurSel(nIndex);
  156. }
  157. }
  158. void KUiTaskNote_System::UpdateView()
  159. {
  160. m_RecordList.GetMessageListBox()->Clear();
  161. int nCount = KTaskDataFile::GetSystemRecordCount();
  162. if (nCount > 0)
  163. {
  164. m_RecordList.GetMessageListBox()->SetCapability(nCount); //+4是多留些空间
  165. for (int i = 0; i < nCount; i++)
  166. {
  167. const TASK_SYSTEM_RECORD* pRecord = KTaskDataFile::GetSystemRecord(i);
  168. if (pRecord == NULL)
  169. break;
  170. m_RecordList.GetMessageListBox()->AddOneMessage(pRecord->cBuffer, pRecord->nContentLen);
  171. }
  172. }
  173. }
  174. //////////////////////////////////////////////////////////////////////////
  175. //  The main class of this file: KUiTaskNote.
  176. //////////////////////////////////////////////////////////////////////////
  177. KUiTaskNote* KUiTaskNote::m_pSelf = NULL;
  178. // constructor. 
  179. KUiTaskNote::KUiTaskNote()
  180. {
  181. }
  182. // destructor
  183. KUiTaskNote::~KUiTaskNote()
  184. {
  185. }
  186. // opennnnnnnnnnnnnnnnnnnnnnnnnnn
  187. KUiTaskNote* KUiTaskNote::OpenWindow()
  188. {
  189. if (m_pSelf == NULL)
  190. {
  191. m_pSelf = new KUiTaskNote;
  192. if (m_pSelf)
  193. {
  194. m_pSelf->Initialize();
  195. m_pSelf->InitData();
  196. }
  197. }
  198. if (m_pSelf)
  199. {
  200. UiSoundPlay(UI_SI_WND_OPENCLOSE);
  201. m_pSelf->BringToTop();
  202. m_pSelf->Show();
  203. }
  204. return m_pSelf;
  205. }
  206. // ....
  207. void KUiTaskNote::CloseWindow(bool bDestroy)
  208. {
  209. if (m_pSelf)
  210. {
  211. m_pSelf->Hide();
  212. if (bDestroy)
  213. {
  214. m_pSelf->SaveData();
  215. KTaskDataFile::ClearAll();
  216. m_pSelf->Destroy();
  217. m_pSelf = NULL;
  218. }
  219. }
  220. }
  221. // is it visible?
  222. KUiTaskNote* KUiTaskNote::GetIfVisible()
  223. {
  224. if (m_pSelf && m_pSelf->IsVisible())
  225. return m_pSelf;
  226. return NULL;
  227. }
  228. void KUiTaskNote::InitData()
  229. {
  230. KTaskDataFile::LoadData();
  231. m_PersonalPad.UpdateView();
  232. m_SystemPad.UpdateView();
  233. }
  234. //保存数据
  235. void KUiTaskNote::SaveData()
  236. {
  237. m_PersonalPad.UpdateData();
  238. KTaskDataFile::SaveData();
  239. }
  240. // Load the face
  241. void KUiTaskNote::LoadScheme(const char* pScheme)
  242. {
  243. if (m_pSelf)
  244. {
  245. char Buff[128];
  246. KIniFile Ini;
  247. sprintf(Buff, "%s\%s", pScheme, SCHEME_INI_TASKNOTE);
  248. if (Ini.Load(Buff))
  249. {
  250. m_pSelf->Init(&Ini, "Main");
  251. m_pSelf->m_BtnSystem.Init(&Ini, "SystemBtn");
  252. m_pSelf->m_BtnPersonal.Init(&Ini, "PersonalBtn");
  253. m_pSelf->m_BtnClose.Init(&Ini, "CloseBtn");
  254. m_pSelf->m_SystemPad.LoadScheme(pScheme);
  255. m_pSelf->m_PersonalPad.LoadScheme(pScheme);
  256. }
  257. }
  258. }
  259. // Initialize
  260. void KUiTaskNote::Initialize()
  261. {
  262. m_SystemPad.Initialize();
  263. AddPage(&m_SystemPad, &m_BtnSystem);
  264. m_PersonalPad.Initialize();
  265. AddPage(&m_PersonalPad, &m_BtnPersonal);
  266. AddChild(&m_BtnClose);
  267. char Scheme[256];
  268. g_UiBase.GetCurSchemePath(Scheme, sizeof(Scheme));
  269. LoadScheme(Scheme);
  270. Wnd_AddWindow(this);
  271. }
  272. // Deal with the window messages.
  273. int KUiTaskNote::WndProc(unsigned int uMsg, unsigned int uParam, int nParam)
  274. {
  275. int nResult = false;
  276. if (uMsg == WND_N_BUTTON_CLICK)
  277. {
  278. if (uParam == (unsigned int)(KWndWindow*)&m_BtnClose)
  279. {
  280. OnClose();
  281. nResult = true;
  282. }
  283. else
  284. {
  285. if (uParam == (unsigned int)(KWndWindow*)&m_BtnPersonal)
  286. m_PersonalPad.Show();
  287. nResult = KWndPageSet::WndProc(uMsg, uParam, nParam);
  288. }
  289. }
  290. else
  291. {
  292. nResult = KWndPageSet::WndProc(uMsg, uParam, nParam);
  293. }
  294. return nResult;
  295. }
  296. void KUiTaskNote::OnClose()
  297. {
  298. CloseWindow(true);
  299. }
  300. void KUiTaskNote::WakeUp(const char* pSystemRecord, int nLen, unsigned int uValue)
  301. {
  302. if (pSystemRecord && nLen > 0)
  303. {
  304. if (m_pSelf == NULL)
  305. KTaskDataFile::LoadData();
  306. TASK_SYSTEM_RECORD Record;
  307. Record.tTime = time(&Record.tTime);
  308. Record.uReserved = uValue;
  309. Record.nContentLen = nLen;
  310. Record.pBuffer = pSystemRecord;
  311. bool bInserted = KTaskDataFile::InsertSystemRecord(&Record);
  312. if (m_pSelf == NULL)
  313. {
  314. if (bInserted)
  315. KTaskDataFile::SaveData();
  316. KTaskDataFile::ClearAll();
  317. }
  318. else if (bInserted)
  319. {
  320. m_pSelf->m_SystemPad.UpdateView();
  321. }
  322. }
  323. }