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

256 lines
10 KiB

  1. PsionicWashView = PsionicWashView or BaseClass(BaseItem)
  2. local PsionicWashView = PsionicWashView
  3. local SortAttrList = SortAttrList
  4. function PsionicWashView:__init(parent_wnd,prefab_asset,layer_name)
  5. self.base_file = "psionic"
  6. self.layout_file = "PsionicWashView"
  7. self.parent_wnd = parent_wnd
  8. self.layer_name = layer_name
  9. self.model = PsionicModel:getInstance()
  10. self.goods_model = GoodsModel:getInstance()
  11. self.wash_cfg = nil
  12. self:Load()
  13. end
  14. function PsionicWashView:Load_callback()
  15. local nodes = {
  16. "bg:raw",
  17. -- awardItem容器
  18. "equip_con", "cost_item_con",
  19. -- 按钮
  20. "break_btn:obj:img", "break_btn/break_btn_lb:tmp", "break_btn/break_red:obj",
  21. "wash_btn:obj:img", "wash_btn/wash_btn_lb:tmp", "wash_btn/wash_red:obj",
  22. -- 属性容器
  23. "attr_scroll",
  24. "attr_scroll/Viewport/attr_con",
  25. -- 战斗力节点
  26. "power_con",
  27. "power_con/power_lb1:tmp",
  28. "power_con/power_cur:txt",
  29. -- 消费节点描述
  30. "cost_item_name:tmp", "cost_item_num:tmp",
  31. -- 洗练装备描述
  32. "equip_lv:tmp", "equip_break_tip:tmp", "equip_lv_tip:tmp",
  33. }
  34. self:GetChildren(nodes)
  35. lua_resM:setOutsideRawImage(self, self.bg_raw, GameResPath.GetViewBigBg("ps_main_wash_bg"))
  36. self.equip_item = PsionicArmorItem.New(self.equip_con)
  37. self.equip_item:SetAnchoredPosition(0, 0)
  38. self.equip_item:SetVisible(false)
  39. self.cost_item = UIObjPool:getInstance():PopItem(UIObjPool.UIType.AwardItem, self.cost_item_con)
  40. self.cost_item:SetAnchoredPosition(0, 0)
  41. self.cost_item:SetItemSize(62, 62)
  42. self.cost_item:SetVisible(false)
  43. self:AddEvents()
  44. if self.need_refreshData then
  45. self:UpdateView()
  46. end
  47. end
  48. function PsionicWashView:AddEvents( )
  49. local function click_event(target)
  50. if target == self.break_btn_obj then
  51. self:OnBreakBtnClick()
  52. elseif target == self.wash_btn_obj then
  53. self:OnWashBtnClick()
  54. end
  55. end
  56. AddClickEvent(self.break_btn_obj, click_event)
  57. AddClickEvent(self.wash_btn_obj, click_event)
  58. local function update_wash_data(pos, reports) -- 洗练或突破成功时刷新
  59. if not pos or self.goods_vo and self.goods_vo.subtype == pos then
  60. self:UpdateWashInfo() -- 加载槽位洗练信息
  61. -- self:UpdateWashCostItem()
  62. self:UpdateEquipWashAttr() -- 加载装备洗练属性信息
  63. -- self:UpdateWashAndBreakRed() -- 更新红点
  64. end
  65. end
  66. self:BindEvent(self.model, PsionicConst.UPDATE_SLOT_WASH_DATA, update_wash_data)
  67. local function update_wash_btn_red(tab_id)
  68. if tab_id and tab_id == PsionicConst.TabId.PWash then
  69. self:UpdateWashCostItem()
  70. self:UpdateWashAndBreakRed() -- 更新红点
  71. end
  72. end
  73. self:BindEvent(self.model, PsionicConst.UPDATE_RED_BY_TABID, update_wash_btn_red)
  74. end
  75. -- 需传入当前装备vo
  76. function PsionicWashView:SetData( goods_vo )
  77. self.goods_vo = goods_vo
  78. if self.is_loaded then
  79. self.need_refreshData = false
  80. self:UpdateView()
  81. else
  82. self.need_refreshData = true
  83. end
  84. end
  85. function PsionicWashView:UpdateView( )
  86. if self.goods_vo then
  87. -- 如今洗练属性跟槽位绑定,不跟装备
  88. self.slot_data = self.model:GetPsionicSlotData(self.goods_vo.subtype)
  89. self:UpdateBasicInfo() -- 加载装备基础信息
  90. self:UpdateWashInfo() -- 加载槽位洗练信息
  91. self:UpdateWashCostItem() -- 加载槽位洗练花费
  92. self:UpdateEquipWashAttr() -- 加载装备洗练属性信息
  93. end
  94. self:UpdateWashAndBreakRed()
  95. end
  96. -- 加载装备基础信息
  97. function PsionicWashView:UpdateBasicInfo( )
  98. -- 展示当前装备
  99. self.equip_item:SetData(self.goods_vo, PsionicConst.ArmorItemFlag.Show)
  100. self.equip_item:SetVisible(true)
  101. end
  102. -- 加载槽位洗练信息
  103. function PsionicWashView:UpdateWashInfo( )
  104. if self.slot_data then
  105. -- 洗练配置
  106. self.wash_cfg = self.model:GetPsionicWashCfg(self.goods_vo.subtype, self.slot_data.grade)
  107. local stage_max_lv, max_stage = self.model:GetPsionicSlotStageMaxLevel(self.slot_data.grade)
  108. self.equip_lv_tmp.text = string.format("等级:<color=%s>%s</color>/%s", ColorUtil.GREEN_DARK,
  109. self.slot_data.lv, stage_max_lv)
  110. if max_stage > self.slot_data.grade then -- 还没有到达最终阶段
  111. local lv_data = Config.Nucleonlv[self.slot_data.lv]
  112. local slot_can_break = stage_max_lv <= self.slot_data.lv and self.slot_data.exp >= lv_data.exp -- 当前槽位已达到阶段满级满经验
  113. -- 达到突破条件
  114. if slot_can_break then
  115. local next_max_lv = self.model:GetPsionicSlotStageMaxLevel(self.slot_data.grade + 1) -- 获取下一阶段的最高等级
  116. self.equip_lv_tip_tmp.text = string.format("突破后 <color=%s>等级上限拓展至%s</color>", ColorUtil.GREEN_DARK, next_max_lv)
  117. else
  118. self.equip_lv_tip_tmp.text = string.format("圣物升级到满级后 <color=%s>可突破</color>", ColorUtil.GREEN_DARK)
  119. end
  120. -- 设置突破所需属性条件
  121. self.equip_break_tip_tmp.text = string.format("至少 <color=%s>1条属性洗练满值</color> 可突破", ColorUtil.GREEN_DARK)
  122. else
  123. self.equip_lv_tip_tmp.text = "当前开放等级已达上限"
  124. self.equip_break_tip_tmp.text = "当前突破阶段已达上限"
  125. end
  126. end
  127. end
  128. function PsionicWashView:UpdateWashCostItem( )
  129. if self.slot_data then
  130. -- 设置洗练花费
  131. local cost_data = self.wash_cfg.cost[1]
  132. local typeId, lock = self.goods_model:GetMappingTypeId(cost_data[1], cost_data[2])
  133. self.cost_item:SetData(typeId, 0, nil, nil, lock)
  134. self.cost_item:SetVisible(true)
  135. local has_num = self.goods_model:GetTypeGoodsNum(typeId)
  136. self.cost_item_name_tmp.text = self.goods_model:getGoodsName(typeId, true, true)
  137. self.cost_item_num_tmp.text = string.format("需求数量:<color=%s>%s</color>/%s",
  138. cost_data[3] <= has_num and ColorUtil.GREEN_DARK or ColorUtil.RED_DARK,
  139. has_num, cost_data[3])
  140. end
  141. end
  142. function PsionicWashView:UpdateEquipWashAttr( )
  143. -- 协议属性
  144. local attr_list, attr_id_list = {}, {}
  145. for k, v in pairs(self.slot_data.attrs) do
  146. attr_list[#attr_list+1] = {[1] = v.attr_id, [2] = v.attr_value}
  147. attr_id_list[v.attr_id] = v.attr_value
  148. end
  149. -- 创建属性节点
  150. self.attr_item_creator = self.attr_item_creator or self:AddUIComponent(UI.ItemListCreator)
  151. local info = {
  152. data_list = self.wash_cfg.maxs, -- 使用满级属性列表的数据作为节点数据
  153. scroll_view = self.attr_scroll,
  154. item_con = self.attr_con,
  155. item_class = PsionicWashAttrItem,
  156. item_height = 50,
  157. start_x = -2,
  158. start_y = -3,
  159. create_frequency = 0.01,
  160. alignment = UnityEngine.TextAnchor.UpperLeft,
  161. on_update_item = function(item, i, v)
  162. local attr_id = v[1]
  163. local cur_val = attr_id_list[attr_id] or 0
  164. item:SetData(self.goods_vo.subtype, v, cur_val)
  165. end,
  166. }
  167. self.attr_item_creator:UpdateItems(info)
  168. -- 更新战斗力
  169. self.power_cur_txt.text = GetFighting(attr_list)
  170. local total_len = self.power_lb1_tmp.preferredWidth + self.power_cur_txt.preferredWidth
  171. local offset_x = (self.power_con.sizeDelta.x - total_len) / 2
  172. SetAnchoredPositionX(self.power_lb1, offset_x)
  173. SetAnchoredPositionX(self.power_cur, offset_x + self.power_lb1_tmp.preferredWidth + 5)
  174. end
  175. -- 突破按钮
  176. function PsionicWashView:OnBreakBtnClick( )
  177. if self.goods_vo then
  178. self.model:Fire(PsionicConst.REQUEST_CCMD_EVENT, 13906, self.goods_vo.subtype)
  179. -- self.model:Fire(PsionicConst.OPEN_MAIN_VIEW, true, PsionicConst.TabId.PAdvance) -- 切换到升级突破界面
  180. end
  181. end
  182. -- 洗练按钮
  183. function PsionicWashView:OnWashBtnClick( )
  184. if self.goods_vo and self.wash_cfg then
  185. --先判断宠物生活技能 如果有免费次数 直接发协议
  186. local wash_red = self.goods_vo and self.model:GetPsionicWashSlotRed(self.goods_vo.subtype) or false
  187. local left_free_wash_times = self.model:GetPsionicFreeWashTimes()
  188. if left_free_wash_times > 0 and wash_red then--如果是词条满了那红点必是false,那么免费洗练也不用判断
  189. self.model:Fire(PsionicConst.REQUEST_CCMD_EVENT, 13909, self.goods_vo.subtype) -- 发送洗练协议
  190. return
  191. end
  192. local cost_data = self.wash_cfg.cost[1]
  193. local typeId, lock = self.goods_model:GetMappingTypeId(cost_data[1], cost_data[2])
  194. local has_num = self.goods_model:GetTypeGoodsNum(typeId)
  195. if has_num > 0 then
  196. self.model:Fire(PsionicConst.REQUEST_CCMD_EVENT, 13909, self.goods_vo.subtype) -- 发送洗练协议
  197. else
  198. UIToolTipMgr:getInstance():AppendGoodsTips(typeId, x, y, nil, nil, nil, nil, true)
  199. end
  200. end
  201. end
  202. -- 更新洗练和突破的红点
  203. function PsionicWashView:UpdateWashAndBreakRed( )
  204. local break_red = self.goods_vo and self.model:GetPsionicWashSlotBreakRed(self.goods_vo.subtype) or false
  205. self.break_red_obj:SetActive(break_red)
  206. SetImageGray(self.break_btn_img, not break_red)
  207. SetTMPSharedMaterial(self.break_btn_lb_tmp,
  208. break_red and ShaderTools.TMPSharedMaterialType.FZZZOutlineDarkOrangeBtn
  209. or ShaderTools.TMPSharedMaterialType.FZZZOutlineDarkGrayBtn)
  210. local wash_red = self.goods_vo and self.model:GetPsionicWashSlotRed(self.goods_vo.subtype) or false
  211. self.wash_red_obj:SetActive(wash_red)
  212. SetImageGray(self.wash_btn_img, not wash_red)
  213. SetTMPSharedMaterial(self.wash_btn_lb_tmp,
  214. wash_red and ShaderTools.TMPSharedMaterialType.FZZZOutlineDarkOrangeBtn
  215. or ShaderTools.TMPSharedMaterialType.FZZZOutlineDarkGrayBtn)
  216. --宠物生活技能多加一次免费洗练
  217. local left_free_wash_times = self.model:GetPsionicFreeWashTimes()
  218. if left_free_wash_times > 0 and wash_red then--如果是词条满了那红点必是false,那么免费洗练也不用判断
  219. self.wash_btn_lb_tmp.text = "免费洗练"
  220. else
  221. self.wash_btn_lb_tmp.text = "洗练"
  222. end
  223. end
  224. function PsionicWashView:__delete( )
  225. if self.equip_item then
  226. self.equip_item:DeleteMe()
  227. self.equip_item = nil
  228. end
  229. if self.cost_item then
  230. UIObjPool:getInstance():PushItem(UIObjPool.UIType.AwardItem, self.cost_item)
  231. end
  232. self.cost_item = nil
  233. end