源战役客户端
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

311 lines
11 KiB

  1. GodActivityCommonView = GodActivityCommonView or BaseClass(BaseItem)
  2. local GodActivityCommonView = GodActivityCommonView
  3. -- GodActivityCommonView.Width = 200
  4. -- GodActivityCommonView.Height = 90
  5. function GodActivityCommonView:__init(parent_wnd,prefab_asset,layer_name)
  6. self.base_file = "godActivity"
  7. self.layout_file = "GodActivityCommonView"
  8. self.layer_name = layer_name
  9. self.model = GodModel:getInstance()
  10. self.full_screen = true
  11. -- self.ani_right = 400
  12. -- self.adjust_mid = {left = 300, right = 800}
  13. self.list_item = {}
  14. self:Load()
  15. self.model:Fire(GodConst.REQ_ACTIVITY_COMMON_INFO)
  16. CustomActivityModel:getInstance():SetGoodsCanFly(false)
  17. end
  18. function GodActivityCommonView:Load_callback()
  19. self.nodes = {
  20. "scroll_1", "scroll_1/Viewport/Content_1",
  21. "icon_money_one:img:obj", "lb_money_one:tmp", "lb_money_ten:tmp", "icon_money_ten:img",
  22. "btn_one/lb_btn_one:tmp", "btn_one:obj", "btn_ten:obj", "btn_ten/lb_btn_ten:tmp",
  23. "btn_tip:obj", "lb_all_time:tmp", "btn_one/free_red:obj",
  24. "bg_1:raw","bg_2:raw","bg_3:raw","bg_4:raw","click_mask:obj",
  25. "goods_show_4:img", "goods_show_6:img", "goods_show_3:img", "goods_show_5:img", "goods_show_1:img", "goods_show_2:img",
  26. -------------------------
  27. "con_item_5", "con_item_2", "con_item_4", "con_item_3", "con_item_1", "free_label:tmp",
  28. }
  29. self:GetChildren(self.nodes)
  30. self:AddEvents()
  31. self.lb_btn_one_tmp.text = "单次召唤"
  32. self.lb_btn_ten_tmp.text = "十回召唤"
  33. self:UpdateView()
  34. self:SetPoolReward()
  35. self:SetLeftReward()
  36. lua_resM:setOutsideRawImage(self,self.bg_1_raw,"/client/assets/icon/god/bg/god_draw_bg_1.png")
  37. lua_resM:setOutsideRawImage(self,self.bg_2_raw,"/client/assets/icon/god/bg/god_draw_bg_2.png")
  38. lua_resM:setOutsideRawImage(self,self.bg_3_raw,"/client/assets/icon/god/bg/god_draw_bg_3.png")
  39. lua_resM:setOutsideRawImage(self,self.bg_4_raw,"/client/assets/icon/god/bg/god_draw_bg_4.png")
  40. end
  41. function GodActivityCommonView:RefreshRed( )
  42. if self.is_loaded then
  43. --宠物生活技能 每日免费抽奖一次
  44. local left_free_draw_times = self.model:GetGodLeftFreeDrawTimes()
  45. local free_red = left_free_draw_times > 0
  46. local num = GoodsModel:getInstance():GetTypeGoodsNum(self.model.acitvity_cost_id)
  47. self.free_red_obj:SetActive(num > 0 or free_red)
  48. end
  49. end
  50. function GodActivityCommonView:AddEvents( )
  51. local function call_back( target )
  52. if target == self.btn_tip_obj then
  53. EventSystem.Fire(GlobalEventSystem,EventName.OPEN_INSTRUCTION_VIEW, 173 .. "@" .. 90)
  54. elseif target == self.btn_one_obj then
  55. self:StartGo(1)
  56. elseif target == self.btn_ten_obj then
  57. self:StartGo(10)
  58. end
  59. end
  60. AddClickEvent(self.btn_tip_obj,call_back,false)
  61. AddClickEvent(self.btn_one_obj,call_back,false)
  62. AddClickEvent(self.btn_ten_obj,call_back,false)
  63. local function ANS_ACTIVITY_COMMON_INFO( )
  64. self:UpdateView()
  65. end
  66. self:BindEvent(self.model, GodConst.ANS_ACTIVITY_COMMON_INFO, ANS_ACTIVITY_COMMON_INFO)
  67. local function on_update_red_dot( )
  68. self:RefreshRed()
  69. end
  70. self:BindEvent(self.model, GodConst.UpdateRedDot, on_update_red_dot)
  71. local function ANS_ACTIVITY_PLAY( pool_type, draw_type, result_data )
  72. --抽奖完成,显示抽奖特效
  73. if pool_type == GodConst.ActivityType.Common then
  74. self:ShowDrawEffect(pool_type, draw_type, result_data)
  75. self.click_mask_obj:SetActive(true)
  76. end
  77. end
  78. self:BindEvent(self.model, GodConst.ANS_ACTIVITY_PLAY, ANS_ACTIVITY_PLAY)
  79. end
  80. function GodActivityCommonView:StartGo( use_type )
  81. local conf_tag = use_type == 1 and "lottery_single" or "lottery_ten"
  82. local have_num = GoodsModel:getInstance():GetTypeGoodsNum(self.model.acitvity_cost_id)
  83. local one_cost_conf = Config.Godkv[conf_tag].value_content
  84. local need_num = stringtotable(one_cost_conf)[1][3]
  85. --宠物生活技能
  86. local left_free_draw_times = self.model:GetGodLeftFreeDrawTimes()
  87. if left_free_draw_times > 0 and use_type == 1 then
  88. self.model:Fire(GodConst.REQ_ACTIVITY_PLAY,GodConst.ActivityType.Common, use_type == 1 and 1 or 2,0)
  89. return
  90. end
  91. if have_num >= need_num then
  92. self.model:Fire(GodConst.REQ_ACTIVITY_PLAY,GodConst.ActivityType.Common, use_type == 1 and 1 or 2,0)
  93. else
  94. local function yes_call( )
  95. self.model:Fire(GodConst.REQ_ACTIVITY_PLAY,GodConst.ActivityType.Common, use_type == 1 and 1 or 2,1)
  96. end
  97. local price = GoodsModel:getInstance():GetGoodsPrice(self.model.acitvity_cost_id)
  98. local need_cost = price * (need_num - have_num)
  99. local have_money = RoleManager.Instance.mainRoleInfo:GetRealJin()
  100. local good_name = GoodsModel:getInstance():getGoodsName(self.model.acitvity_cost_id,true)
  101. local content = string.format( "<color=#fdffc2>%s</color> 购买 %sx%d 召唤 %s 次神座", need_cost,good_name,need_num - have_num,use_type )
  102. if self.model.isAutoBuyActivityCommon then
  103. yes_call()
  104. else
  105. function toggle_function( flag )
  106. self.model.isAutoBuyActivityCommon = flag
  107. end
  108. --需要显示购买提示界面
  109. local data = {
  110. titleText = "温馨提示",
  111. nameText = "",
  112. price = need_cost,
  113. okText = "确定",
  114. gold_res = "ui_momey_icon_1",--货币类型
  115. priceText = content,
  116. ok_callback = yes_call,
  117. toggle_function = toggle_function,
  118. nameText = "是否花费",
  119. insufficientText = "",
  120. }
  121. GlobalEventSystem:Fire(EventName.OPEN_COM_TOGGLE_TIP_VIEW, data)
  122. end
  123. end
  124. end
  125. function GodActivityCommonView:UpdateView( )
  126. local function call_backack( )
  127. if self._use_delete_method then return end
  128. self:UpdateBlessAwardList()
  129. self:RefreshMoney()
  130. self:RefreshRed()
  131. end
  132. TimeManager.GetInstance():StartTime("GodActivityCommonView_CheckRedDot", 0.2, call_backack)
  133. end
  134. function GodActivityCommonView:RefreshMoney( )
  135. local one_cost_conf = Config.Godkv["lottery_single"].value_content
  136. local ten_cost_conf = Config.Godkv["lottery_ten"].value_content
  137. one_cost_conf = stringtotable(one_cost_conf)[1]
  138. ten_cost_conf = stringtotable(ten_cost_conf)[1]
  139. local goods_id = one_cost_conf[2]
  140. local goods_num = GoodsModel:getInstance():GetTypeGoodsNum( goods_id )
  141. -- if goods_num > 0 then
  142. local goods_icon = GoodsModel:getInstance():GetGoodsBasicByTypeId( goods_id ).goods_icon
  143. lua_resM:setOutsideImageSprite(self,self.icon_money_ten_img,GameResPath.GetGoodsIcon(goods_icon),true)
  144. lua_resM:setOutsideImageSprite(self,self.icon_money_one_img,GameResPath.GetGoodsIcon(goods_icon),true)
  145. self.lb_money_one_tmp.text = "x" .. one_cost_conf[3]
  146. self.lb_money_ten_tmp.text = "x" .. ten_cost_conf[3]
  147. -- else
  148. -- local price = GoodsModel:getInstance():GetGoodsPrice(goods_id)
  149. -- local goods_icon = GoodsModel:getInstance():GetGoodsBasicByTypeId( 100000 ).goods_icon
  150. -- lua_resM:setOutsideImageSprite(self,self.icon_money_rest_img,GameResPath.GetGoodsIcon(goods_icon),true)
  151. -- lua_resM:setOutsideImageSprite(self,self.icon_money_ten_img,GameResPath.GetGoodsIcon(goods_icon),true)
  152. -- lua_resM:setOutsideImageSprite(self,self.icon_money_one_img,GameResPath.GetGoodsIcon(goods_icon),true)
  153. -- self.lb_money_ten_tmp.text = price * one_cost_conf[3]
  154. -- self.lb_money_one_tmp.text = price * ten_cost_conf[3]
  155. -- self.lb_money_rest_tmp.text = WordManager:ConvertNum(RoleManager.Instance.mainRoleInfo.jin)
  156. -- end
  157. --宠物生活技能 每日免费抽奖一次
  158. local left_free_draw_times = self.model:GetGodLeftFreeDrawTimes()
  159. if left_free_draw_times > 0 then
  160. self.icon_money_one_obj:SetActive(false)
  161. self.lb_money_one_tmp.text = ""
  162. self.free_label_tmp.text = "本次免费"
  163. else
  164. self.icon_money_one_obj:SetActive(true)
  165. self.free_label_tmp.text = ""
  166. end
  167. end
  168. --累计奖励
  169. function GodActivityCommonView:UpdateBlessAwardList( )
  170. if not self.is_loaded then return end
  171. local base_data = self.model:GetActivityCommonInfo()
  172. if not base_data then return end
  173. local conf = self.model:GetCommonConfByPhase(base_data.phase)
  174. if not conf then return end
  175. -------------------------
  176. local blessing_award = stringtotable(conf.awards)--累计奖励
  177. -------------------------
  178. for i,v in ipairs(blessing_award) do
  179. self.list_item[i] = self.list_item[i] or self:CreateItem(GodActivityRewardItem, self["con_item_" .. i], self.layer_name)
  180. self.list_item[i]:SetData("common",v)
  181. end
  182. self.lb_all_time_tmp.text = string.format("累计次数:<color=#2CF86F>%d</color>",base_data.blessing)
  183. -------------------------
  184. end
  185. function GodActivityCommonView:SetPoolReward( )
  186. if not self.is_loaded then return end
  187. local base_data = self.model:GetActivityCommonInfo()
  188. if not base_data then return end
  189. -------------------------
  190. local show_list = {}
  191. local lv = RoleManager.Instance.mainRoleInfo.level
  192. for k,v in pairs(Config.Godnormalpool) do
  193. if (v.phase == base_data.phase or v.phase == 0) and v.need_lv <= lv and v.show ~= 0 then
  194. local temp = stringtotable(v.awards)[1]
  195. temp[4] = v.show
  196. table.insert( show_list, temp )
  197. end
  198. end
  199. local function sort_call( a,b )
  200. return a[4] < b[4]
  201. end
  202. table.sort( show_list, sort_call )
  203. self.award_item_con_1 = self.award_item_con_1 or self:AddUIComponent(UI.ItemListCreator)
  204. local item_data_list = {
  205. data_list = show_list,
  206. item_con = self.Content_1,
  207. scroll_view = self.scroll_1,
  208. obj_pool_type = UIObjPool.UIType.AwardItem,
  209. item_width = 88,
  210. item_height = 88,
  211. start_x = 15,
  212. start_y = -11,
  213. space_x = 6,
  214. space_y = 1,
  215. create_frequency = 0.01,
  216. alignment = UnityEngine.TextAnchor.UpperLeft,
  217. on_update_item = function(item, i, v)
  218. item:IsNeedShowSeries(true)
  219. item:SetDataWithMapId(v[2], 0, v[1])
  220. item:SetItemSize(84, 84)
  221. end,
  222. }
  223. self.award_item_con_1:UpdateItems(item_data_list)
  224. end
  225. function GodActivityCommonView:SetLeftReward( )
  226. local conf = GodConst.ActivityCommonShowConf
  227. for i=1,#conf do
  228. local basic = GoodsModel:getInstance():GetGoodsBasicByTypeId( conf[i].id )
  229. if basic then
  230. lua_resM:setOutsideImageSprite(self,self["goods_show_" .. i .. "_img"],GameResPath.GetGoodsIcon(basic.goods_icon),true)
  231. end
  232. end
  233. end
  234. function GodActivityCommonView:SetData( data )
  235. self.data = data
  236. if self.is_loaded then
  237. self.need_refreshData = false
  238. self:UpdateView()
  239. else
  240. self.need_refreshData = true
  241. end
  242. end
  243. function GodActivityCommonView:ShowDrawEffect( pool_type, draw_type, result_data )
  244. if not self.is_loaded then return end
  245. self.delay_show_reward = function()
  246. if self.delay_result_id then
  247. GlobalTimerQuest:CancelQuest(self.delay_result_id)
  248. self.delay_result_id = nil
  249. end
  250. self.model:Fire(GodConst.OPEN_ACTIVITY_RESULT_VIEW, result_data )
  251. self.model.draw_ing = false
  252. if self._use_delete_method then return end
  253. self.click_mask_obj:SetActive(false)
  254. end
  255. self.model.draw_ing = true
  256. self.delay_result_id = setTimeout(self.delay_show_reward,3.5)
  257. local data = {
  258. name = "ui_shenzuochoujiang",
  259. scale = 1.5,
  260. pos = co.TempVector2(80, 95),
  261. -- pos = co.TempVector2(135, 95),
  262. time = 3.25,
  263. }
  264. self.model:Fire(GodConst.OPEN_ACTIVITY_EFFECT_VIEW,data)
  265. end
  266. function GodActivityCommonView:__delete( )
  267. self.model.draw_ing = false
  268. CustomActivityModel:getInstance():SetGoodsCanFly(true)
  269. if self.delay_result_id then
  270. GlobalTimerQuest:CancelQuest(self.delay_result_id)
  271. self.delay_result_id = nil
  272. -------------------------
  273. if self.delay_show_reward then
  274. local function delay( )
  275. self.delay_show_reward()
  276. end
  277. setTimeout(delay,0.2)
  278. end
  279. end
  280. end