|
|
- ComboxView = ComboxView or BaseClass(BaseView)
- local ComboxView = ComboxView
-
- function ComboxView:__init(parent_wnd, prefab_data, layer_name)
- self.base_file = "uiComponent"
- self.layout_file = prefab_data and prefab_data.ComboxView or "ComboxView"
- self.layer_name = layer_name or "Activity"
- self.destroy_imm = true
- self.use_background = false
- self.change_scene_close = true
- self.prefab_data = prefab_data or {Combox = "Combox",ComboxView = "ComboxView", ComboxItem = "ComboxItem", show_type = "down"}
- self.height_extra = 0
- self.pos = Vector3(0,0,0)
- self.item_list = {}
- self.red_data = {}
- self:SetOfferXY()
-
- self.load_callback = function ()
- self:LoadSuccess()
- self:AddEvent()
- end
- self.open_callback = function ( )
- self:OpenSuccess()
- end
- self.destroy_callback = function ( )
- self:DestroySuccess()
- end
- end
-
- function ComboxView:Close()
- if self.combox_close_callback then
- self.combox_close_callback()
- end
- BaseView.Close(self)
- end
-
- function ComboxView:Open(data,callback,combox_close_callback,pos,red_data)
- self.data = data or {}
- self.callback = callback
- self.combox_close_callback = combox_close_callback
- self.pos = pos
- self.red_data = red_data or {}
-
- BaseView.Open(self)
- end
-
- --设置偏移量
- function ComboxView:SetOfferXY( )
- if self.layout_file == "ComboxView" then
- self.bg_add_height = 0
- self.bg_offerx = -11
- self.bg_offery = 0
- end
- end
-
- function ComboxView:SetSize(width,height)
- self.width = width
- self.height = height
- if self.img_bg then
- local height = #self.data * (ComboxItem.Height+self.height_extra)+18
- if #self.data == 0 then
- height = (ComboxItem.Height+self.height_extra)
- end
- self.img_bg.sizeDelta = Vector2(self.width,height)
- end
- end
-
- function ComboxView:LoadSuccess()
- self.img_bg = self:GetChild("img_bg")
- self.con = self:GetChild("img_bg/con")
- self.touch_con = self:GetChild("touch_con").gameObject
- SetSizeDelta(self.touch_con.transform, ScreenWidth*1.5, ScreenHeight*1.5)
-
- local width = self.width or self.img_bg.sizeDelta.x
- --总高度
- local height = #self.data * (ComboxItem.Height+self.height_extra)+3
- if #self.data == 0 then
- height = (ComboxItem.Height+self.height_extra)
- end
- self.height = height
- self.img_bg.sizeDelta = Vector2(width,height+self.bg_add_height)
- if self.pos then
- self:SetTransOffsetY()
- local pos = self.img_bg:InverseTransformPoint(self.pos)
- self.img_bg.localPosition = Vector3(pos.x+self.bg_offerx,pos.y+self.bg_offery,0)
- end
- end
-
- function ComboxView:SetTransOffsetY( )
- if self.prefab_data.offset_y then
- if self.prefab_data.show_type == "down" then
- self.bg_offery = -30 + self.prefab_data.offset_y + self.height
- else
- self.bg_offery = 16 + self.prefab_data.offset_y + self.height + self.height
- end
- end
- end
-
- function ComboxView:AddEvent()
- local function onClick(...)
- self:Close()
- end
- AddClickEvent(self.touch_con,onClick)
- end
-
- function ComboxView:OpenSuccess()
- -------------------------
- local function callback(index)
- if self.callback then
- self.callback(index)
- end
- self:Close()
- end
- local x = 0
- local height = self.img_bg.sizeDelta.y
- for i=1,#self.data do
- local item = self.item_list[i]
- if not item then
- item = ComboxItem.New(self.img_bg,nil,nil,self.prefab_data)
- self.item_list[i] = item
- item:SetPosition(x,-(i-1) * ComboxItem.Height-3)
- end
- item:SetData(i,self.data[i],callback,self.red_data[i])
- item:SetWidth(self.img_bg.sizeDelta.x)
- end
- end
-
- function ComboxView:UpdateView( )
-
- end
-
- function ComboxView:DestroySuccess( )
- for k,v in pairs(self.item_list) do
- v:DeleteMe()
- end
- self.item_list = {}
- end
|