Add cg_drawfps + fixes

This commit is contained in:
Federico Cecchetto
2022-05-20 21:11:58 +02:00
parent 6aa313b79b
commit c88f624fe7
7 changed files with 193 additions and 185 deletions

View File

@ -93,6 +93,7 @@ function infoelement(data)
local value = LUI.UIText.new({
left = left + 5,
top = textoffsety,
font = labelfont.Font,
height = textheight,
leftAnchor = true,
topAnchor = true,
@ -156,3 +157,4 @@ LUI.onmenuopen("mp_hud", function(hud)
hud.static:addElement(infobar)
end)

View File

@ -1,5 +1,5 @@
if (game:issingleplayer() or not Engine.InFrontend()) then
return
return
end
game:addlocalizedstring("LUA_MENU_STATS", "Stats")
@ -7,11 +7,15 @@ game:addlocalizedstring("LUA_MENU_STATS_DESC", "Edit player stats settings.")
game:addlocalizedstring("LUA_MENU_UNLOCKALL_ITEMS", "Unlock all items")
game:addlocalizedstring("LUA_MENU_UNLOCKALL_ITEMS_DESC",
"Whether items should be locked based on the player's stats or always unlocked.")
"Whether items should be locked based on the player's stats or always unlocked.")
game:addlocalizedstring("LUA_MENU_UNLOCKALL_LOOT", "Unlock all loot")
game:addlocalizedstring("LUA_MENU_UNLOCKALL_LOOT_DESC",
"Whether loot should be locked based on the player's stats or always unlocked.")
game:addlocalizedstring("LUA_MENU_UNLOCKALL_CLASSES", "Unlock all classes")
game:addlocalizedstring("LUA_MENU_UNLOCKALL_CLASSES_DESC",
"Whether classes should be locked based on the player's stats or always unlocked.")
"Whether classes should be locked based on the player's stats or always unlocked.")
game:addlocalizedstring("LUA_MENU_PRESTIGE", "Prestige")
game:addlocalizedstring("LUA_MENU_PRESTIGE_DESC", "Edit prestige level.")
@ -25,166 +29,152 @@ game:addlocalizedstring("LUA_MENU_SETTINGS", "Settings")
game:addlocalizedstring("LUA_MENU_EDIT_STATS", "Edit Stats")
function createdivider(menu, text)
local element = LUI.UIElement.new({
leftAnchor = true,
rightAnchor = true,
left = 0,
right = 0,
topAnchor = true,
bottomAnchor = false,
top = 0,
bottom = 33.33
})
local element = LUI.UIElement.new({
leftAnchor = true,
rightAnchor = true,
left = 0,
right = 0,
topAnchor = true,
bottomAnchor = false,
top = 0,
bottom = 33.33
})
element.scrollingToNext = true
element:addElement(LUI.MenuBuilder.BuildRegisteredType("h1_option_menu_titlebar", {
title_bar_text = Engine.ToUpperCase(Engine.Localize(text))
}))
element.scrollingToNext = true
element:addElement(LUI.MenuBuilder.BuildRegisteredType("h1_option_menu_titlebar", {
title_bar_text = Engine.ToUpperCase(Engine.Localize(text))
}))
menu.list:addElement(element)
menu.list:addElement(element)
end
local personalizationbutton = LUI.MPLobbyBase.AddPersonalizationButton
LUI.MPLobbyBase.AddPersonalizationButton = function(menu)
personalizationbutton(menu)
menu:AddButton("@LUA_MENU_STATS", function()
LUI.FlowManager.RequestAddMenu(nil, "stats_menu")
end)
personalizationbutton(menu)
menu:AddButton("@LUA_MENU_STATS", function()
LUI.FlowManager.RequestAddMenu(nil, "stats_menu")
end)
end
LUI.MenuBuilder.registerType("stats_menu", function(a1)
local menu = LUI.MenuTemplate.new(a1, {
menu_title = Engine.ToUpperCase(Engine.Localize("@LUA_MENU_STATS")),
menu_width = luiglobals.GenericMenuDims.OptionMenuWidth
})
local menu = LUI.MenuTemplate.new(a1, {
menu_title = Engine.ToUpperCase(Engine.Localize("@LUA_MENU_STATS")),
menu_width = luiglobals.GenericMenuDims.OptionMenuWidth
})
createdivider(menu, "@LUA_MENU_SETTINGS")
createdivider(menu, "@LUA_MENU_SETTINGS")
LUI.Options.CreateOptionButton(menu, "cg_unlockall_items", "@LUA_MENU_UNLOCKALL_ITEMS",
"@LUA_MENU_UNLOCKALL_ITEMS_DESC", {{
text = "@LUA_MENU_ENABLED",
value = true
}, {
text = "@LUA_MENU_DISABLED",
value = false
}}, nil, nil)
LUI.Options.CreateOptionButton(menu, "cg_unlockall_items", "@LUA_MENU_UNLOCKALL_ITEMS",
"@LUA_MENU_UNLOCKALL_ITEMS_DESC", {{
text = "@LUA_MENU_ENABLED",
value = true
}, {
text = "@LUA_MENU_DISABLED",
value = false
}}, nil, nil)
LUI.Options.CreateOptionButton(menu, "cg_unlockall_classes", "@LUA_MENU_UNLOCKALL_CLASSES",
"@LUA_MENU_UNLOCKALL_CLASSES_DESC", {{
text = "@LUA_MENU_ENABLED",
value = true
}, {
text = "@LUA_MENU_DISABLED",
value = false
}}, nil, nil)
LUI.Options.CreateOptionButton(menu, "cg_unlockall_loot", "@LUA_MENU_UNLOCKALL_LOOT",
"@LUA_MENU_UNLOCKALL_LOOT_DESC", {{
text = "@LUA_MENU_ENABLED",
value = true
}, {
text = "@LUA_MENU_DISABLED",
value = false
}}, nil, nil)
createdivider(menu, "@LUA_MENU_EDIT_STATS")
LUI.Options.CreateOptionButton(menu, "cg_unlockall_classes", "@LUA_MENU_UNLOCKALL_CLASSES",
"@LUA_MENU_UNLOCKALL_CLASSES_DESC", {{
text = "@LUA_MENU_ENABLED",
value = true
}, {
text = "@LUA_MENU_DISABLED",
value = false
}}, nil, nil)
local prestige = Engine.GetPlayerData(0, CoD.StatsGroup.Ranked, "prestige") or 0
local experience = Engine.GetPlayerData(0, CoD.StatsGroup.Ranked, "experience") or 0
local rank = luiglobals.Lobby.GetRankForXP(experience, prestige)
createdivider(menu, "@LUA_MENU_EDIT_STATS")
local saved = true
local prestigevalue = prestige
local rankvalue = rank
local rankbutton = nil
local prestige = Engine.GetPlayerData(0, CoD.StatsGroup.Ranked, "prestige") or 0
local experience = Engine.GetPlayerData(0, CoD.StatsGroup.Ranked, "experience") or 0
local rank = Lobby.GetRankForXP(experience, prestige)
prestigeeditbutton(menu, function(value)
prestigevalue = value
saved = false
end)
prestigeeditbutton(menu, function(value)
Engine.SetPlayerData(0, CoD.StatsGroup.Ranked, "prestige", tonumber(value))
end)
rankbutton = rankeditbutton(menu, function(value)
rankvalue = value
saved = false
end)
rankeditbutton(menu, function(value)
local rank = tonumber(value)
local prestige = Engine.GetPlayerData(0, CoD.StatsGroup.Ranked, "prestige") or 0
local experience = rank == 0 and 0 or Rank.GetRankMaxXP(tonumber(value) - 1, prestige)
local savebutton = menu:AddButton("@LUA_MENU_SAVE", function()
Engine.SetPlayerData(0, CoD.StatsGroup.Ranked, "prestige", tonumber(prestigevalue))
Engine.SetPlayerData(0, CoD.StatsGroup.Ranked, "experience", experience)
end)
local rank = tonumber(rankvalue)
local prestige = Engine.GetPlayerData(0, CoD.StatsGroup.Ranked, "prestige") or 0
local experience = rank == 0 and 0 or luiglobals.Rank.GetRankMaxXP(tonumber(rankvalue) - 1, prestige)
LUI.Options.InitScrollingList(menu.list, nil)
LUI.Options.AddOptionTextInfo(menu)
Engine.SetPlayerData(0, CoD.StatsGroup.Ranked, "experience", experience)
menu:AddBackButton()
saved = true
end, nil, nil, nil, {
desc_text = Engine.Localize("LUA_MENU_SAVE_DESC")
})
LUI.Options.InitScrollingList(menu.list, nil)
LUI.Options.AddOptionTextInfo(menu)
menu:AddBackButton(function()
if (saved) then
LUI.FlowManager.RequestLeaveMenu(menu)
return
end
LUI.yesnopopup({
title = Engine.Localize("@MENU_NOTICE"),
text = Engine.Localize("@LUA_MENU_UNSAVED_CHANGES"),
callback = function(result)
if (result) then
LUI.FlowManager.RequestLeaveMenu(menu)
end
end
})
end)
return menu
return menu
end)
function prestigeeditbutton(menu, callback)
local options = {}
local max = luiglobals.Lobby.GetMaxPrestigeLevel()
local prestige = Engine.GetPlayerData(0, CoD.StatsGroup.Ranked, "prestige") or 0
local options = {}
local max = Lobby.GetMaxPrestigeLevel()
local prestige = Engine.GetPlayerData(0, CoD.StatsGroup.Ranked, "prestige") or 0
for i = 0, max do
game:addlocalizedstring("LUA_MENU_" .. i, i .. "")
for i = 0, max do
game:addlocalizedstring("LUA_MENU_" .. i, i .. "")
table.insert(options, {
text = "@" .. i,
value = i .. ""
})
end
table.insert(options, {
text = "@" .. i,
value = i .. ""
})
end
Engine.SetDvarFromString("ui_prestige_level", prestige .. "")
Engine.SetDvarFromString("ui_prestige_level", prestige .. "")
LUI.Options.CreateOptionButton(menu, "ui_prestige_level", "@LUA_MENU_PRESTIGE", "@LUA_MENU_PRESTIGE_DESC", options,
nil, nil, callback)
LUI.Options.CreateOptionButton(menu, "ui_prestige_level", "@LUA_MENU_PRESTIGE", "@LUA_MENU_PRESTIGE_DESC", options,
nil, nil, callback)
end
function rankeditbutton(menu, callback)
local options = {}
local prestige = Engine.GetPlayerData(0, CoD.StatsGroup.Ranked, "prestige") or 0
local experience = Engine.GetPlayerData(0, CoD.StatsGroup.Ranked, "experience") or 0
local options = {}
local prestige = Engine.GetPlayerData(0, CoD.StatsGroup.Ranked, "prestige") or 0
local experience = Engine.GetPlayerData(0, CoD.StatsGroup.Ranked, "experience") or 0
local rank = luiglobals.Lobby.GetRankForXP(experience, prestige)
local max = luiglobals.Rank.GetMaxRank(prestige)
local maxprestige = luiglobals.Lobby.GetMaxPrestigeLevel()
local rank = Lobby.GetRankForXP(experience, prestige)
local max = Rank.GetMaxRank(prestige)
local maxprestige = Lobby.GetMaxPrestigeLevel()
for i = 0, max do
game:addlocalizedstring("LUA_MENU_" .. i, i .. "")
for i = 0, max do
game:addlocalizedstring("LUA_MENU_" .. i, i .. "")
table.insert(options, {
text = "@" .. (i + 1),
value = i .. ""
})
end
table.insert(options, {
text = "@" .. (i + 1),
value = i .. ""
})
end
Engine.SetDvarFromString("ui_rank_level_", rank .. "")
Engine.SetDvarFromString("ui_rank_level_", rank .. "")
return LUI.Options.CreateOptionButton(menu, "ui_rank_level_", "@LUA_MENU_RANK", "@LUA_MENU_RANK_DESC", options, nil,
nil, callback)
return LUI.Options.CreateOptionButton(menu, "ui_rank_level_", "@LUA_MENU_RANK", "@LUA_MENU_RANK_DESC", options, nil,
nil, callback)
end
local isclasslocked = luiglobals.Cac.IsCustomClassLocked
luiglobals.Cac.IsCustomClassLocked = function(...)
if (Engine.GetDvarBool("cg_unlockall_classes")) then
return false
end
local isclasslocked = Cac.IsCustomClassLocked
Cac.IsCustomClassLocked = function(...)
if (Engine.GetDvarBool("cg_unlockall_classes")) then
return false
end
return isclasslocked(table.unpack({...}))
return isclasslocked(...)
end
local getlockstate = Engine.GetItemLockState
Engine.GetItemLockState = function(...)
local status, state, msg = getlockstate(...)
if (state == Cac.ItemLockStatus.NotInInventory and Engine.GetDvarBool("cg_unlockall_loot")) then
return "Unlocked", 0, ""
end
return status, state, msg
end