Add scrollwheel resizing for individual spells (#160)
* Remove mouselistener if plugin is stopped while dragging spells * Scrollwheel resizing for spellbook plugin * Make sure config changes run rebuild script on client thread
This commit is contained in:
@@ -34,5 +34,6 @@ class Spell
|
|||||||
private int widget;
|
private int widget;
|
||||||
private int x;
|
private int x;
|
||||||
private int y;
|
private int y;
|
||||||
|
private int size;
|
||||||
private String name;
|
private String name;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -53,11 +53,22 @@ public interface SpellbookConfig extends Config
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ConfigItem(
|
||||||
|
keyName = "scroll",
|
||||||
|
name = "Scrollwheel resizing",
|
||||||
|
description = "Resize spells by scrolling your scrollwheel over them, reset with scrollwheel click",
|
||||||
|
position = 3
|
||||||
|
)
|
||||||
|
default boolean scroll()
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
@ConfigItem(
|
@ConfigItem(
|
||||||
keyName = "size",
|
keyName = "size",
|
||||||
name = "Spell size",
|
name = "Spell size",
|
||||||
description = "Size (in px) of spells. Normal mobile size is 40px, use common sense for this setting please",
|
description = "Size (in px) of spells. Normal mobile size is 40px, use common sense for this setting please",
|
||||||
position = 3
|
position = 4
|
||||||
)
|
)
|
||||||
default int size()
|
default int size()
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -25,10 +25,12 @@
|
|||||||
package net.runelite.client.plugins.spellbook;
|
package net.runelite.client.plugins.spellbook;
|
||||||
|
|
||||||
import java.awt.event.MouseEvent;
|
import java.awt.event.MouseEvent;
|
||||||
|
import java.awt.event.MouseWheelEvent;
|
||||||
import javax.swing.SwingUtilities;
|
import javax.swing.SwingUtilities;
|
||||||
import net.runelite.client.input.MouseAdapter;
|
import net.runelite.client.input.MouseAdapter;
|
||||||
|
import net.runelite.client.input.MouseWheelListener;
|
||||||
|
|
||||||
public class SpellbookMouseListener extends MouseAdapter
|
public class SpellbookMouseListener extends MouseAdapter implements MouseWheelListener
|
||||||
{
|
{
|
||||||
private final SpellbookPlugin plugin;
|
private final SpellbookPlugin plugin;
|
||||||
|
|
||||||
@@ -40,11 +42,16 @@ public class SpellbookMouseListener extends MouseAdapter
|
|||||||
@Override
|
@Override
|
||||||
public MouseEvent mouseClicked(MouseEvent event)
|
public MouseEvent mouseClicked(MouseEvent event)
|
||||||
{
|
{
|
||||||
if (SwingUtilities.isMiddleMouseButton(event) || !plugin.isOnSpellWidget(event.getPoint()))
|
if (!plugin.isOnSpellWidget(event.getPoint()))
|
||||||
{
|
{
|
||||||
return event;
|
return event;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (SwingUtilities.isMiddleMouseButton(event))
|
||||||
|
{
|
||||||
|
plugin.resetZoom(event.getPoint());
|
||||||
|
}
|
||||||
|
|
||||||
event.consume();
|
event.consume();
|
||||||
return event;
|
return event;
|
||||||
}
|
}
|
||||||
@@ -76,4 +83,27 @@ public class SpellbookMouseListener extends MouseAdapter
|
|||||||
event.consume();
|
event.consume();
|
||||||
return event;
|
return event;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public MouseWheelEvent mouseWheelMoved(MouseWheelEvent event)
|
||||||
|
{
|
||||||
|
if (!plugin.isOnSpellWidget(event.getPoint()))
|
||||||
|
{
|
||||||
|
return event;
|
||||||
|
}
|
||||||
|
|
||||||
|
int direction = event.getWheelRotation();
|
||||||
|
|
||||||
|
if (direction > 0)
|
||||||
|
{
|
||||||
|
plugin.increaseSize(event.getPoint());
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
plugin.decreaseSize(event.getPoint());
|
||||||
|
}
|
||||||
|
|
||||||
|
event.consume();
|
||||||
|
return event;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -116,6 +116,7 @@ public class SpellbookPlugin extends Plugin
|
|||||||
private Point draggingLocation;
|
private Point draggingLocation;
|
||||||
|
|
||||||
private Map<Integer, Spell> spells = new HashMap<>();
|
private Map<Integer, Spell> spells = new HashMap<>();
|
||||||
|
private Map<Integer, Spell> tmp = null;
|
||||||
private List<String> notFilteredSpells = new ArrayList<>();
|
private List<String> notFilteredSpells = new ArrayList<>();
|
||||||
private Spellbook spellbook;
|
private Spellbook spellbook;
|
||||||
private SpellbookMouseListener mouseListener;
|
private SpellbookMouseListener mouseListener;
|
||||||
@@ -142,6 +143,9 @@ public class SpellbookPlugin extends Plugin
|
|||||||
saveSpells();
|
saveSpells();
|
||||||
config.canDrag(false);
|
config.canDrag(false);
|
||||||
mouseManager.unregisterMouseListener(mouseListener);
|
mouseManager.unregisterMouseListener(mouseListener);
|
||||||
|
|
||||||
|
mouseManager.unregisterMouseWheelListener(mouseListener);
|
||||||
|
|
||||||
mouseListener = null;
|
mouseListener = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -173,7 +177,7 @@ public class SpellbookPlugin extends Plugin
|
|||||||
loadFilter();
|
loadFilter();
|
||||||
}
|
}
|
||||||
|
|
||||||
runRebuild();
|
clientThread.invokeLater(this::runRebuild);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Subscribe
|
@Subscribe
|
||||||
@@ -206,6 +210,11 @@ public class SpellbookPlugin extends Plugin
|
|||||||
|
|
||||||
if ("startSpellRedraw".equals(event.getEventName()))
|
if ("startSpellRedraw".equals(event.getEventName()))
|
||||||
{
|
{
|
||||||
|
if (config.canDrag())
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
spellbook = Spellbook.getByID(client.getVar(Varbits.SPELLBOOK));
|
spellbook = Spellbook.getByID(client.getVar(Varbits.SPELLBOOK));
|
||||||
loadSpells();
|
loadSpells();
|
||||||
}
|
}
|
||||||
@@ -221,6 +230,7 @@ public class SpellbookPlugin extends Plugin
|
|||||||
s.setWidget(widget);
|
s.setWidget(widget);
|
||||||
s.setX(-1);
|
s.setX(-1);
|
||||||
s.setY(-1);
|
s.setY(-1);
|
||||||
|
s.setSize(0);
|
||||||
s.setName(spell);
|
s.setName(spell);
|
||||||
|
|
||||||
spells.put(widget, s);
|
spells.put(widget, s);
|
||||||
@@ -255,6 +265,29 @@ public class SpellbookPlugin extends Plugin
|
|||||||
iStack[iStackSize - 1] = FULL_HEIGHT;
|
iStack[iStackSize - 1] = FULL_HEIGHT;
|
||||||
iStack[iStackSize - 2] = FULL_WIDTH;
|
iStack[iStackSize - 2] = FULL_WIDTH;
|
||||||
}
|
}
|
||||||
|
else if ("resizeIndividualSpells".equals(event.getEventName()))
|
||||||
|
{
|
||||||
|
int widget = iStack[iStackSize - 1];
|
||||||
|
int visCount =
|
||||||
|
(int) spells.values().stream()
|
||||||
|
.map(Spell::getName)
|
||||||
|
.filter(s -> notFilteredSpells
|
||||||
|
.stream()
|
||||||
|
.anyMatch(s::contains))
|
||||||
|
.count();
|
||||||
|
|
||||||
|
|
||||||
|
if (visCount > 20 || visCount == 0)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
Spell spell = spells.get(widget);
|
||||||
|
int newSize = spell.getSize() * 5 + config.size();
|
||||||
|
|
||||||
|
iStack[iStackSize - 2] = newSize;
|
||||||
|
iStack[iStackSize - 3] = newSize;
|
||||||
|
}
|
||||||
else if ("setSpellPosition".equals(event.getEventName()))
|
else if ("setSpellPosition".equals(event.getEventName()))
|
||||||
{
|
{
|
||||||
if (!config.dragSpells())
|
if (!config.dragSpells())
|
||||||
@@ -293,12 +326,21 @@ public class SpellbookPlugin extends Plugin
|
|||||||
config.canDrag(true);
|
config.canDrag(true);
|
||||||
overlayManager.add(overlay);
|
overlayManager.add(overlay);
|
||||||
mouseManager.registerMouseListener(mouseListener);
|
mouseManager.registerMouseListener(mouseListener);
|
||||||
|
tmp = new HashMap<>();
|
||||||
|
|
||||||
|
if (config.scroll())
|
||||||
|
{
|
||||||
|
mouseManager.registerMouseWheelListener(mouseListener);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else if (event.getMenuOption().equals(LOCK))
|
else if (event.getMenuOption().equals(LOCK))
|
||||||
{
|
{
|
||||||
config.canDrag(false);
|
config.canDrag(false);
|
||||||
overlayManager.remove(overlay);
|
overlayManager.remove(overlay);
|
||||||
mouseManager.unregisterMouseListener(mouseListener);
|
mouseManager.unregisterMouseListener(mouseListener);
|
||||||
|
mouseManager.unregisterMouseWheelListener(mouseListener);
|
||||||
|
saveSpells();
|
||||||
|
tmp = null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -360,6 +402,11 @@ public class SpellbookPlugin extends Plugin
|
|||||||
Collection<Spell> gson = GSON.fromJson(cfg, new TypeToken<List<Spell>>(){}.getType());
|
Collection<Spell> gson = GSON.fromJson(cfg, new TypeToken<List<Spell>>(){}.getType());
|
||||||
// CHECKSTYLE:ON
|
// CHECKSTYLE:ON
|
||||||
gson.stream().filter(Objects::nonNull).forEach(s -> spells.put(s.getWidget(), s));
|
gson.stream().filter(Objects::nonNull).forEach(s -> spells.put(s.getWidget(), s));
|
||||||
|
|
||||||
|
if (tmp != null)
|
||||||
|
{
|
||||||
|
tmp.forEach((k, v) -> spells.replace(k, v));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void saveSpells()
|
private void saveSpells()
|
||||||
@@ -369,6 +416,8 @@ public class SpellbookPlugin extends Plugin
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
tmp.forEach((k, v) -> spells.replace(k, v));
|
||||||
|
|
||||||
String key = spellbook.getConfigKey();
|
String key = spellbook.getConfigKey();
|
||||||
|
|
||||||
configManager.setConfiguration("spellbook", key, GSON.toJson(spells.values()));
|
configManager.setConfiguration("spellbook", key, GSON.toJson(spells.values()));
|
||||||
@@ -395,25 +444,10 @@ public class SpellbookPlugin extends Plugin
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
for (int id : spells.keySet())
|
return currentWidget(point) != null;
|
||||||
{
|
|
||||||
Widget w = client.getWidget(WidgetInfo.TO_GROUP(id), WidgetInfo.TO_CHILD(id)); // lol very useful
|
|
||||||
|
|
||||||
if (w == null || notFilteredSpells.stream().noneMatch(spells.get(id).getName()::contains))
|
|
||||||
{
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (w.getBounds().contains(point))
|
|
||||||
{
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void startDragging(java.awt.Point point)
|
private Widget currentWidget(java.awt.Point point)
|
||||||
{
|
{
|
||||||
for (int id : spells.keySet())
|
for (int id : spells.keySet())
|
||||||
{
|
{
|
||||||
@@ -424,8 +458,19 @@ public class SpellbookPlugin extends Plugin
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
draggingWidget = w;
|
return w;
|
||||||
break;
|
}
|
||||||
|
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
void startDragging(java.awt.Point point)
|
||||||
|
{
|
||||||
|
draggingWidget = currentWidget(point);
|
||||||
|
|
||||||
|
if (draggingWidget == null)
|
||||||
|
{
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
Point widgetPos = draggingWidget.getCanvasLocation();
|
Point widgetPos = draggingWidget.getCanvasLocation();
|
||||||
@@ -471,11 +516,118 @@ public class SpellbookPlugin extends Plugin
|
|||||||
n.setX(x);
|
n.setX(x);
|
||||||
n.setY(y);
|
n.setY(y);
|
||||||
|
|
||||||
spells.replace(draggedID, n);
|
tmp.put(draggedID, n);
|
||||||
|
|
||||||
draggingWidget.setHidden(false);
|
draggingWidget.setHidden(false);
|
||||||
dragging = false;
|
dragging = false;
|
||||||
|
|
||||||
saveSpells();
|
runRebuild();
|
||||||
|
}
|
||||||
|
|
||||||
|
void resetZoom(java.awt.Point point)
|
||||||
|
{
|
||||||
|
Widget clickedWidget = currentWidget(point);
|
||||||
|
|
||||||
|
if (clickedWidget == null || !config.scroll())
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
int clickedWidgetId = clickedWidget.getId();
|
||||||
|
|
||||||
|
if (!spells.containsKey(clickedWidgetId))
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
Spell clickedSpell = spells.get(clickedWidgetId);
|
||||||
|
|
||||||
|
int oldSize = clickedSpell.getSize();
|
||||||
|
int tmpSize = tmp.get(clickedWidgetId).getSize();
|
||||||
|
|
||||||
|
if (tmpSize == 0 && oldSize == 0)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
clickedSpell.setSize(0);
|
||||||
|
|
||||||
|
clickedSpell.setX(clickedSpell.getX() + oldSize * 5 / 2);
|
||||||
|
clickedSpell.setY(clickedSpell.getY() + oldSize * 5 / 2);
|
||||||
|
|
||||||
|
tmp.put(clickedWidgetId, clickedSpell);
|
||||||
|
|
||||||
|
runRebuild();
|
||||||
|
}
|
||||||
|
|
||||||
|
void decreaseSize(java.awt.Point point)
|
||||||
|
{
|
||||||
|
Widget scrolledWidget = currentWidget(point);
|
||||||
|
|
||||||
|
if (scrolledWidget == null)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
int scrolledWidgetId = scrolledWidget.getId();
|
||||||
|
|
||||||
|
if (!spells.containsKey(scrolledWidgetId))
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
Spell scrolledSpell = spells.get(scrolledWidgetId);
|
||||||
|
|
||||||
|
scrolledSpell.setSize(scrolledSpell.getSize() + 1);
|
||||||
|
|
||||||
|
if (scrolledSpell.getSize() % 2 == 0)
|
||||||
|
{
|
||||||
|
scrolledSpell.setX(scrolledSpell.getX() - 3);
|
||||||
|
scrolledSpell.setY(scrolledSpell.getY() - 3);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
scrolledSpell.setX(scrolledSpell.getX() - 2);
|
||||||
|
scrolledSpell.setY(scrolledSpell.getY() - 2);
|
||||||
|
}
|
||||||
|
|
||||||
|
tmp.put(scrolledWidgetId, scrolledSpell);
|
||||||
|
|
||||||
|
runRebuild();
|
||||||
|
}
|
||||||
|
|
||||||
|
void increaseSize(java.awt.Point point)
|
||||||
|
{
|
||||||
|
Widget scrolledWidget = currentWidget(point);
|
||||||
|
|
||||||
|
if (scrolledWidget == null)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
int scrolledWidgetId = scrolledWidget.getId();
|
||||||
|
|
||||||
|
if (!spells.containsKey(scrolledWidgetId))
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
Spell scrolledSpell = spells.get(scrolledWidgetId);
|
||||||
|
scrolledSpell.setSize(scrolledSpell.getSize() - 1);
|
||||||
|
|
||||||
|
if (scrolledSpell.getSize() % 2 == 0)
|
||||||
|
{
|
||||||
|
scrolledSpell.setX(scrolledSpell.getX() + 3);
|
||||||
|
scrolledSpell.setY(scrolledSpell.getY() + 3);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
scrolledSpell.setX(scrolledSpell.getX() + 2);
|
||||||
|
scrolledSpell.setY(scrolledSpell.getY() + 2);
|
||||||
|
}
|
||||||
|
|
||||||
|
tmp.put(scrolledWidgetId, scrolledSpell);
|
||||||
|
|
||||||
|
runRebuild();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -705,6 +705,10 @@ LABEL611:
|
|||||||
istore 25
|
istore 25
|
||||||
iload 19
|
iload 19
|
||||||
iload 19
|
iload 19
|
||||||
|
iload 25
|
||||||
|
sconst "resizeIndividualSpells"
|
||||||
|
runelite_callback
|
||||||
|
pop_int
|
||||||
iconst 0
|
iconst 0
|
||||||
iconst 0
|
iconst 0
|
||||||
iload 25
|
iload 25
|
||||||
|
|||||||
Reference in New Issue
Block a user