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

模拟服务器

开发平台:

C/C++

  1. // -------------------------------------------------------------------------
  2. // 文件名 : 交易确认框
  3. // 创建者 : Wooy(Wu yue)
  4. // 创建时间 : 2003-5-28
  5. // -------------------------------------------------------------------------
  6. #include "KWin32.h"
  7. #include "KIniFile.h"
  8. #include "../Elem/AutoLocateWnd.h"
  9. #include "../Elem/WndMessage.h"
  10. #include "../Elem/Wnds.h"
  11. #include "../UiBase.h"
  12. #include "UiTradeConfirmWnd.h"
  13. #include "../UiSoundSetting.h"
  14. #include "../../../core/src/coreshell.h"
  15. extern iCoreShell* g_pCoreShell;
  16. #define SCHEME_INI  "买卖确认.ini"
  17. KUiTradeConfirm* KUiTradeConfirm::m_pSelf = NULL;
  18. //--------------------------------------------------------------------------
  19. // 功能:打开窗口,返回唯一的一个类对象实例
  20. //--------------------------------------------------------------------------
  21. KUiTradeConfirm* KUiTradeConfirm::OpenWindow(KUiObjAtContRegion* pObj,
  22. KUiItemBuySelInfo* pPriceInfo, TRADE_CONFIRM_ACTION eAction)
  23. {
  24. if (pObj == NULL || pPriceInfo == NULL)
  25. return NULL;
  26. if (m_pSelf == NULL)
  27. {
  28. m_pSelf = new KUiTradeConfirm;
  29. if (m_pSelf)
  30. m_pSelf->Initialize();
  31. }
  32. if (m_pSelf)
  33. {
  34. m_pSelf->m_BuyImg.Hide();
  35. m_pSelf->m_SaleImg.Hide();
  36. m_pSelf->m_RepairImg.Hide();
  37. if (eAction == TCA_SALE)
  38. {
  39. m_pSelf->m_SaleImg.Show();
  40. m_pSelf->m_OkBtn.Enable(true);
  41. m_pSelf->m_Money.SetTextColor(m_pSelf->m_uNormalPriceColor);
  42. }
  43. else
  44. {
  45. if (eAction == TCA_BUY)
  46. m_pSelf->m_BuyImg.Show();
  47. else
  48. m_pSelf->m_RepairImg.Show();
  49. int nHoldMoney = g_pCoreShell->GetGameData(GDI_PLAYER_HOLD_MONEY, 0, 0);
  50. m_pSelf->m_OkBtn.Enable(nHoldMoney >= pPriceInfo->nPrice);
  51. m_pSelf->m_Money.SetTextColor((nHoldMoney >= pPriceInfo->nPrice) ?
  52. m_pSelf->m_uNormalPriceColor : m_pSelf->m_uNotEnoughMoneyPriceColor);
  53. }
  54. m_pSelf->m_ItemInfo = *pObj;
  55. m_pSelf->m_PriceInfo = *pPriceInfo;
  56. UiSoundPlay(UI_SI_WND_OPENCLOSE);
  57. m_pSelf->BringToTop();
  58. m_pSelf->Show();
  59. }
  60. return m_pSelf;
  61. }
  62. KUiTradeConfirm::KUiTradeConfirm()
  63. {
  64. m_PriceInfo.szItemName[0] = 0;
  65. m_PriceInfo.nPrice = 0;
  66. m_ItemInfo.Obj.uGenre = CGOG_NOTHING;
  67. }
  68. //如果窗口正被显示,则返回实例指针
  69. KUiTradeConfirm* KUiTradeConfirm::GetIfVisible()
  70. {
  71. if (m_pSelf && m_pSelf->IsVisible())
  72. return m_pSelf;
  73. return NULL;
  74. }
  75. //--------------------------------------------------------------------------
  76. // 功能:关闭销毁窗口
  77. //--------------------------------------------------------------------------
  78. void KUiTradeConfirm::CloseWindow(bool bDestroy)
  79. {
  80. if (m_pSelf)
  81. {
  82. if (bDestroy == false)
  83. m_pSelf->Hide();
  84. else
  85. {
  86. m_pSelf->Destroy();
  87. m_pSelf = NULL;
  88. }
  89. }
  90. }
  91. //显示窗口
  92. void KUiTradeConfirm::Show()
  93. {
  94. m_ItemName.SetText(m_PriceInfo.szItemName);
  95. m_Money.SetIntText(m_PriceInfo.nPrice);
  96. int Left, Top;
  97. ALW_GetWndPosition(Left, Top, m_Width, m_Height);
  98. SetPosition(Left, Top);
  99. KWndImage::Show();
  100. Wnd_SetExclusive((KWndWindow*)this);
  101. }
  102. //隐藏窗口
  103. void KUiTradeConfirm::Hide()
  104. {
  105. Wnd_ReleaseExclusive((KWndWindow*)this);
  106. KWndImage::Hide();
  107. }
  108. //--------------------------------------------------------------------------
  109. // 功能:初始化
  110. //--------------------------------------------------------------------------
  111. int KUiTradeConfirm::Initialize()
  112. {
  113. AddChild(&m_ItemName);
  114. AddChild(&m_Money);
  115. AddChild(&m_BuyImg);
  116. AddChild(&m_SaleImg);
  117. AddChild(&m_RepairImg);
  118. AddChild(&m_OkBtn);
  119. AddChild(&m_CancelBtn);
  120. Wnd_AddWindow(this);
  121. char Scheme[256];
  122. g_UiBase.GetCurSchemePath(Scheme, 256);
  123. LoadScheme(Scheme);
  124. return true;
  125. }
  126. //--------------------------------------------------------------------------
  127. // 功能:载入窗口的界面方案
  128. //--------------------------------------------------------------------------
  129. void KUiTradeConfirm::LoadScheme(const char* pScheme)
  130. {
  131. char Buff[128];
  132. KIniFile Ini;
  133. sprintf(Buff, "%s\%s", pScheme, SCHEME_INI);
  134. if (Ini.Load(Buff))
  135. {
  136. Init(&Ini, "Main");
  137. m_ItemName.Init(&Ini, "ItemName");
  138. m_Money.Init(&Ini, "Price");
  139. Ini.GetString("Price", "Color", "", Buff, sizeof(Buff));
  140. m_uNormalPriceColor = GetColor(Buff);
  141. Ini.GetString("Price", "CantBuyColor", "", Buff, sizeof(Buff));
  142. m_uNotEnoughMoneyPriceColor = GetColor(Buff);
  143. m_BuyImg.Init(&Ini, "BuyImg");
  144. m_SaleImg.Init(&Ini, "SaleImg");
  145. m_RepairImg.Init(&Ini, "RepairImg");
  146. m_OkBtn.Init(&Ini, "OkBtn");
  147. m_CancelBtn.Init(&Ini, "CancelBtn");
  148. m_Money.SetIntText(m_PriceInfo.nPrice);
  149. }
  150. }
  151. //--------------------------------------------------------------------------
  152. // 功能:窗口消息函数
  153. //--------------------------------------------------------------------------
  154. int KUiTradeConfirm::WndProc(unsigned int uMsg, unsigned int uParam, int nParam)
  155. {
  156. int nRet = 0;
  157. switch(uMsg)
  158. {
  159. case WND_N_BUTTON_CLICK:
  160. if (uParam == (unsigned int)(KWndWindow*)&m_OkBtn)
  161. {
  162. if (m_BuyImg.IsVisible())
  163. OnBuy();
  164. else if (m_SaleImg.IsVisible())
  165. OnSale();
  166. else
  167. OnRepair();
  168. }
  169. else if (uParam == (unsigned int)(KWndWindow*)&m_CancelBtn)
  170. OnCancel();
  171. break;
  172. case WM_KEYDOWN:
  173. if (uParam == VK_RETURN)
  174. {
  175. if (m_SaleImg.IsVisible())
  176. {
  177. OnSale();
  178. }
  179. else if (m_BuyImg.IsVisible())
  180. {
  181. if (m_BuyImg.IsDisable())
  182. OnCancel();
  183. else
  184. OnBuy();
  185. }
  186. else if (m_RepairImg.IsDisable())
  187. {
  188. OnCancel();
  189. }
  190. else
  191. {
  192. OnRepair();
  193. }
  194. nRet = 1;
  195. }
  196. else if (uParam == VK_ESCAPE)
  197. {
  198. OnCancel();
  199. nRet = 1;
  200. }
  201. break;
  202. default:
  203. nRet = KWndImage::WndProc(uMsg, uParam, nParam);
  204. }
  205. return nRet;
  206. }
  207. //--------------------------------------------------------------------------
  208. // 功能:响应点击买按钮
  209. //--------------------------------------------------------------------------
  210. void KUiTradeConfirm::OnBuy()
  211. {
  212. if (g_pCoreShell)
  213. {
  214. g_pCoreShell->OperationRequest(GOI_TRADE_NPC_BUY,
  215. (unsigned int)(&m_ItemInfo), 0);
  216. }
  217. CloseWindow(false);
  218. }
  219. //--------------------------------------------------------------------------
  220. // 功能:响应点击卖按钮
  221. //--------------------------------------------------------------------------
  222. void KUiTradeConfirm::OnSale()
  223. {
  224. if (g_pCoreShell)
  225. {
  226. g_pCoreShell->OperationRequest(GOI_TRADE_NPC_SELL,
  227. (unsigned int)(&m_ItemInfo), 0);
  228. }
  229. CloseWindow(false);
  230. }
  231. //--------------------------------------------------------------------------
  232. // 功能:响应点修理按钮
  233. //--------------------------------------------------------------------------
  234. void KUiTradeConfirm::OnRepair()
  235. {
  236. if (g_pCoreShell)
  237. {
  238. g_pCoreShell->OperationRequest(GOI_TRADE_NPC_REPAIR,
  239. (unsigned int)(&m_ItemInfo), 0);
  240. }
  241. CloseWindow(false);
  242. }
  243. void KUiTradeConfirm::OnCancel()
  244. {
  245. CloseWindow(false);
  246. }