A Demo Project for the UnrealEngineSDK
Loading...
Searching...
No Matches
DialogueEditableTextPropertyHandle.h
Go to the documentation of this file.
1// Copyright Csaba Molnar, Daniel Butum. All Rights Reserved.
2#pragma once
3#include "CoreMinimal.h"
5#include "IPropertyUtilities.h"
6#include "PropertyHandle.h"
8
9// FROM: FTextCustomization
10// Allows us to edit a property handle
12{
13public:
14 FDialogueEditableTextPropertyHandle(const TSharedRef<IPropertyHandle>& InPropertyHandle, const TSharedPtr<IPropertyUtilities>& InPropertyUtilities)
15 : PropertyHandle(InPropertyHandle)
16 , PropertyUtilities(InPropertyUtilities)
17 {
18 }
19
20 bool IsMultiLineText() const override
21 {
22 return PropertyHandle->IsValidHandle() && PropertyHandle->GetMetaDataProperty()->GetBoolMetaData("MultiLine");
23 }
24
25 bool IsPassword() const override
26 {
27 return PropertyHandle->IsValidHandle() && PropertyHandle->GetMetaDataProperty()->GetBoolMetaData("PasswordField");
28 }
29
30 bool IsReadOnly() const override
31 {
32 return !PropertyHandle->IsValidHandle() || PropertyHandle->IsEditConst();
33 }
34
35 bool IsDefaultValue() const override
36 {
37 return PropertyHandle->IsValidHandle() && !PropertyHandle->DiffersFromDefault();
38 }
39
40 FText GetToolTipText() const override
41 {
42 return PropertyHandle->IsValidHandle() ? PropertyHandle->GetToolTipText() : FText::GetEmpty();
43 }
44
45 int32 GetNumTexts() const override
46 {
47 return (PropertyHandle->IsValidHandle())
48 ? PropertyHandle->GetNumPerObjectValues()
49 : 0;
50 }
51
52 FText GetText(int32 InIndex) const override
53 {
54 if (PropertyHandle->IsValidHandle())
55 {
56 FString ObjectValue;
57 if (PropertyHandle->GetPerObjectValue(InIndex, ObjectValue) == FPropertyAccess::Success)
58 {
59 FText TextValue;
60 if (FTextStringHelper::ReadFromBuffer(*ObjectValue, TextValue))
61 {
62 return TextValue;
63 }
64 }
65 }
66
67 return FText::GetEmpty();
68 }
69
70 void SetText(int32 InIndex, const FText& InText) override
71 {
72 if (PropertyHandle->IsValidHandle())
73 {
74 FString ObjectValue;
75 FTextStringHelper::WriteToBuffer(ObjectValue, InText);
76 PropertyHandle->SetPerObjectValue(InIndex, ObjectValue);
77 }
78 }
79
80 bool IsValidText(const FText& InText, FText& OutErrorMsg) const override
81 {
82 return true;
83 }
84
85#if USE_STABLE_LOCALIZATION_KEYS
86 void GetStableTextId(
87 int32 InIndex,
88 ETextPropertyEditAction InEditAction,
89 const FString& InTextSource,
90 const FString& InProposedNamespace,
91 const FString& InProposedKey,
92 FString& OutStableNamespace, FString& OutStableKey
93 ) const override
94 {
95 if (PropertyHandle->IsValidHandle())
96 {
97 TArray<UPackage*> PropertyPackages;
98 PropertyHandle->GetOuterPackages(PropertyPackages);
99
100 check(PropertyPackages.IsValidIndex(InIndex));
101
102 // NOTE: We use our copied version so that everything is in sync
103 FDlgLocalizationHelper::StaticStableTextId(PropertyPackages[InIndex], InEditAction, InTextSource, InProposedNamespace, InProposedKey, OutStableNamespace, OutStableKey);
104 //StaticStableTextId(PropertyPackages[InIndex], InEditAction, InTextSource, InProposedNamespace, InProposedKey, OutStableNamespace, OutStableKey);
105 }
106 }
107#endif // USE_STABLE_LOCALIZATION_KEYS
108
109 void RequestRefresh() override
110 {
111 if (PropertyUtilities.IsValid())
112 {
113 PropertyUtilities->RequestRefresh();
114 }
115 }
116
117private:
118 TSharedRef<IPropertyHandle> PropertyHandle;
119 TSharedPtr<IPropertyUtilities> PropertyUtilities;
120};
void SetText(int32 InIndex, const FText &InText) override
FDialogueEditableTextPropertyHandle(const TSharedRef< IPropertyHandle > &InPropertyHandle, const TSharedPtr< IPropertyUtilities > &InPropertyUtilities)
bool IsValidText(const FText &InText, FText &OutErrorMsg) const override