|
|
|
ItemUseView = ItemUseView or BaseClass(BaseView)
|
|
|
|
ItemUseView.UIStyle =
|
|
{
|
|
Normal = 1, --正常装备,单个道具使用
|
|
BatUse = 2, --多个道具,批量使用
|
|
Auction = 3, --便捷上架拍卖
|
|
Designation = 4, --称号快捷穿戴
|
|
}
|
|
|
|
ItemUseView.ViewDepth = 750
|
|
|
|
function ItemUseView:__init()
|
|
self.base_file = "itemUse"
|
|
self.layout_file = "ItemUseView"
|
|
self.layer_name = "Activity"
|
|
self.destroy_imm = false
|
|
self.is_delay_callback = false
|
|
self.open_wnd_anim = 0
|
|
self.is_set_zdepth = true
|
|
self.mask_open_sound = true
|
|
self.mask_close_sound = true
|
|
self.close_mode = CloseMode.CloseDestroy
|
|
self.force_no_ctl_queue = true
|
|
-- self.change_scene_close = true
|
|
self.model = ItemUseModel:getInstance()
|
|
self.goods_model = GoodsModel:getInstance()
|
|
self.mainVo = RoleManager.Instance.mainRoleInfo
|
|
self.transform_x = ScreenWidth/2-377--377是对右边的值
|
|
self.transform_y = -ScreenHeight/2+177--177是对下边的值
|
|
self.ui_style = ItemUseView.UIStyle.Normal
|
|
self.is_in_anim = false
|
|
|
|
self.cur_use = 0
|
|
self.max_use = 0
|
|
|
|
self.load_callback = function ()
|
|
self:LoadSuccess()
|
|
self:InitEvent()
|
|
UIDepth.SetUIDepth(self.gameObject,true,ItemUseView.ViewDepth) --强制设置层级
|
|
end
|
|
self.open_callback = function ()
|
|
self:LayoutUI()
|
|
self:ResetCloseTimer()
|
|
|
|
|
|
GlobalEventSystem:Fire(EventName.SET_LOCAK_VIEW_LAYER)
|
|
end
|
|
self.close_callback = function ()
|
|
self:ClearCloseTimer()
|
|
-- self.item_icon:clearResRef()
|
|
self:ClearTimer()
|
|
if self.need_fire_auto then
|
|
local need_do_task = self.close_by_hand == true and true or false
|
|
GuideModel:getInstance():BeginTask(self.layout_file,need_do_task)
|
|
self.need_fire_auto = false
|
|
end
|
|
end
|
|
self.destroy_callback = function ()
|
|
self:Clear()
|
|
end
|
|
end
|
|
|
|
function ItemUseView:ResetCloseTimer( )
|
|
self:ClearCloseTimer()
|
|
-- self:StartCloseTimer()
|
|
end
|
|
|
|
function ItemUseView:Open(vo,forceAutoSec)
|
|
self.vo = vo
|
|
self.forceAutoSec = forceAutoSec
|
|
if self.vo then
|
|
self.type_id = self.vo.type_id
|
|
self.goods_id = self.vo.goods_id
|
|
self.num = self.model:GetGoodsNumById(self.goods_id)
|
|
self.goods_vo = GoodsModel:getInstance():GetGoodsBasicByTypeId(self.vo.type_id)
|
|
end
|
|
BaseView.Open(self)
|
|
end
|
|
|
|
function ItemUseView:Clear()
|
|
if self.dynamic_event_id then
|
|
GlobalEventSystem:UnBind(self.dynamic_event_id)
|
|
self.dynamic_event_id = nil
|
|
end
|
|
if self.item_icon then
|
|
self.item_icon:ReleaseObj()
|
|
self.item_icon = nil
|
|
end
|
|
|
|
if self.refresh_item_id then
|
|
GoodsModel:getInstance():UnBind(self.refresh_item_id)
|
|
self.refresh_item_id = nil
|
|
end
|
|
if self.scale_anim_id then
|
|
TweenLite.Stop(self.scale_anim_id)
|
|
self.scale_anim_id = nil
|
|
end
|
|
|
|
if self.mark_goods_update_id then
|
|
MarketModel:getInstance():UnBind(self.mark_goods_update_id)
|
|
end
|
|
self:ClearTimer()
|
|
self:ClearCloseTimer()
|
|
cc.ActionManager:getInstance():removeAllActionsFromTarget(self.designation_image)
|
|
end
|
|
|
|
function ItemUseView:LayoutUI()
|
|
if self.vo then
|
|
self:AddToStageHandler()
|
|
SetLocalScale(self.gameObject.transform, 1, 1,1)
|
|
self:ClearTimer()
|
|
|
|
local type_id = self.vo.type_id
|
|
local goods_basic = GoodsModel:getInstance():GetGoodsBasicByTypeId(type_id)
|
|
local num = self.model:GetGoodsNumById(self.goods_id)
|
|
self.max_use = 0
|
|
self.cur_use = 0
|
|
|
|
self.close_btn:SetActive(true)
|
|
cc.ActionManager:getInstance():removeAllActionsFromTarget(self.designation_image)
|
|
if goods_basic then
|
|
local nameStr = GoodsModel.GetRealGoodsName(goods_basic)
|
|
if utf8len(nameStr) > 8 then
|
|
nameStr = SubStringUTF8(nameStr, 1, 7) .. "..."
|
|
end
|
|
self.name.text = HtmlColorTxt(nameStr, WordManager.GetGoodsColor(goods_basic.color))
|
|
if self.item_icon then
|
|
if goods_basic.type == GoodsModel.TYPE.EQUIP then
|
|
local stren_data = EquipModel:getInstance():GetBagEquipAwaraItemInfo(self.vo)
|
|
stren_data.equip_key = "EquipView"
|
|
stren_data.key_value = "show_bag_view"
|
|
self.stren_data = stren_data
|
|
self.item_icon:SetData(type_id,num,self.vo.color,stren_data)
|
|
else
|
|
self.item_icon:SetData(type_id,num,self.vo.color)
|
|
end
|
|
self.item_icon:SetVisible(true)
|
|
end
|
|
if self:IsBatchUseGoods(goods_basic, num) then
|
|
self.ui_style = ItemUseView.UIStyle.BatUse
|
|
elseif self:IsActionEquip(self.vo, goods_basic) then
|
|
self.ui_style = ItemUseView.UIStyle.Auction
|
|
elseif self:IsDesignationGoods(goods_basic) then
|
|
self.ui_style = ItemUseView.UIStyle.Designation
|
|
else
|
|
self.ui_style = ItemUseView.UIStyle.Normal
|
|
end
|
|
if self.ui_style == ItemUseView.UIStyle.Auction then
|
|
self.auction_group:SetActive(true)
|
|
self.base_group:SetActive(false)
|
|
self.designation_group_obj:SetActive(false)
|
|
SetAnchoredPosition(self.item_parent.transform , 71, 167)
|
|
SetAnchoredPosition(self.name.transform, 60, 116)
|
|
SetAnchoredPosition(self.effect_con.transform, 64.5, 162)
|
|
self.base_price_txt.text = tostring(goods_basic.trade_price or 0)
|
|
self.fixed_price_txt.text = tostring(goods_basic.buyout_price or 0)
|
|
SetAnchoredPosition(self.transform, self.transform_x-123, self.transform_y+31)--这里的123是因为变宽了向右移,31是多了一个栏 用右下角对齐 需要往上移动
|
|
elseif self.ui_style == ItemUseView.UIStyle.Designation then
|
|
self.auction_group:SetActive(false)
|
|
self.designation_group_obj:SetActive(true)
|
|
self.base_group:SetActive(false)
|
|
self.item_icon:SetVisible(false)
|
|
local cfg = Config.Dsgt
|
|
local designation_id = DesignationModel:GetInstance():GetDesignationIdByGoodsId(type_id)
|
|
cc.ActionManager:getInstance():removeAllActionsFromTarget(self.designation_image)
|
|
if cfg[designation_id].type == 1 then--文字称号(文字称号也用图片了)
|
|
lua_resM:setOutsideImageSprite(self, self.designation_image_img, GameResPath.GetDesignImage(cfg[designation_id].id), true)
|
|
self.designation_image_obj:SetActive(true)
|
|
elseif cfg[designation_id].type == 2 then--图片称号
|
|
lua_resM:setOutsideImageSprite(self, self.designation_image_img, GameResPath.GetDesignImage(cfg[designation_id].id), true)
|
|
self.designation_image_obj:SetActive(true)
|
|
elseif cfg[designation_id].type == 3 then--特效称号
|
|
if not self.dynamic_image_obj then
|
|
self.dynamic_image_obj = UiFactory.createChild(self.designation_image, UIType.Image, "dynamic_image")
|
|
self.dynamic_image_img = self.dynamic_image_obj:GetComponent("Image")
|
|
self.dynamic_image = self.dynamic_image_obj.transform
|
|
SetAnchoredPosition(self.dynamic_image,0,0)
|
|
else
|
|
self.dynamic_image_obj:SetActive(true)
|
|
end
|
|
self.designation_image_obj:SetActive(true)
|
|
local data = DesignationModel:GetInstance():GetDynamicDesignationCFG(designation_id)
|
|
local res = Split(data[1].res,"_")--分割出来配置 然后取文字
|
|
local font_res = res[1] or ""
|
|
lua_resM:setImageSprite(self, self.dynamic_image_img, data[1].ab, font_res.."_font", true)
|
|
local action = cc.Animation.New(data,0.15)
|
|
cc.ActionManager:getInstance():addAction(cc.RepeatForever.New(action),self.designation_image.transform)
|
|
end
|
|
self.designation_tip_text_tmp.text = cfg[designation_id].description
|
|
self.name.text = ""
|
|
SetAnchoredPosition(self.transform, self.transform_x-80, self.transform_y+90)--这里的123是因为变宽了向右移,60是变高了 用右下角对齐 需要往上移动
|
|
self:CheckShowEffectAndAutoUse()
|
|
else
|
|
self.auction_group:SetActive(false)
|
|
self.designation_group_obj:SetActive(false)
|
|
self.base_group:SetActive(true)
|
|
SetAnchoredPosition(self.item_parent.transform , 9.5, 51.5)
|
|
SetAnchoredPosition(self.name.transform, -1, 1)
|
|
SetAnchoredPosition(self.effect_con.transform, 3, 61.5)
|
|
|
|
if goods_basic.type == GoodsModel.TYPE.EQUIP then --10是装备
|
|
if self:IsAutoEquip() then
|
|
self.use_btn_text.text = "装备"
|
|
self.close_btn:SetActive(false)
|
|
else
|
|
self.use_btn_text.text = "查看"
|
|
end
|
|
self:ChangeState()
|
|
else
|
|
self.use_btn_text.text = "使用"
|
|
end
|
|
|
|
if self.ui_style == ItemUseView.UIStyle.BatUse then
|
|
self.addNumCon.gameObject:SetActive(true)
|
|
SetAnchoredPositionY(self.use_btn.transform, -80)
|
|
self.cur_use = num
|
|
self.max_use = num
|
|
self:ChangeCountNum()
|
|
SetAnchoredPosition(self.transform, self.transform_x, self.transform_y+14)--这里的14是因为多了一个栏 用右下角对齐 需要往上移动
|
|
else
|
|
self.addNumCon.gameObject:SetActive(false)
|
|
if self:IsShowAutoUse() then
|
|
SetAnchoredPositionY(self.use_btn.transform, -52)
|
|
else
|
|
SetAnchoredPositionY(self.use_btn.transform, -64)
|
|
end
|
|
SetAnchoredPosition(self.transform, self.transform_x, self.transform_y)
|
|
end
|
|
self:CheckShowEffectAndAutoUse()
|
|
end
|
|
end
|
|
end
|
|
end
|
|
|
|
function ItemUseView:LoadSuccess()
|
|
|
|
self.use_btn = self:GetChild("contain/base_group/UseBtn").gameObject
|
|
self.close_btn = self:GetChild("contain/base_group/CloseBtn").gameObject
|
|
|
|
self.use_btn_text = self:GetChild("contain/base_group/UseBtn/Text"):GetComponent("TextMeshProUGUI")
|
|
self.name = self:GetChild("contain/item_name"):GetComponent("TextMeshProUGUI")
|
|
|
|
self.item_parent = self:GetChild("contain/ItemParent")
|
|
|
|
-- self.item_icon = AwardItem.New(self.item_parent, nil, "Top")
|
|
self.item_icon = UIObjPool:getInstance():PopItem(UIObjPool.UIType.AwardItem, self.item_parent)
|
|
self.item_icon:SetItemSize(78, 78)
|
|
|
|
self.transform.localPosition = Vector3(ScreenWidth/2 - 490,-ScreenHeight/2 + 160,0)
|
|
|
|
self.tip_text = self:GetChild("contain/base_group/Tip"):GetComponent("TextMeshProUGUI")
|
|
self.tip_obj = self:GetChild("contain/base_group/Tip").gameObject
|
|
|
|
self.effect_con = self:GetChild("contain/EffectCon").gameObject
|
|
|
|
self.Border_img = self:GetChild("contain/base_group/Border"):GetComponent("Image")
|
|
|
|
self.addNumCon = self:GetChild("contain/base_group/addNumCon")
|
|
self.del_btn_obj = self:GetChild("contain/base_group/addNumCon/del_btn").gameObject
|
|
self.add_btn_obj = self:GetChild("contain/base_group/addNumCon/add_btn").gameObject
|
|
self.count_btn_obj = self:GetChild("contain/base_group/addNumCon/count_btn").gameObject
|
|
self.count_num_txt = self:GetChild("contain/base_group/addNumCon/count_num"):GetComponent("TextMeshProUGUI")
|
|
|
|
self.base_group = self:GetChild("contain/base_group").gameObject
|
|
self.auction_group = self:GetChild("contain/auction_group").gameObject
|
|
self.base_price_txt = self:GetChild("contain/auction_group/base_price"):GetComponent("TextMeshProUGUI")
|
|
self.fixed_price_txt = self:GetChild("contain/auction_group/fixed_price"):GetComponent("TextMeshProUGUI")
|
|
self.close_btn_2 = self:GetChild("contain/auction_group/CloseBtn2").gameObject
|
|
self.auction_btn = self:GetChild("contain/auction_group/auctionBtn").gameObject
|
|
|
|
--称号快捷使用
|
|
self.nodes = {
|
|
"contain/designation_group:obj", "contain/designation_group/designation_btn:obj", "contain/designation_group/CloseBtn3:obj",
|
|
"contain/designation_group/designation_time_text:tmp", "contain/designation_group/designation_tip_text:tmp",
|
|
"contain/designation_group/designation_name_text:tmp", "contain/designation_group/designation_image:img:obj",
|
|
"contain:obj"
|
|
}
|
|
self:GetChildren(self.nodes)
|
|
GlobalEventSystem:Fire(EventName.OPEN_ITEM_USE_VIEW_SUCCESS, ItemUseView.ViewDepth)
|
|
self.transform:SetAsLastSibling()
|
|
end
|
|
|
|
function ItemUseView:InitEvent()
|
|
local function onBtnClickHandler(target, x, y)
|
|
if target == self.use_btn then
|
|
self:CloseGuide()
|
|
self:UseCall()
|
|
self:NextItemUse(true)
|
|
elseif target == self.auction_btn then
|
|
self:AuctionCall()
|
|
self:NextItemUse(true)
|
|
elseif target == self.close_btn then
|
|
self:CloseGuide()
|
|
self:NextItemUse(true)
|
|
elseif target == self.close_btn_2 then
|
|
self:NextItemUse(true)
|
|
elseif target == self.CloseBtn3_obj then
|
|
self:NextItemUse(true)
|
|
elseif target == self.del_btn_obj then
|
|
self.cur_use = self.cur_use - 1
|
|
self:ChangeCountNum()
|
|
|
|
elseif target == self.add_btn_obj then
|
|
self.cur_use = self.cur_use + 1
|
|
self:ChangeCountNum()
|
|
|
|
elseif target == self.count_btn_obj then
|
|
local function call_back(final_number)
|
|
self.cur_use = final_number
|
|
self:ChangeCountNum()
|
|
end
|
|
|
|
EventSystem.Fire(GlobalEventSystem,EventName.OPEN_CALCULATOR_VIEW,self.max_use,call_back, Vector3(x, y, 0), 9)
|
|
elseif target == self.designation_btn_obj then
|
|
self:UseCall()
|
|
self:NextItemUse(true)
|
|
end
|
|
end
|
|
|
|
AddClickEventHz(0.5,self.use_btn,onBtnClickHandler,LuaSoundManager.SOUND_UI.CLOSE)
|
|
AddClickEventHz(0.5,self.designation_btn_obj,onBtnClickHandler,LuaSoundManager.SOUND_UI.CLOSE)
|
|
AddClickEventHz(0.5,self.auction_btn,onBtnClickHandler,LuaSoundManager.SOUND_UI.CLOSE)
|
|
AddClickEventHz(0.5,self.close_btn,onBtnClickHandler,LuaSoundManager.SOUND_UI.CLOSE)
|
|
AddClickEventHz(0.5,self.close_btn_2,onBtnClickHandler,LuaSoundManager.SOUND_UI.CLOSE)
|
|
AddClickEventHz(0.5,self.CloseBtn3_obj,onBtnClickHandler,LuaSoundManager.SOUND_UI.CLOSE)
|
|
AddClickEvent(self.del_btn_obj,onBtnClickHandler)
|
|
AddClickEvent(self.add_btn_obj,onBtnClickHandler)
|
|
AddClickEvent(self.count_btn_obj,onBtnClickHandler)
|
|
|
|
local change_dynamic = function (goods_id)
|
|
self:ChangeState()
|
|
end
|
|
self.dynamic_event_id = GlobalEventSystem:Bind(GoodsModel.CHANGE_GOODS_DYNAMIC,change_dynamic)
|
|
|
|
local function onRefreshItemNum()
|
|
if self.vo then
|
|
local goods_id = self.vo.goods_id
|
|
local num = self.model:GetGoodsNumById(goods_id)
|
|
if self.num ~= num and num > 0 then
|
|
self.num = num
|
|
if self.item_icon then
|
|
local goods_basic = GoodsModel:getInstance():GetGoodsBasicByTypeId(self.vo.type_id)
|
|
if goods_basic.type == GoodsModel.TYPE.EQUIP then
|
|
local stren_data = EquipModel:getInstance():GetBagEquipAwaraItemInfo(self.vo)
|
|
stren_data.equip_key = "EquipView"
|
|
stren_data.key_value = "show_bag_view"
|
|
self.stren_data = stren_data
|
|
self.item_icon:SetData(self.vo.type_id,num,self.vo.color,stren_data)
|
|
local can_tip, flag = EquipModel:getInstance():EquipCanShowGoodsTip(self.vo)
|
|
self.item_icon:ChangeEquipState(flag)
|
|
else
|
|
self.item_icon:SetData(self.vo.type_id,num,self.vo.color)
|
|
if self:IsBatchUseGoods(goods_basic, num) then
|
|
self.max_use = num
|
|
self.cur_use = num
|
|
self.count_num_txt.text = tostring(self.cur_use)
|
|
end
|
|
end
|
|
end
|
|
end
|
|
end
|
|
end
|
|
self.refresh_item_id = GoodsModel:getInstance():Bind(GoodsModel.CHANGE_BAGLIST,onRefreshItemNum)
|
|
|
|
local function item_click_func(target,target2,x,y)
|
|
if self.vo then
|
|
local type_id = self.vo.type_id
|
|
local goods_basic = GoodsModel:getInstance():GetGoodsBasicByTypeId(type_id)
|
|
|
|
if goods_basic then
|
|
if goods_basic.type == GoodsModel.TYPE.EQUIP then --装备
|
|
if goods_basic.subtype == 12 then --时装物品
|
|
UIToolTipMgr:getInstance():AppendGoodsTips(goods_basic.type_id, x, y,self.vo)
|
|
else
|
|
self.stren_data.key_value = "show_bag_view"
|
|
UIToolTipMgr:getInstance():AppendEquipTips(goods_basic.type_id, x, y,self.vo,nil,true,nil,self.stren_data and self.stren_data.key_value)
|
|
end
|
|
else --普通物品
|
|
UIToolTipMgr:getInstance():AppendGoodsTips(goods_basic.type_id, x, y, self.vo)
|
|
end
|
|
end
|
|
end
|
|
end
|
|
|
|
if self.item_icon then
|
|
self.item_icon.ClickCallFun = item_click_func
|
|
end
|
|
|
|
--监听别的itemuseview打开了
|
|
local function onOpenItemUseViewSuccess(layer_count)
|
|
if self.is_in_anim then
|
|
self:ResetViewUIZDepth(layer_count)
|
|
end
|
|
end
|
|
self:BindEvent(GlobalEventSystem, EventName.OPEN_ITEM_USE_VIEW_SUCCESS, onOpenItemUseViewSuccess)
|
|
|
|
local function onSceneStartHandler()
|
|
self:ChangeSceneHandle()
|
|
end
|
|
self:ChangeSceneHandle()
|
|
self:BindEvent(GlobalEventSystem, EventName.SCENE_LOAD_VIEW_COMPLETE, onSceneStartHandler)
|
|
|
|
local function onGuideTrigger()
|
|
self:AddToStageHandler()
|
|
end
|
|
self:BindEvent(GlobalEventSystem, EventName.TRIGGER_GUIDE_TYPE, onGuideTrigger)
|
|
|
|
local function onLittleMove(is_out)
|
|
if not is_out then
|
|
self:ResetViewUIZDepth(ItemUseView.ViewDepth)
|
|
end
|
|
end
|
|
self:BindEvent(GlobalEventSystem, EventName.PLAY_MAINUI_MOVIE_EVENT, onLittleMove)
|
|
|
|
local function onMarkGoodsUpdate( )
|
|
if MarketModel:getInstance():IsMaxMarketGoods() then
|
|
if self.ui_style == ItemUseView.UIStyle.Auction then
|
|
self:NextItemUse(true)
|
|
end
|
|
end
|
|
end
|
|
self.mark_goods_update_id = MarketModel:getInstance():BindOne("goods_shelves_list", onMarkGoodsUpdate)
|
|
end
|
|
|
|
function ItemUseView:OnCLickUseBtn( )
|
|
if self.vo then
|
|
if self:IsEquipNormalType() then
|
|
--如果数 可自动穿戴的装备,直接穿
|
|
if self:IsAutoEquip() then
|
|
EquipModel:getInstance():WearEquip( self.vo, true )
|
|
else
|
|
--如果该部位有装备,则打开装备对比,并且打开背包
|
|
local serires, pos = self:GetEquipSeriesAndPos()
|
|
local equip = GoodsModel.getInstance():GetTargetSeriesTargetPosEquip(serires, pos)
|
|
if equip then
|
|
GlobalEventSystem:Fire(EventName.ITEM_USE_DELAY_OPEN_EQUIP_TOOL, self.vo)
|
|
end
|
|
GoodsModel.getInstance():SetBagEquipChooseIndex(serires)
|
|
GlobalEventSystem:Fire(EventName.OPEN_BAG_VIEW_IF_NOT, 1)
|
|
--OpenFun.Open(150,1)
|
|
end
|
|
self:CustomClose()
|
|
else
|
|
local use_args = {}
|
|
local type_id = self.vo.type_id
|
|
local goods_basic = GoodsModel:getInstance():GetGoodsBasicByTypeId(type_id)
|
|
if self:IsBatchUseGoods(goods_basic, self.vo.goods_num) then
|
|
use_args.force_batch_use = true
|
|
use_args.use_num = self.cur_use > 0 and self.cur_use or 1
|
|
end
|
|
GoodsModel:getInstance():Fire(GoodsModel.TRY_TO_USE_GOODS, self.vo, nil, use_args)
|
|
self:CustomClose()
|
|
end
|
|
end
|
|
end
|
|
|
|
function ItemUseView:NextItemUse(force_oepn)
|
|
local goods_id = self.vo.goods_id
|
|
self.model:ClearIdData(goods_id)
|
|
local vo = self.model:GetItemShowVo()
|
|
if vo then
|
|
local function call_back()
|
|
self:Close()
|
|
--GlobalEventSystem:Fire(EventName.OPEN_ITEM_USE_VIEW,vo, nil, force_oepn)
|
|
end
|
|
self:DoViewAnim(false, call_back)
|
|
GlobalEventSystem:Fire(EventName.OPEN_ITEM_USE_VIEW,vo, nil, force_oepn, true)
|
|
else
|
|
self:CustomClose()
|
|
end
|
|
end
|
|
|
|
function ItemUseView:CustomClose()
|
|
local function call_back()
|
|
self:Close()
|
|
end
|
|
self:DoViewAnim(false, call_back)
|
|
end
|
|
|
|
function ItemUseView:IsEquipNormalType()
|
|
if self.vo then
|
|
local type_id = self.vo.type_id
|
|
local goods_basic = GoodsModel:getInstance():GetGoodsBasicByTypeId(type_id)
|
|
if goods_basic then
|
|
return goods_basic.type == GoodsModel.TYPE.EQUIP
|
|
end
|
|
end
|
|
return false
|
|
end
|
|
|
|
function ItemUseView:IsItemType()
|
|
if self.vo then
|
|
local type_id = self.vo.type_id
|
|
local goods_basic = GoodsModel:getInstance():GetGoodsBasicByTypeId(type_id)
|
|
if goods_basic then
|
|
return goods_basic.type ~= GoodsModel.TYPE.God and goods_basic.type ~= GoodsModel.TYPE.DESIGNATION
|
|
end
|
|
end
|
|
return false
|
|
end
|
|
|
|
function ItemUseView:Show()
|
|
self.gameObject:SetActive(true)
|
|
end
|
|
|
|
function ItemUseView:Hide()
|
|
self.gameObject:SetActive(false)
|
|
end
|
|
|
|
function ItemUseView:IsShowEffect()
|
|
return false
|
|
end
|
|
|
|
function ItemUseView:GetGoodsId()
|
|
if self.vo then
|
|
return self.vo.goods_id
|
|
end
|
|
return nil
|
|
end
|
|
|
|
function ItemUseView:GetTypeId()
|
|
if self.vo then
|
|
return self.vo.type_id
|
|
end
|
|
return nil
|
|
end
|
|
|
|
function ItemUseView:ShowTipText()
|
|
if self:IsEquipNormalType() or self.model:IsEquipSpecialType(self.vo.type_id) then
|
|
self.tip_text.text = "<color=#ffa229>"..self.sec .."</color>".."秒后自动装备"
|
|
elseif self:IsItemType() then
|
|
self.tip_text.text = "<color=#ffa229>"..self.sec .."</color>".."秒后自动使用"
|
|
elseif self:IsDesignationGoods() then
|
|
self.designation_time_text_tmp.text = "<color=#ffa229>"..self.sec .."</color>".."秒后自动穿戴"
|
|
else
|
|
self.tip_text.text = "<color=#ffa229>"..self.sec .."</color>".."秒后自动装备"
|
|
end
|
|
end
|
|
|
|
function ItemUseView:CheckShowEffectAndAutoUse()
|
|
if self:IsShowEffect() then
|
|
self.effect_con:SetActive(true)
|
|
|
|
local function load_end_func( )
|
|
local renders = self.effect_con:GetComponentsInChildren(typeof(UnityEngine.Renderer))
|
|
if renders then
|
|
for i = 0, renders.Length - 1 do
|
|
local render = renders[i]
|
|
render.sortingOrder = 111
|
|
end
|
|
end
|
|
end
|
|
|
|
self:AddUIEffect("ui_effect_yindao_biankuang", self.effect_con.transform, self.layer_name, nil, nil, true, nil, nil,nil,load_end_func)
|
|
else
|
|
self.effect_con:SetActive(false)
|
|
end
|
|
|
|
if self:IsShowAutoUse() or self.forceAutoSec then
|
|
self:ClearTimer()
|
|
self.tip_obj:SetActive(true)
|
|
|
|
self.sec = self.forceAutoSec or 5
|
|
self:ShowTipText()
|
|
local function onTimer()
|
|
self.sec = self.sec - 1
|
|
if self.sec < 1 then
|
|
self:OnCLickUseBtn()
|
|
self:ClearTimer()
|
|
self:NextItemUse(true)
|
|
else
|
|
self:ShowTipText()
|
|
end
|
|
end
|
|
self.timer_id = GlobalTimerQuest:AddPeriodQuest(onTimer,1,-1)
|
|
else
|
|
self.tip_obj:SetActive(false)
|
|
end
|
|
end
|
|
|
|
function ItemUseView:ClearTimer()
|
|
if self.timer_id then
|
|
GlobalTimerQuest:CancelQuest(self.timer_id)
|
|
self.timer_id = nil
|
|
end
|
|
end
|
|
|
|
function ItemUseView:ChangeState( )
|
|
self.item_icon:ChangeEquipState(nil)
|
|
local basic = GoodsModel:getInstance():GetGoodsBasicByTypeId(self.type_id)
|
|
if basic == nil then
|
|
return
|
|
end
|
|
if self.vo.type == GoodsModel.TYPE.EQUIP and self.vo.goods_num > 0 then
|
|
local can_tip, flag = EquipModel:getInstance():EquipCanShowGoodsTip(self.vo)
|
|
self.item_icon:ChangeEquipState(flag)
|
|
end
|
|
end
|
|
|
|
--5秒后自动关闭,并清除所有数据
|
|
function ItemUseView:StartCloseTimer( )
|
|
local time = 5
|
|
local function onTimer()
|
|
time = time -1
|
|
if time< 0 then
|
|
--清除数据
|
|
local goods_id = self.vo.goods_id
|
|
self.model:ClearIdData(goods_id)
|
|
local vo = self.model:GetItemShowVo()
|
|
if vo then
|
|
local function call_back()
|
|
self:Close()
|
|
--GlobalEventSystem:Fire(EventName.OPEN_ITEM_USE_VIEW,vo)
|
|
end
|
|
self:DoViewAnim(false, call_back)
|
|
GlobalEventSystem:Fire(EventName.OPEN_ITEM_USE_VIEW,vo)
|
|
else
|
|
self:CustomClose()
|
|
end
|
|
end
|
|
end
|
|
self.close_timer_id = GlobalTimerQuest:AddPeriodQuest(onTimer,1,-1)
|
|
end
|
|
|
|
function ItemUseView:ClearCloseTimer()
|
|
if self.close_timer_id then
|
|
GlobalTimerQuest:CancelQuest(self.close_timer_id)
|
|
self.close_timer_id = nil
|
|
end
|
|
end
|
|
|
|
--是否显示自动使用提示
|
|
function ItemUseView:IsShowAutoUse( )
|
|
if (self:IsEquipNormalType() and self:IsAutoEquip())
|
|
then
|
|
return true
|
|
end
|
|
-- if ((self:IsEquipNormalType() and self:IsAutoEquip()) or self.model:IsEquipSpecialType(self.vo.type_id) or self:IsDesignationGoods())
|
|
-- and RoleManager.Instance.mainRoleInfo.level < 150 then
|
|
-- return true
|
|
-- end
|
|
end
|
|
|
|
function ItemUseView:UseCall( )
|
|
self:ResetCloseTimer()
|
|
self:OnCLickUseBtn()
|
|
end
|
|
|
|
function ItemUseView:AuctionCall( )
|
|
self:ResetCloseTimer()
|
|
GlobalEventSystem:Fire(EventName.OPEN_MARKET_VIEW, MarketConst.TabId.SalesHall)
|
|
end
|
|
|
|
--是否可以批量批量使用
|
|
function ItemUseView:IsBatchUseGoods( goods_basic, num )
|
|
return goods_basic and goods_basic.type ~= GoodsModel.TYPE.EQUIP and goods_basic.batch_use == 1 and num > 1
|
|
end
|
|
|
|
--是否可以上架(可以上架,并且不是本职业使用,的装备)
|
|
function ItemUseView:IsActionEquip(goods_vo, goods_basic )
|
|
local bool = GetModuleOpenLevel(155)--得市场开了才能弹出
|
|
return bool and not MarketModel:getInstance():IsMaxMarketGoods() and self.goods_model:IsEquipCanAuctionButNoUse(goods_vo, goods_basic)
|
|
end
|
|
|
|
function ItemUseView:IsDesignationGoods( goods_basic )
|
|
if goods_basic then
|
|
return goods_basic.type == GoodsModel.TYPE.DESIGNATION
|
|
end
|
|
if self.vo then
|
|
local type_id = self.vo.type_id
|
|
local goods_basic = GoodsModel:getInstance():GetGoodsBasicByTypeId(type_id)
|
|
if goods_basic then
|
|
return goods_basic.type == GoodsModel.TYPE.DESIGNATION
|
|
end
|
|
end
|
|
return false
|
|
end
|
|
|
|
|
|
function ItemUseView:ChangeCountNum()
|
|
if self.max_use == 0 then return end
|
|
self.cur_use = self.cur_use < 1 and 1 or self.cur_use
|
|
self.cur_use = self.cur_use > self.max_use and self.max_use or self.cur_use
|
|
self.count_num_txt.text = tostring(self.cur_use)
|
|
end
|
|
|
|
|
|
function ItemUseView:DoViewAnim(show, call_back)
|
|
if not ClientConfig.view_scale_ani_mode then
|
|
if call_back then
|
|
call_back()
|
|
end
|
|
return
|
|
end
|
|
|
|
if not self.gameObject then return end
|
|
self.is_in_anim = true
|
|
local tween_type = show and TweenFunc.EASE_OUT_BACK or TweenFunc.EASE_IN_BACK
|
|
local cfg = show and BaseView.OpenCloseScaleCfg[1] or BaseView.OpenCloseScaleCfg[2]
|
|
local cur_scale = Vector3.New(cfg.start_scale, cfg.start_scale, cfg.start_scale)
|
|
local target_scale = Vector3.New(cfg.end_scale, cfg.end_scale, cfg.end_scale)
|
|
--local target_scale = Vector3.New(3,3, 3)
|
|
local time = cfg.time
|
|
SetLocalScale(self.gameObject.transform, cur_scale.x, cur_scale.y, cur_scale.z)
|
|
if self.scale_anim_id then
|
|
TweenLite.Stop(self.scale_anim_id)
|
|
self.scale_anim_id = nil
|
|
end
|
|
self:ResetUIZDepth()
|
|
self.scale_anim_id = TweenLite.to(self, self.gameObject.transform, TweenLite.UiAnimationType.SCALE, target_scale, time, call_back, tween_type)
|
|
end
|
|
|
|
function ItemUseView:ResetViewUIZDepth(layer_count)
|
|
UIDepth.SetUIDepth(self.gameObject,true, layer_count + 10)
|
|
end
|
|
|
|
function ItemUseView:ChangeSceneHandle()
|
|
local is_hide = SceneManager.Instance:IsJumpOneScene() or SceneManager.Instance:IsMirrorPkRankScene()
|
|
self.contain_obj:SetActive(not is_hide)
|
|
|
|
end
|
|
|
|
--是否是可以自动传的装备(1代装备)
|
|
function ItemUseView:IsAutoEquip()
|
|
if not self.vo or not self.vo.type_id then return false end
|
|
--105级之前自动穿戴
|
|
if RoleManager.Instance.mainRoleInfo.level <= 105 then
|
|
return true
|
|
end
|
|
local cfg = Config.Equipment[self.vo.type_id]
|
|
--1代装备,绿色品质,普通装备(不包括首饰和守护)
|
|
return cfg and cfg.series == 1 and self.vo.color <= 1 and cfg.equip_type < EquipModel.EquipType.Necklace
|
|
end
|
|
|
|
--当前装备的代数和部位
|
|
function ItemUseView:GetEquipSeriesAndPos()
|
|
local cfg = Config.Equipment[self.vo.type_id]
|
|
if cfg then
|
|
return cfg.series, cfg.equip_type
|
|
end
|
|
end
|
|
|
|
function ItemUseView:AddToStageHandler()
|
|
local helpVo = GuideModel:getInstance():GetHelpVo(HelpType.TYPE_EQUIP_COLLECT_ONE,1)
|
|
or GuideModel:getInstance():GetHelpVo(HelpType.TYPE_EQUIP_COLLECT_TWO,1)
|
|
if not helpVo then return end
|
|
local help_type = helpVo.help_type
|
|
if help_type == HelpType.TYPE_EQUIP_COLLECT_ONE or help_type == HelpType.TYPE_EQUIP_COLLECT_TWO then
|
|
local step = helpVo.step
|
|
local button = false
|
|
if (help_type == HelpType.TYPE_EQUIP_COLLECT_ONE and step == 1) or (help_type == HelpType.TYPE_EQUIP_COLLECT_TWO and step == 1) then
|
|
button = self.use_btn
|
|
end
|
|
if button then
|
|
local function call_back()
|
|
|
|
end
|
|
GlobalEventSystem:Fire(EventName.OPEN_GUIDE_PROMPT_VIEW, button.transform, button.transform.parent.transform, call_back, helpVo, self.layout_file)
|
|
end
|
|
GlobalEventSystem:Fire(EventName.STOP_AUTO_DO_TASK)
|
|
GlobalEventSystem:Fire(EventName.STOPAUTOFIGHT)
|
|
else
|
|
GlobalEventSystem:Fire(EventName.CLOSE_GUIDE_PROMPT_VIEW)
|
|
end
|
|
end
|
|
|
|
function ItemUseView:Close()
|
|
self:CloseGuide()
|
|
BaseView.Close(self)
|
|
end
|
|
|
|
function ItemUseView:CloseGuide()
|
|
local helpVo = GuideModel:getInstance():GetHelpVo(HelpType.TYPE_EQUIP_COLLECT_ONE,1)
|
|
or GuideModel:getInstance():GetHelpVo(HelpType.TYPE_EQUIP_COLLECT_TWO,1)
|
|
if helpVo then
|
|
GlobalEventSystem:Fire(EventName.FINISH_CURRENT_HELP_STEP,helpVo)
|
|
end
|
|
end
|
|
|
|
|
|
|