Skip to content

Commit

Permalink
Implement custom mark feature
Browse files Browse the repository at this point in the history
Using:
Add that node in `actor_menu_item(_16).xml`:
```<cell_item_custom_mark x="1" y="1" width="24" height="16" stretch="1">
		<texture>ui_item_count_back</texture>
	</cell_item_custom_mark>```
In item's section:
```item_custom_mark = true
item_custom_mark_offset = -2.0, 0.0
item_custom_mark_size = 10, 10
item_custom_mark_texture = ui_item_count_back
item_custom_mark_clr = 100,250,100```
`item_custom_mark_offset`, `item_custom_mark_size`, `item_custom_mark_texture`, `item_custom_mark_clr` are an optional - will be used texture, size, and color from XML node. By default it has position at right-bottom of cell, remember about it on offset setting up
  • Loading branch information
Hrusteckiy committed Sep 19, 2023
1 parent 25551a5 commit 1ce721e
Show file tree
Hide file tree
Showing 4 changed files with 74 additions and 0 deletions.
19 changes: 19 additions & 0 deletions src/xrGame/inventory_item.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,12 @@ CInventoryItem::CInventoryItem()
m_custom_text_font = nullptr;
m_custom_text_clr_inv = 0;
m_custom_text_offset.set(0.f, 0.f);

m_custom_mark_texture = nullptr;
m_custom_mark = false;
m_custom_mark_offset.set(0.f, 0.f);
m_custom_mark_size.set(0.f, 0.f);
m_custom_mark_clr = 0;
}

CInventoryItem::~CInventoryItem()
Expand Down Expand Up @@ -206,6 +212,19 @@ void CInventoryItem::ReadCustomTextAndMarks(LPCSTR section)
{
m_custom_text_clr_inv = 0;
}
m_custom_mark_texture = READ_IF_EXISTS(pSettings, r_string, section, "item_custom_mark_texture", nullptr);
m_custom_mark = READ_IF_EXISTS(pSettings, r_bool, section, "item_custom_mark", false);
m_custom_mark_offset = READ_IF_EXISTS(pSettings, r_fvector2, section, "item_custom_mark_offset", Fvector2().set(0.f, 0.f));
m_custom_mark_size = READ_IF_EXISTS(pSettings, r_fvector2, section, "item_custom_mark_size", Fvector2().set(0.f, 0.f));

if (pSettings->line_exist(section, "item_custom_mark_clr"))
{
m_custom_mark_clr = pSettings->r_color(section, "item_custom_mark_clr");
}
else
{
m_custom_mark_clr = 0;
}
}

void CInventoryItem::ReloadNames()
Expand Down
6 changes: 6 additions & 0 deletions src/xrGame/inventory_item.h
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,12 @@ class CInventoryItem : public CAttachableItem,
Fvector2 m_custom_text_offset;
CGameFont* m_custom_text_font;
u32 m_custom_text_clr_inv;
bool m_custom_mark;
shared_str m_custom_mark_texture;
Fvector2 m_custom_mark_offset;
Fvector2 m_custom_mark_size;
u32 m_custom_mark_clr;
LPCSTR m_custom_mark_lanim;

SInvItemPlace m_ItemCurrPlace;

Expand Down
46 changes: 46 additions & 0 deletions src/xrGame/ui/UICellItem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ CUICellItem::CUICellItem()
m_upgrade = NULL;
m_pConditionState = NULL;
m_custom_text = NULL;
m_custom_mark = NULL;
m_drawn_frame = 0;
SetAccelerator(0);
m_b_destroy_childs = true;
Expand All @@ -36,6 +37,7 @@ CUICellItem::CUICellItem()
m_cur_mark = false;
m_has_upgrade = false;
m_with_custom_text = false;
m_with_custom_mark = false;

init();
}
Expand Down Expand Up @@ -91,6 +93,16 @@ void CUICellItem::init()
m_custom_text_pos = m_custom_text->GetWndPos();
m_custom_text->Show(false);
}

if (uiXml.NavigateToNode("cell_item_custom_mark", 0))
{
m_custom_mark = xr_new<CUIStatic>("CustomMark");
m_custom_mark->SetAutoDelete(true);
AttachChild(m_custom_mark);
CUIXmlInit::InitStatic(uiXml, "cell_item_custom_mark", 0, m_custom_mark);
m_custom_mark_pos = m_custom_mark->GetWndPos();
m_custom_mark->Show(false);
}
}

void CUICellItem::Draw()
Expand Down Expand Up @@ -153,6 +165,7 @@ void CUICellItem::UpdateCustomMarksAndText()
if (item)
{
m_with_custom_text = item->m_custom_text != nullptr;
m_with_custom_mark = item->m_custom_mark;
if (m_with_custom_text && m_custom_text)
{
Fvector2 pos;
Expand All @@ -176,8 +189,41 @@ void CUICellItem::UpdateCustomMarksAndText()
m_custom_text->TextItemControl()->m_TextOffset = item->m_custom_text_offset;
}
}
if (m_with_custom_mark && m_custom_mark)
{
Fvector2 pos;
pos.set(m_custom_mark_pos);
Fvector2 size = GetWndSize();
Fvector2 up_size = m_custom_mark->GetWndSize();
pos.x = size.x - up_size.x - 4.0f; // making pos at right-end of cell
pos.y = size.y - up_size.y - 4.0f; // making pos at bottom-end of cell
m_custom_mark->SetWndPos(pos);

if (item->m_custom_mark_size.x > 0.f && item->m_custom_mark_size.y > 0.f)
{
m_custom_mark->SetWndSize(item->m_custom_mark_size);
}
else if (item->m_custom_mark_size.x < 0.f || item->m_custom_mark_size.y < 0.f)
{
R_ASSERT("item_custom_mark_size < 0.f || item_custom_mark_size < 0.f");
}

if (item->m_custom_mark_texture != nullptr)
{
m_custom_mark->InitTextureEx(item->m_custom_mark_texture.c_str());
}

if (item->m_custom_mark_clr != 0)
{
m_custom_mark->SetTextureColor(item->m_custom_mark_clr);
}

m_custom_mark->SetTextureOffset(item->m_custom_mark_offset.x, item->m_custom_mark_offset.y);
}
if (m_custom_text)
m_custom_text->Show(m_with_custom_text);
if (m_custom_mark)
m_custom_mark->Show(m_with_custom_mark);
}

bool CUICellItem::OnMouseAction(float x, float y, EUIMessages mouse_action)
Expand Down
3 changes: 3 additions & 0 deletions src/xrGame/ui/UICellItem.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ class CUICellItem : public CUIStatic
Fvector2 m_upgrade_pos;
CUIStatic* m_custom_text;
Fvector2 m_custom_text_pos;
CUIStatic* m_custom_mark;
Fvector2 m_custom_mark_pos;

virtual void UpdateItemText();
void UpdateCustomMarksAndText();
Expand Down Expand Up @@ -92,6 +94,7 @@ class CUICellItem : public CUIStatic
bool m_cur_mark;
bool m_has_upgrade;
bool m_with_custom_text;
bool m_with_custom_mark;
};

class CUIDragItem final : public CUIWindow, public pureRender, public pureFrame
Expand Down

0 comments on commit 1ce721e

Please sign in to comment.