- Open Settings API for plugins
- Skin Composer settings
This commit is contained in:
Binary file not shown.
@@ -140,4 +140,6 @@ public class MsgAPI {
|
||||
public static final String DELETE_ITEMS_COMMAND_DONE = DELETE_ITEMS_COMMAND_CLASS_NAME + "DONE";
|
||||
|
||||
public static final String SHOW_NOTIFICATION = GLOBAL_PREFIX + ".SHOW_NOTIFICATION";
|
||||
|
||||
public static final String ADD_PLUGIN_SETTINGS = GLOBAL_PREFIX + ".ADD_PLUGIN_SETTINGS";
|
||||
}
|
||||
|
||||
+36
@@ -0,0 +1,36 @@
|
||||
package games.rednblack.h2d.common.view;
|
||||
|
||||
import com.kotcrab.vis.ui.widget.VisTable;
|
||||
import com.puremvc.patterns.facade.Facade;
|
||||
|
||||
public abstract class SettingsNodeValue<T> {
|
||||
private final VisTable contentTable = new VisTable();
|
||||
private T settings;
|
||||
private final String name;
|
||||
protected Facade facade;
|
||||
|
||||
public SettingsNodeValue(String name, Facade facade) {
|
||||
this.name = name;
|
||||
contentTable.top().left();
|
||||
this.facade = facade;
|
||||
}
|
||||
|
||||
public abstract void translateSettingsToView();
|
||||
public abstract void translateViewToSettings();
|
||||
public abstract boolean validateSettings();
|
||||
|
||||
public VisTable getContentTable() {
|
||||
return contentTable;
|
||||
}
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public void setSettings(T settings) {
|
||||
this.settings = settings;
|
||||
}
|
||||
|
||||
public T getSettings() {
|
||||
return settings;
|
||||
}
|
||||
}
|
||||
+5
@@ -45,6 +45,11 @@ public class SkinComposerMediator extends SimpleMediator<DownloadingDialog> {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!plugin.getSettingsVO().alwaysCheckUpdates) {
|
||||
runJar(jarPath);
|
||||
return;
|
||||
}
|
||||
|
||||
ExecutorService executor = Executors.newSingleThreadExecutor();
|
||||
executor.execute(() -> {
|
||||
|
||||
|
||||
+11
@@ -1,5 +1,6 @@
|
||||
package games.rednblack.editor.plugin.skincomposer;
|
||||
|
||||
import games.rednblack.h2d.common.MsgAPI;
|
||||
import games.rednblack.h2d.common.plugins.H2DPluginAdapter;
|
||||
import net.mountainblade.modular.annotations.Implementation;
|
||||
|
||||
@@ -12,6 +13,7 @@ public class SkinComposerPlugin extends H2DPluginAdapter {
|
||||
public static final String DOWNLOAD_JAR = CLASS_NAME + ".DOWNLOAD_JAR";
|
||||
|
||||
private final SkinComposerMediator skinComposerMediator;
|
||||
private final SkinComposerVO settingsVO = new SkinComposerVO();
|
||||
|
||||
public SkinComposerPlugin() {
|
||||
super(CLASS_NAME);
|
||||
@@ -22,5 +24,14 @@ public class SkinComposerPlugin extends H2DPluginAdapter {
|
||||
public void initPlugin() {
|
||||
facade.registerMediator(skinComposerMediator);
|
||||
pluginAPI.addMenuItem(WINDOWS_MENU, "Skin Composer", PANEL_OPEN);
|
||||
SkinComposerSettings settings = new SkinComposerSettings(facade, this);
|
||||
|
||||
settingsVO.fromStorage(getStorage());
|
||||
settings.setSettings(settingsVO);
|
||||
facade.sendNotification(MsgAPI.ADD_PLUGIN_SETTINGS, settings);
|
||||
}
|
||||
|
||||
public SkinComposerVO getSettingsVO() {
|
||||
return settingsVO;
|
||||
}
|
||||
}
|
||||
|
||||
+41
@@ -0,0 +1,41 @@
|
||||
package games.rednblack.editor.plugin.skincomposer;
|
||||
|
||||
import com.badlogic.gdx.utils.Json;
|
||||
import com.kotcrab.vis.ui.widget.VisCheckBox;
|
||||
import com.puremvc.patterns.facade.Facade;
|
||||
import games.rednblack.h2d.common.MsgAPI;
|
||||
import games.rednblack.h2d.common.plugins.H2DPluginAdapter;
|
||||
import games.rednblack.h2d.common.view.SettingsNodeValue;
|
||||
|
||||
public class SkinComposerSettings extends SettingsNodeValue<SkinComposerVO> {
|
||||
|
||||
private final VisCheckBox alwaysCheckUpdates;
|
||||
private H2DPluginAdapter plugin;
|
||||
private Json json = new Json();
|
||||
|
||||
public SkinComposerSettings(Facade facade, H2DPluginAdapter plugin) {
|
||||
super("Skin Composer", facade);
|
||||
|
||||
this.plugin = plugin;
|
||||
|
||||
alwaysCheckUpdates = new VisCheckBox("Always check for updates");
|
||||
getContentTable().add(alwaysCheckUpdates).left().row();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void translateSettingsToView() {
|
||||
alwaysCheckUpdates.setChecked(getSettings().alwaysCheckUpdates);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void translateViewToSettings() {
|
||||
getSettings().alwaysCheckUpdates = alwaysCheckUpdates.isChecked();
|
||||
getSettings().toStorage(plugin.getStorage());
|
||||
facade.sendNotification(MsgAPI.SAVE_EDITOR_CONFIG);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean validateSettings() {
|
||||
return getSettings().alwaysCheckUpdates != alwaysCheckUpdates.isChecked();
|
||||
}
|
||||
}
|
||||
+15
@@ -0,0 +1,15 @@
|
||||
package games.rednblack.editor.plugin.skincomposer;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
public class SkinComposerVO {
|
||||
public boolean alwaysCheckUpdates = true;
|
||||
|
||||
public void fromStorage(Map<String, Object> settings) {
|
||||
alwaysCheckUpdates = (boolean) settings.getOrDefault("alwaysCheckUpdates", true);
|
||||
}
|
||||
|
||||
public void toStorage(Map<String, Object> settings) {
|
||||
settings.put("alwaysCheckUpdates", alwaysCheckUpdates);
|
||||
}
|
||||
}
|
||||
@@ -45,9 +45,13 @@ public class StandardWidgetsFactory {
|
||||
}
|
||||
|
||||
public static VisLabel createLabel(String text, int alignment) {
|
||||
return createLabel(text, "small", alignment);
|
||||
}
|
||||
|
||||
public static VisLabel createLabel(String text, String style, int alignment) {
|
||||
Skin skin = VisUI.getSkin();
|
||||
VisLabel visLabel = new VisLabel(text, alignment);
|
||||
visLabel.setStyle(skin.get("small", Label.LabelStyle.class));
|
||||
visLabel.setStyle(skin.get(style, Label.LabelStyle.class));
|
||||
return visLabel;
|
||||
}
|
||||
|
||||
|
||||
@@ -11,6 +11,7 @@ import com.puremvc.patterns.facade.Facade;
|
||||
import games.rednblack.editor.HyperLap2DFacade;
|
||||
import games.rednblack.editor.utils.StandardWidgetsFactory;
|
||||
import games.rednblack.h2d.common.H2DDialog;
|
||||
import games.rednblack.h2d.common.view.SettingsNodeValue;
|
||||
|
||||
public class SettingsDialog extends H2DDialog {
|
||||
|
||||
@@ -41,7 +42,7 @@ public class SettingsDialog extends H2DDialog {
|
||||
public void changed(ChangeEvent event, Actor actor) {
|
||||
containerTable.clear();
|
||||
settingsTree.getSelectedValue().translateSettingsToView();
|
||||
containerTable.add(settingsTree.getSelectedValue().contentTable).expand().fill().pad(5);
|
||||
containerTable.add(settingsTree.getSelectedValue().getContentTable()).expand().fill().pad(5);
|
||||
}
|
||||
});
|
||||
|
||||
@@ -84,6 +85,13 @@ public class SettingsDialog extends H2DDialog {
|
||||
if (node.getValue().validateSettings()) {
|
||||
node.getValue().translateViewToSettings();
|
||||
}
|
||||
if (node.getChildren().size > 0) {
|
||||
for (SettingsNode child : node.getChildren()) {
|
||||
if (child.getValue().validateSettings()) {
|
||||
child.getValue().translateViewToSettings();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -110,8 +118,8 @@ public class SettingsDialog extends H2DDialog {
|
||||
return 500;
|
||||
}
|
||||
|
||||
public void addSettingsNode(SettingsNodeValue<?> nodeValue) {
|
||||
SettingsNode node = new SettingsNode(nodeValue.name);
|
||||
public SettingsNode addSettingsNode(SettingsNodeValue<?> nodeValue) {
|
||||
SettingsNode node = new SettingsNode(nodeValue.getName());
|
||||
int existingIndex = settingsTree.getNodes().indexOf(node, false);
|
||||
if (existingIndex == -1) {
|
||||
node.setValue(nodeValue);
|
||||
@@ -119,6 +127,19 @@ public class SettingsDialog extends H2DDialog {
|
||||
} else {
|
||||
settingsTree.getNodes().get(existingIndex).setValue(nodeValue);
|
||||
}
|
||||
return node;
|
||||
}
|
||||
|
||||
public SettingsNode addChildSettingsNode(SettingsNode parent, SettingsNodeValue<?> nodeValue) {
|
||||
SettingsNode node = new SettingsNode(nodeValue.getName());
|
||||
int existingIndex = parent.getChildren().indexOf(node, false);
|
||||
if (existingIndex == -1) {
|
||||
node.setValue(nodeValue);
|
||||
parent.add(node);
|
||||
} else {
|
||||
parent.getChildren().get(existingIndex).setValue(nodeValue);
|
||||
}
|
||||
return node;
|
||||
}
|
||||
|
||||
public static class SettingsNode extends Tree.Node<SettingsNode, SettingsNodeValue<?>, VisLabel> {
|
||||
@@ -136,33 +157,4 @@ public class SettingsDialog extends H2DDialog {
|
||||
return name.equals(((SettingsNode) o).name);
|
||||
}
|
||||
}
|
||||
|
||||
public abstract static class SettingsNodeValue<T> {
|
||||
private final VisTable contentTable = new VisTable();
|
||||
private T settings;
|
||||
private final String name;
|
||||
protected Facade facade;
|
||||
|
||||
public SettingsNodeValue(String name) {
|
||||
this.name = name;
|
||||
contentTable.top().left();
|
||||
facade = HyperLap2DFacade.getInstance();
|
||||
}
|
||||
|
||||
public abstract void translateSettingsToView();
|
||||
public abstract void translateViewToSettings();
|
||||
public abstract boolean validateSettings();
|
||||
|
||||
protected VisTable getContentTable() {
|
||||
return contentTable;
|
||||
}
|
||||
|
||||
public void setSettings(T settings) {
|
||||
this.settings = settings;
|
||||
}
|
||||
|
||||
public T getSettings() {
|
||||
return settings;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,13 +8,18 @@ import games.rednblack.editor.view.menu.FileMenu;
|
||||
import games.rednblack.editor.view.stage.Sandbox;
|
||||
import games.rednblack.editor.view.stage.UIStage;
|
||||
import games.rednblack.editor.view.ui.settings.GeneralSettings;
|
||||
import games.rednblack.editor.view.ui.settings.PluginsSettings;
|
||||
import games.rednblack.editor.view.ui.settings.SandboxSettings;
|
||||
import games.rednblack.h2d.common.MsgAPI;
|
||||
import games.rednblack.h2d.common.view.SettingsNodeValue;
|
||||
|
||||
public class SettingsDialogMediator extends SimpleMediator<SettingsDialog> {
|
||||
|
||||
private static final String TAG = SettingsDialogMediator.class.getCanonicalName();
|
||||
private static final String NAME = TAG;
|
||||
|
||||
private SettingsDialog.SettingsNode pluginsSettingsNode;
|
||||
|
||||
public SettingsDialogMediator() {
|
||||
super(NAME, new SettingsDialog());
|
||||
}
|
||||
@@ -23,7 +28,8 @@ public class SettingsDialogMediator extends SimpleMediator<SettingsDialog> {
|
||||
public String[] listNotificationInterests() {
|
||||
return new String[]{
|
||||
FileMenu.SETTINGS,
|
||||
SettingsDialog.ADD_SETTINGS
|
||||
SettingsDialog.ADD_SETTINGS,
|
||||
MsgAPI.ADD_PLUGIN_SETTINGS
|
||||
};
|
||||
}
|
||||
|
||||
@@ -41,6 +47,11 @@ public class SettingsDialogMediator extends SimpleMediator<SettingsDialog> {
|
||||
SandboxSettings sandboxSettings = new SandboxSettings();
|
||||
sandboxSettings.setSettings(settingsManager.editorConfigVO);
|
||||
viewComponent.addSettingsNode(sandboxSettings);
|
||||
|
||||
if (settingsManager.editorConfigVO.enablePlugins) {
|
||||
PluginsSettings pluginsSettings = new PluginsSettings();
|
||||
pluginsSettingsNode = viewComponent.addSettingsNode(pluginsSettings);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -54,9 +65,14 @@ public class SettingsDialogMediator extends SimpleMediator<SettingsDialog> {
|
||||
viewComponent.show(uiStage);
|
||||
break;
|
||||
case SettingsDialog.ADD_SETTINGS:
|
||||
SettingsDialog.SettingsNodeValue<?> settings = notification.getBody();
|
||||
SettingsNodeValue<?> settings = notification.getBody();
|
||||
viewComponent.addSettingsNode(settings);
|
||||
break;
|
||||
case MsgAPI.ADD_PLUGIN_SETTINGS:
|
||||
SettingsNodeValue<?> nodeValue = notification.getBody();
|
||||
viewComponent.addChildSettingsNode(pluginsSettingsNode, nodeValue);
|
||||
pluginsSettingsNode.setExpanded(true);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,18 +1,19 @@
|
||||
package games.rednblack.editor.view.ui.settings;
|
||||
|
||||
import com.kotcrab.vis.ui.widget.VisCheckBox;
|
||||
import games.rednblack.editor.HyperLap2DFacade;
|
||||
import games.rednblack.editor.utils.StandardWidgetsFactory;
|
||||
import games.rednblack.editor.view.ui.dialog.SettingsDialog;
|
||||
import games.rednblack.h2d.common.MsgAPI;
|
||||
import games.rednblack.h2d.common.view.SettingsNodeValue;
|
||||
import games.rednblack.h2d.common.vo.EditorConfigVO;
|
||||
|
||||
public class GeneralSettings extends SettingsDialog.SettingsNodeValue<EditorConfigVO> {
|
||||
public class GeneralSettings extends SettingsNodeValue<EditorConfigVO> {
|
||||
|
||||
private final VisCheckBox autoSaving;
|
||||
private final VisCheckBox enablePlugins;
|
||||
|
||||
public GeneralSettings() {
|
||||
super("General");
|
||||
super("General", HyperLap2DFacade.getInstance());
|
||||
|
||||
autoSaving = StandardWidgetsFactory.createCheckBox("Save changes automatically [EXPERIMENTAL]");
|
||||
getContentTable().add(autoSaving).left().row();
|
||||
|
||||
@@ -0,0 +1,32 @@
|
||||
package games.rednblack.editor.view.ui.settings;
|
||||
|
||||
import com.badlogic.gdx.utils.Align;
|
||||
import com.kotcrab.vis.ui.widget.VisLabel;
|
||||
import games.rednblack.editor.HyperLap2DFacade;
|
||||
import games.rednblack.editor.utils.StandardWidgetsFactory;
|
||||
import games.rednblack.h2d.common.view.SettingsNodeValue;
|
||||
|
||||
public class PluginsSettings extends SettingsNodeValue<String> {
|
||||
|
||||
public PluginsSettings() {
|
||||
super("Plugins", HyperLap2DFacade.getInstance());
|
||||
|
||||
VisLabel visLabel = StandardWidgetsFactory.createLabel("Choose a PlugIn to change settings", "default", Align.center);
|
||||
getContentTable().add(visLabel).center().expand().fill().grow();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void translateSettingsToView() {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void translateViewToSettings() {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean validateSettings() {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -7,16 +7,18 @@ import com.kotcrab.vis.ui.widget.VisLabel;
|
||||
import com.kotcrab.vis.ui.widget.VisSelectBox;
|
||||
import com.kotcrab.vis.ui.widget.VisTable;
|
||||
import com.kotcrab.vis.ui.widget.file.FileChooser;
|
||||
import games.rednblack.editor.HyperLap2DFacade;
|
||||
import games.rednblack.editor.proxy.ProjectManager;
|
||||
import games.rednblack.editor.proxy.ResolutionManager;
|
||||
import games.rednblack.editor.utils.StandardWidgetsFactory;
|
||||
import games.rednblack.editor.view.ui.dialog.SettingsDialog;
|
||||
import games.rednblack.editor.view.ui.widget.InputFileWidget;
|
||||
import games.rednblack.h2d.common.MsgAPI;
|
||||
import games.rednblack.h2d.common.view.SettingsNodeValue;
|
||||
import games.rednblack.h2d.common.vo.ProjectVO;
|
||||
import games.rednblack.h2d.common.vo.TexturePackerVO;
|
||||
|
||||
public class ProjectExportSettings extends SettingsDialog.SettingsNodeValue<ProjectVO> {
|
||||
public class ProjectExportSettings extends SettingsNodeValue<ProjectVO> {
|
||||
|
||||
private final InputFileWidget exportSettingsInputFileWidget;
|
||||
private final VisCheckBox duplicateCheckBox;
|
||||
@@ -27,7 +29,7 @@ public class ProjectExportSettings extends SettingsDialog.SettingsNodeValue<Proj
|
||||
private final VisSelectBox<String> filterMinSelectBox;
|
||||
|
||||
public ProjectExportSettings() {
|
||||
super("Project Export");
|
||||
super("Project Export", HyperLap2DFacade.getInstance());
|
||||
duplicateCheckBox = StandardWidgetsFactory.createCheckBox("Duplicate edge pixels in atlas");
|
||||
forceSquareCheckBox = StandardWidgetsFactory.createCheckBox("Force Square");
|
||||
exportSettingsInputFileWidget = new InputFileWidget(FileChooser.Mode.OPEN, FileChooser.SelectionMode.DIRECTORIES, false);
|
||||
|
||||
@@ -1,17 +1,18 @@
|
||||
package games.rednblack.editor.view.ui.settings;
|
||||
|
||||
import com.kotcrab.vis.ui.widget.VisCheckBox;
|
||||
import games.rednblack.editor.HyperLap2DFacade;
|
||||
import games.rednblack.editor.utils.StandardWidgetsFactory;
|
||||
import games.rednblack.editor.view.ui.dialog.SettingsDialog;
|
||||
import games.rednblack.h2d.common.MsgAPI;
|
||||
import games.rednblack.h2d.common.view.SettingsNodeValue;
|
||||
import games.rednblack.h2d.common.vo.EditorConfigVO;
|
||||
|
||||
public class SandboxSettings extends SettingsDialog.SettingsNodeValue<EditorConfigVO> {
|
||||
public class SandboxSettings extends SettingsNodeValue<EditorConfigVO> {
|
||||
|
||||
private final VisCheckBox disableAmbientComposite;
|
||||
|
||||
public SandboxSettings() {
|
||||
super("Sandbox");
|
||||
super("Sandbox", HyperLap2DFacade.getInstance());
|
||||
|
||||
getContentTable().add("Composites").left().row();
|
||||
getContentTable().addSeparator();
|
||||
|
||||
Reference in New Issue
Block a user