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;
|
||||
}
|
||||
|
||||
@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(
|
||||
keyName = "publicTargetLanguage",
|
||||
name = "Target Language",
|
||||
description = "Language to translate messages too.",
|
||||
position = 1,
|
||||
position = 2,
|
||||
group = "Public Chat Translation",
|
||||
hidden = true
|
||||
// unhide = "publicChat"
|
||||
@@ -39,7 +53,7 @@ public interface ChatTranslationConfig extends Config
|
||||
keyName = "playerChat",
|
||||
name = "Translate outgoing Messages",
|
||||
description = "Would you like to Translate your Messages?",
|
||||
position = 2,
|
||||
position = 3,
|
||||
group = "Player Message Translation"
|
||||
)
|
||||
default boolean playerChat()
|
||||
@@ -51,7 +65,7 @@ public interface ChatTranslationConfig extends Config
|
||||
keyName = "playerTargetLanguage",
|
||||
name = "Target Language",
|
||||
description = "Language to translate messages too.",
|
||||
position = 3,
|
||||
position = 4,
|
||||
group = "Player Message Translation",
|
||||
hidden = true,
|
||||
unhide = "playerChat"
|
||||
|
||||
@@ -34,7 +34,7 @@ import java.awt.event.KeyEvent;
|
||||
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");
|
||||
|
||||
@Inject
|
||||
@@ -66,7 +66,10 @@ public class ChatTranslationPlugin extends Plugin implements KeyListener
|
||||
{
|
||||
if (client != null)
|
||||
{
|
||||
menuManager.get().addPlayerMenuItem(TRANSLATE);
|
||||
if (config.translateOptionVisable())
|
||||
{
|
||||
menuManager.get().addPlayerMenuItem(TRANSLATE);
|
||||
}
|
||||
}
|
||||
keyManager.registerKeyListener(this);
|
||||
}
|
||||
@@ -76,7 +79,10 @@ public class ChatTranslationPlugin extends Plugin implements KeyListener
|
||||
{
|
||||
if (client != null)
|
||||
{
|
||||
menuManager.get().removePlayerMenuItem(TRANSLATE);
|
||||
if (config.translateOptionVisable())
|
||||
{
|
||||
menuManager.get().removePlayerMenuItem(TRANSLATE);
|
||||
}
|
||||
}
|
||||
keyManager.unregisterKeyListener(this);
|
||||
}
|
||||
@@ -93,6 +99,11 @@ public class ChatTranslationPlugin extends Plugin implements KeyListener
|
||||
@Subscribe
|
||||
public void onMenuEntryAdded(MenuEntryAdded event)
|
||||
{
|
||||
if (!config.translateOptionVisable())
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
int groupId = WidgetInfo.TO_GROUP(event.getActionParam1());
|
||||
String option = event.getOption();
|
||||
|
||||
@@ -180,42 +191,33 @@ public class ChatTranslationPlugin extends Plugin implements KeyListener
|
||||
|
||||
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();
|
||||
|
||||
Translator translator = new Translator();
|
||||
|
||||
String message = client.getVar(VarClientStr.CHATBOX_TYPED_TEXT);
|
||||
|
||||
try
|
||||
//Automatically check language of message and translate to selected language.
|
||||
String translation = translator.translate("auto", config.playerTargetLanguage().toString(), message);
|
||||
if (translation != null)
|
||||
{
|
||||
//Automatically check language of message and translate to selected language.
|
||||
String translation = translator.translate("auto", config.playerTargetLanguage().toString(), message);
|
||||
client.setVar(VarClientStr.CHATBOX_TYPED_TEXT, translation);
|
||||
|
||||
if (translation != null)
|
||||
clientThread.invoke(() ->
|
||||
{
|
||||
client.setVar(VarClientStr.CHATBOX_TYPED_TEXT, translation);
|
||||
|
||||
clientThread.invoke(() ->
|
||||
{
|
||||
client.runScript(96, 0, translation);
|
||||
}
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
client.setVar(VarClientStr.CHATBOX_TYPED_TEXT, "");
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
e.printStackTrace();
|
||||
client.runScript(96, 0, translation);
|
||||
});
|
||||
}
|
||||
client.setVar(VarClientStr.CHATBOX_TYPED_TEXT, "");
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
return;
|
||||
catch (Exception e)
|
||||
{
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user