232 lines
9.6 KiB
Lua
Raw Permalink Normal View History

2025-01-04 23:00:19 +08:00
---@class W_GamePreparation_C:UUserWidget
---@field Button_Close UButton
---@field Button_OpenSelect UButton
---@field Button_Select UButton
---@field CanvasPanel_BG UCanvasPanel
---@field CanvasPanel_Select UCanvasPanel
---@field Image_MapBG UImage
---@field Overlay_SelectMapName UOverlay
---@field Overlay_WaitTime UOverlay
---@field ScrollBox_DefaultWeapon UScrollBox
---@field ScrollBox_SelectMapBox UScrollBox
---@field TextBlock_Loading UTextBlock
---@field TextBlock_MapShowName UTextBlock
---@field TextBlock_MapSpecialMode UTextBlock
---@field TextBlock_SelectMapName UTextBlock
---@field TextBlock_WaitTime UTextBlock
---@field TextBlock_WaitTime_Mid 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;
LastSelectMapTime = -1.;
SelectMapType = -1;
bLoading = false;
};
function W_GamePreparation:Construct()
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)
UGCEventSystem.AddListener(EventEnum.SelectMapCallBack, self.ServerSelectMapCallBack, self)
WidgetLibrary.BindButtonClicked(self.Button_Select, self.ClickSelectMap, self)
WidgetLibrary.BindButtonClicked(self.Button_Close, self.ClickCloseSelectMap, self)
WidgetLibrary.BindButtonClicked(self.Button_OpenSelect, self.ClickOpenSelectPanel, self)
WidgetLibrary.TextBlockBindingPropertyText(self.TextBlock_WaitTime, self.TextBlock_WaitTime_Text, self)
WidgetLibrary.TextBlockBindingPropertyText(self.TextBlock_WaitTime_Mid, self.TextBlock_WaitTime_Text, self)
self:AddMapSelectItem()
self:AddWeaponSelectItem()
self:SelectMapCallBack(MapConfig.MapType.Random)
--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()
local MapTypeCount = table.getCount(MapConfig.MapType)
for i = 0, MapTypeCount - 1 do
local MapType = i
if i ~= 0 then
MapType = MapTypeCount - i
end
local MapInfo = MapConfig.MapInfo[MapType]
local MapSelectItem = UserWidget.NewWidgetObjectBP(UGCSystemLibrary.GetLocalPlayerController(), self:GetMapItemClass())
self.ScrollBox_SelectMapBox:AddChild(MapSelectItem)
MapSelectItem:InitSelectItem(MapType, self, self.SelectMapCallBack)
if MapInfo.Icon then
UGCSystemLibrary.LoadAsset(MapInfo.Icon, true)
end
if MapInfo.IconSelect then
UGCSystemLibrary.LoadAsset(MapInfo.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()
local NowTime = UGCSystemLibrary.GetGameTime()
if (NowTime - self.LastSelectMapTime > 1) and table.hasValue(MapConfig.MapType, self.SelectMapType) and MapConfig.MapEnable[self.SelectMapType] then
-- self.TextBlock_MapShowName:SetText(MapConfig.MapInfo[self.SelectMapType].ShowName)
--self.bSelected = true
self.LastSelectMapTime = NowTime
self.WidgetSwitcher_SelectFinish:SetActiveWidgetIndex(1)
UGCSendRPCSystem.ActorRPCNotify(nil, UGCGameSystem.GameState, "PlayerOverlapSelectMap", 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")
-- 防止未关闭UI
self:ServerSelectMapCallBack(true, self.SelectMapType)
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.CanvasPanel_BG: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.MapInfo[SelectMapType].Icon, true))
end
self:SetShowName(SelectMapType)
end
function W_GamePreparation:SetShowName(SelectMapType)
local MapName = MapConfig.MapInfo[SelectMapType].ShowName
local ModeName = MapConfig.SpecialModeName[MapConfig.MapInfo[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:SetSelectingVis(IsVis)
UGCLogSystem.Log("[W_GamePreparation_SetSelectingVis]")
local IsShow = IsVis and ESlateVisibility.SelfHitTestInvisible or ESlateVisibility.Collapsed
self.CanvasPanel_Select:SetVisibility(IsShow)
self.CanvasPanel_BG:SetVisibility(IsShow)
end
function W_GamePreparation:ClickOpenSelectPanel()
self:SetSelectingVis(true)
end
function W_GamePreparation:ClickCloseSelectMap()
self:SetSelectingVis(false)
end
function W_GamePreparation:ServerSelectMapCallBack(bIsSucceed, InSelectMapType)
local MapInfo = MapConfig.MapInfo[InSelectMapType]
if MapInfo then
self.TextBlock_SelectMapName:SetText(MapInfo.ShowName)
if MapInfo.SpecialModeType ~= MapConfig.ESpecialModeType.Default then
self.TextBlock_MapSpecialMode:SetText(string.format(" (%s)", MapConfig.SpecialModeName[MapInfo.SpecialModeType]))
else
self.TextBlock_MapSpecialMode:SetText("")
end
UGCLogSystem.Log("[W_GamePreparation_ServerSelectMapCallBack]")
self:SetSelectingVis(false)
else
UGCLogSystem.LogError("[W_GamePreparation_ServerSelectMapCallBack] InSelectMapType:%s", tostring(InSelectMapType))
end
end
-- function W_GamePreparation:Destruct()
-- end
return W_GamePreparation;