Exemplo n.º 1
0
        private Exporter GetExporter(DrawablesOutput output)
        {
            string value = (string)cbxGenerateType.SelectedItem;

            switch (value)
            {
            default:
            {
                FileInfo file = templates[value];
                string   template;
                try
                {
                    template = File.ReadAllText(file.FullName);
                }
                catch (Exception e)
                {
                    throw new ArgumentException("Could not load the template '" + file.Name + "'.\n\nException:\n" + e.Message);
                }

                return(new TemplateExporter(output, template));
            }

            case null:
            case "Common Pistol":
                return(new PistolExporter(output));

            case "Common Shortsword":
                return(new ShortswordExporter(output));

            case "Tesla Staff":
                return(new TeslaStaffExporter(output));
            }
        }
Exemplo n.º 2
0
        private void InventoryIcon_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                DrawablesGenerator generator = new DrawablesGenerator(imagePath);

                generator = DrawableUtilities.SetUpGenerator(generator, "0", "0", tbxIgnoreColor.Text);

                DrawablesOutput output = generator.Generate();

                (new OutputWindow("Inventory Icon:", DrawableUtilities.GenerateInventoryIcon(output))).Show();
            }
            catch (FormatException)
            {
                MessageBox.Show("Invalid format. Did you provide a correct ignore color code? (hexadecimal RRGGBB or RRGGBBAA)");
            }
            catch (ArgumentNullException)
            {
                MessageBox.Show("Argument may not be null. Did you select a valid image?");
            }
            catch (DrawableException exc)
            {
                MessageBox.Show(exc.Message);
                return;
            }
        }
Exemplo n.º 3
0
        private void Command_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                DrawablesGenerator generator = new DrawablesGenerator(imagePath);

                generator = DrawableUtilities.SetUpGenerator(generator, tbxHandX.Text, tbxHandY.Text, tbxIgnoreColor.Text);
                generator.ReplaceWhite = true;

                DrawablesOutput output = generator.Generate();

                Exporter exporter = GetExporter(output);
                (new OutputWindow("Item Command:", exporter.GetCommand(chkAddWeaponGroup.IsChecked.HasValue && chkAddWeaponGroup.IsChecked.Value ? "weapon" : null, chkAddInventoryIcon.IsChecked.Value), false)).Show();
            }
            catch (JsonReaderException exc)
            {
                MessageBox.Show("The template does not appear to be valid JSON.\n\nException:\n" + exc.Message);
            }
            catch (ArgumentNullException)
            {
                MessageBox.Show("Argument may not be null. Did you select a valid image?");
            }
            catch (ArgumentException exc)
            {
                MessageBox.Show("Illegal argument:\n" + exc.Message);
            }
            catch (FormatException)
            {
                MessageBox.Show("Could not convert hand offsets to numbers.");
            }
            catch (Exception exc)
            {
                MessageBox.Show("Uncaught exception:\n" + exc.Message);
            }
        }
Exemplo n.º 4
0
        private void InventoryIcon_Click(object sender, Avalonia.Interactivity.RoutedEventArgs e)
        {
            if (image == null)
            {
                MessageBox.ShowDialog("Please select an image first!", "Error");
                return;
            }

            try
            {
                DrawablesGenerator generator = new DrawablesGenerator(image);

                generator.FlipY = true;

                if (Data.IgnoreWhite)
                {
                    generator.IgnoreColor = new Rgba32(255, 255, 255, 255);
                }

                DrawablesOutput output = generator.Generate();

                TextWindow tw = new TextWindow(DrawablesGenerator.GenerateInventoryIcon(output).ToString(Formatting.Indented), "Inventory Icon");
                tw.ShowDialog();
            }
            catch (ArgumentNullException)
            {
                MessageBox.ShowDialog("Argument may not be null. Did you select a valid image?", "Error");
            }
            catch (DrawableException exc)
            {
                MessageBox.ShowDialog(exc.Message, "Error");
            }
        }
Exemplo n.º 5
0
        private void SingleTextureDirectives_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                DrawablesGenerator generator = new DrawablesGenerator(imagePath);

                bool fade = chkFade.IsChecked.Value;

                generator = DrawableUtilities.SetUpGenerator(generator, tbxHandX.Text, tbxHandY.Text, tbxIgnoreColor.Text);
                generator.ReplaceBlank = !fade;
                generator.ReplaceWhite = true;

                DrawablesOutput output = generator.Generate();

                int j = 64;
                int.TryParse(tbxSourceImageSize.Text, out j);
                (new OutputWindow("Single Texture Directives:", DrawableUtilities.GenerateSingleTextureDirectives(output, j, fade), false)).Show();
            }
            catch (FormatException)
            {
                MessageBox.Show("Invalid format. Did you provide a correct ignore color code? (hexadecimal RRGGBB or RRGGBBAA)");
            }
            catch (ArgumentNullException)
            {
                MessageBox.Show("Argument may not be null. Did you select a valid image?");
            }
            catch (DrawableException exc)
            {
                MessageBox.Show(exc.Message);
                return;
            }
        }
Exemplo n.º 6
0
        /// <summary>
        /// Transforms the directives from a <see cref="DrawablesOutput"/> into a single directives string.
        /// Requires the given output to be generated with ReplaceBlank and ReplaceWhite set to true.
        /// </summary>
        /// <param name="output">Output to read directives from.</param>
        /// <param name="baseScale">Base scale. Should be the biggest dimension in the source image this string will be applied to by the user.
        /// EG. If the user wishes to apply a drawable bigger than 30x50 to a 30x50 object, the base scale should be 50.</param>
        /// <returns>Directives string</returns>
        public static string GenerateSingleTextureDirectives(DrawablesOutput output, int baseScale = 64, bool fade = false)
        {
            int w = output.ImageWidth,
                h = output.ImageHeight;

            int max   = w > h ? w : h;
            int scale = (int)Math.Ceiling((double)max / baseScale);

            StringBuilder dir = new StringBuilder();

            dir.AppendFormat("?setcolor=ffffff?replace;00000000=ffffff;ffffff00=ffffff?setcolor=ffffff?scalenearest={0}?crop=0;0;{1};{2}", scale, w, h);

            foreach (Drawable drawable in output.Drawables)
            {
                if (drawable != null)
                {
                    dir.AppendFormat("?blendmult={0};{1};{2}{3}", drawable.Texture, -drawable.X, -drawable.Y, drawable.Directives);

                    if (fade)
                    {
                        dir.Append("?fade;80ff80;0.0001518");
                    }
                }
            }

            dir.Append("?replace;ffffffff=00000000");

            return(dir.ToString());
        }
Exemplo n.º 7
0
        public void TestOutput()
        {
            int    w = 2, h = 1;
            string path = CreateTempBitmap(w * 32, h * 8);

            try
            {
                DrawablesGenerator dg = new DrawablesGenerator(path);
                dg.OffsetX = 5;
                dg.OffsetY = 3;

                DrawablesOutput dOutput = dg.Generate();

                // Checking output
                Assert.AreEqual(64, dOutput.ImageWidth);
                Assert.AreEqual(8, dOutput.ImageHeight);

                // Checking drawables in output
                Assert.AreEqual(w, dOutput.Drawables.GetLength(0));
                Assert.AreEqual(h, dOutput.Drawables.GetLength(1));

                Drawable d  = dOutput.Drawables[0, 0];
                Drawable d2 = dOutput.Drawables[1, 0];

                // Texture and ResultImage
                Assert.AreEqual(d.Texture, dg.DrawableTexture);
                Assert.AreEqual(d.Texture, d2.Texture);
                Assert.AreEqual(d.ResultImage, d.Texture + d.Directives);
                Assert.AreNotEqual(d.ResultImage, d2.ResultImage);

                // Offset matching
                Assert.AreEqual(dg.OffsetX, dOutput.OffsetX);
                Assert.AreEqual(dg.OffsetY, dOutput.OffsetY);

                // Drawable positioning
                Assert.AreEqual(0, d.X);
                Assert.AreEqual(0, d.Y);
                Assert.AreEqual(32, d2.X);
                Assert.AreEqual(0, d2.Y);
                Assert.AreEqual(0d, d.BlockX);
                Assert.AreEqual(4d, d2.BlockX);
                Assert.AreEqual(0d, d.BlockY);
                Assert.AreEqual(d.BlockY, d2.BlockY);
            }
            catch (DrawableException exc)
            {
                Assert.Fail(exc.Message);
            }
            finally
            {
                if (File.Exists(path))
                {
                    File.Delete(path);
                }
            }
        }
Exemplo n.º 8
0
        public static JArray GenerateInventoryIcon(DrawablesOutput output)
        {
            JArray drawables = new JArray();

            for (int i = 0; i < output.Drawables.GetLength(0); i++)
            {
                for (int j = 0; j < output.Drawables.GetLength(1); j++)
                {
                    Drawable item = output.Drawables[i, j];

                    if (item == null)
                    {
                        continue;
                    }

                    JObject drawable = new JObject();
                    drawable["image"] = item.ResultImage;

                    bool cropH = false, cropV = false;
                    int  hRest = 0, vRest = 0;
                    if (i == output.Drawables.GetLength(0) - 1)
                    {
                        hRest = output.ImageWidth % 32;
                        if (hRest != 0)
                        {
                            cropH = true;
                        }
                    }
                    if (j == output.Drawables.GetLength(1) - 1)
                    {
                        vRest = output.ImageHeight % 8;
                        if (vRest != 0)
                        {
                            cropH = true;
                        }
                    }

                    if (cropH || cropV)
                    {
                        drawable["image"] += "?crop;0;0;" + (cropH ? hRest : 32) + ";" + (cropV ? vRest : 8);
                    }

                    JArray position = new JArray();
                    position.Add(item.X);
                    position.Add(item.Y);
                    drawable["position"] = position;
                    drawables.Add(drawable);
                }
            }
            return(drawables);
        }
Exemplo n.º 9
0
        private void ItemDescriptor_Click(object sender, Avalonia.Interactivity.RoutedEventArgs e)
        {
            if (image == null)
            {
                MessageBox.ShowDialog("Please select an image first!", "Error");
                return;
            }

            try
            {
                DrawablesGenerator generator = new DrawablesGenerator(image);
                generator.OffsetX = Convert.ToInt32(tbxHandX.Text) + 1;
                generator.OffsetY = Convert.ToInt32(tbxHandY.Text);

                generator.FlipY        = true;
                generator.ReplaceBlank = true;
                generator.ReplaceWhite = true;

                if (Data.IgnoreWhite)
                {
                    generator.IgnoreColor = new Rgba32(255, 255, 255, 255);
                }

                DrawablesOutput output = generator.Generate();
                Template        t      = GetTemplate();

                Exporter.Exporter exporter = new Exporter.Exporter(output, t.Config);
                if (Data.WeaponGroup)
                {
                    exporter.Groups.Add("weapon");
                }

                JObject descriptor = exporter.GetDescriptor(Data.InventoryIcon);

                TextWindow tw = new TextWindow(descriptor.ToString(Formatting.Indented), "Item Descriptor");
                tw.ShowDialog();
            }
            catch (ArgumentException exc)
            {
                MessageBox.ShowDialog("Illegal argument:\n" + exc.Message, "Error");
            }
            catch (FormatException)
            {
                MessageBox.ShowDialog("Could not convert hand offsets to numbers.", "Error");
            }
            catch (Exception exc)
            {
                MessageBox.ShowDialog("Uncaught exception:\n" + exc.Message, "Error");
            }
        }
Exemplo n.º 10
0
        /// <summary>
        /// Generate the starbound single texture directive by the given frame
        /// </summary>
        /// <param name="bsource">A frame to create directives from</param>
        /// <returns>The directive string</returns>
        protected static string GenerateDirective(BitmapSource bsource)
        {
            Bitmap             bmp       = BitmapConverter.BitmapSourceToBitmap(bsource);
            DrawablesGenerator generator = new DrawablesGenerator(BitmapConverter.BitmapSourceToBitmap(bsource));

            bmp.Dispose();
            generator = DrawableUtilities.SetUpGenerator(generator, 0, 0);
            generator.ReplaceBlank = true;
            generator.ReplaceWhite = true;

            DrawablesOutput output = generator.Generate();

            return(DrawableUtilities.GenerateSingleTextureDirectives(output, 64));
        }
Exemplo n.º 11
0
        private void SingleTexture_Click(object sender, Avalonia.Interactivity.RoutedEventArgs e)
        {
            if (image == null)
            {
                MessageBox.ShowDialog("Please select an image first!", "Error");
                return;
            }

            try
            {
                DrawablesGenerator generator = new DrawablesGenerator(image);
                generator.OffsetX = Convert.ToInt32(tbxHandX.Text);
                generator.OffsetY = Convert.ToInt32(tbxHandY.Text);

                generator.FlipY = true;

                generator.ReplaceBlank = true;
                generator.ReplaceWhite = true;

                if (Data.IgnoreWhite)
                {
                    generator.IgnoreColor = new Rgba32(255, 255, 255, 255);
                }

                DrawablesOutput output = generator.Generate();

                int        j  = int.Parse(tbxSourceImageSize.Text);
                TextWindow tw = new TextWindow(DrawablesGenerator.GenerateSingleTextureDirectives(output, j), "Single Texture Directives");
                tw.ShowDialog();
            }
            catch (ArgumentNullException)
            {
                MessageBox.ShowDialog("Could not parse the hand position or the source image size (text field next to the button). Please hover over it for more information.", "Error");
            }
            catch (FormatException)
            {
                MessageBox.ShowDialog("Could not parse the hand position or source image size (text field next to the button). Please hover over it for more information.", "Error");
            }
            catch (DrawableException exc)
            {
                MessageBox.ShowDialog(exc.Message, "Error");
            }
        }
Exemplo n.º 12
0
 public ShortswordExporter(DrawablesOutput output) : base(output)
 {
 }
Exemplo n.º 13
0
 public PistolExporter(DrawablesOutput output) : base(output)
 {
 }
Exemplo n.º 14
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="output"></param>
 /// <param name="template"></param>
 public TemplateExporter(DrawablesOutput output, string template) : base(output)
 {
     this.template = template;
 }
Exemplo n.º 15
0
 public TeslaStaffExporter(DrawablesOutput output) : base(output)
 {
 }
Exemplo n.º 16
0
        public void TestGenerate()
        {
            int    w = 4, h = 4;
            string path = CreateTempBitmap(w * 32, h * 8);

            try
            {
                DrawablesGenerator dg      = new DrawablesGenerator(path);
                DrawablesOutput    dOutput = dg.Generate();

                for (int i = 0; i < w; i++)
                {
                    for (int j = 0; j < h; j++)
                    {
                        for (int x = 0; x < w; x++)
                        {
                            for (int y = 0; y < h; y++)
                            {
                                Drawable      drawable  = dOutput.Drawables[i, j];
                                StringBuilder debuilder = new StringBuilder(drawable.Directives);
                                debuilder.Remove(0, 8);

                                while (debuilder.Length >= 18)
                                {
                                    string from = debuilder.ToString(1, 6),
                                           to   = debuilder.ToString(10, 6);

                                    int rFrom = Convert.ToInt32(from.Substring(0, 2)),
                                        bFrom = Convert.ToInt32(from.Substring(4, 2));

                                    int rTo = ColorConversions.HexToInt(to.Substring(0, 2)),
                                        bTo = ColorConversions.HexToInt(to.Substring(4, 2));

                                    if (rTo > 32)
                                    {
                                        rTo = --rTo % 32;
                                        rTo++;
                                    }

                                    if (bTo > 8)
                                    {
                                        bTo = --bTo % 8;
                                        bTo++;
                                    }

                                    Assert.AreEqual(rFrom, rTo);
                                    Assert.AreEqual(bFrom, bTo);

                                    debuilder.Remove(0, 18);
                                }
                            }
                        }
                    }
                }

                dg.IgnoreColor = Color.Blue;
                dg.OffsetX     = 5;
                dg.OffsetY     = 3;
                dg.Generate();

                dg.ReplaceBlank = true;
                dg.ReplaceWhite = true;
                dg.Generate();

                dg.RotateFlipStyle = RotateFlipType.Rotate180FlipY;
                dg.Generate();
            }
            catch (DrawableException exc)
            {
                Assert.Fail(exc.Message);
            }
            finally
            {
                if (File.Exists(path))
                {
                    File.Delete(path);
                }
            }
        }
 public Exporter(DrawablesOutput output, JObject template)
 {
     Template = template;
     Output   = output;
 }
Exemplo n.º 18
0
 public Exporter(DrawablesOutput output)
 {
     this.output = output;
 }