Skip to content

Commit e6ab059

Browse files
committed
bug fix when renaming layer with actors inside.
1 parent ce87bd3 commit e6ab059

File tree

1 file changed

+57
-47
lines changed

1 file changed

+57
-47
lines changed
Lines changed: 57 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
/*******************************************************************************
22
* Copyright 2014 Rafael Garcia Moreno.
3-
*
3+
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
66
* You may obtain a copy of the License at
7-
*
7+
*
88
* http://www.apache.org/licenses/LICENSE-2.0
9-
*
9+
*
1010
* Unless required by applicable law or agreed to in writing, software
1111
* distributed under the License is distributed on an "AS IS" BASIS,
1212
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -25,54 +25,64 @@
2525
import com.bladecoder.engineeditor.ui.panels.InputPanelFactory;
2626

2727
public class EditLayerDialog extends EditModelDialog<Scene, SceneLayer> {
28-
29-
private InputPanel name;
30-
private InputPanel visible;
31-
private InputPanel dynamic;
32-
private InputPanel parallax;
33-
34-
public EditLayerDialog(Skin skin, Scene parent, SceneLayer e) {
35-
super(skin);
36-
37-
name = InputPanelFactory.createInputPanel(skin, "Layer Name", "The name of the layer", true);
38-
visible = InputPanelFactory.createInputPanel(skin, "Visible", "Layer Visibility", Param.Type.BOOLEAN, true, "true");
39-
dynamic = InputPanelFactory.createInputPanel(skin, "Dynamic", "True for actor reordering based in y position", Param.Type.BOOLEAN, true,"false");
40-
parallax = InputPanelFactory.createInputPanel(skin, "Parallax Factor", "The multiplier factor for parallax effect", Param.Type.FLOAT, true,"1.0");
4128

42-
setInfo("Scenes can have a list of layers. Actors are added to a specific layer to control the draw order");
29+
private InputPanel name;
30+
private InputPanel visible;
31+
private InputPanel dynamic;
32+
private InputPanel parallax;
4333

44-
init(parent, e, new InputPanel[] { name, visible, dynamic, parallax });
45-
}
46-
47-
@Override
48-
protected void inputsToModel(boolean create) {
49-
50-
if(create) {
51-
e = new SceneLayer();
52-
}
53-
54-
// TODO if the name is changed. Change all actor layer name.
55-
e.setName(name.getText());
56-
e.setVisible(Boolean.parseBoolean(visible.getText()));
57-
e.setDynamic(Boolean.parseBoolean(dynamic.getText()));
58-
e.setParallaxMultiplier(Float.parseFloat(parallax.getText()));
59-
60-
if(create) {
61-
parent.getLayers().add(e);
62-
}
34+
public EditLayerDialog(Skin skin, Scene parent, SceneLayer e) {
35+
super(skin);
6336

64-
// TODO UNDO OP
37+
name = InputPanelFactory.createInputPanel(skin, "Layer Name", "The name of the layer", true);
38+
visible = InputPanelFactory.createInputPanel(skin, "Visible", "Layer Visibility", Param.Type.BOOLEAN, true, "true");
39+
dynamic = InputPanelFactory.createInputPanel(skin, "Dynamic", "True for actor reordering based in y position", Param.Type.BOOLEAN, true, "false");
40+
parallax = InputPanelFactory.createInputPanel(skin, "Parallax Factor", "The multiplier factor for parallax effect", Param.Type.FLOAT, true, "1.0");
41+
42+
setInfo("Scenes can have a list of layers. Actors are added to a specific layer to control the draw order");
43+
44+
init(parent, e, new InputPanel[]{name, visible, dynamic, parallax});
45+
}
46+
47+
@Override
48+
protected void inputsToModel(boolean create) {
49+
50+
if (create) {
51+
e = new SceneLayer();
52+
}
53+
54+
// if the name is changed. Change all actor layer name.
55+
if (!create && !e.getName().equals(name.getText())) {
56+
for (SceneLayer l : parent.getLayers()) {
57+
for (int i = 0; i < l.getActors().size(); i++) {
58+
if (l.getActors().get(i).getLayer().equals(e.getName())) {
59+
l.getActors().get(i).setLayer(name.getText());
60+
}
61+
}
62+
}
63+
}
64+
65+
e.setName(name.getText());
66+
e.setVisible(Boolean.parseBoolean(visible.getText()));
67+
e.setDynamic(Boolean.parseBoolean(dynamic.getText()));
68+
e.setParallaxMultiplier(Float.parseFloat(parallax.getText()));
69+
70+
if (create) {
71+
parent.getLayers().add(e);
72+
}
73+
74+
// TODO UNDO OP
6575
// UndoOp undoOp = new UndoAddElement(doc, e);
6676
// Ctx.project.getUndoStack().add(undoOp);
67-
68-
Ctx.project.setModified();
69-
}
7077

71-
@Override
72-
protected void modelToInputs() {
73-
name.setText(e.getName());
74-
visible.setText(Boolean.toString(e.isVisible()));
75-
dynamic.setText(Boolean.toString(e.isDynamic()));
76-
parallax.setText(Float.toString(e.getParallaxMultiplier()));
77-
}
78+
Ctx.project.setModified();
79+
}
80+
81+
@Override
82+
protected void modelToInputs() {
83+
name.setText(e.getName());
84+
visible.setText(Boolean.toString(e.isVisible()));
85+
dynamic.setText(Boolean.toString(e.isDynamic()));
86+
parallax.setText(Float.toString(e.getParallaxMultiplier()));
87+
}
7888
}

0 commit comments

Comments
 (0)