avoid text overlapping

This commit is contained in:
2026-04-15 21:34:28 +03:00
parent be360a51b8
commit bb2af28b48
3 changed files with 66 additions and 53 deletions
@@ -31,9 +31,9 @@ class GenericObject extends EventManager{
if (!data.exclude && (data.hud || data.description)){
engine.clickable.add(this.object, async e=>{
this.object.__onhud = !this.object.__onhud;
if (engine.dashboard){
if (data.hud){
this.object.__onhud = !this.object.__onhud;
const filterNoHud = a=>a.getClip().name.match(/\.nohud/)
if (this.object._hud ){
this.#actions.filter(filterNoHud).forEach(a=>a.play());
@@ -59,10 +59,11 @@ class GenericObject extends EventManager{
}
}
if (data.description){
engine.dashboard.updateText(this.object.__onhud ? data.description : '', {
engine.dashboard.updateText((!data.hud || this.object.__onhud) ? data.description : '', {
textScrolledCallback: (d)=>{
d && this.dispatchEvent({type:'finish'})
}
},
hideOnFinish: true
})
}
}
+44 -48
View File
@@ -11,6 +11,7 @@ import { TextObject } from "@/components/InteractiveObjects/TextObject/TextObjec
class DashBoard extends EventManager {
#points = 0;
#attached = null;
#textTimeout = { onKill: 'reject' };
constructor(engine) {
super();
let levelProgress;
@@ -138,60 +139,55 @@ class DashBoard extends EventManager {
sceneHeader.init(scene, startBtnCallback);
}
this.updateText = function(t, params = {}){
this.updateText = async function(t, params = {}){
if (!textPlane) return;
await Utils.killWait(this.#textTimeout);
textPlane.visible = !!t;
engine.motionQueue.clear(text);
text.text = t;
text.anchorY = 0.03 * dashHeight;
text.sync(async()=>{
//console.log(text.clipRect);
let dMax = text.textRenderInfo.blockBounds[3] - text.textRenderInfo.blockBounds[1];
let dh = dMax + text.clipRect[1];
if (params.startFrom){
text.anchorY = text.anchorY + (-dh -text.anchorY) * params.startFrom;
}
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({
o: text,
a: { anchorY: -dh },
t: params.duration ? (params.duration * (1-params.startFrom||0)) : (dMax*77 / dashHeight),
f: async ()=>{
params.textScrolledCallback?.(true);
params.textScrolledCallback = null;
if (params.hideOnFinish){
await Utils.wait(5000);
this.updateText('')
}else{
engine.motionQueue.add({
o: text,
a: { anchorY: -dMax },
t: 4,
f: params.textFinishCallback
})
}
}
})
}else{
if (params.hideOnFinish){
await Utils.wait(10000);
if (text.text == t) this.updateText('')
params.textScrolledCallback?.(false)
}else{
params.textScrolledCallback?.(false)
return new Promise((resolve, reject)=>{
text.sync(async()=>{
//console.log(text.clipRect);
let dMax = text.textRenderInfo.blockBounds[3] - text.textRenderInfo.blockBounds[1];
let dh = dMax + text.clipRect[1];
if (params.startFrom){
text.anchorY = text.anchorY + (-dh -text.anchorY) * params.startFrom;
}
}
if (dh > 0){
engine.motionQueue.add({
o: text,
a: { anchorY: -dh },
t: params.duration ? (params.duration * (1-params.startFrom||0)) : (dMax*77 / dashHeight),
f: async ()=>{
params.textScrolledCallback?.(true);
params.textScrolledCallback = null;
if (params.hideOnFinish){
Utils.wait(5000, this.#textTimeout).then(_=>{
this.updateText('')
}).catch(_=>{})
}else{
engine.motionQueue.add({
o: text,
a: { anchorY: -dMax },
t: 4,
f: params.textFinishCallback
})
}
}
})
}else{
if (params.hideOnFinish){
Utils.wait(10000, this.#textTimeout).then(_=>{
this.updateText('')
params.textScrolledCallback?.(false)
}).catch(_=>{});
}else{
params.textScrolledCallback?.(false)
}
}
resolve();
})
})
}