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

367 line
15 KiB

  1. -- <*
  2. -- @Author: Saber
  3. -- @Description: 圣物进阶页签界面
  4. -- *>
  5. PsionicAdvanceView = PsionicAdvanceView or BaseClass(BaseItem)
  6. local PsionicAdvanceView = PsionicAdvanceView
  7. function PsionicAdvanceView:__init(parent_wnd,prefab_asset,layer_name)
  8. self.base_file = "psionic"
  9. self.layout_file = "PsionicAdvanceView"
  10. self.parent_wnd = parent_wnd
  11. self.layer_name = layer_name
  12. self.star_list = {}
  13. self.attr_item = {}
  14. self.upgrade_need_num = 0 -- 本次升级需要的材料数
  15. self.upgrade_auto_buy = false -- 升阶自动购买
  16. self.last_slot_exp = 0
  17. self.last_slot_lv = 0
  18. self.is_animating = false -- 进度动画中
  19. self.model = PsionicModel:getInstance()
  20. self.goods_model = GoodsModel:getInstance()
  21. self:Load()
  22. end
  23. function PsionicAdvanceView:Load_callback()
  24. local nodes = {
  25. "upgrade_btn:obj",
  26. "upgrade_auto_btn:obj",
  27. "break_btn:obj",
  28. "ques_btn:obj",
  29. "progress_fill:img",
  30. "tips:tmp",
  31. -- 属性容器
  32. "attr_scroll", "attr_scroll/Viewport/attr_con",
  33. -- 等级,经验
  34. "level:tmp",
  35. "exp_val:tmp",
  36. -- 红点
  37. "upgrade_btn/upgrade_red:obj",
  38. "upgrade_auto_btn/upgrade_auto_red:obj",
  39. "break_btn/break_red:obj", "break_btn/break_btn_lb:tmp",
  40. "power:txt",
  41. -- 进阶素材容器
  42. "cost_item_con", "cost_item_name:tmp", "cost_item_num:tmp",
  43. "advance_lv_effect_con",
  44. }
  45. self:GetChildren(nodes)
  46. self.break_btn_lb_tmp.text = "前往突破"
  47. self.break_red_obj:SetActive(false)
  48. self.cost_item = UIObjPool:getInstance():PopItem(UIObjPool.UIType.AwardItem, self.cost_item_con)
  49. self.cost_item:SetAnchoredPosition(0, 0)
  50. self.cost_item:SetItemSize(62, 62)
  51. self.cost_item:SetVisible(false)
  52. self:AddEvents()
  53. if self.need_refreshData then
  54. self:UpdateView()
  55. end
  56. end
  57. -- 需特殊处理隐藏时的特效表现
  58. function PsionicAdvanceView:SetVisible(state, force_hide)
  59. BaseItem.SetVisible(self, state, force_hide)
  60. if not state then
  61. self:ClearUIEffect(self.advance_lv_effect_con)
  62. self.showing_lv_effect = false
  63. if self.attr_item_creator then
  64. self.attr_item_creator:IterateItems(function( item, i )
  65. self:ClearUIEffect(item.attr_effect_con)
  66. item.showing_attr_effect = false
  67. end)
  68. end
  69. end
  70. end
  71. function PsionicAdvanceView:AddEvents( )
  72. local function click_event(target, x, y)
  73. if target == self.upgrade_btn_obj then -- 升阶
  74. self:OnUpgradeBtnClick(false, false)
  75. elseif target == self.upgrade_auto_btn_obj then -- 一键升阶
  76. self:OnUpgradeBtnClick(false, true)
  77. elseif target == self.break_btn_obj then -- 突破
  78. if self.data then
  79. self.model:Fire(PsionicConst.OPEN_MAIN_VIEW, true, PsionicConst.TabId.PWash) -- 切换到洗练界面
  80. end
  81. -- self:OnUpgradeBtnClick(true)
  82. elseif target == self.ques_btn_obj then -- 问号
  83. GlobalEventSystem:Fire(EventName.OPEN_INSTRUCTION_VIEW, 13900)
  84. end
  85. end
  86. AddClickEvent(self.upgrade_btn_obj, click_event)
  87. AddClickEvent(self.upgrade_auto_btn_obj, click_event)
  88. AddClickEvent(self.break_btn_obj, click_event)
  89. AddClickEvent(self.ques_btn_obj, click_event)
  90. local function update_advance_red(tab_id)
  91. if not tab_id or tab_id == PsionicConst.TabId.PAdvance then
  92. self:UpdateLevelData(true) -- 有可能是道具刷新了,保险起见还是多刷新一次等级数据
  93. self:UpdateAdvanceRed()
  94. end
  95. end
  96. self:BindEvent(self.model, PsionicConst.UPDATE_RED_BY_TABID, update_advance_red)
  97. local function update_slot_data(pos)
  98. if pos and self.data and self.data.subtype == pos then
  99. self:UpdateView(true)
  100. end
  101. end
  102. self:BindEvent(self.model, PsionicConst.UPDATE_SLOT_DATA, update_slot_data)
  103. end
  104. -- 传入改装备的服务器数据 data:装备vo (GoodsModel:GetPsionicEquipBySlot)
  105. function PsionicAdvanceView:SetData( data )
  106. self.data = data
  107. if self.is_loaded then
  108. self.need_refreshData = false
  109. self:UpdateView()
  110. else
  111. self.need_refreshData = true
  112. end
  113. end
  114. function PsionicAdvanceView:UpdateView(show_exp_anim)
  115. -- self.upgrade_auto_buy = self.auto_buy_tog.isOn
  116. if self.data then
  117. self:UpdateLevelData(show_exp_anim)
  118. self:UpdateAttrItem(show_exp_anim)
  119. self:UpdateAdvanceRed()
  120. end
  121. end
  122. -- 更新等级信息
  123. function PsionicAdvanceView:UpdateLevelData(show_exp_anim)
  124. self.cur_equip_grade_cfg = self.model:GetPsionicEquipGradeCfg(self.data.type_id)
  125. self.slot_data = self.model:GetPsionicSlotData(self.data.subtype)
  126. self.cur_exp_cfg = Config.Nucleonlv[self.slot_data.lv]
  127. self.advance_cost_cfg = nil
  128. local next_lv = self.cur_exp_cfg.next
  129. self.next_exp_cfg = Config.Nucleonlv[next_lv]
  130. -- 存在下一等级且阶段相同,则可以直接升级,否则需要提示转到突破
  131. local has_next = next_lv ~= 0 and self.next_exp_cfg
  132. self:UpdateAdvanceProgress(show_exp_anim)
  133. -- 加载消费道具
  134. self.advance_cost_cfg = stringtotable(self.cur_exp_cfg.cost)[1]
  135. local typeId, lock = self.goods_model:GetMappingTypeId(self.advance_cost_cfg[1], self.advance_cost_cfg[2])
  136. local has_num = self.goods_model:GetTypeGoodsNum(typeId)
  137. self.cost_item:SetData(typeId, 0, nil, nil, lock)
  138. self.cost_item:SetVisible(true)
  139. self.cost_item_name_tmp.text = self.goods_model:getGoodsName(typeId, true, true)
  140. self.cost_item_num_tmp.text = string.format("剩余数量:<color=%s>%s</color>",
  141. has_num > 0 and ColorUtil.GREEN_DARK or ColorUtil.RED_DARK, has_num)
  142. local cost_goods_value = Config.Nucleonkv["nucleon_equip_value"].value
  143. local need_num = math.ceil((self.cur_exp_cfg.exp - self.slot_data.exp) / cost_goods_value)
  144. -- 缓存升级所需材料数
  145. self.upgrade_need_num = need_num
  146. -- 更新道具表现和按钮
  147. local is_exp_max = self.slot_data.exp >= self.cur_exp_cfg.exp
  148. local show_break = self.next_exp_cfg.grade > self.cur_exp_cfg.grade and is_exp_max or false
  149. self.upgrade_auto_btn_obj:SetActive(not show_break)
  150. self.upgrade_btn_obj:SetActive(not show_break)
  151. self.break_btn_obj:SetActive(has_next and show_break)
  152. end
  153. function PsionicAdvanceView:UpdateAdvanceProgress(show_anim)
  154. local next_lv = self.cur_exp_cfg.next -- 这里还需要判断是否已经满级
  155. local function final_result()
  156. self.level_tmp.text = string.format("Lv.%s", self.slot_data.lv)
  157. self.exp_val_tmp.text = next_lv == 0 and self.slot_data.exp == self.cur_exp_cfg.exp and "MAX"
  158. or string.format("%s / %s", self.slot_data.exp, self.cur_exp_cfg.exp)
  159. self.progress_fill_img.fillAmount = self.slot_data.exp / self.cur_exp_cfg.exp
  160. end
  161. if show_anim then
  162. if self.last_slot_exp == self.slot_data.exp and self.last_slot_lv == self.slot_data.lv then -- 经验和等级都没有变化,则啥也不做
  163. return
  164. end
  165. -- 文本的表现比较恶心,要做很多计算
  166. local temp_lv, temp_exp = self.last_slot_lv, self.last_slot_exp
  167. local need_exp, add_exp = 0, 0
  168. local target_lv, target_exp = self.slot_data.lv, self.slot_data.exp
  169. local lv_cfg
  170. for i = temp_lv, target_lv do
  171. if target_lv == temp_lv then
  172. add_exp = target_exp - temp_exp
  173. break
  174. end
  175. lv_cfg = Config.Nucleonlv[i]
  176. need_exp = need_exp + lv_cfg.exp
  177. if i == temp_lv then
  178. add_exp = add_exp + lv_cfg.exp - self.last_slot_exp
  179. elseif i == target_lv then
  180. add_exp = add_exp + target_exp
  181. else
  182. add_exp = add_exp + lv_cfg.exp
  183. end
  184. end
  185. -- 递归检测等级表现
  186. local function check_exp_lv(exp, lv)
  187. if exp >= Config.Nucleonlv[lv].exp then
  188. exp = exp - Config.Nucleonlv[lv].exp
  189. lv = lv + 1
  190. return check_exp_lv(exp, lv)
  191. end
  192. return exp, lv
  193. end
  194. local function duration_callback(percent)
  195. if percent < 1 then
  196. local exp, lv = check_exp_lv(temp_exp + add_exp * percent, temp_lv)
  197. self.level_tmp.text = string.format("Lv.%s", lv)
  198. self.exp_val_tmp.text = string.format("%s / %s", math.ceil(exp), Config.Nucleonlv[lv].exp)
  199. else -- 为1时直接使用协议数据
  200. final_result()
  201. end
  202. end
  203. local round = self.slot_data.lv - self.last_slot_lv
  204. local last_progress = self.slot_data.exp / self.cur_exp_cfg.exp
  205. local function end_callback()
  206. duration_callback(1)
  207. self.is_animating = false
  208. end
  209. -- 调用图片动画
  210. self.is_animating = true
  211. ImageProgressAction(self.progress_fill, round, last_progress, 0.5, duration_callback, end_callback)
  212. -- 播放经验条特效
  213. -- 进度条流光特效
  214. if not self.showing_lv_effect then
  215. local function call_back( )
  216. self.showing_lv_effect = false
  217. end
  218. self:ClearUIEffect(self.advance_lv_effect_con)
  219. self:AddUIEffect("ui_jinjiejindu", self.advance_lv_effect_con, self.layer_name, Vector3(-110,0,0), 1, false, 0.75, nil, call_back)
  220. self.showing_lv_effect = true
  221. end
  222. else
  223. -- 不做动画,直接使用协议数据
  224. final_result()
  225. end
  226. self.last_slot_exp = self.slot_data.exp
  227. self.last_slot_lv = self.slot_data.lv
  228. end
  229. -- 加载属性条目
  230. function PsionicAdvanceView:UpdateAttrItem(show_exp_anim)
  231. -- local has_next = self.next_exp_cfg and self.next_exp_cfg.grade == self.cur_exp_cfg.grade
  232. local has_next = self.next_exp_cfg and self.next_exp_cfg.next ~= 0 or false
  233. -- 更新战斗力表现
  234. self:UpdatePower(self.data.basic_attrs)
  235. self.attr_item_creator = self.attr_item_creator or self:AddUIComponent(UI.ItemListCreator)
  236. local info = {
  237. data_list = self.data.cfg_attrs,
  238. scroll_view = self.attr_scroll,
  239. item_con = self.attr_con,
  240. prefab_ab_name = "psionic",
  241. prefab_res_name = "PsionicAdvanceAttrItem",
  242. item_height = 30,
  243. create_frequency = 0.01,
  244. alignment = UnityEngine.TextAnchor.UpperLeft,
  245. child_names = {
  246. "attr_name:obj:tmp",
  247. "attr_val:obj:tmp",
  248. "attr_effect_con",
  249. },
  250. on_update_item = function(item, i, v)
  251. local attr_name = WordManager:GetProperties(v[1])
  252. -- 初始值要加上等级与等级成长的值
  253. local val = WordManager:GetPropertyValue(v[1], v[2] + v[3] * self.slot_data.lv)
  254. item.attr_name_tmp.text = attr_name
  255. if has_next then -- 存在下一级数据,展示提升
  256. local val_next = WordManager:GetPropertyValue(v[1], v[3])
  257. val = string.format("%s <color=%s>+%s</color>",
  258. val, ColorUtil.GREEN_DARK, val_next)
  259. end
  260. item.attr_val_tmp.text = val
  261. if show_exp_anim and not item.showing_attr_effect then
  262. local function call_back( )
  263. item.showing_attr_effect = false
  264. end
  265. self:ClearUIEffect(item.attr_effect_con)
  266. self:AddUIEffect("ui_jinjieshuxing", item.attr_effect_con, self.layer_name, Vector3(-175,0,0), 1, false, 0.75, nil, call_back)
  267. item.showing_attr_effect = true
  268. end
  269. end,
  270. }
  271. self.attr_item_creator:UpdateItems(info)
  272. end
  273. -- 更新战斗力以及自动对齐表现
  274. function PsionicAdvanceView:UpdatePower(attr_cur)
  275. local t_p_cur = GetFighting(attr_cur)
  276. self.power_txt.text = "f" .. (t_p_cur or 0)
  277. end
  278. function PsionicAdvanceView:UpdateAdvanceRed( )
  279. local slot_red = false
  280. if self.data then
  281. slot_red = self.model:GetPsionicAdvanceRed(self.data.subtype)
  282. if self.upgrade_auto_btn_obj.activeSelf then
  283. self.upgrade_auto_red_obj:SetActive(slot_red)
  284. end
  285. -- if self.break_btn_obj.activeSelf then
  286. -- self.break_red_obj:SetActive(slot_red)
  287. -- end
  288. end
  289. end
  290. -- 一键升阶按钮点击触发 needs_break:是否需要发送成槽位突破协议
  291. function PsionicAdvanceView:OnUpgradeBtnClick(needs_break, auto_lv)
  292. if not self.advance_cost_cfg then return end
  293. if self.is_animating then return end
  294. local cost_goods_id = self.advance_cost_cfg[2]
  295. local item_num = GoodsModel:getInstance():GetTypeGoodsNum(cost_goods_id)
  296. -- 槽位升级是否自动购买/是否自动升级
  297. local upgrade_auto_buy, upgrade_auto_lv = 0, auto_lv and 1 or 0
  298. local function ok_callback()
  299. if needs_break then
  300. self.model:Fire(PsionicConst.REQUEST_CCMD_EVENT, 13906, self.data.subtype)
  301. else
  302. self.model:Fire(PsionicConst.REQUEST_CCMD_EVENT, 13905, self.data.subtype, upgrade_auto_buy, upgrade_auto_lv)
  303. end
  304. end
  305. if self.upgrade_auto_buy then
  306. local function double_check_toggle_callback(flag)
  307. self.model._hide_double_check_advance_flag = flag
  308. end
  309. upgrade_auto_buy = 1
  310. upgrade_auto_lv = 1
  311. if item_num >= self.upgrade_need_num then -- 数量达到要求,直接发协议
  312. ok_callback()
  313. else
  314. upgrade_auto_buy = 1
  315. upgrade_auto_lv = 1
  316. if self.model._hide_double_check_advance_flag then
  317. ok_callback()
  318. return
  319. end
  320. local cost_cfg = Config.Goodsprice[cost_goods_id]
  321. local total_cost = (self.upgrade_need_num - item_num) * (cost_cfg and cost_cfg.price or 0)
  322. local priceText = string.format("<color=%s>%s</color> 彩钻自动补齐%s?", ColorUtil.YELLOW_DARK, total_cost, GoodsModel:getInstance():getGoodsName(cost_goods_id, true))
  323. local data = {
  324. insufficientText = "",
  325. price = total_cost,
  326. priceText = priceText,
  327. titleText = "提示",
  328. ok_callback = ok_callback,
  329. no_need_toggle = false,
  330. toggle_function = double_check_toggle_callback,
  331. }
  332. GlobalEventSystem:Fire(EventName.OPEN_COM_TOGGLE_TIP_VIEW, data)
  333. end
  334. else
  335. if item_num > 0 then
  336. ok_callback()
  337. else
  338. -- 没有自动购买的前提下,没有道具再弹出tips
  339. UIToolTipMgr:getInstance():AppendGoodsTips(cost_goods_id, x, y, nil, nil, nil, nil, true)
  340. end
  341. end
  342. end
  343. function PsionicAdvanceView:__delete( )
  344. if self.cost_item then
  345. UIObjPool:getInstance():PushItem(UIObjPool.UIType.AwardItem, self.cost_item)
  346. end
  347. self.cost_item = nil
  348. self:ClearUIEffect(self.advance_lv_effect_con)
  349. end