mirror of
https://github.com/tidys/cc-inspector-chrome
synced 2025-04-16 07:01:03 +00:00
优化属性为枚举类型时变为Select选项
This commit is contained in:
parent
31c5ccf7c6
commit
91651243da
@ -1,7 +1,7 @@
|
||||
// eval 注入脚本的代码,变量尽量使用var,后来发现在import之后,let会自动变为var
|
||||
import { uniq } from "lodash";
|
||||
import { Msg, PluginEvent, RequestLogData, RequestNodeInfoData, RequestSetPropertyData, ResponseGameInfoData, ResponseNodeInfoData, ResponseSetPropertyData, ResponseSupportData, ResponseTreeInfoData } from "../../core/types";
|
||||
import { ArrayData, BoolData, ColorData, DataType, EngineData, Group, ImageData, Info, InvalidData, NodeInfoData, NumberData, ObjectCircleData, ObjectData, Property, StringData, TreeData, Vec2Data, Vec3Data, Vec4Data } from "../../views/devtools/data";
|
||||
import { ArrayData, BoolData, ColorData, DataType, EngineData, EnumData, Group, ImageData, Info, InvalidData, NodeInfoData, NumberData, ObjectCircleData, ObjectData, Property, StringData, TreeData, Vec2Data, Vec3Data, Vec4Data } from "../../views/devtools/data";
|
||||
import { InjectEvent } from "./event";
|
||||
import { Hint } from "./hint";
|
||||
import { injectView } from "./inject-view";
|
||||
@ -515,6 +515,31 @@ export class Inspector extends InjectEvent {
|
||||
item.tip = "";
|
||||
return false;
|
||||
}
|
||||
private getEnum(node: any, key: string): Array<{ name: string; value: number }> | null {
|
||||
const cfgArray: Array<{ type: any; list: Array<{ key: string; values: () => Array<{ name: string; value: number }> }> }> = [
|
||||
{
|
||||
type: cc.Widget,
|
||||
list: [
|
||||
{
|
||||
key: "alignMode",
|
||||
values: () => {
|
||||
return cc.Widget.AlignMode.__enums__;
|
||||
},
|
||||
},
|
||||
],
|
||||
},
|
||||
];
|
||||
for (let i = 0; i < cfgArray.length; i++) {
|
||||
const { type, list } = cfgArray[i];
|
||||
if (node instanceof type) {
|
||||
const ret = list.find((item) => item.key === key);
|
||||
if (ret) {
|
||||
return ret.values();
|
||||
}
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
private getDisabled(node: any, key: string, item: Info) {
|
||||
const cfgArray: Array<{ type: any; keys: Array<{ key: string[]; disabled: () => boolean }> }> = [
|
||||
{
|
||||
@ -603,10 +628,17 @@ export class Inspector extends InjectEvent {
|
||||
return make(info);
|
||||
}
|
||||
case "number": {
|
||||
const info = new NumberData(propertyValue);
|
||||
info.step = this.getStep(node, key);
|
||||
info.disabled = this.getDisabled(node, key.toString(), info);
|
||||
return make(info);
|
||||
const enumList = this.getEnum(node, key.toString());
|
||||
if (enumList) {
|
||||
const info = new EnumData(propertyValue);
|
||||
info.values = enumList;
|
||||
return make(info);
|
||||
} else {
|
||||
const info = new NumberData(propertyValue);
|
||||
info.step = this.getStep(node, key);
|
||||
info.disabled = this.getDisabled(node, key.toString(), info);
|
||||
return make(info);
|
||||
}
|
||||
}
|
||||
case "string": {
|
||||
const info = new StringData(propertyValue);
|
||||
|
@ -493,13 +493,16 @@ export class ImageData extends Info {
|
||||
}
|
||||
|
||||
export class EnumData extends Info {
|
||||
public data: string | number = 0;
|
||||
public values: Array<{ name: string; value: any }> = [];
|
||||
constructor() {
|
||||
constructor(data: string | number = 0) {
|
||||
super();
|
||||
this.type = DataType.Enum;
|
||||
this.data = data;
|
||||
}
|
||||
parse(data: EnumData) {
|
||||
super.parse(data);
|
||||
this.data = data.data;
|
||||
for (let i = 0; i < data.values.length; i++) {
|
||||
const item = data.values[i];
|
||||
this.values.push({ name: item.name, value: item.value });
|
||||
|
Loading…
x
Reference in New Issue
Block a user