TextFaceItem = TextFaceItem or BaseClass(BaseItem) function TextFaceItem:__init() self.base_file = "chat" self.layout_file = "textFaceItem" -- self.use_local_view = true self.model = ChatModel:getInstance() self.index = nil self.vo = nil self:Load() end function TextFaceItem:Load_callback() self.select , self.textObj, self.bg, self.addBtn, self.delBtn = GetChildGameObjects(self.transform,{ "Select", "Text", "bg", "addBtn", "delBtn" }) self.select:SetActive(false) self.text = GetChildTexts(self.transform,{ "Text" }) if self.need_refreshData then self:SetData() end local function onClickBtnHandler(target) if target == self.textObj then if self.vo then if self.index > #Config.ConfigChat.text_face and not self.model.horn_view_is_open then --自定义的文字直接发送到聊天频道 self.model:Fire(ChatModel.SEND_MSG_IN_VIEW, self.vo.one) GlobalEventSystem:Fire(EventName.CLOSE_INDIVIDUATION_VIEW) else --选中并发送到输入框 self.model:SeletedTextFaceItem(self) end else GlobalEventSystem:Fire(EventName.OPEN_CHAT_CUSTOM_TEXT_VIEW, self.index) end elseif target == self.addBtn then GlobalEventSystem:Fire(EventName.OPEN_CHAT_CUSTOM_TEXT_VIEW, self.index) elseif target == self.delBtn then local cookie = CookieWrapper.Instance:GetCookie(CookieLevelType.Account, CookieKey.CHAT_CUSTOM_TEXT) if cookie and cookie[self.index] then cookie[self.index] = nil CookieWrapper.Instance:SaveCookie(CookieLevelType.Account, CookieTimeType.TYPE_ALWAYS, CookieKey.CHAT_CUSTOM_TEXT, cookie) Message.show("删除成功") self.model:Fire(ChatModel.UPDATE_INDIVID_VIEW) end end end AddClickEvent(self.textObj,onClickBtnHandler) AddClickEvent(self.addBtn,onClickBtnHandler) AddClickEvent(self.delBtn,onClickBtnHandler) end function TextFaceItem:SetData(index) self.index = index or self.index if self.is_loaded then self.need_refreshData = false if self.index > #Config.ConfigChat.text_face then local cookie = CookieWrapper.Instance:GetCookie(CookieLevelType.Account, CookieKey.CHAT_CUSTOM_TEXT) if cookie and cookie[self.index] then self.vo = {} self.vo.desc = cookie[self.index].desc self.vo.one = cookie[self.index].one self.vo.two = "" self.text.text = self.vo.desc self.addBtn:SetActive(false) self.delBtn:SetActive(true) else self.vo = nil self.text.text = "" self.addBtn:SetActive(true) self.delBtn:SetActive(false) end else self.vo = Config.ConfigChat.text_face[self.index] self.text.text = self.vo.desc self.addBtn:SetActive(false) self.delBtn:SetActive(false) end else self.need_refreshData = true end end function TextFaceItem:SetSelect(bool) if bool then self.select:SetActive(true) else self.select:SetActive(false) end end