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

219 lines
7.0 KiB
Lua

---@class WB_SelectWeapons_C:UUserWidget
---@field Button_Select UButton
---@field HorizontalBox_Bombs UHorizontalBox
---@field HorizontalBox_Defences UHorizontalBox
---@field HorizontalBox_Medication UHorizontalBox
---@field ScrollBox_Items UScrollBox
---@field TextBlock_WeaponSelect UTextBlock
--Edit Below--
---@type WB_SelectWeapons_C
local WB_SelectWeapons = { bInitDoOnce = false; };
WB_SelectWeapons.CurrClickItem = nil;
WB_SelectWeapons.SelectWeapons = nil;
WB_SelectWeapons.IntervalTime = 0.5;
function WB_SelectWeapons:Construct()
self:LuaInit();
end
function WB_SelectWeapons:LuaInit()
if self.bInitDoOnce then return ; end
self.bInitDoOnce = true;
UITool.BindButtonClicked(self.Button_Select, self.OnClickSelect, self);
UGCEventSystem.AddListener(EventTypes.UpdateSelectWeapons, self.OnUpdateSelectWeapons, self)
UGCEventSystem.AddListener(EventTypes.UpdateCurrWeapon, self.OnUpdateCurrWeapon, self)
-- 检测玩家当前有多少武器
self:LoadOthers();
end
function WB_SelectWeapons:OnShowPanel(...)
local vars = { ... };
-- 开启倒计时
self:OnCountDown(vars[1]);
--
end
function WB_SelectWeapons:LoadOthers(InList)
if self.bInitDoOnce then return end
UITool.HideAllChildren(self.HorizontalBox_Bombs);
UITool.HideAllChildren(self.HorizontalBox_Defences);
UITool.HideAllChildren(self.HorizontalBox_Medication);
if table.isEmpty(InList) then return ; end
UGCLogSystem.LogTree(string.format("[WB_SelectWeapons:LoadOthers] InList ="), InList)
-- 统计一下
local ItemCount = table.getCount(InList)
local MedTable, Helmet, Armor = {}, 0, 0;
for i = 1, ItemCount do
local ItemId = 0;
local Item = InList[i];
if type(Item[1]) == 'string' then
-- 从表中查询
local TheId = ItemNameTable[Item[1]];
if TheId ~= nil then ItemId = TheId; end
elseif type(Item[1]) == 'number' then
-- 检查是否在
if ItemTable.AllItem[Item[1]] ~= nil then ItemId = Item[1]; end
end
table.insert(MedTable, {
ItemId = ItemId,
Count = Item[2],
});
end
UGCLogSystem.LogTree(string.format("[WB_SelectWeapons:LoadOthers] MedTable ="), MedTable)
local Supplies = {};
-- 检查有多少药品
local YaoPins, Bombs = {}, {};
for i, v in pairs(MedTable) do
local Type = GetCustomItemType(v.ItemId)
local IdType = GetWeaponIdType(v.ItemId);
if Type == ECustomItemType.Supplies then
if Supplies[IdType] == nil then Supplies[IdType] = {}; end
table.insert(Supplies[IdType], {
ItemId = v.ItemId,
Count = v.Count,
})
elseif Type == ECustomItemType.Equipment then
if IdType == 502 then
-- 头盔编号
Helmet = v.ItemId;
elseif IdType == 503 then
-- 护甲编号
Armor = v.ItemId;
end
end
end
local Func = function(InTable, InBox)
if not table.isEmpty(InTable) then
local MediCount = table.getCount(InTable)
UITool.AdaptChildren(InBox, MediCount, nil);
UITool.ForeachAllChildren(InBox, function(index, Widget)
if InTable[index] ~= nil then
Widget:SetItemId(InTable[index].ItemId, InTable[index].Count);
Widget:SetVisibility(ESlateVisibility.SelfHitTestInvisible);
end
end)
end
end
Func(Supplies[EBigSupplyType.Med], self.HorizontalBox_Medication);
Func(Supplies[EBigSupplyType.Bomb], self.HorizontalBox_Bombs);
local Func1 = function(Index, Num)
if Index ~= 0 then
local Item = self.HorizontalBox_Defences:GetChildAt(Num);
Item:SetVisibility(ESlateVisibility.SelfHitTestInvisible);
Item:SetItemId(Index);
end
end
Func1(Helmet, 0)
Func1(Armor, 1)
self.bInitDoOnce = true;
end
WB_SelectWeapons.SetCount = 0;
WB_SelectWeapons.WeaponItems = {};
function WB_SelectWeapons:LoadWeapons(InList)
-- 加载有哪些枪
if table.isEmpty(InList) then
local AllWeapons = GameState:GetMiniInfo("SelectWeapons");
UGCLogSystem.LogTree(string.format("[WB_SelectWeapons:LoadWeapons] AllWeapons ="), AllWeapons)
if table.isEmpty(AllWeapons) then return ; end
InList = AllWeapons[LocalPlayerKey];
-- 从列表中加载有哪些武器
UGCLogSystem.LogTree(string.format("[WB_SelectWeapons:LoadWeapons] SelfWeapons ="), InList)
if table.isEmpty(InList) then return ; end
end
local WeaponCount = table.getCount(InList);
--if self.SetCount > WeaponCount then return; end
UITool.HideAllChildren(self.ScrollBox_Items);
--self.SetCount = WeaponCount;
-- 构造一下
UITool.AdaptChildren(self.ScrollBox_Items, WeaponCount, ObjectPath.WB_SelectWeaponItems);
self.WeaponItems = {};
UGCLogSystem.LogTree(string.format("[WB_SelectWeapons:LoadWeapons] InList ="), InList)
UITool.ForeachAllChildren(self.ScrollBox_Items, function(index, Widget)
Widget:Init(self, self.OnClickItem);
Widget:SetItemId(InList[index]);
if InList[index] then
Widget:SetVisibility(ESlateVisibility.SelfHitTestInvisible);
UGCLogSystem.Log("[WB_SelectWeapons:LoadWeapons] InList[index] = %s", tostring(InList[index]));
self.WeaponItems[InList[index]] = Widget;
end
end);
end
--- 倒计时
function WB_SelectWeapons:OnCountDown(InTime)
UGCLogSystem.Log("[WB_SelectWeapons:OnCountDown] InTime = %s", tostring(InTime));
InTime = InTime - 1;
self.TextBlock_WeaponSelect:SetText(string.format("%ds", InTime));
GlobalTickTool:AddInternalCount(self, function(o, dt, ServerTime, t)
o.TextBlock_WeaponSelect:SetText(string.format("%ds", math.floor(t)));
end, 1, InTime, function(o)
o:OnClosed();
end);
end
WB_SelectWeapons.CurrItem = nil;
--- 当点击 Item
function WB_SelectWeapons:OnClickItem(ChildItem)
if self.CurrItem == ChildItem then return ; end
if self.CurrItem ~= nil then
self.CurrItem:SetSelect(false);
end
self.CurrItem = ChildItem;
self.CurrItem:SetSelect(true);
GameState:SendMiniGameRPC("SelectCurrWeapon", LocalPlayerKey, self.CurrItem:GetItemIds());
end
function WB_SelectWeapons:OnClosed()
UGCLogSystem.Log("[WB_SelectWeapons:OnClosed] 当关闭的时候执行")
WidgetManager:ClosePanel(self.UIType);
if self.CurrItem ~= nil and UE.IsValid(self.CurrItem) then
self.ScrollBox_Items:RemoveChild(self.CurrItem);
GameState:SendMiniGameRPC("SelectCurrWeapon", LocalPlayerKey, self.CurrItem:GetItemIds());
-- 移除
self.WeaponItems[self.CurrItem:GetItemIds()] = nil;
self.CurrItem = nil;
else
-- 发送 RPC
GameState:SendMiniGameRPC("SelectCurrWeapon", LocalPlayerKey, nil);
end
end
function WB_SelectWeapons:OnUpdateSelectWeapons(InList)
if table.isEmpty(InList) then return ; end
-- 进行加载
UGCLogSystem.LogTree(string.format("[WB_SelectWeapons:OnUpdateSelectWeapons] InList ="), InList)
self:LoadWeapons(InList[LocalPlayerKey]);
end
function WB_SelectWeapons:OnUpdateCurrWeapon(InWeapons)
if table.isEmpty(InWeapons) then return ; end
if InWeapons[LocalPlayerKey] then return ; end
local Item = self.WeaponItems[InWeapons[LocalPlayerKey]];
if Item == nil then return end
Item:SetSelect(false)
self.ScrollBox_Items:RemoveChild(Item);
self.WeaponItems[InWeapons[LocalPlayerKey]] = nil;
end
-- function WB_SelectWeapons:Tick(MyGeometry, InDeltaTime)
-- end
-- function WB_SelectWeapons:Destruct()
-- end
return WB_SelectWeapons;