Skip to content

Commit e97c754

Browse files
committed
Add logical support for listing global TaskForces, Scripts and TeamTypes in their selection windows
Checkboxes for the feature are disabled by default to avoid overwhelming users, especially new users
1 parent 2676ee3 commit e97c754

8 files changed

Lines changed: 104 additions & 19 deletions

File tree

src/TSMapEditor/Config/Default/UI/Windows/SelectScriptWindow.ini

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,10 @@
22
$Width=300
33
$Height=RESOLUTION_HEIGHT - 100
44
$CC0=lblDescription:XNALabel
5-
$CC1=tbSearch:EditorSuggestionTextBox
6-
$CC2=btnSelect:EditorButton
7-
$CC3=lbObjectList:EditorListBox
5+
$CC1=chkIncludeGlobalScripts:XNACheckBox
6+
$CC2=tbSearch:EditorSuggestionTextBox
7+
$CC3=btnSelect:EditorButton
8+
$CC4=lbObjectList:EditorListBox
89
HasCloseButton=true
910

1011

@@ -14,9 +15,16 @@ $Y=EMPTY_SPACE_TOP
1415
FontIndex=1
1516
$Text=translate(Select Script:)
1617

17-
[tbSearch]
18+
[chkIncludeGlobalScripts]
1819
$X=EMPTY_SPACE_SIDES
1920
$Y=getBottom(lblDescription) + EMPTY_SPACE_TOP
21+
$Text=translate(Include Global Scripts)
22+
; We don't want this check box to be available by default. Comment out or remove the line below to enable it.
23+
$Enabled=0
24+
25+
[tbSearch]
26+
$X=EMPTY_SPACE_SIDES
27+
$Y=ifElse(isVisible(chkIncludeGlobalScripts), getBottom(chkIncludeGlobalScripts) + VERTICAL_SPACING, getBottom(lblDescription) + EMPTY_SPACE_TOP)
2028
$Width=getWidth(SelectScriptWindow) - (EMPTY_SPACE_SIDES * 2)
2129
$Suggestion=translate(Search Scripts...)
2230

src/TSMapEditor/Config/Default/UI/Windows/SelectTaskForceWindow.ini

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,10 @@
22
$Width=300
33
$Height=RESOLUTION_HEIGHT - 100
44
$CC0=lblDescription:XNALabel
5-
$CC1=tbSearch:EditorSuggestionTextBox
6-
$CC2=btnSelect:EditorButton
7-
$CC3=lbObjectList:EditorListBox
5+
$CC1=chkIncludeGlobalTaskForces:XNACheckBox
6+
$CC2=tbSearch:EditorSuggestionTextBox
7+
$CC3=btnSelect:EditorButton
8+
$CC4=lbObjectList:EditorListBox
89
HasCloseButton=true
910

1011

@@ -14,9 +15,16 @@ $Y=EMPTY_SPACE_TOP
1415
FontIndex=1
1516
$Text=translate(Select TaskForce:)
1617

17-
[tbSearch]
18+
[chkIncludeGlobalTaskForces]
1819
$X=EMPTY_SPACE_SIDES
1920
$Y=getBottom(lblDescription) + EMPTY_SPACE_TOP
21+
$Text=translate(Include Global TaskForces)
22+
; We don't want this check box to be available by default. Comment out or remove the line below to enable it.
23+
$Enabled=0
24+
25+
[tbSearch]
26+
$X=EMPTY_SPACE_SIDES
27+
$Y=ifElse(isVisible(chkIncludeGlobalTaskForces), getBottom(chkIncludeGlobalTaskForces) + VERTICAL_SPACING, getBottom(lblDescription) + EMPTY_SPACE_TOP)
2028
$Width=getWidth(SelectTaskForceWindow) - (EMPTY_SPACE_SIDES * 2)
2129
$Suggestion=translate(Search TaskForce...)
2230

src/TSMapEditor/Config/Default/UI/Windows/SelectTeamTypeWindow.ini

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,10 @@
22
$Width=300
33
$Height=RESOLUTION_HEIGHT - 100
44
$CC0=lblDescription:XNALabel
5-
$CC1=tbSearch:EditorSuggestionTextBox
6-
$CC2=btnSelect:EditorButton
7-
$CC3=lbObjectList:EditorListBox
5+
$CC1=chkIncludeGlobalTeamTypes:XNACheckBox
6+
$CC2=tbSearch:EditorSuggestionTextBox
7+
$CC3=btnSelect:EditorButton
8+
$CC4=lbObjectList:EditorListBox
89
HasCloseButton=true
910

1011

@@ -14,9 +15,16 @@ $Y=EMPTY_SPACE_TOP
1415
FontIndex=1
1516
$Text=translate(Select TeamType:)
1617

17-
[tbSearch]
18+
[chkIncludeGlobalTeamTypes]
1819
$X=EMPTY_SPACE_SIDES
1920
$Y=getBottom(lblDescription) + EMPTY_SPACE_TOP
21+
$Text=translate(Include Global TeamTypes)
22+
; We don't want this check box to be available by default. Comment out or remove the line below to enable it.
23+
$Enabled=0
24+
25+
[tbSearch]
26+
$X=EMPTY_SPACE_SIDES
27+
$Y=ifElse(isVisible(chkIncludeGlobalTeamTypes), getBottom(chkIncludeGlobalTeamTypes) + VERTICAL_SPACING, getBottom(lblDescription) + EMPTY_SPACE_TOP)
2028
$Width=getWidth(SelectTeamTypeWindow) - (EMPTY_SPACE_SIDES * 2)
2129
$Suggestion=translate(Search TeamType...)
2230

src/TSMapEditor/Config/Translations/en/Translation_en.ini

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -359,6 +359,16 @@ WindowController.NoTriggerAttached.Description=The specified Tag has no attached
359359
ListExtensions.TaskForceParseError=Failed to load TaskForce {0}. It might be missing a section or be otherwise invalid.
360360
ListExtensions.TeamTypes.TaskForceNotFound=TeamType {0} has an invalid TaskForce ({1}) specified!
361361
362+
; *************************************************
363+
; Hint texts
364+
; *************************************************
365+
366+
TaskForce.GetHintText.Contains=Contains:
367+
TaskForce.GetHintText.TotalCost=Total Cost: ${0}
368+
TeamType.GetHintText.Owner=Owner: {0}
369+
TeamType.GetHintText.Script=Script: {0}
370+
TeamType.GetHintText.Waypoint=Waypoint: {0}
371+
362372
; *************************************************
363373
; TileSelector
364374
; *************************************************
@@ -397,6 +407,7 @@ TileInfoDisplay.CellTag=CellTag:\s
397407
TileInfoDisplay.UsagesOfWaypoint=Usages of waypoint {0}:
398408
TileInfoDisplay.TriggerInWaypoint=trigger '{0}',\s
399409
TileInfoDisplay.ScriptInWaypoint=script '{0}',\s
410+
TileInfoDisplay.TeamTypeInwaypoint=team '{0}',\s
400411
401412
; *************************************************
402413
; TopBarMenu
@@ -1009,6 +1020,7 @@ SelectScriptActionWindow.tbSearch.Suggestion=Search script action...
10091020
SelectScriptActionWindow.btnSelect.Text=Select
10101021
10111022
SelectScriptWindow.lblDescription.Text=Select Script:
1023+
SelectScriptWindow.chkIncludeGlobalScripts.Text=Include Global Scripts
10121024
SelectScriptWindow.tbSearch.Suggestion=Search Script...
10131025
SelectScriptWindow.btnSelect.Text=Select
10141026
@@ -1033,12 +1045,15 @@ SelectTagWindow.tbSearch.Suggestion=Search Tag...
10331045
SelectTagWindow.btnSelect.Text=Select
10341046
10351047
SelectTaskForceWindow.lblDescription.Text=Select TaskForce:
1048+
SelectTaskForceWindow.chkIncludeGlobalTaskForces.Text=Include Global TaskForces
10361049
SelectTaskForceWindow.tbSearch.Suggestion=Search TaskForce...
10371050
SelectTaskForceWindow.btnSelect.Text=Select
10381051
10391052
SelectTeamTypeWindow.lblDescription.Text=Select TeamType:
1053+
SelectTeamTypeWindow.chkIncludeGlobalTeamTypes.Text=Include Global TeamTypes
10401054
SelectTeamTypeWindow.tbSearch.Suggestion=Search TeamType...
10411055
SelectTeamTypeWindow.btnSelect.Text=Select
1056+
SelectTeamTypeWindow.None=None
10421057
10431058
SelectTechnoTypeWindow.lblDescription.Text=Select Techno Type:
10441059
SelectTechnoTypeWindow.tbSearch.Suggestion=Search Techno Type...

src/TSMapEditor/UI/Parser.cs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -398,6 +398,17 @@ private int GetFunctionIntegerValue()
398398
case "horizontalCenterOnParent":
399399
parsingControl.CenterOnParentHorizontally();
400400
return parsingControl.X;
401+
case "isVisible":
402+
return GetControl(parameters[0]).Visible ? 1 : 0;
403+
case "ifElse":
404+
if (parameters.Count != 3)
405+
throw new INIConfigException($"Incorrect number of parameters for function {functionName} in expression {Input}");
406+
407+
bool selector = GetExprValueWithContextSave(parameters[0], parsingControl) > 0;
408+
if (selector)
409+
return GetExprValueWithContextSave(parameters[1], parsingControl);
410+
411+
return GetExprValueWithContextSave(parameters[2], parsingControl);
401412

402413
default:
403414
throw new INIConfigException("Unknown function " + functionName + " in expression " + Input);

src/TSMapEditor/UI/Windows/SelectScriptWindow.cs

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
1-
using System;
2-
using Rampastring.XNAUI;
1+
using Rampastring.XNAUI;
32
using Rampastring.XNAUI.XNAControls;
3+
using System;
4+
using System.Collections.Generic;
5+
using System.Linq;
46
using TSMapEditor.Models;
57

68
namespace TSMapEditor.UI.Windows
@@ -14,10 +16,15 @@ public SelectScriptWindow(WindowManager windowManager, Map map) : base(windowMan
1416

1517
private readonly Map map;
1618

19+
private XNACheckBox chkIncludeGlobalScripts;
20+
1721
public override void Initialize()
1822
{
1923
Name = nameof(SelectScriptWindow);
2024
base.Initialize();
25+
26+
chkIncludeGlobalScripts = FindChild<XNACheckBox>(nameof(chkIncludeGlobalScripts));
27+
chkIncludeGlobalScripts.CheckedChanged += (_, _) => ListObjects();
2128
}
2229

2330
protected override void LbObjectList_SelectedIndexChanged(object sender, EventArgs e)
@@ -35,14 +42,19 @@ protected override void ListObjects()
3542
{
3643
lbObjectList.Clear();
3744

38-
foreach (Script script in map.Scripts)
45+
IEnumerable<Script> list = map.Scripts;
46+
if (chkIncludeGlobalScripts.Checked)
47+
list = map.Scripts.UnionBy(map.Rules.Scripts, script => script.ININame);
48+
49+
foreach (Script script in list)
3950
{
4051
lbObjectList.AddItem(new XNAListBoxItem()
4152
{
4253
Text = $"{script.Name} ({script.ININame})",
4354
Tag = script,
4455
TextColor = script.EditorColor == null ? lbObjectList.DefaultItemColor : script.XNAColor
4556
});
57+
4658
if (script == SelectedObject)
4759
lbObjectList.SelectedIndex = lbObjectList.Items.Count - 1;
4860
}

src/TSMapEditor/UI/Windows/SelectTaskForceWindow.cs

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
24
using Rampastring.XNAUI;
35
using Rampastring.XNAUI.XNAControls;
46
using TSMapEditor.Models;
@@ -17,10 +19,15 @@ public SelectTaskForceWindow(WindowManager windowManager, Map map) : base(window
1719

1820
private readonly Map map;
1921

22+
private XNACheckBox chkIncludeGlobalTaskForces;
23+
2024
public override void Initialize()
2125
{
2226
Name = nameof(SelectTaskForceWindow);
2327
base.Initialize();
28+
29+
chkIncludeGlobalTaskForces = FindChild<XNACheckBox>(nameof(chkIncludeGlobalTaskForces));
30+
chkIncludeGlobalTaskForces.CheckedChanged += (_, _) => ListObjects();
2431
}
2532

2633
protected override void LbObjectList_SelectedIndexChanged(object sender, EventArgs e)
@@ -38,9 +45,14 @@ protected override void ListObjects()
3845
{
3946
lbObjectList.Clear();
4047

41-
foreach (TaskForce taskForce in map.TaskForces)
48+
IEnumerable<TaskForce> list = map.TaskForces;
49+
if (chkIncludeGlobalTaskForces.Checked)
50+
list = map.TaskForces.UnionBy(map.Rules.TaskForces, tf => tf.ININame);
51+
52+
foreach (TaskForce taskForce in list)
4253
{
4354
lbObjectList.AddItem(new XNAListBoxItem() { Text = $"{taskForce.Name} ({taskForce.ININame})", Tag = taskForce });
55+
4456
if (taskForce == SelectedObject)
4557
lbObjectList.SelectedIndex = lbObjectList.Items.Count - 1;
4658
}

src/TSMapEditor/UI/Windows/SelectTeamTypeWindow.cs

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
1-
using System;
2-
using Rampastring.XNAUI;
1+
using Rampastring.XNAUI;
32
using Rampastring.XNAUI.XNAControls;
3+
using System;
4+
using System.Collections.Generic;
5+
using System.Linq;
46
using TSMapEditor.Models;
57

68
namespace TSMapEditor.UI.Windows
@@ -18,10 +20,15 @@ public SelectTeamTypeWindow(WindowManager windowManager, Map map) : base(windowM
1820

1921
public bool IsForSecondaryTeam { get; set; }
2022

23+
private XNACheckBox chkIncludeGlobalTeamTypes;
24+
2125
public override void Initialize()
2226
{
2327
Name = nameof(SelectTeamTypeWindow);
2428
base.Initialize();
29+
30+
chkIncludeGlobalTeamTypes = FindChild<XNACheckBox>(nameof(chkIncludeGlobalTeamTypes));
31+
chkIncludeGlobalTeamTypes.CheckedChanged += (_, _) => ListObjects();
2532
}
2633

2734
protected override void LbObjectList_SelectedIndexChanged(object sender, EventArgs e)
@@ -42,7 +49,11 @@ protected override void ListObjects()
4249
if (IncludeNone)
4350
lbObjectList.AddItem(Translate(this, "None", "None"));
4451

45-
foreach (TeamType teamType in map.TeamTypes)
52+
IEnumerable<TeamType> list = map.TeamTypes;
53+
if (chkIncludeGlobalTeamTypes.Checked)
54+
list = map.TeamTypes.UnionBy(map.Rules.TeamTypes, teamType => teamType.ININame);
55+
56+
foreach (TeamType teamType in list)
4657
{
4758
lbObjectList.AddItem(new XNAListBoxItem() { Text = $"{teamType.ININame} {teamType.Name}", TextColor = teamType.GetXNAColor(), Tag = teamType });
4859
if (teamType == SelectedObject)

0 commit comments

Comments
 (0)