Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 9 additions & 3 deletions src/TSMapEditor/CCEngine/ScriptAction.cs
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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;
}
}

Expand All @@ -36,6 +40,7 @@ public ScriptAction(int id)
public string OptionsSectionName { get; set; } = string.Empty;
public TriggerParamType ParamType { get; set; } = TriggerParamType.Unknown;
public List<ScriptActionPresetOption> PresetOptions { get; } = new List<ScriptActionPresetOption>(0);
public bool UseWindowSelection { get; set; } = false;

public void ReadIniSection(IniFile iniFile, string sectionName)
{
Expand All @@ -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;
Expand Down
12 changes: 10 additions & 2 deletions src/TSMapEditor/Config/Default/UI/Windows/ScriptsWindow.ini
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
@@ -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

3 changes: 3 additions & 0 deletions src/TSMapEditor/TSMapEditor.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,9 @@
<None Update="Config\Default\UI\Windows\SelectHouseTypeWindow.ini">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Update="Config\UI\Windows\SelectScriptActionPresetOptionWindow.ini">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Update="Config\Default\UI\Windows\SelectParticleSystemTypeWindow.ini">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
Expand Down
68 changes: 60 additions & 8 deletions src/TSMapEditor/UI/Windows/ScriptsWindow.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -92,6 +94,7 @@ public override void Initialize()
lblParameterDescription = FindChild<XNALabel>(nameof(lblParameterDescription));
tbParameterValue = FindChild<EditorNumberTextBox>(nameof(tbParameterValue));
btnEditorPresetValues = FindChild<MenuButton>(nameof(btnEditorPresetValues));
btnEditorPresetValuesWindow = FindChild<EditorButton>(nameof(btnEditorPresetValuesWindow));
lblActionDescriptionValue = FindChild<XNALabel>(nameof(lblActionDescriptionValue));
ddScriptColor = FindChild<XNADropDown>(nameof(ddScriptColor));

Expand All @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Comment thread
Starkku marked this conversation as resolved.

var item = selectScriptActionPresetOptionWindow.GetMatchingItem(tbParameterValue.Text);
selectScriptActionPresetOptionWindow.Open(item);
}

private void ShowScriptReferences()
{
if (editedScript == null)
Expand Down Expand Up @@ -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)
Expand All @@ -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)
Expand Down Expand Up @@ -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() }));
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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
});
}
Expand All @@ -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) + ")";
}
Expand Down
80 changes: 80 additions & 0 deletions src/TSMapEditor/UI/Windows/SelectScriptActionPresetOptionWindow.cs
Original file line number Diff line number Diff line change
@@ -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<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;
}
}
}
Loading