Skip to content

Commit b1da4b2

Browse files
committed
Merge pull request godotengine#91128 from patwork/splash-image-in-web-export
Splash image support and new progress bar for HTML5 Web Export
2 parents ef48114 + 7c8a4a9 commit b1da4b2

File tree

2 files changed

+65
-142
lines changed

2 files changed

+65
-142
lines changed

misc/dist/html/full-size.html

Lines changed: 64 additions & 142 deletions
Original file line numberDiff line numberDiff line change
@@ -2,135 +2,95 @@
22
<html lang="en">
33
<head>
44
<meta charset="utf-8">
5-
<meta name="viewport" content="width=device-width, user-scalable=no">
5+
<meta name="viewport" content="width=device-width, user-scalable=no, initial-scale=1.0">
66
<title>$GODOT_PROJECT_NAME</title>
77
<style>
8-
body {
9-
touch-action: none;
8+
html, body, #canvas {
109
margin: 0;
11-
border: 0 none;
1210
padding: 0;
13-
text-align: center;
11+
border: 0;
12+
}
13+
14+
body {
15+
color: white;
1416
background-color: black;
17+
overflow: hidden;
18+
touch-action: none;
1519
}
1620

1721
#canvas {
1822
display: block;
19-
margin: 0;
20-
color: white;
2123
}
2224

2325
#canvas:focus {
2426
outline: none;
2527
}
2628

27-
.godot {
28-
font-family: 'Noto Sans', 'Droid Sans', Arial, sans-serif;
29-
color: #e0e0e0;
30-
background-color: #3b3943;
31-
background-image: linear-gradient(to bottom, #403e48, #35333c);
32-
border: 1px solid #45434e;
33-
box-shadow: 0 0 1px 1px #2f2d35;
34-
}
35-
36-
/* Status display */
37-
38-
#status {
29+
#status, #status-splash, #status-progress {
3930
position: absolute;
4031
left: 0;
41-
top: 0;
4232
right: 0;
33+
}
34+
35+
#status, #status-splash {
36+
top: 0;
4337
bottom: 0;
38+
}
39+
40+
#status {
41+
background-color: #38363A;
4442
display: flex;
43+
flex-direction: column;
4544
justify-content: center;
4645
align-items: center;
47-
/* don't consume click events - make children visible explicitly */
4846
visibility: hidden;
4947
}
5048

51-
#status-progress {
52-
width: 366px;
53-
height: 7px;
54-
background-color: #38363A;
55-
border: 1px solid #444246;
56-
padding: 1px;
57-
box-shadow: 0 0 2px 1px #1B1C22;
58-
border-radius: 2px;
59-
visibility: visible;
60-
}
61-
62-
@media only screen and (orientation:portrait) {
63-
#status-progress {
64-
width: 61.8%;
65-
}
49+
#status-splash {
50+
max-height: 100%;
51+
max-width: 100%;
52+
margin: auto;
6653
}
6754

68-
#status-progress-inner {
69-
height: 100%;
70-
width: 0;
71-
box-sizing: border-box;
72-
transition: width 0.5s linear;
73-
background-color: #202020;
74-
border: 1px solid #222223;
75-
box-shadow: 0 0 1px 1px #27282E;
76-
border-radius: 3px;
55+
#status-progress, #status-notice {
56+
display: none;
7757
}
7858

79-
#status-indeterminate {
80-
height: 42px;
81-
visibility: visible;
82-
position: relative;
83-
}
84-
85-
#status-indeterminate > div {
86-
width: 4.5px;
87-
height: 0;
88-
border-style: solid;
89-
border-width: 9px 3px 0 3px;
90-
border-color: #2b2b2b transparent transparent transparent;
91-
transform-origin: center 21px;
92-
position: absolute;
59+
#status-progress {
60+
bottom: 10%;
61+
width: 50%;
62+
margin: 0 auto;
9363
}
9464

95-
#status-indeterminate > div:nth-child(1) { transform: rotate( 22.5deg); }
96-
#status-indeterminate > div:nth-child(2) { transform: rotate( 67.5deg); }
97-
#status-indeterminate > div:nth-child(3) { transform: rotate(112.5deg); }
98-
#status-indeterminate > div:nth-child(4) { transform: rotate(157.5deg); }
99-
#status-indeterminate > div:nth-child(5) { transform: rotate(202.5deg); }
100-
#status-indeterminate > div:nth-child(6) { transform: rotate(247.5deg); }
101-
#status-indeterminate > div:nth-child(7) { transform: rotate(292.5deg); }
102-
#status-indeterminate > div:nth-child(8) { transform: rotate(337.5deg); }
103-
10465
#status-notice {
105-
margin: 0 100px;
66+
background-color: #5b3943;
67+
border-radius: 0.5rem;
68+
border: 1px solid #9b3943;
69+
color: #e0e0e0;
70+
font-family: 'Noto Sans', 'Droid Sans', Arial, sans-serif;
10671
line-height: 1.3;
107-
visibility: visible;
108-
padding: 4px 6px;
109-
visibility: visible;
72+
margin: 0 2rem;
73+
overflow: hidden;
74+
padding: 1rem;
75+
text-align: center;
76+
z-index: 1;
11077
}
11178
</style>
11279
$GODOT_HEAD_INCLUDE
11380
</head>
11481
<body>
11582
<canvas id="canvas">
116-
HTML5 canvas appears to be unsupported in the current browser.<br >
117-
Please try updating or use a different browser.
83+
Your browser does not support the canvas tag.
11884
</canvas>
85+
86+
<noscript>
87+
Your browser does not support JavaScript.
88+
</noscript>
89+
11990
<div id="status">
120-
<div id="status-progress" style="display: none;" oncontextmenu="event.preventDefault();">
121-
<div id ="status-progress-inner"></div>
122-
</div>
123-
<div id="status-indeterminate" style="display: none;" oncontextmenu="event.preventDefault();">
124-
<div></div>
125-
<div></div>
126-
<div></div>
127-
<div></div>
128-
<div></div>
129-
<div></div>
130-
<div></div>
131-
<div></div>
132-
</div>
133-
<div id="status-notice" class="godot" style="display: none;"></div>
91+
<img id="status-splash" src="$GODOT_SPLASH" alt="">
92+
<progress id="status-progress"></progress>
93+
<div id="status-notice"></div>
13494
</div>
13595

13696
<script src="$GODOT_URL"></script>
@@ -140,58 +100,25 @@
140100
const engine = new Engine(GODOT_CONFIG);
141101

142102
(function () {
143-
const INDETERMINATE_STATUS_STEP_MS = 100;
103+
const statusOverlay = document.getElementById('status');
144104
const statusProgress = document.getElementById('status-progress');
145-
const statusProgressInner = document.getElementById('status-progress-inner');
146-
const statusIndeterminate = document.getElementById('status-indeterminate');
147105
const statusNotice = document.getElementById('status-notice');
148106

149107
let initializing = true;
150-
let statusMode = 'hidden';
151-
152-
let animationCallbacks = [];
153-
function animate(time) {
154-
animationCallbacks.forEach((callback) => callback(time));
155-
requestAnimationFrame(animate);
156-
}
157-
requestAnimationFrame(animate);
158-
159-
function animateStatusIndeterminate(ms) {
160-
const i = Math.floor((ms / INDETERMINATE_STATUS_STEP_MS) % 8);
161-
if (statusIndeterminate.children[i].style.borderTopColor === '') {
162-
Array.prototype.slice.call(statusIndeterminate.children).forEach((child) => {
163-
child.style.borderTopColor = '';
164-
});
165-
statusIndeterminate.children[i].style.borderTopColor = '#dfdfdf';
166-
}
167-
}
108+
let statusMode = '';
168109

169110
function setStatusMode(mode) {
170111
if (statusMode === mode || !initializing) {
171112
return;
172113
}
173-
[statusProgress, statusIndeterminate, statusNotice].forEach((elem) => {
174-
elem.style.display = 'none';
175-
});
176-
animationCallbacks = animationCallbacks.filter(function (value) {
177-
return (value !== animateStatusIndeterminate);
178-
});
179-
switch (mode) {
180-
case 'progress':
181-
statusProgress.style.display = 'block';
182-
break;
183-
case 'indeterminate':
184-
statusIndeterminate.style.display = 'block';
185-
animationCallbacks.push(animateStatusIndeterminate);
186-
break;
187-
case 'notice':
188-
statusNotice.style.display = 'block';
189-
break;
190-
case 'hidden':
191-
break;
192-
default:
193-
throw new Error('Invalid status mode');
114+
if (mode === 'hidden') {
115+
statusOverlay.remove();
116+
initializing = false;
117+
return;
194118
}
119+
statusOverlay.style.visibility = 'visible';
120+
statusProgress.style.display = mode === 'progress' ? 'block' : 'none';
121+
statusNotice.style.display = mode === 'notice' ? 'block' : 'none';
195122
statusMode = mode;
196123
}
197124

@@ -217,6 +144,7 @@
217144
const missing = Engine.getMissingFeatures({
218145
threads: GODOT_THREADS_ENABLED,
219146
});
147+
220148
if (missing.length !== 0) {
221149
if (GODOT_CONFIG['serviceWorker'] && GODOT_CONFIG['ensureCrossOriginIsolationHeaders'] && 'serviceWorker' in navigator) {
222150
// There's a chance that installing the service worker would fix the issue
@@ -242,25 +170,19 @@
242170
displayFailureNotice(missingMsg + missing.join('\n'));
243171
}
244172
} else {
245-
setStatusMode('indeterminate');
173+
setStatusMode('progress');
246174
engine.startGame({
247175
'onProgress': function (current, total) {
248-
if (total > 0) {
249-
statusProgressInner.style.width = `${(current / total) * 100}%`;
250-
setStatusMode('progress');
251-
if (current === total) {
252-
// wait for progress bar animation
253-
setTimeout(() => {
254-
setStatusMode('indeterminate');
255-
}, 500);
256-
}
176+
if (current > 0 && total > 0) {
177+
statusProgress.value = current;
178+
statusProgress.max = total;
257179
} else {
258-
setStatusMode('indeterminate');
180+
statusProgress.removeAttribute('value');
181+
statusProgress.removeAttribute('max');
259182
}
260183
},
261184
}).then(() => {
262185
setStatusMode('hidden');
263-
initializing = false;
264186
}, displayFailureNotice);
265187
}
266188
}());

platform/web/export/export_plugin.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,7 @@ void EditorExportPlatformWeb::_fix_html(Vector<uint8_t> &p_html, const Ref<Edito
170170
replaces["$GODOT_PROJECT_NAME"] = GLOBAL_GET("application/config/name");
171171
replaces["$GODOT_HEAD_INCLUDE"] = head_include + custom_head_include;
172172
replaces["$GODOT_CONFIG"] = str_config;
173+
replaces["$GODOT_SPLASH"] = p_name + ".png";
173174

174175
if (p_preset->get("variant/thread_support")) {
175176
replaces["$GODOT_THREADS_ENABLED"] = "true";

0 commit comments

Comments
 (0)