Skip to content

Commit fb894bf

Browse files
authored
Merge pull request #608 from ow-mods/dev
2.15.0 - Add SetText to 3, 4, and Input popups
2 parents cd109a2 + 2640abc commit fb894bf

File tree

8 files changed

+86
-15
lines changed

8 files changed

+86
-15
lines changed

src/OWML.Common/Interfaces/Menus/IOWMLFourChoicePopupMenu.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ public interface IOWMLFourChoicePopupMenu
99
event PopupCancelEvent OnPopupCancel;
1010

1111
void EnableMenu(bool value);
12+
void SetText(string message, string confirm1Text, string confirm2Text, string confirm3Text, string cancelText);
1213

1314
public event Menu.ActivateMenuEvent OnActivateMenu;
1415
public event Menu.DeactivateMenuEvent OnDeactivateMenu;

src/OWML.Common/Interfaces/Menus/IOWMLPopupInputMenu.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ public interface IOWMLPopupInputMenu
1919

2020
public void SetInputFieldPlaceholderText(string text);
2121

22+
public void SetText(string message, string placeholderMessage, string confirmText, string cancelText);
23+
2224
public event PopupMenu.PopupConfirmEvent OnPopupConfirm;
2325
public event Menu.ActivateMenuEvent OnActivateMenu;
2426
public event Menu.DeactivateMenuEvent OnDeactivateMenu;

src/OWML.Common/Interfaces/Menus/IOWMLThreeChoicePopupMenu.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ public interface IOWMLThreeChoicePopupMenu
1212
event PopupCancelEvent OnPopupCancel;
1313

1414
void EnableMenu(bool value);
15+
void SetText(string message, string confirm1Text, string confirm2Text, string cancelText);
1516

1617
public event Menu.ActivateMenuEvent OnActivateMenu;
1718
public event Menu.DeactivateMenuEvent OnDeactivateMenu;

src/OWML.Launcher/OWML.Manifest.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
"author": "Alek",
44
"name": "OWML",
55
"uniqueName": "Alek.OWML",
6-
"version": "2.14.1",
6+
"version": "2.15.0",
77
"minGameVersion": "1.1.15.1018",
88
"maxGameVersion": "1.1.15.1018"
99
}

src/OWML.ModHelper.Menus/CustomInputs/OWMLFourChoicePopupMenu.cs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,24 @@ public override Selectable GetSelectOnActivate()
4040
return _usingGamepad ? null : _selectOnActivate;
4141
}
4242

43+
public void SetText(string message, string confirm1Text, string confirm2Text, string confirm3Text, string cancelText)
44+
{
45+
var ok1prompt = _confirmButton1._screenPrompt == null ? null : new ScreenPrompt(_confirmButton1._screenPrompt._commandList[0], confirm1Text);
46+
var ok2prompt = _confirmButton2._screenPrompt == null ? null : new ScreenPrompt(_confirmButton2._screenPrompt._commandList[0], confirm2Text);
47+
var ok3prompt = _confirmButton3._screenPrompt == null ? null : new ScreenPrompt(_confirmButton3._screenPrompt._commandList[0], confirm3Text);
48+
var cancelprompt = _cancelButton._screenPrompt == null ? null : new ScreenPrompt(_cancelButton._screenPrompt._commandList[0], cancelText);
49+
SetUpPopup(
50+
message,
51+
_ok1Command,
52+
_ok2Command,
53+
_ok3Command,
54+
_cancelCommand,
55+
ok1prompt,
56+
ok2prompt,
57+
ok3prompt,
58+
cancelprompt);
59+
}
60+
4361
public virtual void SetUpPopup(
4462
string message,
4563
IInputCommands ok1Command,

src/OWML.ModHelper.Menus/CustomInputs/OWMLPopupInputMenu.cs

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ public class OWMLPopupInputMenu : PopupMenu, IOWMLPopupInputMenu
2020
[Obsolete("Use OnValidateChar instead.")]
2121
public event PopupInputMenu.InputPopupValidateCharEvent OnInputPopupValidateChar;
2222

23+
private bool _setCancelButtonActive;
24+
2325
public override void Awake()
2426
{
2527
base.Awake();
@@ -43,8 +45,25 @@ public override Selectable GetSelectOnActivate()
4345
return this._selectOnActivate;
4446
}
4547

48+
public void SetText(string message, string placeholderMessage, string confirmText, string cancelText)
49+
{
50+
var okPrompt = _confirmButton._screenPrompt == null ? null : new ScreenPrompt(_confirmButton._screenPrompt._commandList[0], confirmText);
51+
var cancelPrompt = _cancelButton._screenPrompt == null ? null : new ScreenPrompt(_cancelButton._screenPrompt._commandList[0], cancelText);
52+
SetUpPopup(
53+
message,
54+
_okCommand,
55+
_cancelCommand,
56+
okPrompt,
57+
cancelPrompt,
58+
_closeMenuOnOk,
59+
_setCancelButtonActive);
60+
SetInputFieldPlaceholderText(placeholderMessage);
61+
}
62+
4663
public override void SetUpPopup(string message, IInputCommands okCommand, IInputCommands cancelCommand, ScreenPrompt okPrompt, ScreenPrompt cancelPrompt, bool closeMenuOnOk = true, bool setCancelButtonActive = true)
4764
{
65+
_closeMenuOnOk = closeMenuOnOk;
66+
_setCancelButtonActive = setCancelButtonActive;
4867
base.SetUpPopup(message, okCommand, cancelCommand, okPrompt, cancelPrompt, closeMenuOnOk, setCancelButtonActive);
4968
this._selectOnActivate = this._inputField;
5069
}

src/OWML.ModHelper.Menus/CustomInputs/OWMLThreeChoicePopupMenu.cs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,21 @@ public override Selectable GetSelectOnActivate()
4040
return _usingGamepad ? null : _selectOnActivate;
4141
}
4242

43+
public void SetText(string message, string confirm1Text, string confirm2Text, string cancelText)
44+
{
45+
var ok1prompt = _confirmButton1._screenPrompt == null ? null : new ScreenPrompt(_confirmButton1._screenPrompt._commandList[0], confirm1Text);
46+
var ok2prompt = _confirmButton2._screenPrompt == null ? null : new ScreenPrompt(_confirmButton2._screenPrompt._commandList[0], confirm2Text);
47+
var cancelprompt = _cancelButton._screenPrompt == null ? null : new ScreenPrompt(_cancelButton._screenPrompt._commandList[0], cancelText);
48+
SetUpPopup(
49+
message,
50+
_ok1Command,
51+
_ok2Command,
52+
_cancelCommand,
53+
ok1prompt,
54+
ok2prompt,
55+
cancelprompt);
56+
}
57+
4358
public virtual void SetUpPopup(
4459
string message,
4560
IInputCommands ok1Command,

src/SampleMods/OWML.LoadCustomAssets/LoadCustomAssets.cs

Lines changed: 29 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
using OWML.ModHelper;
44
using UnityEngine.InputSystem;
55
using UnityEngine;
6-
using System.Linq;
6+
using OWML.Common.Interfaces.Menus;
77

88
namespace OWML.LoadCustomAssets
99
{
@@ -50,6 +50,9 @@ public void Start()
5050
ModHelper.MenuHelper.PopupMenuManager.RegisterStartupPopup("Test Startup Popup");
5151
}
5252

53+
public IOWMLFourChoicePopupMenu FourChoicePopupMenu;
54+
public IOWMLPopupInputMenu PopupInput;
55+
5356
public override void SetupTitleMenu(ITitleMenuManager titleManager)
5457
{
5558
var infoButton = titleManager.CreateTitleButton("INFO POPUP");
@@ -73,24 +76,24 @@ public override void SetupTitleMenu(ITitleMenuManager titleManager)
7376
threeChoicePopup.OnDeactivateMenu += () => ModHelper.Console.WriteLine("three popup deactivate");
7477

7578
var fourChoiceButton = titleManager.CreateTitleButton("FOUR CHOICE");
76-
var fourChoicePopup = ModHelper.MenuHelper.PopupMenuManager.CreateFourChoicePopup("test four choice popup", "oak", "oak (better)", "oak (worse)", "narp");
77-
fourChoiceButton.OnSubmitAction += () => fourChoicePopup.EnableMenu(true);
78-
fourChoicePopup.OnPopupConfirm1 += () => ModHelper.Console.WriteLine("Confirm 1");
79-
fourChoicePopup.OnPopupConfirm2 += () => ModHelper.Console.WriteLine("Confirm 2");
80-
fourChoicePopup.OnPopupConfirm3 += () => ModHelper.Console.WriteLine("Confirm 3");
81-
fourChoicePopup.OnActivateMenu += () => ModHelper.Console.WriteLine("four popup activate");
82-
fourChoicePopup.OnDeactivateMenu += () => ModHelper.Console.WriteLine("four popup deactivate");
79+
FourChoicePopupMenu = ModHelper.MenuHelper.PopupMenuManager.CreateFourChoicePopup("test four choice popup", "oak", "oak (better)", "oak (worse)", "narp");
80+
fourChoiceButton.OnSubmitAction += () => FourChoicePopupMenu.EnableMenu(true);
81+
FourChoicePopupMenu.OnPopupConfirm1 += () => ModHelper.Console.WriteLine("Confirm 1");
82+
FourChoicePopupMenu.OnPopupConfirm2 += () => ModHelper.Console.WriteLine("Confirm 2");
83+
FourChoicePopupMenu.OnPopupConfirm3 += () => ModHelper.Console.WriteLine("Confirm 3");
84+
FourChoicePopupMenu.OnActivateMenu += () => ModHelper.Console.WriteLine("four popup activate");
85+
FourChoicePopupMenu.OnDeactivateMenu += () => ModHelper.Console.WriteLine("four popup deactivate");
8386

8487
var textButton = titleManager.CreateTitleButton("INPUT POPUP TEST");
85-
var textPopup = ModHelper.MenuHelper.PopupMenuManager.CreateInputFieldPopup("test text popup", "type a funny thing!", "ok", "cancel");
86-
textButton.OnSubmitAction += () => textPopup.EnableMenu(true);
87-
textPopup.OnPopupConfirm += () =>
88+
PopupInput = ModHelper.MenuHelper.PopupMenuManager.CreateInputFieldPopup("test text popup", "type a funny thing!", "ok", "cancel");
89+
textButton.OnSubmitAction += () => PopupInput.EnableMenu(true);
90+
PopupInput.OnPopupConfirm += () =>
8891
{
89-
ModHelper.Console.WriteLine(textPopup.GetInputText());
92+
ModHelper.Console.WriteLine(PopupInput.GetInputText());
9093
};
9194

92-
textPopup.OnActivateMenu += () => ModHelper.Console.WriteLine("text popup activate");
93-
textPopup.OnDeactivateMenu += () => ModHelper.Console.WriteLine("text popup deactivate");
95+
PopupInput.OnActivateMenu += () => ModHelper.Console.WriteLine("text popup activate");
96+
PopupInput.OnDeactivateMenu += () => ModHelper.Console.WriteLine("text popup deactivate");
9497
}
9598

9699
public override void CleanupTitleMenu()
@@ -252,6 +255,18 @@ private void OnCompleteSceneChange(OWScene oldScene, OWScene newScene)
252255

253256
public void Update()
254257
{
258+
if (FourChoicePopupMenu != null)
259+
{
260+
var rnd = new System.Random();
261+
FourChoicePopupMenu.SetText("blah", rnd.Next().ToString(), rnd.Next().ToString(), rnd.Next().ToString(), rnd.Next().ToString());
262+
}
263+
264+
if (PopupInput != null)
265+
{
266+
var rnd = new System.Random();
267+
PopupInput.SetText("blah", rnd.Next().ToString(), rnd.Next().ToString(), rnd.Next().ToString());
268+
}
269+
255270
if (Keyboard.current[Key.F9].wasPressedThisFrame)
256271
{
257272
SendFatalMessage();

0 commit comments

Comments
 (0)