背包系统之值得学习的代码块

获取服务器数据

if v == 1 then --装备
	_dats = user.GetEquips()
	table.sort(_dats, PY_Equip.Compare)
elseif v == 2 then --道具
	_dats =
		user.GetProps(
		function(p)
			return p.qty > 0 and p.trg > 0
		end
	)
	table.sort(_dats, DB_Props.Compare)
else
	_dats = nil
	return
end

自动给页签挂上对应的窗口,以及添加点击事件

_ui = cmp.nsrf

_tabs = _ui.btnTabs    
for i = 1, #_tabs do        
	local tab = _tabs[i]        
	tab.luaBtn.luaCmp = _w.body        
	tab.luaBtn:SetClick("ClickTab", i) --i为param,相当于标识    
end

给Tips弹窗添加Animation组件

function _tp.ShowPopTip(str)
    if str == nil or str == "" then
        return
    end
    local it = _itRt:AddChild(_it)
    it:ChildWidget("lbl").text = str
    it:SetActive(true)
    
    EF.PlayAni(it, "ToolTip")
end

无限列表UIWrapGrid
自动生成道具

function _w:OnWrapGridInitItem(go, idx)
    if idx < 0 or _dats == nil or idx >= #_dats then
        return false
    end
    local ig = Item.Get(go)
    if ig == nil then
        ig = ItemGoods(go)
        go.luaBtn.luaCmp = _w.body
    end
    go.luaBtn.param = idx
    go.gameObject.name = "item_" .. _dats[idx + 1].dbsn
    ig:Init(_dats[idx + 1])
    ig:ShowName()
    _gridTex:Add(ig.imgl)
    if ig.dat and (ig.dat == _curDat or _curDat == nil) then
        _curItem = ig
        if _curDat == nil then
            _curDat = ig.dat
            RefreshInfoPanel()
        end
        _SelectedNum = idx
        ig.Selected = true
    else
        ig.Selected = false
    end
    return true
end

无限列表还原

	_itemGrid = _ui.scrollView:GetCmp(typeof(UIWrapGrid))
	_itemGrid:Reset()
	_itemGrid.realCount = #_dats

道具的点击事件

function _w:ClickItemGoods(btn, idx)
    print("ClickItemGoods--------------")
    btn = btn and Item.Get(btn.gameObject)
    if _curItem ~= btn then
        if _curItem then
            _curItem.Selected = false
        end
        _curItem = btn
        if _curItem then
            _curItem.Selected = true
        end
        _SelectedNum = idx
    end
    btn = btn and btn.dat
    if btn ~= _curDat then
        _curDat = DataCell.DataChange(_curDat, btn, WinTestTwo)
        RefreshInfoPanel()
    end
end

获取Item图标(数据,数据类型(可为nil))

	_ui.tex_img:Load(ResName.GetItemIco(d, tp))

根据稀有度给色

	_pnlEqp.nm.text = ColorStyle.Rare(_curDat)

强化装备demo

function _w:ClickEquipUp()
	local tp = objt(_curDat)
	if tp == PY_Equip then
		if _curDat.IsLvLmt then
			ToolTip.ShowPopTip(L("当前装备等级已经达到主城上限,请升级主城等级"))
			return
		end
	
		SVR.EquipUpgrade(
		_curDat.sn,
		0,
		false,
		function(result)
			if result.success then
				RefreshInfoPanel()
				ToolTip.ShowPopTip(L("强化成功!"))
			end
		end
		)
	end
end

点击使用道具

function _w:ClickOption()
    local tp = objt(_curDat)
    if tp == PY_Props then
        --道具使用
        if _curDat.dbsn > 0 then
            PopUseProps.Use(
                _curDat,
                0,
                function(t)
                    if t.success then
                        RefreshInfoPanel()
                        ToolTip.ShowPopTip(L("使用成功"))
                    end
                end
            )
        end
    end
end

滑动条

function _w:ClickPress(isPress)
    local ta = _ui.proBar:GetCmp(typeof(TweenAlpha))
    local ts = _ui.proBar:GetCmp(typeof(TweenScale))

    if isPress then
        if _ui.proBar.alpha > 0 then
            ta.delay = 0
            ta:PlayForward()
            return
        end

        ta:ResetToBeginning()
        ta.delay = 0
        ta:PlayForward()
        ts:ResetToBeginning()
        ts.delay = 0
        ts:PlayForward()
    else
        ta.delay = 0.5
        ta:PlayReverse()
    end
end            
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值