UIVoyagePrepareCtr.lua 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  1. local UIVoyagePrepareCtr = class("UIVoyagePrepareCtr", require("UICtrBase"))
  2. function UIVoyagePrepareCtr:Init(view)
  3. self.view = view
  4. end
  5. function UIVoyagePrepareCtr:SetData(data)
  6. self.asyncIdx = 0
  7. self.data = data
  8. end
  9. function UIVoyagePrepareCtr:GetAsyncIdx()
  10. self.asyncIdx = self.asyncIdx + 1
  11. return self.asyncIdx
  12. end
  13. function UIVoyagePrepareCtr:GetData()
  14. return self.data
  15. end
  16. function UIVoyagePrepareCtr:OnDispose()
  17. self.numLimit = nil
  18. self.lastSelectId = nil
  19. self.curSelectId = nil
  20. self.data = nil
  21. self.view = nil
  22. end
  23. function UIVoyagePrepareCtr:InitData()
  24. self.numLimit = ManagerContainer.DataMgr.VoyageDataMgr:GetNumLimit()
  25. self.lastSelectId = nil
  26. self.curSelectId = nil
  27. self:RefreshSelectId()
  28. end
  29. function UIVoyagePrepareCtr:GetSelfAirShipData()
  30. return ManagerContainer.DataMgr.VoyageDataMgr:GetSelfAirShipData()
  31. end
  32. function UIVoyagePrepareCtr:GetNum()
  33. return ManagerContainer.DataMgr.VoyageDataMgr:GetVoyageNum()
  34. end
  35. function UIVoyagePrepareCtr:GetNumLimit()
  36. return self.numLimit
  37. end
  38. function UIVoyagePrepareCtr:GetNotifyAirShipUpTip()
  39. return ManagerContainer.DataMgr.VoyageDataMgr:GetNotifyAirShipUpTip()
  40. end
  41. function UIVoyagePrepareCtr:SetNotifyAirShipUpTip(status)
  42. return ManagerContainer.DataMgr.VoyageDataMgr:SetNotifyAirShipUpTip(status)
  43. end
  44. function UIVoyagePrepareCtr:RefreshSelectId()
  45. local newSelectId = ManagerContainer.DataMgr.VoyageDataMgr:GetCurAirShipId()
  46. if self.curSelectId == newSelectId then
  47. return false
  48. end
  49. self.lastSelectId = self.curSelectId
  50. self.curSelectId = newSelectId
  51. return true
  52. end
  53. function UIVoyagePrepareCtr:GetLastSelectId()
  54. return self.lastSelectId
  55. end
  56. function UIVoyagePrepareCtr:GetCurSelectId()
  57. return self.curSelectId
  58. end
  59. function UIVoyagePrepareCtr:GetSendRefreshAirShipReqErrorCode(upHighest)
  60. if not self.curSelectId then
  61. return 2
  62. end
  63. local cfgData = ManagerContainer.CfgMgr:GetVoyageAirShipCfgById(self.curSelectId + 1)
  64. if not cfgData then
  65. return 2
  66. end
  67. cfgData = ManagerContainer.CfgMgr:GetVoyageAirShipCfgById(self.curSelectId)
  68. if not cfgData then
  69. return 3
  70. end
  71. local costs
  72. if upHighest then
  73. costs = cfgData.TopLevel
  74. else
  75. costs = cfgData.Consume
  76. end
  77. if not costs then
  78. return 4
  79. end
  80. local costLength = #costs
  81. if costLength <= 0 then
  82. return 4
  83. end
  84. local validCosts = {}
  85. local remainNum = 1
  86. local cost, costCfgId, costNum, costRemainNum, ownNum
  87. for i = 1, costLength do
  88. cost = costs[i]
  89. costCfgId = tonumber(cost[1])
  90. costNum = tonumber(cost[2])
  91. ownNum = CommonUtil.GetOwnResCountByItemId(costCfgId)
  92. costRemainNum = Mathf.Floor(ownNum / costNum)
  93. if costRemainNum >= remainNum then
  94. validCosts[#validCosts + 1] = {costCfgId, ownNum, costNum, remainNum}
  95. return 0, 1, 0, validCosts
  96. else
  97. validCosts[#validCosts + 1] = {costCfgId, ownNum, costNum, costRemainNum}
  98. end
  99. end
  100. return 1, 1, remainNum, validCosts
  101. end
  102. function UIVoyagePrepareCtr:SendRefreshAirShipReq(upHighest)
  103. if not ManagerContainer.DataMgr.VoyageDataMgr:SendRefreshAirShipReq(upHighest) then
  104. return 100007
  105. end
  106. return 0
  107. end
  108. function UIVoyagePrepareCtr:SendTakeOffAirShipReq()
  109. if not ManagerContainer.DataMgr.VoyageDataMgr:SendTakeOffAirShipReq() then
  110. return 100007
  111. end
  112. return 0
  113. end
  114. return UIVoyagePrepareCtr