Skip to content

Commit

Permalink
Whisper helper, overseer sound
Browse files Browse the repository at this point in the history
  • Loading branch information
Exslims committed Sep 3, 2017
1 parent 997e934 commit c3883bf
Show file tree
Hide file tree
Showing 16 changed files with 210 additions and 31 deletions.
39 changes: 38 additions & 1 deletion app-core/src/main/java/com/mercury/platform/core/ChatHelper.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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);

Expand All @@ -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);
Expand Down Expand Up @@ -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()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,6 @@
@AllArgsConstructor
@NoArgsConstructor
public class SoundDescriptor implements Serializable {
private String wavPath;
private Float db;
private String wavPath = "...";
private Float db = 0f;
}
Original file line number Diff line number Diff line change
@@ -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;

Expand Down Expand Up @@ -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;
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ public HotKeysInterceptor() {
} catch (NativeHookException e) {
e.printStackTrace();
}

GlobalScreen.addNativeKeyListener(new MercuryNativeKeyListener());
GlobalScreen.addNativeMouseListener(new MercuryNativeMouseListener());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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: {
Expand All @@ -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
Expand All @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@ public class MercuryStoreCore {
public static final PublishSubject<Boolean> blockHotkeySubject = PublishSubject.create();
public static final PublishSubject<MercuryError> errorHandlerSubject = PublishSubject.create();
public static final PublishSubject<AdrVisibleState> adrVisibleSubject = PublishSubject.create();
public static final PublishSubject<Boolean> tradeWhisperSubject = PublishSubject.create();
public static final PublishSubject<SoundDescriptor> soundDescriptorSubject = PublishSubject.create();

public static final PublishSubject<NotificationDescriptor> newNotificationSubject = PublishSubject.create();
public static final PublishSubject<NotificationDescriptor> removeNotificationSubject = PublishSubject.create();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -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);
}
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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:");
Expand All @@ -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);
Expand Down Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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:");
Expand All @@ -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);
Expand Down Expand Up @@ -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);
Expand Down
Loading

0 comments on commit c3883bf

Please sign in to comment.