예제 #1
0
        private void SetupControls()
        {
            name             = "ServiceRestrictionTitlebar";
            isVisible        = false;
            canFocus         = true;
            isInteractive    = true;
            relativePosition = Vector3.zero;
            width            = parent.width;
            height           = 40f;

            DragHandle                  = AddUIComponent <UIDragHandle>();
            DragHandle.height           = height;
            DragHandle.relativePosition = Vector3.zero;
            DragHandle.target           = parent;
            DragHandle.eventMouseUp    += (c, e) =>
            {
                ServiceRestrictionsMod.Settings.PanelX = parent.relativePosition.x;
                ServiceRestrictionsMod.Settings.PanelY = parent.relativePosition.y;
                ServiceRestrictionsMod.Settings.Save();
            };

            _titleLabel      = AddUIComponent <UILabel>();
            _titleLabel.text =
                $"{CustomizeItExtendedCompatibility.RetrieveBuildingName()} Restrictions";
            _titleLabel.textScale     = 0.9f;
            _titleLabel.isInteractive = false;

            _closeButton                  = AddUIComponent <UIButton>();
            _closeButton.size             = new Vector2(20, 20);
            _closeButton.relativePosition = new Vector3(width - _closeButton.width - 10f, 10f);
            _closeButton.normalBgSprite   = "DeleteLineButton";
            _closeButton.hoveredBgSprite  = "DeleteLineButtonHovered";
            _closeButton.pressedBgSprite  = "DeleteLineButtonPressed";
            _closeButton.eventClick      += (component, param) =>
            {
                if (RestrictedDistrictsPanel.Instance.CampusPanelWrapper != null)
                {
                    RestrictedDistrictsPanel.Instance.CampusPanelWrapper.isVisible = false;
                    UIUtils.DeepDestroy(RestrictedDistrictsPanel.Instance.CampusPanelWrapper);
                }

                if (RestrictedDistrictsPanel.Instance.IndustriesPanelWrapper != null)
                {
                    RestrictedDistrictsPanel.Instance.IndustriesPanelWrapper.isVisible = false;
                    UIUtils.DeepDestroy(RestrictedDistrictsPanel.Instance.IndustriesPanelWrapper);
                }

                if (RestrictedDistrictsPanel.Instance.ParkPanelWrapper != null)
                {
                    RestrictedDistrictsPanel.Instance.ParkPanelWrapper.isVisible = false;
                    UIUtils.DeepDestroy(RestrictedDistrictsPanel.Instance.ParkPanelWrapper);
                }

                ServiceRestrictTool.instance.RestrictedDistrictsPanelWrapper.isVisible = false;
                UIUtils.DeepDestroy(ServiceRestrictTool.instance.RestrictedDistrictsPanelWrapper);
            };
        }
예제 #2
0
        private void SetupCopyButtons()
        {
            Inputs.Add(UIUtils.CreateButton(this, "Copy Options", (component, value) =>
            {
                if (!ServiceRestrictTool.instance.CustomServiceBuildingOptions.TryGetValue(
                        ServiceRestrictTool.instance.SelectedBuildingID, out var options))
                {
                    return;
                }

                Clipboard.CopyOptions(options, ServiceRestrictTool.instance.SelectedBuildingID);
            }, 0.6f));


            var copyButton = Inputs.Find(x => x.name == "Copy OptionsButton");

            if (!ServiceRestrictTool.instance.CustomServiceBuildingOptions.TryGetValue(
                    ServiceRestrictTool.instance.SelectedBuildingID, out var _))
            {
                copyButton.isEnabled = false;
                copyButton.tooltip   = "No Options are present on this building.";
            }

            copyButton.tooltip = "Copies the existing options to the clipboard." + Environment.NewLine +
                                 "This will overwrite any previous copied settings on the clipboard.";


            Inputs.Add(UIUtils.CreateButton(this, "Paste Options", (component, param) =>
            {
                if (Clipboard.CopiedOptions == null)
                {
                    return;
                }

                if (!ServiceRestrictTool.instance.CustomServiceBuildingOptions.TryGetValue(
                        ServiceRestrictTool.instance.SelectedBuildingID, out var _))
                {
                    ServiceBuildingOptions newOptions = Clipboard.PasteOptions();

                    ServiceRestrictTool.instance.CustomServiceBuildingOptions.Add(
                        ServiceRestrictTool.instance.SelectedBuildingID, newOptions);
                }
                else
                {
                    var tempOptions = Clipboard.PasteOptions();
                    ServiceRestrictTool.instance.CustomServiceBuildingOptions[
                        ServiceRestrictTool.instance.SelectedBuildingID] = tempOptions;
                }

                foreach (var input in Inputs)
                {
                    if (input is UICheckBox checkbox)
                    {
                        switch (checkbox.name)
                        {
                        case "Areas without a district.":
                            {
                                checkbox.isChecked =
                                    ServiceRestrictTool.instance.CustomServiceBuildingOptions.TryGetValue(
                                        ServiceRestrictTool.instance.SelectedBuildingID, out var props) &&
                                    props.CoveredDistricts.Contains(0);
                            }
                            break;

                        case "aaThisDistrictOnly":
                            {
                                checkbox.isChecked =
                                    ServiceRestrictTool.instance.CustomServiceBuildingOptions.TryGetValue(
                                        ServiceRestrictTool.instance.SelectedBuildingID, out var props) &&
                                    props.CoveredDistricts.Contains(DistrictHelper.RetrieveDistrictIDFromName(
                                                                        DistrictManager.instance.GetDistrictName(
                                                                            DistrictManager.instance.GetDistrict(BuildingManager.instance.m_buildings
                                                                                                                 .m_buffer[ServiceRestrictTool.instance.SelectedBuildingID]
                                                                                                                 .m_position))));
                            }
                            break;

                        default:
                            {
                                checkbox.isChecked =
                                    ServiceRestrictTool.instance.CustomServiceBuildingOptions.TryGetValue(
                                        ServiceRestrictTool.instance.SelectedBuildingID, out var props) &&
                                    props.CoveredDistricts.Contains(
                                        DistrictHelper.RetrieveDistrictIDFromName(checkbox.name));
                            }
                            break;
                        }
                    }
                }
            }, 0.6f));

            var pasteButton = Inputs.Find(x => x.name == "Paste OptionsButton");

            if (Clipboard.CopiedOptions == null)
            {
                pasteButton.isEnabled = false;
                pasteButton.tooltip   = "No Options have been copied yet.";
            }

            pasteButton.tooltip =
                $"Pastes the copied settings from {CustomizeItExtendedCompatibility.RetrieveBuildingName(Clipboard.CopiedBuildingID)} onto this building." +
                Environment.NewLine +
                "This will overwrite this buildings current settings.";
        }