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 < sort_b end function ViewUtil.HandCardSort2(a, b) a = tonumber(string.sub(a, 2)) b = tonumber(string.sub(b, 2)) --print(a) --print(b) return a < b end function ViewUtil.HandCardSort3(a, b) local sort_a = a[1] or 101 local sort_b = b[1] or 101 return sort_a < sort_b end function ViewUtil.CardPos(obj, area, oder, index, offset, isAdd, padding) offset = offset or 0 padding = padding or 0 if oder == AreaOderType.left_right then obj.x = index * (obj.width + padding) + offset elseif oder == AreaOderType.up_down then obj.y = index * (obj.height - padding) + offset elseif oder == AreaOderType.right_left then obj.x = (area.width - obj.width) - index * (obj.width + padding) - offset elseif oder == AreaOderType.down_up then if isAdd then obj.y = area.height - obj.height - index * obj.height * 1.5 - offset else obj.y = area.height - obj.height - index * obj.height - offset end --obj.y = area.height - obj.height - index * obj.height - offset end end local _current_group = nil function ViewUtil.PlayMuisc(group, path) if group ~= _current_group then if _current_group then ResourcesManager.UnLoadGroup(_current_group) end _current_group = group end GameApplication.Instance:PlayMuisc(group, path) end function ViewUtil.PlaySound(group, path) if group ~= _current_group then if _current_group then ResourcesManager.UnLoadGroup(_current_group) end _current_group = group end GameApplication.Instance:PlaySound(group, path) end function ViewUtil.HideID(id) local len = string.len(id) return "****" .. string.sub(id, len - 1, len) end -- 检测麻将牌前缀名 function get_majiang_prefix(game_id) -- 加载牌型数据 local ct = 1 if DataManager.CurrenRoom and DataManager.CurrenRoom.card_type then ct = DataManager.CurrenRoom.card_type --printlog("get_majiang_prefix=============1111") elseif game_id then --printlog("get_majiang_prefix=============1111222222222222") 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 end local prefix = ct == 0 and "" or "a" --printlog("get_majiang_prefix===>>>",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