xx 1 năm trước cách đây
mục cha
commit
ed56914a64

Những thai đổi đã bị hủy bỏ vì nó quá lớn
+ 411 - 138
assets/resources/prefab/run/game_run.prefab


+ 56 - 6
assets/script/run/bag/bag_drag_item.ts

@@ -1,7 +1,8 @@
-import { _decorator, Component, instantiate, Node, Prefab, Sprite } from 'cc';
+import { _decorator, Component, EventTouch, instantiate, Node, Prefab, Rect, Sprite, UITransform, Vec2, Vec3 } from 'cc';
 import { dai_dao_ju_item, widget_item_data } from '../../../data/data';
 import { gameManager } from '../gameManager';
 import { widget_base } from '../widget/widget_base';
+import { widget_drag } from '../widget/widget_drag';
 const { ccclass, property } = _decorator;
 
 @ccclass('bag_drag_item')
@@ -11,14 +12,20 @@ export class bag_drag_item extends Component {
     @property(Prefab) drag_item_prefab:Prefab = null;
     private mData:dai_dao_ju_item = null;
     private mCallBack = null;
-    public initView(data:dai_dao_ju_item,widget_data:widget_item_data,call){
-        let item = instantiate(this.drag_item_prefab)
-        item.parent = this.drag_item_parent;
-        let com = item.getComponent(widget_base);
+    private drag_item:Node = null;
+    private action_node:Node = null;
+    private mFinishCall = null;
+    public initView(data:dai_dao_ju_item,widget_data:widget_item_data,call,finish_call){
+        this.drag_item= instantiate(this.drag_item_prefab)
+        this.drag_item_parent.removeAllChildren()
+        this.drag_item.parent = this.drag_item_parent;
+        let com = this.drag_item.getComponent(widget_base);
         com.initView(widget_data,false);
         this.mData = data;
         this.mCallBack = call;
-        this.node.on(Node.EventType.TOUCH_START,()=>{
+        this.mFinishCall = finish_call;
+        this.node.off(Node.EventType.TOUCH_END)
+        this.node.on(Node.EventType.TOUCH_END,()=>{
             if(this.mCallBack!=null){
                 this.mCallBack(this)
             }
@@ -35,6 +42,49 @@ export class bag_drag_item extends Component {
 
     public unSelect(){
         this.spr_select_status.active = false;
+        this.drag_item.off(Node.EventType.TOUCH_END)
+    }
+
+    public getRect():Rect{
+        if(this.drag_item!=null){
+            return this.drag_item.getComponent(widget_drag).getDragRect();
+        }
+    }
+
+    public registeredEvent(action_node:Node){
+        this.action_node = action_node;
+        this.drag_item.off(Node.EventType.TOUCH_MOVE)
+        this.drag_item.on(Node.EventType.TOUCH_MOVE,(et:EventTouch)=>{
+            let p = new Vec3(et.getUILocation().x,et.getUILocation().y)
+            let n_p = this.drag_item_parent.getComponent(UITransform).convertToNodeSpaceAR(p)
+            this.drag_item.position = new Vec3(n_p.x,n_p.y);
+        })
+        this.drag_item.off(Node.EventType.TOUCH_END)
+        this.drag_item.on(Node.EventType.TOUCH_END,()=>{
+            this.onEndEvent()
+        })
+    }
+
+    private onEndEvent(){
+        this.checkOnecFinish()
+    }
+    private checkOnecFinish(){
+        if(this.checkMoveToDragRect()){
+            this.drag_item.getComponent(widget_drag).toFinishEvent()
+            // console.log("完成了自己的任务")
+            if(this.mFinishCall!=null){
+                this.mFinishCall(this)
+            }
+        }else{
+            this.drag_item.position = Vec3.ZERO;
+        }
+    }
+    private checkMoveToDragRect():boolean{
+        let p = this.drag_item.position;
+        let n_p = this.drag_item_parent.getComponent(UITransform).convertToWorldSpaceAR(p)
+        let nn_p = this.action_node.getComponent(UITransform).convertToNodeSpaceAR(n_p)
+        let is = this.getRect().contains(new Vec2(nn_p.x,nn_p.y))
+        return is
     }
 
 }

+ 76 - 8
assets/script/run/bag/dai_dao_ju_bag.ts

@@ -1,8 +1,11 @@
-import { _decorator, Component, instantiate, Node, Prefab } from 'cc';
-import { dai_dao_ju_item, guo_ju_qing_dai_dao_ju } from '../../../data/data';
+import { _decorator, Component, instantiate, Node, Prefab, Rect, Size, Sprite, UITransform, Vec2, Vec3 } from 'cc';
+import { dai_dao_ju_item, event_item, guo_ju_qing_dai_dao_ju } from '../../../data/data';
 import { widget_base } from '../widget/widget_base';
 import { gameManager } from '../gameManager';
 import { bag_drag_item } from './bag_drag_item';
+import { ClientEvent } from '../../clientEvent';
+import { config } from '../../config';
+import { widget_info } from './widget_info';
 const { ccclass, property } = _decorator;
 
 @ccclass('dai_dao_ju_bag')
@@ -12,12 +15,22 @@ export class dai_dao_ju_bag extends Component {
     @property(Node) content:Node;
     @property(Node) btn_info:Node;
     @property(Prefab) item_prefab:Prefab = null;
-    private m_call_back = null;
+    @property(Node) action_node:Node = null;
+    @property(widget_info) widget_info:widget_info = null;
+    @property(Node) drag_des:Node = null;
+    private m_tip_call_back = null;
     private m_add_time_call = null;
     private cur_select_item:bag_drag_item = null;
-    public initView(data:guo_ju_qing_dai_dao_ju,call_back,add_time_call){
+    private mWidgetList:Map<number,bag_drag_item> = new Map;
+    private mData:guo_ju_qing_dai_dao_ju = null;
+    public initView(data:guo_ju_qing_dai_dao_ju,tip_call,add_time_call){
         this.content.removeAllChildren()
-        this.m_call_back = call_back;
+        this.mWidgetList.clear()
+        this.mData = data;
+        this.btn_info.active = false;
+        ClientEvent.off(config.EventRun.NOTICE_EVENT,this.beActive.bind(this),this)
+        ClientEvent.on(config.EventRun.NOTICE_EVENT,this.beActive.bind(this),this)
+        this.m_tip_call_back = tip_call;
         this.m_add_time_call = add_time_call;
         let list = gameManager.getWidgetList(gameManager.Singleton.getSceneManager().getSceneData());
         let getWidgetData = (id)=>{
@@ -39,14 +52,15 @@ export class dai_dao_ju_bag extends Component {
                 }else{
                     item.active = false;
                 }
-                item.getComponent(bag_drag_item).initView(element,getWidgetData(element.widget_id),this.onItemClick.bind(this))
+                item.getComponent(bag_drag_item).initView(element,getWidgetData(element.widget_id),this.onItemClick.bind(this),this.onItemFinish.bind(this))
+                this.mWidgetList.set(element.widget_id,item.getComponent(bag_drag_item))
             }
           
         }
 
         this.btn_tip.on(Node.EventType.TOUCH_END,()=>{
-            if( this.m_call_back !=null){
-                this.m_call_back();
+            if( this.m_tip_call_back !=null){
+                this.m_tip_call_back();
             }
         })
 
@@ -61,11 +75,65 @@ export class dai_dao_ju_bag extends Component {
                 this.m_add_time_call();
             }
         })
+
+        this.btn_info.on(Node.EventType.TOUCH_END,()=>{
+            if( this.cur_select_item !=null){
+                this.widget_info.show(this.cur_select_item.getData().info_res)
+            }
+        })
     }
 
 
+    hideAllItem(){
+        for (let index = 0; index < this.content.children.length; index++) {
+            const element = this.content.children[index];
+            element.getComponent(bag_drag_item).unSelect()
+        }
+    }
     onItemClick(item:bag_drag_item){
+        if(this.cur_select_item==item){
+            return
+        }
+        this.hideAllItem()
         this.cur_select_item = item;
+        this.cur_select_item.onSelect()
+        this.btn_info.active = true;
+        this.addDragRect(this.cur_select_item.getRect())
+        this.cur_select_item.registeredEvent(this.action_node)
+        this.action_node.on(Node.EventType.TOUCH_START,()=>{
+            this.action_node.off(Node.EventType.TOUCH_START)
+            this.btn_info.active = false;
+            this.cur_select_item.unSelect()
+            this.cur_select_item = null;
+        })
+    }
+
+    onItemFinish(item:bag_drag_item){
+        item.node.removeFromParent()
+        this.cur_select_item = null;
+        if(this.isFinishAll()){
+            if( this.mData.finish_event_id!=-1){
+                gameManager.Singleton.exeEvent(this.mData.finish_event_id)
+            }
+        }
+    }
+
+    isFinishAll(){
+        return this.content.children.length<=0;
+    }
+
+    beActive(widgetId:number,event:event_item){
+        if(event.type===config.event_type.active_event){
+            let drag_item = this.mWidgetList.get(widgetId)
+            if(drag_item!=null){
+                drag_item.node.active = true;
+            }
+        }
+    }
+
+    addDragRect(r:Rect){
+        this.drag_des.position = new Vec3(r.x+r.width*0.5,r.y+r.height*0.5);
+        this.drag_des.getComponent(UITransform).setContentSize(new Size(r.width,r.height))
     }
 
 }

+ 24 - 0
assets/script/run/bag/widget_info.ts

@@ -0,0 +1,24 @@
+import { _decorator, Component, Node, Sprite } from 'cc';
+import { bag_item_data } from '../../../data/data';
+import { gameManager } from '../gameManager';
+const { ccclass, property } = _decorator;
+
+@ccclass('widget_info')
+export class widget_info extends Component {
+    @property(Node) btn_back:Node = null;
+    @property(Node) icon:Node = null;
+    public show(data:bag_item_data){
+        this.node.active = true;
+        this.icon.getComponent(Sprite).spriteFrame = gameManager.getCacheSpriteFrameByName(data.url)
+        this.btn_back.off(Node.EventType.TOUCH_END)
+        this.btn_back.on(Node.EventType.TOUCH_END,()=>{
+            this.hide()
+        })
+    }
+
+    public hide(){
+        this.node.active = false;
+    }
+}
+
+

+ 9 - 0
assets/script/run/bag/widget_info.ts.meta

@@ -0,0 +1,9 @@
+{
+  "ver": "4.0.23",
+  "importer": "typescript",
+  "imported": true,
+  "uuid": "60c00b5e-281d-4538-a110-a99067fcdd77",
+  "files": [],
+  "subMetas": {},
+  "userData": {}
+}

+ 8 - 1
assets/script/run/widget/widget_drag.ts

@@ -136,7 +136,10 @@ export class widget_drag extends widget_base {
 
     }
 
-    private getDragRect():Rect{
+    public getDragRect():Rect{
+        if(this.mDragData==null){
+            this.mDragData = this.mData.att.drag_data
+        }
         let w = this.mDragData.drag_size_width;
         let h = this.mDragData.drag_size_height;
         let pos =  new Vec3(this.mData.att.x+this.mDragData.drag_pos_x,this.mData.att.y+this.mDragData.drag_pos_y)
@@ -167,6 +170,10 @@ export class widget_drag extends widget_base {
             this.img_zhaobutong.active = false;
         }
     }
+
+    public toFinishEvent(){
+        this.onFinishEvent()
+    }
 }
 
 

Một số tệp đã không được hiển thị bởi vì quá nhiều tập tin thay đổi trong này khác