Esempio n. 1
0
        /// <summary>
        /// Opens a dialog to edit a Locale's languageid.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        void contextclick_EditLocale(object sender, EventArgs e)
        {
            var parent = (GffData.Field)SelectedNode.Parent.Tag;

            if (parent.localeflags != LocaleDialog.Loc_ALL)
            {
                var field = (GffData.Field)SelectedNode.Tag;

                GffData.Locale locale;

                locale  = parent.Locales[(int)field.localeid];
                _langid = locale.langid;
                _langf  = locale.F;

                using (var f = new LocaleDialog(parent.localeflags, true))
                {
                    if (f.ShowDialog(this) == DialogResult.OK &&
                        (locale.langid != _langid || locale.F != _langf))
                    {
                        LocaleDialog.ClearLocaleFlag(ref parent.localeflags,
                                                     locale.langid,
                                                     locale.F);

                        field.label = GffData.Locale.GetLanguageString(locale.langid = _langid,
                                                                       locale.F = _langf);
                        ((Sortable)SelectedNode)._label = field.label;

                        LocaleDialog.SetLocaleFlag(ref parent.localeflags,
                                                   _langid,
                                                   _langf);

                        SelectedNode.Text = GeneralGFF.ConstructNodetext(field, locale);

                        _f.GffData.Changed = true;
                        _f.GffData         = _f.GffData;
                    }
                }
            }
            else
            {
                using (var f = new InfoDialog(Globals.Error, "All locales are taken."))
                    f.ShowDialog(this);
            }
        }
Esempio n. 2
0
        /// <summary>
        /// Adds a Locale to a CExoLocString Field.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        void contextclick_AddLocale(object sender, EventArgs e)
        {
            var field = (GffData.Field)SelectedNode.Tag;

            if (field.localeflags != LocaleDialog.Loc_ALL)
            {
                using (var f = new LocaleDialog(field.localeflags))
                {
                    if (f.ShowDialog(this) == DialogResult.OK)
                    {
                        var locale = new GffData.Locale();
                        locale.local = String.Empty;

                        LocaleDialog.SetLocaleFlag(ref field.localeflags,
                                                   locale.langid = _langid,
                                                   locale.F      = _langf);

                        if (field.Locales == null)
                        {
                            field.Locales = new List <GffData.Locale>();
                        }

                        var fieldloc = new GffData.Field();
                        fieldloc.type     = FieldTypes.locale;
                        fieldloc.label    = GffData.Locale.GetLanguageString(_langid, _langf);
                        fieldloc.localeid = (uint)field.Locales.Count;

                        field.Locales.Add(locale);
                        AddField(fieldloc, locale);
                    }
                }
            }
            else
            {
                using (var f = new InfoDialog(Globals.Error, "All locales are taken."))
                    f.ShowDialog(this);
            }
        }
Esempio n. 3
0
        /// <summary>
        /// Deletes a field in the TreeList along with any of its subnodes.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        internal void contextclick_Delete(object sender, EventArgs e)
        {
            bool delete;

            if (SelectedNode.Tag == null)             // is TopLevelStruct's node
            {
                delete = false;
                using (var f = new DeleteDialog("Confirm delete TopLevelStruct"))
                {
                    f.cb_Bypass.Visible = false;
                    if (f.ShowDialog(this) == DialogResult.Yes)
                    {
                        delete = true;

                        if (_f.GffData.Pfe == Globals.TopLevelStruct)
                        {
                            _f.GffData = null;
                        }
                    }
                }
            }
            else if (!_bypassDeleteWarning)
            {
                string head = "Confirm delete";
                if (SelectedNode.Nodes.Count != 0)
                {
                    head += " multiple fields";
                }

                delete = false;
                using (var f = new DeleteDialog(head))
                {
                    f.cb_Bypass.Visible = true;

                    if (f.ShowDialog(this) == DialogResult.Yes)
                    {
                        delete = true;
                        _bypassDeleteWarning = f.cb_Bypass.Checked;
                    }
                }
            }
            else
            {
                delete = true;
            }

            if (delete)
            {
                if (SelectedNode.Tag != null)
                {
                    switch (((GffData.Field)SelectedNode.Tag).type)
                    {
                    case FieldTypes.Struct:
                    {
                        // Structs in Lists do not have a Label so keep their pseudo-labels' sequential order

                        var parent = SelectedNode.Parent;
                        if (parent.Tag != null &&                              // parent is NOT TopLevelStruct
                            ((GffData.Field)parent.Tag).type == FieldTypes.List)
                        {
                            Sortable node;

                            var field = (GffData.Field)SelectedNode.Tag;
                            int id    = Int32.Parse(field.label);
                            while (++id != parent.Nodes.Count)
                            {
                                node            = parent.Nodes[id] as Sortable;
                                field           = (GffData.Field)node.Tag;
                                node._label     =
                                    field.label = (id - 1).ToString();

                                node.Text = GeneralGFF.ConstructNodetext(field);
                            }
                        }
                        break;
                    }

                    case FieldTypes.locale:
                    {
                        var parent  = (GffData.Field)SelectedNode.Parent.Tag;
                        var locales = parent.Locales;

                        int            localeid = (int)((GffData.Field)SelectedNode.Tag).localeid;
                        GffData.Locale locale   = locales[localeid];

                        LocaleDialog.ClearLocaleFlag(ref parent.localeflags,
                                                     locale.langid,
                                                     locale.F);

                        for (int i = 0; i != SelectedNode.Parent.Nodes.Count; ++i)
                        {
                            var field = (GffData.Field)SelectedNode.Parent.Nodes[i].Tag;
                            if (field.localeid > localeid)
                            {
                                --field.localeid;
                            }
                        }

                        locales.Remove(locale);
                        break;
                    }
                    }
                }

                SelectedNode.Remove();

                if (SelectedNode == null)
                {
                    _f.ResetEditPanel();
                }

                if (_f.GffData != null)
                {
                    _f.GffData.Changed = true;
                }
                _f.GffData = _f.GffData;
            }
        }
Esempio n. 4
0
        /// <summary>
        /// Adds a Field to a treenode.
        /// </summary>
        /// <param name="field">a Field to add</param>
        /// <param name="parent">a treenode to add it to</param>
        /// <param name="locale">a locale if applicable</param>
        static void AddField(GffData.Field field, TreeNode parent, GffData.Locale locale = null)
        {
            // TODO: Refactor things throughout the code such that the Tag of a
            // treenode is *either* a GffData.Field *or* a GffData.Locale.

            string text = GeneralGFF.ConstructNodetext(field, locale);

            var node = new Sortable(text, field.label);

            node.Tag = field;
            parent.Nodes.Add(node);

            switch (field.type)
            {
            case FieldTypes.Struct:                     // childs can be of any Type.
            {
                List <uint> fieldids = field.Struct.fieldids;
                for (int i = 0; i != fieldids.Count; ++i)
                {
                    AddField(GffReader.Fields[(int)fieldids[i]], node);
                }
                break;
            }

            case FieldTypes.List:                     // childs are Structs.
            {
                List <uint> list = field.List;
                for (int i = 0; i != list.Count; ++i)
                {
                    // NOTE: Structs in Lists do not have a Label inside a GFF-file.
                    // so give Structs in Lists a pseudo-label for their treenode(s)
                    field        = new GffData.Field();
                    field.type   = FieldTypes.Struct;
                    field.label  = i.ToString();
                    field.Struct = GffReader.Structs[(int)list[i]];

                    AddField(field, node);
                }
                break;
            }

            case FieldTypes.CExoLocString:                     // childs are Locales.
                if (field.Locales != null)
                {
                    int locales = field.Locales.Count;
                    for (int i = 0; i != locales; ++i)
                    {
                        locale = field.Locales[i];

                        var fieldloc = new GffData.Field();
                        fieldloc.type     = FieldTypes.locale;
                        fieldloc.localeid = (uint)i;
                        fieldloc.label    = GffData.Locale.GetLanguageString(locale.langid, locale.F);

                        AddField(fieldloc, node, locale);

                        LocaleDialog.SetLocaleFlag(ref field.localeflags,
                                                   locale.langid,
                                                   locale.F);
                    }
                }
                break;
            }
        }