Allow longer hostnames

This commit is contained in:
Federico Cecchetto 2022-03-09 22:27:12 +01:00
parent 0d2fe44aff
commit ce9ff664a1
3 changed files with 119 additions and 121 deletions

View File

@ -24,6 +24,19 @@ local columns = {
"@MENU_PING", "@MENU_PING",
} }
function textlength(text, font, height)
local _, _, width = luiglobals.GetTextDimensions(text, font, height)
return width
end
function trimtext(text, font, height, maxwidth)
while (textlength(text, font, height) > maxwidth) do
text = text:sub(1, #text - 1)
end
return text
end
SystemLinkJoinMenu.AddHeaderButton = function(menu, f12_arg1, width) SystemLinkJoinMenu.AddHeaderButton = function(menu, f12_arg1, width)
local state = CoD.CreateState(0, f12_arg1, nil, nil, CoD.AnchorTypes.TopLeft) local state = CoD.CreateState(0, f12_arg1, nil, nil, CoD.AnchorTypes.TopLeft)
state.width = width state.width = width
@ -53,7 +66,8 @@ SystemLinkJoinMenu.AddServerButton = function(menu, controller, index)
button:addEventHandler("button_action", SystemLinkJoinMenu.OnJoinGame) button:addEventHandler("button_action", SystemLinkJoinMenu.OnJoinGame)
local gettext = function(i) local gettext = function(i)
return Lobby.GetServerData(controller, index, i - 1) local text = Lobby.GetServerData(controller, index, i - 1)
return trimtext(text, CoD.TextSettings.TitleFontSmall.Font, 14, 400)
end end
for i = 1, #offsets do for i = 1, #offsets do

View File

@ -258,20 +258,6 @@ namespace server_list
return true; return true;
} }
void resize_host_name(std::string& name)
{
name = utils::string::split(name, '\n').front();
game::Font_s* font = game::R_RegisterFont("fonts/default.otf", 18);
auto text_size = game::UI_TextWidth(name.data(), 32, font, 1.0f);
while (text_size > 450)
{
text_size = game::UI_TextWidth(name.data(), 32, font, 1.0f);
name.pop_back();
}
}
utils::hook::detour lui_open_menu_hook; utils::hook::detour lui_open_menu_hook;
void lui_open_menu_stub(int controllerIndex, const char* menu, int a3, int a4, unsigned int a5) void lui_open_menu_stub(int controllerIndex, const char* menu, int a3, int a4, unsigned int a5)
@ -364,8 +350,6 @@ namespace server_list
server.in_game = 1; server.in_game = 1;
resize_host_name(server.host_name);
insert_server(std::move(server)); insert_server(std::move(server));
} }

View File

@ -3,162 +3,162 @@ originalmenus = {}
stack = {} stack = {}
LUI.MenuBuilder.m_types_build["generic_waiting_popup_"] = function (menu, event) LUI.MenuBuilder.m_types_build["generic_waiting_popup_"] = function (menu, event)
local oncancel = stack.oncancel local oncancel = stack.oncancel
local popup = LUI.MenuBuilder.BuildRegisteredType("waiting_popup", { local popup = LUI.MenuBuilder.BuildRegisteredType("waiting_popup", {
message_text = stack.text, message_text = stack.text,
isLiveWithCancel = true, isLiveWithCancel = true,
cancel_func = function(...) cancel_func = function(...)
local args = {...} local args = {...}
oncancel() oncancel()
LUI.FlowManager.RequestLeaveMenu(args[1]) LUI.FlowManager.RequestLeaveMenu(args[1])
end end
}) })
local listchildren = popup:getChildById("LUIHorizontalList"):getchildren() local listchildren = popup:getChildById("LUIHorizontalList"):getchildren()
local children = listchildren[2]:getchildren() local children = listchildren[2]:getchildren()
popup.text = children[2] popup.text = children[2]
stack = { stack = {
ret = popup ret = popup
} }
return popup return popup
end end
LUI.MenuBuilder.m_types_build["generic_yes_no_popup_"] = function() LUI.MenuBuilder.m_types_build["generic_yes_no_popup_"] = function()
local callback = stack.callback local callback = stack.callback
local popup = LUI.MenuBuilder.BuildRegisteredType("generic_yesno_popup", { local popup = LUI.MenuBuilder.BuildRegisteredType("generic_yesno_popup", {
popup_title = stack.title, popup_title = stack.title,
message_text = stack.text, message_text = stack.text,
yes_action = function() yes_action = function()
callback(true) callback(true)
end, end,
no_action = function() no_action = function()
callback(false) callback(false)
end end
}) })
stack = { stack = {
ret = popup ret = popup
} }
return popup return popup
end end
LUI.MenuBuilder.m_types_build["generic_confirmation_popup_"] = function() LUI.MenuBuilder.m_types_build["generic_confirmation_popup_"] = function()
local popup = LUI.MenuBuilder.BuildRegisteredType( "generic_confirmation_popup", { local popup = LUI.MenuBuilder.BuildRegisteredType( "generic_confirmation_popup", {
cancel_will_close = false, cancel_will_close = false,
popup_title = stack.title, popup_title = stack.title,
message_text = stack.text, message_text = stack.text,
button_text = stack.buttontext, button_text = stack.buttontext,
confirmation_action = stack.callback confirmation_action = stack.callback
}) })
stack = { stack = {
ret = popup ret = popup
} }
return stack.ret return stack.ret
end end
LUI.onmenuopen = function(name, callback) LUI.onmenuopen = function(name, callback)
if (not LUI.MenuBuilder.m_types_build[name]) then if (not LUI.MenuBuilder.m_types_build[name]) then
return return
end end
if (not menucallbacks[name]) then if (not menucallbacks[name]) then
menucallbacks[name] = {} menucallbacks[name] = {}
end end
table.insert(menucallbacks[name], callback) table.insert(menucallbacks[name], callback)
if (not originalmenus[name]) then if (not originalmenus[name]) then
originalmenus[name] = LUI.MenuBuilder.m_types_build[name] originalmenus[name] = LUI.MenuBuilder.m_types_build[name]
LUI.MenuBuilder.m_types_build[name] = function(...) LUI.MenuBuilder.m_types_build[name] = function(...)
local args = {...} local args = {...}
local menu = originalmenus[name](table.unpack(args)) local menu = originalmenus[name](table.unpack(args))
for k, v in luiglobals.next, menucallbacks[name] do for k, v in luiglobals.next, menucallbacks[name] do
v(menu, table.unpack(args)) v(menu, table.unpack(args))
end end
return menu return menu
end end
end end
end end
local addoptionstextinfo = LUI.Options.AddOptionTextInfo local addoptionstextinfo = LUI.Options.AddOptionTextInfo
LUI.Options.AddOptionTextInfo = function(menu) LUI.Options.AddOptionTextInfo = function(menu)
local result = addoptionstextinfo(menu) local result = addoptionstextinfo(menu)
menu.optionTextInfo = result menu.optionTextInfo = result
return result return result
end end
LUI.addmenubutton = function(name, data) LUI.addmenubutton = function(name, data)
LUI.onmenuopen(name, function(menu) LUI.onmenuopen(name, function(menu)
if (not menu.list) then if (not menu.list) then
return return
end end
local button = menu:AddButton(data.text, data.callback, nil, true, nil, { local button = menu:AddButton(data.text, data.callback, nil, true, nil, {
desc_text = data.description desc_text = data.description
}) })
local buttonlist = menu:getChildById(menu.type .. "_list") local buttonlist = menu:getChildById(menu.type .. "_list")
if (data.id) then if (data.id) then
button.id = data.id button.id = data.id
end end
if (data.index) then if (data.index) then
buttonlist:removeElement(button) buttonlist:removeElement(button)
buttonlist:insertElement(button, data.index) buttonlist:insertElement(button, data.index)
end end
local hintbox = menu.optionTextInfo local hintbox = menu.optionTextInfo
menu:removeElement(hintbox) menu:removeElement(hintbox)
LUI.Options.InitScrollingList(menu.list, nil) LUI.Options.InitScrollingList(menu.list, nil)
menu.optionTextInfo = LUI.Options.AddOptionTextInfo(menu) menu.optionTextInfo = LUI.Options.AddOptionTextInfo(menu)
end) end)
end end
LUI.openmenu = function(menu, args) LUI.openmenu = function(menu, args)
stack = args stack = args
LUI.FlowManager.RequestAddMenu(nil, menu) LUI.FlowManager.RequestAddMenu(nil, menu)
return stack.ret return stack.ret
end end
LUI.openpopupmenu = function(menu, args) LUI.openpopupmenu = function(menu, args)
stack = args stack = args
LUI.FlowManager.RequestPopupMenu(nil, menu) LUI.FlowManager.RequestPopupMenu(nil, menu)
return stack.ret return stack.ret
end end
LUI.yesnopopup = function(data) LUI.yesnopopup = function(data)
for k, v in luiglobals.next, data do for k, v in luiglobals.next, data do
stack[k] = v stack[k] = v
end end
LUI.FlowManager.RequestPopupMenu(nil, "generic_yes_no_popup_") LUI.FlowManager.RequestPopupMenu(nil, "generic_yes_no_popup_")
return stack.ret return stack.ret
end end
LUI.confirmationpopup = function(data) LUI.confirmationpopup = function(data)
for k, v in luiglobals.next, data do for k, v in luiglobals.next, data do
stack[k] = v stack[k] = v
end end
LUI.FlowManager.RequestPopupMenu(nil, "generic_confirmation_popup_") LUI.FlowManager.RequestPopupMenu(nil, "generic_confirmation_popup_")
return stack.ret return stack.ret
end end
function userdata_:getchildren() function userdata_:getchildren()
local children = {} local children = {}
local first = self:getFirstChild() local first = self:getFirstChild()
while (first) do while (first) do
table.insert(children, first) table.insert(children, first)
first = first:getNextSibling() first = first:getNextSibling()
end end
return children return children
end end