Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

improve spine preview #17989

Merged
merged 2 commits into from
Dec 2, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions editor/i18n/en/assets.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,11 @@ module.exports = {
animation: 'Animation',
loop: 'Loop',
timeScale: 'Rate',
premultipliedAlpha: 'Premultiplied Alpha',
useTint: 'Use Tint',
debugSlots: 'Debug Slots',
debugBones: 'Debug Bones',
debugMesh: 'Debug Mesh',
},
},

Expand Down
5 changes: 5 additions & 0 deletions editor/i18n/zh/assets.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,11 @@ module.exports = {
animation: '动画',
loop: '循环',
timeScale: '速率',
premultipliedAlpha: 'Premultiplied Alpha',
useTint: 'Use Tint',
debugSlots: 'Debug Slots',
debugBones: 'Debug Bones',
debugMesh: 'Debug Mesh',
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why these are english, and the above, such as loop is Chinese?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These are more intuitive in English, or we can temporarily use all English for now and replace them with Chinese property names later.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we should do it properly currently.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

},
},

Expand Down
94 changes: 74 additions & 20 deletions editor/inspector/assets/spine-preview.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,32 @@ exports.template = /* html */`
</ui-prop>
<ui-prop class="loop">
<ui-label slot="label" value="i18n:ENGINE.inspector.spine.loop"></ui-label>
<ui-checkbox slot="content" class="loop-check-box"></ui-checkbox>
<ui-checkbox slot="content" class="loop-checkbox"></ui-checkbox>
</ui-prop>
<ui-prop class="timeScale">
<ui-label slot="label" value="i18n:ENGINE.inspector.spine.timeScale"></ui-label>
<ui-slider slot="content" class="time-scale-slider" value="1"></ui-slider>
</ui-prop>
<ui-prop class="premultipliedAlpha">
<ui-label slot="label" value="i18n:ENGINE.inspector.spine.premultipliedAlpha"></ui-label>
<ui-checkbox slot="content" class="premultiplied-alpha-checkbox"></ui-checkbox>
</ui-prop>
<ui-prop class="useTint">
<ui-label slot="label" value="i18n:ENGINE.inspector.spine.useTint"></ui-label>
<ui-checkbox slot="content" class="use-tint-checkbox"></ui-checkbox>
</ui-prop>
<ui-prop class="debugSlots">
<ui-label slot="label" value="i18n:ENGINE.inspector.spine.debugSlots"></ui-label>
<ui-checkbox slot="content" class="debug-slots-checkbox"></ui-checkbox>
</ui-prop>
<ui-prop class="debugBones">
<ui-label slot="label" value="i18n:ENGINE.inspector.spine.debugBones"></ui-label>
<ui-checkbox slot="content" class="debug-bones-checkbox"></ui-checkbox>
</ui-prop>
<ui-prop class="debugMesh">
<ui-label slot="label" value="i18n:ENGINE.inspector.spine.debugMesh"></ui-label>
<ui-checkbox slot="content" class="debug-mesh-checkbox"></ui-checkbox>
</ui-prop>
</div>
<div class="image">
<canvas class="canvas"></canvas>
Expand Down Expand Up @@ -103,11 +123,38 @@ exports.$ = {
pause: '.pause',
stop: '.stop',
duration: '.duration',
loop: '.loop-check-box',
loop: '.loop-checkbox',
useTint: '.use-tint-checkbox',
timeScale: '.time-scale-slider',
debugSlots: '.debug-slots-checkbox',
debugBones: '.debug-bones-checkbox',
premultipliedAlpha: '.premultiplied-alpha-checkbox',
debugMesh: '.debug-mesh-checkbox',
animationCtrl: '.anim-control',
};

const CheckBox = [
'loop',
'useTint',
'debugSlots',
'debugBones',
'debugMesh',
'premultipliedAlpha',
];

const Slider = [
'timeScale',
];

const Other = [
'play',
'stop',
'skinSelectPro',
'animationSelectPro',
];

const Properties = CheckBox.concat(Slider).concat(Other);

async function callFunction(funcName, ...args) {
return await Editor.Message.request('scene', 'call-preview-function', 'scene:spine-preview', funcName, ...args);
}
Expand Down Expand Up @@ -195,6 +242,7 @@ const Elements = {
const panel = this;

callFunction('stop');
callFunction('close');
panel.resizeObserver.unobserve(panel.$.image);
},
},
Expand Down Expand Up @@ -232,21 +280,15 @@ const Elements = {
const panel = this;

if (!info) {
panel.$.loop.setAttribute('disabled', '');
panel.$.timeScale.setAttribute('disabled', '');
panel.$.play.setAttribute('disabled', '');
panel.$.stop.setAttribute('disabled', '');
panel.$.skinSelectPro.setAttribute('disabled', '');
panel.$.animationSelectPro.setAttribute('disabled', '');
Properties.forEach(property => {
panel.$[property].setAttribute('disabled', '');
});
return;
}

panel.$.loop.removeAttribute('disabled');
panel.$.timeScale.removeAttribute('disabled');
panel.$.play.removeAttribute('disabled');
panel.$.stop.removeAttribute('disabled');
panel.$.skinSelectPro.removeAttribute('disabled');
panel.$.animationSelectPro.removeAttribute('disabled');
Properties.forEach(property => {
panel.$[property].removeAttribute('disabled');
});

Elements.spine.updateEnum.call(panel, panel.$.skinSelectPro, info.skin);
Elements.spine.updateEnum.call(panel, panel.$.animationSelectPro, info.animation);
Expand All @@ -265,12 +307,20 @@ const Elements = {
ready() {
const panel = this;

panel.$.timeScale.addEventListener('change', (event) => {
callFunction('setTimeScale', Number(event.target.value));
Slider.forEach((key) => {
panel.$[key].addEventListener('change', (event) => {
callFunction('setProperties', key, Number(event.target.value));
});
});
panel.$.loop.addEventListener('confirm', (event) => {
callFunction('setLoop', Boolean(event.target.value));

CheckBox.forEach((key) => {
panel.$[key].addEventListener('confirm', (event) => {
callFunction('setProperties', key, Boolean(event.target.value)).then((() => {
this.isPreviewDataDirty = true;
}));
});
});

panel.$.play.addEventListener('click', () => {
callFunction('play', panel.animationIndex);
});
Expand All @@ -284,8 +334,12 @@ const Elements = {
updateInfo(info) {
const panel = this;

panel.$.loop.setAttribute('value', Boolean(info.loop));
panel.$.timeScale.setAttribute('value', Number(info.timeScale));
CheckBox.forEach((key) => {
panel.$[key].setAttribute('value', Boolean(info[key]));
});
Slider.forEach((key) => {
panel.$[key].setAttribute('value', Number(info[key]));
});
},
update(playing) {
const panel = this;
Expand Down
Loading