api: fix finding widget parents and make isHidden check parent
This commit is contained in:
@@ -279,4 +279,9 @@ public class Client
|
|||||||
int value = settings[varbit.getIndex()];
|
int value = settings[varbit.getIndex()];
|
||||||
return varbit.get(value);
|
return varbit.get(value);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public XHashTable getComponentTable()
|
||||||
|
{
|
||||||
|
return new XHashTable(client.getComponentTable());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -49,6 +49,11 @@ public class Node
|
|||||||
return of(node.getPrevious());
|
return of(node.getPrevious());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public long getHash()
|
||||||
|
{
|
||||||
|
return node.getHash();
|
||||||
|
}
|
||||||
|
|
||||||
public static final Node of(net.runelite.rs.api.Node node)
|
public static final Node of(net.runelite.rs.api.Node node)
|
||||||
{
|
{
|
||||||
if (node == null)
|
if (node == null)
|
||||||
@@ -66,6 +71,11 @@ public class Node
|
|||||||
return new Renderable((net.runelite.rs.api.Renderable) node);
|
return new Renderable((net.runelite.rs.api.Renderable) node);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (node instanceof net.runelite.rs.api.WidgetNode)
|
||||||
|
{
|
||||||
|
return new WidgetNode((net.runelite.rs.api.WidgetNode) node);
|
||||||
|
}
|
||||||
|
|
||||||
return new Node(node);
|
return new Node(node);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
41
runelite-api/src/main/java/net/runelite/api/WidgetNode.java
Normal file
41
runelite-api/src/main/java/net/runelite/api/WidgetNode.java
Normal file
@@ -0,0 +1,41 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2017, Adam <Adam@sigterm.info>
|
||||||
|
* All rights reserved.
|
||||||
|
*
|
||||||
|
* Redistribution and use in source and binary forms, with or without
|
||||||
|
* modification, are permitted provided that the following conditions are met:
|
||||||
|
*
|
||||||
|
* 1. Redistributions of source code must retain the above copyright notice, this
|
||||||
|
* list of conditions and the following disclaimer.
|
||||||
|
* 2. Redistributions in binary form must reproduce the above copyright notice,
|
||||||
|
* this list of conditions and the following disclaimer in the documentation
|
||||||
|
* and/or other materials provided with the distribution.
|
||||||
|
*
|
||||||
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
||||||
|
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||||
|
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||||
|
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
|
||||||
|
* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||||
|
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||||
|
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
||||||
|
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||||
|
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||||
|
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
|
*/
|
||||||
|
package net.runelite.api;
|
||||||
|
|
||||||
|
public class WidgetNode extends Node
|
||||||
|
{
|
||||||
|
private final net.runelite.rs.api.WidgetNode widgetNode;
|
||||||
|
|
||||||
|
public WidgetNode(net.runelite.rs.api.WidgetNode widgetNode)
|
||||||
|
{
|
||||||
|
super(widgetNode);
|
||||||
|
this.widgetNode = widgetNode;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getId()
|
||||||
|
{
|
||||||
|
return widgetNode.getId();
|
||||||
|
}
|
||||||
|
}
|
||||||
61
runelite-api/src/main/java/net/runelite/api/XHashTable.java
Normal file
61
runelite-api/src/main/java/net/runelite/api/XHashTable.java
Normal file
@@ -0,0 +1,61 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2017, Adam <Adam@sigterm.info>
|
||||||
|
* All rights reserved.
|
||||||
|
*
|
||||||
|
* Redistribution and use in source and binary forms, with or without
|
||||||
|
* modification, are permitted provided that the following conditions are met:
|
||||||
|
*
|
||||||
|
* 1. Redistributions of source code must retain the above copyright notice, this
|
||||||
|
* list of conditions and the following disclaimer.
|
||||||
|
* 2. Redistributions in binary form must reproduce the above copyright notice,
|
||||||
|
* this list of conditions and the following disclaimer in the documentation
|
||||||
|
* and/or other materials provided with the distribution.
|
||||||
|
*
|
||||||
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
||||||
|
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||||
|
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||||
|
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
|
||||||
|
* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||||
|
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||||
|
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
||||||
|
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||||
|
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||||
|
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
|
*/
|
||||||
|
package net.runelite.api;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Collection;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
public class XHashTable
|
||||||
|
{
|
||||||
|
private final net.runelite.rs.api.XHashTable hashtable;
|
||||||
|
|
||||||
|
public XHashTable(net.runelite.rs.api.XHashTable hashtable)
|
||||||
|
{
|
||||||
|
this.hashtable = hashtable;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Collection<Node> getNodes()
|
||||||
|
{
|
||||||
|
List<Node> nodes = new ArrayList<>();
|
||||||
|
|
||||||
|
net.runelite.rs.api.Node[] buckets = hashtable.getBuckets();
|
||||||
|
for (int i = 0; i < buckets.length; ++i)
|
||||||
|
{
|
||||||
|
net.runelite.rs.api.Node node = buckets[i];
|
||||||
|
|
||||||
|
// It looks like the first node in the bucket is always
|
||||||
|
// a sentinel
|
||||||
|
net.runelite.rs.api.Node cur = node.getNext();
|
||||||
|
while (cur != node)
|
||||||
|
{
|
||||||
|
nodes.add(Node.of(cur));
|
||||||
|
cur = cur.getNext();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return nodes;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -29,7 +29,10 @@ import java.util.ArrayList;
|
|||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import net.runelite.api.Client;
|
import net.runelite.api.Client;
|
||||||
|
import net.runelite.api.Node;
|
||||||
import net.runelite.api.Point;
|
import net.runelite.api.Point;
|
||||||
|
import net.runelite.api.WidgetNode;
|
||||||
|
import net.runelite.api.XHashTable;
|
||||||
|
|
||||||
public class Widget
|
public class Widget
|
||||||
{
|
{
|
||||||
@@ -67,6 +70,40 @@ public class Widget
|
|||||||
return new Widget(client, parent);
|
return new Widget(client, parent);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Widget getParentFromId()
|
||||||
|
{
|
||||||
|
int id = getParentId();
|
||||||
|
if (id == -1)
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
return client.getWidget(id >>> 16, id & 0xFFFF);
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getParentId()
|
||||||
|
{
|
||||||
|
int parentId = widget.getParentId();
|
||||||
|
if (parentId != -1)
|
||||||
|
{
|
||||||
|
return parentId;
|
||||||
|
}
|
||||||
|
|
||||||
|
int i = getId() >>> 16;
|
||||||
|
XHashTable componentTable = client.getComponentTable();
|
||||||
|
for (Node node : componentTable.getNodes())
|
||||||
|
{
|
||||||
|
WidgetNode wn = (WidgetNode) node;
|
||||||
|
|
||||||
|
if (i == wn.getId())
|
||||||
|
{
|
||||||
|
return (int) wn.getHash();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
private int getRelativeX()
|
private int getRelativeX()
|
||||||
{
|
{
|
||||||
return widget.getRelativeX();
|
return widget.getRelativeX();
|
||||||
@@ -84,7 +121,8 @@ public class Widget
|
|||||||
|
|
||||||
public boolean isHidden()
|
public boolean isHidden()
|
||||||
{
|
{
|
||||||
return widget.isHidden();
|
Widget parent = getParentFromId();
|
||||||
|
return (parent != null && parent.isHidden()) || widget.isHidden();
|
||||||
}
|
}
|
||||||
|
|
||||||
public Point getCanvasLocation()
|
public Point getCanvasLocation()
|
||||||
|
|||||||
@@ -27,7 +27,7 @@ package net.runelite.rs.api;
|
|||||||
|
|
||||||
import net.runelite.mapping.Import;
|
import net.runelite.mapping.Import;
|
||||||
|
|
||||||
public interface WidgetNode
|
public interface WidgetNode extends Node
|
||||||
{
|
{
|
||||||
@Import("id")
|
@Import("id")
|
||||||
int getId();
|
int getId();
|
||||||
|
|||||||
@@ -25,7 +25,13 @@
|
|||||||
|
|
||||||
package net.runelite.rs.api;
|
package net.runelite.rs.api;
|
||||||
|
|
||||||
|
import net.runelite.mapping.Import;
|
||||||
|
|
||||||
public interface XHashTable
|
public interface XHashTable
|
||||||
{
|
{
|
||||||
//Node get(long var1);
|
@Import("size")
|
||||||
|
int getSize();
|
||||||
|
|
||||||
|
@Import("buckets")
|
||||||
|
Node[] getBuckets();
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user