Skip to content

Commit

Permalink
implemented the ability to add new items
Browse files Browse the repository at this point in the history
  • Loading branch information
Wynadorn committed Nov 12, 2021
1 parent ea9368f commit 0f45ff6
Show file tree
Hide file tree
Showing 2 changed files with 64 additions and 0 deletions.
13 changes: 13 additions & 0 deletions src/main/java/com/banktaglayouts/BankTagLayoutsConfig.java
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
package com.banktaglayouts;

import java.awt.event.InputEvent;
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("banktaglayouts")
public interface BankTagLayoutsConfig extends Config {
Expand Down Expand Up @@ -105,4 +108,14 @@ default int autoLayoutDuplicateLimit() {
)
default boolean preventVanillaPlaceholderMenuBug() { return true; }

@ConfigItem(
keyName = "addKeybind",
name = "Add item keybind",
description = "Keyboard shortcut for adding a placeholder",
position = 11
)
default Keybind addKeybind()
{
return new Keybind(KeyEvent.VK_A, InputEvent.CTRL_DOWN_MASK);
}
}
51 changes: 51 additions & 0 deletions src/main/java/com/banktaglayouts/BankTagLayoutsPlugin.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
import com.google.common.util.concurrent.Runnables;
import com.google.gson.Gson;
import com.google.inject.Provides;
import java.awt.event.KeyEvent;
import java.awt.event.KeyListener;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.RequiredArgsConstructor;
Expand Down Expand Up @@ -45,6 +47,7 @@
import net.runelite.api.widgets.WidgetType;
import net.runelite.client.callback.ClientThread;
import net.runelite.client.config.ConfigManager;
import net.runelite.client.config.Keybind;
import net.runelite.client.eventbus.Subscribe;
import net.runelite.client.events.ConfigChanged;
import net.runelite.client.game.ItemManager;
Expand Down Expand Up @@ -252,6 +255,7 @@ protected void startUp()
spriteManager.addSpriteOverrides(Sprites.values());
mouseManager.registerMouseListener(this);
keyManager.registerKeyListener(antiDrag);
keyManager.registerKeyListener(addItemHotkeyListener);

clientThread.invokeLater(() -> {
if (client.getGameState() == GameState.LOGGED_IN) {
Expand All @@ -269,6 +273,7 @@ protected void shutDown()
spriteManager.removeSpriteOverrides(Sprites.values());
mouseManager.unregisterMouseListener(this);
keyManager.unregisterKeyListener(antiDrag);
keyManager.unregisterKeyListener(addItemHotkeyListener);

clientThread.invokeLater(() -> {
if (client.getGameState() == GameState.LOGGED_IN) {
Expand Down Expand Up @@ -1667,4 +1672,50 @@ public void onMenuShouldLeftClick(MenuShouldLeftClick event)
}
}
}

private final net.runelite.client.input.KeyListener addItemHotkeyListener = new net.runelite.client.input.KeyListener()
{
@Override
public void keyTyped(KeyEvent e)
{
}

@Override
public void keyPressed(KeyEvent e)
{
Keybind keybind = config.addKeybind();
if (keybind.matches(e))
{
//if the bank is not open
Widget bankContainer = client.getWidget(WidgetInfo.BANK_ITEM_CONTAINER);
if (bankContainer == null || bankContainer.isSelfHidden())
{
//do nothing
return;
}

//If the current tab is either a regular tab or an inventory setup
if(!tabInterface.isActive() || isInventorySetup())
{
//do nothing
return;
}

//show the add item dialog
log.debug("Add layout item hotkey pressed");
addToLayout( tabInterface.getActiveTab().getTag());
e.consume();
}
}

@Override
public void keyReleased(KeyEvent e)
{
}
};

private boolean isInventorySetup()
{
return config.useWithInventorySetups() && inventorySetup != null;
}
}

0 comments on commit 0f45ff6

Please sign in to comment.