适配creator v2版本的widget对pos的影响

This commit is contained in:
xu_yanfeng 2025-01-29 17:32:46 +08:00
parent 89f61e3b05
commit 31c5ccf7c6
2 changed files with 17 additions and 12 deletions

View File

@ -515,22 +515,19 @@ export class Inspector extends InjectEvent {
item.tip = ""; item.tip = "";
return false; return false;
} }
private getDisabled(node: any, key: string | number, v: string, item: Info) { private getDisabled(node: any, key: string, item: Info) {
if (typeof key !== "string") { const cfgArray: Array<{ type: any; keys: Array<{ key: string[]; disabled: () => boolean }> }> = [
return false;
}
const cfgArray: Array<{ type: any; keys: Array<{ key: string; disabled: () => boolean }> }> = [
{ {
type: cc.Node, type: cc.Node,
keys: [ keys: [
{ {
key: "position.x", key: ["position.x", "x"],
disabled: () => { disabled: () => {
return this.isDisabledX(node, item); return this.isDisabledX(node, item);
}, },
}, },
{ {
key: "position.y", key: ["position.y", "y"],
disabled: () => { disabled: () => {
return this.isDisabledY(node, item); return this.isDisabledY(node, item);
}, },
@ -541,7 +538,7 @@ export class Inspector extends InjectEvent {
for (let i = 0; i < cfgArray.length; i++) { for (let i = 0; i < cfgArray.length; i++) {
const { type, keys } = cfgArray[i]; const { type, keys } = cfgArray[i];
if (node instanceof type) { if (node instanceof type) {
const ret = keys.find((item) => item.key === `${key.trim()}.${v.trim()}`); const ret = keys.find((item) => !!item.key.find((el) => el === key));
if (ret) { if (ret) {
return ret.disabled(); return ret.disabled();
} }
@ -608,6 +605,7 @@ export class Inspector extends InjectEvent {
case "number": { case "number": {
const info = new NumberData(propertyValue); const info = new NumberData(propertyValue);
info.step = this.getStep(node, key); info.step = this.getStep(node, key);
info.disabled = this.getDisabled(node, key.toString(), info);
return make(info); return make(info);
} }
case "string": { case "string": {
@ -653,13 +651,13 @@ export class Inspector extends InjectEvent {
{ {
key: "x", key: "x",
disabled: (v: string, item: Info) => { disabled: (v: string, item: Info) => {
return this.getDisabled(node, key, v, item); return this.getDisabled(node, `${key}.${v}`, item);
}, },
}, },
{ {
key: "y", key: "y",
disabled: (v: string, item: Info) => { disabled: (v: string, item: Info) => {
return this.getDisabled(node, key, v, item); return this.getDisabled(node, `${key}.${v}`, item);
}, },
}, },
{ key: "z" }, { key: "z" },
@ -691,13 +689,13 @@ export class Inspector extends InjectEvent {
{ {
key: "x", key: "x",
disabled: (v: string, item: Info) => { disabled: (v: string, item: Info) => {
return this.getDisabled(node, key, v, item); return this.getDisabled(node, `${key}.${v}`, item);
}, },
}, },
{ {
key: "y", key: "y",
disabled: (v: string, item: Info) => { disabled: (v: string, item: Info) => {
return this.getDisabled(node, key, v, item); return this.getDisabled(node, `${key}.${v}`, item);
}, },
}, },
], ],

View File

@ -25,11 +25,13 @@ export class Info {
public data: any; public data: any;
public readonly: boolean = false; public readonly: boolean = false;
public path: Array<string> = []; // 属性对应的路径 public path: Array<string> = []; // 属性对应的路径
public tip: string = "";
constructor(id: string = "") { constructor(id: string = "") {
this.id = id || v4(); this.id = id || v4();
} }
parse(data: Info) { parse(data: Info) {
this.id = data.id; this.id = data.id;
this.tip = data.tip || "";
this.path = data.path; this.path = data.path;
this.readonly = data.readonly; this.readonly = data.readonly;
} }
@ -324,6 +326,10 @@ export class StringData extends Info {
export class NumberData extends Info { export class NumberData extends Info {
public data: number = 0; public data: number = 0;
public step: number = 1; public step: number = 1;
/**
* cc.Widget组件会影响调整xy
*/
public disabled: boolean = false;
constructor(data: number = 0) { constructor(data: number = 0) {
super(); super();
this.type = DataType.Number; this.type = DataType.Number;
@ -333,6 +339,7 @@ export class NumberData extends Info {
super.parse(data); super.parse(data);
this.data = data.data; this.data = data.data;
this.step = data.step || 1; this.step = data.step || 1;
this.disabled = !!data.disabled;
return this; return this;
} }
public isNumber(): boolean { public isNumber(): boolean {