Skip to content

Commit

Permalink
xrGame/ui/UIActorMenu: support SOC weight indicators (OpenXRay#392)
Browse files Browse the repository at this point in the history
  • Loading branch information
Xottab-DUTY committed Feb 18, 2020
1 parent a5ccd07 commit 0d13ac4
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 4 deletions.
8 changes: 4 additions & 4 deletions src/xrGame/ui/UIActorMenuInitialize.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -284,7 +284,7 @@ void CUIActorMenu::InitializeInventoryMode(CUIXml& uiXml)
UIHelper::CreateStatic(uiXml, "belt_slots", m_pInventoryWnd);
UIHelper::CreateStatic(uiXml, "back", m_pInventoryWnd);
UIHelper::CreateStatic(uiXml, "bottom_static", m_pInventoryWnd);
CUIStatic* bagWnd = UIHelper::CreateStatic(uiXml, "bag_static", m_pInventoryWnd);
m_ActorWeightBar->m_BagWnd = UIHelper::CreateStatic(uiXml, "bag_static", m_pInventoryWnd);

m_ActorMoney = UIHelper::CreateStatic(uiXml, "money_static", m_pInventoryWnd);

Expand All @@ -308,7 +308,7 @@ void CUIActorMenu::InitializeInventoryMode(CUIXml& uiXml)
{ eInventoryAutomaticList, "dragdrop_automatic", m_pInventoryWnd },
{ eInventoryOutfitList, "dragdrop_outfit", m_pInventoryWnd },
{ eInventoryBeltList, "dragdrop_belt", m_pInventoryWnd },
{ eInventoryBagList, "dragdrop_bag", bagWnd },
{ eInventoryBagList, "dragdrop_bag", m_ActorWeightBar->m_BagWnd },
};
for (auto [id, section, parent] : inventory_lists)
{
Expand Down Expand Up @@ -410,10 +410,10 @@ void CUIActorMenu::InitializeSearchLootMode(CUIXml& uiXml)
m_SearchLootPartnerCharacterInfo->SetAutoDelete(true);
m_SearchLootPartnerCharacterInfo->InitCharacterInfo({ 0.f, 0.f }, partnerIcon->GetWndSize(), TRADE_CHARACTER_XML);

CUIStatic* actorBagWnd = UIHelper::CreateStatic(uiXml, "our_bag_static", m_pSearchLootWnd);
m_ActorWeightBar->m_BagWnd2 = UIHelper::CreateStatic(uiXml, "our_bag_static", m_pSearchLootWnd);
CUIStatic* partnerBagWnd = UIHelper::CreateStatic(uiXml, "others_bag_static", m_pSearchLootWnd);

m_pLists[eSearchLootActorBagList] = UIHelper::CreateDragDropListEx(uiXml, "dragdrop_list_our", actorBagWnd);
m_pLists[eSearchLootActorBagList] = UIHelper::CreateDragDropListEx(uiXml, "dragdrop_list_our", m_ActorWeightBar->m_BagWnd2);
m_pLists[eSearchLootBagList] = UIHelper::CreateDragDropListEx(uiXml, "dragdrop_list_other", partnerBagWnd);

// Item info
Expand Down
26 changes: 26 additions & 0 deletions src/xrGame/ui/UIInventoryUtilities.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -361,6 +361,32 @@ LPCSTR InventoryUtilities::GetTimePeriodAsString(LPSTR _buff, u32 buff_sz, ALife
return _buff;
}

void InventoryUtilities::UpdateWeight(CUIStatic& wnd, CInventoryOwner* pInvOwner, bool withPrefix /*= false*/)
{
R_ASSERT(pInvOwner);
string128 buf;

float total = pInvOwner->inventory().CalcTotalWeight();
float max = pInvOwner->MaxCarryWeight();

string16 cl;

if (total > max)
xr_strcpy(cl, "%c[red]");
else
xr_strcpy(cl, "%c[UI_orange]");

string32 prefix;

if (withPrefix)
xr_sprintf(prefix, "%%c[default]%s ", StringTable().translate("ui_inv_weight"));
else
xr_strcpy(prefix, "");

xr_sprintf(buf, "%s%s%3.1f %s/%5.1f", prefix, cl, total, "%c[UI_orange]", max);
wnd.SetText(buf);
}

//////////////////////////////////////////////////////////////////////////

void InventoryUtilities::UpdateWeightStr(CUITextWnd& wnd, CUITextWnd& wnd_max, CInventoryOwner* pInvOwner)
Expand Down
1 change: 1 addition & 0 deletions src/xrGame/ui/UIInventoryUtilities.h
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ const shared_str Get_GameTimeAndDate_AsString();

LPCSTR GetTimePeriodAsString(LPSTR _buff, u32 buff_sz, ALife::_TIME_ID _from, ALife::_TIME_ID _to);
// Отобразить вес, который несет (*pInvOwner)
void UpdateWeight(CUIStatic& wnd, CInventoryOwner* pInvOwner, bool withPrefix = false);
void UpdateWeightStr(CUITextWnd& wnd, CUITextWnd& wnd_max, CInventoryOwner* pInvOwner);

// Функции получения строки-идентификатора ранга и отношения по их числовому идентификатору
Expand Down
6 changes: 6 additions & 0 deletions src/xrGame/ui/UIWeightBar.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,12 @@ void CUIWeightBar::UpdateData(float weight)

void CUIWeightBar::UpdateData(CInventoryOwner* pInvOwner)
{
if (m_BagWnd)
InventoryUtilities::UpdateWeight(*m_BagWnd, pInvOwner, true);

if (m_BagWnd2)
InventoryUtilities::UpdateWeight(*m_BagWnd2, pInvOwner, false);

if (!m_Weight || !m_WeightMax || !m_BottomInfo)
return;
InventoryUtilities::UpdateWeightStr(*m_Weight, *m_WeightMax, pInvOwner);
Expand Down
4 changes: 4 additions & 0 deletions src/xrGame/ui/UIWeightBar.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ class CUIWeightBar : public CUIWindow
CUITextWnd* m_WeightMax{};
float m_Weight_end_x{};

public:
CUIStatic* m_BagWnd{};
CUIStatic* m_BagWnd2{};

public:
void init_from_xml(CUIXml& uiXml, pcstr path);
void UpdateData(float weight);
Expand Down

0 comments on commit 0d13ac4

Please sign in to comment.