初始化提交
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)
|
||||
54
Content/Lua/UI/Common/PopupMenu/PopupMenuItem.lua
Normal file
54
Content/Lua/UI/Common/PopupMenu/PopupMenuItem.lua
Normal file
@ -0,0 +1,54 @@
|
||||
local PopupMenuItem = {}
|
||||
local UIUtils = require("UI.Utils")
|
||||
|
||||
function PopupMenuItem:ctor()
|
||||
self.on_click_callback = nil
|
||||
end
|
||||
|
||||
function PopupMenuItem:PreConstruct(IsDesignTime)
|
||||
if not IsDesignTime then return end
|
||||
self.TxtMenuName:SetText(self.MenuText)
|
||||
end
|
||||
|
||||
function PopupMenuItem:OnInitialized()
|
||||
self:BindEvent("OnClicked", function() self:OnMenuItemClicked() end)
|
||||
self:BindEvent("OnHovered", function() self:OnHoverStateChange(true) end)
|
||||
self:BindEvent("OnUnhovered", function() self:OnHoverStateChange(false) end)
|
||||
end
|
||||
|
||||
function PopupMenuItem:Construct()
|
||||
self.TxtMenuName:SetText(self.MenuText)
|
||||
end
|
||||
|
||||
function PopupMenuItem:OnDestroy()
|
||||
print(self, "PopupMenuItem:OnDestroy")
|
||||
end
|
||||
|
||||
function PopupMenuItem:SetContent(name, callback)
|
||||
self.TxtMenuName:SetText(name)
|
||||
self.on_click_callback = callback
|
||||
print(self.TxtMenuName:GetText())
|
||||
end
|
||||
|
||||
function PopupMenuItem:BindEvent(event_name, callback)
|
||||
self.BtnMain[event_name]:Add(callback)
|
||||
end
|
||||
|
||||
function PopupMenuItem:OnHoverStateChange(is_hoverd)
|
||||
if is_hoverd then
|
||||
self.ImgBackground.Brush.TintColor = self.ItemHoverdColor
|
||||
else
|
||||
self.ImgBackground.Brush.TintColor = self.ItemNormalColor
|
||||
end
|
||||
end
|
||||
|
||||
function PopupMenuItem:OnMenuItemClicked()
|
||||
print("OnMenuItemClicked")
|
||||
if self.on_click_callback ~= nil then
|
||||
self.on_click_callback()
|
||||
end
|
||||
UIUtils.HideWidgetByName(self, "MenuPanel")
|
||||
end
|
||||
|
||||
|
||||
return Class(nil, nil, PopupMenuItem)
|
||||
81
Content/Lua/UI/Common/PopupMenu/PopupMenuPanel.lua
Normal file
81
Content/Lua/UI/Common/PopupMenu/PopupMenuPanel.lua
Normal file
@ -0,0 +1,81 @@
|
||||
local PopupMenuPanel = {}
|
||||
local UIUtils = require("UI.Utils")
|
||||
local GameplayStatics = import("GameplayStatics")
|
||||
local WidgetBlueprintLibrary = import("WidgetBlueprintLibrary")
|
||||
local KismetSystemLibrary = import("KismetSystemLibrary")
|
||||
|
||||
|
||||
local function delay_adjust_content(menu_panel)
|
||||
local post_callback = function()
|
||||
local timer = KismetSystemLibrary.K2_SetTimerForNextTickDelegate(
|
||||
slua.createDelegate(function ()
|
||||
menu_panel:AdjustMenuContentSize()
|
||||
menu_panel.adjust_content_timer = nil
|
||||
end)
|
||||
)
|
||||
menu_panel.adjust_content_timer = timer
|
||||
end
|
||||
|
||||
local timer = KismetSystemLibrary.K2_SetTimerForNextTickDelegate(
|
||||
slua.createDelegate(function () post_callback() end)
|
||||
)
|
||||
menu_panel.adjust_content_timer = timer
|
||||
end
|
||||
|
||||
local function CreateMenuItem(panel)
|
||||
local pc = GameplayStatics.GetPlayerController(panel, 0)
|
||||
local widget = WidgetBlueprintLibrary.Create(panel, panel.MenuItemClass, pc)
|
||||
return widget
|
||||
end
|
||||
|
||||
|
||||
function PopupMenuPanel:ctor()
|
||||
self.adjust_content_timer = nil
|
||||
end
|
||||
|
||||
function PopupMenuPanel:OnInitialized()
|
||||
self.BtnBackground.OnClicked:Add(function()
|
||||
UIUtils.CloseWidget(self)
|
||||
end)
|
||||
end
|
||||
|
||||
function PopupMenuPanel:OnDestroy()
|
||||
print(self, "PopupMenuPanel:OnDestroy")
|
||||
end
|
||||
|
||||
function PopupMenuPanel:PreConstruct(IsDesignTime)
|
||||
if not IsDesignTime then return end
|
||||
delay_adjust_content(self)
|
||||
end
|
||||
|
||||
|
||||
function PopupMenuPanel:Construct()
|
||||
delay_adjust_content(self)
|
||||
end
|
||||
|
||||
function PopupMenuPanel:AdjustMenuContentSize()
|
||||
local all_child_height = 0
|
||||
for _, child in pairs(self.MenuItemContainer:GetAllChildren()) do
|
||||
local design_size = child:GetDesiredSize()
|
||||
all_child_height = all_child_height + design_size.Y
|
||||
end
|
||||
self.ImgBackground.Brush.ImageSize.Y = all_child_height + 20
|
||||
end
|
||||
|
||||
|
||||
function PopupMenuPanel:Refresh(args)
|
||||
self.MainOverlay.Slot:SetPosition(args[1])
|
||||
self:SetMenuContents(args[2])
|
||||
end
|
||||
|
||||
function PopupMenuPanel:SetMenuContents(contents)
|
||||
self.MenuItemContainer:ClearChildren()
|
||||
for _, content in pairs(contents) do
|
||||
local widget = CreateMenuItem(self)
|
||||
self.MenuItemContainer:AddChildToVerticalBox(widget)
|
||||
widget:SetContent(content[1], content[2])
|
||||
end
|
||||
self:AdjustMenuContentSize()
|
||||
end
|
||||
|
||||
return Class(nil, nil,PopupMenuPanel)
|
||||
28
Content/Lua/UI/Common/TableSwitcher/SwitcherWidget.lua
Normal file
28
Content/Lua/UI/Common/TableSwitcher/SwitcherWidget.lua
Normal file
@ -0,0 +1,28 @@
|
||||
local SwitcherWidget = {}
|
||||
local ESlateVisibility = import("ESlateVisibility")
|
||||
|
||||
function SwitcherWidget:Construct()
|
||||
self:Reset()
|
||||
self["ImageNormal"]:SetVisibility(ESlateVisibility.SelfHitTestInvisible)
|
||||
end
|
||||
|
||||
function SwitcherWidget:Reset()
|
||||
self["ImageHovered"]:SetVisibility(ESlateVisibility.Collapsed)
|
||||
self["ImageSelected"]:SetVisibility(ESlateVisibility.Collapsed)
|
||||
self["ImageNormal"]:SetVisibility(ESlateVisibility.Collapsed)
|
||||
end
|
||||
|
||||
function SwitcherWidget:OnWidgetStateChange(bIsWidgetHovered, bIsWidgetSelected)
|
||||
self:Reset()
|
||||
if bIsWidgetSelected then
|
||||
self["ImageSelected"]:SetVisibility(ESlateVisibility.SelfHitTestInvisible)
|
||||
else
|
||||
if bIsWidgetHovered then
|
||||
self["ImageHovered"]:SetVisibility(ESlateVisibility.SelfHitTestInvisible)
|
||||
else
|
||||
self["ImageNormal"]:SetVisibility(ESlateVisibility.SelfHitTestInvisible)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
return Class(nil, nil, SwitcherWidget)
|
||||
77
Content/Lua/UI/GameUIHud.lua
Normal file
77
Content/Lua/UI/GameUIHud.lua
Normal file
@ -0,0 +1,77 @@
|
||||
local Hud = {}
|
||||
local ESlateVisibility = import("ESlateVisibility")
|
||||
local WidgetBlueprintLibrary = import("WidgetBlueprintLibrary")
|
||||
local GameplayStatics = import("GameplayStatics")
|
||||
local BusyActorManagerSubSystem = import("BusyActorManagerSubSystem")
|
||||
|
||||
|
||||
local function ProcessSuspendShowRequests(hud)
|
||||
for _, request in pairs(hud.suspend_show_requests) do
|
||||
hud:CreateAndShowWidget(request[1], request[2])
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
|
||||
function Hud:ctor()
|
||||
self.layer = nil
|
||||
self.suspend_show_requests = {}
|
||||
self.widget_pool = {}
|
||||
end
|
||||
|
||||
function Hud:ReceiveBeginPlay()
|
||||
print("Hud:ReceiveBeginPlay")
|
||||
|
||||
if self.layer == nil then
|
||||
self.layer = self:GetOrCreateWidget("UILayer")
|
||||
end
|
||||
if self.layer ~= nil then
|
||||
self.layer:SetVisibility(ESlateVisibility.SelfHitTestInvisible)
|
||||
self.layer:AddToViewport(0)
|
||||
self:CreateAndShowWidget("MainUI", {})
|
||||
ProcessSuspendShowRequests(self)
|
||||
end
|
||||
end
|
||||
|
||||
function Hud:ReceiveEndPlay()
|
||||
print("Hud:ReceiveEndPlay")
|
||||
end
|
||||
|
||||
|
||||
function Hud:GetOrCreateWidget(widget_name)
|
||||
local exist_widget = self.widget_pool[widget_name]
|
||||
if exist_widget ~= nil and exist_widget.bSingletonInstance then
|
||||
return exist_widget
|
||||
end
|
||||
local cls = self.UIClassMapping:Get(widget_name)
|
||||
local pc = GameplayStatics.GetPlayerController(self, 0)
|
||||
local widget = WidgetBlueprintLibrary.Create(self, cls, pc)
|
||||
self.widget_pool[widget_name] = widget
|
||||
return widget -- TODO 这里如果非单例widget,会被覆盖
|
||||
end
|
||||
|
||||
function Hud:GetFirstCachedWidget(widget_name)
|
||||
return self.widget_pool[widget_name]
|
||||
end
|
||||
|
||||
function Hud:CreateAndShowWidget(widget_name, args)
|
||||
if not self.layer then
|
||||
table.insert(self.suspend_show_requests, {widget_name, args})
|
||||
return
|
||||
end
|
||||
local widget = self:GetOrCreateWidget(widget_name)
|
||||
if not widget then return end
|
||||
self.layer:ShowWidget(widget, args)
|
||||
end
|
||||
|
||||
function Hud:CloseWidget(widget)
|
||||
self.layer:CloseWidget(widget)
|
||||
end
|
||||
|
||||
function Hud:HideWidgetByName(widget_name)
|
||||
self.layer:HideWidget(self.widget_pool[widget_name])
|
||||
end
|
||||
|
||||
|
||||
|
||||
return Class(nil, nil, Hud)
|
||||
32
Content/Lua/UI/MainUI.lua
Normal file
32
Content/Lua/UI/MainUI.lua
Normal file
@ -0,0 +1,32 @@
|
||||
local MainUI = {}
|
||||
local UIUtils = require("UI.Utils")
|
||||
-- local GameplayStatics = import("GameplayStatics")
|
||||
|
||||
function MainUI:OnInitialized()
|
||||
print("OnInitialized MainUI")
|
||||
self.BtnSetting.OnClicked:Add(function() self:OpenSettingPanel() end)
|
||||
self.BtnBag.OnClicked:Add(function() self:OpenBagPanel() end)
|
||||
self.BtnRoll.OnClicked:Add(function() self:OnUseRoll() end)
|
||||
end
|
||||
|
||||
function MainUI:OnDestroy()
|
||||
|
||||
end
|
||||
|
||||
function MainUI:OpenSettingPanel()
|
||||
-- GameplayStatics.SetGamePaused(self, true)
|
||||
UIUtils.ShowWidget(self, "SettingMenu", {})
|
||||
end
|
||||
|
||||
function MainUI:OpenBagPanel()
|
||||
UIUtils.ShowWidget(self, "BagPanel", {})
|
||||
end
|
||||
|
||||
function MainUI:OnUseRoll()
|
||||
local BusyActorManagerSubSystem = import("BusyActorManagerSubSystem")
|
||||
local mgr = BusyActorManagerSubSystem.Get(self)
|
||||
local role = mgr.current_role
|
||||
role:UseRollSkill()
|
||||
end
|
||||
|
||||
return Class(nil, nil, MainUI)
|
||||
68
Content/Lua/UI/PickBar.lua
Normal file
68
Content/Lua/UI/PickBar.lua
Normal file
@ -0,0 +1,68 @@
|
||||
local PickBar = {}
|
||||
local Reactive = require("Core.Reactive")
|
||||
local ESlateVisibility = import("ESlateVisibility")
|
||||
|
||||
local function ResetWatcher(Bar)
|
||||
if Bar.watcher then
|
||||
Bar.watcher:Destroy()
|
||||
Bar.watcher = nil
|
||||
end
|
||||
end
|
||||
|
||||
function PickBar:ctor()
|
||||
self.watcher = nil
|
||||
self.level_item = nil
|
||||
end
|
||||
|
||||
function PickBar:OnInitialized()
|
||||
self.ProcessBar:SetVisibility(ESlateVisibility.Collapsed)
|
||||
print("PickBar:OnInitialized")
|
||||
end
|
||||
|
||||
function PickBar:BindLevelItem(LevelItem)
|
||||
ResetWatcher(self)
|
||||
self.level_item = LevelItem
|
||||
|
||||
-- self.watcher = Reactive.Watcher(function()
|
||||
-- self:UpdateState()
|
||||
-- end)
|
||||
|
||||
|
||||
self.watcher = Reactive.Watcher(function()
|
||||
local process = LevelItem:GetPickProcess()
|
||||
if process < 1.0 then
|
||||
self.ProcessBar:SetPercent(process)
|
||||
self.ProcessBar:SetVisibility(ESlateVisibility.SelfHitTestInvisible)
|
||||
else
|
||||
self.ProcessBar:SetVisibility(ESlateVisibility.Collapsed)
|
||||
self.ProcessBar:SetPercent(1.0)
|
||||
end
|
||||
end)
|
||||
end
|
||||
|
||||
-- function PickBar:UpdateState()
|
||||
-- local process = self.level_item:GetPickProcess()
|
||||
-- if process < 1.0 then
|
||||
-- self.ProcessBar:SetVisibility(ESlateVisibility.SelfHitTestInvisible)
|
||||
-- self.ProcessBar:SetPercent(process)
|
||||
-- else
|
||||
-- self.ProcessBar:SetVisibility(ESlateVisibility.Collapsed)
|
||||
-- self.ProcessBar:SetPercent(1.0)
|
||||
-- end
|
||||
-- end
|
||||
|
||||
function PickBar:OnDestroy()
|
||||
ResetWatcher(self)
|
||||
end
|
||||
|
||||
function PickBar:Construct()
|
||||
print("PickBar:Construct")
|
||||
end
|
||||
|
||||
function PickBar:Destruct()
|
||||
print("PickBar:Destruct")
|
||||
end
|
||||
|
||||
|
||||
|
||||
return Class(nil, nil, PickBar)
|
||||
38
Content/Lua/UI/RoleStateWidget.lua
Normal file
38
Content/Lua/UI/RoleStateWidget.lua
Normal file
@ -0,0 +1,38 @@
|
||||
local Widget = {}
|
||||
local Reactive = require("Core.Reactive")
|
||||
|
||||
local function ResetWatcher(widget)
|
||||
if widget.health_watcher then
|
||||
widget.health_watcher:Destroy()
|
||||
widget.health_watcher = nil
|
||||
end
|
||||
if widget.hunger_watcher then
|
||||
widget.hunger_watcher:Destroy()
|
||||
widget.hunger_watcher = nil
|
||||
end
|
||||
end
|
||||
|
||||
function Widget:OnDestroy()
|
||||
|
||||
end
|
||||
|
||||
|
||||
function Widget:Refresh(args)
|
||||
local role = args.role
|
||||
if role == nil then return end
|
||||
self:BindRole(role)
|
||||
end
|
||||
|
||||
function Widget:BindRole(role)
|
||||
ResetWatcher(self)
|
||||
self.health_watcher = Reactive.Watcher(function()
|
||||
self.HealthBar:SetPercent(role:GetHealthPercent())
|
||||
end)
|
||||
|
||||
self.hunger_watcher = Reactive.Watcher(function()
|
||||
self.HungerBar:SetPercent(role:GetHungerPercent())
|
||||
end)
|
||||
|
||||
end
|
||||
|
||||
return Class(nil, nil, Widget)
|
||||
28
Content/Lua/UI/SettingPanel.lua
Normal file
28
Content/Lua/UI/SettingPanel.lua
Normal file
@ -0,0 +1,28 @@
|
||||
local SettingPanel = {}
|
||||
local UIUtils = require("UI.Utils")
|
||||
local GameplayStatics = import("GameplayStatics")
|
||||
|
||||
function SettingPanel:OnInitialized()
|
||||
self.BtnContinue.OnClicked:Add(function() self:BackToGame() end)
|
||||
self.BtnExitLevel.OnClicked:Add(function() end)
|
||||
self.BtnExitGame.OnClicked:Add(function() self:ExitGame() end)
|
||||
self.BtnClose.OnClicked:Add(function() self:BackToGame() end)
|
||||
end
|
||||
|
||||
function SettingPanel:OnDestroy()
|
||||
|
||||
end
|
||||
|
||||
|
||||
function SettingPanel:BackToGame()
|
||||
GameplayStatics.SetGamePaused(self, false)
|
||||
UIUtils.CloseWidget(self)
|
||||
end
|
||||
|
||||
function SettingPanel:ExitGame()
|
||||
local pc = GameplayStatics.GetPlayerController(self, 0)
|
||||
pc:QuitGame()
|
||||
end
|
||||
|
||||
|
||||
return Class(nil, nil, SettingPanel)
|
||||
41
Content/Lua/UI/UILayerManager.lua
Normal file
41
Content/Lua/UI/UILayerManager.lua
Normal file
@ -0,0 +1,41 @@
|
||||
local UILayerManager = {}
|
||||
local EWidgetLayoutType = import("EWidgetLayoutType")
|
||||
|
||||
function UILayerManager:ctor()
|
||||
self.layer_mapping = {}
|
||||
end
|
||||
|
||||
function UILayerManager:OnInitialized()
|
||||
self.layer_mapping = {
|
||||
[EWidgetLayoutType.MainLayer] = self.MainLayer,
|
||||
[EWidgetLayoutType.PopupLayer] = self.PopupLayer,
|
||||
[EWidgetLayoutType.FloatLayer] = self.FloatLayer,
|
||||
[EWidgetLayoutType.TopLayer] = self.TopLayer,
|
||||
}
|
||||
end
|
||||
|
||||
function UILayerManager:ShowWidget(widget, args)
|
||||
local layer = self.layer_mapping[widget.LayoutType]
|
||||
if layer == nil then
|
||||
return
|
||||
end
|
||||
layer:AddChild(widget)
|
||||
if widget.Refresh then
|
||||
widget:Refresh(args)
|
||||
end
|
||||
widget.Slot:SetVerticalAlignment(0)
|
||||
widget.Slot:SetHorizontalAlignment(0)
|
||||
widget:SetVisible(true)
|
||||
end
|
||||
|
||||
function UILayerManager:HideWidget(widget)
|
||||
widget:SetVisible(false)
|
||||
end
|
||||
|
||||
function UILayerManager:CloseWidget(widget)
|
||||
widget:SetVisible(false)
|
||||
end
|
||||
|
||||
|
||||
|
||||
return Class(nil, nil, UILayerManager)
|
||||
35
Content/Lua/UI/Utils.lua
Normal file
35
Content/Lua/UI/Utils.lua
Normal file
@ -0,0 +1,35 @@
|
||||
local _M = {}
|
||||
local GameplayStatics = import("GameplayStatics")
|
||||
|
||||
function _M.GetGameUIHud(wco)
|
||||
local pc = GameplayStatics.GetPlayerController(wco, 0)
|
||||
if pc == nil then return nil end
|
||||
return pc:GetHud()
|
||||
end
|
||||
|
||||
function _M.ShowWidget(wco, widget_name, args)
|
||||
local hud = _M.GetGameUIHud(wco)
|
||||
if hud == nil then return end
|
||||
hud:CreateAndShowWidget(widget_name, args)
|
||||
end
|
||||
|
||||
function _M.GetShowedWidget(wco, widget_name)
|
||||
local hud = _M.GetGameUIHud(wco)
|
||||
if hud == nil then return end
|
||||
hud:GetFirstCachedWidget(widget_name)
|
||||
end
|
||||
|
||||
function _M.HideWidgetByName(wco, widget_name)
|
||||
local hud = _M.GetGameUIHud(wco)
|
||||
if hud == nil then return end
|
||||
hud:HideWidgetByName(widget_name)
|
||||
end
|
||||
|
||||
function _M.CloseWidget(widget)
|
||||
local hud = _M.GetGameUIHud(widget)
|
||||
if hud == nil then return end
|
||||
hud:CloseWidget(widget)
|
||||
end
|
||||
|
||||
|
||||
return _M
|
||||
Reference in New Issue
Block a user