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 display name to token properties #4235

Merged
merged 4 commits into from
Aug 14, 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
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,8 @@ private TokenPropertyFunctions() {
"setTokenSnapToGrid",
"getAllowsURIAccess",
"setAllowsURIAccess",
"getDefaultPropertyType");
"getDefaultPropertyType",
"getPropertyDisplayName");
}

public static TokenPropertyFunctions getInstance() {
Expand Down Expand Up @@ -1024,6 +1025,33 @@ public Object childEvaluate(
return MapTool.getCampaign().getCampaignProperties().getDefaultTokenPropertyType();
}

/*
* getPropertyDisplayName(Token Type Name, Property Name)
*/
if (functionName.equalsIgnoreCase("getPropertyDisplayName")) {
FunctionUtil.checkNumberParam(functionName, parameters, 2, 2);
var props = MapTool.getCampaign().getTokenTypeMap().get(parameters.get(0).toString());
if (props == null) {
throw new ParserException(
I18N.getText(
"macro.function.general.unknownPropertyType",
functionName,
parameters.get(0).toString()));
}
final var propName = parameters.get(1).toString();
for (var prop : props) {
if (prop.getName().equals(propName)) {
return prop.hasDisplayName() ? prop.getDisplayName() : prop.getName();
}
}
throw new ParserException(
I18N.getText(
"macro.function.general.unknownProperty",
functionName,
parameters.get(1).toString(),
parameters.get(0).toString()));
}

throw new ParserException(I18N.getText("macro.function.general.unknownFunction", functionName));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -260,6 +260,8 @@ public void initPropertyTable() {
button.setEnabled(getTokenPropertiesTable().getSelectedRow() >= 0);
});
propertyTable.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
propertyTable.getColumnModel().getColumn(0).setPreferredWidth(80);
propertyTable.getColumnModel().getColumn(2).setPreferredWidth(100);
}

public void initTokenTypeName() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,11 @@
<grid id="26b35" binding="mainPanel" layout-manager="GridLayoutManager" row-count="6" column-count="8" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
<margin top="0" left="0" bottom="0" right="0"/>
<constraints>
<xy x="10" y="10" width="909" height="476"/>
<xy x="10" y="10" width="1023" height="474"/>
</constraints>
<properties/>
<border type="none"/>
<children>
<component id="f5d05" class="javax.swing.JLabel">
<constraints>
<grid row="0" column="4" row-span="1" col-span="3" vsize-policy="3" hsize-policy="3" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
</constraints>
<properties>
<text resource-bundle="net/rptools/maptool/language/i18n" key="TokenPropertiesPanel.label.list"/>
</properties>
</component>
<scrollpane id="814eb">
<constraints>
<grid row="3" column="3" row-span="1" col-span="4" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
Expand All @@ -27,6 +19,7 @@
<constraints/>
<properties>
<name value="propertiesTable"/>
<preferredScrollableViewportSize width="550" height="400"/>
</properties>
</component>
</children>
Expand All @@ -44,6 +37,7 @@
<constraints/>
<properties>
<name value="tokenTypeList"/>
<selectionMode value="0"/>
</properties>
</component>
</children>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ public int getRowCount() {

@Override
public int getColumnCount() {
return 6;
return 7;
}

@Override
Expand All @@ -72,10 +72,14 @@ public Object getValueAt(int rowIndex, int columnIndex) {
return switch (columnIndex) {
case 0 -> property.getName();
case 1 -> property.getShortName();
case 2 -> property.isShowOnStatSheet();
case 3 -> property.isGMOnly() & property.isShowOnStatSheet();
case 4 -> property.isOwnerOnly() & property.isShowOnStatSheet();
case 5 -> property.getDefaultValue();
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();
case 6 -> property.getDefaultValue();
default -> null;
};
}
Expand All @@ -85,20 +89,21 @@ public String getColumnName(int column) {
return switch (column) {
case 0 -> I18N.getText("campaignPropertiesTable.column.name");
case 1 -> I18N.getText("campaignPropertiesTable.column.shortName");
case 2 -> I18N.getText("campaignPropertiesTable.column.onStatSheet");
case 3 -> I18N.getText("campaignPropertiesTable.column.gmStatSheet");
case 4 -> I18N.getText("campaignPropertiesTable.column.ownerStatSheet");
case 5 -> I18N.getText("campaignPropertiesTable.column.defaultValue");
case 2 -> I18N.getText("campaignPropertiesTable.column.displayName");
case 3 -> I18N.getText("campaignPropertiesTable.column.onStatSheet");
case 4 -> I18N.getText("campaignPropertiesTable.column.gmStatSheet");
case 5 -> I18N.getText("campaignPropertiesTable.column.ownerStatSheet");
case 6 -> I18N.getText("campaignPropertiesTable.column.defaultValue");
default -> null;
};
}

@Override
public Class<?> getColumnClass(int columnIndex) {
return switch (columnIndex) {
case 0, 1 -> String.class;
case 2, 3, 4 -> Boolean.class;
case 5 -> LargeEditableText.class;
case 0, 1, 2 -> String.class;
case 3, 4, 5 -> Boolean.class;
case 6 -> LargeEditableText.class;
default -> null;
};
}
Expand All @@ -108,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;
};
Expand All @@ -121,13 +126,14 @@ public void setValueAt(Object aValue, int rowIndex, int columnIndex) {
switch (columnIndex) {
case 0 -> tokenProperty.setName((String) aValue);
case 1 -> tokenProperty.setShortName((String) aValue);
case 2 -> {
case 2 -> tokenProperty.setDisplayName((String) aValue);
case 3 -> {
tokenProperty.setShowOnStatSheet((Boolean) aValue);
fireTableRowsUpdated(rowIndex, rowIndex);
}
case 3 -> tokenProperty.setGMOnly((Boolean) aValue);
case 4 -> tokenProperty.setOwnerOnly((Boolean) aValue);
case 5 -> tokenProperty.setDefaultValue((String) aValue);
case 4 -> tokenProperty.setGMOnly((Boolean) aValue);
case 5 -> tokenProperty.setOwnerOnly((Boolean) aValue);
case 6 -> tokenProperty.setDefaultValue((String) aValue);
}
}

Expand Down
27 changes: 25 additions & 2 deletions src/main/java/net/rptools/maptool/model/TokenProperty.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ public class TokenProperty implements Serializable {
private boolean gmOnly;
private String defaultValue;

private String displayName;

public TokenProperty() {
// For serialization
}
Expand Down Expand Up @@ -78,6 +80,7 @@ public TokenProperty(TokenProperty prop) {
this.ownerOnly = prop.ownerOnly;
this.gmOnly = prop.gmOnly;
this.defaultValue = prop.defaultValue;
this.displayName = prop.displayName;
}

public boolean isOwnerOnly() {
Expand All @@ -100,6 +103,14 @@ public String getName() {
return name;
}

public boolean hasDisplayName() {
return displayName != null;
}

public String getDisplayName() {
return displayName;
}

public void setName(String name) {
this.name = name;
}
Expand Down Expand Up @@ -128,6 +139,10 @@ public void setDefaultValue(String defaultValue) {
this.defaultValue = defaultValue;
}

public void setDisplayName(String displayName) {
this.displayName = displayName;
}

public static TokenProperty fromDto(TokenPropertyDto dto) {
var prop = new TokenProperty();
prop.name = dto.getName();
Expand All @@ -136,17 +151,25 @@ public static TokenProperty fromDto(TokenPropertyDto dto) {
prop.ownerOnly = dto.getOwnerOnly();
prop.gmOnly = dto.getGmOnly();
prop.defaultValue = dto.hasDefaultValue() ? dto.getDefaultValue().getValue() : null;
prop.displayName = dto.hasDisplayName() ? dto.getDisplayName().getValue() : null;
return prop;
}

public TokenPropertyDto toDto() {
var dto = TokenPropertyDto.newBuilder();
dto.setName(name);
if (shortName != null) dto.setShortName(StringValue.of(shortName));
if (shortName != null) {
dto.setShortName(StringValue.of(shortName));
}
dto.setHighPriority(highPriority);
dto.setOwnerOnly(ownerOnly);
dto.setGmOnly(gmOnly);
if (defaultValue != null) dto.setDefaultValue(StringValue.of(defaultValue));
if (defaultValue != null) {
dto.setDefaultValue(StringValue.of(defaultValue));
}
if (hasDisplayName()) {
dto.setDisplayName(StringValue.of(displayName));
}
return dto.build();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand All @@ -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;
Expand All @@ -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;
}
Expand Down Expand Up @@ -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()));
}
});

Expand Down
1 change: 1 addition & 0 deletions src/main/proto/data_transfer_objects.proto
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,7 @@ message TokenPropertyDto {
bool owner_only = 4;
bool gm_only = 5;
google.protobuf.StringValue default_value = 6;
google.protobuf.StringValue display_name = 7;
}

message TokenOverlayDto {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -791,6 +791,7 @@ campaignPropertiesDialog.tokenTypeNameRename = Renaming Token Types...
campaignProperties.macroEditDialog.default.title = Default value for Property
campaignPropertiesTable.column.name = Name
campaignPropertiesTable.column.shortName = Short Name
campaignPropertiesTable.column.displayName = Display Name
campaignPropertiesTable.column.onStatSheet = Stat Sheet
campaignPropertiesTable.column.gmStatSheet = GM
campaignPropertiesTable.column.ownerStatSheet = Owner
Expand Down Expand Up @@ -1798,6 +1799,8 @@ macro.function.general.onlyGM = Only the GM can call the "{
macro.function.general.tooManyParam = Function "{0}" requires no more than {1} parameters; {2} were provided.
macro.function.general.unknownFunction = Unknown function name "{0}".
macro.function.general.unknownToken = Error executing "{0}": the token name or id "{1}" is unknown.
macro.function.general.unknownPropertyType = Error executing "{0}": the property type "{1}" is unknown.
macro.function.general.unknownProperty = Error executing "{0}": the property "{1}" is unknown for type "{2}".
macro.function.general.unknownTokenOnMap = Error executing "{0}": the token name or id "{1}" is unknown on map "{2}".
macro.function.general.wrongNumParam = Function "{0}" requires exactly {1} parameters; {2} were provided.
macro.function.general.listCannotBeEmpty = {0}: string list at argument {1} cannot be empty
Expand Down
Loading