Skip to content

Commit 4b1986e

Browse files
committed
CUIButtonHint: support for CS hint (#382)
1 parent 799e951 commit 4b1986e

File tree

2 files changed

+44
-13
lines changed

2 files changed

+44
-13
lines changed

src/xrUICore/Buttons/UIBtnHint.cpp

+39-11
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,28 @@
11
#include "pch.hpp"
22
#include "UIBtnHint.h"
33
#include "Static/UIStatic.h"
4+
#include "Windows/UIFrameLineWnd.h"
45
#include "XML/UIXmlInitBase.h"
56

67
CUIButtonHint* g_btnHint = nullptr;
78
CUIButtonHint* g_statHint = nullptr;
89

9-
CUIButtonHint::CUIButtonHint()
10-
: CUIFrameWindow(CUIButtonHint::GetDebugType()),
11-
m_ownerWnd(nullptr),
12-
m_enabledOnFrame(false)
10+
CUIButtonHint::CUIButtonHint() : CUIFrameWindow(CUIButtonHint::GetDebugType())
1311
{
1412
CUIXml uiXml;
1513
uiXml.Load(CONFIG_PATH, UI_PATH, UI_PATH_DEFAULT, "hint_item.xml");
16-
CUIXmlInitBase::InitFrameWindow(uiXml, "button_hint", 0, this);
14+
15+
if (uiXml.NavigateToNode("button_hint:texture")) // COP
16+
CUIXmlInitBase::InitFrameWindow(uiXml, "button_hint", 0, this);
17+
else // CS
18+
{
19+
CUIXmlInitBase::InitWindow(uiXml, "button_hint", 0, this);
20+
21+
m_border = xr_new<CUIFrameLineWnd>("Border");
22+
m_border->SetAutoDelete(true);
23+
AttachChild(m_border);
24+
CUIXmlInitBase::InitFrameLine(uiXml, "button_hint:frame_line", 0, m_border);
25+
}
1726

1827
m_text = xr_new<CUIStatic>("Text");
1928
m_text->SetAutoDelete(true);
@@ -26,7 +35,14 @@ void CUIButtonHint::OnRender()
2635
if (m_enabledOnFrame)
2736
{
2837
m_text->Update();
29-
SetTextureColor(color_rgba(255, 255, 255, color_get_A(m_text->GetTextColor())));
38+
39+
const u32 color = color_rgba(255, 255, 255, color_get_A(m_text->GetTextColor()));
40+
41+
if (m_border)
42+
m_border->SetTextureColor(color);
43+
else
44+
SetTextureColor(color);
45+
3046
Draw();
3147
m_enabledOnFrame = false;
3248
}
@@ -37,13 +53,25 @@ void CUIButtonHint::SetHintText(CUIWindow* w, LPCSTR text)
3753
m_ownerWnd = w;
3854
m_text->SetTextST(text);
3955

40-
m_text->AdjustHeightToText();
56+
if (m_border)
57+
{
58+
m_text->AdjustWidthToText();
59+
const float hh = _max(m_text->GetWidth()+30.0f, 80.0f);
60+
SetWidth(hh);
61+
m_border->SetWidth(hh); // XXX: CUIFrameLineWnd ignores this. Fix
62+
}
63+
else
64+
{
65+
m_text->AdjustHeightToText();
4166

42-
Fvector2 new_size;
43-
new_size.x = GetWndSize().x;
44-
new_size.y = m_text->GetWndSize().y + 20.0f;
67+
const Fvector2 new_size
68+
{
69+
GetWndSize().x,
70+
m_text->GetWndSize().y + 20.0f
71+
};
4572

46-
SetWndSize(new_size);
73+
SetWndSize(new_size);
74+
}
4775

4876
m_text->ResetColorAnimation();
4977
}

src/xrUICore/Buttons/UIBtnHint.h

+5-2
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,16 @@
22
#include "xrUICore/Windows/UIFrameWindow.h"
33

44
class CUIStatic;
5+
class CUIFrameLineWnd;
56

67
class XRUICORE_API CUIButtonHint final : public CUIFrameWindow
78
{
8-
CUIWindow* m_ownerWnd;
9+
CUIWindow* m_ownerWnd{};
910

1011
CUIStatic* m_text;
11-
bool m_enabledOnFrame;
12+
CUIFrameLineWnd* m_border{};
13+
14+
bool m_enabledOnFrame{};
1215

1316
public:
1417
CUIButtonHint();

0 commit comments

Comments
 (0)