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

238 lines
7.4 KiB
Lua
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

---@class WB_SelectSoldier_C:UUserWidget
---@field Button_Back UButton
---@field Button_Select UButton
---@field HorizontalBox_HadSelected UHorizontalBox
---@field NewButton_Settings UNewButton
---@field ScrollBox_Type UScrollBox
---@field TextBlock_CountDown UTextBlock
---@field TextBlock_Load UTextBlock
---@field TextBlock_Tip UTextBlock
---@field TextBlock_Type UTextBlock
---@field TextBlock_WaitTime UTextBlock
---@field VerticalBox_Diff UVerticalBox
---@field VerticalBox_TeamPlayerSoldier UVerticalBox
--Edit Below--
---@type WB_SelectSoldier_C
local WB_SelectSoldier = { bInitDoOnce = false; };
function WB_SelectSoldier:Construct()
print(string.format('[WB_SelectSoldier:Construct] 执行'))
UITool.BindButtonClicked(self.Button_Select, self.OnClickSelect, self);
UITool.BindButtonClicked(self.NewButton_Settings, self.OpenSettings, self);
UGCEventSystem.AddListener(EventTypes.UpdateWaitingTime, self.UpdateWaitTime, self);
--self.HorizontalBox_HadSelected:SetVisibility(ESlateVisibility.Collapsed);
UGCEventSystem.AddListener(EventTypes.UpdateNewTeams, self.UpdatePlayerTeams, self);
self.TextBlock_Load:SetVisibility(ESlateVisibility.Collapsed);
end
WB_SelectSoldier.CurrentSelectType = nil;
function WB_SelectSoldier:OnShowPanel(...)
UGCLogSystem.Log("[WB_SelectSoldier:OnShowPanel] 执行")
-- 查找对应的数组
local WidgetItemCount = self.ScrollBox_Type:GetChildrenCount();
-- 进行排序
local Table = {};
for Type, Str in pairs(SoldierConfig.Chinese) do
Table[#Table + 1] = { Type = Type };
end
table.sort(Table, function(a, b)
if SoldierConfig.InitShowTypes[a.Type] then
if SoldierConfig.InitShowTypes[b.Type] then
return SoldierConfig.UnlockScore[a.Type].Score < SoldierConfig.UnlockScore[b.Type].Score;
else
return true;
end
else
if SoldierConfig.InitShowTypes[b.Type] then
return false;
else
return SoldierConfig.UnlockScore[a.Type].Score < SoldierConfig.UnlockScore[b.Type].Score
end
end
end);
local Count = 0;
for i, v in pairs(Table) do
local Item;
if Count < WidgetItemCount then
Item = self.ScrollBox_Type:GetChildAt(Count);
Item:SetVisibility(ESlateVisibility.SelfHitTestInvisible);
else
Item = UITool.AddWidgetItem(self.ScrollBox_Type, ObjectPath.WB_SelectSolider_Item, self);
end
Item:SetParentWidget(self);
Item:SetSoldierType(v.Type);
Count = Count + 1;
end
-- 初始化显示
for i = 1, self.VerticalBox_Diff:GetChildrenCount() do
local Item = self.VerticalBox_Diff:GetChildAt(i - 1);
Item:SetInfoName(i);
end
-- 所有子项全部设置为不可点击
for i = 1, self.ScrollBox_Type:GetChildrenCount() do
local Item = self.ScrollBox_Type:GetChildAt(i - 1);
Item:SetButtonEnable(true);
end
end
function WB_SelectSoldier:OnClickSelect()
if self.CurrentSelectType == nil then
return ;
end
-- 发送 RPC
UGCLogSystem.Log("[WB_SelectSoldier:OnClickSelect] 执行");
UGCSendRPCSystem.ActorRPCNotify(nil, UGCGameSystem.GameState, "Server_SelectSoldier", LocalPlayerKey, self.CurrentSelectType);
-- 提示选择的职业
UGCWidgetManagerSystem.ShowTipsUI(string.format("当前选择 %s", SoldierConfig.Chinese[self.CurrentSelectType]));
local ChildrenCount = self.ScrollBox_Type:GetChildrenCount()
for i = 0, ChildrenCount - 1 do
local Item = self.ScrollBox_Type:GetChildAt(i);
Item:SetSubmitSelect(self.CurrentSelectType);
end
SoundSystem.PlaySound(SoundSystem.ESound.OK);
end
function WB_SelectSoldier:OpenSettings()
local MainControlPanel = GameBusinessManager.GetWidgetFromName(ingame, "MainControlPanelTochButton_C");
if MainControlPanel then
MainControlPanel.MainControlBaseUI:OpenSettingPanel();
if self.DoOnceOpenSettingPanel then
MainControlPanel.MainControlBaseUI:OpenSettingPanel();
else
self.DoOnceOpenSettingPanel = true
end
end
end
function WB_SelectSoldier:Tick(MyGeometry, InDeltaTime)
self:Loading(InDeltaTime);
end
-- function WB_SelectSoldier:Destruct()
-- end
--- 到时间的时候自动设置
--- @param InList table<int32, int32> 玩家兵种类型
function WB_SelectSoldier:OnSelectSoldierType(InList)
local LocalTeamId = UGCGameSystem.GameState:GetPlayerTeamId(LocalPlayerKey);
local Players = {};
for i, v in pairs(InList) do
local TeamId = UGCGameSystem.GameState:GetPlayerTeamId(i);
if TeamId == LocalTeamId then
Players[i] = v;
end
end
-- 设置到
UGCEventSystem.SendEvent(EventTypes.UpdatePlayerSoldiers, Players);
end
WB_SelectSoldier.CurrItem = nil;
-- 当点击了某个子控件,该函数作为子控件的回调函数
function WB_SelectSoldier:SetClickItemType(InItem, InType)
if self.CurrItem ~= nil then self.CurrItem:SetSelect(false) end
self.CurrItem = InItem;
self.CurrItem:SetSelect(true);
self.CurrentSelectType = InType;
-- 下面的描述显示一下对应描述
self.HorizontalBox_HadSelected:SetVisibility(ESlateVisibility.SelfHitTestInvisible);
self.TextBlock_Type:SetText(SoldierConfig.Chinese[InType]);
local ChildrenCount = self.ScrollBox_Type:GetChildrenCount();
for i = 0, ChildrenCount - 1 do
local Item = self.ScrollBox_Type:GetChildAt(i);
Item:SetClickSelect(InType);
end
self:UpdateSoldierDiff(InType);
self:OnClickSelect();
end
function WB_SelectSoldier:UpdatePlayerTeams(PlayerTeams)
if DefaultSettings.LocalTeamId then
local TeamPlayers = PlayerTeams[DefaultSettings.LocalTeamId];
local ChildrenCount = self.VerticalBox_TeamPlayerSoldier:GetChildrenCount();
for i = 0, ChildrenCount - 1 do
local Item = self.VerticalBox_TeamPlayerSoldier:GetChildAt(i);
if TeamPlayers and TeamPlayers[i + 1] then
Item:SetVisibility(ESlateVisibility.SelfHitTestInvisible);
Item:SetTargetPlayer(TeamPlayers[i + 1]);
else
Item:SetVisibility(ESlateVisibility.Hidden);
end
end
end
end
--- 更新兵种
--- 更新差异
function WB_SelectSoldier:UpdateSoldierDiff(InType)
for i = 1, self.VerticalBox_Diff:GetChildrenCount() do
local Item = self.VerticalBox_Diff:GetChildAt(i - 1);
Item:SetSoldierType(InType, i);
end
end
function WB_SelectSoldier:UpdateWaitTime(NewTime)
-- 显示出来
UGCLogSystem.Log("[WB_SelectSoldier:UpdateWaitTime] 当前时间:%0.f", NewTime);
self.HorizontalBox_HadSelected:SetVisibility(ESlateVisibility.SelfHitTestInvisible);
local Time = math.floor(math.clamp(NewTime - 1, 0, NewTime));
self.TextBlock_WaitTime:SetText(Time);
UGCLogSystem.Log("[WB_SelectSoldier:UpdateWaitTime] 当前时间1111%0.f", Time);
self.TextBlock_CountDown:SetText(Time);
if Time <= 0 then
-- 启动
self.bShowLoading = true;
self.TextBlock_Load:SetVisibility(ESlateVisibility.SelfHitTestInvisible);
self.Button_Select:SetIsEnabled(false);
-- 所有子项全部设置为不可点击
for i = 1, self.ScrollBox_Type:GetChildrenCount() do
local Item = self.ScrollBox_Type:GetChildAt(i - 1);
Item:SetButtonEnable(false);
end
end
end
WB_SelectSoldier.bIsOnce = false;
WB_SelectSoldier.bShowLoading = false;
WB_SelectSoldier.AddPoint = 0.85;
WB_SelectSoldier.PointCount = 0.;
WB_SelectSoldier.TotalPointCount = 3;
WB_SelectSoldier.CurrCount = 0;
function WB_SelectSoldier:Loading(InDeltaTime)
if self.bIsOnce then
return ;
end
if not self.bShowLoading then
return
end
self.PointCount = self.PointCount + InDeltaTime;
if self.PointCount > self.AddPoint then
self.PointCount = self.PointCount - self.AddPoint;
local s = '加载中'
for i = 1, self.CurrCount + 1 do
s = s .. '. '
end
self.CurrCount = (self.CurrCount + 1) % self.TotalPointCount;
self.TextBlock_Load:SetText(s);
end
end
return WB_SelectSoldier;