Skip to content

Commit fd4fc14

Browse files
committed
Add animation selection support to scripts window
1 parent 6305154 commit fd4fc14

2 files changed

Lines changed: 48 additions & 1 deletion

File tree

src/TSMapEditor/UI/Windows/ScriptsWindow.cs

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ public ScriptsWindow(WindowManager windowManager, Map map, EditorState editorSta
6161
private EditorContextMenu actionListContextMenu;
6262

6363
private SelectBuildingTargetWindow selectBuildingTargetWindow;
64+
private SelectAnimationWindow selectAnimationWindow;
6465

6566
private Script editedScript;
6667

@@ -157,6 +158,11 @@ public override void Initialize()
157158
var buildingTargetWindowDarkeningPanel = DarkeningPanel.InitializeAndAddToParentControlWithChild(WindowManager, Parent, selectBuildingTargetWindow);
158159
buildingTargetWindowDarkeningPanel.Hidden += BuildingTargetWindowDarkeningPanel_Hidden;
159160

161+
selectAnimationWindow = new SelectAnimationWindow(WindowManager, map);
162+
selectAnimationWindow.IncludeNone = false;
163+
var animationWindowDarkeningPanel = DarkeningPanel.InitializeAndAddToParentControlWithChild(WindowManager, Parent, selectAnimationWindow);
164+
animationWindowDarkeningPanel.Hidden += AnimationWindowDarkeningPanel_Hidden;
165+
160166
selTypeOfAction.MouseLeftDown += SelTypeOfAction_MouseLeftDown;
161167

162168
FindChild<EditorButton>("btnAddScript").LeftClick += BtnAddScript_LeftClick;
@@ -185,6 +191,18 @@ public override void Initialize()
185191
lbActions.RightClick += (s, e) => { if (editedScript != null) { lbActions.SelectedIndex = lbActions.HoveredIndex; actionListContextMenu.Open(GetCursorPoint()); } };
186192
}
187193

194+
private void AnimationWindowDarkeningPanel_Hidden(object sender, EventArgs e)
195+
{
196+
if (editedScript == null || lbActions.SelectedItem == null)
197+
return;
198+
199+
if (selectAnimationWindow.SelectedObject != null)
200+
{
201+
editedScript.Actions[lbActions.SelectedIndex].Argument = selectAnimationWindow.SelectedObject.Index;
202+
RefreshParameterEntryText();
203+
}
204+
}
205+
188206
private void BuildingTargetWindowDarkeningPanel_Hidden(object sender, EventArgs e)
189207
{
190208
if (editedScript == null || lbActions.SelectedItem == null)
@@ -302,6 +320,11 @@ private void BtnEditorPresetValues_LeftClick(object sender, EventArgs e)
302320
var (index, property) = SplitBuildingWithProperty(entry.Argument);
303321
selectBuildingTargetWindow.Open(index, property);
304322
}
323+
else if (action.ParamType == TriggerParamType.Animation)
324+
{
325+
var animType = entry.Argument > -1 && entry.Argument < map.Rules.AnimTypes.Count ? map.Rules.AnimTypes[entry.Argument] : null;
326+
selectAnimationWindow.Open(animType);
327+
}
305328
}
306329

307330
private void BtnEditorPresetValuesWindow_LeftClick(object sender, EventArgs e)
@@ -536,6 +559,18 @@ private void SelectScriptActionPresetDarkeningPanel_Hidden(object sender, EventA
536559
tbParameterValue.Text = selectScriptActionPresetOptionWindow.GetSelectedItemText();
537560
}
538561

562+
private void RefreshParameterEntryText()
563+
{
564+
if (lbActions.SelectedItem == null || editedScript == null)
565+
return;
566+
567+
ScriptActionEntry entry = editedScript.Actions[lbActions.SelectedIndex];
568+
ScriptAction action = map.EditorConfig.ScriptActions.GetValueOrDefault(entry.Action);
569+
tbParameterValue.TextChanged -= TbParameterValue_TextChanged;
570+
SetParameterEntryText(entry, action);
571+
tbParameterValue.TextChanged += TbParameterValue_TextChanged;
572+
}
573+
539574
private void LbActions_SelectedIndexChanged(object sender, EventArgs e)
540575
{
541576
if (lbActions.SelectedItem == null || editedScript == null)
@@ -592,6 +627,15 @@ private void SetParameterEntryText(ScriptActionEntry scriptActionEntry, ScriptAc
592627
tbParameterValue.Text = GetBuildingWithPropertyText(scriptActionEntry.Argument);
593628
return;
594629
}
630+
else if (action.ParamType == TriggerParamType.Animation)
631+
{
632+
if (scriptActionEntry.Argument > -1 && scriptActionEntry.Argument < map.Rules.AnimTypes.Count)
633+
tbParameterValue.Text = scriptActionEntry.Argument.ToString(CultureInfo.InvariantCulture) + " - " + map.Rules.AnimTypes[scriptActionEntry.Argument].ININame;
634+
else
635+
tbParameterValue.Text = scriptActionEntry.Argument.ToString(CultureInfo.InvariantCulture) + " - unknown animation";
636+
637+
return;
638+
}
595639

596640
int presetIndex = action.PresetOptions.FindIndex(p => p.Value == scriptActionEntry.Argument);
597641

src/TSMapEditor/UI/Windows/SelectAnimationWindow.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ public SelectAnimationWindow(WindowManager windowManager, Map map) : base(window
1414

1515
private readonly Map map;
1616

17+
public bool IncludeNone { get; set; } = true;
18+
1719
public override void Initialize()
1820
{
1921
Name = nameof(SelectAnimationWindow);
@@ -35,7 +37,8 @@ protected override void ListObjects()
3537
{
3638
lbObjectList.Clear();
3739

38-
lbObjectList.AddItem(new XNAListBoxItem() { Text = "None" });
40+
if (IncludeNone)
41+
lbObjectList.AddItem(new XNAListBoxItem() { Text = "None" });
3942

4043
foreach (AnimType animType in map.Rules.AnimTypes)
4144
{

0 commit comments

Comments
 (0)