Пример #1
0
        public override void OnUpdate(float realTimeDelta, float simulationTimeDelta)
        {
            base.OnUpdate(realTimeDelta, simulationTimeDelta);

            if (!LoadingExtension._isDoneLoading)
            {
                return;
            }

            if (Input.GetKeyUp(KeyCode.Escape))
            {
                if (UiPanelWrapper.Instance != null && UiPanelWrapper.Instance.isVisible)
                {
                    UiPanelWrapper.Instance.isVisible = false;
                    UiUtils.DeepDestroy(UiPanelWrapper.Instance);
                    return;
                }

                if (UIWarehousePanelWrapper.Instance != null && UIWarehousePanelWrapper.Instance.isVisible)
                {
                    UIWarehousePanelWrapper.Instance.isVisible = false;
                    UiUtils.DeepDestroy(UIWarehousePanelWrapper.Instance);
                }

                if (UIUniqueFactoryPanelWrapper.Instance != null && UIUniqueFactoryPanelWrapper.Instance.isVisible)
                {
                    UIUniqueFactoryPanelWrapper.Instance.isVisible = false;

                    UiUtils.DeepDestroy(UIUniqueFactoryPanelWrapper.Instance);
                }
            }
        }
Пример #2
0
        private void AddBuildingInformationButton(WorldInfoPanel infoPanel, out UIButton button, Vector3 offset)
        {
            button = UiUtils.CreateToggleButton(ZoneBuildingPanel.component, offset, UIAlignAnchor.BottomLeft,
                                                (comp, e) =>
            {
                InstanceID instanceID = InstanceHelper.GetInstanceID(infoPanel);

                var building = BuildingManager.instance.m_buildings.m_buffer[instanceID.Building].Info;
                try
                {
                    if (ZonedBuildingPanelWrapper == null || building != CurrentSelectedBuilding)
                    {
                        ZonedBuildingPanelWrapper = building.GenerateBuildingInformation();
                    }
                    else
                    {
                        ZonedBuildingPanelWrapper.isVisible = false;
                        UiUtils.DeepDestroy(ZonedBuildingPanelWrapper);
                    }
                }
                catch (Exception ex)
                {
                    Debug.Log($"{ex.Message} - {ex.StackTrace}");
                }

                if (comp.hasFocus)
                {
                    comp.Unfocus();
                }
            });
        }
Пример #3
0
        private void AddDefaultBuildingPropertiesButton(WorldInfoPanel infoPanel, out UIButton button, Vector3 offset)
        {
            button = UiUtils.CreateToggleButton(infoPanel.component, offset, UIAlignAnchor.BottomLeft,
                                                (comp, e) =>
            {
                PanelType = InfoPanelType.Default;

                InstanceID instanceID = InstanceHelper.GetInstanceID(infoPanel);

                var building = BuildingManager.instance.m_buildings.m_buffer[instanceID.Building].Info;
                try
                {
                    if (CustomizeItExtendedPanel == null || building != CurrentSelectedBuilding)
                    {
                        CustomizeItExtendedPanel = building.GenerateCustomizeItExtendedPanel();
                    }
                    else
                    {
                        CustomizeItExtendedPanel.isVisible = false;
                        UiUtils.DeepDestroy(CustomizeItExtendedPanel);
                    }
                }
                catch (Exception ex)
                {
                    Debug.Log($"{ex.Message} - {ex.StackTrace}");
                }

                if (comp.hasFocus)
                {
                    comp.Unfocus();
                }
            });
        }
        private void AddButton(CitizenWorldInfoPanel infoPanel, out UIButton button, Vector3 offSet)
        {
            button = UiUtils.CreateToggleButton(infoPanel.component, offSet, UIAlignAnchor.BottomLeft, (component, e) =>
            {
                InstanceID instanceID = InstanceHelper.GetInstanceID(infoPanel);

                var citizen = CitizenManager.instance.m_citizens.m_buffer[instanceID.Citizen];

                try
                {
                    if (CitizenPanelWrapper == null || instanceID.Citizen != SelectedCitizen)
                    {
                        CitizenPanelWrapper = citizen.GenerateCitizenPanel(instanceID.Citizen);
                    }
                    else
                    {
                        CitizenPanelWrapper.isVisible = false;
                        UiUtils.DeepDestroy(CitizenPanelWrapper);
                    }
                }
                catch (Exception ex)
                {
                    Debug.Log($"{ex.Message} - {ex.StackTrace}");
                }

                if (component.hasFocus)
                {
                    component.Unfocus();
                }
            });
        }
Пример #5
0
        private void AddVehicleCustomizeButton(VehicleWorldInfoPanel infoPanel, out UIButton button, Vector3 offset)
        {
            button = UiUtils.CreateToggleButton(infoPanel.component, offset, UIAlignAnchor.BottomLeft, (component, e) =>
            {
                InstanceID instanceID = InstanceHelper.GetInstanceID(infoPanel);

                SelectedInstanceID = instanceID;

                var vehicle = VehicleManager.instance.m_vehicles.m_buffer[instanceID.Vehicle].Info;

                try
                {
                    if (VehiclePanelWrapper == null || vehicle != SelectedVehicle)
                    {
                        VehiclePanelWrapper = vehicle.GenerateVehiclePanel();
                    }
                    else
                    {
                        VehiclePanelWrapper.isVisible = false;
                        UiUtils.DeepDestroy(VehiclePanelWrapper);
                    }
                }
                catch (Exception ex)
                {
                    Debug.Log($"{ex.Message} - {ex.StackTrace}");
                }

                if (component.hasFocus)
                {
                    component.Unfocus();
                }
            });
        }
        public override void Update()
        {
            base.Update();

            var instanceID = (InstanceID)CustomizeItExtendedCitizenTool.instance.CitizenWorldInfoPanel.GetType()
                             .GetField("m_InstanceID", BindingFlags.Instance | BindingFlags.NonPublic)
                             .GetValue(CustomizeItExtendedCitizenTool.instance.CitizenWorldInfoPanel);

            if (instanceID.Citizen != CustomizeItExtendedCitizenTool.instance.SelectedCitizen)
            {
                UiUtils.DeepDestroy(this);
            }
        }
Пример #7
0
        public static UICitizenPanelWrapper GenerateCitizenPanel(this Citizen citizen, uint citizenID)
        {
            try
            {
                CustomizeItExtendedCitizenTool.instance.SelectedCitizen = citizenID;
                UiUtils.DeepDestroy(UIView.Find("CustomizeItExtendedCitizenPanelWrapper"));

                return(UIView.GetAView().AddUIComponent(typeof(UICitizenPanelWrapper)) as UICitizenPanelWrapper);
            }
            catch (Exception e)
            {
                Debug.Log($"{e.Message} - {e.StackTrace}");
                return(null);
            }
        }
        public static UIVehiclePanelWrapper GenerateVehiclePanel(this VehicleInfo info)
        {
            try
            {
                CustomizeItExtendedVehicleTool.instance.SelectedVehicle = info;
                UiUtils.DeepDestroy(UIView.Find("CustomizeItExtendedVehiclePanelWrapper"));

                return(UIView.GetAView().AddUIComponent(typeof(UIVehiclePanelWrapper)) as UIVehiclePanelWrapper);
            }
            catch (Exception e)
            {
                Debug.Log($"{e.Message} - {e.StackTrace}");
                return(null);
            }
        }
Пример #9
0
        public override void Update()
        {
            base.Update();

            var instanceId = (InstanceID)CustomizeItExtendedTool.instance.ZoneBuildingPanel.GetType()
                             .GetField("m_InstanceID", BindingFlags.Instance | BindingFlags.NonPublic)
                             ?.GetValue(CustomizeItExtendedTool.instance.ZoneBuildingPanel);

            var buildingInfo = BuildingManager.instance.m_buildings.m_buffer[instanceId.Building].Info;

            if (buildingInfo != CustomizeItExtendedTool.instance.CurrentSelectedBuilding)
            {
                UiUtils.DeepDestroy(this);
            }
        }
Пример #10
0
        private static void DestroyUIs()
        {
            if (CustomizeItExtendedTool.instance.CustomizeItExtendedPanel != null)
            {
                UiUtils.DeepDestroy(CustomizeItExtendedTool.instance.CustomizeItExtendedPanel);
            }

            if (CustomizeItExtendedTool.instance.UniqueFactoryPanelWrapper != null)
            {
                UiUtils.DeepDestroy(CustomizeItExtendedTool.instance.UniqueFactoryPanelWrapper);
            }

            if (CustomizeItExtendedTool.instance.WarehousePanelWrapper != null)
            {
                UiUtils.DeepDestroy(CustomizeItExtendedTool.instance.WarehousePanelWrapper);
            }
        }
Пример #11
0
        public static UIZonedBuildingPanelWrapper GenerateBuildingInformation(this BuildingInfo info)
        {
            try
            {
                CustomizeItExtendedTool.instance.CurrentSelectedBuilding = info;
                UiUtils.DeepDestroy(UIView.Find("CustomizeItExtendedZonedBuildingPanelWrapper"));

                return(UIView.GetAView().AddUIComponent(typeof(UIZonedBuildingPanelWrapper)) as
                       UIZonedBuildingPanelWrapper);

                ;
            }
            catch (Exception e)
            {
                Debug.Log($"{e.Message} - {e.StackTrace}");
                return(null);
            }
        }
        private void Setup()
        {
            name             = "CustomizeItVehicleExtendedPanel";
            isVisible        = false;
            canFocus         = true;
            isInteractive    = true;
            relativePosition = new Vector3(0f, UiVehicleTitleBar.Instance.height);
            width            = parent.width;

            var fields = SelectedVehicle.GetType().GetFields();

            var fieldsToRetrieve = typeof(CustomVehicleProperties).GetFields().Select(x => x.Name);

            Inputs  = new List <UIComponent>();
            _labels = new List <UILabel>();

            var widestWidth = 0f;

            foreach (var field in fields.Where(x => fieldsToRetrieve.Contains(x.Name)))
            {
                var label = AddUIComponent <UILabel>();
                label.name          = field.Name + "Label";
                label.text          = UiUtils.FieldNames[field.Name];
                label.textScale     = 0.9f;
                label.isInteractive = false;

                if (field.FieldType == typeof(float) || field.FieldType == typeof(int))
                {
                    Inputs.Add(UiUtils.CreateVehicleTextField(this, field.Name));
                    _labels.Add(label);
                }
                else if (field.FieldType == typeof(bool))
                {
                    Inputs.Add(UiUtils.CreateVehicleCheckBox(this, field.Name));
                    _labels.Add(label);
                }

                if (label.width + UiUtils.FieldWidth + UiUtils.FieldMargin * 6 > widestWidth)
                {
                    widestWidth = label.width + UiUtils.FieldWidth + UiUtils.FieldMargin * 6;
                }
            }

            if (!CustomizeItExtendedMod.Settings.OverrideAVO)
            {
                foreach (var input in Inputs)
                {
                    if (!AdvancedVehicleOptionsCompatibilityPatch.IsAVOActive() ||
                        !AdvancedVehicleOptionsCompatibilityPatch.AVOFields.Contains(input.name))
                    {
                        continue;
                    }

                    input.isEnabled     = false;
                    input.isInteractive = false;

                    if (input is UITextField textField)
                    {
                        textField.text = "DISABLED";
                    }

                    if (input is UICheckBox checkbox)
                    {
                        checkbox.enabled       = false;
                        checkbox.isInteractive = false;
                        checkbox.disabledColor = Color.gray;
                    }
                }
            }


            Inputs.Add(UiUtils.CreateNameTextfield(this, "DefaultName", (component, value) =>
            {
                if (!string.IsNullOrEmpty(value))
                {
                    if (CustomizeItExtendedVehicleTool.instance.CustomVehicleNames.TryGetValue(SelectedVehicle.name,
                                                                                               out var props))
                    {
                        props.CustomName  = value;
                        props.DefaultName = true;
                    }
                    else
                    {
                        CustomizeItExtendedVehicleTool.instance.CustomVehicleNames.Add(SelectedVehicle.name,
                                                                                       new NameProperties(value, true));
                    }
                }
                else
                {
                    if (CustomizeItExtendedVehicleTool.instance.CustomVehicleNames.TryGetValue(SelectedVehicle.name,
                                                                                               out var _))
                    {
                        CustomizeItExtendedVehicleTool.instance.CustomVehicleNames.Remove(SelectedVehicle.name);
                    }
                }

                if (!CustomizeItExtendedMod.Settings.SavePerCity)
                {
                    CustomizeItExtendedMod.Settings.Save();
                }
            }, CustomizeItExtendedVehicleTool
                                                   .instance.CustomVehicleNames.TryGetValue(SelectedVehicle.name, out var customName)
                ? customName.CustomName
                : string.Empty));

            var nameLabel = AddUIComponent <UILabel>();

            nameLabel.name          = "DefaultNameLabel";
            nameLabel.text          = "Default Name";
            nameLabel.textScale     = 0.9f;
            nameLabel.isInteractive = false;

            if (nameLabel.width + UiUtils.FieldWidth + UiUtils.FieldMargin * 6 > widestWidth)
            {
                widestWidth = nameLabel.width + UiUtils.FieldWidth + UiUtils.FieldMargin * 6;
            }

            _labels.Add(nameLabel);

            Inputs.Sort((x, y) => x.name.CompareTo(y.name));
            _labels.Sort((x, y) => x.name.CompareTo(y.name));

            Inputs.Add(UiUtils.CreateVehicleResetButton(this));

            Inputs.Add(UiUtils.CreateDropdown(this, "SelectedVehicle", VehicleHelper.GetAllVehicleNames().ToArray(),
                                              (component, value) =>
            {
                var newVehicle = VehicleHelper.GetAllVehicles()
                                 .Find(x =>
                                       x.name == VehicleHelper.RetrieveOriginalVehicleName(((UIDropDown)component).items[value]));


                UiUtils.DeepDestroy(CustomizeItExtendedVehicleTool.instance.VehiclePanelWrapper);
                CustomizeItExtendedVehicleTool.instance.SelectedVehicle = newVehicle;
                newVehicle.GenerateVehiclePanel();
            }, VehicleHelper.RetrieveCurrentVehicleName(SelectedVehicle)));

            width = UIVehiclePanelWrapper.Instance.width =
                UiVehicleTitleBar.Instance.width = UiVehicleTitleBar.Instance.DragHandle.width = widestWidth;
            UiVehicleTitleBar.Instance.RecenterElements();
            Align();

            Inputs.Find(x => x.name == "SelectedVehicle").relativePosition = new Vector3(12,
                                                                                         Inputs.Find(x => x.name == "CustomizeItExtendedVehicleResetButton").relativePosition.y);


            height = Inputs.Count * (UiUtils.FieldHeight + UiUtils.FieldMargin) + UiUtils.FieldMargin * 3;

            UIVehiclePanelWrapper.Instance.height = height + UiVehicleTitleBar.Instance.height;


            UIVehiclePanelWrapper.Instance.relativePosition = new Vector3(CustomizeItExtendedMod.Settings.PanelX,
                                                                          CustomizeItExtendedMod.Settings.PanelY);

            isVisible = UIVehiclePanelWrapper.Instance.isVisible =
                UiVehicleTitleBar.Instance.isVisible = UiVehicleTitleBar.Instance.DragHandle.isVisible = true;
        }