Skip to content

Commit

Permalink
Implement "Go To Target" for specific trigger action parameters
Browse files Browse the repository at this point in the history
  • Loading branch information
Shushishtok authored Sep 12, 2024
1 parent 71d6376 commit 77158f1
Show file tree
Hide file tree
Showing 3 changed files with 103 additions and 0 deletions.
6 changes: 6 additions & 0 deletions src/TSMapEditor/Config/UI/Windows/TriggersWindow.ini
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ $CCa09=lblActionParameterValue:XNALabel
$CCa10=tbActionParameterValue:EditorTextBox
$CCa11=btnActionParameterValuePreset:EditorButton
$CCa12=btnCloneAction:EditorButton
$CCa13=btnActionGoToTarget:EditorButton

$Height=getBottom(lbActionParameters) + EMPTY_SPACE_BOTTOM
$Width=getRight(tbName) + EMPTY_SPACE_SIDES
Expand Down Expand Up @@ -377,3 +378,8 @@ $Y=getY(tbActionParameterValue)
$Width=30
Text=...

[btnActionGoToTarget]
$X=getX(tbActionParameterValue)
$Y=getBottom(tbActionParameterValue) + VERTICAL_SPACING
$Width=getWidth(tbActionParameterValue) - 10
Text=Go To Target ->
93 changes: 93 additions & 0 deletions src/TSMapEditor/UI/Windows/TriggersWindow.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,20 @@ public TriggersWindow(WindowManager windowManager, Map map, EditorState editorSt
changeAttachedTagCursorAction = new ChangeAttachedTagCursorAction(cursorActionTarget);
}

public event EventHandler<TeamTypeEventArgs> TeamTypeOpened;

private readonly Map map;
private readonly ICursorActionTarget cursorActionTarget;
private readonly PlaceCellTagCursorAction placeCellTagCursorAction;
private readonly ChangeAttachedTagCursorAction changeAttachedTagCursorAction;
private readonly EditorState editorState;
private readonly TriggerParamType[] supportedGoToSourceTriggerParamTypes =
{
TriggerParamType.Trigger,
TriggerParamType.TeamType,
TriggerParamType.Waypoint,
TriggerParamType.WaypointZZ
};

private XNADropDown ddActions;

Expand Down Expand Up @@ -73,6 +82,7 @@ public TriggersWindow(WindowManager windowManager, Map map, EditorState editorSt
private EditorDescriptionPanel panelActionDescription;
private EditorListBox lbActionParameters;
private EditorTextBox tbActionParameterValue;
private EditorButton btnActionGoToTarget;
private XNAContextMenu ctxActionParameterPresetValues;

private SelectEventWindow selectEventWindow;
Expand Down Expand Up @@ -153,6 +163,7 @@ public override void Initialize()
panelEventDescription = FindChild<EditorDescriptionPanel>(nameof(panelEventDescription));
lbEventParameters = FindChild<EditorListBox>(nameof(lbEventParameters));
tbEventParameterValue = FindChild<EditorTextBox>(nameof(tbEventParameterValue));
btnActionGoToTarget = FindChild<EditorButton>(nameof(btnActionGoToTarget));

ctxEventParameterPresetValues = new XNAContextMenu(WindowManager);
ctxEventParameterPresetValues.Name = nameof(ctxEventParameterPresetValues);
Expand Down Expand Up @@ -214,6 +225,8 @@ public override void Initialize()
FindChild<EditorButton>("btnActionParameterValuePreset").LeftClick += BtnActionParameterValuePreset_LeftClick;
FindChild<EditorButton>("btnEventParameterValuePreset").LeftClick += BtnEventParameterValuePreset_LeftClick;

btnActionGoToTarget.LeftClick += btnActionGoToTarget_LeftClick;

selectEventWindow = new SelectEventWindow(WindowManager, map);
var eventWindowDarkeningPanel = DarkeningPanel.InitializeAndAddToParentControlWithChild(WindowManager, Parent, selectEventWindow);
eventWindowDarkeningPanel.Hidden += EventWindowDarkeningPanel_Hidden;
Expand Down Expand Up @@ -1041,6 +1054,64 @@ private void BtnActionParameterValuePreset_LeftClick(object sender, EventArgs e)
}
}

private void btnActionGoToTarget_LeftClick(object sender, EventArgs e)
{
if (lbActions.SelectedItem == null)
return;

GetTriggerActionAndParamIndex(out TriggerAction triggerAction, out int paramIndex);

var triggerActionType = GetTriggerActionType(triggerAction.ActionIndex);
var triggerActionParam = triggerActionType.Parameters[paramIndex];
var triggerParamType = triggerActionParam.TriggerParamType;

switch (triggerParamType)
{
case TriggerParamType.Trigger:
var triggerId = triggerAction.Parameters[paramIndex];
var triggerIndex = lbTriggers.Items.FindIndex(listBoxTrigger => ((Trigger)listBoxTrigger.Tag).ID == triggerId);
if (triggerIndex == -1)
break;

lbTriggers.SelectedIndex = triggerIndex;
break;

case TriggerParamType.TeamType:
var teamTypeId = triggerAction.Parameters[paramIndex];
var teamType = map.TeamTypes.Find(teamType => teamType.ININame == teamTypeId);
if (teamType == null)
break;

OpenTeamType(teamType);
break;

case TriggerParamType.Waypoint:
case TriggerParamType.WaypointZZ:
int waypointNumber;
if (triggerParamType == TriggerParamType.WaypointZZ)
{
waypointNumber = Helpers.GetWaypointNumberFromAlphabeticalString(triggerAction.Parameters[paramIndex]);
}
else
{
waypointNumber = Conversions.IntFromString(triggerAction.Parameters[paramIndex], -1);
}

if (waypointNumber == -1)
break;

Waypoint waypoint = map.Waypoints.Find(wp => wp.Identifier == waypointNumber);
if (waypoint == null)
break;

cursorActionTarget.Camera.CenterOnCell(waypoint.Position);
break;

default:
break;
}
}

private void AnimationWindowDarkeningPanel_Hidden(object sender, EventArgs e)
{
if (selectAnimationWindow.SelectedObject == null)
Expand Down Expand Up @@ -1550,6 +1621,8 @@ private void EditTrigger(Trigger trigger)
lbActionParameters.Clear();
tbActionParameterValue.Text = string.Empty;

btnActionGoToTarget.Disable();

return;
}

Expand Down Expand Up @@ -1680,6 +1753,8 @@ private void LbActions_SelectedIndexChanged(object sender, EventArgs e)
panelActionDescription.Text = string.Empty;
lbActionParameters.Clear();
tbActionParameterValue.Text = string.Empty;

btnActionGoToTarget.Disable();
return;
}

Expand Down Expand Up @@ -1748,11 +1823,23 @@ private void LbActionParameters_SelectedIndexChanged(object sender, EventArgs e)

tbActionParameterValue.Text = GetParamValueText(triggerAction.Parameters[paramNumber], triggerParamType, triggerActionParam.PresetOptions);
tbActionParameterValue.TextColor = GetParamValueColor(triggerAction.Parameters[paramNumber], triggerParamType);

bool isSupportedGoToSourceParamType = supportedGoToSourceTriggerParamTypes.Contains(triggerParamType);
if (isSupportedGoToSourceParamType)
{
btnActionGoToTarget.Enable();
}
else
{
btnActionGoToTarget.Disable();
}
}
else
{
tbActionParameterValue.Text = triggerAction.Parameters[paramNumber];
tbActionParameterValue.TextColor = UISettings.ActiveSettings.AltColor;

btnActionGoToTarget.Disable();
}

tbActionParameterValue.TextChanged += TbActionParameterValue_TextChanged;
Expand Down Expand Up @@ -2201,5 +2288,11 @@ private string GetObjectValueText<T>(RTTIType rtti, List<T> objectTypeList, stri

return intValue + " " + objectTypeList[intValue].GetEditorDisplayName();
}

private void OpenTeamType(TeamType teamType)
{
TeamTypeOpened?.Invoke(this, new TeamTypeEventArgs(teamType));
PutOnBackground();
}
}
}
4 changes: 4 additions & 0 deletions src/TSMapEditor/UI/Windows/WindowController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,7 @@ public void Initialize(IWindowParentControl windowParentControl, Map map, Editor
TeamTypesWindow.ScriptOpened += TeamTypesWindow_ScriptOpened;
TeamTypesWindow.TagOpened += Window_TagOpened;
AITriggersWindow.TeamTypeOpened += AITriggersWindow_TeamTypeOpened;
TriggersWindow.TeamTypeOpened += TriggersWindow_TeamTypeOpened;
StructureOptionsWindow.TagOpened += Window_TagOpened;
VehicleOptionsWindow.TagOpened += Window_TagOpened;
InfantryOptionsWindow.TagOpened += Window_TagOpened;
Expand Down Expand Up @@ -286,6 +287,8 @@ private void AITriggersWindow_TeamTypeOpened(object sender, TeamTypeEventArgs e)
TeamTypesWindow.SelectTeamType(e.TeamType);
}

private void TriggersWindow_TeamTypeOpened(object sender, TeamTypeEventArgs e) => AITriggersWindow_TeamTypeOpened(sender, e);

private void ClearFocusSwitchHandlerFromChildrenRecursive(EditorWindow window, XNAControl control)
{
foreach (var child in control.Children)
Expand All @@ -304,6 +307,7 @@ public void Clear()
TeamTypesWindow.ScriptOpened -= TeamTypesWindow_ScriptOpened;
TeamTypesWindow.TagOpened -= Window_TagOpened;
AITriggersWindow.TeamTypeOpened -= AITriggersWindow_TeamTypeOpened;
TriggersWindow.TeamTypeOpened -= TriggersWindow_TeamTypeOpened;
StructureOptionsWindow.TagOpened -= Window_TagOpened;
VehicleOptionsWindow.TagOpened -= Window_TagOpened;
InfantryOptionsWindow.TagOpened -= Window_TagOpened;
Expand Down

0 comments on commit 77158f1

Please sign in to comment.