Ejemplo n.º 1
0
 public ColorSelectDialog(Zone_Stockpile stockpile) : base()
 {
     if (ColorPresets == null)
     {
         ColorPresets = IOUtil.LoadColorPresets();
     }
     this.stockpile            = stockpile;
     this.SelectionColorWidget = new SelectionColorWidget(stockpile.color);
     this.SelectionColorWidget.SelectionChangeListener += this.updateMaterial;
 }
Ejemplo n.º 2
0
 private static void SetColorToSelected(List <SelectionColorWidget> dtos, ColorPresets presetsDto, Color color)
 {
     if (presetsDto != null && presetsDto.HasSelected())
     {
         presetsDto.SetSelectedColor(color);
     }
     else if (dtos.Count > 0)
     {
         foreach (SelectionColorWidget dto in dtos)
         {
             dto.SelectedColor = color;
         }
     }
 }
Ejemplo n.º 3
0
        public void AddColorSelectorWidget(float left, float top, float width, List <SelectionColorWidget> selectionDtos, ColorPresets presetsDto)
        {
            Text.Font = GameFont.Medium;

            Rect colorPickerRect = new Rect(0, 25f, width, ColorPickerTexture.height * width / ColorPickerTexture.width);

            GUI.BeginGroup(new Rect(left, top, width, colorPickerRect.height + 20));
            GUI.color = Color.white;
            if (GUI.RepeatButton(colorPickerRect, ColorPickerTexture, GUI.skin.label))
            {
                SetColorToSelected(selectionDtos, presetsDto, GetColorFromTexture(Event.current.mousePosition, colorPickerRect, ColorPickerTexture));
            }
            GUI.EndGroup();

            Color rgbColor = Color.white;

            if (presetsDto.HasSelected())
            {
                rgbColor = presetsDto.GetSelectedColor();
            }
            else if (selectionDtos.Count > 0)
            {
                rgbColor = selectionDtos[0].SelectedColor;
            }

            GUI.BeginGroup(new Rect(0, colorPickerRect.height + 50f, width, 30f));
            GUI.Label(new Rect(0, 0, 75, 40), "ReColorStockpile.Alpha".Translate());
            rgbColor.a = Widgets.HorizontalSlider(new Rect(90, 0, 150, 20), rgbColor.a, 0, 1);
            GUI.EndGroup();

            GUI.BeginGroup(new Rect(0, colorPickerRect.height + 90f, width, 30f));
            GUI.Label(new Rect(0f, 0f, 10f, 20f), "R");
            string rText = GUI.TextField(new Rect(12f, 1f, 30f, 20f), ColorConvert(rgbColor.r), 3);

            GUI.Label(new Rect(52f, 0f, 10f, 20f), "G");
            string gText = GUI.TextField(new Rect(64f, 1f, 30f, 20f), ColorConvert(rgbColor.g), 3);

            GUI.Label(new Rect(104f, 0f, 10f, 20f), "B");
            string bText = GUI.TextField(new Rect(116f, 1f, 30f, 20f), ColorConvert(rgbColor.b), 3);

            GUI.Label(new Rect(156f, 0f, 10f, 20f), "A");
            string aText = GUI.TextField(new Rect(168f, 1f, 30f, 20f), ColorConvert(rgbColor.a), 3);

            GUI.EndGroup();

            GUI.BeginGroup(new Rect(0, colorPickerRect.height + 130, width, 120));
            GUI.Label(new Rect(0, 0, 100, 30), "Presets:");
            bool  skipRGB = false;
            float l       = 0;

            for (int i = 0; i < presetsDto.Count; ++i)
            {
                GUI.color = presetsDto[i];
                l        += ColorPresetTexture.width + 4;
                Rect presetRect = new Rect(l, 32, ColorPresetTexture.width, ColorPresetTexture.height);
                GUI.Label(presetRect, new GUIContent(ColorPresetTexture, "ReColorStockpile.ColorPresetHelp".Translate()));
                if (Widgets.ButtonInvisible(presetRect, false))
                {
                    if (Event.current.shift)
                    {
                        if (presetsDto.IsSelected(i))
                        {
                            presetsDto.Deselect();
                        }
                        else
                        {
                            if (selectionDtos.Count > 0 &&
                                !presetsDto.HasSelected())
                            {
                                presetsDto.SetColor(i, selectionDtos[0].SelectedColor);
                            }
                            presetsDto.SetSelected(i);
                        }
                    }
                    else
                    {
                        SetColorToSelected(selectionDtos, null, presetsDto[i]);
                    }
                    skipRGB = true;
                }
                GUI.color = Color.white;
                if (presetsDto.IsSelected(i))
                {
                    Widgets.DrawBox(presetRect, 1);
                }
            }
            GUI.Label(new Rect(0, 30 + ColorPresetTexture.height + 2, width, 60), GUI.tooltip);
            GUI.EndGroup();

            if (!skipRGB &&
                (selectionDtos.Count > 0 || presetsDto.HasSelected()))
            {
                Color c = Color.white;
                c.r = ColorConvert(rText);
                c.g = ColorConvert(gText);
                c.b = ColorConvert(bText);
                c.a = ColorConvert(aText);

                SetColorToSelected(selectionDtos, presetsDto, c);
            }
        }