初始化提交
This commit is contained in:
130
Content/Lua/UI/Bag/BagGridWidget.lua
Normal file
130
Content/Lua/UI/Bag/BagGridWidget.lua
Normal file
@ -0,0 +1,130 @@
|
||||
local BagGridWidget = {}
|
||||
local UIUtils = require("UI.Utils")
|
||||
local GamePlayUtils = require("GamePlay.Utils")
|
||||
local RoleUtils = require("GamePlay.Utils.RoleUtils")
|
||||
local BuildUtils = require("GamePlay.Utils.BuildUtils")
|
||||
local ESlateVisibility = import("ESlateVisibility")
|
||||
local BlueprintGameplayTagLibrary = import("BlueprintGameplayTagLibrary")
|
||||
|
||||
|
||||
|
||||
|
||||
local function SetIsSelected(check_box, is_selected)
|
||||
if is_selected == nil then
|
||||
check_box:SetVisibility(ESlateVisibility.Collapsed)
|
||||
else
|
||||
check_box:SetVisibility(ESlateVisibility.Visible)
|
||||
check_box:SetIsChecked(is_selected)
|
||||
end
|
||||
end
|
||||
|
||||
local function SetItemAndCnt(entry, item_id, item_cnt)
|
||||
if item_id ~= nil then
|
||||
entry.Icon:SetVisibility(ESlateVisibility.SelfHitTestInvisible)
|
||||
local config = GamePlayUtils.GetItemDescConfig(item_id)
|
||||
local x = slua.loadObject(config.IconResource:ToString())
|
||||
entry.Icon:SetBrushResourceObject(x)
|
||||
else
|
||||
entry.Icon:SetVisibility(ESlateVisibility.Collapsed)
|
||||
end
|
||||
item_cnt = item_cnt or 0
|
||||
if item_cnt > 0 then
|
||||
entry.Icon:SetVisibility(ESlateVisibility.SelfHitTestInvisible)
|
||||
if item_cnt > 1 then
|
||||
entry.TxtCnt:SetVisibility(ESlateVisibility.SelfHitTestInvisible)
|
||||
else
|
||||
entry.TxtCnt:SetVisibility(ESlateVisibility.Collapsed)
|
||||
end
|
||||
else
|
||||
entry.TxtCnt:SetVisibility(ESlateVisibility.Collapsed)
|
||||
entry.Icon:SetVisibility(ESlateVisibility.Collapsed)
|
||||
end
|
||||
entry.item_id = item_id
|
||||
end
|
||||
|
||||
local function GetItemMenuContent(item, item_id)
|
||||
local config = GamePlayUtils.GetItemConfigByID(item_id)
|
||||
if config == nil then return {} end
|
||||
|
||||
local contents = {}
|
||||
|
||||
local consume_function = function()
|
||||
local inventory = item.inventory
|
||||
inventory:ConsumeItems(item.index, 1)
|
||||
local grid = inventory:GetGridWithIndex(item.index)
|
||||
item:SetData(grid)
|
||||
end
|
||||
local is_food = BlueprintGameplayTagLibrary.HasTag(
|
||||
config.TypeTagContainer,
|
||||
GamePlayUtils.GetGameplayTag("GameItem.Food"),
|
||||
false
|
||||
)
|
||||
local is_building = BlueprintGameplayTagLibrary.HasTag(
|
||||
config.TypeTagContainer,
|
||||
GamePlayUtils.GetGameplayTag("GameItem.Building"),
|
||||
false
|
||||
)
|
||||
if is_food then
|
||||
table.insert(contents, {"使用", function()
|
||||
consume_function()
|
||||
RoleUtils.EatFood(item, item_id)
|
||||
end})
|
||||
end
|
||||
if is_building then
|
||||
table.insert(contents, {"建造", function()
|
||||
if BuildUtils.Build(item, item_id) == true then
|
||||
consume_function()
|
||||
end
|
||||
-- RoleUtils.EatFood(item, item_id)
|
||||
end})
|
||||
end
|
||||
table.insert(contents, {"丢弃", function()
|
||||
consume_function()
|
||||
end})
|
||||
return contents
|
||||
end
|
||||
|
||||
|
||||
function BagGridWidget:OnInitialized()
|
||||
self.BtnMain.OnClicked:Add(function() self:OnGridClicked() end)
|
||||
|
||||
self.CheckBox.OnCheckStateChanged:Add(function(is_selected)
|
||||
if self.item == nil then return end
|
||||
self.item.selected = is_selected
|
||||
end)
|
||||
end
|
||||
|
||||
function BagGridWidget:SetData(grid)
|
||||
if grid == nil then grid = {} end
|
||||
SetIsSelected(self.CheckBox, grid.selected)
|
||||
SetItemAndCnt(self, grid.ItemID, grid.CurrentCount)
|
||||
end
|
||||
|
||||
function BagGridWidget:SetInventoryInfo(inventory, index)
|
||||
self.index = index
|
||||
self.inventory = inventory
|
||||
end
|
||||
|
||||
function BagGridWidget:OnDestroy()
|
||||
|
||||
end
|
||||
|
||||
function BagGridWidget:OnGridClicked()
|
||||
if not self.item_id then return end
|
||||
local FVector2D = import("Vector2D")
|
||||
local SlateBlueprintLibrary = import("SlateBlueprintLibrary")
|
||||
|
||||
local geometry = self:GetCachedGeometry()
|
||||
local size = SlateBlueprintLibrary.GetLocalSize(geometry)
|
||||
local center = FVector2D()
|
||||
center.X, center.Y = size.X * 0.5, size.Y * 0.5
|
||||
local _, viewport_pos = SlateBlueprintLibrary.LocalToViewport(self, geometry, center, nil, nil)
|
||||
|
||||
UIUtils.ShowWidget(self, "MenuPanel", {
|
||||
viewport_pos,
|
||||
GetItemMenuContent(self, self.item_id)
|
||||
})
|
||||
|
||||
end
|
||||
|
||||
return Class(nil, nil, BagGridWidget)
|
||||
57
Content/Lua/UI/Bag/BagPanel.lua
Normal file
57
Content/Lua/UI/Bag/BagPanel.lua
Normal file
@ -0,0 +1,57 @@
|
||||
local BagPanel = {}
|
||||
local UIUtils = require("UI.Utils")
|
||||
local GameplayStatics = import("GameplayStatics")
|
||||
local BusyActorManagerSubSystem = import("BusyActorManagerSubSystem")
|
||||
|
||||
function BagPanel:ctor()
|
||||
self.widgets = {}
|
||||
end
|
||||
function BagPanel:OnInitialized()
|
||||
print("BagPanel:OnInitialized")
|
||||
self.BtnClose.OnClicked:Add(function() self:Close() end)
|
||||
end
|
||||
|
||||
function BagPanel:Construct()
|
||||
self["WBP_TableSwitcher"]:SetSelectedSwitcher("RoleInventory")
|
||||
end
|
||||
|
||||
function BagPanel:GetInventory(name)
|
||||
if name == "Bonfire" then
|
||||
local sub_system = BusyActorManagerSubSystem.Get(self)
|
||||
local bonfire = sub_system:GetNearestBonfire()
|
||||
return bonfire.Inventory
|
||||
end
|
||||
end
|
||||
|
||||
function BagPanel:Close()
|
||||
GameplayStatics.SetGamePaused(self, false)
|
||||
UIUtils.CloseWidget(self)
|
||||
end
|
||||
|
||||
function BagPanel:Refresh()
|
||||
GameplayStatics.SetGamePaused(self, true)
|
||||
-- self:SetVisibility(ESlateVisibility.Visible)
|
||||
|
||||
-- local sub_system = BusyActorManagerSubSystem.Get(self)
|
||||
-- local bonfire = sub_system:GetNearestBonfire()
|
||||
|
||||
-- bonfire.Inventory:ForEach(slua.createDelegate(function(idx, grid)
|
||||
-- local widget = self.widgets[idx+1]
|
||||
-- widget:SetData(grid)
|
||||
-- widget:SetInventoryInfo(bonfire.Inventory, idx)
|
||||
-- end))
|
||||
-- local drop_visible = ESlateVisibility.Collapsed
|
||||
-- self.Overlay_Confim:SetVisibility(drop_visible)
|
||||
end
|
||||
|
||||
|
||||
function BagPanel:Destruct()
|
||||
|
||||
end
|
||||
|
||||
function BagPanel:OnDestroy()
|
||||
|
||||
end
|
||||
|
||||
|
||||
return Class(nil, nil, BagPanel)
|
||||
58
Content/Lua/UI/Bag/InventoryArea.lua
Normal file
58
Content/Lua/UI/Bag/InventoryArea.lua
Normal file
@ -0,0 +1,58 @@
|
||||
local InventoryArea = {}
|
||||
local RoleUtils = require("GamePlay.Utils.RoleUtils")
|
||||
local GameplayStatics = import("GameplayStatics")
|
||||
local WidgetBlueprintLibrary = import("WidgetBlueprintLibrary")
|
||||
local BusyActorManagerSubSystem = import("BusyActorManagerSubSystem")
|
||||
|
||||
|
||||
function InventoryArea:ctor()
|
||||
self.widgets = {}
|
||||
end
|
||||
|
||||
function InventoryArea:PreConstruct(bIsDesignTime)
|
||||
if not bIsDesignTime then return end
|
||||
end
|
||||
|
||||
function InventoryArea:OnInitialized()
|
||||
self:InitInventoryLayout(self.RowGridCnt, self.ColGridCnt, self.GridClass)
|
||||
end
|
||||
|
||||
function InventoryArea:InitInventoryLayout(row_cnt, col_cnt, cls)
|
||||
self.widgets = {}
|
||||
local pc = GameplayStatics.GetPlayerController(self, 0)
|
||||
for i=1, row_cnt do
|
||||
for j=1, col_cnt do
|
||||
local widget = WidgetBlueprintLibrary.Create(self, cls, pc)
|
||||
self.GridPanel:AddChildToGrid(widget, i-1, j-1)
|
||||
widget:SetData(nil)
|
||||
table.insert(self.widgets, widget)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
function InventoryArea:OnSwitchIn(inventory_name)
|
||||
self:SetVisible(true)
|
||||
local inventory = nil
|
||||
if inventory_name == "BonfireInventory" then
|
||||
local sub_system = BusyActorManagerSubSystem.Get(self)
|
||||
local bonfire = sub_system:GetNearestBonfire()
|
||||
inventory = bonfire.Inventory
|
||||
elseif inventory_name == "RoleInventory" then
|
||||
local role = RoleUtils.GetRole(self)
|
||||
inventory = role.Inventory
|
||||
end
|
||||
|
||||
if inventory == nil then return end
|
||||
|
||||
inventory:ForEach(slua.createDelegate(function(idx, grid)
|
||||
local widget = self.widgets[idx+1]
|
||||
widget:SetData(grid)
|
||||
widget:SetInventoryInfo(inventory, idx)
|
||||
end))
|
||||
end
|
||||
|
||||
function InventoryArea:OnSwitchOut(inventory_name)
|
||||
self:SetVisible(false)
|
||||
end
|
||||
|
||||
return Class(nil, nil, InventoryArea)
|
||||
Reference in New Issue
Block a user