Skip to content

Commit

Permalink
Implement speech selection window
Browse files Browse the repository at this point in the history
  • Loading branch information
Rampastring committed Apr 29, 2024
1 parent 946604e commit d840408
Show file tree
Hide file tree
Showing 7 changed files with 719 additions and 1 deletion.
582 changes: 582 additions & 0 deletions src/TSMapEditor/Config/Speeches.ini

Large diffs are not rendered by default.

33 changes: 33 additions & 0 deletions src/TSMapEditor/Config/UI/Windows/SelectSpeechWindow.ini
@@ -0,0 +1,33 @@
[SelectSpeechWindow]
$Width=600
$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 Speech:

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

[btnSelect]
$Width=100
$X=(getWidth(SelectSpeechWindow) - getWidth(btnSelect)) / 2
$Y=getHeight(SelectSpeechWindow) - 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

2 changes: 1 addition & 1 deletion src/TSMapEditor/Constants.cs
Expand Up @@ -5,7 +5,7 @@ namespace TSMapEditor
{
public static class Constants
{
public const string ReleaseVersion = "1.0.1";
public const string ReleaseVersion = "1.0.2";

public static int CellSizeX = 48;
public static int CellSizeY = 24;
Expand Down
26 changes: 26 additions & 0 deletions src/TSMapEditor/Models/EditorConfig.cs
Expand Up @@ -29,6 +29,7 @@ public EditorConfig()
public List<BridgeType> Bridges { get; } = new List<BridgeType>();
public List<ConnectedOverlayType> ConnectedOverlays { get; } = new List<ConnectedOverlayType>();
public List<TeamTypeFlag> TeamTypeFlags { get; } = new List<TeamTypeFlag>();
public Dictionary<int, string> Speeches { get; } = new Dictionary<int, string>();

private static readonly Dictionary<string, (int StartIndex, int Count)> TiberiumDefaults = new()
{
Expand Down Expand Up @@ -58,6 +59,7 @@ public void EarlyInit()
ReadTriggerActionTypes();
ReadTheaters();
ReadTeamTypeFlags();
ReadSpeeches();
}

public void RulesDependentInit(Rules rules)
Expand Down Expand Up @@ -370,5 +372,29 @@ private void ReadTeamTypeFlags()
TeamTypeFlags.Add(teamTypeFlag);
}
}

private void ReadSpeeches()
{
Speeches.Clear();

var iniFile = new IniFile(Environment.CurrentDirectory + "/Config/Speeches.ini");
const string sectionName = "Speeches";

var keys = iniFile.GetSectionKeys(sectionName);
if (keys == null)
return;

foreach (var key in keys)
{
int id = Conversions.IntFromString(key, -1);
if (id == -1)
{
Logger.Log("Invalid speech entry " + key);
continue;
}

Speeches[id] = iniFile.GetStringValue(sectionName, key, string.Empty);
}
}
}
}
6 changes: 6 additions & 0 deletions src/TSMapEditor/TSMapEditor.csproj
Expand Up @@ -95,6 +95,9 @@
<None Update="Config\MapCode\Snowy Smudges.ini">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Update="Config\Speeches.ini">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Update="Config\TeamTypeFlags.ini">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
Expand Down Expand Up @@ -215,6 +218,9 @@
<None Update="Config\UI\Windows\SelectScriptActionWindow.ini">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Update="Config\UI\Windows\SelectSpeechWindow.ini">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Update="Config\UI\Windows\SelectTechnoTypeWindow.ini">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
Expand Down
46 changes: 46 additions & 0 deletions src/TSMapEditor/UI/Windows/SelectSpeechWindow.cs
@@ -0,0 +1,46 @@
using Rampastring.XNAUI.XNAControls;
using Rampastring.XNAUI;
using System;
using TSMapEditor.Models;

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

private readonly Map map;

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

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

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

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

foreach (var kvp in map.EditorConfig.Speeches)
{
lbObjectList.AddItem(new XNAListBoxItem() { Text = $"{kvp.Key} {kvp.Value}", Tag = kvp.Key });
if (kvp.Key == SelectedObject)
lbObjectList.SelectedIndex = lbObjectList.Items.Count - 1;
}
}
}
}
25 changes: 25 additions & 0 deletions src/TSMapEditor/UI/Windows/TriggersWindow.cs
Expand Up @@ -88,6 +88,7 @@ public TriggersWindow(WindowManager windowManager, Map map, EditorState editorSt
private SelectTechnoTypeWindow selectTechnoTypeWindow;
private SelectTagWindow selectTagWindow;
private SelectStringWindow selectStringWindow;
private SelectSpeechWindow selectSpeechWindow;

private XNAContextMenu actionContextMenu;
private XNAContextMenu eventContextMenu;
Expand Down Expand Up @@ -263,6 +264,10 @@ public override void Initialize()
var stringDarkeningPanel = DarkeningPanel.InitializeAndAddToParentControlWithChild(WindowManager, Parent, selectStringWindow);
stringDarkeningPanel.Hidden += StringDarkeningPanel_Hidden;

selectSpeechWindow = new SelectSpeechWindow(WindowManager, map);
var speechDarkeningPanel = DarkeningPanel.InitializeAndAddToParentControlWithChild(WindowManager, Parent, selectSpeechWindow);
speechDarkeningPanel.Hidden += SpeechDarkeningPanel_Hidden;

eventContextMenu = new XNAContextMenu(WindowManager);
eventContextMenu.Name = nameof(eventContextMenu);
eventContextMenu.Width = lbEvents.Width;
Expand Down Expand Up @@ -933,6 +938,10 @@ private void BtnActionParameterValuePreset_LeftClick(object sender, EventArgs e)
map.Rules.SuperWeaponTypes.ForEach(sw => ctxActionParameterPresetValues.AddItem(sw.GetDisplayString()));
ctxActionParameterPresetValues.Open(GetCursorPoint());
break;
case TriggerParamType.Speech:
selectSpeechWindow.IsForEvent = false;
selectSpeechWindow.Open(Conversions.IntFromString(triggerAction.Parameters[paramIndex], -1));
break;
default:
break;
}
Expand Down Expand Up @@ -1030,6 +1039,14 @@ private void StringDarkeningPanel_Hidden(object sender, EventArgs e)
AssignParamValue(selectStringWindow.IsForEvent, selectStringWindow.SelectedObject.ID);
}

private void SpeechDarkeningPanel_Hidden(object sender, EventArgs e)
{
if (selectSpeechWindow.SelectedObject < 0)
return;

AssignParamValue(selectSpeechWindow.IsForEvent, selectSpeechWindow.SelectedObject);
}

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

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

if (!map.EditorConfig.Speeches.ContainsKey(intValue))
return intValue + " - unknown speech";

return intValue + " " + map.EditorConfig.Speeches[intValue];
case TriggerParamType.Float:
if (!intParseSuccess)
return paramValue;
Expand Down

0 comments on commit d840408

Please sign in to comment.