diff --git a/data/ui_scripts/server_list/serverlist.lua b/data/ui_scripts/server_list/serverlist.lua index 4eac68e2..afc8137f 100644 --- a/data/ui_scripts/server_list/serverlist.lua +++ b/data/ui_scripts/server_list/serverlist.lua @@ -24,6 +24,19 @@ local columns = { "@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) local state = CoD.CreateState(0, f12_arg1, nil, nil, CoD.AnchorTypes.TopLeft) state.width = width @@ -53,7 +66,8 @@ SystemLinkJoinMenu.AddServerButton = function(menu, controller, index) button:addEventHandler("button_action", SystemLinkJoinMenu.OnJoinGame) 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 for i = 1, #offsets do diff --git a/src/client/component/server_list.cpp b/src/client/component/server_list.cpp index 407acfe7..bbe3cb0d 100644 --- a/src/client/component/server_list.cpp +++ b/src/client/component/server_list.cpp @@ -258,20 +258,6 @@ namespace server_list 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; 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; - resize_host_name(server.host_name); - insert_server(std::move(server)); } diff --git a/src/client/resources/ui_scripts/common.lua b/src/client/resources/ui_scripts/common.lua index 8f68e96d..e073be2e 100644 --- a/src/client/resources/ui_scripts/common.lua +++ b/src/client/resources/ui_scripts/common.lua @@ -3,162 +3,162 @@ originalmenus = {} stack = {} 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", { - message_text = stack.text, - isLiveWithCancel = true, - cancel_func = function(...) - local args = {...} - oncancel() - LUI.FlowManager.RequestLeaveMenu(args[1]) - end + message_text = stack.text, + isLiveWithCancel = true, + cancel_func = function(...) + local args = {...} + oncancel() + LUI.FlowManager.RequestLeaveMenu(args[1]) + end }) - local listchildren = popup:getChildById("LUIHorizontalList"):getchildren() - local children = listchildren[2]:getchildren() - popup.text = children[2] + local listchildren = popup:getChildById("LUIHorizontalList"):getchildren() + local children = listchildren[2]:getchildren() + popup.text = children[2] - stack = { - ret = popup - } + stack = { + ret = popup + } - return popup + return popup end LUI.MenuBuilder.m_types_build["generic_yes_no_popup_"] = function() - local callback = stack.callback - local popup = LUI.MenuBuilder.BuildRegisteredType("generic_yesno_popup", { - popup_title = stack.title, - message_text = stack.text, - yes_action = function() - callback(true) - end, - no_action = function() - callback(false) - end + local callback = stack.callback + local popup = LUI.MenuBuilder.BuildRegisteredType("generic_yesno_popup", { + popup_title = stack.title, + message_text = stack.text, + yes_action = function() + callback(true) + end, + no_action = function() + callback(false) + end }) - stack = { - ret = popup - } + stack = { + ret = popup + } - return popup + return popup end LUI.MenuBuilder.m_types_build["generic_confirmation_popup_"] = function() - local popup = LUI.MenuBuilder.BuildRegisteredType( "generic_confirmation_popup", { - cancel_will_close = false, - popup_title = stack.title, - message_text = stack.text, - button_text = stack.buttontext, - confirmation_action = stack.callback - }) + local popup = LUI.MenuBuilder.BuildRegisteredType( "generic_confirmation_popup", { + cancel_will_close = false, + popup_title = stack.title, + message_text = stack.text, + button_text = stack.buttontext, + confirmation_action = stack.callback + }) - stack = { - ret = popup - } + stack = { + ret = popup + } - return stack.ret + return stack.ret end LUI.onmenuopen = function(name, callback) - if (not LUI.MenuBuilder.m_types_build[name]) then - return - end + if (not LUI.MenuBuilder.m_types_build[name]) then + return + end - if (not menucallbacks[name]) then - menucallbacks[name] = {} - end + if (not menucallbacks[name]) then + menucallbacks[name] = {} + end - table.insert(menucallbacks[name], callback) + table.insert(menucallbacks[name], callback) - if (not originalmenus[name]) then - originalmenus[name] = LUI.MenuBuilder.m_types_build[name] - LUI.MenuBuilder.m_types_build[name] = function(...) - local args = {...} - local menu = originalmenus[name](table.unpack(args)) + if (not originalmenus[name]) then + originalmenus[name] = LUI.MenuBuilder.m_types_build[name] + LUI.MenuBuilder.m_types_build[name] = function(...) + local args = {...} + local menu = originalmenus[name](table.unpack(args)) - for k, v in luiglobals.next, menucallbacks[name] do - v(menu, table.unpack(args)) - end + for k, v in luiglobals.next, menucallbacks[name] do + v(menu, table.unpack(args)) + end - return menu - end - end + return menu + end + end end local addoptionstextinfo = LUI.Options.AddOptionTextInfo LUI.Options.AddOptionTextInfo = function(menu) - local result = addoptionstextinfo(menu) - menu.optionTextInfo = result - return result + local result = addoptionstextinfo(menu) + menu.optionTextInfo = result + return result end LUI.addmenubutton = function(name, data) - LUI.onmenuopen(name, function(menu) - if (not menu.list) then - return - end + LUI.onmenuopen(name, function(menu) + if (not menu.list) then + return + end - local button = menu:AddButton(data.text, data.callback, nil, true, nil, { - desc_text = data.description - }) + local button = menu:AddButton(data.text, data.callback, nil, true, nil, { + desc_text = data.description + }) - local buttonlist = menu:getChildById(menu.type .. "_list") + local buttonlist = menu:getChildById(menu.type .. "_list") - if (data.id) then - button.id = data.id - end + if (data.id) then + button.id = data.id + end - if (data.index) then - buttonlist:removeElement(button) - buttonlist:insertElement(button, data.index) - end + if (data.index) then + buttonlist:removeElement(button) + buttonlist:insertElement(button, data.index) + end - local hintbox = menu.optionTextInfo - menu:removeElement(hintbox) + local hintbox = menu.optionTextInfo + menu:removeElement(hintbox) - LUI.Options.InitScrollingList(menu.list, nil) - menu.optionTextInfo = LUI.Options.AddOptionTextInfo(menu) - end) + LUI.Options.InitScrollingList(menu.list, nil) + menu.optionTextInfo = LUI.Options.AddOptionTextInfo(menu) + end) end LUI.openmenu = function(menu, args) - stack = args - LUI.FlowManager.RequestAddMenu(nil, menu) - return stack.ret + stack = args + LUI.FlowManager.RequestAddMenu(nil, menu) + return stack.ret end LUI.openpopupmenu = function(menu, args) - stack = args - LUI.FlowManager.RequestPopupMenu(nil, menu) - return stack.ret + stack = args + LUI.FlowManager.RequestPopupMenu(nil, menu) + return stack.ret end LUI.yesnopopup = function(data) - for k, v in luiglobals.next, data do - stack[k] = v - end - LUI.FlowManager.RequestPopupMenu(nil, "generic_yes_no_popup_") - return stack.ret + for k, v in luiglobals.next, data do + stack[k] = v + end + LUI.FlowManager.RequestPopupMenu(nil, "generic_yes_no_popup_") + return stack.ret end LUI.confirmationpopup = function(data) - for k, v in luiglobals.next, data do - stack[k] = v - end - LUI.FlowManager.RequestPopupMenu(nil, "generic_confirmation_popup_") - return stack.ret + for k, v in luiglobals.next, data do + stack[k] = v + end + LUI.FlowManager.RequestPopupMenu(nil, "generic_confirmation_popup_") + return stack.ret end function userdata_:getchildren() - local children = {} - local first = self:getFirstChild() + local children = {} + local first = self:getFirstChild() - while (first) do - table.insert(children, first) - first = first:getNextSibling() - end + while (first) do + table.insert(children, first) + first = first:getNextSibling() + end - return children + return children end