NotifyItemCtr.lua 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. local NotifyItemCtr = {}
  2. local _indexAndCloseFun = {};
  3. local _limitCount;
  4. function NotifyItemCtr:SetData(_wnd, _item, _data, _openCb, _closeCb)
  5. if not _limitCount then
  6. _limitCount = GlobalConfig.Instance:GetConfigIntValue(143)
  7. end
  8. self:SetBtnState(_data._showing, _item.btnRight, _item.btnDown, _item.content, _item.textNotifyTitle.text, _data.NoticeTitle);
  9. _wnd.uiBase:AddButtonUniqueEventListener(_item.textNotifyTitle.button, _wnd, function()
  10. if _data._showing then
  11. _closeCb(_wnd,_data)
  12. _data._showing = false
  13. self:SetBtnState(false, _item.btnRight, _item.btnDown, _item.content, _item.textNotifyTitle.text, _data.NoticeTitle);
  14. else
  15. local _lastItem,_title = _openCb(_wnd,_item,_data)
  16. if _lastItem ~= nil then
  17. self:SetBtnState(false, _lastItem.btnRight, _lastItem.btnDown, _lastItem.content, _lastItem.textNotifyTitle.text, _title);
  18. end
  19. _data._showing = true;
  20. self:SetBtnState(true, _item.btnRight, _item.btnDown, _item.content, _item.textNotifyTitle.text, _data.NoticeTitle);
  21. end
  22. end);
  23. _item.textMain.text.text = _data.NoticeTxt;
  24. if _data.LimitedTimeLabel then
  25. _item.textDate.text.text = string.sub(_data.NoticeBeginTime, 1, 10);
  26. else
  27. _item.textDate.text.text = ''
  28. end
  29. end
  30. --设置按钮状态
  31. function NotifyItemCtr:SetBtnState(_open, _btnRight, _btnDown, _content, _text, _titleStr)
  32. _btnRight.gameObject:SetActive(not _open);
  33. _btnDown.gameObject:SetActive(_open);
  34. _content.gameObject:SetActive(_open);
  35. _text.text = self:JudgeTitle(_open, _titleStr);
  36. end
  37. --判断title的显示
  38. function NotifyItemCtr:JudgeTitle(_open, _titleStr)
  39. if _open then
  40. return _titleStr;
  41. else
  42. local _count = StringUtil.GetStringByteLength(_titleStr);
  43. if _count >= _limitCount then
  44. return StringUtil.CutOutString(_titleStr, _limitCount) .. "..."; --策划要求显示16个中文字,一个中文字相当于非中文两个字
  45. else
  46. return _titleStr;
  47. end
  48. end
  49. end
  50. return NotifyItemCtr