feat(demo): add Bootstrap Demo Hub, Chinese UI font, and UI Demo showcase scene

This commit is contained in:
szy73711 committed 2026-12-01 03:13:35 +08:00
1 parent 3572f2da43
commit 4c83c086f4
49 files changed
+7864 -131

No files matched your search

@@ -200,6 +200,149 @@ bool FLuaCallbackBridge::CallInt(UObject* Target, const FString& ModuleName, con
return bOk;
}
bool FLuaCallbackBridge::CallIntBool(UObject* Target, const FString& ModuleName, const char* FuncName, int32 IntValue, bool bBoolValue)
{
if (ModuleName.IsEmpty())
{
return false;
}
UnLua::FLuaEnv* Env = ResolveLuaEnv(Target);
if (!Env)
{
return false;
}
lua_State* L = Env->GetMainState();
if (!L)
{
return false;
}
const int32 Top = lua_gettop(L);
int32 ErrHandlerIdx = 0;
if (!PushModuleFunction(L, ModuleName, FuncName, ErrHandlerIdx))
{
lua_settop(L, Top);
return false;
}
UnLua::PushUObject(L, Target);
lua_pushinteger(L, static_cast<lua_Integer>(IntValue));
lua_pushboolean(L, bBoolValue ? 1 : 0);
const bool bOk = (lua_pcall(L, 3, 0, ErrHandlerIdx) == LUA_OK);
lua_settop(L, Top);
return bOk;
}
bool FLuaCallbackBridge::CallIntFloat(UObject* Target, const FString& ModuleName, const char* FuncName, int32 IntValue, float FloatValue)
{
if (ModuleName.IsEmpty())
{
return false;
}
UnLua::FLuaEnv* Env = ResolveLuaEnv(Target);
if (!Env)
{
return false;
}
lua_State* L = Env->GetMainState();
if (!L)
{
return false;
}
const int32 Top = lua_gettop(L);
int32 ErrHandlerIdx = 0;
if (!PushModuleFunction(L, ModuleName, FuncName, ErrHandlerIdx))
{
lua_settop(L, Top);
return false;
}
UnLua::PushUObject(L, Target);
lua_pushinteger(L, static_cast<lua_Integer>(IntValue));
lua_pushnumber(L, static_cast<lua_Number>(FloatValue));
const bool bOk = (lua_pcall(L, 3, 0, ErrHandlerIdx) == LUA_OK);
lua_settop(L, Top);
return bOk;
}
bool FLuaCallbackBridge::CallIntString(UObject* Target, const FString& ModuleName, const char* FuncName, int32 IntValue, const FString& StrValue)
{
if (ModuleName.IsEmpty())
{
return false;
}
UnLua::FLuaEnv* Env = ResolveLuaEnv(Target);
if (!Env)
{
return false;
}
lua_State* L = Env->GetMainState();
if (!L)
{
return false;
}
const int32 Top = lua_gettop(L);
int32 ErrHandlerIdx = 0;
if (!PushModuleFunction(L, ModuleName, FuncName, ErrHandlerIdx))
{
lua_settop(L, Top);
return false;
}
UnLua::PushUObject(L, Target);
lua_pushinteger(L, static_cast<lua_Integer>(IntValue));
const FTCHARToUTF8 StrUtf8(*StrValue);
lua_pushlstring(L, StrUtf8.Get(), StrUtf8.Length());
const bool bOk = (lua_pcall(L, 3, 0, ErrHandlerIdx) == LUA_OK);
lua_settop(L, Top);
return bOk;
}
bool FLuaCallbackBridge::CallIntStringInt(UObject* Target, const FString& ModuleName, const char* FuncName, int32 IntValue, const FString& StrValue, int32 ExtraInt)
{
if (ModuleName.IsEmpty())
{
return false;
}
UnLua::FLuaEnv* Env = ResolveLuaEnv(Target);
if (!Env)
{
return false;
}
lua_State* L = Env->GetMainState();
if (!L)
{
return false;
}
const int32 Top = lua_gettop(L);
int32 ErrHandlerIdx = 0;
if (!PushModuleFunction(L, ModuleName, FuncName, ErrHandlerIdx))
{
lua_settop(L, Top);
return false;
}
UnLua::PushUObject(L, Target);
lua_pushinteger(L, static_cast<lua_Integer>(IntValue));
const FTCHARToUTF8 StrUtf8(*StrValue);
lua_pushlstring(L, StrUtf8.Get(), StrUtf8.Length());
lua_pushinteger(L, static_cast<lua_Integer>(ExtraInt));
const bool bOk = (lua_pcall(L, 4, 0, ErrHandlerIdx) == LUA_OK);
lua_settop(L, Top);
return bOk;
}
bool FLuaCallbackBridge::CallResourceLoadCallback(
UObject* GameInstanceTarget,
const FString& ModuleName,
@@ -18,6 +18,10 @@ public:
static bool Call(UObject* Target, const FString& ModuleName, const char* FuncName);
static bool CallFloat(UObject* Target, const FString& ModuleName, const char* FuncName, float Value);
static bool CallInt(UObject* Target, const FString& ModuleName, const char* FuncName, int32 Value);
static bool CallIntBool(UObject* Target, const FString& ModuleName, const char* FuncName, int32 IntValue, bool bBoolValue);
static bool CallIntFloat(UObject* Target, const FString& ModuleName, const char* FuncName, int32 IntValue, float FloatValue);
static bool CallIntString(UObject* Target, const FString& ModuleName, const char* FuncName, int32 IntValue, const FString& StrValue);
static bool CallIntStringInt(UObject* Target, const FString& ModuleName, const char* FuncName, int32 IntValue, const FString& StrValue, int32 ExtraInt);
static bool CallResourceLoadCallback(
UObject* GameInstanceTarget,
const FString& ModuleName,
+496 -13
View File
@@ -5,17 +5,37 @@
#include "Blueprint/UserWidget.h"
#include "Blueprint/WidgetTree.h"
#include "Components/Button.h"
#include "Components/CanvasPanelSlot.h"
#include "Components/CheckBox.h"
#include "Components/ComboBoxString.h"
#include "Components/EditableTextBox.h"
#include "Components/Slider.h"
#include "Components/SpinBox.h"
#include "Engine/GameInstance.h"
void ULuaButtonClickProxy::Init(ULuaUIEventSubsystem* InOwner, UButton* InButton, int32 InBindingId)
void ULuaButtonClickProxy::Init(ULuaUIEventSubsystem* InOwner, UButton* InButton, int32 InBindingId, EButtonEventKind InKind)
{
OwnerSubsystem = InOwner;
BoundButton = InButton;
BindingId = InBindingId;
EventKind = InKind;
if (InButton)
if (!InButton)
{
InButton->OnClicked.AddDynamic(this, &ULuaButtonClickProxy::HandleClicked);
return;
}
if (EventKind == EButtonEventKind::Clicked)
{
InButton->OnClicked.AddDynamic(this, &ULuaButtonClickProxy::HandleEvent);
}
else if (EventKind == EButtonEventKind::Hovered)
{
InButton->OnHovered.AddDynamic(this, &ULuaButtonClickProxy::HandleEvent);
}
else
{
InButton->OnUnhovered.AddDynamic(this, &ULuaButtonClickProxy::HandleEvent);
}
}
@@ -23,17 +43,210 @@ void ULuaButtonClickProxy::Unbind()
{
if (UButton* Button = BoundButton.Get())
{
Button->OnClicked.RemoveDynamic(this, &ULuaButtonClickProxy::HandleClicked);
if (EventKind == EButtonEventKind::Clicked)
{
Button->OnClicked.RemoveDynamic(this, &ULuaButtonClickProxy::HandleEvent);
}
else if (EventKind == EButtonEventKind::Hovered)
{
Button->OnHovered.RemoveDynamic(this, &ULuaButtonClickProxy::HandleEvent);
}
else
{
Button->OnUnhovered.RemoveDynamic(this, &ULuaButtonClickProxy::HandleEvent);
}
}
BoundButton.Reset();
OwnerSubsystem.Reset();
}
void ULuaButtonClickProxy::HandleClicked()
void ULuaButtonClickProxy::HandleEvent()
{
if (ULuaUIEventSubsystem* Owner = OwnerSubsystem.Get())
{
Owner->DispatchButtonClicked(BindingId);
if (EventKind == EButtonEventKind::Clicked)
{
Owner->DispatchButtonClicked(BindingId);
}
else
{
Owner->DispatchActionEvent(BindingId);
}
}
}
void ULuaCheckBoxProxy::Init(ULuaUIEventSubsystem* InOwner, UCheckBox* InCheckBox, int32 InBindingId)
{
OwnerSubsystem = InOwner;
BoundCheckBox = InCheckBox;
BindingId = InBindingId;
if (InCheckBox)
{
InCheckBox->OnCheckStateChanged.AddDynamic(this, &ULuaCheckBoxProxy::HandleCheckStateChanged);
}
}
void ULuaCheckBoxProxy::Unbind()
{
if (UCheckBox* CheckBox = BoundCheckBox.Get())
{
CheckBox->OnCheckStateChanged.RemoveDynamic(this, &ULuaCheckBoxProxy::HandleCheckStateChanged);
}
BoundCheckBox.Reset();
OwnerSubsystem.Reset();
}
void ULuaCheckBoxProxy::HandleCheckStateChanged(bool bIsChecked)
{
if (ULuaUIEventSubsystem* Owner = OwnerSubsystem.Get())
{
Owner->DispatchBoolChanged(BindingId, bIsChecked);
}
}
void ULuaSliderProxy::Init(ULuaUIEventSubsystem* InOwner, USlider* InSlider, int32 InBindingId)
{
OwnerSubsystem = InOwner;
BoundSlider = InSlider;
BindingId = InBindingId;
if (InSlider)
{
InSlider->OnValueChanged.AddDynamic(this, &ULuaSliderProxy::HandleValueChanged);
}
}
void ULuaSliderProxy::Unbind()
{
if (USlider* Slider = BoundSlider.Get())
{
Slider->OnValueChanged.RemoveDynamic(this, &ULuaSliderProxy::HandleValueChanged);
}
BoundSlider.Reset();
OwnerSubsystem.Reset();
}
void ULuaSliderProxy::HandleValueChanged(float Value)
{
if (ULuaUIEventSubsystem* Owner = OwnerSubsystem.Get())
{
Owner->DispatchFloatChanged(BindingId, Value);
}
}
void ULuaSpinBoxProxy::Init(ULuaUIEventSubsystem* InOwner, USpinBox* InSpinBox, int32 InBindingId)
{
OwnerSubsystem = InOwner;
BoundSpinBox = InSpinBox;
BindingId = InBindingId;
if (InSpinBox)
{
InSpinBox->OnValueChanged.AddDynamic(this, &ULuaSpinBoxProxy::HandleValueChanged);
}
}
void ULuaSpinBoxProxy::Unbind()
{
if (USpinBox* SpinBox = BoundSpinBox.Get())
{
SpinBox->OnValueChanged.RemoveDynamic(this, &ULuaSpinBoxProxy::HandleValueChanged);
}
BoundSpinBox.Reset();
OwnerSubsystem.Reset();
}
void ULuaSpinBoxProxy::HandleValueChanged(float Value)
{
if (ULuaUIEventSubsystem* Owner = OwnerSubsystem.Get())
{
Owner->DispatchFloatChanged(BindingId, Value);
}
}
void ULuaEditableTextProxy::Init(ULuaUIEventSubsystem* InOwner, UEditableTextBox* InTextBox, int32 InBindingId, ETextEventKind InKind)
{
OwnerSubsystem = InOwner;
BoundTextBox = InTextBox;
BindingId = InBindingId;
EventKind = InKind;
if (!InTextBox)
{
return;
}
if (EventKind == ETextEventKind::Changed)
{
InTextBox->OnTextChanged.AddDynamic(this, &ULuaEditableTextProxy::HandleTextChanged);
}
else
{
InTextBox->OnTextCommitted.AddDynamic(this, &ULuaEditableTextProxy::HandleTextCommitted);
}
}
void ULuaEditableTextProxy::Unbind()
{
if (UEditableTextBox* TextBox = BoundTextBox.Get())
{
if (EventKind == ETextEventKind::Changed)
{
TextBox->OnTextChanged.RemoveDynamic(this, &ULuaEditableTextProxy::HandleTextChanged);
}
else
{
TextBox->OnTextCommitted.RemoveDynamic(this, &ULuaEditableTextProxy::HandleTextCommitted);
}
}
BoundTextBox.Reset();
OwnerSubsystem.Reset();
}
void ULuaEditableTextProxy::HandleTextChanged(const FText& Text)
{
if (ULuaUIEventSubsystem* Owner = OwnerSubsystem.Get())
{
Owner->DispatchTextChanged(BindingId, Text.ToString());
}
}
void ULuaEditableTextProxy::HandleTextCommitted(const FText& Text, ETextCommit::Type CommitMethod)
{
if (ULuaUIEventSubsystem* Owner = OwnerSubsystem.Get())
{
Owner->DispatchTextCommitted(BindingId, Text.ToString(), static_cast<int32>(CommitMethod));
}
}
void ULuaComboBoxProxy::Init(ULuaUIEventSubsystem* InOwner, UComboBoxString* InComboBox, int32 InBindingId)
{
OwnerSubsystem = InOwner;
BoundComboBox = InComboBox;
BindingId = InBindingId;
if (InComboBox)
{
InComboBox->OnSelectionChanged.AddDynamic(this, &ULuaComboBoxProxy::HandleSelectionChanged);
}
}
void ULuaComboBoxProxy::Unbind()
{
if (UComboBoxString* ComboBox = BoundComboBox.Get())
{
ComboBox->OnSelectionChanged.RemoveDynamic(this, &ULuaComboBoxProxy::HandleSelectionChanged);
}
BoundComboBox.Reset();
OwnerSubsystem.Reset();
}
void ULuaComboBoxProxy::HandleSelectionChanged(FString SelectedItem, ESelectInfo::Type SelectionType)
{
if (ULuaUIEventSubsystem* Owner = OwnerSubsystem.Get())
{
Owner->DispatchSelectionChanged(BindingId, SelectedItem, static_cast<int32>(SelectionType));
}
}
@@ -44,14 +257,14 @@ ULuaUIEventSubsystem* ULuaUIEventSubsystem::GetFromGameInstance(UGameInstance* G
void ULuaUIEventSubsystem::Deinitialize()
{
for (TPair<int32, TObjectPtr<ULuaButtonClickProxy>>& Pair : ActiveButtonProxies)
for (TPair<int32, TObjectPtr<ULuaWidgetEventProxyBase>>& Pair : ActiveProxies)
{
if (Pair.Value)
{
Pair.Value->Unbind();
}
}
ActiveButtonProxies.Reset();
ActiveProxies.Reset();
Super::Deinitialize();
}
@@ -64,15 +277,132 @@ int32 ULuaUIEventSubsystem::BindButtonClicked(UButton* Button)
const int32 BindingId = ++NextBindingId;
ULuaButtonClickProxy* Proxy = NewObject<ULuaButtonClickProxy>(this);
Proxy->Init(this, Button, BindingId);
ActiveButtonProxies.Add(BindingId, Proxy);
Proxy->Init(this, Button, BindingId, ULuaButtonClickProxy::EButtonEventKind::Clicked);
ActiveProxies.Add(BindingId, Proxy);
return BindingId;
}
int32 ULuaUIEventSubsystem::BindButtonHovered(UButton* Button)
{
if (!IsValid(Button))
{
return 0;
}
const int32 BindingId = ++NextBindingId;
ULuaButtonClickProxy* Proxy = NewObject<ULuaButtonClickProxy>(this);
Proxy->Init(this, Button, BindingId, ULuaButtonClickProxy::EButtonEventKind::Hovered);
ActiveProxies.Add(BindingId, Proxy);
return BindingId;
}
int32 ULuaUIEventSubsystem::BindButtonUnhovered(UButton* Button)
{
if (!IsValid(Button))
{
return 0;
}
const int32 BindingId = ++NextBindingId;
ULuaButtonClickProxy* Proxy = NewObject<ULuaButtonClickProxy>(this);
Proxy->Init(this, Button, BindingId, ULuaButtonClickProxy::EButtonEventKind::Unhovered);
ActiveProxies.Add(BindingId, Proxy);
return BindingId;
}
int32 ULuaUIEventSubsystem::BindCheckBoxChanged(UCheckBox* CheckBox)
{
if (!IsValid(CheckBox))
{
return 0;
}
const int32 BindingId = ++NextBindingId;
ULuaCheckBoxProxy* Proxy = NewObject<ULuaCheckBoxProxy>(this);
Proxy->Init(this, CheckBox, BindingId);
ActiveProxies.Add(BindingId, Proxy);
return BindingId;
}
int32 ULuaUIEventSubsystem::BindSliderChanged(USlider* Slider)
{
if (!IsValid(Slider))
{
return 0;
}
const int32 BindingId = ++NextBindingId;
ULuaSliderProxy* Proxy = NewObject<ULuaSliderProxy>(this);
Proxy->Init(this, Slider, BindingId);
ActiveProxies.Add(BindingId, Proxy);
return BindingId;
}
int32 ULuaUIEventSubsystem::BindSpinBoxChanged(USpinBox* SpinBox)
{
if (!IsValid(SpinBox))
{
return 0;
}
const int32 BindingId = ++NextBindingId;
ULuaSpinBoxProxy* Proxy = NewObject<ULuaSpinBoxProxy>(this);
Proxy->Init(this, SpinBox, BindingId);
ActiveProxies.Add(BindingId, Proxy);
return BindingId;
}
int32 ULuaUIEventSubsystem::BindEditableTextChanged(UEditableTextBox* TextBox)
{
if (!IsValid(TextBox))
{
return 0;
}
const int32 BindingId = ++NextBindingId;
ULuaEditableTextProxy* Proxy = NewObject<ULuaEditableTextProxy>(this);
Proxy->Init(this, TextBox, BindingId, ULuaEditableTextProxy::ETextEventKind::Changed);
ActiveProxies.Add(BindingId, Proxy);
return BindingId;
}
int32 ULuaUIEventSubsystem::BindEditableTextCommitted(UEditableTextBox* TextBox)
{
if (!IsValid(TextBox))
{
return 0;
}
const int32 BindingId = ++NextBindingId;
ULuaEditableTextProxy* Proxy = NewObject<ULuaEditableTextProxy>(this);
Proxy->Init(this, TextBox, BindingId, ULuaEditableTextProxy::ETextEventKind::Committed);
ActiveProxies.Add(BindingId, Proxy);
return BindingId;
}
int32 ULuaUIEventSubsystem::BindComboBoxSelectionChanged(UComboBoxString* ComboBox)
{
if (!IsValid(ComboBox))
{
return 0;
}
const int32 BindingId = ++NextBindingId;
ULuaComboBoxProxy* Proxy = NewObject<ULuaComboBoxProxy>(this);
Proxy->Init(this, ComboBox, BindingId);
ActiveProxies.Add(BindingId, Proxy);
return BindingId;
}
bool ULuaUIEventSubsystem::UnbindButtonClicked(int32 BindingId)
{
TObjectPtr<ULuaButtonClickProxy> Proxy;
if (!ActiveButtonProxies.RemoveAndCopyValue(BindingId, Proxy))
return UnbindWidgetEvent(BindingId);
}
bool ULuaUIEventSubsystem::UnbindWidgetEvent(int32 BindingId)
{
TObjectPtr<ULuaWidgetEventProxyBase> Proxy;
if (!ActiveProxies.RemoveAndCopyValue(BindingId, Proxy))
{
return false;
}
@@ -93,6 +423,20 @@ UWidget* ULuaUIEventSubsystem::FindChildWidgetByName(UUserWidget* RootWidget, co
return RootWidget->WidgetTree->FindWidget(WidgetName);
}
bool ULuaUIEventSubsystem::SetCanvasPosition(UWidget* Widget, const FVector2D& Position)
{
if (!IsValid(Widget))
{
return false;
}
if (UCanvasPanelSlot* CanvasSlot = Cast<UCanvasPanelSlot>(Widget->Slot))
{
CanvasSlot->SetPosition(Position);
return true;
}
return false;
}
bool ULuaUIEventSubsystem::SimulateButtonClick(UButton* Button)
{
if (!IsValid(Button))
@@ -103,11 +447,150 @@ bool ULuaUIEventSubsystem::SimulateButtonClick(UButton* Button)
return true;
}
bool ULuaUIEventSubsystem::SimulateButtonHover(UButton* Button, bool bHovered)
{
if (!IsValid(Button))
{
return false;
}
if (bHovered)
{
Button->OnHovered.Broadcast();
}
else
{
Button->OnUnhovered.Broadcast();
}
return true;
}
bool ULuaUIEventSubsystem::SimulateCheckBoxToggle(UCheckBox* CheckBox, bool bIsChecked)
{
if (!IsValid(CheckBox))
{
return false;
}
CheckBox->SetIsChecked(bIsChecked);
CheckBox->OnCheckStateChanged.Broadcast(bIsChecked);
return true;
}
bool ULuaUIEventSubsystem::SimulateSliderValue(USlider* Slider, float Value)
{
if (!IsValid(Slider))
{
return false;
}
Slider->SetValue(Value);
Slider->OnValueChanged.Broadcast(Value);
return true;
}
bool ULuaUIEventSubsystem::SimulateSpinBoxValue(USpinBox* SpinBox, float Value)
{
if (!IsValid(SpinBox))
{
return false;
}
SpinBox->SetValue(Value);
SpinBox->OnValueChanged.Broadcast(Value);
return true;
}
bool ULuaUIEventSubsystem::SimulateEditableTextChange(UEditableTextBox* TextBox, const FString& NewText)
{
if (!IsValid(TextBox))
{
return false;
}
const FText TextVal = FText::FromString(NewText);
TextBox->SetText(TextVal);
TextBox->OnTextChanged.Broadcast(TextVal);
return true;
}
bool ULuaUIEventSubsystem::SimulateEditableTextCommit(UEditableTextBox* TextBox, const FString& NewText, int32 CommitMethod)
{
if (!IsValid(TextBox))
{
return false;
}
const FText TextVal = FText::FromString(NewText);
TextBox->SetText(TextVal);
TextBox->OnTextCommitted.Broadcast(TextVal, static_cast<ETextCommit::Type>(CommitMethod));
return true;
}
bool ULuaUIEventSubsystem::SimulateComboBoxSelect(UComboBoxString* ComboBox, const FString& Option)
{
if (!IsValid(ComboBox))
{
return false;
}
ComboBox->SetSelectedOption(Option);
ComboBox->OnSelectionChanged.Broadcast(Option, ESelectInfo::OnMouseClick);
return true;
}
void ULuaUIEventSubsystem::DispatchButtonClicked(int32 BindingId)
{
if (!ActiveButtonProxies.Contains(BindingId))
if (!ActiveProxies.Contains(BindingId))
{
return;
}
FLuaCallbackBridge::CallInt(GetGameInstance(), LuaCallbackModule, "OnNativeButtonClicked", BindingId);
}
void ULuaUIEventSubsystem::DispatchActionEvent(int32 BindingId)
{
if (!ActiveProxies.Contains(BindingId))
{
return;
}
FLuaCallbackBridge::CallInt(GetGameInstance(), LuaCallbackModule, "OnNativeActionEvent", BindingId);
}
void ULuaUIEventSubsystem::DispatchBoolChanged(int32 BindingId, bool bValue)
{
if (!ActiveProxies.Contains(BindingId))
{
return;
}
FLuaCallbackBridge::CallIntBool(GetGameInstance(), LuaCallbackModule, "OnNativeBoolChanged", BindingId, bValue);
}
void ULuaUIEventSubsystem::DispatchFloatChanged(int32 BindingId, float Value)
{
if (!ActiveProxies.Contains(BindingId))
{
return;
}
FLuaCallbackBridge::CallIntFloat(GetGameInstance(), LuaCallbackModule, "OnNativeFloatChanged", BindingId, Value);
}
void ULuaUIEventSubsystem::DispatchTextChanged(int32 BindingId, const FString& Text)
{
if (!ActiveProxies.Contains(BindingId))
{
return;
}
FLuaCallbackBridge::CallIntString(GetGameInstance(), LuaCallbackModule, "OnNativeTextChanged", BindingId, Text);
}
void ULuaUIEventSubsystem::DispatchTextCommitted(int32 BindingId, const FString& Text, int32 CommitMethod)
{
if (!ActiveProxies.Contains(BindingId))
{
return;
}
FLuaCallbackBridge::CallIntStringInt(GetGameInstance(), LuaCallbackModule, "OnNativeTextCommitted", BindingId, Text, CommitMethod);
}
void ULuaUIEventSubsystem::DispatchSelectionChanged(int32 BindingId, const FString& SelectedItem, int32 SelectType)
{
if (!ActiveProxies.Contains(BindingId))
{
return;
}
FLuaCallbackBridge::CallIntStringInt(GetGameInstance(), LuaCallbackModule, "OnNativeSelectionChanged", BindingId, SelectedItem, SelectType);
}
+187 -12
View File
@@ -4,34 +4,151 @@
#include "CoreMinimal.h"
#include "Subsystems/GameInstanceSubsystem.h"
#include "Types/SlateEnums.h"
#include "LuaUIEventSubsystem.generated.h"
class UButton;
class UCheckBox;
class UComboBoxString;
class UEditableTextBox;
class USlider;
class USpinBox;
class UUserWidget;
class UWidget;
class ULuaUIEventSubsystem;
UCLASS()
class UNREALLUADEMO_API ULuaButtonClickProxy : public UObject
UCLASS(Abstract)
class UNREALLUADEMO_API ULuaWidgetEventProxyBase : public UObject
{
GENERATED_BODY()
public:
void Init(ULuaUIEventSubsystem* InOwner, UButton* InButton, int32 InBindingId);
void Unbind();
virtual void Unbind() {}
protected:
TWeakObjectPtr<ULuaUIEventSubsystem> OwnerSubsystem;
int32 BindingId = 0;
};
UCLASS()
class UNREALLUADEMO_API ULuaButtonClickProxy : public ULuaWidgetEventProxyBase
{
GENERATED_BODY()
public:
enum class EButtonEventKind : uint8
{
Clicked,
Hovered,
Unhovered,
};
void Init(ULuaUIEventSubsystem* InOwner, UButton* InButton, int32 InBindingId, EButtonEventKind InKind = EButtonEventKind::Clicked);
virtual void Unbind() override;
UFUNCTION()
void HandleClicked();
void HandleEvent();
private:
TWeakObjectPtr<ULuaUIEventSubsystem> OwnerSubsystem;
TWeakObjectPtr<UButton> BoundButton;
int32 BindingId = 0;
EButtonEventKind EventKind = EButtonEventKind::Clicked;
};
UCLASS()
class UNREALLUADEMO_API ULuaCheckBoxProxy : public ULuaWidgetEventProxyBase
{
GENERATED_BODY()
public:
void Init(ULuaUIEventSubsystem* InOwner, UCheckBox* InCheckBox, int32 InBindingId);
virtual void Unbind() override;
UFUNCTION()
void HandleCheckStateChanged(bool bIsChecked);
private:
TWeakObjectPtr<UCheckBox> BoundCheckBox;
};
UCLASS()
class UNREALLUADEMO_API ULuaSliderProxy : public ULuaWidgetEventProxyBase
{
GENERATED_BODY()
public:
void Init(ULuaUIEventSubsystem* InOwner, USlider* InSlider, int32 InBindingId);
virtual void Unbind() override;
UFUNCTION()
void HandleValueChanged(float Value);
private:
TWeakObjectPtr<USlider> BoundSlider;
};
UCLASS()
class UNREALLUADEMO_API ULuaSpinBoxProxy : public ULuaWidgetEventProxyBase
{
GENERATED_BODY()
public:
void Init(ULuaUIEventSubsystem* InOwner, USpinBox* InSpinBox, int32 InBindingId);
virtual void Unbind() override;
UFUNCTION()
void HandleValueChanged(float Value);
private:
TWeakObjectPtr<USpinBox> BoundSpinBox;
};
UCLASS()
class UNREALLUADEMO_API ULuaEditableTextProxy : public ULuaWidgetEventProxyBase
{
GENERATED_BODY()
public:
enum class ETextEventKind : uint8
{
Changed,
Committed,
};
void Init(ULuaUIEventSubsystem* InOwner, UEditableTextBox* InTextBox, int32 InBindingId, ETextEventKind InKind);
virtual void Unbind() override;
UFUNCTION()
void HandleTextChanged(const FText& Text);
UFUNCTION()
void HandleTextCommitted(const FText& Text, ETextCommit::Type CommitMethod);
private:
TWeakObjectPtr<UEditableTextBox> BoundTextBox;
ETextEventKind EventKind = ETextEventKind::Changed;
};
UCLASS()
class UNREALLUADEMO_API ULuaComboBoxProxy : public ULuaWidgetEventProxyBase
{
GENERATED_BODY()
public:
void Init(ULuaUIEventSubsystem* InOwner, UComboBoxString* InComboBox, int32 InBindingId);
virtual void Unbind() override;
UFUNCTION()
void HandleSelectionChanged(FString SelectedItem, ESelectInfo::Type SelectionType);
private:
TWeakObjectPtr<UComboBoxString> BoundComboBox;
};
/**
* Per-GameInstance UMG delegate bridge for pure TS UI controllers.
* Routes UButton::OnClicked to TS `framework.ui.ui_delegate_bridge.OnNativeButtonClicked(gi, bindingId)`
* without requiring Lua UObject inheritance (@unlua), preserving 100% single-file hot-reload.
* Routes UMG widget delegates (Button, CheckBox, Slider, SpinBox, EditableTextBox, ComboBoxString)
* to TS `framework.ui.ui_delegate_bridge` without requiring Lua UObject inheritance (@unlua),
* preserving 100% single-file hot-reload.
*/
UCLASS()
class UNREALLUADEMO_API ULuaUIEventSubsystem : public UGameInstanceSubsystem
@@ -48,25 +165,83 @@ public:
UFUNCTION(BlueprintCallable, Category = "Lua|UI")
int32 BindButtonClicked(UButton* Button);
UFUNCTION(BlueprintCallable, Category = "Lua|UI")
int32 BindButtonHovered(UButton* Button);
UFUNCTION(BlueprintCallable, Category = "Lua|UI")
int32 BindButtonUnhovered(UButton* Button);
UFUNCTION(BlueprintCallable, Category = "Lua|UI")
int32 BindCheckBoxChanged(UCheckBox* CheckBox);
UFUNCTION(BlueprintCallable, Category = "Lua|UI")
int32 BindSliderChanged(USlider* Slider);
UFUNCTION(BlueprintCallable, Category = "Lua|UI")
int32 BindSpinBoxChanged(USpinBox* SpinBox);
UFUNCTION(BlueprintCallable, Category = "Lua|UI")
int32 BindEditableTextChanged(UEditableTextBox* TextBox);
UFUNCTION(BlueprintCallable, Category = "Lua|UI")
int32 BindEditableTextCommitted(UEditableTextBox* TextBox);
UFUNCTION(BlueprintCallable, Category = "Lua|UI")
int32 BindComboBoxSelectionChanged(UComboBoxString* ComboBox);
UFUNCTION(BlueprintCallable, Category = "Lua|UI")
bool UnbindButtonClicked(int32 BindingId);
UFUNCTION(BlueprintCallable, Category = "Lua|UI")
bool UnbindWidgetEvent(int32 BindingId);
UFUNCTION(BlueprintPure, Category = "Lua|UI")
int32 GetActiveBindingCount() const { return ActiveButtonProxies.Num(); }
int32 GetActiveBindingCount() const { return ActiveProxies.Num(); }
/** Helper: finds a named UWidget inside a UUserWidget's WidgetTree (validates designer renames cleanly). */
UFUNCTION(BlueprintPure, Category = "Lua|UI")
static UWidget* FindChildWidgetByName(UUserWidget* RootWidget, const FName& WidgetName);
/** Simulates a button click for automated UE tests (invokes Button->OnClicked.Broadcast()). */
/** Helper: sets CanvasPanelSlot position if the widget is slotted inside a UCanvasPanel. */
UFUNCTION(BlueprintCallable, Category = "Lua|UI")
static bool SetCanvasPosition(UWidget* Widget, const FVector2D& Position);
/** Automated UE test simulation helpers. */
UFUNCTION(BlueprintCallable, Category = "Lua|UI|Test")
static bool SimulateButtonClick(UButton* Button);
UFUNCTION(BlueprintCallable, Category = "Lua|UI|Test")
static bool SimulateButtonHover(UButton* Button, bool bHovered);
UFUNCTION(BlueprintCallable, Category = "Lua|UI|Test")
static bool SimulateCheckBoxToggle(UCheckBox* CheckBox, bool bIsChecked);
UFUNCTION(BlueprintCallable, Category = "Lua|UI|Test")
static bool SimulateSliderValue(USlider* Slider, float Value);
UFUNCTION(BlueprintCallable, Category = "Lua|UI|Test")
static bool SimulateSpinBoxValue(USpinBox* SpinBox, float Value);
UFUNCTION(BlueprintCallable, Category = "Lua|UI|Test")
static bool SimulateEditableTextChange(UEditableTextBox* TextBox, const FString& NewText);
UFUNCTION(BlueprintCallable, Category = "Lua|UI|Test")
static bool SimulateEditableTextCommit(UEditableTextBox* TextBox, const FString& NewText, int32 CommitMethod);
UFUNCTION(BlueprintCallable, Category = "Lua|UI|Test")
static bool SimulateComboBoxSelect(UComboBoxString* ComboBox, const FString& Option);
void DispatchButtonClicked(int32 BindingId);
void DispatchActionEvent(int32 BindingId);
void DispatchBoolChanged(int32 BindingId, bool bValue);
void DispatchFloatChanged(int32 BindingId, float Value);
void DispatchTextChanged(int32 BindingId, const FString& Text);
void DispatchTextCommitted(int32 BindingId, const FString& Text, int32 CommitMethod);
void DispatchSelectionChanged(int32 BindingId, const FString& SelectedItem, int32 SelectType);
private:
UPROPERTY(Transient)
TMap<int32, TObjectPtr<ULuaButtonClickProxy>> ActiveButtonProxies;
TMap<int32, TObjectPtr<ULuaWidgetEventProxyBase>> ActiveProxies;
int32 NextBindingId = 0;
FString LuaCallbackModule = TEXT("framework.ui.ui_delegate_bridge");
File diff suppressed because it is too large. Load diff
@@ -0,0 +1,46 @@
// Copyright Epic Games, Inc. All Rights Reserved.
#pragma once
#include "CoreMinimal.h"
#include "Commandlets/Commandlet.h"
#include "SetupDemoAssetsCommandlet.generated.h"
class UFont;
class UFontFace;
/**
* Programmatically generates Chinese font assets, Demo textures, /Game/Maps/L_DemoUI,
* and all UMG Widget Blueprints for the Bootstrap Demo Hub and UI Demo scene.
*
* Run via:
* UnrealEditor-Cmd UnrealLuaDemo.uproject -run=SetupDemoAssets -unattended -nop4 -nosplash -NullRHI
*/
UCLASS()
class UNREALLUADEMOEDITOR_API USetupDemoAssetsCommandlet : public UCommandlet
{
GENERATED_BODY()
public:
USetupDemoAssetsCommandlet();
virtual int32 Main(const FString& Params) override;
private:
UFontFace* CreateChineseFontFace() const;
UFont* CreateDemoUIFont(UFontFace* CJKFontFace) const;
bool CreateDemoMap(const FString& PackageName, const FString& MapName) const;
bool CreateProceduralTexture(const FString& PackageName, const FString& AssetName, int32 StyleIndex) const;
bool CreateDemoHubBlueprint(UFont* DemoFont) const;
bool CreateDemoHubItemBlueprint(UFont* DemoFont) const;
bool CreateUIDemoMainBlueprint(UFont* DemoFont) const;
bool CreateUIDemoListItemBlueprint(UFont* DemoFont) const;
bool CreateUIDemoNormalBlueprint(UFont* DemoFont) const;
bool CreateUIDemoFullscreenBlueprint(UFont* DemoFont) const;
bool CreateUIDemoModalBlueprint(UFont* DemoFont) const;
bool CreateUIDemoCachedBlueprint(UFont* DemoFont) const;
bool CreateUIDemoMultiBlueprint(UFont* DemoFont) const;
bool CreateUIDemoToastBlueprint(UFont* DemoFont) const;
bool CreateUIDemoSystemBlueprint(UFont* DemoFont) const;
};