103 lines
3.7 KiB
Lua
103 lines
3.7 KiB
Lua
---@class WB_PlayerHeight_C:UUserWidget
|
|
---@field CanvasPanel_AllPlayerHeight UCanvasPanel
|
|
---@field TextBlock_LocalPlayerHeight UTextBlock
|
|
--Edit Below--
|
|
local WB_PlayerHeight = {
|
|
bInitDoOnce = false;
|
|
AllPlayerKey = {};
|
|
ScaleSize = 300;
|
|
IsSetZeroHeight = false;
|
|
ZeroHeight = 0.
|
|
};
|
|
|
|
function WB_PlayerHeight:Construct()
|
|
UGCEventSystem.AddListener(EventEnum.UpdateMiniGameAllPlayerScore, self.UpdateMiniGameAllPlayerScore, self)
|
|
end
|
|
|
|
function WB_PlayerHeight:OnShowPanel()
|
|
-- self:UpdatePlayerKeys(InAllPlayerKey)
|
|
self.IsShow = true
|
|
end
|
|
|
|
function WB_PlayerHeight:OnClosePanel()
|
|
self.IsShow = false
|
|
end
|
|
|
|
function WB_PlayerHeight:UpdatePlayerKeys(InAllPlayerKey)
|
|
self.AllPlayerKey = InAllPlayerKey
|
|
UGCLogSystem.LogTree("[WB_PlayerHeight_UpdatePlayerKeys] AllPlayerKey", self.AllPlayerKey)
|
|
for i = 1, self.CanvasPanel_AllPlayerHeight:GetChildrenCount() do
|
|
local Item = self.CanvasPanel_AllPlayerHeight:GetChildAt(i - 1)
|
|
Item:SetPlayerKey(self.AllPlayerKey[i])
|
|
end
|
|
end
|
|
|
|
function WB_PlayerHeight:Tick(MyGeometry, InDeltaTime)
|
|
if self.IsShow then
|
|
self.TextBlock_LocalPlayerHeight:SetText(string.format("%sm", tostring(KismetMathLibrary.Round(self:GetPlayerHeight()))))
|
|
--UGCLogSystem.Log("[WB_PlayerHeight_Tick]")
|
|
for i = 1, self.CanvasPanel_AllPlayerHeight:GetChildrenCount() do
|
|
local Item = self.CanvasPanel_AllPlayerHeight:GetChildAt(i - 1)
|
|
Item:Tick(nil, InDeltaTime)
|
|
end
|
|
end
|
|
end
|
|
|
|
function WB_PlayerHeight:GetPlayerHeight()
|
|
if self.IsSetZeroHeight then
|
|
local LocalPawn = UGCSystemLibrary.GetLocalPlayerPawn()
|
|
if UE.IsValid(LocalPawn) then
|
|
local Res = (LocalPawn:K2_GetActorLocation().Z - self.ZeroHeight) / 100
|
|
if Res < 0 then
|
|
return 0
|
|
else
|
|
return Res
|
|
end
|
|
end
|
|
else
|
|
if self.ZeroPoint == nil then
|
|
self.ZeroPoint = UGCSystemLibrary.GetUniqueInstanceFromPath(MiniGameConfig.MiniGameInfo[MiniGameConfig.MiniGameType.BePromotedStepByStep].GameParam.ZeroHeightPointPath)
|
|
UGCLogSystem.Log("[WB_PlayerHeight_GetPlayerHeight]")
|
|
else
|
|
self.ZeroHeight = self.ZeroPoint:K2_GetActorLocation().Z
|
|
self.IsSetZeroHeight = true
|
|
end
|
|
end
|
|
return 0.
|
|
|
|
end
|
|
|
|
function WB_PlayerHeight:UpdateMiniGameAllPlayerScore(AllPlayerScore)
|
|
if #self.AllPlayerKey ~= table.getCount(AllPlayerScore) then
|
|
self:UpdatePlayerKeys(table.getKeys(AllPlayerScore))
|
|
end
|
|
local AllScore = table.getValues(AllPlayerScore)
|
|
local MaxScore, MinScore
|
|
if #AllScore > 1 then
|
|
MaxScore = math.max(table.unpack(AllScore))
|
|
MinScore = math.min(table.unpack(AllScore))
|
|
elseif #AllScore == 1 then
|
|
MaxScore = AllScore[1]
|
|
MinScore = AllScore[1]
|
|
else
|
|
MaxScore = 20
|
|
MinScore = 0
|
|
end
|
|
MaxScore = (MaxScore // 10 + 1) * 10
|
|
MinScore = MinScore // 10 * 10
|
|
MaxScore = MaxScore < 20 and 20 or MaxScore
|
|
|
|
--UGCLogSystem.LogTree("[WB_PlayerHeight_UpdateMiniGameAllPlayerScore] ", AllPlayerScore)
|
|
for i = 1, self.CanvasPanel_AllPlayerHeight:GetChildrenCount() do
|
|
local Item = self.CanvasPanel_AllPlayerHeight:GetChildAt(i - 1)
|
|
if AllPlayerScore[Item:GetPlayerKey()] then
|
|
local Score = AllPlayerScore[Item:GetPlayerKey()]
|
|
local Pos = (Score - MinScore) / (MaxScore - MinScore) * -self.ScaleSize
|
|
Item:SetTargetPos(Pos)
|
|
Item:UpdatePlayerScore(Score)
|
|
UGCLogSystem.Log("[WB_PlayerHeight_UpdateMiniGameAllPlayerScore]Score:%s ", tostring(AllPlayerScore[Item:GetPlayerKey()]))
|
|
end
|
|
end
|
|
end
|
|
|
|
return WB_PlayerHeight; |