From de54507875a1e06903d29800ec7bce3f11fa9dd2 Mon Sep 17 00:00:00 2001 From: Starkku Date: Wed, 12 Jun 2024 00:16:42 +0300 Subject: [PATCH] Add superweapon selector window and support for superweapon ID parameter type --- .../Windows/SelectSuperWeaponTypeWindow.ini | 34 +++++++++++ .../Models/Enums/TriggerParamType.cs | 3 +- src/TSMapEditor/TSMapEditor.csproj | 3 + .../UI/Windows/SelectSuperWeaponTypeWindow.cs | 47 ++++++++++++++++ src/TSMapEditor/UI/Windows/TriggersWindow.cs | 56 ++++++++++++++++--- 5 files changed, 134 insertions(+), 9 deletions(-) create mode 100644 src/TSMapEditor/Config/UI/Windows/SelectSuperWeaponTypeWindow.ini create mode 100644 src/TSMapEditor/UI/Windows/SelectSuperWeaponTypeWindow.cs diff --git a/src/TSMapEditor/Config/UI/Windows/SelectSuperWeaponTypeWindow.ini b/src/TSMapEditor/Config/UI/Windows/SelectSuperWeaponTypeWindow.ini new file mode 100644 index 000000000..8bc3ead47 --- /dev/null +++ b/src/TSMapEditor/Config/UI/Windows/SelectSuperWeaponTypeWindow.ini @@ -0,0 +1,34 @@ +[SelectSuperWeaponTypeWindow] +$Width=400 +$Height=RESOLUTION_HEIGHT - 100 +$CC0=lblDescription:XNALabel +$CC1=tbSearch:EditorSuggestionTextBox +$CC2=btnSelect:EditorButton +$CC3=lbObjectList:EditorListBox +HasCloseButton=true + + +[lblDescription] +$X=EMPTY_SPACE_SIDES +$Y=EMPTY_SPACE_TOP +FontIndex=1 +Text=Select SuperWeapon: + +[tbSearch] +$X=EMPTY_SPACE_SIDES +$Y=getBottom(lblDescription) + EMPTY_SPACE_TOP +$Width=getWidth(SelectSuperWeaponTypeWindow) - (EMPTY_SPACE_SIDES * 2) +Suggestion=Search SuperWeapon... + +[btnSelect] +$Width=100 +$X=(getWidth(SelectSuperWeaponTypeWindow) - getWidth(btnSelect)) / 2 +$Y=getHeight(SelectSuperWeaponTypeWindow) - 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/Models/Enums/TriggerParamType.cs b/src/TSMapEditor/Models/Enums/TriggerParamType.cs index 7a75e9ae6..37056c61d 100644 --- a/src/TSMapEditor/Models/Enums/TriggerParamType.cs +++ b/src/TSMapEditor/Models/Enums/TriggerParamType.cs @@ -37,6 +37,7 @@ public enum TriggerParamType SpotlightBehaviour, RadarEvent, VoxelAnim, - StringTableEntry + StringTableEntry, + SuperWeaponID } } diff --git a/src/TSMapEditor/TSMapEditor.csproj b/src/TSMapEditor/TSMapEditor.csproj index 931bc1c15..f60bf436c 100644 --- a/src/TSMapEditor/TSMapEditor.csproj +++ b/src/TSMapEditor/TSMapEditor.csproj @@ -230,6 +230,9 @@ PreserveNewest + + PreserveNewest + PreserveNewest diff --git a/src/TSMapEditor/UI/Windows/SelectSuperWeaponTypeWindow.cs b/src/TSMapEditor/UI/Windows/SelectSuperWeaponTypeWindow.cs new file mode 100644 index 000000000..1f8c1c42f --- /dev/null +++ b/src/TSMapEditor/UI/Windows/SelectSuperWeaponTypeWindow.cs @@ -0,0 +1,47 @@ +using Rampastring.XNAUI; +using Rampastring.XNAUI.XNAControls; +using System; +using TSMapEditor.Models; + +namespace TSMapEditor.UI.Windows +{ + public class SelectSuperWeaponTypeWindow : SelectObjectWindow + { + public SelectSuperWeaponTypeWindow(WindowManager windowManager, Map map) : base(windowManager) + { + this.map = map; + } + + private readonly Map map; + public bool UseININameAsValue { get; set; } + + public override void Initialize() + { + Name = nameof(SelectSuperWeaponTypeWindow); + base.Initialize(); + } + + protected override void LbObjectList_SelectedIndexChanged(object sender, EventArgs e) + { + if (lbObjectList.SelectedItem == null) + { + SelectedObject = null; + return; + } + + SelectedObject = (SuperWeaponType)lbObjectList.SelectedItem.Tag; + } + + protected override void ListObjects() + { + lbObjectList.Clear(); + + foreach (var swType in map.Rules.SuperWeaponTypes) + { + lbObjectList.AddItem(new XNAListBoxItem() { Text = swType.GetDisplayString(), Tag = swType }); + if (swType == SelectedObject) + lbObjectList.SelectedIndex = lbObjectList.Items.Count - 1; + } + } + } +} diff --git a/src/TSMapEditor/UI/Windows/TriggersWindow.cs b/src/TSMapEditor/UI/Windows/TriggersWindow.cs index 433fd6219..34b7d556d 100644 --- a/src/TSMapEditor/UI/Windows/TriggersWindow.cs +++ b/src/TSMapEditor/UI/Windows/TriggersWindow.cs @@ -90,6 +90,7 @@ public TriggersWindow(WindowManager windowManager, Map map, EditorState editorSt private SelectStringWindow selectStringWindow; private SelectSpeechWindow selectSpeechWindow; private SelectSoundWindow selectSoundWindow; + private SelectSuperWeaponTypeWindow selectSuperWeaponTypeWindow; private XNAContextMenu actionContextMenu; private XNAContextMenu eventContextMenu; @@ -274,6 +275,10 @@ public override void Initialize() var soundDarkeningPanel = DarkeningPanel.InitializeAndAddToParentControlWithChild(WindowManager, Parent, selectSoundWindow); soundDarkeningPanel.Hidden += SoundDarkeningPanel_Hidden; + selectSuperWeaponTypeWindow = new SelectSuperWeaponTypeWindow(WindowManager, map); + var swDarkeningPanel = DarkeningPanel.InitializeAndAddToParentControlWithChild(WindowManager, Parent, selectSuperWeaponTypeWindow); + swDarkeningPanel.Hidden += SuperWeaponDarkeningPanel_Hidden; + eventContextMenu = new XNAContextMenu(WindowManager); eventContextMenu.Name = nameof(eventContextMenu); eventContextMenu.Width = lbEvents.Width; @@ -881,10 +886,17 @@ private void BtnEventParameterValuePreset_LeftClick(object sender, EventArgs e) ctxEventParameterPresetValues.Open(GetCursorPoint()); break; case TriggerParamType.SuperWeapon: - ctxEventParameterPresetValues.ClearItems(); - ctxEventParameterPresetValues.Width = 250; - map.Rules.SuperWeaponTypes.ForEach(sw => ctxEventParameterPresetValues.AddItem(sw.GetDisplayString())); - ctxEventParameterPresetValues.Open(GetCursorPoint()); + int swTypeIndex = Conversions.IntFromString(triggerEvent.Parameters[paramIndex], -1); + selectSuperWeaponTypeWindow.IsForEvent = true; + selectSuperWeaponTypeWindow.UseININameAsValue = false; + if (swTypeIndex > -1 && swTypeIndex < map.Rules.SuperWeaponTypes.Count) + selectSuperWeaponTypeWindow.Open(map.Rules.SuperWeaponTypes[swTypeIndex]); + break; + case TriggerParamType.SuperWeaponID: + string swTypeID = triggerEvent.Parameters[paramIndex]; + selectSuperWeaponTypeWindow.IsForEvent = true; + selectSuperWeaponTypeWindow.UseININameAsValue = true; + selectSuperWeaponTypeWindow.Open(map.Rules.SuperWeaponTypes.Find(swType => swType.ININame.Equals(swTypeID, StringComparison.Ordinal))); break; case TriggerParamType.TeamType: TeamType existingTeamType = map.TeamTypes.Find(tt => tt.ININame == triggerEvent.Parameters[paramIndex]); @@ -1002,10 +1014,18 @@ private void BtnActionParameterValuePreset_LeftClick(object sender, EventArgs e) selectStringWindow.Open(existingString); break; case TriggerParamType.SuperWeapon: - ctxActionParameterPresetValues.ClearItems(); - ctxActionParameterPresetValues.Width = 250; - map.Rules.SuperWeaponTypes.ForEach(sw => ctxActionParameterPresetValues.AddItem(sw.GetDisplayString())); - ctxActionParameterPresetValues.Open(GetCursorPoint()); + int swTypeIndex = Conversions.IntFromString(triggerAction.Parameters[paramIndex], -1); + selectSuperWeaponTypeWindow.IsForEvent = false; + selectSuperWeaponTypeWindow.UseININameAsValue = false; + if (swTypeIndex > -1 && swTypeIndex < map.Rules.SuperWeaponTypes.Count) + selectSuperWeaponTypeWindow.Open(map.Rules.SuperWeaponTypes[swTypeIndex]); + break; + case TriggerParamType.SuperWeaponID: + string swTypeID = triggerAction.Parameters[paramIndex]; + selectSuperWeaponTypeWindow.IsForEvent = false; + selectSuperWeaponTypeWindow.UseININameAsValue = true; + if (!string.IsNullOrEmpty(swTypeID)) + selectSuperWeaponTypeWindow.Open(map.Rules.SuperWeaponTypes.Find(swType => swType.ININame.Equals(swTypeID, StringComparison.Ordinal))); break; case TriggerParamType.Speech: selectSpeechWindow.IsForEvent = false; @@ -1136,6 +1156,19 @@ private void SoundDarkeningPanel_Hidden(object sender, EventArgs e) AssignParamValue(selectSoundWindow.IsForEvent, Constants.IsRA2YR ? sound.Name : sound.Index.ToString(CultureInfo.InvariantCulture)); } + private void SuperWeaponDarkeningPanel_Hidden(object sender, EventArgs e) + { + if (selectSuperWeaponTypeWindow.SelectedObject == null) + return; + + var swType = selectSuperWeaponTypeWindow.SelectedObject; + + if (selectSuperWeaponTypeWindow.UseININameAsValue) + AssignParamValue(selectSuperWeaponTypeWindow.IsForEvent, swType.ININame); + else + AssignParamValue(selectSuperWeaponTypeWindow.IsForEvent, swType.Index); + } + private void AssignParamValue(bool isForEvent, int paramValue) { if (isForEvent) @@ -2041,6 +2074,13 @@ private string GetParamValueText(string paramValue, TriggerParamType paramType, return intValue + " - nonexistent super weapon"; return intValue + " " + map.Rules.SuperWeaponTypes[intValue].GetDisplayStringWithoutIndex(); + case TriggerParamType.SuperWeaponID: + var swType = map.Rules.SuperWeaponTypes.Find(sw => sw.ININame.Equals(paramValue, StringComparison.Ordinal)); + + if (swType == null) + return paramValue; + + return swType.GetDisplayStringWithoutIndex(); case TriggerParamType.Speech: EvaSpeech speech;