added preliminary version of python console · rocksonchan/UnrealEnginePython@c85375c · GitHub
Skip to content

Commit c85375c

Browse files
author
Roberto De Ioris
committed
added preliminary version of python console
1 parent 2f4dfd4 commit c85375c

10 files changed

Lines changed: 1290 additions & 2 deletions

File tree

Lines changed: 162 additions & 0 deletions
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
// Copyright 1998-2016 Epic Games, Inc. All Rights Reserved.
2+
3+
#pragma once
4+
5+
#include "UnrealEd.h"
6+
#include "PythonConsoleModule.h"
7+
#include "SlateBasics.h"
8+
9+
#if UNREAL_ENGINE_PYTHON_ON_MAC
10+
#include <python3.5m/Python.h>
11+
#else
12+
#include <include/Python.h>
13+
#endif
Lines changed: 136 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,136 @@
1+
// Copyright 1998-2016 Epic Games, Inc. All Rights Reserved.
2+
3+
#include "PythonConsolePrivatePCH.h"
4+
#include "PythonConsoleModule.h"
5+
#include "SPythonConsole.h"
6+
#include "SPythonLog.h"
7+
8+
namespace PythonConsoleDefs
9+
{
10+
// How many seconds to animate when console is summoned
11+
static const float IntroAnimationDuration = 0.25f;
12+
}
13+
14+
BEGIN_SLATE_FUNCTION_BUILD_OPTIMIZATION
15+
16+
void SPythonConsole::Construct( const FArguments& InArgs, const EPythonConsoleStyle::Type InStyle, FPythonConsoleModule* PythonConsoleModule, const FPythonConsoleDelegates* PythonConsoleDelegates )
17+
{
18+
CurrentStyle = InStyle;
19+
20+
TSharedPtr<SPythonConsoleInputBox> ConsoleInputBox;
21+
22+
check( PythonConsoleModule != NULL );
23+
ChildSlot
24+
[
25+
SNew( SVerticalBox )
26+
+SVerticalBox::Slot()
27+
.AutoHeight()
28+
[
29+
SNew( SVerticalBox )
30+
.Visibility( this, &SPythonConsole::MakeVisibleIfLogIsShown )
31+
32+
+SVerticalBox::Slot()
33+
.AutoHeight()
34+
.Padding( 10.0f )
35+
[
36+
SNew(SBox)
37+
.HeightOverride( 200.0f )
38+
[
39+
SNew( SBorder )
40+
.BorderImage( FEditorStyle::GetBrush( "ToolPanel.GroupBorder" ) )
41+
.ColorAndOpacity( this, &SPythonConsole::GetAnimatedColorAndOpacity )
42+
.BorderBackgroundColor( this, &SPythonConsole::GetAnimatedSlateColor )
43+
[
44+
SNew( SSpacer )
45+
]
46+
]
47+
]
48+
]
49+
50+
+SVerticalBox::Slot()
51+
.AutoHeight()
52+
.Padding( 10.0f )
53+
[
54+
SNew(SBox)
55+
.HeightOverride( 26.0f )
56+
.HAlign( HAlign_Left )
57+
[
58+
SNew( SBorder )
59+
.Padding( FMargin(2) )
60+
.BorderImage( FEditorStyle::GetBrush( "PythonConsole.Background" ) )
61+
.ColorAndOpacity( this, &SPythonConsole::GetAnimatedColorAndOpacity )
62+
.BorderBackgroundColor( this, &SPythonConsole::GetAnimatedSlateColor )
63+
[
64+
SNew(SHorizontalBox)
65+
+ SHorizontalBox::Slot()
66+
.AutoWidth()
67+
.Padding(3.0f)
68+
.VAlign(VAlign_Center)
69+
[
70+
SNew(STextBlock)
71+
.Text(NSLOCTEXT("Console", "ConsoleLabel", "Console"))
72+
73+
]
74+
+ SHorizontalBox::Slot()
75+
.Padding(5.0f, 2.0f)
76+
.VAlign(VAlign_Center)
77+
.MaxWidth(400.0f)
78+
[
79+
SAssignNew(ConsoleInputBox, SPythonConsoleInputBox)
80+
.OnConsoleCommandExecuted(PythonConsoleDelegates->OnConsoleCommandExecuted)
81+
]
82+
]
83+
]
84+
]
85+
];
86+
87+
EditableTextBox = ConsoleInputBox->GetEditableTextBox();
88+
89+
// Kick off intro animation
90+
AnimCurveSequence = FCurveSequence();
91+
AnimCurve = AnimCurveSequence.AddCurve( 0.0f, PythonConsoleDefs::IntroAnimationDuration, ECurveEaseFunction::QuadOut );
92+
FlashCurve = AnimCurveSequence.AddCurve( PythonConsoleDefs::IntroAnimationDuration, .15f, ECurveEaseFunction::QuadInOut );
93+
94+
AnimCurveSequence.Play(this->AsShared());
95+
}
96+
END_SLATE_FUNCTION_BUILD_OPTIMIZATION
97+
98+
SPythonConsole::SPythonConsole()
99+
: CurrentStyle( EPythonConsoleStyle::Compact )
100+
{
101+
}
102+
103+
104+
void SPythonConsole::SetFocusToEditableText()
105+
{
106+
FSlateApplication::Get().SetKeyboardFocus( EditableTextBox.ToSharedRef(), EFocusCause::SetDirectly );
107+
}
108+
109+
EVisibility SPythonConsole::MakeVisibleIfLogIsShown() const
110+
{
111+
return CurrentStyle == EPythonConsoleStyle::WithLog ? EVisibility::Visible : EVisibility::Collapsed;
112+
}
113+
114+
115+
FLinearColor SPythonConsole::GetAnimatedColorAndOpacity() const
116+
{
117+
return FLinearColor( 1.0f, 1.0f, 1.0f, AnimCurve.GetLerp() );
118+
}
119+
120+
121+
FSlateColor SPythonConsole::GetAnimatedSlateColor() const
122+
{
123+
return FSlateColor( GetAnimatedColorAndOpacity() );
124+
}
125+
126+
FSlateColor SPythonConsole::GetFlashColor() const
127+
{
128+
float FlashAlpha = 1.0f - FlashCurve.GetLerp();
129+
130+
if (FlashAlpha == 1.0f)
131+
{
132+
FlashAlpha = 0.0f;
133+
}
134+
135+
return FLinearColor(1,1,1,FlashAlpha);
136+
}
Lines changed: 53 additions & 0 deletions

0 commit comments

Comments
 (0)