diff --git a/PlayWallCore/src/main/java/de/tobias/playpad/profile/Profile.java b/PlayWallCore/src/main/java/de/tobias/playpad/profile/Profile.java index 4900d036b2a09c0e936c85cbc6e5b52bebea9964..7e50c4dc4866467c22a06cc7372e830b28cd36e7 100644 --- a/PlayWallCore/src/main/java/de/tobias/playpad/profile/Profile.java +++ b/PlayWallCore/src/main/java/de/tobias/playpad/profile/Profile.java @@ -17,9 +17,7 @@ import org.dom4j.DocumentException; import java.io.IOException; import java.nio.file.Files; import java.nio.file.Path; -import java.util.ArrayList; -import java.util.List; -import java.util.Optional; +import java.util.*; public class Profile { @@ -30,11 +28,13 @@ public class Profile { private static Profile currentProfile; // Settings - private ProfileReference ref; + private final ProfileReference ref; private ProfileSettings profileSettings; private MappingCollection mappings; + private Map<String, Object> customSettings; + /** * Use {@link ProfileReferenceManager#addProfile(ProfileReference)} instead * @@ -44,6 +44,7 @@ public class Profile { this.ref = ref; this.profileSettings = new ProfileSettings(); this.mappings = new MappingCollection(); + this.customSettings = new HashMap<>(); } public static Mapping createMappingWithDefaultActions() { @@ -84,6 +85,14 @@ public class Profile { return profileSettings; } + public Object getCustomSettings(String name) { + return customSettings.get(name); + } + + public void addCustomSettings(String name, Object settings) { + customSettings.put(name, settings); + } + public static Profile load(ProfileReference ref) throws DocumentException, IOException, ProfileNotFoundException { if (ref == null) { throw new IllegalArgumentException("Profile is null"); diff --git a/PlayWallPlugins/PlayWallPluginContentPlayer/src/main/scala/de/tobias/playpad/plugin/content/ContentPluginMain.scala b/PlayWallPlugins/PlayWallPluginContentPlayer/src/main/scala/de/tobias/playpad/plugin/content/ContentPluginMain.scala index f0c2c1de0a0e5e2d033b8db275f40899b580d4d4..13ce8dac90ec52fec18a5e53a45f8fea08fb7c59 100644 --- a/PlayWallPlugins/PlayWallPluginContentPlayer/src/main/scala/de/tobias/playpad/plugin/content/ContentPluginMain.scala +++ b/PlayWallPlugins/PlayWallPluginContentPlayer/src/main/scala/de/tobias/playpad/plugin/content/ContentPluginMain.scala @@ -6,10 +6,11 @@ import de.thecodelabs.utils.util.Localization import de.tobias.playpad.PlayPadPlugin import de.tobias.playpad.plugin.content.player.ContentPlayerViewController import de.tobias.playpad.plugin.content.settings.{ZoneConfiguration, ZoneSettingsViewController} -import de.tobias.playpad.plugin.{Module, PlayPadPluginStub} +import de.tobias.playpad.plugin.{Module, PlayPadPluginStub, SettingsListener} +import de.tobias.playpad.profile.{Profile, ProfileListener} import javafx.application.Platform -class ContentPluginMain extends PlayPadPluginStub { +class ContentPluginMain extends PlayPadPluginStub with SettingsListener with ProfileListener { private var module: Module = _ @@ -20,13 +21,10 @@ class ContentPluginMain extends PlayPadPluginStub { Localization.addResourceBundle(localization) PlayPadPlugin.getRegistries.getPadContents.loadComponentsFromFile("PadContent.xml", getClass.getClassLoader, module, localization) - Platform.runLater(() => { - ContentPluginMain.playerViewController = new ContentPlayerViewController - ContentPluginMain.playerViewController.configurePlayers(ContentPluginMain.configuration) - ContentPluginMain.playerViewController.showStage() - }) + PlayPadPlugin.getInstance().addAdditionalProfileSettingsTab(() => new ZoneSettingsViewController) - PlayPadPlugin.getInstance().addGlobalSettingsTab(() => new ZoneSettingsViewController) + PlayPadPlugin.getInstance().addSettingsListener(this) + Profile.registerListener(this) } override def shutdown(): Unit = { @@ -34,9 +32,31 @@ class ContentPluginMain extends PlayPadPluginStub { } override def getModule: Module = module + + override def onLoad(profile: Profile): Unit = { + val path = profile.getRef.getCustomFilePath("Zones.json") + val zoneConfiguration = Storage.load(path, StorageTypes.JSON, classOf[ZoneConfiguration]) + profile.addCustomSettings(ContentPluginMain.zoneConfigurationKey, zoneConfiguration) + } + + override def onSave(profile: Profile): Unit = { + val path = profile.getRef.getCustomFilePath("Zones.json") + val zoneConfigurationObject = profile.getCustomSettings(ContentPluginMain.zoneConfigurationKey) + if (zoneConfigurationObject != null) { + Storage.save(path, StorageTypes.JSON, zoneConfigurationObject) + } + } + + override def reloadSettings(oldProfile: Profile, currentProfile: Profile): Unit = { + val zoneConfiguration = currentProfile.getCustomSettings(ContentPluginMain.zoneConfigurationKey).asInstanceOf[ZoneConfiguration] + Platform.runLater(() => { + ContentPluginMain.playerViewController.configurePlayers(zoneConfiguration) + }) + } } object ContentPluginMain { - var playerViewController: ContentPlayerViewController = _ - lazy val configuration: ZoneConfiguration = Storage.load(StorageTypes.JSON, classOf[ZoneConfiguration]) + lazy val playerViewController: ContentPlayerViewController = new ContentPlayerViewController + + val zoneConfigurationKey = "ZoneConfiguration" } \ No newline at end of file diff --git a/PlayWallPlugins/PlayWallPluginContentPlayer/src/main/scala/de/tobias/playpad/plugin/content/pad/ContentPlayerPadContent.scala b/PlayWallPlugins/PlayWallPluginContentPlayer/src/main/scala/de/tobias/playpad/plugin/content/pad/ContentPlayerPadContent.scala index 210e3d5b2535661ff06aed843b1eae4aef2a0184..389edd1821acd6119f34f96c4dab1c0de247e539 100644 --- a/PlayWallPlugins/PlayWallPluginContentPlayer/src/main/scala/de/tobias/playpad/plugin/content/pad/ContentPlayerPadContent.scala +++ b/PlayWallPlugins/PlayWallPluginContentPlayer/src/main/scala/de/tobias/playpad/plugin/content/pad/ContentPlayerPadContent.scala @@ -10,8 +10,9 @@ import de.tobias.playpad.pad.fade.{Fadeable, LinearFadeController} import de.tobias.playpad.pad.mediapath.MediaPath import de.tobias.playpad.pad.{Pad, PadStatus} import de.tobias.playpad.plugin.content.ContentPluginMain -import de.tobias.playpad.plugin.content.settings.Zone +import de.tobias.playpad.plugin.content.settings.{Zone, ZoneConfiguration} import de.tobias.playpad.plugin.content.util._ +import de.tobias.playpad.profile.Profile import de.tobias.playpad.volume.VolumeManager import javafx.application.Platform import javafx.beans.binding.{Bindings, ObjectBinding} @@ -292,11 +293,13 @@ class ContentPlayerPadContent(val pad: Pad, val `type`: String) extends PadConte } def getSelectedZones: Seq[Zone] = { + val zoneConfiguration = Profile.currentProfile().getCustomSettings(ContentPluginMain.zoneConfigurationKey).asInstanceOf[ZoneConfiguration] + val customSettings = pad.getPadSettings.getCustomSettings val selectedZoneNames = customSettings.getOrDefault( ContentPlayerPadContentFactory.zones, - ContentPluginMain.configuration.zones.stream().map(zone => zone.getName).collect(Collectors.toList()) + zoneConfiguration.zones.stream().map(zone => zone.getName).collect(Collectors.toList()) ).asInstanceOf[util.List[String]] - ContentPluginMain.configuration.zones.asScala.filter(zone => selectedZoneNames.contains(zone.getName)).toSeq + zoneConfiguration.zones.asScala.filter(zone => selectedZoneNames.contains(zone.getName)).toSeq } } diff --git a/PlayWallPlugins/PlayWallPluginContentPlayer/src/main/scala/de/tobias/playpad/plugin/content/pad/ContentPlayerPadContentSettingsViewController.scala b/PlayWallPlugins/PlayWallPluginContentPlayer/src/main/scala/de/tobias/playpad/plugin/content/pad/ContentPlayerPadContentSettingsViewController.scala index 08670f34922ee0e5c7566e164270aa96bdbb9622..14d5e0ee477047de962dfd5959c2ee67d0a9c1c8 100644 --- a/PlayWallPlugins/PlayWallPluginContentPlayer/src/main/scala/de/tobias/playpad/plugin/content/pad/ContentPlayerPadContentSettingsViewController.scala +++ b/PlayWallPlugins/PlayWallPluginContentPlayer/src/main/scala/de/tobias/playpad/plugin/content/pad/ContentPlayerPadContentSettingsViewController.scala @@ -5,7 +5,8 @@ import java.util import de.thecodelabs.utils.util.Localization import de.tobias.playpad.pad.Pad import de.tobias.playpad.plugin.content.ContentPluginMain -import de.tobias.playpad.plugin.content.settings.Zone +import de.tobias.playpad.plugin.content.settings.{Zone, ZoneConfiguration} +import de.tobias.playpad.profile.Profile import de.tobias.playpad.viewcontroller.PadSettingsTabViewController import javafx.beans.binding.Bindings import javafx.fxml.FXML @@ -28,9 +29,9 @@ class ContentPlayerPadContentSettingsViewController(val pad: Pad) extends PadSet load("view", "ContentPadSettings", Localization.getBundle) - override def init(): Unit = { - zoneListView.getItems.addAll(ContentPluginMain.configuration.zones) + val zoneConfiguration = Profile.currentProfile().getCustomSettings(ContentPluginMain.zoneConfigurationKey).asInstanceOf[ZoneConfiguration] + zoneListView.getItems.addAll(zoneConfiguration.zones) addAllZonesButton.disableProperty().bind(Bindings.equal(Bindings.size(zoneListView.getCheckModel.getCheckedIndices), zoneListView.getItems.size())) removeAllZonesButton.disableProperty().bind(Bindings.isEmpty(zoneListView.getCheckModel.getCheckedIndices)) diff --git a/PlayWallPlugins/PlayWallPluginContentPlayer/src/main/scala/de/tobias/playpad/plugin/content/player/ContentPlayerViewController.scala b/PlayWallPlugins/PlayWallPluginContentPlayer/src/main/scala/de/tobias/playpad/plugin/content/player/ContentPlayerViewController.scala index 4fd71e5744f1e817686af3e8a2ba51df81aa0a9f..5a71719da29217ab579a4c94fd02fc14928796e7 100644 --- a/PlayWallPlugins/PlayWallPluginContentPlayer/src/main/scala/de/tobias/playpad/plugin/content/player/ContentPlayerViewController.scala +++ b/PlayWallPlugins/PlayWallPluginContentPlayer/src/main/scala/de/tobias/playpad/plugin/content/player/ContentPlayerViewController.scala @@ -56,6 +56,11 @@ class ContentPlayerViewController extends NVC { } def configurePlayers(configuration: ZoneConfiguration): Unit = { + if (configuration.zones.isEmpty) { + closeStage() + return + } + val parent = getParent.asInstanceOf[Pane] parent.getChildren.clear() @@ -66,6 +71,8 @@ class ContentPlayerViewController extends NVC { parent.getChildren.add(mediaPlayerStack) }) + showStage() + getStageContainer.ifPresent(container => { val stage = container.getStage @@ -88,6 +95,9 @@ class ContentPlayerViewController extends NVC { .foreach(mediaStack => mediaStack.removeActivePad(padIndex)) def highlight(zone: Zone, on: Boolean): Unit = { + if (getMediaStack(zone).isEmpty) { + return + } getMediaStack(zone).head.highlight(on) } diff --git a/PlayWallPlugins/PlayWallPluginContentPlayer/src/main/scala/de/tobias/playpad/plugin/content/settings/ZoneSettingsViewController.scala b/PlayWallPlugins/PlayWallPluginContentPlayer/src/main/scala/de/tobias/playpad/plugin/content/settings/ZoneSettingsViewController.scala index 137a12fac7a5b7680dcf867ea26b6f8aae8b79c2..bae668ff818ef49c8b463df091ccea02bffdb6f4 100644 --- a/PlayWallPlugins/PlayWallPluginContentPlayer/src/main/scala/de/tobias/playpad/plugin/content/settings/ZoneSettingsViewController.scala +++ b/PlayWallPlugins/PlayWallPluginContentPlayer/src/main/scala/de/tobias/playpad/plugin/content/settings/ZoneSettingsViewController.scala @@ -1,17 +1,17 @@ package de.tobias.playpad.plugin.content.settings -import de.thecodelabs.storage.settings.{Storage, StorageTypes} import de.thecodelabs.utils.ui.scene.input.NumberTextField import de.thecodelabs.utils.util.Localization import de.tobias.playpad.plugin.content.ContentPluginMain -import de.tobias.playpad.settings.GlobalSettings +import de.tobias.playpad.profile.{Profile, ProfileSettings} +import de.tobias.playpad.project.Project import de.tobias.playpad.viewcontroller.main.IMainViewController -import de.tobias.playpad.viewcontroller.option.{GlobalSettingsTabViewController, IGlobalReloadTask} +import de.tobias.playpad.viewcontroller.option.{IProfileReloadTask, ProfileSettingsTabViewController} import javafx.application.Platform import javafx.fxml.FXML import javafx.scene.control.{Button, ListCell, ListView, TextField} -class ZoneSettingsViewController extends GlobalSettingsTabViewController with IGlobalReloadTask { +class ZoneSettingsViewController extends ProfileSettingsTabViewController with IProfileReloadTask { @FXML var listView: ListView[Zone] = _ @@ -92,7 +92,7 @@ class ZoneSettingsViewController extends GlobalSettingsTabViewController with IG val newConfiguration = new Zone newConfiguration.setName(Localization.getString("plugin.content.player.settings.default_name")) - ContentPluginMain.configuration.zones.add(newConfiguration) + getZoneConfiguration.zones.add(newConfiguration) listView.getItems.add(newConfiguration) } @@ -101,21 +101,19 @@ class ZoneSettingsViewController extends GlobalSettingsTabViewController with IG val selectedItem = listView.getSelectionModel.getSelectedItem if (selectedItem != null) { listView.getItems.remove(selectedItem) - ContentPluginMain.configuration.zones.remove(selectedItem) + getZoneConfiguration.zones.remove(selectedItem) } } - override def loadSettings(settings: GlobalSettings): Unit = { - listView.getItems.setAll(ContentPluginMain.configuration.zones) + override def loadSettings(settings: Profile): Unit = { + listView.getItems.setAll(getZoneConfiguration.zones) } - override def saveSettings(settings: GlobalSettings): Unit = { + override def saveSettings(settings: Profile): Unit = { val selectedItem = listView.getSelectionModel.getSelectedItem if (selectedItem != null) { saveSettingsToZone(selectedItem) } - - Storage.save(StorageTypes.JSON, ContentPluginMain.configuration) } override def needReload(): Boolean = { @@ -128,6 +126,9 @@ class ZoneSettingsViewController extends GlobalSettingsTabViewController with IG override def name(): String = Localization.getString("plugin.content.player.settings") - override def getTask(settings: GlobalSettings, controller: IMainViewController): Runnable = () => - Platform.runLater(() => ContentPluginMain.playerViewController.configurePlayers(ContentPluginMain.configuration)) + + override def getTask(settings: ProfileSettings, project: Project, controller: IMainViewController): Runnable = () => + Platform.runLater(() => ContentPluginMain.playerViewController.configurePlayers(getZoneConfiguration)) + + private def getZoneConfiguration: ZoneConfiguration = Profile.currentProfile().getCustomSettings(ContentPluginMain.zoneConfigurationKey).asInstanceOf[ZoneConfiguration] }