Skip to content

Commit 659fa94

Browse files
committed
Implement custom mark feature
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
1 parent 25551a5 commit 659fa94

File tree

4 files changed

+74
-0
lines changed

4 files changed

+74
-0
lines changed

src/xrGame/inventory_item.cpp

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,12 @@ CInventoryItem::CInventoryItem()
7373
m_custom_text_font = nullptr;
7474
m_custom_text_clr_inv = 0;
7575
m_custom_text_offset.set(0.f, 0.f);
76+
77+
m_custom_mark_texture = nullptr;
78+
m_custom_mark = false;
79+
m_custom_mark_offset.set(0.f, 0.f);
80+
m_custom_mark_size.set(0.f, 0.f);
81+
m_custom_mark_clr = 0;
7682
}
7783

7884
CInventoryItem::~CInventoryItem()
@@ -206,6 +212,19 @@ void CInventoryItem::ReadCustomTextAndMarks(LPCSTR section)
206212
{
207213
m_custom_text_clr_inv = 0;
208214
}
215+
m_custom_mark_texture = READ_IF_EXISTS(pSettings, r_string, section, "item_custom_mark_texture", nullptr);
216+
m_custom_mark = READ_IF_EXISTS(pSettings, r_bool, section, "item_custom_mark", false);
217+
m_custom_mark_offset = READ_IF_EXISTS(pSettings, r_fvector2, section, "item_custom_mark_offset", Fvector2().set(0.f, 0.f));
218+
m_custom_mark_size = READ_IF_EXISTS(pSettings, r_fvector2, section, "item_custom_mark_size", Fvector2().set(0.f, 0.f));
219+
220+
if (pSettings->line_exist(section, "item_custom_mark_clr"))
221+
{
222+
m_custom_mark_clr = pSettings->r_color(section, "item_custom_mark_clr");
223+
}
224+
else
225+
{
226+
m_custom_mark_clr = 0;
227+
}
209228
}
210229

211230
void CInventoryItem::ReloadNames()

src/xrGame/inventory_item.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,12 @@ class CInventoryItem : public CAttachableItem,
160160
Fvector2 m_custom_text_offset;
161161
CGameFont* m_custom_text_font;
162162
u32 m_custom_text_clr_inv;
163+
bool m_custom_mark;
164+
shared_str m_custom_mark_texture;
165+
Fvector2 m_custom_mark_offset;
166+
Fvector2 m_custom_mark_size;
167+
u32 m_custom_mark_clr;
168+
LPCSTR m_custom_mark_lanim;
163169

164170
SInvItemPlace m_ItemCurrPlace;
165171

src/xrGame/ui/UICellItem.cpp

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ CUICellItem::CUICellItem()
2828
m_upgrade = NULL;
2929
m_pConditionState = NULL;
3030
m_custom_text = NULL;
31+
m_custom_mark = NULL;
3132
m_drawn_frame = 0;
3233
SetAccelerator(0);
3334
m_b_destroy_childs = true;
@@ -36,6 +37,7 @@ CUICellItem::CUICellItem()
3637
m_cur_mark = false;
3738
m_has_upgrade = false;
3839
m_with_custom_text = false;
40+
m_with_custom_mark = false;
3941

4042
init();
4143
}
@@ -91,6 +93,16 @@ void CUICellItem::init()
9193
m_custom_text_pos = m_custom_text->GetWndPos();
9294
m_custom_text->Show(false);
9395
}
96+
97+
if (uiXml.NavigateToNode("cell_item_custom_mark", 0))
98+
{
99+
m_custom_mark = xr_new<CUIStatic>("CustomMark");
100+
m_custom_mark->SetAutoDelete(true);
101+
AttachChild(m_custom_mark);
102+
CUIXmlInit::InitStatic(uiXml, "cell_item_custom_mark", 0, m_custom_mark);
103+
m_custom_mark_pos = m_custom_mark->GetWndPos();
104+
m_custom_mark->Show(false);
105+
}
94106
}
95107

96108
void CUICellItem::Draw()
@@ -153,6 +165,7 @@ void CUICellItem::UpdateCustomMarksAndText()
153165
if (item)
154166
{
155167
m_with_custom_text = item->m_custom_text != nullptr;
168+
m_with_custom_mark = item->m_custom_mark;
156169
if (m_with_custom_text && m_custom_text)
157170
{
158171
Fvector2 pos;
@@ -176,8 +189,41 @@ void CUICellItem::UpdateCustomMarksAndText()
176189
m_custom_text->TextItemControl()->m_TextOffset = item->m_custom_text_offset;
177190
}
178191
}
192+
if (m_with_custom_mark && m_custom_mark)
193+
{
194+
Fvector2 pos;
195+
pos.set(m_custom_mark_pos);
196+
Fvector2 size = GetWndSize();
197+
Fvector2 up_size = m_custom_mark->GetWndSize();
198+
pos.x = size.x - up_size.x - 4.0f; // making pos at right-end of cell
199+
pos.y = size.y - up_size.y - 4.0f; // making pos at bottom-end of cell
200+
m_custom_mark->SetWndPos(pos);
201+
202+
if (item->m_custom_mark_size.x > 0.f && item->m_custom_mark_size.y > 0.f)
203+
{
204+
m_custom_mark->SetWndSize(item->m_custom_mark_size);
205+
}
206+
else if (item->m_custom_mark_size.x < 0.f || item->m_custom_mark_size.y < 0.f)
207+
{
208+
R_ASSERT("item_custom_mark_size < 0.f || item_custom_mark_size < 0.f");
209+
}
210+
211+
if (item->m_custom_mark_texture != nullptr)
212+
{
213+
m_custom_mark->InitTextureEx(item->m_custom_mark_texture.c_str());
214+
}
215+
216+
if (item->m_custom_text_clr_inv != 0)
217+
{
218+
m_custom_mark->SetTextureColor(item->m_custom_mark_clr);
219+
}
220+
221+
m_custom_mark->SetTextureOffset(item->m_custom_mark_offset.x, item->m_custom_mark_offset.y);
222+
}
179223
if (m_custom_text)
180224
m_custom_text->Show(m_with_custom_text);
225+
if (m_custom_mark)
226+
m_custom_mark->Show(m_with_custom_mark);
181227
}
182228

183229
bool CUICellItem::OnMouseAction(float x, float y, EUIMessages mouse_action)

src/xrGame/ui/UICellItem.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,8 @@ class CUICellItem : public CUIStatic
4444
Fvector2 m_upgrade_pos;
4545
CUIStatic* m_custom_text;
4646
Fvector2 m_custom_text_pos;
47+
CUIStatic* m_custom_mark;
48+
Fvector2 m_custom_mark_pos;
4749

4850
virtual void UpdateItemText();
4951
void UpdateCustomMarksAndText();
@@ -92,6 +94,7 @@ class CUICellItem : public CUIStatic
9294
bool m_cur_mark;
9395
bool m_has_upgrade;
9496
bool m_with_custom_text;
97+
bool m_with_custom_mark;
9598
};
9699

97100
class CUIDragItem final : public CUIWindow, public pureRender, public pureFrame

0 commit comments

Comments
 (0)