Skip to content

Commit

Permalink
Add particle system parameter selection interface for trigger actions
Browse files Browse the repository at this point in the history
  • Loading branch information
Rampastring committed Aug 21, 2024
1 parent 7fd1d5c commit 03e678e
Show file tree
Hide file tree
Showing 9 changed files with 141 additions and 3 deletions.
2 changes: 1 addition & 1 deletion src/TSMapEditor/Config/Actions.ini
Original file line number Diff line number Diff line change
Expand Up @@ -486,7 +486,7 @@ P2Type=Boolean
[ParticleSystemAnimAt]
Name=ParticleSystem Anim at
Description=Show particle animation at waypoint location.
P2Type=Particle
P2Type=ParticleSystem
P7Type=WaypointZZ
[RemoveParticleSystemAnimAt]
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
[SelectParticleSystemTypeWindow]
$Width=250
$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 Particle System:

[tbSearch]
$X=EMPTY_SPACE_SIDES
$Y=getBottom(lblDescription) + EMPTY_SPACE_TOP
$Width=getWidth(SelectParticleSystemTypeWindow) - (EMPTY_SPACE_SIDES * 2)
Suggestion=Search Particle System...

[btnSelect]
$Width=100
$X=(getWidth(SelectParticleSystemTypeWindow) - getWidth(btnSelect)) / 2
$Y=getHeight(SelectParticleSystemTypeWindow) - 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: 2 additions & 1 deletion src/TSMapEditor/Models/Enums/RTTIType.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ public enum RTTIType
TeamType,
Waypoint,
CellTag,
SuperWeaponType
SuperWeaponType,
ParticleSystemType
}
}
2 changes: 1 addition & 1 deletion src/TSMapEditor/Models/Enums/TriggerParamType.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public enum TriggerParamType
Speech,
SuperWeapon,
Animation,
Particle,
ParticleSystem,
Waypoint,
WaypointZZ,
String,
Expand Down
24 changes: 24 additions & 0 deletions src/TSMapEditor/Models/ParticleSystemType.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
using System.Globalization;

namespace TSMapEditor.Models
{
public class ParticleSystemType : AbstractObject, INIDefined
{
public ParticleSystemType(string iniName)
{
ININame = iniName;
}

[INI(false)]
public string ININame { get; }

[INI(false)]
public int Index { get; set; }

public string GetDisplayString() => $"{Index.ToString(CultureInfo.InvariantCulture)} {GetDisplayStringWithoutIndex()}";

public string GetDisplayStringWithoutIndex() => ININame;

public override RTTIType WhatAmI() => RTTIType.ParticleSystemType;
}
}
3 changes: 3 additions & 0 deletions src/TSMapEditor/Models/Rules.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ public class Rules
public List<GlobalVariable> GlobalVariables = new List<GlobalVariable>();
public List<Weapon> Weapons = new List<Weapon>();
public List<SuperWeaponType> SuperWeaponTypes = new List<SuperWeaponType>();
public List<ParticleSystemType> ParticleSystemTypes = new List<ParticleSystemType>();

public List<TaskForce> TaskForces = new List<TaskForce>();
public List<Script> Scripts = new List<Script>();
Expand Down Expand Up @@ -60,6 +61,7 @@ public void InitFromINI(IniFile iniFile, IInitializer initializer, bool isMapIni
InitFromTypeSection(iniFile, "Weapons", Weapons); // TS CnCNet ts-patches + Vinifera
InitFromTypeSection(iniFile, "WeaponTypes", Weapons); // YR Ares
InitFromTypeSection(iniFile, "SuperWeaponTypes", SuperWeaponTypes);
InitFromTypeSection(iniFile, "ParticleSystems", ParticleSystemTypes);
InitFromTypeSection(iniFile, "Tiberiums", TiberiumTypes);

if (!isMapIni)
Expand All @@ -80,6 +82,7 @@ public void InitFromINI(IniFile iniFile, IInitializer initializer, bool isMapIni
SmudgeTypes.ForEach(ot => initializer.ReadObjectTypePropertiesFromINI(ot, iniFile));
Weapons.ForEach(w => initializer.ReadObjectTypePropertiesFromINI(w, iniFile));
SuperWeaponTypes.ForEach(sw => initializer.ReadObjectTypePropertiesFromINI(sw, iniFile));
ParticleSystemTypes.ForEach(ps => initializer.ReadObjectTypePropertiesFromINI(ps, iniFile));
AnimTypes.ForEach(a => initializer.ReadObjectTypePropertiesFromINI(a, iniFile));
RulesHouseTypes.ForEach(ht => initializer.ReadObjectTypePropertiesFromINI(ht, iniFile));
TiberiumTypes.ForEach(ht => initializer.ReadObjectTypePropertiesFromINI(ht, iniFile));
Expand Down
3 changes: 3 additions & 0 deletions src/TSMapEditor/TSMapEditor.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,9 @@
<None Update="Config\UI\Windows\SelectHouseTypeWindow.ini">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Update="Config\UI\Windows\SelectParticleSystemTypeWindow.ini">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Update="Config\UI\Windows\SelectLocalVariableWindow.ini">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
Expand Down
46 changes: 46 additions & 0 deletions src/TSMapEditor/UI/Windows/SelectParticleSystemTypeWindow.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
using System;
using Rampastring.XNAUI;
using Rampastring.XNAUI.XNAControls;
using TSMapEditor.Models;

namespace TSMapEditor.UI.Windows
{
public class SelectParticleSystemTypeWindow : SelectObjectWindow<ParticleSystemType>
{
public SelectParticleSystemTypeWindow(WindowManager windowManager, Map map) : base(windowManager)
{
this.map = map;
}

private readonly Map map;

public override void Initialize()
{
Name = nameof(SelectParticleSystemTypeWindow);
base.Initialize();
}

protected override void LbObjectList_SelectedIndexChanged(object sender, EventArgs e)
{
if (lbObjectList.SelectedItem == null)
{
SelectedObject = null;
return;
}

SelectedObject = (ParticleSystemType)lbObjectList.SelectedItem.Tag;
}

protected override void ListObjects()
{
lbObjectList.Clear();

foreach (ParticleSystemType particleSystemType in map.Rules.ParticleSystemTypes)
{
lbObjectList.AddItem(new XNAListBoxItem() { Text = $"{particleSystemType.Index} {particleSystemType.ININame}", Tag = particleSystemType });
if (particleSystemType == SelectedObject)
lbObjectList.SelectedIndex = lbObjectList.Items.Count - 1;
}
}
}
}
26 changes: 26 additions & 0 deletions src/TSMapEditor/UI/Windows/TriggersWindow.cs
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ public TriggersWindow(WindowManager windowManager, Map map, EditorState editorSt
private SelectStringWindow selectStringWindow;
private SelectSpeechWindow selectSpeechWindow;
private SelectSoundWindow selectSoundWindow;
private SelectParticleSystemTypeWindow selectParticleSystemTypeWindow;

private XNAContextMenu actionContextMenu;
private XNAContextMenu eventContextMenu;
Expand Down Expand Up @@ -275,6 +276,10 @@ public override void Initialize()
var soundDarkeningPanel = DarkeningPanel.InitializeAndAddToParentControlWithChild(WindowManager, Parent, selectSoundWindow);
soundDarkeningPanel.Hidden += SoundDarkeningPanel_Hidden;

selectParticleSystemTypeWindow = new SelectParticleSystemTypeWindow(WindowManager, map);
var particleSystemTypeDarkeningPanel = DarkeningPanel.InitializeAndAddToParentControlWithChild(WindowManager, Parent, selectParticleSystemTypeWindow);
particleSystemTypeDarkeningPanel.Hidden += ParticleSystemTypeDarkeningPanel_Hidden;

eventContextMenu = new XNAContextMenu(WindowManager);
eventContextMenu.Name = nameof(eventContextMenu);
eventContextMenu.Width = lbEvents.Width;
Expand Down Expand Up @@ -1006,6 +1011,11 @@ private void BtnActionParameterValuePreset_LeftClick(object sender, EventArgs e)
map.Rules.SuperWeaponTypes.ForEach(sw => ctxActionParameterPresetValues.AddItem(sw.GetDisplayString()));
ctxActionParameterPresetValues.Open(GetCursorPoint());
break;
case TriggerParamType.ParticleSystem:
ParticleSystemType existingParticleSystemType = map.Rules.ParticleSystemTypes.Find(pst => pst.Index == Conversions.IntFromString(triggerAction.Parameters[paramIndex], -1));
selectParticleSystemTypeWindow.IsForEvent = false;
selectParticleSystemTypeWindow.Open(existingParticleSystemType);
break;
case TriggerParamType.Speech:
selectSpeechWindow.IsForEvent = false;
EvaSpeech speech = Constants.IsRA2YR
Expand Down Expand Up @@ -1135,6 +1145,14 @@ private void SoundDarkeningPanel_Hidden(object sender, EventArgs e)
AssignParamValue(selectSoundWindow.IsForEvent, Constants.IsRA2YR ? sound.Name : sound.Index.ToString(CultureInfo.InvariantCulture));
}

private void ParticleSystemTypeDarkeningPanel_Hidden(object sender, EventArgs e)
{
if (selectParticleSystemTypeWindow.SelectedObject == null)
return;

AssignParamValue(selectParticleSystemTypeWindow.IsForEvent, selectParticleSystemTypeWindow.SelectedObject.Index);
}

private void AssignParamValue(bool isForEvent, int paramValue)
{
if (isForEvent)
Expand Down Expand Up @@ -2060,6 +2078,14 @@ private string GetParamValueText(string paramValue, TriggerParamType paramType,
return intValue + " - nonexistent super weapon";

return intValue + " " + map.Rules.SuperWeaponTypes[intValue].GetDisplayStringWithoutIndex();
case TriggerParamType.ParticleSystem:
if (!intParseSuccess)
return paramValue;

if (intValue >= map.Rules.ParticleSystemTypes.Count)
return intValue + " - nonexistent particle system";

return intValue + " " + map.Rules.ParticleSystemTypes[intValue].ININame;
case TriggerParamType.Speech:
EvaSpeech speech;

Expand Down

0 comments on commit 03e678e

Please sign in to comment.