Skip to content

Commit 2f03950

Browse files
committed
xrGame/ui/UIWpnParams.h|cpp: compatibility with CS (#382)
1 parent 8904da0 commit 2f03950

File tree

2 files changed

+31
-36
lines changed

2 files changed

+31
-36
lines changed

src/xrGame/ui/UIWpnParams.cpp

+23-28
Original file line numberDiff line numberDiff line change
@@ -44,13 +44,6 @@ SLuaWpnParams::~SLuaWpnParams() {}
4444

4545
CUIWpnParams::CUIWpnParams()
4646
{
47-
AttachChild(&m_Prop_line);
48-
49-
AttachChild(&m_icon_acc);
50-
AttachChild(&m_icon_dam);
51-
AttachChild(&m_icon_han);
52-
AttachChild(&m_icon_rpm);
53-
5447
AttachChild(&m_textAccuracy);
5548
AttachChild(&m_textDamage);
5649
AttachChild(&m_textHandling);
@@ -60,24 +53,22 @@ CUIWpnParams::CUIWpnParams()
6053
AttachChild(&m_progressDamage);
6154
AttachChild(&m_progressHandling);
6255
AttachChild(&m_progressRPM);
63-
64-
AttachChild(&m_stAmmo);
65-
AttachChild(&m_textAmmoCount);
66-
AttachChild(&m_textAmmoCount2);
6756
}
6857

6958
CUIWpnParams::~CUIWpnParams() {}
7059
void CUIWpnParams::InitFromXml(CUIXml& xml_doc)
7160
{
7261
if (!xml_doc.NavigateToNode("wpn_params", 0))
7362
return;
63+
7464
CUIXmlInit::InitWindow(xml_doc, "wpn_params", 0, this);
75-
CUIXmlInit::InitStatic(xml_doc, "wpn_params:prop_line", 0, &m_Prop_line);
7665

77-
CUIXmlInit::InitStatic(xml_doc, "wpn_params:static_accuracy", 0, &m_icon_acc);
78-
CUIXmlInit::InitStatic(xml_doc, "wpn_params:static_damage", 0, &m_icon_dam);
79-
CUIXmlInit::InitStatic(xml_doc, "wpn_params:static_handling", 0, &m_icon_han);
80-
CUIXmlInit::InitStatic(xml_doc, "wpn_params:static_rpm", 0, &m_icon_rpm);
66+
m_Prop_line = UIHelper::CreateStatic(xml_doc, "wpn_params:prop_line", this, false);
67+
68+
m_icon_acc = UIHelper::CreateStatic(xml_doc, "wpn_params:static_accuracy", this, false);
69+
m_icon_dam = UIHelper::CreateStatic(xml_doc, "wpn_params:static_damage", this, false);
70+
m_icon_han = UIHelper::CreateStatic(xml_doc, "wpn_params:static_handling", this, false);
71+
m_icon_rpm = UIHelper::CreateStatic(xml_doc, "wpn_params:static_rpm", this, false);
8172

8273
CUIXmlInit::InitTextWnd(xml_doc, "wpn_params:cap_accuracy", 0, &m_textAccuracy);
8374
CUIXmlInit::InitTextWnd(xml_doc, "wpn_params:cap_damage", 0, &m_textDamage);
@@ -91,9 +82,9 @@ void CUIWpnParams::InitFromXml(CUIXml& xml_doc)
9182

9283
if (IsGameTypeSingle())
9384
{
94-
CUIXmlInit::InitStatic(xml_doc, "wpn_params:static_ammo", 0, &m_stAmmo);
95-
CUIXmlInit::InitTextWnd(xml_doc, "wpn_params:cap_ammo_count", 0, &m_textAmmoCount);
96-
CUIXmlInit::InitTextWnd(xml_doc, "wpn_params:cap_ammo_count2", 0, &m_textAmmoCount2);
85+
m_stAmmo = UIHelper::CreateStatic(xml_doc, "wpn_params:static_ammo", this, false);
86+
m_textAmmoCount = UIHelper::CreateTextWnd(xml_doc, "wpn_params:cap_ammo_count", this, false);
87+
m_textAmmoCount2 = UIHelper::CreateTextWnd(xml_doc, "wpn_params:cap_ammo_count2", this, false);
9788
m_textAmmoTypes = UIHelper::CreateTextWnd(xml_doc, "wpn_params:cap_ammo_types", this, false);
9889
m_textAmmoUsedType = UIHelper::CreateTextWnd(xml_doc, "wpn_params:cap_ammo_used_type", this, false);
9990
m_stAmmoType1 = UIHelper::CreateStatic(xml_doc, "wpn_params:static_ammo_type1", this, false);
@@ -172,23 +163,27 @@ void CUIWpnParams::SetInfo(CInventoryItem* slot_wpn, CInventoryItem& cur_wpn)
172163
ammo_count2 = slot_weapon->GetAmmoMagSize();
173164
}
174165

175-
if (ammo_count == ammo_count2)
176-
m_textAmmoCount2.SetTextColor(color_rgba(170, 170, 170, 255));
177-
else if (ammo_count < ammo_count2)
178-
m_textAmmoCount2.SetTextColor(color_rgba(255, 0, 0, 255));
179-
else
180-
m_textAmmoCount2.SetTextColor(color_rgba(0, 255, 0, 255));
166+
if (m_textAmmoCount2)
167+
{
168+
if (ammo_count == ammo_count2)
169+
m_textAmmoCount2->SetTextColor(color_rgba(170, 170, 170, 255));
170+
else if (ammo_count < ammo_count2)
171+
m_textAmmoCount2->SetTextColor(color_rgba(255, 0, 0, 255));
172+
else
173+
m_textAmmoCount2->SetTextColor(color_rgba(0, 255, 0, 255));
181174

182-
string128 str;
183-
xr_sprintf(str, sizeof(str), "%d", ammo_count);
184-
m_textAmmoCount2.SetText(str);
175+
string128 str;
176+
xr_sprintf(str, sizeof(str), "%d", ammo_count);
177+
m_textAmmoCount2->SetText(str);
178+
}
185179

186180
const auto& ammo_types = weapon->m_ammoTypes;
187181
if (ammo_types.empty())
188182
return;
189183

190184
if (m_textAmmoUsedType)
191185
{
186+
string128 str;
192187
xr_sprintf(str, sizeof(str), "%s", pSettings->r_string(ammo_types[0].c_str(), "inv_name_short"));
193188
m_textAmmoUsedType->SetTextST(str);
194189
}

src/xrGame/ui/UIWpnParams.h

+8-8
Original file line numberDiff line numberDiff line change
@@ -23,23 +23,23 @@ class CUIWpnParams : public CUIWindow
2323
CUIDoubleProgressBar m_progressDamage;
2424
CUIDoubleProgressBar m_progressRPM;
2525

26-
CUIStatic m_icon_acc;
27-
CUIStatic m_icon_dam;
28-
CUIStatic m_icon_han;
29-
CUIStatic m_icon_rpm;
26+
CUIStatic* m_icon_acc;
27+
CUIStatic* m_icon_dam;
28+
CUIStatic* m_icon_han;
29+
CUIStatic* m_icon_rpm;
3030

31-
CUIStatic m_stAmmo;
31+
CUIStatic* m_stAmmo;
3232
CUITextWnd m_textAccuracy;
3333
CUITextWnd m_textHandling;
3434
CUITextWnd m_textDamage;
3535
CUITextWnd m_textRPM;
3636
CUITextWnd* m_textAmmoTypes;
3737
CUITextWnd* m_textAmmoUsedType;
38-
CUITextWnd m_textAmmoCount;
39-
CUITextWnd m_textAmmoCount2;
38+
CUITextWnd* m_textAmmoCount;
39+
CUITextWnd* m_textAmmoCount2;
4040
CUIStatic* m_stAmmoType1;
4141
CUIStatic* m_stAmmoType2;
42-
CUIStatic m_Prop_line;
42+
CUIStatic* m_Prop_line;
4343
};
4444

4545
// -------------------------------------------------------------------------------------------------

0 commit comments

Comments
 (0)