diff --git a/app-core/src/main/java/com/mercury/platform/core/ChatHelper.java b/app-core/src/main/java/com/mercury/platform/core/ChatHelper.java index c7295cc7..a4b96456 100644 --- a/app-core/src/main/java/com/mercury/platform/core/ChatHelper.java +++ b/app-core/src/main/java/com/mercury/platform/core/ChatHelper.java @@ -3,14 +3,18 @@ import com.mercury.platform.shared.AsSubscriber; import com.mercury.platform.shared.config.Configuration; 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.sun.jna.Native; import com.sun.jna.platform.win32.User32; import java.awt.*; import java.awt.datatransfer.Clipboard; +import java.awt.datatransfer.DataFlavor; import java.awt.datatransfer.StringSelection; +import java.awt.datatransfer.UnsupportedFlavorException; import java.awt.event.KeyEvent; +import java.io.IOException; public class ChatHelper implements AsSubscriber { private Robot robot; @@ -31,7 +35,6 @@ private void executeMessage(String message) { clipboard.setContents(selection, null); MercuryStoreCore.blockHotkeySubject.onNext(true); robot.keyRelease(KeyEvent.VK_ALT); - robot.keyPress(KeyEvent.VK_ENTER); robot.keyRelease(KeyEvent.VK_ENTER); @@ -52,6 +55,39 @@ private void executeMessage(String message) { MercuryStoreCore.blockHotkeySubject.onNext(false); } + private void executeTradeMessage() { + Toolkit toolkit = Toolkit.getDefaultToolkit(); + Clipboard clipboard = toolkit.getSystemClipboard(); + try { + String result = (String) clipboard.getData(DataFlavor.stringFlavor); + if (result.contains("listed for") || result.contains("for my")) { + this.gameToFront(); + MercuryStoreCore.blockHotkeySubject.onNext(true); + robot.keyRelease(KeyEvent.VK_ALT); + robot.keyPress(KeyEvent.VK_ENTER); + robot.keyRelease(KeyEvent.VK_ENTER); + + robot.keyPress(KeyEvent.VK_CONTROL); + robot.keyPress(KeyEvent.VK_A); + robot.keyRelease(KeyEvent.VK_CONTROL); + robot.keyRelease(KeyEvent.VK_A); + + robot.keyPress(KeyEvent.VK_BACK_SPACE); + robot.keyRelease(KeyEvent.VK_BACK_SPACE); + + robot.keyPress(KeyEvent.VK_CONTROL); + robot.keyPress(KeyEvent.VK_V); + robot.keyRelease(KeyEvent.VK_V); + robot.keyRelease(KeyEvent.VK_CONTROL); + robot.keyPress(KeyEvent.VK_ENTER); + robot.keyRelease(KeyEvent.VK_ENTER); + MercuryStoreCore.blockHotkeySubject.onNext(false); + } + } catch (UnsupportedFlavorException | IOException e) { + MercuryStoreCore.errorHandlerSubject.onNext(new MercuryError(e)); + } + } + private void openChat(String whisper) { this.gameToFront(); StringSelection selection = new StringSelection("@" + whisper); @@ -100,6 +136,7 @@ private void gameToFront() { public void subscribe() { MercuryStoreCore.chatCommandSubject.subscribe(this::executeMessage); MercuryStoreCore.openChatSubject.subscribe(this::openChat); + MercuryStoreCore.tradeWhisperSubject.subscribe(state -> this.executeTradeMessage()); MercuryStoreCore.dndSubject.subscribe(state -> { TaskBarDescriptor config = Configuration.get().taskBarConfiguration().get(); if (config.isInGameDnd()) { diff --git a/app-core/src/main/java/com/mercury/platform/core/misc/SoundNotifier.java b/app-core/src/main/java/com/mercury/platform/core/misc/SoundNotifier.java index e05ed5dd..57595cd9 100644 --- a/app-core/src/main/java/com/mercury/platform/core/misc/SoundNotifier.java +++ b/app-core/src/main/java/com/mercury/platform/core/misc/SoundNotifier.java @@ -22,6 +22,9 @@ public SoundNotifier() { .subscribe(data -> play(data.getWavPath(), data.getDb())); MercuryStoreCore.dndSubject .subscribe(value -> this.dnd = value); + MercuryStoreCore.soundDescriptorSubject.subscribe(soundDescriptor -> { + this.play(soundDescriptor.getWavPath(), soundDescriptor.getDb()); + }); } private void play(String wavPath, float db) { diff --git a/app-core/src/main/java/com/mercury/platform/core/utils/interceptor/PlayerInaccessibleInterceptor.java b/app-core/src/main/java/com/mercury/platform/core/utils/interceptor/PlayerInaccessibleInterceptor.java index a0c5497b..4c12f4bf 100644 --- a/app-core/src/main/java/com/mercury/platform/core/utils/interceptor/PlayerInaccessibleInterceptor.java +++ b/app-core/src/main/java/com/mercury/platform/core/utils/interceptor/PlayerInaccessibleInterceptor.java @@ -17,12 +17,16 @@ public PlayerInaccessibleInterceptor() { @Override protected void process(String message) { - this.lastPlainMessage.setMessage(StringUtils.substringAfter(message, " : ")); - MercuryStoreCore.plainMessageSubject.onNext(this.lastPlainMessage); + if (lastPlainMessage != null) { + PlainMessageDescriptor descriptor = new PlainMessageDescriptor(); + descriptor.setNickName(this.lastPlainMessage.getNickName()); + descriptor.setMessage(StringUtils.substringAfter(message, " : ")); + MercuryStoreCore.plainMessageSubject.onNext(descriptor); + } } @Override protected MessageMatcher match() { - return message -> message.contains("That character is not online."); + return message -> true; } } diff --git a/app-core/src/main/java/com/mercury/platform/shared/config/descriptor/SoundDescriptor.java b/app-core/src/main/java/com/mercury/platform/shared/config/descriptor/SoundDescriptor.java index 89aa9ce1..5bbe9758 100644 --- a/app-core/src/main/java/com/mercury/platform/shared/config/descriptor/SoundDescriptor.java +++ b/app-core/src/main/java/com/mercury/platform/shared/config/descriptor/SoundDescriptor.java @@ -10,6 +10,6 @@ @AllArgsConstructor @NoArgsConstructor public class SoundDescriptor implements Serializable { - private String wavPath; - private Float db; + private String wavPath = "..."; + private Float db = 0f; } diff --git a/app-core/src/main/java/com/mercury/platform/shared/config/descriptor/adr/AdrDurationComponentDescriptor.java b/app-core/src/main/java/com/mercury/platform/shared/config/descriptor/adr/AdrDurationComponentDescriptor.java index 75ccf886..89aa4ca8 100644 --- a/app-core/src/main/java/com/mercury/platform/shared/config/descriptor/adr/AdrDurationComponentDescriptor.java +++ b/app-core/src/main/java/com/mercury/platform/shared/config/descriptor/adr/AdrDurationComponentDescriptor.java @@ -1,6 +1,7 @@ package com.mercury.platform.shared.config.descriptor.adr; import com.mercury.platform.shared.config.descriptor.HotKeyDescriptor; +import com.mercury.platform.shared.config.descriptor.SoundDescriptor; import lombok.Data; import lombok.EqualsAndHashCode; @@ -35,4 +36,6 @@ public class AdrDurationComponentDescriptor extends AdrColoredComponentDescripto private Double defaultValueTextThreshold = 5d; private Insets insets = new Insets(0, 0, 0, 0); private boolean bindToTextColor; + private SoundDescriptor soundDescriptor = new SoundDescriptor(); + private Double soundThreshold = 0d; } diff --git a/app-core/src/main/java/com/mercury/platform/shared/hotkey/HotKeysInterceptor.java b/app-core/src/main/java/com/mercury/platform/shared/hotkey/HotKeysInterceptor.java index 28d384d6..9aa78cfb 100644 --- a/app-core/src/main/java/com/mercury/platform/shared/hotkey/HotKeysInterceptor.java +++ b/app-core/src/main/java/com/mercury/platform/shared/hotkey/HotKeysInterceptor.java @@ -17,6 +17,7 @@ public HotKeysInterceptor() { } catch (NativeHookException e) { e.printStackTrace(); } + GlobalScreen.addNativeKeyListener(new MercuryNativeKeyListener()); GlobalScreen.addNativeMouseListener(new MercuryNativeMouseListener()); } diff --git a/app-core/src/main/java/com/mercury/platform/shared/hotkey/MercuryNativeKeyListener.java b/app-core/src/main/java/com/mercury/platform/shared/hotkey/MercuryNativeKeyListener.java index 20736160..2ee65401 100644 --- a/app-core/src/main/java/com/mercury/platform/shared/hotkey/MercuryNativeKeyListener.java +++ b/app-core/src/main/java/com/mercury/platform/shared/hotkey/MercuryNativeKeyListener.java @@ -6,6 +6,8 @@ import org.jnativehook.keyboard.NativeKeyEvent; import org.jnativehook.keyboard.NativeKeyListener; +import javax.swing.*; + public class MercuryNativeKeyListener implements NativeKeyListener { private boolean menuPressed; private boolean shiftPressed; @@ -21,15 +23,15 @@ public MercuryNativeKeyListener() { public void nativeKeyPressed(NativeKeyEvent nativeKeyEvent) { switch (nativeKeyEvent.getKeyCode()) { case 42: { - this.shiftPressed = true; + shiftPressed = true; break; } case 29: { - this.ctrlpressed = true; + ctrlpressed = true; break; } case 56: { - this.menuPressed = true; + menuPressed = true; break; } default: { @@ -44,18 +46,28 @@ public void nativeKeyPressed(NativeKeyEvent nativeKeyEvent) { public void nativeKeyReleased(NativeKeyEvent nativeKeyEvent) { switch (nativeKeyEvent.getKeyCode()) { case 42: { - this.shiftPressed = false; + shiftPressed = false; break; } case 29: { - this.ctrlpressed = false; + ctrlpressed = false; break; } case 56: { - this.menuPressed = false; + menuPressed = false; break; } } + if (!this.block) { + if (nativeKeyEvent.getKeyCode() == 29) { + Timer timer = new Timer(500, action -> { + MercuryStoreCore.tradeWhisperSubject.onNext(true); + }); + timer.setRepeats(false); + timer.start(); + } + } + } @Override @@ -77,9 +89,9 @@ private HotKeyDescriptor getDescriptor(NativeKeyEvent nativeKeyEvent) { HotKeyDescriptor hotKeyDescriptor = new HotKeyDescriptor(); hotKeyDescriptor.setTitle(NativeKeyEvent.getKeyText(nativeKeyEvent.getKeyCode())); hotKeyDescriptor.setVirtualKeyCode(nativeKeyEvent.getKeyCode()); - hotKeyDescriptor.setControlPressed(this.ctrlpressed); - hotKeyDescriptor.setShiftPressed(this.shiftPressed); - hotKeyDescriptor.setMenuPressed(this.menuPressed); + hotKeyDescriptor.setControlPressed(ctrlpressed); + hotKeyDescriptor.setShiftPressed(shiftPressed); + hotKeyDescriptor.setMenuPressed(menuPressed); hotKeyDescriptor.setTitle(this.getButtonText(hotKeyDescriptor)); return hotKeyDescriptor; 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 3232196b..9bf8ca8e 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 @@ -51,6 +51,8 @@ public class MercuryStoreCore { public static final PublishSubject blockHotkeySubject = PublishSubject.create(); public static final PublishSubject errorHandlerSubject = PublishSubject.create(); public static final PublishSubject adrVisibleSubject = PublishSubject.create(); + public static final PublishSubject tradeWhisperSubject = PublishSubject.create(); + public static final PublishSubject soundDescriptorSubject = PublishSubject.create(); public static final PublishSubject newNotificationSubject = PublishSubject.create(); public static final PublishSubject removeNotificationSubject = PublishSubject.create(); diff --git a/app-ui/src/main/java/com/mercury/platform/ui/adr/components/AdrComponentsFactory.java b/app-ui/src/main/java/com/mercury/platform/ui/adr/components/AdrComponentsFactory.java index 7edb56e3..637ca549 100644 --- a/app-ui/src/main/java/com/mercury/platform/ui/adr/components/AdrComponentsFactory.java +++ b/app-ui/src/main/java/com/mercury/platform/ui/adr/components/AdrComponentsFactory.java @@ -20,6 +20,7 @@ import com.mercury.platform.ui.misc.AppThemeColor; import com.mercury.platform.ui.misc.MercuryStoreUI; import com.mercury.platform.ui.misc.TooltipConstants; +import org.apache.commons.lang3.StringUtils; import javax.swing.*; import javax.swing.colorchooser.AbstractColorChooserPanel; @@ -79,6 +80,55 @@ public JPanel getComponentSizePanel(AdrComponentDescriptor descriptor, boolean f return root; } + public JPanel getSoundPanel(AdrDurationComponentDescriptor descriptor) { + String[] soundPaths = { + "...", + "Button-chime", + "Corsica-ding", + "Foolboy-notification", + "Nenadsimic" + }; + JComboBox soundPathBox = this.componentsFactory.getComboBox(soundPaths); + String selectedPath = "..."; + if (!descriptor.getSoundDescriptor().getWavPath().equals("...")) { + selectedPath = StringUtils.substringBetween(descriptor.getSoundDescriptor().getWavPath(), "app/sounds/", ".wav"); + } + soundPathBox.setSelectedItem(selectedPath); + soundPathBox.addActionListener(action -> { + if (!soundPathBox.getSelectedItem().equals("...")) { + descriptor.getSoundDescriptor().setWavPath("app/sounds/" + soundPathBox.getSelectedItem() + ".wav"); + MercuryStoreCore.soundDescriptorSubject.onNext(descriptor.getSoundDescriptor()); + MercuryStoreUI.adrReloadSubject.onNext(descriptor); + } else { + descriptor.getSoundDescriptor().setWavPath("..."); + } + }); + JPanel root = this.componentsFactory.getJPanel(new BorderLayout(4, 0), AppThemeColor.ADR_BG); + JTextField durationField = + this.getSmartField(descriptor.getSoundThreshold(), + new DoubleFieldValidator(0.0, 1000.0), descriptor::setSoundThreshold); + durationField.setPreferredSize(new Dimension(36, 26)); + root.add(soundPathBox, BorderLayout.LINE_START); + root.add(this.componentsFactory.getTextLabel("when duration ="), BorderLayout.CENTER); + root.add(durationField, BorderLayout.LINE_END); + return root; + } + + public JSlider getVolumeSlider(AdrDurationComponentDescriptor descriptor) { + JSlider notificationSlider = this.componentsFactory.getSlider(-40, 6, descriptor.getSoundDescriptor().getDb().intValue(), AppThemeColor.ADR_BG); + notificationSlider.addMouseListener(new MouseAdapter() { + @Override + public void mouseReleased(MouseEvent e) { + if (!descriptor.getSoundDescriptor().getWavPath().equals("...")) { + descriptor.getSoundDescriptor().setDb(notificationSlider.getValue() == -40 ? -80f : (float) notificationSlider.getValue()); + MercuryStoreCore.soundDescriptorSubject.onNext(descriptor.getSoundDescriptor()); + MercuryStoreUI.adrReloadSubject.onNext(descriptor); + } + } + }); + return notificationSlider; + } + public JPanel getCaptureSizePanel(AdrCaptureDescriptor descriptor) { JPanel root = this.componentsFactory.getJPanel(new GridLayout(1, 4, 4, 0)); root.setBackground(AppThemeColor.SLIDE_BG); diff --git a/app-ui/src/main/java/com/mercury/platform/ui/adr/components/panel/AdrDurationCellPanel.java b/app-ui/src/main/java/com/mercury/platform/ui/adr/components/panel/AdrDurationCellPanel.java index 4653c5ee..bbd09e25 100644 --- a/app-ui/src/main/java/com/mercury/platform/ui/adr/components/panel/AdrDurationCellPanel.java +++ b/app-ui/src/main/java/com/mercury/platform/ui/adr/components/panel/AdrDurationCellPanel.java @@ -1,5 +1,7 @@ package com.mercury.platform.ui.adr.components.panel; +import com.mercury.platform.core.ProdStarter; +import com.mercury.platform.shared.FrameVisibleState; import com.mercury.platform.shared.config.descriptor.adr.AdrDurationComponentDescriptor; import com.mercury.platform.shared.config.descriptor.adr.AdrTrackerGroupType; import com.mercury.platform.ui.adr.components.panel.ui.MercuryTracker; @@ -54,16 +56,18 @@ public void onUnSelect() { @Override protected void onHotKeyPressed() { - this.tracker.setStringPainted(descriptor.isTextEnable()); - this.tracker.setMaskPainted(descriptor.isMaskEnable()); - if (this.descriptor.isHotKeyRefresh()) { - this.tracker.abort(); - } - this.tracker.play(); - if (this.getParent() instanceof AdrTrackerGroupPanel) { - AdrTrackerGroupPanel parent = (AdrTrackerGroupPanel) this.getParent(); - if (parent.getDescriptor().getGroupType().equals(AdrTrackerGroupType.DYNAMIC)) { - parent.setComponentZOrder(this, parent.getComponentCount() - 1); + if (ProdStarter.APP_STATUS.equals(FrameVisibleState.SHOW)) { + this.tracker.setStringPainted(descriptor.isTextEnable()); + this.tracker.setMaskPainted(descriptor.isMaskEnable()); + if (this.descriptor.isHotKeyRefresh()) { + this.tracker.abort(); + } + this.tracker.play(); + if (this.getParent() instanceof AdrTrackerGroupPanel) { + AdrTrackerGroupPanel parent = (AdrTrackerGroupPanel) this.getParent(); + if (parent.getDescriptor().getGroupType().equals(AdrTrackerGroupType.DYNAMIC)) { + parent.setComponentZOrder(this, parent.getComponentCount() - 1); + } } } } diff --git a/app-ui/src/main/java/com/mercury/platform/ui/adr/components/panel/page/AdrIconPagePanel.java b/app-ui/src/main/java/com/mercury/platform/ui/adr/components/panel/page/AdrIconPagePanel.java index d8aa26ec..77bc7e50 100644 --- a/app-ui/src/main/java/com/mercury/platform/ui/adr/components/panel/page/AdrIconPagePanel.java +++ b/app-ui/src/main/java/com/mercury/platform/ui/adr/components/panel/page/AdrIconPagePanel.java @@ -33,6 +33,8 @@ protected void init() { JLabel fontSizeLabel = this.componentsFactory.getTextLabel("Font size:"); JLabel invertTimerLabel = this.componentsFactory.getTextLabel("Invert timer:"); JLabel durationLabel = this.componentsFactory.getTextLabel("Duration:"); + JLabel soundLabel = this.componentsFactory.getTextLabel("Sound alert:"); + JLabel soundVolumeLabel = this.componentsFactory.getTextLabel("Sound volume"); JLabel delayLabel = this.componentsFactory.getTextLabel("Delay:"); JLabel backgroundColorLabel = this.componentsFactory.getTextLabel("Background color:"); JLabel textColorLabel = this.componentsFactory.getTextLabel("Text color:"); @@ -50,6 +52,8 @@ protected void init() { JTextField fontSizeField = this.adrComponentsFactory.getFontSizeField(this.payload); JPanel textOutlinePanel = this.adrComponentsFactory.getTextOutlinePanel(this.payload); JTextField durationField = this.adrComponentsFactory.getDurationField(this.payload); + JPanel soundPanel = this.adrComponentsFactory.getSoundPanel(this.payload); + JSlider soundVolumeSlider = this.adrComponentsFactory.getVolumeSlider(this.payload); JTextField delayField = this.adrComponentsFactory.getDelayField(this.payload); JComboBox textFormatBox = this.adrComponentsFactory.getTextFormatBox(this.payload); JPanel backgroundColorPanel = this.adrComponentsFactory.getBackgroundColorPanel(this.payload); @@ -93,6 +97,10 @@ protected void init() { } specPanel.add(alwaysVisibleLabel); specPanel.add(alwaysVisibleBox); + specPanel.add(soundLabel); + specPanel.add(soundPanel); + specPanel.add(soundVolumeLabel); + specPanel.add(soundVolumeSlider); specPanel.add(delayLabel); specPanel.add(delayField); specPanel.add(fontSizeLabel); diff --git a/app-ui/src/main/java/com/mercury/platform/ui/adr/components/panel/page/AdrProgressBarPagePanel.java b/app-ui/src/main/java/com/mercury/platform/ui/adr/components/panel/page/AdrProgressBarPagePanel.java index ce9c88f2..ad689e77 100644 --- a/app-ui/src/main/java/com/mercury/platform/ui/adr/components/panel/page/AdrProgressBarPagePanel.java +++ b/app-ui/src/main/java/com/mercury/platform/ui/adr/components/panel/page/AdrProgressBarPagePanel.java @@ -33,6 +33,8 @@ protected void init() { JLabel textOutlineLabel = this.componentsFactory.getTextLabel("Text outline:"); JLabel fontSizeLabel = this.componentsFactory.getTextLabel("Font size:"); JLabel durationLabel = this.componentsFactory.getTextLabel("Duration:"); + JLabel soundLabel = this.componentsFactory.getTextLabel("Sound alert:"); + JLabel soundVolumeLabel = this.componentsFactory.getTextLabel("Sound volume"); JLabel delayLabel = this.componentsFactory.getTextLabel("Delay:"); JLabel invertTimerLabel = this.componentsFactory.getTextLabel("Invert timer:"); JLabel textColorLabel = this.componentsFactory.getTextLabel("Text color:"); @@ -48,6 +50,8 @@ protected void init() { JPanel locationPanel = this.adrComponentsFactory.getLocationPanel(this.payload, this.fromGroup); JPanel hotKeyPanel = this.adrComponentsFactory.getHotKeyPanel(this.payload); JPanel iconPanel = this.adrComponentsFactory.getIconPanel(this.payload); + JPanel soundPanel = this.adrComponentsFactory.getSoundPanel(this.payload); + JSlider soundVolumeSlider = this.adrComponentsFactory.getVolumeSlider(this.payload); JPanel insetsPanel = this.adrComponentsFactory.getInsetsPanel(this.payload); JComboBox iconAlignment = this.adrComponentsFactory.getIconAlignment(this.payload); JTextField fontSizeField = this.adrComponentsFactory.getFontSizeField(this.payload); @@ -91,6 +95,10 @@ protected void init() { specPanel.add(opacityLabel); specPanel.add(opacitySlider); } + specPanel.add(soundLabel); + specPanel.add(soundPanel); + specPanel.add(soundVolumeLabel); + specPanel.add(soundVolumeSlider); specPanel.add(delayLabel); specPanel.add(delayField); specPanel.add(pbOrientationLabel); diff --git a/app-ui/src/main/java/com/mercury/platform/ui/adr/components/panel/ui/MercuryTracker.java b/app-ui/src/main/java/com/mercury/platform/ui/adr/components/panel/ui/MercuryTracker.java index 29161e4e..aecf7f6a 100644 --- a/app-ui/src/main/java/com/mercury/platform/ui/adr/components/panel/ui/MercuryTracker.java +++ b/app-ui/src/main/java/com/mercury/platform/ui/adr/components/panel/ui/MercuryTracker.java @@ -3,6 +3,7 @@ import com.mercury.platform.shared.config.descriptor.adr.AdrDurationComponentDescriptor; import com.mercury.platform.shared.config.descriptor.adr.AdrIconDescriptor; import com.mercury.platform.shared.config.descriptor.adr.AdrProgressBarDescriptor; +import com.mercury.platform.shared.store.MercuryStoreCore; import com.mercury.platform.ui.adr.components.panel.ui.impl.ProgressBarUI; import com.mercury.platform.ui.adr.components.panel.ui.impl.SquareIconTrackerUI; import com.mercury.platform.ui.components.ComponentsFactory; @@ -10,8 +11,10 @@ import com.mercury.platform.ui.misc.AppThemeColor; import lombok.Getter; import lombok.Setter; +import org.apache.commons.lang3.Range; import org.pushingpixels.trident.Timeline; import org.pushingpixels.trident.callback.TimelineCallback; +import org.pushingpixels.trident.callback.TimelineCallbackAdapter; import javax.swing.*; @@ -40,6 +43,8 @@ public class MercuryTracker extends JComponent { private Timeline progressTl; + private boolean soundPlayed; + public MercuryTracker(AdrDurationComponentDescriptor descriptor) { this.descriptor = descriptor; this.setMaximum((int) (this.descriptor.getDuration() * 1000)); @@ -51,12 +56,41 @@ public MercuryTracker(AdrDurationComponentDescriptor descriptor) { this.progressTl.setInitialDelay((long) (descriptor.getDelay() * 1000)); this.progressTl.setDuration((int) (descriptor.getDuration() * 1000)); if (this.descriptor.isInvertTimer()) { - this.setValue((int) (this.descriptor.getDuration() * 1000)); this.progressTl.addPropertyToInterpolate("value", 0, this.getMaximum()); + this.value = 0; } else { - this.setValue(0); this.progressTl.addPropertyToInterpolate("value", this.getMaximum(), 0); + this.value = this.maximum; } + + this.progressTl.addCallback(new TimelineCallbackAdapter() { + @Override + public void onTimelineStateChanged(Timeline.TimelineState oldState, Timeline.TimelineState newState, float durationFraction, float timelinePosition) { + if (newState.equals(Timeline.TimelineState.IDLE)) { + if (descriptor.isInvertTimer()) { + value = 0; + } else { + value = maximum; + } + } + } + + @Override + public void onTimelinePulse(float durationFraction, float timelinePosition) { + if (!descriptor.getSoundDescriptor().getWavPath().equals("...") && !soundPlayed) { + if (valueInSoundRange() && !showCase) { + soundPlayed = true; + MercuryStoreCore.soundDescriptorSubject.onNext(descriptor.getSoundDescriptor()); + } + } + } + }); + } + + private boolean valueInSoundRange() { + float value = getValue() / 1000f; + float threshold = this.descriptor.getSoundThreshold().floatValue(); + return Range.between(threshold - 0.1, threshold + 0.1).contains((double) value); } private void initUI() { @@ -104,6 +138,7 @@ public void playLoop() { } public void play() { + this.soundPlayed = false; this.progressTl.play(); } diff --git a/app-ui/src/main/java/com/mercury/platform/ui/components/panel/notification/TradeOutNotificationPanel.java b/app-ui/src/main/java/com/mercury/platform/ui/components/panel/notification/TradeOutNotificationPanel.java index 5aaeab7e..7f741fd4 100644 --- a/app-ui/src/main/java/com/mercury/platform/ui/components/panel/notification/TradeOutNotificationPanel.java +++ b/app-ui/src/main/java/com/mercury/platform/ui/components/panel/notification/TradeOutNotificationPanel.java @@ -80,8 +80,8 @@ public void subscribe() { if (this.data.getWhisperNickname().equals(message.getNickName())) { if (this.notificationConfig.get() .getAutoCloseTriggers().stream() - .anyMatch(it -> StringUtils.normalizeSpace(it.toLowerCase()) - .equals(StringUtils.normalizeSpace(message.getMessage().toLowerCase())))) { + .anyMatch(it -> message.getMessage().toLowerCase() + .contains(StringUtils.normalizeSpace(it.toLowerCase())))) { this.controller.performHide(); } } diff --git a/app-ui/src/main/java/com/mercury/platform/ui/components/panel/settings/page/NotificationSettingsPagePanel.java b/app-ui/src/main/java/com/mercury/platform/ui/components/panel/settings/page/NotificationSettingsPagePanel.java index c356d2e3..1770d9d6 100644 --- a/app-ui/src/main/java/com/mercury/platform/ui/components/panel/settings/page/NotificationSettingsPagePanel.java +++ b/app-ui/src/main/java/com/mercury/platform/ui/components/panel/settings/page/NotificationSettingsPagePanel.java @@ -44,6 +44,8 @@ public void onViewInit() { this.outHotkeyGroup = new HotKeyGroup(); this.scannerHotkeyGroup = new HotKeyGroup(); + JPanel whisperHelperPanel = this.adrComponentsFactory.getCounterPanel(this.getWhisperHelperPanel(), "Whisper helper:", AppThemeColor.ADR_BG, false); + whisperHelperPanel.setBorder(BorderFactory.createLineBorder(AppThemeColor.ADR_PANEL_BORDER)); JPanel inPanel = this.adrComponentsFactory.getCounterPanel(this.getIncomingPanel(), "Incoming notification:", AppThemeColor.ADR_BG, false); inPanel.setBorder(BorderFactory.createLineBorder(AppThemeColor.ADR_PANEL_BORDER)); JPanel outPanel = this.adrComponentsFactory.getCounterPanel(this.getOutgoingPanel(), "Outgoing notification:", AppThemeColor.ADR_BG, false); @@ -51,6 +53,7 @@ public void onViewInit() { JPanel scannerPanel = this.adrComponentsFactory.getCounterPanel(this.getChatScannerPanel(), "Chat scanner notification:", AppThemeColor.ADR_BG, false); scannerPanel.setBorder(BorderFactory.createLineBorder(AppThemeColor.ADR_PANEL_BORDER)); this.container.add(this.componentsFactory.wrapToSlide(this.getGeneralPanel(), 4, 4, 2, 4)); + this.container.add(this.componentsFactory.wrapToSlide(whisperHelperPanel, 2, 4, 2, 4)); this.container.add(this.componentsFactory.wrapToSlide(inPanel, 2, 4, 2, 4)); this.container.add(this.componentsFactory.wrapToSlide(outPanel, 2, 4, 2, 4)); this.container.add(this.componentsFactory.wrapToSlide(scannerPanel, 2, 4, 2, 4)); @@ -119,6 +122,16 @@ public void focusLost(FocusEvent e) { return root; } + private JPanel getWhisperHelperPanel() { + JPanel root = this.componentsFactory.getJPanel(new BorderLayout(), AppThemeColor.ADR_BG); + root.add(this.componentsFactory.getTextLabel("When you release CTRL key clipboard content will be transferred to chat.", FontStyle.REGULAR, 16), BorderLayout.PAGE_START); + JLabel img = new JLabel(); + img.setIcon(this.componentsFactory.getImage("app/whisper-helper.png")); + root.add(this.componentsFactory.wrapToSlide(img, AppThemeColor.ADR_BG, 4, 4, 4, 4), BorderLayout.CENTER); + root.add(this.componentsFactory.getTextLabel("Example: press CTRL => click on 'Whisper' button => release CTRL.", FontStyle.REGULAR, 16), BorderLayout.PAGE_END); + root.setVisible(false); + return root; + } private JPanel getIncomingPanel() { JPanel root = this.componentsFactory.getJPanel(new BorderLayout(), AppThemeColor.ADR_BG); JPanel propertiesPanel = this.componentsFactory.getJPanel(new GridLayout(0, 2, 4, 4), AppThemeColor.ADR_BG); diff --git a/app-ui/src/main/java/com/mercury/platform/ui/frame/titled/SettingsFrame.java b/app-ui/src/main/java/com/mercury/platform/ui/frame/titled/SettingsFrame.java index 7d1a913d..a1ddbb33 100644 --- a/app-ui/src/main/java/com/mercury/platform/ui/frame/titled/SettingsFrame.java +++ b/app-ui/src/main/java/com/mercury/platform/ui/frame/titled/SettingsFrame.java @@ -93,8 +93,7 @@ private JPanel getBottomPanel() { donateDescriptor.setBackgroundColor(AppThemeColor.FRAME); donateDescriptor.setForegroundColor(AppThemeColor.BUTTON); MercuryTracker tracker = new MercuryTracker(donateDescriptor); - float percent = 200 * (77 / 100f); - tracker.setValue((int) (percent * 100)); + tracker.setValue(87 * 1000); tracker.setPreferredSize(donateDescriptor.getSize()); root.add(this.componentsFactory.getTextLabel("Monthly donations:", FontStyle.BOLD, 16), BorderLayout.LINE_START); root.add(this.componentsFactory.wrapToSlide(tracker, AppThemeColor.ADR_FOOTER_BG, 2, 2, 2, 1), BorderLayout.CENTER);