-
-
Notifications
You must be signed in to change notification settings - Fork 14
/
SpaghettiUI.cs
660 lines (540 loc) · 22.9 KB
/
SpaghettiUI.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
using BeatSaberMarkupLanguage;
using BeatSaberMarkupLanguage.Attributes;
using BeatSaberMarkupLanguage.Components;
using BeatSaberMarkupLanguage.Components.Settings;
using BeatSaberMarkupLanguage.GameplaySetup;
using BeatSaberMarkupLanguage.MenuButtons;
using BeatSaberMarkupLanguage.ViewControllers;
using Camera2.Behaviours;
using Camera2.Configuration;
using Camera2.Managers;
using HarmonyLib;
using HMUI;
using System;
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel;
using System.Diagnostics;
using System.Linq;
using System.Net;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Threading.Tasks;
using UnityEngine.UI;
namespace Camera2.UI {
// Theres a reason this is called Spaghetti UI, I will definitely maybe possibly make this not spaghetti one day.
class SpaghettiUI {
private static Coordinator _flow;
internal static CustomScenesSwitchUI scenesSwitchUI = new CustomScenesSwitchUI();
public static void Init() {
MenuButtons.instance.RegisterButton(new MenuButton("Camera2", "This is a Camera plugin 2 4Head", ShowFlow, true));
if(ScenesManager.settings.customScenes.Count > 0)
GameplaySetup.instance.AddTab("Camera2", "Camera2.UI.Views.customScenesList.bsml", scenesSwitchUI);
}
private static void ShowFlow() {
if(_flow == null)
_flow = BeatSaberUI.CreateFlowCoordinator<Coordinator>();
BeatSaberUI.MainFlowCoordinator.PresentFlowCoordinator(_flow);
}
}
class PreviewView : BSMLResourceViewController {
public override string ResourceName => "Camera2.UI.Views.camPreview.bsml";
[UIComponent("previewImage")] public RawImage image = null;
[UIAction("#post-parse")]
private void Parsed() {
image.transform.localEulerAngles = new UnityEngine.Vector3(180f, 0, 0);
OnEnable();
}
UnityEngine.RenderTexture renderTexture;
void OnEnable() {
if(image == null)
return;
renderTexture = new UnityEngine.RenderTexture(UnityEngine.Screen.width, UnityEngine.Screen.height, 0);
image.texture = renderTexture;
var imageTransform = image.transform;
imageTransform.localPosition = new UnityEngine.Vector3(0, 0, -3.7f);
imageTransform.localEulerAngles = new UnityEngine.Vector3(10, 180, 180);
StartCoroutine(DoTheFunny());
}
void OnDisable() {
if(image)
image.texture = null;
if(renderTexture != null) {
renderTexture.Release();
renderTexture = null;
}
}
IEnumerator DoTheFunny() {
while(isActiveAndEnabled) {
yield return new UnityEngine.WaitForEndOfFrame();
if(renderTexture)
UnityEngine.ScreenCapture.CaptureScreenshotIntoRenderTexture(renderTexture);
yield return null;
yield return null;
}
}
}
class SettingsView : BSMLResourceViewController, INotifyPropertyChanged {
public override string ResourceName => "Camera2.UI.Views.camSettings.bsml";
[UIComponent("zOffsetSlider")] SliderSetting zOffsetSlider = null;
[UIComponent("xRotationSlider")] SliderSetting xRotationSlider = null;
[UIComponent("pivotingOffsetToggle")] ToggleSetting pivotingOffsetToggle = null;
[UIComponent("previewSizeSlider")] SliderSetting previewSizeSlider = null;
[UIComponent("modmapExt_moveWithMapCheckbox")] ToggleSetting modmapExt_moveWithMapSlider = null;
[UIComponent("worldcamVisibilityInput")] LayoutElement worldcamVisibilityObj = null;
[UIComponent("smoothfollowTab")] Tab smoothfollowTab = null;
[UIComponent("follow360Tab")] Tab follow360Tab = null;
[UIComponent("viewRectTab")] internal Tab viewRectTab = null;
[UIComponent("tabSelector")] TabSelector tabSelector = null;
internal static Cam2 cam { get; private set; }
static string[] props;
void Awake() {
// Dont really care which cam it is, this is just for BSML to init
cam = CamManager.cams.Values.First();
props ??= typeof(SettingsView).GetProperties(
BindingFlags.Instance | BindingFlags.NonPublic
).Select(x => x.Name).ToArray();
scenes ??= Enum.GetValues(typeof(SceneTypes)).Cast<SceneTypes>().Select(x => new SceneToggle() { type = x, host = this }).ToArray();
}
#region variables
internal string camName {
get => cam.name;
set {
if(CamManager.RenameCamera(cam, value))
Coordinator.instance.camList.list.tableView.ReloadData();
NotifyPropertyChanged("camName");
}
}
internal CameraType type {
get => cam.settings.type;
set {
// When switching to FP reset Rot / Pos so that the previous TP values arent used as the FP offset
if(value == CameraType.FirstPerson) {
cam.settings.targetPos = new UnityEngine.Vector3(0, 0, 0);
NotifyPropertyChanged("zOffset");
} else if(value == CameraType.Positionable) {
cam.settings.targetPos = new UnityEngine.Vector3(0, 1.5f, 1f);
}
cam.settings.targetRot = UnityEngine.Vector3.zero;
cam.settings.type = value;
ToggleSettingVisibility();
}
}
internal WorldCamVisibility worldCamVisibility { get => cam.settings.worldCamVisibility; set { cam.settings.worldCamVisibility = value; } }
internal float FOV { get => cam.settings.FOV; set { cam.settings.FOV = value; } }
internal int fpsLimit { get => cam.settings.FPSLimiter.fpsLimit; set { cam.settings.FPSLimiter.fpsLimit = value; } }
internal float renderScale { get => cam.settings.renderScale; set { cam.settings.renderScale = value; } }
internal int antiAliasing { get => cam.settings.antiAliasing; set { cam.settings.antiAliasing = value; } }
internal float previewSize { get => cam.settings.previewScreenSize; set { cam.settings.previewScreenSize = value; } }
internal float zOffset {
get {
float ret = 0f;
cam.settings.Unoverriden(delegate () {
ret = cam.settings.targetPos.z;
});
return ret;
}
set {
cam.settings.Unoverriden(delegate () {
var x = cam.settings.targetPos;
x.z = value;
cam.settings.targetPos = x;
});
cam.settings.ApplyPositionAndRotation();
}
}
internal WallVisiblity visibility_Walls {
get => cam.settings.visibleObjects.Walls; set { cam.settings.visibleObjects.Walls = value; }
}
internal NoteVisibility visibility_Notes {
get => cam.settings.visibleObjects.Notes; set { cam.settings.visibleObjects.Notes = value; }
}
internal bool visibility_Debris {
get => cam.settings.visibleObjects.Debris; set { cam.settings.visibleObjects.Debris = value; }
}
internal bool visibility_UI {
get => cam.settings.visibleObjects.UI; set { cam.settings.visibleObjects.UI = value; }
}
internal AvatarVisibility visibility_Avatar {
get => cam.settings.visibleObjects.Avatar; set { cam.settings.visibleObjects.Avatar = value; }
}
internal bool visibility_Floor {
get => cam.settings.visibleObjects.Floor; set { cam.settings.visibleObjects.Floor = value; }
}
internal bool visibility_CutParticles {
get => cam.settings.visibleObjects.CutParticles; set { cam.settings.visibleObjects.CutParticles = value; }
}
internal bool visibility_Sabers {
get => cam.settings.visibleObjects.Sabers; set { cam.settings.visibleObjects.Sabers = value; }
}
internal bool visibility_EverythingElse {
get => cam.settings.visibleObjects.EverythingElse; set { cam.settings.visibleObjects.EverythingElse = value; }
}
internal bool multiplayer_followSpectatorPlattform {
get => cam.settings.Multiplayer.followSpectatorPlattform; set { cam.settings.Multiplayer.followSpectatorPlattform = value; }
}
internal bool smoothFollow_forceUpright {
get => cam.settings.Smoothfollow.limits.rot_z == "0:0";
set {
if(value) {
cam.settings.Smoothfollow.limits.rot_z = "0:0";
} else {
cam.settings.Smoothfollow.limits.rot_z_min = float.NegativeInfinity;
cam.settings.Smoothfollow.limits.rot_z_max = float.PositiveInfinity;
}
}
}
internal bool smoothFollow_followReplayPosition {
get => cam.settings.Smoothfollow.followReplayPosition; set { cam.settings.Smoothfollow.followReplayPosition = value; }
}
internal float smoothFollow_position {
get => cam.settings.Smoothfollow.position; set { cam.settings.Smoothfollow.position = value; }
}
internal float smoothFollow_rotation {
get => cam.settings.Smoothfollow.rotation; set { cam.settings.Smoothfollow.rotation = value; }
}
internal bool modmapExt_moveWithMap {
get => cam.settings.ModmapExtensions.moveWithMap; set { cam.settings.ModmapExtensions.moveWithMap = value; }
}
internal bool modmapExt_autoOpaqueWalls {
get => cam.settings.ModmapExtensions.autoOpaqueWalls; set { cam.settings.ModmapExtensions.autoOpaqueWalls = value; }
}
internal bool modmapExt_autoHideHUD {
get => cam.settings.ModmapExtensions.autoHideHUD; set { cam.settings.ModmapExtensions.autoHideHUD = value; }
}
internal bool follow360_moveWithMap {
get => cam.settings.Follow360.enabled; set { cam.settings.Follow360.enabled = value; }
}
internal float follow360_smoothing {
get => cam.settings.Follow360.smoothing; set { cam.settings.Follow360.smoothing = value; }
}
internal float postprocessing_transparencyThreshold {
get => cam.settings.PostProcessing.transparencyThreshold; set { cam.settings.PostProcessing.transparencyThreshold = value; }
}
internal bool postprocessing_forceDepthTexture {
get => cam.settings.PostProcessing.forceDepthTexture; set { cam.settings.PostProcessing.forceDepthTexture = value; }
}
internal float viewRect_x {
get => cam.settings.viewRect.x; set => cam.settings.SetViewRect(value, null, null, null);
}
internal float viewRect_y {
get => cam.settings.viewRect.y; set => cam.settings.SetViewRect(null, value, null, null);
}
internal float viewRect_width {
get => cam.settings.viewRect.width; set => cam.settings.SetViewRect(null, null, value, null);
}
internal float viewRect_height {
get => cam.settings.viewRect.height; set => cam.settings.SetViewRect(null, null, null, value);
}
internal bool viewRect_isLocked {
get => cam.settings.isScreenLocked; set => cam.settings.isScreenLocked = value;
}
internal float xRotation {
get {
float ret = 0f;
cam.settings.Unoverriden(delegate () {
ret = cam.settings.targetRot.x;
});
return ret;
}
set {
cam.settings.Unoverriden(delegate () {
var x = cam.settings.targetRot;
x.x = value;
cam.settings.targetRot = x;
});
cam.settings.ApplyPositionAndRotation();
}
}
internal bool misc_pivotingOffset {
get => cam.settings.Smoothfollow.pivotingOffset; set { cam.settings.Smoothfollow.pivotingOffset = value; }
}
internal bool misc_orthographic {
get => cam.settings.orthographic; set { cam.settings.orthographic = value; }
}
internal bool misc_MovementScript_enableInMenu {
get => cam.settings.MovementScript.enableInMenu; set { cam.settings.MovementScript.enableInMenu = value; }
}
#endregion
[UIAction("SetRenderDistanceNear")] void SetRenderDistanceNear() => cam.settings.farZ = 6f;
[UIAction("SetRenderDistanceShort")] void SetRenderDistanceShort() => cam.settings.farZ = 10f;
[UIAction("SetRenderDistanceUnlimited")] void SetRenderDistanceUnlimited() => cam.settings.farZ = 5000f;
private static readonly List<object> types = new List<object> { CameraType.FirstPerson, CameraType.Positionable };
private static readonly List<object> antiAliasingLevels = new List<object> { 1, 2, 4, 8 };
private static readonly List<object> worldCamVisibilities = Enum.GetValues(typeof(WorldCamVisibility)).Cast<object>().ToList();
private static readonly List<object> visibilities_Walls = Enum.GetValues(typeof(WallVisiblity)).Cast<object>().ToList();
private static readonly List<object> visibilities_Notes = Enum.GetValues(typeof(NoteVisibility)).Cast<object>().ToList();
private static readonly List<object> visibilities_Avatar = Enum.GetValues(typeof(AvatarVisibility)).Cast<object>().ToList();
private SceneToggle[] scenes;
class SceneToggle : NotifiableSettingsObj {
internal SettingsView host;
internal SceneTypes type;
internal bool val {
get => ScenesManager.settings.scenes[type].Contains(host.camName);
set {
var x = ScenesManager.settings.scenes[type];
if(!value) {
x.RemoveAll(c => c == host.camName);
} else if(!x.Contains(host.camName)) {
x.Add(host.camName);
}
}
}
}
internal bool SetCam(Cam2 newCam) {
if(cam == newCam)
return false;
SaveSettings();
cam = newCam;
ScenesManager.LoadGameScene(forceReload: true);
//if(Coordinator.instance.previewView?.dd != null) {
// Coordinator.instance.previewView.dd.material = cam?.worldCam.viewMaterial;
// Coordinator.instance.previewView.dd.SetMaterialDirty();
//}
CamManager.ApplyCameraValues(worldCam: true, viewLayer: true);
if(cam == null)
return true;
cam.gameObject.SetActive(true);
ToggleSettingVisibility();
foreach(var prop in props)
NotifyPropertyChanged(prop);
foreach(var x in scenes)
x.NotifyPropertyChanged("val");
return true;
}
internal void SaveSettings() {
if(cam != null)
cam.settings.Save();
ScenesManager.settings.Save();
}
[UIAction("#post-parse")]
private void Parsed() {
cam = null;
// Since BSML doesnt make all the inputs have the same width I need to to it myself for my own sanity
foreach(var x in GetComponentsInChildren<StringSetting>(true)) {
var picker = x.transform.Find("ValuePicker/DecButton");
picker.gameObject.SetActive(false);
picker.parent.localScale = new UnityEngine.Vector3(1.06f, 1f, 1f);
}
foreach(var x in GetComponentsInChildren<DropDownListSetting>(true))
x.transform.localScale = new UnityEngine.Vector3(1.09f, 1f, 1f);
viewRectTab.IsVisible = false;
Coordinator.instance.ShowSettingsForCam(CamManager.cams.Values.First());
}
private void ToggleSettingVisibility() {
if(zOffsetSlider == null) return;
zOffsetSlider.gameObject.SetActive(type == CameraType.FirstPerson);
xRotationSlider.gameObject.SetActive(type == CameraType.FirstPerson);
pivotingOffsetToggle.gameObject.SetActive(type == CameraType.FirstPerson);
previewSizeSlider.gameObject.SetActive(type == CameraType.Positionable);
modmapExt_moveWithMapSlider.gameObject.SetActive(type == CameraType.Positionable);
worldcamVisibilityObj.gameObject.SetActive(type == CameraType.Positionable);
smoothfollowTab.IsVisible = type == CameraType.FirstPerson;
follow360Tab.IsVisible = type == CameraType.Positionable;
// Apparently this is the best possible way to programmatically switch the selected tab
tabSelector.textSegmentedControl.SelectCellWithNumber(0);
AccessTools.Method(typeof(TabSelector), "TabSelected").Invoke(tabSelector, new object[] { tabSelector.textSegmentedControl, 0 });
}
}
class CamList : BSMLResourceViewController {
public override string ResourceName => "Camera2.UI.Views.camList.bsml";
private readonly string cam2Version = $"Version {Assembly.GetExecutingAssembly().GetName().Version.ToString(3)} by Kinsi55";
[UIComponent("deleteButton")] public NoTransitionsButton deleteButton = null;
[UIComponent("camList")] public CustomCellListTableData list = null;
public List<CamListCellWrapper> listData = new List<CamListCellWrapper>();
public IEnumerable<CamListCellWrapper> listDataOrdered => listData.OrderByDescending(x => x.cam.settings.layer);
List<object> cams => listDataOrdered.ToList<object>();
public class CamListCellWrapper {
public Cam2 cam { get; private set; }
public CamListCellWrapper(Cam2 cam) => this.cam = cam;
public string name => cam.name;
int sceneCount => ScenesManager.settings.scenes.Values.Count(x => x.Contains(name)) + ScenesManager.settings.customScenes.Values.Count(x => x.Contains(name));
string details => $"{cam.settings.type}, assigned to {sceneCount} {(sceneCount == 1 ? "Scene" : "Scenes")}";
string layerUIText => $"Layer {cam.settings.layer}{(CamManager.cams.Values.Count(x => x.settings.layer == cam.settings.layer) > 1 ? " <color=#d5a145>⚠</color>" : "")}";
[UIComponent("bgContainer")] ImageView bg = null;
[UIAction("refresh-visuals")]
public void Refresh(bool selected, bool highlighted) {
var x = new UnityEngine.Color(0, 0, 0, 0.45f);
if(selected || highlighted)
x.a = selected ? 0.9f : 0.6f;
bg.color = x;
}
}
internal void UpdateCamListUI() {
//var x = Sprite.Create(cam.screenImage.material, new Rect(0, 0, cam.renderTexture.width, cam.renderTexture.width), new Vector2(0.5f, 0.5f));
list.data = cams;
list.tableView.ReloadData();
deleteButton.interactable = listData.Count > 1;
}
[UIAction("#post-parse")]
internal void Init() {
listData.Clear();
listData.AddRange(CamManager.cams.Values.Select(x => new CamListCellWrapper(x)));
UpdateCamListUI();
}
[UIAction("SelectCamera")]
void SelectCamera(TableView tableView, CamListCellWrapper row) => Coordinator.instance.ShowSettingsForCam(row.cam);
Cam2 GetNewCam(string name) {
var cam = CamManager.AddNewCamera(name);
cam.settings.SetViewRect(
UnityEngine.Random.Range(0, 0.2f),
UnityEngine.Random.Range(0, 0.2f),
1f / 3,
1f / 3
);
return cam;
}
void AddCam(Cam2 cam) {
cam.settings.ApplyPositionAndRotation();
cam.settings.ApplyLayerBitmask();
cam.UpdateRenderTextureAndView();
listData.Insert(0, new CamListCellWrapper(cam));
UpdateCamListUI();
Coordinator.instance.ShowSettingsForCam(cam);
}
void AddCamDefault() => AddCam(GetNewCam("Unnamed Camera"));
void AddCamSideview() {
var cam = CamManager.AddNewCamera("Side View");
cam.settings.type = CameraType.Positionable;
cam.settings.FOV = 75;
cam.settings.SetViewRect(0, 0, .195f, .395f);
cam.settings.targetPos = new UnityEngine.Vector3(3, 1.2f, 0);
cam.settings.targetRot = new UnityEngine.Vector3(0, -90f, 0);
cam.settings.visibleObjects.Walls = WallVisiblity.Hidden;
cam.settings.visibleObjects.Debris = false;
cam.settings.visibleObjects.UI = false;
cam.settings.visibleObjects.Floor = false;
cam.settings.visibleObjects.CutParticles = false;
cam.settings.farZ = 10f;
AddCam(cam);
}
void AddCamBackview() {
var cam = CamManager.AddNewCamera("Back View");
cam.settings.type = CameraType.Positionable;
cam.settings.FOV = 42;
cam.settings.SetViewRect(0.8f, 0, .2f, .3f);
cam.settings.targetPos = new UnityEngine.Vector3(0, 1.5f, -1.3f);
cam.settings.visibleObjects.Walls = WallVisiblity.Hidden;
cam.settings.visibleObjects.Debris = false;
cam.settings.visibleObjects.UI = false;
cam.settings.visibleObjects.Floor = false;
cam.settings.visibleObjects.CutParticles = false;
cam.settings.farZ = 6f;
cam.settings.orthographic = true;
AddCam(cam);
}
void AddCamThirdperson() {
var cam = GetNewCam("Static Thirdperson");
cam.settings.type = CameraType.Positionable;
cam.settings.FOV = 75;
cam.settings.targetPos = new UnityEngine.Vector3(1.93f, 2.32f, -2.45f);
cam.settings.targetRot = new UnityEngine.Vector3(16.48f, 335.78f, 0.81f);
AddCam(cam);
}
void AddCamAvatarFaceCam() {
var cam = GetNewCam("Facecam");
cam.settings.type = CameraType.FirstPerson;
cam.settings.FOV = 75;
cam.settings.targetPos = new UnityEngine.Vector3(0, -0.1f, 0.5f);
cam.settings.targetRot = new UnityEngine.Vector3(0, 180f, 0);
cam.settings.Smoothfollow.followReplayPosition = false;
cam.settings.Smoothfollow.limits.rot_z = "0:0";
cam.settings.Smoothfollow.position = 8f;
cam.settings.Smoothfollow.rotation = 3f;
cam.settings.visibleObjects.Avatar = AvatarVisibility.ForceVisibleInFP;
cam.settings.visibleObjects.UI = false;
AddCam(cam);
}
void DeleteCam() {
listData.Remove(listData.Find(x => x.cam == SettingsView.cam));
CamManager.DeleteCamera(SettingsView.cam);
UpdateCamListUI();
Coordinator.instance.ShowSettingsForCam(listDataOrdered.First().cam);
}
void ChangeLayer(int diff) {
SettingsView.cam.settings.layer += diff;
Coordinator.instance.camList.UpdateCamListUI();
Coordinator.instance.ShowSettingsForCam(SettingsView.cam, true);
}
void LayerIncrease() => ChangeLayer(1);
void LayerDecrease() => ChangeLayer(-1);
void UnlockCamPosTab() => Coordinator.instance.settingsView.viewRectTab.IsVisible = true;
void ShowGithub() => Process.Start("https://github.com/kinsi55/CS_BeatSaber_Camera2");
void ShowWiki() => Process.Start("https://github.com/kinsi55/CS_BeatSaber_Camera2/wiki");
[UIComponent("sponsorsText")] CurvedTextMeshPro sponsorsText = null;
void OpenSponsorsLink() => Process.Start("https://github.com/sponsors/kinsi55");
void OpenSponsorsModal() {
sponsorsText.text = "Loading...";
Task.Run(() => {
string desc = "Failed to load";
try {
desc = (new WebClient()).DownloadString("http://kinsi.me/sponsors/bsout.php");
} catch { }
_ = IPA.Utilities.Async.UnityMainThreadTaskScheduler.Factory.StartNew(() => {
sponsorsText.text = desc;
// There is almost certainly a better way to update / correctly set the scrollbar size...
sponsorsText.gameObject.SetActive(false);
sponsorsText.gameObject.SetActive(true);
});
}).ConfigureAwait(false);
}
}
class Coordinator : FlowCoordinator {
internal static Coordinator instance { get; private set; }
internal SettingsView settingsView;
internal CamList camList;
internal PreviewView previewView;
public void Awake() {
instance = this;
if(camList == null)
camList = BeatSaberUI.CreateViewController<CamList>();
if(settingsView == null)
settingsView = BeatSaberUI.CreateViewController<SettingsView>();
if(previewView == null)
previewView = BeatSaberUI.CreateViewController<PreviewView>();
}
public void ShowSettingsForCam(Cam2 cam, bool reselect = false) {
SetTitle($"Camera2 | {cam.name}");
if(!settingsView.SetCam(cam) && !reselect)
return;
var cellIndex = Array.FindIndex(camList.listDataOrdered.ToArray(), x => x.cam == cam);
camList.list.tableView.SelectCellWithIdx(cellIndex);
camList.list.tableView.ScrollToCellWithIdx(cellIndex, TableView.ScrollPositionType.Center, false);
}
protected override void DidActivate(bool firstActivation, bool addedToHierarchy, bool screenSystemEnabling) {
try {
if(!firstActivation) {
if(camList != null)
camList.Init();
ShowSettingsForCam(CamManager.cams.Values.First());
return;
}
showBackButton = true;
ProvideInitialViewControllers(settingsView, camList, null, previewView);
} catch(Exception ex) {
Plugin.Log.Error(ex);
}
}
protected override void BackButtonWasPressed(ViewController topViewController) {
settingsView.SetCam(null);
ScenesManager.LoadGameScene(forceReload: true);
BeatSaberUI.MainFlowCoordinator.DismissFlowCoordinator(this, null, ViewController.AnimationDirection.Horizontal);
}
}
class NotifiableSettingsObj : INotifyPropertyChanged {
public event PropertyChangedEventHandler PropertyChanged;
internal void NotifyPropertyChanged([CallerMemberName] string propertyName = "") {
try {
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
} catch(Exception ex) {
Plugin.Log?.Error($"Error Invoking PropertyChanged: {ex.Message}");
Plugin.Log?.Error(ex);
}
}
internal void NotifyPropertiesChanged() {
foreach(var x in GetType().GetFields(BindingFlags.Public | BindingFlags.Instance))
NotifyPropertyChanged(x.Name);
}
}
}