CalculatorView = CalculatorView or BaseClass(BaseView)
|
|
function CalculatorView:__init()
|
|
self.base_file = "common"
|
|
self.layout_file = "CalculatorView"
|
|
self.layer_name = "Top"
|
|
self.destroy_imm = true
|
|
self.use_background = true
|
|
self.background_alpha = 0
|
|
self.close_mode = CloseMode.CloseDestroy
|
|
self.click_bg_toClose = true
|
|
self.append_to_ctl_queue = false
|
|
self.hide_maincancas = false
|
|
self.is_set_zdepth = true
|
|
|
|
self.mainVo = RoleManager.Instance.mainRoleInfo
|
|
|
|
self.key_list = {}
|
|
self.final_num = 0 --输入的数字
|
|
self.mult_num = 10 --倍数
|
|
|
|
self.call_back = nil
|
|
self.max_count = 0
|
|
|
|
|
|
self.localPos = Vector3(701, 347,0)
|
|
self.input_number_list = {}
|
|
|
|
self.load_callback = function()
|
|
self:LoadSuccess()
|
|
self:InitEvent()
|
|
end
|
|
|
|
self.open_callback = function()
|
|
self:SetWinPosition()
|
|
end
|
|
|
|
self.destroy_callback = function()
|
|
self:Remove()
|
|
end
|
|
end
|
|
|
|
--type 1 通用 2 兑换 3战力 4等级 5发红包
|
|
function CalculatorView:Open(max_count,call_back,type, min_price)
|
|
self.max_count = max_count
|
|
self.call_back = call_back
|
|
self.type = type or 1
|
|
self.min_price = min_price
|
|
BaseView.Open(self)
|
|
end
|
|
|
|
function CalculatorView:Close()
|
|
-- if self.call_back then
|
|
-- self.call_back(self.final_num, true)
|
|
-- end
|
|
if not self.click_sure_btn then
|
|
self:InputNumKey(self.final_num, true)
|
|
end
|
|
|
|
self.call_back = nil
|
|
self.max_count = 0
|
|
self.final_num = 0
|
|
self.localPos = nil
|
|
self.input_number_list = {}
|
|
BaseView.Close(self)
|
|
end
|
|
|
|
function CalculatorView:Remove()
|
|
self.key_list = {}
|
|
end
|
|
|
|
function CalculatorView:LoadSuccess()
|
|
self.container = self:GetChild("container")
|
|
|
|
for i=1,12 do
|
|
table.insert(self.key_list,self:GetChild("container/keyPanel/key_"..i).gameObject)
|
|
end
|
|
|
|
self.transform.sizeDelta = Vector2(ScreenWidth, ScreenHeight)
|
|
end
|
|
|
|
function CalculatorView:InitEvent()
|
|
local function onBtnClickHandler(target)
|
|
if target == self.key_list[1] then
|
|
self:InputNumKey(1)
|
|
elseif target == self.key_list[2] then
|
|
self:InputNumKey(2)
|
|
elseif target == self.key_list[3] then
|
|
self:InputNumKey(3)
|
|
elseif target == self.key_list[4] then
|
|
self:InputNumKey(4)
|
|
elseif target == self.key_list[5] then
|
|
self:InputNumKey(5)
|
|
elseif target == self.key_list[6] then
|
|
self:InputNumKey(6)
|
|
elseif target == self.key_list[7] then
|
|
self:InputNumKey(7)
|
|
elseif target == self.key_list[8] then
|
|
self:InputNumKey(8)
|
|
elseif target == self.key_list[9] then
|
|
self:InputNumKey(9)
|
|
elseif target == self.key_list[10] then
|
|
self:InputNumKey(0)
|
|
elseif target == self.key_list[11] then
|
|
self:BackKey()
|
|
elseif target == self.key_list[12] then
|
|
-- if self.call_back and self.type ~= 7 then
|
|
-- self.call_back(self.final_num, true)
|
|
-- end
|
|
self.click_sure_btn = true
|
|
self:InputNumKey(self.final_num, true)
|
|
self:Close()
|
|
end
|
|
end
|
|
|
|
for i=1,12 do
|
|
AddClickEvent(self.key_list[i],onBtnClickHandler)
|
|
end
|
|
|
|
-- self.transform.localPosition = self.localPos
|
|
end
|
|
|
|
-- is_check_full 是否立马判断是否足够数量
|
|
function CalculatorView:InputNumKey(num, is_check_full)
|
|
local number = self.final_num * self.mult_num + num
|
|
if is_check_full then
|
|
number = self.final_num
|
|
end
|
|
-- local number = 0
|
|
|
|
-- if self.final_num == 1 and num ~= 1 then
|
|
-- number = num
|
|
-- else
|
|
-- number = self.final_num * self.mult_num + num
|
|
-- end
|
|
|
|
if number <= 0 then
|
|
if self.type == 7 then
|
|
Message.show("选择数量为0")
|
|
return
|
|
end
|
|
--Message.show("选择数量为0个")
|
|
return
|
|
end
|
|
|
|
-- if number > self.max_count then
|
|
-- if self.type == 1 then
|
|
-- Message.show("本次最多购买"..self.max_count.."个")
|
|
-- elseif self.type == 2 then
|
|
-- Message.show("本次最多兑换"..self.max_count.."个")
|
|
-- elseif self.type == 3 then
|
|
-- Message.show("战力最高设置为"..self.max_count)
|
|
-- elseif self.type == 4 then
|
|
-- Message.show("等级最高设置为"..self.max_count.."级")
|
|
-- elseif self.type == 5 then
|
|
-- Message.show("本次最多发"..self.max_count.."个")
|
|
-- elseif self.type == 6 then
|
|
-- Message.show("本次最多可上架"..self.max_count.."个")
|
|
-- elseif self.type == 7 then
|
|
-- Message.show("价格不能超过"..self.max_count)
|
|
-- elseif self.type == 8 then
|
|
-- Message.show("最多加价"..self.max_count)
|
|
-- end
|
|
-- self:AutoSetMaxNum(self.max_count)
|
|
-- return
|
|
-- end
|
|
|
|
|
|
-- table.insert(self.input_number_list,num)
|
|
self.final_num = number
|
|
|
|
-- self.call_back(self.final_num)
|
|
|
|
if is_check_full then
|
|
if number > self.max_count then
|
|
if self.type == 1 then
|
|
Message.show("本次最多购买"..self.max_count.."个")
|
|
elseif self.type == 2 then
|
|
Message.show("本次最多兑换"..self.max_count.."个")
|
|
elseif self.type == 3 then
|
|
Message.show("战力最高设置为"..self.max_count)
|
|
elseif self.type == 4 then
|
|
Message.show("等级最高设置为"..self.max_count.."级")
|
|
elseif self.type == 5 then
|
|
Message.show("本次最多发"..self.max_count.."个")
|
|
elseif self.type == 6 then
|
|
Message.show("本次最多可上架"..self.max_count.."个")
|
|
elseif self.type == 7 then
|
|
Message.show("价格不能超过"..self.max_count)
|
|
elseif self.type == 8 then
|
|
Message.show("最多加价"..self.max_count)
|
|
elseif self.type == 9 then
|
|
Message.show("不能大于"..self.max_count)
|
|
end
|
|
self:AutoSetMaxNum(self.max_count, is_check_full)
|
|
return
|
|
elseif self.min_price and number < self.min_price then
|
|
if self.type == 1 then
|
|
|
|
elseif self.type == 2 then
|
|
|
|
elseif self.type == 3 then
|
|
|
|
elseif self.type == 4 then
|
|
|
|
elseif self.type == 5 then
|
|
|
|
elseif self.type == 6 then
|
|
|
|
elseif self.type == 7 then
|
|
Message.show("价格不能少于"..self.min_price)
|
|
end
|
|
self:AutoSetMinNum(self.min_price, is_check_full)
|
|
return
|
|
end
|
|
else
|
|
table.insert(self.input_number_list,num)
|
|
self.final_num = number
|
|
|
|
self.call_back(self.final_num)
|
|
end
|
|
-- self.final_num = number
|
|
|
|
end
|
|
|
|
function CalculatorView:BackKey()
|
|
|
|
--PrintTable(self.input_number_list)
|
|
local lastNum = self.input_number_list[#self.input_number_list]
|
|
|
|
if lastNum ~= nil then
|
|
self.final_num = (self.final_num - lastNum) / self.mult_num
|
|
table.remove(self.input_number_list,#self.input_number_list)
|
|
|
|
if self.final_num == 0 then
|
|
self.final_num = 1
|
|
end
|
|
else
|
|
self.final_num = 0
|
|
--Message.show("最少购买1个")
|
|
end
|
|
|
|
|
|
self.call_back(self.final_num)
|
|
|
|
end
|
|
|
|
function CalculatorView:AutoSetMaxNum(num, is_check_full)
|
|
self.input_number_list = {}
|
|
local max_mult = 10000000
|
|
local max_num = num
|
|
local start_insert = false
|
|
for i=1,8 do
|
|
local input_num = max_num/max_mult
|
|
--print("===============input_num:"..input_num)
|
|
if input_num >= 1 or input_num == 0 or start_insert then
|
|
input_num = math.floor(input_num)
|
|
max_num = max_num - (input_num*max_mult)
|
|
table.insert(self.input_number_list,input_num)
|
|
start_insert = true
|
|
end
|
|
|
|
max_mult = max_mult/10
|
|
end
|
|
|
|
-- PrintTable(self.input_number_list)
|
|
-- print(num)
|
|
|
|
self.final_num = num
|
|
print("tanar: [CalculatorView 269]=> num: ",num)
|
|
|
|
self.call_back(self.final_num, is_check_full)
|
|
|
|
end
|
|
|
|
function CalculatorView:AutoSetMinNum(num, is_check_full)
|
|
self.input_number_list = {}
|
|
local min_mult = 10000000
|
|
local min_num = num
|
|
local start_insert = false
|
|
|
|
self.final_num = num
|
|
self.call_back(self.final_num, is_check_full)
|
|
end
|
|
|
|
function CalculatorView:SetWinPosition()
|
|
local con_width = self.container.transform.sizeDelta.x
|
|
local con_height = self.container.transform.sizeDelta.y
|
|
|
|
local x, y = ScreenToViewportPoint(self.localPos.x, self.localPos.y)
|
|
x = x - 180
|
|
y = y + 255
|
|
x = x < 40 and 40 or x
|
|
if x + con_width > ScreenWidth then
|
|
x = ScreenWidth - con_width - 25
|
|
end
|
|
if y > ScreenHeight then
|
|
y = y - con_height - 80
|
|
end
|
|
|
|
self.container.transform.anchoredPosition = Vector3(x, y, 0)
|
|
end
|