Merge pull request #3813 from deathbeam/save-overlays-properly
Reduce code duplicity in resetOverlay method, fix overlay saving
This commit is contained in:
@@ -55,8 +55,12 @@ import net.runelite.client.plugins.PluginManager;
|
|||||||
import net.runelite.client.ui.ClientUI;
|
import net.runelite.client.ui.ClientUI;
|
||||||
import net.runelite.client.ui.DrawManager;
|
import net.runelite.client.ui.DrawManager;
|
||||||
import net.runelite.client.ui.TitleToolbar;
|
import net.runelite.client.ui.TitleToolbar;
|
||||||
|
import net.runelite.client.ui.overlay.OverlayManager;
|
||||||
import net.runelite.client.ui.overlay.OverlayRenderer;
|
import net.runelite.client.ui.overlay.OverlayRenderer;
|
||||||
import net.runelite.client.ui.overlay.infobox.InfoBoxManager;
|
import net.runelite.client.ui.overlay.infobox.InfoBoxManager;
|
||||||
|
import net.runelite.client.ui.overlay.infobox.InfoBoxOverlay;
|
||||||
|
import net.runelite.client.ui.overlay.tooltip.TooltipOverlay;
|
||||||
|
import net.runelite.client.ui.overlay.worldmap.WorldMapOverlay;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
import org.slf4j.MDC;
|
import org.slf4j.MDC;
|
||||||
|
|
||||||
@@ -124,6 +128,18 @@ public class RuneLite
|
|||||||
@Inject
|
@Inject
|
||||||
private InfoBoxManager infoBoxManager;
|
private InfoBoxManager infoBoxManager;
|
||||||
|
|
||||||
|
@Inject
|
||||||
|
private OverlayManager overlayManager;
|
||||||
|
|
||||||
|
@Inject
|
||||||
|
private InfoBoxOverlay infoBoxOverlay;
|
||||||
|
|
||||||
|
@Inject
|
||||||
|
private TooltipOverlay tooltipOverlay;
|
||||||
|
|
||||||
|
@Inject
|
||||||
|
private WorldMapOverlay worldMapOverlay;
|
||||||
|
|
||||||
Client client;
|
Client client;
|
||||||
|
|
||||||
public static void main(String[] args) throws Exception
|
public static void main(String[] args) throws Exception
|
||||||
@@ -212,6 +228,7 @@ public class RuneLite
|
|||||||
// Register event listeners
|
// Register event listeners
|
||||||
eventBus.register(clientUI);
|
eventBus.register(clientUI);
|
||||||
eventBus.register(overlayRenderer);
|
eventBus.register(overlayRenderer);
|
||||||
|
eventBus.register(overlayManager);
|
||||||
eventBus.register(drawManager);
|
eventBus.register(drawManager);
|
||||||
eventBus.register(menuManager);
|
eventBus.register(menuManager);
|
||||||
eventBus.register(chatMessageManager);
|
eventBus.register(chatMessageManager);
|
||||||
@@ -245,6 +262,12 @@ public class RuneLite
|
|||||||
// Load the session, including saved configuration
|
// Load the session, including saved configuration
|
||||||
sessionManager.loadSession();
|
sessionManager.loadSession();
|
||||||
|
|
||||||
|
// Add core overlays after configuration has been loaded so their properties will be
|
||||||
|
// loaded properly
|
||||||
|
overlayManager.add(infoBoxOverlay);
|
||||||
|
overlayManager.add(worldMapOverlay);
|
||||||
|
overlayManager.add(tooltipOverlay);
|
||||||
|
|
||||||
// Start plugins
|
// Start plugins
|
||||||
pluginManager.startCorePlugins();
|
pluginManager.startCorePlugins();
|
||||||
|
|
||||||
|
|||||||
@@ -25,6 +25,7 @@
|
|||||||
package net.runelite.client.ui.overlay;
|
package net.runelite.client.ui.overlay;
|
||||||
|
|
||||||
import com.google.common.annotations.VisibleForTesting;
|
import com.google.common.annotations.VisibleForTesting;
|
||||||
|
import com.google.common.eventbus.Subscribe;
|
||||||
import java.awt.Dimension;
|
import java.awt.Dimension;
|
||||||
import java.awt.Point;
|
import java.awt.Point;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
@@ -41,6 +42,7 @@ import lombok.Getter;
|
|||||||
import net.runelite.client.config.ConfigGroup;
|
import net.runelite.client.config.ConfigGroup;
|
||||||
import net.runelite.client.config.ConfigManager;
|
import net.runelite.client.config.ConfigManager;
|
||||||
import net.runelite.client.config.RuneLiteConfig;
|
import net.runelite.client.config.RuneLiteConfig;
|
||||||
|
import net.runelite.client.events.PluginChanged;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Manages state of all game overlays
|
* Manages state of all game overlays
|
||||||
@@ -90,6 +92,13 @@ public class OverlayManager
|
|||||||
this.configManager = configManager;
|
this.configManager = configManager;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Subscribe
|
||||||
|
public void onPluginChanged(final PluginChanged event)
|
||||||
|
{
|
||||||
|
overlays.forEach(this::loadOverlay);
|
||||||
|
rebuildOverlayLayers();
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets all of the overlays on a layer
|
* Gets all of the overlays on a layer
|
||||||
*
|
*
|
||||||
@@ -116,12 +125,7 @@ public class OverlayManager
|
|||||||
|
|
||||||
// Add is always true
|
// Add is always true
|
||||||
overlays.add(overlay);
|
overlays.add(overlay);
|
||||||
final Point location = loadOverlayLocation(overlay);
|
loadOverlay(overlay);
|
||||||
overlay.setPreferredLocation(location);
|
|
||||||
final Dimension size = loadOverlaySize(overlay);
|
|
||||||
overlay.setPreferredSize(size);
|
|
||||||
final OverlayPosition position = loadOverlayPosition(overlay);
|
|
||||||
overlay.setPreferredPosition(position);
|
|
||||||
rebuildOverlayLayers();
|
rebuildOverlayLayers();
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@@ -191,13 +195,10 @@ public class OverlayManager
|
|||||||
*/
|
*/
|
||||||
public synchronized void resetOverlay(final Overlay overlay)
|
public synchronized void resetOverlay(final Overlay overlay)
|
||||||
{
|
{
|
||||||
final String locationKey = overlay.getName() + OVERLAY_CONFIG_PREFERRED_LOCATION;
|
overlay.setPreferredPosition(null);
|
||||||
final String positionKey = overlay.getName() + OVERLAY_CONFIG_PREFERRED_POSITION;
|
overlay.setPreferredSize(null);
|
||||||
final String sizeKey = overlay.getName() + OVERLAY_CONFIG_PREFERRED_SIZE;
|
overlay.setPreferredLocation(null);
|
||||||
configManager.unsetConfiguration(RUNELITE_CONFIG_GROUP_NAME, locationKey);
|
saveOverlay(overlay);
|
||||||
configManager.unsetConfiguration(RUNELITE_CONFIG_GROUP_NAME, positionKey);
|
|
||||||
configManager.unsetConfiguration(RUNELITE_CONFIG_GROUP_NAME, sizeKey);
|
|
||||||
rebuildOverlayLayers();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private synchronized void rebuildOverlayLayers()
|
private synchronized void rebuildOverlayLayers()
|
||||||
@@ -229,6 +230,16 @@ public class OverlayManager
|
|||||||
overlayLayers.forEach((layer, value) -> overlayLayers.put(layer, Collections.unmodifiableList(value)));
|
overlayLayers.forEach((layer, value) -> overlayLayers.put(layer, Collections.unmodifiableList(value)));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void loadOverlay(final Overlay overlay)
|
||||||
|
{
|
||||||
|
final Point location = loadOverlayLocation(overlay);
|
||||||
|
overlay.setPreferredLocation(location);
|
||||||
|
final Dimension size = loadOverlaySize(overlay);
|
||||||
|
overlay.setPreferredSize(size);
|
||||||
|
final OverlayPosition position = loadOverlayPosition(overlay);
|
||||||
|
overlay.setPreferredPosition(position);
|
||||||
|
}
|
||||||
|
|
||||||
private void saveOverlayLocation(final Overlay overlay)
|
private void saveOverlayLocation(final Overlay overlay)
|
||||||
{
|
{
|
||||||
final String key = overlay.getName() + OVERLAY_CONFIG_PREFERRED_LOCATION;
|
final String key = overlay.getName() + OVERLAY_CONFIG_PREFERRED_LOCATION;
|
||||||
|
|||||||
@@ -50,9 +50,6 @@ import net.runelite.client.input.KeyManager;
|
|||||||
import net.runelite.client.input.MouseListener;
|
import net.runelite.client.input.MouseListener;
|
||||||
import net.runelite.client.input.MouseManager;
|
import net.runelite.client.input.MouseManager;
|
||||||
import net.runelite.client.ui.FontManager;
|
import net.runelite.client.ui.FontManager;
|
||||||
import net.runelite.client.ui.overlay.infobox.InfoBoxOverlay;
|
|
||||||
import net.runelite.client.ui.overlay.tooltip.TooltipOverlay;
|
|
||||||
import net.runelite.client.ui.overlay.worldmap.WorldMapOverlay;
|
|
||||||
|
|
||||||
@Singleton
|
@Singleton
|
||||||
@Slf4j
|
@Slf4j
|
||||||
@@ -94,21 +91,13 @@ public class OverlayRenderer extends MouseListener implements KeyListener
|
|||||||
final OverlayManager overlayManager,
|
final OverlayManager overlayManager,
|
||||||
final RuneLiteConfig runeLiteConfig,
|
final RuneLiteConfig runeLiteConfig,
|
||||||
final MouseManager mouseManager,
|
final MouseManager mouseManager,
|
||||||
final KeyManager keyManager,
|
final KeyManager keyManager)
|
||||||
final InfoBoxOverlay infoBoxOverlay,
|
|
||||||
final TooltipOverlay tooltipOverlay,
|
|
||||||
final WorldMapOverlay worldMapOverlay)
|
|
||||||
{
|
{
|
||||||
this.clientProvider = clientProvider;
|
this.clientProvider = clientProvider;
|
||||||
this.overlayManager = overlayManager;
|
this.overlayManager = overlayManager;
|
||||||
this.runeLiteConfig = runeLiteConfig;
|
this.runeLiteConfig = runeLiteConfig;
|
||||||
keyManager.registerKeyListener(this);
|
keyManager.registerKeyListener(this);
|
||||||
mouseManager.registerMouseListener(this);
|
mouseManager.registerMouseListener(this);
|
||||||
|
|
||||||
// Register core overlays
|
|
||||||
overlayManager.add(infoBoxOverlay);
|
|
||||||
overlayManager.add(worldMapOverlay);
|
|
||||||
overlayManager.add(tooltipOverlay);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Subscribe
|
@Subscribe
|
||||||
@@ -256,9 +245,6 @@ public class OverlayRenderer extends MouseListener implements KeyListener
|
|||||||
// detached overlays have no place to reset back to
|
// detached overlays have no place to reset back to
|
||||||
if (overlay.getPosition() != OverlayPosition.DETACHED)
|
if (overlay.getPosition() != OverlayPosition.DETACHED)
|
||||||
{
|
{
|
||||||
overlay.setPreferredPosition(null);
|
|
||||||
overlay.setPreferredSize(null);
|
|
||||||
overlay.setPreferredLocation(null);
|
|
||||||
overlayManager.resetOverlay(overlay);
|
overlayManager.resetOverlay(overlay);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -33,6 +33,7 @@ import java.awt.Rectangle;
|
|||||||
import java.util.List;
|
import java.util.List;
|
||||||
import javax.inject.Inject;
|
import javax.inject.Inject;
|
||||||
import javax.inject.Provider;
|
import javax.inject.Provider;
|
||||||
|
import javax.inject.Singleton;
|
||||||
import net.runelite.api.Client;
|
import net.runelite.api.Client;
|
||||||
import net.runelite.client.config.RuneLiteConfig;
|
import net.runelite.client.config.RuneLiteConfig;
|
||||||
import net.runelite.client.ui.overlay.Overlay;
|
import net.runelite.client.ui.overlay.Overlay;
|
||||||
@@ -44,6 +45,7 @@ import net.runelite.client.ui.overlay.components.PanelComponent;
|
|||||||
import net.runelite.client.ui.overlay.tooltip.Tooltip;
|
import net.runelite.client.ui.overlay.tooltip.Tooltip;
|
||||||
import net.runelite.client.ui.overlay.tooltip.TooltipManager;
|
import net.runelite.client.ui.overlay.tooltip.TooltipManager;
|
||||||
|
|
||||||
|
@Singleton
|
||||||
public class InfoBoxOverlay extends Overlay
|
public class InfoBoxOverlay extends Overlay
|
||||||
{
|
{
|
||||||
private final PanelComponent panelComponent = new PanelComponent();
|
private final PanelComponent panelComponent = new PanelComponent();
|
||||||
|
|||||||
Reference in New Issue
Block a user