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

623 lines
18 KiB
Lua

local f0_local0 = module
local f0_local1, f0_local2 = ...
f0_local0( f0_local1, package.seeall )
CoD.PrintModuleLoad( "Registering " .. _NAME )
function EndAnnouncerPreviewSound( f1_arg0 )
local f1_local0 = LUI.FlowManager.GetMenuScopedDataFromElement( f1_arg0 )
if f1_local0.announcerPreview then
Engine.StopSound( f1_local0.announcerPreview )
f1_local0.announcerPreview = nil
end
end
function OnCreate( f2_arg0, f2_arg1 )
f2_arg0:processEvent( LUI.ButtonHelperText.CommonEvents.addBackButton )
local f2_local0 = LUI.FlowManager.GetMenuScopedDataFromElement( f2_arg0 )
f2_local0.detailsVisible = false
f2_local0.hList = f2_arg0:getFirstDescendentById( "thumbnail_list_id" )
f2_arg0:processEvent( {
name = "update_tags"
} )
f2_arg0:processEvent( {
name = "update_thumbnail_arrows",
left_visible = showLeft,
right_visible = showRight
} )
end
function ChangeCategory( f3_arg0, f3_arg1 )
local f3_local0 = LUI.FlowManager.GetMenuScopedDataFromElement( f3_arg0 )
f3_local0.category = f3_arg0.properties.article_category
f3_local0.articleIndex = nil
EndAnnouncerPreviewSound( f3_arg0 )
f3_arg0:dispatchEventToRoot( {
name = "refresh_thumbnails",
immediate = true
} )
f3_arg0:dispatchEventToRoot( {
name = "update_store_helper_text",
immediate = true
} )
end
function ChangeArticle( f4_arg0, f4_arg1 )
local f4_local0 = LUI.FlowManager.GetMenuScopedDataFromElement( f4_arg0 )
f4_local0.articleIndex = f4_arg1.headerIndex
f4_local0.articleId = f4_arg1.itemId
local f4_local1, f4_local2, f4_local3, f4_local4 = f4_local0.hList:GetAnchorData()
local f4_local5 = math.max( f4_local0.articleIndex - Sns.MaxVisibleArticles - 1, 0 )
local f4_local6 = f4_local5 * -(Sns.Dims.Thumbnail.width + Sns.HListSpacing)
f4_local0.minVisibleArticle = f4_local5
f4_local0.hList:registerAnimationState( "default", {
leftAnchor = f4_local1,
rightAnchor = f4_local3,
topAnchor = f4_local2,
bottomAnchor = f4_local4,
left = f4_local6 + Sns.HListOffset,
right = -Sns.HListOffset,
top = Sns.HListOffset,
bottom = -Sns.HListOffset
} )
f4_local0.hList:animateToState( "default", 100 )
f4_arg0:processEvent( {
name = "refresh_article",
itemId = f4_arg1.itemId
} )
local f4_local7 = Store.GetNumItemsInCategory( f4_local0.category )
local f4_local8 = f4_local0.articleIndex >= Sns.MaxVisibleArticles
local f4_local9
if f4_local7 <= Sns.MaxVisibleArticles or f4_local0.articleIndex >= f4_local7 - 1 then
f4_local9 = false
else
f4_local9 = true
end
f4_arg0:processEvent( {
name = "update_thumbnail_arrows",
left_visible = f4_local8,
right_visible = f4_local9
} )
EndAnnouncerPreviewSound( f4_arg0 )
if f4_local0.category == StoreCategory.AnnouncerVoices then
local f4_local10 = Engine.TableLookup( "mp/cac/announcers.csv", 0, tostring( f4_local0.articleIndex + 1 ), 2 )
if f4_local10 ~= "" then
f4_local0.announcerPreview = Engine.PlaySound( f4_local10 )
end
end
end
function RefreshArticle( f5_arg0, f5_arg1 )
local f5_local0 = LUI.FlowManager.GetMenuScopedDataFromElement( f5_arg0 )
local f5_local1 = CrossGameHackData( f5_local0.category )
assert( f5_arg1.itemId == f5_local0.articleId )
Sns.UpdateScopedArticleInfo( f5_arg0, f5_local0 )
f5_local0.detailsVisible = false
local f5_local2 = {}
if f5_local0.articleCount > 0 then
f5_local2[1] = {
fileId = Sns.GetScopedArticleInfo( f5_arg0, "image" ),
thumbName = Sns.GetScopedArticleInfo( f5_arg0, "thumbName" )
}
local f5_local3 = f5_local0.minVisibleArticle
local f5_local4 = math.min( f5_local0.articleCount - 1, f5_local3 + Sns.MaxPrefetchArticles - 1 )
for f5_local5 = f5_local3, f5_local4, 1 do
local f5_local8 = nil
if f5_local1 then
f5_local8 = {
dlcName = "s1",
id = -1,
thumb = "s1",
thumbName = "s1"
}
else
f5_local8 = Store.GetItemInfoByCategory( f5_local0.category, f5_local5 )
end
if f5_local8.thumb ~= f5_local2[1] then
f5_local2[#f5_local2 + 1] = {
fileId = f5_local8.thumb,
thumbName = f5_local8.thumbName
}
end
end
end
Store.RequestContentServerImages( unpack( f5_local2 ) )
f5_arg0:dispatchEventToChildren( {
name = "hide_more_details"
} )
f5_arg0:dispatchEventToChildren( {
name = "update_article_details",
end_time = endTime
} )
f5_arg0:dispatchEventToChildren( {
name = "show_article_purchaseinfo",
itemID = itemId,
dispatchChildren = true
} )
f5_arg0:dispatchEventToChildren( {
name = "update_purchase_checkboxes"
} )
f5_arg0:dispatchEventToRoot( {
name = "update_store_helper_text",
immediate = true
} )
end
function UpdateHelperText( f6_arg0, f6_arg1 )
local f6_local0 = LUI.FlowManager.GetMenuScopedDataFromElement( f6_arg0 )
local f6_local1 = f6_local0.category
f6_arg0:processEvent( {
name = "add_button_helper_text",
button_ref = "button_action",
helper_text = "",
side = "left"
} )
f6_arg0:processEvent( {
name = "add_button_helper_text",
button_ref = "button_alt1",
helper_text = "",
side = "left"
} )
if f6_local0.articleIndex then
local f6_local2 = nil
if f6_local0.articleInfo then
if f6_local0.articleInfo.purchased then
f6_local2 = Engine.Localize( "@LUA_MENU_DOWNLOAD" )
else
f6_local2 = Engine.Localize( "@LUA_MENU_PURCHASE" )
end
else
f6_local2 = ""
end
f6_arg0:processEvent( {
name = "add_button_helper_text",
button_ref = "button_action",
helper_text = f6_local2,
side = "left",
clickable = true
} )
end
if not Sns.IsRedeemCodeDisabled() then
if not f6_local0.articleIndex and Engine.IsPS3() then
return
end
f6_arg0:processEvent( {
name = "add_button_helper_text",
button_ref = "button_alt1",
helper_text = Engine.Localize( "@LUA_MENU_REDEEM_CODE" ),
side = "left",
clickable = true
} )
end
end
function OnActionPressed( f7_arg0, f7_arg1 )
local f7_local0 = LUI.FlowManager.GetMenuScopedDataFromElement( f7_arg0 )
if not f7_local0.articleIndex then
return
end
DebugPrint( "Action pressed. Category: " .. f7_local0.category .. " Index: " .. f7_local0.articleIndex )
DebugPrint( "Attempting to purchase..." )
if Engine.IsXbox360() then
if f7_local0.category == StoreCategory.Crossgame then
Engine.ExecNow( "downloadSelectedOffer 0x0 " .. StoreCategory.Crossgame )
else
Engine.ExecNow( "downloadSelectedOffer " .. f7_local0.articleId .. " " .. f7_local0.category )
end
elseif Engine.IsPS3() or Engine.IsPS4() then
if f7_local0.category == StoreCategory.Crossgame and Engine.IsPS4() then
Engine.ExecNow( "crossGameSelectedOffer " .. f7_local0.articleId )
elseif f7_local0.articleInfo.purchased then
Engine.ExecNow( "downloadSelectedOffer " .. f7_local0.articleId )
else
Engine.ExecNow( "purchaseSelectedOffer " .. f7_local0.articleId )
end
elseif Engine.IsXB3() then
Engine.ExecNow( "purchaseSelectedOffer " .. f7_local0.articleIndex .. " " .. f7_local0.category )
end
end
function OnAltPressed( f8_arg0, f8_arg1 )
if Sns.IsRedeemCodeDisabled() then
return
else
local f8_local0 = LUI.FlowManager.GetMenuScopedDataFromElement( f8_arg0 )
if not f8_local0.articleIndex and Engine.IsPS3() then
return
else
Engine.Exec( "showTokenRedemptionUI" )
end
end
end
function CategoryFetchCompleted( f9_arg0, f9_arg1 )
DebugPrint( "CategoryFetchCompleted" )
local f9_local0 = LUI.FlowManager.GetMenuScopedDataByMenuName( "store_main" )
local f9_local1
if f9_local0 then
f9_local1 = f9_local0.category
if not f9_local1 then
else
if f9_local1 == f9_arg1.category then
f9_arg0:processEvent( {
name = "refresh_thumbnails"
} )
elseif not Store.HasContentForCategory( f9_local1 ) then
f9_arg0:processEvent( {
name = "show_fetching_metadata"
} )
Store.FetchContentForCategory( f9_local1 )
end
end
end
f9_local1 = StoreCategory.SeasonPass
end
function ThumbnailFeeder( f10_arg0 )
local f10_local0 = LUI.FlowManager.GetMenuScopedDataByMenuName( "store_main" )
local f10_local1 = f10_local0 and f10_local0.category
if not f10_local1 then
if Sns.IsSeasonPassAccessible() then
local f10_local2 = StoreCategory.SeasonPass
end
f10_local1 = f10_local2 or StoreCategory.MapPacks
end
local f10_local3 = {}
local f10_local4 = CrossGameHackData( f10_local1 )
if not f10_local4 and not Store.HasContentForCategory( f10_local1 ) then
DebugPrint( "Fetch content" )
local f10_local5 = Engine.GetLuiRoot()
f10_local5:processEvent( {
name = "show_fetching_metadata",
immediate = true
} )
Store.FetchContentForCategory( f10_local1 )
return f10_local3
end
local f10_local5 = Engine.GetLuiRoot()
f10_local5:processEvent( {
name = "hide_fetching_metadata",
immediate = true
} )
f10_local5 = Store.GetNumItemsInCategory( f10_local1 )
f10_local0.articleCount = f10_local5
for f10_local6 = 0, f10_local5 - 1, 1 do
local f10_local9 = nil
if not f10_local4 then
f10_local9 = Store.GetItemInfoByCategory( f10_local1, f10_local6 )
else
f10_local9 = {
dlcName = "s1",
id = -1,
thumb = "s1",
thumb_name = "s1"
}
end
f10_local3[#f10_local3 + 1] = {
type = "sns_thumbnail",
id = "thumbnail_" .. f10_local6,
listDefaultFocus = f10_local9.dlcName == f10_arg0.initialDlcName,
properties = {
item_id = f10_local9.id,
file_id = f10_local9.thumb,
item_index = f10_local6,
thumbName = f10_local9.thumbName
},
handlers = {
button_over = MBh.EmitEventToRoot( {
name = "change_article",
headerIndex = f10_local6,
itemId = f10_local9.id,
immediate = true
} )
}
}
end
f10_arg0.initialDlcName = ""
return f10_local3
end
function CategoryButtonFactory( f11_arg0, f11_arg1, f11_arg2, f11_arg3 )
if not Store.GetCategoryInfo( f11_arg2 ) then
return nil
else
return {
type = "store_category_button",
id = f11_arg0,
listDefaultFocus = f11_arg2 == f11_arg3,
properties = {
button_text = f11_arg1,
button_over_func = ChangeCategory,
button_action_func = OnActionPressed,
article_category = f11_arg2
}
}
end
end
function CategoryFeeder( f12_arg0 )
local f12_local0 = {}
local f12_local1 = Store.GetCategoryForDLCName( f12_arg0.initialDlcName )
if f12_local1 >= 0 then
local f12_local2 = f12_local1
end
local f12_local3 = f12_local2 or StoreCategory.SeasonPass
if Sns.IsSeasonPassAccessible() then
f12_local0[#f12_local0 + 1] = CategoryButtonFactory( "seasonpass_id", Engine.Localize( "@LUA_MENU_STORE_SEASON_PASS" ), StoreCategory.SeasonPass, f12_local3 )
end
if 1 == Engine.GetDvarInt( "igs_smappacks" ) then
f12_local0[#f12_local0 + 1] = CategoryButtonFactory( "mappacks_id", Engine.Localize( "@LUA_MENU_STORE_MAP_PACKS" ), StoreCategory.MapPacks, f12_local3 )
end
f12_local0[#f12_local0 + 1] = CategoryButtonFactory( "mappacks_id", Engine.Localize( "@LUA_MENU_STORE_MAP_PACKS" ), StoreCategory.MapPacks, f12_local3 )
f12_local0[#f12_local0 + 1] = CategoryButtonFactory( "personalization_id", Engine.Localize( "@LUA_MENU_MP_STORE_PERSONALIZATION_PACKS" ), StoreCategory.Personalization, f12_local3 )
f12_local0[#f12_local0 + 1] = CategoryButtonFactory( "customization_id", Engine.Localize( "@LUA_MENU_STORE_CUSTOMIZATION_PACKS" ), StoreCategory.Customization, f12_local3 )
f12_local0[#f12_local0 + 1] = CategoryButtonFactory( "extraslots_id", Engine.Localize( "@LUA_MENU_MP_STORE_EXTRA_SLOTS" ), StoreCategory.ExtraSlots, f12_local3 )
if 0 ~= Engine.GetDvarInt( "igs_announcer" ) then
f12_local0[#f12_local0 + 1] = CategoryButtonFactory( "voices_id", Engine.Localize( "@LUA_MENU_MP_STORE_ANNOUNCER_VOICES" ), StoreCategory.AnnouncerVoices, f12_local3 )
end
f12_local0[#f12_local0 + 1] = CategoryButtonFactory( "additional_id", Engine.Localize( "@LUA_MENU_MP_STORE_ADDITIONAL_ITEMS" ), StoreCategory.AdditionalItems, f12_local3 )
if Engine.IsXbox360() then
f12_local0[#f12_local0 + 1] = CategoryButtonFactory( "avatar_id", Engine.Localize( "@LUA_MENU_STORE_AVATAR_UNIFORM" ), StoreCategory.Avatar, f12_local3 )
end
if 1 == Engine.GetDvarInt( "igs_crossgame" ) then
f12_local0[#f12_local0 + 1] = CategoryButtonFactory( "crossgame_id", Engine.Localize( "@LUA_MENU_STORE_CROSS_GAME" ), StoreCategory.Crossgame, f12_local3 )
end
return f12_local0
end
function store_category_button()
return {
type = "UIGenericButton",
id = "store_category_button_id",
properties = {
style = GenericButtonSettings.Styles.FlatButton,
substyle = GenericButtonSettings.Styles.FlatButton.SubStyles.SubMenu,
use_locking = false,
article_category = StoreCategory.SeasonPass
},
handlers = {
update_tags = function ( f14_arg0, f14_arg1 )
local f14_local0 = Store.GetCategoryInfo( f14_arg0.properties.article_category )
assert( f14_local0 )
f14_arg0.properties.hasNew = f14_local0.hasNew
f14_arg0.properties.hasSale = f14_local0.hasSale
f14_arg0:dispatchEventToChildren( f14_arg1 )
end
},
children = {
{
type = "UIImage",
id = "store_category_button_new_image_id",
properties = {
article_category = MBh.Property( "article_category" )
},
states = {
default = {
topAnchor = false,
bottomAnchor = false,
leftAnchor = false,
rightAnchor = true,
left = -20,
right = 0,
top = -10,
bottom = 10,
red = 0.5,
green = 0.5,
blue = 0.5,
material = RegisterMaterial( "icon_new" ),
alpha = 1
},
hidden = {
alpha = 0
}
},
handlers = {
update_tags = function ( f15_arg0, f15_arg1 )
local f15_local0 = f15_arg0
local f15_local1 = f15_arg0.animateToState
local f15_local2 = f15_arg0:getParent()
f15_local1( f15_local0, f15_local2.properties.hasNew and "default" or "hidden", 0 )
end
}
},
{
type = "UIImage",
id = "store_category_button_sale_image_id",
properties = {
article_category = MBh.Property( "article_category" )
},
states = {
default = {
topAnchor = false,
bottomAnchor = false,
leftAnchor = false,
rightAnchor = true,
left = -20,
right = 20,
top = -10,
bottom = 10,
red = 0.5,
green = 0.5,
blue = 0.5,
material = RegisterMaterial( "icon_sale" ),
alpha = 1
},
hidden = {
alpha = 0
}
},
handlers = {
update_tags = function ( f16_arg0, f16_arg1 )
local f16_local0 = f16_arg0
local f16_local1 = f16_arg0.animateToState
local f16_local2 = f16_arg0:getParent()
f16_local1( f16_local0, f16_local2.properties.hasSale and "default" or "hidden", 0 )
end
}
}
}
}
end
function store_main()
return {
type = "UIElement",
id = "store_root",
properties = {
initialDlcName = ""
},
states = {
default = {
topAnchor = true,
bottomAnchor = true,
leftAnchor = true,
rightAnchor = true,
top = 0,
bottom = 0,
left = 0,
right = 0
}
},
handlers = {
menu_create = OnCreate,
gain_focus = nil,
update_store_helper_text = UpdateHelperText,
change_article = ChangeArticle,
store_got_metadata = CategoryFetchCompleted,
menu_close = function ( f18_arg0, f18_arg1 )
if Engine.GetDvarString( "ui_contextualMenuLocation" ) == "squad_menu" then
LUI.FlowManager.RequestRestoreMenu( f18_arg0, "menu_xboxlive", false, f18_arg1.controller, false )
end
EndAnnouncerPreviewSound( f18_arg0 )
end
,
purchase_complete = function ( f19_arg0, f19_arg1 )
Sns.UpdateScopedArticleInfo( f19_arg0 )
f19_arg0:dispatchEventToRoot( {
name = "refresh_thumbnails",
immediate = true
} )
end
},
children = {
{
type = "generic_menu_title",
properties = {
menu_title = Engine.Localize( "@LUA_MENU_STORE_CAPS" )
}
},
{
type = "UIImage",
id = "store_playstation_logo_id",
states = {
default = {
topAnchor = true,
bottomAnchor = false,
leftAnchor = false,
rightAnchor = true,
top = 49,
right = -80,
width = 128,
height = 32,
material = RegisterMaterial( "logo_playstation_store" ),
alpha = 0
},
show = {
alpha = 1
}
},
handlers = {
menu_create = function ( f20_arg0, f20_arg1 )
if Engine.IsPS3() or Engine.IsPS4() then
f20_arg0:animateToState( "show", 0 )
end
end
}
},
{
type = "sns_category_window",
id = "store_category_window_id",
properties = {
feeder = CategoryFeeder,
initialDlcName = MBh.Property( "initialDlcName" )
}
},
{
type = "sns_thumbnail_window",
id = "store_thumbnail_window_id",
properties = {
feeder = ThumbnailFeeder,
initialDlcName = MBh.Property( "initialDlcName" )
}
},
{
type = "sns_article",
id = "sns_article_id",
properties = {
additional_handlers = {
refresh_article = RefreshArticle
}
}
},
{
type = "sns_fetching_category_spinner",
id = "sns_fetching_category_spinner_id"
},
{
type = "button_helper_text_main",
id = "store_helper_text_id"
},
{
type = "online_friends_widget",
id = "online_friends_widget_id"
},
{
type = "UIBindButton",
id = "store_bind_button_id",
handlers = {
button_secondary = MBh.LeaveMenu(),
button_alt1 = OnAltPressed
}
}
}
}
end
function store_noguests_error()
return {
type = "generic_confirmation_popup",
id = "store_noguests_error_popup_id",
properties = {
popup_title = Engine.Localize( "@MENU_NOTICE" ),
message_text = Engine.Localize( "@LUA_MENU_STORE_NOGUESTACCOUNTS" )
}
}
end
function store_disabled_error()
return {
type = "generic_confirmation_popup",
id = "store_disabled_error_popup_id",
properties = {
popup_title = Engine.Localize( "@MENU_NOTICE" ),
message_text = Engine.Localize( "@LUA_MENU_STORE_RESTRICTED" )
}
}
end
LUI.MenuBuilder.registerDef( "store_main", store_main )
LUI.MenuBuilder.registerDef( "store_noguests_error", store_noguests_error )
LUI.MenuBuilder.registerDef( "store_disabled_error", store_disabled_error )
LUI.MenuBuilder.registerDef( "store_category_button", store_category_button )
LUI.FlowManager.RegisterStackPushBehaviour( "store_main", function ()
end )
LUI.FlowManager.RegisterStackPopBehaviour( "store_main", function ()
Engine.ExecNow( "decnosplitscreencontrol menu_STORE" )
end )
LockTable( _M )