123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189 |
- using System.Collections.Generic;
- using UnityEngine;
- namespace MeidoPhotoStudio.Plugin;
- public class MainWindow : BaseWindow
- {
- private readonly MeidoManager meidoManager;
- private readonly Dictionary<Constants.Window, BaseMainWindowPane> windowPanes;
- private readonly PropManager propManager;
- private readonly LightManager lightManager;
- private readonly TabsPane tabsPane;
- private readonly Button settingsButton;
- private BaseMainWindowPane currentWindowPane;
- private string settingsButtonLabel;
- private string closeButtonLabel;
- private Constants.Window selectedWindow;
- // TODO: Find a better way of doing this
- public MainWindow(MeidoManager meidoManager, PropManager propManager, LightManager lightManager)
- {
- this.meidoManager = meidoManager;
- this.meidoManager.UpdateMeido += UpdateMeido;
- this.propManager = propManager;
- this.propManager.FromPropSelect += (_, _) =>
- ChangeWindow(Constants.Window.BG2);
- this.lightManager = lightManager;
- this.lightManager.Select += (_, _) =>
- ChangeWindow(Constants.Window.BG);
- windowPanes = new();
- WindowRect = new(Screen.width, Screen.height * 0.08f, 240f, Screen.height * 0.9f);
- tabsPane = new();
- tabsPane.TabChange += (_, _) =>
- ChangeTab();
- settingsButtonLabel = Translation.Get("settingsLabels", "settingsButton");
- closeButtonLabel = Translation.Get("settingsLabels", "closeSettingsButton");
- settingsButton = new(settingsButtonLabel);
- settingsButton.ControlEvent += (_, _) =>
- {
- if (selectedWindow is Constants.Window.Settings)
- {
- ChangeTab();
- }
- else
- {
- settingsButton.Label = closeButtonLabel;
- SetCurrentWindow(Constants.Window.Settings);
- }
- };
- }
- public override Rect WindowRect
- {
- set
- {
- value.width = 240f;
- value.height = Screen.height * 0.9f;
- if (MeidoPhotoStudio.EditMode)
- value.height *= 0.85f;
- value.x = Mathf.Clamp(value.x, 0, Screen.width - value.width);
- value.y = Mathf.Clamp(value.y, -value.height + 30, Screen.height - 50);
- windowRect = value;
- }
- }
- public BaseMainWindowPane this[Constants.Window id]
- {
- get => windowPanes[id];
- set => AddWindow(id, value);
- }
- public void AddWindow(Constants.Window id, BaseMainWindowPane window)
- {
- if (windowPanes.ContainsKey(id))
- Panes.Remove(windowPanes[id]);
- windowPanes[id] = window;
- windowPanes[id].SetTabsPane(tabsPane);
- windowPanes[id].SetParent(this);
- Panes.Add(windowPanes[id]);
- }
- public override void Activate()
- {
- base.Activate();
- updating = true;
- tabsPane.SelectedTab = Constants.Window.Call;
- updating = false;
- Visible = true;
- }
- public override void Update()
- {
- base.Update();
- if (InputManager.GetKeyDown(MpsKey.ToggleUI))
- Visible = !Visible;
- }
- public override void Draw()
- {
- currentWindowPane?.Draw();
- GUI.enabled = true;
- GUILayout.FlexibleSpace();
- var labelStyle = new GUIStyle(GUI.skin.label)
- {
- fontSize = 10,
- alignment = TextAnchor.LowerLeft,
- };
- GUILayout.BeginHorizontal();
- GUILayout.Label(MeidoPhotoStudio.PluginString, labelStyle);
- GUILayout.FlexibleSpace();
- GUI.enabled = !InputManager.Listening;
- settingsButton.Draw(GUILayout.ExpandWidth(false));
- GUI.enabled = true;
- GUILayout.EndHorizontal();
- GUI.DragWindow();
- }
- protected override void ReloadTranslation()
- {
- settingsButtonLabel = Translation.Get("settingsLabels", "settingsButton");
- closeButtonLabel = Translation.Get("settingsLabels", "closeSettingsButton");
- settingsButton.Label = selectedWindow == Constants.Window.Settings ? closeButtonLabel : settingsButtonLabel;
- }
- private void ChangeTab()
- {
- settingsButton.Label = Translation.Get("settingsLabels", "settingsButton");
- SetCurrentWindow(tabsPane.SelectedTab);
- }
- private void SetCurrentWindow(Constants.Window window)
- {
- if (currentWindowPane is not null)
- currentWindowPane.ActiveWindow = false;
- selectedWindow = window;
- currentWindowPane = windowPanes[selectedWindow];
- currentWindowPane.ActiveWindow = true;
- currentWindowPane.UpdatePanes();
- }
- private void UpdateMeido(object sender, MeidoUpdateEventArgs args)
- {
- if (args.FromMeido)
- {
- var newWindow = args.IsBody ? Constants.Window.Pose : Constants.Window.Face;
- ChangeWindow(newWindow);
- }
- else
- {
- currentWindowPane.UpdatePanes();
- }
- }
- private void ChangeWindow(Constants.Window window)
- {
- if (selectedWindow == window)
- currentWindowPane.UpdatePanes();
- else
- tabsPane.SelectedTab = window;
- Visible = true;
- }
- }
|