Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
oetzit
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
This is an archived project. Repository and other project resources are read-only.
Show more breadcrumbs
commul
oetzit
Commits
9fe82481
Commit
9fe82481
authored
3 years ago
by
Paolo.Brasolin
Browse files
Options
Downloads
Patches
Plain Diff
feat: #fe make HUD responsive
parent
bc13ad7d
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
frontend/src/js/hud.ts
+31
-14
31 additions, 14 deletions
frontend/src/js/hud.ts
with
31 additions
and
14 deletions
frontend/src/js/hud.ts
+
31
−
14
View file @
9fe82481
...
@@ -4,23 +4,35 @@ const ICONS = {
...
@@ -4,23 +4,35 @@ const ICONS = {
HEALTH
:
"
❤️️
"
,
HEALTH
:
"
❤️️
"
,
};
};
const
DEFAULT_TEXT_STYLE
=
{
const
STATS_TEXT_STYLE
=
{
font
:
"
bold 24px Courier
"
,
fontFamily
:
"
Courier
"
,
fontStyle
:
"
bold
"
,
fontSize
:
"
max(3vw,20px)
"
,
// never smaller than 20px
color
:
"
white
"
,
color
:
"
white
"
,
testString
:
`
${
ICONS
.
CLOCK
}${
ICONS
.
HEALTH
}${
ICONS
.
SCORE
}
1234567890:.`
,
testString
:
`
${
ICONS
.
CLOCK
}${
ICONS
.
HEALTH
}${
ICONS
.
SCORE
}
1234567890:.`
,
stroke
:
"
black
"
,
stroke
:
"
black
"
,
strokeThickness
:
4
,
strokeThickness
:
4
,
}
as
Phaser
.
Types
.
GameObjects
.
Text
.
TextStyle
;
}
as
Phaser
.
Types
.
GameObjects
.
Text
.
TextStyle
;
const
INPUT_TEXT_STYLE
=
{
fontFamily
:
"
Courier
"
,
fontStyle
:
"
bold
"
,
fontSize
:
"
min(12vw,60px)
"
,
// always fit ~12 chars comfortably in width
color
:
"
white
"
,
testString
:
`ABCDEFGHIJKLMNOPQRSTUVWXYZÄÜÖẞabcdefghijklmnopqrstuvwxyzäüöß `
,
}
as
Phaser
.
Types
.
GameObjects
.
Text
.
TextStyle
;
export
default
class
HUD
{
export
default
class
HUD
{
scene
:
Phaser
.
Scene
;
scene
:
Phaser
.
Scene
;
input
:
Phaser
.
GameObjects
.
Text
;
input
:
Phaser
.
GameObjects
.
Text
;
score
:
Phaser
.
GameObjects
.
Text
;
score
:
Phaser
.
GameObjects
.
Text
;
clock
:
Phaser
.
GameObjects
.
Text
;
clock
:
Phaser
.
GameObjects
.
Text
;
health
:
Phaser
.
GameObjects
.
Text
;
health
:
Phaser
.
GameObjects
.
Text
;
pad
:
number
;
constructor
(
scene
:
Phaser
.
Scene
)
{
constructor
(
scene
:
Phaser
.
Scene
)
{
this
.
scene
=
scene
;
this
.
scene
=
scene
;
this
.
pad
=
Math
.
min
(
this
.
scene
.
cameras
.
main
.
width
*
0.01
,
10
);
// min(1vw,10px)
this
.
input
=
this
.
initInput
(
scene
);
this
.
input
=
this
.
initInput
(
scene
);
this
.
score
=
this
.
initScore
(
scene
);
this
.
score
=
this
.
initScore
(
scene
);
this
.
health
=
this
.
initHealth
(
scene
);
this
.
health
=
this
.
initHealth
(
scene
);
...
@@ -29,20 +41,24 @@ export default class HUD {
...
@@ -29,20 +41,24 @@ export default class HUD {
initInput
(
scene
:
Phaser
.
Scene
)
{
initInput
(
scene
:
Phaser
.
Scene
)
{
return
scene
.
add
return
scene
.
add
.
text
(
scene
.
cameras
.
main
.
width
/
2
,
scene
.
cameras
.
main
.
height
/
2
,
""
,
{
.
text
(
font
:
"
bold 64px Courier
"
,
scene
.
cameras
.
main
.
width
/
2
,
color
:
"
#ffffff
"
,
scene
.
cameras
.
main
.
height
/
2
,
})
""
,
INPUT_TEXT_STYLE
,
)
.
setOrigin
(
0.5
,
0.5
);
.
setOrigin
(
0.5
,
0.5
);
}
}
initScore
(
scene
:
Phaser
.
Scene
)
{
initScore
(
scene
:
Phaser
.
Scene
)
{
return
scene
.
add
.
text
(
10
,
10
,
""
,
DEFAULT_TEXT_STYLE
).
setOrigin
(
0
,
0
);
return
scene
.
add
.
text
(
this
.
pad
,
this
.
pad
,
""
,
STATS_TEXT_STYLE
)
.
setOrigin
(
0
,
0
);
}
}
initHealth
(
scene
:
Phaser
.
Scene
)
{
initHealth
(
scene
:
Phaser
.
Scene
)
{
return
scene
.
add
return
scene
.
add
.
text
(
scene
.
cameras
.
main
.
width
-
10
,
10
,
""
,
DEFAULT
_TEXT_STYLE
)
.
text
(
scene
.
cameras
.
main
.
width
-
this
.
pad
,
this
.
pad
,
""
,
STATS
_TEXT_STYLE
)
.
setOrigin
(
1
,
0
);
.
setOrigin
(
1
,
0
);
}
}
...
@@ -50,9 +66,9 @@ export default class HUD {
...
@@ -50,9 +66,9 @@ export default class HUD {
return
scene
.
add
return
scene
.
add
.
text
(
.
text
(
scene
.
cameras
.
main
.
width
*
0.5
,
scene
.
cameras
.
main
.
width
*
0.5
,
10
,
this
.
pad
,
`
${
ICONS
.
CLOCK
}
1:23.32`
,
`
${
ICONS
.
CLOCK
}
1:23.32`
,
DEFAULT
_TEXT_STYLE
,
STATS
_TEXT_STYLE
,
)
)
.
setOrigin
(
0.5
,
0
);
.
setOrigin
(
0.5
,
0
);
}
}
...
@@ -62,11 +78,11 @@ export default class HUD {
...
@@ -62,11 +78,11 @@ export default class HUD {
}
}
setScore
(
score
:
number
)
{
setScore
(
score
:
number
)
{
this
.
score
.
text
=
`
${
ICONS
.
SCORE
}
${
score
}
`
;
this
.
score
.
text
=
`
${
ICONS
.
SCORE
}
\u2009
${
score
}
`
;
}
}
setHealth
(
health
:
number
)
{
setHealth
(
health
:
number
)
{
this
.
health
.
text
=
`
${
health
}
${
ICONS
.
HEALTH
}
`
;
this
.
health
.
text
=
`
${
health
}
\u2009
${
ICONS
.
HEALTH
}
`
;
}
}
setClock
(
milliseconds
:
number
)
{
setClock
(
milliseconds
:
number
)
{
...
@@ -78,7 +94,8 @@ export default class HUD {
...
@@ -78,7 +94,8 @@ export default class HUD {
.
toString
()
.
toString
()
.
padStart
(
2
,
"
0
"
);
.
padStart
(
2
,
"
0
"
);
const
formatted
=
`
${
minutes
}
:
${
seconds
}
.
${
hundredths
}
`
;
const
formatted
=
`
${
minutes
}
:
${
seconds
}
.
${
hundredths
}
`
;
this
.
clock
.
text
=
`
${
formatted
}
${
ICONS
.
CLOCK
}
`
;
// TODO: we can probably do away with the clock icon
this
.
clock
.
text
=
`
${
formatted
}
\u2009
${
ICONS
.
CLOCK
}
`
;
}
}
showSubmitFeedback
(
color
:
string
,
input
:
string
)
{
showSubmitFeedback
(
color
:
string
,
input
:
string
)
{
...
@@ -88,7 +105,7 @@ export default class HUD {
...
@@ -88,7 +105,7 @@ export default class HUD {
this
.
scene
.
cameras
.
main
.
height
/
2
,
this
.
scene
.
cameras
.
main
.
height
/
2
,
input
,
input
,
{
{
font
:
"
bold 64px Courier
"
,
...
INPUT_TEXT_STYLE
,
color
:
color
,
color
:
color
,
},
},
)
)
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment