Skip to content

Commit

Permalink
Merge pull request #597 from ow-mods/dev
Browse files Browse the repository at this point in the history
2.14.0
  • Loading branch information
misternebula authored Oct 11, 2024
2 parents 7e5505b + 78f39b5 commit 43024f6
Show file tree
Hide file tree
Showing 12 changed files with 185 additions and 41 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ jobs:
- name: pack
run: dotnet pack -o . src\OWML.ModHelper\OWML.ModHelper.csproj -p:NuspecFile=OWML.ModHelper.nuspec -p:NuspecProperties="version=${{ steps.version.outputs.prop }};"
- name: upload nuget
uses: actions/upload-artifact@v2
uses: actions/upload-artifact@v4
with:
name: owml-nuget
path: OWML.*.nupkg
Expand All @@ -67,7 +67,7 @@ jobs:
mkdir Mods
7z a OWML.zip *
- name: upload zip
uses: actions/upload-artifact@v2
uses: actions/upload-artifact@v4
with:
name: owml-zip
path: src\OWML.Launcher\bin\Debug\net48\OWML.zip
Expand Down
2 changes: 1 addition & 1 deletion src/OWML.Abstractions/GameObjectHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,6 @@ public TBehaviour CreateAndAdd<TBehaviour>(string name = null) =>
CreateAndAdd<TBehaviour>(typeof(TBehaviour), name);

public TBehaviour CreateAndAdd<TBehaviour>(Type type, string name = null) =>
(TBehaviour)(object)new GameObject(name).AddComponent(type);
(TBehaviour)(object)new GameObject(name ?? type.Name).AddComponent(type);
}
}
6 changes: 6 additions & 0 deletions src/OWML.Common/Interfaces/Menus/IMenuManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,11 @@ public interface IMenuManager
public IPopupMenuManager PopupMenuManager { get; }

internal IList<IModBehaviour> ModList { get; set; }

/// <summary>
/// Keeps the Mod Options tab open, since it is ephemeral.
/// Otherwise, a popup opening in the tab would close it.
/// </summary>
public void ForceModOptionsOpen(bool force);
}
}
7 changes: 6 additions & 1 deletion src/OWML.Common/Interfaces/Menus/IOWMLPopupInputMenu.cs
Original file line number Diff line number Diff line change
@@ -1,11 +1,16 @@
using UnityEngine.UI;
using System;
using UnityEngine.UI;

namespace OWML.Common.Interfaces.Menus
{
public interface IOWMLPopupInputMenu
{
[Obsolete("Use OnValidateChar instead.")]
public event PopupInputMenu.InputPopupValidateCharEvent OnInputPopupValidateChar;

public delegate bool InputPopupValidateCharEvent(string input, int charIndex, char addedChar);
public event InputPopupValidateCharEvent OnValidateChar;

public void EnableMenu(bool value);

public string GetInputText();
Expand Down
10 changes: 10 additions & 0 deletions src/OWML.Common/Interfaces/Menus/IOWMLTextEntryElement.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,15 @@ public interface IOWMLTextEntryElement : IOWMLMenuValueOption
public event TextEntryConfirmEvent OnConfirmEntry;

public string GetInputText();

/// <summary>
/// Sets the text that is displayed without updating the underlying option value.
/// </summary>
public void SetText(string text);

/// <summary>
/// Sets the underlying option value to the text, and updates the displayed text.
/// </summary>
public void SetCurrentValue(string text);
}
}
2 changes: 1 addition & 1 deletion src/OWML.Launcher/OWML.Manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"author": "Alek",
"name": "OWML",
"uniqueName": "Alek.OWML",
"version": "2.13.0",
"version": "2.14.0",
"minGameVersion": "1.1.15.1018",
"maxGameVersion": "1.1.15.1018"
}
29 changes: 22 additions & 7 deletions src/OWML.ModHelper.Menus/CustomInputs/OWMLPopupInputMenu.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@ public class OWMLPopupInputMenu : PopupMenu, IOWMLPopupInputMenu
protected bool _virtualKeyboardOpen;

public event PopupInputMenu.InputPopupTextChangedEvent OnInputPopupTextChanged;
public event IOWMLPopupInputMenu.InputPopupValidateCharEvent OnValidateChar;

[Obsolete("Use OnValidateChar instead.")]
public event PopupInputMenu.InputPopupValidateCharEvent OnInputPopupValidateChar;

public override void Awake()
Expand Down Expand Up @@ -152,20 +155,32 @@ private void OnTextFieldChanged()

private char OnValidateInput(string input, int charIndex, char addedChar)
{
bool flag = true;
if (this.OnInputPopupValidateChar != null)
var isValidCharacter = true;
if (OnInputPopupValidateChar != null)
{
var invocationList = OnInputPopupValidateChar.GetInvocationList();
for (var i = 0; i < invocationList.Length; i++)
{
var flag2 = (bool)invocationList[i].DynamicInvoke(new object[] { addedChar });
isValidCharacter = isValidCharacter && flag2;
}
}

if (OnValidateChar != null && isValidCharacter)
{
Delegate[] invocationList = this.OnInputPopupValidateChar.GetInvocationList();
for (int i = 0; i < invocationList.Length; i++)
var invocationList = OnValidateChar.GetInvocationList();
for (var i = 0; i < invocationList.Length; i++)
{
bool flag2 = (bool)invocationList[i].DynamicInvoke(new object[] { addedChar });
flag = flag && flag2;
var flag2 = (bool)invocationList[i].DynamicInvoke(new object[] { input, charIndex, addedChar });
isValidCharacter = isValidCharacter && flag2;
}
}
if (flag)

if (isValidCharacter)
{
return addedChar;
}

return '\0';
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,14 @@ public string GetInputText()
return _popup.GetInputText();
}

public void SetCurrentValue(string text)
public void SetText(string text)
{
gameObject.GetComponentsInChildren<MenuOption>().First(x => x != this)._label.text = text;
}

public void SetCurrentValue(string text)
{
SetText(text);
_popup.GetInputField().text = text;
OnConfirmEntry();
}
Expand Down
2 changes: 1 addition & 1 deletion src/OWML.ModHelper.Menus/ModInputMenu.cs
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ private bool OnValidateNumber() =>
float.TryParse(_inputMenu.GetInputText(), out _);

private bool OnValidateCharNumber(char c) =>
"0123456789.".Contains("" + c);
"0123456789.-".Contains(c.ToString());

protected override void OnPopupConfirm()
{
Expand Down
33 changes: 30 additions & 3 deletions src/OWML.ModHelper.Menus/NewMenuSystem/MenuManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ enum SettingType
internal static List<(IModBehaviour behaviour, Menu modMenu)> ModSettingsMenus = new();

private bool _hasSetupMenusThisScene = false;
private bool _forceModOptionsOpen;

public MenuManager(
IModConsole console,
Expand All @@ -52,7 +53,7 @@ public MenuManager(
_unityEvents = unityEvents;
TitleMenuManager = new TitleMenuManager();
PopupMenuManager = new PopupMenuManager(console, harmony, this);
OptionsMenuManager = new OptionsMenuManager(console, unityEvents, PopupMenuManager);
OptionsMenuManager = new OptionsMenuManager(console, unityEvents, PopupMenuManager, this);
PauseMenuManager = new PauseMenuManager(console);

var harmonyInstance = harmony.GetValue<Harmony>("_harmony");
Expand Down Expand Up @@ -85,6 +86,11 @@ public MenuManager(
};
}

public void ForceModOptionsOpen(bool force)
{
_forceModOptionsOpen = force;
}

internal void SetupMenus(IList<IModBehaviour> modList)
{
if (_hasSetupMenusThisScene)
Expand All @@ -103,8 +109,8 @@ void SaveConfig()

// Create menus and submenus
var (modsMenu, modsMenuButton) = OptionsMenuManager.CreateTabWithSubTabs("MODS");
var (owmlSubTab, owmlSubTabButton) = OptionsMenuManager.AddSubTab(modsMenu, "OWML");
var (modsSubTab, modsSubTabButton) = OptionsMenuManager.AddSubTab(modsMenu, "MODS");
var (owmlSubTab, owmlSubTabButton) = OptionsMenuManager.AddSubTab(modsMenu, "OWML");

OWMLSettingsMenu = owmlSubTab;

Expand Down Expand Up @@ -210,7 +216,20 @@ void SaveConfig()

newModTab.OnDeactivateMenu += () =>
{
OptionsMenuManager.RemoveTab(newModTab);
if (_forceModOptionsOpen)
{
return;
}

// Fixes tab dissapearing when you click on it again
// Clicking on a tab closes and opens it again
_unityEvents.FireOnNextUpdate(() =>
{
if (!newModTab._isActivated)
{
OptionsMenuManager.RemoveTab(newModTab);
}
});
};

foreach (var (name, setting) in mod.ModHelper.Config.Settings)
Expand Down Expand Up @@ -307,6 +326,7 @@ void SaveConfig()
mod.ModHelper.Config.SetSettingsValue(name, newValue);
mod.ModHelper.Storage.Save(mod.ModHelper.Config, Constants.ModConfigFileName);
mod.Configure(mod.ModHelper.Config);
textInput.SetText(newValue);
};
break;
case SettingType.NUMBER:
Expand All @@ -319,6 +339,7 @@ void SaveConfig()
mod.ModHelper.Config.SetSettingsValue(name, newValue);
mod.ModHelper.Storage.Save(mod.ModHelper.Config, Constants.ModConfigFileName);
mod.Configure(mod.ModHelper.Config);
numberInput.SetText(newValue.ToString());
};
break;
default:
Expand Down Expand Up @@ -387,6 +408,12 @@ private void EditExistingMenus()
{
var text = item.GetComponent<UIStyleApplier>()._textItems[0];
text.horizontalOverflow = HorizontalWrapMode.Wrap;

// Give a little bit of margin to account for the dividing lines
// (as otherwise it can look like the text is on top of them when in mouse mode)
float margin = 0.03f;
text.rectTransform.anchorMin = new Vector2(margin, 0.0f);
text.rectTransform.anchorMax = new Vector2(1f - margin, 1.0f);
}
}

Expand Down
Loading

0 comments on commit 43024f6

Please sign in to comment.