Skip to content

Commit c705f89

Browse files
Feature/external layout options (#3178)
Improve scene selection and help text for an external layout
1 parent 3b73b5e commit c705f89

File tree

10 files changed

+228
-145
lines changed

10 files changed

+228
-145
lines changed

Core/GDCore/Project/ExternalEvents.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
#if defined(GD_IDE_ONLY)
21
#include "GDCore/Project/ExternalEvents.h"
2+
33
#include "ExternalEvents.h"
44
#include "GDCore/Events/Event.h"
55
#include "GDCore/Events/Serialization.h"
@@ -48,4 +48,3 @@ void ExternalEvents::UnserializeFrom(gd::Project& project,
4848
}
4949

5050
} // namespace gd
51-
#endif

Core/GDCore/Project/ExternalEvents.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,12 @@
33
* Copyright 2008-2016 Florian Rival ([email protected]). All rights
44
* reserved. This project is released under the MIT License.
55
*/
6-
#if defined(GD_IDE_ONLY)
76
#ifndef GDCORE_EXTERNALEVENTS_H
87
#define GDCORE_EXTERNALEVENTS_H
98
#include <ctime>
109
#include <memory>
1110
#include <vector>
11+
1212
#include "GDCore/Events/EventsList.h"
1313
#include "GDCore/String.h"
1414
namespace gd {
@@ -135,4 +135,3 @@ struct ExternalEventsHasName
135135
} // namespace gd
136136

137137
#endif // GDCORE_EXTERNALEVENTS_H
138-
#endif

Core/GDCore/Project/ExternalLayout.cpp

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
*/
66

77
#include "GDCore/Project/ExternalLayout.h"
8+
89
#include "GDCore/IDE/Dialogs/LayoutEditorCanvas/EditorSettings.h"
910
#include "GDCore/Project/InitialInstancesContainer.h"
1011
#include "GDCore/Serialization/SerializerElement.h"
@@ -15,19 +16,15 @@ namespace gd {
1516
void ExternalLayout::UnserializeFrom(const SerializerElement& element) {
1617
name = element.GetStringAttribute("name", "", "Name");
1718
instances.UnserializeFrom(element.GetChild("instances", 0, "Instances"));
18-
#if defined(GD_IDE_ONLY)
1919
editorSettings.UnserializeFrom(element.GetChild("editionSettings"));
20-
#endif
2120
associatedLayout = element.GetStringAttribute("associatedLayout");
2221
}
2322

24-
#if defined(GD_IDE_ONLY)
2523
void ExternalLayout::SerializeTo(SerializerElement& element) const {
2624
element.SetAttribute("name", name);
2725
instances.SerializeTo(element.AddChild("instances"));
2826
editorSettings.SerializeTo(element.AddChild("editionSettings"));
2927
element.SetAttribute("associatedLayout", associatedLayout);
3028
}
31-
#endif
3229

3330
} // namespace gd

Core/GDCore/Project/ExternalLayout.h

Lines changed: 5 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,13 @@
77
#ifndef GDCORE_EXTERNALLAYOUT_H
88
#define GDCORE_EXTERNALLAYOUT_H
99
#include <memory>
10+
1011
#include "GDCore/Project/InitialInstancesContainer.h"
1112
#include "GDCore/String.h"
1213
namespace gd {
1314
class SerializerElement;
1415
}
15-
#if defined(GD_IDE_ONLY)
1616
#include "GDCore/IDE/Dialogs/LayoutEditorCanvas/EditorSettings.h"
17-
#endif
1817

1918
namespace gd {
2019

@@ -54,7 +53,6 @@ class GD_CORE_API ExternalLayout {
5453
*/
5554
gd::InitialInstancesContainer& GetInitialInstances() { return instances; }
5655

57-
#if defined(GD_IDE_ONLY)
5856
/**
5957
* \brief Get the user settings for the IDE.
6058
*/
@@ -65,10 +63,7 @@ class GD_CORE_API ExternalLayout {
6563
/**
6664
* \brief Get the user settings for the IDE.
6765
*/
68-
gd::EditorSettings& GetAssociatedEditorSettings() {
69-
return editorSettings;
70-
}
71-
#endif
66+
gd::EditorSettings& GetAssociatedEditorSettings() { return editorSettings; }
7267

7368
/**
7469
* \brief Get the name of the layout last used to edit the external layout.
@@ -80,15 +75,13 @@ class GD_CORE_API ExternalLayout {
8075
*/
8176
void SetAssociatedLayout(const gd::String& name) { associatedLayout = name; }
8277

83-
/** \name Serialization
84-
*/
85-
///@{
86-
#if defined(GD_IDE_ONLY)
78+
/** \name Serialization
79+
*/
80+
///@{
8781
/**
8882
* \brief Serialize external layout.
8983
*/
9084
void SerializeTo(SerializerElement& element) const;
91-
#endif
9285

9386
/**
9487
* \brief Unserialize the external layout.
@@ -99,9 +92,7 @@ class GD_CORE_API ExternalLayout {
9992
private:
10093
gd::String name;
10194
gd::InitialInstancesContainer instances;
102-
#if defined(GD_IDE_ONLY)
10395
gd::EditorSettings editorSettings;
104-
#endif
10596
gd::String associatedLayout;
10697
};
10798

newIDE/app/src/MainFrame/EditorContainers/ExternalEventsEditorContainer.js

Lines changed: 36 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,9 @@ import {
88
type RenderEditorContainerProps,
99
type RenderEditorContainerPropsWithRef,
1010
} from './BaseEditor';
11-
import LayoutChooserDialog from './LayoutChooserDialog';
11+
import ExternalPropertiesDialog, {
12+
type ExternalProperties,
13+
} from './ExternalPropertiesDialog';
1214
import Text from '../../UI/Text';
1315
import { Line } from '../../UI/Grid';
1416

@@ -20,7 +22,7 @@ const styles = {
2022
};
2123

2224
type State = {|
23-
layoutChooserOpen: boolean,
25+
externalPropertiesDialogOpen: boolean,
2426
|};
2527

2628
export class ExternalEventsEditorContainer extends React.Component<
@@ -30,7 +32,7 @@ export class ExternalEventsEditorContainer extends React.Component<
3032
editor: ?EventsSheet;
3133

3234
state = {
33-
layoutChooserOpen: false,
35+
externalPropertiesDialogOpen: false,
3436
};
3537

3638
shouldComponentUpdate(nextProps: RenderEditorContainerProps) {
@@ -65,32 +67,43 @@ export class ExternalEventsEditorContainer extends React.Component<
6567
const { project } = this.props;
6668
if (!project) return null;
6769

70+
const layoutName = this.getAssociatedLayoutName();
71+
if (!layoutName) return null;
72+
73+
return project.getLayout(layoutName);
74+
}
75+
76+
getAssociatedLayoutName(): ?string {
77+
const { project } = this.props;
78+
if (!project) return null;
79+
6880
const externalEvents = this.getExternalEvents();
6981
if (!externalEvents) return null;
7082

7183
const layoutName = externalEvents.getAssociatedLayout();
7284
if (!project.hasLayoutNamed(layoutName)) {
7385
return null;
7486
}
75-
return project.getLayout(layoutName);
87+
88+
return layoutName;
7689
}
7790

78-
setAssociatedLayout = (layoutName: string) => {
91+
saveExternalProperties = (externalProps: ExternalProperties) => {
7992
const externalEvents = this.getExternalEvents();
8093
if (!externalEvents) return;
8194

82-
externalEvents.setAssociatedLayout(layoutName);
95+
externalEvents.setAssociatedLayout(externalProps.layoutName);
8396
this.setState(
8497
{
85-
layoutChooserOpen: false,
98+
externalPropertiesDialogOpen: false,
8699
},
87100
() => this.updateToolbar()
88101
);
89102
};
90103

91-
openLayoutChooser = () => {
104+
openExternalPropertiesDialog = () => {
92105
this.setState({
93-
layoutChooserOpen: true,
106+
externalPropertiesDialogOpen: true,
94107
});
95108
};
96109

@@ -124,7 +137,7 @@ export class ExternalEventsEditorContainer extends React.Component<
124137
globalObjectsContainer={project}
125138
objectsContainer={layout}
126139
events={externalEvents.getEvents()}
127-
onOpenSettings={this.openLayoutChooser}
140+
onOpenSettings={this.openExternalPropertiesDialog}
128141
onOpenExternalEvents={this.props.onOpenExternalEvents}
129142
/>
130143
)}
@@ -140,18 +153,24 @@ export class ExternalEventsEditorContainer extends React.Component<
140153
<RaisedButton
141154
label={<Trans>Choose the scene</Trans>}
142155
primary
143-
onClick={this.openLayoutChooser}
156+
onClick={this.openExternalPropertiesDialog}
144157
/>
145158
</Line>
146159
</PlaceholderMessage>
147160
)}
148-
<LayoutChooserDialog
149-
title={<Trans>Choose the associated scene</Trans>}
150-
helpText="You still need to add a Link event in the scene to import the external events"
151-
open={this.state.layoutChooserOpen}
161+
<ExternalPropertiesDialog
162+
title={<Trans>Configure the external events</Trans>}
163+
helpTexts={[
164+
<Trans>
165+
In order to use these external events, you still need to add a
166+
"Link" event in the events sheet of the corresponding scene
167+
</Trans>,
168+
]}
169+
open={this.state.externalPropertiesDialogOpen}
152170
project={project}
153-
onChoose={this.setAssociatedLayout}
154-
onClose={() => this.setState({ layoutChooserOpen: false })}
171+
onChoose={this.saveExternalProperties}
172+
layoutName={this.getAssociatedLayoutName()}
173+
onClose={() => this.setState({ externalPropertiesDialogOpen: false })}
155174
/>
156175
</div>
157176
);

newIDE/app/src/MainFrame/EditorContainers/ExternalLayoutEditorContainer.js

Lines changed: 42 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,9 @@ import {
1313
type RenderEditorContainerProps,
1414
type RenderEditorContainerPropsWithRef,
1515
} from './BaseEditor';
16-
import LayoutChooserDialog from './LayoutChooserDialog';
16+
import ExternalPropertiesDialog, {
17+
type ExternalProperties,
18+
} from './ExternalPropertiesDialog';
1719
import { Line } from '../../UI/Grid';
1820
import Text from '../../UI/Text';
1921
import { prepareInstancesEditorSettings } from '../../InstancesEditor/InstancesEditorSettings';
@@ -26,7 +28,7 @@ const styles = {
2628
};
2729

2830
type State = {|
29-
layoutChooserOpen: boolean,
31+
externalPropertiesDialogOpen: boolean,
3032
|};
3133

3234
export class ExternalLayoutEditorContainer extends React.Component<
@@ -35,7 +37,7 @@ export class ExternalLayoutEditorContainer extends React.Component<
3537
> {
3638
editor: ?SceneEditor;
3739
state = {
38-
layoutChooserOpen: false,
40+
externalPropertiesDialogOpen: false,
3941
};
4042

4143
getProject(): ?gdProject {
@@ -98,32 +100,43 @@ export class ExternalLayoutEditorContainer extends React.Component<
98100
const { project } = this.props;
99101
if (!project) return null;
100102

103+
const layoutName = this.getAssociatedLayoutName();
104+
if (!layoutName) return;
105+
106+
return project.getLayout(layoutName);
107+
}
108+
109+
getAssociatedLayoutName(): ?string {
110+
const { project } = this.props;
111+
if (!project) return null;
112+
101113
const externalLayout = this.getExternalLayout();
102114
if (!externalLayout) return null;
103115

104116
const layoutName = externalLayout.getAssociatedLayout();
105117
if (!project.hasLayoutNamed(layoutName)) {
106118
return null;
107119
}
108-
return project.getLayout(layoutName);
120+
121+
return layoutName;
109122
}
110123

111-
setAssociatedLayout = (layoutName: string) => {
124+
saveExternalProperties = (externalProps: ExternalProperties) => {
112125
const externalLayout = this.getExternalLayout();
113126
if (!externalLayout) return;
114127

115-
externalLayout.setAssociatedLayout(layoutName);
128+
externalLayout.setAssociatedLayout(externalProps.layoutName);
116129
this.setState(
117130
{
118-
layoutChooserOpen: false,
131+
externalPropertiesDialogOpen: false,
119132
},
120133
() => this.updateToolbar()
121134
);
122135
};
123136

124-
openLayoutChooser = () => {
137+
openExternalPropertiesDialog = () => {
125138
this.setState({
126-
layoutChooserOpen: true,
139+
externalPropertiesDialogOpen: true,
127140
});
128141
};
129142

@@ -170,7 +183,7 @@ export class ExternalLayoutEditorContainer extends React.Component<
170183
)
171184
)
172185
}
173-
onOpenMoreSettings={this.openLayoutChooser}
186+
onOpenMoreSettings={this.openExternalPropertiesDialog}
174187
isActive={isActive}
175188
/>
176189
)}
@@ -186,17 +199,30 @@ export class ExternalLayoutEditorContainer extends React.Component<
186199
<RaisedButton
187200
label={<Trans>Choose the scene</Trans>}
188201
primary
189-
onClick={this.openLayoutChooser}
202+
onClick={this.openExternalPropertiesDialog}
190203
/>
191204
</Line>
192205
</PlaceholderMessage>
193206
)}
194-
<LayoutChooserDialog
195-
title={<Trans>Choose the associated scene</Trans>}
196-
open={this.state.layoutChooserOpen}
207+
<ExternalPropertiesDialog
208+
title={<Trans>Configure the external layout</Trans>}
209+
helpTexts={[
210+
<Trans>
211+
In order to see your objects in the scene, you need to add an
212+
action "Create objects from external layout" in your events sheet.
213+
</Trans>,
214+
<Trans>
215+
You can also launch a preview from this external layout, but
216+
remember that it will still create objects from the scene, as well
217+
as trigger its events. Make sure to disable any action loading the
218+
external layout before doing so to avoid having duplicate objects!
219+
</Trans>,
220+
]}
221+
open={this.state.externalPropertiesDialogOpen}
197222
project={project}
198-
onChoose={this.setAssociatedLayout}
199-
onClose={() => this.setState({ layoutChooserOpen: false })}
223+
layoutName={this.getAssociatedLayoutName()}
224+
onChoose={this.saveExternalProperties}
225+
onClose={() => this.setState({ externalPropertiesDialogOpen: false })}
200226
/>
201227
</div>
202228
);

0 commit comments

Comments
 (0)