Loot Tracker: Allow loot boxes to be collapsed (#9439)
This commit is contained in:
@@ -28,6 +28,7 @@ package net.runelite.client.plugins.loottracker;
|
|||||||
import com.google.common.base.Strings;
|
import com.google.common.base.Strings;
|
||||||
import java.awt.BorderLayout;
|
import java.awt.BorderLayout;
|
||||||
import java.awt.Color;
|
import java.awt.Color;
|
||||||
|
import java.awt.Component;
|
||||||
import java.awt.GridLayout;
|
import java.awt.GridLayout;
|
||||||
import java.awt.image.BufferedImage;
|
import java.awt.image.BufferedImage;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
@@ -59,6 +60,8 @@ class LootTrackerBox extends JPanel
|
|||||||
private final JPanel itemContainer = new JPanel();
|
private final JPanel itemContainer = new JPanel();
|
||||||
private final JLabel priceLabel = new JLabel();
|
private final JLabel priceLabel = new JLabel();
|
||||||
private final JLabel subTitleLabel = new JLabel();
|
private final JLabel subTitleLabel = new JLabel();
|
||||||
|
private final JPanel logTitle = new JPanel(new BorderLayout(5, 0));
|
||||||
|
private final JLabel titleLabel = new JLabel();
|
||||||
private final ItemManager itemManager;
|
private final ItemManager itemManager;
|
||||||
@Getter(AccessLevel.PACKAGE)
|
@Getter(AccessLevel.PACKAGE)
|
||||||
private final String id;
|
private final String id;
|
||||||
@@ -85,11 +88,10 @@ class LootTrackerBox extends JPanel
|
|||||||
setLayout(new BorderLayout(0, 1));
|
setLayout(new BorderLayout(0, 1));
|
||||||
setBorder(new EmptyBorder(5, 0, 0, 0));
|
setBorder(new EmptyBorder(5, 0, 0, 0));
|
||||||
|
|
||||||
final JPanel logTitle = new JPanel(new BorderLayout(5, 0));
|
|
||||||
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(ColorScheme.DARKER_GRAY_COLOR.darker());
|
||||||
|
|
||||||
final JLabel titleLabel = new JLabel(Text.removeTags(id));
|
titleLabel.setText(Text.removeTags(id));
|
||||||
titleLabel.setFont(FontManager.getRunescapeSmallFont());
|
titleLabel.setFont(FontManager.getRunescapeSmallFont());
|
||||||
titleLabel.setForeground(Color.WHITE);
|
titleLabel.setForeground(Color.WHITE);
|
||||||
|
|
||||||
@@ -182,6 +184,39 @@ class LootTrackerBox extends JPanel
|
|||||||
repaint();
|
repaint();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void collapse()
|
||||||
|
{
|
||||||
|
if (!isCollapsed())
|
||||||
|
{
|
||||||
|
itemContainer.setVisible(false);
|
||||||
|
applyDimmer(false, logTitle);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void expand()
|
||||||
|
{
|
||||||
|
if (isCollapsed())
|
||||||
|
{
|
||||||
|
itemContainer.setVisible(true);
|
||||||
|
applyDimmer(true, logTitle);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
boolean isCollapsed()
|
||||||
|
{
|
||||||
|
return !itemContainer.isVisible();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void applyDimmer(boolean brighten, JPanel panel)
|
||||||
|
{
|
||||||
|
for (Component component : panel.getComponents())
|
||||||
|
{
|
||||||
|
Color color = component.getForeground();
|
||||||
|
|
||||||
|
component.setForeground(brighten ? color.brighter() : color.darker());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This method creates stacked items from the item list, calculates total price and then
|
* This method creates stacked items from the item list, calculates total price and then
|
||||||
* displays all the items in the UI.
|
* displays all the items in the UI.
|
||||||
|
|||||||
@@ -69,6 +69,8 @@ class LootTrackerPanel extends PluginPanel
|
|||||||
private static final ImageIcon VISIBLE_ICON_HOVER;
|
private static final ImageIcon VISIBLE_ICON_HOVER;
|
||||||
private static final ImageIcon INVISIBLE_ICON;
|
private static final ImageIcon INVISIBLE_ICON;
|
||||||
private static final ImageIcon INVISIBLE_ICON_HOVER;
|
private static final ImageIcon INVISIBLE_ICON_HOVER;
|
||||||
|
private static final ImageIcon COLLAPSE_ICON;
|
||||||
|
private static final ImageIcon EXPAND_ICON;
|
||||||
|
|
||||||
private static final String HTML_LABEL_TEMPLATE =
|
private static final String HTML_LABEL_TEMPLATE =
|
||||||
"<html><body style='color:%s'>%s<span style='color:white'>%s</span></body></html>";
|
"<html><body style='color:%s'>%s<span style='color:white'>%s</span></body></html>";
|
||||||
@@ -92,6 +94,7 @@ class LootTrackerPanel extends PluginPanel
|
|||||||
private final JLabel viewHiddenBtn = new JLabel();
|
private final JLabel viewHiddenBtn = new JLabel();
|
||||||
private final JLabel singleLootBtn = new JLabel();
|
private final JLabel singleLootBtn = new JLabel();
|
||||||
private final JLabel groupedLootBtn = new JLabel();
|
private final JLabel groupedLootBtn = new JLabel();
|
||||||
|
private final JLabel collapseBtn = new JLabel();
|
||||||
|
|
||||||
// Log collection
|
// Log collection
|
||||||
private final List<LootTrackerRecord> records = new ArrayList<>();
|
private final List<LootTrackerRecord> records = new ArrayList<>();
|
||||||
@@ -112,6 +115,8 @@ class LootTrackerPanel extends PluginPanel
|
|||||||
final BufferedImage backArrowImg = ImageUtil.getResourceStreamFromClass(LootTrackerPlugin.class, "back_icon.png");
|
final BufferedImage backArrowImg = ImageUtil.getResourceStreamFromClass(LootTrackerPlugin.class, "back_icon.png");
|
||||||
final BufferedImage visibleImg = ImageUtil.getResourceStreamFromClass(LootTrackerPlugin.class, "visible_icon.png");
|
final BufferedImage visibleImg = ImageUtil.getResourceStreamFromClass(LootTrackerPlugin.class, "visible_icon.png");
|
||||||
final BufferedImage invisibleImg = ImageUtil.getResourceStreamFromClass(LootTrackerPlugin.class, "invisible_icon.png");
|
final BufferedImage invisibleImg = ImageUtil.getResourceStreamFromClass(LootTrackerPlugin.class, "invisible_icon.png");
|
||||||
|
final BufferedImage collapseImg = ImageUtil.getResourceStreamFromClass(LootTrackerPlugin.class, "collapsed.png");
|
||||||
|
final BufferedImage expandedImg = ImageUtil.getResourceStreamFromClass(LootTrackerPlugin.class, "expanded.png");
|
||||||
|
|
||||||
SINGLE_LOOT_VIEW = new ImageIcon(singleLootImg);
|
SINGLE_LOOT_VIEW = new ImageIcon(singleLootImg);
|
||||||
SINGLE_LOOT_VIEW_FADED = new ImageIcon(ImageUtil.alphaOffset(singleLootImg, -180));
|
SINGLE_LOOT_VIEW_FADED = new ImageIcon(ImageUtil.alphaOffset(singleLootImg, -180));
|
||||||
@@ -129,6 +134,9 @@ class LootTrackerPanel extends PluginPanel
|
|||||||
|
|
||||||
INVISIBLE_ICON = new ImageIcon(invisibleImg);
|
INVISIBLE_ICON = new ImageIcon(invisibleImg);
|
||||||
INVISIBLE_ICON_HOVER = new ImageIcon(ImageUtil.alphaOffset(invisibleImg, -220));
|
INVISIBLE_ICON_HOVER = new ImageIcon(ImageUtil.alphaOffset(invisibleImg, -220));
|
||||||
|
|
||||||
|
COLLAPSE_ICON = new ImageIcon(collapseImg);
|
||||||
|
EXPAND_ICON = new ImageIcon(expandedImg);
|
||||||
}
|
}
|
||||||
|
|
||||||
LootTrackerPanel(final LootTrackerPlugin plugin, final ItemManager itemManager, final LootTrackerConfig config)
|
LootTrackerPanel(final LootTrackerPlugin plugin, final ItemManager itemManager, final LootTrackerConfig config)
|
||||||
@@ -156,6 +164,16 @@ class LootTrackerPanel extends PluginPanel
|
|||||||
final JPanel viewControls = new JPanel(new GridLayout(1, 3, 10, 0));
|
final JPanel viewControls = new JPanel(new GridLayout(1, 3, 10, 0));
|
||||||
viewControls.setBackground(ColorScheme.DARKER_GRAY_COLOR);
|
viewControls.setBackground(ColorScheme.DARKER_GRAY_COLOR);
|
||||||
|
|
||||||
|
collapseBtn.setIcon(EXPAND_ICON);
|
||||||
|
collapseBtn.addMouseListener(new MouseAdapter()
|
||||||
|
{
|
||||||
|
@Override
|
||||||
|
public void mousePressed(MouseEvent e)
|
||||||
|
{
|
||||||
|
changeCollapse();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
singleLootBtn.setIcon(SINGLE_LOOT_VIEW);
|
singleLootBtn.setIcon(SINGLE_LOOT_VIEW);
|
||||||
singleLootBtn.setToolTipText("Show each kill separately");
|
singleLootBtn.setToolTipText("Show each kill separately");
|
||||||
singleLootBtn.addMouseListener(new MouseAdapter()
|
singleLootBtn.addMouseListener(new MouseAdapter()
|
||||||
@@ -225,6 +243,7 @@ class LootTrackerPanel extends PluginPanel
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
viewControls.add(collapseBtn);
|
||||||
viewControls.add(groupedLootBtn);
|
viewControls.add(groupedLootBtn);
|
||||||
viewControls.add(singleLootBtn);
|
viewControls.add(singleLootBtn);
|
||||||
viewControls.add(viewHiddenBtn);
|
viewControls.add(viewHiddenBtn);
|
||||||
@@ -265,8 +284,8 @@ class LootTrackerPanel extends PluginPanel
|
|||||||
leftTitleContainer.add(backBtn, BorderLayout.WEST);
|
leftTitleContainer.add(backBtn, BorderLayout.WEST);
|
||||||
leftTitleContainer.add(detailsTitle, BorderLayout.CENTER);
|
leftTitleContainer.add(detailsTitle, BorderLayout.CENTER);
|
||||||
|
|
||||||
actionsContainer.add(leftTitleContainer, BorderLayout.WEST);
|
|
||||||
actionsContainer.add(viewControls, BorderLayout.EAST);
|
actionsContainer.add(viewControls, BorderLayout.EAST);
|
||||||
|
actionsContainer.add(leftTitleContainer, BorderLayout.WEST);
|
||||||
|
|
||||||
// Create panel that will contain overall data
|
// Create panel that will contain overall data
|
||||||
overallPanel.setBorder(BorderFactory.createCompoundBorder(
|
overallPanel.setBorder(BorderFactory.createCompoundBorder(
|
||||||
@@ -325,6 +344,27 @@ class LootTrackerPanel extends PluginPanel
|
|||||||
add(errorPanel);
|
add(errorPanel);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void updateCollapseText()
|
||||||
|
{
|
||||||
|
if (isAllCollapsed())
|
||||||
|
{
|
||||||
|
collapseBtn.setToolTipText("Un-Collapse All");
|
||||||
|
collapseBtn.setIcon(COLLAPSE_ICON);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
collapseBtn.setToolTipText("Collapse All");
|
||||||
|
collapseBtn.setIcon(EXPAND_ICON);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private boolean isAllCollapsed()
|
||||||
|
{
|
||||||
|
return boxes.stream()
|
||||||
|
.filter(i -> i.isCollapsed())
|
||||||
|
.count() == boxes.size();
|
||||||
|
}
|
||||||
|
|
||||||
void loadHeaderIcon(BufferedImage img)
|
void loadHeaderIcon(BufferedImage img)
|
||||||
{
|
{
|
||||||
overallIcon.setIcon(new ImageIcon(img));
|
overallIcon.setIcon(new ImageIcon(img));
|
||||||
@@ -382,6 +422,28 @@ class LootTrackerPanel extends PluginPanel
|
|||||||
viewHiddenBtn.setIcon(hideIgnoredItems ? VISIBLE_ICON : INVISIBLE_ICON);
|
viewHiddenBtn.setIcon(hideIgnoredItems ? VISIBLE_ICON : INVISIBLE_ICON);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Changes the collapse status of loot entries
|
||||||
|
*/
|
||||||
|
private void changeCollapse()
|
||||||
|
{
|
||||||
|
boolean isAllCollapsed = isAllCollapsed();
|
||||||
|
|
||||||
|
for (LootTrackerBox box : boxes)
|
||||||
|
{
|
||||||
|
if (isAllCollapsed)
|
||||||
|
{
|
||||||
|
box.expand();
|
||||||
|
}
|
||||||
|
else if (!box.isCollapsed())
|
||||||
|
{
|
||||||
|
box.collapse();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
updateCollapseText();
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* After an item changed it's ignored state, iterate all the records and make
|
* After an item changed it's ignored state, iterate all the records and make
|
||||||
* sure all items of the same name also get updated
|
* sure all items of the same name also get updated
|
||||||
@@ -464,6 +526,27 @@ class LootTrackerPanel extends PluginPanel
|
|||||||
popupMenu.setBorder(new EmptyBorder(5, 5, 5, 5));
|
popupMenu.setBorder(new EmptyBorder(5, 5, 5, 5));
|
||||||
box.setComponentPopupMenu(popupMenu);
|
box.setComponentPopupMenu(popupMenu);
|
||||||
|
|
||||||
|
// Create collapse event
|
||||||
|
box.addMouseListener(new MouseAdapter()
|
||||||
|
{
|
||||||
|
@Override
|
||||||
|
public void mouseClicked(MouseEvent e)
|
||||||
|
{
|
||||||
|
if (e.getButton() == MouseEvent.BUTTON1)
|
||||||
|
{
|
||||||
|
if (box.isCollapsed())
|
||||||
|
{
|
||||||
|
box.expand();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
box.collapse();
|
||||||
|
}
|
||||||
|
updateCollapseText();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
// Create reset menu
|
// Create reset menu
|
||||||
final JMenuItem reset = new JMenuItem("Reset");
|
final JMenuItem reset = new JMenuItem("Reset");
|
||||||
reset.addActionListener(e ->
|
reset.addActionListener(e ->
|
||||||
@@ -541,6 +624,7 @@ class LootTrackerPanel extends PluginPanel
|
|||||||
|
|
||||||
overallKillsLabel.setText(htmlLabel("Total count: ", overallKills));
|
overallKillsLabel.setText(htmlLabel("Total count: ", overallKills));
|
||||||
overallGpLabel.setText(htmlLabel("Total value: ", overallGp));
|
overallGpLabel.setText(htmlLabel("Total value: ", overallGp));
|
||||||
|
updateCollapseText();
|
||||||
}
|
}
|
||||||
|
|
||||||
private static String htmlLabel(String key, long value)
|
private static String htmlLabel(String key, long value)
|
||||||
|
|||||||
Binary file not shown.
|
After Width: | Height: | Size: 131 B |
Binary file not shown.
|
After Width: | Height: | Size: 161 B |
Reference in New Issue
Block a user