Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 0 additions & 4 deletions src/main/java/inventorysetups/InventorySetupsItem.java
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,6 @@ public class InventorySetupsItem
@Setter
private InventorySetupsStackCompareID stackCompare;

public void toggleIsFuzzy()
{
fuzzy = !fuzzy;
}

public static InventorySetupsItem getDummyItem()
{
Expand Down
115 changes: 72 additions & 43 deletions src/main/java/inventorysetups/InventorySetupsPlugin.java
Original file line number Diff line number Diff line change
Expand Up @@ -1495,7 +1495,7 @@ public void updateSlotFromSearch(final InventorySetupsSlot slot, boolean allowSt
panel.getCurrentSelectedSetup().getAdditionalFilteredItems();
if (!additionalFilteredItemsHasItem(finalId, additionalFilteredItems))
{
removeAdditionalFilteredItem(slot, additionalFilteredItems);
removeAdditionalFilteredItem(slot);
addAdditionalFilteredItem(finalId, slot.getParentSetup(), additionalFilteredItems);
}
return;
Comment thread
dillydill123 marked this conversation as resolved.
Expand Down Expand Up @@ -1608,14 +1608,18 @@ public void removeItemFromSlot(final InventorySetupsSlot slot)
JOptionPane.ERROR_MESSAGE);
return;
}
if (panel.getCurrentSelectedSetup() == null)
{
return;
}

// must be invoked on client thread to get the name
clientThread.invokeLater(() ->
{

if (slot.getSlotID() == InventorySetupsSlotID.ADDITIONAL_ITEMS)
{
removeAdditionalFilteredItem(slot, panel.getCurrentSelectedSetup().getAdditionalFilteredItems());
removeAdditionalFilteredItem(slot);
layoutUtilities.recalculateLayout(panel.getCurrentSelectedSetup());
dataManager.updateConfig(true, false);
panel.refreshCurrentSetup();
Expand All @@ -1642,58 +1646,70 @@ public void removeItemFromSlot(final InventorySetupsSlot slot)
});
}

public void toggleFuzzyOnSlot(final InventorySetupsSlot slot)
public void toggleAllFuzzyOnSlot(final InventorySetupsSlot slot)
Comment thread
Dragonkiller93 marked this conversation as resolved.
{
if (panel.getCurrentSelectedSetup() == null)
{
return;
}

InventorySetupsItem item = null;

final InventorySetup inventorySetup = slot.getParentSetup();
InventorySetupsItem originalItem;
//If an additional slot was clicked
if (slot.getSlotID() == InventorySetupsSlotID.ADDITIONAL_ITEMS)
{
// Empty slot was selected to be toggled, don't do anything
if (slot.getIndexInSlot() >= slot.getParentSetup().getAdditionalFilteredItems().size())
Integer keyToToggle = getAdditionalItemKey(slot);
if (keyToToggle == null)
{
return;
}

final Map<Integer, InventorySetupsItem> additionalFilteredItems = slot.getParentSetup().getAdditionalFilteredItems();
final int slotID = slot.getIndexInSlot();
int j = 0;
Integer keyToMakeFuzzy = null;
for (final Integer key : additionalFilteredItems.keySet())
{
if (slotID == j)
{
keyToMakeFuzzy = key;
break;
}
j++;
else{
Comment thread
Dragonkiller93 marked this conversation as resolved.
originalItem = inventorySetup.getAdditionalFilteredItems().get(keyToToggle);
}
item = additionalFilteredItems.get(keyToMakeFuzzy);
}
else
else{
Comment thread
Dragonkiller93 marked this conversation as resolved.
originalItem = getContainerFromSlot(slot).get(slot.getIndexInSlot());
}
if (originalItem.getId() == -1)
{
final List<InventorySetupsItem> container = getContainerFromSlot(slot);
item = container.get(slot.getIndexInSlot());
return;
}
item.toggleIsFuzzy();
final int itemId = item.getId();
boolean newFuzzyValue = !originalItem.isFuzzy();

//has to be in client to use itemManager
Comment thread
Dragonkiller93 marked this conversation as resolved.
clientThread.invoke(() ->
{
if (itemId == -1)
//Find all variations of the item, so they can also be toggled
Comment thread
Dragonkiller93 marked this conversation as resolved.
int processedId = itemManager.canonicalize(originalItem.getId());
int baseProcessedId = InventorySetupsVariationMapping.map(processedId);
Collection<Integer> variations = InventorySetupsVariationMapping.getVariations(baseProcessedId);
variations.add(processedId);
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do you need to add the processedId here? Shouldn't variations contain it already?


Consumer<InventorySetupsItem> toggleFuzzyIfMatched = item ->
{
return;
if (variations.contains(item.getId()))
{
item.setFuzzy(newFuzzyValue);
}
};

inventorySetup.getInventory().forEach(toggleFuzzyIfMatched);

Comment thread
Dragonkiller93 marked this conversation as resolved.
inventorySetup.getEquipment().forEach(toggleFuzzyIfMatched);
inventorySetup.getAdditionalFilteredItems().values().forEach(toggleFuzzyIfMatched);

Comment thread
Dragonkiller93 marked this conversation as resolved.
if (inventorySetup.getQuiver() != null)
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you need to also consider the bolt pouch and rune pouch. The InventorySetup needs a nicer/extendable interface for "Containers" but that's a different problem

{
inventorySetup.getQuiver().forEach(toggleFuzzyIfMatched);
}

layoutUtilities.recalculateLayout(slot.getParentSetup());
dataManager.updateConfig(true, false);
panel.refreshCurrentSetup();
});

dataManager.updateConfig(true, false);
panel.refreshCurrentSetup();
}

}
public void setStackCompareOnSlot(final InventorySetupsSlot slot, final InventorySetupsStackCompareID newStackCompare)
{
if (panel.getCurrentSelectedSetup() == null)
Expand All @@ -1708,32 +1724,45 @@ public void setStackCompareOnSlot(final InventorySetupsSlot slot, final Inventor
panel.refreshCurrentSetup();
}

private void removeAdditionalFilteredItem(final InventorySetupsSlot slot, final Map<Integer, InventorySetupsItem> additionalFilteredItems)
private Integer getAdditionalItemKey(final InventorySetupsSlot slot)
{

assert panel.getCurrentSelectedSetup() != null : "Current setup is null";

final int slotID = slot.getIndexInSlot();

// Empty slot was selected to be removed, don't do anything
if (slotID >= additionalFilteredItems.size())
final Map<Integer, InventorySetupsItem> additionalFilteredItems = slot.getParentSetup().getAdditionalFilteredItems();
// Empty slot was selected to be toggled, don't do anything
if (slot.getIndexInSlot() >= additionalFilteredItems.size())
{
return;
return null;
}


final int slotID = slot.getIndexInSlot();
int j = 0;
Integer keyToDelete = null;
Integer keyToMakeFuzzy = null;
for (final Integer key : additionalFilteredItems.keySet())
{
if (slotID == j)
{
keyToDelete = key;
keyToMakeFuzzy = key;
break;
}
j++;
}
return keyToMakeFuzzy;
}
private void removeAdditionalFilteredItem(final InventorySetupsSlot slot)
{

if (panel.getCurrentSelectedSetup() == null)
{
return;
}

Integer keyToDelete = getAdditionalItemKey(slot);
if (keyToDelete == null)
{
return;
}

additionalFilteredItems.remove(keyToDelete);
slot.getParentSetup().getAdditionalFilteredItems().remove(keyToDelete);
// None of the data functions are called here because the callee does it.
// If an item is swapped (removed + added) this would result in a double data process
// Which isn't bad, just a minor optimization
Expand Down
3 changes: 1 addition & 2 deletions src/main/java/inventorysetups/ui/InventorySetupsSlot.java
Original file line number Diff line number Diff line change
Expand Up @@ -254,10 +254,9 @@ public static void addFuzzyMouseListenerToSlot(final InventorySetupsPlugin plugi
slot.getRightClickMenu().add(makeSlotFuzzy);
makeSlotFuzzy.addActionListener(e ->
{
plugin.toggleFuzzyOnSlot(slot);
plugin.toggleAllFuzzyOnSlot(slot);
Comment thread
Dragonkiller93 marked this conversation as resolved.
});
}

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bring back this newline

// adds the menu option to update set a slot to fuzzy
public static void addStackMouseListenerToSlot(final InventorySetupsPlugin plugin, final InventorySetupsSlot slot)
{
Expand Down