runelite-client: add wasd camera plugin
This commit is contained in:
@@ -0,0 +1,79 @@
|
||||
/*
|
||||
* 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.wasdcamera;
|
||||
|
||||
import java.awt.event.KeyEvent;
|
||||
import net.runelite.client.config.Config;
|
||||
import net.runelite.client.config.ConfigGroup;
|
||||
import net.runelite.client.config.ConfigItem;
|
||||
import net.runelite.client.config.Keybind;
|
||||
|
||||
@ConfigGroup("wasdcamera")
|
||||
public interface WASDCameraConfig extends Config
|
||||
{
|
||||
@ConfigItem(
|
||||
position = 1,
|
||||
keyName = "up",
|
||||
name = "Up key",
|
||||
description = "The key which will replace up."
|
||||
)
|
||||
default Keybind up()
|
||||
{
|
||||
return new Keybind(KeyEvent.VK_W, 0);
|
||||
}
|
||||
|
||||
@ConfigItem(
|
||||
position = 2,
|
||||
keyName = "down",
|
||||
name = "Down key",
|
||||
description = "The key which will replace down."
|
||||
)
|
||||
default Keybind down()
|
||||
{
|
||||
return new Keybind(KeyEvent.VK_S, 0);
|
||||
}
|
||||
|
||||
@ConfigItem(
|
||||
position = 3,
|
||||
keyName = "left",
|
||||
name = "Left key",
|
||||
description = "The key which will replace left."
|
||||
)
|
||||
default Keybind left()
|
||||
{
|
||||
return new Keybind(KeyEvent.VK_A, 0);
|
||||
}
|
||||
|
||||
@ConfigItem(
|
||||
position = 4,
|
||||
keyName = "right",
|
||||
name = "Right key",
|
||||
description = "The key which will replace right."
|
||||
)
|
||||
default Keybind right()
|
||||
{
|
||||
return new Keybind(KeyEvent.VK_D, 0);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,198 @@
|
||||
/*
|
||||
* Copyright (c) 2018, Adam <Adam@sigterm.info>
|
||||
* Copyright (c) 2018, Abexlry <abexlry@gmail.com>
|
||||
* 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.wasdcamera;
|
||||
|
||||
import java.awt.event.KeyEvent;
|
||||
import javax.inject.Inject;
|
||||
import net.runelite.api.Client;
|
||||
import net.runelite.api.VarClientStr;
|
||||
import net.runelite.client.callback.ClientThread;
|
||||
import net.runelite.client.input.KeyListener;
|
||||
import net.runelite.client.input.MouseListener;
|
||||
|
||||
class WASDCameraListener extends MouseListener implements KeyListener
|
||||
{
|
||||
@Inject
|
||||
private WASDCameraPlugin plugin;
|
||||
|
||||
@Inject
|
||||
private WASDCameraConfig config;
|
||||
|
||||
@Inject
|
||||
private Client client;
|
||||
|
||||
@Inject
|
||||
private ClientThread clientThread;
|
||||
|
||||
@Override
|
||||
public void keyTyped(KeyEvent e)
|
||||
{
|
||||
handleKey(e);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void keyPressed(KeyEvent e)
|
||||
{
|
||||
if (!plugin.chatboxFocused())
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (!plugin.isTyping())
|
||||
{
|
||||
if (config.up().matches(e))
|
||||
{
|
||||
e.setKeyCode(KeyEvent.VK_UP);
|
||||
}
|
||||
else if (config.down().matches(e))
|
||||
{
|
||||
e.setKeyCode(KeyEvent.VK_DOWN);
|
||||
}
|
||||
else if (config.left().matches(e))
|
||||
{
|
||||
e.setKeyCode(KeyEvent.VK_LEFT);
|
||||
}
|
||||
else if (config.right().matches(e))
|
||||
{
|
||||
e.setKeyCode(KeyEvent.VK_RIGHT);
|
||||
}
|
||||
else
|
||||
{
|
||||
switch (e.getKeyCode())
|
||||
{
|
||||
case KeyEvent.VK_ENTER:
|
||||
case KeyEvent.VK_SLASH:
|
||||
// refocus chatbox
|
||||
clientThread.invoke(() ->
|
||||
{
|
||||
plugin.unlockChat();
|
||||
});
|
||||
break;
|
||||
case KeyEvent.VK_F1:
|
||||
case KeyEvent.VK_F2:
|
||||
case KeyEvent.VK_F3:
|
||||
case KeyEvent.VK_F4:
|
||||
case KeyEvent.VK_F5:
|
||||
case KeyEvent.VK_F6:
|
||||
case KeyEvent.VK_F7:
|
||||
case KeyEvent.VK_F8:
|
||||
case KeyEvent.VK_F9:
|
||||
case KeyEvent.VK_F10:
|
||||
case KeyEvent.VK_F11:
|
||||
case KeyEvent.VK_F12:
|
||||
case KeyEvent.VK_UP:
|
||||
case KeyEvent.VK_DOWN:
|
||||
case KeyEvent.VK_LEFT:
|
||||
case KeyEvent.VK_RIGHT:
|
||||
break;
|
||||
default:
|
||||
e.consume();
|
||||
break;
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
switch (e.getKeyCode())
|
||||
{
|
||||
case KeyEvent.VK_ENTER:
|
||||
clientThread.invoke(() ->
|
||||
{
|
||||
plugin.lockChat();
|
||||
});
|
||||
break;
|
||||
case KeyEvent.VK_ESCAPE:
|
||||
clientThread.invoke(() ->
|
||||
{
|
||||
client.setVar(VarClientStr.CHATBOX_TYPED_TEXT, "");
|
||||
plugin.lockChat();
|
||||
});
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void keyReleased(KeyEvent e)
|
||||
{
|
||||
handleKey(e);
|
||||
}
|
||||
|
||||
private void handleKey(KeyEvent e)
|
||||
{
|
||||
if (!plugin.chatboxFocused())
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (!plugin.isTyping())
|
||||
{
|
||||
if (config.up().matches(e))
|
||||
{
|
||||
e.setKeyCode(KeyEvent.VK_UP);
|
||||
}
|
||||
else if (config.down().matches(e))
|
||||
{
|
||||
e.setKeyCode(KeyEvent.VK_DOWN);
|
||||
}
|
||||
else if (config.left().matches(e))
|
||||
{
|
||||
e.setKeyCode(KeyEvent.VK_LEFT);
|
||||
}
|
||||
else if (config.right().matches(e))
|
||||
{
|
||||
e.setKeyCode(KeyEvent.VK_RIGHT);
|
||||
}
|
||||
else
|
||||
{
|
||||
switch (e.getKeyCode())
|
||||
{
|
||||
case KeyEvent.VK_F1:
|
||||
case KeyEvent.VK_F2:
|
||||
case KeyEvent.VK_F3:
|
||||
case KeyEvent.VK_F4:
|
||||
case KeyEvent.VK_F5:
|
||||
case KeyEvent.VK_F6:
|
||||
case KeyEvent.VK_F7:
|
||||
case KeyEvent.VK_F8:
|
||||
case KeyEvent.VK_F9:
|
||||
case KeyEvent.VK_F10:
|
||||
case KeyEvent.VK_F11:
|
||||
case KeyEvent.VK_F12:
|
||||
case KeyEvent.VK_UP:
|
||||
case KeyEvent.VK_DOWN:
|
||||
case KeyEvent.VK_LEFT:
|
||||
case KeyEvent.VK_RIGHT:
|
||||
break;
|
||||
default:
|
||||
e.consume();
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,159 @@
|
||||
/*'
|
||||
* Copyright (c) 2018, Adam <Adam@sigterm.info>
|
||||
* Copyright (c) 2018, Abexlry <abexlry@gmail.com>
|
||||
* 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.wasdcamera;
|
||||
|
||||
import com.google.common.eventbus.Subscribe;
|
||||
import com.google.inject.Provides;
|
||||
import javax.inject.Inject;
|
||||
import lombok.AccessLevel;
|
||||
import lombok.Getter;
|
||||
import net.runelite.api.Client;
|
||||
import net.runelite.api.GameState;
|
||||
import net.runelite.api.events.ScriptCallbackEvent;
|
||||
import net.runelite.api.widgets.Widget;
|
||||
import net.runelite.api.widgets.WidgetInfo;
|
||||
import net.runelite.client.callback.ClientThread;
|
||||
import net.runelite.client.config.ConfigManager;
|
||||
import net.runelite.client.input.KeyManager;
|
||||
import net.runelite.client.plugins.Plugin;
|
||||
import net.runelite.client.plugins.PluginDescriptor;
|
||||
|
||||
@PluginDescriptor(
|
||||
name = "WASD Camera",
|
||||
description = "Allows use of WASD keys for camera movement with 'Press Enter to Chat'",
|
||||
tags = {"enter", "chat"},
|
||||
enabledByDefault = false
|
||||
)
|
||||
public class WASDCameraPlugin extends Plugin
|
||||
{
|
||||
private static final String PRESS_ENTER_TO_CHAT = "Press Enter to Chat...";
|
||||
private static final String SCRIPT_EVENT_SET_CHATBOX_INPUT = "setChatboxInput";
|
||||
|
||||
@Inject
|
||||
private Client client;
|
||||
|
||||
@Inject
|
||||
private ClientThread clientThread;
|
||||
|
||||
@Inject
|
||||
private KeyManager keyManager;
|
||||
|
||||
@Inject
|
||||
private WASDCameraListener inputListener;
|
||||
|
||||
@Getter(AccessLevel.PACKAGE)
|
||||
private boolean typing;
|
||||
|
||||
@Override
|
||||
protected void startUp() throws Exception
|
||||
{
|
||||
typing = false;
|
||||
keyManager.registerKeyListener(inputListener);
|
||||
|
||||
clientThread.invoke(() ->
|
||||
{
|
||||
if (client.getGameState() == GameState.LOGGED_IN)
|
||||
{
|
||||
lockChat();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void shutDown() throws Exception
|
||||
{
|
||||
clientThread.invoke(() ->
|
||||
{
|
||||
if (client.getGameState() == GameState.LOGGED_IN)
|
||||
{
|
||||
unlockChat();
|
||||
}
|
||||
});
|
||||
|
||||
keyManager.unregisterKeyListener(inputListener);
|
||||
}
|
||||
|
||||
@Provides
|
||||
WASDCameraConfig getConfig(ConfigManager configManager)
|
||||
{
|
||||
return configManager.getConfig(WASDCameraConfig.class);
|
||||
}
|
||||
|
||||
boolean chatboxFocused()
|
||||
{
|
||||
Widget chatboxParent = client.getWidget(WidgetInfo.CHATBOX_PARENT);
|
||||
return chatboxParent != null && chatboxParent.getOnKeyListener() != null;
|
||||
}
|
||||
|
||||
@Subscribe
|
||||
public void onScriptEvent(ScriptCallbackEvent scriptCallbackEvent)
|
||||
{
|
||||
if (scriptCallbackEvent.getEventName().equals(SCRIPT_EVENT_SET_CHATBOX_INPUT))
|
||||
{
|
||||
Widget chatboxInput = client.getWidget(WidgetInfo.CHATBOX_INPUT);
|
||||
if (chatboxInput != null)
|
||||
{
|
||||
if (chatboxFocused() && !typing)
|
||||
{
|
||||
chatboxInput.setText(PRESS_ENTER_TO_CHAT);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void lockChat()
|
||||
{
|
||||
Widget chatboxParent = client.getWidget(WidgetInfo.CHATBOX_PARENT);
|
||||
if (chatboxParent != null && chatboxParent.getOnKeyListener() != null)
|
||||
{
|
||||
typing = false;
|
||||
|
||||
Widget chatboxInput = client.getWidget(WidgetInfo.CHATBOX_INPUT);
|
||||
if (chatboxInput != null)
|
||||
{
|
||||
chatboxInput.setText(PRESS_ENTER_TO_CHAT);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void unlockChat()
|
||||
{
|
||||
Widget chatboxParent = client.getWidget(WidgetInfo.CHATBOX_PARENT);
|
||||
if (chatboxParent != null)
|
||||
{
|
||||
typing = true;
|
||||
|
||||
Widget chatboxInput = client.getWidget(WidgetInfo.CHATBOX_INPUT);
|
||||
if (chatboxInput != null)
|
||||
{
|
||||
if (client.getGameState() == GameState.LOGGED_IN)
|
||||
{
|
||||
chatboxInput.setText(client.getLocalPlayer().getName() + ": <col=0000ff>*</col>");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user