From 94d0f9eaac945e5b4a515968071a72e369254dc9 Mon Sep 17 00:00:00 2001 From: Chugunov Roman Date: Tue, 24 Dec 2024 15:35:52 +0300 Subject: [PATCH] xrGame/ui/UIActorMenu.cpp: refact code for change inv grid size --- src/xrGame/console_commands.cpp | 12 ------------ src/xrGame/ui/UIActorMenu.cpp | 21 +++------------------ src/xrGame/ui/UIActorMenu.h | 2 +- src/xrGame/ui/UIActorMenuDeadBodySearch.cpp | 4 ++++ src/xrGame/ui/UIActorMenuInventory.cpp | 2 ++ src/xrGame/ui/UIActorMenuTrade.cpp | 5 +++++ 6 files changed, 15 insertions(+), 31 deletions(-) diff --git a/src/xrGame/console_commands.cpp b/src/xrGame/console_commands.cpp index 749bac67b7f..c0f1a291c1b 100644 --- a/src/xrGame/console_commands.cpp +++ b/src/xrGame/console_commands.cpp @@ -2140,18 +2140,6 @@ class CCC_InvCellSize : public CCC_Integer else *value = num; - if (!g_pGameLevel) - return; - CUIGameSP* ui_game_sp = smart_cast(CurrentGameUI()); - if (!ui_game_sp) - return; - CUIActorMenu* actor_menu = smart_cast(&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); } diff --git a/src/xrGame/ui/UIActorMenu.cpp b/src/xrGame/ui/UIActorMenu.cpp index b724fb3bd28..fe71781195c 100644 --- a/src/xrGame/ui/UIActorMenu.cpp +++ b/src/xrGame/ui/UIActorMenu.cpp @@ -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); @@ -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(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); diff --git a/src/xrGame/ui/UIActorMenu.h b/src/xrGame/ui/UIActorMenu.h index a1bb514bd6b..20e309d14ba 100644 --- a/src/xrGame/ui/UIActorMenu.h +++ b/src/xrGame/ui/UIActorMenu.h @@ -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); diff --git a/src/xrGame/ui/UIActorMenuDeadBodySearch.cpp b/src/xrGame/ui/UIActorMenuDeadBodySearch.cpp index adb7ee23fe0..9d12c2a8fcc 100644 --- a/src/xrGame/ui/UIActorMenuDeadBodySearch.cpp +++ b/src/xrGame/ui/UIActorMenuDeadBodySearch.cpp @@ -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]); diff --git a/src/xrGame/ui/UIActorMenuInventory.cpp b/src/xrGame/ui/UIActorMenuInventory.cpp index aa1b20fc6ee..df77e48c592 100644 --- a/src/xrGame/ui/UIActorMenuInventory.cpp +++ b/src/xrGame/ui/UIActorMenuInventory.cpp @@ -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); diff --git a/src/xrGame/ui/UIActorMenuTrade.cpp b/src/xrGame/ui/UIActorMenuTrade.cpp index dcc93fe50f0..8a471e3426f 100644 --- a/src/xrGame/ui/UIActorMenuTrade.cpp +++ b/src/xrGame/ui/UIActorMenuTrade.cpp @@ -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)