-
-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fixed test settings RequireRestart Fixed v1 override of GetSettings Changed ApplicationContainerProvider and SynchronizationProvider to use their singleton ability instead of relying on some game's list Minor re branding
- Loading branch information
Showing
37 changed files
with
447 additions
and
313 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
using MBOptionScreen.Data; | ||
|
||
using TaleWorlds.Core.ViewModelCollection; | ||
|
||
namespace MBOptionScreen.Actions | ||
{ | ||
public sealed class SetDropdownAction : IAction | ||
{ | ||
public Ref? Context { get; } | ||
public object Value { get; } | ||
public object Original { get; } | ||
|
||
public SetDropdownAction(Ref context, SelectorVM<SelectorItemVM> value) | ||
{ | ||
Context = context; | ||
Value = value.SelectedIndex; | ||
Original = (Context.Value as IDropdownProvider)!.SelectedIndex; | ||
} | ||
|
||
public void DoAction() => (Context!.Value as IDropdownProvider)!.SelectedIndex = (int) Value; | ||
public void UndoAction() => (Context!.Value as IDropdownProvider)!.SelectedIndex = (int) Original; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
namespace MBOptionScreen.Actions | ||
{ | ||
public sealed class SetStringAction : IAction | ||
{ | ||
public Ref? Context { get; } | ||
public object Value { get; } | ||
public object Original { get; } | ||
|
||
public SetStringAction(Ref context, string value) | ||
{ | ||
Context = context; | ||
Value = value!; | ||
Original = Context.Value; | ||
} | ||
|
||
public void DoAction() => Context!.Value = Value; | ||
public void UndoAction() => Context!.Value = Original; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
namespace MBOptionScreen.Actions | ||
{ | ||
|
||
public sealed class SetValueTypeAction<T> : IAction | ||
where T : struct | ||
{ | ||
public Ref? Context { get; } | ||
public object Value { get; } | ||
public object Original { get; } | ||
|
||
public SetValueTypeAction(Ref context, T value) | ||
{ | ||
Context = context; | ||
Value = value!; | ||
Original = Context.Value; | ||
} | ||
|
||
public void DoAction() => Context!.Value = Value; | ||
public void UndoAction() => Context!.Value = Original; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
113 changes: 21 additions & 92 deletions
113
MBOptionScreen/ApplicationContainer/DefaultApplicationContainerProvider.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,113 +1,42 @@ | ||
using HarmonyLib; | ||
using MBOptionScreen.Attributes; | ||
|
||
using MBOptionScreen.Attributes; | ||
|
||
using System.Collections; | ||
using System.Collections.Generic; | ||
|
||
using TaleWorlds.Localization; | ||
using TaleWorlds.MountAndBlade; | ||
|
||
using Module = TaleWorlds.MountAndBlade.Module; | ||
using System.Collections.Concurrent; | ||
|
||
namespace MBOptionScreen.ApplicationContainer | ||
{ | ||
[Version("e1.0.0", 200)] | ||
[Version("e1.0.1", 200)] | ||
[Version("e1.0.2", 200)] | ||
[Version("e1.0.3", 200)] | ||
[Version("e1.0.4", 200)] | ||
[Version("e1.0.5", 200)] | ||
[Version("e1.0.6", 200)] | ||
[Version("e1.0.7", 200)] | ||
[Version("e1.0.8", 200)] | ||
[Version("e1.0.9", 200)] | ||
[Version("e1.0.10", 200)] | ||
[Version("e1.0.11", 200)] | ||
[Version("e1.1.0", 200)] | ||
[Version("e1.2.0", 200)] | ||
[Version("e1.0.0", 201)] | ||
[Version("e1.0.1", 201)] | ||
[Version("e1.0.2", 201)] | ||
[Version("e1.0.3", 201)] | ||
[Version("e1.0.4", 201)] | ||
[Version("e1.0.5", 201)] | ||
[Version("e1.0.6", 201)] | ||
[Version("e1.0.7", 201)] | ||
[Version("e1.0.8", 201)] | ||
[Version("e1.0.9", 201)] | ||
[Version("e1.0.10", 201)] | ||
[Version("e1.0.11", 201)] | ||
[Version("e1.1.0", 201)] | ||
[Version("e1.2.0", 201)] | ||
[Version("e1.2.1", 201)] | ||
[Version("e1.3.0", 201)] | ||
internal sealed class DefaultApplicationContainerProvider : IApplicationContainerProvider | ||
{ | ||
private static readonly AccessTools.FieldRef<Module, IList> _initialStateOptions = | ||
AccessTools.FieldRefAccess<Module, IList>("_initialStateOptions"); | ||
|
||
private readonly List<Container> _containers = new List<Container>(); | ||
private static readonly ConcurrentDictionary<string, object> _containers = new ConcurrentDictionary<string, object>(); | ||
|
||
public object Get(string name) | ||
{ | ||
if (Module.CurrentModule.GetInitialStateOptionWithId(name) is object obj) | ||
{ | ||
if (!(obj is Container container)) | ||
{ | ||
var wrapper = new ContainerWrapper(obj); | ||
if (!wrapper.IsCorrect) | ||
return default; | ||
container = wrapper; | ||
} | ||
|
||
return container.Value; | ||
} | ||
return default; | ||
return _containers.TryGetValue(name, out var value) ? value : default; | ||
} | ||
|
||
public void Set(string name, object value) | ||
{ | ||
if (Module.CurrentModule.GetInitialStateOptionWithId(name) is object obj) | ||
{ | ||
if (!(obj is Container container)) | ||
{ | ||
var wrapper = new ContainerWrapper(obj); | ||
if (!wrapper.IsCorrect) | ||
return; | ||
container = wrapper; | ||
} | ||
|
||
container.Value = value; | ||
} | ||
else | ||
{ | ||
var container = new Container(name, value); | ||
Module.CurrentModule.AddInitialStateOption(container); | ||
_containers.Add(container); | ||
} | ||
_containers.AddOrUpdate(name, value, (n, v) => v); | ||
} | ||
|
||
public void Clear() | ||
{ | ||
var list = _initialStateOptions(Module.CurrentModule); | ||
foreach (var container in _containers) | ||
list.Remove(container); | ||
_containers.Clear(); | ||
} | ||
|
||
private class Container : InitialStateOption | ||
{ | ||
public object Value { get; internal set; } | ||
|
||
public Container(string name, object value) : base(name, new TextObject(""), 1, () => { }, true) | ||
{ | ||
Value = value; | ||
} | ||
} | ||
private class ContainerWrapper : Container, IWrapper | ||
{ | ||
private static string? GetName(object @object) | ||
{ | ||
var propInfo = @object.GetType().GetProperty("Id"); | ||
return propInfo?.GetValue(@object) as string; | ||
} | ||
private static object? GetValue(object @object) | ||
{ | ||
var propInfo = @object.GetType().GetProperty("Value"); | ||
return propInfo?.GetValue(@object) as object; | ||
} | ||
|
||
public bool IsCorrect { get; } | ||
|
||
public ContainerWrapper(object @object) : base(GetName(@object) ?? "ERROR", GetValue(@object)) | ||
{ | ||
IsCorrect = Id != "ERROR" && @object.GetType().GetProperty("Value") != null; | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.