|
|
- CommonAwardFlyView = CommonAwardFlyView or BaseClass(BaseView)
- local CommonAwardFlyView = CommonAwardFlyView
- function CommonAwardFlyView:__init()
- self.base_file = "common"
- self.layout_file = "CommonAwardFlyView"
- self.layer_name = "Top"
- self.destroy_imm = true
- self.use_background = false
- self.append_to_ctl_queue = false
- self.item_list = {}
- self.item_con_list = {}
- self.offer_x = 640--X轴偏移量
- self.offer_y = -360--X轴偏移量
- self.is_set_zdepth = true
- self.end_offer_x = 0
- self.end_offer_y = 0
- self.load_callback = function ()
- self:LoadSuccess()
- self:UpdateView()
- end
- self.close_callback = function ()
- self:Remove()
- end
- end
-
- function CommonAwardFlyView:Remove()
- for i,v in ipairs(self.item_list) do
- UIObjPool:PushItem(UIObjPool.UIType.AwardItem, v)
- end
- self.item_list = {}
-
- for i,v in ipairs(self.item_con_list) do
- cc.ActionManager:getInstance():removeAllActionsFromTarget(v.transform)
- end
- end
-
- --target初始节点
- --end_target终点节点
-
- -- data = {
- -- item_list = {
- -- [1] = {target,end_target,goods_vo}--goods_vo = {type_kind,type_id,type_num}--万一你要显示道具数量那不是坑爹
- -- }
- -- offer_x = 640,整体偏移量
- -- offer_y = 360,整体偏移量
- -- end_offer_x = 0,--结束位置偏移量
- -- end_offer_y = 0,--结束位置偏移量
- -- end_func = callback--结束方法
- -- times = 2
- -- }
-
- function CommonAwardFlyView:Open( data )
- self.data = data or self.data
- if not self.data then
- self:Close()
- return
- end
- self.offer_x = self.data.offer_x or self.offer_x
- self.offer_y = self.data.offer_y or self.offer_y
- self.end_offer_x = self.data.end_offer_x or self.end_offer_x
- self.end_offer_y = self.data.end_offer_y or self.end_offer_y
- print("huangcong:CommonAwardFlyView [start:45] self.data:", self.data)
- PrintTable(self.data)
- print("huangcong:CommonAwardFlyView [end]")
- BaseView.Open(self)
- end
-
- function CommonAwardFlyView:LoadSuccess()
- local nodes = {
- "itemCon"
- }
- self:GetChildren(nodes)
- self:InitEvent()
- end
-
- function CommonAwardFlyView:InitEvent()
-
- end
-
- function CommonAwardFlyView:UpdateView()
- if not self.data or not self.data.item_list then
- self:Close()
- return
- end
- self:UpdateItemList()
- end
-
- --更新道具列表
- function CommonAwardFlyView:UpdateItemList( )
- local list = self.data.item_list
- local count = 0
- local len = #list
- for i,v in ipairs(list) do
- local item = self.item_list[i]
- if item == nil then
- local item_transform = UiFactory.createChild(self.transform, UIType.EmptyObject)
- item_transform.transform.pivot = Vector2(0, 1)
- item_transform.transform.sizeDelta = Vector2(78, 78)
- item_transform.transform.anchorMin = Vector2(0, 1)
- item_transform.transform.anchorMax = Vector2(0, 1)
- item_transform:SetActive(false)
- self.item_con_list[i] = item_transform
- item = UIObjPool:PopItem(UIObjPool.UIType.AwardItem,item_transform.transform)
- self.item_list[i] = item
- local goods_vo = v[3]
- if goods_vo then
- item:SetData(goods_vo[2],goods_vo[3] or nil)
- end
- self:StartAction(item_transform.transform,v[1],v[2],i == len)
- end
- end
- end
-
- function CommonAwardFlyView:StartAction( transform,target,end_target,is_end )
- if IsNull(target) or IsNull(end_target) then return end
- --设置初始状态
- local start_abs_pos = target.transform:TransformPoint(Vector3.zero)
- local start_pos = self.transform:InverseTransformPoint(Vector3.New(start_abs_pos.x, start_abs_pos.y, 0))
-
- local end_abs_pos = end_target.transform:TransformPoint(Vector3.zero)
- local end_pos = self.transform:InverseTransformPoint(Vector3.New(end_abs_pos.x, end_abs_pos.y, 0))
-
- -- new_pos.x = new_pos.x + 145
- -- new_pos.y = new_pos.y + 210
- -- SetLocalScale(transform,1.1,1.1,1.1)
- SetAnchoredPosition(transform,start_pos.x + self.offer_x,start_pos.y + self.offer_y)
- transform.gameObject:SetActive(true)
- local time = self.data.time or 1
- local action = cc.MoveTo.createAnchoredType(time, end_pos.x + self.offer_x + self.end_offer_x, end_pos.y + self.offer_y + self.end_offer_y)
- local function end_func()
- transform.gameObject:SetActive(false)
- -- SetLocalScale(transform,1,1,1)
- if is_end then--最后要设置已获得
- if self.data.end_func then
- self.data.end_func()
- end
- self:Close()
- end
- end
- -- action = cc.Spawn.New(action, cc.ScaleTo.New(time,0.8,0.8,0.8))
- action = cc.Sequence.New(action,cc.CallFunc.New(end_func))
- cc.ActionManager:getInstance():addAction(action, transform)
- end
|