Skip to content

Commit 9f85c41

Browse files
committed
New CUIProgressBar mode: from center to edges
For example, you can create loading screen like in SoC/CS with this feature
1 parent 1ff5db9 commit 9f85c41

File tree

3 files changed

+43
-17
lines changed

3 files changed

+43
-17
lines changed

src/xrGame/ui/UIProgressBar.cpp

Lines changed: 32 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -39,16 +39,26 @@ void CUIProgressBar::UpdateProgressBar()
3939

4040
float fCurrentLength = m_ProgressPos.x * progressbar_unit;
4141

42-
if (m_orient_mode == om_horz || m_orient_mode == om_back)
42+
switch (m_orient_mode)
4343
{
44+
case om_horz:
45+
case om_back:
46+
case om_fromcenter:
4447
m_CurrentLength = GetWidth() * fCurrentLength;
45-
}
46-
else if (m_orient_mode == om_vert || m_orient_mode == om_down)
47-
{
48+
break;
49+
50+
case om_vert:
51+
case om_down:
52+
case om_vfromcenter:
4853
m_CurrentLength = GetHeight() * fCurrentLength;
49-
}
50-
else
51-
{
54+
break;
55+
56+
case om_tocenter:
57+
case om_vtocenter:
58+
R_ASSERT2(false, "to_center mode is not implemented.");
59+
break;
60+
61+
default:
5262
m_CurrentLength = 0.0f;
5363
}
5464

@@ -116,10 +126,21 @@ void CUIProgressBar::Draw()
116126
case om_vert: progress_rect.set(0, GetHeight() - m_CurrentLength, GetWidth(), GetHeight()); break;
117127
case om_back: progress_rect.set(GetWidth() - m_CurrentLength * 1.01f, 0, GetWidth(), GetHeight()); break;
118128
case om_down: progress_rect.set(0, 0, GetWidth(), m_CurrentLength); break;
119-
// XXX: Implement two-way progress bar
120-
case om_twoway: R_ASSERT2(false, "two_way mode is not implemented."); break;
121-
case om_vtwoway: R_ASSERT2(false, "vert_two_way mode is not implemented."); break;
122-
case om_tocenter: R_ASSERT2(false, "from_edges_to_center mode is not implemented."); break;
129+
case om_fromcenter:
130+
{
131+
const float center = GetWidth() / 2.f;
132+
progress_rect.set(center - m_CurrentLength, 0, center + m_CurrentLength, GetHeight());
133+
break;
134+
}
135+
case om_vfromcenter:
136+
{
137+
const float center = GetHeight() / 2.f;
138+
progress_rect.set(0, center - m_CurrentLength, GetWidth(), center + m_CurrentLength);
139+
break;
140+
}
141+
// XXX: Implement to_center mode
142+
case om_tocenter:
143+
case om_vtocenter: R_ASSERT2(false, "to_center mode is not implemented."); break;
123144
default: NODEFAULT; break;
124145
}
125146

src/xrGame/ui/UIProgressBar.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,10 @@ class CUIProgressBar : public CUIWindow
1616
om_vert = 1,
1717
om_back = 2,
1818
om_down = 3,
19-
om_twoway = 4,
20-
om_vtwoway = 5,
19+
om_fromcenter = 4,
20+
om_vfromcenter = 5,
2121
om_tocenter = 6,
22+
om_vtocenter = 7,
2223
om_count
2324
} m_orient_mode;
2425

src/xrGame/ui/UIXmlInit.cpp

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -559,18 +559,22 @@ bool CUIXmlInit::InitProgressBar(CUIXml& xml_doc, LPCSTR path, int index, CUIPro
559559
{
560560
mode = CUIProgressBar::om_down;
561561
}
562-
else if (xr_stricmp(mode_str, "two_way") == 0)
562+
else if (xr_stricmp(mode_str, "from_center") == 0)
563563
{
564-
mode = CUIProgressBar::om_twoway;
564+
mode = CUIProgressBar::om_fromcenter;
565565
}
566-
else if (xr_stricmp(mode_str, "vert_two_way") == 0)
566+
else if (xr_stricmp(mode_str, "vert_from_center") == 0)
567567
{
568-
mode = CUIProgressBar::om_vtwoway;
568+
mode = CUIProgressBar::om_vfromcenter;
569569
}
570570
else if (xr_stricmp(mode_str, "to_center") == 0)
571571
{
572572
mode = CUIProgressBar::om_tocenter;
573573
}
574+
else if (xr_stricmp(mode_str, "vert_to_center") == 0)
575+
{
576+
mode = CUIProgressBar::om_vtocenter;
577+
}
574578

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

0 commit comments

Comments
 (0)