public static Image makePatternThumb(patternDetails pattern, Wrappers.Database db)
        {
            Image temp = null;

                if (pattern.type == "HSV")
                {
                    DdsFileTypePlugin.DdsFile ddsP = new DdsFileTypePlugin.DdsFile();

                    Colours.HSVColor channel1Color = new Colours.HSVColor();
                    Colours.HSVColor channel2Color = new Colours.HSVColor();
                    Colours.HSVColor channel3Color = new Colours.HSVColor();

                    Colours.HSVColor backColor = new Colours.HSVColor(Convert.ToDouble(pattern.HBg, CultureInfo.InvariantCulture) * 360, Convert.ToDouble(pattern.SBg, CultureInfo.InvariantCulture), Convert.ToDouble(pattern.VBg, CultureInfo.InvariantCulture));
                    bool[] channelsEnabled = new bool[3];

                    if (pattern.ChannelEnabled[0] != null && pattern.ChannelEnabled[0].ToLower() == "true")
                    {
                        channel1Color = new Colours.HSVColor(Convert.ToDouble(pattern.H[0], CultureInfo.InvariantCulture) * 360, Convert.ToDouble(pattern.S[0], CultureInfo.InvariantCulture), Convert.ToDouble(pattern.V[0], CultureInfo.InvariantCulture));
                        channelsEnabled[0] = true;
                    }
                    if (pattern.ChannelEnabled[1] != null && pattern.ChannelEnabled[1].ToLower() == "true")
                    {
                        channel2Color = new Colours.HSVColor(Convert.ToDouble(pattern.H[1], CultureInfo.InvariantCulture) * 360, Convert.ToDouble(pattern.S[1], CultureInfo.InvariantCulture), Convert.ToDouble(pattern.V[1], CultureInfo.InvariantCulture));
                        channelsEnabled[1] = true;
                    }
                    if (pattern.ChannelEnabled[2] != null && pattern.ChannelEnabled[2].ToLower() == "true")
                    {
                        channel3Color = new Colours.HSVColor(Convert.ToDouble(pattern.H[2], CultureInfo.InvariantCulture) * 360, Convert.ToDouble(pattern.S[2], CultureInfo.InvariantCulture), Convert.ToDouble(pattern.V[2], CultureInfo.InvariantCulture));
                        channelsEnabled[2] = true;
                    }
                    if (isEmptyMask(pattern.rgbmask))
                    {
                        if (db != null)
                        {
                            temp = Patterns.createHSVPattern(KeyUtils.findKey(new Wrappers.ResourceKey(pattern.BackgroundImage), 2, db), backColor);
                        }
                        else
                        {
                            temp = Patterns.createHSVPattern(KeyUtils.findKey(pattern.BackgroundImage), backColor);
                        }
                    }
                    else
                    {
                        if (db != null)
                        {
                            temp = Patterns.createHSVPattern(KeyUtils.findKey(new Wrappers.ResourceKey(pattern.BackgroundImage), 2, db), KeyUtils.findKey(new Wrappers.ResourceKey(pattern.rgbmask), 2, db), backColor, KeyUtils.findKey(new MadScience.Wrappers.ResourceKey(makeKey(pattern.Channel[0])), 0, db), KeyUtils.findKey(new Wrappers.ResourceKey(makeKey(pattern.Channel[1])), 0, db), KeyUtils.findKey(new Wrappers.ResourceKey(makeKey(pattern.Channel[2])), 0, db), channel1Color, channel2Color, channel3Color, channelsEnabled);
                        }
                        else
                        {
                            temp = Patterns.createHSVPattern(KeyUtils.findKey(pattern.BackgroundImage), KeyUtils.findKey(pattern.rgbmask), backColor, KeyUtils.findKey(makeKey(pattern.Channel[0])), KeyUtils.findKey(makeKey(pattern.Channel[1])), KeyUtils.findKey(makeKey(pattern.Channel[2])), channel1Color, channel2Color, channel3Color, channelsEnabled);
                        }
                    }
                }
                else if (pattern.type == "Coloured")
                {
                    DdsFileTypePlugin.DdsFile ddsP = new DdsFileTypePlugin.DdsFile();
                    Color bgColor = Colours.convertColour(pattern.ColorP[0], true);
                    if (bgColor == Color.Empty)
                    {
                        bgColor = Color.Black;
                    }
                    if (pattern.isCustom)
                    {
                        // We need this in here becuase findKey only searches the game files and any local DDS files - it
                        // doesn't search custom packages
                        if (File.Exists(pattern.customFilename))
                        {
                            Stream patternThumb = KeyUtils.searchForKey(pattern.rgbmask, pattern.customFilename);
                            if (!StreamHelpers.isValidStream(patternThumb))
                            {
                                patternThumb = KeyUtils.searchForKey(pattern.BackgroundImage, pattern.customFilename);
                            }
                            if (StreamHelpers.isValidStream(patternThumb))
                            {
                                ddsP.Load(patternThumb);
                            }
                            patternThumb.Close();
                        }
                    }
                    else
                    {
                        if (db != null)
                        {
                            ddsP.Load(KeyUtils.findKey(new Wrappers.ResourceKey(pattern.rgbmask), 2, db));
                        }
                        else
                        {
                            ddsP.Load(KeyUtils.findKey(pattern.rgbmask));
                        }
                    }
                    temp = ddsP.Image(bgColor, Colours.convertColour(pattern.ColorP[1], true), Colours.convertColour(pattern.ColorP[2], true), Colours.convertColour(pattern.ColorP[3], true), Colours.convertColour(pattern.ColorP[4], true));

                }
                else if (pattern.type == "solidColor")
                {
                    temp = new Bitmap(256,256);
                    using (Graphics g = Graphics.FromImage(temp))
                    {
                        g.FillRectangle(new SolidBrush(Colours.convertColour(pattern.Color)),0,0,256,256);
                    }

                }

            return temp;
        }
예제 #2
0
        private void picHSVColorChannel3_Click(object sender, EventArgs e)
        {
            int patternNo = cmbPatternSelect.SelectedIndex;
            xmlChunkDetails chunk = (xmlChunkDetails)casPartNew.xmlChunk[listView1.SelectedIndices[0]];
            Patterns.patternDetails pDetail = chunk.pattern[patternNo];
            picHSVColorChannel3.BackColor = showColourDialog(picHSVColorChannel3.BackColor);

            Colours.HSVColor hsv = new Colours.HSVColor(picHSVColorChannel3.BackColor);
            hsv.Hue -= Convert.ToDouble(pDetail.BaseH[2], CultureInfo.InvariantCulture) * 360;
            hsv.Saturation -= Convert.ToDouble(pDetail.BaseS[2], CultureInfo.InvariantCulture);
            hsv.Value -= Convert.ToDouble(pDetail.BaseV[2], CultureInfo.InvariantCulture);

            pDetail.H[2] = MadScience.Helpers.numberToString(hsv.Hue / 360);
            pDetail.S[2] = MadScience.Helpers.numberToString(hsv.Saturation);
            pDetail.V[2] = MadScience.Helpers.numberToString(hsv.Value);

            makePatternPreviewThumb();
        }
예제 #3
0
        public static Image makePatternThumb(patternDetails pattern, Wrappers.Database db)
        {
            Image temp = null;

            if (pattern.type == "HSV")
            {
                DdsFileTypePlugin.DdsFile ddsP = new DdsFileTypePlugin.DdsFile();

                Colours.HSVColor channel1Color = new Colours.HSVColor();
                Colours.HSVColor channel2Color = new Colours.HSVColor();
                Colours.HSVColor channel3Color = new Colours.HSVColor();

                Colours.HSVColor backColor       = new Colours.HSVColor(Convert.ToDouble(pattern.HBg, CultureInfo.InvariantCulture) * 360, Convert.ToDouble(pattern.SBg, CultureInfo.InvariantCulture), Convert.ToDouble(pattern.VBg, CultureInfo.InvariantCulture));
                bool[]           channelsEnabled = new bool[3];

                if (pattern.ChannelEnabled[0] != null && pattern.ChannelEnabled[0].ToLower() == "true")
                {
                    channel1Color      = new Colours.HSVColor(Convert.ToDouble(pattern.H[0], CultureInfo.InvariantCulture) * 360, Convert.ToDouble(pattern.S[0], CultureInfo.InvariantCulture), Convert.ToDouble(pattern.V[0], CultureInfo.InvariantCulture));
                    channelsEnabled[0] = true;
                }
                if (pattern.ChannelEnabled[1] != null && pattern.ChannelEnabled[1].ToLower() == "true")
                {
                    channel2Color      = new Colours.HSVColor(Convert.ToDouble(pattern.H[1], CultureInfo.InvariantCulture) * 360, Convert.ToDouble(pattern.S[1], CultureInfo.InvariantCulture), Convert.ToDouble(pattern.V[1], CultureInfo.InvariantCulture));
                    channelsEnabled[1] = true;
                }
                if (pattern.ChannelEnabled[2] != null && pattern.ChannelEnabled[2].ToLower() == "true")
                {
                    channel3Color      = new Colours.HSVColor(Convert.ToDouble(pattern.H[2], CultureInfo.InvariantCulture) * 360, Convert.ToDouble(pattern.S[2], CultureInfo.InvariantCulture), Convert.ToDouble(pattern.V[2], CultureInfo.InvariantCulture));
                    channelsEnabled[2] = true;
                }
                if (isEmptyMask(pattern.rgbmask))
                {
                    if (db != null)
                    {
                        temp = Patterns.createHSVPattern(KeyUtils.findKey(new Wrappers.ResourceKey(pattern.BackgroundImage), 2, db), backColor);
                    }
                    else
                    {
                        temp = Patterns.createHSVPattern(KeyUtils.findKey(pattern.BackgroundImage), backColor);
                    }
                }
                else
                {
                    if (db != null)
                    {
                        temp = Patterns.createHSVPattern(KeyUtils.findKey(new Wrappers.ResourceKey(pattern.BackgroundImage), 2, db), KeyUtils.findKey(new Wrappers.ResourceKey(pattern.rgbmask), 2, db), backColor, KeyUtils.findKey(new MadScience.Wrappers.ResourceKey(makeKey(pattern.Channel[0])), 0, db), KeyUtils.findKey(new Wrappers.ResourceKey(makeKey(pattern.Channel[1])), 0, db), KeyUtils.findKey(new Wrappers.ResourceKey(makeKey(pattern.Channel[2])), 0, db), channel1Color, channel2Color, channel3Color, channelsEnabled);
                    }
                    else
                    {
                        temp = Patterns.createHSVPattern(KeyUtils.findKey(pattern.BackgroundImage), KeyUtils.findKey(pattern.rgbmask), backColor, KeyUtils.findKey(makeKey(pattern.Channel[0])), KeyUtils.findKey(makeKey(pattern.Channel[1])), KeyUtils.findKey(makeKey(pattern.Channel[2])), channel1Color, channel2Color, channel3Color, channelsEnabled);
                    }
                }
            }
            else if (pattern.type == "Coloured")
            {
                DdsFileTypePlugin.DdsFile ddsP = new DdsFileTypePlugin.DdsFile();
                Color bgColor = Colours.convertColour(pattern.ColorP[0], true);
                if (bgColor == Color.Empty)
                {
                    bgColor = Color.Black;
                }
                if (pattern.isCustom)
                {
                    // We need this in here becuase findKey only searches the game files and any local DDS files - it
                    // doesn't search custom packages
                    if (File.Exists(pattern.customFilename))
                    {
                        Stream patternThumb = KeyUtils.searchForKey(pattern.rgbmask, pattern.customFilename);
                        if (!StreamHelpers.isValidStream(patternThumb))
                        {
                            patternThumb = KeyUtils.searchForKey(pattern.BackgroundImage, pattern.customFilename);
                        }
                        if (StreamHelpers.isValidStream(patternThumb))
                        {
                            ddsP.Load(patternThumb);
                        }
                        patternThumb.Close();
                    }
                }
                else
                {
                    if (db != null)
                    {
                        ddsP.Load(KeyUtils.findKey(new Wrappers.ResourceKey(pattern.rgbmask), 2, db));
                    }
                    else
                    {
                        ddsP.Load(KeyUtils.findKey(pattern.rgbmask));
                    }
                }
                temp = ddsP.Image(bgColor, Colours.convertColour(pattern.ColorP[1], true), Colours.convertColour(pattern.ColorP[2], true), Colours.convertColour(pattern.ColorP[3], true), Colours.convertColour(pattern.ColorP[4], true));
            }
            else if (pattern.type == "solidColor")
            {
                temp = new Bitmap(256, 256);
                using (Graphics g = Graphics.FromImage(temp))
                {
                    g.FillRectangle(new SolidBrush(Colours.convertColour(pattern.Color)), 0, 0, 256, 256);
                }
            }


            return(temp);
        }
        private void showPatternDetails(Patterns.patternDetails pDetails, bool doEnable)
        {
            txtPatternAFilename.Text = pDetails.filename;
            txtPatternAKey.Text = pDetails.key;
            txtPatternAName.Text = pDetails.name;
            if (pDetails.Linked.ToLower() == "true") { chkPatternALinked.Checked = true; }
            else { chkPatternALinked.Checked = false; }

            txtPatternARGBMask.Text = pDetails.rgbmask;
            txtPatternASpecular.Text = pDetails.specmap;
            txtPatternATiling.Text = pDetails.Tiling;

            switch (pDetails.type)
            {
                case "solidColor":
                    cmbPatternAType.SelectedIndex = 0;
                    picPatternSolidColour.BackColor = MadScience.Colours.convertColour(pDetails.Color);

                    picPatternThumb.Image = Patterns.makePatternThumb(pDetails);

                    break;
                case "HSV":
                    cmbPatternAType.SelectedIndex = 2;

                    Colours.HSVColor hsv = new Colours.HSVColor();
                    hsv.Hue = Convert.ToDouble(pDetails.HBg,CultureInfo.InvariantCulture) * 360 + Convert.ToDouble(pDetails.BaseHBg,CultureInfo.InvariantCulture) * 360;
                    hsv.Saturation = Convert.ToDouble(pDetails.SBg,CultureInfo.InvariantCulture) + Convert.ToDouble(pDetails.BaseSBg,CultureInfo.InvariantCulture);
                    hsv.Value = Convert.ToDouble(pDetails.VBg,CultureInfo.InvariantCulture) + Convert.ToDouble(pDetails.BaseVBg,CultureInfo.InvariantCulture);
                    picHSVColorBG.BackColor = hsv.Color;

                    if ((pDetails.ChannelEnabled[0] != null) && (pDetails.ChannelEnabled[0].ToLower() == "true"))
                    {
                        hsv.Hue = Convert.ToDouble(pDetails.H[0],CultureInfo.InvariantCulture) * 360 + Convert.ToDouble(pDetails.BaseH[0],CultureInfo.InvariantCulture) * 360;
                        hsv.Saturation = Convert.ToDouble(pDetails.S[0],CultureInfo.InvariantCulture) + Convert.ToDouble(pDetails.BaseS[0],CultureInfo.InvariantCulture);
                        hsv.Value = Convert.ToDouble(pDetails.V[0],CultureInfo.InvariantCulture) + Convert.ToDouble(pDetails.BaseV[0],CultureInfo.InvariantCulture);
                        picHSVColorChannel1.BackColor = hsv.Color;
                        picHSVColorChannel1.Visible = true;
                        label23.Visible = true;
                    }
                    else
                    {
                        picHSVColorChannel1.Visible = false;
                        label23.Visible = false;
                    }

                    if ((pDetails.ChannelEnabled[1] != null) && (pDetails.ChannelEnabled[1].ToLower() == "true"))
                    {
                        hsv.Hue = Convert.ToDouble(pDetails.H[1],CultureInfo.InvariantCulture) * 360 + Convert.ToDouble(pDetails.BaseH[1],CultureInfo.InvariantCulture) * 360;
                        hsv.Saturation = Convert.ToDouble(pDetails.S[1],CultureInfo.InvariantCulture) + Convert.ToDouble(pDetails.BaseS[1],CultureInfo.InvariantCulture);
                        hsv.Value = Convert.ToDouble(pDetails.V[1],CultureInfo.InvariantCulture) + Convert.ToDouble(pDetails.BaseV[1],CultureInfo.InvariantCulture);
                        picHSVColorChannel2.BackColor = hsv.Color;
                        picHSVColorChannel2.Visible = true;
                        label24.Visible = true;
                    }
                    else
                    {
                        picHSVColorChannel2.Visible = false;
                        label24.Visible = false;
                    }

                    if ((pDetails.ChannelEnabled[2] != null) && (pDetails.ChannelEnabled[2].ToLower() == "true"))
                    {
                        hsv.Hue = Convert.ToDouble(pDetails.H[2],CultureInfo.InvariantCulture) * 360 + Convert.ToDouble(pDetails.BaseH[2],CultureInfo.InvariantCulture) * 360;
                        hsv.Saturation = Convert.ToDouble(pDetails.S[2],CultureInfo.InvariantCulture) + Convert.ToDouble(pDetails.BaseS[2],CultureInfo.InvariantCulture);
                        hsv.Value = Convert.ToDouble(pDetails.V[2],CultureInfo.InvariantCulture) + Convert.ToDouble(pDetails.BaseV[2],CultureInfo.InvariantCulture);
                        picHSVColorChannel3.BackColor = hsv.Color;
                        picHSVColorChannel3.Visible = true;
                        label25.Visible = true;
                    }
                    else
                    {
                        picHSVColorChannel3.Visible = false;
                        label25.Visible = false;
                    }

                    picPatternThumb.Image = Patterns.makePatternThumb(pDetails);

                    break;
                case "Coloured":
                    cmbPatternAType.SelectedIndex = 1;

                    Color temp;
                    temp = MadScience.Colours.convertColour(pDetails.ColorP[0], true);
                    picPatternColourBg.BackColor = temp;
                    if (temp == Color.Empty)
                    {
                        picPatternColourBg.Tag = "empty";
                        picPatternColourBg.Visible = false;
                        label65.Visible = false;
                    }
                    else
                    {
                        picPatternColourBg.Tag = "color";
                        //picPatternColourBg.Visible = true;
                        //label65.Visible = true;
                        picPatternColourBg.Visible = false;
                        label65.Visible = false;
                    }

                    temp = MadScience.Colours.convertColour(pDetails.ColorP[1], true);
                    picPatternColour1.BackColor = temp;
                    if (temp == Color.Empty)
                    {
                        picPatternColour1.Tag = "empty";
                        picPatternColour1.Visible = false;
                        label64.Visible = false;
                    }
                    else
                    {
                        picPatternColour1.Tag = "color";
                        picPatternColour1.Visible = true;
                        label64.Visible = true;
                    }

                    temp = MadScience.Colours.convertColour(pDetails.ColorP[2], true);
                    picPatternColour2.BackColor = temp;
                    if (temp == Color.Empty)
                    {
                        picPatternColour2.Tag = "empty";
                        picPatternColour2.Visible = false;
                        label67.Visible = false;
                    }
                    else
                    {
                        picPatternColour2.Tag = "color";
                        picPatternColour2.Visible = true;
                        label67.Visible = true;
                    }

                    temp = MadScience.Colours.convertColour(pDetails.ColorP[3], true);
                    picPatternColour3.BackColor = temp;
                    if (temp == Color.Empty)
                    {
                        picPatternColour3.Tag = "empty";
                        picPatternColour3.Visible = false;
                        label66.Visible = false;
                    }
                    else
                    {
                        picPatternColour3.Tag = "color";
                        picPatternColour3.Visible = true;
                        label66.Visible = true;
                    }

                    temp = MadScience.Colours.convertColour(pDetails.ColorP[4], true);
                    picPatternColour4.BackColor = temp;
                    if (temp == Color.Empty)
                    {
                        picPatternColour4.Tag = "empty";
                        picPatternColour4.Visible = false;
                        label68.Visible = false;
                    }
                    else
                    {
                        picPatternColour4.Tag = "color";
                        picPatternColour4.Visible = true;
                        label68.Visible = true;
                    }

                    picPatternThumb.Image = Patterns.makePatternThumb(pDetails);

                    break;
            }

            if (doEnable)
            {
                if (pDetails.Enabled.ToLower() == "true") { chkPatternAEnabled.Checked = true; }
                else { chkPatternAEnabled.Checked = false; }
            }

            grpPatternA.Enabled = true;
        }