源战役客户端
您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

168 行
4.6 KiB

  1. GuideWelcomeView = GuideWelcomeView or BaseClass(BaseView)
  2. local GuideWelcomeView = GuideWelcomeView
  3. function GuideWelcomeView:__init()
  4. self.base_file = "guide"
  5. self.layout_file = "GuideWelcomeView"
  6. self.layer_name = "Top"
  7. self.destroy_imm = true
  8. self.use_background = true
  9. self.change_scene_close = true
  10. self.append_to_ctl_queue = false --是否要添加进界面堆栈
  11. self.need_show_money = false --是否要显示顶部的金钱栏
  12. self.hide_maincancas = true
  13. -- self.hide_maincancas = true
  14. -- self.click_bg_toClose = true
  15. self.award_list = {}
  16. self.load_callback = function ()
  17. self:LoadSuccess()
  18. self:AddEvent()
  19. end
  20. self.open_callback = function ( )
  21. self:OpenSuccess()
  22. end
  23. self.destroy_callback = function ( )
  24. self:DestroySuccess()
  25. end
  26. end
  27. function GuideWelcomeView:Open(chapter_id)
  28. self.chapter_id = chapter_id or 1
  29. BaseView.Open(self)
  30. end
  31. function GuideWelcomeView:Close( )
  32. GlobalEventSystem:Fire(EventName.FORCE_TO_DO_TASK, true)
  33. BaseView.Close(self)
  34. end
  35. function GuideWelcomeView:LoadSuccess()
  36. self.icon_obj = self:GetChild("icon").gameObject
  37. self.icon_img = self:GetChild("icon"):GetComponent("Image")
  38. self.time_text = self:GetChild("time"):GetComponent("Text")
  39. self.cont = self:GetChild("cont")
  40. self:UpdateAward()
  41. end
  42. function GuideWelcomeView:AddEvent()
  43. local function on_btn_click( )
  44. self:CancelTimer()
  45. self:PlayAnimal()
  46. end
  47. AddClickEvent(self.icon_obj, on_btn_click)
  48. end
  49. function GuideWelcomeView:OpenSuccess()
  50. GlobalEventSystem:Fire(EventName.STOP_AUTO_DO_TASK)
  51. GlobalEventSystem:Fire(EventName.STOPAUTOFIGHT)
  52. self:UpdateTimer()
  53. end
  54. function GuideWelcomeView:UpdateTimer( )
  55. local left_time = 10
  56. local function on_timer( )
  57. local str = HtmlColorTxt(left_time, "#ffc658") .. " 秒后自动发车"
  58. self.time_text.text = str
  59. left_time = left_time -1
  60. if left_time <= 0 then
  61. self:CancelTimer()
  62. self:PlayAnimal()
  63. return
  64. end
  65. end
  66. on_timer()
  67. if not self.count_down_timer then
  68. self.count_down_timer = GlobalTimerQuest:AddPeriodQuest(on_timer, 1, -1)
  69. end
  70. end
  71. function GuideWelcomeView:CancelTimer( )
  72. if self.count_down_timer then
  73. GlobalTimerQuest:CancelQuest(self.count_down_timer)
  74. self.count_down_timer = nil
  75. end
  76. end
  77. function GuideWelcomeView:UpdateAward( )
  78. local chapter_id = self.chapter_id or 1
  79. lua_resM:setOutsideImageSprite(self, self.icon_img, GameResPath.GetViewBigBg("guide_welcome_view_".. chapter_id), false)
  80. local awards = self:GetChapterAwardsCfg(chapter_id)
  81. if IsTableEmpty(awards) then
  82. return
  83. end
  84. for i=1,3 do
  85. local award = awards[i] or {}
  86. local item = self.award_list[i]
  87. if not item then
  88. item = UIObjPool:getInstance():PopItem(UIObjPool.UIType.AwardItem, self.cont)
  89. self.award_list[i] = item
  90. end
  91. item:SetItemSize(84, 84)
  92. item:SetPosition((i-1)*94, 0)
  93. item:SetVisible(true)
  94. local typeId, lock = GoodsModel:getInstance():GetMappingTypeId(award[2], award[3])
  95. item:SetData(typeId, award[4], nil, nil, lock)
  96. end
  97. end
  98. function GuideWelcomeView:GetChapterAwardsCfg( chapter_id )
  99. if not chapter_id then
  100. return {}
  101. end
  102. self.chapter_award_cfg = self.chapter_award_cfg or {}
  103. if self.chapter_award_cfg[chapter_id] then
  104. return self.chapter_award_cfg[chapter_id]
  105. end
  106. local career = RoleManager.Instance.mainRoleInfo.career
  107. if career == 0 then
  108. return {}
  109. end
  110. local chapter_cfg = Config.Chapter[chapter_id]
  111. if not chapter_cfg then
  112. return {}
  113. end
  114. local temp_cfg = stringtotable(chapter_cfg.awards)
  115. local temp_awards = {}
  116. for i,v in ipairs(temp_cfg) do
  117. if v[1] and (v[1] == 0 or v[1] == career) then
  118. table.insert(temp_awards, v)
  119. end
  120. end
  121. self.chapter_award_cfg[chapter_id] = temp_awards
  122. return temp_awards
  123. end
  124. function GuideWelcomeView:PlayAnimal( )
  125. do self:Close() return end
  126. local function end_func( )
  127. self:Close()
  128. end
  129. local target_pos = MainUIController.Instance:GetChapterAwardPos( )
  130. -- if self.chapter_id <= 3 then
  131. -- target_pos = Vector3(-ScreenWidth/2+ClientConfig.iphone_x_offset_right+2+16.84+50, ScreenHeight/2-50-76-128.3-88, 0)
  132. -- else
  133. -- target_pos = Vector3(-ScreenWidth/2+ClientConfig.iphone_x_offset_right+2+16.84+50, creenHeight/2-50-76-128.3-88, 0)
  134. -- end
  135. if IsTableEmpty(target_pos) then
  136. end_func()
  137. return
  138. end
  139. local time = 0.8
  140. local target_scale = Vector3(0.7, 0.7, 0.7)
  141. TweenLite.to(self, self.cont, TweenLite.UiAnimationType.POS, target_pos, time, end_func)
  142. TweenLite.to(self, self.cont, TweenLite.UiAnimationType.SCALE, target_scale, time)
  143. end
  144. function GuideWelcomeView:DestroySuccess( )
  145. self:CancelTimer()
  146. for i,item in pairs(self.award_list) do
  147. UIObjPool:getInstance():PushItem(UIObjPool.UIType.AwardItem, item)
  148. end
  149. self.award_list = {}
  150. end