209 lines
6.7 KiB
Lua
209 lines
6.7 KiB
Lua
|
---@class WBP_WeaponPartItem_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_WeaponPartItem = {
|
|||
|
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_WeaponPartItem: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_WeaponPartItem:Tick(MyGeometry, InDeltaTime)
|
|||
|
-- 当没有需要选择操作的时候就不用执行操作
|
|||
|
print(string.format("[WBP_WeaponPartItem:Tick] 执行"))
|
|||
|
if UIManager.AllPanel[EUIType.Backpack]:GetOperateType() ~= EBagOperateType.None then
|
|||
|
return
|
|||
|
end
|
|||
|
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_WeaponPartItem:Destruct()
|
|||
|
self.DragDropClass = nil
|
|||
|
self.DragVisualClass = nil
|
|||
|
end
|
|||
|
|
|||
|
-- 该方法只会在开始的时候设置一次
|
|||
|
-- 设置当前Item的数据,数据类型: {id, count}
|
|||
|
function WBP_WeaponPartItem: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)
|
|||
|
-- TODO 这个设置需要根据 具体强型修改
|
|||
|
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))
|
|||
|
|
|||
|
-- 根据品质设置颜色
|
|||
|
self.CanvasPanel_Main:SetVisibility(ESlateVisibility.SelfHitTestInvisible)
|
|||
|
else
|
|||
|
print("[WBP_WeaponPartItem:SetItemData] 当前 GameDataManager 没有值,请检查一下是否有保存")
|
|||
|
end
|
|||
|
|
|||
|
print(string.format("数据设置完成"))
|
|||
|
end
|
|||
|
|
|||
|
function WBP_WeaponPartItem:OnDragDetected(MyGeometry, PointerEvent, Operation)
|
|||
|
print("[WBP_WeaponPartItem: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_WeaponPartItem:OnMouseMove(MyGeometry, MouseEvent)
|
|||
|
-- 隐藏 ItemInfo 界面
|
|||
|
print(string.format("[WBP_WeaponPartItem:OnMouseMove] 执行"))
|
|||
|
local ret = WBP_WeaponPartItem.SuperClass:OnMouseMove(MyGeometry, MouseEvent);
|
|||
|
if not self.bClickLeftButton then
|
|||
|
return ret
|
|||
|
end
|
|||
|
|
|||
|
EventSystem:SendEvent(EventType.ShowItemDescribe, self.FittingData, false)
|
|||
|
|
|||
|
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)
|
|||
|
local that = self
|
|||
|
self.DragTimerHandler = EventSystem.SetTimerLoop(self, function()
|
|||
|
if that.VisualWidget.bHasInit then
|
|||
|
EventSystem.StopTimer(that.DragTimerHandler)
|
|||
|
that.VisualWidget:SetVisualItemData(that.FittingData, that.ItemIconAndBG:GetItemIcon())
|
|||
|
end
|
|||
|
that.VisualWidget:SetVisibility(ESlateVisibility.SelfHitTestInvisible)
|
|||
|
end, 0.05)
|
|||
|
end
|
|||
|
return WidgetBlueprintLibrary.DetectDragIfPressed(MouseEvent, self, "LeftMouseButton")
|
|||
|
end
|
|||
|
return ret
|
|||
|
end
|
|||
|
|
|||
|
function WBP_WeaponPartItem:OnMouseButtonDown(MyGeometry, PointerEvent)
|
|||
|
--开始即时
|
|||
|
-- 检测当前是否可以执行操作
|
|||
|
print(string.format("[WBP_WeaponPartItem:OnMouseButtonDown] 执行"))
|
|||
|
self.bClickLeftButton = true
|
|||
|
return self.SuperClass:OnMouseButtonDown(MyGeometry, PointerEvent)
|
|||
|
end
|
|||
|
|
|||
|
-- 当鼠标抬起来的时候
|
|||
|
function WBP_WeaponPartItem:OnMouseButtonUp(MyGeometry, InTouchEvent)
|
|||
|
-- 检查当前时间是否够了
|
|||
|
print(string.format("[WBP_WeaponPartItem:OnMouseButtonUp] 鼠标抬起"))
|
|||
|
if UIManager.AllPanel[EUIType.Backpack]:GetOperateType() ~= EBagOperateType.None then
|
|||
|
-- 说明此时要进行操作了,此时发送具体数据
|
|||
|
EventSystem:SendEvent(EventType.SelectedItem, self.FittingData)
|
|||
|
else
|
|||
|
EventSystem:SendEvent(EventType.ShowItemDescribe, self.FittingData, false)
|
|||
|
end
|
|||
|
self:RestProperty()
|
|||
|
end
|
|||
|
|
|||
|
function WBP_WeaponPartItem:RestProperty()
|
|||
|
self.bFirstButtonClick = false
|
|||
|
self.bClickLeftButton = false
|
|||
|
self.PressTime = 0
|
|||
|
self.bStartMove = false
|
|||
|
end
|
|||
|
|
|||
|
-- 开始触摸的时候
|
|||
|
function WBP_WeaponPartItem:OnTouchStarted(MyGeometry, InTouchEvent)
|
|||
|
self.bClickLeftButton = true
|
|||
|
return WidgetBlueprintLibrary.DetectDragIfPressed(InTouchEvent, self, "LeftMouseButton")
|
|||
|
end
|
|||
|
|
|||
|
--结束触摸
|
|||
|
function WBP_WeaponPartItem:OnTouchEnded(MyGeometry, InTouchEvent)
|
|||
|
self.bClickLeftButton = false
|
|||
|
self.bFirstButtonClick = false
|
|||
|
self.PressTime = 0
|
|||
|
end
|
|||
|
|
|||
|
function WBP_WeaponPartItem:CloseWidget()
|
|||
|
self.CanvasPanel_Main:SetVisibility(ESlateVisibility.Collapsed)
|
|||
|
end
|
|||
|
|
|||
|
function WBP_WeaponPartItem:GetItemData()
|
|||
|
return self.FittingData
|
|||
|
end
|
|||
|
|
|||
|
return WBP_WeaponPartItem;
|