Skip to content

Commit 25551a5

Browse files
committed
Implement custom text feature
Using: Add that node in `actor_menu_item(_16).xml`: ```<cell_item_custom_text x="1" y="1" width="24" height="16" stretch="1"> <text x="2" y="6" width="24" height="16" font="arial_14" color="ui_2" align="r" vert_align="c"/> </cell_item_custom_text>``` In item's section: ```item_custom_text = st_text item_custom_text_clr_inv = 100,250,100 item_custom_text_font = graffiti22 item_custom_text_offset = -2.0, -2.0``` `item_custom_text_clr_inv`, `item_custom_text_font`, `item_custom_text_offset`, are an optional, if not written - will be used font, color, offset from XML node. `item_custom_text` is a text from StringTable. `item_custom_text_offset` is an offset by right-bottom of cell
1 parent 05cb6be commit 25551a5

File tree

9 files changed

+154
-17
lines changed

9 files changed

+154
-17
lines changed

src/xrGame/inventory_item.cpp

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@
1414
#include "PhysicsShellHolder.h"
1515
#include "entity_alive.h"
1616
#include "Level.h"
17+
#include "../xrUICore/ui_base.h"
18+
#include "../xrUICore/UIFontDefines.h"
1719
#include "game_cl_base.h"
1820
#include "Actor.h"
1921
#include "Include/xrRender/Kinematics.h"
@@ -66,6 +68,11 @@ CInventoryItem::CInventoryItem()
6668
m_Description = "";
6769
m_section_id = 0;
6870
m_flags.set(FIsHelperItem, FALSE);
71+
72+
m_custom_text = nullptr;
73+
m_custom_text_font = nullptr;
74+
m_custom_text_clr_inv = 0;
75+
m_custom_text_offset.set(0.f, 0.f);
6976
}
7077

7178
CInventoryItem::~CInventoryItem()
@@ -129,6 +136,76 @@ void CInventoryItem::Load(LPCSTR section)
129136
m_fControlInertionFactor = g_normalize_mouse_sens ? 1.0f : pSettings->read_if_exists<float>(section, "control_inertion_factor", 1.0f);
130137
}
131138
m_icon_name = READ_IF_EXISTS(pSettings, r_string, section, "icon_name", NULL);
139+
140+
ReadCustomTextAndMarks(section);
141+
}
142+
143+
void CInventoryItem::ReadCustomTextAndMarks(LPCSTR section)
144+
{
145+
m_custom_text = READ_IF_EXISTS(pSettings, r_string, section, "item_custom_text", nullptr);
146+
m_custom_text_offset =
147+
READ_IF_EXISTS(pSettings, r_fvector2, section, "item_custom_text_offset", Fvector2().set(0.f, 0.f));
148+
149+
if (pSettings->line_exist(section, "item_custom_text_font"))
150+
{
151+
shared_str font_str = pSettings->r_string(section, "item_custom_text_font");
152+
if (!xr_strcmp(font_str, GRAFFITI19_FONT_NAME))
153+
{
154+
m_custom_text_font = UI().Font().pFontGraffiti19Russian;
155+
}
156+
else if (!xr_strcmp(font_str, GRAFFITI22_FONT_NAME))
157+
{
158+
m_custom_text_font = UI().Font().pFontGraffiti22Russian;
159+
}
160+
else if (!xr_strcmp(font_str, GRAFFITI32_FONT_NAME))
161+
{
162+
m_custom_text_font = UI().Font().pFontGraffiti32Russian;
163+
}
164+
else if (!xr_strcmp(font_str, GRAFFITI50_FONT_NAME))
165+
{
166+
m_custom_text_font = UI().Font().pFontGraffiti50Russian;
167+
}
168+
else if (!xr_strcmp(font_str, ARIAL14_FONT_NAME))
169+
{
170+
m_custom_text_font = UI().Font().pFontArial14;
171+
}
172+
else if (!xr_strcmp(font_str, MEDIUM_FONT_NAME))
173+
{
174+
m_custom_text_font = UI().Font().pFontMedium;
175+
}
176+
else if (!xr_strcmp(font_str, SMALL_FONT_NAME))
177+
{
178+
m_custom_text_font = UI().Font().pFontStat;
179+
}
180+
else if (!xr_strcmp(font_str, LETTERICA16_FONT_NAME))
181+
{
182+
m_custom_text_font = UI().Font().pFontLetterica16Russian;
183+
}
184+
else if (!xr_strcmp(font_str, LETTERICA18_FONT_NAME))
185+
{
186+
m_custom_text_font = UI().Font().pFontLetterica18Russian;
187+
}
188+
else if (!xr_strcmp(font_str, LETTERICA25_FONT_NAME))
189+
{
190+
m_custom_text_font = UI().Font().pFontLetterica25;
191+
}
192+
else if (!xr_strcmp(font_str, DI_FONT_NAME))
193+
{
194+
m_custom_text_font = UI().Font().pFontDI;
195+
}
196+
else
197+
{
198+
m_custom_text_font = nullptr;
199+
}
200+
}
201+
if (pSettings->line_exist(section, "item_custom_text_clr_inv"))
202+
{
203+
m_custom_text_clr_inv = pSettings->r_color(section, "item_custom_text_clr_inv");
204+
}
205+
else
206+
{
207+
m_custom_text_clr_inv = 0;
208+
}
132209
}
133210

134211
void CInventoryItem::ReloadNames()

src/xrGame/inventory_item.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,7 @@ class CInventoryItem : public CAttachableItem,
9595

9696
public:
9797
virtual void Load(LPCSTR section);
98+
void ReadCustomTextAndMarks(LPCSTR section);
9899
void ReloadNames();
99100

100101
LPCSTR NameItem(); // remove <virtual> by sea
@@ -155,6 +156,11 @@ class CInventoryItem : public CAttachableItem,
155156
shared_str m_nameShort;
156157
shared_str m_nameComplex;
157158

159+
shared_str m_custom_text;
160+
Fvector2 m_custom_text_offset;
161+
CGameFont* m_custom_text_font;
162+
u32 m_custom_text_clr_inv;
163+
158164
SInvItemPlace m_ItemCurrPlace;
159165

160166
virtual void OnMoveToSlot(const SInvItemPlace& prev){};

src/xrGame/ui/UICellItem.cpp

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,13 +27,15 @@ CUICellItem::CUICellItem()
2727
//- m_mark = NULL;
2828
m_upgrade = NULL;
2929
m_pConditionState = NULL;
30+
m_custom_text = NULL;
3031
m_drawn_frame = 0;
3132
SetAccelerator(0);
3233
m_b_destroy_childs = true;
3334
m_selected = false;
3435
m_select_armament = false;
3536
m_cur_mark = false;
3637
m_has_upgrade = false;
38+
m_with_custom_text = false;
3739

3840
init();
3941
}
@@ -79,6 +81,16 @@ void CUICellItem::init()
7981

8082
if (m_pConditionState)
8183
m_pConditionState->Show(true);
84+
85+
if (uiXml.NavigateToNode("cell_item_custom_text", 0))
86+
{
87+
m_custom_text = xr_new<CUIStatic>("CustomText");
88+
m_custom_text->SetAutoDelete(true);
89+
AttachChild(m_custom_text);
90+
CUIXmlInit::InitStatic(uiXml, "cell_item_custom_text", 0, m_custom_text);
91+
m_custom_text_pos = m_custom_text->GetWndPos();
92+
m_custom_text->Show(false);
93+
}
8294
}
8395

8496
void CUICellItem::Draw()
@@ -132,6 +144,40 @@ void CUICellItem::Update()
132144
}
133145
m_upgrade->Show(m_has_upgrade);
134146
}
147+
UpdateCustomMarksAndText();
148+
}
149+
150+
void CUICellItem::UpdateCustomMarksAndText()
151+
{
152+
PIItem item = (PIItem)m_pData;
153+
if (item)
154+
{
155+
m_with_custom_text = item->m_custom_text != nullptr;
156+
if (m_with_custom_text && m_custom_text)
157+
{
158+
Fvector2 pos;
159+
pos.set(m_custom_text_pos);
160+
Fvector2 size = GetWndSize();
161+
Fvector2 up_size = m_custom_text->GetWndSize();
162+
pos.x = size.x - up_size.x - 4.0f; // making pos at right-end of cell
163+
pos.y = size.y - up_size.y - 4.0f; // making pos at bottom-end of cell
164+
m_custom_text->SetWndPos(pos);
165+
m_custom_text->TextItemControl()->SetTextST(*item->m_custom_text);
166+
167+
if (item->m_custom_text_clr_inv != 0)
168+
{
169+
m_custom_text->TextItemControl()->SetTextColor(item->m_custom_text_clr_inv);
170+
}
171+
if (item->m_custom_text_font != nullptr)
172+
{
173+
m_custom_text->TextItemControl()->SetFont(item->m_custom_text_font);
174+
}
175+
176+
m_custom_text->TextItemControl()->m_TextOffset = item->m_custom_text_offset;
177+
}
178+
}
179+
if (m_custom_text)
180+
m_custom_text->Show(m_with_custom_text);
135181
}
136182

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

src/xrGame/ui/UICellItem.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,11 @@ class CUICellItem : public CUIStatic
4242
CUIStatic* m_text;
4343
CUIStatic* m_upgrade;
4444
Fvector2 m_upgrade_pos;
45+
CUIStatic* m_custom_text;
46+
Fvector2 m_custom_text_pos;
4547

4648
virtual void UpdateItemText();
49+
void UpdateCustomMarksAndText();
4750
void init();
4851

4952
public:
@@ -88,6 +91,7 @@ class CUICellItem : public CUIStatic
8891
bool m_select_armament;
8992
bool m_cur_mark;
9093
bool m_has_upgrade;
94+
bool m_with_custom_text;
9195
};
9296

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

src/xrUICore/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ set(SRC_FILES
99
"ui_debug.h"
1010
"ui_defs.h"
1111
"ui_styles.cpp"
12+
"UIFontDefines.h"
1213
"ui_styles.h"
1314
"uiabstract.h"
1415
"UIMessages.h"

src/xrUICore/UIFontDefines.h

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
2+
#define ARIAL14_FONT_NAME "arial_14"
3+
4+
#define MEDIUM_FONT_NAME "medium"
5+
#define SMALL_FONT_NAME "small"
6+
7+
#define GRAFFITI19_FONT_NAME "graffiti19"
8+
#define GRAFFITI22_FONT_NAME "graffiti22"
9+
#define GRAFFITI32_FONT_NAME "graffiti32"
10+
#define GRAFFITI50_FONT_NAME "graffiti50"
11+
12+
#define LETTERICA16_FONT_NAME "letterica16"
13+
#define LETTERICA18_FONT_NAME "letterica18"
14+
#define LETTERICA25_FONT_NAME "letterica25"
15+
16+
#define DI_FONT_NAME "di"

src/xrUICore/XML/UIXmlInitBase.cpp

Lines changed: 2 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
#include "pch.hpp"
22
#include "UIXmlInitBase.h"
3+
#include "../UIFontDefines.h"
34
#include "Windows/UIFrameWindow.h"
45
#include "Windows/UITextFrameLineWnd.h"
56
#include "Buttons/UICheckButton.h"
@@ -17,22 +18,6 @@
1718
#include "UITextureMaster.h"
1819
#include "Lines/UILines.h"
1920

20-
#define ARIAL_FONT_NAME "arial"
21-
22-
#define MEDIUM_FONT_NAME "medium"
23-
#define SMALL_FONT_NAME "small"
24-
25-
#define GRAFFITI19_FONT_NAME "graffiti19"
26-
#define GRAFFITI22_FONT_NAME "graffiti22"
27-
#define GRAFFITI32_FONT_NAME "graffiti32"
28-
#define GRAFFITI50_FONT_NAME "graffiti50"
29-
30-
#define LETTERICA16_FONT_NAME "letterica16"
31-
#define LETTERICA18_FONT_NAME "letterica18"
32-
#define LETTERICA25_FONT_NAME "letterica25"
33-
34-
#define DI_FONT_NAME "di"
35-
3621
//////////////////////////////////////////////////////////////////////////
3722

3823
constexpr pcstr COLOR_DEFINITIONS = "color_defs.xml";
@@ -701,7 +686,7 @@ bool CUIXmlInitBase::InitFont(CUIXml& xml_doc, LPCSTR path, int index, u32& colo
701686
{
702687
pFnt = UI().Font().pFontGraffiti50Russian;
703688
}
704-
else if (!xr_strcmp(font_name, "arial_14"))
689+
else if (!xr_strcmp(font_name, ARIAL14_FONT_NAME))
705690
{
706691
pFnt = UI().Font().pFontArial14;
707692
}

src/xrUICore/xrUICore.vcxproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,7 @@
109109
<ClInclude Include="ui_debug.h" />
110110
<ClInclude Include="ui_styles.h" />
111111
<ClInclude Include="ui_base.h" />
112+
<ClInclude Include="UIFontDefines.h" />
112113
<ClInclude Include="ui_defs.h" />
113114
<ClInclude Include="Windows\UIFrameLineWnd.h" />
114115
<ClInclude Include="Windows\UIFrameWindow.h" />

src/xrUICore/xrUICore.vcxproj.filters

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -330,6 +330,7 @@
330330
<ClInclude Include="uiabstract.h" />
331331
<ClInclude Include="UIMessages.h" />
332332
<ClInclude Include="ui_base.h" />
333+
<ClInclude Include="UIFontDefines.h" />
333334
<ClInclude Include="Options\UIOptionsItem.h">
334335
<Filter>Options</Filter>
335336
</ClInclude>

0 commit comments

Comments
 (0)