diff --git a/app-core/src/main/java/com/mercury/platform/shared/config/configration/impl/ApplicationConfigurationService.java b/app-core/src/main/java/com/mercury/platform/shared/config/configration/impl/ApplicationConfigurationService.java index 4bd8c471..f6cceb8e 100644 --- a/app-core/src/main/java/com/mercury/platform/shared/config/configration/impl/ApplicationConfigurationService.java +++ b/app-core/src/main/java/com/mercury/platform/shared/config/configration/impl/ApplicationConfigurationService.java @@ -5,6 +5,9 @@ import com.mercury.platform.shared.config.configration.PlainConfigurationService; import com.mercury.platform.shared.config.descriptor.ApplicationDescriptor; import com.mercury.platform.shared.config.descriptor.ProfileDescriptor; +import org.apache.commons.lang3.StringUtils; + +import java.io.File; public class ApplicationConfigurationService extends BaseConfigurationService implements PlainConfigurationService { @@ -17,6 +20,10 @@ public void validate() { if (this.selectedProfile.getApplicationDescriptor() == null) { this.selectedProfile.setApplicationDescriptor(this.getDefault()); } + ApplicationDescriptor applicationDescriptor = this.selectedProfile.getApplicationDescriptor(); + if (!StringUtils.substringAfterLast(applicationDescriptor.getGamePath(), "\\").equals("")) { + applicationDescriptor.setGamePath(applicationDescriptor.getGamePath() + File.separatorChar); + } } @Override diff --git a/app-ui/src/main/java/com/mercury/platform/ui/components/ControlsFactory.java b/app-ui/src/main/java/com/mercury/platform/ui/components/ControlsFactory.java deleted file mode 100644 index c34366a3..00000000 --- a/app-ui/src/main/java/com/mercury/platform/ui/components/ControlsFactory.java +++ /dev/null @@ -1,25 +0,0 @@ -package com.mercury.platform.ui.components; - - -import com.mercury.platform.ui.misc.AppThemeColor; -import com.mercury.platform.ui.misc.TooltipConstants; -import lombok.NonNull; - -import javax.swing.*; - -//todo generic for components constructor -public class ControlsFactory { - private ComponentsFactory componentsFactory; - - public ControlsFactory(@NonNull ComponentsFactory factory) { - this.componentsFactory = factory; - } - - public void getInviteButton(float iconSize) { - JButton invite = componentsFactory.getIconButton( - "app/invite.png", - iconSize, - AppThemeColor.SLIDE_BG, - TooltipConstants.INVITE); - } -} diff --git a/app-ui/src/main/java/com/mercury/platform/ui/components/panel/CollapsiblePanel.java b/app-ui/src/main/java/com/mercury/platform/ui/components/panel/CollapsiblePanel.java deleted file mode 100644 index 00e12e67..00000000 --- a/app-ui/src/main/java/com/mercury/platform/ui/components/panel/CollapsiblePanel.java +++ /dev/null @@ -1,64 +0,0 @@ -package com.mercury.platform.ui.components.panel; - -import com.mercury.platform.ui.components.ComponentsFactory; -import com.mercury.platform.ui.misc.AppThemeColor; -import com.mercury.platform.ui.misc.TooltipConstants; - -import javax.swing.*; -import java.awt.*; -import java.awt.event.MouseAdapter; -import java.awt.event.MouseEvent; - -/** - * Created by Константин on 05.01.2017. - */ -public class CollapsiblePanel extends JPanel { - private ComponentsFactory componentsFactory; - private String title; - private InnerPanel innerPanel; - private JFrame owner; - private boolean expand; - - public CollapsiblePanel(String title, InnerPanel innerPanel, JFrame owner, boolean expand) { - this.title = title; - this.innerPanel = innerPanel; - this.owner = owner; - this.expand = expand; - this.componentsFactory = new ComponentsFactory(); - - this.setBackground(AppThemeColor.TRANSPARENT); - this.setBorder(BorderFactory.createMatteBorder(1, 0, 1, 0, AppThemeColor.BORDER)); - this.setLayout(new BorderLayout()); - createUI(); - } - - private void createUI() { - JPanel header = componentsFactory.getBorderedTransparentPanel(BorderFactory.createEmptyBorder(-4, 0, -4, 0), new FlowLayout(FlowLayout.LEFT)); - - header.add(getExpandButton()); - header.add(componentsFactory.getTextLabel(title)); - header.setBackground(AppThemeColor.HEADER); - innerPanel.setVisible(expand); - this.add(header, BorderLayout.PAGE_START); - this.add(innerPanel, BorderLayout.CENTER); - } - - private JButton getExpandButton() { - String iconPath = expand ? "app/collapse.png" : "app/expand.png"; - JButton expandButton = componentsFactory.getIconButton(iconPath, 16, AppThemeColor.FRAME_ALPHA, TooltipConstants.EXPAND_COLLAPSE); - expandButton.addMouseListener(new MouseAdapter() { - @Override - public void mousePressed(MouseEvent e) { - if (!innerPanel.isVisible()) { - expandButton.setIcon(componentsFactory.getIcon("app/collapse.png", 16)); - innerPanel.setVisible(true); - } else { - expandButton.setIcon(componentsFactory.getIcon("app/expand.png", 16)); - innerPanel.setVisible(false); - } - owner.pack(); - } - }); - return expandButton; - } -} diff --git a/app-ui/src/main/java/com/mercury/platform/ui/frame/titled/TimerFrame.java b/app-ui/src/main/java/com/mercury/platform/ui/frame/titled/TimerFrame.java deleted file mode 100644 index 198fc2d0..00000000 --- a/app-ui/src/main/java/com/mercury/platform/ui/frame/titled/TimerFrame.java +++ /dev/null @@ -1,198 +0,0 @@ -package com.mercury.platform.ui.frame.titled; - -import com.mercury.platform.ui.components.fields.font.FontStyle; -import com.mercury.platform.ui.components.fields.font.TextAlignment; -import com.mercury.platform.ui.misc.AppThemeColor; -import com.mercury.platform.ui.misc.TooltipConstants; - -import javax.swing.*; -import java.awt.*; -import java.awt.event.MouseAdapter; -import java.awt.event.MouseEvent; - -/** - * Created by Константин on 06.01.2017. - */ -public class TimerFrame extends AbstractTitledComponentFrame { - private Timer timeAgo; - private JLabel timeLabel; - private int seconds = 0; - private int minutes = 0; - private int hours = 0; - private int mapCount = 0; - private int chaosSpend = 0; - - public TimerFrame() { - super(); - } - - @Override - protected void initialize() { - super.initialize(); - JPanel root = componentsFactory.getTransparentPanel(new FlowLayout(FlowLayout.LEFT)); - JButton play = componentsFactory.getIconButton("app/timer-play.png", 16, AppThemeColor.FRAME_ALPHA, TooltipConstants.PLAY); - play.addMouseListener(new MouseAdapter() { - @Override - public void mousePressed(MouseEvent e) { - getNewTimer().start(); - } - }); - JButton pause = componentsFactory.getIconButton("app/timer-pause.png", 16, AppThemeColor.FRAME_ALPHA, TooltipConstants.PAUSE); - pause.addMouseListener(new MouseAdapter() { - @Override - public void mousePressed(MouseEvent e) { - if (timeAgo != null) { - timeAgo.stop(); - } - } - }); - JButton stop = componentsFactory.getIconButton("app/timer-stop.png", 16, AppThemeColor.FRAME_ALPHA, TooltipConstants.STOP); - stop.addMouseListener(new MouseAdapter() { - @Override - public void mousePressed(MouseEvent e) { - if (timeAgo != null) { - timeAgo.stop(); - seconds = 0; - minutes = 0; - hours = 0; - } - } - }); - JLabel mapCountLabel = componentsFactory.getTextLabel("Map count: 0"); - JLabel chaosSpendLabel = componentsFactory.getTextLabel("Chaos spend: 0"); - JButton reset = componentsFactory.getIconButton("app/timer-reset.png", 16, AppThemeColor.FRAME_ALPHA, TooltipConstants.RESET); - reset.addMouseListener(new MouseAdapter() { - @Override - public void mousePressed(MouseEvent e) { - if (timeAgo != null) { - timeAgo.stop(); - } - timeLabel.setText("00:00:00"); - seconds = 0; - minutes = 0; - hours = 0; - mapCount = 0; - chaosSpend = 0; - mapCountLabel.setText("Map count: 0"); - chaosSpendLabel.setText("Chaos spend: 0"); - TimerFrame.this.repaint(); - } - }); - root.add(getTimePanel()); - root.add(play); - root.add(pause); - root.add(stop); - root.add(reset); - this.add(root, BorderLayout.CENTER); - - JPanel miscPanel = componentsFactory.getTransparentPanel(null); - miscPanel.setLayout(new BoxLayout(miscPanel, BoxLayout.Y_AXIS)); - - JPanel mapCountPanel = getIncrementRow(mapCountLabel, new MouseAdapter() { - @Override - public void mousePressed(MouseEvent e) { - mapCount++; - mapCountLabel.setText("Map count: " + mapCount); - TimerFrame.this.repaint(); - } - }, new MouseAdapter() { - @Override - public void mousePressed(MouseEvent e) { - if (mapCount > 0) { - mapCount--; - mapCountLabel.setText("Map count: " + mapCount); - TimerFrame.this.repaint(); - } - } - }); - JPanel chaosSpendPanel = getIncrementRow(chaosSpendLabel, new MouseAdapter() { - @Override - public void mousePressed(MouseEvent e) { - chaosSpend++; - chaosSpendLabel.setText("Chaos spend: " + chaosSpend); - TimerFrame.this.repaint(); - } - }, new MouseAdapter() { - @Override - public void mousePressed(MouseEvent e) { - if (chaosSpend > 0) { - chaosSpend--; - chaosSpendLabel.setText("Chaos spend: " + chaosSpend); - TimerFrame.this.repaint(); - } - } - }); - - miscPanel.add(mapCountPanel); - miscPanel.add(chaosSpendPanel); - this.add(miscPanel, BorderLayout.PAGE_END); - this.pack(); - } - - private Timer getNewTimer() { - timeAgo = new Timer(1000, e -> { - String labelText = ""; - seconds++; - if (seconds > 59) { - minutes++; - seconds = 0; - if (minutes > 59) { - hours++; - minutes = 0; - } - } - String secLabel = ((seconds / 10.0) >= 1f) ? String.valueOf(seconds) : "0" + seconds; - String minLabel = ((minutes / 10.0) >= 1f) ? String.valueOf(minutes) : "0" + minutes; - String hLabel = ((hours / 10.0) >= 1f) ? String.valueOf(hours) : "0" + hours; - if (minutes == 0 && hours == 0) { - labelText = "00:00:" + secLabel; - } else if (minutes > 0) { - labelText = "00:" + minLabel + ":" + secLabel; - } else if (hours > 0) { - labelText = hLabel + ":" + minLabel + ":" + secLabel; - } - timeLabel.setText(labelText); - TimerFrame.this.repaint(); - }); - return timeAgo; - } - - private JPanel getIncrementRow(JLabel label, MouseAdapter plusListener, MouseAdapter minusListener) { - JPanel panel = componentsFactory.getTransparentPanel(new FlowLayout(FlowLayout.LEFT)); - JButton plus = componentsFactory.getIconButton("app/invite.png", 14, AppThemeColor.FRAME_ALPHA, ""); - plus.addMouseListener(plusListener); - JButton minus = componentsFactory.getIconButton("app/kick.png", 14, AppThemeColor.FRAME_ALPHA, ""); - minus.addMouseListener(minusListener); - panel.add(label); - panel.add(plus); - panel.add(minus); - return panel; - } - - private JPanel getTimePanel() { - JPanel panel = new JPanel(new FlowLayout(FlowLayout.LEFT)); - panel.setBackground(AppThemeColor.TRANSPARENT); - timeLabel = componentsFactory.getTextLabel(FontStyle.BOLD, AppThemeColor.TEXT_MISC, TextAlignment.CENTER, 18, "00:00:00"); - timeLabel.setVerticalAlignment(SwingConstants.CENTER); - timeLabel.setHorizontalAlignment(SwingConstants.CENTER); - panel.setBorder(BorderFactory.createLineBorder(AppThemeColor.BUTTON, 1)); - panel.setMinimumSize(new Dimension(100, 30)); - panel.setPreferredSize(new Dimension(100, 30)); - panel.add(timeLabel); - return panel; - } - - @Override - public void subscribe() { - } - - @Override - protected String getFrameTitle() { - return "Timer"; - } - - @Override - public void onViewInit() { - - } -} diff --git a/app/src/main/java/com/mercury/platform/AppMain.java b/app/src/main/java/com/mercury/platform/AppMain.java index b9acd195..fbb0bf11 100644 --- a/app/src/main/java/com/mercury/platform/AppMain.java +++ b/app/src/main/java/com/mercury/platform/AppMain.java @@ -10,38 +10,33 @@ import com.mercury.platform.ui.frame.titled.GamePathChooser; import com.mercury.platform.ui.manager.FramesManager; import com.sun.jna.Native; -import com.sun.jna.Pointer; -import com.sun.jna.platform.DesktopWindow; import com.sun.jna.platform.WindowUtils; import com.sun.jna.platform.win32.User32; -import com.sun.jna.platform.win32.WinDef; -import com.sun.jna.platform.win32.WinUser; import org.apache.commons.lang3.StringUtils; import java.io.File; -import java.util.List; public class AppMain { public static void main(String[] args) { - System.setProperty("sun.java2d.d3d","false"); - System.setProperty("jna.nosys","true"); + System.setProperty("sun.java2d.d3d", "false"); + System.setProperty("jna.nosys", "true"); new ErrorHandler(); MercuryLoadingFrame mercuryLoadingFrame = new MercuryLoadingFrame(); mercuryLoadingFrame.init(); mercuryLoadingFrame.showComponent(); - if(args.length == 0) { + if (args.length == 0) { new ProdStarter().startApplication(); - }else { + } else { new DevStarter().startApplication(); } String configGamePath = Configuration.get().applicationConfiguration().get().getGamePath(); - if(configGamePath.equals("") || !isValidGamePath(configGamePath)){ + if (configGamePath.equals("") || !isValidGamePath(configGamePath)) { String gamePath = getGamePath(); - if(gamePath == null) { + if (gamePath == null) { MercuryStoreCore.appLoadingSubject.onNext(false); GamePathChooser gamePathChooser = new GamePathChooser(); gamePathChooser.init(); - }else { + } else { gamePath = gamePath + "\\"; Configuration.get().applicationConfiguration().get().setGamePath(gamePath); MercuryStoreCore.saveConfigSubject.onNext(true); @@ -49,17 +44,19 @@ public static void main(String[] args) { FramesManager.INSTANCE.start(); MercuryStoreCore.appLoadingSubject.onNext(false); } - }else { + } else { new FileMonitor().start(); FramesManager.INSTANCE.start(); MercuryStoreCore.appLoadingSubject.onNext(false); } } - private static boolean isValidGamePath(String gamePath){ + + private static boolean isValidGamePath(String gamePath) { File file = new File(gamePath + File.separator + "logs" + File.separator + "Client.txt"); return file.exists(); } - private static String getGamePath(){ + + private static String getGamePath() { return WindowUtils.getAllWindows(false).stream().filter(window -> { char[] className = new char[512]; User32.INSTANCE.GetClassName(window.getHWND(), className, 512);