Пример #1
0
        public static void AddColorSelectorWidget(float left, float top, float width, List <SelectionColorWidgetDTO> selectionDtos, ColorPresetsDTO presetsDto)
        {
            Text.Font = GameFont.Medium;

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

            GUI.BeginGroup(new Rect(left, top, width, 220));

            GUI.color = Color.white;
            if (GUI.RepeatButton(colorPickerRect, colorPickerTexture, GUI.skin.label))
            {
                SetColorToSelected(selectionDtos, presetsDto, GetColorFromTexture(Event.current.mousePosition, colorPickerRect, colorFinder));
            }

            Color originalRgb = Color.white;
            Color rgb         = Color.white;

            if (presetsDto != null && presetsDto.HasSelected() == true)
            {
                rgb = presetsDto.GetSelectedColor();
            }
            else if (selectionDtos.Count > 0)
            {
                rgb = selectionDtos[0].SelectedColor;
            }
            HSL hsl = new HSL();

            Color.RGBToHSV(rgb, out hsl.h, out hsl.s, out hsl.l);
            Copy(rgb, originalRgb);
            HSL originalHsl = new HSL(hsl);

            GUI.BeginGroup(new Rect(width - 135, 0, 200, 200));
            rgb.r = Widgets.HorizontalSlider(new Rect(0, 15, 125f, 20f), rgb.r, 0, 1, false, null, "R", ((int)(rgb.r * 255)).ToString());
            rgb.g = Widgets.HorizontalSlider(new Rect(0, 45, 125f, 20f), rgb.g, 0, 1, false, null, "ChangeMirror.G".Translate(), ((int)(rgb.g * 255)).ToString());
            rgb.b = Widgets.HorizontalSlider(new Rect(0, 75, 125f, 20f), rgb.b, 0, 1, false, null, "ChangeMirror.B".Translate(), ((int)(rgb.b * 255)).ToString());
            hsl.h = Widgets.HorizontalSlider(new Rect(0, 105, 125f, 20f), hsl.h, 0, 1, false, null, "ChangeMirror.H".Translate(), ((int)(hsl.h * 255)).ToString());
            hsl.s = Widgets.HorizontalSlider(new Rect(0, 135, 125f, 20f), hsl.s, 0, 1, false, null, "ChangeMirror.S".Translate(), ((int)(hsl.s * 255)).ToString());
            hsl.l = Widgets.HorizontalSlider(new Rect(0, 175, 125f, 20f), hsl.l, 0, 1, false, null, "ChangeMirror.L".Translate(), ((int)(hsl.l * 255)).ToString());
            GUI.EndGroup();

            bool skipRGB = false;

            if (presetsDto != null)
            {
                for (int row = 0; row < ColorPresetsDTO.ROWS; ++row)
                {
                    float l = 0;
                    GUI.BeginGroup(new Rect(0, colorPickerRect.yMax + row * ColorPreset.height, (ColorPreset.width + 4) * ColorPresetsDTO.COLUMNS, ColorPreset.height + 5));
                    for (int col = 0; col < ColorPresetsDTO.COLUMNS; ++col)
                    {
                        int i = row * ColorPresetsDTO.COLUMNS + col;
                        GUI.color = presetsDto[i];

                        l += ColorPreset.width + 4;
                        Rect presetRect = new Rect(l, 0f, ColorPreset.width, ColorPreset.height);
                        GUI.Label(presetRect, new GUIContent(ColorPreset,
                                                             "ChangeMirror.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.EndGroup();
                }
            }
            GUI.EndGroup();

            if (!skipRGB &&
                (selectionDtos.Count > 0 || presetsDto.HasSelected()))
            {
                if (hsl != originalHsl)
                {
                    rgb = Color.HSVToRGB(hsl.h, hsl.s, hsl.l);
                }
                if (rgb != originalRgb)
                {
                    SetColorToSelected(selectionDtos, presetsDto, rgb);
                }
            }
            Text.Anchor = TextAnchor.UpperLeft;
        }
Пример #2
0
        public static void AddColorSelectorV2Widget(float left, float top, float width, List <SelectionColorWidgetDTO> selectionDtos, ColorPresetsDTO presetsDto)
        {
            Text.Font = GameFont.Medium;

            GUI.BeginGroup(new Rect(left, top, width, 225));

            GUI.color = Color.white;

            Color originalRgb = Color.white;
            Color rgb         = Color.white;

            if (presetsDto.HasSelected())
            {
                rgb = presetsDto.GetSelectedColor();
            }
            else if (selectionDtos.Count > 0)
            {
                rgb = selectionDtos[0].SelectedColor;
            }
            HSL hsl = new HSL();

            Color.RGBToHSV(rgb, out hsl.h, out hsl.s, out hsl.l);
            Copy(rgb, originalRgb);
            HSL originalHsl = new HSL(hsl);

            rgb.r = Widgets.HorizontalSlider(new Rect(0f, 20f, 125f, 20f), rgb.r, 0, 1, false, null, "ChangeMirror.R".Translate(), ((int)(rgb.r * 255)).ToString());
            rgb.g = Widgets.HorizontalSlider(new Rect(0f, 55f, 125f, 20f), rgb.g, 0, 1, false, null, "ChangeMirror.G".Translate(), ((int)(rgb.g * 255)).ToString());
            rgb.b = Widgets.HorizontalSlider(new Rect(0f, 90f, 125f, 20f), rgb.b, 0, 1, false, null, "ChangeMirror.B".Translate(), ((int)(rgb.b * 255)).ToString());
            hsl.h = Widgets.HorizontalSlider(new Rect(0f, 125f, 125f, 20f), hsl.h, 0, 1, false, null, "ChangeMirror.H".Translate(), ((int)(hsl.h * 255)).ToString());
            hsl.s = Widgets.HorizontalSlider(new Rect(0f, 160f, 125f, 20f), hsl.s, 0, 1, false, null, "ChangeMirror.S".Translate(), ((int)(hsl.s * 255)).ToString());
            hsl.l = Widgets.HorizontalSlider(new Rect(0f, 195f, 125f, 20f), hsl.l, 0, 1, false, null, "ChangeMirror.L".Translate(), ((int)(hsl.l * 255)).ToString());

            bool  skipRGB = false;
            float l       = 150f;

            for (int i = 0; i < presetsDto.Count; ++i)
            {
                GUI.color = presetsDto[i];

                l += ColorPreset.width + 4;
                Rect presetRect = new Rect(l, 90f, ColorPreset.width, ColorPreset.height);
                GUI.Label(presetRect, new GUIContent(ColorPreset,
                                                     "ChangeMirror.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.EndGroup();

            if (!skipRGB &&
                (selectionDtos.Count > 0 || presetsDto.HasSelected()))
            {
                if (hsl != originalHsl)
                {
                    rgb = Color.HSVToRGB(hsl.h, hsl.s, hsl.l);
                }
                if (rgb != originalRgb)
                {
                    SetColorToSelected(selectionDtos, presetsDto, rgb);
                }
            }
            Text.Anchor = TextAnchor.UpperLeft;
        }
Пример #3
0
 public HSL(HSL hsl)
 {
     this.h = hsl.h;
     this.s = hsl.s;
     this.l = hsl.l;
 }