2025-01-04 23:00:19 +08:00

273 lines
9.5 KiB
Lua

---@class W_WeaponShop_C:UUserWidget
---@field ShowShopPanel UWidgetAnimation
---@field Button_BuyProp UButton
---@field Button_BuyWeapon UButton
---@field Button_Close UButton
---@field Button_Save UButton
---@field Button_Select UButton
---@field Button_ShopShow UButton
---@field CanvasPanel_Main UCanvasPanel
---@field HorizontalBox_Props UHorizontalBox
---@field Image_0 UImage
---@field Image_1 UImage
---@field Image_2 UImage
---@field Image_ItemTexBig UImage
---@field Image_ItemTexSmall UImage
---@field Image_Tip1 UImage
---@field Image_Tip2 UImage
---@field TextBlock_ItemName UTextBlock
---@field TextBlock_money UTextBlock
---@field TextBlock_PropPrice UTextBlock
---@field TextBlock_Rewards UTextBlock
---@field TextBlock_Time UTextBlock
---@field TextBlock_WeaponPrice UTextBlock
---@field W_CenterScrollBoxType1 UW_CenterScrollBox_C
---@field W_CenterScrollBoxType2 UW_CenterScrollBox_C
---@field WidgetSwitcher_SelectItemTex UWidgetSwitcher
--Edit Below--
---@type W_WeaponShop_C
local W_WeaponShop = {
bInitDoOnce = false;
-- Select
Type1Path = UGCGameSystem.GetUGCResourcesFullPath('Asset/UI/Shop/W_WeaponShopWeaponType.W_WeaponShopWeaponType_C');
Type2Path = UGCGameSystem.GetUGCResourcesFullPath('Asset/UI/Shop/W_WeaponShopWeaponInst.W_WeaponShopWeaponInst_C');
SelectType1 = nil;
SelectType2 = nil;
SelectItemID= nil;
ScrollSoundType = SoundSystem.ESound.Click;
SelectItemSoundType = SoundSystem.ESound.Btn;
ItemsCol = 3;
SelectItemNumRangeMax = 200;
SelectItemNumRange = 1;
SelectItemNum = 1;
};
function W_WeaponShop:Construct()
self:LuaInit();
end
function W_WeaponShop:OnShowPanel()
-- self:ShowHideWidget()
if self.LoopUpdateCountHandle == nil then
self.LoopUpdateCountHandle = UGCEventSystem.SetTimerLoop(self, self.UpdateItemShowCount, 1.)
end
-- self:PlayAnimation(self.ShowShopPanel, 0, 1, EUMGSequencePlayMode.Forward, 1.)
end
function W_WeaponShop:OnClosePanel()
if self.LoopUpdateCountHandle then
UGCEventSystem.StopTimer(self.LoopUpdateCountHandle)
self.LoopUpdateCountHandle = nil
end
end
function W_WeaponShop:Tick(MyGeometry, InDeltaTime)
end
function W_WeaponShop:CloseSelf()
--if self.CanvasPanel_Main:IsVisible() then
-- self.CanvasPanel_Main:SetVisibility(ESlateVisibility.Collapsed)
-- self.Button_ShopShow:SetVisibility(ESlateVisibility.Visible)
--else
-- self.CanvasPanel_Main:SetVisibility(ESlateVisibility.SelfHitTestInvisible)
-- self.Button_ShopShow:SetVisibility(ESlateVisibility.Collapsed)
--end
WidgetManager:ClosePanel(WidgetConfig.EUIType.Shop)
end
-- function W_WeaponShop:Destruct()
-- end
-- [Editor Generated Lua] function define Begin:
function W_WeaponShop:LuaInit()
if self.bInitDoOnce then
return;
end
self.bInitDoOnce = true;
--self.Button_Close.OnClicked:Add(self.ShowHideWidget, self)
--self.Button_ShopShow.OnClicked:Add(self.ShowHideWidget, self)
--self.Button_Select.OnClicked:Add(self.Buy, self)
WidgetLibrary.BindButtonClicked(self.Button_Close, self.CloseSelf, self)
--WidgetLibrary.BindButtonClicked(self.Button_Select, self.Buy, self)
WidgetLibrary.BindButtonClicked(self.Button_BuyWeapon, self.BuyWeapon, self)
WidgetLibrary.BindButtonClicked(self.Button_BuyProp, self.BuyParts, self)
UGCEventSystem.AddListener(EventEnum.PlayerBuyCallBack, self.ShowBuyCallBack, self)
UGCEventSystem.AddListener(EventEnum.PlayerGoldCoinChange, self.UpdateMoney, self)
self:InitParam()
end
function W_WeaponShop:InitParam()
self:InitDownLoadIcon()
self:InitHorizontalBox_Props()
self:UpdateMoney()
-- 隔帧初始化
UGCEventSystem.SetTimer(self,
function()
self.W_CenterScrollBoxType1:Init(UE.LoadClass(self.Type1Path), 70., "InitSelectInfo", "SetSelect", "Button_ItemType")
self.W_CenterScrollBoxType2:Init(UE.LoadClass(self.Type2Path), 70., "InitSelectInfo", "SetSelect", "Button_ItemType")
self.W_CenterScrollBoxType1:BindUpdateSelectItem(self.UpdateSelectType2Item, self)
self.W_CenterScrollBoxType2:BindUpdateSelectItem(self.UpdateSelectItem, self)
self:InitType1()
end,
0.1
)
end
function W_WeaponShop:InitHorizontalBox_Props()
for i = 1, self.HorizontalBox_Props:GetChildrenCount() do
local Item = self.HorizontalBox_Props:GetChildAt(i - 1)
Item:Init(i)
end
end
function W_WeaponShop:InitDownLoadIcon()
for _, ItemInfo in pairs(ItemTable.AllItem) do
UGCSystemLibrary.LoadAsset(ItemInfo.SmallPic, true)
if ItemInfo.BigPic then
UGCSystemLibrary.LoadAsset(ItemInfo.BigPic, true)
end
end
end
function W_WeaponShop:InitType1()
local ItemParams = {}
for k, v in pairs(WeaponShopTable.ShopWeaponType) do
local ItemParam = {v}
ItemParams[#ItemParams + 1] = ItemParam
end
self.W_CenterScrollBoxType1:UpdateItemInfo(ItemParams)
self.W_CenterScrollBoxType1:ScrollToMidItem()
end
--- 更新二级类Item
function W_WeaponShop:UpdateSelectType2Item(SelectItem, SelectIndex)
SoundSystem.PlaySound(self.ScrollSoundType)
self.SelectType1 = SelectItem:GetItemKey()
self:InitType2(self.SelectType1)
end
function W_WeaponShop:InitType2(Type1Select)
local ItemParams = {}
for k, v in pairs(WeaponShopTable.WeaponShopInfo[Type1Select]) do
local ItemParam = {v}
ItemParams[#ItemParams + 1] = ItemParam
end
self.W_CenterScrollBoxType2:UpdateItemInfo(ItemParams)
self.W_CenterScrollBoxType2:ScrollToMidItem()
UGCLogSystem.Log("[W_WeaponShop_InitType2] Finish")
end
--- 更新可选择的Item
function W_WeaponShop:UpdateSelectItem(SelectItem, SelectIndex)
SoundSystem.PlaySound(self.ScrollSoundType)
self.SelectType2 = SelectItem:GetItemKey()
self:UpdateSelectItemInfo()
end
function W_WeaponShop:ShowBuyCallBack(bBuySucceed)
--local TipStr = (bBuySucceed and "购买成功" or "购买失败")
--UGCEventSystem.SendEvent(EventEnum.AddTip, TipStr, 2)
-- UGCWidgetManagerSystem.ShowTipsUI((bBuySucceed and "购买成功" or "金额不足"))
if bBuySucceed then
UGCEventSystem.SendEvent(EventEnum.AddTip, TipConfig.TipType.BuySucceed)
SoundSystem.PlaySound(SoundSystem.ESound.Buy)
else
UGCEventSystem.SendEvent(EventEnum.AddTip, TipConfig.TipType.BuyFailure)
SoundSystem.PlaySound(SoundSystem.ESound.Error)
end
end
function W_WeaponShop:Buy()
SoundSystem.PlaySound(SoundSystem.ESound.Btn)
if self.SelectItemID then
UGCSendRPCSystem.ActorRPCNotify(nil, UGCGameSystem.GameState, "PlayerBuy", UGCSystemLibrary.GetLocalPlayerKey(), self.SelectItemID, self.SelectItemNum)
end
end
function W_WeaponShop:BuyWeapon()
SoundSystem.PlaySound(SoundSystem.ESound.Btn)
UGCSendRPCSystem.ActorRPCNotify(nil, UGCGameSystem.GameState, "PlayerBuyWeapon", UGCSystemLibrary.GetLocalPlayerKey(), self.SelectType2, false)
end
function W_WeaponShop:BuyParts()
SoundSystem.PlaySound(SoundSystem.ESound.Btn)
UGCSendRPCSystem.ActorRPCNotify(nil, UGCGameSystem.GameState, "PlayerBuyWeapon", UGCSystemLibrary.GetLocalPlayerKey(), self.SelectType2, true)
end
-------------------------------------------------------- Item Info 右栏目 --------------------------------------------------------
function W_WeaponShop:UpdateSelectItemInfo()
local ItemInfo = ItemTable.AllItem[self.SelectType2]
self.TextBlock_ItemName:SetText(ItemInfo.Name)
self.TextBlock_WeaponPrice:SetText(WeaponShopTable.ItemPrice[self.SelectType2])
self.TextBlock_Rewards:SetText(WeaponShopTable.WeaponKillRewards[self.SelectType2])
if ItemInfo.BigPic then
self.Image_ItemTexBig:SetBrushFromTexture(UGCSystemLibrary.LoadAsset(ItemInfo.BigPic, true))
self.WidgetSwitcher_SelectItemTex:SetActiveWidgetIndex(1)
else
self.Image_ItemTexSmall:SetBrushFromTexture(UGCSystemLibrary.LoadAsset(ItemInfo.SmallPic, true))
self.WidgetSwitcher_SelectItemTex:SetActiveWidgetIndex(0)
end
local PartIDs = WeaponTable.GetRecommendedWeaponParts(self.SelectType2)
self.TextBlock_PropPrice:SetText(WeaponShopTable.GetPropsPrice(PartIDs))
local PartMaps = {}
if PartIDs ~= nil then
for i, v in pairs(PartIDs) do
PartMaps[WeaponTable.GetPartType(v)] = v
end
end
for i = 1, self.HorizontalBox_Props:GetChildrenCount() do
local Item = self.HorizontalBox_Props:GetChildAt(i - 1)
if PartMaps[i] then
Item:SetHasPart(true, PartMaps[i])
else
Item:SetHasPart(false)
end
end
-- self:UpdateBuyItemNumRange()
end
function W_WeaponShop:UpdateMoney()
self.TextBlock_money:SetText(tostring(UGCGameSystem.GameState:GetPlayerCoin(UGCSystemLibrary.GetLocalPlayerKey())))
end
function W_WeaponShop:UpdateItemShowCount()
for i = 1, self.HorizontalBox_Props:GetChildrenCount() do
local Item = self.HorizontalBox_Props:GetChildAt(i - 1)
Item:UpdateCount()
end
local WeaponCount = self.W_CenterScrollBoxType2:GetEnableItemNum()
for i = 1, WeaponCount do
local Item = self.W_CenterScrollBoxType2:GetScrollItem(i - 1)
Item:UpdateCount()
end
end
-------------------------------------------------------------------------------------------------------------------------------------------------
function W_WeaponShop:UpdateBuyItemNumRange()
local ItemPrice = ItemTable.GetItemPrice(self.SelectItemID)
local HasMoney = UGCGameSystem.GameState:GetPlayerCoin(UGCSystemLibrary.GetLocalPlayerKey())
end
return W_WeaponShop;