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

177 lines
7.4 KiB
Lua

---@class W_GamePreparation_C:UUserWidget
---@field Button_Select UButton
---@field CanvasPanel_Select UCanvasPanel
---@field Image_7 UImage
---@field Image_MapBG UImage
---@field ScrollBox_DefaultWeapon UScrollBox
---@field ScrollBox_SelectMapBox UScrollBox
---@field TextBlock_Loading UTextBlock
---@field TextBlock_MapShowName UTextBlock
---@field TextBlock_WaitTime UTextBlock
---@field VerticalBox_Loading UVerticalBox
---@field WB_RandomSelectPlayerVoteMap UWB_RandomSelectPlayerVoteMap_C
---@field WidgetSwitcher_MapBG UWidgetSwitcher
---@field WidgetSwitcher_SelectFinish UWidgetSwitcher
--Edit Below--
---@type W_GamePreparation_C
local W_GamePreparation = {
bInitDoOnce = false;
bSelected = false;
SelectMapType = -1;
bLoading = false;
};
function W_GamePreparation:Construct()
self.TextBlock_WaitTime:BindingProperty("Text", self.TextBlock_WaitTime_Text, self)
UGCEventSystem.AddListener(EventEnum.GameWillBegin, self.GameWillBegin, self)
UGCEventSystem.AddListener(EventEnum.LoadMap, self.LoadingMap, self)
UGCEventSystem.AddListener(EventEnum.GameStateChange, self.RemoveSelf, self)
UGCEventSystem.AddListener(EventEnum.RandomSelectVoteMap, self.RandomSelectVoteMap, self)
WidgetLibrary.BindButtonClicked(self.Button_Select, self.ClickSelectMap, self)
self:AddMapSelectItem()
self:AddWeaponSelectItem()
self:SelectMapCallBack(MapConfig.MapType.Level1)
local LoadMapType = UGCGameSystem.GameState:GetMapSelectionResult(false)
if LoadMapType ~= nil then
self:LoadingMap(LoadMapType)
end
end
function W_GamePreparation:OnClosePanel()
UGCLogSystem.Log("[W_GamePreparation_OnClosePanel]")
self.bLoading = false
WidgetManager:DestroyPanel(WidgetConfig.EUIType.WaitingTime)
end
function W_GamePreparation:RemoveSelf(NewGameState)
if NewGameState ~= CustomEnum.EGameState.Waiting and UE.IsValid(self) then
UGCEventSystem.SetTimer(self, self.OnClosePanel, GlobalConfigs.GameSetting.ClientLoadMapTime)
end
end
function W_GamePreparation:TextBlock_WaitTime_Text(ReturnValue)
return tostring(UGCGameSystem.GameState.WaitPlayerJoinTime)
end
function W_GamePreparation:GameWillBegin()
UGCLogSystem.Log("[W_GamePreparation_GameWillBegin]")
UGCEventSystem.SendEvent(EventEnum.AddTip, TipConfig.TipType.GameWillStart)
end
function W_GamePreparation:AddWeaponSelectItem()
for i, TempWeaponID in pairs(WeaponGradientTable.DefaultWeapon) do
local WeaponSelectItem = UserWidget.NewWidgetObjectBP(UGCSystemLibrary.GetLocalPlayerController(), self:GetWeaponItemClass())
self.ScrollBox_DefaultWeapon:AddChild(WeaponSelectItem)
WeaponSelectItem:InitDefaultWeapon(TempWeaponID, self, self.SelectWeaponCallBack)
if i == 1 then
self.WeaponID = TempWeaponID
WeaponSelectItem:SetSelect(true)
else
WeaponSelectItem:SetSelect(false)
end
end
end
function W_GamePreparation:AddMapSelectItem()
for i, v in pairs(MapConfig.GetMultiModeMapInfo()) do
local MapSelectItem = UserWidget.NewWidgetObjectBP(UGCSystemLibrary.GetLocalPlayerController(), self:GetMapItemClass())
self.ScrollBox_SelectMapBox:AddChild(MapSelectItem)
MapSelectItem:InitSelectItem(i, self, self.SelectMapCallBack)
--local ItemHorizontalBoxSlot = WidgetLayoutLibrary.SlotAsHorizontalBoxSlot(MapSelectItem)
--ItemHorizontalBoxSlot:SetSize({Value = 1.0, SizeRule = ESlateSizeRule.Fill})
if v.Icon then
UGCSystemLibrary.LoadAsset(v.Icon, true)
end
if v.IconSelect then
UGCSystemLibrary.LoadAsset(v.IconSelect, true)
end
end
end
function W_GamePreparation:GetMapItemClass()
if self.ItemClass == nil then
self.ItemClass = UE.LoadClass(UGCGameSystem.GetUGCResourcesFullPath('Asset/UI/StatusUI/GamePreparation/W_SelectMapItem.W_SelectMapItem_C'))
end
return self.ItemClass
end
function W_GamePreparation:GetWeaponItemClass()
if self.WeaponItemClass == nil then
self.WeaponItemClass = UE.LoadClass(UGCGameSystem.GetUGCResourcesFullPath('Asset/UI/StatusUI/GamePreparation/WB_SelectDefaultWeapon.WB_SelectDefaultWeapon_C'))
end
return self.WeaponItemClass
end
function W_GamePreparation:SelectMapCallBack(InSelectMapType)
self.SelectMapType = InSelectMapType
for i = 0, self.ScrollBox_SelectMapBox:GetChildrenCount() - 1 do
local SelectMapItem = self.ScrollBox_SelectMapBox:GetChildAt(i)
SelectMapItem:SetSelect(self.SelectMapType == SelectMapItem:GetSelectMapType())
end
self:SetMapSelect(self.SelectMapType)
end
function W_GamePreparation:SelectWeaponCallBack(InWeaponID)
self.WeaponID = InWeaponID
UGCLogSystem.Log("[W_GamePreparation_SelectWeaponCallBack] InWeaponID:%s", tostring(InWeaponID))
for i = 0, self.ScrollBox_DefaultWeapon:GetChildrenCount() - 1 do
local SelectWeaponItem = self.ScrollBox_DefaultWeapon:GetChildAt(i)
SelectWeaponItem:SetSelect(self.WeaponID == SelectWeaponItem:GetWeaponID())
end
end
function W_GamePreparation:ClickSelectMap()
if (not self.bSelected) and table.hasValue(MapConfig.MapType, self.SelectMapType) and MapConfig.GetMultiModeMapEnable()[self.SelectMapType] then
-- self.TextBlock_MapShowName:SetText(MapConfig.GetMultiModeMapInfo()[self.SelectMapType].ShowName)
self.bSelected = true
self.WidgetSwitcher_SelectFinish:SetActiveWidgetIndex(1)
UGCSendRPCSystem.ActorRPCNotify(nil, UGCGameSystem.GameState, "PlayerSelectMap", UGCSystemLibrary.GetLocalPlayerKey(), self.SelectMapType)
UGCSendRPCSystem.ActorRPCNotify(nil, UGCGameSystem.GameState, "PlayerSelectDefaultWeapon", UGCSystemLibrary.GetLocalPlayerKey(), self.WeaponID)
SoundSystem.PlaySound(SoundSystem.ESound.Btn)
UGCLogSystem.Log("[W_GamePreparation_ClickSelectMap] Finish")
end
end
function W_GamePreparation:LoadingMap(LoadMapType)
self.WB_RandomSelectPlayerVoteMap:SetVisibility(ESlateVisibility.Collapsed)
self.CanvasPanel_Select:SetVisibility(ESlateVisibility.Collapsed)
self.VerticalBox_Loading:SetVisibility(ESlateVisibility.SelfHitTestInvisible)
self.bLoading = true
self:SetMapSelect(LoadMapType)
UGCGameSystem.GameState:LoadNowMiniMap()
end
function W_GamePreparation:SetMapSelect(SelectMapType)
UGCLogSystem.Log("[W_GamePreparation_SetMapSelect] SelectMapType:%s", tostring(SelectMapType))
if SelectMapType == MapConfig.MapType.Random then
self.WidgetSwitcher_MapBG:SetActiveWidgetIndex(1)
else
self.WidgetSwitcher_MapBG:SetActiveWidgetIndex(0)
self.Image_MapBG:SetBrushFromTexture(UGCSystemLibrary.LoadAsset(MapConfig.GetMultiModeMapInfo()[SelectMapType].Icon, true))
end
self:SetShowName(SelectMapType)
end
function W_GamePreparation:SetShowName(SelectMapType)
local MapName = MapConfig.GetMultiModeMapInfo()[SelectMapType].ShowName
local ModeName = MapConfig.SpecialModeName[MapConfig.GetMultiModeMapInfo()[SelectMapType].SpecialModeType]
if ModeName and ModeName ~= "" then
MapName = string.format("%s - ( %s )", MapName, ModeName)
end
self.TextBlock_MapShowName:SetText(MapName)
end
function W_GamePreparation:RandomSelectVoteMap(MapList, InTargetIndex)
self.WB_RandomSelectPlayerVoteMap:SetVisibility(ESlateVisibility.SelfHitTestInvisible)
self.WB_RandomSelectPlayerVoteMap:ShowVoteRandomMap(MapList, InTargetIndex, GlobalConfigs.GameSetting.RollMapTime)
end
-- function W_GamePreparation:Destruct()
-- end
return W_GamePreparation;