Skip to content

Commit 5ab8b85

Browse files
author
Roberto De Ioris
committed
completed porting to 4.18
1 parent ed95a8a commit 5ab8b85

File tree

2 files changed

+40
-24
lines changed

2 files changed

+40
-24
lines changed

Source/PythonConsole/Private/SPythonLog.cpp

Lines changed: 38 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
#include "Engine/LocalPlayer.h"
88
#include "GameFramework/GameState.h"
99
#include "SSearchBox.h"
10+
#include "Runtime/Launch/Resources/Version.h"
1011
//#include "UnrealEnginePython.h"
1112
#define LOCTEXT_NAMESPACE "PythonConsole"
1213

@@ -46,7 +47,8 @@ class SPythonConsoleEditableTextBox : public SEditableTextBox
4647
]);
4748
}
4849

49-
void SetPythonBox(SPythonConsoleInputBox *box) {
50+
void SetPythonBox(SPythonConsoleInputBox *box)
51+
{
5052
SPythonConsoleEditableText *PythonEditableText = (SPythonConsoleEditableText *)EditableText.Get();
5153
box->HistoryPosition = 0;
5254
PythonEditableText->PythonConsoleInputBox = box;
@@ -72,15 +74,15 @@ class SPythonConsoleEditableTextBox : public SEditableTextBox
7274
void Construct(const FArguments& InArgs)
7375
{
7476
SEditableText::Construct
75-
(
76-
SEditableText::FArguments()
77-
.HintText(InArgs._HintText)
78-
.OnTextChanged(InArgs._OnTextChanged)
79-
.OnTextCommitted(InArgs._OnTextCommitted)
80-
.ClearKeyboardFocusOnCommit(false)
81-
.IsCaretMovedWhenGainFocus(false)
82-
.MinDesiredWidth(400.0f)
83-
);
77+
(
78+
SEditableText::FArguments()
79+
.HintText(InArgs._HintText)
80+
.OnTextChanged(InArgs._OnTextChanged)
81+
.OnTextCommitted(InArgs._OnTextCommitted)
82+
.ClearKeyboardFocusOnCommit(false)
83+
.IsCaretMovedWhenGainFocus(false)
84+
.MinDesiredWidth(400.0f)
85+
);
8486
}
8587

8688
virtual FReply OnKeyDown(const FGeometry& MyGeometry, const FKeyEvent& InKeyEvent)
@@ -90,16 +92,20 @@ class SPythonConsoleEditableTextBox : public SEditableTextBox
9092
{
9193
return FReply::Unhandled();
9294
}
93-
else if (InKeyEvent.GetKey() == EKeys::Up) {
94-
if (PythonConsoleInputBox->HistoryPosition > 0) {
95+
else if (InKeyEvent.GetKey() == EKeys::Up)
96+
{
97+
if (PythonConsoleInputBox->HistoryPosition > 0)
98+
{
9599
PythonConsoleInputBox->HistoryPosition--;
96100
this->SetText(FText::FromString(PythonConsoleInputBox->History[PythonConsoleInputBox->HistoryPosition]));
97101
}
98102

99103
return FReply::Handled();
100104
}
101-
else if (InKeyEvent.GetKey() == EKeys::Down) {
102-
if (PythonConsoleInputBox->HistoryPosition < PythonConsoleInputBox->History.Num() - 1) {
105+
else if (InKeyEvent.GetKey() == EKeys::Down)
106+
{
107+
if (PythonConsoleInputBox->HistoryPosition < PythonConsoleInputBox->History.Num() - 1)
108+
{
103109
PythonConsoleInputBox->HistoryPosition++;
104110
this->SetText(FText::FromString(PythonConsoleInputBox->History[PythonConsoleInputBox->HistoryPosition]));
105111
}
@@ -213,25 +219,31 @@ void SPythonConsoleInputBox::OnTextCommitted(const FText& InText, ETextCommit::T
213219
//
214220
FUnrealEnginePythonModule &PythonModule = FModuleManager::GetModuleChecked<FUnrealEnginePythonModule>("UnrealEnginePython");
215221

216-
if (IsMultiline) {
217-
if (ExecString.StartsWith(" ")) {
222+
if (IsMultiline)
223+
{
224+
if (ExecString.StartsWith(" "))
225+
{
218226
MultilineString += FString("\n") + ExecString;
219227
}
220-
else {
228+
else
229+
{
221230
IsMultiline = false;
222231
PythonModule.RunString(TCHAR_TO_UTF8(*MultilineString));
223232
}
224233
}
225-
else if (ExecString.EndsWith(":")) {
234+
else if (ExecString.EndsWith(":"))
235+
{
226236
IsMultiline = true;
227237
MultilineString = ExecString;
228238
}
229-
else {
239+
else
240+
{
230241
PythonModule.RunString(TCHAR_TO_UTF8(*ExecString));
231242
}
232243

233244
}
234-
else if (IsMultiline) {
245+
else if (IsMultiline)
246+
{
235247
IsMultiline = false;
236248
FUnrealEnginePythonModule &PythonModule = FModuleManager::GetModuleChecked<FUnrealEnginePythonModule>("UnrealEnginePython");
237249
PythonModule.RunString(TCHAR_TO_UTF8(*MultilineString));
@@ -349,7 +361,11 @@ FPythonLogTextLayoutMarshaller::FPythonLogTextLayoutMarshaller(TArray< TSharedPt
349361
BEGIN_SLATE_FUNCTION_BUILD_OPTIMIZATION
350362
void SPythonLog::Construct(const FArguments& InArgs)
351363
{
364+
#if ENGINE_MINOR_VERSION < 18
352365
MessagesTextMarshaller = FPythonLogTextLayoutMarshaller::Create(MoveTemp(InArgs._Messages));
366+
#else
367+
MessagesTextMarshaller = FPythonLogTextLayoutMarshaller::Create(InArgs._Messages);
368+
#endif
353369

354370
MessagesTextBox = SNew(SMultiLineEditableTextBox)
355371
.Style(FEditorStyle::Get(), "Log.TextBox")
@@ -485,14 +501,14 @@ void SPythonLog::ExtendTextBoxMenu(FMenuBuilder& Builder)
485501
FUIAction ClearPythonLogAction(
486502
FExecuteAction::CreateRaw(this, &SPythonLog::OnClearLog),
487503
FCanExecuteAction::CreateSP(this, &SPythonLog::CanClearLog)
488-
);
504+
);
489505

490506
Builder.AddMenuEntry(
491507
NSLOCTEXT("PythonConsole", "ClearLogLabel", "Clear Log"),
492508
NSLOCTEXT("PythonConsole", "ClearLogTooltip", "Clears all log messages"),
493509
FSlateIcon(),
494510
ClearPythonLogAction
495-
);
511+
);
496512
}
497513

498514
void SPythonLog::OnClearLog()

Source/UnrealEnginePython/Private/UObject/UEPyPhysics.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -441,7 +441,7 @@ PyObject *py_ue_destructible_apply_damage(ue_PyUObject * self, PyObject * args)
441441
#else
442442
for (UActorComponent *component : actor->GetComponents())
443443
{
444-
if (component->Implements<IDestructibleInterface>())
444+
if (Cast<IDestructibleInterface>(component))
445445
{
446446
destructible = (IDestructibleInterface *)component;
447447
break;
@@ -460,7 +460,7 @@ PyObject *py_ue_destructible_apply_damage(ue_PyUObject * self, PyObject * args)
460460
#else
461461
for (UActorComponent *component : actor->GetComponents())
462462
{
463-
if (component->Implements<IDestructibleInterface>())
463+
if (Cast<IDestructibleInterface>(component))
464464
{
465465
destructible = (IDestructibleInterface *)component;
466466
break;

0 commit comments

Comments
 (0)