Add credits menu

This commit is contained in:
fed 2023-02-25 04:10:05 +01:00
parent f4830d3cab
commit fa023f15fa
5 changed files with 261 additions and 12 deletions

View File

@ -2,7 +2,114 @@ local spacing = 10
local topoffset = 15
local extrawidth = 50
local extraheight = 40
local extraheight1 = 0
local function makelink(element, link)
element:setHandleMouseMove(true)
element:setHandleMouseButton(true)
element:registerAnimationState("focused", {
color = {
r = 1,
g = 1,
b = 1
}
})
local entered = false
element:registerEventHandler("mouseenter", function()
if (not entered) then
Engine.PlaySound(CoD.SFX.MouseOver)
entered = true
end
element:animateToState("focused")
end)
element:registerEventHandler("mouseleave", function()
entered = false
element:animateToState("default")
end)
element:registerEventHandler("leftmousedown", function()
Engine.PlaySound(CoD.SFX.MouseClick)
game:openlink(link)
end)
end
local addlinkinfo = function(menu, key, value, link)
local text = Engine.Localize(value)
local element = menu:AddInfo(Engine.Localize(key), function()
return text
end)
local linkelement = element:getFirstChild():getNextSibling()
makelink(linkelement, link)
end
local function getnumcredits()
local csv = "credits.csv"
local rowcount = Engine.TableGetRowCount(csv)
return rowcount
end
local extraheight2 = getnumcredits() * 25 / 2
local function addcredits(menu)
local cols = {
name = 0,
link = 1
}
local csv = "credits.csv"
local rowcount = Engine.TableGetRowCount(csv)
local num = 0
local creditselement = LUI.UIElement.new({
topAnchor = true,
leftAnchor = true,
left = 500,
width = 30,
top = 255
})
menu:addElement(creditselement)
menu:AddInfo(Engine.Localize("MENU_CREDITS"), function()
return ""
end)
local num = 0
local addcredit = function(name, link)
local row = num % 4
local col = num >= 4 and 0 or 1
local text = Engine.Localize(name)
local element = LUI.UIText.new({
rightAnchor = true,
topAnchor = true,
right = -10 + (col * -100),
top = 25 * row,
width = 90,
height = LUI.MenuGenericButtons.ButtonLabelFont.Height * 0.8,
font = LUI.MenuGenericButtons.ButtonLabelFont.Font,
color = Colors.h1.light_grey,
alignment = Engine.IsRightToLeftLanguage() and LUI.Alignment.None or LUI.Alignment.Right
})
element.id = "credits_" .. num
element:setText(text)
creditselement:addElement(element)
makelink(element, link)
num = num + 1
end
for i = 0, rowcount - 1 do
local name = Engine.TableLookupByRow(csv, i, cols.name)
local link = Engine.TableLookupByRow(csv, i, cols.link)
addcredit(name, link)
end
end
LUI.MenuBuilder.m_types_build["SystemInfo"] = function (f6_arg0, f6_arg1)
local f6_local0 = LUI.MenuTemplate.spMenuOffset
@ -30,7 +137,7 @@ LUI.MenuBuilder.m_types_build["SystemInfo"] = function (f6_arg0, f6_arg1)
f6_local7 = f6_local5
end
f6_local7 = f6_local7 + f6_local6 - extraheight
f6_local7 = f6_local7 + f6_local6 - extraheight1
local f6_local9 = luiglobals.GenericMenuDims.OptionMenuWidth + 100
local f6_local10 = menu.properties
@ -75,13 +182,7 @@ LUI.MenuBuilder.m_types_build["SystemInfo"] = function (f6_arg0, f6_arg1)
return Engine.GetBuildNumber()
end)
menu:AddInfo(Engine.Localize("MENU_SYSINFO_CUSTOMER_SUPPORT_LINK"), function()
return Engine.Localize("MENU_SYSINFO_CUSTOMER_SUPPORT_URL")
end)
menu:AddInfo(Engine.Localize("MENU_SYSINFO_DONATION_LINK"), function()
return Engine.Localize("MENU_SYSINFO_DONATION_URL")
end)
addlinkinfo(menu, "MENU_SYSINFO_CUSTOMER_SUPPORT_LINK", "MENU_SYSINFO_CUSTOMER_SUPPORT_URL", "github")
luiglobals.GenericMenuDims.OptionMenuWidth = optionmenuwidth
@ -90,3 +191,108 @@ LUI.MenuBuilder.m_types_build["SystemInfo"] = function (f6_arg0, f6_arg1)
return menu
end
local startmap = Engine.StreamingInstallMap
Engine.StreamingInstallMap = function(map, args, ...)
if (args == "set ui_play_credits 1; devmap ending;") then
LUI.FlowManager.RequestAddMenu(nil, "credits_menu")
else
startmap(map, args, ...)
end
end
local creditsmap = function()
LUI.FlowManager.PushMenuStackToDVar()
if LUI.LevelSelect.IsAllLevelCompleted() then
Engine.SetDvarString("ui_char_museum_mode", "credits_2", true)
else
Engine.SetDvarString("ui_char_museum_mode", "credits_black", true)
end
startmap("ending", "set ui_play_credits 1; devmap ending;")
end
LUI.MenuBuilder.registerType("credits_menu", function(f6_arg0, f6_arg1)
local f6_local0 = LUI.MenuTemplate.spMenuOffset
local title = "MENU_SP_CREDITS_CAPS"
local f6_local2 = false
local f6_local3 = 0
local menu = LUI.MenuTemplate.new(f6_arg0, {
menu_title = title,
menu_top_indent = f6_local0 + f6_local3,
showSelectButton = false,
skipAnim = f6_local2
})
menu:AddButton("MENU_SP_CREDITS_CAPS", creditsmap, nil, true, nil, {
desc_text = Engine.Localize("@LUA_MENU_CREDITS_DESC")
})
menu:setClass(LUI.SystemInfo)
menu:PopulateMissingProps(f6_arg1)
menu:ValidateProps(f6_arg1)
menu.id = "systemInfo_id"
local f6_local5 = 300
local f6_local6 = LUI.MenuTemplate.ListTop + f6_local0
local f6_local7 = f6_arg1.menu_height
if not f6_local7 then
f6_local7 = f6_local5
end
f6_local7 = f6_local7 + f6_local6 - extraheight2
local f6_local9 = luiglobals.GenericMenuDims.OptionMenuWidth + 100
local f6_local10 = menu.properties
local topoffset2 = LUI.MenuTemplate.ListTop + LUI.MenuTemplate.spMenuOffset + 50
local decobox = LUI.MenuBuilder.BuildRegisteredType("h1_box_deco", {
decoTopOffset = topoffset2 - topoffset + 15,
decoBottomOffset = -f6_local7,
decoRightOffset = -665 + extrawidth
})
menu:addElement(decobox)
local decoleft = CoD.CreateState(0, 0.5, 8, 0.5, CoD.AnchorTypes.TopLeft)
decoleft.color = luiglobals.Colors.h1.light_grey
decobox:addElement(LUI.UILine.new(decoleft))
local decoright = CoD.CreateState(0, 0.5, -8, 0.5, CoD.AnchorTypes.TopRight)
decoright.color = luiglobals.Colors.h1.light_grey
decobox:addElement(LUI.UILine.new(decoright))
local element = LUI.UIVerticalList.new({
leftAnchor = true,
rightAnchor = true,
topAnchor = true,
bottomAnchor = true,
left = spacing,
right = 100,
top = topoffset2 + 15,
bottom = 0,
spacing = spacing * 0.8
})
element.id = "systemInfoList_id"
menu.vlist = element
menu:addElement(element)
local optionmenuwidth = luiglobals.GenericMenuDims.OptionMenuWidth
luiglobals.GenericMenuDims.OptionMenuWidth = optionmenuwidth + extrawidth
addlinkinfo(menu, "MENU_SYSINFO_CUSTOMER_SUPPORT_LINK", "MENU_SYSINFO_CUSTOMER_SUPPORT_URL", "github")
addlinkinfo(menu, "MENU_SYSINFO_DONATION_LINK", "MENU_SYSINFO_DONATION_URL", "donate")
addcredits(menu)
luiglobals.GenericMenuDims.OptionMenuWidth = optionmenuwidth
menu:AddBackButton()
menu:registerEventHandler("menu_close", LUI.SystemInfo.LeaveMenu)
return menu
end)

View File

@ -1 +1,2 @@
localize,english
stringtable,credits.csv

1 localize english
2 stringtable credits.csv

View File

@ -0,0 +1,8 @@
MENU_CREDITS_1,credits_1,
MENU_CREDITS_2,credits_2,
MENU_CREDITS_3,credits_3,
MENU_CREDITS_4,credits_4,
MENU_CREDITS_5,credits_5,
MENU_CREDITS_6,credits_6,
MENU_CREDITS_7,credits_7,
MENU_CREDITS_8,credits_8,
1 MENU_CREDITS_1 credits_1
2 MENU_CREDITS_2 credits_2
3 MENU_CREDITS_3 credits_3
4 MENU_CREDITS_4 credits_4
5 MENU_CREDITS_5 credits_5
6 MENU_CREDITS_6 credits_6
7 MENU_CREDITS_7 credits_7
8 MENU_CREDITS_8 credits_8

View File

@ -86,5 +86,14 @@
"MENU_SPANISHNA": "Español (América Latina)",
"MENU_KOREAN": "한국어",
"MENU_ENGLISH_SAFE": "English (Safe)",
"MENU_RUSSIAN_PARTIAL": "Русский (Англ. озвучка)"
"MENU_RUSSIAN_PARTIAL": "Русский (Англ. озвучка)",
"MENU_CREDITS_1": "momo5502",
"MENU_CREDITS_2": "Vlad",
"MENU_CREDITS_3": "Future",
"MENU_CREDITS_4": "JariKCoding",
"MENU_CREDITS_5": "netadr",
"MENU_CREDITS_6": "quaK",
"MENU_CREDITS_7": "xensik",
"MENU_CREDITS_8": "ZoneTool"
}

View File

@ -336,6 +336,31 @@ namespace ui_scripting
return fastfiles::exists(name);
};
game_type["openlink"] = [](const game&, const std::string& name)
{
static std::unordered_map<std::string, std::string> links =
{
{"github", "https://github.com/fedddddd/h2-mod"},
{"donate", "https://www.paypal.com/donate/?hosted_button_id=LM5BA9UABEV4Q"},
{"credits_1", "https://github.com/momo5502"},
{"credits_2", "https://github.com/VladWinner"},
{"credits_3", "https://github.com/diamante0018"},
{"credits_4", "https://github.com/JariKCoding"},
{"credits_5", "https://github.com/netadr"},
{"credits_6", "https://github.com/Joelrau"},
{"credits_7", "https://github.com/xensik"},
{"credits_8", "https://github.com/ZoneTool/zonetool"},
};
const auto link = links.find(name);
if (link == links.end())
{
return;
}
ShellExecuteA(nullptr, "open", link->second.data(), nullptr, nullptr, SW_SHOWNORMAL);
};
lua["Engine"]["SetLanguage"] = [](const int index)
{
language::set_from_index(index);