Skip to content
GitLab
Menu
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
GameDevWeek
Sommersemester 2019
Cpp
PhaseShifter
Commits
306b27cd
Commit
306b27cd
authored
Sep 17, 2019
by
Kevin Balz
Browse files
Merge branch 'feature/10-ui-hud' into 'develop'
Feature/10 ui hud See merge request
!6
parents
10133b11
38bd1e7c
Pipeline
#3233
failed with stage
in 1 minute and 20 seconds
Changes
4
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
src/gameplay/beat_system.cpp
View file @
306b27cd
...
...
@@ -17,7 +17,7 @@ namespace phase_shifter::gameplay {
_acc
=
0
;
}
_state
=
{
beat
,
_acc
,
beat_time
-
_acc
};
_state
=
{
beat
,
_acc
,
beat_time
-
_acc
,
beat_time
};
}
}
// namespace phase_shifter::gameplay
src/meta_system.cpp
View file @
306b27cd
...
...
@@ -32,7 +32,7 @@ namespace phase_shifter {
,
_camera_system
(
std
::
make_unique
<
gameplay
::
Camera_system
>
(
_entities
))
,
_input_system
(
std
::
make_unique
<
input
::
Input_system
>
(
engine
.
bus
(),
_entities
))
,
_attachment_system
(
std
::
make_unique
<
helper
::
Attachment_system
>
(
_entities
))
,
_hud_system
(
std
::
make_unique
<
ui
::
Hud_system
>
(
engine
.
gui
(),
_entities
))
,
_hud_system
(
std
::
make_unique
<
ui
::
Hud_system
>
(
engine
.
gui
(),
_entities
,
*
_beat_system
))
{
_entities
.
register_component_type
<
ecs
::
components
::
Transform_comp
>
();
...
...
src/ui/hud_system.cpp
View file @
306b27cd
...
...
@@ -13,16 +13,28 @@ namespace phase_shifter::ui {
namespace
{
constexpr
auto
hud_height
=
100
;
}
constexpr
auto
count_down
=
300
;
constexpr
auto
bar_speed
=
100
;
}
// namespace
Hud_system
::
Hud_system
(
mirrage
::
gui
::
Gui
&
gui
,
mirrage
::
ecs
::
Entity_manager
&
ecs
)
:
_gui
(
gui
)
,
_ecs
(
ecs
)
Hud_system
::
Hud_system
(
mirrage
::
gui
::
Gui
&
gui
,
mirrage
::
ecs
::
Entity_manager
&
ecs
,
const
phase_shifter
::
gameplay
::
Beat_system
&
beat_system
)
:
_gui
(
gui
),
_ecs
(
ecs
),
_timeLeft
(
count_down
),
_beat_system
(
beat_system
)
{
//_circle_texture = _gui.load_texture("tex:circle"_aid);
_max_distance
=
gui
.
viewport
().
z
/
2
;
}
void
Hud_system
::
update
(
mirrage
::
util
::
Time
dt
)
{
_timeLeft
-=
dt
;
auto
state
=
_beat_system
.
beat_state
();
int
max_bars
=
static_cast
<
int
>
(
_max_distance
/
(
bar_speed
*
state
.
avg_beat_time
)
+
1
);
if
(
state
.
beat
&&
_beats
<
max_bars
)
{
_beats
++
;
}
_offset
=
state
.
time_to_beat
*
bar_speed
;
}
void
Hud_system
::
draw
()
...
...
@@ -33,20 +45,56 @@ namespace phase_shifter::ui {
if
(
font
.
is_some
())
ImGui
::
PushFont
(
font
.
get_or_throw
());
ImGui
::
PushStyleColor
(
ImGuiCol_WindowBg
,
"#333333FF"
_imcolor
.
Value
);
ImGui
::
PositionNextWindow
(
glm
::
vec2
(
viewport
.
z
,
hud_height
),
ImGui
::
WindowPosition_X
::
center
,
ImGui
::
WindowPosition_Y
::
bot
to
m
);
ImGui
::
WindowPosition_X
::
left
,
ImGui
::
WindowPosition_Y
::
to
p
);
if
(
ImGui
::
Begin
(
"hud"
,
nullptr
,
ImGuiWindowFlags_NoTitleBar
|
ImGuiWindowFlags_NoMove
|
ImGuiWindowFlags_NoResize
))
{
ImGui
::
Text
(
"TODO"
);
nullptr
,
ImGuiWindowFlags_NoTitleBar
|
ImGuiWindowFlags_NoMove
|
ImGuiWindowFlags_NoResize
|
ImGuiWindowFlags_NoBackground
))
{
ImGui
::
Text
(
"%.2f"
,
_timeLeft
.
value
());
ImGui
::
End
();
}
ImGui
::
PositionNextWindow
(
glm
::
vec2
(
viewport
.
z
,
150
),
ImGui
::
WindowPosition_X
::
center
,
ImGui
::
WindowPosition_Y
::
bottom
);
if
(
ImGui
::
Begin
(
"beat"
,
nullptr
,
ImGuiWindowFlags_NoTitleBar
|
ImGuiWindowFlags_NoMove
|
ImGuiWindowFlags_NoResize
|
ImGuiWindowFlags_NoBackground
))
{
ImGui
::
PushStyleColor
(
ImGuiCol_Border
,
"#00000000"
_imcolor
.
Value
);
// Hide Border
ImVec2
cursor
=
ImGui
::
GetCursorScreenPos
();
auto
beat_state
=
_beat_system
.
beat_state
();
int
max_bars
=
static_cast
<
int
>
(
_max_distance
/
(
bar_speed
*
beat_state
.
avg_beat_time
)
+
1
);
auto
line_offset
=
bar_speed
*
beat_state
.
avg_beat_time
;
auto
start_offset
=
(
max_bars
-
_beats
)
*
line_offset
;
ImGui
::
BeginChild
(
"Line"
,
{
viewport
.
z
,
90
},
true
);
ImDrawList
*
drawList
=
ImGui
::
GetWindowDrawList
();
for
(
int
i
=
0
;
i
<
_beats
;
i
++
)
{
ImVec2
p
(
cursor
.
x
+
_max_distance
-
_offset
-
start_offset
-
i
*
line_offset
,
cursor
.
y
+
10
);
drawList
->
AddLine
(
p
,
{
p
.
x
,
p
.
y
+
50
},
0xFFFFFFFF
,
1
);
}
for
(
int
i
=
0
;
i
<
_beats
;
i
++
)
{
ImVec2
p
(
cursor
.
x
+
viewport
.
z
/
2
+
_offset
+
start_offset
+
i
*
line_offset
,
cursor
.
y
+
10
);
drawList
->
AddLine
(
p
,
{
p
.
x
,
p
.
y
+
50
},
0xFFFFFFFF
,
1
);
}
ImVec2
middle
(
cursor
.
x
+
viewport
.
z
/
2
,
cursor
.
y
);
drawList
->
AddLine
(
middle
,
{
middle
.
x
,
middle
.
y
+
70
},
0xFFFF0000
,
3
);
ImGui
::
EndChild
();
ImGui
::
PopStyleColor
();
ImGui
::
End
();
if
(
beat_state
.
beat
||
beat_state
.
avg_beat_time
-
beat_state
.
time_since_beat
<
0.1
f
||
beat_state
.
time_to_beat
<
0.1
f
)
{
//TODO: Flash image to beat
//ImGui::Image(_circle_texture.get(), {10, 10});
}
}
ImGui
::
PopStyleColor
();
if
(
font
.
is_some
())
ImGui
::
PopFont
();
...
...
src/ui/hud_system.hpp
View file @
306b27cd
...
...
@@ -6,13 +6,16 @@
#include
<unordered_map>
#include
<memory>
#include
"../gameplay/beat_system.hpp"
namespace
phase_shifter
::
ui
{
class
Hud_system
{
public:
Hud_system
(
mirrage
::
gui
::
Gui
&
gui
,
mirrage
::
ecs
::
Entity_manager
&
ecs
);
Hud_system
(
mirrage
::
gui
::
Gui
&
gui
,
mirrage
::
ecs
::
Entity_manager
&
ecs
,
const
phase_shifter
::
gameplay
::
Beat_system
&
beat_system
);
void
update
(
mirrage
::
util
::
Time
dt
);
void
draw
();
...
...
@@ -20,6 +23,11 @@ namespace phase_shifter::ui {
private:
mirrage
::
gui
::
Gui
&
_gui
;
mirrage
::
ecs
::
Entity_manager
&
_ecs
;
mirrage
::
util
::
Time
_timeLeft
;
int
_beats
=
0
;
float
_offset
=
0
;
float
_max_distance
;
const
phase_shifter
::
gameplay
::
Beat_system
&
_beat_system
;
};
}
// namespace phase_shifter::ui
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment