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

Fix the issue of update the wrapMode after changing the image type #16315

Merged
merged 3 commits into from
Oct 12, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
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
30 changes: 13 additions & 17 deletions editor/inspector/assets/image.js
Original file line number Diff line number Diff line change
Expand Up @@ -327,26 +327,22 @@ exports.methods = {
// any -> sprite : texture.wrapMode -> Clamp
if (['sprite-frame', 'texture'].includes(this.meta.userData.type)) {
const textureKey = Editor.Utils.UUID.nameToSubId('texture');
let wrapModeCache;
if (this.meta.subMetas[textureKey]) {
const textureUUID = this.meta.subMetas[textureKey].uuid;
wrapModeCache = await Editor.Profile.getConfig('inspector', `${textureUUID}.texture.wrapMode`);
}
if (!wrapModeCache) {
// use default wrapMode if not changed
const wrapModeName = this.meta.userData.type === 'texture' ? 'Repeat' : 'Clamp';
this.metaList.forEach((meta) => {
const data = ModeMap.wrap[wrapModeName];
if (!meta.subMetas[textureKey]) {
meta.subMetas[textureKey] = {
userData: {}
}
}
// use default wrapMode if not changed
const wrapModeName = this.meta.userData.type === 'texture' ? 'Repeat' : 'Clamp';
this.metaList.forEach(async (meta) => {
const data = ModeMap.wrap[wrapModeName];
if (!meta.subMetas[textureKey]) {
meta.subMetas[textureKey] = {
userData: {},
};
}
let wrapModeCache = await Editor.Profile.getConfig('inspector', `${meta.uuid}@${textureKey}.texture.wrapMode`, 'default');
nianba23 marked this conversation as resolved.
Show resolved Hide resolved
if (!wrapModeCache) {
for (const key of Object.keys(data)) {
meta.subMetas[textureKey].userData[key] = data[key];
}
});
}
}
});
}
if (this.originImageType === 'sprite-frame' || this.meta.userData.type === 'sprite-frame') {
const changeTypes = ['texture', 'normal map', 'texture cube', 'sprite-frame'];
Expand Down
29 changes: 15 additions & 14 deletions editor/inspector/assets/texture/texture.js
Original file line number Diff line number Diff line change
Expand Up @@ -335,15 +335,15 @@ const Elements = {
panel.userDataList.forEach((userData) => {
const value = event.target.value;
if (!value) {
// 没勾选 生成 mipmaps,不显示 mipfilter 选项
// Generate mipmaps is unchecked, and the mipfilter option is not displayed
userData.mipfilter = 'none';
panel.$.generateMipmapsSection.style.display = 'none';
} else {
panel.$.generateMipmapsSection.style.display = 'block';
// 为空的话默认 nearest
// Defaults to nearest if empty
if (panel.$.mipfilterSelect.value === 'none') {
panel.$.mipfilterSelect.value = 'nearest';
// TODO: 目前 ui-select 通过 .value 修改组件值后没有触发 change 事件,需要手动提交
// TODO: Currently, ui-select does not trigger the change event after modifying the component value via .value, so you need to submit it manually
panel.$.mipfilterSelect.dispatch('change');
}
}
Expand All @@ -360,7 +360,7 @@ const Elements = {

panel.$.generateMipmapsCheckbox.value = panel.userData.mipfilter ? panel.userData.mipfilter !== 'none' : false;

// 更新时判断是否显示 mipfilter 选项
// Determine whether to display the mipfilter option on update
panel.$.generateMipmapsCheckbox.value
? (panel.$.generateMipmapsSection.style.display = 'block')
: (panel.$.generateMipmapsSection.style.display = 'none');
Expand Down Expand Up @@ -396,7 +396,7 @@ const Elements = {

panel.$.mipfilterSelect.value = panel.userData.mipfilter || 'nearest';

// 临时记录 mipfilter 配置
// temporary logging of mipfilter
panel.metaList && panel.metaList.forEach((meta) => {
Editor.Profile.setConfig('inspector', `${meta.uuid}.texture.mipfilter`, panel.userData.mipfilter, 'default');
});
Expand All @@ -410,10 +410,12 @@ const Elements = {
const panel = this;

panel.$.wrapModeSelect.addEventListener('change', (event) => {
// 根据 wrapModeSelect 组合值同步相应的 wrapModeS/wrapModeT userData
// Synchronize the corresponding wrapModeS/wrapModeT to userData based on the wrapModeSelect combination
const value = event.target.value;
// 临时记录用户的修改配置
Editor.Profile.setConfig('inspector', `${this.meta.uuid}.texture.wrapMode`, value, 'default');
// temporary logging of wrapMode
this.metaList && this.metaList.forEach((meta) => {
Editor.Profile.setConfig('inspector', `${meta.uuid}.texture.wrapMode`, value, 'default');
Copy link
Contributor

Choose a reason for hiding this comment

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

Is this data for the interface temporary? Would it be better to put it in 'Temp'?
这个数据是界面用的临时数据吧?放到 Temp 会不会更好?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Temporary data is stored in the 'default' and is only valid for the current session. It won't be remembered next time. So, there is no need to store it in 'temp' for long-term recording.

});
if (ModeMap.wrap[value]) {
panel.userDataList.forEach((userData) => {
const data = ModeMap.wrap[value];
Expand All @@ -423,10 +425,10 @@ const Elements = {
});
panel.$.wrapAdvancedSection.style.display = 'none';
} else {
// 选择 advanced 显示自定义项
// Select advanced to display customized items
panel.$.wrapAdvancedSection.style.display = 'block';
}
// 校验是否显示警告提示
// Calibrate whether to display a warning
Elements.warnWords.update.call(panel);
panel.dispatch('change');
});
Expand All @@ -439,14 +441,13 @@ const Elements = {
const panel = this;

let optionsHtml = '';
// WrapMode 选项
const types = Object.keys(ModeMap.wrap).concat('Advanced');
types.forEach((type) => {
optionsHtml += `<option value="${type}">${type}</option>`;
});
panel.$.wrapModeSelect.innerHTML = optionsHtml;

// 匹配 wrapModeSelect 值,没有匹配到组合,则为自定义 Advanced
// Match wrapModeSelect value, no combination matched, then custom Advanced
let value = 'Advanced';
for (const wrapKey of Object.keys(ModeMap.wrap)) {
const wrapItem = ModeMap.wrap[wrapKey];
Expand All @@ -464,12 +465,12 @@ const Elements = {
}
panel.$.wrapModeSelect.value = value;

// 更新时需要判断是否显示自定义项
// Determine whether to display customized items when updating
value === 'Advanced'
? (panel.$.wrapAdvancedSection.style.display = 'block')
: (panel.$.wrapAdvancedSection.style.display = 'none');

// 校验是否显示警告提示
// Calibrate whether to display a warning
panel.updateInvalid(panel.$.wrapModeSelect, 'wrapMode');
updateElementReadonly.call(panel, panel.$.wrapModeSelect);
},
Expand Down
Loading