From a8e6da4328c8f81bff5b36b84c80504992893630 Mon Sep 17 00:00:00 2001 From: cwisniew Date: Thu, 3 Aug 2023 23:19:33 +0930 Subject: [PATCH] send property display name to statsheet --- .../TokenPropertiesTableModel.java | 7 +++-- .../model/sheet/stats/StatSheetContext.java | 29 ++++++++++++++++--- 2 files changed, 30 insertions(+), 6 deletions(-) diff --git a/src/main/java/net/rptools/maptool/client/ui/campaignproperties/TokenPropertiesTableModel.java b/src/main/java/net/rptools/maptool/client/ui/campaignproperties/TokenPropertiesTableModel.java index ae83386953..7de03395b9 100644 --- a/src/main/java/net/rptools/maptool/client/ui/campaignproperties/TokenPropertiesTableModel.java +++ b/src/main/java/net/rptools/maptool/client/ui/campaignproperties/TokenPropertiesTableModel.java @@ -72,7 +72,10 @@ public Object getValueAt(int rowIndex, int columnIndex) { return switch (columnIndex) { case 0 -> property.getName(); case 1 -> property.getShortName(); - case 2 -> property.getDisplayName(); + case 2 -> { + var displayName = property.getDisplayName(); + yield displayName == null || displayName.isBlank() ? null : displayName; + } case 3 -> property.isShowOnStatSheet(); case 4 -> property.isGMOnly() & property.isShowOnStatSheet(); case 5 -> property.isOwnerOnly() & property.isShowOnStatSheet(); @@ -110,7 +113,7 @@ public boolean isCellEditable(int rowIndex, int columnIndex) { var properties = tokenTypeMap.get(tokenType); var tokenProperty = properties.get(rowIndex); return switch (columnIndex) { - case 3, 4 -> tokenProperty + case 4, 5 -> tokenProperty .isShowOnStatSheet(); // GM, Owner only editable if show on stat sheet is set default -> true; }; diff --git a/src/main/java/net/rptools/maptool/model/sheet/stats/StatSheetContext.java b/src/main/java/net/rptools/maptool/model/sheet/stats/StatSheetContext.java index 63e9889b05..663a75bb28 100644 --- a/src/main/java/net/rptools/maptool/model/sheet/stats/StatSheetContext.java +++ b/src/main/java/net/rptools/maptool/model/sheet/stats/StatSheetContext.java @@ -17,6 +17,7 @@ import java.awt.Dimension; import java.util.ArrayList; import java.util.List; +import java.util.Objects; import net.rptools.lib.MD5Key; import net.rptools.maptool.client.AppPreferences; import net.rptools.maptool.client.AppUtil; @@ -34,6 +35,9 @@ public class StatSheetContext { /** Class that represents a token property on a stat sheet. */ static class Property { /** Name of the property. */ + private final String name; + + /** Display Name of the property. */ private final String displayName; /** Value of the property. */ private final Object value; @@ -46,13 +50,15 @@ static class Property { /** * Creates a new instance of the class. * - * @param displayName Name of the property. + * @param name Name of the property. + * @param displayName Display Name of the property. * @param value Value of the property. * @param gmOnly True if the property is GM only. * @note GM only properties are only extracted if the player is a GM. */ - Property(String displayName, String shortName, Object value, boolean gmOnly) { - this.displayName = displayName; + Property(String name, String displayName, String shortName, Object value, boolean gmOnly) { + this.name = name; + this.displayName = Objects.requireNonNullElse(displayName, name); this.shortName = shortName; this.value = value; this.gmOnly = gmOnly; @@ -63,6 +69,15 @@ static class Property { * * @return The name of the property. */ + public String getName() { + return name; + } + + /** + * Returns the display name of the property. + * + * @return The display name of the property. + */ public String getDisplayName() { return displayName; } @@ -193,7 +208,13 @@ public StatSheetContext(Token token, Player player, StatSheetLocation location) return; } } - properties.add(new Property(tp.getName(), tp.getShortName(), value, tp.isGMOnly())); + properties.add( + new Property( + tp.getName(), + tp.getDisplayName(), + tp.getShortName(), + value, + tp.isGMOnly())); } });