182 lines
5.9 KiB
Lua
182 lines
5.9 KiB
Lua
|
---@class WB_SelectWeapons_C:UUserWidget
|
||
|
---@field HorizontalBox_Bombs UHorizontalBox
|
||
|
---@field HorizontalBox_Defences UHorizontalBox
|
||
|
---@field HorizontalBox_Medication UHorizontalBox
|
||
|
---@field NewButton_Close UNewButton
|
||
|
---@field TextBlock_SoldierType UTextBlock
|
||
|
---@field TextBlock_WeaponSelect UTextBlock
|
||
|
---@field WB_CommonWeaponList UWB_CommonWeaponList_C
|
||
|
---@field WB_SplitWeaponList UWB_SplitWeaponList_C
|
||
|
---@field WidgetSwitcher_Scrolls UWidgetSwitcher
|
||
|
--Edit Below--
|
||
|
---@type WB_SelectWeapons_C
|
||
|
local WB_SelectWeapons = { bInitDoOnce = false; };
|
||
|
|
||
|
WB_SelectWeapons.CurrClickItem = nil;
|
||
|
WB_SelectWeapons.SelectWeapons = nil;
|
||
|
WB_SelectWeapons.IntervalTime = 0.5;
|
||
|
WB_SelectWeapons.SoldierType = nil;
|
||
|
WB_SelectWeapons.InShowTime = 0;
|
||
|
|
||
|
function WB_SelectWeapons:Construct()
|
||
|
UGCEventSystem.AddListener(EventTypes.UpdateCurrWeapon, self.OnUpdateCurrWeapon, self)
|
||
|
UIManager:Register("WB_SelectWeapons", self);
|
||
|
|
||
|
-- 检查当前是否有 SoldierType
|
||
|
if LocalPlayerKey then
|
||
|
if GlobalMiniMode ~= nil then
|
||
|
local SoldierType = GlobalMiniMode.PlayerSelectSoldiers[LocalPlayerKey];
|
||
|
if SoldierType ~= nil then
|
||
|
self.SoldierType = SoldierType;
|
||
|
self:UpdatePlayerSoldiers(SoldierType);
|
||
|
end
|
||
|
end
|
||
|
end
|
||
|
|
||
|
UITool.BindButtonClicked(self.NewButton_Close, self.OnClosed, self);
|
||
|
|
||
|
-- 初始化一下
|
||
|
self.WB_CommonWeaponList:Init(self, self.OnClickItem);
|
||
|
self.WB_SplitWeaponList:Init(self, self.OnClickItem);
|
||
|
end
|
||
|
|
||
|
function WB_SelectWeapons:OnShowPanel(Time, SoldierType)
|
||
|
UGCLogSystem.Log("[WB_SelectWeapons:OnShowPanel] Time = %s, SoldierType = %s", tostring(Time), tostring(SoldierType));
|
||
|
if Time == nil then
|
||
|
Time = self.InShowTime;
|
||
|
self.NewButton_Close:SetVisibility(ESlateVisibility.Visible);
|
||
|
else
|
||
|
self.InShowTime = Time;
|
||
|
if self.SoldierType ~= SoldierType then
|
||
|
self:UpdatePlayerSoldiers(SoldierType);
|
||
|
end
|
||
|
self.NewButton_Close:SetVisibility(ESlateVisibility.Collapsed);
|
||
|
end
|
||
|
self:OnCloseCountDown(math.abs(Time));
|
||
|
end
|
||
|
|
||
|
function WB_SelectWeapons:UpdatePlayerSoldiers(SoldierType)
|
||
|
self.SoldierType = SoldierType;
|
||
|
if SoldierType ~= nil then
|
||
|
UGCLogSystem.Log("[WB_SelectWeapons:UpdatePlayerSoldiers] SoldierType = %s", tostring(SoldierType))
|
||
|
local Weapons = SoldierConfig[SoldierType].Weapons
|
||
|
self:SetWeaponTypeAndCount(Weapons.Main, Weapons.Count or 1);
|
||
|
self.TextBlock_SoldierType:SetText(SoldierConfig[SoldierType].Info.Name);
|
||
|
self:LoadItems(SoldierType);
|
||
|
end
|
||
|
UGCLogSystem.Log("[WB_SelectWeapons:UpdatePlayerSoldiers] 执行")
|
||
|
end
|
||
|
|
||
|
function WB_SelectWeapons:LoadItems(SoldierType)
|
||
|
UGCLogSystem.Log("[WB_SelectWeapons:LoadItems] 执行")
|
||
|
local Items = {};
|
||
|
-- 添加炸弹
|
||
|
local BombDiff = SoldierConfig[SoldierType].Weapons.Bomb;
|
||
|
-- 此时玩家必须存在
|
||
|
for i, v in pairs(SoldierCommonInfo.Bombs) do
|
||
|
local Count = v;
|
||
|
if BombDiff ~= nil then Count = Count + (BombDiff[i] or 0); end
|
||
|
if Count > 0 then
|
||
|
if EBombType[i] and BombItems[EBombType[i]] then
|
||
|
local ItemId = BombItems[EBombType[i]]
|
||
|
table.insert(Items, {
|
||
|
ItemId = ItemId,
|
||
|
Count = Count,
|
||
|
})
|
||
|
end
|
||
|
end
|
||
|
end
|
||
|
UGCLogSystem.LogTree(string.format("[WB_SelectWeapons:LoadItems] BombsItems"), Items)
|
||
|
self:LoadBoxItems(self.HorizontalBox_Bombs, Items);
|
||
|
|
||
|
Items = {};
|
||
|
local MedicationsDiff = SoldierConfig[SoldierType].Medications
|
||
|
for i, v in pairs(SoldierCommonInfo.Medications) do
|
||
|
local Count = v;
|
||
|
if MedicationsDiff then
|
||
|
Count = Count + (MedicationsDiff[i] or 0);
|
||
|
end
|
||
|
if Count > 0 then
|
||
|
if ESupplyType[i] and SupplyItems[ESupplyType[i]] then
|
||
|
local ItemId = SupplyItems[ESupplyType[i]];
|
||
|
table.insert(Items, {
|
||
|
ItemId = ItemId,
|
||
|
Count = Count;
|
||
|
})
|
||
|
end
|
||
|
end
|
||
|
end
|
||
|
UGCLogSystem.LogTree(string.format("[WB_SelectWeapons:LoadItems] MedicationItems"), Items)
|
||
|
self:LoadBoxItems(self.HorizontalBox_Medication, Items);
|
||
|
|
||
|
local Armors = SoldierConfig[SoldierType].Armors;
|
||
|
if Armors then
|
||
|
self.HorizontalBox_Defences:GetChildAt(0):SetItemId(ArmorItems[Armors[1]]);
|
||
|
self.HorizontalBox_Defences:GetChildAt(1):SetItemId(HelmetItems[Armors[2]]);
|
||
|
end
|
||
|
end
|
||
|
|
||
|
function WB_SelectWeapons:LoadBoxItems(InBox, Items)
|
||
|
UITool.HideAllChildren(InBox);
|
||
|
UITool.AdaptChildren(InBox, #(Items), ObjectPath.WB_SelectWeaponOtherItem);
|
||
|
|
||
|
UITool.ForeachAllChildren(InBox, function(index, Widget)
|
||
|
if Items[index] then
|
||
|
Widget:SetItemId(Items[index].ItemId, Items[index].Count);
|
||
|
Widget:SetVisibility(ESlateVisibility.SelfHitTestInvisible);
|
||
|
else
|
||
|
Widget:SetVisibility(ESlateVisibility.Collapsed);
|
||
|
end
|
||
|
end)
|
||
|
end
|
||
|
|
||
|
function WB_SelectWeapons:SetWeaponTypeAndCount(InTypes, Count)
|
||
|
if Count == 1 then
|
||
|
self.WidgetSwitcher_Scrolls:SetActiveWidgetIndex(0);
|
||
|
self.WB_CommonWeaponList:SetTypes(InTypes);
|
||
|
else
|
||
|
assert(table.getCount(InTypes) > 1);
|
||
|
self.WidgetSwitcher_Scrolls:SetActiveWidgetIndex(1);
|
||
|
self.WB_SplitWeaponList:SetTypes(InTypes);
|
||
|
end
|
||
|
end
|
||
|
|
||
|
--- 倒计时
|
||
|
function WB_SelectWeapons:OnCloseCountDown(InTime)
|
||
|
UGCLogSystem.Log("[WB_SelectWeapons:OnCountDown] InTime = %s", tostring(InTime));
|
||
|
InTime = InTime - 1;
|
||
|
self.TextBlock_WeaponSelect:SetText(string.format("%ds", math.abs(InTime)));
|
||
|
GlobalTickTool:AddInternalCount(self, function(o, dt, ServerTime, t)
|
||
|
o.TextBlock_WeaponSelect:SetText(string.format("%ds", math.abs(math.floor(t))));
|
||
|
end, 1, InTime, function(o)
|
||
|
o:OnClosed();
|
||
|
end);
|
||
|
end
|
||
|
|
||
|
--- 当点击 Item
|
||
|
function WB_SelectWeapons:OnClickItem(SelectIds)
|
||
|
UGCLogSystem.LogTree(string.format("[WB_SelectWeapons:OnClickItem] SelectIds ="), SelectIds)
|
||
|
if GameState then
|
||
|
GameState:SendMiniGameRPC("SelectCurrWeapon", LocalPlayerKey, SelectIds);
|
||
|
end
|
||
|
end
|
||
|
|
||
|
function WB_SelectWeapons:OnClosed()
|
||
|
UGCLogSystem.Log("[WB_SelectWeapons:OnClosed] 当关闭的时候执行")
|
||
|
WidgetManager:ClosePanel(self.UIType);
|
||
|
end
|
||
|
|
||
|
function WB_SelectWeapons:OnUpdateCurrWeapon(InWeapons)
|
||
|
if table.isEmpty(InWeapons) then return ; end
|
||
|
if InWeapons[LocalPlayerKey] then return ; end
|
||
|
end
|
||
|
|
||
|
-- function WB_SelectWeapons:Tick(MyGeometry, InDeltaTime)
|
||
|
|
||
|
-- end
|
||
|
|
||
|
-- function WB_SelectWeapons:Destruct()
|
||
|
|
||
|
-- end
|
||
|
|
||
|
return WB_SelectWeapons;
|