Exemplo n.º 1
0
        private void GLSurface_DragDrop(object sender, DragEventArgs e)
        {
            try
            {
                if (!e.Data.GetDataPresent(DataFormats.FileDrop))
                {
                    return;
                }
                var paths = e.Data.GetData(DataFormats.FileDrop) as string[];
                if (paths.Length != 1 || Resource.GetType(paths[0]) != ResourceType.Tile)
                {
                    return;
                }
                var path = ExtraPath.MakeDirectoryRelated(Directory.GetCurrentDirectory(), paths[0]);

                bool insert = !GLSurface.TileLoaded(path);

                if (GLSurface.LoadTile(path, path))
                {
                    if (insert)
                    {
                        TileComboBox.Items.Add(path);
                    }
                    var pos = GLSurface.AdjustMouse(GLSurface.PointToClient(new Point(e.X, e.Y)));
                    MouseManager.UpdateLocation(pos);

                    int tx = (int)Math.Round(-OffsetX + pos.X + GLSurface.FieldW / 2 - 0.5);
                    int ty = (int)Math.Round(-OffsetY + pos.Y + GLSurface.FieldH / 2 - 0.5);

                    if (GLSurface.GetTile(tx, ty) == null)
                    {
                        GLSurface.PlaceTile(path, tx, ty);
                    }
                    else
                    {
                        GLSurface.PlaceTile(null, tx, ty);
                    }

                    TileComboBox.SelectedItem = path;
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(this, ex.ToString(), "Error: Can not place tile.",
                                MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
Exemplo n.º 2
0
        private void VariantsListBox_DragDrop(object sender, DragEventArgs e)
        {
            try
            {
                int sind = PartsListBox.SelectedIndex;
                if (sind < 0 || sind >= LoadedResource.Sprites.Count)
                {
                    return;
                }
                var sprites = LoadedResource.Sprites[sind];
                //int index = VariantsListBox.SelectedIndex;
                //if (index < 0 || index >= LoadedResource.Sprites[sind].Count) return;

                if (e.Data.GetDataPresent(DataFormats.FileDrop))
                {
                    var paths = e.Data.GetData(DataFormats.FileDrop) as string[];
                    var dpath = Directory.GetCurrentDirectory();
                    foreach (var path in paths)
                    {
                        if (!path.StartsWith(dpath))
                        {
                            MessageBox.Show(this,
                                            "Resource is not in description directory.",
                                            "Error: Invalid resource.", MessageBoxButtons.OK,
                                            MessageBoxIcon.Error);
                        }
                        else
                        {
                            var rpath = ExtraPath.MakeDirectoryRelated(dpath, path);
                            sprites.Add(new Subresource <SpriteResource>(rpath, true));
                            VariantsListBox.Items.Add(rpath);
                        }
                    }
                    BackupChanges();
                    MakeUnsaved();
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(this, ex.ToString(), "Error: Can not link sprites.",
                                MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
Exemplo n.º 3
0
        private void LinkTextBox_DragDrop(object sender, DragEventArgs e)
        {
            try
            {
                if (e.Data.GetDataPresent(DataFormats.FileDrop))
                {
                    var paths = e.Data.GetData(DataFormats.FileDrop) as string[];
                    if (paths.Length != 1)
                    {
                        MessageBox.Show(this, "You must choose only one image file.",
                                        "Error: Can not import [" + paths.Length + "] files.",
                                        MessageBoxButtons.OK, MessageBoxIcon.Error);
                        return;
                    }

                    var fpath = paths[0];
                    var dpath = Directory.GetCurrentDirectory();
                    if (!fpath.StartsWith(dpath))
                    {
                        MessageBox.Show(this,
                                        "Resource is not in description directory.",
                                        "Error: Invalid resource.", MessageBoxButtons.OK,
                                        MessageBoxIcon.Error);
                    }
                    else
                    {
                        LinkTextBox.Text = ExtraPath.MakeDirectoryRelated(dpath, fpath);
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(this, ex.ToString(), "Error: Can not link texture.",
                                MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
Exemplo n.º 4
0
 private void Watcher_Renamed(object sender, RenamedEventArgs e)
 {
     _Link = ExtraPath.MakeDirectoryRelated(Directory.GetCurrentDirectory(), e.FullPath);
     Updated?.Invoke(this, EventArgs.Empty);
     Reload();
 }
Exemplo n.º 5
0
        private void LoaderWorker_DoWork(object sender, DoWorkEventArgs e)
        {
            LoaderWorker.ReportProgress(0);

            if (File.Exists(TablePath))
            {
                LogQueue.Put("Reading ID table...");
                using (var r = File.OpenText(TablePath))
                {
                    while (!r.EndOfStream)
                    {
                        var line = r.ReadLine();
                        switch (line)
                        {
                        case "[Tiles]": TilesIDTable.Read(r, (string path) => { return(Resource.GetType(path) == ResourceType.Tile); }); break;

                        case "[Events]": EventsIDTable.Read(r, (string path) => { return(Resource.GetType(path) == ResourceType.Event); }); break;

                        case "[Entities]": EntitiesIDTable.Read(r, (string path) => { return(Resource.GetType(path) == ResourceType.Entity); }); break;

                        case "[Outfits]": OutfitsIDTable.Read(r, (string path) => { return(Resource.GetType(path) == ResourceType.Outfit); }); break;

                        case "[Items]": ItemsIDTable.Read(r, (string path) => { return(Resource.GetType(path) == ResourceType.Item); }); break;
                        }
                    }
                }
                LogQueue.Put("Tiles loaded: " + TilesIDTable.Count);
                LogQueue.Put("Tiles valid: " + TilesIDTable.Items.Count((IDTable.Item i) => { return(i.Valid); }));
                LogQueue.Put("Events loaded: " + EventsIDTable.Count);
                LogQueue.Put("Events valid: " + EventsIDTable.Items.Count((IDTable.Item i) => { return(i.Valid); }));
                LogQueue.Put("Entities loaded: " + EntitiesIDTable.Count);
                LogQueue.Put("Entities valid: " + EntitiesIDTable.Items.Count((IDTable.Item i) => { return(i.Valid); }));
                LogQueue.Put("Outfits loaded: " + OutfitsIDTable.Count);
                LogQueue.Put("Outfits valid: " + OutfitsIDTable.Items.Count((IDTable.Item i) => { return(i.Valid); }));
                LogQueue.Put("items loaded: " + ItemsIDTable.Count);
                LogQueue.Put("Items valid: " + ItemsIDTable.Items.Count((IDTable.Item i) => { return(i.Valid); }));
                LogQueue.Put("Reading ID table done.");
            }
            else
            {
                LogQueue.Put("ID table not found.");
            }
            LogQueue.Put("");

            LoaderWorker.ReportProgress(5);

            LogQueue.Put("Indexing files...");
            string[] paths = Directory.GetFiles(Directory.GetCurrentDirectory(), "*", SearchOption.AllDirectories);
            for (int i = 0; i < paths.Length; i++)
            {
                paths[i] = ExtraPath.MakeDirectoryRelated(Directory.GetCurrentDirectory(), paths[i]);
            }
            LogQueue.Put("Files found: " + paths.Length);
            LogQueue.Put("Indexing files done.");
            LogQueue.Put("");

            LoaderWorker.ReportProgress(10);

            LogQueue.Put("Searching resources...");
            int progress = 0;

            for (int i = 0; i < paths.Length; i++)
            {
                int current_progress = i * 90 / (paths.Length - 1);
                if (progress != current_progress)
                {
                    progress = current_progress;
                    LoaderWorker.ReportProgress(10 + progress);
                }

                var path = paths[i];
                switch (Resource.GetType(path))
                {
                case ResourceType.Tile: TilesIDTable.Add(path); break;

                case ResourceType.Event: EventsIDTable.Add(path); break;

                case ResourceType.Sprite: SpritesIDTable.Add(path); break;

                case ResourceType.Ragdoll: RagdollsIDTable.Add(path); break;

                case ResourceType.Animation: AnimationsIDTable.Add(path); break;

                case ResourceType.Entity: EntitiesIDTable.Add(path); break;

                case ResourceType.Outfit: OutfitsIDTable.Add(path); break;

                case ResourceType.Item: ItemsIDTable.Add(path); break;
                }
            }
            LogQueue.Put("Tiles found: " + TilesIDTable.Count);
            LogQueue.Put("Events found: " + EventsIDTable.Count);
            LogQueue.Put("Sprites found: " + SpritesIDTable.Count);
            LogQueue.Put("Ragdolls found: " + RagdollsIDTable.Count);
            LogQueue.Put("Animations found: " + AnimationsIDTable.Count);
            LogQueue.Put("Entities found: " + EntitiesIDTable.Count);
            LogQueue.Put("Outfits found: " + OutfitsIDTable.Count);
            LogQueue.Put("Items found: " + ItemsIDTable.Count);
            LogQueue.Put("Total resources found: " + (
                             TilesIDTable.Count +
                             EventsIDTable.Count +
                             SpritesIDTable.Count +
                             RagdollsIDTable.Count +
                             AnimationsIDTable.Count +
                             EntitiesIDTable.Count +
                             OutfitsIDTable.Count +
                             ItemsIDTable.Count));
            LogQueue.Put("Searching resources done.");
            LogQueue.Put("");
        }