local UICollectView = UIViewClass() local EventSystem = require('Event/EventSystem') function UICollectView:OnOpened(context) self:RegistSystemEvent(EventID.UI_Scene_BreakCollectItem,self.BreakSceneCollect) self:RegistSystemEvent(EventID.UI_Scene_AutoCollectItem,self.StartSceneCollect) self.interactData = DataSheetManager.InteractData:GetDataByID(context.collectionId) self.context = context self.state:SetState(0) UIUtils.SetAtlasImageFillAmount(self.sprite_CollectProgress,0) self:SetPushStyle(LuaConst.PushStyleEnum.HIDE) end function UICollectView:OnButtonClicked(comp) if comp == self.btn and self.duration == nil then self:StartSceneCollect() end end function UICollectView:StartSceneCollect() self.state:SetState(1) --UIUtils.SetLabel(self.labLocal_Collect,UIUtils.GetLocalizedTxt(ConstIDS[self.interactData.InteractTipsIDS])) if self.interactData.InteractAnim and string.len(self.interactData.InteractAnim)>0 then NotSyncBattleSetter.OffHorse() NotSyncBattleSetter.SetMainPlayerNextState(LuaConst.StateType.Interact,-1, self.interactData.InteractAnim, nil ,-1) end if self.interactData.InteractTime > 0 then self.duration = self.interactData.InteractTime / 1000 self.collectTimer = 0 self:StopRepeatFunc(self.UpdateCollectProgress) self:StartRepeatFunc(self.UpdateCollectProgress, 0) else self:OnCollectFinish() end end function UICollectView:OnCollectFinish() --if self.interactData.InteractType == LuaConst.InteractType.Collection then self.duration = nil self.collectTimer = nil EventSystem.Dispatch(EventID.UI_Collection_Finish,self.context.itemId,self.context.index) --end if self.interactData.InteractAnim and string.len(self.interactData.InteractAnim)>0 then NotSyncBattleSetter.SetMainPlayerNextState(LuaConst.StateType.Idle,-1, "idle_loop", nil ,-1) end self.state:SetState(0) self:CloseView() end function UICollectView:OnClosed( ) CTL.Interact.SetCurVistedId(nil) end function UICollectView:UpdateCollectProgress(deltaTime, timeSinceUpdate) self:UpdateSceneCollect(timeSinceUpdate) end function UICollectView:UpdateSceneCollect(time) if not self.collectTimer then return end if self.collectTimer > self.duration then self:OnCollectFinish() else self.collectTimer = time UIUtils.SetAtlasImageFillAmount(self.sprite_CollectProgress,self.collectTimer/self.duration) if BattleDataGetter.GetMainPlayerLogicMoveDir() ~= FP.Const.Vector2_Zero then self:BreakSceneCollect() end end end function UICollectView:BreakSceneCollect(entity) if entity ~= LogicUpdateManager._curEntity then return end --if self.interactData.InteractType == LuaConst.InteractType.Collection then self.duration = nil self.collectTimer = nil --end CTL.Interact.SetCurVistedId(nil) UIUtils.SetAtlasImageFillAmount(self.sprite_CollectProgress,0) self.state:SetState(0) --self:CloseView() end function UICollectView:OnFocusChanged(value) UIUtils.SetActive(self.gameObject, value) end return UICollectView