Skip to content

Commit

Permalink
[Flame] Save panel (libgdx#7040)
Browse files Browse the repository at this point in the history
* Save panel on Flame

* Update CHANGES
  • Loading branch information
Dgzt authored Jan 17, 2023
1 parent aca13b2 commit 9fb9353
Show file tree
Hide file tree
Showing 4 changed files with 96 additions and 4 deletions.
1 change: 1 addition & 0 deletions CHANGES
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
- LWJGL3 Fix: Stereo audio can now be played on mono output devices. This may also improve downmixing to stereo and upmixing to surround.
- API Addition: Added CheckBox#getImageDrawable.
- FIX: HexagonalTiledMapRenderer now displays maps with the correct stagger index.
- TOOLS Features: Save mode can be changed in Flame particle 3D editor.

[1.11.0]
- [BREAKING CHANGE] iOS: Increased min supported iOS version to 9.0. Update your Info.plist file if necessary.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@
import com.badlogic.gdx.scenes.scene2d.ui.TextButton;
import com.badlogic.gdx.scenes.scene2d.utils.ClickListener;
import com.badlogic.gdx.utils.Array;
import com.badlogic.gdx.utils.JsonWriter;
import com.badlogic.gdx.utils.StreamUtils;
import com.badlogic.gdx.utils.StringBuilder;

Expand Down Expand Up @@ -199,6 +200,8 @@ private ControllerType (String desc, InfluencerWrapper[] wrappers) {
AssetManager assetManager;
JComboBox influencerBox;
TextureAtlas textureAtlas;
JsonWriter.OutputType jsonOutputType = JsonWriter.OutputType.minimal;
boolean jsonPrettyPrint = false;

private ParticleEffect effect;
/** READ only */
Expand Down Expand Up @@ -265,6 +268,7 @@ public void run () {
addRow(editorPropertiesPanel, new TextureLoaderPanel(FlameMain.this, "Texture", ""));
addRow(editorPropertiesPanel, new BillboardBatchPanel(FlameMain.this, renderer.billboardBatch), 1, 1);
addRow(editorPropertiesPanel, new PointSpriteBatchPanel(FlameMain.this, renderer.pointSpriteBatch), 1, 1);
addRow(editorPropertiesPanel, new SavePanel(FlameMain.this, "Save", ""));
editorPropertiesPanel.repaint();

// Controller props
Expand Down Expand Up @@ -948,8 +952,8 @@ public void saveEffect (File file) {
Writer fileWriter = null;
try {
ParticleEffectLoader loader = (ParticleEffectLoader)assetManager.getLoader(ParticleEffect.class);
loader.save(effect,
new ParticleEffectSaveParameter(new FileHandle(file.getAbsolutePath()), assetManager, particleSystem.getBatches()));
loader.save(effect, new ParticleEffectSaveParameter(new FileHandle(file.getAbsolutePath()), assetManager,
particleSystem.getBatches(), jsonOutputType, jsonPrettyPrint));
} catch (Exception ex) {
System.out.println("Error saving effect: " + file.getAbsolutePath());
ex.printStackTrace();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
/*******************************************************************************
* Copyright 2011 See AUTHORS file.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
******************************************************************************/

package com.badlogic.gdx.tools.flame;

import com.badlogic.gdx.utils.JsonWriter;

import java.awt.GridBagConstraints;
import java.awt.Insets;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.DefaultComboBoxModel;
import javax.swing.JCheckBox;
import javax.swing.JComboBox;
import javax.swing.JLabel;

public class SavePanel extends EditorPanel<Void> {

JComboBox<JsonWriter.OutputType> jsonMode;
JCheckBox prettyPrintBox;

public SavePanel (FlameMain particleEditor3D, String name, String description) {
super(particleEditor3D, name, description);
setValue(null);
}

@Override
protected void initializeComponents () {
super.initializeComponents();

jsonMode = new JComboBox<JsonWriter.OutputType>(new DefaultComboBoxModel(JsonWriter.OutputType.values()));
jsonMode.setSelectedItem(SavePanel.this.editor.jsonOutputType);

contentPanel.add(new JLabel("Json output mode:"), new GridBagConstraints(0, 1, 1, 1, 0, 0, GridBagConstraints.EAST,
GridBagConstraints.NONE, new Insets(6, 0, 0, 0), 0, 0));
contentPanel.add(jsonMode, new GridBagConstraints(1, 1, 1, 1, 0, 0, GridBagConstraints.WEST, GridBagConstraints.NONE,
new Insets(6, 6, 0, 0), 0, 0));

contentPanel.add(new JLabel("Pretty print:"), new GridBagConstraints(0, 2, 1, 1, 0, 0, GridBagConstraints.EAST,
GridBagConstraints.NONE, new Insets(6, 0, 0, 0), 0, 0));
prettyPrintBox = new JCheckBox();
prettyPrintBox.setSelected(SavePanel.this.editor.jsonPrettyPrint);
contentPanel.add(prettyPrintBox, new GridBagConstraints(1, 2, 1, 1, 1, 0, GridBagConstraints.WEST, GridBagConstraints.NONE,
new Insets(6, 6, 0, 0), 0, 0));

jsonMode.addActionListener(new ActionListener() {
public void actionPerformed (ActionEvent event) {
SavePanel.this.editor.jsonOutputType = (JsonWriter.OutputType)jsonMode.getSelectedItem();
}
});

prettyPrintBox.addActionListener(new ActionListener() {
public void actionPerformed (ActionEvent event) {
SavePanel.this.editor.jsonPrettyPrint = prettyPrintBox.isSelected();
}
});
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import com.badlogic.gdx.graphics.g3d.particles.batches.ParticleBatch;
import com.badlogic.gdx.utils.Array;
import com.badlogic.gdx.utils.Json;
import com.badlogic.gdx.utils.JsonWriter;
import com.badlogic.gdx.utils.ObjectMap;
import com.badlogic.gdx.utils.reflect.ClassReflection;

Expand Down Expand Up @@ -104,8 +105,13 @@ public void save (ParticleEffect effect, ParticleEffectSaveParameter parameter)
}

// save
Json json = new Json();
json.toJson(data, parameter.file);
Json json = new Json(parameter.jsonOutputType);
if (parameter.prettyPrint) {
String prettyJson = json.prettyPrint(data);
parameter.file.writeString(prettyJson, false);
} else {
json.toJson(data, parameter.file);
}
}

@Override
Expand Down Expand Up @@ -157,11 +163,20 @@ public static class ParticleEffectSaveParameter extends AssetLoaderParameters<Pa
/** Required parameters */
FileHandle file;
AssetManager manager;
JsonWriter.OutputType jsonOutputType;
boolean prettyPrint;

public ParticleEffectSaveParameter (FileHandle file, AssetManager manager, Array<ParticleBatch<?>> batches) {
this(file, manager, batches, JsonWriter.OutputType.minimal, false);
}

public ParticleEffectSaveParameter (FileHandle file, AssetManager manager, Array<ParticleBatch<?>> batches,
JsonWriter.OutputType jsonOutputType, boolean prettyPrint) {
this.batches = batches;
this.file = file;
this.manager = manager;
this.jsonOutputType = jsonOutputType;
this.prettyPrint = prettyPrint;
}
}

Expand Down

0 comments on commit 9fb9353

Please sign in to comment.