protected void show_update_kerbalx_craft_dialog()
        {
            string    resp  = "";
            CraftData craft = CraftData.selected_craft;

            if (craft.upload_data == null) //create new instance of upload data if it's not already been set
            {
                craft.upload_data = KerbalXUploadData.prepare_for(craft);
            }
            craft.upload_data.update_to_id = craft.matching_remote_ids.Count == 0 ? 0 : craft.matching_remote_ids[0];

            string menu_label             = "";
            string kx_url                 = "";
            bool   show_craft_select_menu = craft.matching_remote_ids.Count != 1;
            Rect   d_offset               = new Rect();

            Dictionary <string, string> upload_select_data_matching = new Dictionary <string, string>();
            Dictionary <string, string> upload_select_data_all      = new Dictionary <string, string>();

            foreach (int id in craft.matching_remote_ids)
            {
                upload_select_data_matching.Add(id.ToString(), KerbalX.api.user_craft[id]["url"].Replace(("/" + KerbalX.api.logged_in_as + "/"), ""));
            }
            foreach (KeyValuePair <int, Dictionary <string, string> > c in KerbalX.api.user_craft)
            {
                upload_select_data_all.Add(c.Key.ToString(), c.Value["url"].Replace(("/" + KerbalX.api.logged_in_as + "/"), ""));
            }

            DropdownMenuData upload_select_menu   = new DropdownMenuData();
            DropdownMenuData upload_select_menu_2 = new DropdownMenuData();

            if (craft.matching_remote_ids.Count == 0)
            {
                upload_select_menu.set_data(upload_select_data_all);
            }
            else
            {
                upload_select_menu.set_data(upload_select_data_matching);
            }
            upload_select_menu_2.set_data(upload_select_data_all);

            show_dialog("Update KerbalX Craft", "", d => {
                d_offset.x = -d.window_pos.x; d_offset.y = -d.window_pos.y;

                if (craft.upload_data.update_to_id != 0)
                {
                    menu_label = KerbalX.api.user_craft[craft.upload_data.update_to_id]["url"].Replace(("/" + KerbalX.api.logged_in_as + "/"), "");
                    kx_url     = KerbalX.api.url_to(KerbalX.api.user_craft[craft.upload_data.update_to_id]["url"]);
                }
                else
                {
                    menu_label = "Select a craft";
                }

                if (show_craft_select_menu)
                {
                    if (craft.matching_remote_ids.Count > 1)
                    {
                        label("There are " + craft.matching_remote_ids.Count + " craft in your account with the same name as this craft");
                    }
                    label("Select which craft you want to update");
                    dropdown(menu_label, StyleSheet.assets["caret-down"], "upload_select_menu", upload_select_menu, d, d_offset, d.window_pos.width * 0.8f, (sel) => {
                        craft.upload_data.update_to_id = int.Parse(sel);
                    });
                    if (upload_select_menu.items != upload_select_data_all)
                    {
                        section(() => {
                            fspace();
                            button("show all your craft in menu", "hyperlink", () => {
                                upload_select_menu.set_data(upload_select_data_all);
                                open_dropdown(upload_select_menu);
                            });
                        });
                    }
                }

                if (!String.IsNullOrEmpty(kx_url))
                {
                    label("This will update the KerbalX craft:");
                    section((w) => {
                        button(kx_url, "hyperlink.update_url", 500f, 800f, () => { Application.OpenURL(kx_url); });
                        if (!show_craft_select_menu)
                        {
                            dropdown("edit", StyleSheet.assets["caret-down"], "upload_select_menu_2", upload_select_menu_2, d, d_offset, d.window_pos.width * 0.8f, (sel) => {
                                craft.upload_data.update_to_id = int.Parse(sel);
                            });
                        }
                    });
                    section(() => {
                        fspace();
                        label("make sure this is the craft you want to update!", "small.compact");
                    });
                }

                foreach (string error in craft.upload_data.errors)
                {
                    label(error, "error.bold");
                }

                GUILayout.Space(10f);
                gui_state(craft.upload_data.update_to_id > 0, () => {
                    button("Confirm Update", "button.large", () => {
                        craft.upload_data.put();
                    });
                });
                GUILayout.Space(4f);
                section(() => {
                    button("Upload as a new Craft", "button.large", open_upload_interface);
                    button("Cancel", "button.large", close_dialog);
                });
                return(resp);
            });
        }
        //The main dialog used for both editing and creating tags
        protected void tag_dialog_form(string mode, bool show_rule_opts, string tag_name, string save_dir, bool rule_based,
                                       string rule_attr, string rule_comparator, string rule_value, float top, float left, List <CraftData> auto_add_craft = null
                                       )
        {
            string initial_name = tag_name;
            string resp         = "";
            string header       = (mode == "Create" ? "Create Tag" : ("Edit Tag: " + tag_name));

            Rect             d_offset         = new Rect();
            List <Tag>       tags             = Tags.find_all(tag_name, save_dir);
            DropdownMenuData rule_attrs       = new DropdownMenuData(Tags.instance.rule_attributes);
            DropdownMenuData rule_comparators = new DropdownMenuData();
            DropdownMenuData bool_opts        = new DropdownMenuData(new List <string> {
                "True", "False"
            });
            string prev_rule_attr = rule_attr;
            string sel_attr_type  = "";
            bool   first_pass     = true;

            show_dialog("Tag Form", header, top, left, 400f, true, d => {
                d_offset.x = -d.window_pos.x; d_offset.y = -d.window_pos.y;

                if (tags.Count > 1)
                {
                    label("You are viewing craft from all saves, this will edit " + tags.Count + " tags called " + initial_name + " in each of your saves.", "alert.h3");
                }
                GUI.SetNextControlName("dialog_focus_field");
                tag_name = GUILayout.TextField(tag_name, width(400f - 22f));

                if (show_rule_opts)
                {
                    rule_based = GUILayout.Toggle(rule_based, "Use Auto Tag rule", "Button");
                }

                if (rule_based)
                {
                    section(() => {
                        prev_rule_attr = rule_attr;
                        section(d.window_pos.width * 0.35f, () => {
                            dropdown((String.IsNullOrEmpty(rule_attr) ? "Select an Attribute" : rule_attrs.items[rule_attr]), StyleSheet.assets["caret-down"],
                                     "tag_rule_attr_menu", rule_attrs, d, d_offset, d.window_pos.width * 0.35f,
                                     (sel_attr) => {
                                rule_attr = sel_attr;
                            }
                                     );
                        });

                        if (prev_rule_attr != rule_attr || first_pass)
                        {
                            if (!String.IsNullOrEmpty(rule_attr))
                            {
                                sel_attr_type = typeof(CraftData).GetProperty(rule_attr).PropertyType.ToString();
                                if (sel_attr_type == "System.String")
                                {
                                    rule_comparators.set_data(new Dictionary <string, string>(Tags.instance.rule_comparitors_string));
                                }
                                else if (sel_attr_type == "System.Int32" || sel_attr_type == "System.Single")
                                {
                                    rule_comparators.set_data(new Dictionary <string, string>(Tags.instance.rule_comparitors_numeric));
                                }
                            }
                        }

                        if (!rule_comparators.items.ContainsKey(rule_comparator))
                        {
                            rule_comparator = "equal_to";
                        }
                        if (sel_attr_type == "System.Int32" || sel_attr_type == "System.Single")
                        {
                            rule_value = System.Text.RegularExpressions.Regex.Replace(rule_value, "[^0-9]", "");
                        }

                        if (!String.IsNullOrEmpty(sel_attr_type))
                        {
                            if (sel_attr_type == "System.Boolean")
                            {
                                if (!bool_opts.items.ContainsKey(rule_value))
                                {
                                    rule_value = "True";
                                }
                                rule_comparator = "equal_to";
                                label("==", "Button", width(d.window_pos.width * 0.25f));
                                dropdown(rule_value, StyleSheet.assets["caret-down"], "tag_rule_bool_opt_menu", bool_opts, d, d_offset, d.window_pos.width * 0.25f, (bool_val) => {
                                    rule_value = bool_val;
                                });
                            }
                            else
                            {
                                section(d.window_pos.width * 0.25f, () => {
                                    dropdown(rule_comparators.items[rule_comparator], StyleSheet.assets["caret-down"], "tag_rule_comp_menu", rule_comparators, d, d_offset, d.window_pos.width * 0.25f, (sel_comparator) => {
                                        rule_comparator = sel_comparator;
                                    });
                                });
                                rule_value = GUILayout.TextField(rule_value);
                            }
                        }
                    });
                }

                section((w) => {
                    fspace();
                    button("Cancel", close_dialog);
                    if (mode == "Edit")
                    {
                        resp = submit("Update", () => {
                            return(Tags.update(initial_name, tag_name, save_dir, rule_based, rule_attr, rule_comparator, rule_value));
                        });
                    }
                    else
                    {
                        resp = submit("Create Tag", () => {
                            return(Tags.create(tag_name, save_dir, rule_based, rule_attr, rule_comparator, rule_value, auto_add_craft));
                        });
                    }
                });
                return(resp);
            });
        }