Skip to content

Commit

Permalink
xrGame/ui/UIActorMenu.cpp: refact code for change inv grid size
Browse files Browse the repository at this point in the history
  • Loading branch information
ChugunovRoman committed Dec 24, 2024
1 parent 572203c commit 94d0f9e
Show file tree
Hide file tree
Showing 6 changed files with 15 additions and 31 deletions.
12 changes: 0 additions & 12 deletions src/xrGame/console_commands.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2140,18 +2140,6 @@ class CCC_InvCellSize : public CCC_Integer
else
*value = num;

if (!g_pGameLevel)
return;
CUIGameSP* ui_game_sp = smart_cast<CUIGameSP*>(CurrentGameUI());
if (!ui_game_sp)
return;
CUIActorMenu* actor_menu = smart_cast<CUIActorMenu*>(&ui_game_sp->GetActorMenu());
if (!actor_menu)
return;
if (!actor_menu->IsShown())
return;
actor_menu->UpdateGridSize();
actor_menu->UpdateActor();
}
virtual void GetStatus(TStatus& S) { xr_itoa(*value, S, 10); }
virtual void Info(TInfo& I) { xr_sprintf(I, sizeof(I), "integer value in range [%d,%d]", min, max); }
Expand Down
21 changes: 3 additions & 18 deletions src/xrGame/ui/UIActorMenu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -223,13 +223,8 @@ void CUIActorMenu::Draw()
m_message_static->Draw();
}

void CUIActorMenu::UpdateGridSize()
void CUIActorMenu::SetInvGridSize(CUIDragDropListEx* dragdrop_inv)
{
if (m_pActorInvOwner == nullptr)
return;
if (dragdrop_bag == nullptr)
return;

string32 section;
xr_sprintf(section, "inventory_size_%d", g_inv_inv_cell_size);

Expand All @@ -242,18 +237,8 @@ void CUIActorMenu::UpdateGridSize()
w_cells.y = pSettings->r_u16(section, "rows_num");
w_cells.x = pSettings->r_u16(section, "cols_num");

dragdrop_bag->SetCellSize(w_cell_sz);
dragdrop_bag->SetStartCellsCapacity(w_cells);

TIItemContainer ruck_list = m_pActorInvOwner->inventory().m_ruck;
std::sort(ruck_list.begin(), ruck_list.end(), InventoryUtilities::GreaterRoomInRuck);

for (PIItem item : ruck_list)
{
CUIInventoryCellItem* cell = smart_cast<CUIInventoryCellItem*>(create_cell_item(item));
if (cell)
cell->UpdateIcon();
}
dragdrop_inv->SetCellSize(w_cell_sz);
dragdrop_inv->SetStartCellsCapacity(w_cells);
}
else
Msg("Section: '%s' not found in system.ltx", section);
Expand Down
2 changes: 1 addition & 1 deletion src/xrGame/ui/UIActorMenu.h
Original file line number Diff line number Diff line change
Expand Up @@ -372,7 +372,7 @@ class CUIActorMenu final : public CUIDialogWnd, public CUIWndCallback
virtual void SendMessage(CUIWindow* pWnd, s16 msg, void* pData = NULL);
virtual void Draw();
virtual void Update();
virtual void UpdateGridSize();
void SetInvGridSize(CUIDragDropListEx* dragdrop_inv);
virtual void Show(bool status);

virtual bool OnKeyboardAction(int dik, EUIMessages keyboard_action);
Expand Down
4 changes: 4 additions & 0 deletions src/xrGame/ui/UIActorMenuDeadBodySearch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,10 @@ void CUIActorMenu::InitDeadBodySearchMode()
m_takeall_button->Show(true);
GetModeSpecificPartnerInfo(mmDeadBodySearch)->Show(nullptr != m_pPartnerInvOwner);

SetInvGridSize(m_pLists[eSearchLootBagList]);
SetInvGridSize(m_pLists[eSearchLootActorBagList]);
SetInvGridSize(m_pLists[eInventoryBagList]);

InitInventoryContents(m_pLists[eSearchLootActorBagList],
m_pLists[eSearchLootActorBagList] != m_pLists[eInventoryBagList]);

Expand Down
2 changes: 2 additions & 0 deletions src/xrGame/ui/UIActorMenuInventory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -423,6 +423,8 @@ void CUIActorMenu::InitInventoryContents(CUIDragDropListEx* pBagList, bool onlyB

CUIDragDropListEx* curr_list = pBagList;

SetInvGridSize(curr_list);

TIItemContainer ruck_list = m_pActorInvOwner->inventory().m_ruck;
std::sort(ruck_list.begin(), ruck_list.end(), InventoryUtilities::GreaterRoomInRuck);

Expand Down
5 changes: 5 additions & 0 deletions src/xrGame/ui/UIActorMenuTrade.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,11 @@ void CUIActorMenu::InitPartnerInventoryContents()
m_pPartnerInvOwner->inventory().AddAvailableItems(items_list, true);
std::sort(items_list.begin(), items_list.end(), InventoryUtilities::GreaterRoomInRuck);

SetInvGridSize(m_pLists[eTradeActorList]);
SetInvGridSize(m_pLists[eTradeActorBagList]);
SetInvGridSize(m_pLists[eTradePartnerList]);
SetInvGridSize(m_pLists[eTradePartnerBagList]);

TIItemContainer::iterator itb = items_list.begin();
TIItemContainer::iterator ite = items_list.end();
for (; itb != ite; ++itb)
Expand Down

0 comments on commit 94d0f9e

Please sign in to comment.