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

551 lines
15 KiB
Lua

local f0_local0 = module
local f0_local1, f0_local2 = ...
f0_local0( f0_local1, package.seeall )
CoD.PrintModuleLoad( _NAME )
function MapFeeder( f1_arg0 )
local f1_local0 = {}
local f1_local1 = Lobby.GetMapFeederCount()
local f1_local2 = LUI.FlowManager.GetMenuScopedDataByMenuName( "mapsetup_menu_main" ) or {}
local f1_local3 = nil
if f1_local2.squadBaseSelect then
f1_local3 = Engine.GetPlayerDataEx( f1_local2.exclusiveControllerIndex, CoD.StatsGroup.Ranked, "squadHQ", "squad_base" )
end
for f1_local4 = 0, f1_local1 - 1, 1 do
local f1_local7 = nil
local f1_local8 = Lobby.GetMapLoadNameByIndex( f1_local4 )
local f1_local9 = false
if f1_local2.squadBaseSelect then
f1_local9 = f1_local8 == f1_local3
end
if f1_local8 == "bonus_map" or f1_local8 == "more_maps" then
f1_local7 = {
type = "UIGenericButton",
id = "mapsetup_rotationmap" .. f1_local4,
properties = {
button_text = GetButtonMapName( f1_local4 ),
button_action_func = MBh.EmitEventToRoot( {
name = "select_map",
idx = f1_local4
} ),
button_over_func = MBh.EmitEventToRoot( {
name = "update_map",
idx = f1_local4
} )
}
}
else
f1_local7 = {
type = "UIGenericButton",
id = "mapsetup_rotationmap" .. f1_local4,
listDefaultFocus = f1_local9,
properties = {
variant = GenericButtonSettings.Variants.Checkbox,
button_text = Lobby.GetMapNameByIndex( f1_local4 ),
button_action_func = MBh.EmitEventToRoot( {
name = "select_map",
idx = f1_local4
} ),
button_over_func = MBh.EmitEventToRoot( {
name = "update_map",
idx = f1_local4
} )
}
}
end
if f1_local4 == 0 and Engine.GetDvarBool( "accessToSubscriberContent" ) then
f1_local0[#f1_local0 + 1] = f1_local7
end
if Engine.IsAliensMode() and Lobby.GetMapSupportsAliensByIdx( f1_local4 ) then
f1_local0[#f1_local0 + 1] = f1_local7
end
if not Engine.IsAliensMode() and not Lobby.GetMapSupportsAliensByIdx( f1_local4 ) then
f1_local0[#f1_local0 + 1] = f1_local7
end
end
return f1_local0
end
function MapSetupCreate( f2_arg0, f2_arg1 )
local f2_local0 = LUI.FlowManager.GetMenuScopedDataFromElement( f2_arg0 ) or {}
f2_local0.rotationAllowed = f2_arg0.properties.rotationAllowed
f2_arg0:dispatchEventToRoot( {
name = "add_button_helper_text",
button_ref = "button_secondary",
helper_text = Engine.Localize( "@LUA_MENU_BACK" ),
side = "left",
clickable = true,
immediate = true
} )
f2_arg0:dispatchEventToRoot( {
name = "add_button_helper_text",
button_ref = "button_action",
helper_text = Engine.Localize( "@LUA_MENU_SELECT" ),
side = "left",
clickable = true,
immediate = true
} )
f2_arg0:dispatchEventToRoot( {
name = "update_lists",
immediate = true
} )
UpdateMapRotation( f2_arg0, f2_arg1 )
UpdateMap( f2_arg0, {
idx = 0
} )
end
function UpdateMapRotation( f3_arg0, f3_arg1 )
local f3_local0 = LUI.FlowManager.GetMenuScopedDataFromElement( f3_arg0 )
if not f3_local0.squadBaseSelect then
local f3_local1 = Lobby.GetMapFeederCount()
for f3_local2 = 0, f3_local1 - 1, 1 do
local f3_local5 = Lobby.GetMapLoadNameByIndex( f3_local2 )
local f3_local6 = f3_arg0:getFirstDescendentById( "mapsetup_rotationmap" .. f3_local2 )
if Lobby.IsMapInRotation( f3_local5 ) then
f3_local6:processEvent( {
name = "set_checked",
dispatchChildren = true
} )
end
end
end
end
function GetButtonMapName( f4_arg0 )
local f4_local0 = Lobby.GetMapNameByIndex( f4_arg0 )
if Engine.MarkLocalized( f4_local0 ) == Engine.Localize( "DLC_MAPSTORE" ) then
f4_local0 = Engine.Localize( "PATCH_MENU_MORE_MAPS" )
end
return f4_local0
end
function UpdateMap( f5_arg0, f5_arg1 )
local f5_local0 = f5_arg0:getFirstDescendentById( "mapsetup_mapname" )
local f5_local1 = f5_arg0:getFirstDescendentById( "mapsetup_mapdesc" )
local f5_local2 = f5_arg0:getFirstDescendentById( "mapsetup_mapimage" )
local f5_local3 = f5_arg1.idx
local f5_local4 = Lobby.GetMapDescByIndex( f5_local3 )
if f5_local0 then
f5_local0:setText( Lobby.GetMapNameByIndex( f5_local3 ) )
end
if f5_local1 then
f5_local1:setText( Engine.Localize( f5_local4 ) )
end
f5_arg0:processEvent( {
name = "adjust_desc_text",
dispatchChildren = true,
descText = f5_local4
} )
if f5_local2 then
local f5_local5 = Lobby.GetMapLoadNameByIndex( f5_local3 )
if f5_local5 == "bonus_map" or f5_local5 == "more_maps" then
f5_local2:setImage( RegisterMaterial( "loadscreen_mp_bonusmaps" ) )
else
f5_local2:setImage( RegisterMaterial( Lobby.GetMapImageByIndex( f5_local3 ) ) )
end
end
end
function SelectMap( f6_arg0, f6_arg1 )
local f6_local0 = Lobby.GetMapLoadNameByIndex( f6_arg1.idx )
if f6_local0 == "bonus_map" then
if Lobby.GetDLCMapCount() > 0 then
Engine.SetDvarBool( "ui_showDLCMaps", true )
f6_arg0:dispatchEventToRoot( {
name = "refresh_maps"
} )
elseif Engine.GetDvarBool( "onlinegame" ) then
LUI.FlowManager.RequestPopupMenu( f6_arg0, "you_dont_have_bonus_maps", true, f6_arg1.controller, nil, nil, nil, nil, false )
else
LUI.FlowManager.RequestPopupMenu( f6_arg0, "you_dont_have_bonus_maps_offline", true, f6_arg1.controller, nil, nil, nil, nil, false )
end
elseif f6_local0 == "more_maps" then
if Engine.GetDvarBool( "onlinegame" ) then
LUI.FlowManager.RequestPopupMenu( f6_arg0, "get_more_maps", true, f6_arg1.controller, nil, nil, nil, nil, false )
else
LUI.FlowManager.RequestPopupMenu( f6_arg0, "get_more_maps_offline", true, f6_arg1.controller, nil, nil, nil, nil, false )
end
elseif f6_arg0.properties.rotationAllowed and MatchRules.IsUsingCustomMapRotation() then
SelectMap_Rotation( f6_arg0, f6_arg1 )
else
SelectMap_Single( f6_arg0, f6_arg1 )
end
end
function SelectMap_Single( f7_arg0, f7_arg1 )
local f7_local0 = LUI.FlowManager.GetMenuScopedDataFromElement( f7_arg0 ) or {}
local f7_local1 = f7_arg1.idx
if f7_local1 == nil then
return
end
local f7_local2 = Lobby.GetMapLoadNameByIndex( f7_local1 )
if f7_local0.squadBaseSelect then
Engine.SetPlayerDataEx( f7_local0.exclusiveControllerIndex, CoD.StatsGroup.Ranked, "squadHQ", "squad_base", f7_local2 )
else
Engine.SetDvarString( "ui_mapname", f7_local2 )
end
ExitMenu( f7_arg0, f7_arg1 )
end
function SelectMap_Rotation( f8_arg0, f8_arg1 )
local f8_local0 = Lobby.GetMapLoadNameByIndex( f8_arg1.idx )
if Lobby.IsMapInRotation( f8_local0 ) then
Lobby.IncludeMapInRotation( f8_local0, false )
else
Lobby.IncludeMapInRotation( f8_local0, true )
end
Engine.ExecNow( "xupdatepartystate" )
end
function ToggleMultiMap( f9_arg0, f9_arg1 )
if f9_arg0.properties.rotationAllowed then
Engine.PlaySound( CoD.SFX.MouseClick )
MatchRules.SetUsingCustomMapRotation( MatchRules.IsUsingCustomMapRotation() )
f9_arg0:dispatchEventToRoot( {
name = "update_lists"
} )
end
end
function UpdateLists( f10_arg0, f10_arg1 )
local f10_local0 = LUI.FlowManager.GetMenuScopedDataFromElement( f10_arg0 ) or {}
if not f10_local0.squadBaseSelect then
local f10_local1 = f10_local0.rotationAllowed
local f10_local2 = MatchRules.IsUsingCustomMapRotation()
end
local f10_local3 = f10_local1 and f10_local2 or false
f10_arg0:processEvent( {
name = "show_checkbox",
showBox = f10_local3,
dispatchChildren = true
} )
if f10_local3 then
f10_arg0:dispatchEventToRoot( {
name = "add_button_helper_text",
button_ref = "button_alt1",
helper_text = Engine.Localize( "@LUA_MENU_RULES_TOGGLE_ROTATION_OFF" ),
side = "left",
clickable = true,
immediate = true
} )
elseif f10_arg0.properties.rotationAllowed then
f10_arg0:dispatchEventToRoot( {
name = "add_button_helper_text",
button_ref = "button_alt1",
helper_text = Engine.Localize( "@LUA_MENU_RULES_TOGGLE_ROTATION_ON" ),
side = "left",
clickable = true,
immediate = true
} )
end
end
function RefreshMapList( f11_arg0, f11_arg1 )
f11_arg0:processEvent( {
name = "refresh_scroll_list",
dispatchChildren = true
} )
f11_arg0:processEvent( {
name = "update_lists"
} )
f11_arg0:processEvent( {
name = "gain_focus"
} )
UpdateMapRotation( f11_arg0, f11_arg1 )
end
function ExitMenu( f12_arg0, f12_arg1 )
local f12_local0 = LUI.FlowManager.GetMenuScopedDataFromElement( f12_arg0 ) or {}
local f12_local1
if not f12_local0.squadBaseSelect then
f12_local1 = f12_local0.rotationAllowed
if f12_local1 then
f12_local1 = MatchRules.IsUsingCustomMapRotation()
end
else
f12_local1 = false
end
if f12_local1 == false then
Engine.ExecNow( "xupdatepartystate" )
end
Engine.SetDvarBool( "ui_showDLCMaps", false )
LUI.FlowManager.RequestLeaveMenu( f12_arg0 )
end
function BackButtonFunc( f13_arg0, f13_arg1 )
if Engine.GetDvarBool( "ui_showDLCMaps" ) then
Engine.SetDvarBool( "ui_showDLCMaps", false )
f13_arg0:dispatchEventToRoot( {
name = "refresh_maps"
} )
else
ExitMenu( f13_arg0, f13_arg1 )
end
end
function mapsetup_map_vlist()
return {
type = "UIVerticalList",
focusable = true,
states = {
default = {
leftAnchor = true,
rightAnchor = true,
topAnchor = true,
bottomAnchor = true,
left = 0,
right = -50,
top = 0,
bottom = 0,
alpha = 1
},
hidden = {
alpha = 0
}
}
}
end
function mapsetup_details_window()
return {
type = "UIElement",
states = {
default = {
topAnchor = true,
bottomAnchor = false,
leftAnchor = true,
rightAnchor = false,
top = 140,
bottom = 600,
left = 560,
right = 1040
}
},
children = {
{
type = "generic_menu_titlebar",
id = "mapsetup_details_title",
properties = {
font = CoD.TextSettings.BoldFont,
title_bar_text = Engine.Localize( "@LUA_MENU_MAP_DETAILS_CAPS" ),
title_bar_text_indent = GenericTitleBarDims.TitleBarLCapWidth,
title_bar_alignment = LUI.Alignment.Left,
fill_alpha = 1
}
},
{
type = "generic_menu_background_withfade",
id = "mapsetup_details_window_bg",
properties = {
fill_alpha = 1
}
},
{
type = "UIImage",
id = "mapsetup_mapimage",
states = {
default = {
topAnchor = true,
bottomAnchor = false,
leftAnchor = true,
rightAnchor = true,
material = RegisterMaterial( "" ),
left = 10,
right = -10,
top = GenericTitleBarDims.TitleBarHeight + 10,
height = 240
}
}
},
{
type = "UIText",
id = "mapsetup_mapname",
properties = {
text = ""
},
states = {
default = {
left = -220,
top = 65,
width = 380,
height = CoD.TextSettings.BoldFont.Height,
font = CoD.TextSettings.BoldFont.Font,
alignment = LUI.Alignment.Left
}
}
},
{
type = "UIText",
id = "mapsetup_mapdesc",
states = {
default = {
left = -220,
top = 85,
width = 450,
height = CoD.TextSettings.NormalFont.Height,
font = CoD.TextSettings.NormalFont.Font,
alignment = LUI.Alignment.Left,
red = Colors.primary_text_color.r,
green = Colors.primary_text_color.g,
blue = Colors.primary_text_color.b
},
adjusted = {
top = 105,
height = CoD.TextSettings.NormalFont.Height
}
},
handlers = {
adjust_desc_text = function ( f16_arg0, f16_arg1 )
if f16_arg1.descText == "@DLC_MAPS_DESC" then
f16_arg0:animateToState( "adjusted" )
else
f16_arg0:animateToState( "default" )
end
end
}
}
}
}
end
function mapsetup_menu_main()
return {
type = "UIElement",
id = "mapsetup_root",
properties = {
menu_title = Engine.Localize( "@LUA_MENU_MAP_SELECT_CAPS" ),
rotationAllowed = false
},
states = {
default = {
topAnchor = true,
bottomAnchor = true,
leftAnchor = true,
rightAnchor = true,
top = 0,
bottom = 0,
left = 0,
right = 0
}
},
handlers = {
menu_create = MapSetupCreate,
update_map = UpdateMap,
update_lists = UpdateLists,
select_map = SelectMap,
refresh_maps = RefreshMapList
},
children = {
{
type = "generic_menu_title",
id = "mapsetup_title",
properties = {
menu_title = MBh.Property( "menu_title" )
}
},
{
type = "UIScrollingVerticalList",
id = "mapsetup_rptatopmmaplist",
childrenFeeder = MapFeeder,
properties = {
use_arrows = true,
use_scrollbar = false,
bar_width = 20
},
states = {
default = {
leftAnchor = true,
rightAnchor = false,
topAnchor = true,
bottomAnchor = false,
left = GenericMenuDims.menu_left,
right = GenericMenuDims.menu_right,
top = GenericMenuDims.menu_top,
bottom = GenericMenuDims.menu_top + GenericButtonSettings.Styles.GradientButton.height * 11 + 2 + 60
}
}
},
{
type = "mapsetup_details_window",
id = "mapsetup_details_window_id"
},
{
type = "UIBindButton",
id = "mapsetup_bindbuttons",
handlers = {
button_secondary = BackButtonFunc,
button_alt1 = ToggleMultiMap
}
},
{
type = "button_helper_text_main",
id = "mapsetup_button_helper_text_id"
},
{
type = "online_friends_widget",
id = "online_friends_widget_id"
}
}
}
end
function you_dont_have_bonus_maps()
return {
type = "generic_yesno_popup",
properties = {
message_text = Engine.Localize( "@LUA_MENU_NO_BONUS_MAPS" ),
popup_title = Engine.Localize( "@MENU_NOTICE" ),
yes_action = function ( f19_arg0, f19_arg1 )
LUI.FlowManager.RequestLeaveMenu( f19_arg0 )
Sns.OpenStoreMenu( f19_arg1.controller, "map_select_menu" )
end
}
}
end
function get_more_maps()
return {
type = "generic_yesno_popup",
properties = {
message_text = Engine.Localize( "@LUA_MENU_PURCHASE_MAPS" ),
popup_title = Engine.Localize( "@MENU_NOTICE" ),
yes_action = function ( f21_arg0, f21_arg1 )
LUI.FlowManager.RequestLeaveMenu( f21_arg0 )
Sns.OpenStoreMenu( f21_arg1.controller, "map_select_menu" )
end
}
}
end
function you_dont_have_bonus_maps_offline()
return {
type = "generic_confirmation_popup",
properties = {
popup_title = Engine.Localize( "@MENU_NOTICE" ),
message_text = Engine.Localize( "@LUA_MENU_NO_BONUS_MAPS_OFFLINE" )
}
}
end
function get_more_maps_offline()
return {
type = "generic_confirmation_popup",
properties = {
popup_title = Engine.Localize( "@MENU_NOTICE" ),
message_text = Engine.Localize( "@LUA_MENU_PURCHASE_MAPS_OFFLINE" )
}
}
end
LUI.MenuBuilder.registerDef( "mapsetup_menu_main", mapsetup_menu_main )
LUI.MenuBuilder.registerDef( "mapsetup_map_vlist", mapsetup_map_vlist )
LUI.MenuBuilder.registerDef( "mapsetup_details_window", mapsetup_details_window )
LUI.MenuBuilder.registerDef( "you_dont_have_bonus_maps", you_dont_have_bonus_maps )
LUI.MenuBuilder.registerDef( "get_more_maps", get_more_maps )
LUI.MenuBuilder.registerDef( "you_dont_have_bonus_maps_offline", you_dont_have_bonus_maps_offline )
LUI.MenuBuilder.registerDef( "get_more_maps_offline", get_more_maps_offline )
LockTable( _M )