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); } }
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; } }
/// <summary> /// Confirms if the new text value is a valid positive or negative integer, and updates the preview image position if it is. /// If the value is invalid, restores it to the preview value. /// </summary> /// <param name="sender">The source of the event</param> /// <param name="e">The <see cref="EventArgs"/> instance containing the event data.</param> private void HandY_TextChanged(object sender, TextChangedEventArgs e) { if (!this.IsInitialized) { return; } TextBox tbx = tbxHandY; if (tbx.Text == string.Empty) { this.oldTbxHandY = "0"; tbx.CaretIndex = 1; return; } e.Handled = !DrawableUtilities.IsNumber(tbx.Text); if (e.Handled) { int index = DrawableUtilities.Clamp(tbx.CaretIndex - 1, 0, tbx.Text.Length - 1); tbx.Text = this.oldTbxHandY; tbx.CaretIndex = index; } else { this.oldTbxHandY = tbx.Text; Thickness t = imgPreview.Margin; t.Top = PREVIEW_MARGIN_TOP - Convert.ToInt32(imgPreview.Height) - (Convert.ToInt32(tbx.Text) * 2); imgPreview.Margin = t; } }
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; } }
protected JObject CreateDescriptor(string template, string group = "weapon", bool addInventoryIcon = false) { JObject descriptor = JObject.Parse(template); if (descriptor["name"] == null) { descriptor["name"] = "perfectlygenericitem"; } if (descriptor["count"] == null) { descriptor["count"] = 1; } if (descriptor["parameters"] == null) { descriptor["parameters"] = new JObject(); } JObject parameters = (JObject)descriptor["parameters"]; if (parameters == null) { parameters = new JObject(); } if (parameters["animationCustom"] == null) { parameters["animationCustom"] = new JObject(); } if (parameters["animationCustom"]["animatedParts"] == null) { parameters["animationCustom"]["animatedParts"] = new JObject(); } if (parameters["animationCustom"]["animatedParts"]["parts"] == null) { parameters["animationCustom"]["animatedParts"]["parts"] = new JObject(); } JToken parts = parameters["animationCustom"]["animatedParts"]["parts"]; string prefix = "D_"; int i = 1; JArray groups = new JArray(); if (!string.IsNullOrEmpty(group)) { groups.Add(group); } foreach (Drawable item in output.Drawables) { if (item == null) { continue; } JObject part = JObject.Parse("{'properties':{'centered':false,'offset':[0,0]}}"); part["properties"]["image"] = item.ResultImage; part["properties"]["offset"][0] = item.BlockX + Math.Round(output.OffsetX / 8d, 3); part["properties"]["offset"][1] = item.BlockY + Math.Round(output.OffsetY / 8d, 3); part["properties"]["transformationGroups"] = groups; parts[prefix + i++] = part; } if (addInventoryIcon) { parameters["inventoryIcon"] = DrawableUtilities.GenerateInventoryIcon(output); } return(descriptor); }