123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187 |
- import { _decorator, assetManager, Component, ImageAsset, Node, ScrollView, Size, Sprite, SpriteFrame, Texture2D, Toggle, UITransform } from 'cc';
- import { attributes_data, scene_item_data } from '../../data/data';
- import { config } from '../config';
- import { ClientEvent } from '../clientEvent';
- import { tools } from '../tools';
- const { ccclass, property } = _decorator;
- @ccclass('scroll_scene')
- export class scroll_scene extends Component {
- @property(Node) mask_view:Node = null;
- @property(Node) mask_view_content:Node = null;
- @property(Node) mask_check_node:Node = null;
- @property(Node) mask_check:Node = null;
- @property(Node) mask:Node = null;
- @property(SpriteFrame) mask_sf:SpriteFrame = null;
- private m_data:scene_item_data = null;
- private m_att:attributes_data = null;
- private _bg:Node = null;
- private m_call_back = null;
- protected start(): void {
- if(this._bg===null){
- this.setBg(this.node)
- }
- ClientEvent.on(config.Event.UpdateAttributesToView,this.UpdateAttributesToView,this)
- }
- UpdateAttributesToView(data:attributes_data,update_type:string){
- if(data.id===this.m_att.id){
- switch(update_type){
- case config.attributes_list_type.pos:
- 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.getBg().getComponent(UITransform).contentSize = new Size(data.width,data.height)
- 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.getBg().getComponent(Sprite).spriteFrame =null;
- }else{
- 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.getBg().getComponent(UITransform).contentSize = new Size(data.width,data.height)
- this.getBg().getComponent(Sprite).spriteFrame = spFrame2
- }
- });
- }
-
- break;
-
- }
- }
- }
- protected onDestroy(): void {
- ClientEvent.off(config.Event.UpdateAttributesToView,this.UpdateAttributesToView,this)
- }
- public setBg(bg:Node){
- this._bg = bg;
- }
- public getBg(){
- if(this._bg===null){
- this.setBg(this.node)
- }
- return this._bg;
- }
- public addWidget(node:Node){
- node.parent = this.getBg()
- }
- public initView(is_mask:boolean,att_data:attributes_data=null){
- if(att_data!=null){
- this.m_att =att_data;
- if(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.getBg().getComponent(UITransform).contentSize = new Size(this.m_data.att.width,this.m_data.att.height)
- this.getBg().getComponent(Sprite).spriteFrame = spFrame2
- }
- });
- }
- }else{
- this.m_att.id = config.getNewId();
- }
- if(is_mask){
- this.mask_check_node.active = true;
- this.mask_check.getComponent(Toggle).isChecked = true;
- }else{
- this.mask_check.getComponent(Toggle).isChecked = false;
- this.mask_check_node.active = false;
- }
- this.mask_check.on(Node.EventType.TOUCH_START,()=>{
- this.mask_check.getComponent(Toggle).isChecked=!this.mask_check.getComponent(Toggle).isChecked
- this.updatStatus()
- })
- this.updatStatus()
- this.setBg(this.mask_view_content)
- }
- public initFullView(att_data:attributes_data=null){
- if(att_data!=null){
- this.m_att =att_data;
- if(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.getBg().getComponent(UITransform).contentSize = new Size(this.m_data.att.width,this.m_data.att.height)
- this.getBg().getComponent(Sprite).spriteFrame = spFrame2
- }
- });
- }
- }else{
- this.m_att.id = config.getNewId();
- }
- }
- public setData(data:scene_item_data){
- this.m_data = data;
- this.m_data.att = this.m_att;
- }
- public getData(){
- return this.m_data;
- }
- public setCallBack(call){
- this.m_call_back = call;
- this.getBg().on(Node.EventType.TOUCH_START,()=>{
- if(this.m_call_back!=null){
- this.m_call_back()
- }
- })
- }
- public getScenePageAtt(){
- this.m_att.name = this.m_data.name!=""?this.m_data.name:"场景";
- this.m_att.height = this.getBg().getComponent(UITransform).contentSize.height;
- this.m_att.width = this.getBg().getComponent(UITransform).contentSize.width;
- this.m_att.type = config.attributes_type.scene;
- this.m_att.src_name = this.m_att.src.length>0? this.m_att.src_name:"空";
- return this.m_att;
- }
- updatStatus(){
- if(this.mask_check.getComponent(Toggle).isChecked){
- this.mask.active = true;
- }else{
- this.mask.active = false;
- }
- }
- public stopTouch(){
- if(this.mask_view!=null){
- this.node.getComponent(ScrollView).enabled = false;
- }
- }
- public startTouch(){
- if(this.mask_view!=null){
- this.node.getComponent(ScrollView).enabled = true;
- }
- }
- public getContent():Node{
- return this.node.getComponent(ScrollView).content
- }
- getAtt(){
- return this.m_att;
- }
- }
|