avoid text overlapping
This commit is contained in:
+18
-2
@@ -94,12 +94,28 @@ const Utils = {
|
|||||||
})
|
})
|
||||||
},
|
},
|
||||||
|
|
||||||
async wait(ms){
|
async wait(ms, opts = {}){
|
||||||
await new Promise((resolve, reject)=>{
|
await new Promise((resolve, reject)=>{
|
||||||
setTimeout(resolve, ms)
|
opts.id = setTimeout(resolve, ms)
|
||||||
|
opts.resolve = resolve;
|
||||||
|
opts.reject = reject;
|
||||||
})
|
})
|
||||||
},
|
},
|
||||||
|
|
||||||
|
async killWait(opts){
|
||||||
|
if (opts.id){
|
||||||
|
clearTimeout(opts.id);
|
||||||
|
if (opts.onKill == 'resolve') {
|
||||||
|
await opts.resolve()
|
||||||
|
}else {
|
||||||
|
await opts.reject()
|
||||||
|
}
|
||||||
|
delete opts.id;
|
||||||
|
delete opts.resolve;
|
||||||
|
delete opts.reject;
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
async waitFor(expFn){
|
async waitFor(expFn){
|
||||||
while (!expFn()){
|
while (!expFn()){
|
||||||
await Utils.wait(200);
|
await Utils.wait(200);
|
||||||
|
|||||||
@@ -31,9 +31,9 @@ class GenericObject extends EventManager{
|
|||||||
|
|
||||||
if (!data.exclude && (data.hud || data.description)){
|
if (!data.exclude && (data.hud || data.description)){
|
||||||
engine.clickable.add(this.object, async e=>{
|
engine.clickable.add(this.object, async e=>{
|
||||||
this.object.__onhud = !this.object.__onhud;
|
|
||||||
if (engine.dashboard){
|
if (engine.dashboard){
|
||||||
if (data.hud){
|
if (data.hud){
|
||||||
|
this.object.__onhud = !this.object.__onhud;
|
||||||
const filterNoHud = a=>a.getClip().name.match(/\.nohud/)
|
const filterNoHud = a=>a.getClip().name.match(/\.nohud/)
|
||||||
if (this.object._hud ){
|
if (this.object._hud ){
|
||||||
this.#actions.filter(filterNoHud).forEach(a=>a.play());
|
this.#actions.filter(filterNoHud).forEach(a=>a.play());
|
||||||
@@ -59,10 +59,11 @@ class GenericObject extends EventManager{
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (data.description){
|
if (data.description){
|
||||||
engine.dashboard.updateText(this.object.__onhud ? data.description : '', {
|
engine.dashboard.updateText((!data.hud || this.object.__onhud) ? data.description : '', {
|
||||||
textScrolledCallback: (d)=>{
|
textScrolledCallback: (d)=>{
|
||||||
d && this.dispatchEvent({type:'finish'})
|
d && this.dispatchEvent({type:'finish'})
|
||||||
}
|
},
|
||||||
|
hideOnFinish: true
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+11
-15
@@ -11,6 +11,7 @@ import { TextObject } from "@/components/InteractiveObjects/TextObject/TextObjec
|
|||||||
class DashBoard extends EventManager {
|
class DashBoard extends EventManager {
|
||||||
#points = 0;
|
#points = 0;
|
||||||
#attached = null;
|
#attached = null;
|
||||||
|
#textTimeout = { onKill: 'reject' };
|
||||||
constructor(engine) {
|
constructor(engine) {
|
||||||
super();
|
super();
|
||||||
let levelProgress;
|
let levelProgress;
|
||||||
@@ -138,12 +139,14 @@ class DashBoard extends EventManager {
|
|||||||
sceneHeader.init(scene, startBtnCallback);
|
sceneHeader.init(scene, startBtnCallback);
|
||||||
}
|
}
|
||||||
|
|
||||||
this.updateText = function(t, params = {}){
|
this.updateText = async function(t, params = {}){
|
||||||
if (!textPlane) return;
|
if (!textPlane) return;
|
||||||
|
await Utils.killWait(this.#textTimeout);
|
||||||
textPlane.visible = !!t;
|
textPlane.visible = !!t;
|
||||||
engine.motionQueue.clear(text);
|
engine.motionQueue.clear(text);
|
||||||
text.text = t;
|
text.text = t;
|
||||||
text.anchorY = 0.03 * dashHeight;
|
text.anchorY = 0.03 * dashHeight;
|
||||||
|
return new Promise((resolve, reject)=>{
|
||||||
text.sync(async()=>{
|
text.sync(async()=>{
|
||||||
//console.log(text.clipRect);
|
//console.log(text.clipRect);
|
||||||
let dMax = text.textRenderInfo.blockBounds[3] - text.textRenderInfo.blockBounds[1];
|
let dMax = text.textRenderInfo.blockBounds[3] - text.textRenderInfo.blockBounds[1];
|
||||||
@@ -152,17 +155,6 @@ class DashBoard extends EventManager {
|
|||||||
text.anchorY = text.anchorY + (-dh -text.anchorY) * params.startFrom;
|
text.anchorY = text.anchorY + (-dh -text.anchorY) * params.startFrom;
|
||||||
}
|
}
|
||||||
if (dh > 0){
|
if (dh > 0){
|
||||||
// let updateFn = ()=>{
|
|
||||||
// //text.sync();
|
|
||||||
// //console.log(text.clipRect, text.textRenderInfo.blockBounds)
|
|
||||||
// if (text.textRenderInfo.blockBounds[1] > text.clipRect[1] ){
|
|
||||||
// params.textScrolledCallback?.(true);
|
|
||||||
// params.textScrolledCallback = null;
|
|
||||||
// if (params.hideOnFinish){
|
|
||||||
// this.updateText('')
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
engine.motionQueue.add({
|
engine.motionQueue.add({
|
||||||
o: text,
|
o: text,
|
||||||
a: { anchorY: -dh },
|
a: { anchorY: -dh },
|
||||||
@@ -171,8 +163,9 @@ class DashBoard extends EventManager {
|
|||||||
params.textScrolledCallback?.(true);
|
params.textScrolledCallback?.(true);
|
||||||
params.textScrolledCallback = null;
|
params.textScrolledCallback = null;
|
||||||
if (params.hideOnFinish){
|
if (params.hideOnFinish){
|
||||||
await Utils.wait(5000);
|
Utils.wait(5000, this.#textTimeout).then(_=>{
|
||||||
this.updateText('')
|
this.updateText('')
|
||||||
|
}).catch(_=>{})
|
||||||
}else{
|
}else{
|
||||||
engine.motionQueue.add({
|
engine.motionQueue.add({
|
||||||
o: text,
|
o: text,
|
||||||
@@ -185,13 +178,16 @@ class DashBoard extends EventManager {
|
|||||||
})
|
})
|
||||||
}else{
|
}else{
|
||||||
if (params.hideOnFinish){
|
if (params.hideOnFinish){
|
||||||
await Utils.wait(10000);
|
Utils.wait(10000, this.#textTimeout).then(_=>{
|
||||||
if (text.text == t) this.updateText('')
|
this.updateText('')
|
||||||
params.textScrolledCallback?.(false)
|
params.textScrolledCallback?.(false)
|
||||||
|
}).catch(_=>{});
|
||||||
}else{
|
}else{
|
||||||
params.textScrolledCallback?.(false)
|
params.textScrolledCallback?.(false)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
resolve();
|
||||||
|
})
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user