mirror of
https://github.com/tidys/cc-inspector-chrome
synced 2025-04-16 07:01:03 +00:00
优化widget对pos的影响
This commit is contained in:
parent
819fc0602b
commit
89f61e3b05
@ -402,22 +402,32 @@ export class Inspector extends InjectEvent {
|
||||
|
||||
_buildVecData(options: BuildVecOptions) {
|
||||
const ctor: Function = options.ctor;
|
||||
const keys: Array<string> = options.keys;
|
||||
const keys = options.keys;
|
||||
const value: Object = options.value;
|
||||
const data: Vec3Data | Vec2Data = options.data;
|
||||
const path: Array<string> = options.path;
|
||||
|
||||
if (ctor && value instanceof ctor) {
|
||||
let hasUnOwnProperty = keys.find((key) => !value.hasOwnProperty(key));
|
||||
let hasUnOwnProperty = keys.find((item) => !value.hasOwnProperty(item.key));
|
||||
if (!hasUnOwnProperty) {
|
||||
for (let key in keys) {
|
||||
let propName = keys[key];
|
||||
const propName = keys[key].key;
|
||||
const stepFunc = keys[key].step;
|
||||
const disabledFunc = keys[key].disabled;
|
||||
|
||||
if (value.hasOwnProperty(propName)) {
|
||||
let propPath = path.concat(propName);
|
||||
let itemData = this._genInfoData(value, propName, propPath);
|
||||
if (itemData) {
|
||||
if (itemData instanceof NumberData && options.step !== undefined) {
|
||||
if (itemData instanceof NumberData) {
|
||||
if (stepFunc) {
|
||||
itemData.step = stepFunc(propName);
|
||||
} else if (options.step) {
|
||||
itemData.step = options.step;
|
||||
} else {
|
||||
itemData.step = 1;
|
||||
}
|
||||
itemData.disabled = disabledFunc ? disabledFunc(propName, itemData) : false;
|
||||
}
|
||||
data.add(new Property(propName, itemData));
|
||||
}
|
||||
@ -475,6 +485,70 @@ export class Inspector extends InjectEvent {
|
||||
}
|
||||
}
|
||||
}
|
||||
private isDisabledX(node: any, item: Info) {
|
||||
const widget = node.getComponent(cc.Widget);
|
||||
if (widget && widget.enabled) {
|
||||
if (widget.isAlignLeft) {
|
||||
item.tip = "widget.isAlignLeft";
|
||||
return true;
|
||||
}
|
||||
if (widget.isAlignRight) {
|
||||
item.tip = "widget.isAlignRight";
|
||||
return true;
|
||||
}
|
||||
}
|
||||
item.tip = "";
|
||||
return false;
|
||||
}
|
||||
private isDisabledY(node: any, item: Info) {
|
||||
const widget = node.getComponent(cc.Widget);
|
||||
if (widget && widget.enabled) {
|
||||
if (widget.isAlignTop) {
|
||||
item.tip = "widget.isAlignTop";
|
||||
return true;
|
||||
}
|
||||
if (widget.isAlignBottom) {
|
||||
item.tip = "widget.isAlignBottom";
|
||||
return true;
|
||||
}
|
||||
}
|
||||
item.tip = "";
|
||||
return false;
|
||||
}
|
||||
private getDisabled(node: any, key: string | number, v: string, item: Info) {
|
||||
if (typeof key !== "string") {
|
||||
return false;
|
||||
}
|
||||
const cfgArray: Array<{ type: any; keys: Array<{ key: string; disabled: () => boolean }> }> = [
|
||||
{
|
||||
type: cc.Node,
|
||||
keys: [
|
||||
{
|
||||
key: "position.x",
|
||||
disabled: () => {
|
||||
return this.isDisabledX(node, item);
|
||||
},
|
||||
},
|
||||
{
|
||||
key: "position.y",
|
||||
disabled: () => {
|
||||
return this.isDisabledY(node, item);
|
||||
},
|
||||
},
|
||||
],
|
||||
},
|
||||
];
|
||||
for (let i = 0; i < cfgArray.length; i++) {
|
||||
const { type, keys } = cfgArray[i];
|
||||
if (node instanceof type) {
|
||||
const ret = keys.find((item) => item.key === `${key.trim()}.${v.trim()}`);
|
||||
if (ret) {
|
||||
return ret.disabled();
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
private getStep(node: any, key: string | number) {
|
||||
if (typeof key !== "string") {
|
||||
return 1;
|
||||
@ -564,7 +638,7 @@ export class Inspector extends InjectEvent {
|
||||
ctor: cc.Size,
|
||||
path: path,
|
||||
data: new Vec2Data(),
|
||||
keys: ["width", "height"],
|
||||
keys: [{ key: "width" }, { key: "height" }],
|
||||
value: propertyValue,
|
||||
});
|
||||
if (info) {
|
||||
@ -575,7 +649,21 @@ export class Inspector extends InjectEvent {
|
||||
ctor: cc.Vec3,
|
||||
path: path,
|
||||
data: new Vec3Data(),
|
||||
keys: ["x", "y", "z"],
|
||||
keys: [
|
||||
{
|
||||
key: "x",
|
||||
disabled: (v: string, item: Info) => {
|
||||
return this.getDisabled(node, key, v, item);
|
||||
},
|
||||
},
|
||||
{
|
||||
key: "y",
|
||||
disabled: (v: string, item: Info) => {
|
||||
return this.getDisabled(node, key, v, item);
|
||||
},
|
||||
},
|
||||
{ key: "z" },
|
||||
],
|
||||
step: this.getStep(node, key),
|
||||
value: propertyValue,
|
||||
});
|
||||
@ -587,7 +675,7 @@ export class Inspector extends InjectEvent {
|
||||
ctor: cc.Quat,
|
||||
path: path,
|
||||
data: new Vec4Data(),
|
||||
keys: ["x", "y", "z", "w"],
|
||||
keys: [{ key: "x" }, { key: "y" }, { key: "z" }, { key: "w" }],
|
||||
value: propertyValue,
|
||||
});
|
||||
if (info) {
|
||||
@ -599,7 +687,20 @@ export class Inspector extends InjectEvent {
|
||||
path: path,
|
||||
data: new Vec2Data(),
|
||||
step: this.getStep(node, key),
|
||||
keys: ["x", "y"],
|
||||
keys: [
|
||||
{
|
||||
key: "x",
|
||||
disabled: (v: string, item: Info) => {
|
||||
return this.getDisabled(node, key, v, item);
|
||||
},
|
||||
},
|
||||
{
|
||||
key: "y",
|
||||
disabled: (v: string, item: Info) => {
|
||||
return this.getDisabled(node, key, v, item);
|
||||
},
|
||||
},
|
||||
],
|
||||
value: propertyValue,
|
||||
});
|
||||
if (info) {
|
||||
|
@ -1,4 +1,4 @@
|
||||
import { ArrayData, ImageData, ObjectData, Vec2Data, Vec3Data } from "../../views/devtools/data";
|
||||
import { ArrayData, ImageData, Info, ObjectData, Vec2Data, Vec3Data } from "../../views/devtools/data";
|
||||
|
||||
export interface BuildObjectOptions {
|
||||
path: string[];
|
||||
@ -15,7 +15,20 @@ export interface BuildArrayOptions {
|
||||
|
||||
export interface BuildVecOptions {
|
||||
path: string[];
|
||||
keys: string[];
|
||||
keys: Array<{
|
||||
key: string;
|
||||
/**
|
||||
* 分量使用的步进值,优先使用,主要是为了实现不同分量不同的步进
|
||||
*/
|
||||
step?: (key: string) => number;
|
||||
/**
|
||||
* 分量是否可以调整
|
||||
*/
|
||||
disabled?: (key: string, item: Info) => boolean;
|
||||
}>;
|
||||
/**
|
||||
* 所有的vec统一使用的步进值
|
||||
*/
|
||||
step?: number;
|
||||
ctor: Function;
|
||||
value: Object;
|
||||
|
@ -7,7 +7,7 @@
|
||||
</div>
|
||||
<CCInput v-if="value.isString()" v-model:value="value.data" :disabled="value.readonly" @change="onChangeValue"> </CCInput>
|
||||
<CCTextarea v-if="value.isText()" v-model:value="value.data" :disabled="value.readonly" @change="onChangeValue"> </CCTextarea>
|
||||
<CCInputNumber v-if="value.isNumber()" v-model:value="value.data" :step="getStep()" :disabled="value.readonly" @change="onChangeValue"></CCInputNumber>
|
||||
<CCInputNumber v-if="value.isNumber()" v-model:value="value.data" :step="getStep()" :readonly="value.readonly" :disabled="getDisabled()" @change="onChangeValue" :tip="value.tip"></CCInputNumber>
|
||||
<div v-if="value.isVec2() || value.isVec3() || value.isVec4()" class="vec">
|
||||
<UiProp v-for="(vec, index) in value.data" :icon="!!index" head-width="auto" :key="index" :arrow="false" :value="vec.value" :name="vec.name"> </UiProp>
|
||||
</div>
|
||||
@ -145,6 +145,13 @@ export default defineComponent({
|
||||
return 1;
|
||||
}
|
||||
},
|
||||
getDisabled() {
|
||||
if (props.value instanceof NumberData) {
|
||||
return props.value.disabled;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
},
|
||||
};
|
||||
},
|
||||
});
|
||||
|
Loading…
x
Reference in New Issue
Block a user