From 25551a561fe19188fe2a2fb151ac0d49165e05e8 Mon Sep 17 00:00:00 2001 From: Hrusteckiy Date: Tue, 12 Sep 2023 00:47:05 +0300 Subject: [PATCH 1/2] Implement custom text feature Using: Add that node in `actor_menu_item(_16).xml`: ``` ``` 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 --- src/xrGame/inventory_item.cpp | 77 +++++++++++++++++++++++++++ src/xrGame/inventory_item.h | 6 +++ src/xrGame/ui/UICellItem.cpp | 46 ++++++++++++++++ src/xrGame/ui/UICellItem.h | 4 ++ src/xrUICore/CMakeLists.txt | 1 + src/xrUICore/UIFontDefines.h | 16 ++++++ src/xrUICore/XML/UIXmlInitBase.cpp | 19 +------ src/xrUICore/xrUICore.vcxproj | 1 + src/xrUICore/xrUICore.vcxproj.filters | 1 + 9 files changed, 154 insertions(+), 17 deletions(-) create mode 100644 src/xrUICore/UIFontDefines.h diff --git a/src/xrGame/inventory_item.cpp b/src/xrGame/inventory_item.cpp index e8f836c601e..5ef424b92f5 100644 --- a/src/xrGame/inventory_item.cpp +++ b/src/xrGame/inventory_item.cpp @@ -14,6 +14,8 @@ #include "PhysicsShellHolder.h" #include "entity_alive.h" #include "Level.h" +#include "../xrUICore/ui_base.h" +#include "../xrUICore/UIFontDefines.h" #include "game_cl_base.h" #include "Actor.h" #include "Include/xrRender/Kinematics.h" @@ -66,6 +68,11 @@ CInventoryItem::CInventoryItem() m_Description = ""; m_section_id = 0; m_flags.set(FIsHelperItem, FALSE); + + m_custom_text = nullptr; + m_custom_text_font = nullptr; + m_custom_text_clr_inv = 0; + m_custom_text_offset.set(0.f, 0.f); } CInventoryItem::~CInventoryItem() @@ -129,6 +136,76 @@ void CInventoryItem::Load(LPCSTR section) m_fControlInertionFactor = g_normalize_mouse_sens ? 1.0f : pSettings->read_if_exists(section, "control_inertion_factor", 1.0f); } m_icon_name = READ_IF_EXISTS(pSettings, r_string, section, "icon_name", NULL); + + ReadCustomTextAndMarks(section); +} + +void CInventoryItem::ReadCustomTextAndMarks(LPCSTR section) +{ + m_custom_text = READ_IF_EXISTS(pSettings, r_string, section, "item_custom_text", nullptr); + m_custom_text_offset = + READ_IF_EXISTS(pSettings, r_fvector2, section, "item_custom_text_offset", Fvector2().set(0.f, 0.f)); + + if (pSettings->line_exist(section, "item_custom_text_font")) + { + shared_str font_str = pSettings->r_string(section, "item_custom_text_font"); + if (!xr_strcmp(font_str, GRAFFITI19_FONT_NAME)) + { + m_custom_text_font = UI().Font().pFontGraffiti19Russian; + } + else if (!xr_strcmp(font_str, GRAFFITI22_FONT_NAME)) + { + m_custom_text_font = UI().Font().pFontGraffiti22Russian; + } + else if (!xr_strcmp(font_str, GRAFFITI32_FONT_NAME)) + { + m_custom_text_font = UI().Font().pFontGraffiti32Russian; + } + else if (!xr_strcmp(font_str, GRAFFITI50_FONT_NAME)) + { + m_custom_text_font = UI().Font().pFontGraffiti50Russian; + } + else if (!xr_strcmp(font_str, ARIAL14_FONT_NAME)) + { + m_custom_text_font = UI().Font().pFontArial14; + } + else if (!xr_strcmp(font_str, MEDIUM_FONT_NAME)) + { + m_custom_text_font = UI().Font().pFontMedium; + } + else if (!xr_strcmp(font_str, SMALL_FONT_NAME)) + { + m_custom_text_font = UI().Font().pFontStat; + } + else if (!xr_strcmp(font_str, LETTERICA16_FONT_NAME)) + { + m_custom_text_font = UI().Font().pFontLetterica16Russian; + } + else if (!xr_strcmp(font_str, LETTERICA18_FONT_NAME)) + { + m_custom_text_font = UI().Font().pFontLetterica18Russian; + } + else if (!xr_strcmp(font_str, LETTERICA25_FONT_NAME)) + { + m_custom_text_font = UI().Font().pFontLetterica25; + } + else if (!xr_strcmp(font_str, DI_FONT_NAME)) + { + m_custom_text_font = UI().Font().pFontDI; + } + else + { + m_custom_text_font = nullptr; + } + } + if (pSettings->line_exist(section, "item_custom_text_clr_inv")) + { + m_custom_text_clr_inv = pSettings->r_color(section, "item_custom_text_clr_inv"); + } + else + { + m_custom_text_clr_inv = 0; + } } void CInventoryItem::ReloadNames() diff --git a/src/xrGame/inventory_item.h b/src/xrGame/inventory_item.h index 0501cc7d0e1..244c4ebae79 100644 --- a/src/xrGame/inventory_item.h +++ b/src/xrGame/inventory_item.h @@ -95,6 +95,7 @@ class CInventoryItem : public CAttachableItem, public: virtual void Load(LPCSTR section); + void ReadCustomTextAndMarks(LPCSTR section); void ReloadNames(); LPCSTR NameItem(); // remove by sea @@ -155,6 +156,11 @@ class CInventoryItem : public CAttachableItem, shared_str m_nameShort; shared_str m_nameComplex; + shared_str m_custom_text; + Fvector2 m_custom_text_offset; + CGameFont* m_custom_text_font; + u32 m_custom_text_clr_inv; + SInvItemPlace m_ItemCurrPlace; virtual void OnMoveToSlot(const SInvItemPlace& prev){}; diff --git a/src/xrGame/ui/UICellItem.cpp b/src/xrGame/ui/UICellItem.cpp index 1e2997c3bf3..d825ff64927 100644 --- a/src/xrGame/ui/UICellItem.cpp +++ b/src/xrGame/ui/UICellItem.cpp @@ -27,6 +27,7 @@ CUICellItem::CUICellItem() //- m_mark = NULL; m_upgrade = NULL; m_pConditionState = NULL; + m_custom_text = NULL; m_drawn_frame = 0; SetAccelerator(0); m_b_destroy_childs = true; @@ -34,6 +35,7 @@ CUICellItem::CUICellItem() m_select_armament = false; m_cur_mark = false; m_has_upgrade = false; + m_with_custom_text = false; init(); } @@ -79,6 +81,16 @@ void CUICellItem::init() if (m_pConditionState) m_pConditionState->Show(true); + + if (uiXml.NavigateToNode("cell_item_custom_text", 0)) + { + m_custom_text = xr_new("CustomText"); + m_custom_text->SetAutoDelete(true); + AttachChild(m_custom_text); + CUIXmlInit::InitStatic(uiXml, "cell_item_custom_text", 0, m_custom_text); + m_custom_text_pos = m_custom_text->GetWndPos(); + m_custom_text->Show(false); + } } void CUICellItem::Draw() @@ -132,6 +144,40 @@ void CUICellItem::Update() } m_upgrade->Show(m_has_upgrade); } + UpdateCustomMarksAndText(); +} + +void CUICellItem::UpdateCustomMarksAndText() +{ + PIItem item = (PIItem)m_pData; + if (item) + { + m_with_custom_text = item->m_custom_text != nullptr; + if (m_with_custom_text && m_custom_text) + { + Fvector2 pos; + pos.set(m_custom_text_pos); + Fvector2 size = GetWndSize(); + Fvector2 up_size = m_custom_text->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_text->SetWndPos(pos); + m_custom_text->TextItemControl()->SetTextST(*item->m_custom_text); + + if (item->m_custom_text_clr_inv != 0) + { + m_custom_text->TextItemControl()->SetTextColor(item->m_custom_text_clr_inv); + } + if (item->m_custom_text_font != nullptr) + { + m_custom_text->TextItemControl()->SetFont(item->m_custom_text_font); + } + + m_custom_text->TextItemControl()->m_TextOffset = item->m_custom_text_offset; + } + } + if (m_custom_text) + m_custom_text->Show(m_with_custom_text); } bool CUICellItem::OnMouseAction(float x, float y, EUIMessages mouse_action) diff --git a/src/xrGame/ui/UICellItem.h b/src/xrGame/ui/UICellItem.h index f07254b0092..a90f9d3d4da 100644 --- a/src/xrGame/ui/UICellItem.h +++ b/src/xrGame/ui/UICellItem.h @@ -42,8 +42,11 @@ class CUICellItem : public CUIStatic CUIStatic* m_text; CUIStatic* m_upgrade; Fvector2 m_upgrade_pos; + CUIStatic* m_custom_text; + Fvector2 m_custom_text_pos; virtual void UpdateItemText(); + void UpdateCustomMarksAndText(); void init(); public: @@ -88,6 +91,7 @@ class CUICellItem : public CUIStatic bool m_select_armament; bool m_cur_mark; bool m_has_upgrade; + bool m_with_custom_text; }; class CUIDragItem final : public CUIWindow, public pureRender, public pureFrame diff --git a/src/xrUICore/CMakeLists.txt b/src/xrUICore/CMakeLists.txt index 2150e028e16..dfb81531c09 100644 --- a/src/xrUICore/CMakeLists.txt +++ b/src/xrUICore/CMakeLists.txt @@ -9,6 +9,7 @@ set(SRC_FILES "ui_debug.h" "ui_defs.h" "ui_styles.cpp" + "UIFontDefines.h" "ui_styles.h" "uiabstract.h" "UIMessages.h" diff --git a/src/xrUICore/UIFontDefines.h b/src/xrUICore/UIFontDefines.h new file mode 100644 index 00000000000..d06393b16cd --- /dev/null +++ b/src/xrUICore/UIFontDefines.h @@ -0,0 +1,16 @@ + +#define ARIAL14_FONT_NAME "arial_14" + +#define MEDIUM_FONT_NAME "medium" +#define SMALL_FONT_NAME "small" + +#define GRAFFITI19_FONT_NAME "graffiti19" +#define GRAFFITI22_FONT_NAME "graffiti22" +#define GRAFFITI32_FONT_NAME "graffiti32" +#define GRAFFITI50_FONT_NAME "graffiti50" + +#define LETTERICA16_FONT_NAME "letterica16" +#define LETTERICA18_FONT_NAME "letterica18" +#define LETTERICA25_FONT_NAME "letterica25" + +#define DI_FONT_NAME "di" diff --git a/src/xrUICore/XML/UIXmlInitBase.cpp b/src/xrUICore/XML/UIXmlInitBase.cpp index 58e587115cd..32994a3a103 100644 --- a/src/xrUICore/XML/UIXmlInitBase.cpp +++ b/src/xrUICore/XML/UIXmlInitBase.cpp @@ -1,5 +1,6 @@ #include "pch.hpp" #include "UIXmlInitBase.h" +#include "../UIFontDefines.h" #include "Windows/UIFrameWindow.h" #include "Windows/UITextFrameLineWnd.h" #include "Buttons/UICheckButton.h" @@ -17,22 +18,6 @@ #include "UITextureMaster.h" #include "Lines/UILines.h" -#define ARIAL_FONT_NAME "arial" - -#define MEDIUM_FONT_NAME "medium" -#define SMALL_FONT_NAME "small" - -#define GRAFFITI19_FONT_NAME "graffiti19" -#define GRAFFITI22_FONT_NAME "graffiti22" -#define GRAFFITI32_FONT_NAME "graffiti32" -#define GRAFFITI50_FONT_NAME "graffiti50" - -#define LETTERICA16_FONT_NAME "letterica16" -#define LETTERICA18_FONT_NAME "letterica18" -#define LETTERICA25_FONT_NAME "letterica25" - -#define DI_FONT_NAME "di" - ////////////////////////////////////////////////////////////////////////// constexpr pcstr COLOR_DEFINITIONS = "color_defs.xml"; @@ -701,7 +686,7 @@ bool CUIXmlInitBase::InitFont(CUIXml& xml_doc, LPCSTR path, int index, u32& colo { pFnt = UI().Font().pFontGraffiti50Russian; } - else if (!xr_strcmp(font_name, "arial_14")) + else if (!xr_strcmp(font_name, ARIAL14_FONT_NAME)) { pFnt = UI().Font().pFontArial14; } diff --git a/src/xrUICore/xrUICore.vcxproj b/src/xrUICore/xrUICore.vcxproj index d7008ee69a9..5abffa32666 100644 --- a/src/xrUICore/xrUICore.vcxproj +++ b/src/xrUICore/xrUICore.vcxproj @@ -109,6 +109,7 @@ + diff --git a/src/xrUICore/xrUICore.vcxproj.filters b/src/xrUICore/xrUICore.vcxproj.filters index 9cfc696907c..30878d4252e 100644 --- a/src/xrUICore/xrUICore.vcxproj.filters +++ b/src/xrUICore/xrUICore.vcxproj.filters @@ -330,6 +330,7 @@ + Options From 1ce721ed63b20342477dde637141b1bc24e64250 Mon Sep 17 00:00:00 2001 From: Hrusteckiy Date: Tue, 12 Sep 2023 01:08:06 +0300 Subject: [PATCH 2/2] Implement custom mark feature Using: Add that node in `actor_menu_item(_16).xml`: ``` ui_item_count_back ``` 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 --- src/xrGame/inventory_item.cpp | 19 +++++++++++++++ src/xrGame/inventory_item.h | 6 +++++ src/xrGame/ui/UICellItem.cpp | 46 +++++++++++++++++++++++++++++++++++ src/xrGame/ui/UICellItem.h | 3 +++ 4 files changed, 74 insertions(+) diff --git a/src/xrGame/inventory_item.cpp b/src/xrGame/inventory_item.cpp index 5ef424b92f5..101c814dc90 100644 --- a/src/xrGame/inventory_item.cpp +++ b/src/xrGame/inventory_item.cpp @@ -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() @@ -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() diff --git a/src/xrGame/inventory_item.h b/src/xrGame/inventory_item.h index 244c4ebae79..81c5b5aba40 100644 --- a/src/xrGame/inventory_item.h +++ b/src/xrGame/inventory_item.h @@ -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; diff --git a/src/xrGame/ui/UICellItem.cpp b/src/xrGame/ui/UICellItem.cpp index d825ff64927..2a557aa42f0 100644 --- a/src/xrGame/ui/UICellItem.cpp +++ b/src/xrGame/ui/UICellItem.cpp @@ -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; @@ -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(); } @@ -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("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() @@ -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; @@ -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) diff --git a/src/xrGame/ui/UICellItem.h b/src/xrGame/ui/UICellItem.h index a90f9d3d4da..fcd0359a2ce 100644 --- a/src/xrGame/ui/UICellItem.h +++ b/src/xrGame/ui/UICellItem.h @@ -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(); @@ -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