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

Add UI for defining unique lights #4553

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

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@
import net.rptools.maptool.util.ExtractHeroLab;
import net.rptools.maptool.util.FunctionUtil;
import net.rptools.maptool.util.ImageManager;
import net.rptools.maptool.util.LightSyntax;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.fife.ui.rsyntaxtextarea.RSyntaxTextArea;
Expand Down Expand Up @@ -172,6 +173,10 @@ public void initTerrainModifiersIgnoredList() {
EnumSet.allOf(TerrainModifierOperation.class).forEach(operationModel::addElement);
}

public void initUniqueLightSourcesTextPane() {
setUniqueLightSourcesEnabled(MapTool.getPlayer().isGM());
}

public void initJtsMethodComboBox() {
getJtsMethodComboBox().setModel(new DefaultComboBoxModel<>(JTS_SimplifyMethodType.values()));
}
Expand Down Expand Up @@ -201,6 +206,8 @@ public void closeDialog() {
setGmNotesEnabled(MapTool.getPlayer().isGM());
getComponent("@GMName").setEnabled(MapTool.getPlayer().isGM());

setUniqueLightSourcesEnabled(MapTool.getPlayer().isGM());

dialog.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);

setLibTokenPaneEnabled(token.isLibToken());
Expand Down Expand Up @@ -371,6 +378,9 @@ public void bind(final Token token) {
.mapToInt(Integer::valueOf)
.toArray());

getUniqueLightSourcesTextPane()
.setText(new LightSyntax().stringifyLights(token.getUniqueLightSources()));

// Jamz: Init the Topology tab...
JTabbedPane tabbedPane = getTabbedPane();

Expand Down Expand Up @@ -709,6 +719,15 @@ public JList<TerrainModifierOperation> getTerrainModifiersIgnoredList() {
return (JList<TerrainModifierOperation>) getComponent("terrainModifiersIgnored");
}

public void setUniqueLightSourcesEnabled(boolean enabled) {
getUniqueLightSourcesTextPane().setEnabled(enabled);
getLabel("uniqueLightSourcesLabel").setEnabled(enabled);
}

public JTextPane getUniqueLightSourcesTextPane() {
return (JTextPane) getComponent("uniqueLightSources");
}

public JLabel getLibTokenURIErrorLabel() {
return (JLabel) getComponent("Label.LibURIError");
}
Expand Down Expand Up @@ -783,6 +802,14 @@ public boolean commit() {
token.setTerrainModifiersIgnored(
new HashSet<>(getTerrainModifiersIgnoredList().getSelectedValuesList()));

var uniqueLightSources =
new LightSyntax()
.parseLights(getUniqueLightSourcesTextPane().getText(), token.getUniqueLightSources());
token.removeAllUniqueLightsources();
for (var lightSource : uniqueLightSources.values()) {
token.addUniqueLightSource(lightSource);
}

// Get the states
Component[] stateComponents = getStatesPanel().getComponents();
Container barPanel = null;
Expand Down Expand Up @@ -1210,6 +1237,7 @@ public void initTokenDetails() {

public void initTokenLayoutPanel() {
TokenLayoutPanel layoutPanel = new TokenLayoutPanel();
layoutPanel.setMinimumSize(new Dimension(150, 125));
layoutPanel.setPreferredSize(new Dimension(150, 125));
layoutPanel.setName("tokenLayout");

Expand All @@ -1218,6 +1246,7 @@ public void initTokenLayoutPanel() {

public void initCharsheetPanel() {
ImageAssetPanel panel = new ImageAssetPanel();
panel.setMinimumSize(new Dimension(150, 125));
panel.setPreferredSize(new Dimension(150, 125));
panel.setName("charsheet");
panel.setLayout(new GridLayout());
Expand All @@ -1227,6 +1256,7 @@ public void initCharsheetPanel() {

public void initPortraitPanel() {
ImageAssetPanel panel = new ImageAssetPanel();
panel.setMinimumSize(new Dimension(150, 125));
panel.setPreferredSize(new Dimension(150, 125));
panel.setName("portrait");
panel.setLayout(new GridLayout());
Expand Down

Large diffs are not rendered by default.

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

import java.awt.*;
import javax.swing.*;
import net.rptools.maptool.client.swing.htmleditorsplit.HtmlEditorSplit;

Expand Down
4 changes: 4 additions & 0 deletions src/main/java/net/rptools/maptool/model/Token.java
Original file line number Diff line number Diff line change
Expand Up @@ -933,6 +933,10 @@ public void removeUniqueLightSource(GUID lightSourceId) {
uniqueLightSources.remove(lightSourceId);
}

public void removeAllUniqueLightsources() {
uniqueLightSources.clear();
}

public void addLightSource(GUID lightSourceId) {
if (lightSourceList.stream().anyMatch(source -> source.matches(lightSourceId))) {
// Avoid duplicates.
Expand Down
Loading
Loading