Merge pull request #3761 from Adam-/master+clearchat
chat commands: alow clearing words and chat with ctrl w/backspace
This commit is contained in:
@@ -625,6 +625,14 @@ public interface Client extends GameEngine
|
||||
*/
|
||||
String getVar(VarClientStr varClientStr);
|
||||
|
||||
/**
|
||||
* Sets the given variable
|
||||
*
|
||||
* @param varClientStr
|
||||
* @param value
|
||||
*/
|
||||
void setVar(VarClientStr varClientStr, String value);
|
||||
|
||||
/**
|
||||
* Sets the value of a given variable.
|
||||
*
|
||||
|
||||
@@ -44,6 +44,7 @@ import net.runelite.client.chat.ChatMessageBuilder;
|
||||
import net.runelite.client.chat.ChatMessageManager;
|
||||
import net.runelite.client.config.ConfigManager;
|
||||
import net.runelite.client.game.ItemManager;
|
||||
import net.runelite.client.input.KeyManager;
|
||||
import net.runelite.client.plugins.Plugin;
|
||||
import net.runelite.client.plugins.PluginDescriptor;
|
||||
import net.runelite.client.util.StackFormatter;
|
||||
@@ -80,6 +81,24 @@ public class ChatCommandsPlugin extends Plugin
|
||||
@Inject
|
||||
private ScheduledExecutorService executor;
|
||||
|
||||
@Inject
|
||||
private KeyManager keyManager;
|
||||
|
||||
@Inject
|
||||
private ChatKeyboardListener chatKeyboardListener;
|
||||
|
||||
@Override
|
||||
public void startUp()
|
||||
{
|
||||
keyManager.registerKeyListener(chatKeyboardListener);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void shutDown()
|
||||
{
|
||||
keyManager.unregisterKeyListener(chatKeyboardListener);
|
||||
}
|
||||
|
||||
@Provides
|
||||
ChatCommandsConfig provideConfig(ConfigManager configManager)
|
||||
{
|
||||
|
||||
@@ -0,0 +1,96 @@
|
||||
/*
|
||||
* Copyright (c) 2018, Adam <Adam@sigterm.info>
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice, this
|
||||
* list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright notice,
|
||||
* this list of conditions and the following disclaimer in the documentation
|
||||
* and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
|
||||
* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
||||
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
package net.runelite.client.plugins.chatcommands;
|
||||
|
||||
import java.awt.event.KeyEvent;
|
||||
import javax.inject.Inject;
|
||||
import javax.inject.Singleton;
|
||||
import net.runelite.api.Client;
|
||||
import net.runelite.api.VarClientStr;
|
||||
import net.runelite.client.callback.ClientThread;
|
||||
import net.runelite.client.input.KeyListener;
|
||||
|
||||
@Singleton
|
||||
public class ChatKeyboardListener implements KeyListener
|
||||
{
|
||||
@Inject
|
||||
private Client client;
|
||||
|
||||
@Inject
|
||||
private ClientThread clientThread;
|
||||
|
||||
@Override
|
||||
public void keyTyped(KeyEvent e)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void keyPressed(KeyEvent e)
|
||||
{
|
||||
if (!e.isControlDown())
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
switch (e.getKeyCode())
|
||||
{
|
||||
case KeyEvent.VK_W:
|
||||
String input = client.getVar(VarClientStr.CHATBOX_TYPED_TEXT);
|
||||
if (input != null)
|
||||
{
|
||||
// remove trailing space
|
||||
while (input.endsWith(" "))
|
||||
{
|
||||
input = input.substring(0, input.length() - 1);
|
||||
}
|
||||
|
||||
// find next word
|
||||
int idx = input.lastIndexOf(' ');
|
||||
final String replacement;
|
||||
if (idx != -1)
|
||||
{
|
||||
replacement = input.substring(0, idx);
|
||||
}
|
||||
else
|
||||
{
|
||||
replacement = "";
|
||||
}
|
||||
|
||||
clientThread.invokeLater(() -> client.setVar(VarClientStr.CHATBOX_TYPED_TEXT, replacement));
|
||||
}
|
||||
break;
|
||||
case KeyEvent.VK_BACK_SPACE:
|
||||
clientThread.invokeLater(() -> client.setVar(VarClientStr.CHATBOX_TYPED_TEXT, ""));
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void keyReleased(KeyEvent e)
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
@@ -126,6 +126,14 @@ public abstract class VarbitMixin implements RSClient
|
||||
return getStrVarcs()[varClientStr.getIndex()];
|
||||
}
|
||||
|
||||
@Inject
|
||||
@Override
|
||||
public void setVar(VarClientStr varClientStr, String value)
|
||||
{
|
||||
String[] vars = getStrVarcs();
|
||||
vars[varClientStr.getIndex()] = value;
|
||||
}
|
||||
|
||||
@Inject
|
||||
@Override
|
||||
public int[] getIntVarcs()
|
||||
|
||||
Reference in New Issue
Block a user