|
|
-
- PopupComponent = PopupComponent or BaseClass(BaseComponent)
-
- function PopupComponent:__init(parent,layout_file,default_text,popup_list,call_back)
- self.show_list = false
- self:InitData(layout_file,default_text,popup_list,call_back)
- self:CreateGameObject(UIType.PopupComponent)
-
- end
-
- function PopupComponent:InitData(layout_file,default_text,popup_list,call_back)
- self.popup_item_list = {}
- self.layout_file = layout_file
- self.default_text = default_text or ""
- self.popup_list = popup_list or {}
- self.call_back = call_back
- end
-
- function PopupComponent:LoadSuccess()
- self.item_parent = self:GetChild("Mask/Parent/ItemParent")
- self.popup_parent = self:GetChild("Mask/Parent")
- self.popup_bg = self:GetChild("Mask/Parent/Bg")
- self.hideListBtn = self:GetChild("HideListBtn").gameObject
-
- self.arrow = self:GetChild("PopupBtn/Arrow")
- self.popup_btn = self:GetChild("PopupBtn").gameObject
- self.popup_btn_txt = self:GetChild("PopupBtn/Value"):GetComponent("Text")
-
- self:InitEvent()
- self:LayoutUI()
- end
-
- --在父窗口调用
- function PopupComponent:__delete()
- if self.select_item_id then
- GlobalEventSystem:UnBind(self.select_item_id)
- self.select_item_id = nil
- end
-
- for i,item in pairs(self.popup_item_list) do
- item:DeleteMe()
- end
-
- self.popup_item_list = {}
- end
-
- function PopupComponent:LayoutUI()
- self.popup_btn_txt.text = self.default_text
- self:SetPopupItemList()
- end
-
- function PopupComponent:PopupBtnClick()
- self.show_list = not self.show_list
- if self.show_list then
- self:ShowPopupList()
- else
- self:HidePopupList()
- end
- end
-
- function PopupComponent:InitEvent()
- local function onBtnClickHandler(target)
- if target == self.popup_btn then
- self:PopupBtnClick()
- elseif target == self.hideListBtn then
- self:HidePopupList()
- end
- end
-
- AddClickEvent(self.popup_btn, onBtnClickHandler,LuaSoundManager.SOUND_UI.SWITCH)
- AddClickEvent(self.hideListBtn, onBtnClickHandler,LuaSoundManager.SOUND_UI.SWITCH)
-
- local function onSelectItem(layout_file,data)
- if self.layout_file == layout_file then
- self:SetPopupBtnText(data.content)
- self:HidePopupList()
- end
- end
-
- self.select_item_id = GlobalEventSystem:Bind(EventName.SELECT_POPUP_LIST_ITEM,onSelectItem)
- end
-
- function PopupComponent:SetPopupBtnText(str)
- self.popup_btn_txt.text = str
- end
-
- function PopupComponent:ShowPopupList()
- if self.is_moving then
- return
- end
-
- self.show_list = true
-
- self.hideListBtn:SetActive(true)
-
- self.arrow.localRotation = Quaternion.Euler(0,0,90)
- local sizeDelta = self.popup_bg.sizeDelta
- self.popup_parent.localPosition = Vector3(0,sizeDelta.y,0)
-
- self.popup_parent.gameObject:SetActive(true)
-
- local function onCompleted()
- self.is_moving = false
- end
-
- TweenLite.to(self, self.popup_parent,TweenLite.UiAnimationType.POSY,0,0.1,onCompleted)
- end
-
- function PopupComponent:HidePopupList()
-
- if self.is_moving then
- return
- end
-
- self.show_list = false
-
- self.hideListBtn:SetActive(false)
-
- self.arrow.localRotation = Quaternion.Euler(0,0,270)
-
- local function onCompleted()
- self.is_moving = false
- self.popup_parent.gameObject:SetActive(false)
- end
-
- local sizeDelta = self.popup_bg.sizeDelta
-
- TweenLite.to(self, self.popup_parent,TweenLite.UiAnimationType.POSY,sizeDelta.y,0.1,onCompleted)
- end
-
- function PopupComponent:SetPopupItemList()
-
- local popup_list = self.popup_list
- local len = #popup_list
- for i,v in ipairs(popup_list) do
- item = self.popup_item_list[i]
- if item == nil then
- item = PopupSelectItem.New(self.item_parent)
- table.insert(self.popup_item_list,item)
- end
- item:SetVisible(true)
- item:SetData(i,self.layout_file,v,self.call_back)
- end
-
- self.popup_bg.sizeDelta = Vector2(152,len*50 + 8)
-
- for i=#popup_list + 1,#self.popup_item_list do
- self.popup_item_list[i]:SetVisible(false)
- end
- end
-
|