Skip to content

Commit

Permalink
Adjust speech selector to allow selecting speeches in YR
Browse files Browse the repository at this point in the history
  • Loading branch information
ZivDero committed May 7, 2024
1 parent 08998fb commit bd6e00d
Show file tree
Hide file tree
Showing 7 changed files with 106 additions and 11 deletions.
2 changes: 1 addition & 1 deletion src/TSMapEditor/Config/Constants.ini
Original file line number Diff line number Diff line change
Expand Up @@ -100,4 +100,4 @@ AI=INI/AI.ini
AIE=INI/AIE.ini
Tutorial=INI/Tutorial.ini
Theme=INI/Theme.ini

EVA=
2 changes: 2 additions & 0 deletions src/TSMapEditor/Constants.cs
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ public static class Constants
public static string FirestormAIIniPath;
public static string TutorialIniPath;
public static string ThemeIniPath;
public static string EvaIniPath;

public const int TextureSizeLimit = 16384;

Expand Down Expand Up @@ -153,6 +154,7 @@ public static void Init()
FirestormAIIniPath = constantsIni.GetStringValue(FilePathsSectionName, "AIFS", "INI/AIE.ini");
TutorialIniPath = constantsIni.GetStringValue(FilePathsSectionName, "Tutorial", "INI/Tutorial.ini");
ThemeIniPath = constantsIni.GetStringValue(FilePathsSectionName, "Theme", "INI/Theme.ini");
EvaIniPath = constantsIni.GetStringValue(FilePathsSectionName, "EVA", "INI/Eva.ini");

InitUIConstants();
}
Expand Down
59 changes: 59 additions & 0 deletions src/TSMapEditor/Models/EvaSpeeches.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
using System.Collections.Generic;
using TSMapEditor.Extensions;

namespace TSMapEditor.Models
{
public struct EvaSpeech
{
public EvaSpeech(int index, string name, string text)
{
Index = index;
Name = name;
Text = text;
}

public override string ToString()
{
return $"{Name} {Text}";
}

public int Index;
public string Name;
public string Text;
}

public class EvaSpeeches
{
public EvaSpeeches(IniFileEx evaIni)
{
Initialize(evaIni);
}

private List<EvaSpeech> speeches;
public List<EvaSpeech> Speeches => new(speeches);


private void Initialize(IniFileEx evaIni)
{
speeches = new List<EvaSpeech>();

const string speechSectionName = "DialogList";

evaIni.DoForEveryValueInSection(speechSectionName, name =>
{
if (string.IsNullOrEmpty(name))
return;
var speechSection = evaIni.GetSection(name);
string text = string.Empty;
if (speechSection != null)
{
text = speechSection.GetStringValue("Text", text);
}
speeches.Add(new EvaSpeech(speeches.Count, name, text));
});
}
}
}
1 change: 1 addition & 0 deletions src/TSMapEditor/Models/Rules.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ public class Rules

public TutorialLines TutorialLines { get; set; }
public Themes Themes { get; set; }
public EvaSpeeches EvaSpeeches { get; set; }

public double ExtraUnitLight { get; set; }
public double ExtraInfantryLight { get; set; }
Expand Down
2 changes: 2 additions & 0 deletions src/TSMapEditor/UI/Windows/MainMenuWindows/MapSetup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ public static string InitializeMap(string gameDirectory, bool createNew, string

var tutorialLines = new TutorialLines(Path.Combine(gameDirectory, Constants.TutorialIniPath), a => windowManager.AddCallback(a, null));
var themes = new Themes(IniFileEx.FromPathOrMix(Constants.ThemeIniPath, gameDirectory, ccFileManager));
var evaSpeeches = new EvaSpeeches(IniFileEx.FromPathOrMix(Constants.EvaIniPath, gameDirectory, ccFileManager));

Map map = new Map(ccFileManager);

Expand Down Expand Up @@ -70,6 +71,7 @@ public static string InitializeMap(string gameDirectory, bool createNew, string

map.Rules.TutorialLines = tutorialLines;
map.Rules.Themes = themes;
map.Rules.EvaSpeeches = evaSpeeches;

Console.WriteLine();
Console.WriteLine("Map created.");
Expand Down
20 changes: 16 additions & 4 deletions src/TSMapEditor/UI/Windows/SelectSpeechWindow.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,23 @@ protected override void ListObjects()
{
lbObjectList.Clear();

foreach (var kvp in map.EditorConfig.Speeches)
if (Constants.IsRA2YR)
{
lbObjectList.AddItem(new XNAListBoxItem() { Text = $"{kvp.Key} {kvp.Value}", Tag = kvp.Key });
if (kvp.Key == SelectedObject)
lbObjectList.SelectedIndex = lbObjectList.Items.Count - 1;
foreach (var evaSpeech in map.Rules.EvaSpeeches.Speeches)
{
lbObjectList.AddItem(new XNAListBoxItem() { Text = evaSpeech.ToString(), Tag = evaSpeech.Index });
if (evaSpeech.Index == SelectedObject)
lbObjectList.SelectedIndex = lbObjectList.Items.Count - 1;
}
}
else
{
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;
}
}
}
}
Expand Down
31 changes: 25 additions & 6 deletions src/TSMapEditor/UI/Windows/TriggersWindow.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1044,7 +1044,14 @@ private void SpeechDarkeningPanel_Hidden(object sender, EventArgs e)
if (selectSpeechWindow.SelectedObject < 0)
return;

AssignParamValue(selectSpeechWindow.IsForEvent, selectSpeechWindow.SelectedObject);
if (Constants.IsRA2YR)
{
AssignParamValue(selectSpeechWindow.IsForEvent, map.Rules.EvaSpeeches.Speeches[selectSpeechWindow.SelectedObject].Name);
}
else
{
AssignParamValue(selectSpeechWindow.IsForEvent, selectSpeechWindow.SelectedObject);
}
}

private void AssignParamValue(bool isForEvent, int paramValue)
Expand Down Expand Up @@ -1948,13 +1955,25 @@ private string GetParamValueText(string paramValue, TriggerParamType paramType,

return intValue + " " + map.Rules.SuperWeaponTypes[intValue].GetDisplayStringWithoutIndex();
case TriggerParamType.Speech:
if (!intParseSuccess)
return paramValue;
if (Constants.IsRA2YR)
{
int speechIndex = map.Rules.EvaSpeeches.Speeches.FindIndex(speech => speech.Name == paramValue);

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

return intValue + " " + map.EditorConfig.Speeches[intValue];
return map.Rules.EvaSpeeches.Speeches[speechIndex].Name;
}
else
{
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 bd6e00d

Please sign in to comment.