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 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;
            }
        }