-
Notifications
You must be signed in to change notification settings - Fork 274
Fixing reseting of bar when visibility is toggled. #5809
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
base: develop
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -38,6 +38,9 @@ private TokenBarFunction() { | |
| /** singleton instance of this function */ | ||
| private static final TokenBarFunction instance = new TokenBarFunction(); | ||
|
|
||
| /** Suffix added to the bar name to store the hidden value of the bar */ | ||
| public static final String hidenBarSuffix = "StoredValue"; | ||
|
|
||
| /** | ||
| * @return singleton instance | ||
| */ | ||
|
|
@@ -84,7 +87,10 @@ public Object childEvaluate( | |
| * @return A {@link BigDecimal} value, or an empty string "" if bar is not visible | ||
| */ | ||
| public static Object getValue(Token token, String bar) { | ||
| Object value = token.getState(bar); | ||
| Object value = token.getState(bar + hidenBarSuffix); | ||
| if (value == null) { | ||
| value = token.getState(bar); | ||
| } | ||
| return value != null ? value : ""; | ||
| } | ||
|
|
||
|
|
@@ -95,8 +101,19 @@ public static Object getValue(Token token, String bar) { | |
| * @return The {@link BigDecimal} value that was actually set. | ||
| */ | ||
| public static Object setValue(Token token, String bar, Object value) { | ||
| Object valueShown = token.getState(bar); | ||
| BigDecimal val = getBigDecimalValue(value); | ||
| MapTool.serverCommand().updateTokenProperty(token, Token.Update.setState, bar, val); | ||
| if (valueShown != null) { | ||
| // If the bar is visible, set both the visual value of the bar and the stored value | ||
| MapTool.serverCommand().updateTokenProperty(token, Token.Update.setState, bar, val); | ||
| MapTool.serverCommand() | ||
| .updateTokenProperty(token, Token.Update.setState, bar + hidenBarSuffix, val); | ||
| } else { | ||
| // If the bar is not visible, only set the stored value | ||
| MapTool.serverCommand() | ||
| .updateTokenProperty(token, Token.Update.setState, bar + hidenBarSuffix, val); | ||
| } | ||
|
|
||
| return val; | ||
| } | ||
|
|
||
|
|
@@ -116,7 +133,34 @@ public static BigDecimal isVisible(Token token, String bar) { | |
| * @return If the bar visible or not | ||
| */ | ||
| public static BigDecimal setVisible(Token token, String bar, boolean show) { | ||
| MapTool.serverCommand().updateTokenProperty(token, Token.Update.setState, bar, show); | ||
| Object valueShown = token.getState(bar); | ||
| Object valueHidden = token.getState(bar + hidenBarSuffix); | ||
| if (show) { | ||
| if (valueHidden != null) { | ||
| // if we want to show the bar, and we have a hidden value, restore it | ||
| MapTool.serverCommand() | ||
| .updateTokenProperty( | ||
| token, Token.Update.setState, bar, getBigDecimalValue(valueHidden)); | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Need to handle the case where setVisible(..., true) is called an a bar that is already visible (i.e. it shouldn't copy the hidden value over the visible value). Also the opposite case where setVisible(..., false) is called on a bar that is already hidden, you don't want to copy the visible state (null) over the hidden state. |
||
| } else { | ||
| if (valueShown == null) { | ||
| // if we want to show the bar, and we don't have a hidden value, and no shown value, set | ||
| // both to true/1.0 | ||
| // This check is to avoid messing with old tokens that does not have a hidden value. | ||
| MapTool.serverCommand().updateTokenProperty(token, Token.Update.setState, bar, true); | ||
| MapTool.serverCommand() | ||
| .updateTokenProperty(token, Token.Update.setState, bar + hidenBarSuffix, true); | ||
| } | ||
| } | ||
| } else { | ||
| if (valueShown != null) { | ||
| // if we want to hide the bar, and we have a shown value, store it and hide the bar | ||
| MapTool.serverCommand() | ||
| .updateTokenProperty( | ||
| token, Token.Update.setState, bar + hidenBarSuffix, getBigDecimalValue(valueShown)); | ||
| MapTool.serverCommand().updateTokenProperty(token, Token.Update.setState, bar, false); | ||
| } | ||
| } | ||
|
|
||
| return show ? BigDecimal.ONE : BigDecimal.ZERO; | ||
| } | ||
|
|
||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Typo (should be hiddenBarSuffix)