Exemple #1
0
        public virtual int GetTile(int x, int y, PluginManager manager)
        {
            Room room = manager.GetActiveRoom();
            int  t    = room.GetTile(x, y);

            if (!tiles.Contains(t) || ignoreTiles.Contains(t))
            {
                return(t);
            }

            Func <int, bool> f = a => {
                return(tiles.Contains(a));
            };

            return(GetTileBy(x, y, manager, f));
        }
Exemple #2
0
        public void Apply(PluginManager manager)
        {
            if (baseTiles[0, 0] == -1)
            {
                return;
            }

            AssembleTiles();

            Room room = manager.GetActiveRoom();

            for (int y = 0; y < room.Height; y++)
            {
                for (int x = 0; x < room.Width; x++)
                {
                    int t = GetTile(x, y, manager);
                    if (t != room.GetTile(x, y))
                    {
                        room.SetTile(x, y, t);
                    }
                }
            }
        }
Exemple #3
0
        public override void Clicked()
        {
            Treasure.Project = Project;
            Chest.Project    = Project;

            Gtk.Window win = new Window(WindowType.Toplevel);
            Alignment  warningsContainer = new Alignment(0.1f, 0.1f, 0f, 0f);

            VBox vbox = new VBox();

            var chestGui = new ChestEditorGui(manager);

            chestGui.SetRoom(manager.GetActiveRoom().Index);
            chestGui.Destroyed += (sender2, e2) => win.Destroy();

            Frame chestFrame = new Frame();

            chestFrame.Label = "Chest Data";
            chestFrame.Add(chestGui);

            var   treasureGui   = new TreasureEditorGui(manager);
            Frame treasureFrame = new Frame();

            treasureFrame.Label = "Treasure Data";
            treasureFrame.Add(treasureGui);

            System.Action UpdateWarnings = () => {
                VBox warningBox = new VBox();
                warningBox.Spacing = 4;

                System.Action <string> AddWarning = (s) => {
                    Image img = new Image(Stock.DialogWarning, IconSize.Button);
                    HBox  hb  = new HBox();
                    hb.Spacing = 10;
                    hb.Add(img);
                    Gtk.Label l = new Gtk.Label(s);
                    l.LineWrap = true;
                    hb.Add(l);
                    Alignment a = new  Alignment(0, 0, 0, 0);
                    a.Add(hb);
                    warningBox.Add(a);
                };

                foreach (var c in warningsContainer.Children)
                {
                    warningsContainer.Remove(c);
                }

                int index = chestGui.GetTreasureIndex();
                if (index < 0)
                {
                    return;
                }

                if (!Treasure.IndexExists(index))
                {
                    AddWarning("Treasure " + Wla.ToWord(index) + " does not exist.");
                }
                else
                {
                    if (index != treasureGui.Index)
                    {
                        AddWarning("Your treasure index is different\nfrom the chest you're editing.");
                    }

                    int spawnMode = (Treasure.GetTreasureByte(index, 0) >> 4) & 7;

                    if (spawnMode != 3)
                    {
                        AddWarning("Treasure " + Wla.ToWord(index) + " doesn't have spawn\nmode $3 (needed for chests).");
                    }

                    int  yx = Chest.GetChestByte(chestGui.RoomIndex, 0);
                    int  x  = yx & 0xf;
                    int  y  = yx >> 4;
                    Room r  = Project.GetIndexedDataType <Room>(chestGui.RoomIndex);
                    if (x >= r.Width || y >= r.Height || r.GetTile(x, y) != 0xf1)
                    {
                        AddWarning("There is no chest at coordinates (" + x + "," + y + ").");
                    }
                }

                warningsContainer.Add(warningBox);

                win.ShowAll();
            };

            chestGui.SetTreasureEditor(treasureGui);
            chestGui.ChestChangedEvent += () => {
                UpdateWarnings();
            };
            treasureGui.TreasureChangedEvent += () => {
                UpdateWarnings();
            };

            HBox hbox = new Gtk.HBox();

            hbox.Spacing = 6;
            hbox.Add(chestFrame);
            hbox.Add(treasureFrame);

            Button okButton = new Gtk.Button();

            okButton.UseStock = true;
            okButton.Label    = "gtk-ok";
            okButton.Clicked += (a, b) => {
                win.Destroy();
            };

            Alignment buttonAlign = new Alignment(0.5f, 0.5f, 0f, 0f);

            buttonAlign.Add(okButton);

            vbox.Add(hbox);
            vbox.Add(warningsContainer);
            vbox.Add(buttonAlign);

            win.Add(vbox);

            UpdateWarnings();
            win.ShowAll();
        }
Exemple #4
0
        public override void Clicked()
        {
            Room room = manager.GetActiveRoom();
            int  area = room.Area.Index;

            var reader = new XmlTextReader("Plugins/AutoSmoother.xml");

            Smoother smoother  = new Smoother();
            bool     validArea = false;

            string name = "";

            while (reader.Read())
            {
                string s;

                switch (reader.NodeType)
                {
                case XmlNodeType.Element:
                    name = reader.Name;
                    switch (name)
                    {
                    case "area":
                        s = reader.GetAttribute("index");
                        List <int> ints = GetIntList(s);
                        validArea = ints.Contains(area);
                        break;
                    }
                    break;

                case XmlNodeType.Text:
                    if (!validArea)
                    {
                        continue;
                    }

                    s = reader.Value.Trim();
                    switch (name)
                    {
                    case "base":
                    {
                        IEnumerable <int> values = Regex.Split(s, @"\s+")
                                                   .Select(a => Convert.ToInt32(a, 16));
                        int c = 0;
                        foreach (int i in values)
                        {
                            smoother.baseTiles[c / 3, c % 3] = i;
                            c++;
                        }
                    }
                    break;

                    case "horizontal":
                    {
                        IEnumerable <int> values = Regex.Split(s, @"\s+")
                                                   .Select(a => Convert.ToInt32(a, 16));
                        int c = 0;
                        foreach (int i in values)
                        {
                            smoother.hTiles[c] = i;
                            c++;
                        }
                    }
                    break;

                    case "vertical":
                    {
                        IEnumerable <int> values = Regex.Split(s, @"\s+")
                                                   .Select(a => Convert.ToInt32(a, 16));
                        int c = 0;
                        foreach (int i in values)
                        {
                            smoother.vTiles[c] = i;
                            c++;
                        }
                    }
                    break;

                    case "friendly":
                    {
                        s = Regex.Replace(s, @"\s", "");
                        List <int> ints = GetIntList(s);
                        foreach (int i in ints)
                        {
                            smoother.ignoreTiles.Add(i);
                        }
                    }
                    break;
                    }
                    break;

                case XmlNodeType.EndElement:
                    switch (reader.Name)
                    {
                    case "area":
                        validArea = false;
                        break;

                    case "smoother":
                        smoother.Apply(manager);
                        smoother = new Smoother();
                        break;
                    }
                    name = "";
                    break;
                }
            }
        }