iw6-lui/lui/mp_menus/systemlinkjoinmenu.dec.lua
2024-09-12 17:25:45 +02:00

430 lines
11 KiB
Lua

local f0_local0 = module
local f0_local1, f0_local2 = ...
f0_local0( f0_local1, package.seeall )
DebugPrint( "Registering " .. _NAME )
GameDataColumn = {
Host = 0,
Map = 1,
Clients = 2,
Game = 3,
Ping = 4
}
COLUMN_0 = 0
COLUMN_1 = 360
COLUMN_2 = 560
COLUMN_3 = 700
function OnCreate( f1_arg0, f1_arg1 )
local f1_local0 = LUI.FlowManager.GetMenuScopedDataFromElement( f1_arg0 )
f1_local0.serverCount = 0
f1_arg0:processEvent( LUI.ButtonHelperText.CommonEvents.addBackButton )
f1_arg0:processEvent( {
name = "add_button_helper_text",
button_ref = "button_action",
helper_text = Engine.Localize( "@MENU_JOIN_GAME1" ),
side = "left",
clickable = true
} )
f1_arg0:processEvent( {
name = "add_button_helper_text",
button_ref = "button_alt1",
helper_text = Engine.Localize( "@MENU_SB_TOOLTIP_BTN_REFRESH" ),
side = "left",
clickable = true
} )
local f1_local1 = Lobby.BuildServerList
local f1_local2 = f1_arg1.controller
if not f1_local2 then
f1_local2 = Engine.GetFirstActiveController()
end
f1_local1( f1_local2 )
end
function JoinGame( f2_arg0, f2_arg1 )
local f2_local0 = Lobby.JoinServer
local f2_local1 = f2_arg1.controller
if not f2_local1 then
f2_local1 = Engine.GetFirstActiveController()
end
f2_local0( f2_local1, f2_arg1.idx )
end
function UpdateGameList( f3_arg0, f3_arg1 )
local f3_local0 = f3_arg1.controller
if not f3_local0 then
f3_local0 = Engine.GetFirstActiveController()
end
local f3_local1 = LUI.FlowManager.GetMenuScopedDataFromElement( f3_arg0 )
Lobby.UpdateServerDisplayList( f3_local0 )
local f3_local2 = Lobby.GetServerCount( f3_local0 )
if f3_local2 ~= f3_local1.serverCount then
f3_local1.serverCount = f3_local2
f3_arg0:processEvent( {
name = "menu_refresh",
immediate = true
} )
f3_arg0:processEvent( {
name = "gain_focus",
immediate = true
} )
end
end
function RefreshServers( f4_arg0, f4_arg1 )
local f4_local0 = LUI.FlowManager.GetMenuScopedDataFromElement( f4_arg0 )
f4_local0.serverCount = 0
if f4_local0.serverList then
local f4_local1 = Lobby.RefreshServerList
local f4_local2 = f4_arg1.controller
if not f4_local2 then
f4_local2 = Engine.GetFirstActiveController()
end
f4_local1( f4_local2 )
f4_local0.serverList:processEvent( {
name = "lose_focus",
immediate = true
} )
f4_local0.serverList:clearSavedState()
f4_local0.serverList:processEvent( {
name = "menu_refresh",
dispatchChildren = true
} )
end
end
function CreateHeaderDef()
local f5_local0 = {
type = "UIElement",
id = "header_row_id",
states = {
default = {
topAnchor = true,
bottomAnchor = false,
leftAnchor = true,
rightAnchor = true,
top = 2,
left = 2,
right = -2,
height = GenericTitleBarDims.TitleBarHeight
}
}
}
local f5_local1 = {
[#f5_local1 + 1] = CreateRowBackground( Colors.generic_menu_bg_color ),
[#f5_local1 + 1] = CreateColumnShade( "column_shade_rect_id", false, COLUMN_1, COLUMN_2 ),
[#f5_local1 + 1] = CreateColumnShade( "column_shade_rect_2_id", true, COLUMN_3, -1 ),
[#f5_local1 + 1] = CreateColumnText( "host_header", Engine.Localize( "@MENU_HOST_NAME" ), true, false, COLUMN_0, COLUMN_1 ),
[#f5_local1 + 1] = CreateColumnText( "map_header", Engine.Localize( "@MENU_MAP" ), true, false, COLUMN_1, COLUMN_2 ),
[#f5_local1 + 1] = CreateColumnText( "players_header", Engine.Localize( "@MENU_NUMPLAYERS" ), true, false, COLUMN_2, COLUMN_3 ),
[#f5_local1 + 1] = CreateColumnText( "type_header", Engine.Localize( "@MENU_TYPE1" ), true, true, COLUMN_3, 0 )
}
f5_local0.children = f5_local1
return f5_local0
end
function CreateRowDef( f6_arg0, f6_arg1, f6_arg2, f6_arg3 )
local f6_local0 = {
type = "UIButton",
id = "row_" .. f6_arg1,
disabled = f6_arg2,
focusable = not f6_arg2,
properties = {
button_height = GenericButtonDims.button_height
},
states = {
default = {
topAnchor = true,
bottomAnchor = false,
leftAnchor = true,
rightAnchor = true,
top = 0,
bottom = MBh.Property( "button_height" ),
left = 0,
right = 0
}
},
handlers = {
button_action = MBh.EmitEventToRoot( {
name = "select_game",
idx = f6_arg1
} )
}
}
local f6_local1 = {
[#f6_local1 + 1] = CreateRowBackground( f6_arg3 ),
[#f6_local1 + 1] = CreateColumnShade( "column_shade_rect_id", false, COLUMN_1, COLUMN_2 ),
[#f6_local1 + 1] = CreateColumnShade( "column_shade_rect_2_id", true, COLUMN_3, -1 ),
[#f6_local1 + 1] = CreateColumnText( "host_text", Lobby.GetServerData( f6_arg0, f6_arg1, GameDataColumn.Host ), true, false, COLUMN_0, COLUMN_1 ),
[#f6_local1 + 1] = CreateColumnText( "map_text", Lobby.GetServerData( f6_arg0, f6_arg1, GameDataColumn.Map ), true, false, COLUMN_1, COLUMN_2 ),
[#f6_local1 + 1] = CreateColumnText( "players_text", Lobby.GetServerData( f6_arg0, f6_arg1, GameDataColumn.Clients ), true, false, COLUMN_2, COLUMN_3 ),
[#f6_local1 + 1] = CreateColumnText( "type_text", Lobby.GetServerData( f6_arg0, f6_arg1, GameDataColumn.Game ), true, true, COLUMN_3, 0 )
}
f6_local0.children = f6_local1
return f6_local0
end
function CreateRowBackground( f7_arg0 )
return {
type = "UIImage",
id = "background",
states = {
default = {
topAnchor = true,
bottomAnchor = true,
leftAnchor = true,
rightAnchor = true,
top = 0,
bottom = 0,
left = 1,
right = -1,
red = f7_arg0.r,
green = f7_arg0.g,
blue = f7_arg0.b,
material = RegisterMaterial( "white" ),
alpha = 0.05
},
over = {
material = RegisterMaterial( "btn_cas_fill_f" ),
red = 1,
green = 1,
blue = 1,
alpha = 1
}
},
handlers = {
button_over = MBh.AnimateToState( "over" ),
button_up = MBh.AnimateToState( "default" )
}
}
end
function CreateColumnShade( f8_arg0, f8_arg1, f8_arg2, f8_arg3 )
return {
type = "UIImage",
id = f8_arg0,
states = {
default = {
topAnchor = true,
bottomAnchor = true,
leftAnchor = true,
rightAnchor = f8_arg1,
top = 0,
bottom = 0,
left = f8_arg2,
right = f8_arg3,
red = 0.05,
green = 0.05,
blue = 0.05,
alpha = 0.25,
material = RegisterMaterial( "white" )
},
over = {
alpha = 0
}
},
handlers = {
button_over = MBh.AnimateToState( "over" ),
button_up = MBh.AnimateToState( "default" )
}
}
end
function CreateColumnText( f9_arg0, f9_arg1, f9_arg2, f9_arg3, f9_arg4, f9_arg5 )
return {
type = "UIText",
id = f9_arg0,
properties = {
text = f9_arg1
},
states = {
default = {
font = CoD.TextSettings.NormalFont.Font,
alignment = LUI.Alignment.Left,
leftAnchor = f9_arg2,
rightAnchor = f9_arg3,
topAnchor = false,
bottomAnchor = false,
left = f9_arg4 + 5,
right = f9_arg5,
top = -CoD.TextSettings.NormalFont.Height / 2,
bottom = CoD.TextSettings.NormalFont.Height / 2,
red = Colors.cac_label_text.r,
green = Colors.cac_label_text.g,
blue = Colors.cac_label_text.b,
alpha = 1
},
over = {
red = Colors.cac_focus_text.r,
green = Colors.cac_focus_text.g,
blue = Colors.cac_focus_text.b,
alpha = 1
},
disabled = {
alpha = 0
}
},
handlers = {
button_over = MBh.AnimateToState( "over" ),
button_up = MBh.AnimateToState( "default" ),
button_disable = MBh.AnimateToState( "disabled" )
}
}
end
function LinkGamesFeeder( f10_arg0 )
local f10_local0 = f10_arg0.controller
if not f10_local0 then
f10_local0 = Engine.GetFirstActiveController()
end
local f10_local1 = Lobby.GetServerCount( f10_local0 )
local f10_local2 = 16
local f10_local3 = {}
for f10_local4 = 0, f10_local2 - 1, 1 do
f10_local3[#f10_local3 + 1] = CreateRowDef( f10_local0, f10_local4, f10_local1 <= f10_local4, f10_local4 % 2 and Colors.white or Colors.black )
end
return f10_local3
end
function menu_systemlink_join()
return {
type = "UIElement",
id = "menu_systemlink_join_root",
states = {
default = {
topAnchor = true,
bottomAnchor = true,
leftAnchor = true,
rightAnchor = true,
top = 0,
bottom = 0,
left = 0,
right = 0
}
},
handlers = {
menu_create = OnCreate,
select_game = JoinGame
},
children = {
{
type = "UIImage",
states = {
default = CoD.ColorizeState( Swatches.Overlay.Color, {
topAnchor = true,
bottomAnchor = true,
leftAnchor = true,
rightAnchor = true,
top = 0,
bottom = 0,
left = 0,
right = 0,
material = RegisterMaterial( "white" ),
alpha = Swatches.Overlay.AlphaMore
} )
}
},
{
type = "UIElement",
states = {
default = {
topAnchor = false,
bottomAnchor = false,
leftAnchor = true,
rightAnchor = true,
left = 200,
right = -200,
height = 550
}
},
children = {
{
type = "generic_drop_shadow",
properties = {
offset_shadow = 0
}
},
{
type = "generic_menu_titlebar",
id = "menu_systemlink_join_title_id",
properties = {
fill_alpha = 1,
font = CoD.TextSettings.BoldFont,
title_bar_text = Engine.Localize( "@PLATFORM_SYSTEM_LINK_TITLE" ),
title_bar_text_indent = GenericTitleBarDims.TitleBarLCapWidth,
title_bar_alignment = LUI.Alignment.Left
}
},
{
type = "generic_menu_background",
id = "menu_systemlink_join_bg_id",
properties = {
fill_alpha = 1
},
children = {
CreateHeaderDef(),
{
type = "UIVerticalList",
id = "menu_systemlink_join_game_list_id",
states = {
default = {
topAnchor = true,
bottomAnchor = true,
leftAnchor = true,
rightAnchor = true,
top = GenericTitleBarDims.TitleBarHeight + 4,
bottom = 600,
left = 2,
right = -2
}
},
childrenFeeder = LinkGamesFeeder,
handlers = {
update_game_list = UpdateGameList,
menu_create = function ( f12_arg0, f12_arg1 )
local f12_local0 = LUI.FlowManager.GetMenuScopedDataFromElement( f12_arg0 )
f12_local0.serverList = f12_arg0
RefreshServers( f12_arg0, f12_arg1 )
end
}
},
{
type = "button_helper_text_main",
id = "online_vault_helper_text_id",
properties = {
left_inset = 10,
right_inset = -10,
top_margin = GenericFooterDims.TopMargin_WithoutBackground,
height = 42,
spacing = 12,
background_alpha = 0
}
}
}
}
}
},
{
type = "UITimer",
id = "menu_systemlink_join_update_timer",
properties = {
event = "update_game_list",
interval = 250,
disposable = false,
broadcastToRoot = true
}
},
{
type = "UIBindButton",
id = "menu_systemlink_join_bind_button_id",
handlers = {
button_secondary = MBh.LeaveMenu(),
button_alt1 = RefreshServers
}
}
}
}
end
LUI.MenuBuilder.registerDef( "menu_systemlink_join", menu_systemlink_join )
LockTable( _M )