mirror of
https://github.com/tidys/cc-inspector-chrome
synced 2025-10-22 20:35:24 +00:00
优化属性为枚举类型时变为Select选项
This commit is contained in:
@@ -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);
|
||||
|
Reference in New Issue
Block a user