Exemple #1
0
        public void Init(SpecializationPanel parent, SpecializationDescriptor spec, int maxValue)
        {
            this.ParentPanel        = parent;
            this.SpecializationName = spec.Name;

            canAutoManage = spec.CanAutoManageSubSpecializations;
            this.AutoPriorityToggle.gameObject.SetActive(spec.CanAutoManageSubSpecializations);

            if (spec.CanAutoManageSubSpecializations)
            {
                this.AutoPriorityText.gameObject.SetActive(false);
                this.AutoPriorityText.gameObject.AddComponent <TooltipHoverable>().Init("",
                                                                                        Localization.GetText($"Specialization_{spec.Profession}_{spec.Name}_AutoManageTooltip"));
                this.AutoPriorityText.gameObject.SetActive(true);
            }

            this.SpecializationToggle.MaxValue        = maxValue;
            this.SpecializationToggle.ToggleText.text = spec.GetDisplayName();

            if (spec.SubSpecializations.Count == 0)
            {
                SubExpandButton.gameObject.SetActive(false);
                SubCollapseButton.gameObject.SetActive(false);
                AutoPriorityToggle.gameObject.SetActive(false);
            }
            else
            {
                foreach (var sub in spec.SubSpecializations.Values)
                {
                    OrderableToggle subToggle = GameObject.Instantiate(this.SubSpecializationToggleTemplate.gameObject).GetComponent <OrderableToggle>();
                    subToggle.transform.SetParent(this.SubSpecializationsContainer.transform);
                    subToggle.name            = sub.Name;
                    subToggle.ToggleText.text = sub.GetDisplayName();
                    subToggle.MaxValue        = spec.SubSpecializations.Count - 1;
                    subToggle.gameObject.SetActive(true);

                    subToggle.UpButton.onClick.AddListener(() => SubSpecializationToggle_ButtonUpClicked(subToggle));
                    subToggle.DownButton.onClick.AddListener(() => SubSpecializationToggle_ButtonDownClicked(subToggle));
                    subToggle.Toggle.onValueChanged.AddListener((x) => SubSpecializationToggle_ToggleValueChanged(subToggle));
                    subToggle.OrderInput.onValueChanged.AddListener((x) => SubSpecializationToggle_InputValueChanged(subToggle));

                    this.SubSpecToggles.Add(sub.Name, subToggle);
                }

                OrderSubSpecializations();
            }

            this.SpecializationToggle.OrderInput.onValueChanged.AddListener((x) => SpecializationToggle_InputValueChanged());
            this.SpecializationToggle.Toggle.onValueChanged.AddListener((x) => SpecializationToggle_ToggleValueChanged());

            this.SubCollapseButton.onClick.AddListener(SpecializationToggle_CollapseButtonClicked);
            this.SubExpandButton.onClick.AddListener(SpecializationToggle_ExpandButtonClicked);

            this.AutoPriorityToggle.onValueChanged.AddListener(this.AutoManageToggle_ValueChanged);
            this.DistanceInput.onValueChanged.AddListener((x) => this.DistanceInput_ValueChanged());
        }
        private void InitColonistForSpecialization(HumanAI human, string specName,
                                                   SpecializationDescriptor desc,
                                                   Dictionary <string, Specialization> specs)
        {
            if (!specs.ContainsKey(specName))
            {
                specs.Add(specName, desc.ToSpecialization(human,
                                                          specs.Count));
            }
            else
            {
                foreach (var subSpecName in specs[specName].SubSpecializations.Keys.ToArray()
                         .Where(x => !desc.SubSpecializations.Keys.Contains(x)))
                {
                    specs[specName].SubSpecializations.Remove(subSpecName);
                }
            }

            foreach (var subSpecName in desc.SubSpecializations.Keys.ToArray())
            {
                InitColonistForSubSpecialization(human, subSpecName, desc.SubSpecializations[subSpecName], specs[specName]);
            }
        }