Skip to content

Commit

Permalink
Merge pull request #5264 from kwvanderlinde/refactor/5238-hide-statsh…
Browse files Browse the repository at this point in the history
…eet-overlay-and-overlay-panel

Hide statsheet overlay when no statsheet visible, and overlay panel when no overlay is visible
  • Loading branch information
cwisniew authored Feb 15, 2025
2 parents d9f4146 + 07a8987 commit 4f2f47c
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
/*
* This software Copyright by the RPTools.net development team, and
* licensed under the Affero GPL Version 3 or, at your option, any later
* version.
*
* MapTool Source Code is distributed in the hope that it will be
* useful, but WITHOUT ANY WARRANTY; without even the implied warranty
* of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
*
* You should have received a copy of the GNU Affero General Public
* License * along with this source Code. If not, please visit
* <http://www.gnu.org/licenses/> and specifically the Affero license
* text at <http://www.gnu.org/licenses/agpl.html>.
*/
package net.rptools.maptool.client.events;

import net.rptools.maptool.client.ui.htmlframe.HTMLOverlayManager;

public record OverlayVisibilityChanged(HTMLOverlayManager overlay, boolean isVisible) {}
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,10 @@
import javafx.scene.web.WebView;
import net.rptools.maptool.client.AppPreferences;
import net.rptools.maptool.client.MapTool;
import net.rptools.maptool.client.events.OverlayVisibilityChanged;
import net.rptools.maptool.client.functions.MacroLinkFunction;
import net.rptools.maptool.client.ui.zone.renderer.ZoneRenderer;
import net.rptools.maptool.events.MapToolEventBus;
import netscape.javascript.JSObject;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
Expand Down Expand Up @@ -224,6 +226,7 @@ public Map<String, String> macroCallbacks() {
@Override
public void setVisible(boolean visible) {
getWebView().setVisible(visible);
new MapToolEventBus().getMainEventBus().post(new OverlayVisibilityChanged(this, visible));
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
*/
package net.rptools.maptool.client.ui.htmlframe;

import com.google.common.eventbus.Subscribe;
import java.awt.*;
import java.awt.event.*;
import java.awt.image.BufferedImage;
Expand All @@ -32,10 +33,12 @@
import javafx.scene.web.WebView;
import javax.swing.*;
import net.rptools.maptool.client.MapTool;
import net.rptools.maptool.client.events.OverlayVisibilityChanged;
import net.rptools.maptool.client.swing.SwingUtil;
import net.rptools.maptool.client.tool.DefaultTool;
import net.rptools.maptool.client.tool.Tool;
import net.rptools.maptool.client.ui.AppMenuBar;
import net.rptools.maptool.events.MapToolEventBus;
import net.rptools.maptool.model.Token;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
Expand Down Expand Up @@ -71,6 +74,8 @@ public HTMLOverlayPanel() {

Platform.runLater(this::setupScene);
setVisible(false); // disabled by default

new MapToolEventBus().getMainEventBus().register(this);
}

/** Setups the scene of the JFXPanel. */
Expand Down Expand Up @@ -275,6 +280,11 @@ public void showOverlay(String name, int zOrder, boolean locked, String html, Ob
});
}

@Subscribe
private void onOverlayVisibilityChanged(OverlayVisibilityChanged event) {
Platform.runLater(() -> setVisible(overlays.stream().anyMatch(HTMLOverlayManager::isVisible)));
}

/** Display the overlays according to their zOrder. */
private void sortOverlays() {
overlays.forEach(overlay -> overlay.getWebView().toFront());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ public void setContent(Token token, String content, URL entry, StatSheetLocation
.getOverlay(AppConstants.INTERNAL_MAP_UNDER_POINTER_HTML_OVERLAY_NAME);
if (overlay != null) {
overlay.updateContents(output, true);
overlay.setVisible(true);
} else {
MapTool.getFrame()
.getOverlayPanel()
Expand All @@ -79,6 +80,7 @@ public void clearContent() {
.getOverlayPanel()
.getOverlay(AppConstants.INTERNAL_MAP_UNDER_POINTER_HTML_OVERLAY_NAME);
if (overlay != null) {
overlay.setVisible(false);
overlay.updateContents("", true);
}
});
Expand Down

0 comments on commit 4f2f47c

Please sign in to comment.