HorizonTweenPlugin  4.17.0
HorizonTweenEvent.h
Go to the documentation of this file.
1 // Created by dorgon, All Rights Reserved.
2 // email: dorgonman@hotmail.com
3 // blog: dorgon.horizon-studio.net
4 
5 #pragma once
6 
7 #include "Object.h"
8 #include "Function.h"
12 
13 #include "Kismet/BlueprintAsyncActionBase.h"
14 
15 
17 
18 
20 
21 //namespace EUMGSequencePlayMode
22 
23 
24 
25 
26 
27 DECLARE_DYNAMIC_MULTICAST_DELEGATE_OneParam(FOnHorizonTweenEvent, UHorizonTweenEvent*, pTweenEvent);
28 DECLARE_MULTICAST_DELEGATE_OneParam(FOnHorizonTweenEventNative, UHorizonTweenEvent*);
32 UCLASS(BlueprintType, Blueprintable)
33 class HORIZONTWEEN_API UHorizonTweenEvent : public UBlueprintAsyncActionBase
34 {
35 
36 
37  GENERATED_BODY()
38 
39 
40 
41 protected:
42  enum class ETweenEvent {
43  InitProcess,
44  Processing,
45  Finished
46  };
47 public:
49  virtual ~UHorizonTweenEvent();
50 
51  template <typename TDerivedPtr, typename TEventParam>
52  FORCEINLINE void InitEvent(const FHorizonTweenEventParameters& eventParam,
53  TEventParam&& eventImplementParam) {
54  SetTweenEventParam(eventParam);
55  static_cast<TDerivedPtr>(this)->SetEventParam_Implementation(Forward<TEventParam>(eventImplementParam));
56  };
57 
58  template <typename TDerivedPtr, typename TEventParam>
59  const TEventParam& GetEventParam() {
60  return static_cast<TDerivedPtr>(this)->GetEventParam_Implementation();
61  };
62 
63 public: //delegate
64  // for blueprint
65  UPROPERTY(BlueprintAssignable, Category = "HorizonPlugin|TweenEvent")
66  FOnHorizonTweenEvent OnTweenStart;
67  UPROPERTY(BlueprintAssignable, Category = "HorizonPlugin|TweenEvent")
68  FOnHorizonTweenEvent OnTweenUpdate;
69  UPROPERTY(BlueprintAssignable, Category = "HorizonPlugin|TweenEvent")
70  FOnHorizonTweenEvent OnTweenLoop;
71  UPROPERTY(BlueprintAssignable, Category = "HorizonPlugin|TweenEvent")
72  FOnHorizonTweenEvent OnTweenFinished;
73 
74  // for c++ callback binding
75  FOnHorizonTweenEventNative OnTweenStartNative;
76  FOnHorizonTweenEventNative OnTweenUpdateNative;
77  FOnHorizonTweenEventNative OnTweenLoopNative;
78  FOnHorizonTweenEventNative OnTweenFinishedNative;
79 
80 protected:
81  virtual void TweenStart();
82  virtual void TweenUpdate();
83  virtual void TweenLoop();
84  virtual void TweenFinished();
85 
86 
87 
88 
89 public:
90  virtual void Init(AHorizonTweenSystem* pTweenSystem);
91 
92  virtual void Processing(float DeltaTime);// PURE_VIRTUAL(UHorizonTweenEvent::Processing, );
93  void SetEventStatus(ETweenEvent eventStatus);
94  ETweenEvent GetEventStatus() { return EventStatus; };
95  bool IsFinished() { return (ETweenEvent::Finished == EventStatus); };
96  bool IsPlaying() { return !bPause; }
97 
98  UFUNCTION(BlueprintCallable, Category = "HorizonPlugin|TweenEvent")
99  float GetCurrentDuration() { return CurrentDuration; };
100  UFUNCTION(BlueprintCallable, Category = "HorizonPlugin|TweenEvent")
101  float GetCurrentAlpha();// { return CurrentAlpha; };
102  UFUNCTION(BlueprintCallable, Category = "HorizonPlugin|TweenEvent")
103  float GetCurrentNumOfLoop() { return CurrentNumOfLoop; };
104 
105  void SetTweenEventParam(const FHorizonTweenEventParameters& param) { TweenEventParam = param; };
106  UFUNCTION(BlueprintCallable, Category = "HorizonPlugin|TweenEvent")
107  FHorizonTweenEventParameters& GetTweenEventParam() {return TweenEventParam;}
108 
109 
110 
111 protected: //TweenEventImplement
112  template <typename THorizonTweenEventParameter, typename TReturn>
113  TReturn GetTweenStart(const THorizonTweenEventParameter& paramImpl,
114  TFunction<TReturn()> getDefaultValue) {
115  TReturn result;
116 
117  if (paramImpl.TweenStartList.Num() == 0) {
118  result = getDefaultValue();
119  }
120  else {
121  int currentNumOfLoop = GetCurrentNumOfLoop();
122  if (paramImpl.bLoopTweenList) {
123  currentNumOfLoop = currentNumOfLoop % paramImpl.TweenStartList.Num();
124  }
125 
126  if (currentNumOfLoop < paramImpl.TweenStartList.Num()) {
127  result = paramImpl.TweenStartList[currentNumOfLoop];
128  }
129  else {
130  result = paramImpl.TweenStartList.Last();
131  }
132  }
133 
134  return result;
135  }
136 
137 
138  template <typename THorizonTweenEventParameter, typename TReturn>
139  TReturn GetTweenEnd(const THorizonTweenEventParameter& paramImpl,
140  TFunction<TReturn()> getDefaultValue) {
141  TReturn result;
142 
143  if (paramImpl.TweenEndList.Num() == 0) {
144  result = getDefaultValue();
145  }
146  else {
147  int currentNumOfLoop = GetCurrentNumOfLoop();
148  if (paramImpl.bLoopTweenList) {
149  currentNumOfLoop = currentNumOfLoop % paramImpl.TweenEndList.Num();
150  }
151 
152  if (currentNumOfLoop < paramImpl.TweenEndList.Num()) {
153  result = paramImpl.TweenEndList[currentNumOfLoop];
154  }
155  else {
156  result = paramImpl.TweenEndList.Last();
157  }
158  }
159 
160  return result;
161  }
162 
163 
164 
165  template <typename THorizonTweenEventParameter, typename TReturn>
166  TReturn GetTweenLerpValue(const THorizonTweenEventParameter& paramImpl,
167  TFunction<TReturn()> getDefaultValue) {
168  auto currentAlpha = GetCurrentAlpha();
169  if (paramImpl.bUseCustomCurve)
170  {
171  currentAlpha = paramImpl.CustomTweenCurve.Eval(GetCurrentAlpha());
172  }
173 
174 
175  auto tweenStart = GetTweenStart<decltype(paramImpl), TReturn>(paramImpl,
176  getDefaultValue);
177 
178 
179  auto tweenEnd = GetTweenEnd<decltype(paramImpl), TReturn>(paramImpl,
180  getDefaultValue);
181 
182  auto& tweenEventParam = GetTweenEventParam();
183  auto result = UHorizonTweenFunctionLibrary::Lerp<TReturn>(tweenEventParam.LerpMode,
184  tweenStart, tweenEnd, currentAlpha, tweenEventParam.LerpModeExtraParameterList);
185  return result;
186  };
187 public:
188  UFUNCTION(BlueprintCallable, Category = "HorizonPlugin|TweenEvent")
189  virtual void Play();
190  UFUNCTION(BlueprintCallable, Category = "HorizonPlugin|TweenEvent")
191  virtual void Stop();
192  UFUNCTION(BlueprintCallable, Category = "HorizonPlugin|TweenEvent")
193  virtual void Pause();
194  UFUNCTION(BlueprintCallable, Category = "HorizonPlugin|TweenEvent")
195  virtual void Resume();
196 
201  UFUNCTION(BlueprintCallable, Category = "HorizonPlugin|TweenEvent")
202  virtual void Finish(bool bTweenToEnd);
203 
204  UFUNCTION(BlueprintCallable, Category = "HorizonPlugin|TweenEvent")
205  void SetFreeze(bool b) {bFreeze = b;};
206  UFUNCTION(BlueprintCallable, Category = "HorizonPlugin|TweenEvent")
207  bool IsFreeze() {return bFreeze;}
208 
209 
210 
211 
212 
213 
214 private:
215  ETweenEvent EventStatus;
216  FHorizonTweenEventParameters TweenEventParam;
217 
218  TWeakObjectPtr<AHorizonTweenSystem> TweenSystemWeakPtr;
219 private:
220  float DelayCurrentDuration;
221  float CurrentAlpha;
222  float CurrentDuration;
223  int CurrentNumOfLoop;
224  bool bPause;
225 
226  //if true, only call TweenUpdate when process tween event
227  bool bFreeze;
228 
229 
230 };
231 
232 
233 
Definition: HorizonTweenSystem.h:20
Definition: HorizonTweenEvent.h:33
DECLARE_DYNAMIC_MULTICAST_DELEGATE_OneParam(FOnHorizonTweenEvent, UHorizonTweenEvent *, pTweenEvent)
TReturn GetTweenLerpValue(const THorizonTweenEventParameter &paramImpl, TFunction< TReturn()> getDefaultValue)
Definition: HorizonTweenEvent.h:166
Definition: HorizonTweenEventParameters.h:13
const TEventParam & GetEventParam()
Definition: HorizonTweenEvent.h:59
bool IsPlaying()
Definition: HorizonTweenEvent.h:96
#define HORIZONTWEEN_API
Definition: Definitions.HorizonTween.h:40
bool IsFinished()
Definition: HorizonTweenEvent.h:95
void SetTweenEventParam(const FHorizonTweenEventParameters &param)
Definition: HorizonTweenEvent.h:105
ETweenEvent
Definition: HorizonTweenEvent.h:42
FORCEINLINE void InitEvent(const FHorizonTweenEventParameters &eventParam, TEventParam &&eventImplementParam)
Definition: HorizonTweenEvent.h:52
DECLARE_MULTICAST_DELEGATE_OneParam(FOnHorizonTweenEventNative, UHorizonTweenEvent *)
TReturn GetTweenEnd(const THorizonTweenEventParameter &paramImpl, TFunction< TReturn()> getDefaultValue)
Definition: HorizonTweenEvent.h:139
TReturn GetTweenStart(const THorizonTweenEventParameter &paramImpl, TFunction< TReturn()> getDefaultValue)
Definition: HorizonTweenEvent.h:113