Skip to content

Commit

Permalink
New CUIProgressBar mode: from center to edges
Browse files Browse the repository at this point in the history
For example, you can create loading screen like in SoC/CS with this
feature
  • Loading branch information
Xottab-DUTY committed Jun 24, 2018
1 parent 1ff5db9 commit 9f85c41
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 17 deletions.
43 changes: 32 additions & 11 deletions src/xrGame/ui/UIProgressBar.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,16 +39,26 @@ void CUIProgressBar::UpdateProgressBar()

float fCurrentLength = m_ProgressPos.x * progressbar_unit;

if (m_orient_mode == om_horz || m_orient_mode == om_back)
switch (m_orient_mode)
{
case om_horz:
case om_back:
case om_fromcenter:
m_CurrentLength = GetWidth() * fCurrentLength;
}
else if (m_orient_mode == om_vert || m_orient_mode == om_down)
{
break;

case om_vert:
case om_down:
case om_vfromcenter:
m_CurrentLength = GetHeight() * fCurrentLength;
}
else
{
break;

case om_tocenter:
case om_vtocenter:
R_ASSERT2(false, "to_center mode is not implemented.");
break;

default:
m_CurrentLength = 0.0f;
}

Expand Down Expand Up @@ -116,10 +126,21 @@ void CUIProgressBar::Draw()
case om_vert: progress_rect.set(0, GetHeight() - m_CurrentLength, GetWidth(), GetHeight()); break;
case om_back: progress_rect.set(GetWidth() - m_CurrentLength * 1.01f, 0, GetWidth(), GetHeight()); break;
case om_down: progress_rect.set(0, 0, GetWidth(), m_CurrentLength); break;
// XXX: Implement two-way progress bar
case om_twoway: R_ASSERT2(false, "two_way mode is not implemented."); break;
case om_vtwoway: R_ASSERT2(false, "vert_two_way mode is not implemented."); break;
case om_tocenter: R_ASSERT2(false, "from_edges_to_center mode is not implemented."); break;
case om_fromcenter:
{
const float center = GetWidth() / 2.f;
progress_rect.set(center - m_CurrentLength, 0, center + m_CurrentLength, GetHeight());
break;
}
case om_vfromcenter:
{
const float center = GetHeight() / 2.f;
progress_rect.set(0, center - m_CurrentLength, GetWidth(), center + m_CurrentLength);
break;
}
// XXX: Implement to_center mode
case om_tocenter:
case om_vtocenter: R_ASSERT2(false, "to_center mode is not implemented."); break;
default: NODEFAULT; break;
}

Expand Down
5 changes: 3 additions & 2 deletions src/xrGame/ui/UIProgressBar.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,10 @@ class CUIProgressBar : public CUIWindow
om_vert = 1,
om_back = 2,
om_down = 3,
om_twoway = 4,
om_vtwoway = 5,
om_fromcenter = 4,
om_vfromcenter = 5,
om_tocenter = 6,
om_vtocenter = 7,
om_count
} m_orient_mode;

Expand Down
12 changes: 8 additions & 4 deletions src/xrGame/ui/UIXmlInit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -559,18 +559,22 @@ bool CUIXmlInit::InitProgressBar(CUIXml& xml_doc, LPCSTR path, int index, CUIPro
{
mode = CUIProgressBar::om_down;
}
else if (xr_stricmp(mode_str, "two_way") == 0)
else if (xr_stricmp(mode_str, "from_center") == 0)
{
mode = CUIProgressBar::om_twoway;
mode = CUIProgressBar::om_fromcenter;
}
else if (xr_stricmp(mode_str, "vert_two_way") == 0)
else if (xr_stricmp(mode_str, "vert_from_center") == 0)
{
mode = CUIProgressBar::om_vtwoway;
mode = CUIProgressBar::om_vfromcenter;
}
else if (xr_stricmp(mode_str, "to_center") == 0)
{
mode = CUIProgressBar::om_tocenter;
}
else if (xr_stricmp(mode_str, "vert_to_center") == 0)
{
mode = CUIProgressBar::om_vtocenter;
}

pWnd->InitProgressBar(pos, size, mode);

Expand Down

1 comment on commit 9f85c41

@Xottab-DUTY
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Indirectly related to #382 and #392

Please sign in to comment.