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 boolean hideIgnoredItems,
|
||||||
final LootTrackerPriceType priceType,
|
final LootTrackerPriceType priceType,
|
||||||
final boolean showPriceType,
|
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.id = id;
|
||||||
this.lootRecordType = lootRecordType;
|
this.lootRecordType = lootRecordType;
|
||||||
@@ -106,7 +108,7 @@ class LootTrackerBox extends JPanel
|
|||||||
|
|
||||||
logTitle.setLayout(new BoxLayout(logTitle, BoxLayout.X_AXIS));
|
logTitle.setLayout(new BoxLayout(logTitle, BoxLayout.X_AXIS));
|
||||||
logTitle.setBorder(new EmptyBorder(7, 7, 7, 7));
|
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();
|
JLabel titleLabel = new JLabel();
|
||||||
titleLabel.setText(Text.removeTags(id));
|
titleLabel.setText(Text.removeTags(id));
|
||||||
@@ -135,6 +137,15 @@ class LootTrackerBox extends JPanel
|
|||||||
|
|
||||||
add(logTitle, BorderLayout.NORTH);
|
add(logTitle, BorderLayout.NORTH);
|
||||||
add(itemContainer, BorderLayout.CENTER);
|
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;
|
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.awt.image.BufferedImage;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
|
import java.util.Collections;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.function.Predicate;
|
import java.util.function.Predicate;
|
||||||
import javax.swing.BorderFactory;
|
import javax.swing.BorderFactory;
|
||||||
@@ -355,6 +356,11 @@ class LootTrackerPanel extends PluginPanel
|
|||||||
final LootTrackerRecord record = new LootTrackerRecord(eventName, subTitle, type, items, 1);
|
final LootTrackerRecord record = new LootTrackerRecord(eventName, subTitle, type, items, 1);
|
||||||
sessionRecords.add(record);
|
sessionRecords.add(record);
|
||||||
|
|
||||||
|
if (hideIgnoredItems && plugin.isEventIgnored(eventName))
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
LootTrackerBox box = buildBox(record);
|
LootTrackerBox box = buildBox(record);
|
||||||
if (box != null)
|
if (box != null)
|
||||||
{
|
{
|
||||||
@@ -450,15 +456,12 @@ class LootTrackerPanel extends PluginPanel
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
int start = 0;
|
sessionRecords.stream()
|
||||||
if (sessionRecords.size() > MAX_LOOT_BOXES)
|
.sorted(Collections.reverseOrder())
|
||||||
{
|
// filter records prior to limiting so that it is limited to the correct amount
|
||||||
start = sessionRecords.size() - MAX_LOOT_BOXES;
|
.filter(r -> !hideIgnoredItems || !plugin.isEventIgnored(r.getTitle()))
|
||||||
}
|
.limit(MAX_LOOT_BOXES)
|
||||||
for (int i = start; i < sessionRecords.size(); i++)
|
.forEach(this::buildBox);
|
||||||
{
|
|
||||||
buildBox(sessionRecords.get(i));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
boxes.forEach(LootTrackerBox::rebuild);
|
boxes.forEach(LootTrackerBox::rebuild);
|
||||||
@@ -480,6 +483,12 @@ class LootTrackerPanel extends PluginPanel
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
final boolean isIgnored = plugin.isEventIgnored(record.getTitle());
|
||||||
|
if (hideIgnoredItems && isIgnored)
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
// Group all similar loot together
|
// Group all similar loot together
|
||||||
if (groupLoot)
|
if (groupLoot)
|
||||||
{
|
{
|
||||||
@@ -500,13 +509,17 @@ class LootTrackerPanel extends PluginPanel
|
|||||||
|
|
||||||
// Create box
|
// Create box
|
||||||
final LootTrackerBox box = new LootTrackerBox(itemManager, record.getTitle(), record.getType(), record.getSubTitle(),
|
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);
|
box.addKill(record);
|
||||||
|
|
||||||
// Create popup menu
|
// Use the existing popup menu or create a new one
|
||||||
final JPopupMenu popupMenu = new JPopupMenu();
|
JPopupMenu popupMenu = box.getComponentPopupMenu();
|
||||||
popupMenu.setBorder(new EmptyBorder(5, 5, 5, 5));
|
if (popupMenu == null)
|
||||||
box.setComponentPopupMenu(popupMenu);
|
{
|
||||||
|
popupMenu = new JPopupMenu();
|
||||||
|
popupMenu.setBorder(new EmptyBorder(5, 5, 5, 5));
|
||||||
|
box.setComponentPopupMenu(popupMenu);
|
||||||
|
}
|
||||||
|
|
||||||
// Create collapse event
|
// Create collapse event
|
||||||
box.addMouseListener(new MouseAdapter()
|
box.addMouseListener(new MouseAdapter()
|
||||||
@@ -593,6 +606,11 @@ class LootTrackerPanel extends PluginPanel
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (hideIgnoredItems && plugin.isEventIgnored(record.getTitle()))
|
||||||
|
{
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
int present = record.getItems().length;
|
int present = record.getItems().length;
|
||||||
|
|
||||||
for (LootTrackerItem item : record.getItems())
|
for (LootTrackerItem item : record.getItems())
|
||||||
|
|||||||
@@ -43,6 +43,7 @@ import java.util.Arrays;
|
|||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.Comparator;
|
import java.util.Comparator;
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
|
import java.util.LinkedHashSet;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
@@ -199,6 +200,7 @@ public class LootTrackerPlugin extends Plugin
|
|||||||
private String lastPickpocketTarget;
|
private String lastPickpocketTarget;
|
||||||
|
|
||||||
private List<String> ignoredItems = new ArrayList<>();
|
private List<String> ignoredItems = new ArrayList<>();
|
||||||
|
private List<String> ignoredEvents = new ArrayList<>();
|
||||||
|
|
||||||
private Multiset<Integer> inventorySnapshot;
|
private Multiset<Integer> inventorySnapshot;
|
||||||
|
|
||||||
@@ -268,6 +270,7 @@ public class LootTrackerPlugin extends Plugin
|
|||||||
if (event.getGroup().equals("loottracker"))
|
if (event.getGroup().equals("loottracker"))
|
||||||
{
|
{
|
||||||
ignoredItems = Text.fromCSV(config.getIgnoredItems());
|
ignoredItems = Text.fromCSV(config.getIgnoredItems());
|
||||||
|
ignoredEvents = Text.fromCSV(config.getIgnoredEvents());
|
||||||
SwingUtilities.invokeLater(panel::updateIgnoredRecords);
|
SwingUtilities.invokeLater(panel::updateIgnoredRecords);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -276,6 +279,7 @@ public class LootTrackerPlugin extends Plugin
|
|||||||
protected void startUp() throws Exception
|
protected void startUp() throws Exception
|
||||||
{
|
{
|
||||||
ignoredItems = Text.fromCSV(config.getIgnoredItems());
|
ignoredItems = Text.fromCSV(config.getIgnoredItems());
|
||||||
|
ignoredEvents = Text.fromCSV(config.getIgnoredEvents());
|
||||||
panel = new LootTrackerPanel(this, itemManager, config);
|
panel = new LootTrackerPanel(this, itemManager, config);
|
||||||
spriteManager.getSpriteAsync(SpriteID.TAB_INVENTORY, 0, panel::loadHeaderIcon);
|
spriteManager.getSpriteAsync(SpriteID.TAB_INVENTORY, 0, panel::loadHeaderIcon);
|
||||||
|
|
||||||
@@ -750,6 +754,28 @@ public class LootTrackerPlugin extends Plugin
|
|||||||
return ignoredItems.contains(name);
|
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)
|
private LootTrackerItem buildLootTrackerItem(int itemId, int quantity)
|
||||||
{
|
{
|
||||||
final ItemComposition itemComposition = itemManager.getItemComposition(itemId);
|
final ItemComposition itemComposition = itemManager.getItemComposition(itemId);
|
||||||
|
|||||||
Reference in New Issue
Block a user