1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495 |
- import { _decorator, Component, EditBox, instantiate, Label, Node, Prefab, Size } from 'cc';
- import { att_drag_data } from '../../../data/data';
- import { other_drag_list_item } from './other_drag_list_item';
- const { ccclass, property } = _decorator;
- @ccclass('attributes_drop')
- export class attributes_drop extends Component {
- @property(EditBox) drag_width:EditBox = null;
- @property(EditBox) drag_height:EditBox = null;
- @property(EditBox) drag_x:EditBox = null;
- @property(EditBox) drag_y:EditBox = null;
- @property(Node) btn_is_err_back_pos:Node = null;
- @property(Node) lab_is_err_back_pos:Node = null;
- @property(Node) btn_add_other_drag_dis:Node = null;
- @property(Node) content:Node = null;
- @property(Prefab) other_drag_item:Prefab = null;
- private call_back = null;
- private _err_back_status_call = null;
- private _is_err_drag_back:boolean = false;
- private m_data:att_drag_data = null;
- public update_att(data:att_drag_data){
- this.m_data = data;
- this.drag_width.string = data.drag_size_width.toString()
- this.drag_height.string = data.drag_size_height.toString()
- this.drag_x.string = data.drag_pos_x.toString()
- this.drag_y.string = data.drag_pos_y.toString()
- this._is_err_drag_back = data.is_err_drag_back;
- this.lab_is_err_back_pos.getComponent(Label).string = this._is_err_drag_back ?"是":"否"
- this.content.removeAllChildren()
- if(this.m_data.other_drag_list==undefined){
- this.m_data.other_drag_list = []
- }
- for (let index = 0; index < this.m_data.other_drag_list.length; index++) {
- let item = instantiate(this.other_drag_item)
- item.parent = this.content;
- let item_data = this.m_data.other_drag_list[index]
- item.getComponent(other_drag_list_item).initView(item_data,this.onOtherDragItemClickDelete.bind(this))
- }
- }
- protected start(): void {
- this.drag_width.node.on('editing-did-ended', this.change, this);
- this.drag_height.node.on('editing-did-ended', this.change, this);
- this.drag_x.node.on('editing-did-ended', this.change, this);
- this.drag_y.node.on('editing-did-ended', this.change, this);
- this.btn_is_err_back_pos.on(Node.EventType.TOUCH_END,()=>{
- if(this._err_back_status_call!=null){
- this._is_err_drag_back = !this._is_err_drag_back
- this._err_back_status_call(this._is_err_drag_back)
- this.lab_is_err_back_pos.getComponent(Label).string = this._is_err_drag_back?"是":"否"
- }
- })
- this.btn_add_other_drag_dis.on(Node.EventType.TOUCH_END,()=>{
- this.addOtherDragItem()
- })
- }
- public initView(call,err_back_status_call){
- this.call_back = call;
- this._err_back_status_call = err_back_status_call;
- }
- addOtherDragItem(){
- let item = instantiate(this.other_drag_item)
- item.parent = this.content;
- let item_data = new att_drag_data
- item_data.drag_pos_x = this.m_data.drag_pos_x+50;
- item_data.drag_pos_y = this.m_data.drag_pos_y;
- item_data.drag_size_width = this.m_data.drag_size_width;
- item_data.drag_size_height = this.m_data.drag_size_height;
- this.m_data.other_drag_list.push(item_data)
- item.getComponent(other_drag_list_item).initView(this.m_data.other_drag_list[this.m_data.other_drag_list.length-1],this.onOtherDragItemClickDelete.bind(this))
- this.change()
- }
- onOtherDragItemClickDelete(data:att_drag_data){
- let index = this.m_data.other_drag_list.indexOf(data)
- this.m_data.other_drag_list.splice(index,1)
- this.change()
- }
- change(){
- this.m_data.drag_pos_x = parseInt(this.drag_x.string);
- this.m_data.drag_pos_y = parseInt(this.drag_y.string);
- this.m_data.drag_size_width = parseInt(this.drag_width.string);
- this.m_data.drag_size_height = parseInt(this.drag_height.string);
- if(this.call_back!=null){
- this.call_back(this.m_data)
- }
- }
- }
|