private void AddPalette(string errorMsg = null, string oldVal = null) => K45DialogControl.ShowModalPromptText(new K45DialogControl.BindProperties { title = Locale.Get("K45_TLM_ADDPALETTE"), message = (errorMsg + "\n").TrimToNull() + Locale.Get("K45_TLM_ADDPALETTE_PROMPTNAME"), defaultTextFieldContent = oldVal, showButton1 = true, textButton1 = Locale.Get("EXCEPTION_OK"), textButton2 = Locale.Get("CANCEL"), showButton2 = true }, (x, val) => { if (x == 1) { if (val == TLMAutoColorPaletteContainer.PALETTE_RANDOM || !(TLMAutoColorPaletteContainer.GetPalette(val) is null)) { AddPalette(Locale.Get("K45_TLM_ADDPALETTE_ERROR_PALETTEALREADYEXISTS"), val); } else if (val.IsNullOrWhiteSpace()) { AddPalette(Locale.Get("K45_TLM_ADDPALETTE_ERROR_INVALIDNAME"), val); } TLMAutoColorPaletteContainer.AddPalette(val); TLMAutoColorPaletteContainer.Save(val); ReloadData(); m_paletteSelect.selectedValue = val; } return(true); });
private void AddColor() { if (canEdit && GetPaletteName(out string paletteName)) { var palette = TLMAutoColorPaletteContainer.GetPalette(paletteName); palette.Add(); StartCoroutine(SavePalette(paletteName)); } }
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; }
internal static Color CalculateAutoColor(ushort num, TransportSystemDefinition tsdRef, bool avoidRandom = false, bool allowClear = false) { var config = tsdRef.GetConfig(); if (tsdRef.TransportType == TransportInfo.TransportType.EvacuationBus) { return(tsdRef.Color); } bool prefixBased = config.PalettePrefixBased; bool randomOnOverflow = config.PaletteRandomOnOverflow; var pal = new List <string>(); if (num >= 0 && config.Prefix != NamingMode.None) { uint prefix = num / 1000u; ITLMTransportTypeExtension ext = tsdRef.GetTransportExtension(); string tempPal = ext.GetCustomPalette(prefix) ?? string.Empty; if (tempPal != string.Empty) { pal.Add(tempPal); num %= 1000; } else { if (prefix > 0 && prefixBased) { num /= 1000; } else { num %= 1000; } } pal.Add(config.Palette); } else { pal.Add(config.Palette); } Color c; c = TLMAutoColorPaletteContainer.GetColor(num, pal.ToArray(), randomOnOverflow, avoidRandom); if (c == Color.clear && !allowClear) { c = tsdRef.Color; } return(c); }
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 IEnumerator SavePalette(string paletteName) { if (!canEdit) { yield break; } if (framesCooldownSave > 0) { framesCooldownSave = 3; yield break; } framesCooldownSave = 3; do { yield return(null); framesCooldownSave--; } while (framesCooldownSave > 0); TLMAutoColorPaletteContainer.Save(paletteName); UpdateColorList(TLMAutoColorPaletteContainer.GetColors(paletteName)); }