1314 lines
37 KiB
Lua
1314 lines
37 KiB
Lua
|
-- Lua中的继承
|
|||
|
function Inherit(tbParent, tbChild)
|
|||
|
if not tbParent then
|
|||
|
local o = tbChild or {}
|
|||
|
setmetatable(o, { __index = o })
|
|||
|
return o
|
|||
|
else
|
|||
|
local tb = tbChild or {}
|
|||
|
tbParent.__index = tbParent
|
|||
|
--local super_mt = getmetatable(tbParent)
|
|||
|
setmetatable(tb, tbParent)
|
|||
|
tb.super = setmetatable({}, tbParent)
|
|||
|
return tb
|
|||
|
end
|
|||
|
end
|
|||
|
|
|||
|
function RandomList(arr)
|
|||
|
if not arr or #arr <= 1 then
|
|||
|
return
|
|||
|
end
|
|||
|
local index
|
|||
|
for i = #arr, 1, -1 do
|
|||
|
index = math.random(1, i)
|
|||
|
arr[i], arr[index] = arr[index], arr[i]
|
|||
|
end
|
|||
|
end
|
|||
|
|
|||
|
--查找对象--
|
|||
|
function find(str)
|
|||
|
return GameObject.Find(str)
|
|||
|
end
|
|||
|
|
|||
|
function destroy(obj)
|
|||
|
GameObject.DestroyImmediate(obj)
|
|||
|
end
|
|||
|
|
|||
|
function newObject(prefab)
|
|||
|
return GameObject.Instantiate(prefab)
|
|||
|
end
|
|||
|
|
|||
|
--适配
|
|||
|
function screenAdapte(go)
|
|||
|
--if Screen.width > 1080 or Screen.height > 1920 then
|
|||
|
-- local scale = math.max(Screen.width / 1080, Screen.height / 1920)
|
|||
|
-- go.transform.localScale = Vector3.one * scale
|
|||
|
--end
|
|||
|
end
|
|||
|
|
|||
|
function effectAdapte(go)
|
|||
|
local scale = Screen.width / Screen.height / 1080 * 1920
|
|||
|
--local scale = Screen.width / 1080
|
|||
|
--local scale = 1920 / Screen.height
|
|||
|
--Log("scale:"..scale)
|
|||
|
local v3 = go.transform.localScale
|
|||
|
if scale <= 1 then
|
|||
|
Util.SetParticleScale(go, scale)
|
|||
|
end
|
|||
|
go.transform.localScale = v3
|
|||
|
end
|
|||
|
|
|||
|
--创建面板--
|
|||
|
function createPanel(name)
|
|||
|
PanelManager:CreatePanel(name)
|
|||
|
end
|
|||
|
|
|||
|
function child(str)
|
|||
|
return transform:FindChild(str)
|
|||
|
end
|
|||
|
|
|||
|
function subGet(childNode, typeName)
|
|||
|
return child(childNode):GetComponent(typeName)
|
|||
|
end
|
|||
|
|
|||
|
function findPanel(str)
|
|||
|
local obj = find(str)
|
|||
|
if obj == nil then
|
|||
|
error(str .. " is null")
|
|||
|
return nil
|
|||
|
end
|
|||
|
return obj:GetComponent("BaseLua")
|
|||
|
end
|
|||
|
|
|||
|
function ReloadFile(file_path)
|
|||
|
package.loaded[file_path] = nil -- 消除载入记录
|
|||
|
return require(file_path) -- 重新加载lua文件
|
|||
|
end
|
|||
|
|
|||
|
function UnLoadLuaFiles(config)
|
|||
|
for i, v in ipairs(config) do
|
|||
|
package.loaded[v] = nil
|
|||
|
package.preload[v] = nil
|
|||
|
end
|
|||
|
end
|
|||
|
|
|||
|
function LoadLuaFiles(config)
|
|||
|
for i, v in ipairs(config) do
|
|||
|
require(v)
|
|||
|
end
|
|||
|
end
|
|||
|
|
|||
|
--播放指定音效,在同一时刻点击音效不播放
|
|||
|
function PlaySoundWithoutClick(sound)
|
|||
|
SoundManager.PlaySound(sound)
|
|||
|
Framework.PlayClickSoundThisTime = false
|
|||
|
end
|
|||
|
|
|||
|
-- 连续弹出文字
|
|||
|
-- 1 -- 使用正常Tip
|
|||
|
-- 2 -- 使用带颜色的
|
|||
|
function PopupText(strTable, delayTime, type)
|
|||
|
local index = 1
|
|||
|
local timer
|
|||
|
timer = Timer.New(function()
|
|||
|
if index == #strTable + 1 then
|
|||
|
timer:Stop()
|
|||
|
else
|
|||
|
if type == 1 then
|
|||
|
PopupTipPanel.ShowTip(strTable[index])
|
|||
|
elseif type == 2 then
|
|||
|
PopupTipPanel.ShowColorTip(strTable[index].name, strTable[index].icon, strTable[index].num)
|
|||
|
end
|
|||
|
index = index + 1
|
|||
|
end
|
|||
|
end, delayTime, #strTable * delayTime * 2)
|
|||
|
timer:Start()
|
|||
|
end
|
|||
|
|
|||
|
function Util_SetHeadImage(url, image, isSelf)
|
|||
|
if image == nil then
|
|||
|
return
|
|||
|
end
|
|||
|
|
|||
|
if url == nil then
|
|||
|
Util_SetToDefaultHeadImage(image)
|
|||
|
return
|
|||
|
end
|
|||
|
|
|||
|
if url == "" or url == "/0" then
|
|||
|
Util_SetToDefaultHeadImage(image)
|
|||
|
return
|
|||
|
end
|
|||
|
|
|||
|
imageDownloadMgr:SetImage_Image(url, image, isSelf)
|
|||
|
end
|
|||
|
|
|||
|
function Util_SetToDefaultHeadImage(image)
|
|||
|
if image == nil then
|
|||
|
return
|
|||
|
end
|
|||
|
|
|||
|
local bundleName = "normal_asset"
|
|||
|
local assetName = "Avatar"
|
|||
|
|
|||
|
local sprite = Util.LoadSprite("Platform", assetName)
|
|||
|
image.sprite = sprite
|
|||
|
end
|
|||
|
|
|||
|
function TextHelper_Get24HourTimeStr(time)
|
|||
|
if time < 10 then
|
|||
|
return "0" .. time
|
|||
|
else
|
|||
|
return time
|
|||
|
end
|
|||
|
end
|
|||
|
|
|||
|
function PrintWanNum(num)
|
|||
|
if num >= 100000000 then
|
|||
|
return string.format("%.1f", num / 100000000) .. "亿"
|
|||
|
elseif num >= 1000000 then
|
|||
|
return tostring(math.floor(num / 10000)) .. "万"
|
|||
|
else
|
|||
|
return tostring(num)
|
|||
|
end
|
|||
|
end
|
|||
|
function PrintWanNum2(num)
|
|||
|
if num >= 100000000 then
|
|||
|
return string.format("%.1f", num / 100000000) .. "亿"
|
|||
|
elseif num >= 10000 then
|
|||
|
return tostring(math.floor(num / 10000)) .. "万"
|
|||
|
--return tostring(math.floor(num / 1000)/10) .. "万"
|
|||
|
else
|
|||
|
return tostring(num)
|
|||
|
end
|
|||
|
end
|
|||
|
|
|||
|
--判断两个时间在同一天
|
|||
|
function Util_Check_insameday(time1, time2)
|
|||
|
local date1 = os.date("*t", time1)
|
|||
|
local date2 = os.date("*t", time2)
|
|||
|
if date1.year == date2.year and date1.month == date2.month and date1.day == date2.day then
|
|||
|
return true
|
|||
|
end
|
|||
|
return false
|
|||
|
end
|
|||
|
|
|||
|
--判断两个时间在同一个月
|
|||
|
function Util_Check_insamemonth(time1, time2)
|
|||
|
local date1 = os.date("*t", time1)
|
|||
|
local date2 = os.date("*t", time2)
|
|||
|
if date1.year == date2.year and date1.month == date2.month then
|
|||
|
return true
|
|||
|
end
|
|||
|
return false
|
|||
|
end
|
|||
|
|
|||
|
--判断两个时间在同一星期
|
|||
|
function Util_Check_insameweek(time1, time2)
|
|||
|
local week_second = 7 * 24 * 3600
|
|||
|
local time_zero = os.time { year = 2015, month = 1, day = 5, hour = 0, min = 0, sec = 0 }
|
|||
|
local time1_tran = time1 - time_zero
|
|||
|
local time2_tran = time2 - time_zero
|
|||
|
local week1 = math.floor(time1_tran / week_second)
|
|||
|
local week2 = math.floor(time2_tran / week_second)
|
|||
|
|
|||
|
if week1 == week2 then
|
|||
|
return true
|
|||
|
end
|
|||
|
return false
|
|||
|
end
|
|||
|
--秒转换成文字对应时间
|
|||
|
function GetTimeStrBySeconds(_seconds)
|
|||
|
return os.date("%Y年%m月%d日%H时", _seconds)
|
|||
|
end
|
|||
|
--秒转换成文字对应时间 只有分秒
|
|||
|
function GetTimeMaoHaoStrBySeconds(_seconds)
|
|||
|
return os.date("%M:%S", _seconds)
|
|||
|
end
|
|||
|
|
|||
|
function PrintTable(root)
|
|||
|
local cache = { [root] = "." }
|
|||
|
local function _dump(t, space, name)
|
|||
|
if type(t) == "table" then
|
|||
|
local temp = {}
|
|||
|
for k, v in pairs(t) do
|
|||
|
local key = tostring(k)
|
|||
|
if cache[v] then
|
|||
|
tinsert(temp, "+" .. key .. " {" .. cache[v] .. "}")
|
|||
|
elseif type(v) == "table" then
|
|||
|
local new_key = name .. "." .. key
|
|||
|
cache[v] = new_key
|
|||
|
tinsert(temp, "+" .. key .. _dump(v, space .. (next(t, k) and "|" or " ") .. srep(" ", #key), new_key))
|
|||
|
else
|
|||
|
tinsert(temp, "+" .. key .. " [" .. tostring(v) .. "]")
|
|||
|
end
|
|||
|
end
|
|||
|
return tconcat(temp, "\n" .. space)
|
|||
|
end
|
|||
|
end
|
|||
|
print(_dump(root, "", ""))
|
|||
|
end
|
|||
|
|
|||
|
local isPcall = true
|
|||
|
--用于查找错误用
|
|||
|
function MyPCall(func)
|
|||
|
if not isPcall then
|
|||
|
func()
|
|||
|
return
|
|||
|
end
|
|||
|
local flag, msg = pcall(func)
|
|||
|
if not flag then
|
|||
|
Util.LogError(msg)
|
|||
|
end
|
|||
|
end
|
|||
|
|
|||
|
function PlayUIAnims(gameObject, callback)
|
|||
|
local anims = gameObject:GetComponentsInChildren(typeof(PlayFlyAnim))
|
|||
|
if anims.Length > 0 then
|
|||
|
for i = 0, anims.Length - 1 do
|
|||
|
anims[i]:PlayAnim(false, callback)
|
|||
|
end
|
|||
|
end
|
|||
|
end
|
|||
|
|
|||
|
function PlayUIAnimBacks(gameObject, callback)
|
|||
|
local anims = gameObject:GetComponentsInChildren(typeof(PlayFlyAnim))
|
|||
|
if anims.Length > 0 then
|
|||
|
for i = 0, anims.Length - 1 do
|
|||
|
anims[i]:PlayHideAnim(callback)
|
|||
|
end
|
|||
|
end
|
|||
|
end
|
|||
|
|
|||
|
function PlayUIAnim(gameObject, callback)
|
|||
|
local anim = gameObject:GetComponent(typeof(PlayFlyAnim))
|
|||
|
if anim then
|
|||
|
anim:PlayAnim(false, callback)
|
|||
|
end
|
|||
|
end
|
|||
|
|
|||
|
function PlayUIAnimBack(gameObject, callback)
|
|||
|
--local anim = gameObject:GetComponent(typeof(PlayFlyAnim))
|
|||
|
local anim = gameObject:GetComponent("PlayFlyAnim")
|
|||
|
if anim then
|
|||
|
anim:PlayHideAnim(callback)
|
|||
|
end
|
|||
|
end
|
|||
|
|
|||
|
--地图uv坐标
|
|||
|
function Map_UV2Pos(u, v)
|
|||
|
return u * 256 + v
|
|||
|
end
|
|||
|
--地图uv坐标
|
|||
|
function Map_Pos2UV(pos)
|
|||
|
return math.floor(pos / 256), pos % 256
|
|||
|
end
|
|||
|
|
|||
|
-- 公会地图坐标精细化处理
|
|||
|
function GuildMap_UV2Pos(u, v)
|
|||
|
-- return u * 256 + v
|
|||
|
local _u = math.floor(u *100)
|
|||
|
local _v = math.floor(v *100)
|
|||
|
return _u * 25600 + _v
|
|||
|
end
|
|||
|
function GuildMap_Pos2UV(pos)
|
|||
|
-- return math.floor(pos / 256), pos % 256
|
|||
|
local _u = math.floor(pos/25600)/100
|
|||
|
local _v = pos%25600/100
|
|||
|
return math.round(_u), math.round(_v), _u, _v
|
|||
|
end
|
|||
|
|
|||
|
--把英雄星级父对象和星级传过来
|
|||
|
function SetHeroStars(starGrid, star)
|
|||
|
if star < 6 then
|
|||
|
for i = 1, 15 do
|
|||
|
if i <= star then
|
|||
|
starGrid.transform:GetChild(i - 1).gameObject:SetActive(true)
|
|||
|
else
|
|||
|
starGrid.transform:GetChild(i - 1).gameObject:SetActive(false)
|
|||
|
end
|
|||
|
end
|
|||
|
elseif star > 5 and star < 11 then
|
|||
|
for i = 1, 15 do
|
|||
|
if i <= star and i > 5 then
|
|||
|
starGrid.transform:GetChild(i - 1).gameObject:SetActive(true)
|
|||
|
else
|
|||
|
starGrid.transform:GetChild(i - 1).gameObject:SetActive(false)
|
|||
|
end
|
|||
|
end
|
|||
|
elseif star > 10 then
|
|||
|
for i = 1, 15 do
|
|||
|
if i <= star and i > 10 then
|
|||
|
starGrid.transform:GetChild(i - 1).gameObject:SetActive(true)
|
|||
|
else
|
|||
|
starGrid.transform:GetChild(i - 1).gameObject:SetActive(false)
|
|||
|
end
|
|||
|
end
|
|||
|
end
|
|||
|
end
|
|||
|
-- 在给定节点下加载预设, 返回实例化的预设
|
|||
|
function newObjToParent(prefab, parent)
|
|||
|
local go = newObject(prefab)
|
|||
|
go.transform:SetParent(parent.transform)
|
|||
|
go.transform.localScale = Vector3.one
|
|||
|
go.transform.localPosition = Vector3.zero
|
|||
|
go:SetActive(true)
|
|||
|
return go
|
|||
|
end
|
|||
|
|
|||
|
-- 清除节点下所有的子节点
|
|||
|
function ClearChild(parent)
|
|||
|
Util.ClearChild(parent.transform)
|
|||
|
end
|
|||
|
|
|||
|
-- 加载一个商店使用的item
|
|||
|
function AddShopItem(parent, itemId, shopType)
|
|||
|
local item = SubUIManager.Open(SubUIConfig.ShopItemView, parent.transform)
|
|||
|
item:OnOpen(itemId, shopType)
|
|||
|
return item
|
|||
|
end
|
|||
|
|
|||
|
-- 根据ID返回物品的Icon,配置数据在artResourceConfig中
|
|||
|
function SetIcon(id)
|
|||
|
if not id or id == 0 then
|
|||
|
Log("设置的物品Icon不存在!")
|
|||
|
return
|
|||
|
end
|
|||
|
|
|||
|
local itemConfig = ConfigManager.GetConfig(ConfigName.ItemConfig)
|
|||
|
local icon = nil
|
|||
|
local resId = itemConfig[id].ResourceID
|
|||
|
if not resId then
|
|||
|
Log("资源ID不存在!!")
|
|||
|
return
|
|||
|
end
|
|||
|
local resPath = GetResourcePath(resId)
|
|||
|
if not resPath then
|
|||
|
Log("尚未有此类美术资源!!")
|
|||
|
return
|
|||
|
end
|
|||
|
icon = Util.LoadSprite(resPath)
|
|||
|
return icon
|
|||
|
end
|
|||
|
|
|||
|
function SetFrame(id)
|
|||
|
if not id or id == 0 then
|
|||
|
Log("设置的物品Icon不存在!")
|
|||
|
return
|
|||
|
end
|
|||
|
|
|||
|
local itemConfig = ConfigManager.GetConfig(ConfigName.ItemConfig)
|
|||
|
local icon = nil
|
|||
|
local resId = itemConfig[id].Quantity
|
|||
|
if not resId then
|
|||
|
Log("资源ID不存在!!")
|
|||
|
return
|
|||
|
end
|
|||
|
icon = Util.LoadSprite(GetQuantityImageByquality(resId))
|
|||
|
return icon
|
|||
|
end
|
|||
|
|
|||
|
--属性表ID转换表
|
|||
|
function GetProIndexByProId(proId)
|
|||
|
local proIndex = 0
|
|||
|
if proId == 1 then
|
|||
|
-- 最大生命
|
|||
|
proIndex = 3
|
|||
|
elseif proId == 2 then
|
|||
|
-- 攻击力
|
|||
|
proIndex = 4
|
|||
|
elseif proId == 3 then
|
|||
|
-- 护甲
|
|||
|
proIndex = 5
|
|||
|
elseif proId == 4 then
|
|||
|
-- 魔抗
|
|||
|
proIndex = 6
|
|||
|
elseif proId == 5 then
|
|||
|
-- 速度
|
|||
|
proIndex = 7
|
|||
|
elseif proId == 6 or proId == 67 or proId == 68 then
|
|||
|
-- 当前生命值
|
|||
|
proIndex = 2
|
|||
|
elseif proId == 51 then
|
|||
|
-- 伤害加成
|
|||
|
proIndex = 8
|
|||
|
elseif proId == 52 then
|
|||
|
-- 伤害减免
|
|||
|
proIndex = 9
|
|||
|
elseif proId == 53 then
|
|||
|
-- 效果命中
|
|||
|
proIndex = 10
|
|||
|
elseif proId == 54 then
|
|||
|
-- 效果抵抗
|
|||
|
proIndex = 11
|
|||
|
elseif proId == 55 then
|
|||
|
-- 暴击率
|
|||
|
proIndex = 12
|
|||
|
elseif proId == 56 then
|
|||
|
-- 暴伤
|
|||
|
proIndex = 13
|
|||
|
elseif proId == 57 then
|
|||
|
-- 回复率
|
|||
|
proIndex = 14
|
|||
|
elseif proId == 101 then
|
|||
|
-- 火焰伤害
|
|||
|
proIndex = 15
|
|||
|
elseif proId == 102 then
|
|||
|
-- 狂风伤害
|
|||
|
proIndex = 16
|
|||
|
elseif proId == 103 then
|
|||
|
-- 碧水伤害
|
|||
|
proIndex = 17
|
|||
|
elseif proId == 104 then
|
|||
|
-- 大地伤害
|
|||
|
proIndex = 18
|
|||
|
elseif proId == 105 then
|
|||
|
-- 神圣伤害
|
|||
|
elseif proId == 106 then
|
|||
|
-- 黑暗伤害
|
|||
|
elseif proId == 107 then
|
|||
|
-- 火焰抗性
|
|||
|
elseif proId == 108 then
|
|||
|
-- 狂风抗性
|
|||
|
elseif proId == 109 then
|
|||
|
-- 碧水抗性
|
|||
|
elseif proId == 110 then
|
|||
|
-- 大地抗性
|
|||
|
elseif proId == 111 then
|
|||
|
-- 神圣抗性
|
|||
|
elseif proId == 112 then
|
|||
|
-- 黑暗抗性
|
|||
|
end
|
|||
|
|
|||
|
return proIndex
|
|||
|
end
|
|||
|
|
|||
|
--逐渐显示对应文字内容,若在此期间点击屏幕,则立刻显示完文字内容
|
|||
|
function ShowText(go, str, duration, callBack)
|
|||
|
local text = go:GetComponent("Text")
|
|||
|
text.text = ""
|
|||
|
local tween = text:DOText(str, duration)
|
|||
|
local isClick = false
|
|||
|
tween:OnUpdate(function()
|
|||
|
if Input.GetMouseButtonDown(0) then
|
|||
|
isClick = true
|
|||
|
end
|
|||
|
if isClick then
|
|||
|
if tween then
|
|||
|
tween:Kill()
|
|||
|
go:GetComponent("Text").text = str
|
|||
|
if callBack then
|
|||
|
callBack()
|
|||
|
end
|
|||
|
end
|
|||
|
end
|
|||
|
end)
|
|||
|
tween:OnComplete(callBack)
|
|||
|
end
|
|||
|
|
|||
|
-- 将秒转换成分:秒格式返回
|
|||
|
function SetTimeFormation(seconds)
|
|||
|
|
|||
|
local str = ""
|
|||
|
local ten_minute = math.modf(seconds / 600)
|
|||
|
local minute = math.modf(seconds / 60) % 10
|
|||
|
local ten_second = math.modf(seconds / 10) % 6
|
|||
|
local second = seconds % 10
|
|||
|
str = ten_minute .. minute .. " : " .. ten_second .. second
|
|||
|
return str
|
|||
|
end
|
|||
|
|
|||
|
function Dump(data, showMetatable, lastCount)
|
|||
|
if type(data) == "table" then
|
|||
|
--Format
|
|||
|
local count = lastCount or 0
|
|||
|
count = count + 1
|
|||
|
|
|||
|
local B2 = ""
|
|||
|
for i = 1, count do
|
|||
|
B2 = B2 .. " "
|
|||
|
end
|
|||
|
Log(B2 .. "{\n")
|
|||
|
--Metatable
|
|||
|
if showMetatable then
|
|||
|
local blank = " "
|
|||
|
for i = 1, count do
|
|||
|
blank = blank .. " "
|
|||
|
end
|
|||
|
local mt = getmetatable(data)
|
|||
|
Log(blank .. "\"__metatable\" = ")
|
|||
|
|
|||
|
Dump(mt, showMetatable, count)
|
|||
|
end
|
|||
|
--Key
|
|||
|
for key, value in pairs(data) do
|
|||
|
local blank = " "
|
|||
|
for i = 1, count do
|
|||
|
blank = blank .. " "
|
|||
|
end
|
|||
|
if type(key) == "string" then
|
|||
|
Log(blank .. "\"" .. key .. "\" = " .. GetStr(value))
|
|||
|
|
|||
|
elseif type(key) == "number" then
|
|||
|
Log(blank .. "[" .. key .. "] = " .. GetStr(value))
|
|||
|
else
|
|||
|
Log(blank .. string.format("%s", key) .. GetStr(value))
|
|||
|
end
|
|||
|
Dump(value, showMetatable, count)
|
|||
|
end
|
|||
|
--Format
|
|||
|
local B0 = " "
|
|||
|
for i = 1, lastCount or 0 do
|
|||
|
B0 = B0 .. " "
|
|||
|
end
|
|||
|
Log(B0 .. "}")
|
|||
|
end
|
|||
|
--Format
|
|||
|
if not lastCount then
|
|||
|
Log("\n")
|
|||
|
end
|
|||
|
end
|
|||
|
|
|||
|
function GetStr(data)
|
|||
|
local str = ""
|
|||
|
if type(data) ~= "table" then
|
|||
|
--Value
|
|||
|
if type(data) == "string" then
|
|||
|
str = ("\"" .. data .. "\"")
|
|||
|
elseif data == nil then
|
|||
|
str = "nil"
|
|||
|
else
|
|||
|
str = (string.format("%s", data))
|
|||
|
end
|
|||
|
end
|
|||
|
return str
|
|||
|
end
|
|||
|
|
|||
|
|
|||
|
--通过item稀有度读取背景框
|
|||
|
function GetQuantityImageByquality(quality)
|
|||
|
if quality == 1 then
|
|||
|
return "r_characterbg_gray"
|
|||
|
elseif quality == 2 then
|
|||
|
return "r_characterbg_green"
|
|||
|
elseif quality == 3 then
|
|||
|
return "r_characterbg_blue"
|
|||
|
elseif quality == 4 then
|
|||
|
return "r_characterbg_purple"
|
|||
|
elseif quality == 5 then
|
|||
|
return "r_characterbg_yellow"
|
|||
|
elseif quality == 6 then
|
|||
|
return "r_characterbg_gules"
|
|||
|
elseif quality == 7 then
|
|||
|
return "t_tongyong_topkaung"
|
|||
|
else
|
|||
|
return "t_tongyong_topkaung"
|
|||
|
end
|
|||
|
end
|
|||
|
|
|||
|
|
|||
|
--通过item稀有度读取背景框
|
|||
|
function GetQuantityImageByqualityPoint(quality)
|
|||
|
if quality == 1 then
|
|||
|
return "r_hunyin_zise"
|
|||
|
elseif quality == 2 then
|
|||
|
return "r_hunyin_zise"
|
|||
|
elseif quality == 3 then
|
|||
|
return "r_hunyin_zise"
|
|||
|
elseif quality == 4 then
|
|||
|
return "r_hunyin_zise"
|
|||
|
elseif quality == 5 then
|
|||
|
return "r_hunyin_chengse"
|
|||
|
elseif quality == 6 then
|
|||
|
return "r_hunyin_hongse"
|
|||
|
elseif quality == 7 then
|
|||
|
return "r_hunyin_caise"
|
|||
|
else
|
|||
|
return "r_hunyin_caise"
|
|||
|
end
|
|||
|
end
|
|||
|
|
|||
|
--通过item稀有度读取背景框
|
|||
|
function GetQuantityStrByquality(quality)
|
|||
|
if quality == 1 then
|
|||
|
return "白色"
|
|||
|
elseif quality == 2 then
|
|||
|
return "绿色"
|
|||
|
elseif quality == 3 then
|
|||
|
return "蓝色"
|
|||
|
elseif quality == 4 then
|
|||
|
return "紫色"
|
|||
|
elseif quality == 5 then
|
|||
|
return "橙色"
|
|||
|
elseif quality == 6 then
|
|||
|
return "红色"
|
|||
|
elseif quality == 7 then
|
|||
|
return "金色"
|
|||
|
else
|
|||
|
return "白色"
|
|||
|
end
|
|||
|
end
|
|||
|
--通过Hero稀有度读取碎片遮罩(小)
|
|||
|
function GetHeroChipQuantityImageByquality(quality)
|
|||
|
if quality == 1 then
|
|||
|
return "PieceMask_blue"
|
|||
|
elseif quality == 2 then
|
|||
|
return "PieceMask_blue"
|
|||
|
elseif quality == 3 then
|
|||
|
return "PieceMask_blue"
|
|||
|
elseif quality == 4 then
|
|||
|
return "PieceMask_purple"
|
|||
|
elseif quality == 5 then
|
|||
|
return "PieceMask_orange"
|
|||
|
elseif quality > 5 then
|
|||
|
return "PieceMask_orange"
|
|||
|
end
|
|||
|
end
|
|||
|
--通过Hero稀有度读取背景框(小)
|
|||
|
function GetHeroQuantityImageByquality(quality)
|
|||
|
if quality == 0 or quality == 1 then
|
|||
|
return "r_characterbg_gray"
|
|||
|
elseif quality == 2 then
|
|||
|
return "r_characterbg_green"
|
|||
|
elseif quality == 3 then
|
|||
|
return "r_characterbg_blue"
|
|||
|
elseif quality == 4 then
|
|||
|
return "r_characterbg_purple"
|
|||
|
elseif quality == 5 then
|
|||
|
return "r_characterbg_yellow"
|
|||
|
elseif quality > 5 then
|
|||
|
return "r_characterbg_yellow"
|
|||
|
end
|
|||
|
end
|
|||
|
--通过Hero稀有度读取背景框(卡库)外框
|
|||
|
function GetHeroCardQuantityWaiImageByquality(quality)
|
|||
|
if quality <= 3 then
|
|||
|
return "r_hero_lankuang"
|
|||
|
elseif quality == 4 then
|
|||
|
return "r_hero_zikuang"
|
|||
|
elseif quality == 5 then
|
|||
|
return "r_hero_huangkuang"
|
|||
|
elseif quality > 5 then
|
|||
|
return "r_hero_huangkuang"
|
|||
|
end
|
|||
|
end
|
|||
|
--通过Hero或异妖稀有度读取资质框
|
|||
|
function GetQuantityImage(quality)
|
|||
|
local sprite
|
|||
|
if quality<11 then
|
|||
|
sprite=Util.LoadSprite(AptitudeQualityFrame[1])
|
|||
|
elseif quality>=11 and quality<13 then
|
|||
|
sprite=Util.LoadSprite(AptitudeQualityFrame[2])
|
|||
|
elseif quality>=13 and quality<15 then
|
|||
|
sprite=Util.LoadSprite(AptitudeQualityFrame[3])
|
|||
|
elseif quality>=15 and quality<17 then
|
|||
|
sprite=Util.LoadSprite(AptitudeQualityFrame[4])
|
|||
|
elseif quality>=17 and quality<19 then
|
|||
|
sprite=Util.LoadSprite(AptitudeQualityFrame[5])
|
|||
|
end
|
|||
|
return sprite
|
|||
|
end
|
|||
|
|
|||
|
--通过装备位置获得装备位置类型字符串
|
|||
|
function GetEquipPosStrByEquipPosNum(_index)
|
|||
|
if _index == 1 then
|
|||
|
return "武器"
|
|||
|
elseif _index == 2 then
|
|||
|
return "全身铠甲"
|
|||
|
elseif _index == 3 then
|
|||
|
return "头饰"
|
|||
|
elseif _index == 4 then
|
|||
|
return "鞋子"
|
|||
|
elseif _index == 5 then
|
|||
|
return "戒指"
|
|||
|
elseif _index == 6 then
|
|||
|
return "腰带"
|
|||
|
end
|
|||
|
end
|
|||
|
|
|||
|
--通过职业获取职业字符串
|
|||
|
function GetJobStrByJobNum(_index)
|
|||
|
if _index == 0 then
|
|||
|
return "通用"
|
|||
|
elseif _index == 1 then
|
|||
|
return "武卫"
|
|||
|
elseif _index == 2 then
|
|||
|
return "天罚"
|
|||
|
elseif _index == 3 then
|
|||
|
return "秘法"
|
|||
|
elseif _index == 4 then
|
|||
|
return "玄策"
|
|||
|
elseif _index == 5 then
|
|||
|
return "生花"
|
|||
|
end
|
|||
|
end
|
|||
|
--通过职业获取职业字符串
|
|||
|
function GetJobSpriteStrByJobNum(_index)
|
|||
|
if _index == 0 then
|
|||
|
return "r_hero_wuwei"
|
|||
|
elseif _index == 1 then
|
|||
|
return "r_hero_wuwei"
|
|||
|
elseif _index == 2 then
|
|||
|
return "r_hero_tianfa"
|
|||
|
elseif _index == 3 then
|
|||
|
return "r_hero_mifa"
|
|||
|
elseif _index == 4 then
|
|||
|
return "r_hero_xuance"
|
|||
|
elseif _index == 5 then
|
|||
|
return "r_hero_shenghua"
|
|||
|
end
|
|||
|
end
|
|||
|
|
|||
|
--角色定位ID 获取角色定位背景图片
|
|||
|
function GetHeroPosBgStr(_i)
|
|||
|
if _i==1 then
|
|||
|
return "r_hero_roudundi"
|
|||
|
elseif _i==2 then
|
|||
|
return "r_hero_shuchudi"
|
|||
|
elseif _i==3 then
|
|||
|
return "r_hero_kongzhidi"
|
|||
|
elseif _i==4 then
|
|||
|
return "r_hero_fuzhudi"
|
|||
|
end
|
|||
|
end
|
|||
|
|
|||
|
--根据角色定位Id 获取角色定位图
|
|||
|
function GetHeroPosStr(_i)
|
|||
|
if _i==1 then
|
|||
|
return "r_hero_roudunbiao"
|
|||
|
elseif _i==2 then
|
|||
|
return "r_hero_shuchubiao"
|
|||
|
elseif _i==3 then
|
|||
|
return "r_hero_konghzibiao"
|
|||
|
elseif _i==4 then
|
|||
|
return "r_hero_fuzhubiao"
|
|||
|
end
|
|||
|
end
|
|||
|
|
|||
|
--获取技能类型 data 当前技能数据
|
|||
|
function GetSkillType(data)
|
|||
|
local SkillIconType={"r_hero_pu","r_hero_jue","r_hero_bei"}
|
|||
|
if data.skillConfig.Type == SkillType.Pu then
|
|||
|
return SkillIconType[SkillType.Pu]--普技
|
|||
|
elseif data.skillConfig.Type == SkillType.Jue then
|
|||
|
return SkillIconType[SkillType.Jue]--绝技
|
|||
|
elseif data.skillConfig.Type == SkillType.Bei then
|
|||
|
return SkillIconType[SkillType.Bei]--被动技
|
|||
|
end
|
|||
|
end
|
|||
|
|
|||
|
--通过角色属性获取角色属性图标
|
|||
|
function GetProStrImageByProNum(_index)
|
|||
|
if _index == 1 then
|
|||
|
return "r_hero_huo 1"
|
|||
|
elseif _index == 2 then
|
|||
|
return "r_hero_feng 1"
|
|||
|
elseif _index == 3 then
|
|||
|
return "r_hero_shui 1"
|
|||
|
elseif _index == 4 then
|
|||
|
return "r_hero_dadi 1"
|
|||
|
elseif _index == 5 then
|
|||
|
return "r_hero_guang 1"
|
|||
|
elseif _index == 6 then
|
|||
|
return "r_hero_an 1"
|
|||
|
else
|
|||
|
return "r_hero_huo 1"
|
|||
|
end
|
|||
|
end
|
|||
|
--通过装备位置获得装备位置类型字符串
|
|||
|
function GetQuaStringByEquipQua(_Qua)
|
|||
|
--
|
|||
|
if _Qua == 1 then
|
|||
|
return "[一般]"
|
|||
|
elseif _Qua == 2 then
|
|||
|
return "[精良]"
|
|||
|
elseif _Qua == 3 then
|
|||
|
return "[优秀]"
|
|||
|
elseif _Qua == 4 then
|
|||
|
return "[史诗]"
|
|||
|
elseif _Qua == 5 then
|
|||
|
return "[传说]"
|
|||
|
elseif _Qua == 6 then
|
|||
|
return "[远古]"
|
|||
|
elseif _Qua == 7 then
|
|||
|
return "[不朽]"
|
|||
|
end
|
|||
|
end
|
|||
|
--通过item稀有度获取改颜色的文字
|
|||
|
function GetStringByEquipQua(_Qua, _Str)
|
|||
|
if _Qua == 1 then
|
|||
|
return string.format("<color=#FCF5D3FF>%s</color>", _Str)
|
|||
|
elseif _Qua == 2 then
|
|||
|
return string.format("<color=#529764FF>%s</color>", _Str)
|
|||
|
elseif _Qua == 3 then
|
|||
|
return string.format("<color=#6398c9FF>%s</color>", _Str)
|
|||
|
elseif _Qua == 4 then
|
|||
|
return string.format("<color=#9358bdFF>%s</color>", _Str)
|
|||
|
elseif _Qua == 5 then
|
|||
|
return string.format("<color=#fcb24eFF>%s</color>", _Str)
|
|||
|
elseif _Qua == 6 then
|
|||
|
return string.format("<color=#C66366FF>%s</color>", _Str)
|
|||
|
elseif _Qua == 7 then
|
|||
|
return string.format("<color=#FFEDA1FF>%s</color>", _Str)
|
|||
|
end
|
|||
|
end
|
|||
|
|
|||
|
--冒险通过区域序号取得区域名称美术字图标
|
|||
|
function GetAreaNameIconByAreaNumer(index)
|
|||
|
if index == 1 then
|
|||
|
return "r_guaji_qiyuanzhidi"
|
|||
|
elseif index == 2 then
|
|||
|
return "r_guaji_yiwangzhilu"
|
|||
|
elseif index == 3 then
|
|||
|
return "r_guaji_houhuizhishi"
|
|||
|
elseif index == 4 then
|
|||
|
return "r_guaji_zuifashengdian"
|
|||
|
elseif index == 5 then
|
|||
|
return "r_guaji_qidaoshengsuo"
|
|||
|
elseif index == 6 then
|
|||
|
return "r_guaji_youjieyehuo"
|
|||
|
elseif index == 7 then
|
|||
|
return "r_guaji_wushengmishi"
|
|||
|
elseif index == 8 then
|
|||
|
return "r_guaji_wanshenghuanghun"
|
|||
|
end
|
|||
|
|
|||
|
end
|
|||
|
|
|||
|
--- N钟,N时,N天
|
|||
|
function GetLeftTimeStrByDeltaTime(deltaTime)
|
|||
|
if deltaTime > 86400 then
|
|||
|
return math.floor(deltaTime / 86400) .. "天"
|
|||
|
end
|
|||
|
if deltaTime > 3600 then
|
|||
|
return math.floor(deltaTime / 3600) .. "时"
|
|||
|
end
|
|||
|
if deltaTime > 60 then
|
|||
|
return math.floor(deltaTime / 60) .. "分"
|
|||
|
end
|
|||
|
return math.floor(deltaTime).."秒"
|
|||
|
end
|
|||
|
--- 获取经历的时间字符串
|
|||
|
--- 刚刚,N分钟前,N小时前,N天前
|
|||
|
function GetDeltaTimeStrByDeltaTime(deltaTime)
|
|||
|
if deltaTime > 86400 then
|
|||
|
return math.floor(deltaTime / 86400) .. "天前"
|
|||
|
end
|
|||
|
if deltaTime > 3600 then
|
|||
|
return math.floor(deltaTime / 3600) .. "小时前"
|
|||
|
end
|
|||
|
if deltaTime > 60 then
|
|||
|
return math.floor(deltaTime / 60) .. "分钟前"
|
|||
|
end
|
|||
|
return "刚刚"
|
|||
|
end
|
|||
|
function GetDeltaTimeStr(timestamp)
|
|||
|
local curTimeStemp = GetTimeStamp()
|
|||
|
local deltaTime = curTimeStemp - timestamp
|
|||
|
return GetDeltaTimeStrByDeltaTime(deltaTime)
|
|||
|
end
|
|||
|
--- 计算公式 a*x^3 + b*x^2 + c*x +d
|
|||
|
--- 1、 CalculateCostCount(x, a, b, c, d)
|
|||
|
--- 2、 CalculateCostCount(x, array)
|
|||
|
--- array 为按顺序存储a, b, c, d值的数组
|
|||
|
---
|
|||
|
function CalculateCostCount(x, ...)
|
|||
|
if not x then
|
|||
|
return
|
|||
|
end
|
|||
|
local args = { ... }
|
|||
|
if type(args[1]) == "table" then
|
|||
|
args = args[1]
|
|||
|
end
|
|||
|
if type(args[1]) ~= "number" then
|
|||
|
return
|
|||
|
end
|
|||
|
|
|||
|
local a = args[1]
|
|||
|
local b = args[2]
|
|||
|
local c = args[3]
|
|||
|
local d = args[4]
|
|||
|
local cost = math.pow(x, 3) * a + math.pow(x, 2) * b + x * c + d
|
|||
|
return cost
|
|||
|
end
|
|||
|
|
|||
|
--- 获取当前时间戳
|
|||
|
function GetTimeStamp()
|
|||
|
return PlayerManager.serverTime
|
|||
|
end
|
|||
|
|
|||
|
--- 获取当前时间到一天中某时的剩余时间(24小时制)
|
|||
|
function CalculateSecondsNowTo_N_OClock(n)
|
|||
|
local curTimeStemp = GetTimeStamp()
|
|||
|
--- 标准时间戳从1970年1月1日8点开始,加上八个小时的秒数,使其从0点开始
|
|||
|
--- 8*60*60 = 28800
|
|||
|
--- 24*60*60 = 86400
|
|||
|
local todayPassSeconds = (curTimeStemp + 28800) % 86400
|
|||
|
local targetSeconds = n * 3600 --- 60*60 = 3600
|
|||
|
if todayPassSeconds <= targetSeconds then
|
|||
|
return targetSeconds - todayPassSeconds
|
|||
|
else
|
|||
|
-- 如果已经过去了,则计算到第二天这个时间点需要的秒数
|
|||
|
return targetSeconds + 86400 - todayPassSeconds
|
|||
|
end
|
|||
|
end
|
|||
|
|
|||
|
--- 将一段时间转换为天时分秒
|
|||
|
function TimeToDHMS(second)
|
|||
|
local day = math.floor(second / (24 * 3600))
|
|||
|
local minute = math.floor(second / 60) % 60
|
|||
|
local sec = second % 60
|
|||
|
local hour = math.floor(math.floor(second - day * 24 * 3600 - sec - minute * 60) / 3600)
|
|||
|
return string.format("%d天%02d时%02d分%02d秒",day, hour, minute, sec)
|
|||
|
end
|
|||
|
--- 将一段时间转换为时分秒
|
|||
|
function TimeToHMS(t)
|
|||
|
if not t or t < 0 then
|
|||
|
return "00:00:00"
|
|||
|
end
|
|||
|
local _sec = t % 60
|
|||
|
local allMin = math.floor(t / 60)
|
|||
|
local _min = allMin % 60
|
|||
|
local _hour = math.floor(allMin / 60)
|
|||
|
return string.format("%02d:%02d:%02d", _hour, _min, _sec), _hour, _min, _sec
|
|||
|
end
|
|||
|
|
|||
|
--- 将一段时间转换为分秒
|
|||
|
function TimeToMS(t)
|
|||
|
if not t or t < 0 then
|
|||
|
return "00:00"
|
|||
|
end
|
|||
|
local _sec = t % 60
|
|||
|
local _min = math.floor(t / 60)
|
|||
|
return string.format("%02d:%02d", _min, _sec)
|
|||
|
end
|
|||
|
|
|||
|
--- 获取今天某时间点时间戳
|
|||
|
function Today_N_OClockTimeStamp(n)
|
|||
|
local currentTime = math.floor(GetTimeStamp())
|
|||
|
local tab = os.date("*t", currentTime)
|
|||
|
tab.hour = n
|
|||
|
tab.min = 0
|
|||
|
tab.sec = 0
|
|||
|
local N_TimeStamp = os.time(tab)
|
|||
|
return N_TimeStamp
|
|||
|
end
|
|||
|
|
|||
|
----- 时效类时间(服务器按照每天凌晨的5点为起始的一天)
|
|||
|
function GetTimePass(timeValue)
|
|||
|
local tab = os.date("*t", timeValue)
|
|||
|
tab.hour = 0
|
|||
|
tab.min = 0
|
|||
|
tab.sec = 0
|
|||
|
|
|||
|
local tab2 = os.date("*t", timeValue)
|
|||
|
tab2.hour = 5
|
|||
|
tab2.min = 0
|
|||
|
tab2.sec = 0
|
|||
|
local timeStartSum = os.time(tab2)
|
|||
|
--0点
|
|||
|
local forwardDay
|
|||
|
local zeroTimeStamp = os.time(tab)
|
|||
|
if timeValue > zeroTimeStamp and timeValue < timeStartSum then
|
|||
|
forwardDay = 1
|
|||
|
else
|
|||
|
forwardDay = 0
|
|||
|
end
|
|||
|
local dayPass = math.ceil((GetTimeStamp() - timeStartSum) / 86400)
|
|||
|
return (dayPass + forwardDay) > 3 and 3 or (dayPass + forwardDay)
|
|||
|
end
|
|||
|
|
|||
|
---时间格式化接口
|
|||
|
function GetTimeShow(data)
|
|||
|
local year = math.floor(os.date("%Y", data))
|
|||
|
local month = math.floor(os.date("%m", data))
|
|||
|
local day = math.floor(os.date("%d", data))
|
|||
|
local time = year .. "." .. month .. "." .. day
|
|||
|
return time
|
|||
|
end
|
|||
|
|
|||
|
|
|||
|
---obj必须是userdata(c#对象)
|
|||
|
function IsNull(obj)
|
|||
|
return obj == nil or obj:Equals(nil)
|
|||
|
end
|
|||
|
|
|||
|
------- 红点相关 ----------
|
|||
|
-- 绑定红点物体
|
|||
|
function BindRedPointObject(rpType, rpObj)
|
|||
|
RedpotManager.BindObject(rpType, rpObj)
|
|||
|
end
|
|||
|
|
|||
|
-- 清除红点上绑定的所有物体
|
|||
|
function ClearRedPointObject(rpType, rpObj)
|
|||
|
RedpotManager.ClearObject(rpType, rpObj)
|
|||
|
end
|
|||
|
|
|||
|
-- 强制改变红点状态(不建议使用)
|
|||
|
function ChangeRedPointStatus(rpType, state)
|
|||
|
RedpotManager.SetRedPointStatus(rpType, state)
|
|||
|
end
|
|||
|
|
|||
|
-- 重置服务器红点状态到隐藏状态
|
|||
|
function ResetServerRedPointStatus(rpType)
|
|||
|
RedpotManager.SetServerRedPointStatus(rpType, RedPointStatus.Hide)
|
|||
|
end
|
|||
|
|
|||
|
-- 检测红点显示
|
|||
|
function CheckRedPointStatus(rpType)
|
|||
|
RedpotManager.CheckRedPointStatus(rpType)
|
|||
|
end
|
|||
|
|
|||
|
-------------------------
|
|||
|
--统用属性展示
|
|||
|
function GetPropertyFormatStr(type, value)
|
|||
|
if type == 1 then
|
|||
|
return value
|
|||
|
else
|
|||
|
if value % 100 == 0 then
|
|||
|
return string.format("%d%%", value / 100)
|
|||
|
else
|
|||
|
return string.format("%.2f%%", value / 100)
|
|||
|
end
|
|||
|
end
|
|||
|
end
|
|||
|
--统用属性展示
|
|||
|
function GetPropertyFormatStrOne(type, value)
|
|||
|
if type == 1 then
|
|||
|
return value
|
|||
|
else
|
|||
|
if value % 100 == 0 then
|
|||
|
return string.format("%d%%", value / 100)
|
|||
|
else
|
|||
|
return string.format("%.1f%%", value / 100)
|
|||
|
end
|
|||
|
end
|
|||
|
end
|
|||
|
--装备专属属性展示
|
|||
|
function GetEquipPropertyFormatStr(type, value)
|
|||
|
if type == 1 then
|
|||
|
return value
|
|||
|
else
|
|||
|
if value / 100 > 1 then
|
|||
|
return string.format("%d%%", value / 100)
|
|||
|
else
|
|||
|
return string.format("%d%%", 1)
|
|||
|
end
|
|||
|
end
|
|||
|
end
|
|||
|
-- 将秒转换成显示使用的时间
|
|||
|
function FormatSecond(second)
|
|||
|
local day = math.floor(second / (24 * 3600))
|
|||
|
local minute = math.floor(second / 60) % 60
|
|||
|
local sec = second % 60
|
|||
|
local hour = math.floor(math.floor(second - day * 24 * 3600 - sec - minute * 60) / 3600)
|
|||
|
|
|||
|
return string.format("%s天 %02d:%02d:%02d", day, hour, minute, sec)
|
|||
|
end
|
|||
|
|
|||
|
-- 将时间戳转换为用于显示的日期字符串
|
|||
|
function TimeStampToDateStr(timestamp)
|
|||
|
local date = os.date("*t", timestamp)
|
|||
|
local cdate = os.date("*t", GetTimeStamp())
|
|||
|
if date.year == cdate.year and date.month == cdate.month and date.day == cdate.day then
|
|||
|
return string.format("%02d:%02d", date.hour, date.min)
|
|||
|
end
|
|||
|
return string.format("%d年%d月%d日 %02d:%02d", date.year, date.month, date.day, date.hour, date.min)
|
|||
|
end
|
|||
|
-- 将时间戳转换为用于显示的日期字符串(时分秒)
|
|||
|
function TimeStampToDateStr3(second)
|
|||
|
local minute = math.floor(second / 60) % 60
|
|||
|
local sec = second % 60
|
|||
|
local hour = math.floor(math.floor(second - sec - minute * 60) / 3600)
|
|||
|
|
|||
|
return string.format("%02d:%02d:%02d", hour, minute, sec)
|
|||
|
end
|
|||
|
|
|||
|
--- 根据id获取资源
|
|||
|
function GetResourcePath(id)
|
|||
|
return ConfigManager.GetConfigData(ConfigName.ArtResourcesConfig, id).Name
|
|||
|
end
|
|||
|
|
|||
|
--- 获取玩家头像资源
|
|||
|
function GetPlayerHeadSprite(headId)
|
|||
|
if headId == 0 then headId = 71000 end
|
|||
|
local head = ConfigManager.GetConfigData(ConfigName.ItemConfig, headId)
|
|||
|
return Util.LoadSprite(GetResourcePath(head.ResourceID))
|
|||
|
end
|
|||
|
|
|||
|
--- 获取玩家头像框资源
|
|||
|
function GetPlayerHeadFrameSprite(frameId)
|
|||
|
if frameId == 0 then frameId = 80000 end
|
|||
|
local frame = ConfigManager.GetConfigData(ConfigName.ItemConfig, frameId)
|
|||
|
return Util.LoadSprite(GetResourcePath(frame.ResourceID))
|
|||
|
end
|
|||
|
|
|||
|
--是否弹出快捷购买面板
|
|||
|
function PopQuickPurchasePanel(type, needNum)
|
|||
|
local ownNumber = BagManager.GetItemCountById(type)
|
|||
|
if ownNumber >= needNum then
|
|||
|
return false
|
|||
|
else
|
|||
|
UIManager.OpenPanel(UIName.QuickPurchasePanel, { type = type })
|
|||
|
return true
|
|||
|
end
|
|||
|
end
|
|||
|
|
|||
|
----- SDK数据上报
|
|||
|
----- @param context
|
|||
|
---- {
|
|||
|
---- type, -- required, 调用时机
|
|||
|
---- }
|
|||
|
function SubmitExtraData(context)
|
|||
|
if not AppConst.isSDK then
|
|||
|
return
|
|||
|
end
|
|||
|
local params = KTSDK.KTSDKSubmitExtraDataArgs.New()
|
|||
|
params.dataType = context.type
|
|||
|
params.serverID = tonumber(PlayerManager.serverInfo.server_id)
|
|||
|
params.serverName = PlayerManager.serverInfo.name
|
|||
|
params.zoneID = PlayerManager.serverInfo.server_id
|
|||
|
params.zoneName = PlayerManager.serverInfo.name
|
|||
|
params.roleID = tostring(PlayerManager.uid)
|
|||
|
params.roleName = PlayerManager.nickName
|
|||
|
params.roleLevel = tostring(PlayerManager.level)
|
|||
|
params.guildID = PlayerManager.familyId
|
|||
|
params.Vip = tostring(VipManager.GetVipLevel())
|
|||
|
params.moneyNum = BagManager.GetItemCountById(16)
|
|||
|
params.roleCreateTime = DateUtils.GetDateTime(PlayerManager.userCreateTime)
|
|||
|
params.roleLevelUpTime = context.roleLevelUpTime and DateUtils.GetDateTime(context.roleLevelUpTime) or ""
|
|||
|
KTSDK.Helper.Instance:SubmitExtraData(params)
|
|||
|
end
|
|||
|
|
|||
|
-- context = {
|
|||
|
-- title = "",
|
|||
|
-- content = "",
|
|||
|
-- confirmCallback = function() end,
|
|||
|
-- cancelCallback = function() end,
|
|||
|
-- confirmText = "确认",
|
|||
|
-- cancelText = "取消",
|
|||
|
-- type, -- 单双按钮
|
|||
|
-- extra --额外操作
|
|||
|
-- }
|
|||
|
function ShowConfirmPanel(context)
|
|||
|
UIManager.OpenPanel(UIName.CommonConfirmPanel, context)
|
|||
|
end
|
|||
|
|
|||
|
-- 检测某一面板关闭再抛相应的事件
|
|||
|
function CallBackOnPanelClose(uiPanel, func)
|
|||
|
if UIManager.IsOpen(uiPanel) then
|
|||
|
local triggerCallBack
|
|||
|
triggerCallBack = function (panelType, panel)
|
|||
|
if panelType == uiPanel then
|
|||
|
if func then func() end
|
|||
|
Game.GlobalEvent:RemoveEvent(GameEvent.UI.OnClose, triggerCallBack)
|
|||
|
end
|
|||
|
end
|
|||
|
Game.GlobalEvent:AddEvent(GameEvent.UI.OnClose, triggerCallBack)
|
|||
|
else
|
|||
|
if func then func() end
|
|||
|
end
|
|||
|
end
|
|||
|
|
|||
|
-- 检测某一面板打开再抛相应的事件
|
|||
|
function CallBackOnPanelOpen(uiPanel, func)
|
|||
|
if not UIManager.IsOpen(uiPanel) then
|
|||
|
local triggerCallBack
|
|||
|
triggerCallBack = function (panelType, panel)
|
|||
|
if panelType == uiPanel then
|
|||
|
if func then func() end
|
|||
|
Game.GlobalEvent:RemoveEvent(GameEvent.UI.OnOpen, triggerCallBack)
|
|||
|
end
|
|||
|
end
|
|||
|
Game.GlobalEvent:AddEvent(GameEvent.UI.OnOpen, triggerCallBack)
|
|||
|
else
|
|||
|
if func then func() end
|
|||
|
end
|
|||
|
end
|
|||
|
|
|||
|
-- 通过地图坐标设置物体在UI平面的位置
|
|||
|
function SetObjPosByUV(pos)
|
|||
|
local u, v = Map_Pos2UV(pos)
|
|||
|
local v2 = RectTransformUtility.WorldToScreenPoint(TileMapView.GetCamera(), TileMapView.GetLiveTilePos(u, v))
|
|||
|
v2 = v2 / math.min(Screen.width/1080, Screen.height/1920)
|
|||
|
v2.x = v2.x - (Screen.width - UIManager.width) / 2
|
|||
|
v2.y = v2.y - (Screen.height - UIManager.height) / 2
|
|||
|
return v2
|
|||
|
|
|||
|
end
|
|||
|
|
|||
|
--获取技能描述
|
|||
|
function GetSkillConfigDesc(cfg)
|
|||
|
if cfg.DescColor then
|
|||
|
local ss = {}
|
|||
|
for i=1, #cfg.DescColor do
|
|||
|
local str
|
|||
|
if cfg.DescColor[i] == 1 then
|
|||
|
str=string.format("<color=#4c805eFF>%s</color>", cfg.DescValue[i])
|
|||
|
elseif cfg.DescColor[i] == 2 then
|
|||
|
str=string.format("<color=#b4595eFF>%s</color>", cfg.DescValue[i])
|
|||
|
else
|
|||
|
str=cfg.DescValue[i]
|
|||
|
end
|
|||
|
ss[i] = str
|
|||
|
end
|
|||
|
return string.format(cfg.Desc, unpack(ss))
|
|||
|
end
|
|||
|
return cfg.Desc
|
|||
|
end
|
|||
|
|
|||
|
-- 设置排名所需要的数字框
|
|||
|
function SetRankNumFrame(rankNum)
|
|||
|
local rankNumRes = {
|
|||
|
[1] = "r_Dungeon_001",
|
|||
|
[2] = "r_Dungeon_002",
|
|||
|
[3] = "r_Dungeon_003",
|
|||
|
[4] = "r_hero_zhuangbeidi",
|
|||
|
}
|
|||
|
|
|||
|
local resPath = rankNum > 3 and rankNumRes[4] or rankNumRes[rankNum]
|
|||
|
local icon = Util.LoadSprite(resPath)
|
|||
|
return icon
|
|||
|
end
|
|||
|
|
|||
|
--- 本方法适用滚动条中 生成item的使用 (主要适用每条滚动条item数量不定的滚动条中)
|
|||
|
--- itemview重设复用 1根节点 2生成到父节点 3item容器 4容器上限 5缩放 6层级 7根据数据类型生成 8不定参数据...
|
|||
|
function ResetItemView(root,rewardRoot,itemList,max,scale,sortingOrder,type,...)
|
|||
|
local args={...}
|
|||
|
local data1=args[1]
|
|||
|
local data2=args[2]
|
|||
|
|
|||
|
if itemList[root] then -- 存在
|
|||
|
for i = 1, max do
|
|||
|
itemList[root][i].gameObject:SetActive(false)
|
|||
|
end
|
|||
|
if type then
|
|||
|
itemList[root][1]:OnOpen(false, {data1,data2},scale,false,false,false,sortingOrder)
|
|||
|
itemList[root][1].gameObject:SetActive(true)
|
|||
|
else
|
|||
|
for i = 1, #data1 do
|
|||
|
if itemList[root][i] then
|
|||
|
itemList[root][i]:OnOpen(false, {data1[i][1],data1[i][2]},scale,false,false,false,sortingOrder)
|
|||
|
itemList[root][i]:Reset({data1[i][1],data1[i][2]},ItemType.Hero,{false,true,true,true})
|
|||
|
itemList[root][i].gameObject:SetActive(true)
|
|||
|
end
|
|||
|
end
|
|||
|
end
|
|||
|
else -- 不存在 新建
|
|||
|
itemList[root]={}
|
|||
|
for i = 1, max do
|
|||
|
itemList[root][i] = SubUIManager.Open(SubUIConfig.ItemView, rewardRoot)
|
|||
|
itemList[root][i].gameObject:SetActive(false)
|
|||
|
end
|
|||
|
if type then
|
|||
|
itemList[root][1]:OnOpen(false, {data1,data2},scale,false,false,false,sortingOrder)
|
|||
|
itemList[root][1].gameObject:SetActive(true)
|
|||
|
else
|
|||
|
for i = 1, #data1 do
|
|||
|
itemList[root][i]:OnOpen(false, {data1[i][1],data1[i][2]},scale,false,false,false,sortingOrder)
|
|||
|
itemList[root][i]:Reset({data1[i][1],data1[i][2]},ItemType.Hero,{false,true,true,true})
|
|||
|
itemList[root][i].gameObject:SetActive(true)
|
|||
|
end
|
|||
|
end
|
|||
|
end
|
|||
|
end
|