Skip to content
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
1 change: 1 addition & 0 deletions src/TSMapEditor/Config/Translations/en/Translation_en.ini
Original file line number Diff line number Diff line change
Expand Up @@ -372,6 +372,7 @@ WindowController.NoTriggerAttached.Title=No trigger attached
WindowController.NoTriggerAttached.Description=The specified Tag has no attached Trigger!
ListExtensions.TaskForceParseError=Failed to load TaskForce {0}. It might be missing a section or be otherwise invalid.
ListExtensions.TeamTypes.TaskForceNotFound=TeamType {0} has an invalid TaskForce ({1}) specified!
CloneName=\s(Clone)

; *************************************************
; Hint texts
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2385,8 +2385,5 @@ SetMapDifficultySettingsWindow.lblTeamDelayEasy.Text=简单:
SetMapDifficultySettingsWindow.btnApply.Text=应用

TriggersWindow.UnknownSpeech=\s- 未知语音
Trigger.CloneName=\s(副本)
TaskForce.CloneName=\s(副本)
TeamType.CloneName=\s(副本)
Script.CloneName=\s(副本)
CloneName=\s(副本)
TeamTypes.Global=(全局)\s
24 changes: 24 additions & 0 deletions src/TSMapEditor/Helpers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -847,5 +847,29 @@ public static string DifficultyToTranslatedString(Difficulty difficulty)
throw new NotImplementedException(nameof(DifficultyToTranslatedString) + ": Unknown difficulty level " + difficulty);
}
}

/// <summary>
/// Shared helper function used by Triggers, TaskForces, Scripts, TeamTypes, and AI Triggers.
/// Used to generate the name of the instance during the cloning process of those entities.
/// If the provided name contains a number, the number is incremented and the name is returned as is.
/// Otherwise, a localized " (Clone)" suffix is appended to the name.
/// If there are multiple numbers in the name, only the first is incremented.
/// </summary>
public static string GetNameForClone(string name)
{
string[] parts = name.Split(" ");
int numPart = -1;

for (int i = 0; i < parts.Length; i++)
{
if (int.TryParse(parts[i], out numPart) && numPart >= 0)
{
parts[i] = (numPart + 1).ToString(CultureInfo.InvariantCulture);
return string.Join(" ", parts);
}
}

return name + Translate("CloneName", " (Clone)");
}
}
}
2 changes: 1 addition & 1 deletion src/TSMapEditor/Models/AITriggerType.cs
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ public AITriggerType(string iniName)
public AITriggerType Clone(string newUniqueId)
{
var clonedAITrigger = (AITriggerType)MemberwiseClone();
clonedAITrigger.Name = Name + " (Clone)";
clonedAITrigger.Name = Helpers.GetNameForClone(Name);
clonedAITrigger.ININame = newUniqueId;
return clonedAITrigger;
}
Expand Down
2 changes: 1 addition & 1 deletion src/TSMapEditor/Models/Script.cs
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ public string EditorColor
public Script Clone(string iniName)
{
var script = new Script(iniName);
script.Name = Name + Translate(this, "CloneName", " (Clone)");
script.Name = Helpers.GetNameForClone(Name);
script.EditorColor = EditorColor;

foreach (var action in Actions)
Expand Down
2 changes: 1 addition & 1 deletion src/TSMapEditor/Models/TaskForce.cs
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ public string GetHintText()
public TaskForce Clone(string iniName)
{
var newTaskForce = new TaskForce(iniName);
newTaskForce.Name = Name + Translate(this, "CloneName", " (Clone)");
newTaskForce.Name = Helpers.GetNameForClone(Name);
newTaskForce.Group = Group;

for (int i = 0; i < TechnoTypes.Length; i++)
Expand Down
2 changes: 1 addition & 1 deletion src/TSMapEditor/Models/TeamType.cs
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ public TeamType Clone(string iniName)
{
var clone = MemberwiseClone() as TeamType;
clone.ININame = iniName;
clone.Name = Name + Translate(this, "CloneName", " (Clone)");
clone.Name = Helpers.GetNameForClone(Name);

clone.EnabledTeamTypeFlags = new List<string>(EnabledTeamTypeFlags);

Expand Down
2 changes: 1 addition & 1 deletion src/TSMapEditor/Models/Trigger.cs
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ public Trigger Clone(string uniqueId)
{
Trigger clone = (Trigger)MemberwiseClone();
clone.ID = uniqueId;
clone.Name = Name + Translate(this, "CloneName", " (Clone)");
clone.Name = Helpers.GetNameForClone(Name);

// Deep clone the events and actions

Expand Down
Loading