优化这段代码 if index == BackpackMainWindow.TAB.attr or index == BackpackMainWindow.TAB.backpack then self.titlePanel:Hiden() self.growPanel:Hiden() self.characterpanel:Show() self.honorPanel:Hiden() if index == BackpackMainWindow.TAB.attr then self.attrpanel:Show() self.backgridpanel:Hiden() elseif index == BackpackMainWindow.TAB.backpack then self.attrpanel:Hiden() self.growPanel:Hiden() self.backgridpanel:Show(self.openArgs) self.secondTab = nil end elseif index == BackpackMainWindow.TAB.title then self.characterpanel:Hiden() self.backgridpanel:Hiden() self.attrpanel:Hiden() self.growPanel:Hiden() self.titlePanel:Show(self.extra_param) self.honorPanel:Hiden() elseif index == BackpackMainWindow.TAB.grow then self.characterpanel:Hiden() self.backgridpanel:Hiden() self.attrpanel:Hiden() self.titlePanel:Hiden() self.growPanel:Show(0) self.honorPanel:Hiden() elseif index == BackpackMainWindow.TAB.honor then self.characterpanel:Hiden() self.backgridpanel:Hiden() self.attrpanel:Hiden() self.titlePanel:Hiden() self.growPanel:Hiden() self.honorPanel:Show() end
时间: 2024-02-24 12:00:11 浏览: 72
可以将每个TAB对应的操作封装成一个函数,然后根据不同的index调用对应的函数,代码如下:
```lua
function BackpackMainWindow:ShowCharacterPanel()
self.titlePanel:Hiden()
self.growPanel:Hiden()
self.characterpanel:Show()
self.honorPanel:Hiden()
end
function BackpackMainWindow:ShowAttributePanel()
self.titlePanel:Hiden()
self.growPanel:Hiden()
self.characterpanel:Show()
self.honorPanel:Hiden()
self.attrpanel:Show()
self.backgridpanel:Hiden()
end
function BackpackMainWindow:ShowBackpackPanel()
self.titlePanel:Hiden()
self.growPanel:Hiden()
self.characterpanel:Show()
self.honorPanel:Hiden()
self.attrpanel:Hiden()
self.growPanel:Hiden()
self.backgridpanel:Show(self.openArgs)
self.secondTab = nil
end
function BackpackMainWindow:ShowTitlePanel()
self.characterpanel:Hiden()
self.backgridpanel:Hiden()
self.attrpanel:Hiden()
self.growPanel:Hiden()
self.titlePanel:Show(self.extra_param)
self.honorPanel:Hiden()
end
function BackpackMainWindow:ShowGrowPanel()
self.characterpanel:Hiden()
self.backgridpanel:Hiden()
self.attrpanel:Hiden()
self.titlePanel:Hiden()
self.growPanel:Show(0)
self.honorPanel:Hiden()
end
function BackpackMainWindow:ShowHonorPanel()
self.characterpanel:Hiden()
self.backgridpanel:Hiden()
self.attrpanel:Hiden()
self.titlePanel:Hiden()
self.growPanel:Hiden()
self.honorPanel:Show()
end
function BackpackMainWindow:OnTabClick(index)
if index == BackpackMainWindow.TAB.attr then
self:ShowAttributePanel()
elseif index == BackpackMainWindow.TAB.backpack then
self:ShowBackpackPanel()
elseif index == BackpackMainWindow.TAB.title then
self:ShowTitlePanel()
elseif index == BackpackMainWindow.TAB.grow then
self:ShowGrowPanel()
elseif index == BackpackMainWindow.TAB.honor then
self:ShowHonorPanel()
end
end
```
这样,代码更加清晰,易于维护和修改。同时,如果需要新增或修改某个TAB对应的操作,只需在对应的函数中修改即可,不会影响到其他部分的代码。
阅读全文