コード例 #1
0
        //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);
            });
        }