源战役客户端
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.

136 line
4.4 KiB

  1. -- <*
  2. -- @Author: msh
  3. -- @Description: 界面view
  4. -- *>
  5. ChildShowBabyView = ChildShowBabyView or BaseClass(BaseView)
  6. local ChildShowBabyView = ChildShowBabyView
  7. function ChildShowBabyView:__init()
  8. self.base_file = "child"
  9. self.layout_file = "ChildShowBabyView"
  10. self.layer_name = "Activity"
  11. self.destroy_imm = true
  12. self.use_background = G_USING_BG --全屏界面默认使用这个参数
  13. --self.hide_maincancas = true --全屏界面需要放开隐藏主UI
  14. self.change_scene_close = true
  15. self.append_to_ctl_queue = false --是否要添加进界面堆栈
  16. self.need_show_money = false --是否要显示顶部的金钱栏
  17. self.model = ChildModel:getInstance()
  18. self.send_limit = ChildConst.ShowBabyTextLenLimit
  19. self.load_callback = function ()
  20. self:LoadSuccess()
  21. self:AddEvent()
  22. end
  23. self.open_callback = function ( )
  24. self:OpenSuccess()
  25. end
  26. self.switch_callback = function(index)
  27. self:SwitchTab(index)
  28. end
  29. self.destroy_callback = function ( )
  30. self:DestroySuccess()
  31. end
  32. end
  33. function ChildShowBabyView:Open( )
  34. --self.data = data
  35. BaseView.Open(self)
  36. end
  37. function ChildShowBabyView:LoadSuccess()
  38. local nodes = {
  39. "btn_close:obj", "showCSBtn:obj",
  40. "showGuildBtn:obj", "showBtn:obj:img",
  41. "showWorldBtn:obj","bg:raw",
  42. }
  43. self:GetChildren(nodes)
  44. self.input_text = self:GetChild("input"):GetComponent("InputField")
  45. lua_resM:setOutsideRawImage(self,self.bg_raw,GameResPath.GetViewBigBg("tips_comm_bg6"),false)
  46. self:ChangeShowText()
  47. self:UpdateBaseView( )
  48. end
  49. function ChildShowBabyView:UpdateBaseView( )
  50. end
  51. function ChildShowBabyView:AddEvent()
  52. local on_click = function ( click_obj )
  53. if self.showBtn_obj == click_obj then
  54. self:ChangeShowText()
  55. elseif self.showWorldBtn_obj == click_obj then -- 世界晒娃
  56. if RoleManager.Instance.mainRoleInfo.level >= Config.Moduleid[110].open_lv then
  57. self.model:Fire(ChildConst.CHILD_REQ_EVENT, 16509,ChatModel.CHANNEL_WORLD)
  58. else
  59. Message.show("等级不足"..Config.Moduleid[110].open_lv, "fault")
  60. end
  61. elseif self.showCSBtn_obj == click_obj then -- 跨服晒
  62. if RoleManager.Instance.mainRoleInfo.level >= Config.ConfigOpenLv.ChatOpenLevel.CROSS then
  63. self.model:Fire(ChildConst.CHILD_REQ_EVENT, 16509,ChatModel.CHANNEL_CROSS)
  64. else
  65. Message.show("等级不足"..Config.ConfigOpenLv.ChatOpenLevel.CROSS, "fault")
  66. end
  67. --Message.show("2")
  68. elseif self.showGuildBtn_obj == click_obj then -- 社团晒
  69. if RoleManager.Instance.mainRoleInfo.level >= Config.ConfigOpenLv.ChatOpenLevel.GUILD and ( RoleManager.Instance:GetMainRoleVo().guild_id and RoleManager.Instance:GetMainRoleVo().guild_id ~= 0) then
  70. self.model:Fire(ChildConst.CHILD_REQ_EVENT, 16509,ChatModel.CHANNEL_GUILD)
  71. else
  72. Message.show("社团频道还未开启哦", "fault")
  73. end
  74. elseif self.btn_close_obj == click_obj then
  75. self:Close()
  76. end
  77. end
  78. AddClickEvent(self.showBtn_obj, on_click)
  79. AddClickEvent(self.showWorldBtn_obj, on_click)
  80. AddClickEvent(self.showCSBtn_obj, on_click)
  81. AddClickEvent(self.showGuildBtn_obj, on_click)
  82. AddClickEvent(self.btn_close_obj, on_click)
  83. self.input_text.onValueChanged:AddListener(function()
  84. local len = utf8len(self.input_text.text)
  85. if len > self.send_limit then
  86. self.input_text.text = string.sub(self.input_text.text, 1, self.send_limit-len-1) --减去多出来的字符
  87. self.tip_time = self.tip_time or 0
  88. if Status.NowTime - self.tip_time > 0.1 then
  89. Message.show(string.format("最多可输入%d个字符", self.send_limit))
  90. self.tip_time = Status.NowTime
  91. end
  92. end
  93. -- 判断是否是人为输入
  94. -- local is_need_name = self.input_text.text == ChildConst.ShowBabyText[self.last_index or 1]
  95. self.model:SetShowBabyStr( self.input_text.text, is_need_name )
  96. end)
  97. end
  98. function ChildShowBabyView:ChangeShowText( )
  99. local cfg = ChildConst.ShowBabyText
  100. local index = math.random(1, #cfg)
  101. if self.last_index and index == self.last_index then -- 不跟上一套重复
  102. local new_index = index + 1
  103. index = new_index <= #cfg and new_index or 1
  104. end
  105. self.last_index = index
  106. local childList = self.model:GetChildInfo()
  107. local child_name = childList.child_name
  108. self.input_text.text = string.format(cfg[index], "<" .. child_name .. ">")
  109. self.model:SetShowBabyStr( self.input_text.text)
  110. end
  111. function ChildShowBabyView:OpenSuccess()
  112. self:UpdateView()
  113. end
  114. function ChildShowBabyView:UpdateView()
  115. end
  116. function ChildShowBabyView:SwitchTab( index )
  117. end
  118. function ChildShowBabyView:DestroySuccess( )
  119. end