Skip to content

Commit

Permalink
xrGame/ui/UIMotionIcon.h|cpp: returned deleted fields (#382 and proba…
Browse files Browse the repository at this point in the history
…bly #392)
  • Loading branch information
Xottab-DUTY committed May 23, 2019
1 parent ddece9a commit 44d4666
Show file tree
Hide file tree
Showing 2 changed files with 215 additions and 44 deletions.
229 changes: 191 additions & 38 deletions src/xrGame/ui/UIMotionIcon.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,28 @@
#include "UIMainIngameWnd.h"
#include "UIMotionIcon.h"
#include "UIXmlInit.h"
const LPCSTR MOTION_ICON_XML = "motion_icon.xml";
#include "UIHelper.h"

CUIMotionIcon* g_pMotionIcon = NULL;
constexpr pcstr MOTION_ICON_XML = "motion_icon.xml";

CUIMotionIcon* g_pMotionIcon = nullptr;

CUIMotionIcon::CUIMotionIcon()
{
m_current_state = stLast;
g_pMotionIcon = this;
m_bchanged = true;
m_luminosity = 0.0f;
cur_pos = 0.f;
m_cur_pos = 0.f;

m_power_progress = nullptr;
m_luminosity_progress_bar = nullptr;
m_noise_progress_bar = nullptr;
m_luminosity_progress_shape = nullptr;
m_noise_progress_shape = nullptr;
}

CUIMotionIcon::~CUIMotionIcon() { g_pMotionIcon = NULL; }
CUIMotionIcon::~CUIMotionIcon() { g_pMotionIcon = nullptr; }
void CUIMotionIcon::ResetVisibility()
{
m_npc_visibility.clear();
Expand All @@ -26,47 +35,159 @@ void CUIMotionIcon::Init(Frect const& zonemap_rect)
CUIXml uiXml;
uiXml.Load(CONFIG_PATH, UI_PATH, UI_PATH_DEFAULT, MOTION_ICON_XML);

CUIXmlInit::InitWindow(uiXml, "window", 0, this);
float rel_sz = uiXml.ReadAttribFlt("window", 0, "rel_size", 1.0f);
bool independent = false; // Not bound to minimap
if (!CUIXmlInit::InitWindow(uiXml, "window", 0, this, false))
{
independent = CUIXmlInit::InitStatic(uiXml, "background", 0, this, false);
}

const float rel_sz = uiXml.ReadAttribFlt("window", 0, "rel_size", 1.0f);
Fvector2 sz;
Fvector2 pos;
zonemap_rect.getsize(sz);

pos.set(sz.x / 2.0f, sz.y / 2.0f);
SetWndSize(sz);
SetWndPos(pos);
if (!independent)
{
SetWndSize(sz);
SetWndPos(pos);
}

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

// float h = Device.dwHeight;
// float w = Device.dwWidth;
AttachChild(&m_luminosity_progress);
CUIXmlInit::InitProgressShape(uiXml, "luminosity_progress", 0, &m_luminosity_progress);
m_luminosity_progress.SetWndSize(sz);
m_luminosity_progress.SetWndPos(pos);

AttachChild(&m_noise_progress);
CUIXmlInit::InitProgressShape(uiXml, "noise_progress", 0, &m_noise_progress);
m_noise_progress.SetWndSize(sz);
m_noise_progress.SetWndPos(pos);
// Initialization order matters, we should try progress bars first!!!
m_luminosity_progress_bar = UIHelper::CreateProgressBar(uiXml, "luminosity_progress", this, false);
m_noise_progress_bar = UIHelper::CreateProgressBar(uiXml, "noise_progress", this, false);

// 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);
}
}

CUIStatic* state;

if ((state = UIHelper::CreateStatic(uiXml, "state_normal", this, false)))
{
m_states[stNormal] = state;
state->Show(false);
}
if ((state = UIHelper::CreateStatic(uiXml, "state_normal", this, false)))
{
m_states[stNormal] = state;
state->Show(false);
}

if ((state = UIHelper::CreateStatic(uiXml, "state_crouch", this, false)))
{
m_states[stCrouch] = state;
state->Show(false);
}

if ((state = UIHelper::CreateStatic(uiXml, "state_creep", this, false)))
{
m_states[stCreep] = state;
state->Show(false);
}

if ((state = UIHelper::CreateStatic(uiXml, "state_climb", this, false)))
{
m_states[stClimb] = state;
state->Show(false);
}

if ((state = UIHelper::CreateStatic(uiXml, "state_run", this, false)))
{
m_states[stRun] = state;
state->Show(false);
}

if ((state = UIHelper::CreateStatic(uiXml, "state_sprint", this, false)))
{
m_states[stSprint] = state;
state->Show(false);
}

ShowState(stNormal);
}

void CUIMotionIcon::ShowState(EState state)
{
if (m_current_state == state)
return;

if (m_current_state != stLast)
{
CUIStatic* curState = m_states[m_current_state];
if (curState)
{
curState->Show(false);
curState->Enable(false);
}
}
CUIStatic* newState = m_states[m_current_state];
if (newState)
{
newState->Show(true);
newState->Enable(true);
}

m_current_state = state;
}

void CUIMotionIcon::SetPower(float newPos)
{
if (m_power_progress)
m_power_progress->SetProgressPos(newPos);
}

void CUIMotionIcon::SetNoise(float Pos)
void CUIMotionIcon::SetNoise(float newPos)
{
if (!IsGameTypeSingle())
return;

Pos = clampr(Pos, 0.f, 100.f);
m_noise_progress.SetPos(Pos / 100.f);
if (m_noise_progress_shape)
{
float pos = newPos;
pos = clampr(pos, 0.f, 100.f);
m_noise_progress_shape->SetPos(pos / 100.f);
}
else if (m_noise_progress_bar)
{
float pos = newPos;
pos = clampr(pos, m_noise_progress_bar->GetRange_min(), m_noise_progress_bar->GetRange_max());
m_noise_progress_bar->SetProgressPos(pos);
}
}

void CUIMotionIcon::SetLuminosity(float Pos)
void CUIMotionIcon::SetLuminosity(float newPos)
{
if (!IsGameTypeSingle())
return;

m_luminosity = Pos;
if (m_luminosity_progress_shape)
m_luminosity = newPos;
else if (m_luminosity_progress_bar)
{
newPos = clampr(newPos, m_luminosity_progress_bar->GetRange_min(), m_luminosity_progress_bar->GetRange_max());
m_luminosity = newPos;
}
}

void CUIMotionIcon::Draw() { inherited::Draw(); }
Expand All @@ -80,7 +201,7 @@ void CUIMotionIcon::Update()
if (m_bchanged)
{
m_bchanged = false;
if (m_npc_visibility.size())
if (!m_npc_visibility.empty())
{
std::sort(m_npc_visibility.begin(), m_npc_visibility.end());
SetLuminosity(m_npc_visibility.back().value);
Expand All @@ -90,20 +211,43 @@ void CUIMotionIcon::Update()
}
inherited::Update();

// m_luminosity_progress
if (cur_pos != m_luminosity)
// m_luminosity_progress_shape
if (m_cur_pos != m_luminosity)
{
float _diff = _abs(m_luminosity - cur_pos);
if (m_luminosity > cur_pos)
if (m_luminosity_progress_shape)
{
cur_pos += _diff * Device.fTimeDelta;
const float _diff = _abs(m_luminosity - m_cur_pos);
if (m_luminosity > m_cur_pos)
{
m_cur_pos += _diff * Device.fTimeDelta;
}
else
{
m_cur_pos -= _diff * Device.fTimeDelta;
}
clamp(m_cur_pos, 0.f, 100.f);
// XXX: make it like progress bar so we can remove m_cur_pos
m_luminosity_progress_shape->SetPos(m_cur_pos / 100.f);
}
else
else if (m_luminosity_progress_bar)
{
cur_pos -= _diff * Device.fTimeDelta;
const float len = m_luminosity_progress_bar->GetRange_max() - m_luminosity_progress_bar->GetRange_min();
m_cur_pos = m_luminosity_progress_bar->GetProgressPos();
if (m_cur_pos != m_luminosity)
{
const float _diff = _abs(m_luminosity - m_cur_pos);
if (m_luminosity > m_cur_pos)
{
m_cur_pos += _min(len * Device.fTimeDelta, _diff);
}
else
{
m_cur_pos -= _min(len * Device.fTimeDelta, _diff);
}
clamp(m_cur_pos, m_luminosity_progress_bar->GetRange_min(), m_luminosity_progress_bar->GetRange_max());
m_luminosity_progress_bar->SetProgressPos(m_cur_pos);
}
}
clamp(cur_pos, 0.f, 100.f);
m_luminosity_progress.SetPos(cur_pos / 100.f);
}
}

Expand All @@ -118,10 +262,19 @@ void SetActorVisibility(u16 who_id, float value)

void CUIMotionIcon::SetActorVisibility(u16 who_id, float value)
{
clamp(value, 0.f, 1.f);
value *= 100.f;
if (m_luminosity_progress_shape)
{
clamp(value, 0.f, 1.f);
value *= 100.f;
}
else if (m_luminosity_progress_bar)
{
float v = float(m_luminosity_progress_bar->GetRange_max() - m_luminosity_progress_bar->GetRange_min());
value *= v;
value += m_luminosity_progress_bar->GetRange_min();
}

xr_vector<_npc_visibility>::iterator it = std::find(m_npc_visibility.begin(), m_npc_visibility.end(), who_id);
auto it = std::find(m_npc_visibility.begin(), m_npc_visibility.end(), who_id);

if (it == m_npc_visibility.end() && value != 0)
{
Expand Down
30 changes: 24 additions & 6 deletions src/xrGame/ui/UIMotionIcon.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,30 @@
#include "xrUICore/ProgressBar/UIProgressBar.h"
#include "xrUICore/ProgressBar/UIProgressShape.h"

class CUIMotionIcon : public CUIWindow
class CUIMotionIcon : public CUIStatic
{
typedef CUIWindow inherited;
using inherited = CUIStatic;

public:
enum EState
{
stNormal,
stCrouch,
stCreep,
stClimb,
stRun,
stSprint,
stLast
};
private:
CUIProgressShape m_luminosity_progress;
CUIProgressShape m_noise_progress;
EState m_current_state;
xr_map<EState, CUIStatic*> m_states;
CUIProgressBar* m_power_progress;

CUIProgressShape* m_luminosity_progress_shape;
CUIProgressShape* m_noise_progress_shape;
CUIProgressBar* m_luminosity_progress_bar;
CUIProgressBar* m_noise_progress_bar;

struct _npc_visibility
{
Expand All @@ -21,16 +37,18 @@ class CUIMotionIcon : public CUIWindow
xr_vector<_npc_visibility> m_npc_visibility;
bool m_bchanged;
float m_luminosity;
float cur_pos;
float m_cur_pos;

public:
virtual ~CUIMotionIcon();
CUIMotionIcon();
virtual void Update();
virtual void Draw();
void Init(Frect const& rect);
void ShowState(EState state);
void SetPower(float Pos);
void SetNoise(float Pos);
void SetLuminosity(float Pos);
void SetLuminosity(float newPos);
void SetActorVisibility(u16 who_id, float value);
void ResetVisibility();
};

0 comments on commit 44d4666

Please sign in to comment.