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

442 lines
13 KiB

EquipItem = EquipItem or BaseClass(BaseItem)
function EquipItem:__init(parent_wnd, prefab_asset, layer_name, is_bag)
self.base_file = "bag"
self.layout_file = "EquipItem"
self.is_delay_callback = true
self.is_bag = is_bag or false --is_bag 是否用于背包界面中
self.model = EquipModel:getInstance()
self.mainVo = RoleManager.Instance.mainRoleInfo
self.only_show_strength_tag = false --是否仅显示可精炼标识
self.pos_type = false
self.pos_type_visible = false
self.default_conta_show = false
self.series = false
self.bg_alpha = 1
self.showing_effect = false
self.will_show_effect = false
self.init_guide_event = false
--self.use_local_view = true
self:Load()
end
function EquipItem:Load_callback()
self.equip_conta,self.canStren,self.effect_con = GetChildTransforms(self.transform,
{
"equip_conta","canStren", "effect_con"
})
self.strengthText,self.stren = GetChildTexts (self.transform,
{
"strengthText","stren"
})
self.default_conta,self.red_dot,self.selectBg,self.canStrenObj, self.can_buy_obj = GetChildGameObjects (self.transform,
{
"default_conta","red_dot","selectBg","canStren", "can_buy"
})
self.pos_type_img, self.default_conta_img = GetChildImages (self.transform,
{
"pos_type", "default_conta"
})
local nodes = {
"can_buy:img"
}
self:GetChildren(nodes)
self.stren.text = ""
self.icon_item = AwardItem.New(self.equip_conta)
-- self.icon_item = UIObjPool:getInstance():PopItem(UIObjPool.UIType.AwardItem, self.equip_conta)
self.icon_item:SetItemSize(78,78)
-- self.icon_item:SetAnchoredPosition(0,0)
if self.style_cache then
self:SetEquipStyle(self.style_cache)
self.style_cache = nil
end
if self.need_refreshData then
self:SetData(self.data)
self:SetPosType(self.pos_type, self.pos_type_visible, self.series, self.default_conta_show)
self:SetBgAlpha(self.bg_alpha)
self:WillShowEffect(self.will_show_effect)
end
if self.need_set_ring_show then
self:SetRingShow()
end
self.icon_item:SetEnableClick(false)
self.icon_item.ClickCallFun = function (target,target2,x,y) --覆盖AwardItem 的点击方法
self:ClickHandler(target2,x,y)
end
self:AddToStageHandler()
self:InitEvent()
end
function EquipItem:InitEvent()
local function click_fun(target,x,y)
if self.pos_type == EquipModel.EquipType.Weapon then
local helpVo = GuideModel:getInstance():GetHelpVo(HelpType.TYPE_EQUIP_SUIT_ACTIVE,4)
if helpVo then
GlobalEventSystem:Fire(EventName.FINISH_CURRENT_HELP_STEP,helpVo)
end
end
self:ClickHandler(target,x,y)
end
AddClickEvent(self.gameObject, click_fun)
local select_fun = function (goods_vo)
if self.data and goods_vo then
if self.is_bag == false then
if self.data.goods_id == goods_vo.goods_id then
self:SetSelect(true)
else
self:SetSelect(false)
end
end
end
end
self.event_id = self.model:Bind(EquipModel.EQUIP_ITEM_BE_CLICK, select_fun)
local change_dynamic = function (goods_id)
if self.data then
if self.data.goods_id == goods_id then
self:SetData(self.data, self.only_show_strength_tag)
end
end
end
self.dynamic_event_id = GlobalEventSystem:Bind(GoodsModel.CHANGE_GOODS_DYNAMIC,change_dynamic)
--发生改变时,判断是否进行提示
local update_red_func = function ()
self:SetRedPoint()
end
self.change_tong_id = self.mainVo:BindOne("tong", update_red_func)
local function RedDotRefresh( )
if self.is_open_ring then
self.icon_item:SetRedDot(MateModel:GetInstance():GetShipRedDot(false))
end
end
self:BindEvent(MateModel:GetInstance(), MateConst.RedDotRefresh, RedDotRefresh)
end
function EquipItem:ClickHandler(target,x,y)
if self.data then
if self.is_bag == false then
self.model:Fire(EquipModel.EQUIP_ITEM_BE_CLICK, self.data)
else
UIToolTipMgr:getInstance():AppendEquipTips(self.data.type_id, x, y, self.data)
end
else
if self.is_open_ring then
UIToolTipMgr:getInstance():AppendEquipTips(self.ring_equip_id, x, y)
-- UIToolTipMgr:getInstance():AppendMarriageTips(self.ring_info, x, y)
else
local ui_tf = panelMgr:GetParent("UI").transform
local pos = ui_tf:InverseTransformPoint(self.transform.position)
local w = ScreenWidth
local h = ScreenHeight
pos.x = w / 2 + pos.x
pos.y = h / 2 + pos.y
local key = self.pos_type .. "@" .. self.series .. "@" .. self.pos_type
local cfg = Config.Equipmentempty[key]
if cfg then
BagModel:getInstance():Fire(BagModel.EQUIP_ITEM_GET_WAY_TIPS, cfg,pos.x,pos.y)
else
print(">>>>> unfinfd config Equipmentempty ", self.pos_type, self.series )
end
end
end
end
function EquipItem:SetData(data, only_show_strength_tag)
self.data = data
self.only_show_strength_tag = only_show_strength_tag
if self.is_loaded then
self.need_refreshData = false
--设置装备
local callback = function (dynamic)
if self.data and self.data.goods_id == dynamic.goods_id then
if self.gameObject == nil then return end
if self.data.type_id ~= dynamic.type_id then
self.data.type_id = dynamic.type_id
GoodsModel:getInstance():SetBaseInfo(self.data)
end
self.dynamic = dynamic
self:SetDynamic(self.dynamic)
self:ShowCanStrength(self.data.type_id)
if self.icon_item then
self.icon_item:SetVisible(true)
local stren_data = EquipModel:getInstance():GetBagEquipAwaraItemInfo(self.data)
stren_data.equip_key = "EquipView"
stren_data.is_find = true
local hide_color_effect = false
if self.pos_type == EquipModel.EquipType.Guard or self.pos_type == EquipModel.EquipType.Fetter then
hide_color_effect = true
end
self.icon_item:SetData(self.data.type_id, self.data.goods_num, self.dynamic.color,stren_data,nil,nil,nil,nil,nil,hide_color_effect)
--是否过期装备
if self.data.expire_time and self.data.expire_time~=0 and self.data.expire_time - TimeUtil:getServerTime() <= 0 then
self.icon_item:SetExpiredVisible(true)
else
self.icon_item:SetExpiredVisible(false)
end
end
self:SetRedPoint()
end
end
self.can_buy_obj:SetActive(false)
if self.data then
GoodsModel:getInstance():GetDynamic(self.data.goods_id, callback)
end
else
self.need_refreshData = true
end
end
--设置一生一世的信息
function EquipItem:SetRingShow()
if self.is_loaded then
self.need_set_ring_show = false
local goods_id = false
local conf = false
local data = false
if GetModuleIsOpen(149) then
data = MateModel:GetInstance():GetShipBasic()
if not data or not data.stage then return end
conf = MateModel:GetInstance():GetShipConf(data.stage, data.star)
goods_id = conf and conf.goods_id
end
if goods_id and goods_id > 0 then
--保存数据做tip显示用
EquipModel:getInstance().mate_show_tool_tip_data = {stage = data.stage, star = data.star}
self.ring_equip_id = goods_id
self.icon_item:SetDataWithMapId(goods_id)
self.icon_item:SetVisible(true)
self.is_open_ring = true
local function delay( )
if self._use_delete_method then return end
self.icon_item:SetRedDot(MateModel:GetInstance():GetShipRedDot(false))
end
setTimeout(delay,0.1)
else
self.icon_item:SetVisible(false)
self.is_open_ring = false
end
else
self.need_set_ring_show = true
end
end
function EquipItem:SetRedPoint()
if not self.dynamic or not self.data then
local bool = GoodsModel:getInstance():GetQuickBuyEquipRedDot(self.series,self.pos_type)
if self.red_dot then
lua_resM:setImageSprite(self,self.can_buy_img,"bag_asset","bag_ui_29", false)
self.can_buy_obj:SetActive(bool)
end
return
end
local bool = false
local equip_cfg = EquipModel:getInstance():GetEquipmentCfg(self.dynamic.type_id)
-- print("huangcong:EquipItem [start:165] :", equip_cfg)
-- PrintTable(equip_cfg)
-- print("huangcong:EquipItem [end]")
--------现在背包中,升品,升星,精炼,不需要显示红点------
if equip_cfg then
--升品
bool = EquipModel:getInstance():GetEquipCanUpQualityByPos(equip_cfg.series,equip_cfg.equip_type)
if not bool and ComposeModel:getInstance():GetGuardOrOrnamentCanEvolution(equip_cfg)
and (equip_cfg.equip_type <= EquipModel.EquipType.Guard and equip_cfg.equip_type >= EquipModel.EquipType.Necklace) then--可购买升品
lua_resM:setImageSprite(self,self.can_buy_img,"bag_asset","bag_ui_31", false)
self.can_buy_obj:SetActive(true)
end
-- if not bool then
-- --升星
-- bool = EquipModel:getInstance():EquipIsCanEvolution(equip_cfg.series,equip_cfg.equip_type,self.data)
-- end
-- if not bool then
-- --精炼
-- bool = EquipModel:getInstance():GetEquipCanStrengthByPos(equip_cfg.series,equip_cfg.equip_type)
-- end
end
-- if self.red_dot then
-- self.red_dot:SetActive(bool)
-- end
end
--是否显示可精炼和镶嵌
function EquipItem:ShowCanStrength(type_id)
-- local bool = false
-- local equip_cfg = EquipModel:getInstance():GetEquipmentCfg(type_id)
-- -- print("huangcong:EquipItem [start:176] :", type_id)
-- -- PrintTable(equip_cfg)
-- -- print("huangcong:EquipItem [end]")
-- if equip_cfg then
-- bool = EquipModel:getInstance():GetEquipCanStrengthByPos(equip_cfg.series,equip_cfg.equip_type)
-- end
-- print("huangcong:EquipItem [start:180] :", bool)
-- self.red_dot:SetActive(bool)
-- self:showEffect(bool)
end
function EquipItem:SetDynamic(dynamic)
if self.gameObject == nil then return end
if dynamic.stren and dynamic.stren > 0 then
self.stren.text = "+" .. dynamic.stren
else
self.stren.text = ""
end
end
function EquipItem:SetEquipStyle(style)
self.equip_style = style
if self.is_loaded and style ~= nil then
local str = WordManager:GetEquipStyleStr(style)
self.stren.text = ""
else
self.style_cache = style
end
end
function EquipItem:ClearData()
self.data = nil
if self.icon_item then
self.icon_item:SetVisible(false, false)
end
if self.stren then
self.stren.text = ""
end
if self.red_dot then
self.red_dot:SetActive(false)
end
end
function EquipItem:SetSelect(bool)
self.selectBg:SetActive(bool)
end
function EquipItem:showEffect(bool)
if bool then
self.canStrenObj:SetActive(true)
if self.is_bag then
self:AddUIEffect("ui_effect_jineng_jiantou1", self.canStren, self.layer_name, nil, nil, true)
else
self:AddUIEffect("ui_effect_jineng_jiantou1", self.canStren, self.layer_name, nil, nil, true)
end
else
self.canStrenObj:SetActive(false)
self:ClearUIEffect(self.canStren)
end
end
function EquipItem:__delete()
if self.event_id then
self.model:UnBind(self.event_id)
self.event_id = nil
end
if self.dynamic_event_id then
GlobalEventSystem:UnBind(self.dynamic_event_id)
self.dynamic_event_id = nil
end
self:ClearUIEffect(self.canStren)
if self.change_tong_id then
self.mainVo:UnBind(self.change_tong_id)
self.change_tong_id = nil
end
if self.icon_item then
self.icon_item:DeleteMe()
-- self.icon_item:ReleaseObj()
self.icon_item = nil
end
self:ClearUIEffect(self.effect_con)
end
function EquipItem:SetPosType(pos, b, series, default_conta_show)
self.pos_type = pos
self.pos_type_visible = b
self.series = series
self.default_conta_show = default_conta_show
if self.is_loaded then
self.need_refreshData = false
self.default_conta:SetActive(self.default_conta_show or (self.pos_type and ((self.pos_type == 11 and self.data == nil) or self.pos_type ~= 11)))
if self.pos_type then
lua_resM:setImageSprite(self,self.pos_type_img,"common_asset","com_equip_pos_".. self.pos_type, true)
lua_resM:setImageSprite(self,self.default_conta_img,"common_asset","tyui_pz_8", true)
end
self.pos_type_img.gameObject:SetActive(self.pos_type_visible)
self:SetRedPoint()
if not self.init_guide_event and self.pos_type == EquipModel.EquipType.Weapon then
self.init_guide_event = true
local function onGuideTrigger()
self:AddToStageHandler()
end
self:BindEvent(GlobalEventSystem, EventName.TRIGGER_GUIDE_TYPE, onGuideTrigger)
end
else
self.need_refreshData = true
end
end
function EquipItem:SetBgAlpha(alpha)
self.bg_alpha = alpha
if self.is_loaded then
self.need_refreshData = false
self.icon_item:SetAlpha(self.bg_alpha)
else
self.need_refreshData = true
end
end
function EquipItem:GetPosType()
return self.pos_type
end
function EquipItem:WillShowEffect(show)
self.will_show_effect = show
if self.is_loaded then
if self.will_show_effect then
self.will_show_effect = false
self:AddEffect()
end
else
self.need_refreshData = true
end
end
function EquipItem:AddEffect()
if not self.showing_effect then
local function call_back( )
self.showing_effect = false
end
self:ClearUIEffect(self.effect_con)
self:AddUIEffect("ui_hunliqiudianliang", self.effect_con, "Activity", nil, 4, false, 0.6, nil, call_back)
self.showing_effect = true
end
end
function EquipItem:AddToStageHandler()
local helpVo = GuideModel:getInstance():GetHelpVo(HelpType.TYPE_EQUIP_SUIT_ACTIVE,4)
if not helpVo then return end
local help_type = helpVo.help_type
local step = helpVo.step
local button = false
if (help_type == HelpType.TYPE_EQUIP_SUIT_ACTIVE) and step == 4 then
button = self.effect_con.gameObject
end
if button then
local function call_back()
end
GlobalEventSystem:Fire(EventName.OPEN_GUIDE_PROMPT_VIEW, button.transform, self.transform, call_back, helpVo, self.layout_file)
end
end