2020-05-09 14:45:23 +00:00
|
|
|
/* typehints:start */
|
|
|
|
import { Application } from "../application";
|
|
|
|
/* typehints:end */
|
2020-09-19 10:21:32 +00:00
|
|
|
|
|
|
|
import { randomChoice } from "../core/utils";
|
2020-05-17 10:12:13 +00:00
|
|
|
import { T } from "../translations";
|
2020-05-09 14:45:23 +00:00
|
|
|
|
|
|
|
export class GameLoadingOverlay {
|
|
|
|
/**
|
|
|
|
*
|
|
|
|
* @param {Application} app
|
|
|
|
* @param {HTMLElement} parent
|
|
|
|
*/
|
|
|
|
constructor(app, parent) {
|
|
|
|
this.app = app;
|
|
|
|
this.parent = parent;
|
|
|
|
|
|
|
|
/** @type {HTMLElement} */
|
|
|
|
this.element = null;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Removes the overlay if its currently visible
|
|
|
|
*/
|
|
|
|
removeIfAttached() {
|
|
|
|
if (this.element) {
|
|
|
|
this.element.remove();
|
|
|
|
this.element = null;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns if the loading overlay is attached
|
|
|
|
*/
|
|
|
|
isAttached() {
|
|
|
|
return this.element;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Shows a super basic overlay
|
|
|
|
*/
|
|
|
|
showBasic() {
|
|
|
|
assert(!this.element, "Loading overlay already visible, cant show again");
|
|
|
|
this.element = document.createElement("div");
|
|
|
|
this.element.classList.add("gameLoadingOverlay");
|
|
|
|
this.parent.appendChild(this.element);
|
|
|
|
this.internalAddSpinnerAndText(this.element);
|
2020-09-19 10:21:32 +00:00
|
|
|
this.internalAddHint(this.element);
|
2022-06-18 12:43:26 +00:00
|
|
|
this.internalAddProgressIndicator(this.element);
|
2020-05-09 14:45:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Adds a text with 'loading' and a spinner
|
|
|
|
* @param {HTMLElement} element
|
|
|
|
*/
|
|
|
|
internalAddSpinnerAndText(element) {
|
|
|
|
const inner = document.createElement("span");
|
|
|
|
inner.classList.add("prefab_LoadingTextWithAnim");
|
|
|
|
element.appendChild(inner);
|
|
|
|
}
|
2020-09-19 10:21:32 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Adds a random hint
|
|
|
|
* @param {HTMLElement} element
|
|
|
|
*/
|
|
|
|
internalAddHint(element) {
|
|
|
|
const hint = document.createElement("span");
|
|
|
|
hint.innerHTML = randomChoice(T.tips);
|
2020-09-19 16:57:14 +00:00
|
|
|
hint.classList.add("prefab_GameHint");
|
2020-09-19 10:21:32 +00:00
|
|
|
element.appendChild(hint);
|
|
|
|
}
|
2022-06-18 12:43:26 +00:00
|
|
|
|
|
|
|
internalAddProgressIndicator(element) {
|
|
|
|
const indicator = document.createElement("span");
|
|
|
|
indicator.innerHTML = "";
|
|
|
|
indicator.classList.add("prefab_LoadingProgressIndicator");
|
|
|
|
element.appendChild(indicator);
|
|
|
|
this.loadingIndicator = indicator;
|
|
|
|
}
|
2020-05-09 14:45:23 +00:00
|
|
|
}
|