Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

onMouseOver event #4319

Merged
merged 6 commits into from
Nov 3, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/main/java/net/rptools/maptool/client/MapTool.java
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@
import net.rptools.maptool.client.ui.zone.ZoneRenderer;
import net.rptools.maptool.client.ui.zone.ZoneRendererFactory;
import net.rptools.maptool.events.MapToolEventBus;
import net.rptools.maptool.events.TokenHoverListener;
import net.rptools.maptool.events.ZoneLoadedListener;
import net.rptools.maptool.language.I18N;
import net.rptools.maptool.model.AssetManager;
Expand Down Expand Up @@ -1396,6 +1397,7 @@ private static void postInitialize() {

// Register the instance that will listen for token hover events and create a stat sheet.
new MapToolEventBus().getMainEventBus().register(new StatSheetListener());
new MapToolEventBus().getMainEventBus().register(new TokenHoverListener());

final var enabledDeveloperOptions = DeveloperOptions.getEnabledOptions();
if (!enabledDeveloperOptions.isEmpty()) {
Expand Down
88 changes: 88 additions & 0 deletions src/main/java/net/rptools/maptool/events/TokenHoverListener.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
/*
* 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.events;

import com.google.common.eventbus.Subscribe;
import java.util.Collections;
import java.util.concurrent.ExecutionException;
import net.rptools.maptool.client.events.TokenHoverEnter;
import net.rptools.maptool.client.events.TokenHoverExit;
import net.rptools.maptool.language.I18N;
import net.rptools.maptool.model.library.Library;
import net.rptools.maptool.model.library.LibraryManager;
import net.rptools.maptool.util.EventMacroUtil;
import org.apache.log4j.LogManager;
import org.apache.log4j.Logger;

public class TokenHoverListener {
public static final String ON_MOUSE_OVER_CALLBACK = "onMouseOver";
private static final Logger LOGGER = LogManager.getLogger(EventMacroUtil.class);

@Subscribe
public void onMouseOverEnter(TokenHoverEnter event) {
var token = event.token();
var tokX = event.token().getX();
var tokY = event.token().getY();
var shiftKey = event.shiftDown();
var ctrlKey = event.controlDown();
try {
var libs = new LibraryManager().getLegacyEventTargets(ON_MOUSE_OVER_CALLBACK).get();
if (libs.isEmpty()) return;
for (Library handler : libs) {
try {
String libraryNamespace = handler.getNamespace().get();
EventMacroUtil.callEventHandler(
ON_MOUSE_OVER_CALLBACK,
libraryNamespace,
token.getId().toString() + "," + tokX + "," + tokY + "," + shiftKey + "," + ctrlKey,
null,
Collections.emptyMap(),
false);
} catch (InterruptedException | ExecutionException e) {
LOGGER.error(I18N.getText("library.error.namespace"), e);
throw new AssertionError("Error retrieving library namespace");
}
}
} catch (InterruptedException | ExecutionException e) {
LOGGER.error(I18N.getText("library.error.retrievingEventHandler"), e);
}
}

@Subscribe
public void onMouseOverExit(TokenHoverExit event) {
var token = event.token();
try {
var libs = new LibraryManager().getLegacyEventTargets(ON_MOUSE_OVER_CALLBACK).get();
if (libs.isEmpty()) return;
for (Library handler : libs) {
try {
String libraryNamespace = handler.getNamespace().get();
EventMacroUtil.callEventHandler(
ON_MOUSE_OVER_CALLBACK,
libraryNamespace,
token.getId().toString() + ",exit",
null,
Collections.emptyMap(),
false);
} catch (InterruptedException | ExecutionException e) {
LOGGER.error(I18N.getText("library.error.namespace"), e);
throw new AssertionError("Error retrieving library namespace");
}
}
} catch (InterruptedException | ExecutionException e) {
LOGGER.error(I18N.getText("library.error.retrievingEventHandler"), e);
}
}
}
Loading