Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implemented custom marks and custom text features #1447

Open
wants to merge 3 commits into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
96 changes: 96 additions & 0 deletions src/xrGame/inventory_item.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -129,6 +142,89 @@ void CInventoryItem::Load(LPCSTR section)
m_fControlInertionFactor = g_normalize_mouse_sens ? 1.0f : pSettings->read_if_exists<float>(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()
Expand Down
12 changes: 12 additions & 0 deletions src/xrGame/inventory_item.h
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ class CInventoryItem : public CAttachableItem,

public:
virtual void Load(LPCSTR section);
void ReadCustomTextAndMarks(LPCSTR section);
void ReloadNames();

LPCSTR NameItem(); // remove <virtual> by sea
Expand Down Expand Up @@ -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){};
Expand Down
92 changes: 92 additions & 0 deletions src/xrGame/ui/UICellItem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,17 @@ 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;
m_selected = false;
m_select_armament = false;
m_cur_mark = false;
m_has_upgrade = false;
m_with_custom_text = false;
m_with_custom_mark = false;

init();
}
Expand Down Expand Up @@ -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<CUIStatic>("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<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 @@ -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)
Expand Down
7 changes: 7 additions & 0 deletions src/xrGame/ui/UICellItem.h
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions src/xrUICore/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
16 changes: 16 additions & 0 deletions src/xrUICore/UIFontDefines.h
Original file line number Diff line number Diff line change
@@ -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"
19 changes: 2 additions & 17 deletions src/xrUICore/XML/UIXmlInitBase.cpp
Original file line number Diff line number Diff line change
@@ -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"
Expand All @@ -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";
Expand Down Expand Up @@ -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;
}
Expand Down
1 change: 1 addition & 0 deletions src/xrUICore/xrUICore.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@
<ClInclude Include="ui_debug.h" />
<ClInclude Include="ui_styles.h" />
<ClInclude Include="ui_base.h" />
<ClInclude Include="UIFontDefines.h" />
<ClInclude Include="ui_defs.h" />
<ClInclude Include="Windows\UIFrameLineWnd.h" />
<ClInclude Include="Windows\UIFrameWindow.h" />
Expand Down
1 change: 1 addition & 0 deletions src/xrUICore/xrUICore.vcxproj.filters
Original file line number Diff line number Diff line change
Expand Up @@ -330,6 +330,7 @@
<ClInclude Include="uiabstract.h" />
<ClInclude Include="UIMessages.h" />
<ClInclude Include="ui_base.h" />
<ClInclude Include="UIFontDefines.h" />
<ClInclude Include="Options\UIOptionsItem.h">
<Filter>Options</Filter>
</ClInclude>
Expand Down