HeavenStudioPlus/Assets/Scripts/UI/SettingsDialog/Tabs/ControllerSettings.cs
Rapandrasmus 98835c3936
Title Screen (#454)
* Barebones title screen prefab added

* logo and stuff

* cool

* Added sfx to title screen

* The logo now bops to the beat

* epic reveal

* Fixed something

* put some of the stuff into the main menu

* other logo bop

* Implemented logobop2 and starbop

* added scrolling bg, tweaked positioning and wip splash text for play button

* more menu

* ooops

* Expand implemented

* cool

* Made stars spawn in in the opening

* make UI elements look nicer on different aspect ratios

* add sound while hovering over logo

* add settings menu to title screen

make the title screen properly play after the opening

* swap out title screen hover sound

remove the old config path warning

* every button works, some play mode fixes

* fix issues with beataction/multisound and pausing

* fix dropdown menus not working in certain screens

* fix particles rotating when camera controls are used

* touch style pause menu items only trigger if cursor is over an item

* various changes

make playback (unpausing) more reliable
only apply changes to advanced audio settings on launch
fix title screen visuals
add opening music
continue past opening by pressing a key
update credits

* almost forgot this

* lol

* initial flow mems

* user-taggable fonts in textboxes

* alt materials for kurokane

* assets prep

* plan out judgement screen layout

change sound encodings

* start sequencing judgement

* judgement screen sequence

* full game loop

* fix major issue with pooled sound objects

rebalance ranking audio
fix issues with some effects in play mode

* new graphics

* particles

* make certain uses of the beat never go below 0

fix loop of superb music

* make markers non clamped

lockstep frees rendertextures when unloading

* lockstep creates its own rendertextures

swapped button order on title screen
added null checks to animation helpers
disabled controller auto-search for now

* enable particles on OK rank

* play mode info panel

* let play mode handle its own fade out

* fix that alignment bug in controller settings

* more safety here

* Update PauseMenu.cs

* settable (one-liner) rating screen text

* address minigame loading crashes

* don't do this twice

* wav converter for mp3

* Update Minigames.cs

* don't double-embed the converted audio

* studio dance bugfixing spree

* import redone sprites for studio dance

* update jukebox

prep epilogue screen

* epilogue screen

* studio dance inkling shuffle test

* new studio dance choreo system

* markers upgrade

* fix deleting volume changes and markers

prep category markers

* Update Editor.unity

* new rating / epilogue settings look

* update to use new tooltip system

mark certain editor components as blocking

* finish category system

* dedicated tempo / volume marker dialogs

* swing prep

* open properties dialog if mapper hasn't opened it prior for this chart

fix memory copy bug when making new chart

* fix ctrl + s

* return to title screen button

* make graphy work everywhere

studio dance selector
membillion mems

* make sure riq cache is clear when loading chart

* lol

* fix the stupid

* bring back tempo and volume change scrolling

* new look for panels

* adjust alignment

* round tooltip

* alignment of chart property prefab

* change scale factor of mem

* adjust open captions material

no dotted BG in results commentary (only epilogue)
bugfix for tempo / volume scroll

* format line 2 of judgement a bit better

update font

* oops

* adjust look of judgement score bar

* new rating bar

* judgement size adjustment

* fix timing window scaling with song pitch

* proper clamping in dialogs

better sync conductor to dsptime (experiment)

* disable timeline pitch change when song is paused

enable perfect challenge if no marker is set to do so

* new app icon

* timing window values are actually double now

* improve deferred timekeep even more

* re-generate font atlases

new app icon in credits

* default epilogue images

* more timing window adjustment

* fix timing display when pitched

* use proper terminology here

* new logo on titlescreen

* remove wip from play

update credits

* adjust spacing of play mode panel

* redo button spacing

* can pass title screen with any controller

fix issues with controller auto-search

* button scale fixes

* controller title screen nav

* remove song genre from properties editor

* disable circle cursor when not using touch style

* proper selection graphic

remove refs
re-add heart to the opening

* controller support in opening

---------

Co-authored-by: ev <85412919+evdial@users.noreply.github.com>
Co-authored-by: minenice55 <star.elementa@gmail.com>
Co-authored-by: ThatZeoMan <67521686+ThatZeoMan@users.noreply.github.com>
2023-12-26 05:22:51 +00:00

495 lines
No EOL
18 KiB
C#

using System;
using System.Linq;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using TMPro;
using System.Threading.Tasks;
using HeavenStudio;
using HeavenStudio.Util;
using HeavenStudio.InputSystem;
using static JSL;
namespace HeavenStudio.Editor
{
public class ControllerSettings : TabsContent
{
[SerializeField] private TMP_Dropdown stylesDropdown;
[SerializeField] private TMP_Text numConnectedLabel;
[SerializeField] private TMP_Text currentControllerLabel;
[SerializeField] private TMP_Dropdown controllersDropdown;
[SerializeField] private GameObject pairSearchItem;
[SerializeField] private GameObject autoSearchLabel;
[SerializeField] private GameObject pairSearchLabel;
[SerializeField] private GameObject pairSearchCancelBt;
[SerializeField] private TMP_Text pairingLabel;
[SerializeField] private List<GameObject> controllerIcons;
[SerializeField] private Material controllerMat;
[SerializeField] private List<GameObject> PadBindingsMenus;
[SerializeField] private List<GameObject> BatonBindingsMenus;
[SerializeField] private List<GameObject> TouchBindingsMenus;
[SerializeField] private List<TMP_Text> PadBindingsTxt;
[SerializeField] private List<TMP_Text> BatonBindingsTxt;
[SerializeField] private List<TMP_Text> TouchBindingsTxt;
[SerializeField] private Slider cursorSensitivitySlider;
private bool isAutoSearching = false;
private bool isPairSearching = false;
private bool pairSelectLR = false; //true = left, false = right
private bool bindAllMode;
private int currentBindingBt;
private void Start()
{
numConnectedLabel.text = "Connected: " + PlayerInput.GetNumControllersConnected();
currentControllerLabel.text = "Current Controller: " + PlayerInput.GetInputController(1).GetDeviceName();
PopulateControllersDropdown();
PopulateStylesDropdown();
pairSearchItem.SetActive(false);
InputController initController = PlayerInput.GetInputController(1);
if (!initController.GetCurrentStyleSupported())
{
PlayerInput.CurrentControlStyle = initController.GetDefaultStyle();
stylesDropdown.SetValueWithoutNotify((int)PlayerInput.CurrentControlStyle);
}
UpdateControlStyleMapping();
ShowControllerBinds(initController);
ShowControllerIcon(initController);
}
private void Update()
{
InputController currentController = PlayerInput.GetInputController(1);
if (currentBindingBt >= 0)
{
int bt = currentController.GetLastButtonDown();
if (bt > 0)
{
InputController.ControlBindings binds = currentController.GetCurrentBindings();
switch (PlayerInput.CurrentControlStyle)
{
case InputController.ControlStyles.Touch:
binds.Touch[currentBindingBt] = bt;
break;
case InputController.ControlStyles.Baton:
binds.Baton[currentBindingBt] = bt;
break;
default:
binds.Pad[currentBindingBt] = bt;
break;
}
currentController.SetCurrentBindings(binds);
currentControllerLabel.text = "Current Controller: " + currentController.GetDeviceName();
ShowControllerBinds(currentController);
AdvanceAutoBind(currentController);
}
return;
}
else
{
if (isAutoSearching)
{
var controllers = PlayerInput.GetInputControllers();
foreach (var newController in controllers)
{
if (newController.GetLastButtonDown(true) > 0)
{
autoSearchLabel.SetActive(false);
AssignController(newController, currentController);
controllersDropdown.SetValueWithoutNotify(PlayerInput.GetInputControllerId(1));
isAutoSearching = false;
}
}
}
else if (isPairSearching)
{
var controllers = PlayerInput.GetInputControllers();
InputController.InputFeatures lrFlag = pairSelectLR ? InputController.InputFeatures.Extra_SplitControllerLeft : InputController.InputFeatures.Extra_SplitControllerRight;
foreach (var pairController in controllers)
{
if (pairController == currentController) continue;
InputController.InputFeatures features = pairController.GetFeatures();
if (!features.HasFlag(lrFlag)) continue;
if (pairController.GetLastButtonDown() > 0)
{
(PlayerInput.GetInputController(1) as InputJoyshock)?.AssignOtherHalf((InputJoyshock)pairController);
isPairSearching = false;
pairSearchLabel.SetActive(false);
currentControllerLabel.text = "Current Controller: " + pairController.GetDeviceName();
pairingLabel.text = "Joy-Con Pair Selected\nPairing Successful!";
ShowControllerIcon(pairController);
currentController.OnSelected();
pairController.OnSelected();
}
}
}
}
}
void AdvanceAutoBind(InputController currentController)
{
int pauseVal;
Type enumType;
switch (PlayerInput.CurrentControlStyle)
{
case InputController.ControlStyles.Touch:
enumType = typeof(InputController.ActionsTouch);
pauseVal = (int)InputController.ActionsTouch.Pause;
break;
case InputController.ControlStyles.Baton:
enumType = typeof(InputController.ActionsBaton);
pauseVal = (int)InputController.ActionsBaton.Pause;
break;
default:
enumType = typeof(InputController.ActionsPad);
pauseVal = (int)InputController.ActionsPad.Pause;
break;
}
if (bindAllMode)
{
currentBindingBt++;
Debug.Log("Binding: " + currentBindingBt);
while (currentController.GetIsActionUnbindable(currentBindingBt, PlayerInput.CurrentControlStyle) && currentBindingBt < pauseVal)
{
currentBindingBt++;
Debug.Log("Unbindable, binding: " + currentBindingBt);
}
if (currentBindingBt > pauseVal)
{
currentController.SaveBindings();
CancelBind();
return;
}
currentControllerLabel.text = $"Now Binding: {enumType.GetEnumName(currentBindingBt)}";
}
else
{
currentController.SaveBindings();
CancelBind();
}
}
void AssignController(InputController newController, InputController lastController)
{
Debug.Log("Assigning controller: " + newController.GetDeviceName());
lastController.SetPlayer(null);
newController.SetPlayer(1);
if ((lastController as InputJoyshock) != null)
{
(lastController as InputJoyshock)?.UnAssignOtherHalf();
}
if ((newController as InputJoyshock) != null)
{
newController.OnSelected();
(newController as InputJoyshock)?.UnAssignOtherHalf();
}
currentControllerLabel.text = "Current Controller: " + newController.GetDeviceName();
if (!newController.GetCurrentStyleSupported())
{
PlayerInput.CurrentControlStyle = newController.GetDefaultStyle();
stylesDropdown.SetValueWithoutNotify((int)PlayerInput.CurrentControlStyle);
}
UpdateControlStyleMapping();
ShowControllerBinds(newController);
ShowControllerIcon(newController);
InputController.InputFeatures features = newController.GetFeatures();
if (features.HasFlag(InputController.InputFeatures.Extra_SplitControllerLeft))
{
pairingLabel.text = "Joy-Con (L) Selected\nPress any button on Joy-Con (R) to pair.";
pairSelectLR = !features.HasFlag(InputController.InputFeatures.Extra_SplitControllerLeft);
pairSearchItem.SetActive(true);
StartPairSearch();
}
else if (features.HasFlag(InputController.InputFeatures.Extra_SplitControllerRight))
{
pairingLabel.text = "Joy-Con (R) Selected\nPress any button on Joy-Con (L) to pair.";
pairSelectLR = !features.HasFlag(InputController.InputFeatures.Extra_SplitControllerLeft);
pairSearchItem.SetActive(true);
StartPairSearch();
}
else
{
CancelPairSearch();
pairSearchItem.SetActive(false);
}
}
public void ControllerDropdownChange()
{
CancelBind();
InputController lastController = PlayerInput.GetInputController(1);
lastController.SaveBindings();
InputController newController = PlayerInput.GetInputControllers()[controllersDropdown.value];
AssignController(newController, lastController);
}
public void StartBindSingle(int bt)
{
CancelBind();
if (PlayerInput.GetInputController(1).GetIsActionUnbindable(bt, PlayerInput.CurrentControlStyle))
{
return;
}
currentBindingBt = bt;
switch (PlayerInput.CurrentControlStyle)
{
case InputController.ControlStyles.Touch:
currentControllerLabel.text = $"Now Binding: {(InputController.ActionsTouch)bt}";
break;
case InputController.ControlStyles.Baton:
currentControllerLabel.text = $"Now Binding: {(InputController.ActionsBaton)bt}";
break;
default:
currentControllerLabel.text = $"Now Binding: {(InputController.ActionsPad)bt}";
break;
}
}
public void StartBindAll()
{
CancelBind();
bindAllMode = true;
currentBindingBt = -1;
AdvanceAutoBind(PlayerInput.GetInputController(1));
}
public void CancelBind()
{
bindAllMode = false;
currentBindingBt = -1;
currentControllerLabel.text = "Current Controller: " + PlayerInput.GetInputController(1).GetDeviceName();
}
public void ResetBindings()
{
CancelBind();
InputController controller = PlayerInput.GetInputController(1);
controller.ResetBindings();
ShowControllerBinds(controller);
controller.SaveBindings();
}
public void StartAutoSearch()
{
CancelBind();
if (!isPairSearching)
{
autoSearchLabel.SetActive(true);
isAutoSearching = true;
}
}
public void StartPairSearch()
{
CancelBind();
if (!isAutoSearching)
{
pairSearchLabel.SetActive(true);
pairSearchCancelBt.SetActive(true);
isPairSearching = true;
}
}
public void CancelPairSearch()
{
CancelBind();
if (isPairSearching)
{
pairSearchLabel.SetActive(false);
pairSearchCancelBt.SetActive(false);
isPairSearching = false;
pairingLabel.text = "Joy-Con Selected\nPairing was cancelled.";
}
}
public void SearchAndConnectControllers()
{
int connected = PlayerInput.RefreshInputControllers();
numConnectedLabel.text = "Connected: " + connected;
currentControllerLabel.text = "Current Controller: " + PlayerInput.GetInputController(1).GetDeviceName();
PopulateControllersDropdown();
}
public void PopulateStylesDropdown()
{
List<TMP_Dropdown.OptionData> dropDownData = new List<TMP_Dropdown.OptionData>();
var enumNames = Enum.GetNames(typeof(InputController.ControlStyles)).ToList();
stylesDropdown.ClearOptions();
stylesDropdown.AddOptions(enumNames);
stylesDropdown.SetValueWithoutNotify((int)PlayerInput.CurrentControlStyle);
}
public void PopulateControllersDropdown()
{
List<TMP_Dropdown.OptionData> dropDownData = new List<TMP_Dropdown.OptionData>();
var vals = PlayerInput.GetInputControllers();
for (int i = 0; i < vals.Count; i++)
{
TMP_Dropdown.OptionData optionData = new TMP_Dropdown.OptionData();
optionData.text = vals[i].GetDeviceName();
dropDownData.Add(optionData);
}
controllersDropdown.ClearOptions();
controllersDropdown.AddOptions(dropDownData);
controllersDropdown.SetValueWithoutNotify(PlayerInput.GetInputControllerId(1));
}
public void ChangeControlStyle()
{
CancelBind();
PlayerInput.CurrentControlStyle = (InputController.ControlStyles)stylesDropdown.value;
}
public void UpdateControlStyleMapping()
{
switch (PlayerInput.CurrentControlStyle)
{
case InputController.ControlStyles.Touch:
PadBindingsMenus.ForEach(x => x.SetActive(false));
BatonBindingsMenus.ForEach(x => x.SetActive(false));
TouchBindingsMenus.ForEach(x => x.SetActive(true));
break;
case InputController.ControlStyles.Baton:
PadBindingsMenus.ForEach(x => x.SetActive(false));
BatonBindingsMenus.ForEach(x => x.SetActive(true));
TouchBindingsMenus.ForEach(x => x.SetActive(false));
break;
default:
PadBindingsMenus.ForEach(x => x.SetActive(true));
BatonBindingsMenus.ForEach(x => x.SetActive(false));
TouchBindingsMenus.ForEach(x => x.SetActive(false));
break;
}
if (PlayerInput.CurrentControlStyle == InputController.ControlStyles.Touch)
{
cursorSensitivitySlider.gameObject.SetActive(true);
}
else
{
cursorSensitivitySlider.gameObject.SetActive(false);
}
}
public void ShowControllerBinds(InputController controller)
{
string[] buttons = controller.GetButtonNames();
List<TMP_Text> bindsTxt;
int[] binds;
InputController.ControlBindings ctrlBinds = controller.GetCurrentBindings();
switch (PlayerInput.CurrentControlStyle)
{
case InputController.ControlStyles.Touch:
bindsTxt = TouchBindingsTxt;
binds = ctrlBinds.Touch;
break;
case InputController.ControlStyles.Baton:
bindsTxt = BatonBindingsTxt;
binds = ctrlBinds.Baton;
break;
default:
bindsTxt = PadBindingsTxt;
binds = ctrlBinds.Pad;
break;
}
//show binds
int ac = 0;
foreach (int i in binds)
{
if (ac >= bindsTxt.Count) break;
if (bindsTxt[ac] == null)
{
ac++;
continue;
}
if (i == -1)
{
bindsTxt[ac].text = "NOT BOUND";
}
else if (buttons[i] == null)
{
bindsTxt[ac].text = "UNKNOWN";
}
else
{
bindsTxt[ac].text = buttons[i];
}
ac++;
}
cursorSensitivitySlider.value = ctrlBinds.PointerSensitivity;
}
public void ShowControllerIcon(InputController controller)
{
string name = controller.GetDeviceName();
//show icon
foreach (var icon in controllerIcons)
{
if (icon.name == name)
{
icon.SetActive(true);
}
else
{
icon.SetActive(false);
}
}
//setup material
controller.SetMaterialProperties(controllerMat);
}
public void SetCursorSensitivity()
{
var currentController = PlayerInput.GetInputController(1);
InputController.ControlBindings binds = currentController.GetCurrentBindings();
binds.PointerSensitivity = cursorSensitivitySlider.value;
currentController.SetCurrentBindings(binds);
}
public override void OnOpenTab()
{
CancelBind();
}
public override void OnCloseTab()
{
CancelBind();
}
}
}