Skip to content

Commit

Permalink
Revised CUIMotionIcon and CUIMiniMap SOC/CS compatibility (#382, #392)
Browse files Browse the repository at this point in the history
WndPosIsProbablyRelative is a bad function :)
  • Loading branch information
Xottab-DUTY committed Aug 13, 2023
1 parent 1a83879 commit 4b1d592
Show file tree
Hide file tree
Showing 10 changed files with 67 additions and 85 deletions.
17 changes: 7 additions & 10 deletions src/xrGame/UIZoneMap.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
#include "ui/UIInventoryUtilities.h"
//////////////////////////////////////////////////////////////////////////

void CUIZoneMap::Init()
void CUIZoneMap::Init(bool motionIconAttached)
{
CUIXml uiXml;
uiXml.Load(CONFIG_PATH, UI_PATH, UI_PATH_DEFAULT, "zone_map.xml");
Expand All @@ -39,10 +39,7 @@ void CUIZoneMap::Init()
m_activeMap->SetAutoDelete(true);
m_activeMap->EnableHeading(true);

// Clear Sky and Shadow of Chernobyl compatibility
// Check for m_pointerDistanceText reduces flexibility
// But it's all we can, probably.
m_activeMap->SetRounded(!m_pointerDistanceText);
m_activeMap->SetRounded(motionIconAttached);

CUIXmlInit::InitStatic(uiXml, "minimap:compass", 0, &m_compass);
m_background.AttachChild(&m_compass);
Expand All @@ -55,7 +52,7 @@ void CUIZoneMap::Init()
Fvector2 temp;
const float k = UI().get_current_kx();

if (m_clipFrame.WndRectIsProbablyRelative())
if (motionIconAttached)
{
temp = m_clipFrame.GetWndSize();
temp.y *= UI_BASE_HEIGHT * k;
Expand All @@ -66,7 +63,7 @@ void CUIZoneMap::Init()
m_clipFrame.SetWndPos(temp.mul(UI_BASE_HEIGHT));
}

if (m_background.WndSizeIsProbablyRelative())
if (motionIconAttached)
{
m_background.SetHeight(m_background.GetHeight() * UI_BASE_HEIGHT);
m_background.SetWidth(m_background.GetHeight() * k);
Expand All @@ -78,14 +75,14 @@ void CUIZoneMap::Init()
temp = m_clipFrame.GetWndSize();
m_center.SetWndPos(temp.div(2.0f));

if (m_compass.WndPosIsProbablyRelative())
if (motionIconAttached)
{
temp = m_compass.GetWndPos();
temp.mul(m_background.GetWndSize());
m_compass.SetWndPos(temp);
}

if (m_clock_wnd && m_clock_wnd->WndPosIsProbablyRelative())
if (m_clock_wnd && motionIconAttached)
{
temp = m_clock_wnd->GetWndPos();
temp.mul(m_background.GetWndSize());
Expand All @@ -99,7 +96,7 @@ void CUIZoneMap::Init()
CUIXmlInit::InitTextWnd(uiXml, "minimap:static_counter:text_static", 0, &m_Counter_text);
m_Counter.AttachChild(&m_Counter_text);

if (m_Counter.WndPosIsProbablyRelative())
if (motionIconAttached)
{
temp = m_Counter.GetWndPos();
temp.mul(m_background.GetWndSize());
Expand Down
6 changes: 3 additions & 3 deletions src/xrGame/UIZoneMap.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,15 @@
#include "xrUICore/Static/UIStatic.h"

class CActor;
class CUIMiniMap;
class CUICustomMap;

class CUIZoneMap
{
public:
bool visible{ true };

private:
CUIMiniMap* m_activeMap{};
CUICustomMap* m_activeMap{};

CUIStatic m_background{ "Background" };
CUIStatic m_center{ "Center" };
Expand All @@ -27,7 +27,7 @@ class CUIZoneMap
public:
virtual ~CUIZoneMap() = default;

void Init();
void Init(bool motionIconAttached);

void Render();
void Update();
Expand Down
12 changes: 6 additions & 6 deletions src/xrGame/ui/UIDragDropListEx.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ void CUIDragDropListEx::InitDragDropList(Fvector2 pos, Fvector2 size)
Fvector2().set(m_vScrollBar->GetWndPos().x - m_vScrollBar->GetWidth(), m_vScrollBar->GetWndPos().y));
}

void CUIDragDropListEx::SetHighlighter(CUIStatic* highlighter, Fvector2 spacing)
void CUIDragDropListEx::SetHighlighter(CUIStatic* highlighter, Fvector2 spacing, bool convertPosToOurs /*= true*/)
{
if (m_highlighter)
{
Expand All @@ -113,7 +113,7 @@ void CUIDragDropListEx::SetHighlighter(CUIStatic* highlighter, Fvector2 spacing)
AttachChild(m_highlighter);
// Convert absolute position to relative
// Without this, UI Frustum will cull our highlighter
if (!m_highlighter->WndPosIsProbablyRelative())
if (convertPosToOurs)
{
Fvector2 ourAbsPos;
GetAbsolutePos(ourAbsPos);
Expand All @@ -130,7 +130,7 @@ void CUIDragDropListEx::Highlight(bool highlight)
m_highlighter->Show(highlight);
}

void CUIDragDropListEx::SetBlocker(CUIStatic* blocker, Fvector2 spacing)
void CUIDragDropListEx::SetBlocker(CUIStatic* blocker, Fvector2 spacing, bool convertPosToOurs /*= true*/)
{
if (m_blocker)
{
Expand All @@ -152,7 +152,7 @@ void CUIDragDropListEx::SetBlocker(CUIStatic* blocker, Fvector2 spacing)
AttachChild(m_blocker);
// Convert absolute position to relative
// Without this, UI Frustum will cull our blocker
if (!m_blocker->WndPosIsProbablyRelative())
if (convertPosToOurs)
{
Fvector2 ourAbsPos;
GetAbsolutePos(ourAbsPos);
Expand All @@ -163,7 +163,7 @@ void CUIDragDropListEx::SetBlocker(CUIStatic* blocker, Fvector2 spacing)
}
}

void CUIDragDropListEx::SetConditionIndicator(CUIProgressBar* indicator)
void CUIDragDropListEx::SetConditionIndicator(CUIProgressBar* indicator, bool convertPosToOurs /*= true*/)
{
if (m_condition_indicator && m_condition_indicator->GetParent() == this)
{
Expand All @@ -178,7 +178,7 @@ void CUIDragDropListEx::SetConditionIndicator(CUIProgressBar* indicator)
AttachChild(m_condition_indicator);
// Convert absolute position to relative
// Without this, UI Frustum will cull our indicator
if (!m_condition_indicator->WndPosIsProbablyRelative())
if (convertPosToOurs)
{
Fvector2 ourAbsPos;
GetAbsolutePos(ourAbsPos);
Expand Down
6 changes: 3 additions & 3 deletions src/xrGame/ui/UIDragDropListEx.h
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ class CUIDragDropListEx : public CUIWindow, public CUIWndCallback
bool GetVirtualCells();
void SetVirtualCells(bool b);

void SetHighlighter(CUIStatic* highlighter, Fvector2 spacing);
void SetHighlighter(CUIStatic* highlighter, Fvector2 spacing, bool convertPosToOurs = true);
CUIStatic* GetHighlighter() const
{
return m_highlighter;
Expand All @@ -153,7 +153,7 @@ class CUIDragDropListEx : public CUIWindow, public CUIWndCallback
}
void Highlight(bool highlight);

void SetBlocker(CUIStatic* blocker, Fvector2 spacing);
void SetBlocker(CUIStatic* blocker, Fvector2 spacing, bool convertPosToOurs = true);
CUIStatic* GetBlocker() const
{
return m_blocker;
Expand All @@ -163,7 +163,7 @@ class CUIDragDropListEx : public CUIWindow, public CUIWndCallback
return m_blocker_spacing;
}

void SetConditionIndicator(CUIProgressBar* indicator);
void SetConditionIndicator(CUIProgressBar* indicator, bool convertPosToOurs = true);
CUIProgressBar* GetConditionIndicator() const
{
return m_condition_indicator;
Expand Down
2 changes: 1 addition & 1 deletion src/xrGame/ui/UIDragDropReferenceList.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ void CUIDragDropReferenceList::Initialize(pcstr labelSection /*= nullptr*/, pcst
CUITextWnd* label = UIHelper::CreateTextWnd(*uiXml, temp, this, false);
if (label)
{
if (!label->WndPosIsProbablyRelative()) // Without this, UI Frustum will cull our label
if (true /*!label->WndPosIsProbablyRelative()*/) // Without this, UI Frustum will cull our label
{
const Fvector2& lblPos = label->GetWndPos();
label->SetWndPos({ lblPos.x - listAbsPos.x, lblPos.y - listAbsPos.y });
Expand Down
16 changes: 11 additions & 5 deletions src/xrGame/ui/UIMainIngameWnd.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -103,9 +103,6 @@ void CUIMainIngameWnd::Init()
m_iPickUpItemIconY = UIPickUpItemIcon->GetWndRect().top;
//---------------------------------------------------------

//индикаторы
UIZoneMap->Init();

// Подсказки, которые возникают при наведении прицела на объект
UIStaticQuickHelp = UIHelper::CreateTextWnd(uiXml, "quick_info", this);

Expand Down Expand Up @@ -207,11 +204,20 @@ void CUIMainIngameWnd::Init()

UIMotionIcon = xr_new<CUIMotionIcon>();
UIMotionIcon->SetAutoDelete(true);
const bool independent = UIMotionIcon->Init(UIZoneMap->MapFrame().GetWndRect());
if (!independent)
const bool attachedToMinimap = UIMotionIcon->Init();

//индикаторы
UIZoneMap->Init(attachedToMinimap);

if (attachedToMinimap)
{
UIZoneMap->MapFrame().AttachChild(UIMotionIcon);
UIMotionIcon->AttachToMinimap(UIZoneMap->MapFrame().GetWndRect());
}
else
{
AttachChild(UIMotionIcon);
}

UIStaticDiskIO = UIHelper::CreateStatic(uiXml, "disk_io", this);

Expand Down
2 changes: 0 additions & 2 deletions src/xrGame/ui/UIMap.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -578,8 +578,6 @@ void CUIMiniMap::Init_internal(const shared_str& name, const CInifile& pLtx, con
CUIStatic::SetTextureColor(0x7fffffff);
}

// XXX: examine the difference with CUILevelMap::UpdateSpots()
// maybe we need to use inherited::UpdateSpots() here when minimap is not rounded..
void CUIMiniMap::UpdateSpots()
{
DetachAll();
Expand Down
71 changes: 33 additions & 38 deletions src/xrGame/ui/UIMotionIcon.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,32 +32,17 @@ void CUIMotionIcon::ResetVisibility()
m_bchanged = true;
}

bool CUIMotionIcon::Init(Frect const& zonemap_rect)
bool CUIMotionIcon::Init()
{
CUIXml uiXml;
uiXml.Load(CONFIG_PATH, UI_PATH, UI_PATH_DEFAULT, MOTION_ICON_XML);

bool independent = false; // Not bound to minimap
if (!CUIXmlInit::InitWindow(uiXml, "window", 0, this, false))
{
independent = CUIXmlInit::InitStatic(uiXml, "background", 0, this, false);
}

Fvector2 sz{};
Fvector2 pos{};

if (!independent)
const bool attachedToMinimap = CUIXmlInit::InitWindow(uiXml, "window", 0, this, false);
if (attachedToMinimap)
m_relative_size = uiXml.ReadAttribFlt("window", 0, "rel_size", 1.0f);
else
{
const float rel_sz = uiXml.ReadAttribFlt("window", 0, "rel_size", 1.0f);

zonemap_rect.getsize(sz);
pos.set(sz.x / 2.0f, sz.y / 2.0f);

SetWndSize(sz);
SetWndPos(pos);

const float k = UICore::get_current_kx();
sz.mul(rel_sz * k);
CUIXmlInit::InitStatic(uiXml, "background", 0, this, false);
}

m_power_progress = UIHelper::CreateProgressBar(uiXml, "power_progress", this, false);
Expand All @@ -68,29 +53,14 @@ bool CUIMotionIcon::Init(Frect const& zonemap_rect)

// Allow only shape or bar, not both
if (!m_luminosity_progress_bar)
{
m_luminosity_progress_shape = UIHelper::CreateProgressShape(uiXml, "luminosity_progress", this, false);
if (m_luminosity_progress_shape && !independent)
{
m_luminosity_progress_shape->SetWndSize(sz);
m_luminosity_progress_shape->SetWndPos(pos);
}
}

if (!m_noise_progress_bar)
{
m_noise_progress_shape = UIHelper::CreateProgressShape(uiXml, "noise_progress", this, false);
if (m_noise_progress_shape && !independent)
{
m_noise_progress_shape->SetWndSize(sz);
m_noise_progress_shape->SetWndPos(pos);
}
}

const auto create_static = [&uiXml, this](pcstr ui_path, EState state)
{
auto ui_static = UIHelper::CreateStatic(uiXml, ui_path, this, false);
if (ui_static)
if (const auto ui_static = UIHelper::CreateStatic(uiXml, ui_path, this, false))
{
m_states[state] = ui_static;
ui_static->Show(false);
Expand All @@ -106,7 +76,32 @@ bool CUIMotionIcon::Init(Frect const& zonemap_rect)

ShowState(stNormal);

return independent;
return attachedToMinimap;
}

void CUIMotionIcon::AttachToMinimap(const Frect& rect)
{
Fvector2 sz{}, pos{};

rect.getsize(sz);
pos.set(sz.x / 2.0f, sz.y / 2.0f);

SetWndSize(sz);
SetWndPos(pos);

const float k = UICore::get_current_kx();
sz.mul(m_relative_size * k);

if (m_luminosity_progress_shape)
{
m_luminosity_progress_shape->SetWndSize(sz);
m_luminosity_progress_shape->SetWndPos(pos);
}
if (m_noise_progress_shape)
{
m_noise_progress_shape->SetWndSize(sz);
m_noise_progress_shape->SetWndPos(pos);
}
}

void CUIMotionIcon::ShowState(EState state)
Expand Down
4 changes: 3 additions & 1 deletion src/xrGame/ui/UIMotionIcon.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,13 +38,15 @@ class CUIMotionIcon final : public CUIStatic
bool m_bchanged;
float m_luminosity;
float m_cur_pos;
float m_relative_size{ 1.0f };

public:
CUIMotionIcon();
~CUIMotionIcon() override;
virtual void Update();
virtual void Draw();
bool Init(Frect const& rect);
bool Init();
void AttachToMinimap(const Frect& rect);
void ShowState(EState state);
void SetPower(float Pos);
void SetNoise(float Pos);
Expand Down
16 changes: 0 additions & 16 deletions src/xrUICore/uiabstract.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,22 +54,6 @@ class CUISimpleWindow : public Noncopyable
m_wndPos.set(rect.lt);
rect.getsize(m_wndSize);
}

virtual bool WndPosIsProbablyRelative()
{
return m_wndPos.x <= 1.0f && m_wndPos.y <= 1.0f;
}

virtual bool WndSizeIsProbablyRelative()
{
return m_wndSize.x <= 1.0f && m_wndSize.y <= 1.0f;
}

virtual bool WndRectIsProbablyRelative()
{
return WndPosIsProbablyRelative() && WndSizeIsProbablyRelative();
}

virtual void SetHeight(float height) { m_wndSize.y = height; }
IC float GetHeight() const { return m_wndSize.y; }
virtual void SetWidth(float width) { m_wndSize.x = width; }
Expand Down

0 comments on commit 4b1d592

Please sign in to comment.