Skip to content

Commit

Permalink
made pausemenu checkbox toggle tricksaber globally
Browse files Browse the repository at this point in the history
  • Loading branch information
ToniMacaroni committed May 23, 2020
1 parent fc5cbfe commit b235bbc
Show file tree
Hide file tree
Showing 9 changed files with 45 additions and 36 deletions.
24 changes: 10 additions & 14 deletions TrickSaber/GameplayManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,23 +37,19 @@ public static void OnGameSceneLoaded()
public static void CreateCheckbox()
{
var canvas = GameObject.Find("Wrapper/PauseMenu/Wrapper/UI/Canvas").GetComponent<Canvas>();
GameObject go = Resources.FindObjectsOfTypeAll<GameObject>().FirstOrDefault(res => res.name == "Toggle");
go = Object.Instantiate(go, canvas.transform, false);
Object.Destroy(go.GetComponentInChildren<LocalizedTextMeshProUGUI>());
RectTransform rect = go.transform as RectTransform;
if (!canvas) return;

GameObject toggleObject = Resources.FindObjectsOfTypeAll<GameObject>().FirstOrDefault(res => res.name == "Toggle");
toggleObject = Object.Instantiate(toggleObject, canvas.transform, false);
Object.Destroy(toggleObject.GetComponentInChildren<LocalizedTextMeshProUGUI>());
RectTransform rect = toggleObject.transform as RectTransform;
rect.anchorMin = new Vector2(0.5f, 0.5f);
rect.anchorMax = new Vector2(0.5f, 0.5f);
rect.anchoredPosition = new Vector2(40, 35);
go.GetComponentInChildren<TextMeshProUGUI>().text = "Tricksaber Enabled";
var toggle = go.GetComponentInChildren<Toggle>();
toggle.isOn = true;
toggle.onValueChanged.AddListener(enabled =>
{
if (GlobalTrickManager.Instance)
{
GlobalTrickManager.Instance.Enabled = enabled;
}
});
toggleObject.GetComponentInChildren<TextMeshProUGUI>().text = "Tricksaber Enabled";
var toggle = toggleObject.GetComponentInChildren<Toggle>();
toggle.isOn = PluginConfig.Instance.TrickSaberEnabled;
toggle.onValueChanged.AddListener(enabled => { PluginConfig.Instance.TrickSaberEnabled = enabled; });
}
}
}
7 changes: 6 additions & 1 deletion TrickSaber/GlobalTrickManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,14 @@ public AudioSource AudioSource

public bool Enabled
{
get => LeftSaberSaberTrickManager.Enabled || RightSaberSaberTrickManager.Enabled;
get
{
if (!LeftSaberSaberTrickManager || !RightSaberSaberTrickManager) return false;
return LeftSaberSaberTrickManager.Enabled || RightSaberSaberTrickManager.Enabled;
}
set
{
if (!LeftSaberSaberTrickManager || !RightSaberSaberTrickManager) return;
LeftSaberSaberTrickManager.Enabled = value;
RightSaberSaberTrickManager.Enabled = value;
}
Expand Down
2 changes: 2 additions & 0 deletions TrickSaber/PluginConfig.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ public class PluginConfig
{
public static PluginConfig Instance { get; set; }

public bool TrickSaberEnabled { get; set; } = true;

public string TriggerAction { get; set; } = TrickAction.Throw.ToString();
public string GripAction { get; set; } = TrickAction.None.ToString();
public string ThumbstickAction { get; set; } = TrickAction.Spin.ToString();
Expand Down
4 changes: 2 additions & 2 deletions TrickSaber/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,5 @@
[assembly: AssemblyCulture("")]
[assembly: ComVisible(false)]
[assembly: Guid("9246546f-bdae-4371-8252-513e78a8791f")]
[assembly: AssemblyVersion("0.3.0.0")]
[assembly: AssemblyFileVersion("0.3.0.0")]
[assembly: AssemblyVersion("0.3.1.0")]
[assembly: AssemblyFileVersion("0.3.1.0")]
10 changes: 8 additions & 2 deletions TrickSaber/SaberTrickManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,7 @@ private void OnTrickDeactivated(TrickAction trickAction)

private void OnTrickActivated(TrickAction trickAction, float val)
{
if (!Enabled) return;
if (!GlobalTrickManager.Instance.CanDoTrick()) return;
if (!CanDoTrick()) return;
var trick = Tricks[trickAction];
trick.Value = val;
if (trick.State != TrickState.Inactive) return;
Expand Down Expand Up @@ -141,5 +140,12 @@ public bool IsDoingTrick()

return false;
}

private bool CanDoTrick()
{
return PluginConfig.Instance.TrickSaberEnabled &&
Enabled &&
GlobalTrickManager.Instance.CanDoTrick();
}
}
}
18 changes: 9 additions & 9 deletions TrickSaber/UI/TrickSaberFlowCoordinator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,17 @@ namespace TrickSaber.UI
{
internal class TrickSaberFlowCoordinator : FlowCoordinator
{
private BindingsViewController bindingsViewController;
private MiscViewController miscViewController;
private ThresholdViewController thresholdViewController;
private BindingsViewController _bindingsViewController;
private MiscViewController _miscViewController;
private ThresholdViewController _thresholdViewController;

public void Awake()
{
if (!bindingsViewController)
bindingsViewController = BeatSaberUI.CreateViewController<BindingsViewController>();
if (!thresholdViewController)
thresholdViewController = BeatSaberUI.CreateViewController<ThresholdViewController>();
if (!miscViewController) miscViewController = BeatSaberUI.CreateViewController<MiscViewController>();
if (!_bindingsViewController)
_bindingsViewController = BeatSaberUI.CreateViewController<BindingsViewController>();
if (!_thresholdViewController)
_thresholdViewController = BeatSaberUI.CreateViewController<ThresholdViewController>();
if (!_miscViewController) _miscViewController = BeatSaberUI.CreateViewController<MiscViewController>();
}

protected override void DidActivate(bool firstActivation, ActivationType activationType)
Expand All @@ -28,7 +28,7 @@ protected override void DidActivate(bool firstActivation, ActivationType activat
{
title = "Trick Settings";
showBackButton = true;
ProvideInitialViewControllers(bindingsViewController, miscViewController, thresholdViewController);
ProvideInitialViewControllers(_bindingsViewController, _miscViewController, _thresholdViewController);
}
}
catch (Exception e)
Expand Down
4 changes: 2 additions & 2 deletions TrickSaber/ViewControllers/MiscViewController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -87,8 +87,8 @@ public bool EnableCutting
[UIAction("#post-parse")]
public void Setup()
{
//_scrollable = BSMLScrollableSettingsContainer
if (_scrollable)
//align the scrollable, so it uses the whole screen
if (_scrollable && _scrollable.name == "BSMLScrollableSettingsContainer")
{
var rect = _scrollable as RectTransform;
rect.anchoredPosition = new Vector2(0, 0);
Expand Down
6 changes: 3 additions & 3 deletions TrickSaber/Views/BindingsView.bsml
Original file line number Diff line number Diff line change
Expand Up @@ -26,15 +26,15 @@
<vertical ignore-layout='true' pad-top='20' spacing='0.7'
child-control-height='false' child-expand-height='false'>
<horizontal horizontal-fit='PreferredSize' spacing='10'>
<list-setting preferred-width='70' text='Trigger action' value='TriggerAction-value' options='TrickActionEnum-list' apply-on-change='true' hover-hint='What happens on trigger press'/>
<list-setting preferred-width='80' text='Trigger action' value='TriggerAction-value' options='TrickActionEnum-list' apply-on-change='true' hover-hint='What happens on trigger press'/>
<checkbox-setting preferred-width='20' text='Reverse' value='ReverseTrigger-value' apply-on-change='true' hover-hint='Activate action when input is released rather than pressed' />
</horizontal>
<horizontal horizontal-fit='PreferredSize' spacing='10'>
<list-setting preferred-width='70' text='Grip action' value='GripAction-value' options='TrickActionEnum-list' apply-on-change='true' hover-hint='What happens on grip press'/>
<list-setting preferred-width='80' text='Grip action' value='GripAction-value' options='TrickActionEnum-list' apply-on-change='true' hover-hint='What happens on grip press'/>
<checkbox-setting preferred-width='20' text='Reverse' value='ReverseGrip-value' apply-on-change='true' hover-hint='Activate action when input is released rather than pressed' />
</horizontal>
<horizontal horizontal-fit='PreferredSize' spacing='10'>
<list-setting preferred-width='70' text='Thumbstick action' value='ThumbAction-value' options='TrickActionEnum-list' apply-on-change='true' hover-hint='What happens on thumbstick move'/>
<list-setting preferred-width='80' text='Thumbstick action' value='ThumbAction-value' options='TrickActionEnum-list' apply-on-change='true' hover-hint='What happens on thumbstick move'/>
<checkbox-setting preferred-width='20' text='Reverse' value='ReverseThumbstick-value' apply-on-change='true' hover-hint='Activate action when input is released rather than pressed' />
</horizontal>
<horizontal preferred-width='50' pad-left='9' pad-right='9' pad-top='4' pad-bottom='4' bg='round-rect-panel' active='~ShowIndexText'>
Expand Down
6 changes: 3 additions & 3 deletions TrickSaber/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@
"$schema": "https://raw.githubusercontent.com/beat-saber-modding-group/BSIPA-MetadataFileSchema/master/Schema.json",
"author": "Toni Macaroni",
"description": "A BeatSaber mod for performing tricks",
"gameVersion": "1.9.0",
"gameVersion": "1.9.1",
"id": "TrickSaber",
"name": "TrickSaber",
"version": "0.3.0",
"version": "0.3.1",
"dependsOn": {
"BS Utils": "^1.4.9",
"BeatSaberMarkupLanguage": "^1.3.1"
"BeatSaberMarkupLanguage": "^1.3.2"
},
"links": {
"project-source": "https://github.com/ToniMacaroni/TrickSaber"
Expand Down

0 comments on commit b235bbc

Please sign in to comment.