newlist

  博客园 :: 首页 :: 博问 :: 闪存 :: 新随笔 :: 联系 :: 订阅 订阅 :: 管理 ::
-- 这里要注意的点是:虽然nAmount是局部变量,却在控件的响应函数中使用
-- 因为控件的响应函数是在该变量的区域内,所以可以用
-- 如果控件的响应函数在外部,那么该变量就要声明成为全局变量
function UIBagController:showUse(  )
    -- 赋值属性
    local nAmount = self.item.pileCount;
    local imageViewItem = tolua.cast(UIHelper:seekWidgetByName(self.panelUse, "ImageView_Item"), "ImageView");
    local labelItemDsc = tolua.cast(UIHelper:seekWidgetByName(self.panelUse, "Label_ItemDsc"), "Label");
    local lebGNum = tolua.cast(UIHelper:seekWidgetByName(self.panelUse, "lebGNum"), "Label");
    local btnNumDes = tolua.cast(UIHelper:seekWidgetByName(self.panelUse, "btnNumDes"), "Button");
    local btnGNumAdd = tolua.cast(UIHelper:seekWidgetByName(self.panelUse, "btnGNumAdd"), "Button");
    local btnMax = tolua.cast(UIHelper:seekWidgetByName(self.panelUse, "btnMax"), "Button");
    lebGNum:setText(nAmount .. "/99");
    btnNumDes:addTouchEventListener(function ( uiwidget, eventType )
        if eventType == TOUCH_EVENT_ENDED then
            -- 数字减少
            if nAmount > 1 then
                nAmount = nAmount - 1;
                lebGNum:setText(nAmount .. "/99");
            end
        end;
    end);
    btnGNumAdd:addTouchEventListener(function ( uiwidget, eventType )
        if eventType == TOUCH_EVENT_ENDED then
            -- 数字增加
            if nAmount < self.item.pileCount then
                nAmount = nAmount + 1;
                lebGNum:setText(nAmount .. "/99");
            end
        end;
    end);
    btnMax:addTouchEventListener(function ( uiwidget, eventType )
        if eventType == TOUCH_EVENT_ENDED then
            -- 数字直接到最大
            lebGNum:setText(self.item.pileCount .. "/99");
        end;
    end);
    imageViewItem:loadTexture(self.item:getIconPath());
    labelItemDsc:setText(self.item:getDsc());
    self:setLabelFont(labelItemDsc)
    local labelItenNum = tolua.cast(UIHelper:seekWidgetByName(self.panelUse, "Label_ItenNum"), "Label");
    self:showItemNum(self.item, labelItenNum)
    
    self.panelUse:setVisible(true)    
    self.panelUse:setEnabled(true);
    self.panelUse:setTouchEnabled(true);

    self:hideDetail()
    self:hideSell()
end

 

posted on 2014-04-15 19:55  一枚程序  阅读(3844)  评论(0编辑  收藏  举报