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.DrawManager;
|
||||
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.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.MDC;
|
||||
|
||||
@@ -124,6 +128,18 @@ public class RuneLite
|
||||
@Inject
|
||||
private InfoBoxManager infoBoxManager;
|
||||
|
||||
@Inject
|
||||
private OverlayManager overlayManager;
|
||||
|
||||
@Inject
|
||||
private InfoBoxOverlay infoBoxOverlay;
|
||||
|
||||
@Inject
|
||||
private TooltipOverlay tooltipOverlay;
|
||||
|
||||
@Inject
|
||||
private WorldMapOverlay worldMapOverlay;
|
||||
|
||||
Client client;
|
||||
|
||||
public static void main(String[] args) throws Exception
|
||||
@@ -212,6 +228,7 @@ public class RuneLite
|
||||
// Register event listeners
|
||||
eventBus.register(clientUI);
|
||||
eventBus.register(overlayRenderer);
|
||||
eventBus.register(overlayManager);
|
||||
eventBus.register(drawManager);
|
||||
eventBus.register(menuManager);
|
||||
eventBus.register(chatMessageManager);
|
||||
@@ -245,6 +262,12 @@ public class RuneLite
|
||||
// Load the session, including saved configuration
|
||||
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
|
||||
pluginManager.startCorePlugins();
|
||||
|
||||
|
||||
@@ -25,6 +25,7 @@
|
||||
package net.runelite.client.ui.overlay;
|
||||
|
||||
import com.google.common.annotations.VisibleForTesting;
|
||||
import com.google.common.eventbus.Subscribe;
|
||||
import java.awt.Dimension;
|
||||
import java.awt.Point;
|
||||
import java.util.ArrayList;
|
||||
@@ -41,6 +42,7 @@ import lombok.Getter;
|
||||
import net.runelite.client.config.ConfigGroup;
|
||||
import net.runelite.client.config.ConfigManager;
|
||||
import net.runelite.client.config.RuneLiteConfig;
|
||||
import net.runelite.client.events.PluginChanged;
|
||||
|
||||
/**
|
||||
* Manages state of all game overlays
|
||||
@@ -90,6 +92,13 @@ public class OverlayManager
|
||||
this.configManager = configManager;
|
||||
}
|
||||
|
||||
@Subscribe
|
||||
public void onPluginChanged(final PluginChanged event)
|
||||
{
|
||||
overlays.forEach(this::loadOverlay);
|
||||
rebuildOverlayLayers();
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets all of the overlays on a layer
|
||||
*
|
||||
@@ -116,12 +125,7 @@ public class OverlayManager
|
||||
|
||||
// Add is always true
|
||||
overlays.add(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);
|
||||
loadOverlay(overlay);
|
||||
rebuildOverlayLayers();
|
||||
return true;
|
||||
}
|
||||
@@ -191,13 +195,10 @@ public class OverlayManager
|
||||
*/
|
||||
public synchronized void resetOverlay(final Overlay overlay)
|
||||
{
|
||||
final String locationKey = overlay.getName() + OVERLAY_CONFIG_PREFERRED_LOCATION;
|
||||
final String positionKey = overlay.getName() + OVERLAY_CONFIG_PREFERRED_POSITION;
|
||||
final String sizeKey = overlay.getName() + OVERLAY_CONFIG_PREFERRED_SIZE;
|
||||
configManager.unsetConfiguration(RUNELITE_CONFIG_GROUP_NAME, locationKey);
|
||||
configManager.unsetConfiguration(RUNELITE_CONFIG_GROUP_NAME, positionKey);
|
||||
configManager.unsetConfiguration(RUNELITE_CONFIG_GROUP_NAME, sizeKey);
|
||||
rebuildOverlayLayers();
|
||||
overlay.setPreferredPosition(null);
|
||||
overlay.setPreferredSize(null);
|
||||
overlay.setPreferredLocation(null);
|
||||
saveOverlay(overlay);
|
||||
}
|
||||
|
||||
private synchronized void rebuildOverlayLayers()
|
||||
@@ -229,6 +230,16 @@ public class OverlayManager
|
||||
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)
|
||||
{
|
||||
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.MouseManager;
|
||||
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
|
||||
@Slf4j
|
||||
@@ -94,21 +91,13 @@ public class OverlayRenderer extends MouseListener implements KeyListener
|
||||
final OverlayManager overlayManager,
|
||||
final RuneLiteConfig runeLiteConfig,
|
||||
final MouseManager mouseManager,
|
||||
final KeyManager keyManager,
|
||||
final InfoBoxOverlay infoBoxOverlay,
|
||||
final TooltipOverlay tooltipOverlay,
|
||||
final WorldMapOverlay worldMapOverlay)
|
||||
final KeyManager keyManager)
|
||||
{
|
||||
this.clientProvider = clientProvider;
|
||||
this.overlayManager = overlayManager;
|
||||
this.runeLiteConfig = runeLiteConfig;
|
||||
keyManager.registerKeyListener(this);
|
||||
mouseManager.registerMouseListener(this);
|
||||
|
||||
// Register core overlays
|
||||
overlayManager.add(infoBoxOverlay);
|
||||
overlayManager.add(worldMapOverlay);
|
||||
overlayManager.add(tooltipOverlay);
|
||||
}
|
||||
|
||||
@Subscribe
|
||||
@@ -256,9 +245,6 @@ public class OverlayRenderer extends MouseListener implements KeyListener
|
||||
// detached overlays have no place to reset back to
|
||||
if (overlay.getPosition() != OverlayPosition.DETACHED)
|
||||
{
|
||||
overlay.setPreferredPosition(null);
|
||||
overlay.setPreferredSize(null);
|
||||
overlay.setPreferredLocation(null);
|
||||
overlayManager.resetOverlay(overlay);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -33,6 +33,7 @@ import java.awt.Rectangle;
|
||||
import java.util.List;
|
||||
import javax.inject.Inject;
|
||||
import javax.inject.Provider;
|
||||
import javax.inject.Singleton;
|
||||
import net.runelite.api.Client;
|
||||
import net.runelite.client.config.RuneLiteConfig;
|
||||
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.TooltipManager;
|
||||
|
||||
@Singleton
|
||||
public class InfoBoxOverlay extends Overlay
|
||||
{
|
||||
private final PanelComponent panelComponent = new PanelComponent();
|
||||
|
||||
Reference in New Issue
Block a user