Merge pull request #6153 from Abextm/loottracker-optimize
Optimize Loottracker
This commit is contained in:
@@ -63,9 +63,7 @@ class LootTrackerBox extends JPanel
|
|||||||
@Getter
|
@Getter
|
||||||
private final List<LootTrackerRecord> records = new ArrayList<>();
|
private final List<LootTrackerRecord> records = new ArrayList<>();
|
||||||
|
|
||||||
@Getter
|
|
||||||
private long totalPrice;
|
private long totalPrice;
|
||||||
|
|
||||||
private boolean hideIgnoredItems;
|
private boolean hideIgnoredItems;
|
||||||
private BiConsumer<String, Boolean> onItemToggle;
|
private BiConsumer<String, Boolean> onItemToggle;
|
||||||
|
|
||||||
@@ -116,7 +114,7 @@ class LootTrackerBox extends JPanel
|
|||||||
*
|
*
|
||||||
* @return total amount of kills
|
* @return total amount of kills
|
||||||
*/
|
*/
|
||||||
long getTotalKills()
|
private long getTotalKills()
|
||||||
{
|
{
|
||||||
return hideIgnoredItems
|
return hideIgnoredItems
|
||||||
? records.stream().filter(r -> !Arrays.stream(r.getItems()).allMatch(LootTrackerItem::isIgnored)).count()
|
? records.stream().filter(r -> !Arrays.stream(r.getItems()).allMatch(LootTrackerItem::isIgnored)).count()
|
||||||
@@ -162,12 +160,18 @@ class LootTrackerBox extends JPanel
|
|||||||
}
|
}
|
||||||
|
|
||||||
records.add(record);
|
records.add(record);
|
||||||
|
}
|
||||||
|
|
||||||
|
void rebuild()
|
||||||
|
{
|
||||||
buildItems();
|
buildItems();
|
||||||
|
|
||||||
priceLabel.setText(StackFormatter.quantityToStackSize(totalPrice) + " gp");
|
priceLabel.setText(StackFormatter.quantityToStackSize(totalPrice) + " gp");
|
||||||
if (records.size() > 1)
|
|
||||||
|
final long kills = getTotalKills();
|
||||||
|
if (kills > 1)
|
||||||
{
|
{
|
||||||
subTitleLabel.setText("x " + records.size());
|
subTitleLabel.setText("x " + kills);
|
||||||
}
|
}
|
||||||
|
|
||||||
repaint();
|
repaint();
|
||||||
|
|||||||
@@ -53,6 +53,8 @@ import net.runelite.client.util.StackFormatter;
|
|||||||
|
|
||||||
class LootTrackerPanel extends PluginPanel
|
class LootTrackerPanel extends PluginPanel
|
||||||
{
|
{
|
||||||
|
private static final int MAX_LOOT_BOXES = 500;
|
||||||
|
|
||||||
private static final ImageIcon SINGLE_LOOT_VIEW;
|
private static final ImageIcon SINGLE_LOOT_VIEW;
|
||||||
private static final ImageIcon SINGLE_LOOT_VIEW_FADED;
|
private static final ImageIcon SINGLE_LOOT_VIEW_FADED;
|
||||||
private static final ImageIcon SINGLE_LOOT_VIEW_HOVER;
|
private static final ImageIcon SINGLE_LOOT_VIEW_HOVER;
|
||||||
@@ -325,7 +327,12 @@ class LootTrackerPanel extends PluginPanel
|
|||||||
final String subTitle = actorLevel > -1 ? "(lvl-" + actorLevel + ")" : "";
|
final String subTitle = actorLevel > -1 ? "(lvl-" + actorLevel + ")" : "";
|
||||||
final LootTrackerRecord record = new LootTrackerRecord(eventName, subTitle, items, System.currentTimeMillis());
|
final LootTrackerRecord record = new LootTrackerRecord(eventName, subTitle, items, System.currentTimeMillis());
|
||||||
records.add(record);
|
records.add(record);
|
||||||
buildBox(record);
|
LootTrackerBox box = buildBox(record);
|
||||||
|
if (box != null)
|
||||||
|
{
|
||||||
|
box.rebuild();
|
||||||
|
updateOverall();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -380,7 +387,16 @@ class LootTrackerPanel extends PluginPanel
|
|||||||
{
|
{
|
||||||
logsContainer.removeAll();
|
logsContainer.removeAll();
|
||||||
boxes.clear();
|
boxes.clear();
|
||||||
records.forEach(this::buildBox);
|
int start = 0;
|
||||||
|
if (!groupLoot && records.size() > MAX_LOOT_BOXES)
|
||||||
|
{
|
||||||
|
start = records.size() - MAX_LOOT_BOXES;
|
||||||
|
}
|
||||||
|
for (int i = start; i < records.size(); i++)
|
||||||
|
{
|
||||||
|
buildBox(records.get(i));
|
||||||
|
}
|
||||||
|
boxes.forEach(LootTrackerBox::rebuild);
|
||||||
updateOverall();
|
updateOverall();
|
||||||
logsContainer.revalidate();
|
logsContainer.revalidate();
|
||||||
logsContainer.repaint();
|
logsContainer.repaint();
|
||||||
@@ -391,12 +407,12 @@ class LootTrackerPanel extends PluginPanel
|
|||||||
* add its items to it, updating the log's overall price and kills. If not, a new log will be created
|
* add its items to it, updating the log's overall price and kills. If not, a new log will be created
|
||||||
* to hold this entry's information.
|
* to hold this entry's information.
|
||||||
*/
|
*/
|
||||||
private void buildBox(LootTrackerRecord record)
|
private LootTrackerBox buildBox(LootTrackerRecord record)
|
||||||
{
|
{
|
||||||
// If this record is not part of current view, return
|
// If this record is not part of current view, return
|
||||||
if (!record.matches(currentView))
|
if (!record.matches(currentView))
|
||||||
{
|
{
|
||||||
return;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Group all similar loot together
|
// Group all similar loot together
|
||||||
@@ -407,8 +423,7 @@ class LootTrackerPanel extends PluginPanel
|
|||||||
if (box.matches(record))
|
if (box.matches(record))
|
||||||
{
|
{
|
||||||
box.combine(record);
|
box.combine(record);
|
||||||
updateOverall();
|
return box;
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -456,14 +471,45 @@ class LootTrackerPanel extends PluginPanel
|
|||||||
boxes.add(box);
|
boxes.add(box);
|
||||||
logsContainer.add(box, 0);
|
logsContainer.add(box, 0);
|
||||||
|
|
||||||
// Update overall
|
if (!groupLoot && boxes.size() > MAX_LOOT_BOXES)
|
||||||
updateOverall();
|
{
|
||||||
|
logsContainer.remove(boxes.remove(0));
|
||||||
|
}
|
||||||
|
|
||||||
|
return box;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void updateOverall()
|
private void updateOverall()
|
||||||
{
|
{
|
||||||
final long overallGp = boxes.stream().mapToLong(LootTrackerBox::getTotalPrice).sum();
|
long overallKills = 0;
|
||||||
final long overallKills = boxes.stream().mapToLong(LootTrackerBox::getTotalKills).sum();
|
long overallGp = 0;
|
||||||
|
|
||||||
|
for (LootTrackerRecord record : records)
|
||||||
|
{
|
||||||
|
if (!record.matches(currentView))
|
||||||
|
{
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
int present = record.getItems().length;
|
||||||
|
|
||||||
|
for (LootTrackerItem item : record.getItems())
|
||||||
|
{
|
||||||
|
if (hideIgnoredItems && item.isIgnored())
|
||||||
|
{
|
||||||
|
present--;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
overallGp += item.getPrice();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (present > 0)
|
||||||
|
{
|
||||||
|
overallKills++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
overallKillsLabel.setText(htmlLabel("Total count: ", overallKills));
|
overallKillsLabel.setText(htmlLabel("Total count: ", overallKills));
|
||||||
overallGpLabel.setText(htmlLabel("Total value: ", overallGp));
|
overallGpLabel.setText(htmlLabel("Total value: ", overallGp));
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user