Esempio n. 1
0
        public void ReloadData()
        {
            var layers = m_layers.SetItemCount(EditingInstancePreview?.TextDescriptors?.Count ?? 0);

            IBridgeADR.AdrHighwayParameters parameters = null;
            if (layers.Length > 0)
            {
                parameters = WriteTheSignsMod.Controller.ConnectorADR.GetHighwayTypeData(EditingInstancePreview.SaveName);
            }
            for (var i = 0; i < layers.Length; i++)
            {
                var desc  = EditingInstancePreview.TextDescriptors[i];
                var layer = m_layers.items[i];
                layer.relativePosition = desc.OffsetUV - new Vector2(desc.PivotUV.x * desc.OffsetUV.x, desc.PivotUV.y * desc.OffsetUV.y);
                var texture = desc.IsSpriteText()
                    ? desc.m_spriteParam?.GetCurrentSpriteInfo(null)?.texture
                    : desc.GetTargetText(parameters, out string text)
                        ? (FontServer.instance[desc.m_overrideFont] ?? FontServer.instance[WTSEtcData.Instance.FontSettings.GetTargetFont(desc.m_fontClass)] ?? FontServer.instance[WTSEtcData.Instance.FontSettings.GetTargetFont(FontClass.HighwayShields)] ?? FontServer.instance[WTSController.DEFAULT_FONT_KEY])
                              .DrawTextToTexture(text, desc.m_charSpacingFactor)
                        : null;
                if (texture is null)
                {
                    layer.texture = null;
                    continue;
                }
                var area = desc.GetAreaSize(m_bg.width, m_bg.height, texture.width, texture.height);
                layer.texture = texture;

                switch (desc.ColoringConfig.ColorSource)
                {
                case BoardTextDescriptorGeneralXml.ColoringSettings.ColoringSource.Fixed:
                    layer.color = desc.ColoringConfig.m_cachedColor;
                    break;

                case BoardTextDescriptorGeneralXml.ColoringSettings.ColoringSource.Contrast:
                    layer.color = EditingInstancePreview.BackgroundColor.ContrastColor();
                    break;

                case BoardTextDescriptorGeneralXml.ColoringSettings.ColoringSource.Parent:
                    layer.color = EditingInstancePreview.BackgroundColor;
                    break;
                }
                layer.area = area;
                layer.transform.localScale = Vector3.one;
            }
            if (EditingInstancePreview != null)
            {
                m_bg.texture = EditingInstancePreview.BackgroundImageParameter?.GetCurrentSpriteInfo(null)?.texture;
                m_bg.color   = EditingInstancePreview.BackgroundColor;
            }
            else
            {
                m_bg.texture = null;
            }
        }
        private void Awake()
        {
            parent = GetComponentInParent <UIComponent>();
            var group6 = new UIHelperExtension(parent.GetComponentInChildren <UIScrollablePanel>());

            ((UIScrollablePanel)group6.Self).autoLayoutDirection = LayoutDirection.Horizontal;
            ((UIScrollablePanel)group6.Self).wrapLayout          = true;
            ((UIScrollablePanel)group6.Self).width = 730;

            group6.AddLabel(Locale.Get("K45_TLM_CUSTOM_PALETTE_CONFIG"));
            group6.AddSpace(15);

            FileInfo fiPalette = FileUtils.EnsureFolderCreation(TLMController.PalettesFolder);

            group6.AddLabel(Locale.Get("K45_TLM_PALETTE_FOLDER_LABEL") + ":");
            var namesFilesButton = ((UIButton)group6.AddButton("/", () => ColossalFramework.Utils.OpenInFileBrowser(fiPalette.FullName)));

            namesFilesButton.textColor = Color.yellow;
            KlyteMonoUtils.LimitWidthAndBox(namesFilesButton, 710);
            namesFilesButton.text = fiPalette.FullName + Path.DirectorySeparatorChar;
            ((UIButton)group6.AddButton(Locale.Get("K45_TLM_RELOAD_PALETTES"), delegate()
            {
                TLMAutoColorPaletteContainer.Reload();
                ReloadData();
                OnPaletteReloaded?.Invoke();
            })).width = 710;

            UIPanel m_listColorContainer = null;

            m_paletteSelect = group6.AddDropdown(Locale.Get("K45_TLM_PALETTE_VIEW"), TLMAutoColorPaletteContainer.PaletteListForEditing, 0, delegate(int sel)
            {
                if (sel <= 0 || sel >= TLMAutoColorPaletteContainer.PaletteListForEditing.Length)
                {
                    m_listColorContainer?.Disable();
                    m_colorFieldTemplateListColors?.SetItemCount(0);
                }
                else
                {
                    m_listColorContainer?.Enable();
                    UpdateColorList(TLMAutoColorPaletteContainer.GetColors(TLMAutoColorPaletteContainer.PaletteListForEditing[sel]));
                }
            }) as UIDropDown;
            m_paletteSelect.GetComponentInParent <UIPanel>().width = 720;
            m_paletteSelect.GetComponentInParent <UIPanel>().autoLayoutDirection = LayoutDirection.Horizontal;
            m_paletteSelect.GetComponentInParent <UIPanel>().wrapLayout          = true;
            m_paletteSelect.width = 710;

            KlyteMonoUtils.CreateUIElement(out m_listColorContainer, group6.Self.transform, "listColors", new UnityEngine.Vector4(0, 0, group6.Self.width, group6.Self.height - 250));
            KlyteMonoUtils.CreateScrollPanel(m_listColorContainer, out m_colorListScroll, out _, m_listColorContainer.width - 20, m_listColorContainer.height);
            m_colorListScroll.backgroundSprite    = "OptionsScrollbarTrack";
            m_colorListScroll.autoLayout          = true;
            m_colorListScroll.autoLayoutDirection = LayoutDirection.Horizontal;
            m_colorListScroll.wrapLayout          = true;
        }
Esempio n. 3
0
 public void FixTabstrip()
 {
     m_tabs.SetItemCount(EditingInstance?.TextDescriptors?.Length ?? 0);
     for (int i = 0; i < (EditingInstance?.TextDescriptors?.Length ?? 0); i++)
     {
         var but = m_tabs.items[i];
         if (but.stringUserData.IsNullOrWhiteSpace())
         {
             but.eventClicked  += (x, y) => OnTabChange(x.zOrder + 1);
             but.stringUserData = "A";
         }
         but.text = EditingInstance.TextDescriptors[i]?.SaveName ?? "<EMPTY NAME>";
     }
 }
        private void UpdateColorList(List <Color32> colors)
        {
            UIPanel[] colorPickers = m_colorFieldTemplateListColors.SetItemCount(colors.Count);

            for (int i = 0; i < colors.Count; i++)
            {
                UIColorField colorField = colorPickers[i].GetComponentInChildren <UIColorField>();
                if (canEdit && colorField.objectUserData == null)
                {
                    colorField.colorPicker = KlyteMonoUtils.GetDefaultPicker();
                    colorField.eventSelectedColorReleased += (x, y) =>
                    {
                        if (GetPaletteName(out string paletteName))
                        {
                            var palette  = TLMAutoColorPaletteContainer.GetPalette(paletteName);
                            var selColor = ((UIColorField)x).selectedColor;
                            palette[x.parent.zOrder] = selColor;
                            if (selColor == default)
                            {
                                ((UIColorField)x).isVisible = false;
                                ((UIColorField)x).OnDisable();
                            }
                            StartCoroutine(SavePalette(paletteName));
                        }
                    };
                    colorField.eventColorPickerOpen += KlyteMonoUtils.DefaultColorPickerHandler;
                    colorField.objectUserData        = true;
                }
                (colorField.triggerButton as UILabel).text              = $"{i.ToString("0")}";
                (colorField.triggerButton as UILabel).textColor         = KlyteMonoUtils.ContrastColor(colors[i]);
                (colorField.triggerButton as UILabel).disabledTextColor = KlyteMonoUtils.ContrastColor(colors[i]);
                colorField.selectedColor = colors[i];
                colorField.isVisible     = true;
            }
            if (canEdit)
            {
                m_addColor.zOrder = 99999999;
            }
        }
 private void UpdateColorList(ref VehicleCityDataRuleXml reference)
 {
     UIPanel[] colorPickers = m_colorFieldTemplateListColors.SetItemCount(reference.m_colorList.Count);
     m_isLoadingColors = true;
     for (int i = 0; i < reference.m_colorList.Count; i++)
     {
         UIColorField colorField = colorPickers[i].GetComponentInChildren <UIColorField>();
         if (colorField.objectUserData == null)
         {
             colorField.eventSelectedColorChanged += (x, y) =>
                                                     SafeObtain((ref VehicleCityDataRuleXml z) =>
             {
                 if (!m_isLoadingColors && z.m_colorList.Count > x.parent.zOrder)
                 {
                     m_isLoadingColors = true;
                     if (y == default)
                     {
                         z.m_colorList.RemoveAt(x.parent.zOrder);
                         UpdateColorList(ref z);
                     }
                     else
                     {
                         z.m_colorList[x.parent.zOrder] = y;
                     }
                     BuildingManager.instance.UpdateBuildingColors();
                     m_isLoadingColors = false;
                 }
             });
             colorField.eventColorPickerOpen += KlyteMonoUtils.DefaultColorPickerHandler;
             colorField.objectUserData        = true;
         }
         colorField.selectedColor = reference.m_colorList[i];
     }
     m_addColor.zOrder = 99999999;
     m_isLoadingColors = false;
 }
Esempio n. 6
0
        public void OnSetTarget(Type source)
        {
            if (source == GetType())
            {
                return;
            }

            TransportSystemDefinition tsd = TransportSystem;

            if (!tsd.HasVehicles())
            {
                MainPanel.isVisible = false;
                return;
            }
            m_isLoading = true;

            var           lineId        = GetLineID();
            List <ushort> cityDepotList = TLMDepotUtils.GetAllDepotsFromCity(tsd);

            Interfaces.IBasicExtension config = TLMLineUtils.GetEffectiveExtensionForLine(lineId);
            List <ushort> targetDepotList     = config.GetAllowedDepots(tsd, lineId);

            UIPanel[] depotChecks = m_checkboxTemplateList.SetItemCount(cityDepotList.Count);
            LogUtils.DoLog($"depotChecks = {depotChecks.Length}");
            for (int idx = 0; idx < cityDepotList.Count; idx++)
            {
                ushort     buildingID = cityDepotList[idx];
                UICheckBox uiCheck    = depotChecks[idx].GetComponentInChildren <UICheckBox>();
                uiCheck.objectUserData = buildingID;
                uiCheck.isChecked      = targetDepotList.Contains(buildingID);

                UILabel uilabel = uiCheck.label;

                uilabel.prefix = BuildingUtils.GetBuildingName(buildingID, out _, out _);
                ref Building depotBuilding = ref BuildingManager.instance.m_buildings.m_buffer[buildingID];
                Vector3      sidewalk      = depotBuilding.CalculateSidewalkPosition();
                TransportLinesManagerMod.Controller.ConnectorADR.GetAddressStreetAndNumber(sidewalk, depotBuilding.m_position, out int number, out string streetName);
                byte districtId = DistrictManager.instance.GetDistrict(sidewalk);
                uilabel.text = $"\n<color gray>{streetName}, {number} - {(districtId == 0 ? SimulationManager.instance.m_metaData.m_CityName : DistrictManager.instance.GetDistrictName(districtId))}</color>";



                if (uilabel.objectUserData == null)
                {
                    uiCheck.eventCheckChanged += (x, y) =>
                    {
                        if (!m_isLoading)
                        {
                            if (y)
                            {
                                TLMLineUtils.GetEffectiveExtensionForLine(UVMPublicTransportWorldInfoPanel.GetLineID()).AddDepotForLine(UVMPublicTransportWorldInfoPanel.GetLineID(), (ushort)x.objectUserData);
                            }
                            else
                            {
                                TLMLineUtils.GetEffectiveExtensionForLine(UVMPublicTransportWorldInfoPanel.GetLineID()).RemoveDepotForLine(UVMPublicTransportWorldInfoPanel.GetLineID(), (ushort)x.objectUserData);
                            }
                        }
                    };
                    KlyteMonoUtils.LimitWidthAndBox(uiCheck.label, 280, true);
                    UIButton gotoButton = depotChecks[idx].Find <UIButton>("GoTo");
                    gotoButton.eventClick += delegate(UIComponent c, UIMouseEventParameter r)
                    {
                        ushort buildingId = (ushort)uiCheck.objectUserData;
                        if (buildingId != 0)
                        {
                            Vector3 position = BuildingManager.instance.m_buildings.m_buffer[buildingId].m_position;
                            ToolsModifierControl.cameraController.SetTarget(new InstanceID()
                            {
                                Building = buildingId
                            }, position, true);
                        }
                    };
                    uilabel.objectUserData = true;
                }
            }
        public void OnSetTarget(Type source)
        {
            if (source == GetType())
            {
                return;
            }

            TransportSystemDefinition tsd = TransportSystem;

            if (!tsd.HasVehicles())
            {
                MainPanel.isVisible = false;
                return;
            }
            m_isLoading = true;
            LogUtils.DoLog("tsd = {0}", tsd);
            IBasicExtension config = TLMLineUtils.GetEffectiveExtensionForLine(GetLineID());

            if (TransportSystem != m_lastSystem)
            {
                m_defaultAssets = tsd.GetTransportExtension().GetAllBasicAssetsForLine(0);
                UIPanel[] depotChecks = m_checkboxTemplateList.SetItemCount(m_defaultAssets.Count);

                LogUtils.DoLog("m_defaultAssets Size = {0} ({1})", m_defaultAssets?.Count, string.Join(",", m_defaultAssets.Keys?.ToArray() ?? new string[0]));
                for (int i = 0; i < m_defaultAssets.Count; i++)
                {
                    string     assetName = m_defaultAssets.Keys.ElementAt(i);
                    UICheckBox checkbox  = depotChecks[i].GetComponentInChildren <UICheckBox>();
                    checkbox.objectUserData = assetName;
                    UITextField capacityEditor = depotChecks[i].GetComponentInChildren <UITextField>();
                    capacityEditor.text = VehicleUtils.GetCapacity(PrefabCollection <VehicleInfo> .FindLoaded(assetName)).ToString("0");
                    if (checkbox.label.objectUserData == null)
                    {
                        checkbox.eventCheckChanged += (x, y) =>
                        {
                            if (m_isLoading)
                            {
                                return;
                            }

                            ushort          lineId    = GetLineID();
                            IBasicExtension extension = TLMLineUtils.GetEffectiveExtensionForLine(lineId);

                            LogUtils.DoLog($"checkbox event: {x.objectUserData} => {y} at {extension}[{lineId}]");
                            if (y)
                            {
                                extension.AddAssetToLine(lineId, x.objectUserData.ToString());
                            }
                            else
                            {
                                extension.RemoveAssetFromLine(lineId, x.objectUserData.ToString());
                            }
                        };
                        CreateModelCheckBox(checkbox);
                        KlyteMonoUtils.LimitWidthAndBox(checkbox.label, 280);
                        capacityEditor.eventTextSubmitted += CapacityEditor_eventTextSubmitted;;

                        capacityEditor.eventMouseEnter += (x, y) =>
                        {
                            m_lastInfo = PrefabCollection <VehicleInfo> .FindLoaded(checkbox.objectUserData.ToString());

                            RedrawModel();
                        };
                        checkbox.label.objectUserData = true;
                    }
                    checkbox.text = m_defaultAssets[assetName];
                }
                m_lastSystem = TransportSystem;
            }
            else
            {
                List <string> allowedAssets = config.GetAssetListForLine(GetLineID());
                for (int i = 0; i < m_checkboxTemplateList.items.Count; i++)
                {
                    UICheckBox checkbox = m_checkboxTemplateList.items[i].GetComponentInChildren <UICheckBox>();
                    checkbox.isChecked = allowedAssets.Contains(checkbox.objectUserData.ToString());
                }
            }

            if (TransportLinesManagerMod.DebugMode)
            {
                List <string> allowedAssets = config.GetAssetListForLine(GetLineID());
                LogUtils.DoLog($"selectedAssets Size = {allowedAssets?.Count} ({ string.Join(",", allowedAssets?.ToArray() ?? new string[0])}) {config?.GetType()}");
            }

            if (config is TLMTransportLineConfiguration)
            {
                m_title.text = string.Format(Locale.Get("K45_TLM_ASSET_SELECT_WINDOW_TITLE"), TLMLineUtils.GetLineStringId(GetLineID()));
            }
            else
            {
                int prefix = (int)TLMPrefixesUtils.GetPrefix(GetLineID());
                m_title.text = string.Format(Locale.Get("K45_TLM_ASSET_SELECT_WINDOW_TITLE_PREFIX"), prefix > 0 ? NumberingUtils.GetStringFromNumber(TLMPrefixesUtils.GetStringOptionsForPrefix(tsd), prefix + 1) : Locale.Get("K45_TLM_UNPREFIXED"), tsd.GetTransportName());
            }

            m_isLoading = false;
        }