Exemplo n.º 1
0
        private void imgColor_Click(object sender, EventArgs e)
        {
            using (ObjectSelector selector = new ObjectSelector()) {
                int imgSize = 48;
                selector.ClientSize = new Size(imgSize * 7, imgSize * 5);
                foreach (KeyValuePair <short, Color> pair in Palette.Colors)
                {
                    if (pair.Value.A == 0)
                    {
                        continue;
                    }

                    Bitmap img = new Bitmap(imgSize, imgSize);
                    using (Graphics g = Graphics.FromImage(img)) {
                        using (SolidBrush brush = new SolidBrush(pair.Value)) {
                            g.FillRectangle(brush, 0, 0, imgSize, imgSize);
                        }
                    }
                    ListItem item = new ListItem(new KeyValuePair <short, Color>(pair.Key, pair.Value), pair.Key.ToString("00000"), img);
                    selector.AddItem(item, pair.Key == flower.Color);
                }

                selector.SortItems();
                selector.BackColor = Palette.Edge;
                selector.Icon      = this.Icon;
                DialogResult result = selector.ShowDialog(this);
                if (result == DialogResult.OK)
                {
                    KeyValuePair <short, Color> pair = (KeyValuePair <short, Color>)selector.SelectedItem;
                    flower.Color       = pair.Key;
                    imgColor.BackColor = pair.Value;
                }
            }
        }
Exemplo n.º 2
0
        private void btnSetLevel_Click(object sender, EventArgs e)
        {
            string text = txtFile.Text;

            using (ObjectSelector selector = new ObjectSelector()) {
                selector.DrawText = true;

                int imgWidth   = WorldViewer.LevelImageWidth;
                int imgHeight  = WorldViewer.LevelImageHeight;
                int addedCount = LevelList.Count;
                for (int i = 0; i < addedCount; i++)
                {
                    ListItem level = LevelList[i];
                    Grid     map   = (Grid)level.Value;

                    ListItem item = new ListItem(map, map.Name, imgWidth, imgHeight);
                    item.BackColor = level.BackColor;
                    selector.AddItem(item, map.FileName.Equals(text, StringComparison.OrdinalIgnoreCase));
                }

                selector.BackColor = this.BackColor;
                selector.Icon      = this.Icon;

                if (addedCount == 0)
                {
                    MessageBox.Show(this, "No level maps to choose from.");
                    return;
                }

                Size size = Renderer.GetSizeForCount(addedCount, 5, 6);
                selector.ClientSize = new Size(imgWidth * size.Width, imgHeight * size.Height);
                selector.SortByText = LevelList.SortByText;
                selector.SortItems();
                selector.SetRenderItem(delegate(ListItem item, Graphics g) {
                    Grid grid = (Grid)item.Value;
                    Renderer.Render(grid, g, item.Width, item.Height);
                });

                DialogResult result = selector.ShowDialog(this);
                if (result == DialogResult.OK)
                {
                    Grid map = (Grid)selector.SelectedItem;
                    levelCopy.Name = map.Name;
                    levelCopy.File = map.FileName;
                    txtFile.Text   = map.FileName;
                    txtName.Text   = map.Name;
                }
            }
        }
Exemplo n.º 3
0
        private void imgObject_Click(object sender, EventArgs e)
        {
            using (ObjectSelector selector = new ObjectSelector()) {
                int spriteCount = 0;
                foreach (Item spriteItem in Reader.DefaultsByObject.Values)
                {
                    if (spriteItem.ID <= 0 || string.IsNullOrEmpty(spriteItem.Sprite))
                    {
                        continue;
                    }

                    spriteCount++;
                }
                Size size = Renderer.GetSizeForCount(spriteCount);

                int imgSize = WorldViewer.Instance.Width / (size.Width + 1);
                if (imgSize * (size.Height + 2) > WorldViewer.Instance.Height)
                {
                    imgSize = WorldViewer.Instance.Height / (size.Height + 2);
                }
                if (imgSize > 48)
                {
                    imgSize = 48;
                }

                Rectangle rect = new Rectangle(0, 0, imgSize, imgSize);
                foreach (Item spriteItem in Reader.DefaultsByObject.Values)
                {
                    if (spriteItem.ID <= 0 || string.IsNullOrEmpty(spriteItem.Sprite))
                    {
                        continue;
                    }

                    ItemChange change;
                    Item       copy = spriteItem;
                    if (Map.Changes.TryGetValue(spriteItem.ID, out change))
                    {
                        copy = copy.Copy();
                        change.Apply(copy);
                    }

                    string name  = copy.Name;
                    int    index = name.IndexOf("text");
                    if (index == 0)
                    {
                        name = name.Substring(5) + "_text";
                    }

                    Bitmap img = new Bitmap(imgSize, imgSize);
                    using (Graphics g = Graphics.FromImage(img)) {
                        Renderer.DrawSprite(null, g, rect, copy, Palette);
                    }
                    ListItem item = new ListItem(copy, name, img);
                    item.BackColor = Palette.Background;
                    selector.AddItem(item, copy.Name == pathCopy.Name);
                }

                selector.BackColor  = Palette.Edge;
                selector.Icon       = this.Icon;
                selector.ClientSize = new Size(imgSize * size.Width, imgSize * size.Height);
                selector.SortItems();

                DialogResult result = selector.ShowDialog(this);
                if (result == DialogResult.OK)
                {
                    Item item = (Item)selector.SelectedItem;
                    pathCopy.Object = item.Object;
                    UpdateObject();
                }
            }
        }
Exemplo n.º 4
0
        private void imgIcon_Click(object sender, EventArgs e)
        {
            if (imgIcon.Cursor != Cursors.Hand)
            {
                return;
            }

            using (ObjectSelector selector = new ObjectSelector()) {
                int spriteCount = 0;
                foreach (Sprite sprite in Reader.Sprites.Values)
                {
                    if (sprite.Name.IndexOf("img_") == 0)
                    {
                        continue;
                    }

                    spriteCount++;
                }
                Size size = Renderer.GetSizeForCount(spriteCount);

                int imgSize = WorldViewer.Instance.Width / (size.Width + 1);
                if (imgSize * (size.Height + 2) > WorldViewer.Instance.Height)
                {
                    imgSize = WorldViewer.Instance.Height / (size.Height + 2);
                }
                if (imgSize > 48)
                {
                    imgSize = 48;
                }

                Rectangle rect  = new Rectangle(0, 0, imgSize, imgSize);
                Color     color = Palette.Colors[levelCopy.ActiveColor >= 0 ? levelCopy.ActiveColor : levelCopy.Color];
                foreach (Sprite sprite in Reader.Sprites.Values)
                {
                    if (sprite.Name.IndexOf("img_") == 0)
                    {
                        continue;
                    }

                    string name  = sprite.Name;
                    int    index = name.IndexOf("text");
                    if (index == 0)
                    {
                        name = name.Substring(5) + "_text";
                    }

                    Bitmap img = new Bitmap(imgSize, imgSize);
                    using (Graphics g = Graphics.FromImage(img)) {
                        Renderer.DrawSprite(g, rect, sprite, color);
                    }
                    ListItem item = new ListItem(sprite, name, img);
                    item.BackColor = Palette.Background;
                    selector.AddItem(item, levelCopy.Sprite == sprite.Name);
                }

                selector.BackColor = Palette.Edge;
                selector.Icon      = this.Icon;


                selector.ClientSize = new Size(imgSize * size.Width, imgSize * size.Height);
                selector.SortItems();

                DialogResult result = selector.ShowDialog(this);
                if (result == DialogResult.OK)
                {
                    Sprite sprite = (Sprite)selector.SelectedItem;
                    levelCopy.Sprite       = sprite.Name;
                    levelCopy.SpriteInRoot = sprite.IsRoot;
                    UpdateIcon();
                }
            }
        }
Exemplo n.º 5
0
        private void imgCurrent_Click(object sender, EventArgs e)
        {
            using (ObjectSelector selector = new ObjectSelector()) {
                int spriteCount = 0;
                foreach (Sprite sprite in Reader.Sprites.Values)
                {
                    if (sprite.Name.IndexOf("img_") == 0 || sprite.Name.IndexOf("icon_") == 0)
                    {
                        continue;
                    }

                    spriteCount++;
                }
                Size size = Renderer.GetSizeForCount(spriteCount);

                int imgSize = WorldViewer.Instance.Width / (size.Width + 1);
                if (imgSize * (size.Height + 2) > WorldViewer.Instance.Height)
                {
                    imgSize = WorldViewer.Instance.Height / (size.Height + 2);
                }
                if (imgSize > 48)
                {
                    imgSize = 48;
                }

                Rectangle rect  = new Rectangle(0, 0, imgSize, imgSize);
                Color     color = Palette.Colors[Edit.ActiveColor >= 0 ? Edit.ActiveColor : Edit.Color];
                foreach (Sprite sprite in Reader.Sprites.Values)
                {
                    if (sprite.Name.IndexOf("img_") == 0 || sprite.Name.IndexOf("icon_") == 0)
                    {
                        continue;
                    }

                    string name  = sprite.Name;
                    int    index = name.IndexOf("text");
                    if (index == 0)
                    {
                        name = name.Substring(5) + "_text";
                    }

                    Bitmap img = new Bitmap(imgSize, imgSize);
                    using (Graphics g = Graphics.FromImage(img)) {
                        Renderer.DrawSprite(g, rect, sprite, color);
                    }
                    ListItem item = new ListItem(sprite, name, img);
                    item.BackColor = Palette.Background;
                    selector.AddItem(item, sender == imgObject ? Edit.Name.Equals(sprite.Name, StringComparison.OrdinalIgnoreCase) : Edit.Sprite.Equals(sprite.Name, StringComparison.OrdinalIgnoreCase));
                }

                selector.BackColor  = Palette.Edge;
                selector.Icon       = this.Icon;
                selector.ClientSize = new Size(imgSize * size.Width, imgSize * size.Height);
                selector.SortItems();

                DialogResult result = selector.ShowDialog(this);
                if (result == DialogResult.OK)
                {
                    Sprite sprite = (Sprite)selector.SelectedItem;
                    Edit.Name          = sender == imgImage ? Edit.Name : sprite.Name;
                    txtObjectText.Text = Edit.Name;
                    Edit.Sprite        = sender == imgImage ? sprite.Name : Edit.Sprite;
                    Edit.SpriteInRoot  = sender == imgImage ? sprite.IsRoot : Edit.SpriteInRoot;
                    Edit.IsObject      = Edit.Name.IndexOf("text_") < 0;
                    if (Edit.IsObject)
                    {
                        Edit.ActiveColor = -1;
                        Edit.ArgExtra    = null;
                        Edit.ArgType     = null;
                    }

                    Item item;
                    if (sender == imgObject)
                    {
                        if (Reader.DefaultsByName.TryGetValue(Edit.Name, out item))
                        {
                            Edit.Type = item.Type;
                            if (!Edit.IsObject)
                            {
                                if (Edit.ActiveColor < 0)
                                {
                                    Edit.ActiveColor = Edit.Color;
                                }
                                Edit.ArgExtra = item.ArgExtra;
                                Edit.ArgType  = item.ArgType;
                            }
                        }
                        else
                        {
                            Edit.Type = 0;
                        }
                    }

                    if (sender == imgImage)
                    {
                        if (Reader.DefaultsByName.TryGetValue(Edit.Sprite, out item))
                        {
                            Edit.Tiling = item.Tiling;
                            if (!Edit.IsObject && Edit.ActiveColor < 0)
                            {
                                Edit.ActiveColor = Edit.Color;
                            }
                        }
                        else
                        {
                            switch (sprite.MaxIndex)
                            {
                            case 31: Edit.Tiling = (byte)Tiling.Character; break;

                            case 27: Edit.Tiling = (byte)Tiling.Animated; break;

                            case 24: Edit.Tiling = (byte)Tiling.Directional; break;

                            case 15: Edit.Tiling = (byte)Tiling.Tiled; break;

                            case 3: Edit.Tiling = (byte)Tiling.SingleAnimated; break;

                            default: Edit.Tiling = (byte)Tiling.None; break;
                            }
                        }
                    }

                    UpdateImages();
                }
            }
        }