Пример #1
0
        private void NewButton_Click(object sender, EventArgs e)
        {
            var ind = SelectedStringInd + 1;

            Content.Content.Get().Changes.BlockingResMod(new ResAction(() =>
            {
                ActiveString.InsertString(ind, new STRItem());
            }, ActiveString));
            UpdateStrings();
            SelectedStringInd = StringList.Items.Count - 1;
        }
Пример #2
0
        private void AddButton_Click(object sender, EventArgs e)
        {
            if (AllList.SelectedItem == null)
            {
                return;
            }
            string name = (string)AllList.SelectedItem;

            Content.Content.Get().Changes.BlockingResMod(new ResAction(() =>
            {
                AnimTable.InsertString(AnimTable.Length, new STRItem()
                {
                    Value = name
                });
            }, AnimTable));
            RefreshAnimTable();
        }
Пример #3
0
        private void NameBox_TextChanged(object sender,EventArgs e)
        {
            if (OwnChange)
            {
                return;
            }
            var text = NameBox.Text;
            var ind  = SelectedStringInd;

            if (ActiveSLOTLabel != null)
            {
                Content.Content.Get().Changes.QueueResMod(new ResAction(() =>
                {
                    while (ind >= ActiveSLOTLabel.Length)
                    {
                        ActiveSLOTLabel.InsertString(ActiveSLOTLabel.Length,new STRItem(""));
                    }
                    ActiveSLOTLabel.SetString(ind,text);
                },ActiveSLOTLabel));
            }
        }
Пример #4
0
        private void OKButton_Click(object sender, EventArgs e)
        {
            var  name  = ChunkLabelEntry.Text;
            var  guidT = GUIDEntry.Text;
            uint guid;
            var  objProvider = Content.Content.Get().WorldObjects;

            if (name == "")
            {
                MessageBox.Show("Name cannot be empty!", "Invalid Object Name");
            }
            else if (guidT == "")
            {
                MessageBox.Show("GUID cannot be empty!", "Invalid GUID");
            }
            else if (!uint.TryParse(guidT, NumberStyles.HexNumber, CultureInfo.InvariantCulture, out guid))
            {
                MessageBox.Show("GUID is invalid! Make sure it is a hex string of size 8. (eg. 6789ABCD)", "Invalid GUID");
            }
            else
            {
                lock (objProvider.Entries)
                {
                    if (objProvider.Entries.ContainsKey(guid))
                    {
                        MessageBox.Show("This GUID is already being used!", "GUID is Taken!");
                        return;
                    }

                    //OK, it's valid. Now to add it to the objects system...
                    //This is a little tricky because we want to add an object that does not exist yet.
                    //There's a special function just for this! But first, we need an OBJD...

                    var obj = new OBJD()
                    {
                        GUID             = guid,
                        ObjectType       = OBJDType.Normal,
                        ChunkLabel       = name,
                        ChunkID          = 1,
                        ChunkProcessed   = true,
                        ChunkType        = "OBJD",
                        ChunkParent      = TargetIff,
                        AnimationTableID = 128,
                        AddedByPatch     = true
                    };

                    Content.Content.Get().Changes.BlockingResMod(new ResAction(() =>
                    {
                        //find a free space to place the object
                        ushort id = 16807; //todo: why???
                        var list  = TargetIff.List <OBJD>();
                        if (list != null)
                        {
                            foreach (var chk in list.OrderBy(x => x.ChunkID))
                            {
                                if (chk.ChunkID == id)
                                {
                                    id++;
                                }
                            }
                        }
                        obj.ChunkID = id;
                        //add it to the iff file
                        TargetIff.AddChunk(obj);
                    }, obj));

                    if (IsNew)
                    {
                        //add a default animation table, for quality of life reasons

                        var anim = new STR()
                        {
                            ChunkLabel     = name,
                            ChunkID        = 128,
                            ChunkProcessed = true,
                            ChunkType      = "STR#",
                            ChunkParent    = TargetIff,
                        };

                        anim.InsertString(0, new STRItem {
                            Value = "", Comment = ""
                        });
                        TargetIff.AddChunk(anim);

                        var filename = TargetIff.RuntimeInfo.Path;
                        Directory.CreateDirectory(Path.GetDirectoryName(filename));
                        using (var stream = new FileStream(filename, FileMode.Create))
                            TargetIff.Write(stream);
                    }

                    //add it to the provider
                    objProvider.AddObject(TargetIff, obj);

                    DialogResult = DialogResult.OK;
                    ResultGUID   = guid;
                    Close();
                }
            }
        }