Skip to content

Commit

Permalink
completed porting to 4.18
Browse files Browse the repository at this point in the history
  • Loading branch information
Roberto De Ioris committed Oct 3, 2017
1 parent ed95a8a commit 5ab8b85
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 24 deletions.
60 changes: 38 additions & 22 deletions Source/PythonConsole/Private/SPythonLog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#include "Engine/LocalPlayer.h"
#include "GameFramework/GameState.h"
#include "SSearchBox.h"
#include "Runtime/Launch/Resources/Version.h"
//#include "UnrealEnginePython.h"
#define LOCTEXT_NAMESPACE "PythonConsole"

Expand Down Expand Up @@ -46,7 +47,8 @@ class SPythonConsoleEditableTextBox : public SEditableTextBox
]);
}

void SetPythonBox(SPythonConsoleInputBox *box) {
void SetPythonBox(SPythonConsoleInputBox *box)
{
SPythonConsoleEditableText *PythonEditableText = (SPythonConsoleEditableText *)EditableText.Get();
box->HistoryPosition = 0;
PythonEditableText->PythonConsoleInputBox = box;
Expand All @@ -72,15 +74,15 @@ class SPythonConsoleEditableTextBox : public SEditableTextBox
void Construct(const FArguments& InArgs)
{
SEditableText::Construct
(
SEditableText::FArguments()
.HintText(InArgs._HintText)
.OnTextChanged(InArgs._OnTextChanged)
.OnTextCommitted(InArgs._OnTextCommitted)
.ClearKeyboardFocusOnCommit(false)
.IsCaretMovedWhenGainFocus(false)
.MinDesiredWidth(400.0f)
);
(
SEditableText::FArguments()
.HintText(InArgs._HintText)
.OnTextChanged(InArgs._OnTextChanged)
.OnTextCommitted(InArgs._OnTextCommitted)
.ClearKeyboardFocusOnCommit(false)
.IsCaretMovedWhenGainFocus(false)
.MinDesiredWidth(400.0f)
);
}

virtual FReply OnKeyDown(const FGeometry& MyGeometry, const FKeyEvent& InKeyEvent)
Expand All @@ -90,16 +92,20 @@ class SPythonConsoleEditableTextBox : public SEditableTextBox
{
return FReply::Unhandled();
}
else if (InKeyEvent.GetKey() == EKeys::Up) {
if (PythonConsoleInputBox->HistoryPosition > 0) {
else if (InKeyEvent.GetKey() == EKeys::Up)
{
if (PythonConsoleInputBox->HistoryPosition > 0)
{
PythonConsoleInputBox->HistoryPosition--;
this->SetText(FText::FromString(PythonConsoleInputBox->History[PythonConsoleInputBox->HistoryPosition]));
}

return FReply::Handled();
}
else if (InKeyEvent.GetKey() == EKeys::Down) {
if (PythonConsoleInputBox->HistoryPosition < PythonConsoleInputBox->History.Num() - 1) {
else if (InKeyEvent.GetKey() == EKeys::Down)
{
if (PythonConsoleInputBox->HistoryPosition < PythonConsoleInputBox->History.Num() - 1)
{
PythonConsoleInputBox->HistoryPosition++;
this->SetText(FText::FromString(PythonConsoleInputBox->History[PythonConsoleInputBox->HistoryPosition]));
}
Expand Down Expand Up @@ -213,25 +219,31 @@ void SPythonConsoleInputBox::OnTextCommitted(const FText& InText, ETextCommit::T
//
FUnrealEnginePythonModule &PythonModule = FModuleManager::GetModuleChecked<FUnrealEnginePythonModule>("UnrealEnginePython");

if (IsMultiline) {
if (ExecString.StartsWith(" ")) {
if (IsMultiline)
{
if (ExecString.StartsWith(" "))
{
MultilineString += FString("\n") + ExecString;
}
else {
else
{
IsMultiline = false;
PythonModule.RunString(TCHAR_TO_UTF8(*MultilineString));
}
}
else if (ExecString.EndsWith(":")) {
else if (ExecString.EndsWith(":"))
{
IsMultiline = true;
MultilineString = ExecString;
}
else {
else
{
PythonModule.RunString(TCHAR_TO_UTF8(*ExecString));
}

}
else if (IsMultiline) {
else if (IsMultiline)
{
IsMultiline = false;
FUnrealEnginePythonModule &PythonModule = FModuleManager::GetModuleChecked<FUnrealEnginePythonModule>("UnrealEnginePython");
PythonModule.RunString(TCHAR_TO_UTF8(*MultilineString));
Expand Down Expand Up @@ -349,7 +361,11 @@ FPythonLogTextLayoutMarshaller::FPythonLogTextLayoutMarshaller(TArray< TSharedPt
BEGIN_SLATE_FUNCTION_BUILD_OPTIMIZATION
void SPythonLog::Construct(const FArguments& InArgs)
{
#if ENGINE_MINOR_VERSION < 18
MessagesTextMarshaller = FPythonLogTextLayoutMarshaller::Create(MoveTemp(InArgs._Messages));
#else
MessagesTextMarshaller = FPythonLogTextLayoutMarshaller::Create(InArgs._Messages);
#endif

MessagesTextBox = SNew(SMultiLineEditableTextBox)
.Style(FEditorStyle::Get(), "Log.TextBox")
Expand Down Expand Up @@ -485,14 +501,14 @@ void SPythonLog::ExtendTextBoxMenu(FMenuBuilder& Builder)
FUIAction ClearPythonLogAction(
FExecuteAction::CreateRaw(this, &SPythonLog::OnClearLog),
FCanExecuteAction::CreateSP(this, &SPythonLog::CanClearLog)
);
);

Builder.AddMenuEntry(
NSLOCTEXT("PythonConsole", "ClearLogLabel", "Clear Log"),
NSLOCTEXT("PythonConsole", "ClearLogTooltip", "Clears all log messages"),
FSlateIcon(),
ClearPythonLogAction
);
);
}

void SPythonLog::OnClearLog()
Expand Down
4 changes: 2 additions & 2 deletions Source/UnrealEnginePython/Private/UObject/UEPyPhysics.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -441,7 +441,7 @@ PyObject *py_ue_destructible_apply_damage(ue_PyUObject * self, PyObject * args)
#else
for (UActorComponent *component : actor->GetComponents())
{
if (component->Implements<IDestructibleInterface>())
if (Cast<IDestructibleInterface>(component))
{
destructible = (IDestructibleInterface *)component;
break;
Expand All @@ -460,7 +460,7 @@ PyObject *py_ue_destructible_apply_damage(ue_PyUObject * self, PyObject * args)
#else
for (UActorComponent *component : actor->GetComponents())
{
if (component->Implements<IDestructibleInterface>())
if (Cast<IDestructibleInterface>(component))
{
destructible = (IDestructibleInterface *)component;
break;
Expand Down

0 comments on commit 5ab8b85

Please sign in to comment.