Skip to content

Commit

Permalink
CUIButtonHint: support for CS hint (#382)
Browse files Browse the repository at this point in the history
  • Loading branch information
Xottab-DUTY committed Feb 23, 2024
1 parent 799e951 commit 4b1986e
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 13 deletions.
50 changes: 39 additions & 11 deletions src/xrUICore/Buttons/UIBtnHint.cpp
Original file line number Diff line number Diff line change
@@ -1,19 +1,28 @@
#include "pch.hpp"
#include "UIBtnHint.h"
#include "Static/UIStatic.h"
#include "Windows/UIFrameLineWnd.h"
#include "XML/UIXmlInitBase.h"

CUIButtonHint* g_btnHint = nullptr;
CUIButtonHint* g_statHint = nullptr;

CUIButtonHint::CUIButtonHint()
: CUIFrameWindow(CUIButtonHint::GetDebugType()),
m_ownerWnd(nullptr),
m_enabledOnFrame(false)
CUIButtonHint::CUIButtonHint() : CUIFrameWindow(CUIButtonHint::GetDebugType())
{
CUIXml uiXml;
uiXml.Load(CONFIG_PATH, UI_PATH, UI_PATH_DEFAULT, "hint_item.xml");
CUIXmlInitBase::InitFrameWindow(uiXml, "button_hint", 0, this);

if (uiXml.NavigateToNode("button_hint:texture")) // COP
CUIXmlInitBase::InitFrameWindow(uiXml, "button_hint", 0, this);
else // CS
{
CUIXmlInitBase::InitWindow(uiXml, "button_hint", 0, this);

m_border = xr_new<CUIFrameLineWnd>("Border");
m_border->SetAutoDelete(true);
AttachChild(m_border);
CUIXmlInitBase::InitFrameLine(uiXml, "button_hint:frame_line", 0, m_border);
}

m_text = xr_new<CUIStatic>("Text");
m_text->SetAutoDelete(true);
Expand All @@ -26,7 +35,14 @@ void CUIButtonHint::OnRender()
if (m_enabledOnFrame)
{
m_text->Update();
SetTextureColor(color_rgba(255, 255, 255, color_get_A(m_text->GetTextColor())));

const u32 color = color_rgba(255, 255, 255, color_get_A(m_text->GetTextColor()));

if (m_border)
m_border->SetTextureColor(color);
else
SetTextureColor(color);

Draw();
m_enabledOnFrame = false;
}
Expand All @@ -37,13 +53,25 @@ void CUIButtonHint::SetHintText(CUIWindow* w, LPCSTR text)
m_ownerWnd = w;
m_text->SetTextST(text);

m_text->AdjustHeightToText();
if (m_border)
{
m_text->AdjustWidthToText();
const float hh = _max(m_text->GetWidth()+30.0f, 80.0f);
SetWidth(hh);
m_border->SetWidth(hh); // XXX: CUIFrameLineWnd ignores this. Fix
}
else
{
m_text->AdjustHeightToText();

Fvector2 new_size;
new_size.x = GetWndSize().x;
new_size.y = m_text->GetWndSize().y + 20.0f;
const Fvector2 new_size
{
GetWndSize().x,
m_text->GetWndSize().y + 20.0f
};

SetWndSize(new_size);
SetWndSize(new_size);
}

m_text->ResetColorAnimation();
}
7 changes: 5 additions & 2 deletions src/xrUICore/Buttons/UIBtnHint.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,16 @@
#include "xrUICore/Windows/UIFrameWindow.h"

class CUIStatic;
class CUIFrameLineWnd;

class XRUICORE_API CUIButtonHint final : public CUIFrameWindow
{
CUIWindow* m_ownerWnd;
CUIWindow* m_ownerWnd{};

CUIStatic* m_text;
bool m_enabledOnFrame;
CUIFrameLineWnd* m_border{};

bool m_enabledOnFrame{};

public:
CUIButtonHint();
Expand Down

0 comments on commit 4b1986e

Please sign in to comment.