SoundItemChoosePopUp = class("SoundItemChoosePopUp", BaseView) SoundItemChoosePopUp.ViewType = UIViewType.PopUpLayer autoImport("SoundItemCell"); function SoundItemChoosePopUp:Init() self:InitUI(); self:MapEvent(); self.npc = self.viewdata.viewdata.npc; end function SoundItemChoosePopUp:InitUI() local grid = self:FindComponent("SoundListGrid", UIGrid); self.soundItemCtl = UIGridListCtrl.new(grid , SoundItemCell, "SoundItemCell"); self.soundItemCtl:AddEventListener(SoundItemCellEvent.Play, self.ChoosePlay, self); self.soundItemCtl:AddEventListener(SoundItemCellEvent.Buy, self.ChooseBuy, self); self:UpdateSoundItems(); end function SoundItemChoosePopUp:UpdateSoundItems() local soundItems = {}; local bagProxy = BagProxy.Instance; for _,mdata in pairs(Table_MusicBox) do local item = BagProxy.Instance:GetItemByStaticID(mdata.id); if(not item)then item = ItemData.new("SoundItem", mdata.id); end table.insert(soundItems, item); end table.sort(soundItems, function (a,b) local hasA = a.id ~= "SoundItem"; local hasB = b.id ~= "SoundItem"; if(hasA~=hasB)then return hasA; end return a.staticData.id