Refactor Equipment inspector

This commit is contained in:
Scott Burns
2019-05-16 00:45:01 +02:00
parent d39d103bc2
commit b0194eeefd
4 changed files with 270 additions and 232 deletions

View File

@@ -24,13 +24,9 @@
*/
package net.runelite.client.plugins.equipmentinspector;
import java.awt.Color;
import net.runelite.client.config.Config;
import net.runelite.client.config.ConfigGroup;
import net.runelite.client.config.ConfigItem;
import net.runelite.client.plugins.grounditems.config.ItemHighlightMode;
import net.runelite.client.plugins.grounditems.config.MenuHighlightMode;
import net.runelite.client.plugins.grounditems.config.PriceDisplayMode;
@ConfigGroup("grounditems")
public interface EquipmentInspectorConfig extends Config
@@ -45,6 +41,7 @@ public interface EquipmentInspectorConfig extends Config
{
return true;
}
@ConfigItem(
keyName = "protecteditems",
name = "# of protected items",
@@ -52,7 +49,10 @@ public interface EquipmentInspectorConfig extends Config
position = 2
)
default int protecteditems()
{ return 1; }
{
return 1;
}
@ConfigItem(
keyName = "ExactValue",
name = "Show exact value",
@@ -60,5 +60,7 @@ public interface EquipmentInspectorConfig extends Config
position = 3
)
default boolean ExactValue()
{ return false; }
{
return false;
}
}

View File

@@ -24,6 +24,21 @@
*/
package net.runelite.client.plugins.equipmentinspector;
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.util.HashMap;
import java.util.Map;
import javax.inject.Inject;
import javax.inject.Singleton;
import javax.swing.BorderFactory;
import javax.swing.GroupLayout;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.SwingUtilities;
import javax.swing.border.CompoundBorder;
import javax.swing.border.EmptyBorder;
import lombok.extern.slf4j.Slf4j;
import net.runelite.api.ItemComposition;
import net.runelite.api.kit.KitType;
@@ -32,15 +47,6 @@ import net.runelite.client.game.ItemManager;
import net.runelite.client.ui.ColorScheme;
import net.runelite.client.ui.PluginPanel;
import javax.inject.Inject;
import javax.inject.Singleton;
import javax.swing.*;
import javax.swing.border.CompoundBorder;
import javax.swing.border.EmptyBorder;
import java.awt.*;
import java.util.HashMap;
import java.util.Map;
@Slf4j
@Singleton
public class EquipmentInspectorPanel extends PluginPanel
@@ -91,7 +97,7 @@ public class EquipmentInspectorPanel extends PluginPanel
public void update(Map<KitType, ItemComposition> playerEquipment, String playerName)
{
if (playerName.isEmpty() || playerName == null)
if (playerName.isEmpty())
{
nameLabel.setText(NO_PLAYER_SELECTED);
}

View File

@@ -26,6 +26,18 @@ package net.runelite.client.plugins.equipmentinspector;
import com.google.inject.Provides;
import java.awt.image.BufferedImage;
import java.lang.reflect.InvocationTargetException;
import java.text.NumberFormat;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.Optional;
import java.util.concurrent.ScheduledExecutorService;
import javax.annotation.Nullable;
import javax.inject.Inject;
import javax.swing.SwingUtilities;
import lombok.extern.slf4j.Slf4j;
import net.runelite.api.ChatMessageType;
import net.runelite.api.Client;
@@ -49,15 +61,6 @@ import net.runelite.client.ui.NavigationButton;
import net.runelite.client.util.ImageUtil;
import net.runelite.client.util.Text;
import javax.annotation.Nullable;
import javax.inject.Inject;
import javax.swing.*;
import java.awt.image.BufferedImage;
import java.lang.reflect.InvocationTargetException;
import java.text.NumberFormat;
import java.util.*;
import java.util.concurrent.ScheduledExecutorService;
@PluginDescriptor(
name = "Equipment Inspector",
enabledByDefault = false,
@@ -66,10 +69,9 @@ import java.util.concurrent.ScheduledExecutorService;
@Slf4j
public class EquipmentInspectorPlugin extends Plugin {
public class EquipmentInspectorPlugin extends Plugin
{
private static final String INSPECT_EQUIPMENT = "Gear";
private static final String KICK_OPTION = "Kick";
@Inject
@Nullable
@@ -100,22 +102,22 @@ public class EquipmentInspectorPlugin extends Plugin {
private int Prot4 = 0;
@Provides
EquipmentInspectorConfig provideConfig(ConfigManager configManager) {
EquipmentInspectorConfig provideConfig(ConfigManager configManager)
{
return configManager.getConfig(EquipmentInspectorConfig.class);
}
@Override
protected void startUp() throws Exception {
protected void startUp() throws Exception
{
equipmentInspectorPanel = injector.getInstance(EquipmentInspectorPanel.class);
if (client != null) {
if (client != null)
{
menuManager.addPlayerMenuItem(INSPECT_EQUIPMENT);
}
//synchronized (ImageIO.class)
//{
final BufferedImage icon = ImageUtil.getResourceStreamFromClass(this.getClass(), "normal.png");
//}
navButton = NavigationButton.builder()
.tooltip("Equipment Inspector")
@@ -130,26 +132,33 @@ public class EquipmentInspectorPlugin extends Plugin {
}
@Override
protected void shutDown() throws Exception {
protected void shutDown() throws Exception
{
menuManager.removePlayerMenuItem(INSPECT_EQUIPMENT);
}
@Subscribe
public void onPlayerMenuOptionClicked(PlayerMenuOptionClicked event) {
if (event.getMenuOption().equals(INSPECT_EQUIPMENT)) {
public void onPlayerMenuOptionClicked(PlayerMenuOptionClicked event)
{
if (event.getMenuOption().equals(INSPECT_EQUIPMENT))
{
executor.execute(() ->
{
try {
try
{
SwingUtilities.invokeAndWait(() ->
{
if (!navButton.isSelected()) {
if (!navButton.isSelected())
{
navButton.getOnSelect().run();
}
});
} catch (InterruptedException | InvocationTargetException e) {
}
catch (InterruptedException | InvocationTargetException e)
{
throw new RuntimeException(e);
@@ -164,7 +173,8 @@ public class EquipmentInspectorPlugin extends Plugin {
.filter(Objects::nonNull)
.filter(p -> p.getName().equals(finalPlayerName)).findFirst();
if (targetPlayer.isPresent()) {
if (targetPlayer.isPresent())
{
TotalPrice = 0;
Prot1 = 0;
Prot2 = 0;
@@ -173,41 +183,59 @@ public class EquipmentInspectorPlugin extends Plugin {
Player p = targetPlayer.get();
Map<KitType, ItemComposition> playerEquipment = new HashMap<>();
for (KitType kitType : KitType.values()) {
if (kitType == KitType.RING) continue; //prevents the equipment inspector from breaking
if (kitType == KitType.AMMUNITION) continue;
for (KitType kitType : KitType.values())
{
if (kitType == KitType.RING)
{
continue; //prevents the equipment inspector from breaking
}
if (kitType == KitType.AMMUNITION)
{
continue;
}
int itemId = p.getPlayerComposition().getEquipmentId(kitType);
if (itemId != -1) {
if (itemId != -1)
{
ItemComposition itemComposition = client.getItemDefinition(itemId);
playerEquipment.put(kitType, itemComposition);
int ItemPrice = itemManager.getItemPrice(itemId);
TotalPrice += ItemPrice;
if (ItemPrice > Prot1) {
if (ItemPrice > Prot1)
{
Prot4 = Prot3;
Prot3 = Prot2;
Prot2 = Prot1;
Prot1 = ItemPrice;
} else if (ItemPrice > Prot2) {
}
else if (ItemPrice > Prot2)
{
Prot4 = Prot3;
Prot3 = Prot2;
Prot2 = ItemPrice;
} else if (ItemPrice > Prot3) {
}
else if (ItemPrice > Prot3)
{
Prot4 = Prot3;
Prot3 = ItemPrice;
} else if (ItemPrice > Prot4) {
}
else if (ItemPrice > Prot4)
{
Prot4 = ItemPrice;
}
}
}
int IgnoredItems = config.protecteditems();
if (IgnoredItems != 0 && IgnoredItems != 1 && IgnoredItems != 2 && IgnoredItems != 3) {
if (IgnoredItems != 0 && IgnoredItems != 1 && IgnoredItems != 2 && IgnoredItems != 3)
{
IgnoredItems = 4;
}
if (config.ShowValue()) {
switch (IgnoredItems) {
if (config.ShowValue())
{
switch (IgnoredItems)
{
case 1:
TotalPrice = TotalPrice - Prot1;
break;
@@ -229,12 +257,14 @@ public class EquipmentInspectorPlugin extends Plugin {
break;
}
String StringPrice = "";
if (!config.ExactValue()) {
if (!config.ExactValue())
{
TotalPrice = TotalPrice / 1000;
StringPrice = NumberFormat.getIntegerInstance().format(TotalPrice);
StringPrice = StringPrice + 'K';
}
if (config.ExactValue()) {
if (config.ExactValue())
{
StringPrice = NumberFormat.getIntegerInstance().format(TotalPrice);
}
chatMessageManager.queue(QueuedMessage.builder()

View File

@@ -24,6 +24,10 @@
*/
package net.runelite.client.plugins.equipmentinspector;
import javax.swing.GroupLayout;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.border.EmptyBorder;
import net.runelite.api.ItemComposition;
import net.runelite.api.kit.KitType;
import net.runelite.client.game.AsyncBufferedImage;
@@ -31,12 +35,8 @@ import net.runelite.client.ui.ColorScheme;
import net.runelite.client.ui.FontManager;
import org.apache.commons.lang3.StringUtils;
import javax.swing.*;
import javax.swing.border.EmptyBorder;
class ItemPanel extends JPanel
{
ItemPanel(ItemComposition item, KitType kitType, AsyncBufferedImage icon)
{