Skip to content

Commit

Permalink
Fix the issue of update the wrapMode after changing the image type (#…
Browse files Browse the repository at this point in the history
…16315)

* Fix the issue of udate the wrapMode after changing the image type

* update review
  • Loading branch information
nianba23 authored Oct 12, 2023
1 parent 9df8de8 commit b9c56dd
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 31 deletions.
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');
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');
});
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

0 comments on commit b9c56dd

Please sign in to comment.