源战役客户端
Ви не можете вибрати більше 25 тем Теми мають розпочинатися з літери або цифри, можуть містити дефіси (-) і не повинні перевищувати 35 символів.

488 рядки
16 KiB

4 тижднів тому
  1. EscortMainView = EscortMainView or BaseClass(BaseView)
  2. local EscortMainView = EscortMainView
  3. function EscortMainView:__init()
  4. self.base_file = "escort"
  5. self.layout_file = "EscortMainView"
  6. self.layer_name = "UI"
  7. self.destroy_imm = true
  8. self.use_background = true --全屏界面默认使用这个参数
  9. self.hide_maincancas = true --全屏界面需要放开隐藏主UI
  10. self.blur_activity_bg = true
  11. self.close_fog = true
  12. self.change_scene_close = true
  13. self.append_to_ctl_queue = false --是否要添加进界面堆栈
  14. self.need_show_money = true --是否要显示顶部的金钱栏
  15. self.improve_target_id = 0
  16. self.item_list = {}
  17. self.awarditem_list = {}
  18. self.position_data = {
  19. [1] = {15, -202},
  20. [2] = {207, -41},
  21. [3] = {457, -64},
  22. [4] = {617, -254},
  23. }
  24. self.model = EscortModel:getInstance()
  25. self.is_auto_buy = self.model.is_auto_buy
  26. self.model:Fire(EscortConst.REQUEST_SCMD_EVENT, 50000)
  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 EscortMainView:Open( )
  42. --self.data = data
  43. BaseView.Open(self)
  44. end
  45. function EscortMainView:LoadSuccess()
  46. local nodes = {
  47. "fresh_btn:obj", "buy_toggle:tog:obj", "bg:raw", "tip_btn:obj", "close_btn:obj",
  48. "escort_btn:obj", "item_con", "cost_image:img:obj", "reward_con",
  49. "time_text2:tmp", "cost_text:tmp", "time_text1:tmp", "num_text:tmp", "con_money",
  50. "progress_text:tmp", "progress_image:img", "desc_text:tmp"
  51. }
  52. self:GetChildren(nodes)
  53. local pos_x = GetAnchoredPosition(self.desc_text)
  54. SetAnchoredPositionX(self.desc_text, pos_x - 12)
  55. lua_resM:setOutsideRawImage(self,self.bg_raw,GameResPath.GetViewBigBg("escort_bg"),false)
  56. lua_resM:setOutsideImageSprite(self, self.cost_image_img, GameResPath.GetGoodsIcon(EscortConst.ESCORT_GOODS_ID),false)
  57. self.buy_toggle_tog.isOn = self.is_auto_buy
  58. self:CreateMoneyView()
  59. self:UpdateEscortItem()
  60. self:SetDoubleExpTime()
  61. end
  62. function EscortMainView:AddEvent()
  63. local on_click = function ( click_obj )
  64. if self.close_btn_obj == click_obj then
  65. self:Close()
  66. elseif self.tip_btn_obj == click_obj then
  67. EventSystem.Fire(GlobalEventSystem,EventName.OPEN_INSTRUCTION_VIEW, 50000)
  68. elseif self.fresh_btn_obj == click_obj then
  69. self:StartFresh()
  70. elseif self.escort_btn_obj == click_obj then
  71. if self.model:CurTimeIsDouble() then
  72. self.model:Fire(EscortConst.REQUEST_SCMD_EVENT, 50002, 1)
  73. else
  74. self:AskCall()
  75. end
  76. elseif self.buy_toggle_obj == click_obj then
  77. self.is_auto_buy = not self.is_auto_buy
  78. self.model.is_auto_buy = self.is_auto_buy
  79. elseif self.cost_image_obj == click_obj then
  80. UIToolTipMgr:getInstance():AppendGoodsTips(EscortConst.ESCORT_GOODS_ID, x, y, nil, nil, nil,nil,false)
  81. end
  82. end
  83. AddClickEvent(self.close_btn_obj, on_click)
  84. AddClickEvent(self.support_btn_obj, on_click)
  85. AddClickEvent(self.tip_btn_obj, on_click)
  86. AddClickEvent(self.fresh_btn_obj, on_click)
  87. AddClickEvent(self.escort_btn_obj, on_click)
  88. AddClickEvent(self.buy_toggle_obj, on_click)
  89. AddClickEvent(self.cost_image_obj, on_click)
  90. local function on_update( )
  91. local base_info = self.model:GetEscortBaseInfo()
  92. if base_info.is_convoy == 1 then--如果已经开始护送了 就别刷新界面了 会刷到下一次的信息
  93. else
  94. self:UpdateView()
  95. end
  96. end
  97. self.update_id = self.model:BindOne("escort_base_info", on_update)
  98. end
  99. function EscortMainView:AskCall( )
  100. local cost = self.model.double_escort_cost[1][3] -- config
  101. local cost_type = self.model.double_escort_cost[1][1]
  102. local jin = RoleManager.Instance.mainRoleInfo.jin
  103. local jinLock = RoleManager.Instance.mainRoleInfo.jinLock
  104. local function recharge_call_back( ... )--充值
  105. local args = {...}
  106. local use_lockjin = args[1]
  107. -- 关闭道具tips
  108. UIToolTipMgr:getInstance():CloseGoodsTips()
  109. local qc_data = {
  110. price = cost - (use_lockjin and jinLock or 0),
  111. close_callback = nil,
  112. qc_type = 0,
  113. }
  114. GlobalEventSystem:Fire(EventName.OPEN_RECHARGE_TIP_VIEW, true, qc_data)
  115. end
  116. local function invest_call_back( ... )--前往投资
  117. -- 关闭道具tips
  118. UIToolTipMgr:getInstance():CloseGoodsTips()
  119. OpenFun.Open(420,1)
  120. end
  121. -- 双倍护送
  122. local function ok_callback()
  123. if cost_type == 1 then
  124. if jin < cost then--彩钻不足
  125. recharge_call_back()
  126. else
  127. self.model:Fire(EscortConst.REQUEST_SCMD_EVENT, 50002, 1)
  128. end
  129. elseif cost_type == 2 then
  130. if jinLock < cost then
  131. local ok = function ( )
  132. if jinLock + jin < cost then
  133. recharge_call_back(true)
  134. else
  135. self.model:Fire(EscortConst.REQUEST_SCMD_EVENT, 50002, 1)
  136. end
  137. end
  138. local jin_type_img = WordManager:GetMoneyFaceStr( 1 )
  139. local jinLock_type_name = GoodsModel:getInstance():getGoodsName(100001, false)
  140. local str = string.format("您的<color=#ff203a>%s不足</color>,是否使用<color=#fdffc2> %s%s </color>补全?",jinLock_type_name,jin_type_img,cost - jinLock)
  141. if VipModel:getInstance():HasBoughtAllInvestmentTypes() then -- 已经购买了全部的投资类型,则不提示前往投资
  142. Alert.show(str, Alert.Type.Two, ok, nil, "彩钻补全", "取消")
  143. else
  144. Alert.show(str, Alert.Type.Two, ok, invest_call_back, "彩钻补全", "前往投资")
  145. end
  146. else
  147. self.model:Fire(EscortConst.REQUEST_SCMD_EVENT, 50002, 1)
  148. end
  149. end
  150. end
  151. -- 单倍护送
  152. local function cancel_callback()
  153. self.model:Fire(EscortConst.REQUEST_SCMD_EVENT, 50002, 0)
  154. end
  155. local function toggle_function( flag )
  156. self.model.not_show_go_ask = flag
  157. end
  158. -- 屏蔽接口里面的recharge_callback 跳转到自己的函数
  159. local function rechanger_callback(...)
  160. ok_callback()
  161. end
  162. local time_str = HtmlColorTxt("(17:00-17:30 21:30-22:00)", ColorUtil.GREEN_DARK)
  163. local str = string.format("现在不是 %s\n%s", HtmlColorTxt("双倍护送时间", ColorUtil.GREEN_DARK), time_str)
  164. local toggle_tip_data = {
  165. insufficientText = str,
  166. titleText = "提示",
  167. nameText = "是否花费 ",
  168. priceText = string.format("%s 进行护送获得双倍奖励", HtmlColorTxt(cost, "#fdffc2")),
  169. okText = "确认双倍",
  170. cancelText = "坚持单倍",
  171. toggleText = " 记住本次选择",--8字符
  172. ok_callback = ok_callback,
  173. close_callback = cancel_callback,
  174. rechanger_callback = rechanger_callback,
  175. toggle_function = toggle_function,
  176. is_complex_ok_callback = false,
  177. gold_res = "ui_momey_icon_" .. cost_type,
  178. price = cost, -- config
  179. }
  180. if not self.model.not_show_go_ask_indeed or self.model.last_double_escort == nil then
  181. GlobalEventSystem:Fire(EventName.OPEN_COM_TOGGLE_TIP_VIEW, toggle_tip_data)
  182. else
  183. if self.model.last_double_escort == 1 then
  184. ok_callback()
  185. elseif self.model.last_double_escort == 0 then
  186. cancel_callback()
  187. end
  188. end
  189. end
  190. function EscortMainView:StartFresh( )
  191. -- local goods_num = GoodsModel:getInstance():GetTypeGoodsNum(EscortConst.ESCORT_GOODS_ID)
  192. -- local buy_price = GoodsModel:getInstance():GetGoodsPrice(EscortConst.ESCORT_GOODS_ID)
  193. -- local cost_price = (self.need_num - goods_num) * buy_price
  194. -- local price_asset, price_icon = WordManager:GetCommonMoneyIcon(2)
  195. -- local toggle_tip_data = {
  196. -- gold_ab_res = price_asset,
  197. -- gold_res = price_icon,
  198. -- price = cost_price,
  199. -- insufficientText = "",
  200. -- priceText = string.format("<color=#fdffc2>%s</color> 补齐所需的护送令牌",cost_price),
  201. -- titleText = "提示",
  202. -- ok_callback = ok_callback,
  203. -- toggle_function = toggle_function,
  204. -- is_complex_ok_callback = true,
  205. -- }
  206. -- if not self.model.not_show_escort_ask and cost_price ~= 0 and self.is_auto_buy then
  207. -- GlobalEventSystem:Fire(EventName.OPEN_COM_TOGGLE_TIP_VIEW, toggle_tip_data)
  208. -- else
  209. -- ok_callback()
  210. -- end
  211. local function ok_callback()
  212. local auto_buy = self.is_auto_buy and 1 or 0
  213. -- local auto_buy = 1--这里改了 永远都要自动购买
  214. self.model:Fire(EscortConst.REQUEST_SCMD_EVENT, 50001, auto_buy)
  215. end
  216. local function toggle_function( flag )
  217. self.model.not_show_escort_ask = flag
  218. end
  219. local function use_function( toggle_tip_data,call_fun_sum )
  220. if not self.model.not_show_escort_ask then
  221. GlobalEventSystem:Fire(EventName.OPEN_COM_TOGGLE_TIP_VIEW, toggle_tip_data)
  222. else
  223. call_fun_sum()
  224. end
  225. end
  226. local goods_num = GoodsModel:getInstance():GetTypeGoodsNum(EscortConst.ESCORT_GOODS_ID)
  227. local buy_price = GoodsModel:getInstance():GetGoodsPrice(EscortConst.ESCORT_GOODS_ID)
  228. local cost_price = (self.need_num - goods_num) * buy_price
  229. if not self.model.not_show_escort_ask and cost_price ~= 0 and not self.is_auto_buy then
  230. local buy_tip_data = {
  231. gold_type = 2,--货币类型
  232. cost_price = cost_price,--消耗金额
  233. ok_callback = ok_callback,--成功
  234. toggle_function = toggle_function,--多选
  235. togglePriceStr = string.format("<color=#fdffc2>%s</color> 补齐所需的%s", cost_price, HtmlColorTxt(" [外送凭证]", ColorUtil.BLUE_DARK)),--提示语
  236. use_function = use_function,--最终调用
  237. }
  238. CustomActivityModel:getInstance():BuyTips(buy_tip_data)
  239. else
  240. ok_callback()
  241. end
  242. end
  243. function EscortMainView:OpenSuccess()
  244. self:UpdateView()
  245. end
  246. function EscortMainView:UpdateView()
  247. self.base_info = self.model:GetEscortBaseInfo()
  248. local index = self.model:GetEscortObjectIndexById(self.base_info.object_id or 1001)
  249. local cfg = Config.Convoyobject
  250. local cur_id = self.base_info.object_id or 1001
  251. if cfg[cur_id] then
  252. self.progress_text_tmp.text = string.format("%s/%s", self.base_info.pray_val or 0, cfg[cur_id].up_next_val)
  253. self.progress_image_img.fillAmount = (self.base_info.pray_val or 0)/cfg[cur_id].up_next_val
  254. end
  255. -- lua_resM:setImageSprite(self, self.type_image_img, "escort_asset", "escort_text"..index)
  256. -- self:UpdateDropDown()
  257. self:SetSelect()
  258. self:UpdateNeedCost()
  259. self:UpdateRewardCon()
  260. if self.model:IsOverMaxCount() then
  261. self.num_text_tmp.text = string.format("剩余次数:%s/%s", HtmlColorTxt(0, ColorUtil.RED_DARK), self.model.max_escort_num)
  262. else
  263. local left_num = self.model.max_escort_num-self.model:GetEscortTimes()
  264. self.num_text_tmp.text = string.format("剩余次数:%s/%s", HtmlColorTxt(left_num, ColorUtil.GREEN_DARK), self.model.max_escort_num)
  265. end
  266. end
  267. function EscortMainView:CreateMoneyView( )
  268. if not self.money_view then
  269. self.money_view = UIMoneyView.New(self.con_money)
  270. end
  271. self.money_view:SetPosition(0,0)
  272. self.money_view:SetData()
  273. end
  274. function EscortMainView:SetSelect( )
  275. local index = self.model:GetEscortObjectIndexById(self.base_info.object_id or 0)
  276. for i,v in ipairs(self.item_list) do
  277. v:SetSelect(i==index)
  278. end
  279. end
  280. --双倍时间
  281. function EscortMainView:SetDoubleExpTime()
  282. local cfg1 = DailyModel:getInstance():GetAcConfig(500, 1, 2)
  283. if cfg1 then
  284. local time = ErlangParser:GetInstance():Parse(cfg1.time_region)
  285. for i=1,2 do
  286. for j=1,2 do
  287. if tonumber(time[1][i][j]) < 10 and #(tostring(time[1][i][j])) == 1 then
  288. time[1][i][j] = "0"..time[1][i][j]
  289. end
  290. if tonumber(time[2][i][j]) < 10 and #(tostring(time[2][i][j])) == 1 then
  291. time[2][i][j] = "0"..time[2][i][j]
  292. end
  293. end
  294. end
  295. local time1 = string.format("%s:%s-%s:%s", time[1][1][1], time[1][1][2],time[1][2][1], time[1][2][2])
  296. local time2 = string.format("%s:%s-%s:%s", time[2][1][1], time[2][1][2],time[2][2][1], time[2][2][2])
  297. self.time_text2_tmp.text = string.format("%s %s", HtmlColorTxt(time1, ColorUtil.GREEN_DARK), HtmlColorTxt(time2, ColorUtil.GREEN_DARK))
  298. -- self.time_text2_tmp.text = string.format("%s:%s-%s:%s", time[2][1][1], time[2][1][2],
  299. -- time[2][2][1], time[2][2][2])
  300. end
  301. -- local cfg2 = DailyModel:getInstance():GetAcConfig(500, 1, 2)
  302. -- if cfg2 then
  303. -- local time = ErlangParser:GetInstance():Parse(cfg2.time_region)
  304. -- for j=1,2 do
  305. -- for k=1,2 do
  306. -- if tonumber(time[1][j][k]) < 10 then
  307. -- time[1][j][k] = "0"..time[1][j][k]
  308. -- end
  309. -- end
  310. -- end
  311. -- self.time_text2_tmp.text = string.format("%s:%s-%s:%s", time[1][1][1], time[1][1][2],
  312. -- time[1][2][1], time[1][2][2])
  313. -- end
  314. end
  315. function EscortMainView:UpdateDropDown( )
  316. local list = {}
  317. local cfg_list = {}
  318. local cfg = Config.Convoyobject
  319. local first = true
  320. local cur_index = self.base_info.object_id
  321. local last_cfg = {}
  322. local count = 1
  323. for i,v in pairsByKeys(cfg) do
  324. if first then
  325. first = false
  326. cur_index = cur_index or i
  327. end
  328. if i > cur_index then
  329. local name = self:GetColorName(v.name, v.id)
  330. table.insert(list, name)
  331. table.insert(cfg_list, v)
  332. end
  333. if count == TableSize(cfg) then
  334. last_cfg = v
  335. end
  336. count = count + 1
  337. end
  338. if TableSize(cfg_list) == 0 then
  339. local name = self:GetColorName(last_cfg.name, last_cfg.id)
  340. table.insert(list, name)
  341. table.insert(cfg_list, last_cfg)
  342. end
  343. self.improve_index = 1
  344. self.improve_target_id = cfg_list[self.improve_index].id
  345. local function update_object_id_func(index)
  346. self.improve_index = index
  347. self.improve_target_id = cfg_list[index].id
  348. self:UpdateNeedCost()
  349. end
  350. local prefab_data = {Combox = "Combox",ComboxView = "ComboxView", ComboxItem = "ComboxItem", offset_y = -#list*ComboxItem.Height -10}
  351. if not self.object_drop_down then
  352. self.object_drop_down = Combox.New(self.improve_con,list,update_object_id_func,138,30,nil,prefab_data)
  353. else
  354. self.object_drop_down:ResetData(list,self.improve_index,update_object_id_func,138,30)
  355. end
  356. end
  357. function EscortMainView:UpdateNeedCost( )
  358. local cur_id = self.base_info.object_id
  359. if cur_id == 0 or not cur_id then
  360. return
  361. end
  362. local cfg = Config.Convoyobject
  363. local num = 0
  364. local goods_num = GoodsModel:getInstance():GetTypeGoodsNum(EscortConst.ESCORT_GOODS_ID)
  365. if self.is_improve_to then
  366. for k,v in pairsByKeys(cfg) do
  367. if k >= cur_id and k < self.improve_target_id then
  368. num = num + stringtotable(v.upgrade_cost)[1][3]
  369. end
  370. end
  371. else
  372. local data = stringtotable(cfg[cur_id].upgrade_cost)
  373. if TableSize(data) > 0 then
  374. num = data[1][3]
  375. end
  376. end
  377. local color_str = ColorUtil.GREEN_DARK
  378. if goods_num < num then
  379. color_str = ColorUtil.RED_DARK
  380. end
  381. self.need_num = num
  382. self.cost_text_tmp.text = string.format("剩余:%s/%s", HtmlColorTxt(goods_num, color_str), num)
  383. end
  384. function EscortMainView:GetColorName(name,id)
  385. local index = self.model:GetEscortObjectIndexById(id)
  386. local color_str = {
  387. [1] = "#ffffff",
  388. [2] = "#10aaf1",--7bb1ff
  389. [3] = "#d322ff",--f280f7
  390. [4] = "#ffea9c",--ffe96c
  391. }
  392. return HtmlColorTxt(name, color_str[index])
  393. end
  394. function EscortMainView:UpdateEscortItem( )
  395. local data = Config.Convoyobject
  396. local count = 1
  397. local x_offset = 290
  398. for i,v in pairsByKeys(data) do
  399. local item = self.item_list[count]
  400. if not item then
  401. item = EscortItem.New(self.item_con)
  402. self.item_list[count] = item
  403. end
  404. item:SetData(v, count)
  405. -- item:SetPosition(self.position_data[count][1], self.position_data[count][2])
  406. item:SetPosition((count - 1) * x_offset-10, -168)
  407. count = count + 1
  408. end
  409. end
  410. function EscortMainView:UpdateRewardCon( )
  411. local cur_id = self.base_info.object_id or 1001
  412. cur_id = cur_id == 0 and 1001 or cur_id
  413. local exp_num = self.model:GetEscortExpByLv(RoleManager.Instance.mainRoleInfo.level, cur_id, false)
  414. local data = stringtotable(Config.Convoyobject[cur_id].award) or {}
  415. local exp_data = {
  416. [1] = 0,
  417. [2] = EscortConst.EXP_TPYE_ID,
  418. [3] = exp_num
  419. }
  420. table.insert(data, exp_data)
  421. for i,v in ipairs(data) do
  422. local item = self.awarditem_list[i]
  423. if not item then
  424. item = UIObjPool:getInstance():PopItem(UIObjPool.UIType.AwardItem, self.reward_con)
  425. item:SetItemSize(59,59)
  426. item:SetPosition(64*(i-1), 0)
  427. self.awarditem_list[i] = item
  428. end
  429. item:SetData(v[2],v[3])
  430. end
  431. end
  432. function EscortMainView:DestroySuccess( )
  433. for i,v in ipairs(self.item_list) do
  434. v:DeleteMe()
  435. v = nil
  436. end
  437. self.item_list = {}
  438. if self.drop_down then
  439. self.drop_down:DeleteMe()
  440. self.drop_down = nil
  441. end
  442. if self.update_id then
  443. self.model:UnBind(self.update_id)
  444. self.update_id = nil
  445. end
  446. if self.money_view then
  447. self.money_view:DeleteMe()
  448. self.money_view = nil
  449. end
  450. if self.object_drop_down then
  451. self.object_drop_down:DeleteMe()
  452. self.object_drop_down = nil
  453. end
  454. for i,v in ipairs(self.awarditem_list) do
  455. UIObjPool:getInstance():PushItem(UIObjPool.UIType.AwardItem, v)
  456. end
  457. self.awarditem_list = {}
  458. end