Skip to content

Separate auras from lights #5357

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

Merged
19 changes: 0 additions & 19 deletions src/main/java/net/rptools/maptool/client/AppActions.java
Original file line number Diff line number Diff line change
Expand Up @@ -2684,25 +2684,6 @@ protected void done() {
}
}

/**
* This is the integrated load/save interface that allows individual components of the
* application's dataset to be saved to an external file. The goal is to allow specific maps and
* tokens, campaign properties (sight, light, token props), and layers + their contents to be
* saved through a single unified interface.
*/
public static final Action LOAD_SAVE =
new DeveloperClientAction() {
{
init("action.loadSaveDialog");
}

@Override
protected void executeAction() {
LoadSaveImpl impl = new LoadSaveImpl();
impl.saveApplication(); // All the work is done here
}
};

public static final Action SAVE_CAMPAIGN =
new DefaultClientAction() {
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,7 @@
import java.awt.event.ActionEvent;
import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Set;
Expand Down Expand Up @@ -123,28 +120,66 @@ public void actionPerformed(ActionEvent e) {
protected JMenu createLightSourceMenu() {
JMenu menu = new JMenu(I18N.getText("panel.MapExplorer.View.LIGHT_SOURCES"));

boolean hasAnyLights = false;
boolean hasLights = false;
boolean hasLights =
selectedTokenSet.stream()
.map(tokenGUID -> renderer.getZone().getToken(tokenGUID))
.anyMatch(token -> token.hasLightSourceType(LightSource.Type.NORMAL));
if (hasLights) {
menu.add(new ClearLightsAction());
menu.addSeparator();
}

// Add unique light sources for the token.
{
JMenu subMenu = createLightCategoryMenu("Unique", tokenUnderMouse.getUniqueLightSources());
if (subMenu.getItemCount() != 0) {
menu.add(subMenu);
menu.addSeparator();
}
}

for (Entry<String, Map<GUID, LightSource>> entry :
MapTool.getCampaign().getLightSourcesMap().entrySet()) {
JMenu subMenu = createLightCategoryMenu(entry.getKey(), entry.getValue().values());
if (subMenu.getItemCount() != 0) {
menu.add(subMenu);
}
}
return menu;
}

protected JMenu createLightCategoryMenu(String categoryName, Collection<LightSource> sources) {
JMenu subMenu = new JMenu(categoryName);

for (LightSource lightSource : sources) {
if (lightSource.getType() != LightSource.Type.NORMAL) {
continue;
}

JCheckBoxMenuItem menuItem = new JCheckBoxMenuItem(new ToggleLightSourceAction(lightSource));
menuItem.setSelected(tokenUnderMouse.hasLightSource(lightSource));
subMenu.add(menuItem);
}

return subMenu;
}

protected JMenu createAurasMenu() {
JMenu menu = new JMenu(I18N.getText("panel.MapExplorer.View.AURAS"));

boolean hasAuras = false;
boolean hasGmAuras = false;
boolean hasOwnerOnlyAuras = false;

for (GUID tokenGUID : selectedTokenSet) {
Token token = renderer.getZone().getToken(tokenGUID);
hasAnyLights |= token.hasLightSources();
hasLights |= token.hasLightSourceType(LightSource.Type.NORMAL);
hasAuras |= token.hasLightSourceType(LightSource.Type.AURA);
hasGmAuras |= token.hasGMAuras();
hasOwnerOnlyAuras |= token.hasOwnerOnlyAuras();
}
if (hasAnyLights) {
menu.add(new ClearLightAction());
if (hasLights) {
menu.add(new ClearLightsOnlyAction());
}
if (hasAuras) {
menu.add(new ClearAurasOnlyAction());
}

if (hasAuras) {
menu.add(new ClearAurasAction());
if (hasGmAuras) {
menu.add(new ClearGMAurasOnlyAction());
}
Expand All @@ -156,7 +191,7 @@ protected JMenu createLightSourceMenu() {

// Add unique light sources for the token.
{
JMenu subMenu = createLightCategoryMenu("Unique", tokenUnderMouse.getUniqueLightSources());
JMenu subMenu = createAuraCategoryMenu("Unique", tokenUnderMouse.getUniqueLightSources());
if (subMenu.getItemCount() != 0) {
menu.add(subMenu);
menu.addSeparator();
Expand All @@ -165,21 +200,22 @@ protected JMenu createLightSourceMenu() {

for (Entry<String, Map<GUID, LightSource>> entry :
MapTool.getCampaign().getLightSourcesMap().entrySet()) {
JMenu subMenu = createLightCategoryMenu(entry.getKey(), entry.getValue().values());
JMenu subMenu = createAuraCategoryMenu(entry.getKey(), entry.getValue().values());
if (subMenu.getItemCount() != 0) {
menu.add(subMenu);
}
}
return menu;
}

protected JMenu createLightCategoryMenu(String categoryName, Collection<LightSource> sources) {
protected JMenu createAuraCategoryMenu(String categoryName, Collection<LightSource> sources) {
JMenu subMenu = new JMenu(categoryName);

List<LightSource> lightSources = new ArrayList<>(sources);
Collections.sort(lightSources);
for (LightSource lightSource : sources) {
if (lightSource.getType() != LightSource.Type.AURA) {
continue;
}

for (LightSource lightSource : lightSources) {
// Don't include light sources that don't have lights visible to the player. Note that the
// player must be an owner to use the popup, so don't bother checking `::isOwner()`.
boolean include =
Expand Down Expand Up @@ -706,8 +742,8 @@ public void actionPerformed(ActionEvent e) {
}
}

public class ClearLightsOnlyAction extends AbstractAction {
public ClearLightsOnlyAction() {
public class ClearLightsAction extends AbstractAction {
public ClearLightsAction() {
super(I18N.getString("token.popup.menu.lights.clear"));
}

Expand All @@ -724,8 +760,8 @@ public void actionPerformed(ActionEvent e) {
}
}

public class ClearAurasOnlyAction extends AbstractAction {
public ClearAurasOnlyAction() {
public class ClearAurasAction extends AbstractAction {
public ClearAurasAction() {
super(I18N.getString("token.popup.menu.auras.clear"));
}

Expand Down Expand Up @@ -782,24 +818,6 @@ public void actionPerformed(ActionEvent e) {
}
}

public class ClearLightAction extends AbstractAction {
public ClearLightAction() {
super(I18N.getText("token.popup.menu.lights.clearAll"));
}

public void actionPerformed(ActionEvent e) {
ZoneRenderer renderer = MapTool.getFrame().getCurrentZoneRenderer();
for (GUID tokenGUID : selectedTokenSet) {
Token token = renderer.getZone().getToken(tokenGUID);
token.clearLightSources();
renderer.flush(token);
MapTool.serverCommand().putToken(renderer.getZone().getId(), token);
renderer.getZone().putToken(token);
}
renderer.repaint();
}
}

public class SnapToGridAction extends AbstractAction {
private final boolean snapToGrid;
private final ZoneRenderer renderer;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ public StampPopupMenu(
}
add(new JSeparator());
addOwnedItem(createLightSourceMenu());
addOwnedItem(createAurasMenu());
add(new JSeparator());

addToggledItem(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@ public TokenPopupMenu(
add(createExposeMenu());
}
addOwnedItem(createLightSourceMenu());
addOwnedItem(createAurasMenu());
add(new JSeparator());

addToggledItem(new ShowPathsAction(), renderer.isPathShowing(tokenUnderMouse));
Expand Down
Loading