Skip to content

Commit

Permalink
Merge pull request #608 from ow-mods/dev
Browse files Browse the repository at this point in the history
2.15.0 - Add SetText to 3, 4, and Input popups
  • Loading branch information
misternebula authored Feb 13, 2025
2 parents cd109a2 + 2640abc commit fb894bf
Show file tree
Hide file tree
Showing 8 changed files with 86 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ public interface IOWMLFourChoicePopupMenu
event PopupCancelEvent OnPopupCancel;

void EnableMenu(bool value);
void SetText(string message, string confirm1Text, string confirm2Text, string confirm3Text, string cancelText);

public event Menu.ActivateMenuEvent OnActivateMenu;
public event Menu.DeactivateMenuEvent OnDeactivateMenu;
Expand Down
2 changes: 2 additions & 0 deletions src/OWML.Common/Interfaces/Menus/IOWMLPopupInputMenu.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ public interface IOWMLPopupInputMenu

public void SetInputFieldPlaceholderText(string text);

public void SetText(string message, string placeholderMessage, string confirmText, string cancelText);

public event PopupMenu.PopupConfirmEvent OnPopupConfirm;
public event Menu.ActivateMenuEvent OnActivateMenu;
public event Menu.DeactivateMenuEvent OnDeactivateMenu;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ public interface IOWMLThreeChoicePopupMenu
event PopupCancelEvent OnPopupCancel;

void EnableMenu(bool value);
void SetText(string message, string confirm1Text, string confirm2Text, string cancelText);

public event Menu.ActivateMenuEvent OnActivateMenu;
public event Menu.DeactivateMenuEvent OnDeactivateMenu;
Expand Down
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.14.1",
"version": "2.15.0",
"minGameVersion": "1.1.15.1018",
"maxGameVersion": "1.1.15.1018"
}
18 changes: 18 additions & 0 deletions src/OWML.ModHelper.Menus/CustomInputs/OWMLFourChoicePopupMenu.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,24 @@ public override Selectable GetSelectOnActivate()
return _usingGamepad ? null : _selectOnActivate;
}

public void SetText(string message, string confirm1Text, string confirm2Text, string confirm3Text, string cancelText)
{
var ok1prompt = _confirmButton1._screenPrompt == null ? null : new ScreenPrompt(_confirmButton1._screenPrompt._commandList[0], confirm1Text);
var ok2prompt = _confirmButton2._screenPrompt == null ? null : new ScreenPrompt(_confirmButton2._screenPrompt._commandList[0], confirm2Text);
var ok3prompt = _confirmButton3._screenPrompt == null ? null : new ScreenPrompt(_confirmButton3._screenPrompt._commandList[0], confirm3Text);
var cancelprompt = _cancelButton._screenPrompt == null ? null : new ScreenPrompt(_cancelButton._screenPrompt._commandList[0], cancelText);
SetUpPopup(
message,
_ok1Command,
_ok2Command,
_ok3Command,
_cancelCommand,
ok1prompt,
ok2prompt,
ok3prompt,
cancelprompt);
}

public virtual void SetUpPopup(
string message,
IInputCommands ok1Command,
Expand Down
19 changes: 19 additions & 0 deletions src/OWML.ModHelper.Menus/CustomInputs/OWMLPopupInputMenu.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ public class OWMLPopupInputMenu : PopupMenu, IOWMLPopupInputMenu
[Obsolete("Use OnValidateChar instead.")]
public event PopupInputMenu.InputPopupValidateCharEvent OnInputPopupValidateChar;

private bool _setCancelButtonActive;

public override void Awake()
{
base.Awake();
Expand All @@ -43,8 +45,25 @@ public override Selectable GetSelectOnActivate()
return this._selectOnActivate;
}

public void SetText(string message, string placeholderMessage, string confirmText, string cancelText)
{
var okPrompt = _confirmButton._screenPrompt == null ? null : new ScreenPrompt(_confirmButton._screenPrompt._commandList[0], confirmText);
var cancelPrompt = _cancelButton._screenPrompt == null ? null : new ScreenPrompt(_cancelButton._screenPrompt._commandList[0], cancelText);
SetUpPopup(
message,
_okCommand,
_cancelCommand,
okPrompt,
cancelPrompt,
_closeMenuOnOk,
_setCancelButtonActive);
SetInputFieldPlaceholderText(placeholderMessage);
}

public override void SetUpPopup(string message, IInputCommands okCommand, IInputCommands cancelCommand, ScreenPrompt okPrompt, ScreenPrompt cancelPrompt, bool closeMenuOnOk = true, bool setCancelButtonActive = true)
{
_closeMenuOnOk = closeMenuOnOk;
_setCancelButtonActive = setCancelButtonActive;
base.SetUpPopup(message, okCommand, cancelCommand, okPrompt, cancelPrompt, closeMenuOnOk, setCancelButtonActive);
this._selectOnActivate = this._inputField;
}
Expand Down
15 changes: 15 additions & 0 deletions src/OWML.ModHelper.Menus/CustomInputs/OWMLThreeChoicePopupMenu.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,21 @@ public override Selectable GetSelectOnActivate()
return _usingGamepad ? null : _selectOnActivate;
}

public void SetText(string message, string confirm1Text, string confirm2Text, string cancelText)
{
var ok1prompt = _confirmButton1._screenPrompt == null ? null : new ScreenPrompt(_confirmButton1._screenPrompt._commandList[0], confirm1Text);
var ok2prompt = _confirmButton2._screenPrompt == null ? null : new ScreenPrompt(_confirmButton2._screenPrompt._commandList[0], confirm2Text);
var cancelprompt = _cancelButton._screenPrompt == null ? null : new ScreenPrompt(_cancelButton._screenPrompt._commandList[0], cancelText);
SetUpPopup(
message,
_ok1Command,
_ok2Command,
_cancelCommand,
ok1prompt,
ok2prompt,
cancelprompt);
}

public virtual void SetUpPopup(
string message,
IInputCommands ok1Command,
Expand Down
43 changes: 29 additions & 14 deletions src/SampleMods/OWML.LoadCustomAssets/LoadCustomAssets.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
using OWML.ModHelper;
using UnityEngine.InputSystem;
using UnityEngine;
using System.Linq;
using OWML.Common.Interfaces.Menus;

namespace OWML.LoadCustomAssets
{
Expand Down Expand Up @@ -50,6 +50,9 @@ public void Start()
ModHelper.MenuHelper.PopupMenuManager.RegisterStartupPopup("Test Startup Popup");
}

public IOWMLFourChoicePopupMenu FourChoicePopupMenu;
public IOWMLPopupInputMenu PopupInput;

public override void SetupTitleMenu(ITitleMenuManager titleManager)
{
var infoButton = titleManager.CreateTitleButton("INFO POPUP");
Expand All @@ -73,24 +76,24 @@ public override void SetupTitleMenu(ITitleMenuManager titleManager)
threeChoicePopup.OnDeactivateMenu += () => ModHelper.Console.WriteLine("three popup deactivate");

var fourChoiceButton = titleManager.CreateTitleButton("FOUR CHOICE");
var fourChoicePopup = ModHelper.MenuHelper.PopupMenuManager.CreateFourChoicePopup("test four choice popup", "oak", "oak (better)", "oak (worse)", "narp");
fourChoiceButton.OnSubmitAction += () => fourChoicePopup.EnableMenu(true);
fourChoicePopup.OnPopupConfirm1 += () => ModHelper.Console.WriteLine("Confirm 1");
fourChoicePopup.OnPopupConfirm2 += () => ModHelper.Console.WriteLine("Confirm 2");
fourChoicePopup.OnPopupConfirm3 += () => ModHelper.Console.WriteLine("Confirm 3");
fourChoicePopup.OnActivateMenu += () => ModHelper.Console.WriteLine("four popup activate");
fourChoicePopup.OnDeactivateMenu += () => ModHelper.Console.WriteLine("four popup deactivate");
FourChoicePopupMenu = ModHelper.MenuHelper.PopupMenuManager.CreateFourChoicePopup("test four choice popup", "oak", "oak (better)", "oak (worse)", "narp");
fourChoiceButton.OnSubmitAction += () => FourChoicePopupMenu.EnableMenu(true);
FourChoicePopupMenu.OnPopupConfirm1 += () => ModHelper.Console.WriteLine("Confirm 1");
FourChoicePopupMenu.OnPopupConfirm2 += () => ModHelper.Console.WriteLine("Confirm 2");
FourChoicePopupMenu.OnPopupConfirm3 += () => ModHelper.Console.WriteLine("Confirm 3");
FourChoicePopupMenu.OnActivateMenu += () => ModHelper.Console.WriteLine("four popup activate");
FourChoicePopupMenu.OnDeactivateMenu += () => ModHelper.Console.WriteLine("four popup deactivate");

var textButton = titleManager.CreateTitleButton("INPUT POPUP TEST");
var textPopup = ModHelper.MenuHelper.PopupMenuManager.CreateInputFieldPopup("test text popup", "type a funny thing!", "ok", "cancel");
textButton.OnSubmitAction += () => textPopup.EnableMenu(true);
textPopup.OnPopupConfirm += () =>
PopupInput = ModHelper.MenuHelper.PopupMenuManager.CreateInputFieldPopup("test text popup", "type a funny thing!", "ok", "cancel");
textButton.OnSubmitAction += () => PopupInput.EnableMenu(true);
PopupInput.OnPopupConfirm += () =>
{
ModHelper.Console.WriteLine(textPopup.GetInputText());
ModHelper.Console.WriteLine(PopupInput.GetInputText());
};

textPopup.OnActivateMenu += () => ModHelper.Console.WriteLine("text popup activate");
textPopup.OnDeactivateMenu += () => ModHelper.Console.WriteLine("text popup deactivate");
PopupInput.OnActivateMenu += () => ModHelper.Console.WriteLine("text popup activate");
PopupInput.OnDeactivateMenu += () => ModHelper.Console.WriteLine("text popup deactivate");
}

public override void CleanupTitleMenu()
Expand Down Expand Up @@ -252,6 +255,18 @@ private void OnCompleteSceneChange(OWScene oldScene, OWScene newScene)

public void Update()
{
if (FourChoicePopupMenu != null)
{
var rnd = new System.Random();
FourChoicePopupMenu.SetText("blah", rnd.Next().ToString(), rnd.Next().ToString(), rnd.Next().ToString(), rnd.Next().ToString());
}

if (PopupInput != null)
{
var rnd = new System.Random();
PopupInput.SetText("blah", rnd.Next().ToString(), rnd.Next().ToString(), rnd.Next().ToString());
}

if (Keyboard.current[Key.F9].wasPressedThisFrame)
{
SendFatalMessage();
Expand Down

0 comments on commit fb894bf

Please sign in to comment.