UGCProjects/SoloKing/Script/UI/TwoConfirm/WB_SecondaryConfirmation_Strip.lua
2025-01-21 11:29:14 +08:00

131 lines
4.3 KiB
Lua

---@class WB_SecondaryConfirmation_Strip_C:UUserWidget
---@field ShowAnim UWidgetAnimation
---@field Button_AddVal UButton
---@field Button_Cancellation UButton
---@field Button_Confirm UButton
---@field Button_SubVal UButton
---@field Slider_Val USlider
---@field TextBlock_Cancellation UTextBlock
---@field TextBlock_Confirm UTextBlock
---@field TextBlock_ShowInfo UTextBlock
---@field TextBlock_Val UTextBlock
--Edit Below--
local WB_SecondaryConfirmation_Strip = {
bInitDoOnce = false;
bIsShowing = false;
MinVal = 0;
MaxVal = 1;
Interval = 1;
TextFunc = function(val) return "" end ;
};
function WB_SecondaryConfirmation_Strip:Construct()
WidgetLibrary.BindButtonClicked(self.Button_Cancellation, self.ClickCancellation, self)
WidgetLibrary.BindButtonClicked(self.Button_Confirm, self.ClickConfirm, self)
WidgetLibrary.SliderOnValueChanged(self.Slider_Val, self.UpdateVal, self)
WidgetLibrary.BindButtonClicked(self.Button_AddVal, self.AddVal, self)
WidgetLibrary.BindButtonClicked(self.Button_SubVal, self.SubVal, self)
end
function WB_SecondaryConfirmation_Strip:OnShowPanel()
self.bIsShowing = true
self:PlayAnimation(self.ShowAnim, 0, 1, EUMGSequencePlayMode.Forward, 1);
end
---@param TextFunc "function:(val:int) return str"
function WB_SecondaryConfirmation_Strip:SetTextInfo(TextFunc, CancellationText, ConfirmText)
self.TextFunc = TextFunc
self:UpdateVal()
if CancellationText then
self.TextBlock_Cancellation:SetText(CancellationText)
end
if ConfirmText then
self.TextBlock_Confirm:SetText(ConfirmText)
end
end
function WB_SecondaryConfirmation_Strip:GetVal()
return math.clamp(KismetMathLibrary.Round(self.Slider_Val:GetValue() * self.Interval + self.MinVal), self.MinVal, self.MaxVal)
end
function WB_SecondaryConfirmation_Strip:SetValRange(MinVal, MaxVal)
self.MinVal = MinVal
self.MaxVal = MaxVal
self.Interval = self.MaxVal - self.MinVal
end
function WB_SecondaryConfirmation_Strip:AddVal()
local TargetVal = math.clamp(self.Slider_Val:GetValue() + 1./self.Interval, 0, 1)
self.Slider_Val:SetValue(TargetVal)
self:UpdateVal()
end
function WB_SecondaryConfirmation_Strip:SubVal()
local TargetVal = math.clamp(self.Slider_Val:GetValue() - 1./self.Interval, 0, 1)
self.Slider_Val:SetValue(TargetVal)
self:UpdateVal()
end
function WB_SecondaryConfirmation_Strip:UpdateVal()
local Val = self:GetVal()
self.TextBlock_ShowInfo:SetText(self.TextFunc(Val))
self.TextBlock_Val:SetText(tostring(Val))
end
function WB_SecondaryConfirmation_Strip:BindCancellationCallBack(InCancellationCallBackFunc, InCancellationCallBackObj)
self.CancellationCallBackFunc = InCancellationCallBackFunc
self.CancellationCallBackObj = InCancellationCallBackObj
end
function WB_SecondaryConfirmation_Strip:BindConfirmCallBack(InConfirmCallBackFunc, InConfirmCallBackObj)
self.ConfirmCallBackFunc = InConfirmCallBackFunc
self.ConfirmCallBackObj = InConfirmCallBackObj
end
function WB_SecondaryConfirmation_Strip:Reset()
self.bIsShowing = false
self:BindCancellationCallBack()
self:BindConfirmCallBack()
self.TextBlock_Cancellation:SetText("取消")
self.TextBlock_Confirm:SetText("确认")
WidgetManager:ClosePanel(WidgetConfig.EUIType.SecondaryConfirmation_Strip)
end
function WB_SecondaryConfirmation_Strip:ClickCancellation()
if not self.bIsShowing then return end
SoundSystem.PlaySound(SoundSystem.ESound.Click)
if self.CancellationCallBackFunc then
if self.CancellationCallBackObj then
self.CancellationCallBackFunc(self.CancellationCallBackObj)
else
self.CancellationCallBackFunc()
end
end
self:Reset()
end
function WB_SecondaryConfirmation_Strip:ClickConfirm()
if not self.bIsShowing then return end
SoundSystem.PlaySound(SoundSystem.ESound.Click)
if self.ConfirmCallBackFunc then
if self.ConfirmCallBackObj then
self.ConfirmCallBackFunc(self.ConfirmCallBackObj, self:GetVal())
else
self.ConfirmCallBackFunc(self:GetVal())
end
end
self:Reset()
end
-- function WB_SecondaryConfirmation_Strip:Tick(MyGeometry, InDeltaTime)
-- end
-- function WB_SecondaryConfirmation_Strip:Destruct()
-- end
return WB_SecondaryConfirmation_Strip;