源战役客户端
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

64 lines
2.0 KiB

  1. --个性化聊天界面
  2. ChatCustomTextView = ChatCustomTextView or BaseClass(BaseView)
  3. function ChatCustomTextView:__init()
  4. self.base_file = "chat"
  5. self.layout_file = "chatCustomTextView"
  6. self.layer_name = "UI"
  7. self.destroy_imm = true
  8. self.use_background = true
  9. self.click_bg_toClose = true
  10. self.change_scene_close = true
  11. self.background_alpha = 0
  12. self.model = ChatModel:getInstance()
  13. self.load_callback = function ()
  14. self:LoadSuccess()
  15. self:InitEvent()
  16. end
  17. self.open_callback = function ()
  18. self.titleText.text = ""
  19. self.contentText.text = ""
  20. end
  21. self.close_callback = function ()
  22. end
  23. self.destroy_callback = function ()
  24. end
  25. end
  26. function ChatCustomTextView:LoadSuccess()
  27. self.titleInput = self:GetChild("titleInput")
  28. self.contentInput = self:GetChild("contentInput")
  29. self.titleText = self:GetChild("titleInput"):GetComponent("InputField")
  30. self.contentText = self:GetChild("contentInput"):GetComponent("InputField")
  31. self.sureBtn = self:GetChild("sureBtn").gameObject
  32. self.cancelBtn = self:GetChild("cancelBtn").gameObject
  33. self.titleText.characterLimit = 4
  34. self.contentText.characterLimit = 25
  35. end
  36. function ChatCustomTextView:Open(index)
  37. self.index = index
  38. BaseView.Open(self)
  39. end
  40. function ChatCustomTextView:InitEvent()
  41. local function onBtnClickHandler(target)
  42. if target == self.sureBtn then
  43. local cookie = CookieWrapper.Instance:GetCookie(CookieLevelType.Account, CookieKey.CHAT_CUSTOM_TEXT)
  44. cookie = cookie or {}
  45. cookie[self.index] = cookie[self.index] or {}
  46. cookie[self.index].desc = string.gsub(self.titleText.text,'(["])',"")
  47. cookie[self.index].one = string.gsub(self.contentText.text,'(["])',"")
  48. CookieWrapper.Instance:SaveCookie(CookieLevelType.Account, CookieTimeType.TYPE_ALWAYS, CookieKey.CHAT_CUSTOM_TEXT, cookie)
  49. Message.show("添加成功")
  50. self.model:Fire(ChatModel.UPDATE_INDIVID_VIEW)
  51. self:Close()
  52. elseif target == self.cancelBtn then
  53. self:Close()
  54. end
  55. end
  56. AddClickEvent(self.sureBtn,onBtnClickHandler)
  57. AddClickEvent(self.cancelBtn,onBtnClickHandler)
  58. end