Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
129 changes: 109 additions & 20 deletions src/source/NewUIInventoryCtrl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -534,6 +534,80 @@ void SEASON3B::CNewUIInventoryCtrl::RemoveItem(ITEM* pItem)
}
}

bool SEASON3B::CNewUIInventoryCtrl::RemoveItemAt(int iLinealPos)
{
iLinealPos -= m_nIndexOffset;
ITEM* pItem = this->FindItemFromSlotIndex(iLinealPos, true);
if (pItem == nullptr)
{
return false;
}

this->RemoveItem(pItem);
return true;
}

ITEM* SEASON3B::CNewUIInventoryCtrl::FindItemFromSlotIndex(const int slotIndex, const bool recoverIfMissing)
{
if (slotIndex < 0 || slotIndex >= m_nColumn * m_nRow)
{
return nullptr;
}

const DWORD key = m_pdwItemCheckBox[slotIndex];
if (key <= 1)
{
return nullptr;
}

ITEM* pItem = this->FindItemByKey(key);
if (pItem != nullptr)
{
return pItem;
}

if (recoverIfMissing)
{
this->ClearSlotKey(key);
this->RequestInventoryRefresh();
}

return nullptr;
}

void SEASON3B::CNewUIInventoryCtrl::ClearSlotKey(const DWORD key)
{
if (key == 0)
{
return;
}

for (int i = 0; i < m_nColumn * m_nRow; ++i)
{
if (m_pdwItemCheckBox[i] == key)
{
m_pdwItemCheckBox[i] = 0;
}
}
}

void SEASON3B::CNewUIInventoryCtrl::RequestInventoryRefresh() const
{
static DWORD lastRefreshRequestTick = 0;
const DWORD currentTick = GetTickCount();
if (currentTick - lastRefreshRequestTick < 1000)
{
return;
}

lastRefreshRequestTick = currentTick;

if (SocketClient != nullptr && SocketClient->ToGameServer() != nullptr)
{
SocketClient->ToGameServer()->SendInventoryRequest();
}
}
Comment thread
olisikh marked this conversation as resolved.

void SEASON3B::CNewUIInventoryCtrl::RemoveAllItems()
{
memset(m_pdwItemCheckBox, 0, sizeof(DWORD) * m_nColumn * m_nRow);
Expand Down Expand Up @@ -583,12 +657,7 @@ void SEASON3B::CNewUIInventoryCtrl::GetSquareColorWarning(float* pfParams) const
ITEM* SEASON3B::CNewUIInventoryCtrl::FindItem(int iLinealPos)
{
iLinealPos -= m_nIndexOffset;
if (iLinealPos >= 0 && iLinealPos < m_nColumn * m_nRow)
{
const DWORD dwKey = m_pdwItemCheckBox[iLinealPos];
return FindItemByKey(dwKey);
}
return nullptr;
return this->FindItemFromSlotIndex(iLinealPos, true);
}

ITEM* SEASON3B::CNewUIInventoryCtrl::FindItem(int iColumnX, int iRowY)
Expand Down Expand Up @@ -819,7 +888,7 @@ bool SEASON3B::CNewUIInventoryCtrl::UpdateMouseEvent()
)
{
m_EventState = EVENT_PICKING;
ITEM* pItem = FindItemByKey(m_pdwItemCheckBox[m_iPointedSquareIndex - m_nIndexOffset]);
ITEM* pItem = this->FindItem(m_iPointedSquareIndex);
if (pItem)
{
if (CreatePickedItem(this, pItem))
Expand All @@ -835,8 +904,8 @@ bool SEASON3B::CNewUIInventoryCtrl::UpdateMouseEvent()
&& nullptr == GetPickedItem()
&& (m_pdwItemCheckBox[m_iPointedSquareIndex - m_nIndexOffset] > 1) && g_pNewUIMng)
{
ITEM* pItem = FindItemByKey(m_pdwItemCheckBox[m_iPointedSquareIndex - m_nIndexOffset]);
if (pItem != m_pToolTipItem)
ITEM* pItem = this->FindItem(m_iPointedSquareIndex);
if (pItem != nullptr && pItem != m_pToolTipItem)
{
CreateItemToolTip(pItem);

Expand Down Expand Up @@ -871,8 +940,13 @@ void SEASON3B::CNewUIInventoryCtrl::UpdateProcess()
m_iPointedSquareIndex = iCurSquareIndex;
}

if (m_iPointedSquareIndex == -1
|| (m_iPointedSquareIndex != -1 && m_pdwItemCheckBox[m_iPointedSquareIndex - m_nIndexOffset] == 0))
bool hasValidPointedItem = false;
if (m_iPointedSquareIndex != -1)
{
hasValidPointedItem = this->FindItem(m_iPointedSquareIndex) != nullptr;
}

if (m_iPointedSquareIndex == -1 || !hasValidPointedItem)
{
m_EventState = EVENT_NONE;
DeleteItemToolTip();
Expand All @@ -888,11 +962,12 @@ void SEASON3B::CNewUIInventoryCtrl::Render()
{
const int iCurSquareIndex = y * m_nColumn + x;

if (m_pdwItemCheckBox[iCurSquareIndex] > 1)
const DWORD slotKey = m_pdwItemCheckBox[iCurSquareIndex];
if (slotKey > 1)
{
EnableAlphaTest();

ITEM* pItem = FindItemByKey(m_pdwItemCheckBox[iCurSquareIndex]);
ITEM* pItem = FindItemByKey(slotKey);

if (pItem)
{
Expand Down Expand Up @@ -928,7 +1003,9 @@ void SEASON3B::CNewUIInventoryCtrl::Render()
}
else
{
glColor4f(0.3f, 0.5f, 0.5f, 0.6f);
this->ClearSlotKey(slotKey);
this->RequestInventoryRefresh();
Comment thread
olisikh marked this conversation as resolved.
glColor4f(0.f, 0.f, 0.f, 0.f);
}

RenderColor(m_Pos.x + (x * INVENTORY_SQUARE_WIDTH), m_Pos.y + (y * INVENTORY_SQUARE_HEIGHT), INVENTORY_SQUARE_WIDTH, INVENTORY_SQUARE_HEIGHT);
Expand Down Expand Up @@ -1247,9 +1324,16 @@ bool SEASON3B::CNewUIInventoryCtrl::CheckSlot(int startIndex, int width, int hei
return false;
}

if (m_pdwItemCheckBox[iIndex] != 0)
const DWORD slotKey = m_pdwItemCheckBox[iIndex];
if (slotKey != 0)
{
return false;
if (slotKey == 1 || this->FindItemByKey(slotKey) != nullptr)
{
return false;
}
Comment thread
olisikh marked this conversation as resolved.

this->ClearSlotKey(slotKey);
this->RequestInventoryRefresh();
}
}
}
Expand Down Expand Up @@ -1507,9 +1591,14 @@ void SEASON3B::CNewUIInventoryCtrl::BackupPickedItem()
ITEM* pItemObj = ms_pPickedItem->GetItem();
if (pOwner)
{
pOwner->AddItem(pItemObj->x, pItemObj->y, pItemObj);

DeletePickedItem();
if (pOwner->AddItem(pItemObj->x, pItemObj->y, pItemObj))
{
DeletePickedItem();
}
else
{
pOwner->RequestInventoryRefresh();
}
}
else if (pItemObj->ex_src_type == ITEM_EX_SRC_EQUIPMENT)
{
Expand Down Expand Up @@ -1734,4 +1823,4 @@ bool SEASON3B::CNewUIInventoryCtrl::CanUpgradeItem(ITEM* pSourceItem, ITEM* pTar
}

return false;
}
}
5 changes: 5 additions & 0 deletions src/source/NewUIInventoryCtrl.h
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,10 @@ namespace SEASON3B

void UpdateProcess();

ITEM* FindItemFromSlotIndex(int slotIndex, bool recoverIfMissing);
void ClearSlotKey(DWORD key);
void RequestInventoryRefresh() const;

bool CheckSlot(int startIndex, int width, int height);
bool CheckSlot(int iColumnX, int iRowY, int width, int height);
public:
Expand All @@ -174,6 +178,7 @@ namespace SEASON3B
bool AddItem(int iColumnX, int iRowY, BYTE byType, BYTE bySubType, BYTE byLevel = 0, BYTE byDurability = 255,
BYTE byOption1 = 0, BYTE byOptionEx = 0, BYTE byOption380 = 0, BYTE byOptionHarmony = 0);
void RemoveItem(ITEM* pItem);
bool RemoveItemAt(int iLinealPos);
void RemoveAllItems();

size_t GetNumberOfItems();
Expand Down
5 changes: 2 additions & 3 deletions src/source/NewUIInventoryExtension.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -290,7 +290,7 @@ bool CNewUIInventoryExtension::InsertItem(int iIndex, std::span<const BYTE> pbyI
{
if (const auto& extension = TryGetExtensionByInventoryIndex(iIndex))
{
extension->AddItem(iIndex, pbyItemPacket);
return extension->AddItem(iIndex, pbyItemPacket);
}

return false;
Expand All @@ -300,9 +300,8 @@ void CNewUIInventoryExtension::DeleteItem(int iIndex) const
{
if (const auto& extension = TryGetExtensionByInventoryIndex(iIndex))
{
if (const auto& pItem = extension->FindItem(iIndex))
if (extension->RemoveItemAt(iIndex))
{
extension->RemoveItem(pItem);
return;
}

Expand Down
19 changes: 8 additions & 11 deletions src/source/NewUIMyInventory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -377,22 +377,19 @@ void CNewUIMyInventory::DeleteItem(int iIndex) const
{
if (m_pNewInventoryCtrl)
{
ITEM* pItem = m_pNewInventoryCtrl->FindItem(iIndex);
if (pItem != nullptr)
if (m_pNewInventoryCtrl->RemoveItemAt(iIndex))
{
m_pNewInventoryCtrl->RemoveItem(pItem);
return;
}
else

CNewUIPickedItem* pPickedItem = CNewUIInventoryCtrl::GetPickedItem();
if (pPickedItem)
{
CNewUIPickedItem* pPickedItem = CNewUIInventoryCtrl::GetPickedItem();
if (pPickedItem)
if (pPickedItem->GetOwnerInventory() == m_pNewInventoryCtrl)
{
if (pPickedItem->GetOwnerInventory() == m_pNewInventoryCtrl)
if (pPickedItem->GetSourceLinealPos() == iIndex)
{
if (pPickedItem->GetSourceLinealPos() == iIndex)
{
CNewUIInventoryCtrl::DeletePickedItem();
}
CNewUIInventoryCtrl::DeletePickedItem();
}
}
}
Expand Down
Loading
Loading