Class Report
- All Implemented Interfaces:
Serializable,ReportEntry
Each Report contains message text, formatting information, visibility settings, and the data needed to display the report to players. Reports are typically created by the server, then transmitted to clients for display.
The actual text of reports comes from the report-messages.properties resource file. Each report is identified
by a numeric ID that corresponds to a message template in this file. The template can contain tags that will be
replaced with data provided by the Report object:
<data>- Replaced with values added viaadd(String)or similar methods<msg:id1,id2>- Conditionally shows one of two messages based on a boolean value<list>- Lists all remaining data values, comma-separated<newline>- Inserts a line break
Example usage:
// Create a report with ID 3455 Report r = Report.subjectReport(3455, entity.getId()); r.indent() .addDesc(entity) .add(6) .choose(true); vPhaseReport.addElement(r);
The corresponding entry in report-messages.properties might be:
3455::<data> (<data>) does <data> damage to the <msg:3456,3457>. 3456::tank 3457::building
This would produce output like: "Crusader (Bob) does 6 damage to the tank."
Reports can be public (visible to all) or hidden based on subject entity or player. They support HTML formatting, entity links, tooltips, and other rich text features.
- See Also:
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final intNumber of spaces to use per indentation level.static final StringPrefix for entity hyperlinksAdditional sections to add to raw message prior to inserting tagsstatic final intReport is only visible to those players who can see the subject.static intstatic final intNumber of indentation levels allowed.intRequired - associates this object with its text.intThe number of newlines to add at the end of this report.static final intReport Type: visible to all players, but all data marked for obscuration remains hidden.static final StringThe string that appears in the report to obscure certain information.intThe player this report concerns, if applicable.static final intMessages which should be sent only to the player indicated by "player"static final intReport Type: visible to all players.intThe entity this report concerns, if applicable.static final intTesting only - remove me later.static final StringPrefix for tooltip textintHow this report is handled when double-blind play is in effect. -
Constructor Summary
ConstructorsConstructorDescriptionReport()Default constructor, note that using this means themessageIdfield must be explicitly set.Report(int id) Create a new report associated with the given report text.Report(int id, int type) Create a new report associated with the given report text and having the given type.Create a new report which is an exact copy of the given report. -
Method Summary
Modifier and TypeMethodDescriptionadd(int data) Add the given int to the list of data that will be substituted for the <data> tags in the report.add(int data, boolean obscure) Add the given int to the list of data that will be substituted for the <data> tags in the report, and mark it as double-blind sensitive information ifobscureis true.Add the given String to the list of data that will be substituted for the <data> tags in the report.Add the given String to the list of data that will be substituted for the <data> tags in the report, and mark it as double-blind sensitive information ifobscureis true.Add the given string to the list of data that will be substituted for the <data> tags in the report.add(TargetRoll targetRoll) Adds target roll to report with details available as a tooltipaddDataWithTooltip(Integer data, String tooltip) addDataWithTooltip(String data, String tooltip) Adds a field to the report with additional data available as a tooltipShortcut method for adding entity name and owner data at the same time.addEntityName(Entity entity) Adds a unit's linked name alone, for a name inside a sentence: no owner, no crew nickname and no sprite, unlikeaddDesc(Entity).addEntityName(Entity entity, String displayName) Adds a unit's linked name alone, shown as the given text: no owner, no crew nickname and no sprite.static voidaddNewline(Vector<Report> v) Adds a newline to the last report in the given Vector.voidaddObscuredRecipient(String playerName) Internal method.Adds the result of the given roll to this ReportEntry.Deprecated, for removal: This API element is subject to removal in a future version.Wraps text in a span with the given hex background color.static StringWraps text in a bold tag.choose(boolean choice) Indicate which of two possible messages should be substituted for the<msg:n,m>tag.intInternal method.voidextend(int id) Add an additional message id that will extend the base messageWraps text in a span with the given foreground color.Wraps text in a span with the given hex foreground color.Safety accessor for extensionsvoidhideData(int index) Internal method.Creates an HTML anchor tag.indent()Indent the report.indent(int n) Indent the report n times.static voidSets the indentation for all reports of the given reports list to the given amount by callingindent(int)booleanisObscuredRecipient(String playerName) Internal method.booleanisValueObscured(int index) Internal method.Set the report to be public (Report.PUBLIC).newLines(int newlines) Set the report to not add the given number of newlines at the end.noNL()Set the report to not add a newline at the end, so that the current line of text can be continued with another report.voidstatic ReportpublicReport(int id) Returns a new report associated with the given report text (ID) and having the type Report.PUBLIC.voidsetShowImage(boolean showImage) Deprecated, for removal: This API element is subject to removal in a future version.static voidsetupStylesheet(JTextPane pane) static voidsetupStylesheet(StyleSheet styleSheet) Wraps text in a span with the given class name.subject(int subjectId) Set the report's subject (Entity ID).static ReportsubjectReport(int id, int subjectId) Returns a new report associated with the given report text (ID) and having the given subject (Entity ID).text()Get the report in its final form, with all the necessary substitutions made.toString()Useful for debugging purposes.Wraps text in a warning span.Set the report's subject and add its description.
-
Field Details
-
PUBLIC
public static final int PUBLICReport Type: visible to all players.- See Also:
-
OBSCURED
public static final int OBSCUREDReport Type: visible to all players, but all data marked for obscuration remains hidden. Note: Not used at this time, since all reports are consideredobscuredunless explicitly markedpublic.- See Also:
-
HIDDEN
public static final int HIDDENReport is only visible to those players who can see the subject. Note: Not used at this time, since all reports are consideredobscuredunless explicitly markedpublic.- See Also:
-
TESTING
public static final int TESTINGTesting only - remove me later.- See Also:
-
PLAYER
public static final int PLAYERMessages which should be sent only to the player indicated by "player"- See Also:
-
OBSCURED_STRING
The string that appears in the report to obscure certain information.- See Also:
-
DEFAULT_INDENTATION
public static final int DEFAULT_INDENTATIONNumber of spaces to use per indentation level.- See Also:
-
MAX_INDENTATION
public static final int MAX_INDENTATIONNumber of indentation levels allowed. Currently, the same as the DEFAULT_INDENTATION value, to limit indentations to one level for a cleaner look of the report.- See Also:
-
ENTITY_LINK
Prefix for entity hyperlinks- See Also:
-
TOOLTIP_LINK
Prefix for tooltip text- See Also:
-
messageId
public int messageIdRequired - associates this object with its text. -
extensions
Additional sections to add to raw message prior to inserting tags -
newlines
public int newlinesThe number of newlines to add at the end of this report. Defaults to one. -
type
public transient int typeHow this report is handled when double-blind play is in effect. See constants below for more details. -
subject
public transient int subjectThe entity this report concerns, if applicable. If this is left blank, then the report will be consideredpublic. -
player
public transient int playerThe player this report concerns, if applicable. This should be filled in if this report is not public and still does not belong to a specific visible entity -
HIDDEN_ENTITY_NUM
public static int HIDDEN_ENTITY_NUM
-
-
Constructor Details
-
Report
public Report()Default constructor, note that using this means themessageIdfield must be explicitly set. -
Report
public Report(int id) Create a new report associated with the given report text.- Parameters:
id- the int value of the report from report-messages.properties
-
Report
public Report(int id, int type) Create a new report associated with the given report text and having the given type.- Parameters:
id- the int value of the report from report-messages.propertiestype- the constant specifying the visibility of the report (PUBLIC, OBSCURED, or HIDDEN)
-
Report
Create a new report which is an exact copy of the given report.- Parameters:
r- the report to be copied
-
-
Method Details
-
publicReport
Returns a new report associated with the given report text (ID) and having the type Report.PUBLIC.- Parameters:
id- the int value of the report from report-messages.properties- Returns:
- A new Report
-
subjectReport
Returns a new report associated with the given report text (ID) and having the given subject (Entity ID). The Report will be the default type Report.HIDDEN.- Parameters:
id- the int value of the report from report-messages.propertiessubjectId- The Entity ID of the subject entity- Returns:
- A new Report
-
makePublic
Set the report to be public (Report.PUBLIC).- Returns:
- This Report to allow chaining
-
newLines
Set the report to not add the given number of newlines at the end.- Returns:
- This Report to allow chaining
-
noNL
Set the report to not add a newline at the end, so that the current line of text can be continued with another report.- Returns:
- This Report to allow chaining
-
extend
public void extend(int id) Add an additional message id that will extend the base message -
getExtensions
Safety accessor for extensions- Returns:
- extensions Vector of integer values of report messages
-
subject
Set the report's subject (Entity ID).- Returns:
- This Report to allow chaining
-
with
Set the report's subject and add its description. This is equivalent to calling
Typically used in reports that start with "<data> (<data>) ..."report.subject(entity.getId()); report.addDesc(entity);- Returns:
- This Report to allow chaining
-
add
Add the given int to the list of data that will be substituted for the <data> tags in the report. The order in which items are added must match the order of the tags in the report text.- Parameters:
data- the int to be substituted- Returns:
- This Report to allow chaining
-
add
Add the given int to the list of data that will be substituted for the <data> tags in the report, and mark it as double-blind sensitive information ifobscureis true. The order in which items are added must match the order of the tags in the report text.- Parameters:
data- the int to be substitutedobscure- boolean indicating whether the data is double-blind sensitive- Returns:
- This Report to allow chaining
-
add
Add the given String to the list of data that will be substituted for the <data> tags in the report. The order in which items are added must match the order of the tags in the report text.- Parameters:
data- the String to be substituted- Returns:
- This Report to allow chaining
-
add
Add the given string to the list of data that will be substituted for the <data> tags in the report. The order in which items are added must match the order of the tags in the report text. The second string argument sets the translation flag to the string value.- Parameters:
data- the String to be substitutedtranslate- the common Resource Bundle to be used for translation- Returns:
- This Report to allow chaining
-
add
Add the given String to the list of data that will be substituted for the <data> tags in the report, and mark it as double-blind sensitive information ifobscureis true. The order in which items are added must match the order of the tags in the report text.- Parameters:
data- the String to be substitutedobscure- boolean indicating whether the data is double-blind sensitive- Returns:
- This Report to allow chaining
-
add
Adds target roll to report with details available as a tooltip- Parameters:
targetRoll- the target roll- Returns:
- This Report to allow chaining
-
add
-
addDataWithTooltip
-
addDataWithTooltip
Adds a field to the report with additional data available as a tooltip- Parameters:
data- the data for the report fieldtooltip- the tooltip text- Returns:
- This Report to allow chaining
-
choose
Indicate which of two possible messages should be substituted for the<msg:n,m>tag. An argument oftruewould select message n while an argument offalsewould select m. In the future, this capability may be expanded to support more than two choices.- Parameters:
choice- boolean indicating which message to substitute- Returns:
- This Report to allow chaining
-
span
-
addDesc
Shortcut method for adding entity name and owner data at the same time. Assumes that the entity name should be obscured, but the owner should not.- Parameters:
entity- the entity you wish to add- Returns:
- This Report to allow chaining
-
addEntityName
Adds a unit's linked name alone, for a name inside a sentence: no owner, no crew nickname and no sprite, unlikeaddDesc(Entity).- Parameters:
entity- the entity to name- Returns:
- This Report to allow chaining
-
addEntityName
Adds a unit's linked name alone, shown as the given text: no owner, no crew nickname and no sprite.- Parameters:
entity- the entity to namedisplayName- the text of the link, such as the chassis alone- Returns:
- This Report to allow chaining
-
setShowImage
Deprecated, for removal: This API element is subject to removal in a future version.Manually Toggle if the report should show an image of the entity -
obscureImg
public void obscureImg() -
isValueObscured
public boolean isValueObscured(int index) Internal method. Not for typical use.Tests whether the data value at the given index has been marked as obscured.
- Parameters:
index- position of data value (indexes are chronological and start at zero)- Returns:
- true if the data value was marked obscured
-
hideData
public void hideData(int index) Internal method. Not for typical use.Remove the data value from the report. This operation is irreversible.
- Parameters:
index- position of data value (indexes are chronological and start at zero
-
indent
Indent the report. Equivalent to callingindent(int)with a parameter of 1.- Returns:
- This Report to allow chaining
-
indent
Indent the report n times.- Parameters:
n- the number of times to indent the report- Returns:
- This Report to allow chaining
-
dataCount
public int dataCount()Internal method. Not for typical use.Get the total number of data values associated with this report. Note that this includes the
true/falsevalues added for <msg> tags as well.- Returns:
- the number of data values
-
text
Get the report in its final form, with all the necessary substitutions made.- Specified by:
textin interfaceReportEntry- Returns:
- a String with the final report
-
addRoll
Description copied from interface:ReportEntryAdds the result of the given roll to this ReportEntry. Returns this ReportEntry to allow chaining calls.- Specified by:
addRollin interfaceReportEntry- Parameters:
roll- The roll to add- Returns:
- this ReportEntry
-
addNewline
Adds a newline to the last report in the given Vector.- Parameters:
v- a Vector of Report objects
-
setupStylesheet
-
setupStylesheet
-
span
Wraps text in a span with the given class name.- Parameters:
name- The class name.text- The text to wrap.- Returns:
- The HTML string.
-
warning
Wraps text in a warning span.- Parameters:
text- The text to wrap.- Returns:
- The HTML string.
-
fgColor
Wraps text in a span with the given foreground color.- Parameters:
color- The color to use.str- The text to wrap.- Returns:
- The HTML string.
-
fgColor
Wraps text in a span with the given hex foreground color.- Parameters:
hexColor- The hex color string (e.g., "#RRGGBB").str- The text to wrap.- Returns:
- The HTML string.
-
bgColor
Deprecated, for removal: This API element is subject to removal in a future version.Wraps text in a span with the given background color.- Parameters:
color- The color to use.str- The text to wrap.- Returns:
- The HTML string.
-
bgColor
Wraps text in a span with the given hex background color.- Parameters:
hexColor- The hex color string (e.g., "#RRGGBB").str- The text to wrap.- Returns:
- The HTML string.
-
bold
Wraps text in a bold tag.- Parameters:
str- The text to wrap.- Returns:
- The HTML string.
-
href
Creates an HTML anchor tag.- Parameters:
href- The URL.str- The link text.- Returns:
- The HTML string.
-
addObscuredRecipient
Internal method. Not for typical use.Adds the given player name to the report's list of players who received an obscured version of this report from the server at some time in the past.
- Parameters:
playerName- the String containing the player's name
-
isObscuredRecipient
Internal method. Not for typical use.Tests whether the given player name is on the report's list of players who received an obscured version of this report from the server at some time in the past.
- Parameters:
playerName- the String containing the player's name- Returns:
- true if the player was sent an obscured version of this report
-
toString
Useful for debugging purposes. -
indentAll
Sets the indentation for all reports of the given reports list to the given amount by callingindent(int)- Parameters:
reports- A list of reports to be affectedamount- The amount of indentation to give each report in the list
-