diff --git a/src/TSMapEditor/CCEngine/ScriptAction.cs b/src/TSMapEditor/CCEngine/ScriptAction.cs index dd0ce7c87..780610483 100644 --- a/src/TSMapEditor/CCEngine/ScriptAction.cs +++ b/src/TSMapEditor/CCEngine/ScriptAction.cs @@ -1,11 +1,12 @@ -using Rampastring.Tools; +using Microsoft.Xna.Framework; +using Rampastring.Tools; using System; using System.Collections.Generic; using TSMapEditor.Models.Enums; namespace TSMapEditor.CCEngine { - public struct ScriptActionPresetOption + public class ScriptActionPresetOption { public int Value; public string Text; @@ -18,7 +19,10 @@ public ScriptActionPresetOption(int value, string text) public string GetOptionText() { - return Value + " - " + Text; + if (string.IsNullOrEmpty(Text)) + return Value.ToString(); + else + return Value + " - " + Text; } } @@ -36,6 +40,7 @@ public ScriptAction(int id) public string OptionsSectionName { get; set; } = string.Empty; public TriggerParamType ParamType { get; set; } = TriggerParamType.Unknown; public List PresetOptions { get; } = new List(0); + public bool UseWindowSelection { get; set; } = false; public void ReadIniSection(IniFile iniFile, string sectionName) { @@ -45,6 +50,7 @@ public void ReadIniSection(IniFile iniFile, string sectionName) Description = iniSection.GetStringValue(nameof(Description), Description); OptionsSectionName = iniSection.GetStringValue(nameof(OptionsSectionName), OptionsSectionName); ParamDescription = iniSection.GetStringValue(nameof(ParamDescription), ParamDescription); + UseWindowSelection = iniSection.GetBooleanValue(nameof(UseWindowSelection), UseWindowSelection); if (Enum.TryParse(iniSection.GetStringValue(nameof(ParamType), "Unknown"), out TriggerParamType result)) { ParamType = result; diff --git a/src/TSMapEditor/Config/Default/UI/Windows/ScriptsWindow.ini b/src/TSMapEditor/Config/Default/UI/Windows/ScriptsWindow.ini index 937bd4a5f..7d2229a2f 100644 --- a/src/TSMapEditor/Config/Default/UI/Windows/ScriptsWindow.ini +++ b/src/TSMapEditor/Config/Default/UI/Windows/ScriptsWindow.ini @@ -27,8 +27,9 @@ $CC22=selTypeOfAction:EditorPopUpSelector $CC23=lblParameterDescription:XNALabel $CC24=tbParameterValue:EditorNumberTextBox $CC25=btnEditorPresetValues:MenuButton -$CC26=lblActionDescription:XNALabel -$CC27=panelActionDescription:EditorPanel +$CC26=btnEditorPresetValuesWindow:EditorButton +$CC27=lblActionDescription:XNALabel +$CC28=panelActionDescription:EditorPanel HasCloseButton=true [lblWindowDescription] @@ -177,6 +178,13 @@ $Width=getWidth(ScriptsWindow) - getRight(tbParameterValue) - EMPTY_SPACE_SIDES $Height=getHeight(tbParameterValue) Text=v +[btnEditorPresetValuesWindow] +$X=getX(btnEditorPresetValues) +$Y=getY(btnEditorPresetValues) +$Width=getWidth(btnEditorPresetValues) +$Height=getHeight(btnEditorPresetValues) +Text=... + [lblActionDescription] $X=getX(lblName) $Y=getBottom(tbParameterValue) + VERTICAL_SPACING diff --git a/src/TSMapEditor/Config/Default/UI/Windows/SelectScriptActionPresetOptionWindow.ini b/src/TSMapEditor/Config/Default/UI/Windows/SelectScriptActionPresetOptionWindow.ini new file mode 100644 index 000000000..6259481a7 --- /dev/null +++ b/src/TSMapEditor/Config/Default/UI/Windows/SelectScriptActionPresetOptionWindow.ini @@ -0,0 +1,32 @@ +[SelectScriptActionPresetOptionWindow] +$Width=350 +$Height=RESOLUTION_HEIGHT - 100 +$CC0=lblDescription:XNALabel +$CC1=tbSearch:EditorSuggestionTextBox +$CC2=btnSelect:EditorButton +$CC3=lbObjectList:EditorListBox + +[lblDescription] +$X=EMPTY_SPACE_SIDES +$Y=EMPTY_SPACE_TOP +FontIndex=1 +Text=Select parameter value: + +[tbSearch] +$X=EMPTY_SPACE_SIDES +$Y=getBottom(lblDescription) + EMPTY_SPACE_TOP +$Width=getWidth(SelectScriptActionPresetOptionWindow) - (EMPTY_SPACE_SIDES * 2) +Suggestion=Search parameter values... + +[btnSelect] +$Width=100 +$X=(getWidth(SelectScriptActionPresetOptionWindow) - getWidth(btnSelect)) / 2 +$Y=getHeight(SelectScriptActionPresetOptionWindow) - EMPTY_SPACE_BOTTOM - getHeight(btnSelect) +Text=Select + +[lbObjectList] +$X=EMPTY_SPACE_SIDES +$Y=getBottom(tbSearch) + VERTICAL_SPACING +$Width=getWidth(tbSearch) +$Height=getY(btnSelect) - getY(lbObjectList) - EMPTY_SPACE_TOP + diff --git a/src/TSMapEditor/TSMapEditor.csproj b/src/TSMapEditor/TSMapEditor.csproj index 4ab667e65..b7e348e27 100644 --- a/src/TSMapEditor/TSMapEditor.csproj +++ b/src/TSMapEditor/TSMapEditor.csproj @@ -225,6 +225,9 @@ PreserveNewest + + PreserveNewest + PreserveNewest diff --git a/src/TSMapEditor/UI/Windows/ScriptsWindow.cs b/src/TSMapEditor/UI/Windows/ScriptsWindow.cs index 6b54e1bb6..5d81b4998 100644 --- a/src/TSMapEditor/UI/Windows/ScriptsWindow.cs +++ b/src/TSMapEditor/UI/Windows/ScriptsWindow.cs @@ -52,10 +52,12 @@ public ScriptsWindow(WindowManager windowManager, Map map, EditorState editorSta private XNALabel lblParameterDescription; private EditorNumberTextBox tbParameterValue; private MenuButton btnEditorPresetValues; + private EditorButton btnEditorPresetValuesWindow; private XNALabel lblActionDescriptionValue; private XNADropDown ddScriptColor; private SelectScriptActionWindow selectScriptActionWindow; + private SelectScriptActionPresetOptionWindow selectScriptActionPresetOptionWindow; private EditorContextMenu actionListContextMenu; private SelectBuildingTargetWindow selectBuildingTargetWindow; @@ -92,6 +94,7 @@ public override void Initialize() lblParameterDescription = FindChild(nameof(lblParameterDescription)); tbParameterValue = FindChild(nameof(tbParameterValue)); btnEditorPresetValues = FindChild(nameof(btnEditorPresetValues)); + btnEditorPresetValuesWindow = FindChild(nameof(btnEditorPresetValuesWindow)); lblActionDescriptionValue = FindChild(nameof(lblActionDescriptionValue)); ddScriptColor = FindChild(nameof(ddScriptColor)); @@ -109,6 +112,9 @@ public override void Initialize() btnEditorPresetValues.ContextMenu.OptionSelected += ContextMenu_OptionSelected; btnEditorPresetValues.LeftClick += BtnEditorPresetValues_LeftClick; + btnEditorPresetValuesWindow.LeftClick += BtnEditorPresetValuesWindow_LeftClick; + btnEditorPresetValuesWindow.Disable(); + tbName.TextChanged += TbName_TextChanged; tbParameterValue.TextChanged += TbParameterValue_TextChanged; lbScriptTypes.SelectedIndexChanged += LbScriptTypes_SelectedIndexChanged; @@ -143,6 +149,10 @@ public override void Initialize() var selectScriptActionDarkeningPanel = DarkeningPanel.InitializeAndAddToParentControlWithChild(WindowManager, Parent, selectScriptActionWindow); selectScriptActionDarkeningPanel.Hidden += SelectScriptActionDarkeningPanel_Hidden; + selectScriptActionPresetOptionWindow = new SelectScriptActionPresetOptionWindow(WindowManager, map); + var selectScriptActionPresetDarkeningPanel = DarkeningPanel.InitializeAndAddToParentControlWithChild(WindowManager, Parent, selectScriptActionPresetOptionWindow); + selectScriptActionPresetDarkeningPanel.Hidden += SelectScriptActionPresetDarkeningPanel_Hidden; + selectBuildingTargetWindow = new SelectBuildingTargetWindow(WindowManager, map); var buildingTargetWindowDarkeningPanel = DarkeningPanel.InitializeAndAddToParentControlWithChild(WindowManager, Parent, selectBuildingTargetWindow); buildingTargetWindowDarkeningPanel.Hidden += BuildingTargetWindowDarkeningPanel_Hidden; @@ -294,6 +304,18 @@ private void BtnEditorPresetValues_LeftClick(object sender, EventArgs e) } } + private void BtnEditorPresetValuesWindow_LeftClick(object sender, EventArgs e) + { + if (editedScript == null) + return; + + if (lbActions.SelectedItem == null) + return; + + var item = selectScriptActionPresetOptionWindow.GetMatchingItem(tbParameterValue.Text); + selectScriptActionPresetOptionWindow.Open(item); + } + private void ShowScriptReferences() { if (editedScript == null) @@ -502,6 +524,18 @@ private void SelectScriptActionDarkeningPanel_Hidden(object sender, EventArgs e) InputIgnoreTime = TimeSpan.FromSeconds(Constants.UIAccidentalClickPreventionTime); } + + private void SelectScriptActionPresetDarkeningPanel_Hidden(object sender, EventArgs e) + { + if (lbActions.SelectedItem == null || editedScript == null) + { + return; + } + + if (selectScriptActionPresetOptionWindow.SelectedObject != null) + tbParameterValue.Text = selectScriptActionPresetOptionWindow.GetSelectedItemText(); + } + private void LbActions_SelectedIndexChanged(object sender, EventArgs e) { if (lbActions.SelectedItem == null || editedScript == null) @@ -526,7 +560,23 @@ private void LbActions_SelectedIndexChanged(object sender, EventArgs e) lblParameterDescription.Text = action == null ? "Parameter:" : action.ParamDescription + ":"; lblActionDescriptionValue.Text = GetActionDescriptionFromIndex(entry.Action); - FillPresetContextMenu(entry, action); + string text = null; + + if (action.UseWindowSelection && action.PresetOptions.Count > 0) + { + btnEditorPresetValues.Disable(); + btnEditorPresetValuesWindow.Enable(); + text = selectScriptActionPresetOptionWindow.FillPresetOptions(entry, action); + } + else + { + btnEditorPresetValues.Enable(); + btnEditorPresetValuesWindow.Disable(); + text = FillPresetContextMenu(entry, action); + } + + if (text != null) + tbParameterValue.Text = text; } private void SetParameterEntryText(ScriptActionEntry scriptActionEntry, ScriptAction action) @@ -585,13 +635,13 @@ private string GetBuildingWithPropertyText(int argument) return GetBuildingWithPropertyText(index, property); } - private void FillPresetContextMenu(ScriptActionEntry entry, ScriptAction action) + private string FillPresetContextMenu(ScriptActionEntry entry, ScriptAction action) { btnEditorPresetValues.ContextMenu.ClearItems(); if (action == null) { - return; + return null; } action.PresetOptions.ForEach(p => btnEditorPresetValues.ContextMenu.AddItem(new XNAContextMenuItem() { Text = p.GetOptionText() })); @@ -630,7 +680,9 @@ private void FillPresetContextMenu(ScriptActionEntry entry, ScriptAction action) fittingItem = btnEditorPresetValues.ContextMenu.Items.Find(item => item.Text.StartsWith(entry.Argument.ToString())); if (fittingItem != null) - tbParameterValue.Text = fittingItem.Text; + return fittingItem.Text; + + return null; } private void LbScriptTypes_SelectedIndexChanged(object sender, EventArgs e) => RefreshSelectedScript(); @@ -734,9 +786,9 @@ private void EditScript(Script script) for (int i = 0; i < editedScript.Actions.Count; i++) { var actionEntry = editedScript.Actions[i]; - lbActions.AddItem(new XNAListBoxItem() - { - Text = GetActionEntryText(i, actionEntry), + lbActions.AddItem(new XNAListBoxItem() + { + Text = GetActionEntryText(i, actionEntry), Tag = actionEntry }); } @@ -754,7 +806,7 @@ private string GetActionEntryText(int index, ScriptActionEntry entry) { ScriptAction action = GetScriptAction(entry.Action); if (action == null) - return "#" + index + " - Unknown (" + entry.Argument.ToString(CultureInfo.InvariantCulture) + ")"; + return "#" + index + " - Unknown (" + entry.Argument.ToString(CultureInfo.InvariantCulture) + ")"; return "#" + index + " - " + action.Name + " (" + entry.Argument.ToString(CultureInfo.InvariantCulture) + ")"; } diff --git a/src/TSMapEditor/UI/Windows/SelectScriptActionPresetOptionWindow.cs b/src/TSMapEditor/UI/Windows/SelectScriptActionPresetOptionWindow.cs new file mode 100644 index 000000000..313d1bcdd --- /dev/null +++ b/src/TSMapEditor/UI/Windows/SelectScriptActionPresetOptionWindow.cs @@ -0,0 +1,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 + { + public SelectScriptActionPresetOptionWindow(WindowManager windowManager, Map map) : base(windowManager) + { + this.map = map; + } + + private Map map; + public List presetOptions { get; } = new List(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; + } + } +}