loot tracker - add ability to ignore loot events
This commit is contained in:
@@ -91,7 +91,9 @@ class LootTrackerBox extends JPanel
|
||||
final boolean hideIgnoredItems,
|
||||
final LootTrackerPriceType priceType,
|
||||
final boolean showPriceType,
|
||||
final BiConsumer<String, Boolean> onItemToggle)
|
||||
final BiConsumer<String, Boolean> onItemToggle,
|
||||
final BiConsumer<String, Boolean> onEventToggle,
|
||||
final boolean eventIgnored)
|
||||
{
|
||||
this.id = id;
|
||||
this.lootRecordType = lootRecordType;
|
||||
@@ -106,7 +108,7 @@ class LootTrackerBox extends JPanel
|
||||
|
||||
logTitle.setLayout(new BoxLayout(logTitle, BoxLayout.X_AXIS));
|
||||
logTitle.setBorder(new EmptyBorder(7, 7, 7, 7));
|
||||
logTitle.setBackground(ColorScheme.DARKER_GRAY_COLOR.darker());
|
||||
logTitle.setBackground(eventIgnored ? ColorScheme.DARKER_GRAY_HOVER_COLOR : ColorScheme.DARKER_GRAY_COLOR.darker());
|
||||
|
||||
JLabel titleLabel = new JLabel();
|
||||
titleLabel.setText(Text.removeTags(id));
|
||||
@@ -135,6 +137,15 @@ class LootTrackerBox extends JPanel
|
||||
|
||||
add(logTitle, BorderLayout.NORTH);
|
||||
add(itemContainer, BorderLayout.CENTER);
|
||||
|
||||
// Create popup menu for ignoring the loot event
|
||||
final JPopupMenu popupMenu = new JPopupMenu();
|
||||
popupMenu.setBorder(new EmptyBorder(5, 5, 5, 5));
|
||||
this.setComponentPopupMenu(popupMenu);
|
||||
|
||||
final JMenuItem toggle = new JMenuItem(eventIgnored ? "Include group" : "Ignore group");
|
||||
toggle.addActionListener(e -> onEventToggle.accept(id, !eventIgnored));
|
||||
popupMenu.add(toggle);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -90,4 +90,21 @@ public interface LootTrackerConfig extends Config
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
@ConfigItem(
|
||||
keyName = "ignoredEvents",
|
||||
name = "Ignored groups",
|
||||
description = "Configures which loot groups should be excluded from the panel UI"
|
||||
)
|
||||
default String getIgnoredEvents()
|
||||
{
|
||||
return "";
|
||||
}
|
||||
|
||||
@ConfigItem(
|
||||
keyName = "ignoredEvents",
|
||||
name = "",
|
||||
description = ""
|
||||
)
|
||||
void setIgnoredEvents(String key);
|
||||
}
|
||||
@@ -35,6 +35,7 @@ import java.awt.event.MouseEvent;
|
||||
import java.awt.image.BufferedImage;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.function.Predicate;
|
||||
import javax.swing.BorderFactory;
|
||||
@@ -355,6 +356,11 @@ class LootTrackerPanel extends PluginPanel
|
||||
final LootTrackerRecord record = new LootTrackerRecord(eventName, subTitle, type, items, 1);
|
||||
sessionRecords.add(record);
|
||||
|
||||
if (hideIgnoredItems && plugin.isEventIgnored(eventName))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
LootTrackerBox box = buildBox(record);
|
||||
if (box != null)
|
||||
{
|
||||
@@ -450,15 +456,12 @@ class LootTrackerPanel extends PluginPanel
|
||||
}
|
||||
else
|
||||
{
|
||||
int start = 0;
|
||||
if (sessionRecords.size() > MAX_LOOT_BOXES)
|
||||
{
|
||||
start = sessionRecords.size() - MAX_LOOT_BOXES;
|
||||
}
|
||||
for (int i = start; i < sessionRecords.size(); i++)
|
||||
{
|
||||
buildBox(sessionRecords.get(i));
|
||||
}
|
||||
sessionRecords.stream()
|
||||
.sorted(Collections.reverseOrder())
|
||||
// filter records prior to limiting so that it is limited to the correct amount
|
||||
.filter(r -> !hideIgnoredItems || !plugin.isEventIgnored(r.getTitle()))
|
||||
.limit(MAX_LOOT_BOXES)
|
||||
.forEach(this::buildBox);
|
||||
}
|
||||
|
||||
boxes.forEach(LootTrackerBox::rebuild);
|
||||
@@ -480,6 +483,12 @@ class LootTrackerPanel extends PluginPanel
|
||||
return null;
|
||||
}
|
||||
|
||||
final boolean isIgnored = plugin.isEventIgnored(record.getTitle());
|
||||
if (hideIgnoredItems && isIgnored)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
// Group all similar loot together
|
||||
if (groupLoot)
|
||||
{
|
||||
@@ -500,13 +509,17 @@ class LootTrackerPanel extends PluginPanel
|
||||
|
||||
// Create box
|
||||
final LootTrackerBox box = new LootTrackerBox(itemManager, record.getTitle(), record.getType(), record.getSubTitle(),
|
||||
hideIgnoredItems, config.priceType(), config.showPriceType(), plugin::toggleItem);
|
||||
hideIgnoredItems, config.priceType(), config.showPriceType(), plugin::toggleItem, plugin::toggleEvent, isIgnored);
|
||||
box.addKill(record);
|
||||
|
||||
// Create popup menu
|
||||
final JPopupMenu popupMenu = new JPopupMenu();
|
||||
popupMenu.setBorder(new EmptyBorder(5, 5, 5, 5));
|
||||
box.setComponentPopupMenu(popupMenu);
|
||||
// Use the existing popup menu or create a new one
|
||||
JPopupMenu popupMenu = box.getComponentPopupMenu();
|
||||
if (popupMenu == null)
|
||||
{
|
||||
popupMenu = new JPopupMenu();
|
||||
popupMenu.setBorder(new EmptyBorder(5, 5, 5, 5));
|
||||
box.setComponentPopupMenu(popupMenu);
|
||||
}
|
||||
|
||||
// Create collapse event
|
||||
box.addMouseListener(new MouseAdapter()
|
||||
@@ -593,6 +606,11 @@ class LootTrackerPanel extends PluginPanel
|
||||
continue;
|
||||
}
|
||||
|
||||
if (hideIgnoredItems && plugin.isEventIgnored(record.getTitle()))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
int present = record.getItems().length;
|
||||
|
||||
for (LootTrackerItem item : record.getItems())
|
||||
|
||||
@@ -43,6 +43,7 @@ import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
import java.util.Comparator;
|
||||
import java.util.HashSet;
|
||||
import java.util.LinkedHashSet;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
@@ -199,6 +200,7 @@ public class LootTrackerPlugin extends Plugin
|
||||
private String lastPickpocketTarget;
|
||||
|
||||
private List<String> ignoredItems = new ArrayList<>();
|
||||
private List<String> ignoredEvents = new ArrayList<>();
|
||||
|
||||
private Multiset<Integer> inventorySnapshot;
|
||||
|
||||
@@ -268,6 +270,7 @@ public class LootTrackerPlugin extends Plugin
|
||||
if (event.getGroup().equals("loottracker"))
|
||||
{
|
||||
ignoredItems = Text.fromCSV(config.getIgnoredItems());
|
||||
ignoredEvents = Text.fromCSV(config.getIgnoredEvents());
|
||||
SwingUtilities.invokeLater(panel::updateIgnoredRecords);
|
||||
}
|
||||
}
|
||||
@@ -276,6 +279,7 @@ public class LootTrackerPlugin extends Plugin
|
||||
protected void startUp() throws Exception
|
||||
{
|
||||
ignoredItems = Text.fromCSV(config.getIgnoredItems());
|
||||
ignoredEvents = Text.fromCSV(config.getIgnoredEvents());
|
||||
panel = new LootTrackerPanel(this, itemManager, config);
|
||||
spriteManager.getSpriteAsync(SpriteID.TAB_INVENTORY, 0, panel::loadHeaderIcon);
|
||||
|
||||
@@ -750,6 +754,28 @@ public class LootTrackerPlugin extends Plugin
|
||||
return ignoredItems.contains(name);
|
||||
}
|
||||
|
||||
void toggleEvent(String name, boolean ignore)
|
||||
{
|
||||
final Set<String> ignoredSet = new LinkedHashSet<>(ignoredEvents);
|
||||
|
||||
if (ignore)
|
||||
{
|
||||
ignoredSet.add(name);
|
||||
}
|
||||
else
|
||||
{
|
||||
ignoredSet.remove(name);
|
||||
}
|
||||
|
||||
config.setIgnoredEvents(Text.toCSV(ignoredSet));
|
||||
// the config changed will update the panel
|
||||
}
|
||||
|
||||
boolean isEventIgnored(String name)
|
||||
{
|
||||
return ignoredEvents.contains(name);
|
||||
}
|
||||
|
||||
private LootTrackerItem buildLootTrackerItem(int itemId, int quantity)
|
||||
{
|
||||
final ItemComposition itemComposition = itemManager.getItemComposition(itemId);
|
||||
|
||||
Reference in New Issue
Block a user