Skip to content
Open
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
2 changes: 0 additions & 2 deletions src/TSMapEditor/Config/Default/ScriptActions.ini
Original file line number Diff line number Diff line change
Expand Up @@ -143,12 +143,10 @@ ParamType=Waypoint
[ChangeScript]
Name=Change Script
Description=Instructs the team to execute another script.
ParamType=ScriptType

[ChangeTeam]
Name=Change Team
Description=Instructs the TaskForce to join another TeamType.
ParamType=TeamType

[Panic]
Name=Panic
Expand Down
67 changes: 65 additions & 2 deletions src/TSMapEditor/UI/Windows/ScriptsWindow.cs
Original file line number Diff line number Diff line change
Expand Up @@ -634,6 +634,8 @@ private void SetParameterEntryText(ScriptActionEntry scriptActionEntry, ScriptAc
return;
}

lbActions.SelectedItem.Text = GetActionEntryText(scriptActionEntry.Action, scriptActionEntry);

if (action.ParamType == TriggerParamType.BuildingWithProperty)
{
tbParameterValue.Text = GetBuildingWithPropertyText(scriptActionEntry.Argument);
Expand Down Expand Up @@ -860,11 +862,72 @@ private void EditScript(Script script)

private string GetActionEntryText(int index, ScriptActionEntry entry)
{
string actionEntryText;
string textDetails = null;

ScriptAction action = GetScriptAction(entry.Action);
if (action == null)
return "#" + index + " - Unknown (" + entry.Argument.ToString(CultureInfo.InvariantCulture) + ")";
{
actionEntryText = $"#{index} - Unknown";
textDetails = $"({ entry.Argument.ToString(CultureInfo.InvariantCulture)})";
}
else
{
actionEntryText = $"#{index} - {action.Name}";
int presetOptionIndex = action.PresetOptions.FindIndex(presetOption => presetOption.Value == entry.Argument);
bool hasValidPresetOption = presetOptionIndex > -1;

switch (action.ParamType)
{
case TriggerParamType.BuildingWithProperty:
var (buildingTypeIndex, property) = SplitBuildingWithProperty(entry.Argument);
string propertyDescription = property.ToDescription();
BuildingType buildingType = map.Rules.BuildingTypes.GetElementIfInRange(buildingTypeIndex);

if (buildingType != null)
textDetails = $"({buildingType.GetEditorDisplayName()} - {propertyDescription})";
break;

case TriggerParamType.LocalVariable:
var localVar = map.LocalVariables.GetElementIfInRange(entry.Argument);
if (localVar != null)
textDetails = $"({localVar.Index} - {localVar.Name})";
break;

case TriggerParamType.HouseType:
var houseType = map.Houses.GetElementIfInRange(entry.Argument);
if (houseType != null)
textDetails = $"({houseType.ININame})";
break;

case TriggerParamType.Animation:
var animation = map.Rules.AnimTypes.GetElementIfInRange(entry.Argument);
if (animation != null)
textDetails = $"({animation.ININame})";
break;

case TriggerParamType.Unknown:
// special handling: script actions that have no type but still have presets should be handled by showing the preset value
// otherwise we'll show no text after the name of the action
if (hasValidPresetOption)
goto default;

textDetails = null;
break;

default:
if (hasValidPresetOption)
textDetails = $"({action.PresetOptions[presetOptionIndex].Text})";
else
textDetails = $"({entry.Argument.ToString(CultureInfo.InvariantCulture)})";
break;
}
}

if (string.IsNullOrEmpty(textDetails))
return actionEntryText;

return "#" + index + " - " + action.Name + " (" + entry.Argument.ToString(CultureInfo.InvariantCulture) + ")";
return $"{actionEntryText} {textDetails}";
}

private string GetActionNameFromIndex(int index)
Expand Down
Loading