Merge pull request #7917 from RoosterDragon/replay-browser-load-perf
Faster replay browser loading
This commit is contained in:
@@ -33,9 +33,17 @@ namespace OpenRA
|
|||||||
throw new NotImplementedException("FieldLoader: Missing field `{0}` on `{1}`".F(s, f.Name));
|
throw new NotImplementedException("FieldLoader: Missing field `{0}` on `{1}`".F(s, f.Name));
|
||||||
};
|
};
|
||||||
|
|
||||||
|
static readonly ConcurrentCache<Type, FieldLoadInfo[]> TypeLoadInfo =
|
||||||
|
new ConcurrentCache<Type, FieldLoadInfo[]>(BuildTypeLoadInfo);
|
||||||
|
static readonly ConcurrentCache<MemberInfo, bool> MemberHasTranslateAttribute =
|
||||||
|
new ConcurrentCache<MemberInfo, bool>(member => member.HasAttribute<TranslateAttribute>());
|
||||||
|
|
||||||
|
static readonly object TranslationsLock = new object();
|
||||||
|
static Dictionary<string, string> translations;
|
||||||
|
|
||||||
public static void Load(object self, MiniYaml my)
|
public static void Load(object self, MiniYaml my)
|
||||||
{
|
{
|
||||||
var loadInfo = typeLoadInfo[self.GetType()];
|
var loadInfo = TypeLoadInfo[self.GetType()];
|
||||||
|
|
||||||
Dictionary<string, MiniYaml> md = null;
|
Dictionary<string, MiniYaml> md = null;
|
||||||
|
|
||||||
@@ -82,7 +90,6 @@ namespace OpenRA
|
|||||||
return t;
|
return t;
|
||||||
}
|
}
|
||||||
|
|
||||||
static readonly object[] NoIndexes = { };
|
|
||||||
public static void LoadField(object target, string key, string value)
|
public static void LoadField(object target, string key, string value)
|
||||||
{
|
{
|
||||||
const BindingFlags Flags = BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance;
|
const BindingFlags Flags = BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance;
|
||||||
@@ -103,7 +110,7 @@ namespace OpenRA
|
|||||||
{
|
{
|
||||||
var sa = prop.GetCustomAttributes<SerializeAttribute>(false).DefaultIfEmpty(SerializeAttribute.Default).First();
|
var sa = prop.GetCustomAttributes<SerializeAttribute>(false).DefaultIfEmpty(SerializeAttribute.Default).First();
|
||||||
if (!sa.FromYamlKey)
|
if (!sa.FromYamlKey)
|
||||||
prop.SetValue(target, GetValue(prop.Name, prop.PropertyType, value, prop), NoIndexes);
|
prop.SetValue(target, GetValue(prop.Name, prop.PropertyType, value, prop), null);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -162,7 +169,7 @@ namespace OpenRA
|
|||||||
}
|
}
|
||||||
else if (fieldType == typeof(string))
|
else if (fieldType == typeof(string))
|
||||||
{
|
{
|
||||||
if (field != null && field.HasAttribute<TranslateAttribute>())
|
if (field != null && MemberHasTranslateAttribute[field])
|
||||||
return Regex.Replace(value, "@[^@]+@", m => Translate(m.Value.Substring(1, m.Value.Length - 2)), RegexOptions.Compiled);
|
return Regex.Replace(value, "@[^@]+@", m => Translate(m.Value.Substring(1, m.Value.Length - 2)), RegexOptions.Compiled);
|
||||||
return value;
|
return value;
|
||||||
}
|
}
|
||||||
@@ -438,12 +445,10 @@ namespace OpenRA
|
|||||||
|
|
||||||
public static IEnumerable<FieldLoadInfo> GetTypeLoadInfo(Type type, bool includePrivateByDefault = false)
|
public static IEnumerable<FieldLoadInfo> GetTypeLoadInfo(Type type, bool includePrivateByDefault = false)
|
||||||
{
|
{
|
||||||
return typeLoadInfo[type].Where(fli => includePrivateByDefault || fli.Field.IsPublic || (fli.Attribute.Serialize && !fli.Attribute.IsDefault));
|
return TypeLoadInfo[type].Where(fli => includePrivateByDefault || fli.Field.IsPublic || (fli.Attribute.Serialize && !fli.Attribute.IsDefault));
|
||||||
}
|
}
|
||||||
|
|
||||||
static Cache<Type, List<FieldLoadInfo>> typeLoadInfo = new Cache<Type, List<FieldLoadInfo>>(BuildTypeLoadInfo);
|
static FieldLoadInfo[] BuildTypeLoadInfo(Type type)
|
||||||
|
|
||||||
static List<FieldLoadInfo> BuildTypeLoadInfo(Type type)
|
|
||||||
{
|
{
|
||||||
var ret = new List<FieldLoadInfo>();
|
var ret = new List<FieldLoadInfo>();
|
||||||
|
|
||||||
@@ -465,7 +470,7 @@ namespace OpenRA
|
|||||||
ret.Add(fli);
|
ret.Add(fli);
|
||||||
}
|
}
|
||||||
|
|
||||||
return ret;
|
return ret.ToArray();
|
||||||
}
|
}
|
||||||
|
|
||||||
[AttributeUsage(AttributeTargets.Field)]
|
[AttributeUsage(AttributeTargets.Field)]
|
||||||
@@ -520,17 +525,27 @@ namespace OpenRA
|
|||||||
|
|
||||||
public static string Translate(string key)
|
public static string Translate(string key)
|
||||||
{
|
{
|
||||||
if (Translations == null || string.IsNullOrEmpty(key))
|
if (string.IsNullOrEmpty(key))
|
||||||
|
return key;
|
||||||
|
|
||||||
|
lock (TranslationsLock)
|
||||||
|
{
|
||||||
|
if (translations == null)
|
||||||
return key;
|
return key;
|
||||||
|
|
||||||
string value;
|
string value;
|
||||||
if (!Translations.TryGetValue(key, out value))
|
if (!translations.TryGetValue(key, out value))
|
||||||
return key;
|
return key;
|
||||||
|
|
||||||
return value;
|
return value;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public static Dictionary<string, string> Translations = new Dictionary<string, string>();
|
public static void SetTranslations(IDictionary<string, string> translations)
|
||||||
|
{
|
||||||
|
lock (TranslationsLock)
|
||||||
|
FieldLoader.translations = new Dictionary<string, string>(translations);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
[AttributeUsage(AttributeTargets.Field | AttributeTargets.Property)]
|
[AttributeUsage(AttributeTargets.Field | AttributeTargets.Property)]
|
||||||
@@ -546,6 +561,7 @@ namespace OpenRA
|
|||||||
}
|
}
|
||||||
|
|
||||||
// mirrors DescriptionAttribute from System.ComponentModel but we dont want to have to use that everywhere.
|
// mirrors DescriptionAttribute from System.ComponentModel but we dont want to have to use that everywhere.
|
||||||
|
[AttributeUsage(AttributeTargets.All)]
|
||||||
public sealed class DescAttribute : Attribute
|
public sealed class DescAttribute : Attribute
|
||||||
{
|
{
|
||||||
public readonly string[] Lines;
|
public readonly string[] Lines;
|
||||||
|
|||||||
@@ -116,7 +116,6 @@ namespace OpenRA
|
|||||||
if (!Manifest.Translations.Any())
|
if (!Manifest.Translations.Any())
|
||||||
{
|
{
|
||||||
Languages = new string[0];
|
Languages = new string[0];
|
||||||
FieldLoader.Translations = new Dictionary<string, string>();
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -144,7 +143,7 @@ namespace OpenRA
|
|||||||
translations.Add(tkv.Key, tkv.Value);
|
translations.Add(tkv.Key, tkv.Value);
|
||||||
}
|
}
|
||||||
|
|
||||||
FieldLoader.Translations = translations;
|
FieldLoader.SetTranslations(translations);
|
||||||
}
|
}
|
||||||
|
|
||||||
public Map PrepareMap(string uid)
|
public Map PrepareMap(string uid)
|
||||||
|
|||||||
@@ -145,6 +145,7 @@
|
|||||||
<Compile Include="Player.cs" />
|
<Compile Include="Player.cs" />
|
||||||
<Compile Include="Primitives\MergedStream.cs" />
|
<Compile Include="Primitives\MergedStream.cs" />
|
||||||
<Compile Include="Primitives\SpatiallyPartitioned.cs" />
|
<Compile Include="Primitives\SpatiallyPartitioned.cs" />
|
||||||
|
<Compile Include="Primitives\ConcurrentCache.cs" />
|
||||||
<Compile Include="Selection.cs" />
|
<Compile Include="Selection.cs" />
|
||||||
<Compile Include="Server\Connection.cs" />
|
<Compile Include="Server\Connection.cs" />
|
||||||
<Compile Include="Server\Exts.cs" />
|
<Compile Include="Server\Exts.cs" />
|
||||||
|
|||||||
@@ -9,7 +9,6 @@
|
|||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
using System;
|
using System;
|
||||||
using System.Collections;
|
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
|
||||||
namespace OpenRA.Primitives
|
namespace OpenRA.Primitives
|
||||||
@@ -23,6 +22,7 @@ namespace OpenRA.Primitives
|
|||||||
{
|
{
|
||||||
if (loader == null)
|
if (loader == null)
|
||||||
throw new ArgumentNullException("loader");
|
throw new ArgumentNullException("loader");
|
||||||
|
|
||||||
this.loader = loader;
|
this.loader = loader;
|
||||||
cache = new Dictionary<T, U>(c);
|
cache = new Dictionary<T, U>(c);
|
||||||
}
|
}
|
||||||
@@ -32,13 +32,7 @@ namespace OpenRA.Primitives
|
|||||||
|
|
||||||
public U this[T key]
|
public U this[T key]
|
||||||
{
|
{
|
||||||
get
|
get { return cache.GetOrAdd(key, loader); }
|
||||||
{
|
|
||||||
U result;
|
|
||||||
if (!cache.TryGetValue(key, out result))
|
|
||||||
cache.Add(key, result = loader(key));
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public bool ContainsKey(T key) { return cache.ContainsKey(key); }
|
public bool ContainsKey(T key) { return cache.ContainsKey(key); }
|
||||||
@@ -47,6 +41,6 @@ namespace OpenRA.Primitives
|
|||||||
public ICollection<T> Keys { get { return cache.Keys; } }
|
public ICollection<T> Keys { get { return cache.Keys; } }
|
||||||
public ICollection<U> Values { get { return cache.Values; } }
|
public ICollection<U> Values { get { return cache.Values; } }
|
||||||
public IEnumerator<KeyValuePair<T, U>> GetEnumerator() { return cache.GetEnumerator(); }
|
public IEnumerator<KeyValuePair<T, U>> GetEnumerator() { return cache.GetEnumerator(); }
|
||||||
IEnumerator IEnumerable.GetEnumerator() { return GetEnumerator(); }
|
System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator() { return GetEnumerator(); }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
47
OpenRA.Game/Primitives/ConcurrentCache.cs
Normal file
47
OpenRA.Game/Primitives/ConcurrentCache.cs
Normal file
@@ -0,0 +1,47 @@
|
|||||||
|
#region Copyright & License Information
|
||||||
|
/*
|
||||||
|
* Copyright 2007-2015 The OpenRA Developers (see AUTHORS)
|
||||||
|
* This file is part of OpenRA, which is free software. It is made
|
||||||
|
* available to you under the terms of the GNU General Public License
|
||||||
|
* as published by the Free Software Foundation. For more information,
|
||||||
|
* see COPYING.
|
||||||
|
*/
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
using System;
|
||||||
|
using System.Collections.Concurrent;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
|
||||||
|
namespace OpenRA.Primitives
|
||||||
|
{
|
||||||
|
public class ConcurrentCache<T, U> : IReadOnlyDictionary<T, U>
|
||||||
|
{
|
||||||
|
readonly ConcurrentDictionary<T, U> cache;
|
||||||
|
readonly Func<T, U> loader;
|
||||||
|
|
||||||
|
public ConcurrentCache(Func<T, U> loader, IEqualityComparer<T> c)
|
||||||
|
{
|
||||||
|
if (loader == null)
|
||||||
|
throw new ArgumentNullException("loader");
|
||||||
|
|
||||||
|
this.loader = loader;
|
||||||
|
cache = new ConcurrentDictionary<T, U>(c);
|
||||||
|
}
|
||||||
|
|
||||||
|
public ConcurrentCache(Func<T, U> loader)
|
||||||
|
: this(loader, EqualityComparer<T>.Default) { }
|
||||||
|
|
||||||
|
public U this[T key]
|
||||||
|
{
|
||||||
|
get { return cache.GetOrAdd(key, loader); }
|
||||||
|
}
|
||||||
|
|
||||||
|
public bool ContainsKey(T key) { return cache.ContainsKey(key); }
|
||||||
|
public bool TryGetValue(T key, out U value) { return cache.TryGetValue(key, out value); }
|
||||||
|
public int Count { get { return cache.Count; } }
|
||||||
|
public ICollection<T> Keys { get { return cache.Keys; } }
|
||||||
|
public ICollection<U> Values { get { return cache.Values; } }
|
||||||
|
public IEnumerator<KeyValuePair<T, U>> GetEnumerator() { return cache.GetEnumerator(); }
|
||||||
|
System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator() { return GetEnumerator(); }
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -9,9 +9,12 @@
|
|||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
using System;
|
using System;
|
||||||
|
using System.Collections.Concurrent;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
|
using System.Threading;
|
||||||
|
using System.Threading.Tasks;
|
||||||
using OpenRA.FileFormats;
|
using OpenRA.FileFormats;
|
||||||
using OpenRA.Mods.Common.Widgets;
|
using OpenRA.Mods.Common.Widgets;
|
||||||
using OpenRA.Primitives;
|
using OpenRA.Primitives;
|
||||||
@@ -23,16 +26,17 @@ namespace OpenRA.Mods.Common.Widgets.Logic
|
|||||||
{
|
{
|
||||||
static Filter filter = new Filter();
|
static Filter filter = new Filter();
|
||||||
|
|
||||||
Widget panel;
|
readonly Widget panel;
|
||||||
ScrollPanelWidget replayList, playerList;
|
readonly ScrollPanelWidget replayList, playerList;
|
||||||
ScrollItemWidget playerTemplate, playerHeader;
|
readonly ScrollItemWidget playerTemplate, playerHeader;
|
||||||
List<ReplayMetadata> replays;
|
readonly List<ReplayMetadata> replays = new List<ReplayMetadata>();
|
||||||
Dictionary<ReplayMetadata, ReplayState> replayState = new Dictionary<ReplayMetadata, ReplayState>();
|
readonly Dictionary<ReplayMetadata, ReplayState> replayState = new Dictionary<ReplayMetadata, ReplayState>();
|
||||||
|
readonly Action onStart;
|
||||||
|
|
||||||
Dictionary<CPos, SpawnOccupant> selectedSpawns;
|
Dictionary<CPos, SpawnOccupant> selectedSpawns;
|
||||||
ReplayMetadata selectedReplay;
|
ReplayMetadata selectedReplay;
|
||||||
|
|
||||||
Action onStart;
|
volatile bool cancelLoadingReplays;
|
||||||
|
|
||||||
[ObjectCreator.UseCtor]
|
[ObjectCreator.UseCtor]
|
||||||
public ReplayBrowserLogic(Widget widget, Action onExit, Action onStart)
|
public ReplayBrowserLogic(Widget widget, Action onExit, Action onStart)
|
||||||
@@ -46,7 +50,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic
|
|||||||
playerTemplate = playerList.Get<ScrollItemWidget>("TEMPLATE");
|
playerTemplate = playerList.Get<ScrollItemWidget>("TEMPLATE");
|
||||||
playerList.RemoveChildren();
|
playerList.RemoveChildren();
|
||||||
|
|
||||||
panel.Get<ButtonWidget>("CANCEL_BUTTON").OnClick = () => { Ui.CloseWindow(); onExit(); };
|
panel.Get<ButtonWidget>("CANCEL_BUTTON").OnClick = () => { cancelLoadingReplays = true; Ui.CloseWindow(); onExit(); };
|
||||||
|
|
||||||
replayList = panel.Get<ScrollPanelWidget>("REPLAY_LIST");
|
replayList = panel.Get<ScrollPanelWidget>("REPLAY_LIST");
|
||||||
var template = panel.Get<ScrollItemWidget>("REPLAY_TEMPLATE");
|
var template = panel.Get<ScrollItemWidget>("REPLAY_TEMPLATE");
|
||||||
@@ -54,26 +58,8 @@ namespace OpenRA.Mods.Common.Widgets.Logic
|
|||||||
var mod = Game.ModData.Manifest.Mod;
|
var mod = Game.ModData.Manifest.Mod;
|
||||||
var dir = Platform.ResolvePath("^", "Replays", mod.Id, mod.Version);
|
var dir = Platform.ResolvePath("^", "Replays", mod.Id, mod.Version);
|
||||||
|
|
||||||
replayList.RemoveChildren();
|
|
||||||
if (Directory.Exists(dir))
|
if (Directory.Exists(dir))
|
||||||
{
|
ThreadPool.QueueUserWorkItem(_ => LoadReplays(dir, template));
|
||||||
using (new Support.PerfTimer("Load replays"))
|
|
||||||
{
|
|
||||||
replays = Directory
|
|
||||||
.GetFiles(dir, "*.orarep")
|
|
||||||
.Select(ReplayMetadata.Read)
|
|
||||||
.Where(r => r != null)
|
|
||||||
.OrderByDescending(r => r.GameInfo.StartTimeUtc)
|
|
||||||
.ToList();
|
|
||||||
}
|
|
||||||
|
|
||||||
foreach (var replay in replays)
|
|
||||||
AddReplay(replay, template);
|
|
||||||
|
|
||||||
ApplyFilter();
|
|
||||||
}
|
|
||||||
else
|
|
||||||
replays = new List<ReplayMetadata>();
|
|
||||||
|
|
||||||
var watch = panel.Get<ButtonWidget>("WATCH_BUTTON");
|
var watch = panel.Get<ButtonWidget>("WATCH_BUTTON");
|
||||||
watch.IsDisabled = () => selectedReplay == null || selectedReplay.GameInfo.MapPreview.Status != MapStatus.Available;
|
watch.IsDisabled = () => selectedReplay == null || selectedReplay.GameInfo.MapPreview.Status != MapStatus.Available;
|
||||||
@@ -99,6 +85,40 @@ namespace OpenRA.Mods.Common.Widgets.Logic
|
|||||||
SetupManagement();
|
SetupManagement();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void LoadReplays(string dir, ScrollItemWidget template)
|
||||||
|
{
|
||||||
|
using (new Support.PerfTimer("Load replays"))
|
||||||
|
{
|
||||||
|
var loadedReplays = new ConcurrentBag<ReplayMetadata>();
|
||||||
|
Parallel.ForEach(Directory.GetFiles(dir, "*.orarep"), (fileName, pls) =>
|
||||||
|
{
|
||||||
|
if (cancelLoadingReplays)
|
||||||
|
{
|
||||||
|
pls.Stop();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
var replay = ReplayMetadata.Read(fileName);
|
||||||
|
if (replay != null)
|
||||||
|
loadedReplays.Add(replay);
|
||||||
|
});
|
||||||
|
|
||||||
|
if (cancelLoadingReplays)
|
||||||
|
return;
|
||||||
|
|
||||||
|
var sortedReplays = loadedReplays.OrderByDescending(replay => replay.GameInfo.StartTimeUtc).ToList();
|
||||||
|
Game.RunAfterTick(() =>
|
||||||
|
{
|
||||||
|
replayList.RemoveChildren();
|
||||||
|
foreach (var replay in sortedReplays)
|
||||||
|
AddReplay(replay, template);
|
||||||
|
|
||||||
|
SetupReplayDependentFilters();
|
||||||
|
ApplyFilter();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void SetupFilters()
|
void SetupFilters()
|
||||||
{
|
{
|
||||||
// Game type
|
// Game type
|
||||||
@@ -202,6 +222,50 @@ namespace OpenRA.Mods.Common.Widgets.Logic
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Outcome (depends on Player)
|
||||||
|
{
|
||||||
|
var ddb = panel.GetOrNull<DropDownButtonWidget>("FLT_OUTCOME_DROPDOWNBUTTON");
|
||||||
|
if (ddb != null)
|
||||||
|
{
|
||||||
|
ddb.IsDisabled = () => string.IsNullOrEmpty(filter.PlayerName);
|
||||||
|
|
||||||
|
// Using list to maintain the order
|
||||||
|
var options = new List<Pair<WinState, string>>
|
||||||
|
{
|
||||||
|
Pair.New(WinState.Undefined, ddb.GetText()),
|
||||||
|
Pair.New(WinState.Lost, "Defeat"),
|
||||||
|
Pair.New(WinState.Won, "Victory")
|
||||||
|
};
|
||||||
|
var lookup = options.ToDictionary(kvp => kvp.First, kvp => kvp.Second);
|
||||||
|
|
||||||
|
ddb.GetText = () => lookup[filter.Outcome];
|
||||||
|
ddb.OnMouseDown = _ =>
|
||||||
|
{
|
||||||
|
Func<Pair<WinState, string>, ScrollItemWidget, ScrollItemWidget> setupItem = (option, tpl) =>
|
||||||
|
{
|
||||||
|
var item = ScrollItemWidget.Setup(
|
||||||
|
tpl,
|
||||||
|
() => filter.Outcome == option.First,
|
||||||
|
() => { filter.Outcome = option.First; ApplyFilter(); });
|
||||||
|
item.Get<LabelWidget>("LABEL").GetText = () => option.Second;
|
||||||
|
return item;
|
||||||
|
};
|
||||||
|
|
||||||
|
ddb.ShowDropDown("LABEL_DROPDOWN_TEMPLATE", 330, options, setupItem);
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Reset button
|
||||||
|
{
|
||||||
|
var button = panel.Get<ButtonWidget>("FLT_RESET_BUTTON");
|
||||||
|
button.IsDisabled = () => filter.IsEmpty;
|
||||||
|
button.OnClick = () => { filter = new Filter(); ApplyFilter(); };
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void SetupReplayDependentFilters()
|
||||||
|
{
|
||||||
// Map
|
// Map
|
||||||
{
|
{
|
||||||
var ddb = panel.GetOrNull<DropDownButtonWidget>("FLT_MAPNAME_DROPDOWNBUTTON");
|
var ddb = panel.GetOrNull<DropDownButtonWidget>("FLT_MAPNAME_DROPDOWNBUTTON");
|
||||||
@@ -258,40 +322,6 @@ namespace OpenRA.Mods.Common.Widgets.Logic
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Outcome (depends on Player)
|
|
||||||
{
|
|
||||||
var ddb = panel.GetOrNull<DropDownButtonWidget>("FLT_OUTCOME_DROPDOWNBUTTON");
|
|
||||||
if (ddb != null)
|
|
||||||
{
|
|
||||||
ddb.IsDisabled = () => string.IsNullOrEmpty(filter.PlayerName);
|
|
||||||
|
|
||||||
// Using list to maintain the order
|
|
||||||
var options = new List<Pair<WinState, string>>
|
|
||||||
{
|
|
||||||
Pair.New(WinState.Undefined, ddb.GetText()),
|
|
||||||
Pair.New(WinState.Lost, "Defeat"),
|
|
||||||
Pair.New(WinState.Won, "Victory")
|
|
||||||
};
|
|
||||||
var lookup = options.ToDictionary(kvp => kvp.First, kvp => kvp.Second);
|
|
||||||
|
|
||||||
ddb.GetText = () => lookup[filter.Outcome];
|
|
||||||
ddb.OnMouseDown = _ =>
|
|
||||||
{
|
|
||||||
Func<Pair<WinState, string>, ScrollItemWidget, ScrollItemWidget> setupItem = (option, tpl) =>
|
|
||||||
{
|
|
||||||
var item = ScrollItemWidget.Setup(
|
|
||||||
tpl,
|
|
||||||
() => filter.Outcome == option.First,
|
|
||||||
() => { filter.Outcome = option.First; ApplyFilter(); });
|
|
||||||
item.Get<LabelWidget>("LABEL").GetText = () => option.Second;
|
|
||||||
return item;
|
|
||||||
};
|
|
||||||
|
|
||||||
ddb.ShowDropDown("LABEL_DROPDOWN_TEMPLATE", 330, options, setupItem);
|
|
||||||
};
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Faction (depends on Player)
|
// Faction (depends on Player)
|
||||||
{
|
{
|
||||||
var ddb = panel.GetOrNull<DropDownButtonWidget>("FLT_FACTION_DROPDOWNBUTTON");
|
var ddb = panel.GetOrNull<DropDownButtonWidget>("FLT_FACTION_DROPDOWNBUTTON");
|
||||||
@@ -323,13 +353,6 @@ namespace OpenRA.Mods.Common.Widgets.Logic
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Reset button
|
|
||||||
{
|
|
||||||
var button = panel.Get<ButtonWidget>("FLT_RESET_BUTTON");
|
|
||||||
button.IsDisabled = () => filter.IsEmpty;
|
|
||||||
button.OnClick = () => { filter = new Filter(); ApplyFilter(); };
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void SetupManagement()
|
void SetupManagement()
|
||||||
@@ -632,6 +655,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic
|
|||||||
{
|
{
|
||||||
Action startReplay = () =>
|
Action startReplay = () =>
|
||||||
{
|
{
|
||||||
|
cancelLoadingReplays = true;
|
||||||
Game.JoinReplay(selectedReplay.FilePath);
|
Game.JoinReplay(selectedReplay.FilePath);
|
||||||
Ui.CloseWindow();
|
Ui.CloseWindow();
|
||||||
onStart();
|
onStart();
|
||||||
@@ -643,6 +667,8 @@ namespace OpenRA.Mods.Common.Widgets.Logic
|
|||||||
|
|
||||||
void AddReplay(ReplayMetadata replay, ScrollItemWidget template)
|
void AddReplay(ReplayMetadata replay, ScrollItemWidget template)
|
||||||
{
|
{
|
||||||
|
replays.Add(replay);
|
||||||
|
|
||||||
var item = ScrollItemWidget.Setup(template,
|
var item = ScrollItemWidget.Setup(template,
|
||||||
() => selectedReplay == replay,
|
() => selectedReplay == replay,
|
||||||
() => SelectReplay(replay),
|
() => SelectReplay(replay),
|
||||||
|
|||||||
@@ -162,9 +162,12 @@ namespace OpenRA.Mods.Common.Widgets
|
|||||||
WidgetUtils.DrawRGBA(ChromeProvider.GetImage("scrollbar", downPressed || downDisabled ? "down_pressed" : "down_arrow"),
|
WidgetUtils.DrawRGBA(ChromeProvider.GetImage("scrollbar", downPressed || downDisabled ? "down_pressed" : "down_arrow"),
|
||||||
new float2(downButtonRect.Left + downOffset, downButtonRect.Top + downOffset));
|
new float2(downButtonRect.Left + downOffset, downButtonRect.Top + downOffset));
|
||||||
|
|
||||||
Game.Renderer.EnableScissor(backgroundRect.InflateBy(-1, -1, -1, -1));
|
var drawBounds = backgroundRect.InflateBy(-1, -1, -1, -1);
|
||||||
|
Game.Renderer.EnableScissor(drawBounds);
|
||||||
|
|
||||||
|
drawBounds.Offset((-ChildOrigin).ToPoint());
|
||||||
foreach (var child in Children)
|
foreach (var child in Children)
|
||||||
|
if (child.Bounds.IntersectsWith(drawBounds))
|
||||||
child.DrawOuter();
|
child.DrawOuter();
|
||||||
|
|
||||||
Game.Renderer.DisableScissor();
|
Game.Renderer.DisableScissor();
|
||||||
|
|||||||
Reference in New Issue
Block a user