Browse Source

Change tools to use gray color for players' nicks

feature_improvement
Anton Tarasenko 2 years ago
parent
commit
2e9ae360d0
  1. 18
      sources/Tools/InventoryTool.uc
  2. 75
      sources/Tools/ReportTool.uc

18
sources/Tools/InventoryTool.uc

@ -27,7 +27,7 @@ class InventoryTool extends AcediaObject;
enum InventoryReportTarget enum InventoryReportTarget
{ {
IRT_Caller, IRT_Instigator,
IRT_Target, IRT_Target,
IRT_Others IRT_Others
}; };
@ -492,7 +492,7 @@ public final function ReportChanges(
} }
else else
{ {
if (reportTarget == IRT_Caller) { if (reportTarget == IRT_Instigator) {
targetName = T(TYOURSELF).Copy(); targetName = T(TYOURSELF).Copy();
} }
else { else {
@ -509,7 +509,7 @@ public final function ReportChanges(
itemsAdded.Report(writer, blamedName, T(TYOU)); itemsAdded.Report(writer, blamedName, T(TYOU));
itemsRemoved.Report(writer, blamedName, T(TYOU)); itemsRemoved.Report(writer, blamedName, T(TYOU));
} }
else if (reportTarget == IRT_Caller) else if (reportTarget == IRT_Instigator)
{ {
if (targetPlayer.SameAs(blamedPlayer)) if (targetPlayer.SameAs(blamedPlayer))
{ {
@ -648,17 +648,17 @@ private final function AppendAmmoInstanceInfo(MutableText builder, EAmmo ammo)
defaultproperties defaultproperties
{ {
TITEMS_ADDED_MESSAGE = 0 TITEMS_ADDED_MESSAGE = 0
stringConstants(0) = "%cause% has {$TextPositive added} following weapons to %target%:" stringConstants(0) = "%%instigator%% {$TextPositive added} following weapons to %%target%%:"
TITEMS_ADDED_VEROBSE_MESSAGE = 1 TITEMS_ADDED_VEROBSE_MESSAGE = 1
stringConstants(1) = "Weapons {$TextPositive added} to %target%:" stringConstants(1) = "Weapons {$TextPositive added} to %%target%%:"
TITEMS_REMOVED_MESSAGE = 2 TITEMS_REMOVED_MESSAGE = 2
stringConstants(2) = "%cause% has {$TextNegative removed} following weapons from %target%:" stringConstants(2) = "%%instigator%% {$TextNegative removed} following weapons from %%target%%:"
TITEMS_REMOVED_VERBOSE_MESSAGE = 3 TITEMS_REMOVED_VERBOSE_MESSAGE = 3
stringConstants(3) = "Weapons {$TextNegative removed} from %target%:" stringConstants(3) = "Weapons {$TextNegative removed} from %%target%%:"
TITEMS_ADDITION_FAILED_MESSAGE = 4 TITEMS_ADDITION_FAILED_MESSAGE = 4
stringConstants(4) = "Weapons we've {$TextFailure failed} to add to %target%:" stringConstants(4) = "Weapons we've {$TextFailure failed} to add to %%target%%:"
TITEMS_REMOVAL_FAILED_MESSAGE = 5 TITEMS_REMOVAL_FAILED_MESSAGE = 5
stringConstants(5) = "Weapons we've {$TextFailure failed} to remove from %target%:" stringConstants(5) = "Weapons we've {$TextFailure failed} to remove from %%target%%:"
TRESOLVED_INTO = 6 TRESOLVED_INTO = 6
stringConstants(6) = "` resolved into `" stringConstants(6) = "` resolved into `"
TTILDE_QUOTE = 7 TTILDE_QUOTE = 7

75
sources/Tools/ReportTool.uc

@ -27,8 +27,8 @@ class ReportTool extends AcediaObject;
/** /**
* How to use: * How to use:
* 1. Specify "list header" via `Initialize()` method right after creating * 1. Specify "list header" via `Initialize()` method right after creating
* a new instance of `ReportTool`. It can contain "%cause%" and * a new instance of `ReportTool`. It can contain "%%instigator%%" and
* "%target%" substrings, that will be replaces with approprtiate * "%%target%%" substrings, that will be replaces with approprtiate
* parameters of `Report()` method when it is invoked; * parameters of `Report()` method when it is invoked;
* 2. Use `Item()` method to add new items (they will be listed after * 2. Use `Item()` method to add new items (they will be listed after
* list header + whitespace, separated by commas and whitespaces ", "); * list header + whitespace, separated by commas and whitespaces ", ");
@ -42,8 +42,8 @@ class ReportTool extends AcediaObject;
* (but not list header), allowing to start forming a new report. * (but not list header), allowing to start forming a new report.
*/ */
// Header template (with possible "%cause%" and "%target%" placeholders) // Header template (with possible "%%instigator%%" and "%%target%%"
// for the lists this `ReportTool` will generate. // placeholders) for the lists this `ReportTool` will generate.
// Doubles as a way to remember whether `ReportTool` was already // Doubles as a way to remember whether `ReportTool` was already
// initialized (iff `headerTemplate != none`). // initialized (iff `headerTemplate != none`).
var private Text headerTemplate; var private Text headerTemplate;
@ -71,10 +71,10 @@ protected function Finalizer()
* Initialized a new `ReportTool` with appropriate template to serve as * Initialized a new `ReportTool` with appropriate template to serve as
* a header. * a header.
* *
* Template (`template`) is allowed to contain "%cause%" and "%target%" * Template (`template`) is allowed to contain "%%instigator%%" and
* placeholder substrings that will be replaced with corresponding names of the * "%%target%%" placeholder substrings that will be replaced with corresponding
* player that caused a change we are reporting and player affefcted by * names of the player that caused a change we are reporting and player
* that change. * affefcted by that change.
* *
* @param template Template for the header of the reports made by * @param template Template for the header of the reports made by
* the caller `ReportTool`. * the caller `ReportTool`.
@ -101,6 +101,7 @@ public final function Initialize(BaseText template)
public final function ReportTool Item(BaseText item) public final function ReportTool Item(BaseText item)
{ {
local ReportItem newItem; local ReportItem newItem;
if (headerTemplate == none) return self; if (headerTemplate == none) return self;
if (item == none) return self; if (item == none) return self;
@ -122,6 +123,7 @@ public final function ReportTool Item(BaseText item)
public final function ReportTool Detail(BaseText detail) public final function ReportTool Detail(BaseText detail)
{ {
local array<Text> detailToReport; local array<Text> detailToReport;
if (headerTemplate == none) return self; if (headerTemplate == none) return self;
if (detail == none) return self; if (detail == none) return self;
if (itemsToReport.length == 0) return self; if (itemsToReport.length == 0) return self;
@ -136,32 +138,28 @@ public final function ReportTool Detail(BaseText detail)
* Outputs report assembled thus far into the provided `ConsoleWriter`. * Outputs report assembled thus far into the provided `ConsoleWriter`.
* Reports will be made only if at least one items was added (see `Item()`). * Reports will be made only if at least one items was added (see `Item()`).
* *
* @param writer `ConsoleWriter` to output report into. * @param writer `ConsoleWriter` to output report into.
* @param cause Player that caused the change this report is about. * @param instigator Player that caused the change this report is about.
* Their name will replace "%cause%" substring in the header template * Their name will replace "%%instigator%%" substring in the header
* (if it is contained there). * template (if it is contained there).
* @param target Player that was affected by the change this report is about. * @param target Player that was affected by the change this report is
* Their name will replace "%target%" substring in the header template * about. Their name will replace "%%target%%" substring in the header
* (if it is contained there). * template (if it is contained there).
* @return Reference to the caller `ReportTool` to allow for method chaining. * @return Reference to the caller `ReportTool` to allow for method chaining.
*/ */
public final function ReportTool Report( public final function ReportTool Report(
ConsoleWriter writer, ConsoleWriter writer,
optional BaseText cause, optional BaseText instigator,
optional BaseText target) optional BaseText target)
{ {
local int i, j; local int i, j;
local MutableText intro;
local array<Text> detailToReport; local array<Text> detailToReport;
if (headerTemplate == none) return self; if (headerTemplate == none) return self;
if (itemsToReport.length == 0) return self; if (itemsToReport.length == 0) return self;
if (writer == none) return self; if (writer == none) return self;
intro = headerTemplate.MutableCopy() AppendHeader(writer, instigator, target);
.Replace(T(TCAUSE), cause)
.Replace(T(TTARGET), target);
writer.Flush().Write(intro);
_.memory.Free(intro);
for (i = 0; i < itemsToReport.length; i += 1) for (i = 0; i < itemsToReport.length; i += 1)
{ {
if (i > 0) { if (i > 0) {
@ -187,6 +185,35 @@ public final function ReportTool Report(
return self; return self;
} }
private final function AppendHeader(
ConsoleWriter writer,
optional BaseText instigator,
optional BaseText target)
{
local MutableText intro;
local MutableText grayInstigatorName, grayTargetName;
if (headerTemplate == none) return;
if (writer == none) return;
if (instigator != none)
{
grayInstigatorName = instigator
.MutableCopy()
.ChangeDefaultColor(_.color.Gray);
}
if (target != none) {
grayTargetName = target.MutableCopy().ChangeDefaultColor(_.color.Gray);
}
intro = headerTemplate.MutableCopy()
.Replace(T(TCAUSE), grayInstigatorName)
.Replace(T(TTARGET), grayTargetName);
writer.Flush().Write(intro);
_.memory.Free(intro);
_.memory.Free(grayTargetName);
_.memory.Free(grayInstigatorName);
}
/** /**
* Forgets all items or details specified for the caller `ReportTool` so far, * Forgets all items or details specified for the caller `ReportTool` so far,
* allowing to start forming a new report. Does not reset template header, * allowing to start forming a new report. Does not reset template header,
@ -211,9 +238,9 @@ public final function ReportTool Reset()
defaultproperties defaultproperties
{ {
TCAUSE = 0 TCAUSE = 0
stringConstants(0) = "%cause%" stringConstants(0) = "%%instigator%%"
TTARGET = 1 TTARGET = 1
stringConstants(1) = "%target%" stringConstants(1) = "%%target%%"
TCOMMA = 2 TCOMMA = 2
stringConstants(2) = "," stringConstants(2) = ","
TSPACE = 3 TSPACE = 3

Loading…
Cancel
Save