Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add superweapon selector window and superweapon ID param type #177

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
34 changes: 34 additions & 0 deletions src/TSMapEditor/Config/UI/Windows/SelectSuperWeaponTypeWindow.ini
Original file line number Diff line number Diff line change
@@ -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

3 changes: 2 additions & 1 deletion src/TSMapEditor/Models/Enums/TriggerParamType.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ public enum TriggerParamType
SpotlightBehaviour,
RadarEvent,
VoxelAnim,
StringTableEntry
StringTableEntry,
SuperWeaponID
}
}
3 changes: 3 additions & 0 deletions src/TSMapEditor/TSMapEditor.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,9 @@
<None Update="Config\UI\Windows\SelectSpeechWindow.ini">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Update="Config\UI\Windows\SelectSuperWeaponTypeWindow.ini">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Update="Config\UI\Windows\SelectTechnoTypeWindow.ini">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
Expand Down
47 changes: 47 additions & 0 deletions src/TSMapEditor/UI/Windows/SelectSuperWeaponTypeWindow.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
using Rampastring.XNAUI;
using Rampastring.XNAUI.XNAControls;
using System;
using TSMapEditor.Models;

namespace TSMapEditor.UI.Windows
{
public class SelectSuperWeaponTypeWindow : SelectObjectWindow<SuperWeaponType>
{
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;
}
}
}
}
56 changes: 48 additions & 8 deletions src/TSMapEditor/UI/Windows/TriggersWindow.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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]);
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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();
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How about just .ToString()?

case TriggerParamType.Speech:
EvaSpeech speech;

Expand Down
Loading