Added config options for adding the 'Translate' right-click menu option in the Chatbox.
(More so to hide it while the Public Chat Translate part of the plugin is disabled/hidden.)
This commit is contained in:
committed by
Ian W. ONeill
parent
08134881e8
commit
c41709de1f
@@ -21,11 +21,25 @@ public interface ChatTranslationConfig extends Config
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ConfigItem(
|
||||||
|
keyName = "translateOptionVisable",
|
||||||
|
name = "Show 'Translate' menu option",
|
||||||
|
description = "Adds 'Translate' to the right-click menu in the Chatbox.",
|
||||||
|
position = 1,
|
||||||
|
group = "Public Chat Translation",
|
||||||
|
hidden = true
|
||||||
|
// unhide = "publicChat"
|
||||||
|
)
|
||||||
|
default boolean translateOptionVisable()
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
@ConfigItem(
|
@ConfigItem(
|
||||||
keyName = "publicTargetLanguage",
|
keyName = "publicTargetLanguage",
|
||||||
name = "Target Language",
|
name = "Target Language",
|
||||||
description = "Language to translate messages too.",
|
description = "Language to translate messages too.",
|
||||||
position = 1,
|
position = 2,
|
||||||
group = "Public Chat Translation",
|
group = "Public Chat Translation",
|
||||||
hidden = true
|
hidden = true
|
||||||
// unhide = "publicChat"
|
// unhide = "publicChat"
|
||||||
@@ -39,7 +53,7 @@ public interface ChatTranslationConfig extends Config
|
|||||||
keyName = "playerChat",
|
keyName = "playerChat",
|
||||||
name = "Translate outgoing Messages",
|
name = "Translate outgoing Messages",
|
||||||
description = "Would you like to Translate your Messages?",
|
description = "Would you like to Translate your Messages?",
|
||||||
position = 2,
|
position = 3,
|
||||||
group = "Player Message Translation"
|
group = "Player Message Translation"
|
||||||
)
|
)
|
||||||
default boolean playerChat()
|
default boolean playerChat()
|
||||||
@@ -51,7 +65,7 @@ public interface ChatTranslationConfig extends Config
|
|||||||
keyName = "playerTargetLanguage",
|
keyName = "playerTargetLanguage",
|
||||||
name = "Target Language",
|
name = "Target Language",
|
||||||
description = "Language to translate messages too.",
|
description = "Language to translate messages too.",
|
||||||
position = 3,
|
position = 4,
|
||||||
group = "Player Message Translation",
|
group = "Player Message Translation",
|
||||||
hidden = true,
|
hidden = true,
|
||||||
unhide = "playerChat"
|
unhide = "playerChat"
|
||||||
|
|||||||
@@ -34,7 +34,7 @@ import java.awt.event.KeyEvent;
|
|||||||
public class ChatTranslationPlugin extends Plugin implements KeyListener
|
public class ChatTranslationPlugin extends Plugin implements KeyListener
|
||||||
{
|
{
|
||||||
|
|
||||||
public static final String TRANSLATE = "Translate";
|
private static final String TRANSLATE = "Translate";
|
||||||
private static final ImmutableList<String> AFTER_OPTIONS = ImmutableList.of("Message", "Add ignore", "Remove friend", "Kick");
|
private static final ImmutableList<String> AFTER_OPTIONS = ImmutableList.of("Message", "Add ignore", "Remove friend", "Kick");
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
@@ -66,7 +66,10 @@ public class ChatTranslationPlugin extends Plugin implements KeyListener
|
|||||||
{
|
{
|
||||||
if (client != null)
|
if (client != null)
|
||||||
{
|
{
|
||||||
menuManager.get().addPlayerMenuItem(TRANSLATE);
|
if (config.translateOptionVisable())
|
||||||
|
{
|
||||||
|
menuManager.get().addPlayerMenuItem(TRANSLATE);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
keyManager.registerKeyListener(this);
|
keyManager.registerKeyListener(this);
|
||||||
}
|
}
|
||||||
@@ -76,7 +79,10 @@ public class ChatTranslationPlugin extends Plugin implements KeyListener
|
|||||||
{
|
{
|
||||||
if (client != null)
|
if (client != null)
|
||||||
{
|
{
|
||||||
menuManager.get().removePlayerMenuItem(TRANSLATE);
|
if (config.translateOptionVisable())
|
||||||
|
{
|
||||||
|
menuManager.get().removePlayerMenuItem(TRANSLATE);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
keyManager.unregisterKeyListener(this);
|
keyManager.unregisterKeyListener(this);
|
||||||
}
|
}
|
||||||
@@ -93,6 +99,11 @@ public class ChatTranslationPlugin extends Plugin implements KeyListener
|
|||||||
@Subscribe
|
@Subscribe
|
||||||
public void onMenuEntryAdded(MenuEntryAdded event)
|
public void onMenuEntryAdded(MenuEntryAdded event)
|
||||||
{
|
{
|
||||||
|
if (!config.translateOptionVisable())
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
int groupId = WidgetInfo.TO_GROUP(event.getActionParam1());
|
int groupId = WidgetInfo.TO_GROUP(event.getActionParam1());
|
||||||
String option = event.getOption();
|
String option = event.getOption();
|
||||||
|
|
||||||
@@ -180,42 +191,33 @@ public class ChatTranslationPlugin extends Plugin implements KeyListener
|
|||||||
|
|
||||||
if (chatboxParent != null && chatboxParent.getOnKeyListener() != null)
|
if (chatboxParent != null && chatboxParent.getOnKeyListener() != null)
|
||||||
{
|
{
|
||||||
if (event.getKeyCode() == 0xA)
|
if (event.getKeyCode() == 0xA)
|
||||||
|
{
|
||||||
|
event.consume();
|
||||||
|
|
||||||
|
Translator translator = new Translator();
|
||||||
|
String message = client.getVar(VarClientStr.CHATBOX_TYPED_TEXT);
|
||||||
|
|
||||||
|
try
|
||||||
{
|
{
|
||||||
event.consume();
|
//Automatically check language of message and translate to selected language.
|
||||||
|
String translation = translator.translate("auto", config.playerTargetLanguage().toString(), message);
|
||||||
Translator translator = new Translator();
|
if (translation != null)
|
||||||
|
|
||||||
String message = client.getVar(VarClientStr.CHATBOX_TYPED_TEXT);
|
|
||||||
|
|
||||||
try
|
|
||||||
{
|
{
|
||||||
//Automatically check language of message and translate to selected language.
|
client.setVar(VarClientStr.CHATBOX_TYPED_TEXT, translation);
|
||||||
String translation = translator.translate("auto", config.playerTargetLanguage().toString(), message);
|
|
||||||
|
|
||||||
if (translation != null)
|
clientThread.invoke(() ->
|
||||||
{
|
{
|
||||||
client.setVar(VarClientStr.CHATBOX_TYPED_TEXT, translation);
|
client.runScript(96, 0, translation);
|
||||||
|
});
|
||||||
clientThread.invoke(() ->
|
|
||||||
{
|
|
||||||
client.runScript(96, 0, translation);
|
|
||||||
}
|
|
||||||
);
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
client.setVar(VarClientStr.CHATBOX_TYPED_TEXT, "");
|
|
||||||
}
|
|
||||||
catch (Exception e)
|
|
||||||
{
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
}
|
||||||
|
client.setVar(VarClientStr.CHATBOX_TYPED_TEXT, "");
|
||||||
}
|
}
|
||||||
}
|
catch (Exception e)
|
||||||
else
|
{
|
||||||
{
|
e.printStackTrace();
|
||||||
return;
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user