Advertisement
ikiyah

WndFastJewelSelect.cpp

Oct 23rd, 2020 (edited)
486
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 5.88 KB | None | 0 0
  1. #include "StdAfx.h"
  2. #include "WndFastJewelSelect.h"
  3. #include "ResData.h"
  4. #include "DPClient.h"
  5. extern CDPClient g_DPlay;
  6.  
  7. CWndFastJewelSelect::CWndFastJewelSelect() : gemOptions(nullptr), startButton(nullptr), cancelbutton(nullptr), itemStatic(nullptr), gemStatic(nullptr), itemTexture(nullptr), gemTexture(nullptr),
  8.     itemElem(nullptr), gemItem(nullptr), tickTimer(0)
  9. {
  10. }
  11.  
  12. CWndFastJewelSelect::~CWndFastJewelSelect()
  13. {
  14.     if (itemElem)
  15.         itemElem->SetExtra(0);
  16.     if (gemItem)
  17.         gemItem->SetExtra(0);
  18.  
  19.     gemItem = itemElem = nullptr;
  20. }
  21.  
  22. BOOL CWndFastJewelSelect::Initialize(CWndBase* pWndParent, DWORD)
  23. {
  24.     return InitDialog(g_Neuz.GetSafeHwnd(), APP_FASTJEWEL, 0, CPoint(0, 0), pWndParent);
  25. }
  26.  
  27. void CWndFastJewelSelect::putItem(const unsigned long id)
  28. {
  29.     CItemElem* pTempElem = dynamic_cast<CItemElem*>(g_pPlayer->GetItemId(id));
  30.     if (!pTempElem)
  31.         return;
  32.  
  33.     ItemProp* pItemProp = pTempElem->GetProp();
  34.     if (!pItemProp)
  35.         return;
  36.  
  37.     putItem(pTempElem, pItemProp);
  38. }
  39.  
  40. void CWndFastJewelSelect::putItem(CItemElem* pItemElem, const ItemProp* iProp)
  41. {
  42.     if (iProp->dwReferStat1 == WEAPON_ULTIMATE)
  43.     {
  44.         const auto size = pItemElem->GetUltimatePiercingSize();
  45.         int i = 0;
  46.         for (; i < size; ++i)
  47.         {
  48.             if (pItemElem->GetUltimatePiercingItem(i) == 0)
  49.                 break;
  50.         }
  51.  
  52.         if (size == 0 || i == size)
  53.         {
  54.             g_WndMng.PutString("Need an item with avaliable slots!");
  55.             return;
  56.         }
  57.  
  58.         itemElem = pItemElem;
  59.         itemElem->SetExtra(itemElem->m_nItemNum);
  60.         itemTexture = CWndBase::m_textureMng.AddTexture(g_Neuz.m_pd3dDevice, MakePath(DIR_ITEM, iProp->szIcon), 0xffff00ff);
  61.     }
  62.     else if (iProp->dwItemKind3 == IK3_ULTIMATE)
  63.     {
  64.         gemItem = pItemElem;
  65.         gemItem->SetExtra(gemItem->m_nItemNum);
  66.         gemTexture = CWndBase::m_textureMng.AddTexture(g_Neuz.m_pd3dDevice, MakePath(DIR_ITEM, iProp->szIcon), 0xffff00ff);
  67.     }
  68. }
  69.  
  70. void CWndFastJewelSelect::setDefaultGemTexture()
  71. {
  72.     std::string textureName;
  73.     switch (xRandom(5))
  74.     {
  75.         case 0:
  76.             textureName = "Itm_GenMatRuby.dds";
  77.             break;
  78.         case 1:
  79.             textureName = "Itm_GenMatTopaz.dds";
  80.             break;
  81.         case 2:
  82.             textureName = "Itm_GenMatSapphire.dds";
  83.             break;
  84.         case 3:
  85.             textureName = "Itm_GenMatEmerald.dds";
  86.             break;
  87.         case 4:
  88.         default:
  89.             textureName = "Itm_GenMatDiamond.dds";
  90.             break;
  91.     }
  92.     gemTexture = CWndBase::m_textureMng.AddTexture(g_Neuz.m_pd3dDevice, MakePath(DIR_ITEM, textureName.c_str()), 0xffff00ff);
  93. }
  94.  
  95. void CWndFastJewelSelect::OnInitialUpdate()
  96. {
  97.     CWndNeuz::OnInitialUpdate();
  98.     gemOptions = dynamic_cast<CWndComboBox*>(GetDlgItem(WIDC_COMBOBOX1));
  99.     for (auto& iter : prj.m_UltimateWeapon.m_vecGemAbilityKind)
  100.     {
  101.         const int pos = gemOptions->AddString(g_WndMng.findDstString(iter.nAbility));
  102.         gemOptions->SetItemData(pos, iter.nAbility);
  103.     }
  104.     gemOptions->SetCurSel(0);
  105.     gemOptions->AddWndStyle(EBS_READONLY);
  106.  
  107.     startButton = dynamic_cast<CWndButton*>(GetDlgItem(WIDC_BUTTON10));
  108.     cancelbutton = dynamic_cast<CWndButton*>(GetDlgItem(WIDC_BUTTON11));
  109.    
  110.     itemStatic = dynamic_cast<CWndStatic*>(GetDlgItem(WIDC_STATIC1));
  111.     gemStatic = dynamic_cast<CWndStatic*>(GetDlgItem(WIDC_STATIC2));
  112.     setDefaultGemTexture();
  113.     MoveParentCenter();
  114. }
  115.  
  116.  
  117. void CWndFastJewelSelect::OnLButtonUp(UINT nFlags, CPoint point)
  118. {
  119.     if (itemStatic && itemStatic->GetWndRect().PtInRect(point))
  120.     {
  121.         if (itemElem)
  122.         {
  123.             itemElem->SetExtra(0);
  124.             itemElem = nullptr;
  125.             itemTexture = nullptr;
  126.         }
  127.     }
  128.     if (gemStatic && gemStatic->GetWndRect().PtInRect(point))
  129.     {
  130.         if (gemItem)
  131.         {
  132.             gemItem->SetExtra(0);
  133.             gemItem = nullptr;
  134.             setDefaultGemTexture();
  135.         }
  136.     }
  137. }
  138.  
  139.  
  140. void CWndFastJewelSelect::OnDraw(C2DRender* p2DRender)
  141. {
  142.     if (gemTexture && gemStatic)
  143.     {
  144.         if (gemItem)
  145.         {
  146.             gemTexture->Render(p2DRender, CPoint(gemStatic->GetWndRect().left, gemStatic->GetWndRect().top));
  147.             p2DRender->TextOut(gemStatic->GetWndRect().left, gemStatic->GetWndRect().bottom - 6, 0.8f, 0.8f, std::to_string(gemItem->GetExtra()).c_str(), 0xff000000);
  148.         }
  149.         else
  150.             gemTexture->Render(p2DRender, CPoint(gemStatic->GetWndRect().left, gemStatic->GetWndRect().top), 80);
  151.     }
  152.  
  153.     if (itemElem)
  154.     {
  155.         if (itemTexture && itemStatic)
  156.             itemTexture->Render(p2DRender, CPoint(itemStatic->GetWndRect().left, itemStatic->GetWndRect().top));
  157.  
  158.         if (!tickTimer)
  159.         {
  160.             if (gemItem)
  161.                 startButton->EnableWindow(true);
  162.             else
  163.                 startButton->EnableWindow(false);
  164.         }
  165.     }
  166.  
  167.     if (tickTimer)
  168.     {
  169.         if (g_tmCurrent >= tickTimer)
  170.         {
  171.             startButton->EnableWindow(true);
  172.             tickTimer = 0;
  173.         }
  174.         else
  175.             startButton->EnableWindow(false);          
  176.     }
  177. }
  178.  
  179.  
  180. BOOL CWndFastJewelSelect::OnDropIcon(LPSHORTCUT pShortcut, CPoint point)
  181. {
  182.     CWndBase* pWndFrame = pShortcut->m_pFromWnd->GetFrameWnd();
  183.     if (!pWndFrame)
  184.         return false;
  185.  
  186.     if (pWndFrame->GetWndId() != APP_INVENTORY && pWndFrame->GetWndId() != APP_BAG_EX)
  187.     {
  188.         SetForbid(true);
  189.         return false;
  190.     }
  191.    
  192.     if (pShortcut->m_dwShortcut == SHORTCUT_ITEM)
  193.         putItem(pShortcut->m_dwId);
  194.     return false;
  195. }
  196.  
  197. BOOL CWndFastJewelSelect::OnChildNotify(const UINT message, const UINT nID, LRESULT* pLResult)
  198. {
  199.     switch (nID)
  200.     {
  201.         case WIDC_BUTTON10:
  202.         {
  203.             if (gemOptions->GetCurSel() < 0 || !itemElem || !gemItem)
  204.                 break;
  205.  
  206.             int i = 0;
  207.             for (; i < itemElem->GetUltimatePiercingSize(); ++i)
  208.             {
  209.                 if (itemElem->GetUltimatePiercingItem(i) == 0)
  210.                     break;
  211.             }
  212.             if (i == itemElem->GetUltimatePiercingSize())
  213.             {
  214.                 g_WndMng.PutString("Need an item with avaliable slots!");
  215.                 break;
  216.             }
  217.  
  218.             tickTimer = g_tmCurrent += 2000;
  219.             g_DPlay.sendFastJewelSelect(itemElem->m_dwObjId, gemItem->m_dwObjId, gemOptions->GetItemData(gemOptions->GetCurSel()));
  220.             if (gemItem->GetExtra() > 1)
  221.                 gemItem->SetExtra(gemItem->GetExtra() - 1);
  222.             else
  223.             {
  224.                 gemItem->SetExtra(0);
  225.                 gemItem = nullptr;
  226.                 setDefaultGemTexture();
  227.             }
  228.            
  229.             break;
  230.         }
  231.         case WIDC_BUTTON11:
  232.         {
  233.             Destroy();
  234.             break;
  235.         }
  236.         default:
  237.         break;
  238.     }
  239.     return CWndNeuz::OnChildNotify(message, nID, pLResult);
  240. }
  241.  
  242.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement