changhong/lua_probject/base_project/Game/View/NewGroup/MngView/GroupNumberInputView.lua

118 lines
3.5 KiB
Lua

-- 数字输入界面
local GroupNumberInputView = {}
local M = GroupNumberInputView
local KEY_DEL = "del"
local KEY_CLEAR = "c"
local InputType =
{
-- 普通输入框
Default = 0,
-- 增加体力值
FagAdd = 1,
-- 减少体力值
FagMinus = 2,
-- 体力值抽成,有小数点
FagDeduct = 3,
-- 其他传入的组件
Other = 4,
}
function GroupNumberInputView.new(blur_view,callback,itype,fag,com)
setmetatable(M, {__index = BaseWindow})
local self = setmetatable({}, {__index = M})
self.class = "GroupNumberInputView"
self._currenIndex = 0
self._close_destroy = true
self._blur_view = blur_view
self._callback = callback
itype = itype or InputType.Default
local url = "ui://NewGroup/Win_FagInput" .. itype
if com then url = com end
self._str_len_limit = itype == InputType.FagDeduct and 10 or 8
self._type = itype
self._fag = fag
self:init(url)
return self
end
function M:init(url)
BaseWindow.init(self,url)
self.tex_num = self._view:GetChild("tex_num")
self:ClearNumTex()
local cnt = self._view.numChildren - 1
for i = 0 , 10 do
local obj = self._view:GetChild("btn_"..i)
if obj then
obj.onClick:Set(handler(self , self.OnNumButtonAction))
end
i = i + 1
end
local btn_ok = self._view:GetChild("btn_ok")
btn_ok.onClick:Set(function()
if self._currenIndex <1 then
return
end
self:Destroy()
if self._callback then
self._callback(tonumber(self._texnum_str))
end
end)
local btn_del = self._view:GetChild("btn_del")
btn_del.onClick:Set(handler(self , self.OnNumButtonAction))
local btn_c = self._view:GetChild("btn_c")
if btn_c then btn_c.onClick:Set(handler(self, self.OnNumButtonAction)) end
end
function M:OnNumButtonAction(context)
local typer = string.sub(context.sender.name ,5)
if typer == KEY_DEL then
if (self._currenIndex > 0) then
self._currenIndex = self._currenIndex - 1
self._texnum_str = string.sub(self._texnum_str,0,self._currenIndex)
self.tex_num.text = self._texnum_str
end
elseif typer == KEY_CLEAR then
-- local msg = "你确定要减少" .. self._fag .. "体力值吗?"
-- local _curren_msg = MsgWindow.new(self._view, msg, MsgWindow.MsgMode.OkAndCancel,"ui://NewGroup/MessageBox")
-- _curren_msg.onOk:Add(function()
-- self._callback(self._fag)
-- self:Destroy()
-- end)
-- _curren_msg:Show()
self._currenIndex = string.len(self._fag)
self._texnum_str = self._fag
self.tex_num.text = self._texnum_str
else
-- 限制只能输入3位小数
if self._type == 3 then
local _, i = string.find(self._texnum_str, '%.')
if i then
if context.sender.title == "." then
return
end
if self._currenIndex - i == 3 then
return
end
end
end
if (self._currenIndex < self._str_len_limit) then
self._currenIndex = self._currenIndex + 1
self._texnum_str = self._texnum_str .. context.sender.title
self.tex_num.text = self._texnum_str
end
end
end
function M:ClearNumTex()
self._texnum_str = ""
self._currenIndex = 0
self.tex_num.text = self._texnum_str
end
return M