源战役客户端
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.

439 lines
15 KiB

  1. GodActivityLimitView = GodActivityLimitView or BaseClass(BaseItem)
  2. local GodActivityLimitView = GodActivityLimitView
  3. -- GodActivityLimitView.Width = 200
  4. -- GodActivityLimitView.Height = 90
  5. local FILL_VALUE = {
  6. [1] = 0.21,
  7. [2] = 0.4,
  8. [3] = 0.58,
  9. [4] = 0.77,
  10. [5] = 1,
  11. }
  12. function GodActivityLimitView:__init(parent_wnd,prefab_asset,layer_name)
  13. self.base_file = "godActivity"
  14. self.layout_file = "GodActivityLimitView"
  15. self.layer_name = layer_name
  16. self.model = GodModel:getInstance()
  17. self.per_start = 0.085
  18. self.per_end = 0.915
  19. self.all_per = self.per_end - self.per_start
  20. self.full_screen = true
  21. self.ani_right = 400
  22. self.adjust_mid = {left = 257, right = 800}
  23. self:Load()
  24. self.model:Fire(GodConst.REQ_ACTIVITY_LIMIT_INFO)
  25. CustomActivityModel:getInstance():SetGoodsCanFly(false)
  26. end
  27. function GodActivityLimitView:Load_callback()
  28. self.nodes = {
  29. "icon_money_ten:img", "icon_money_one:img:obj",
  30. "lb_money_ten:tmp", "lb_money_one:tmp",
  31. "img_ad_des:img", "con_model",
  32. "lb_all_time:tmp", "model_click:obj",
  33. "img_per:img", "lb_per:tmp", "red_one:obj","red_bd:obj",
  34. "btn_tip:obj", "btn_one:obj", "btn_ten:obj", "btn_one/lb_btn_one:tmp", "btn_ten/lb_btn_ten:tmp",
  35. "con_extra_item", "scroll_1",
  36. "scroll_1/Viewport/Content_1",
  37. "bg_1:raw","bg_2:raw","bg_3:raw","bg_4:raw","click_mask:obj",
  38. "con_item_5", "con_item_2", "con_item_4", "con_item_3", "con_item_1",
  39. -- "btn_reward_detail:obj",
  40. "di_bg:raw", "bg:raw", "fill_img:img",
  41. "btn_see_more:obj",
  42. "lb_ac_time:tmp",
  43. "free_label:tmp",
  44. }
  45. self:GetChildren(self.nodes)
  46. self:AddEvents()
  47. SetAnchoredPosition(self.con_model, -65 - 30, 41 + 15)
  48. self.lb_btn_one_tmp.text = "单次召唤"
  49. self.lb_btn_ten_tmp.text = "十回召唤"
  50. self:UpdateView()
  51. self:SetPoolReward()
  52. -- lua_resM:setOutsideRawImage(self,self.bg_1_raw,"/client/assets/icon/god/bg/god_draw_bg_5.png")
  53. -- lua_resM:setOutsideRawImage(self,self.bg_2_raw,"/client/assets/icon/god/bg/god_draw_bg_6.png")
  54. -- lua_resM:setOutsideRawImage(self,self.bg_3_raw,"/client/assets/icon/god/bg/god_draw_bg_7.png")
  55. -- lua_resM:setOutsideRawImage(self,self.bg_4_raw,"/client/assets/icon/god/bg/god_draw_bg_8.png")
  56. lua_resM:setOutsideRawImage(self,self.bg_raw, GameResPath.GetGodBg( "god_ac_bg" ) )
  57. lua_resM:setOutsideRawImage(self,self.di_bg_raw, GameResPath.GetGodBg( "god_ac_bg2" ) )
  58. end
  59. function GodActivityLimitView:RefreshRed( )
  60. if self.is_loaded then
  61. --宠物生活技能 每日免费抽奖一次
  62. local left_free_draw_times = self.model:GetGodLeftFreeDrawTimes()
  63. local free_red = left_free_draw_times > 0
  64. local num = GoodsModel:getInstance():GetTypeGoodsNum(self.model.acitvity_cost_id)
  65. self.red_one_obj:SetActive(num > 0 or free_red)
  66. end
  67. end
  68. function GodActivityLimitView:AddEvents( )
  69. local function call_back( target )
  70. if target == self.btn_tip_obj then
  71. EventSystem.Fire(GlobalEventSystem,EventName.OPEN_INSTRUCTION_VIEW, 173 .. "@" .. 91)
  72. elseif target == self.btn_one_obj then
  73. self:StartGo(1)
  74. elseif target == self.btn_ten_obj then
  75. self:StartGo(10)
  76. elseif target == self.model_click_obj then
  77. local base_data = self.model:GetActivityLimitInfo()
  78. if not base_data then return end
  79. local conf = self.model:GetLimitConfByPhase(base_data.phase)
  80. if not conf then return end
  81. GodModel:getInstance():Fire(GodConst.OPEN_GOD_INFO_VIEW,tonumber(conf.god_id))
  82. elseif target == self.btn_reward_detail_obj then
  83. local show_list = {}
  84. local lv = RoleManager.Instance.mainRoleInfo.level
  85. for k,v in pairs(Config.Godlimitpool) do
  86. if (v.phase == base_data.phase or v.phase == 0) and v.need_lv <= lv then
  87. local temp = stringtotable(v.awards)[1]
  88. temp[4] = v.is_show
  89. table.insert( show_list, temp )
  90. end
  91. end
  92. local function sort_call( a,b )
  93. return a[4] < b[4]
  94. end
  95. table.sort( show_list, sort_call )
  96. elseif target == self.btn_see_more_obj then
  97. self.model:Fire(GodConst.OPEN_PREVIEW_VIEW, true)
  98. end
  99. end
  100. AddClickEvent(self.btn_tip_obj,call_back,false)
  101. AddClickEvent(self.btn_one_obj,call_back,false)
  102. AddClickEvent(self.btn_ten_obj,call_back,false)
  103. AddClickEvent(self.model_click_obj,call_back,false)
  104. AddClickEvent(self.btn_reward_detail_obj,call_back,false)
  105. AddClickEvent(self.btn_see_more_obj,call_back,false)
  106. local function ANS_ACTIVITY_LIMIT_INFO( )
  107. self:UpdateView()
  108. end
  109. self:BindEvent(self.model, GodConst.ANS_ACTIVITY_LIMIT_INFO, ANS_ACTIVITY_LIMIT_INFO)
  110. local function on_update_red_dot( )
  111. self:RefreshRed()
  112. self:RefreshMoney()
  113. end
  114. self:BindEvent(self.model, GodConst.UpdateRedDot, on_update_red_dot)
  115. local function ANS_ACTIVITY_PLAY( pool_type, draw_type, result_data )
  116. --抽奖完成,显示抽奖特效
  117. if pool_type == GodConst.ActivityType.Limit then
  118. self:ShowDrawEffect(pool_type, draw_type, result_data)
  119. self.click_mask_obj:SetActive(true)
  120. end
  121. end
  122. self:BindEvent(self.model, GodConst.ANS_ACTIVITY_PLAY, ANS_ACTIVITY_PLAY)
  123. end
  124. function GodActivityLimitView:SetPoolReward( )
  125. if not self.is_loaded then return end
  126. local base_data = self.model:GetActivityLimitInfo()
  127. if not base_data then return end
  128. -------------------------
  129. local show_list = {}
  130. local lv = RoleManager.Instance.mainRoleInfo.level
  131. for k,v in pairs(Config.Godlimitpool) do
  132. if (v.phase == base_data.phase or v.phase == 0) and v.need_lv <= lv and v.is_show ~= 0 then
  133. local temp = stringtotable(v.awards)[1]
  134. temp[4] = v.is_show
  135. table.insert( show_list, temp )
  136. end
  137. end
  138. local function sort_call( a,b )
  139. return a[4] < b[4]
  140. end
  141. table.sort( show_list, sort_call )
  142. self.award_item_con_1 = self.award_item_con_1 or self:AddUIComponent(UI.ItemListCreator)
  143. local item_data_list = {
  144. data_list = show_list,
  145. item_con = self.Content_1,
  146. scroll_view = self.scroll_1,
  147. obj_pool_type = UIObjPool.UIType.AwardItem,
  148. item_width = 78,
  149. item_height = 78,
  150. start_x = 10,
  151. start_y = -10,
  152. space_x = 10,
  153. space_y = 10,
  154. create_frequency = 0.01,
  155. alignment = UnityEngine.TextAnchor.UpperLeft,
  156. on_update_item = function(item, i, v)
  157. item:IsNeedShowSeries(true)
  158. item:SetDataWithMapId(v[2], 0, v[1])
  159. item:SetItemSize(78, 78)
  160. end,
  161. }
  162. self.award_item_con_1:UpdateItems(item_data_list)
  163. end
  164. function GodActivityLimitView:StartGo( use_type )
  165. local conf_tag = use_type == 1 and "lottery_single" or "lottery_ten"
  166. local have_num = GoodsModel:getInstance():GetTypeGoodsNum(self.model.acitvity_cost_id)
  167. local one_cost_conf = Config.Godkv[conf_tag].value_content
  168. local need_num = stringtotable(one_cost_conf)[1][3]
  169. --宠物生活技能
  170. local left_free_draw_times = self.model:GetGodLeftFreeDrawTimes()
  171. if left_free_draw_times > 0 and use_type == 1 then
  172. self.model:Fire(GodConst.REQ_ACTIVITY_PLAY, use_type == 1 and 1 or 2,0)
  173. return
  174. end
  175. if have_num >= need_num then
  176. self.model:Fire(GodConst.REQ_ACTIVITY_PLAY, use_type == 1 and 1 or 2,0)
  177. else
  178. local function yes_call( )
  179. self.model:Fire(GodConst.REQ_ACTIVITY_PLAY, use_type == 1 and 1 or 2,1)
  180. end
  181. local price = GoodsModel:getInstance():GetGoodsPrice(self.model.acitvity_cost_id)
  182. local need_cost = price * (need_num - have_num)
  183. local have_money = RoleManager.Instance.mainRoleInfo:GetRealJin()
  184. local good_name = GoodsModel:getInstance():getGoodsName(self.model.acitvity_cost_id,true)
  185. local content = string.format( "<color=#fdffc2>%s</color> 购买 %sx%s 召唤 %s 次神座", need_cost,good_name,need_num - have_num,use_type )
  186. if self.model.isAutoBuyActivityLimit then
  187. yes_call()
  188. else
  189. local function toggle_function( flag )
  190. self.model.isAutoBuyActivityLimit = flag
  191. end
  192. --需要显示购买提示界面
  193. local data = {
  194. titleText = "温馨提示",
  195. nameText = "",
  196. price = need_cost,
  197. okText = "确定",
  198. gold_res = "ui_momey_icon_1",--货币类型
  199. priceText = content,
  200. ok_callback = yes_call,
  201. toggle_function = toggle_function,
  202. nameText = "是否花费",
  203. insufficientText = "",
  204. }
  205. GlobalEventSystem:Fire(EventName.OPEN_COM_TOGGLE_TIP_VIEW, data)
  206. end
  207. end
  208. end
  209. function GodActivityLimitView:UpdateView( )
  210. local function call_backack( )
  211. if self._use_delete_method then return end
  212. self:UpdateCountAward()
  213. self:UpdateBlessAwardList()
  214. self:RefreshModel()
  215. self:RefreshMoney()
  216. self:RefreshRed()
  217. end
  218. TimeManager.GetInstance():StartTime("GodActivityLimitView_CheckRedDot", 0.2, call_backack)
  219. self:UpdateTime( )
  220. end
  221. function GodActivityLimitView:RefreshMoney( )
  222. local one_cost_conf = Config.Godkv["lottery_single"].value_content
  223. local ten_cost_conf = Config.Godkv["lottery_ten"].value_content
  224. one_cost_conf = stringtotable(one_cost_conf)[1]
  225. ten_cost_conf = stringtotable(ten_cost_conf)[1]
  226. local goods_id = one_cost_conf[2]
  227. local goods_num = GoodsModel:getInstance():GetTypeGoodsNum( goods_id )
  228. -- if goods_num > 0 then
  229. local goods_icon = GoodsModel:getInstance():GetGoodsBasicByTypeId( goods_id ).goods_icon
  230. lua_resM:setOutsideImageSprite(self,self.icon_money_ten_img,GameResPath.GetGoodsIcon(goods_icon),false)
  231. lua_resM:setOutsideImageSprite(self,self.icon_money_one_img,GameResPath.GetGoodsIcon(goods_icon),false)
  232. self.lb_money_one_tmp.text = "x" .. one_cost_conf[3]
  233. self.lb_money_ten_tmp.text = "x" .. ten_cost_conf[3]
  234. -- else
  235. -- local price = GoodsModel:getInstance():GetGoodsPrice(goods_id)
  236. -- local goods_icon = GoodsModel:getInstance():GetGoodsBasicByTypeId( 100000 ).goods_icon
  237. -- lua_resM:setOutsideImageSprite(self,self.icon_money_rest_img,GameResPath.GetGoodsIcon(goods_icon),true)
  238. -- lua_resM:setOutsideImageSprite(self,self.icon_money_ten_img,GameResPath.GetGoodsIcon(goods_icon),true)
  239. -- lua_resM:setOutsideImageSprite(self,self.icon_money_one_img,GameResPath.GetGoodsIcon(goods_icon),true)
  240. -- self.lb_money_ten_tmp.text = price * one_cost_conf[3]
  241. -- self.lb_money_one_tmp.text = price * ten_cost_conf[3]
  242. -- self.lb_money_rest_tmp.text = WordManager:ConvertNum(RoleManager.Instance.mainRoleInfo.jin)
  243. -- end
  244. --宠物生活技能 每日免费抽奖一次
  245. local left_free_draw_times = self.model:GetGodLeftFreeDrawTimes()
  246. if left_free_draw_times > 0 then
  247. self.icon_money_one_obj:SetActive(false)
  248. self.lb_money_one_tmp.text = ""
  249. self.free_label_tmp.text = "本次免费"
  250. else
  251. self.icon_money_one_obj:SetActive(true)
  252. self.free_label_tmp.text = ""
  253. end
  254. end
  255. function GodActivityLimitView:RefreshModel( force )
  256. if force then self.model_show_id = false end
  257. if not self.is_loaded then return end
  258. local base_data = self.model:GetActivityLimitInfo()
  259. if not base_data then return end
  260. local conf = self.model:GetLimitConfByPhase(base_data.phase)
  261. if not conf then return end
  262. local res_id = self.model:GetGodShowModelResID(conf.god_id)
  263. if res_id ~= self.model_show_id then
  264. local res_data = {
  265. father_node = self,
  266. transform = self.con_model,
  267. fashion_type = FuncOpenModel.TypeId.God,
  268. raycast_size = Vector2(0,0),
  269. figure_id = res_id,
  270. position = Vector3(0,-300,-500),
  271. size = Vector2(720,720),
  272. scale = 135,
  273. layer_name = self.layer_name,
  274. ui_model_type = UIModelCommon.ModelType.Model,
  275. }
  276. FuncOpenModel:getInstance():SetModelRes(res_data)
  277. self.model_show_id = res_id
  278. end
  279. -------------------------
  280. lua_resM:setOutsideImageSprite(self,self.img_ad_des_img, "/client/assets/icon/godActivity/godActivity_ad_"..conf.god_id..".png" ,true)
  281. end
  282. --保底奖励
  283. function GodActivityLimitView:UpdateCountAward( )
  284. if not self.is_loaded then return end
  285. local base_data = self.model:GetActivityLimitInfo()
  286. if not base_data then return end
  287. local conf = self.model:GetLimitConfByPhase(base_data.phase)
  288. if not conf then return end
  289. local count_award = stringtotable(conf.count_award)
  290. local last_get = 0
  291. for k,v in pairs(base_data.counts_award) do
  292. last_get = last_get < v.award_id and v.award_id or last_get
  293. end
  294. local show_info = false--当前需要展示的数据
  295. for i,v in ipairs(count_award) do
  296. if v[1] > last_get then
  297. show_info = v
  298. break
  299. end
  300. end
  301. if not show_info then return end
  302. self.award_count = self.award_count or UIObjPool:getInstance():PopItem(UIObjPool.UIType.AwardItem,self.con_extra_item)
  303. self.award_count:SetItemSize(78,78)
  304. self.award_count:SetPosition(0,1.5)
  305. self.award_count:SetDataWithMapId(show_info[3][1][2], show_info[3][1][3], show_info[3][1][1])
  306. local function call_back( )
  307. self.model:Fire(GodConst.REQ_ACTIVITY_GET_MIN_AWARD, tonumber(show_info[1]))
  308. end
  309. self.award_count:SetCallBack(call_back)
  310. -------------------------
  311. self.lb_per_tmp.text = base_data.counts .. "/" .. show_info[2]
  312. local per = base_data.counts/show_info[2]
  313. per = per > 1 and 1 or per
  314. self.red_bd_obj:SetActive(per == 1)
  315. -------------------------
  316. --进度条不完整,要特殊算
  317. per = per * self.all_per + self.per_start
  318. self.img_per_img.fillAmount = per
  319. end
  320. --累计奖励
  321. function GodActivityLimitView:UpdateBlessAwardList( )
  322. if not self.is_loaded then return end
  323. local base_data = self.model:GetActivityLimitInfo()
  324. if not base_data then return end
  325. local conf = self.model:GetLimitConfByPhase(base_data.phase)
  326. if not conf then return end
  327. -------------------------
  328. local blessing_award = stringtotable(conf.blessing_award)--累计奖励
  329. -------------------------
  330. self.list_item = self.list_item or {}
  331. self.fill_img_img.fillAmount = 0
  332. local function status_callback( index, is_match )
  333. if is_match then
  334. local new_value = FILL_VALUE[index]
  335. if new_value > self.fill_img_img.fillAmount then
  336. self.fill_img_img.fillAmount = new_value
  337. end
  338. end
  339. end
  340. for i,v in ipairs(blessing_award) do
  341. self.list_item[i] = self.list_item[i] or self:CreateItem(GodActivityRewardItem, self["con_item_" .. i], self.layer_name,"GodActivityRewardTwoItem")
  342. self.list_item[i]:SetData("limit",v, status_callback, i)
  343. end
  344. self.lb_all_time_tmp.text = string.format("累计次数:<color=#04bd27>%d</color>",base_data.blessing)
  345. end
  346. function GodActivityLimitView:SetData( data )
  347. self.data = data
  348. if self.is_loaded then
  349. self.need_refreshData = false
  350. self:UpdateView()
  351. else
  352. self.need_refreshData = true
  353. end
  354. end
  355. function GodActivityLimitView:ShowDrawEffect( pool_type, draw_type, result_data )
  356. if not self.is_loaded then return end
  357. self.delay_show_reward = function()
  358. if self.delay_result_id then
  359. GlobalTimerQuest:CancelQuest(self.delay_result_id)
  360. self.delay_result_id = nil
  361. end
  362. self.model:Fire(GodConst.OPEN_ACTIVITY_RESULT_VIEW, result_data )
  363. self.model.draw_ing = false
  364. if self._use_delete_method then return end
  365. self.click_mask_obj:SetActive(false)
  366. end
  367. self.model.draw_ing = true
  368. -- self.delay_result_id = setTimeout(self.delay_show_reward,3.5)
  369. local data = {
  370. name = "ui_shenzuochoujiang",
  371. scale = 1.5,
  372. pos = co.TempVector2(80, 50),
  373. time = 1,
  374. end_func = self.delay_show_reward,
  375. }
  376. self.model:Fire(GodConst.OPEN_ACTIVITY_EFFECT_VIEW,data)
  377. end
  378. -- 刷新活动持续日期
  379. function GodActivityLimitView:UpdateTime( )
  380. if not self.is_loaded then return end
  381. local base_data = self.model:GetActivityLimitInfo()
  382. if not base_data then return end
  383. local stime_str = TimeUtil:timeConversion(base_data.begin_time, "yyyy.mm.dd")
  384. local etime_str = TimeUtil:timeConversion(base_data.end_time, "yyyy.mm.dd")
  385. self.lb_ac_time_tmp.text = stime_str .. "~" .. etime_str
  386. end
  387. function GodActivityLimitView:__delete( )
  388. self.model.draw_ing = false
  389. CustomActivityModel:getInstance():SetGoodsCanFly(true)
  390. if self.delay_result_id then
  391. GlobalTimerQuest:CancelQuest(self.delay_result_id)
  392. self.delay_result_id = nil
  393. -------------------------
  394. if self.delay_show_reward then
  395. local function delay( )
  396. self.delay_show_reward()
  397. end
  398. setTimeout(delay,0.2)
  399. end
  400. end
  401. end