ViewUtil = { Num_Converted = { "一", "二", "三", "四" }, Sex_Chat = { "man", "woman" }, Fix_Msg_Chat = { "大家好,很高兴见到各位!", "和你合作太愉快了!", "快点啊,我等的花儿都谢了!", "你丫的牌打得也忒好了", "不要吵了不要吵了,吵什么吵啊,专心打牌", "怎么又断线了,网络这么差!", "各位,真不好意思啊,我得离开一会", "不要走,决战到天亮!", "你是妹妹,还是哥哥啊?", "我们交个朋友吧,能不能告诉我你的联系方法", "再见了,我会想念大家的", "不好意思临时有事,申请解散!" } } function ViewUtil.GetPos(self_seat,seat,people_num) if self_seat == 0 then return seat end local cur_seat = self_seat local tem = seat - (cur_seat - 1) if (tem <= 0) then tem = tem +people_num end return tem end -- 隐藏手机号 function ViewUtil.phone_hide(phone) return string.sub(phone,1,3).."****"..string.sub(phone,8) end -- 隐藏身份证 function ViewUtil.identity_hide(identity) return string.sub(identity,1,8).."****"..string.sub(identity,13) end local modal_wait_win =nil -- local modal_wait_win_url = "ui://Common/GlobalModalWaiting" function ViewUtil.ShowModalWait(blur_view, title) ViewUtil.CloseModalWait() ModalWaitingWindow.ShowModal(title) end function ViewUtil.CloseModalWait() ModalWaitingWindow.CloseModal() end local _defaultTooltipWin =nil local function __waittips(obj) _defaultTooltipWin:Dispose() _defaultTooltipWin = nil end local _tip_timer local function __ShowTips(msg,time) time = time or 2 if _defaultTooltipWin then _tip_timer:Stop() _defaultTooltipWin:Dispose() _defaultTooltipWin = nil end _defaultTooltipWin = UIPackage.CreateObjectFromURL("ui://Common/ToolsTip") _defaultTooltipWin.touchable = false _defaultTooltipWin.text = msg GRoot.inst:AddChild(_defaultTooltipWin) _defaultTooltipWin:MakeFullScreen() _tip_timer = Timer.New(function() __waittips() end,time,1,true) _tip_timer:Start() end function ViewUtil.ErrorTip(code,tip,time) if(Table_Error_code_Map[code]~=nil) then __ShowTips(string.format("%s",Table_Error_code_Map[code].note), time) else __ShowTips(tip,time) end end function ViewUtil.ErrorMsg(_root_view,code,tip,url) local msg = tip if(Table_Error_code_Map[code]~=nil) then msg = string.format("%s",Table_Error_code_Map[code].note) end local _curren_msg = MsgWindow.new(_root_view, msg, MsgWindow.MsgMode.OnlyOk,url) _curren_msg:Show() end function ViewUtil.ShowTips(msg) __ShowTips(msg) end function ViewUtil.ShowBannerOnScreenCenter(msg, s) local time = s or 0.8 if ViewUtil._banner then ViewUtil._banner:Dispose() end local banner = UIPackage.CreateObjectFromURL("ui://Common/Pop_tips") banner:GetChild("tex_tip").text = msg GRoot.inst:AddChild(banner) banner:Center() ViewUtil._banner = banner local timer = Timer.New(function() banner:Dispose() end,time,1,true) timer:Start() end function ViewUtil.PlaySoundBg() GameApplication.Instance:PlayMuisc("base/common/sound/bgmusic1.mp3") end function ViewUtil.HandCardSort(a,b) local sort_a = a local sort_b = b if a >= 400 then sort_a = sort_a -1000 end if b >= 400 then sort_b = sort_b - 1000 end return sort_a>>",prefix,ct) return prefix end function get_majiang_card_type(game_id) local ct_data = nil local json_data = Utils.LoadLocalFile("CardTypeData") if json_data then ct_data = json.decode(json_data) else ct_data = {} end ct = ct_data[tostring(game_id)] or 0 return ct end -- 数据转换成3位小数 data to a decimal function d2ad(data) return data / 1000 end -- 3位小数转换成数据 a decimal to data function ad2d(decimal) return decimal * 1000 end -- 获取gps function get_gps(callback) if Application.platform == RuntimePlatform.IPhonePlayer or Application.platform == RuntimePlatform.Android then local s,e = pcall(function() Utils.LocalAddress(function(result, latitude, longitude) if not result or (latitude == 0 and longitude == 0) then return end DataManager.SelfUser.location = Location.new(tostring(longitude) .. "," .. tostring(latitude)) if callback then callback() end end) end) if not s then --print("Error" .. e) end elseif Application.platform == RuntimePlatform.WindowsPlayer or Application.platform == RuntimePlatform.WindowsEditor then -- DataManager.SelfUser.location = Location.new(string.format("%s,%s", math.random(10,20), math.random(10,20))) DataManager.SelfUser.location = Location.new("10,10") if callback then callback() end end end --依据宽度截断字符 function ViewUtil.stringEllipsis(szText,size,full) full = full or false size = size or 4 --截断结果 local szResult = "..." --完成判断 local bOK = false local i = 1 local char_count = 0 while true do local cur = string.sub(szText,i,i) local byte = string.byte(cur) if byte == nil then break end if char_count >= size and full == false then bOK = true break end if byte > 128 then i = i + 3 char_count = char_count + 1 elseif byte ~= 32 then if string.byte('A') <= byte and byte <= string.byte('Z') then char_count = char_count + 1 else char_count = char_count + 0.5 end i = i + 1 else i = i + 1 char_count = char_count + 0.5 end end if i ~= 1 then szResult = string.sub(szText, 1, i-1) if(bOK) then szResult = szResult.."..." end end return szResult end -------------------------lingmeng--------------------------- function ViewUtil.ShowOneChooose(showText,btnType,callback) local pop_oneChoose = UIPackage.CreateObjectFromURL("ui://Common/pop_oneChoose") pop_oneChoose:GetChild('text_show').text = showText GRoot.inst:AddChild(pop_oneChoose) pop_oneChoose:Center() local btn_center = pop_oneChoose:GetChild('btn_center') if type(btnType) == "number" then btn_center.icon = string.format("ui://Common/btn_%d",btnType) else btn_center.icon = btnType end btn_center.onClick:Add(function() GRoot.inst:RemoveChild(pop_oneChoose) if callback then callback() end end) end