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

97 lines
3.0 KiB
Lua

---@class WB_RangeMinimap_C:UUserWidget
---@field Button_Close UButton
---@field CanvasPanel_Range UCanvasPanel
---@field Image_Range UImage
--Edit Below--
---@type WB_RangeMinimap_C
local WB_RangeMinimap = { bInitDoOnce = false; };
function WB_RangeMinimap:Construct()
self:LuaInit();
end
function WB_RangeMinimap:LuaInit()
if self.bInitDoOnce then return ; end
UITool.BindButtonClicked(self.Button_Close, self.OnClickClose, self)
self:OnClickClose();
self:CreateSomeChildren();
self.bInitDoOnce = true;
end
-- function WB_RangeMinimap:Tick(MyGeometry, InDeltaTime)
-- end
-- function WB_RangeMinimap:Destruct()
-- end
function WB_RangeMinimap:OnClickClose()
if self.CanvasPanel_Range:IsVisible() then
self.CanvasPanel_Range:SetVisibility(ESlateVisibility.Collapsed);
else
self.CanvasPanel_Range:SetVisibility(ESlateVisibility.SelfHitTestInvisible);
end
end
--function WB_RangeMinimap:OnMouseButtonDown(MyGeometry, MouseEvent)
-- --SlateBlueprintLibrary.AbsoluteToLocal(MyGeometry, )
-- local ImageGeo = self.Image_Range:GetCachedGeometry();
-- local ImageSize = SlateBlueprintLibrary.GetLocalSize(ImageGeo);
-- local ImageAbsolutePos = SlateBlueprintLibrary.GetAbsolutePosition(ImageGeo);
-- local LeftUpPos = SlateBlueprintLibrary.AbsoluteToLocal(MyGeometry, ImageAbsolutePos);
--
-- UGCLogSystem.Log("[WB_RangeMinimap:OnMouseButtonDown] 执行 ImageSize = %s", VectorHelper.ToString2D(ImageSize));
-- UGCLogSystem.Log("[WB_RangeMinimap:OnMouseButtonDown] 左上角坐标:%s", VectorHelper.ToString2D(LeftUpPos));
-- return self.SuperClass:OnMouseButtonDown(MyGeometry, MouseEvent);
--end
WB_RangeMinimap.ChildClass = nil;
function WB_RangeMinimap:GetChildClass()
if self.ChildClass == nil then
self.ChildClass = UE.LoadClass(UGCGameSystem.GetUGCResourcesFullPath('Asset/Blueprint/SceneObj/Range/UI/WB_RangeItem.WB_RangeItem_C'))
end
return self.ChildClass;
end
---@type table<int32, UUserWidget>
WB_RangeMinimap.Children = {};
function WB_RangeMinimap:CreateSomeChildren()
for i = 1, 10 do
local Widget = UITool.AddWidgetItem(self.CanvasPanel_Range, self:GetChildClass(), self);
table.insert(self.Children, Widget);
Widget:SetVisibility(ESlateVisibility.Collapsed);
end
-- 拿到子类的大小
self.ChildItemSize = self.Children[1]:GetMainButtonSize();
end
WB_RangeMinimap.ChildItemSize = nil;
function WB_RangeMinimap:SetRangePercent(InPercent)
-- 获取左上角坐标
local Pos = UITool.GetChildLeftUpPos(self.CanvasPanel_Range, self);
local Size = UITool.GetChildWidgetSize(self.CanvasPanel_Range);
local Index = 1;
for i, v in pairs(self.Children) do
v:SetVisibility(ESlateVisibility.Collapsed);
end
for i, v in pairs(InPercent) do
local ItemPos = VectorHelper.Mul2D(Size, v);
local Scale = 1;
local Item = self.Children[Index];
Item:SetVisibility(ESlateVisibility.SelfHitTestInvisible);
Item:SetReflectActor(i);
---@type UCanvasPanelSlot
local Slot = WidgetLayoutLibrary.SlotAsCanvasSlot(Item);
Slot:SetPosition(ItemPos);
Slot:SetSize(self.ChildItemSize);
Index = Index + 1;
end
end
return WB_RangeMinimap;