Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Auto Layout Improvements #101

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
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
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ repositories {
mavenCentral()
}

def runeLiteVersion = '1.10.34'
def runeLiteVersion = '1.10.40'

dependencies {
compileOnly group: 'net.runelite', name:'client', version: runeLiteVersion
Expand Down
11 changes: 11 additions & 0 deletions src/main/java/com/banktaglayouts/BankTagLayoutsConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,17 @@ default boolean showAutoLayoutButton() {
return true;
}

@ConfigItem(
keyName = "addNewItemsToEnd",
name = "Add New Items to End",
description = "Enabling this will add new items and variations to the end of your layout instead of the beginning.",
position = 6,
section = autoLayout
)
default boolean addNewItemsToEnd() {
return false;
}

@ConfigItem(
keyName = "showCoreRuneliteLayoutOptions",
name = "RuneLite layouts options",
Expand Down
52 changes: 43 additions & 9 deletions src/main/java/com/banktaglayouts/BankTagLayoutsPlugin.java
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,11 @@ public class BankTagLayoutsPlugin extends Plugin implements MouseListener
public static final String EXPORT_LAYOUT = "Export tag tab with layout";
public static final String REMOVE_FROM_LAYOUT_MENU_OPTION = "Remove-layout";
public static final String PREVIEW_AUTO_LAYOUT = "Preview auto layout";
public static final String SET_ZIGZAG = "Set zigzag";
public static final String SET_ZIGZAG_INVASIVE = "Set zigzag (Fresh)";
public static final String SET_PRESETS = "Set presets";
public static final String SET_PRESETS_INVASIVE = "Set presets (Fresh)";
public static final String RESET_LAYOUT = "Reset Layout";
public static final String DUPLICATE_ITEM = "Duplicate-item";
public static final String REMOVE_DUPLICATE_ITEM = "Remove-duplicate-item";

Expand Down Expand Up @@ -193,10 +198,38 @@ private void updateButton() {
showLayoutPreviewButton.setOriginalY(45);
showLayoutPreviewButton.setSpriteId(Sprites.AUTO_LAYOUT.getSpriteId());

showLayoutPreviewButton.setOnOpListener((JavaScriptCallback) (e) -> showLayoutPreview());
showLayoutPreviewButton.setOnOpListener((JavaScriptCallback) (e) ->
{
//action index + 1 = op
int op = e.getOp();
if (op == 1)
{
showLayoutPreview(BankTagLayoutsConfig.LayoutStyles.ZIGZAG, false);
}
else if (op == 2)
{
showLayoutPreview(BankTagLayoutsConfig.LayoutStyles.ZIGZAG, true);
}
if (op == 3)
{
showLayoutPreview(BankTagLayoutsConfig.LayoutStyles.PRESETS, false);
}
else if (op == 4)
{
showLayoutPreview(BankTagLayoutsConfig.LayoutStyles.PRESETS, true);
}
else
{
showLayoutPreview(null, true);
}
});
showLayoutPreviewButton.setHasListener(true);
showLayoutPreviewButton.revalidate();
showLayoutPreviewButton.setAction(0, PREVIEW_AUTO_LAYOUT);
showLayoutPreviewButton.setAction(0, SET_ZIGZAG);
showLayoutPreviewButton.setAction(1, SET_ZIGZAG_INVASIVE);
showLayoutPreviewButton.setAction(2, SET_PRESETS);
showLayoutPreviewButton.setAction(3, SET_PRESETS_INVASIVE);
showLayoutPreviewButton.setAction(4, RESET_LAYOUT);

applyLayoutPreviewButton = parent.createChild(-1, WidgetType.GRAPHIC);

Expand Down Expand Up @@ -491,7 +524,7 @@ private void cancelLayoutPreview() {

private final InventorySetupsAdapter inventorySetupsAdapter = new InventorySetupsAdapter(this);

private void showLayoutPreview() {
private void showLayoutPreview(BankTagLayoutsConfig.LayoutStyles styleToUse, boolean invasive) {

if (isShowingPreview()) return;
LayoutableThing currentLayoutableThing = getCurrentLayoutableThing();
Expand All @@ -518,14 +551,14 @@ private void showLayoutPreview() {
Layout currentLayout = getBankOrderNonPreview(currentLayoutableThing);
if (currentLayout == null) currentLayout = Layout.emptyLayout();

previewLayout = layoutGenerator.basicBankTagLayout(equippedGear, inventory, config.autoLayoutIncludeRunePouchRunes() ? getRunePouchRunes() : Collections.emptyList(), Collections.emptyList(), currentLayout, getAutoLayoutDuplicateLimit(), config.autoLayoutStyle());
previewLayout = layoutGenerator.basicBankTagLayout(equippedGear, inventory, config.autoLayoutIncludeRunePouchRunes() ? getRunePouchRunes() : Collections.emptyList(), Collections.emptyList(), invasive ? Layout.emptyLayout() : currentLayout, getAutoLayoutDuplicateLimit(), styleToUse);
} else {
InventorySetup inventorySetup = inventorySetupsAdapter.getInventorySetup(currentLayoutableThing.name);

Layout currentLayout = getBankOrderNonPreview(currentLayoutableThing);
if (currentLayout == null) currentLayout = Layout.emptyLayout();

previewLayout = layoutGenerator.basicInventorySetupsLayout(inventorySetup, currentLayout, getAutoLayoutDuplicateLimit(), config.autoLayoutStyle(), config.autoLayoutIncludeRunePouchRunes());
previewLayout = layoutGenerator.basicInventorySetupsLayout(inventorySetup, invasive ? Layout.emptyLayout() : currentLayout, getAutoLayoutDuplicateLimit(), styleToUse, config.autoLayoutIncludeRunePouchRunes());
}

hideLayoutPreviewButtons(false);
Expand Down Expand Up @@ -1040,7 +1073,7 @@ private void assignNonVariantItemPositions(Layout layout, List<Widget> bankItems

if (indexForItem == -1) {
// The item is not in the layout.
indexForItem = layout.getFirstEmptyIndex();
indexForItem = config.addNewItemsToEnd() ? layout.getLastEmptyIndex() : layout.getFirstEmptyIndex();
layout.putItem(itemId, indexForItem);
}
indexToWidget.put(indexForItem, bankItem);
Expand Down Expand Up @@ -1423,7 +1456,7 @@ public void onMenuOptionClicked(MenuOptionClicked event)
} else if (IMPORT_LAYOUT.equals(menuOption)) {
importLayout();
} else if (PREVIEW_AUTO_LAYOUT.equals(menuOption)) {
showLayoutPreview();
showLayoutPreview(config.autoLayoutStyle(), false);
} else if (DUPLICATE_ITEM.equals(menuOption)) {
duplicateItem(event.getParam0());
} else if (REMOVE_DUPLICATE_ITEM.equals(menuOption)) {
Expand Down Expand Up @@ -1504,6 +1537,7 @@ private void assignVariantItemPositions(Layout layout, List<Widget> bankItems, M
}
}

int afterIndex = config.addNewItemsToEnd() ? (layout.getFirstEmptyRow() - 1) : -1;
for (Integer variationBaseId : variantItemsInBank.keySet()) {
List<Widget> notYetPositionedWidgets = new ArrayList<>(variantItemsInBank.get(variationBaseId));

Expand Down Expand Up @@ -1532,7 +1566,7 @@ private void assignVariantItemPositions(Layout layout, List<Widget> bankItems, M
int itemId = notYetPositionedWidget.getItemId();
int layoutIndex = layout.getIndexForItem(itemId);
if (layoutIndex != -1) continue; // Prevents an issue where items with the same id that take up multiple bank slots, e.g. items that have their charges stored on the item, can be added into two slots during this stage.
int index = layout.getFirstEmptyIndex();
int index = layout.getFirstEmptyIndex(afterIndex);
layout.putItem(itemId, index);
log.debug("item " + itemNameWithId(itemId) + " assigned on pass 4 (assign to empty spot) to index " + index);
indexToWidget.put(index, notYetPositionedWidget);
Expand Down Expand Up @@ -1909,7 +1943,7 @@ public void onMenuShouldLeftClick(MenuShouldLeftClick event)
for (MenuEntry entry : menuEntries)
{
// checking the type is kinda hacky because really both preview auto layout entries should have the runelite id... but it works.
if (entry.getOption().equals(PREVIEW_AUTO_LAYOUT) && entry.getType() != MenuAction.RUNELITE)
if (entry.getOption().equals(SET_ZIGZAG) && entry.getType() != MenuAction.RUNELITE)
{
event.setForceRightClick(true);
return;
Expand Down
13 changes: 13 additions & 0 deletions src/main/java/com/banktaglayouts/Layout.java
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,19 @@ public int getFirstEmptyIndex() {
return getFirstEmptyIndex(-1);
}

public int getLastEmptyIndex() {
int maxIndex = getAllUsedIndexes().stream().max(Integer::compare).orElse(-1);
return maxIndex + 1;
}

public int getFirstEmptyRow() {
int maxIndex = getAllUsedIndexes().stream().max(Integer::compare).orElse(-1);
maxIndex++;
while (maxIndex % 8 != 0)
maxIndex++;
return maxIndex;
}

public int getFirstEmptyIndex(int afterThisIndex) {
List<Integer> indexes = new ArrayList<>(getAllUsedIndexes());
indexes.sort(Integer::compare);
Expand Down
12 changes: 10 additions & 2 deletions src/main/java/com/banktaglayouts/LayoutGenerator.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,16 @@ public Layout generateLayout(List<Integer> equippedItems, List<Integer> inventor
runePouch = null;
}
equippedItems = equippedItems.stream()
.map(itemId -> plugin.itemManager.canonicalize(itemId)) // Weight reducing items have different ids when equipped; this fixes that.
.collect(Collectors.toList());
.map(itemId -> plugin.itemManager.canonicalize(itemId)) // Weight reducing items have different ids when equipped; this fixes that.
.collect(Collectors.toList());
inventory = inventory.stream()
.map(itemId -> plugin.itemManager.canonicalize(itemId)) // You can't have noted items in your bank
.collect(Collectors.toList());

if (layoutStyle == null)
{
return Layout.emptyLayout();
}

switch (layoutStyle){
case ZIGZAG:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,10 @@ public static int map(final Integer id)
mappings.put(GHOMMALS_AVERNIC_DEFENDER_5_L, AVERNIC_DEFENDER);
mappings.put(GHOMMALS_AVERNIC_DEFENDER_6, AVERNIC_DEFENDER);
mappings.put(GHOMMALS_AVERNIC_DEFENDER_6_L, AVERNIC_DEFENDER);

// Blazing blowpipe -> toxic blowpipe
mappings.put(BLAZING_BLOWPIPE_EMPTY, TOXIC_BLOWPIPE_EMPTY);
mappings.put(BLAZING_BLOWPIPE, TOXIC_BLOWPIPE);
}

}