diff --git a/app-core/src/main/java/com/mercury/platform/shared/config/ConfigManager.java b/app-core/src/main/java/com/mercury/platform/shared/config/ConfigManager.java index 63b06d52..f9fa944a 100644 --- a/app-core/src/main/java/com/mercury/platform/shared/config/ConfigManager.java +++ b/app-core/src/main/java/com/mercury/platform/shared/config/ConfigManager.java @@ -29,5 +29,7 @@ public interface ConfigManager { IconBundleConfigurationService iconBundleConfiguration(); + IconBundleConfigurationService pictureBundleConfiguration(); + List profiles(); } diff --git a/app-core/src/main/java/com/mercury/platform/shared/config/MercuryConfigManager.java b/app-core/src/main/java/com/mercury/platform/shared/config/MercuryConfigManager.java index 3b046197..343f82a4 100644 --- a/app-core/src/main/java/com/mercury/platform/shared/config/MercuryConfigManager.java +++ b/app-core/src/main/java/com/mercury/platform/shared/config/MercuryConfigManager.java @@ -36,6 +36,7 @@ public class MercuryConfigManager implements ConfigManager, AsSubscriber { private PlainConfigurationService hotKeyConfigurationService; private ListConfigurationService stashTabConfigurationService; private IconBundleConfigurationService iconBundleConfigurationService; + private IconBundleConfigurationService pictureBundleConfigurationService; private AdrConfigurationService adrConfigurationService; private List services = new ArrayList<>(); @@ -96,6 +97,11 @@ public IconBundleConfigurationService iconBundleConfiguration() { return this.iconBundleConfigurationService; } + @Override + public IconBundleConfigurationService pictureBundleConfiguration() { + return this.pictureBundleConfigurationService; + } + @Override public PlainConfigurationService hotKeysConfiguration() { return this.hotKeyConfigurationService; @@ -112,9 +118,11 @@ public void load() { File configFile = new File(dataSource.getConfigurationFilePath()); File configFolder = new File(dataSource.getConfigurationPath()); File iconFolder = new File(dataSource.getConfigurationPath() + "\\icons"); - if (!configFolder.exists() || !configFile.exists() || !iconFolder.exists()) { + File pictureFolder = new File(dataSource.getConfigurationPath() + "\\pictures"); + if (!configFolder.exists() || !configFile.exists() || !iconFolder.exists() || !pictureFolder.exists()) { new File(dataSource.getConfigurationPath() + "\\temp").mkdir(); new File(dataSource.getConfigurationPath() + "\\icons").mkdir(); + new File(dataSource.getConfigurationPath() + "\\pictures").mkdir(); new File(dataSource.getConfigurationFilePath()).createNewFile(); ClassLoader classLoader = Thread.currentThread().getContextClassLoader(); @@ -155,6 +163,7 @@ public void load() { this.hotKeyConfigurationService = new HotKeyConfigurationService(selectedProfile); this.adrConfigurationService = new AdrConfigurationServiceMock(selectedProfile); this.iconBundleConfigurationService = new IconBundleConfigurationServiceImpl(selectedProfile); + this.pictureBundleConfigurationService = new PictureBundleConfigurationServiceImpl(selectedProfile); this.services.add((BaseConfigurationService) this.framesConfigurationService); this.services.add((BaseConfigurationService) this.soundConfigurationService); @@ -167,6 +176,7 @@ public void load() { this.services.add((BaseConfigurationService) this.hotKeyConfigurationService); this.services.add((BaseConfigurationService) this.adrConfigurationService); this.services.add((BaseConfigurationService) this.iconBundleConfigurationService); + this.services.add((BaseConfigurationService) this.pictureBundleConfigurationService); this.services.forEach(BaseConfigurationService::validate); diff --git a/app-core/src/main/java/com/mercury/platform/shared/config/configration/impl/PictureBundleConfigurationServiceImpl.java b/app-core/src/main/java/com/mercury/platform/shared/config/configration/impl/PictureBundleConfigurationServiceImpl.java new file mode 100644 index 00000000..53cad154 --- /dev/null +++ b/app-core/src/main/java/com/mercury/platform/shared/config/configration/impl/PictureBundleConfigurationServiceImpl.java @@ -0,0 +1,117 @@ +package com.mercury.platform.shared.config.configration.impl; + +import com.mercury.platform.shared.config.configration.BaseConfigurationService; +import com.mercury.platform.shared.config.configration.IconBundleConfigurationService; +import com.mercury.platform.shared.config.descriptor.ProfileDescriptor; +import com.mercury.platform.shared.entity.message.MercuryError; +import com.mercury.platform.shared.store.MercuryStoreCore; +import org.apache.commons.lang3.StringUtils; + +import javax.imageio.ImageIO; +import java.awt.image.BufferedImage; +import java.io.File; +import java.io.IOException; +import java.net.MalformedURLException; +import java.net.URL; +import java.util.*; +import java.util.stream.Collectors; + +public class PictureBundleConfigurationServiceImpl extends BaseConfigurationService> implements IconBundleConfigurationService { + private static final String PICTURES_PATH = System.getenv("USERPROFILE") + "\\AppData\\Local\\MercuryTrade\\pictures\\"; + private Map pictureBundle = new HashMap<>(); + + public PictureBundleConfigurationServiceImpl(ProfileDescriptor selectedProfile) { + super(selectedProfile); + } + + @Override + public URL getIcon(String iconPath) { + URL url = this.pictureBundle.get(iconPath); + if (url == null) { + url = this.pictureBundle.get("default_syndicate.png"); + } + return url; + } + + @Override + public Map getIconBundle() { + return this.pictureBundle; + } + + @Override + public void addIcon(String iconPath) { + try { + URL url = new URL("file:///" + iconPath); + String iconName = StringUtils.substringAfterLast(iconPath, "\\"); + + File file = new File(PICTURES_PATH + iconName); + BufferedImage image = ImageIO.read(url); + ImageIO.write(image, "png", file); + this.getEntities().add(iconName); + this.pictureBundle.put(iconName, url); + } catch (IOException e) { + MercuryStoreCore.errorHandlerSubject.onNext( + new MercuryError("Error while add icon: " + iconPath, e)); + } + } + + @Override + public void removeIcon(String iconPath) { + } + + @Override + public List getDefault() { + return new ArrayList<>(); + } + + @Override + public List getDefaultBundle() { + return Arrays.stream(new String[]{ + "default_syndicate.png", + "syndicate_colored.png", + "betrayal_reference_guide.png", + "map_drops.png", + }).collect(Collectors.toList()); + } + + @Override + public void toDefault() { + this.selectedProfile.setPictureBundleList(this.getDefault()); + } + + @Override + public List getEntities() { + return this.selectedProfile.getPictureBundleList(); + } + + @Override + public void validate() { + if (this.selectedProfile.getPictureBundleList() == null) { + this.selectedProfile.setPictureBundleList(this.getDefault()); + } + this.initPictureBundle(this.pictureBundle); + } + + private void initPictureBundle(Map pictureBundle) { + this.getDefaultBundle().forEach(it -> { + URL resource = this.getClass().getClassLoader().getResource("app/adr/pictures/" + it); + if (resource != null) { + pictureBundle.put(it, resource); + } + }); + this.getEntities().forEach(it -> { + try { + if (new File(PICTURES_PATH + it).exists()) { + URL resource = new URL("file:///" + PICTURES_PATH + it); + pictureBundle.put(it, resource); + } else { + URL resource = this.getClass().getClassLoader().getResource("app/adr/pictures/" + "default_syndicate.png"); + pictureBundle.put(it, resource); + } + } catch (MalformedURLException e) { + MercuryStoreCore.errorHandlerSubject.onNext( + new MercuryError("Error while initializing icon: " + it, e)); + } + }); + } +} diff --git a/app-core/src/main/java/com/mercury/platform/shared/config/descriptor/ProfileDescriptor.java b/app-core/src/main/java/com/mercury/platform/shared/config/descriptor/ProfileDescriptor.java index 293a8586..9e0c844d 100644 --- a/app-core/src/main/java/com/mercury/platform/shared/config/descriptor/ProfileDescriptor.java +++ b/app-core/src/main/java/com/mercury/platform/shared/config/descriptor/ProfileDescriptor.java @@ -21,4 +21,5 @@ public class ProfileDescriptor { private List stashTabDescriptors; private List adrProfileDescriptorList; private List iconBundleList; + private List pictureBundleList; } diff --git a/app-core/src/main/java/com/mercury/platform/shared/config/descriptor/TaskBarDescriptor.java b/app-core/src/main/java/com/mercury/platform/shared/config/descriptor/TaskBarDescriptor.java index f368a34d..6309ef27 100644 --- a/app-core/src/main/java/com/mercury/platform/shared/config/descriptor/TaskBarDescriptor.java +++ b/app-core/src/main/java/com/mercury/platform/shared/config/descriptor/TaskBarDescriptor.java @@ -10,4 +10,5 @@ public class TaskBarDescriptor implements Serializable { private String dndResponseText = "Response message"; private HotKeyDescriptor hideoutHotkey = new HotKeyDescriptor(); private HotKeyDescriptor helpIGHotkey = new HotKeyDescriptor(); + private String helpIGPath = "..."; } diff --git a/app-core/src/main/java/com/mercury/platform/shared/store/MercuryStoreCore.java b/app-core/src/main/java/com/mercury/platform/shared/store/MercuryStoreCore.java index 9bf8ca8e..d0b832ce 100644 --- a/app-core/src/main/java/com/mercury/platform/shared/store/MercuryStoreCore.java +++ b/app-core/src/main/java/com/mercury/platform/shared/store/MercuryStoreCore.java @@ -60,4 +60,6 @@ public class MercuryStoreCore { public static final PublishSubject newScannerMessageSubject = PublishSubject.create(); public static final PublishSubject removeScannerNotificationSubject = PublishSubject.create(); public static final PublishSubject expiredNotificationSubject = PublishSubject.create(); + + public static final PublishSubject pictureChange = PublishSubject.create(); } diff --git a/app-ui/src/main/java/com/mercury/platform/ui/adr/components/AdrManagerFrame.java b/app-ui/src/main/java/com/mercury/platform/ui/adr/components/AdrManagerFrame.java index cf9ef7ae..4b159fa0 100644 --- a/app-ui/src/main/java/com/mercury/platform/ui/adr/components/AdrManagerFrame.java +++ b/app-ui/src/main/java/com/mercury/platform/ui/adr/components/AdrManagerFrame.java @@ -11,6 +11,7 @@ import com.mercury.platform.ui.adr.dialog.AdrExportDialog; import com.mercury.platform.ui.adr.dialog.AdrIconSelectDialog; import com.mercury.platform.ui.adr.dialog.AdrNewProfileDialog; +import com.mercury.platform.ui.adr.dialog.AdrPictureSelectDialog; import com.mercury.platform.ui.adr.routing.AdrPageDefinition; import com.mercury.platform.ui.adr.routing.AdrPageState; import com.mercury.platform.ui.components.fields.font.FontStyle; @@ -38,6 +39,7 @@ public class AdrManagerFrame extends AbstractTitledComponentFrame { private JComboBox profileSelector; private AdrExportDialog exportDialog; private AdrIconSelectDialog iconSelectDialog; + private AdrPictureSelectDialog pictureSelectDialog; @Getter private AdrProfileDescriptor selectedProfile; @@ -52,6 +54,8 @@ public AdrManagerFrame(AdrProfileDescriptor selectedProfile) { this.exportDialog = new AdrExportDialog(this, new ArrayList<>()); this.iconSelectDialog = new AdrIconSelectDialog(); this.iconSelectDialog.setLocationRelativeTo(null); + this.pictureSelectDialog = new AdrPictureSelectDialog(); + this.pictureSelectDialog.setLocationRelativeTo(null); FrameDescriptor frameDescriptor = this.framesConfig.get(this.getClass().getSimpleName()); this.setPreferredSize(frameDescriptor.getFrameSize()); UIManager.put("MenuItem.background", AppThemeColor.ADR_BG); @@ -133,6 +137,10 @@ public void subscribe() { this.iconSelectDialog.setCallback(callback); this.iconSelectDialog.setVisible(true); }); + MercuryStoreUI.adrOpenPictureSelectSubject.subscribe(callback -> { + this.pictureSelectDialog.setCallback(callback); + this.pictureSelectDialog.setVisible(true); + }); } public void setSelectedProfile(AdrProfileDescriptor profile) { diff --git a/app-ui/src/main/java/com/mercury/platform/ui/adr/components/panel/ui/PicturesListCellRenderer.java b/app-ui/src/main/java/com/mercury/platform/ui/adr/components/panel/ui/PicturesListCellRenderer.java new file mode 100644 index 00000000..5f7790b3 --- /dev/null +++ b/app-ui/src/main/java/com/mercury/platform/ui/adr/components/panel/ui/PicturesListCellRenderer.java @@ -0,0 +1,25 @@ +package com.mercury.platform.ui.adr.components.panel.ui; + +import com.mercury.platform.shared.config.Configuration; +import com.mercury.platform.shared.config.configration.IconBundleConfigurationService; +import com.mercury.platform.ui.components.ComponentsFactory; +import com.mercury.platform.ui.misc.AppThemeColor; + +import javax.swing.*; +import java.awt.*; + + +public class PicturesListCellRenderer implements ListCellRenderer { + private ComponentsFactory componentsFactory = new ComponentsFactory(); + private IconBundleConfigurationService config = Configuration.get().pictureBundleConfiguration(); + + @Override + public Component getListCellRendererComponent(JList list, String value, int index, boolean isSelected, boolean cellHasFocus) { + JLabel iconLabel = this.componentsFactory.getIconLabel(this.config.getIcon(value), 230); + iconLabel.setBorder(BorderFactory.createEmptyBorder(2, 2, 2, 2)); + if (isSelected) { + iconLabel.setBorder(BorderFactory.createLineBorder(AppThemeColor.TEXT_MESSAGE)); + } + return iconLabel; + } +} diff --git a/app-ui/src/main/java/com/mercury/platform/ui/adr/dialog/AdrIconSelectDialog.java b/app-ui/src/main/java/com/mercury/platform/ui/adr/dialog/AdrIconSelectDialog.java index d1c2982c..30b9b629 100644 --- a/app-ui/src/main/java/com/mercury/platform/ui/adr/dialog/AdrIconSelectDialog.java +++ b/app-ui/src/main/java/com/mercury/platform/ui/adr/dialog/AdrIconSelectDialog.java @@ -2,26 +2,17 @@ import com.mercury.platform.shared.config.Configuration; -import com.mercury.platform.shared.config.configration.IconBundleConfigurationService; -import com.mercury.platform.shared.store.MercuryStoreCore; import com.mercury.platform.ui.adr.components.panel.ui.IconsListCellRenderer; -import com.mercury.platform.ui.components.fields.font.FontStyle; import com.mercury.platform.ui.components.panel.VerticalScrollContainer; -import com.mercury.platform.ui.dialog.BaseDialog; import com.mercury.platform.ui.misc.AppThemeColor; -import org.apache.commons.lang3.StringUtils; import javax.swing.*; import java.awt.*; import java.util.List; -import java.util.stream.Collectors; - -public class AdrIconSelectDialog extends BaseDialog { - private JList iconsList; - private IconBundleConfigurationService config; +public class AdrIconSelectDialog extends AdrSelectDialog { public AdrIconSelectDialog() { - super(null, null, null); + super(); this.setTitle("Select icon"); } @@ -51,79 +42,4 @@ protected void createView() { this.add(scrollPane, BorderLayout.CENTER); this.add(this.getBottomPanel(), BorderLayout.PAGE_END); } - - public void setSelectedIcon(String iconPath) { - this.iconsList.setSelectedValue(iconPath, true); - } - - private JPanel getFilterPanel() { - JPanel root = this.componentsFactory.getJPanel(new BorderLayout()); - root.add(this.componentsFactory.getTextLabel("Filter:"), BorderLayout.LINE_START); - JTextField filterField = this.componentsFactory.getTextField("Filter:", FontStyle.REGULAR, 15); - filterField.addActionListener(action -> { - List entities = this.config.getDefaultBundle(); - entities.addAll(this.config.getEntities()); - if (filterField.getText().equals("")) { - this.iconsList.setListData(entities.toArray()); - } else { - List collect = entities.stream() - .filter(name -> StringUtils.containsIgnoreCase(name, filterField.getText())) - .collect(Collectors.toList()); - this.iconsList.setListData(collect.toArray()); - } - }); - root.add(filterField, BorderLayout.CENTER); - root.setBackground(AppThemeColor.SLIDE_BG); - root.setBorder( - BorderFactory.createCompoundBorder( - BorderFactory.createLineBorder(AppThemeColor.BORDER_DARK), - BorderFactory.createEmptyBorder(4, 0, 4, 4))); - JButton addIconButton = this.componentsFactory.getBorderedButton("Add icon"); - addIconButton.setPreferredSize(new Dimension(100, 26)); - addIconButton.addActionListener(action -> { - FileDialog dialog = new FileDialog(this, "Choose icon", FileDialog.LOAD); - dialog.setFile("*.png"); - dialog.setVisible(true); - dialog.toFront(); - if (this.isValidIconPath(dialog.getFile())) { - this.config.addIcon(dialog.getDirectory() + dialog.getFile()); - Object selectedValue = this.iconsList.getSelectedValue(); - List entities = this.config.getDefaultBundle(); - entities.addAll(this.config.getEntities()); - this.iconsList.setListData(entities.toArray()); - this.setSelectedIcon((String) selectedValue); - MercuryStoreCore.saveConfigSubject.onNext(true); - } - }); - root.add(this.componentsFactory.wrapToSlide(addIconButton, AppThemeColor.ADR_BG), BorderLayout.LINE_END); - JPanel wrapper = this.componentsFactory.wrapToSlide(root); - wrapper.setBorder(BorderFactory.createEmptyBorder(4, 0, 4, 0)); - return wrapper; - } - - private JPanel getBottomPanel() { - JPanel root = this.componentsFactory.getJPanel(new FlowLayout(FlowLayout.CENTER)); - JButton selectButton = this.componentsFactory.getBorderedButton("Select"); - selectButton.setFont(this.componentsFactory.getFont(FontStyle.BOLD, 15f)); - JButton cancelButton = componentsFactory.getButton( - FontStyle.BOLD, - AppThemeColor.FRAME_RGB, - BorderFactory.createLineBorder(AppThemeColor.BORDER), - "Cancel", - 15f); - selectButton.setPreferredSize(new Dimension(128, 26)); - cancelButton.setPreferredSize(new Dimension(128, 26)); - selectButton.addActionListener(action -> { - this.callback.onAction((String) this.iconsList.getSelectedValue()); - this.setVisible(false); - }); - cancelButton.addActionListener(action -> this.setVisible(false)); - root.add(selectButton); - root.add(cancelButton); - return root; - } - - private boolean isValidIconPath(String name) { - return name != null && (name.endsWith(".png")); - } } diff --git a/app-ui/src/main/java/com/mercury/platform/ui/adr/dialog/AdrPictureSelectDialog.java b/app-ui/src/main/java/com/mercury/platform/ui/adr/dialog/AdrPictureSelectDialog.java new file mode 100644 index 00000000..5a585d43 --- /dev/null +++ b/app-ui/src/main/java/com/mercury/platform/ui/adr/dialog/AdrPictureSelectDialog.java @@ -0,0 +1,45 @@ +package com.mercury.platform.ui.adr.dialog; + + +import com.mercury.platform.shared.config.Configuration; +import com.mercury.platform.ui.adr.components.panel.ui.PicturesListCellRenderer; +import com.mercury.platform.ui.components.panel.VerticalScrollContainer; +import com.mercury.platform.ui.misc.AppThemeColor; + +import javax.swing.*; +import java.awt.*; +import java.util.List; + +public class AdrPictureSelectDialog extends AdrSelectDialog { + public AdrPictureSelectDialog() { + super(); + this.setTitle("Select picture"); + } + + @Override + protected void createView() { + this.config = Configuration.get().pictureBundleConfiguration(); + this.setPreferredSize(new Dimension(530, 400)); + + VerticalScrollContainer container = new VerticalScrollContainer(); + container.setBackground(AppThemeColor.SLIDE_BG); + container.setLayout(new BorderLayout()); + + JScrollPane scrollPane = this.componentsFactory.getVerticalContainer(container); + List entities = this.config.getDefaultBundle(); + entities.addAll(this.config.getEntities()); + this.iconsList = new JList<>(entities.toArray()); + this.iconsList.setBackground(AppThemeColor.SLIDE_BG); + this.iconsList.setSelectionMode(ListSelectionModel.SINGLE_INTERVAL_SELECTION); + this.iconsList.setVisibleRowCount(-1); + this.iconsList.setCellRenderer(new PicturesListCellRenderer()); + this.iconsList.setLayoutOrientation(JList.HORIZONTAL_WRAP); + + container.add(this.iconsList, BorderLayout.CENTER); + + scrollPane.setBorder(BorderFactory.createLineBorder(AppThemeColor.BORDER_DARK)); + this.add(this.getFilterPanel(), BorderLayout.PAGE_START); + this.add(scrollPane, BorderLayout.CENTER); + this.add(this.getBottomPanel(), BorderLayout.PAGE_END); + } +} diff --git a/app-ui/src/main/java/com/mercury/platform/ui/adr/dialog/AdrSelectDialog.java b/app-ui/src/main/java/com/mercury/platform/ui/adr/dialog/AdrSelectDialog.java new file mode 100644 index 00000000..af9168d8 --- /dev/null +++ b/app-ui/src/main/java/com/mercury/platform/ui/adr/dialog/AdrSelectDialog.java @@ -0,0 +1,99 @@ +package com.mercury.platform.ui.adr.dialog; + + +import com.mercury.platform.shared.config.configration.IconBundleConfigurationService; +import com.mercury.platform.shared.store.MercuryStoreCore; +import com.mercury.platform.ui.components.fields.font.FontStyle; +import com.mercury.platform.ui.dialog.BaseDialog; +import com.mercury.platform.ui.misc.AppThemeColor; +import org.apache.commons.lang3.StringUtils; + +import javax.swing.*; +import java.awt.*; +import java.util.List; +import java.util.stream.Collectors; + +public abstract class AdrSelectDialog extends BaseDialog { + protected JList iconsList; + protected IconBundleConfigurationService config; + + public void setSelectedIcon(String iconPath) { + this.iconsList.setSelectedValue(iconPath, true); + } + + public AdrSelectDialog() { + super(null, null, null); + this.setTitle("Select"); + } + + protected JPanel getFilterPanel() { + JPanel root = this.componentsFactory.getJPanel(new BorderLayout()); + root.add(this.componentsFactory.getTextLabel("Filter:"), BorderLayout.LINE_START); + JTextField filterField = this.componentsFactory.getTextField("Filter:", FontStyle.REGULAR, 15); + filterField.addActionListener(action -> { + List entities = this.config.getDefaultBundle(); + entities.addAll(this.config.getEntities()); + if (filterField.getText().equals("")) { + this.iconsList.setListData(entities.toArray()); + } else { + List collect = entities.stream() + .filter(name -> StringUtils.containsIgnoreCase(name, filterField.getText())) + .collect(Collectors.toList()); + this.iconsList.setListData(collect.toArray()); + } + }); + root.add(filterField, BorderLayout.CENTER); + root.setBackground(AppThemeColor.SLIDE_BG); + root.setBorder( + BorderFactory.createCompoundBorder( + BorderFactory.createLineBorder(AppThemeColor.BORDER_DARK), + BorderFactory.createEmptyBorder(4, 0, 4, 4))); + JButton addIconButton = this.componentsFactory.getBorderedButton("Add icon"); + addIconButton.setPreferredSize(new Dimension(100, 26)); + addIconButton.addActionListener(action -> { + FileDialog dialog = new FileDialog(this, "Choose icon", FileDialog.LOAD); + dialog.setFile("*.png"); + dialog.setVisible(true); + dialog.toFront(); + if (this.isValidIconPath(dialog.getFile())) { + this.config.addIcon(dialog.getDirectory() + dialog.getFile()); + Object selectedValue = this.iconsList.getSelectedValue(); + List entities = this.config.getDefaultBundle(); + entities.addAll(this.config.getEntities()); + this.iconsList.setListData(entities.toArray()); + this.setSelectedIcon((String) selectedValue); + MercuryStoreCore.saveConfigSubject.onNext(true); + } + }); + root.add(this.componentsFactory.wrapToSlide(addIconButton, AppThemeColor.ADR_BG), BorderLayout.LINE_END); + JPanel wrapper = this.componentsFactory.wrapToSlide(root); + wrapper.setBorder(BorderFactory.createEmptyBorder(4, 0, 4, 0)); + return wrapper; + } + + protected JPanel getBottomPanel() { + JPanel root = this.componentsFactory.getJPanel(new FlowLayout(FlowLayout.CENTER)); + JButton selectButton = this.componentsFactory.getBorderedButton("Select"); + selectButton.setFont(this.componentsFactory.getFont(FontStyle.BOLD, 15f)); + JButton cancelButton = componentsFactory.getButton( + FontStyle.BOLD, + AppThemeColor.FRAME_RGB, + BorderFactory.createLineBorder(AppThemeColor.BORDER), + "Cancel", + 15f); + selectButton.setPreferredSize(new Dimension(128, 26)); + cancelButton.setPreferredSize(new Dimension(128, 26)); + selectButton.addActionListener(action -> { + this.callback.onAction((String) this.iconsList.getSelectedValue()); + this.setVisible(false); + }); + cancelButton.addActionListener(action -> this.setVisible(false)); + root.add(selectButton); + root.add(cancelButton); + return root; + } + + protected boolean isValidIconPath(String name) { + return name != null && (name.endsWith(".png")); + } +} diff --git a/app-ui/src/main/java/com/mercury/platform/ui/components/panel/settings/page/TaskBarSettingsPagePanel.java b/app-ui/src/main/java/com/mercury/platform/ui/components/panel/settings/page/TaskBarSettingsPagePanel.java index 871d85a6..2e38214e 100644 --- a/app-ui/src/main/java/com/mercury/platform/ui/components/panel/settings/page/TaskBarSettingsPagePanel.java +++ b/app-ui/src/main/java/com/mercury/platform/ui/components/panel/settings/page/TaskBarSettingsPagePanel.java @@ -6,6 +6,7 @@ import com.mercury.platform.shared.config.descriptor.TaskBarDescriptor; import com.mercury.platform.ui.components.fields.font.FontStyle; import com.mercury.platform.ui.misc.AppThemeColor; +import com.mercury.platform.ui.misc.MercuryStoreUI; import javax.swing.*; import java.awt.*; @@ -16,6 +17,7 @@ public class TaskBarSettingsPagePanel extends SettingsPagePanel { private PlainConfigurationService taskBarService; private TaskBarDescriptor taskBarSnapshot; + @Override public void onViewInit() { super.onViewInit(); @@ -43,23 +45,27 @@ public void focusLost(FocusEvent e) { root.add(componentsFactory.getTextLabel("DND response:", FontStyle.REGULAR)); root.add(this.componentsFactory.wrapToSlide(responseField, AppThemeColor.ADR_BG)); - JPanel hotKeysPanel = this.componentsFactory.getJPanel(new GridLayout(0, 2, 4, 4), AppThemeColor.SETTINGS_BG); - hotKeysPanel.setBorder(BorderFactory.createLineBorder(AppThemeColor.ADR_DEFAULT_BORDER)); root.add(this.componentsFactory.getIconLabel("app/hideout.png", 24, SwingConstants.CENTER)); HotKeyGroup hotKeyGroup = new HotKeyGroup(true); HotKeyPanel hotKeyHideoutPanel = new HotKeyPanel(this.taskBarSnapshot.getHideoutHotkey()); hotKeyGroup.registerHotkey(hotKeyHideoutPanel); - root.add(this.componentsFactory.wrapToSlide(hotKeyHideoutPanel, AppThemeColor.SETTINGS_BG, 2, 4, 1, 1)); - this.container.add(this.componentsFactory.wrapToSlide(root)); - this.container.add(this.componentsFactory.wrapToSlide(hotKeysPanel)); + root.add(this.componentsFactory.wrapToSlide(hotKeyHideoutPanel, AppThemeColor.ADR_BG, 2, 4, 1, 1)); root.add(this.componentsFactory.getIconLabel("app/helpIG_icon.png", 24, SwingConstants.CENTER)); + JPanel helpIGPanel = componentsFactory.getTransparentPanel(new BorderLayout(4, 4)); HotKeyPanel hotKeyHelpIGPanel = new HotKeyPanel(this.taskBarSnapshot.getHelpIGHotkey()); hotKeyGroup.registerHotkey(hotKeyHelpIGPanel); - root.add(this.componentsFactory.wrapToSlide(hotKeyHelpIGPanel, AppThemeColor.SETTINGS_BG, 2, 4, 1, 1)); + helpIGPanel.add(hotKeyHelpIGPanel, BorderLayout.CENTER); + JButton selectIcon = this.componentsFactory.getBorderedButton("Select Picture"); + selectIcon.addActionListener(action -> { + MercuryStoreUI.adrOpenPictureSelectSubject.onNext(selectedIconPath -> { + this.taskBarSnapshot.setHelpIGPath(selectedIconPath); + }); + }); + helpIGPanel.add(selectIcon, BorderLayout.LINE_END); + root.add(this.componentsFactory.wrapToSlide(helpIGPanel, AppThemeColor.ADR_BG, 2, 4, 1, 1)); this.container.add(this.componentsFactory.wrapToSlide(root)); - this.container.add(this.componentsFactory.wrapToSlide(hotKeysPanel)); } @Override diff --git a/app-ui/src/main/java/com/mercury/platform/ui/components/panel/taskbar/MercuryTaskBarController.java b/app-ui/src/main/java/com/mercury/platform/ui/components/panel/taskbar/MercuryTaskBarController.java index 8442f3b2..8780d0fa 100644 --- a/app-ui/src/main/java/com/mercury/platform/ui/components/panel/taskbar/MercuryTaskBarController.java +++ b/app-ui/src/main/java/com/mercury/platform/ui/components/panel/taskbar/MercuryTaskBarController.java @@ -38,6 +38,7 @@ public void performHideout() { @Override public void showHelpIG() { FramesManager.INSTANCE.hideOrShowFrame(HelpIGFrame.class); + MercuryStoreCore.pictureChange.onNext(false); } @Override diff --git a/app-ui/src/main/java/com/mercury/platform/ui/frame/other/HelpIGFrame.java b/app-ui/src/main/java/com/mercury/platform/ui/frame/other/HelpIGFrame.java index c7f36ce6..ff845360 100644 --- a/app-ui/src/main/java/com/mercury/platform/ui/frame/other/HelpIGFrame.java +++ b/app-ui/src/main/java/com/mercury/platform/ui/frame/other/HelpIGFrame.java @@ -1,14 +1,27 @@ package com.mercury.platform.ui.frame.other; +import com.mercury.platform.shared.CloneHelper; +import com.mercury.platform.shared.config.Configuration; +import com.mercury.platform.shared.config.configration.IconBundleConfigurationService; +import com.mercury.platform.shared.config.configration.PlainConfigurationService; +import com.mercury.platform.shared.config.descriptor.TaskBarDescriptor; +import com.mercury.platform.shared.entity.message.MercuryError; +import com.mercury.platform.shared.store.MercuryStoreCore; import com.mercury.platform.ui.frame.AbstractOverlaidFrame; +import javax.imageio.ImageIO; import javax.swing.*; import java.awt.*; import java.awt.event.MouseAdapter; import java.awt.event.MouseEvent; +import java.awt.image.BufferedImage; +import java.io.IOException; +import java.net.MalformedURLException; +import java.net.URL; public class HelpIGFrame extends AbstractOverlaidFrame { - private int MARGIN = 400; + private JLabel img = new JLabel(); + private int MARGIN = 300; private int x; private int y; public HelpIGFrame() { @@ -22,6 +35,7 @@ protected void initialize() { @Override public void subscribe() { + MercuryStoreCore.pictureChange.subscribe(message -> refreshImage()); } @Override @@ -31,25 +45,14 @@ protected LayoutManager getFrameLayout() { @Override public void onViewInit() { - this.setOpacity(this.applicationConfig.get().getMaxOpacity() / 100f); - Dimension dim = Toolkit.getDefaultToolkit().getScreenSize(); - - ImageIcon icon = this.componentsFactory.getImage("app/helpIGImg.png"); - Image image = icon.getImage(); // transform it - Image newimg = image.getScaledInstance(dim.width - MARGIN, -1, java.awt.Image.SCALE_SMOOTH); - if(dim.height-MARGIN < newimg.getHeight(null)) { - newimg = image.getScaledInstance(-1, dim.height - MARGIN, java.awt.Image.SCALE_SMOOTH); - } - icon = new ImageIcon(newimg); - - JLabel img = new JLabel(icon); + refreshImage(); this.add(img); + this.repaint(); img.addMouseListener(new DraggedFrameMouseListener()); img.addMouseMotionListener(new DraggedFrameMotionListener()); img.setCursor(new Cursor(Cursor.MOVE_CURSOR)); this.pack(); - this.setLocation(dim.width/2-this.getSize().width/2, 0); } public class DraggedFrameMotionListener extends MouseAdapter { @@ -60,6 +63,39 @@ public void mouseDragged(MouseEvent e) { } } + + private void refreshImage() { + ImageIcon icon = this.componentsFactory.getImage("app/adr/pictures/default_syndicate.png"); + PlainConfigurationService taskBarService = Configuration.get().taskBarConfiguration(); + TaskBarDescriptor taskBarSnapshot = CloneHelper.cloneObject(taskBarService.get()); + IconBundleConfigurationService config = Configuration.get().pictureBundleConfiguration(); + try { + URL url = config.getIcon(taskBarSnapshot.getHelpIGPath()); + BufferedImage img = ImageIO.read(url); + icon = new ImageIcon(img); + } catch (MalformedURLException e) { + MercuryStoreCore.errorHandlerSubject.onNext( + new MercuryError("Error while initializing picture: " + taskBarSnapshot.getHelpIGPath(), e)); + } catch (IOException e) { + e.printStackTrace(); + } + + this.setOpacity(this.applicationConfig.get().getMaxOpacity() / 100f); + Dimension dim = Toolkit.getDefaultToolkit().getScreenSize(); + + Image image = icon.getImage(); // transform it + Image newImg = image.getScaledInstance(dim.width - MARGIN, -1, java.awt.Image.SCALE_SMOOTH); + if(dim.height-MARGIN < newImg.getHeight(null)) { + newImg = image.getScaledInstance(-1, dim.height - MARGIN, java.awt.Image.SCALE_SMOOTH); + } + icon = new ImageIcon(newImg); + + img.setIcon(icon); + this.repaint(); + this.pack(); + this.setLocation(dim.width/2-newImg.getWidth(null)/2, 0); + } + public class DraggedFrameMouseListener extends MouseAdapter { @Override public void mousePressed(MouseEvent e) { diff --git a/app-ui/src/main/java/com/mercury/platform/ui/misc/MercuryStoreUI.java b/app-ui/src/main/java/com/mercury/platform/ui/misc/MercuryStoreUI.java index 8a831068..5dac3b22 100644 --- a/app-ui/src/main/java/com/mercury/platform/ui/misc/MercuryStoreUI.java +++ b/app-ui/src/main/java/com/mercury/platform/ui/misc/MercuryStoreUI.java @@ -51,6 +51,7 @@ public class MercuryStoreUI { public static final PublishSubject adrExportSubject = PublishSubject.create(); public static final PublishSubject adrUpdateSubject = PublishSubject.create(); public static final PublishSubject> adrOpenIconSelectSubject = PublishSubject.create(); + public static final PublishSubject> adrOpenPictureSelectSubject = PublishSubject.create(); public static final PublishSubject settingsStateSubject = PublishSubject.create(); public static final PublishSubject settingsRepaintSubject = PublishSubject.create(); diff --git a/app-ui/src/main/resources/app/adr/pictures/betrayal_reference_guide.png b/app-ui/src/main/resources/app/adr/pictures/betrayal_reference_guide.png new file mode 100644 index 00000000..5977be6e Binary files /dev/null and b/app-ui/src/main/resources/app/adr/pictures/betrayal_reference_guide.png differ diff --git a/app-ui/src/main/resources/app/adr/pictures/default_syndicate.png b/app-ui/src/main/resources/app/adr/pictures/default_syndicate.png new file mode 100644 index 00000000..92a7fa5f Binary files /dev/null and b/app-ui/src/main/resources/app/adr/pictures/default_syndicate.png differ diff --git a/app-ui/src/main/resources/app/adr/pictures/map_drops.png b/app-ui/src/main/resources/app/adr/pictures/map_drops.png new file mode 100644 index 00000000..bac3cd23 Binary files /dev/null and b/app-ui/src/main/resources/app/adr/pictures/map_drops.png differ diff --git a/app-ui/src/main/resources/app/adr/pictures/syndicate_colored.png b/app-ui/src/main/resources/app/adr/pictures/syndicate_colored.png new file mode 100644 index 00000000..9b64094b Binary files /dev/null and b/app-ui/src/main/resources/app/adr/pictures/syndicate_colored.png differ diff --git a/app-ui/src/main/resources/app/helpIGImg.png b/app-ui/src/main/resources/app/helpIGImg.png deleted file mode 100644 index 6e730773..00000000 Binary files a/app-ui/src/main/resources/app/helpIGImg.png and /dev/null differ