Add support for game translation
This commit is contained in:
@@ -14,6 +14,7 @@ using System.Drawing;
|
||||
using System.Globalization;
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
using System.Text.RegularExpressions;
|
||||
|
||||
namespace OpenRA.FileFormats
|
||||
{
|
||||
@@ -38,31 +39,31 @@ namespace OpenRA.FileFormats
|
||||
object val;
|
||||
if (kv.Value != null)
|
||||
val = kv.Value(kv.Key.Name, kv.Key.FieldType, my);
|
||||
else if (!TryGetValueFromYaml(kv.Key.Name, kv.Key.FieldType, my, out val))
|
||||
else if (!TryGetValueFromYaml(kv.Key, my, out val))
|
||||
continue;
|
||||
|
||||
kv.Key.SetValue(self, val);
|
||||
}
|
||||
}
|
||||
|
||||
static bool TryGetValueFromYaml(string fieldName, Type fieldType, MiniYaml yaml, out object ret)
|
||||
static bool TryGetValueFromYaml(FieldInfo field, MiniYaml yaml, out object ret)
|
||||
{
|
||||
ret = null;
|
||||
var n = yaml.Nodes.Where(x => x.Key == fieldName).ToList();
|
||||
var n = yaml.Nodes.Where(x => x.Key == field.Name).ToList();
|
||||
if (n.Count == 0)
|
||||
return false;
|
||||
if (n.Count == 1 && n[0].Value.Nodes.Count == 0)
|
||||
{
|
||||
ret = GetValue(fieldName, fieldType, n[0].Value.Value);
|
||||
ret = GetValue(field.Name, field.FieldType, n[0].Value.Value, field);
|
||||
return true;
|
||||
}
|
||||
else if (n.Count > 1)
|
||||
{
|
||||
throw new InvalidOperationException("The field {0} has multiple definitions:\n{1}"
|
||||
.F(fieldName, n.Select(m => "\t- " + m.Location).JoinWith("\n")));
|
||||
.F(field.Name, n.Select(m => "\t- " + m.Location).JoinWith("\n")));
|
||||
}
|
||||
|
||||
throw new InvalidOperationException("TryGetValueFromYaml: unable to load field {0} (of type {1})".F(fieldName, fieldType));
|
||||
throw new InvalidOperationException("TryGetValueFromYaml: unable to load field {0} (of type {1})".F(field.Name, field.FieldType));
|
||||
}
|
||||
|
||||
public static T Load<T>(MiniYaml y) where T : new()
|
||||
@@ -80,7 +81,7 @@ namespace OpenRA.FileFormats
|
||||
if (field != null)
|
||||
{
|
||||
if (!field.HasAttribute<FieldFromYamlKeyAttribute>())
|
||||
field.SetValue(self, GetValue(field.Name, field.FieldType, value));
|
||||
field.SetValue(self, GetValue(field.Name, field.FieldType, value, field));
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -89,7 +90,7 @@ namespace OpenRA.FileFormats
|
||||
if (prop != null)
|
||||
{
|
||||
if (!prop.HasAttribute<FieldFromYamlKeyAttribute>())
|
||||
prop.SetValue(self, GetValue(prop.Name, prop.PropertyType, value), NoIndexes);
|
||||
prop.SetValue(self, GetValue(prop.Name, prop.PropertyType, value, prop), NoIndexes);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -98,61 +99,70 @@ namespace OpenRA.FileFormats
|
||||
|
||||
public static T GetValue<T>(string field, string value)
|
||||
{
|
||||
return (T)GetValue(field, typeof(T), value);
|
||||
return (T)GetValue(field, typeof(T), value, null);
|
||||
}
|
||||
|
||||
public static object GetValue(string field, Type fieldType, string x)
|
||||
public static object GetValue(string fieldName, Type fieldType, string value)
|
||||
{
|
||||
if (x != null) x = x.Trim();
|
||||
return GetValue(fieldName, fieldType, value, null);
|
||||
}
|
||||
|
||||
public static object GetValue(string fieldName, Type fieldType, string value, MemberInfo field)
|
||||
{
|
||||
if (value != null) value = value.Trim();
|
||||
|
||||
if (fieldType == typeof(int))
|
||||
{
|
||||
int res;
|
||||
if (int.TryParse(x, out res))
|
||||
if (int.TryParse(value, out res))
|
||||
return res;
|
||||
return InvalidValueAction(x, fieldType, field);
|
||||
return InvalidValueAction(value, fieldType, fieldName);
|
||||
}
|
||||
|
||||
else if (fieldType == typeof(ushort))
|
||||
{
|
||||
ushort res;
|
||||
if (ushort.TryParse(x, out res))
|
||||
if (ushort.TryParse(value, out res))
|
||||
return res;
|
||||
return InvalidValueAction(x, fieldType, field);
|
||||
return InvalidValueAction(value, fieldType, fieldName);
|
||||
}
|
||||
|
||||
else if (fieldType == typeof(float))
|
||||
{
|
||||
float res;
|
||||
if (float.TryParse(x.Replace("%", ""), NumberStyles.Any, NumberFormatInfo.InvariantInfo, out res))
|
||||
return res * (x.Contains('%') ? 0.01f : 1f);
|
||||
return InvalidValueAction(x, fieldType, field);
|
||||
if (float.TryParse(value.Replace("%", ""), NumberStyles.Any, NumberFormatInfo.InvariantInfo, out res))
|
||||
return res * (value.Contains('%') ? 0.01f : 1f);
|
||||
return InvalidValueAction(value, fieldType, fieldName);
|
||||
}
|
||||
|
||||
else if (fieldType == typeof(decimal))
|
||||
{
|
||||
decimal res;
|
||||
if (decimal.TryParse(x.Replace("%", ""), NumberStyles.Any, NumberFormatInfo.InvariantInfo, out res))
|
||||
return res * (x.Contains('%') ? 0.01m : 1m);
|
||||
return InvalidValueAction(x, fieldType, field);
|
||||
if (decimal.TryParse(value.Replace("%", ""), NumberStyles.Any, NumberFormatInfo.InvariantInfo, out res))
|
||||
return res * (value.Contains('%') ? 0.01m : 1m);
|
||||
return InvalidValueAction(value, fieldType, fieldName);
|
||||
}
|
||||
|
||||
else if (fieldType == typeof(string))
|
||||
return x;
|
||||
{
|
||||
if (field != null && field.HasAttribute<TranslateAttribute>())
|
||||
return Regex.Replace(value, "@[^@]+@", m => Translate(m.Value.Substring(1, m.Value.Length - 2)), RegexOptions.Compiled);
|
||||
return value;
|
||||
}
|
||||
|
||||
else if (fieldType == typeof(Color))
|
||||
{
|
||||
var parts = x.Split(',');
|
||||
var parts = value.Split(',');
|
||||
if (parts.Length == 3)
|
||||
return Color.FromArgb(int.Parse(parts[0]).Clamp(0, 255), int.Parse(parts[1]).Clamp(0, 255), int.Parse(parts[2]).Clamp(0, 255));
|
||||
if (parts.Length == 4)
|
||||
return Color.FromArgb(int.Parse(parts[0]).Clamp(0, 255), int.Parse(parts[1]).Clamp(0, 255), int.Parse(parts[2]).Clamp(0, 255), int.Parse(parts[3]).Clamp(0, 255));
|
||||
return InvalidValueAction(x, fieldType, field);
|
||||
return InvalidValueAction(value, fieldType, fieldName);
|
||||
}
|
||||
|
||||
else if (fieldType == typeof(HSLColor))
|
||||
{
|
||||
var parts = x.Split(',');
|
||||
var parts = value.Split(',');
|
||||
|
||||
// Allow old ColorRamp format to be parsed as HSLColor
|
||||
if (parts.Length == 3 || parts.Length == 4)
|
||||
@@ -161,21 +171,21 @@ namespace OpenRA.FileFormats
|
||||
(byte)int.Parse(parts[1]).Clamp(0, 255),
|
||||
(byte)int.Parse(parts[2]).Clamp(0, 255));
|
||||
|
||||
return InvalidValueAction(x, fieldType, field);
|
||||
return InvalidValueAction(value, fieldType, fieldName);
|
||||
}
|
||||
|
||||
else if (fieldType == typeof(WRange))
|
||||
{
|
||||
WRange res;
|
||||
if (WRange.TryParse(x, out res))
|
||||
if (WRange.TryParse(value, out res))
|
||||
return res;
|
||||
|
||||
return InvalidValueAction(x, fieldType, field);
|
||||
return InvalidValueAction(value, fieldType, fieldName);
|
||||
}
|
||||
|
||||
else if (fieldType == typeof(WVec))
|
||||
{
|
||||
var parts = x.Split(',');
|
||||
var parts = value.Split(',');
|
||||
if (parts.Length == 3)
|
||||
{
|
||||
WRange rx, ry, rz;
|
||||
@@ -183,12 +193,12 @@ namespace OpenRA.FileFormats
|
||||
return new WVec(rx, ry, rz);
|
||||
}
|
||||
|
||||
return InvalidValueAction(x, fieldType, field);
|
||||
return InvalidValueAction(value, fieldType, fieldName);
|
||||
}
|
||||
|
||||
else if (fieldType == typeof(WPos))
|
||||
{
|
||||
var parts = x.Split(',');
|
||||
var parts = value.Split(',');
|
||||
if (parts.Length == 3)
|
||||
{
|
||||
WRange rx, ry, rz;
|
||||
@@ -196,62 +206,62 @@ namespace OpenRA.FileFormats
|
||||
return new WPos(rx, ry, rz);
|
||||
}
|
||||
|
||||
return InvalidValueAction(x, fieldType, field);
|
||||
return InvalidValueAction(value, fieldType, fieldName);
|
||||
}
|
||||
|
||||
else if (fieldType == typeof(WAngle))
|
||||
{
|
||||
int res;
|
||||
if (int.TryParse(x, out res))
|
||||
if (int.TryParse(value, out res))
|
||||
return new WAngle(res);
|
||||
return InvalidValueAction(x, fieldType, field);
|
||||
return InvalidValueAction(value, fieldType, fieldName);
|
||||
}
|
||||
|
||||
else if (fieldType == typeof(WRot))
|
||||
{
|
||||
var parts = x.Split(',');
|
||||
var parts = value.Split(',');
|
||||
if (parts.Length == 3)
|
||||
{
|
||||
int rr, rp, ry;
|
||||
if (int.TryParse(x, out rr) && int.TryParse(x, out rp) && int.TryParse(x, out ry))
|
||||
if (int.TryParse(value, out rr) && int.TryParse(value, out rp) && int.TryParse(value, out ry))
|
||||
return new WRot(new WAngle(rr), new WAngle(rp), new WAngle(ry));
|
||||
}
|
||||
|
||||
return InvalidValueAction(x, fieldType, field);
|
||||
return InvalidValueAction(value, fieldType, fieldName);
|
||||
}
|
||||
|
||||
else if (fieldType.IsEnum)
|
||||
{
|
||||
if (!Enum.GetNames(fieldType).Select(a => a.ToLower()).Contains(x.ToLower()))
|
||||
return InvalidValueAction(x, fieldType, field);
|
||||
return Enum.Parse(fieldType, x, true);
|
||||
if (!Enum.GetNames(fieldType).Select(a => a.ToLower()).Contains(value.ToLower()))
|
||||
return InvalidValueAction(value, fieldType, fieldName);
|
||||
return Enum.Parse(fieldType, value, true);
|
||||
}
|
||||
|
||||
else if (fieldType == typeof(bool))
|
||||
return ParseYesNo(x, fieldType, field);
|
||||
return ParseYesNo(value, fieldType, fieldName);
|
||||
|
||||
else if (fieldType.IsArray)
|
||||
{
|
||||
if (x == null)
|
||||
if (value == null)
|
||||
return Array.CreateInstance(fieldType.GetElementType(), 0);
|
||||
|
||||
var parts = x.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries);
|
||||
var parts = value.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries);
|
||||
|
||||
var ret = Array.CreateInstance(fieldType.GetElementType(), parts.Length);
|
||||
for (int i = 0; i < parts.Length; i++)
|
||||
ret.SetValue(GetValue(field, fieldType.GetElementType(), parts[i].Trim()), i);
|
||||
ret.SetValue(GetValue(fieldName, fieldType.GetElementType(), parts[i].Trim(), field), i);
|
||||
return ret;
|
||||
}
|
||||
|
||||
else if (fieldType == typeof(int2))
|
||||
{
|
||||
var parts = x.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries);
|
||||
var parts = value.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries);
|
||||
return new int2(int.Parse(parts[0]), int.Parse(parts[1]));
|
||||
}
|
||||
|
||||
else if (fieldType == typeof(float2))
|
||||
{
|
||||
var parts = x.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries);
|
||||
var parts = value.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries);
|
||||
float xx = 0;
|
||||
float yy = 0;
|
||||
float res;
|
||||
@@ -264,13 +274,13 @@ namespace OpenRA.FileFormats
|
||||
|
||||
else if (fieldType == typeof(Rectangle))
|
||||
{
|
||||
var parts = x.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries);
|
||||
var parts = value.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries);
|
||||
return new Rectangle(int.Parse(parts[0]), int.Parse(parts[1]), int.Parse(parts[2]), int.Parse(parts[3]));
|
||||
}
|
||||
|
||||
else if (fieldType.IsGenericType && fieldType.GetGenericTypeDefinition() == typeof(Bits<>))
|
||||
{
|
||||
var parts = x.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries);
|
||||
var parts = value.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries);
|
||||
var argTypes = new Type[] { typeof(string[]) };
|
||||
var argValues = new object[] { parts };
|
||||
return fieldType.GetConstructor(argTypes).Invoke(argValues);
|
||||
@@ -279,11 +289,11 @@ namespace OpenRA.FileFormats
|
||||
else if (fieldType.IsGenericType && fieldType.GetGenericTypeDefinition() == typeof(Nullable<>))
|
||||
{
|
||||
var innerType = fieldType.GetGenericArguments().First();
|
||||
var innerValue = GetValue("Nullable<T>", innerType, x);
|
||||
return fieldType.GetConstructor(new []{ innerType }).Invoke(new []{ innerValue });
|
||||
var innerValue = GetValue("Nullable<T>", innerType, value, field);
|
||||
return fieldType.GetConstructor(new[] { innerType }).Invoke(new[] { innerValue });
|
||||
}
|
||||
|
||||
UnknownFieldAction("[Type] {0}".F(x), fieldType);
|
||||
UnknownFieldAction("[Type] {0}".F(value), fieldType);
|
||||
return null;
|
||||
}
|
||||
|
||||
@@ -312,7 +322,7 @@ namespace OpenRA.FileFormats
|
||||
if (loadUsing.Length != 0)
|
||||
ret[field] = (_1, fieldType, yaml) => loadUsing[0].LoaderFunc(field)(yaml);
|
||||
else if (fromYamlKey.Length != 0)
|
||||
ret[field] = (f, ft, yaml) => GetValue(f, ft, yaml.Value);
|
||||
ret[field] = (f, ft, yaml) => GetValue(f, ft, yaml.Value, field);
|
||||
else if (ignore.Length == 0)
|
||||
ret[field] = null;
|
||||
}
|
||||
@@ -342,8 +352,25 @@ namespace OpenRA.FileFormats
|
||||
return loaderFuncCache;
|
||||
}
|
||||
}
|
||||
|
||||
public static string Translate(string key)
|
||||
{
|
||||
if (Translations == null || string.IsNullOrEmpty(key))
|
||||
return key;
|
||||
|
||||
string value;
|
||||
if (!Translations.TryGetValue(key, out value))
|
||||
return key;
|
||||
|
||||
return value;
|
||||
}
|
||||
|
||||
public static Dictionary<string, string> Translations = new Dictionary<string, string>();
|
||||
}
|
||||
|
||||
[AttributeUsage(AttributeTargets.Field | AttributeTargets.Property)]
|
||||
public class TranslateAttribute : Attribute { }
|
||||
|
||||
public class FieldFromYamlKeyAttribute : Attribute { }
|
||||
|
||||
// mirrors DescriptionAttribute from System.ComponentModel but we dont want to have to use that everywhere.
|
||||
|
||||
@@ -21,7 +21,7 @@ namespace OpenRA.FileFormats
|
||||
public readonly string[]
|
||||
Mods, Folders, Rules, ServerTraits,
|
||||
Sequences, VoxelSequences, Cursors, Chrome, Assemblies, ChromeLayout,
|
||||
Weapons, Voices, Notifications, Music, Movies, TileSets,
|
||||
Weapons, Voices, Notifications, Music, Movies, Translations, TileSets,
|
||||
ChromeMetrics, PackageContents;
|
||||
|
||||
public readonly Dictionary<string, string> Packages;
|
||||
@@ -53,6 +53,7 @@ namespace OpenRA.FileFormats
|
||||
Notifications = YamlList(yaml, "Notifications");
|
||||
Music = YamlList(yaml, "Music");
|
||||
Movies = YamlList(yaml, "Movies");
|
||||
Translations = YamlList(yaml, "Translations");
|
||||
TileSets = YamlList(yaml, "TileSets");
|
||||
ChromeMetrics = YamlList(yaml, "ChromeMetrics");
|
||||
PackageContents = YamlList(yaml, "PackageContents");
|
||||
|
||||
@@ -96,6 +96,9 @@ namespace OpenRA.GameRules
|
||||
public int BatchSize = 8192;
|
||||
public int NumTempBuffers = 8;
|
||||
public int SheetSize = 2048;
|
||||
|
||||
public string Language = "english";
|
||||
public string DefaultLanguage = "english";
|
||||
}
|
||||
|
||||
public class SoundSettings
|
||||
|
||||
@@ -99,6 +99,7 @@ namespace OpenRA
|
||||
[FieldLoader.Ignore] public List<MiniYamlNode> Weapons = new List<MiniYamlNode>();
|
||||
[FieldLoader.Ignore] public List<MiniYamlNode> Voices = new List<MiniYamlNode>();
|
||||
[FieldLoader.Ignore] public List<MiniYamlNode> Notifications = new List<MiniYamlNode>();
|
||||
[FieldLoader.Ignore] public List<MiniYamlNode> Translations = new List<MiniYamlNode>();
|
||||
|
||||
// Binary map data
|
||||
[FieldLoader.Ignore] public byte TileFormat = 1;
|
||||
@@ -191,6 +192,7 @@ namespace OpenRA
|
||||
Weapons = MiniYaml.NodesOrEmpty(yaml, "Weapons");
|
||||
Voices = MiniYaml.NodesOrEmpty(yaml, "Voices");
|
||||
Notifications = MiniYaml.NodesOrEmpty(yaml, "Notifications");
|
||||
Translations = MiniYaml.NodesOrEmpty(yaml, "Translations");
|
||||
|
||||
CustomTerrain = new string[MapSize.X, MapSize.Y];
|
||||
|
||||
@@ -247,6 +249,7 @@ namespace OpenRA
|
||||
root.Add(new MiniYamlNode("Weapons", null, Weapons));
|
||||
root.Add(new MiniYamlNode("Voices", null, Voices));
|
||||
root.Add(new MiniYamlNode("Notifications", null, Notifications));
|
||||
root.Add(new MiniYamlNode("Translations", null, Translations));
|
||||
|
||||
var entries = new Dictionary<string, byte[]>();
|
||||
entries.Add("map.bin", SaveBinaryData());
|
||||
|
||||
@@ -44,6 +44,7 @@ namespace OpenRA
|
||||
|
||||
public ModData(params string[] mods)
|
||||
{
|
||||
Languages = new string[0];
|
||||
Manifest = new Manifest(mods);
|
||||
ObjectCreator = new ObjectCreator(Manifest);
|
||||
LoadScreen = ObjectCreator.CreateObject<ILoadScreen>(Manifest.LoadScreen.Value);
|
||||
@@ -71,6 +72,47 @@ namespace OpenRA
|
||||
CursorProvider.Initialize(Manifest.Cursors);
|
||||
}
|
||||
|
||||
public IEnumerable<string> Languages { get; private set; }
|
||||
|
||||
void LoadTranslations(Map map)
|
||||
{
|
||||
var selectedTranslations = new Dictionary<string, string>();
|
||||
var defaultTranslations = new Dictionary<string, string>();
|
||||
|
||||
if (!Manifest.Translations.Any())
|
||||
{
|
||||
Languages = new string[0];
|
||||
FieldLoader.Translations = new Dictionary<string, string>();
|
||||
return;
|
||||
}
|
||||
|
||||
var yaml = Manifest.Translations.Select(MiniYaml.FromFile).Aggregate(MiniYaml.MergeLiberal);
|
||||
Languages = yaml.Select(t => t.Key).ToArray();
|
||||
|
||||
yaml = MiniYaml.MergeLiberal(map.Translations, yaml);
|
||||
|
||||
foreach (var y in yaml)
|
||||
{
|
||||
if (y.Key == Game.Settings.Graphics.Language)
|
||||
selectedTranslations = y.Value.NodesDict.ToDictionary(x => x.Key, x => x.Value.Value ?? "");
|
||||
if (y.Key == Game.Settings.Graphics.DefaultLanguage)
|
||||
defaultTranslations = y.Value.NodesDict.ToDictionary(x => x.Key, x => x.Value.Value ?? "");
|
||||
}
|
||||
|
||||
var translations = new Dictionary<string, string>();
|
||||
foreach (var tkv in defaultTranslations.Concat(selectedTranslations))
|
||||
{
|
||||
if (translations.ContainsKey(tkv.Key))
|
||||
continue;
|
||||
if (selectedTranslations.ContainsKey(tkv.Key))
|
||||
translations.Add(tkv.Key, selectedTranslations[tkv.Key]);
|
||||
else
|
||||
translations.Add(tkv.Key, tkv.Value);
|
||||
}
|
||||
|
||||
FieldLoader.Translations = translations;
|
||||
}
|
||||
|
||||
public Map PrepareMap(string uid)
|
||||
{
|
||||
LoadScreen.Display();
|
||||
@@ -78,6 +120,8 @@ namespace OpenRA
|
||||
throw new InvalidDataException("Invalid map uid: {0}".F(uid));
|
||||
var map = new Map(AvailableMaps[uid].Path);
|
||||
|
||||
LoadTranslations(map);
|
||||
|
||||
// Reinit all our assets
|
||||
InitializeLoaders();
|
||||
FileSystem.LoadFromManifest(Manifest);
|
||||
|
||||
@@ -25,7 +25,7 @@ namespace OpenRA.Widgets
|
||||
set { GetKey = _ => value; }
|
||||
}
|
||||
|
||||
public string Text = "";
|
||||
[Translate] public string Text = "";
|
||||
public bool Depressed = false;
|
||||
public int VisualHeight = ChromeMetrics.Get<int>("ButtonDepth");
|
||||
public string Font = ChromeMetrics.Get<string>("ButtonFont");
|
||||
|
||||
@@ -10,6 +10,7 @@
|
||||
|
||||
using System;
|
||||
using System.Drawing;
|
||||
using OpenRA.FileFormats;
|
||||
using OpenRA.Graphics;
|
||||
|
||||
namespace OpenRA.Widgets
|
||||
@@ -19,7 +20,7 @@ namespace OpenRA.Widgets
|
||||
|
||||
public class LabelWidget : Widget
|
||||
{
|
||||
public string Text = null;
|
||||
[Translate] public string Text = null;
|
||||
public TextAlign Align = TextAlign.Left;
|
||||
public TextVAlign VAlign = TextVAlign.Middle;
|
||||
public string Font = "Regular";
|
||||
|
||||
@@ -104,6 +104,10 @@ namespace OpenRA.Mods.Cnc.Widgets.Logic
|
||||
var windowHeight = generalPane.Get<TextFieldWidget>("WINDOW_HEIGHT");
|
||||
windowHeight.Text = graphicsSettings.WindowedSize.Y.ToString();
|
||||
|
||||
var languageDropDownButton = generalPane.Get<DropDownButtonWidget>("LANGUAGE_DROPDOWNBUTTON");
|
||||
languageDropDownButton.OnMouseDown = _ => SettingsMenuLogic.ShowLanguageDropdown(languageDropDownButton);
|
||||
languageDropDownButton.GetText = () => FieldLoader.Translate(Game.Settings.Graphics.Language);
|
||||
|
||||
// Audio
|
||||
var soundSlider = generalPane.Get<SliderWidget>("SOUND_SLIDER");
|
||||
soundSlider.OnChange += x => { soundSettings.SoundVolume = x; Sound.SoundVolume = x; };
|
||||
|
||||
@@ -11,6 +11,7 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using OpenRA.FileFormats;
|
||||
using OpenRA.FileFormats.Graphics;
|
||||
using OpenRA.GameRules;
|
||||
using OpenRA.Widgets;
|
||||
@@ -142,6 +143,10 @@ namespace OpenRA.Mods.RA.Widgets.Logic
|
||||
var maxFrameRate = display.Get<TextFieldWidget>("MAX_FRAMERATE");
|
||||
maxFrameRate.Text = gs.MaxFramerate.ToString();
|
||||
|
||||
var languageDropDownButton = display.Get<DropDownButtonWidget>("LANGUAGE_DROPDOWNBUTTON");
|
||||
languageDropDownButton.OnMouseDown = _ => ShowLanguageDropdown(languageDropDownButton);
|
||||
languageDropDownButton.GetText = () => FieldLoader.Translate(Game.Settings.Graphics.Language);
|
||||
|
||||
// Keys
|
||||
var keys = bg.Get("KEYS_PANE");
|
||||
var keyConfig = Game.Settings.Keys;
|
||||
@@ -270,6 +275,20 @@ namespace OpenRA.Mods.RA.Widgets.Logic
|
||||
return true;
|
||||
}
|
||||
|
||||
public static bool ShowLanguageDropdown(DropDownButtonWidget dropdown)
|
||||
{
|
||||
Func<string, ScrollItemWidget, ScrollItemWidget> setupItem = (o, itemTemplate) =>
|
||||
{
|
||||
var item = ScrollItemWidget.Setup(itemTemplate,
|
||||
() => Game.Settings.Graphics.Language == o,
|
||||
() => Game.Settings.Graphics.Language = o);
|
||||
item.Get<LabelWidget>("LABEL").GetText = () => FieldLoader.Translate(o);
|
||||
return item;
|
||||
};
|
||||
|
||||
dropdown.ShowDropDown("LABEL_DROPDOWN_TEMPLATE", 500, Game.modData.Languages, setupItem);
|
||||
return true;
|
||||
}
|
||||
|
||||
public static bool ShowSoundTickDropdown(DropDownButtonWidget dropdown, SoundSettings audio)
|
||||
{
|
||||
|
||||
@@ -3,7 +3,7 @@ Container@SETTINGS_PANEL:
|
||||
X:(WINDOW_RIGHT - WIDTH)/2
|
||||
Y:(WINDOW_BOTTOM - 250)/2
|
||||
Width:740
|
||||
Height:535
|
||||
Height:565
|
||||
Children:
|
||||
ColorPreviewManager@COLOR_MANAGER:
|
||||
Label@TITLE:
|
||||
@@ -15,7 +15,7 @@ Container@SETTINGS_PANEL:
|
||||
Text:Settings
|
||||
Background@GENERAL_CONTROLS:
|
||||
Width:740
|
||||
Height:290
|
||||
Height:320
|
||||
Background:panel-black
|
||||
Children:
|
||||
Label@TITLE:
|
||||
@@ -66,35 +66,35 @@ Container@SETTINGS_PANEL:
|
||||
Text:Shellmap Music
|
||||
Label@DEBUG_TITLE:
|
||||
X:15
|
||||
Y:150
|
||||
Y:180
|
||||
Width:340
|
||||
Font:Bold
|
||||
Text:Debug
|
||||
Align:Center
|
||||
Checkbox@PERFTEXT_CHECKBOX:
|
||||
X:15
|
||||
Y:170
|
||||
Y:200
|
||||
Width:300
|
||||
Height:20
|
||||
Font:Regular
|
||||
Text:Show Performance Text
|
||||
Checkbox@PERFGRAPH_CHECKBOX:
|
||||
X:15
|
||||
Y:200
|
||||
Y:230
|
||||
Width:300
|
||||
Height:20
|
||||
Font:Regular
|
||||
Text:Show Performance Graph
|
||||
Checkbox@CHECKUNSYNCED_CHECKBOX:
|
||||
X:15
|
||||
Y:230
|
||||
Y:260
|
||||
Width:300
|
||||
Height:20
|
||||
Font:Regular
|
||||
Text:Check Sync around Unsynced Code
|
||||
Checkbox@SHOW_FATAL_ERROR_DIALOG_CHECKBOX:
|
||||
X:15
|
||||
Y:260
|
||||
Y:290
|
||||
Width:300
|
||||
Height:20
|
||||
Font:Regular
|
||||
@@ -149,70 +149,82 @@ Container@SETTINGS_PANEL:
|
||||
Width:45
|
||||
Height:25
|
||||
MaxLength:5
|
||||
Label@LANGUAGE_LABEL:
|
||||
X:375
|
||||
Y:70
|
||||
Width:75
|
||||
Height:25
|
||||
Align:Right
|
||||
Text:Language:
|
||||
DropDownButton@LANGUAGE_DROPDOWNBUTTON:
|
||||
X:455
|
||||
Y:70
|
||||
Width:140
|
||||
Height:25
|
||||
Label@VIDEO_DESC:
|
||||
X:375
|
||||
Y:68
|
||||
Y:100
|
||||
Width:340
|
||||
Height:25
|
||||
Font:Tiny
|
||||
Align:Center
|
||||
Text:Mode/Resolution changes will be applied after the game is restarted
|
||||
Text:Mode/Resolution/Language changes will be applied after the game is restarted
|
||||
Checkbox@PIXELDOUBLE_CHECKBOX:
|
||||
X:375
|
||||
Y:110
|
||||
Y:140
|
||||
Width:200
|
||||
Height:20
|
||||
Font:Regular
|
||||
Text:Enable Pixel Doubling
|
||||
Label@AUDIO_TITLE:
|
||||
X:375
|
||||
Y:150
|
||||
Y:180
|
||||
Width:340
|
||||
Font:Bold
|
||||
Text:Sound
|
||||
Align:Center
|
||||
Label@SOUND_LABEL:
|
||||
X:375
|
||||
Y:164
|
||||
Y:194
|
||||
Width:95
|
||||
Height:25
|
||||
Align:Right
|
||||
Text:Sound Volume:
|
||||
Slider@SOUND_SLIDER:
|
||||
X:475
|
||||
Y:170
|
||||
Y:200
|
||||
Width:240
|
||||
Height:20
|
||||
Ticks:5
|
||||
Label@MUSIC_LABEL:
|
||||
X:375
|
||||
Y:194
|
||||
Y:224
|
||||
Width:95
|
||||
Height:25
|
||||
Align:Right
|
||||
Text:Music Volume:
|
||||
Slider@MUSIC_SLIDER:
|
||||
X:475
|
||||
Y:200
|
||||
Y:230
|
||||
Width:240
|
||||
Height:20
|
||||
Ticks:5
|
||||
Label@AUDIO_DEVICE_LABEL:
|
||||
X:375
|
||||
Y:229
|
||||
Y:259
|
||||
Width:75
|
||||
Height:20
|
||||
Text:Audio Device:
|
||||
DropDownButton@AUDIO_DEVICE:
|
||||
X:475
|
||||
Y:230
|
||||
Y:260
|
||||
Width:240
|
||||
Height:25
|
||||
Font:Regular
|
||||
Text:Default Device
|
||||
Label@AUDIO_DESC:
|
||||
X:375
|
||||
Y:258
|
||||
Y:288
|
||||
Width:340
|
||||
Height:25
|
||||
Font:Tiny
|
||||
@@ -296,20 +308,20 @@ Container@SETTINGS_PANEL:
|
||||
Font:Regular
|
||||
Text:Shift-Enter Toggles Team Chat
|
||||
Button@GENERAL_BUTTON:
|
||||
Y:289
|
||||
Y:319
|
||||
Width:140
|
||||
Height:35
|
||||
Text:General
|
||||
Button@INPUT_BUTTON:
|
||||
X:150
|
||||
Y:289
|
||||
Y:319
|
||||
Width:140
|
||||
Height:35
|
||||
Text:Input
|
||||
Button@BACK_BUTTON:
|
||||
Key:escape
|
||||
X:600
|
||||
Y:289
|
||||
Y:319
|
||||
Width:140
|
||||
Height:35
|
||||
Text:Back
|
||||
|
||||
@@ -138,7 +138,7 @@ Background@SETTINGS_MENU:
|
||||
Label@SOUND_VOLUME_LABEL:
|
||||
X:0
|
||||
Y:10
|
||||
Text: Sound Volume
|
||||
Text: Sound Volume
|
||||
Slider@SOUND_VOLUME:
|
||||
X:100
|
||||
Y:0
|
||||
@@ -255,7 +255,7 @@ Background@SETTINGS_MENU:
|
||||
Height:25
|
||||
Font:Tiny
|
||||
Align:Center
|
||||
Text:Renderer/Mode/Resolution changes will be applied after the game is restarted.
|
||||
Text:Mode/Resolution changes will be applied after the game is restarted.
|
||||
Checkbox@PIXELDOUBLE_CHECKBOX:
|
||||
Y:60
|
||||
Width:200
|
||||
@@ -274,6 +274,24 @@ Background@SETTINGS_MENU:
|
||||
Width:45
|
||||
Height:25
|
||||
MaxLength:3
|
||||
Label@LANGUAGE_LABEL:
|
||||
X:0
|
||||
Y:130
|
||||
Width:75
|
||||
Height:25
|
||||
Text:Language:
|
||||
DropDownButton@LANGUAGE_DROPDOWNBUTTON:
|
||||
X:80
|
||||
Y:130
|
||||
Width:140
|
||||
Height:25
|
||||
Label@LANGUAGE_DESC:
|
||||
Y:160
|
||||
Width:PARENT_RIGHT
|
||||
Height:25
|
||||
Font:Tiny
|
||||
Align:Center
|
||||
Text:Language changes will be applied after the game is restarted.
|
||||
Container@KEYS_PANE:
|
||||
X:37
|
||||
Y:100
|
||||
|
||||
Reference in New Issue
Block a user