增加visible的控制

This commit is contained in:
xu_yanfeng 2025-01-06 17:58:33 +08:00
parent 14121c19f0
commit 250155cd35
4 changed files with 55 additions and 8 deletions

View File

@ -13,5 +13,9 @@ export function getSimpleProperties(typeName: string): string[] {
config[CompType.Node2] = ["position", "rotation", "scale", "anchor", "size", "color", "opacity", "skew", "group"];
config[CompType.Label2] = ["string", "horizontalAlign", "verticalAlign", "fontSize", "lineHeight", "overflow", "font", "fontFamily", "ebableBold", "enableItalic", "enableUnderline", "underlineHeight", "cacheMode", "useSystemFont"];
config[CompType.Spirte2] = ["atlas", "spriteFrame", "type", "sizeMode"];
return config[typeName];
return config[typeName] || [];
}
export const VisibleProp = {
Active: "active",
Enabled: "enabled",
};

View File

@ -1,6 +1,6 @@
import { ITreeData } from "@xuyanfeng/cc-ui/types/cc-tree/const";
import { v4 } from "uuid";
import { getSimpleProperties } from "./comp";
import { getSimpleProperties, VisibleProp } from "./comp";
export enum DataType {
Number = "Number",
String = "String",
@ -565,9 +565,18 @@ export class Group {
this.id = id || "";
}
isSimple(name: string): boolean {
if (name === VisibleProp.Active || name === VisibleProp.Enabled) {
return true;
}
const arr = getSimpleProperties(this.name);
const b = arr.find((el) => el === name);
return !!b;
if (arr.length) {
const b = arr.find((el) => el === name);
return !!b;
} else {
// 这个类型,没有追加精简属性的配置,默认都是精简属性
return true;
}
}
parse(data: Group, simple: boolean = false) {
this.id = data.id;

View File

@ -1,5 +1,6 @@
import { v4 } from "uuid";
import { Msg, Page, PluginEvent, RequestNodeInfoData, ResponseNodeInfoData, ResponseSupportData, ResponseTreeInfoData } from "../../../core/types";
import { VisibleProp } from "../comp";
import { ArrayData, BoolData, ColorData, EngineData, EnumData, Group, ImageData, Info, InvalidData, NodeInfoData, NumberData, ObjectData, Property, StringData, TextData, TreeData, Vec2Data, Vec3Data, Vec4Data } from "../data";
export class TestClient {
recv(event: PluginEvent) {}
@ -125,11 +126,19 @@ export class TestServer {
this.testData.buildChild("str2").buildComponent("group6").buildProperty("str2", new StringData("str2"));
this.testData.buildChild("Invalid").buildComponent("group7").buildProperty("NaN", new InvalidData(NaN)).buildProperty("null", new InvalidData(null)).buildProperty("Infinity", new InvalidData(Infinity)).buildProperty("undefined", new InvalidData(undefined));
this.testData
.buildChild("Invalid")
.buildComponent("group7")
.buildProperty("NaN", new InvalidData(NaN)) //
.buildProperty("null", new InvalidData(null))
.buildProperty("Infinity", new InvalidData(Infinity))
.buildProperty(VisibleProp.Active, new BoolData(true))
.buildProperty("undefined", new InvalidData(undefined));
this.testData
.buildChild("comp")
.buildComponent("node-2") //
.buildProperty("rotation", new NumberData(0))
.buildProperty(VisibleProp.Enabled, new BoolData(true))
.buildProperty("max", new NumberData(100));
}
add(client: TestClient) {

View File

@ -1,6 +1,11 @@
<template>
<div class="property-group">
<CCSection :expand="!fold" :name="group.name" :expand-by-full-header="true" :auto-slot-header="true">
<template v-slot:title>
<div v-if="visible" @click.stop="">
<CCCheckBox :value="visible.data" @change="onChangeVisible"> </CCCheckBox>
</div>
</template>
<template v-slot:header>
<div style="flex: 1"></div>
<i style="" @click.stop="onLog" class="print iconfont icon_print"></i>
@ -15,11 +20,12 @@
<script lang="ts">
import ccui from "@xuyanfeng/cc-ui";
import { defineComponent, onMounted, onUnmounted, PropType, ref, toRaw, watch } from "vue";
import { Msg, RequestLogData } from "../../../core/types";
import { Msg, RequestLogData, RequestSetPropertyData } from "../../../core/types";
import { bridge } from "../bridge";
import { Bus, BusMsg } from "../bus";
import { Group } from "../data";
import { BoolData, Group, Info, Property } from "../data";
import UiProp from "./ui-prop.vue";
import { VisibleProp } from "../comp";
const { CCInput, CCSection, CCButton, CCInputNumber, CCSelect, CCCheckBox, CCColor } = ccui.components;
export default defineComponent({
name: "property-group",
@ -43,14 +49,33 @@ export default defineComponent({
Bus.off(BusMsg.FoldAllGroup, funcFoldAllGroup);
});
const fold = ref(false);
const visible = ref<Info | null>(null);
let visibleTarget: Property = null;
watch(
() => props.group,
(v) => {
// console.log(v);
freshVisible();
}
);
function freshVisible() {
visibleTarget = props.group.data.find((el) => {
return el.name === VisibleProp.Enabled || el.name == VisibleProp.Active;
});
if (visibleTarget) {
visible.value = visibleTarget.value;
} else {
visible.value = null;
}
}
freshVisible();
return {
fold,
visible,
onChangeVisible(b: boolean) {
const raw: BoolData = toRaw<Info>(visibleTarget.value) as BoolData;
raw.data = b;
bridge.send(Msg.RequestSetProperty, raw as RequestSetPropertyData);
},
onLog() {
const raw = toRaw(props);
const data = [raw.group.id];