protected void move_copy_craft_dialog()
        {
//            CraftData craft = CraftData.selected_craft;
            if (CraftData.active_craft.Count > 0)
            {
                string           resp                = "";
                string           selected_save       = "";
                DropdownMenuData move_copy_save_menu = new DropdownMenuData();
                save_menu_data(move_copy_save_menu);

                foreach (CraftData craft in CraftData.active_craft)
                {
                    move_copy_save_menu.items.Remove(craft.save_dir);
                }
                move_copy_save_menu.items.Remove(all_saves_ref);
                move_copy_save_menu.items.Remove("kerbalx_remote");
                Rect d_offset = new Rect();
                show_dialog("Move/Copy Craft", "Move or Copy " + (CraftData.active_craft.Count > 1 ? "these" : "this") + " craft to another save:", d => {
                    section(500f, (inner_width) => {
                        d_offset.x = -d.window_pos.x;
                        d_offset.y = -d.window_pos.y;
                        dropdown("Select Save", StyleSheet.assets["caret-down"], "copy_transfer_save_menu", move_copy_save_menu, d, d_offset, inner_width / 2, "button.large", "menu.background", "menu.item", (selected_save_name) => {
                            resp          = "";
                            selected_save = selected_save_name;
                        });
                    });
                    if (CraftData.active_craft.Count > 1)
                    {
                        label("if the save you're looking for is not listed, it is because one of the craft you've selected is already in that save", "small");
                    }
                    section(() => {
                        label("Selected Save: ", "h2");
                        label(selected_save, "h2");
                    });
                    section(() => {
                        button("Move", "button.large", () => {
                            resp = CraftData.move_copy_active_craft_to(selected_save, true);
                        });
                        button("Copy", "button.large", () => {
                            resp = CraftData.move_copy_active_craft_to(selected_save, false);
                        });
                    });
                    section(() => {
                        fspace();
                        button("Cancel", close_dialog);
                    });
                    return(resp);
                });
            }
        }
예제 #2
0
        //prepare to open a tag menu, triggered from another dropdown menu, which is why this is a bit odd. It has to be opened after the first menu has been closed (and destroyed)
        //so this method is called from the frist menu which sets up the tag menu and sets a flag (open_tag_menu).  After this call the first menu closes, but then on the next pass
        //the open_tag_menu flag triggers the opening of this second menu.
        protected void prepare_tag_menu(Rect container)
        {
            inline_tag_menu             = new DropdownMenuData();
            inline_tag_menu.remote_data = new DataSource(menu => {
                menu.set_data(Tags.names.FindAll(t => !Tags.instance.autotags_list.Contains(t)));
            });
            inline_tag_menu.special_items.Add("new_tag", "New Tag");
            inline_tag_menu.offset_menu = false;

//            foreach(CraftData craft in CraftData.active_craft){
//                foreach(string tag in craft.tag_names()){
//                    inline_tag_menu.selected_items.AddUnique(tag);
//                }
//            }
            inline_tag_menu.selected_items = tags_for_active_craft;
//            inline_tag_menu.selected_items = craft.tag_names();

            inline_tag_menu.set_attributes(container, new Rect(0, 0, 0, 0), this, 0f, "menu.background", "menu.item.small", (resp) => {
                respond_to_tag_menu(resp);
            });
            open_tag_menu = true;
        }
        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);
            });
        }