Skip to content

Commit

Permalink
Merge pull request #4553 from kwvanderlinde/feature/331-unique-light-…
Browse files Browse the repository at this point in the history
…source-ui-minimal

Add UI for defining unique lights
  • Loading branch information
cwisniew authored Dec 15, 2023
2 parents 47d9899 + 0f92499 commit 53d8009
Show file tree
Hide file tree
Showing 8 changed files with 776 additions and 581 deletions.

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

0 comments on commit 53d8009

Please sign in to comment.