267 lines
8.8 KiB
Lua
267 lines
8.8 KiB
Lua
---@class WBP_WeaponFittingItem_C:UAEUserWidget
|
||
---@field CanvasPanel_Main UCanvasPanel
|
||
---@field ItemIconAndBG UWBP_WeaponItemFitting_C
|
||
---@field TextBlock_ItemCount UTextBlock
|
||
---@field TextBlock_ItemType UTextBlock
|
||
---@field TextBlock_Quality UTextBlock
|
||
--Edit Below--
|
||
local WBP_WeaponFittingItem = {
|
||
bInitDoOnce = false;
|
||
-- 拖拽数据的类
|
||
DragDropClass = nil,
|
||
--拖拽显示的类
|
||
DragVisualClass = nil,
|
||
-- 存放的物品数据
|
||
FittingData = nil,
|
||
--是否正在点击按钮
|
||
bClickLeftButton = false,
|
||
--按压时间
|
||
PressTime = 0,
|
||
--按压多长时间之后会执行操作
|
||
FunctionPressTime = 0.6,
|
||
|
||
bStartMove = false,
|
||
bFirstButtonClick = false,
|
||
VisualWidget = nil,
|
||
|
||
DragTimerHandler = nil;
|
||
};
|
||
|
||
function WBP_WeaponFittingItem:Construct()
|
||
print(string.format("[WBP_WeaponFittingItem:Construct] 执行构造"))
|
||
self.DragDropClass = UE.LoadClass(UGCGameSystem.GetUGCResourcesFullPath('Asset/UI/ChildWidgets/BP_FittingDragDropData.BP_FittingDragDropData_C'))
|
||
self.DragVisualClass = UE.LoadClass(UGCGameSystem.GetUGCResourcesFullPath('Asset/UI/ChildWidgets/WBP_DragItemVisual.WBP_DragItemVisual_C'))
|
||
self.CanvasPanel_Main:SetVisibility(ESlateVisibility.Collapsed)
|
||
self.bCanEverTick = true
|
||
end
|
||
|
||
function WBP_WeaponFittingItem:Tick(MyGeometry, InDeltaTime)
|
||
-- 当没有需要选择操作的时候就不用执行操作
|
||
if self.bClickLeftButton and not self.bStartMove then
|
||
-- 开始即时
|
||
self.PressTime = self.PressTime + InDeltaTime
|
||
if self.PressTime > self.FunctionPressTime then
|
||
-- 执行操作
|
||
if not self.bFirstButtonClick then
|
||
self.bFirstButtonClick = true
|
||
end
|
||
end
|
||
|
||
if self.bFirstButtonClick then
|
||
EventSystem:SendEvent(EventType.ShowItemDescribe, self.FittingData, true)
|
||
end
|
||
else
|
||
self.PressTime = 0
|
||
end
|
||
end
|
||
|
||
function WBP_WeaponFittingItem:Destruct()
|
||
self.DragDropClass = nil
|
||
self.DragVisualClass = nil
|
||
end
|
||
|
||
-- 该方法只会在开始的时候设置一次
|
||
-- 设置当前Item的数据,数据类型: {id, count}
|
||
function WBP_WeaponFittingItem:SetFittingItemData(InData)
|
||
--首先保存
|
||
print(string.format("开始设置数据:Id:%d, count:%d", InData.ItemID, InData.ItemCount))
|
||
self.FittingData = InData
|
||
|
||
if GameDataManager then
|
||
local Val = GameDataManager.GetItemInfoByItemID(InData.ItemID)
|
||
|
||
self.ItemIconAndBG:SetItemIcon(Val.Icon)
|
||
self.ItemIconAndBG:SetItemBGColor(GetItemQualityLevel(InData.ItemID))
|
||
self.TextBlock_ItemCount:SetText(tostring(InData.ItemCount))
|
||
-- 设置信息
|
||
-- 先处理技能书
|
||
local TextVal
|
||
if InData.ItemID > 20000 then
|
||
--local TheId = InData.ItemID // 100 % 100
|
||
TextVal = DropItemMap.SkillItemMap[InData.ItemID].SkillName
|
||
else
|
||
TextVal = DropItemMap.FittingItemMap[InData.ItemID].WeaponType
|
||
end
|
||
|
||
self.TextBlock_ItemType:SetText(TextVal)
|
||
|
||
-- 设置质量
|
||
local Quality = Tables.QualityInfo[GetItemQualityLevel(InData.ItemID)][1]
|
||
|
||
if Quality == nil then
|
||
print(string.format("Can't Find Quality Type, ItemId = %d", InData.ItemID))
|
||
else
|
||
print(string.format("Find Item Weapon, Quality Is %s", Quality))
|
||
end
|
||
|
||
self.TextBlock_Quality:SetText(string.format("%s", Quality))
|
||
local Color = Tables.ItemRarityColor[GetItemQualityLevel(InData.ItemID)].Color
|
||
local SlateColor_ = { SpecifiedColor = Color, ColorUseRule = 0, }
|
||
self.TextBlock_Quality:SetColorAndOpacity(SlateColor_)
|
||
|
||
-- 根据品质设置颜色
|
||
self.CanvasPanel_Main:SetVisibility(ESlateVisibility.SelfHitTestInvisible)
|
||
else
|
||
print("[WBP_WeaponFittingItem:SetItemData] 当前 GameDataManager 没有值,请检查一下是否有保存")
|
||
end
|
||
|
||
print(string.format("数据设置完成"))
|
||
end
|
||
|
||
function WBP_WeaponFittingItem:OnDragDetected(MyGeometry, PointerEvent, Operation)
|
||
self:RemoveRelatedGuide()
|
||
|
||
print("[WBP_WeaponFittingItem:OnDragDetected] 检测到 拖拽行为")
|
||
self.bFirstButtonClick = false
|
||
self.bClickLeftButton = false
|
||
self.PressTime = 0
|
||
self.bStartMove = false
|
||
|
||
Operation = UE.NewObject(nil, self.DragDropClass)
|
||
--由于不知道是什么,因此使用 None
|
||
Operation:SetOperationData(self.FittingData, EItemDropType.None)
|
||
Operation.DefaultDragVisual = self.VisualWidget
|
||
return Operation
|
||
end
|
||
|
||
function WBP_WeaponFittingItem:OnMouseMove(MyGeometry, MouseEvent)
|
||
|
||
-- 隐藏 ItemInfo 界面
|
||
print(string.format("[WBP_WeaponFittingItem:OnMouseMove] 执行"))
|
||
local ret = WBP_WeaponFittingItem.SuperClass:OnMouseMove(MyGeometry, MouseEvent);
|
||
EventSystem:SendEvent(EventType.ShowItemDescribe, self.FittingData, false)
|
||
if not self.bClickLeftButton then
|
||
print(string.format('[WBP_WeaponFittingItem:OnMouseMove] 没有点击左键'))
|
||
return ret
|
||
end
|
||
|
||
local PC = GameDataManager.GetLocalPlayerController()
|
||
local IsKeyDown = PC:IsInputKeyDown({KeyName = "LeftMouseButton"})
|
||
--if IsKeyDown == false then
|
||
-- print(string.format('[WBP_WeaponFittingItem:OnMouseMove] 直接返回了'))
|
||
-- self.bClickLeftButton = false
|
||
-- self.bFirstButtonClick = false
|
||
-- self.bStartMove = false
|
||
-- return
|
||
--end
|
||
|
||
print(string.format('[WBP_WeaponFittingItem:OnMouseMove] 开始执行拖拽'))
|
||
if not self.bStartMove then
|
||
self.bStartMove = true
|
||
|
||
local GameState = UGCGameSystem.GameState
|
||
if self.FittingData == nil then
|
||
return ret
|
||
end
|
||
|
||
if UE.IsValid(self.DragVisualClass) and UE.IsValid(GameState) then
|
||
self.VisualWidget = UserWidget.NewWidgetObjectBP(GameState, self.DragVisualClass)
|
||
self.VisualWidget:SetVisibility(ESlateVisibility.Collapsed)
|
||
print(string.format('[WBP_WeaponFittingItem:OnMouseMove] 创建好Visual Widget'))
|
||
local that = self
|
||
self.DragTimerHandler = EventSystem.SetTimerLoop(self, function()
|
||
if that.VisualWidget.bHasInit then
|
||
print(string.format('[WBP_WeaponFittingItem:OnMouseMove] 初始化完成 VisualWidget'))
|
||
EventSystem.StopTimer(that.DragTimerHandler)
|
||
that.VisualWidget:SetVisualItemData(that.FittingData, that.ItemIconAndBG:GetItemIcon())
|
||
end
|
||
that.VisualWidget:SetVisibility(ESlateVisibility.SelfHitTestInvisible)
|
||
end, 0.05)
|
||
end
|
||
print(string.format('[WBP_WeaponFittingItem:OnMouseMove] 开始拖拽'))
|
||
UIManager.AllPanel[EUIType.Backpack]:SetIsDrop(true)
|
||
return WidgetBlueprintLibrary.DetectDragIfPressed(MouseEvent, self, {KeyName="LeftMouseButton"})
|
||
end
|
||
return ret
|
||
end
|
||
|
||
function WBP_WeaponFittingItem:OnMouseButtonDown(MyGeometry, PointerEvent)
|
||
self:RemoveRelatedGuide()
|
||
|
||
--开始即时
|
||
-- 检测当前是否可以执行操作
|
||
print(string.format("[WBP_WeaponFittingItem:OnMouseButtonDown] 执行"))
|
||
self.bClickLeftButton = true
|
||
return self.SuperClass:OnMouseButtonDown(MyGeometry, PointerEvent)
|
||
end
|
||
|
||
-- 当鼠标抬起来的时候
|
||
function WBP_WeaponFittingItem:OnMouseButtonUp(MyGeometry, InTouchEvent)
|
||
self:RemoveRelatedGuide()
|
||
UIManager:ClosePanel(EUIType.UseSkill)
|
||
|
||
-- 检查当前时间是否够了
|
||
print(string.format("[WBP_WeaponFittingItem:OnMouseButtonUp] 鼠标抬起"))
|
||
if UIManager.AllPanel[EUIType.Backpack]:GetOperateType() ~= EBagOperateType.None then
|
||
-- 说明此时要进行操作了,此时发送具体数据
|
||
EventSystem:SendEvent(EventType.SelectedItem, self.FittingData)
|
||
else
|
||
EventSystem:SendEvent(EventType.ShowItemDescribe, self.FittingData, false)
|
||
UIManager.AllPanel[EUIType.Backpack]:SetIsDrop(false)
|
||
if self.FittingData == nil then
|
||
UIManager.AllPanel[EUIType.Backpack]:HideSelectSkill()
|
||
else
|
||
if GetItemTypeByItemId(self.FittingData.ItemID) == EItemType.SkillBook then
|
||
-- 检查是否已经满了
|
||
-- local Pos = WidgetLayoutLibrary.GetMousePositionOnViewport(self)
|
||
-- local PC = GameDataManager.GetLocalPlayerController()
|
||
-- local PosX, PosY = 0, 0
|
||
-- local bSuccess, PositionX, PositionY = PC:GetMousePosition(PosX, PosY)
|
||
|
||
-- if math.isNearlyEqual(PositionY, 0) or math.isNearlyEqual(PositionX, 0) then
|
||
-- Pos.X = 1980/2
|
||
-- Pos.Y = 1260/2
|
||
-- else
|
||
-- Pos.X = PositionX
|
||
-- Pos.Y = PositionY
|
||
-- end
|
||
|
||
local _, Pos = SlateBlueprintLibrary.LocalToViewport(self, MyGeometry,{X = 0, Y = 0})
|
||
UIManager:ShowPanel(EUIType.UseSkill, self.FittingData, Pos)
|
||
end
|
||
end
|
||
end
|
||
|
||
self:RestProperty()
|
||
end
|
||
|
||
function WBP_WeaponFittingItem:RestProperty()
|
||
self.bFirstButtonClick = false
|
||
self.bClickLeftButton = false
|
||
self.PressTime = 0
|
||
self.bStartMove = false
|
||
end
|
||
|
||
-- 开始触摸的时候
|
||
function WBP_WeaponFittingItem:OnTouchStarted(MyGeometry, InTouchEvent)
|
||
self:RemoveRelatedGuide()
|
||
|
||
self.bClickLeftButton = true
|
||
return WidgetBlueprintLibrary.DetectDragIfPressed(InTouchEvent, self, "LeftMouseButton")
|
||
end
|
||
|
||
--结束触摸
|
||
function WBP_WeaponFittingItem:OnTouchEnded(MyGeometry, InTouchEvent)
|
||
self:RemoveRelatedGuide()
|
||
|
||
self.bClickLeftButton = false
|
||
self.bFirstButtonClick = false
|
||
self.PressTime = 0
|
||
end
|
||
|
||
function WBP_WeaponFittingItem:CloseWidget()
|
||
self.CanvasPanel_Main:SetVisibility(ESlateVisibility.Collapsed)
|
||
self.FittingData = nil
|
||
end
|
||
|
||
function WBP_WeaponFittingItem:GetItemData()
|
||
return self.FittingData
|
||
end
|
||
|
||
function WBP_WeaponFittingItem:RemoveRelatedGuide()
|
||
for i = 21, 28 do
|
||
NewPlayerGuideManager:RemoveGuide(i)
|
||
end
|
||
end
|
||
|
||
return WBP_WeaponFittingItem; |