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

300 lines
7.6 KiB

  1. CalculatorView = CalculatorView or BaseClass(BaseView)
  2. function CalculatorView:__init()
  3. self.base_file = "common"
  4. self.layout_file = "CalculatorView"
  5. self.layer_name = "Top"
  6. self.destroy_imm = true
  7. self.use_background = true
  8. self.background_alpha = 0
  9. self.close_mode = CloseMode.CloseDestroy
  10. self.click_bg_toClose = true
  11. self.append_to_ctl_queue = false
  12. self.hide_maincancas = false
  13. self.is_set_zdepth = true
  14. self.mainVo = RoleManager.Instance.mainRoleInfo
  15. self.key_list = {}
  16. self.final_num = 0 --输入的数字
  17. self.mult_num = 10 --倍数
  18. self.call_back = nil
  19. self.max_count = 0
  20. self.localPos = Vector3(701, 347,0)
  21. self.input_number_list = {}
  22. self.load_callback = function()
  23. self:LoadSuccess()
  24. self:InitEvent()
  25. end
  26. self.open_callback = function()
  27. self:SetWinPosition()
  28. end
  29. self.destroy_callback = function()
  30. self:Remove()
  31. end
  32. end
  33. --type 1 通用 2 兑换 3战力 4等级 5发红包
  34. function CalculatorView:Open(max_count,call_back,type, min_price)
  35. self.max_count = max_count
  36. self.call_back = call_back
  37. self.type = type or 1
  38. self.min_price = min_price
  39. BaseView.Open(self)
  40. end
  41. function CalculatorView:Close()
  42. -- if self.call_back then
  43. -- self.call_back(self.final_num, true)
  44. -- end
  45. if not self.click_sure_btn then
  46. self:InputNumKey(self.final_num, true)
  47. end
  48. self.call_back = nil
  49. self.max_count = 0
  50. self.final_num = 0
  51. self.localPos = nil
  52. self.input_number_list = {}
  53. BaseView.Close(self)
  54. end
  55. function CalculatorView:Remove()
  56. self.key_list = {}
  57. end
  58. function CalculatorView:LoadSuccess()
  59. self.container = self:GetChild("container")
  60. for i=1,12 do
  61. table.insert(self.key_list,self:GetChild("container/keyPanel/key_"..i).gameObject)
  62. end
  63. self.transform.sizeDelta = Vector2(ScreenWidth, ScreenHeight)
  64. end
  65. function CalculatorView:InitEvent()
  66. local function onBtnClickHandler(target)
  67. if target == self.key_list[1] then
  68. self:InputNumKey(1)
  69. elseif target == self.key_list[2] then
  70. self:InputNumKey(2)
  71. elseif target == self.key_list[3] then
  72. self:InputNumKey(3)
  73. elseif target == self.key_list[4] then
  74. self:InputNumKey(4)
  75. elseif target == self.key_list[5] then
  76. self:InputNumKey(5)
  77. elseif target == self.key_list[6] then
  78. self:InputNumKey(6)
  79. elseif target == self.key_list[7] then
  80. self:InputNumKey(7)
  81. elseif target == self.key_list[8] then
  82. self:InputNumKey(8)
  83. elseif target == self.key_list[9] then
  84. self:InputNumKey(9)
  85. elseif target == self.key_list[10] then
  86. self:InputNumKey(0)
  87. elseif target == self.key_list[11] then
  88. self:BackKey()
  89. elseif target == self.key_list[12] then
  90. -- if self.call_back and self.type ~= 7 then
  91. -- self.call_back(self.final_num, true)
  92. -- end
  93. self.click_sure_btn = true
  94. self:InputNumKey(self.final_num, true)
  95. self:Close()
  96. end
  97. end
  98. for i=1,12 do
  99. AddClickEvent(self.key_list[i],onBtnClickHandler)
  100. end
  101. -- self.transform.localPosition = self.localPos
  102. end
  103. -- is_check_full 是否立马判断是否足够数量
  104. function CalculatorView:InputNumKey(num, is_check_full)
  105. local number = self.final_num * self.mult_num + num
  106. if is_check_full then
  107. number = self.final_num
  108. end
  109. -- local number = 0
  110. -- if self.final_num == 1 and num ~= 1 then
  111. -- number = num
  112. -- else
  113. -- number = self.final_num * self.mult_num + num
  114. -- end
  115. if number <= 0 then
  116. if self.type == 7 then
  117. Message.show("选择数量为0")
  118. return
  119. end
  120. --Message.show("选择数量为0个")
  121. return
  122. end
  123. -- if number > self.max_count then
  124. -- if self.type == 1 then
  125. -- Message.show("本次最多购买"..self.max_count.."个")
  126. -- elseif self.type == 2 then
  127. -- Message.show("本次最多兑换"..self.max_count.."个")
  128. -- elseif self.type == 3 then
  129. -- Message.show("战力最高设置为"..self.max_count)
  130. -- elseif self.type == 4 then
  131. -- Message.show("等级最高设置为"..self.max_count.."级")
  132. -- elseif self.type == 5 then
  133. -- Message.show("本次最多发"..self.max_count.."个")
  134. -- elseif self.type == 6 then
  135. -- Message.show("本次最多可上架"..self.max_count.."个")
  136. -- elseif self.type == 7 then
  137. -- Message.show("价格不能超过"..self.max_count)
  138. -- elseif self.type == 8 then
  139. -- Message.show("最多加价"..self.max_count)
  140. -- end
  141. -- self:AutoSetMaxNum(self.max_count)
  142. -- return
  143. -- end
  144. -- table.insert(self.input_number_list,num)
  145. self.final_num = number
  146. -- self.call_back(self.final_num)
  147. if is_check_full then
  148. if number > self.max_count then
  149. if self.type == 1 then
  150. Message.show("本次最多购买"..self.max_count.."")
  151. elseif self.type == 2 then
  152. Message.show("本次最多兑换"..self.max_count.."")
  153. elseif self.type == 3 then
  154. Message.show("战力最高设置为"..self.max_count)
  155. elseif self.type == 4 then
  156. Message.show("等级最高设置为"..self.max_count.."")
  157. elseif self.type == 5 then
  158. Message.show("本次最多发"..self.max_count.."")
  159. elseif self.type == 6 then
  160. Message.show("本次最多可上架"..self.max_count.."")
  161. elseif self.type == 7 then
  162. Message.show("价格不能超过"..self.max_count)
  163. elseif self.type == 8 then
  164. Message.show("最多加价"..self.max_count)
  165. elseif self.type == 9 then
  166. Message.show("不能大于"..self.max_count)
  167. end
  168. self:AutoSetMaxNum(self.max_count, is_check_full)
  169. return
  170. elseif self.min_price and number < self.min_price then
  171. if self.type == 1 then
  172. elseif self.type == 2 then
  173. elseif self.type == 3 then
  174. elseif self.type == 4 then
  175. elseif self.type == 5 then
  176. elseif self.type == 6 then
  177. elseif self.type == 7 then
  178. Message.show("价格不能少于"..self.min_price)
  179. end
  180. self:AutoSetMinNum(self.min_price, is_check_full)
  181. return
  182. end
  183. else
  184. table.insert(self.input_number_list,num)
  185. self.final_num = number
  186. self.call_back(self.final_num)
  187. end
  188. -- self.final_num = number
  189. end
  190. function CalculatorView:BackKey()
  191. --PrintTable(self.input_number_list)
  192. local lastNum = self.input_number_list[#self.input_number_list]
  193. if lastNum ~= nil then
  194. self.final_num = (self.final_num - lastNum) / self.mult_num
  195. table.remove(self.input_number_list,#self.input_number_list)
  196. if self.final_num == 0 then
  197. self.final_num = 1
  198. end
  199. else
  200. self.final_num = 0
  201. --Message.show("最少购买1个")
  202. end
  203. self.call_back(self.final_num)
  204. end
  205. function CalculatorView:AutoSetMaxNum(num, is_check_full)
  206. self.input_number_list = {}
  207. local max_mult = 10000000
  208. local max_num = num
  209. local start_insert = false
  210. for i=1,8 do
  211. local input_num = max_num/max_mult
  212. --print("===============input_num:"..input_num)
  213. if input_num >= 1 or input_num == 0 or start_insert then
  214. input_num = math.floor(input_num)
  215. max_num = max_num - (input_num*max_mult)
  216. table.insert(self.input_number_list,input_num)
  217. start_insert = true
  218. end
  219. max_mult = max_mult/10
  220. end
  221. -- PrintTable(self.input_number_list)
  222. -- print(num)
  223. self.final_num = num
  224. print("tanar: [CalculatorView 269]=> num: ",num)
  225. self.call_back(self.final_num, is_check_full)
  226. end
  227. function CalculatorView:AutoSetMinNum(num, is_check_full)
  228. self.input_number_list = {}
  229. local min_mult = 10000000
  230. local min_num = num
  231. local start_insert = false
  232. self.final_num = num
  233. self.call_back(self.final_num, is_check_full)
  234. end
  235. function CalculatorView:SetWinPosition()
  236. local con_width = self.container.transform.sizeDelta.x
  237. local con_height = self.container.transform.sizeDelta.y
  238. local x, y = ScreenToViewportPoint(self.localPos.x, self.localPos.y)
  239. x = x - 180
  240. y = y + 255
  241. x = x < 40 and 40 or x
  242. if x + con_width > ScreenWidth then
  243. x = ScreenWidth - con_width - 25
  244. end
  245. if y > ScreenHeight then
  246. y = y - con_height - 80
  247. end
  248. self.container.transform.anchoredPosition = Vector3(x, y, 0)
  249. end