123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181 |
- using UnityEngine;
- using System.Collections.Generic;
- using System.Linq;
- namespace COM3D2.MeidoPhotoStudio.Plugin
- {
- internal class PropsPane : BasePane
- {
- private PropManager propManager;
- private string currentCategory;
- private string SelectedCategory => Constants.DoguCategories[this.doguCategoryDropdown.SelectedItemIndex];
- private Dropdown doguCategoryDropdown;
- private Dropdown doguDropdown;
- private Button addDoguButton;
- private Button nextDoguButton;
- private Button prevDoguButton;
- private Button nextDoguCategoryButton;
- private Button prevDoguCategoryButton;
- private string header;
- private static bool handItemsReady = false;
- private bool itemSelectorEnabled = true;
- public PropsPane(PropManager propManager)
- {
- this.header = Translation.Get("propsPane", "header");
- this.propManager = propManager;
- handItemsReady = Constants.HandItemsInitialized;
- if (!handItemsReady) Constants.MenuFilesChange += InitializeHandItems;
- this.doguCategoryDropdown = new Dropdown(Translation.GetArray("doguCategories", Constants.DoguCategories));
- this.doguCategoryDropdown.SelectionChange += (s, a) => ChangeDoguCategory(SelectedCategory);
- this.doguDropdown = new Dropdown(new[] { string.Empty });
- this.addDoguButton = new Button("+");
- this.addDoguButton.ControlEvent += (s, a) => SpawnObject();
- this.nextDoguButton = new Button(">");
- this.nextDoguButton.ControlEvent += (s, a) => this.doguDropdown.Step(1);
- this.prevDoguButton = new Button("<");
- this.prevDoguButton.ControlEvent += (s, a) => this.doguDropdown.Step(-1);
- this.nextDoguCategoryButton = new Button(">");
- this.nextDoguCategoryButton.ControlEvent += (s, a) => this.doguCategoryDropdown.Step(1);
- this.prevDoguCategoryButton = new Button("<");
- this.prevDoguCategoryButton.ControlEvent += (s, a) => this.doguCategoryDropdown.Step(-1);
- ChangeDoguCategory(SelectedCategory);
- }
- protected override void ReloadTranslation()
- {
- this.header = Translation.Get("propsPane", "header");
- this.doguCategoryDropdown.SetDropdownItems(
- Translation.GetArray("doguCategories", Constants.DoguCategories)
- );
- string category = SelectedCategory;
- string[] translationArray;
- if (category == Constants.customDoguCategories[Constants.DoguCategory.HandItem] && !handItemsReady)
- {
- translationArray = new[] { Translation.Get("systemMessage", "initializing") };
- }
- else
- {
- translationArray = GetTranslations(category);
- }
- doguDropdown.SetDropdownItems(translationArray);
- }
- public override void Draw()
- {
- float arrowButtonSize = 30;
- GUILayoutOption[] arrowLayoutOptions = {
- GUILayout.Width(arrowButtonSize),
- GUILayout.Height(arrowButtonSize)
- };
- float dropdownButtonHeight = arrowButtonSize;
- float dropdownButtonWidth = 120f;
- GUILayoutOption[] dropdownLayoutOptions = new GUILayoutOption[] {
- GUILayout.Height(dropdownButtonHeight),
- GUILayout.Width(dropdownButtonWidth)
- };
- // MiscGUI.Header(this.header);
- // MiscGUI.WhiteLine();
- GUILayout.BeginHorizontal();
- this.prevDoguCategoryButton.Draw(arrowLayoutOptions);
- this.doguCategoryDropdown.Draw(dropdownLayoutOptions);
- this.nextDoguCategoryButton.Draw(arrowLayoutOptions);
- GUILayout.EndHorizontal();
- GUI.enabled = itemSelectorEnabled;
- GUILayout.BeginHorizontal();
- this.doguDropdown.Draw(dropdownLayoutOptions);
- this.prevDoguButton.Draw(arrowLayoutOptions);
- this.nextDoguButton.Draw(arrowLayoutOptions);
- this.addDoguButton.Draw(arrowLayoutOptions);
- GUILayout.EndHorizontal();
- GUI.enabled = true;
- }
- private void InitializeHandItems(object sender, MenuFilesEventArgs args)
- {
- if (args.Type == MenuFilesEventArgs.EventType.HandItems)
- {
- handItemsReady = true;
- string selectedCategory = SelectedCategory;
- if (selectedCategory == Constants.customDoguCategories[Constants.DoguCategory.HandItem])
- {
- ChangeDoguCategory(selectedCategory, true);
- }
- }
- }
- private void ChangeDoguCategory(string category, bool force = false)
- {
- if (category != currentCategory || force)
- {
- currentCategory = category;
- string[] translationArray;
- if (category == Constants.customDoguCategories[Constants.DoguCategory.HandItem] && !handItemsReady)
- {
- translationArray = new[] { Translation.Get("systemMessage", "initializing") };
- itemSelectorEnabled = false;
- }
- else
- {
- translationArray = GetTranslations(category);
- itemSelectorEnabled = true;
- }
- doguDropdown.SetDropdownItems(translationArray, 0);
- }
- }
- private string[] GetTranslations(string category)
- {
- IEnumerable<string> itemList = Constants.DoguDict[category];
- if (category == Constants.customDoguCategories[Constants.DoguCategory.HandItem])
- {
- itemList = itemList.Select(item =>
- {
- string handItemAsOdogu = Utility.HandItemToOdogu(item);
- if (Translation.Has("propNames", handItemAsOdogu)) return handItemAsOdogu;
- else return item;
- });
- }
- string translationCategory = category == Constants.customDoguCategories[Constants.DoguCategory.BGSmall]
- ? "bgNames"
- : "propNames";
- return Translation.GetArray(translationCategory, itemList);
- }
- private void SpawnObject()
- {
- string assetName = Constants.DoguDict[SelectedCategory][this.doguDropdown.SelectedItemIndex];
- if (SelectedCategory == Constants.customDoguCategories[Constants.DoguCategory.BGSmall])
- {
- this.propManager.SpawnBG(assetName);
- }
- else
- {
- this.propManager.SpawnObject(assetName);
- }
- }
- }
- }
|