text: ﻿#include "BFL/KBFL_Widgets.h"
  
  #include <string>
  
  #include "Blueprint/UserWidget.h"
  #include "Patching/BlueprintHookHelper.h"
  #include "Patching/BlueprintHookManager.h"
  
  void UKBFL_Widgets::BindOnWidget(const TSubclassOf<UUserWidget> WidgetClass, FOnWidgetCreated Binding) {
  	if (!WidgetClass)
  		return;
  	UFunction* ConstructFunction = WidgetClass->FindFunctionByName(TEXT("Construct"));
  	if (!ConstructFunction || ConstructFunction->IsNative())
  	{
  		return;
  	}
  	UBlueprintHookManager* HookManager = GEngine->GetEngineSubsystem<UBlueprintHookManager>();
  	HookManager->HookBlueprintFunction(ConstructFunction, [Binding](FBlueprintHookHelper& HookHelper) {
  		Binding.ExecuteIfBound(Cast<UUserWidget>(HookHelper.GetContext()));
  		}, EPredefinedHookOffset::Return);
  }
  
  void UKBFL_Widgets::TextToNumbers(float& Float, int& Int, FText Text, bool ShouldClamp, float ClampMin, float ClampMax,
  	bool ShouldRound)
  {
  	Float = FCString::Atof(*Text.ToString());
  	if(ShouldRound)
  		Float = FMath::RoundToFloat(Float);
  
  	if(ShouldClamp)
  		Float = FMath::Clamp(Float, ClampMin, ClampMax);
  
  	Int = FMath::RoundToInt(Float);
  }
  
  void UKBFL_Widgets::SortFloatArray(TArray<float>& FloatArray)
  {
  	FloatArray.Sort();
  }
  
  void UKBFL_Widgets::SortIntArray(TArray<float>& IntArray)
  {
  	IntArray.Sort();
  }
  
  
  
  
  