diff --git a/src/xrGame/inventory_item.cpp b/src/xrGame/inventory_item.cpp index e8f836c601e..101c814dc90 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,17 @@ 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); + + 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() @@ -129,6 +142,89 @@ 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; + } + 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 0501cc7d0e1..81c5b5aba40 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,17 @@ 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; + 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; virtual void OnMoveToSlot(const SInvItemPlace& prev){}; diff --git a/src/xrGame/ui/UICellItem.cpp b/src/xrGame/ui/UICellItem.cpp index 1e2997c3bf3..2a557aa42f0 100644 --- a/src/xrGame/ui/UICellItem.cpp +++ b/src/xrGame/ui/UICellItem.cpp @@ -27,6 +27,8 @@ CUICellItem::CUICellItem() //- m_mark = NULL; 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; @@ -34,6 +36,8 @@ CUICellItem::CUICellItem() m_select_armament = false; m_cur_mark = false; m_has_upgrade = false; + m_with_custom_text = false; + m_with_custom_mark = false; init(); } @@ -79,6 +83,26 @@ 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); + } + + 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() @@ -132,6 +156,74 @@ 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; + m_with_custom_mark = item->m_custom_mark; + 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_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 f07254b0092..fcd0359a2ce 100644 --- a/src/xrGame/ui/UICellItem.h +++ b/src/xrGame/ui/UICellItem.h @@ -42,8 +42,13 @@ class CUICellItem : public CUIStatic CUIStatic* m_text; CUIStatic* m_upgrade; 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(); void init(); public: @@ -88,6 +93,8 @@ class CUICellItem : public CUIStatic bool m_select_armament; 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 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 aac67d443c4..46ae67b6f57 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