forked from CnCNet/WorldAlteringEditor
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSelectScriptActionPresetOptionWindow.cs
More file actions
80 lines (64 loc) · 2.42 KB
/
SelectScriptActionPresetOptionWindow.cs
File metadata and controls
80 lines (64 loc) · 2.42 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
using Microsoft.Xna.Framework;
using Rampastring.XNAUI;
using Rampastring.XNAUI.XNAControls;
using System;
using System.Collections.Generic;
using TSMapEditor.CCEngine;
using TSMapEditor.Models;
using TSMapEditor.Models.Enums;
namespace TSMapEditor.UI.Windows
{
public class SelectScriptActionPresetOptionWindow : SelectObjectWindow<ScriptActionPresetOption>
{
public SelectScriptActionPresetOptionWindow(WindowManager windowManager, Map map) : base(windowManager)
{
this.map = map;
}
private Map map;
public List<ScriptActionPresetOption> presetOptions { get; } = new List<ScriptActionPresetOption>(0);
public override void Initialize()
{
Name = nameof(SelectScriptActionPresetOptionWindow);
base.Initialize();
}
protected override void LbObjectList_SelectedIndexChanged(object sender, EventArgs e)
{
if (lbObjectList.SelectedItem == null)
{
SelectedObject = null;
return;
}
SelectedObject = (ScriptActionPresetOption)lbObjectList.SelectedItem.Tag;
}
protected override void ListObjects()
{
lbObjectList.Clear();
foreach (ScriptActionPresetOption presetOption in presetOptions)
{
var item = new XNAListBoxItem() { Text = $"{presetOption.GetOptionText()}", Tag = presetOption };
lbObjectList.AddItem(item);
if (presetOption == SelectedObject)
lbObjectList.SelectedIndex = lbObjectList.Items.Count - 1;
}
}
public string FillPresetOptions(ScriptActionEntry entry, ScriptAction action)
{
presetOptions.Clear();
presetOptions.AddRange(action.PresetOptions);
var fittingItem = presetOptions.Find(item => item.Text.StartsWith(entry.Argument.ToString()));
if (fittingItem != null)
return fittingItem.Text;
return null;
}
public ScriptActionPresetOption GetMatchingItem(string text)
{
return presetOptions.Find(item => item.GetOptionText().Equals(text, StringComparison.Ordinal));
}
public string GetSelectedItemText()
{
if (SelectedObject != null)
return SelectedObject.GetOptionText();
return string.Empty;
}
}
}