123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744 |
- import { _decorator, assetManager, Color, Component, Director, director, EventTouch, ImageAsset, instantiate, Label, math, Node, NodePool, Prefab, Size, Sprite, SpriteFrame, Texture2D, Toggle, Tween, tween, UITransform, Vec2, Vec3 } from 'cc';
- import { att_click_data, att_container, att_count_down, att_drag_data, att_question_select, att_slide_data, att_text_sound_data, att_top_data, attributes_data, widget_item_data } from '../../data/data';
- import { ClientEvent } from '../clientEvent';
- import { config } from '../config';
- import { scroll_scene } from './scroll_scene';
- import { slide } from './slide';
- import { ui_top } from './uiWidget/ui_top';
- import { tools } from '../tools';
- import { Text_Sound } from './uiWidget/Text_Sound';
- import { question_select } from './uiWidget/question_select';
- import { count_down } from './uiWidget/count_down';
- const { ccclass, property } = _decorator;
- @ccclass('widget_item')
- export class widget_item extends Component {
- @property(Node) lab_name:Node = null;
- @property(Node) spr:Node = null;
- @property(Node) slide:Node = null;
- @property(Node) drag:Node = null;
- @property(Node) lab_drag:Node = null;
- @property(Node) img_select:Node = null;
- @property(Prefab) ui_prefab:Prefab = null;
- @property(Prefab) text_sound_pf:Prefab = null;
- @property(Prefab) count_down_pf:Prefab = null;
- @property(Prefab) question_select_pf:Prefab = null;
- @property(Prefab) self_pf:Prefab = null;
- @property(Node) toggle_active:Node = null;
- @property(Node) toggle_check:Node = null;
- @property(Node) other_drag_content:Node = null;
- @property(Node) lab_remark:Node = null;
- @property(Node) btn_look_voice_text:Node = null;
- @property(Node) btn_delete:Node = null;
- @property(Node) container:Node = null;
- private m_data:widget_item_data = null;
- private m_att:attributes_data = null;
- private isMove:boolean = false;
- private call_back = null;
- private m_ui_widget:Node = null;
- private m_text_sound:Node = null;
- private m_question_select:Node = null;
- private m_count_down:Node = null;
- private x_len:number = 0;
- private y_len:number = 0;
- private m_isShowDragOtherList:boolean = false;
- private m_isShowContainerChilden:boolean = true;
- private m_delete_cb = null;
- protected start(): void {
- this.btn_delete.on(Node.EventType.TOUCH_END, ()=>{
- this.m_delete_cb && this.m_delete_cb(this)
- })
- }
- public showPageNumberName() {
- // console.log('showPageNumberName lab_name=',this.lab_name.getComponent(Label).string)
- if(this.m_data.scene_type>0) {
- if(this.m_data.is_container_layer) {
- let name = `第${this.m_data.scene_page_number}页-容器层-${this.lab_name.getComponent(Label).string}`
- this.lab_name.getComponent(Label).string = name
- } else {
- let name = `第${this.m_data.scene_page_number}页-${this.lab_name.getComponent(Label).string}`
- this.lab_name.getComponent(Label).string = name
- }
- }
- }
- public initWidgetAddCurEditSecne(timeout:number=0) {
- setTimeout(()=>{
- this.updateLabNamePosition()
- this.lab_name.getComponent(Label).string = this.m_data.name + (this.m_data.att?`id:${this.m_data.att.id}`:"");
- },timeout)
- }
- public initWidgetType() {
- this.lab_name.setPosition(0,0,0)
- }
- public hideContainerChilden(){
- this.m_isShowContainerChilden = false
- }
- public hideDragOtherList() {
- // 点击->控件列表,不显示拖拽其他按钮
- this.hideContainerChilden()
- this.m_isShowDragOtherList = true
- }
- public initView(data:widget_item_data,call=null,cur_select_id:number=-1){
- this.m_data = data;
- this.lab_name.getComponent(Label).string = data.name + (this.m_data.att?`id:${this.m_data.att.id}`:"");
- this.lab_remark.getComponent(Label).string = ''
- if(data.att!=null){
- this.lab_remark.getComponent(Label).string = this.m_data.att.remark
- if(this.m_data.type==config.Widget_Type_List.TEXT_SOUND) {
- this.btn_look_voice_text.active = true
- this.btn_look_voice_text.off(Node.EventType.TOUCH_END)
- this.btn_look_voice_text.on(Node.EventType.TOUCH_END, ()=> {
- tools.show_dialog(this.m_data.att.text_sound_data.text, null)
- },this)
- } else {
- this.btn_look_voice_text.active = false
- }
- this.call_back = call
- if(cur_select_id===null){
- this.toggle_active.active = true;
- this.toggle_check.getComponent(Toggle).isChecked = this.m_data.att.edit_active
- this.toggle_check.on(Node.EventType.TOUCH_END,()=>{
- if(this.call_back!=null){
- this.m_data.att.edit_active = !this.m_data.att.edit_active;
- this.call_back(this.m_data)
- }
- })
- }else{
- this.node.on(Node.EventType.TOUCH_END,()=>{
- if(this.call_back!=null){
- this.call_back(this.m_data)
- }
- })
- if(cur_select_id===this.m_data.att.id){
- this.img_select.active = true;
- }
- }
- this.initWidgetHaveAtt(data.att)
- this.node.active = true
- }else{
- this.node.on(Node.EventType.MOUSE_DOWN,this.onDragWidget.bind(this),this)
- }
- }
- public showButtonDelete(is_show:boolean, delete_cb:Function) {
- this.btn_delete.active = is_show
- if(is_show) {
- this.m_delete_cb = delete_cb
- }
- }
- public getShowWidgetData(){
- return this.m_data;
- }
- public setSelectStatus(){
- if(this.call_back!=null){
- this.m_data.att.edit_active = true;
- this.toggle_check.getComponent(Toggle).isChecked = true
- this.call_back(this.m_data)
- }
- }
- public setUnSelectStatus(){
- if(this.call_back!=null){
- this.m_data.att.edit_active = false;
- this.toggle_check.getComponent(Toggle).isChecked = false
- this.call_back(this.m_data)
- }
- }
- onDragWidget(){
- ClientEvent.dispatchEvent(config.Event.DragWidget,this.node)
- }
- initDrag(){
- this.drag.on(Node.EventType.TOUCH_MOVE,(et:EventTouch)=>{
- let p = new Vec3(et.getUILocation().x,et.getUILocation().y)
- let n_p = this.node.getComponent(UITransform).convertToNodeSpaceAR(p)
- this.drag.position = n_p;
- this.m_att.drag_data.drag_pos_x = this.drag.position.x;
- this.m_att.drag_data.drag_pos_y = this.drag.position.y;
-
- })
- if(this.m_att.drag_data.other_drag_list==undefined){
- this.m_att.drag_data.other_drag_list = []
- }
- // 刷新 其他拖拽
- this.other_drag_content.removeAllChildren()
- for (let index = 0; index < this.m_att.drag_data.other_drag_list.length; index++) {
- const element:att_drag_data = this.m_att.drag_data.other_drag_list[index];
- let item = instantiate(this.drag)
- item.off(Node.EventType.TOUCH_MOVE)
- item.parent = this.other_drag_content;
- item.position = new Vec3(element.drag_pos_x,element.drag_pos_y)
- item.getComponent(UITransform).setContentSize(new Size(element.drag_size_width,element.drag_size_height))
- item.on(Node.EventType.TOUCH_MOVE,(et:EventTouch)=>{
- let p = new Vec3(et.getUILocation().x,et.getUILocation().y)
- let n_p = this.node.getComponent(UITransform).convertToNodeSpaceAR(p)
- item.position = n_p;
- this.m_att.drag_data.other_drag_list[index].drag_pos_x = item.position.x;
- this.m_att.drag_data.other_drag_list[index].drag_pos_y = item.position.y;
- })
- item.getComponent(Sprite).color = this.getOtherDragListColor(index) //Color.YELLOW
- item.getChildByName('lab_drag_remark').getComponent(Label).string = element.remark
- if(element.is_show_inTheEditor==undefined) {
- element.is_show_inTheEditor = true
- }
- item.active = element.is_show_inTheEditor
- }
- this.lab_drag.getComponent(Label).string = `${this.m_data.name}id:${this.m_att.id}`
- }
- initSlide(){
- this.slide.getComponent(slide).updateDistance(this.m_att.slide_data.slide_dir,this.m_att.slide_data.slide_distance)
- }
- initUiWidget(){
- if(this.call_back==null){
- let ui = instantiate(this.ui_prefab)
- ui.parent = this.node;
- ui.getComponent(ui_top).initView(this.m_att.top_data)
- this.m_ui_widget = ui;
- this.node.getComponent(UITransform).contentSize = new Size(1080,1020)
- }
- }
- initTextSound(){
- if(this.call_back==null){
- let text_sound = instantiate(this.text_sound_pf)
- text_sound.parent = this.node;
- text_sound.getComponent(Text_Sound).initView(this.m_att.text_sound_data)
- this.m_text_sound = text_sound;
- this.node.getComponent(UITransform).contentSize = new Size(1080,1020)
- }
- }
- initQuestionSelect(){
- if(this.call_back==null){
- let node_question_select = instantiate(this.question_select_pf)
- node_question_select.parent = this.node;
- node_question_select.getComponent(question_select).initView(this.m_att.question_select)
- this.m_question_select = node_question_select;
- this.node.getComponent(UITransform).contentSize = new Size(1080,1020)
- }
- }
- initConatiner(){
- let container_layer = this.m_att.container_layer
- this.container.removeAllChildren()
- if(container_layer!=null){
- for (let index = 0; index < container_layer.widget_list.length; index++) {
- const widget_data = container_layer.widget_list[index];
- // console.log("widget_data",widget_data)
- let node = instantiate(this.self_pf)
- node.getComponent(widget_item).initWidgetByScene(widget_data,widget_data.att)
- node.parent = this.container
- }
- }
- }
- initCountDown(){
- if(this.call_back==null){
- let _time_count = instantiate(this.count_down_pf)
- _time_count.parent = this.node;
- _time_count.getComponent(count_down).initView(this.m_att.count_down)
- this.m_count_down = _time_count;
- this.node.getComponent(UITransform).contentSize = new Size(1080,1020)
- }
- }
- initWidgetHaveAtt(att:attributes_data){
- if(att!=null){
- this.lab_name.active = true;
- this.m_att = att;
- this.initWidgetAtt()
- }else{
- this.m_att = new attributes_data
- this.m_att.id = config.getNewId();
- }
- if(this.m_data.type===config.Widget_Type_List.CLICK_TYPE){
- if(this.m_att.click_data===null){
- this.m_att.click_data = new att_click_data;
- }
- this.lab_name.getComponent(Label).string = config.clcik_type_map.get(this.m_att.click_data.click_type) +`id:${this.m_att.id}`
- }else if(this.m_data.type===config.Widget_Type_List.SLIDE_TYPE){
- this.slide.active = true;
- if(this.m_att.slide_data===null){
- this.m_att.slide_data = new att_slide_data;
- }
- this.initSlide()
- this.lab_name.getComponent(Label).string = `滑动id:${this.m_att.id}`
- }else if(this.m_data.type===config.Widget_Type_List.DRAG_TYPE){
- if(this.m_att.drag_data===null){
- this.m_att.drag_data = new att_drag_data;
- }
- this.drag.active = true;
- if(this.m_isShowDragOtherList == false) {
- this.initDrag()
- }
- this.lab_name.getComponent(Label).string = `拖拽id:${this.m_att.id}`
- }else if(this.m_data.type===config.Widget_Type_List.UI_TOP){
- if(this.m_att.top_data===null){
- this.m_att.top_data = new att_top_data;
- }
- this.initUiWidget()
- this.lab_name.getComponent(Label).string = `弹窗:${config.top_view_type_map.get(this.m_att.top_data.top_ui_type)}:id:${this.m_att.id}`
- }else if(this.m_data.type==config.Widget_Type_List.IMG_TYPE) {
- this.lab_name.getComponent(Label).string = `图片id:${this.m_att.id}`
- }else if(this.m_data.type==config.Widget_Type_List.ACTION_TYPE) {
- this.lab_name.getComponent(Label).string = `动画id:${this.m_att.id}`
- }else if(this.m_data.type===config.Widget_Type_List.TEXT_SOUND){
- if(this.m_att.text_sound_data===null){
- this.m_att.text_sound_data = new att_text_sound_data;
- }
- this.lab_name.getComponent(Label).string =`文本和语音id:${this.m_att.id}`
- this.initTextSound()
- }else if(this.m_data.type===config.Widget_Type_List.QUESTION_SELECT){
- if(this.m_att.question_select===null){
- this.m_att.question_select = new att_question_select;
- }
- this.initQuestionSelect()
- this.lab_name.getComponent(Label).string =`问题选择id:${this.m_att.id}`
- }else if(this.m_data.type===config.Widget_Type_List.COUNT_DOWN){
- if(this.m_att.count_down===null){
- this.m_att.count_down = new att_count_down;
- }
- this.initCountDown()
- this.lab_name.getComponent(Label).string =`倒计时id:${this.m_att.id}`
- }else if(this.m_data.type===config.Widget_Type_List.CONTAINER_LAYER){
- if(this.m_att.container_layer===null){
- this.m_att.container_layer = new att_container;
- }
- if(this.m_isShowContainerChilden){
- this.initConatiner()
- }
- this.lab_name.getComponent(Label).string =`容器层id:${this.m_att.id}`
- }
- this.node.active = this.m_att.edit_active
- }
- public initWidgetByScene(data:widget_item_data,att:attributes_data=null){
- this.m_data = data;
- this.initWidgetHaveAtt(att)
- if(this.m_data.type===config.Widget_Type_List.UI_TOP){ //弹窗不可以拖动
- // MAC电脑浏览器
- if(config.is_MAC_edit) {
- this.node.on(Node.EventType.TOUCH_END,(et:EventTouch)=>{
- ClientEvent.dispatchEvent(config.Event.UpdateAttributes,this.getWidgetAtt())
- })
- return
- }
- this.node.on(Node.EventType.MOUSE_DOWN,(et:EventTouch)=>{
- ClientEvent.dispatchEvent(config.Event.UpdateAttributes,this.getWidgetAtt())
- })
- }else if(this.m_data.type===config.Widget_Type_List.TEXT_SOUND){
- // MAC电脑浏览器
- if(config.is_MAC_edit) {
- this.node.on(Node.EventType.TOUCH_END,(et:EventTouch)=>{
- ClientEvent.dispatchEvent(config.Event.UpdateAttributes,this.getWidgetAtt())
- })
- return
- }
- this.node.on(Node.EventType.MOUSE_DOWN,(et:EventTouch)=>{
- ClientEvent.dispatchEvent(config.Event.UpdateAttributes,this.getWidgetAtt())
- })
- }
- else if(this.m_data.type==config.Widget_Type_List.CONTAINER_LAYER){
- // MAC电脑浏览器
- if(config.is_MAC_edit) {
- this.node.on(Node.EventType.TOUCH_END,(et:EventTouch)=>{
- ClientEvent.dispatchEvent(config.Event.UpdateAttributes,this.getWidgetAtt())
- },this,true)
- return
- }
- this.node.on(Node.EventType.MOUSE_DOWN,(et:EventTouch)=>{
- ClientEvent.dispatchEvent(config.Event.UpdateAttributes,this.getWidgetAtt())
- },this,true)
- }
- else{
- this.node.on(Node.EventType.TOUCH_MOVE,(et:EventTouch)=>{
- if(this.isMove){
- let p = new Vec3(et.getUILocation().x,et.getUILocation().y)
- let n_p = this.node.parent.getComponent(UITransform).convertToNodeSpaceAR(p)
- let offset_x = this.x_len;
- let offset_y = this.y_len;
- this.node.position = new Vec3(n_p.x-offset_x,n_p.y-offset_y);
- if(this.node.parent.name=="content"){
- this.node.parent.parent.parent.getComponent(scroll_scene).stopTouch()
- }
- ClientEvent.dispatchEvent(config.Event.UpdateAttributes,this.getWidgetAtt())
- }
- })
- if(!config.is_MAC_edit) {
- this.node.on(Node.EventType.MOUSE_DOWN,(et:EventTouch)=>{
- et.propagationStopped = true;
- let pos = this.node.parent.getComponent(UITransform).convertToWorldSpaceAR(this.node.position)
- if(this.x_len==0){
- this.x_len = (et.getUILocation().x - pos.x)*2;
- this.y_len = (et.getUILocation().y - pos.y)*2;
- let p = new Vec3(et.getUILocation().x,et.getUILocation().y)
- let n_p = this.node.parent.getComponent(UITransform).convertToNodeSpaceAR(p)
- this.node.position = new Vec3(n_p.x-this.x_len,n_p.y-this.y_len);
- // console.log("a_x",this.x_len, this.y_len ,et.getUILocation().x,this.m_att.width)
- }
- // console.log("this.x_len",this.x_len,this.y_len)
- this.isMove = true;
- ClientEvent.dispatchEvent(config.Event.UpdateAttributes,this.getWidgetAtt())
- })
- }
- this.node.on(Node.EventType.TOUCH_END,(et:EventTouch)=>{
- if(this.node.parent.name=="content"){
- this.node.parent.parent.parent.getComponent(scroll_scene).startTouch()
- }
- this.isMove = false;
- this.x_len = 0;
- this.y_len = 0;
- // MAC电脑浏览器
- if(config.is_MAC_edit) {
- let pos = this.node.parent.getComponent(UITransform).convertToWorldSpaceAR(this.node.position)
- if(this.x_len==0){
- this.x_len = (et.getUILocation().x - pos.x)*2;
- this.y_len = (et.getUILocation().y - pos.y)*2;
- let p = new Vec3(et.getUILocation().x,et.getUILocation().y)
- let n_p = this.node.parent.getComponent(UITransform).convertToNodeSpaceAR(p)
- this.node.position = new Vec3(n_p.x-this.x_len,n_p.y-this.y_len);
- // console.log("a_x",this.x_len, this.y_len ,et.getUILocation().x,this.m_att.width)
- }
- // console.log("this.x_len",this.x_len,this.y_len)
- this.isMove = true;
- ClientEvent.dispatchEvent(config.Event.UpdateAttributes,this.getWidgetAtt())
- }
- })
-
- this.node.on(Node.EventType.MOUSE_LEAVE,()=>{
- if(this.node.parent.name=="content"){
- this.node.parent.parent.parent.getComponent(scroll_scene).startTouch()
- }
- this.isMove = false;
- this.x_len = 0;
- this.y_len = 0;
- })
- }
- ClientEvent.dispatchEvent(config.Event.UpdateAttributes,this.getWidgetAtt())
- ClientEvent.on(config.Event.UpdateAttributesToView,this.UpdateAttributesToView,this)
- }
- protected onDestroy(): void {
- ClientEvent.off(config.Event.UpdateAttributesToView,this.UpdateAttributesToView,this)
- }
- UpdateAttributesToView(data:attributes_data,update_type:string){
- if(this.m_att===null){
- return;
- }
- if(data.id===this.m_att.id){
- // console.log("this.m_att",this.m_att)
- switch(update_type){
- case config.attributes_list_type.pos:
- this.m_att.x = data.x;
- this.m_att.y = data.y;
- this.m_att.z = data.z;
- this.node.setSiblingIndex(this.m_att.z)
- this.node.position = new Vec3(data.x,data.y)
- break;
- case config.attributes_list_type.animation:
- this.m_att.animation_list = data.animation_list;
- break;
- case config.attributes_list_type.size:
- this.m_att.width = data.width;
- this.m_att.height = data.height;
- this.spr.getComponent(UITransform).contentSize = new Size(data.width,data.height)
- this.node.getComponent(UITransform).contentSize = this.spr.getComponent(UITransform).contentSize
- this.updateLabNamePosition()
- break;
- case config.attributes_list_type.anchor:
- this.m_att.anchor_x = data.anchor_x;
- this.m_att.anchor_y = data.anchor_y;
- this.spr.getComponent(UITransform).setAnchorPoint(data.anchor_x, data.anchor_y)
- break;
- case config.attributes_list_type.rotation:
- this.m_att.rotation = data.rotation;
- this.spr.angle = data.rotation;
- break;
- case config.attributes_list_type.url:
- this.m_att.src = data.src
- this.m_att.src_name = data.src_name
- if(this.m_att.src.length<=0){
- this.spr.getComponent(Sprite).spriteFrame = null
- }else{
- assetManager.loadRemote<ImageAsset>(this.m_att.src, (err, imageAsset2)=>{
- if (!err && imageAsset2) {
- // this.lab_name.active = false;
- const texture = new Texture2D();
- texture.image = imageAsset2;
- let spFrame2 = new SpriteFrame();
- spFrame2.texture = texture;
- this.spr.getComponent(Sprite).spriteFrame = spFrame2
- this.spr.getComponent(UITransform).contentSize = new Size(data.width,data.height)
- this.updateLabNamePosition()
- director.once(Director.EVENT_AFTER_DRAW,()=>{
- this.node.getComponent(UITransform).contentSize = this.spr.getComponent(UITransform).contentSize
- })
- }
- });
- }
-
- break;
- case config.attributes_list_type.origin:
- if(this.m_att.src.length>0){
- this.spr.getComponent(UITransform).setContentSize(new Size(this.m_att.width,this.m_att.height))
- this.node.getComponent(UITransform).contentSize = this.spr.getComponent(UITransform).contentSize
- this.updateLabNamePosition()
- ClientEvent.dispatchEvent(config.Event.UpdateAttributes,this.getWidgetAtt())
- // this.spr.getComponent(Sprite).sizeMode = Sprite.SizeMode.RAW;
- // director.once(Director.EVENT_AFTER_DRAW,()=>{
- // console.log("Director.EVENT_AFTER_DRAW")
- // this.m_att.width = this.spr.getComponent(UITransform).contentSize.width;
- // this.m_att.height = this.spr.getComponent(UITransform).contentSize.height;
- // director.once(Director.EVENT_AFTER_DRAW,()=>{
- // this.node.getComponent(UITransform).contentSize = this.spr.getComponent(UITransform).contentSize
- // })
- // ClientEvent.dispatchEvent(config.Event.UpdateAttributes,this.getWidgetAtt())
- // })
- }
- break;
- case config.attributes_list_type.delete:
- this.node.destroy()
- this.node.removeFromParent()
- ClientEvent.dispatchEvent(config.Event.UpdateAttributes,null)
- ClientEvent.dispatchEvent(config.Event.RemoveWidget,this.node)
- break;
- case config.attributes_list_type.drag:
- this.m_att.drag_data = data.drag_data
- if(this.m_data.type===config.Widget_Type_List.DRAG_TYPE){
- this.drag.getComponent(UITransform).contentSize = new Size(data.drag_data.drag_size_width,data.drag_data.drag_size_height);
- this.drag.position = new Vec3( this.m_att.drag_data.drag_pos_x , this.m_att.drag_data.drag_pos_y)
- if(this.m_att.drag_data.other_drag_list==undefined){
- this.m_att.drag_data.other_drag_list = []
- }
- // 更新 其他拖拽
- this.other_drag_content.removeAllChildren()
- for (let index = 0; index < this.m_att.drag_data.other_drag_list.length; index++) {
- const element = this.m_att.drag_data.other_drag_list[index];
- let item = instantiate(this.drag)
- item.off(Node.EventType.TOUCH_MOVE)
- item.parent = this.other_drag_content;
- item.position = new Vec3(element.drag_pos_x,element.drag_pos_y)
- item.getComponent(UITransform).setContentSize(new Size(element.drag_size_width,element.drag_size_height))
- item.on(Node.EventType.TOUCH_MOVE,(et:EventTouch)=>{
- let p = new Vec3(et.getUILocation().x,et.getUILocation().y)
- let n_p = this.node.getComponent(UITransform).convertToNodeSpaceAR(p)
- item.position = n_p;
- this.m_att.drag_data.other_drag_list[index].drag_pos_x = item.position.x;
- this.m_att.drag_data.other_drag_list[index].drag_pos_y = item.position.y;
- })
- item.getComponent(Sprite).color = this.getOtherDragListColor(index) //Color.YELLOW
- item.getChildByName('lab_drag_remark').getComponent(Label).string = element.remark
- item.active = element.is_show_inTheEditor
- }
- }
- break;
- case config.attributes_list_type.drag_err_back_status:
- if(this.m_data.type===config.Widget_Type_List.DRAG_TYPE){
- this.m_att.drag_data.is_err_drag_back = data.drag_data.is_err_drag_back;
- }
- break;
- case config.attributes_list_type.slide:
- if(this.m_data.type===config.Widget_Type_List.SLIDE_TYPE){
- this.m_att.slide_data.slide_dir = data.slide_data.slide_dir;
- this.m_att.slide_data.slide_distance = data.slide_data.slide_distance;
- this.m_att.slide_data.slide_num = data.slide_data.slide_num;
- this.slide.getComponent(slide).updateDistance(this.m_att.slide_data.slide_dir,this.m_att.slide_data.slide_distance)
- }
- break;
- case config.attributes_list_type.click:
- if(this.m_data.type===config.Widget_Type_List.CLICK_TYPE){
- this.m_att.click_data = data.click_data;
- this.lab_name.getComponent(Label).string = config.clcik_type_map.get(this.m_att.click_data.click_type)
- }
- case config.attributes_list_type.is_interaction:
- this.m_att.is_interaction = data.is_interaction;
- break;
- case config.attributes_list_type.find_widget_pos:
- this.Shiny()
- break;
- case config.attributes_list_type.active:
- this.m_att.edit_active = data.edit_active;
- this.node.active = this.m_att.edit_active
- this.toggle_check.getComponent(Toggle).isChecked = this.m_att.edit_active
- break;
- case config.attributes_list_type.top:
- this.m_att.top_data = data.top_data;
- if(this.m_ui_widget!=null){
- this.m_ui_widget.getComponent(ui_top).changeData(this.m_att.top_data)
- }
- break;
- case config.attributes_list_type.text_sound:
- this.m_att.text_sound_data = data.text_sound_data;
- if(this.m_text_sound!=null){
- this.m_text_sound.getComponent(Text_Sound).updateView(this.m_att.text_sound_data)
- }
- break;
- case config.attributes_list_type.question_select:
- this.m_att.question_select = data.question_select;
- if(this.m_question_select!=null){
- this.m_question_select.getComponent(question_select).updateView(this.m_att.question_select)
- }
- break;
- case config.attributes_list_type.count_down:
- this.m_att.count_down = data.count_down;
- if(this.m_count_down!=null){
- this.m_count_down.getComponent(count_down).updateView(this.m_att.count_down)
- }
- break;
- case config.attributes_list_type.zIndex:
- this.m_att.zIndex = data.zIndex;
- break;
- case config.attributes_list_type.dir:
- this.m_att.img_dir = data.img_dir;
- this.updateDir()
- break;
- case config.attributes_list_type.show:
- this.m_att.is_show = data.is_show;
- break;
- case config.attributes_list_type.container:
- this.m_att.container_layer = data.container_layer
- // this.initConatiner()
- break;
- }
- }
- director.once(Director.EVENT_AFTER_DRAW,()=>{
- ClientEvent.dispatchEvent(config.Event.updateWidgetData)
- })
- }
- updateLabNamePosition() {
- let lab_name_y = -(this.spr.getComponent(UITransform).contentSize.height/2+17) //-117
- this.lab_name.setPosition(this.lab_name.getPosition().x,lab_name_y,0)
- }
- updateDir(){
- if(this.call_back==null){
- switch (this.m_att.img_dir) {
- case config.widget_scale_dir.left:
- this.spr.scale = new Vec3(-1,1)
- break;
- case config.widget_scale_dir.up:
- this.spr.scale = new Vec3(1,-1)
- break;
- case config.widget_scale_dir.normal:
- this.spr.scale = new Vec3(1,1)
- break;
- }
- }
- }
- getOtherDragListColor(index:number):Color {
- var color_index = index
- if(index >= config.COLOR_LIST.length) {
- let count = Math.floor(index / config.COLOR_LIST.length)
- color_index = index - (config.COLOR_LIST.length * count)
- }
- return config.COLOR_LIST[color_index]
- // return Color.YELLOW
- }
- Shiny(){
- this.img_select.active = true;
- this.img_select.getComponent(UITransform).setContentSize(this.node.getComponent(UITransform).contentSize)
- Tween.stopAllByTarget(this.img_select)
- tween(this.img_select).delay(0.3).hide().delay(0.3).show().delay(0.3).hide().delay(0.3).show().delay(0.3).call(()=>{
- this.img_select.active = false;
- }).start()
- }
-
- public getWidgetAtt(){
- this.m_att.name = this.m_data.name!=""?this.m_data.name:"普通控件";
- this.m_att.remark = this.m_att.remark;
- this.m_att.height = this.spr.getComponent(UITransform).contentSize.height;
- this.m_att.width = this.spr.getComponent(UITransform).contentSize.width;
- this.m_att.anchor_x = this.m_att.anchor_x==undefined?0.5:this.m_att.anchor_x
- this.m_att.anchor_y = this.m_att.anchor_y==undefined?0.5:this.m_att.anchor_y
- this.m_att.rotation = this.m_att.rotation;
- this.m_att.x = this.node.position.x;
- this.m_att.widget_type = this.m_data.type;
- this.m_att.y = this.node.position.y;
- this.m_att.z = this.node.getSiblingIndex();
- this.m_att.type = config.attributes_type.widget;
- this.m_att.src_name = this.m_att.src.length>0? this.m_att.src_name:"空";
- if(this.m_att.drag_data!=null){
- this.m_att.drag_data.drag_pos_x = this.drag.position.x;
- this.m_att.drag_data.drag_pos_y = this.drag.position.y;
- this.m_att.drag_data.drag_size_width = this.drag.getComponent(UITransform).contentSize.width;
- this.m_att.drag_data.drag_size_height = this.drag.getComponent(UITransform).contentSize.height;
- }
- return this.m_att;
- }
- initWidgetAtt(){
- if(this.call_back==null){
- this.node.position = new Vec3(this.m_att.x,this.m_att.y)
- this.node.getComponent(UITransform).setContentSize(new Size( this.m_att.width,this.m_att.height))
- this.spr.angle = this.m_att.rotation
- this.spr.getComponent(UITransform).setAnchorPoint(new Vec2(this.m_att.anchor_x, this.m_att.anchor_y))
- if(this.m_att.drag_data!=null){
- this.drag.position = new Vec3(this.m_att.drag_data.drag_pos_x,this.m_att.drag_data.drag_pos_y)
- this.drag.getComponent(UITransform).setContentSize(new Size(this.m_att.drag_data.drag_size_width ,this.m_att.drag_data.drag_size_height ))
- }
- this.spr.getComponent(UITransform).setContentSize(this.node.getComponent(UITransform).contentSize)
- this.lab_name.getComponent(Label).string = this.m_att.name+"id:"+this.m_att.id;;
- }else{
- this.lab_name.getComponent(Label).string = this.m_data.name+"id:"+this.m_att.id;
- }
- if(this.m_att.src!=""&&this.m_att.src.length>0){
- assetManager.loadRemote<ImageAsset>(this.m_att.src, (err, imageAsset2)=>{
- if (!err && imageAsset2) {
- const texture = new Texture2D();
- texture.image = imageAsset2;
- let spFrame2 = new SpriteFrame();
- spFrame2.texture = texture;
- this.spr.getComponent(Sprite).spriteFrame = spFrame2
-
- }
- });
- }
- //进行数据差矫正
- let t_data = new attributes_data
- for (const key in t_data) {
- if (Object.prototype.hasOwnProperty.call(t_data ,key)) {
- const element = t_data[key];
- if(this.m_att[key]===undefined){
- this.m_att[key] = element;
- }
- }
- }
- this.updateDir()
- }
- public getData(){
- if(this.m_att!=null){
- this.getWidgetAtt()
- }
- this.m_data.att = this.m_att;
- return this.m_data;
- }
- public setData(data){
- this.m_data = data;
- }
- public getContainer(){
- return this.container
- }
- }
|