コード例 #1
0
        void OnDragged(int x, int y, Gdk.Event triggerEvent)
        {
            if (EnableTileEditing && draggingTile)
            {
                if (IsInBounds(x, y, scale: false, offset: false))
                {
                    Cairo.Point p = GetGridPosition(x, y, scale: false, offset: false);
                    RoomLayout.SetTile(p.X, p.Y, TilesetViewer.SelectedIndex);
                }
            }
            if (DrawRoomComponents && draggingObject)
            {
                RoomComponent com = selectedComponent;
                if (com != null && com.HasXY)
                {
                    int newX, newY;
                    if (gdkState.HasFlag(Gdk.ModifierType.ControlMask) || com.HasShortenedXY)
                    {
                        newX = x;
                        newY = y;
                    }
                    else
                    {
                        // Move comects in increments of 8 pixels
                        int unit    = 8;
                        int unitLog = (int)Math.Log(unit, 2);

                        int dataX  = com.X + unit / 2;
                        int dataY  = com.Y + unit / 2;
                        int alignX = (dataX) % unit;
                        int alignY = (dataY) % unit;
                        newX = (x - alignX) >> unitLog;
                        newY = (y - alignY) >> unitLog;
                        newX = newX * unit + alignX + unit / 2;
                        newY = newY * unit + alignY + unit / 2;
                    }

                    if (newX >= 0 && newX < 256 && newY >= 0 && newY < 256)
                    {
                        com.X = (byte)newX;
                        com.Y = (byte)newY;
                    }

                    QueueDraw();
                }
            }
        }
コード例 #2
0
        public void Apply(PluginManager manager)
        {
            if (baseTiles[0, 0] == -1)
            {
                return;
            }

            AssembleTiles();

            RoomLayout room = manager.GetActiveRoomLayout();

            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);
                    }
                }
            }
        }
コード例 #3
0
        void OnClicked(int posX, int posY, Gdk.Event triggerEvent, uint button)
        {
            Cairo.Point p = GetGridPosition(posX, posY, scale: false, offset: false);
            if (EnableTileEditing && hoveringComponent == null)
            {
                if (!IsInBounds(posX, posY, scale: false, offset: false))
                {
                    return;
                }
                if (button == 1)   // Left-click
                {
                    RoomLayout.SetTile(p.X, p.Y, TilesetViewer.SelectedIndex);
                    draggingTile = true;
                }
                else if (button == 3)   // Right-click
                {
                    TilesetViewer.SelectedIndex = RoomLayout.GetTile(p.X, p.Y);
                }
            }
            if (DrawRoomComponents)
            {
                if (hoveringComponent != null)
                {
                    selectedComponent = hoveringComponent;
                    hoveringComponent.Select();

                    if (button == 1)   // Left click
                    {
                        draggingObject = true;
                    }
                    else if (button == 3)   // Right click
                    {
                        Gtk.Menu menu = new Gtk.Menu();

                        foreach (Gtk.MenuItem item in selectedComponent.GetRightClickMenuItems())
                        {
                            menu.Add(item);
                        }

                        RoomComponent comp = selectedComponent;

                        if (comp.Deletable)
                        {
                            if (menu.Children.Length != 0)
                            {
                                menu.Add(new Gtk.SeparatorMenuItem());
                            }

                            var deleteButton = new Gtk.MenuItem("Delete");
                            deleteButton.Activated += (sender, args) => {
                                comp.Delete();
                            };
                            menu.Add(deleteButton);
                        }

                        menu.AttachToWidget(this, null);
                        menu.ShowAll();
                        menu.PopupAtPointer(triggerEvent);
                    }
                }
            }
            QueueDraw();
        }