-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added CustomOptionButton. CustomOptionHeader is now a derived class of CustomOptionButton. Property CustomOption.LobbyTextScale has been renamed to HudTextScale. Property CustomOption.LobbyTextScroller has been renamed to HudTextScroller. Property CustomOption.ClearDefaultLobbyText has been renamed to ClearDefaultHudText. Added CustomOption.DefaultNameStringFormat, DefaultValueStringFormat and DefaultHudStringFormat. Property CustomOption.StringFormat has been renamed to ValueStringFormat. Property CustomOption.ToStringFormat has been renamed to HudStringFormat. Protected method CustomOption.GameOptionCreated now returns bool, returning false will destroy the object that was created. Significantly reduced CustomOption RPC size. CustomOption values sent during RpcSyncSettings will now be sent one by one, immediately. CustomStringOption.Values now returns a readonly collection. CustomToggleOption will now also appear in the options menu for players who aren't the host. Updated environment variables. Updated OxygenFilter. Added readme with installation, development and building instructions.
- Loading branch information
1 parent
0e76484
commit e2cbdb5
Showing
11 changed files
with
270 additions
and
97 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,104 @@ | ||
using Essentials.Extensions; | ||
using System; | ||
|
||
namespace Essentials.Options | ||
{ | ||
/// <summary> | ||
/// A derivative of <see cref="CustomOption"/>, handling "buttons" in the options menu. | ||
/// </summary> | ||
public class CustomOptionButton : CustomOption, IToggleOption | ||
{ | ||
public override bool SendRpc { get { return false; } } | ||
|
||
/// <summary> | ||
/// Adds an option header. | ||
/// </summary> | ||
/// <param name="title">The title of the header</param> | ||
/// <param name="menu">The button will be visible in the lobby options menu</param> | ||
/// <param name="hud">The button title will appear in the HUD (option list) in the lobby</param> | ||
/// <param name="initialValue">The button's initial (client sided) value, can be used to hide/show other options</param> | ||
public CustomOptionButton(string title, bool menu = true, bool hud = false, bool initialValue = false) : base(title, title, false, CustomOptionType.Toggle, initialValue) | ||
{ | ||
HudStringFormat = (_, name, _) => name; | ||
|
||
MenuVisible = menu; | ||
HudVisible = hud; | ||
} | ||
|
||
protected override bool GameOptionCreated(OptionBehaviour o) | ||
{ | ||
if (o is ToggleOption toggle) | ||
{ | ||
toggle.TitleText.Text = GetFormattedName(); | ||
|
||
toggle.CheckMark.enabled = toggle.oldValue = false; | ||
|
||
toggle.transform.FindChild("CheckBox")?.gameObject?.SetActive(false); | ||
|
||
return true; | ||
} | ||
else if (o is StringOption str) // Display options in menu for non-host | ||
{ | ||
str.TitleText.Text = GetFormattedName(); | ||
|
||
str.Value = str.oldValue = 0; | ||
|
||
str.ValueText.Text = GetFormattedValue(); | ||
|
||
return true; | ||
} | ||
|
||
return false; | ||
} | ||
|
||
/// <summary> | ||
/// Toggles the option value (called when the button is pressed). | ||
/// </summary> | ||
public virtual void Toggle() | ||
{ | ||
SetValue(!GetValue()); | ||
} | ||
|
||
/// <summary> | ||
/// Sets a new value | ||
/// </summary> | ||
/// <param name="value">The new value</param> | ||
public virtual void SetValue(bool value) | ||
{ | ||
SetValue(value, true); | ||
} | ||
|
||
/// <returns>The boolean-casted default value.</returns> | ||
public virtual bool GetDefaultValue() | ||
{ | ||
return GetDefaultValue<bool>(); | ||
} | ||
|
||
/// <returns>The boolean-casted old value.</returns> | ||
public virtual bool GetOldValue() | ||
{ | ||
return GetOldValue<bool>(); | ||
} | ||
|
||
/// <returns>The boolean-casted current value.</returns> | ||
public virtual bool GetValue() | ||
{ | ||
return GetValue<bool>(); | ||
} | ||
} | ||
|
||
public partial class CustomOption | ||
{ | ||
/// <summary> | ||
/// Adds a "button" in the options menu. | ||
/// </summary> | ||
/// <param name="title">The title of the button</param> | ||
/// <param name="menu">The button will be visible in the lobby options menu</param> | ||
/// <param name="hud">The button title will appear in the HUD (option list) in the lobby</param> | ||
/// <param name="initialValue">The button's initial (client sided) value, can be used to hide/show other options</param> | ||
public static CustomOptionButton AddButton(string title, bool menu = true, bool hud = false, bool initialValue = false) | ||
{ | ||
return new CustomOptionButton(title, menu, hud, initialValue); | ||
} | ||
} | ||
} |
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
Oops, something went wrong.