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

268 lines
9.5 KiB

преди 4 седмици
  1. -- <*
  2. -- @Author: Saber
  3. -- @Description: 社团改名改标识界面
  4. -- *>
  5. GuildRenameView = GuildRenameView or BaseClass(BaseView)
  6. local GuildRenameView = GuildRenameView
  7. function GuildRenameView:__init()
  8. self.base_file = "guild"
  9. self.layout_file = "GuildRenameView"
  10. self.layer_name = "Activity"
  11. self.destroy_imm = true
  12. self.use_background = true --全屏界面默认使用这个参数,非全屏界面自行设置
  13. self.change_scene_close = true --是否切换场景时关闭(弹出界面使用)
  14. -- self.append_to_ctl_queue = true --是否要添加进界面堆栈
  15. self.blur_activity_bg = true
  16. self.use_show_anim = true
  17. self.use_hide_anim = true
  18. self.model = GuildModel:getInstance()
  19. self.no_guild_name_str = "<color=#D5D7DF>(未命名)</color>"
  20. self.tip_time = Status.NowTime
  21. self.icon_list = {} -- 图标列表
  22. self.color_list = {} -- 颜色列表
  23. self.cur_flag = 10001
  24. self.cur_icon_flag = 1
  25. self.cur_icon_color = 1
  26. self.name_limit = 6 -- 社团名称字数限制
  27. self.load_callback = function ()
  28. self:LoadSuccess()
  29. self:AddEvent()
  30. end
  31. self.open_callback = function ( )
  32. self:OpenSuccess()
  33. end
  34. self.switch_callback = function(index)
  35. self:SwitchTab(index)
  36. end
  37. self.destroy_callback = function ( )
  38. self:DestroySuccess()
  39. end
  40. end
  41. function GuildRenameView:Open( )
  42. --self.data = data
  43. BaseView.Open(self)
  44. end
  45. function GuildRenameView:LoadSuccess()
  46. local nodes = {
  47. "content",
  48. "content/comfirm_btn:obj",
  49. "content/cur_icon:img",
  50. "content/name_input:tmpInput",
  51. "content/color_con", "content/icon_con",
  52. "content/rename_cond:tmp",
  53. "content/final_name:tmp",
  54. -- 改名花费
  55. "content/rename_cost_icon:img",
  56. "content/rename_costval:tmp",
  57. -- 改标识花费
  58. "content/flag_cost_icon:img",
  59. "content/flag_costval:tmp",
  60. -- 总花费
  61. "content/total_cost_node",
  62. "content/total_cost_node/total_cost_icon:img",
  63. "content/total_cost_node/total_cost_title:tmp",
  64. "content/total_cost_node/total_costval:tmp",
  65. }
  66. self:GetChildren(nodes)
  67. self.final_name_tmp.text = self.no_guild_name_str
  68. local function close_callback()
  69. self:Close()
  70. end
  71. self.tabWindowComponent = UITabWindow.New(self.transform, {}, nil, close_callback, self.background_wnd, self.content, UITabWindow.SizeSmallNoTab, nil, nil, true)
  72. self.tabWindowComponent:SetTitleText("信息变更")
  73. self.tabWindowComponent:SetBackgroundRes("guild_rename_bg")
  74. end
  75. function GuildRenameView:AddEvent()
  76. local function click_event(target)
  77. if target == self.comfirm_btn_obj then -- 确认修改
  78. self:OnComfirmBtnClick()
  79. end
  80. end
  81. AddClickEvent(self.comfirm_btn_obj, click_event)
  82. -- 输入监听
  83. self.name_input_tmpInput.onValueChanged:AddListener(function()
  84. local len = utf8len(self.name_input_tmpInput.text)
  85. if len > self.name_limit then
  86. self.name_input_tmpInput.text = GetInputLimitResultStr(self.name_input_tmpInput.text, self.name_limit) --减去多出来的字符
  87. self.tip_time = self.tip_time or 0
  88. if Status.NowTime - self.tip_time > 0.2 then
  89. Message.show(string.format("最多可输入%s个字符", self.name_limit), "fault")
  90. self.tip_time = Status.NowTime
  91. end
  92. end
  93. -- 右侧同步玩家输入的社团名称
  94. self.final_name_tmp.text = self.name_input_tmpInput.text == "" and self.no_guild_name_str or self.name_input_tmpInput.text
  95. self:UpdateTotalCost()
  96. end)
  97. end
  98. function GuildRenameView:OpenSuccess()
  99. if self.tabWindowComponent then
  100. self.tabWindowComponent:ChangeShowFlag("smallWindow2")
  101. end
  102. self:UpdateView()
  103. end
  104. function GuildRenameView:UpdateView()
  105. self:InitFlagDataAndChangeCost()
  106. self:UpdateGuildIconAndColor()
  107. end
  108. -- 获取当前的社团旗帜和扣费配置
  109. function GuildRenameView:InitFlagDataAndChangeCost( )
  110. local guild_info = self.model:GetGuildBaseInfo()
  111. local flag = guild_info and guild_info.guild_flag
  112. self.cur_flag = flag
  113. self.cur_icon_flag = flag and math.floor(flag / 10000) or 1
  114. self.cur_icon_color = flag and flag % 10000 or 1
  115. -- 扣费配置
  116. self.changed_name_cfg = stringtotable(self.model:GetGuildKvByKey("rename_cost").val)[1]
  117. local cost_asset, cost_res = WordManager:GetCommonMoneyIcon(self.changed_name_cfg[1])
  118. lua_resM:setImageSprite(self, self.rename_cost_icon_img, cost_asset, cost_res)
  119. self.change_flag_cfg = stringtotable(self.model:GetGuildKvByKey("logo_change_cost").val)[1]
  120. cost_asset, cost_res = WordManager:GetCommonMoneyIcon(self.change_flag_cfg[1])
  121. lua_resM:setImageSprite(self, self.flag_cost_icon_img, cost_asset, cost_res)
  122. end
  123. function GuildRenameView:UpdateGuildIconAndColor( )
  124. local function icon_call_back(index)
  125. for k, v in ipairs(self.icon_list) do
  126. if v.index then
  127. v:SetSelect(v.index == index)
  128. end
  129. end
  130. self.cur_icon_flag = index
  131. self:ChangePreviewIcon()
  132. end
  133. local offset_x = (self.icon_con.sizeDelta.x - 4 * 86) / 2 + 10
  134. for i = 1, 4 do
  135. local item = self.icon_list[i]
  136. if not item then
  137. item = GuildCreateIconItem.New(self.icon_con, nil, self.layer_name)
  138. self.icon_list[i] = item
  139. end
  140. local pos = Vector2((i-1) * 86 + offset_x, -13)
  141. item:SetData(i, pos, icon_call_back)
  142. item:SetSelect(i == self.cur_icon_flag)
  143. end
  144. local function color_callback(index)
  145. for k, v in ipairs(self.color_list) do
  146. if v.index then
  147. v:SetSelect(v.index == index)
  148. end
  149. end
  150. self.cur_icon_color = index
  151. self:ChangePreviewIcon()
  152. end
  153. offset_x = (self.color_con.sizeDelta.x - 8 * 50) / 2 + 6
  154. for i = 1, 8 do
  155. local item = self.color_list[i]
  156. if not item then
  157. item = GuildCreateColorItem.New(self.color_con, nil, self.layer_name)
  158. self.color_list[i] = item
  159. end
  160. local pos = Vector2((i-1) * 50 + offset_x, 0)
  161. item:SetData(i, pos, color_callback)
  162. item:SetSelect(i == self.cur_icon_color)
  163. end
  164. -- color_callback(1)
  165. self:ChangePreviewIcon()
  166. end
  167. -- 修改右侧已设置的社团icon样式和花费
  168. function GuildRenameView:ChangePreviewIcon( )
  169. lua_resM:setImageSprite(self, self.cur_icon_img, "guildIcon_asset", "guild_icon" .. (self.cur_icon_flag * 10000 + self.cur_icon_color), true)
  170. self:UpdateTotalCost()
  171. end
  172. -- 更新总花费
  173. function GuildRenameView:UpdateTotalCost( )
  174. local new_name = self.name_input_tmpInput.text
  175. -- 是否已经改了名字
  176. local changed_name = new_name ~= "" and 1 or 0
  177. -- 是否已经改了旗帜
  178. local new_flag = self.cur_icon_flag * 10000 + self.cur_icon_color
  179. local changed_flag = new_flag ~= self.cur_flag
  180. local rename_cost = changed_name == 1 and self.changed_name_cfg[3] or 0
  181. local flag_cost = changed_flag and self.change_flag_cfg[3] or 0
  182. local total_cost = rename_cost + flag_cost
  183. self.rename_costval_tmp.text = rename_cost
  184. self.flag_costval_tmp.text = flag_cost
  185. self.total_costval_tmp.text = total_cost
  186. -- 对齐节点
  187. local offset_x = (self.total_cost_node.sizeDelta.x - self.total_costval_tmp.preferredWidth - self.total_cost_title_tmp.preferredWidth - 42) / 2
  188. SetAnchoredPositionX(self.total_cost_title, offset_x)
  189. SetAnchoredPositionX(self.total_cost_icon, offset_x + self.total_cost_title_tmp.preferredWidth + 5)
  190. SetAnchoredPositionX(self.total_costval, self.total_cost_icon.anchoredPosition.x + 37)
  191. end
  192. -- 点击确认按钮
  193. function GuildRenameView:OnComfirmBtnClick( )
  194. local total_cost = tonumber(self.total_costval_tmp.text)
  195. if total_cost ~= 0 then -- 有变动了就允许发协议
  196. local new_name = self.name_input_tmpInput.text
  197. -- 是否已经改了名字
  198. local changed_name = new_name ~= "" and 1 or 0
  199. -- 新旗帜
  200. local new_flag = self.cur_icon_flag * 10000 + self.cur_icon_color
  201. local function ok_callback()
  202. self.model:Fire(GuildModel.REQUEST_CCMD_EVENT, 40025, changed_name, new_name, new_flag)
  203. end
  204. local priceText = string.format("<color=%s>%s</color> 修改社团信息?", ColorUtil.YELLOW_DARK, total_cost)
  205. local function use_function( toggle_tip_data, call_fun_sum )
  206. if total_cost ~= 0 then
  207. GlobalEventSystem:Fire(EventName.OPEN_COM_TOGGLE_TIP_VIEW, toggle_tip_data)
  208. else
  209. call_fun_sum()
  210. end
  211. end
  212. local data = {
  213. gold_type = 1,
  214. cost_price = total_cost,
  215. ok_callback = ok_callback,
  216. togglePriceStr = priceText,
  217. use_function = use_function,
  218. no_need_toggle = true,
  219. recharge_open_call_back = function()
  220. self:Close()
  221. end,
  222. }
  223. CustomActivityModel:getInstance():BuyTips(data)
  224. else
  225. Message.show("好像什么都没改动哦~", "fault")
  226. end
  227. end
  228. function GuildRenameView:DestroySuccess( )
  229. for k, v in pairs(self.icon_list) do
  230. v:DeleteMe()
  231. v = nil
  232. end
  233. for k, v in pairs(self.color_list) do
  234. v:DeleteMe()
  235. v = nil
  236. end
  237. if self.tabWindowComponent then
  238. self.tabWindowComponent:DeleteMe()
  239. self.tabWindowComponent = nil
  240. end
  241. end