58 lines
		
	
	
		
			1.7 KiB
		
	
	
	
		
			Lua
		
	
	
	
	
	
		
		
			
		
	
	
			58 lines
		
	
	
		
			1.7 KiB
		
	
	
	
		
			Lua
		
	
	
	
	
	
| 
								 | 
							
								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)
							 |