Skip to content

Commit

Permalink
xrGame/ui/UIWpnParams.h|cpp: compatibility with CS (#382)
Browse files Browse the repository at this point in the history
  • Loading branch information
Xottab-DUTY committed May 14, 2019
1 parent 8904da0 commit 2f03950
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 36 deletions.
51 changes: 23 additions & 28 deletions src/xrGame/ui/UIWpnParams.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,13 +44,6 @@ SLuaWpnParams::~SLuaWpnParams() {}

CUIWpnParams::CUIWpnParams()
{
AttachChild(&m_Prop_line);

AttachChild(&m_icon_acc);
AttachChild(&m_icon_dam);
AttachChild(&m_icon_han);
AttachChild(&m_icon_rpm);

AttachChild(&m_textAccuracy);
AttachChild(&m_textDamage);
AttachChild(&m_textHandling);
Expand All @@ -60,24 +53,22 @@ CUIWpnParams::CUIWpnParams()
AttachChild(&m_progressDamage);
AttachChild(&m_progressHandling);
AttachChild(&m_progressRPM);

AttachChild(&m_stAmmo);
AttachChild(&m_textAmmoCount);
AttachChild(&m_textAmmoCount2);
}

CUIWpnParams::~CUIWpnParams() {}
void CUIWpnParams::InitFromXml(CUIXml& xml_doc)
{
if (!xml_doc.NavigateToNode("wpn_params", 0))
return;

CUIXmlInit::InitWindow(xml_doc, "wpn_params", 0, this);
CUIXmlInit::InitStatic(xml_doc, "wpn_params:prop_line", 0, &m_Prop_line);

CUIXmlInit::InitStatic(xml_doc, "wpn_params:static_accuracy", 0, &m_icon_acc);
CUIXmlInit::InitStatic(xml_doc, "wpn_params:static_damage", 0, &m_icon_dam);
CUIXmlInit::InitStatic(xml_doc, "wpn_params:static_handling", 0, &m_icon_han);
CUIXmlInit::InitStatic(xml_doc, "wpn_params:static_rpm", 0, &m_icon_rpm);
m_Prop_line = UIHelper::CreateStatic(xml_doc, "wpn_params:prop_line", this, false);

m_icon_acc = UIHelper::CreateStatic(xml_doc, "wpn_params:static_accuracy", this, false);
m_icon_dam = UIHelper::CreateStatic(xml_doc, "wpn_params:static_damage", this, false);
m_icon_han = UIHelper::CreateStatic(xml_doc, "wpn_params:static_handling", this, false);
m_icon_rpm = UIHelper::CreateStatic(xml_doc, "wpn_params:static_rpm", this, false);

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

if (IsGameTypeSingle())
{
CUIXmlInit::InitStatic(xml_doc, "wpn_params:static_ammo", 0, &m_stAmmo);
CUIXmlInit::InitTextWnd(xml_doc, "wpn_params:cap_ammo_count", 0, &m_textAmmoCount);
CUIXmlInit::InitTextWnd(xml_doc, "wpn_params:cap_ammo_count2", 0, &m_textAmmoCount2);
m_stAmmo = UIHelper::CreateStatic(xml_doc, "wpn_params:static_ammo", this, false);
m_textAmmoCount = UIHelper::CreateTextWnd(xml_doc, "wpn_params:cap_ammo_count", this, false);
m_textAmmoCount2 = UIHelper::CreateTextWnd(xml_doc, "wpn_params:cap_ammo_count2", this, false);
m_textAmmoTypes = UIHelper::CreateTextWnd(xml_doc, "wpn_params:cap_ammo_types", this, false);
m_textAmmoUsedType = UIHelper::CreateTextWnd(xml_doc, "wpn_params:cap_ammo_used_type", this, false);
m_stAmmoType1 = UIHelper::CreateStatic(xml_doc, "wpn_params:static_ammo_type1", this, false);
Expand Down Expand Up @@ -172,23 +163,27 @@ void CUIWpnParams::SetInfo(CInventoryItem* slot_wpn, CInventoryItem& cur_wpn)
ammo_count2 = slot_weapon->GetAmmoMagSize();
}

if (ammo_count == ammo_count2)
m_textAmmoCount2.SetTextColor(color_rgba(170, 170, 170, 255));
else if (ammo_count < ammo_count2)
m_textAmmoCount2.SetTextColor(color_rgba(255, 0, 0, 255));
else
m_textAmmoCount2.SetTextColor(color_rgba(0, 255, 0, 255));
if (m_textAmmoCount2)
{
if (ammo_count == ammo_count2)
m_textAmmoCount2->SetTextColor(color_rgba(170, 170, 170, 255));
else if (ammo_count < ammo_count2)
m_textAmmoCount2->SetTextColor(color_rgba(255, 0, 0, 255));
else
m_textAmmoCount2->SetTextColor(color_rgba(0, 255, 0, 255));

string128 str;
xr_sprintf(str, sizeof(str), "%d", ammo_count);
m_textAmmoCount2.SetText(str);
string128 str;
xr_sprintf(str, sizeof(str), "%d", ammo_count);
m_textAmmoCount2->SetText(str);
}

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

if (m_textAmmoUsedType)
{
string128 str;
xr_sprintf(str, sizeof(str), "%s", pSettings->r_string(ammo_types[0].c_str(), "inv_name_short"));
m_textAmmoUsedType->SetTextST(str);
}
Expand Down
16 changes: 8 additions & 8 deletions src/xrGame/ui/UIWpnParams.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,23 +23,23 @@ class CUIWpnParams : public CUIWindow
CUIDoubleProgressBar m_progressDamage;
CUIDoubleProgressBar m_progressRPM;

CUIStatic m_icon_acc;
CUIStatic m_icon_dam;
CUIStatic m_icon_han;
CUIStatic m_icon_rpm;
CUIStatic* m_icon_acc;

This comment has been minimized.

Copy link
@FreeZoneMods

FreeZoneMods May 22, 2019

Contributor

Maybe there were some reasons to avoid pointers while developing CoP...

This comment has been minimized.

Copy link
@Xottab-DUTY

Xottab-DUTY May 22, 2019

Author Member

I used pointers to avoid object creation at all if corresponding XML tag doesn't exist.
For example:

// The last argument tells that we should not trigger R_ASSERT because tag doesn't exist
// In other words, it's not critical and it's safe to return nullptr
m_stAmmo = UIHelper::CreateStatic(xml_doc, "wpn_params:static_ammo", this, false);

m_stAmmo will be nullptr, if static_ammo tag doesn't exist.

CUIStatic* m_icon_dam;
CUIStatic* m_icon_han;
CUIStatic* m_icon_rpm;

CUIStatic m_stAmmo;
CUIStatic* m_stAmmo;
CUITextWnd m_textAccuracy;
CUITextWnd m_textHandling;
CUITextWnd m_textDamage;
CUITextWnd m_textRPM;
CUITextWnd* m_textAmmoTypes;
CUITextWnd* m_textAmmoUsedType;
CUITextWnd m_textAmmoCount;
CUITextWnd m_textAmmoCount2;
CUITextWnd* m_textAmmoCount;
CUITextWnd* m_textAmmoCount2;
CUIStatic* m_stAmmoType1;
CUIStatic* m_stAmmoType2;
CUIStatic m_Prop_line;
CUIStatic* m_Prop_line;
};

// -------------------------------------------------------------------------------------------------
Expand Down

0 comments on commit 2f03950

Please sign in to comment.