Esempio n. 1
0
 public void SetSelected(bool Selected)
 {
     if (this.Selected != Selected)
     {
         if (Selected && !Toggleable)
         {
             foreach (Widget w in Parent.Widgets)
             {
                 if (!(w is IconButton))
                 {
                     continue;
                 }
                 IconButton b = w as IconButton;
                 if (b.Selected)
                 {
                     b.SetSelected(false);
                 }
             }
         }
         this.Selected = Selected;
         if (Selected)
         {
             this.OnSelection?.Invoke(new BaseEventArgs());
         }
         if (!Selected)
         {
             this.OnDeselection?.Invoke(new BaseEventArgs());
         }
         SetIcon(IconX, IconY, Selected);
     }
 }
Esempio n. 2
0
        public TilesPanel(IContainer Parent) : base(Parent)
        {
            Label Header = new Label(this);

            Header.SetText("Tiles");
            Header.SetFont(Font.Get("Fonts/Ubuntu-B", 16));
            Header.SetPosition(5, 5);

            Sprites["sep"]   = new Sprite(this.Viewport, new SolidBitmap(288, 2, new Color(10, 23, 37)));
            Sprites["sep"].Y = 50;

            Sprites["slider"]   = new Sprite(this.Viewport, new SolidBitmap(10, Size.Height - 34, new Color(10, 23, 37)));
            Sprites["slider"].Y = 53;

            this.OnWidgetSelected += WidgetSelected;

            CursorIM = new MouseInputManager(this);

            MainContainer = new Container(this);
            MainContainer.SetPosition(0, 53);
            MainContainer.VAutoScroll = true;

            VScrollBar vs = new VScrollBar(this);

            MainContainer.SetVScrollBar(vs);

            Cursor = new CursorWidget(MainContainer);
            Cursor.SetPosition(3, 8);
            Cursor.SetZIndex(1);

            MainStackPanel = new VStackPanel(MainContainer);
            MainStackPanel.SetWidth(264);
            MainStackPanel.SetPosition(8, 3);

            DrawToolsContainer = new Container(this);
            DrawToolsContainer.SetPosition(46, 22);
            DrawToolsContainer.SetSize(186, 28);
            DrawToolsContainer.Sprites["line1"]   = new Sprite(DrawToolsContainer.Viewport, new SolidBitmap(1, 26, new Color(28, 50, 73)));
            DrawToolsContainer.Sprites["line1"].X = 144;
            DrawToolsContainer.Sprites["line2"]   = new Sprite(DrawToolsContainer.Viewport, new SolidBitmap(1, 26, new Color(28, 50, 73)));
            DrawToolsContainer.Sprites["line2"].X = 185;

            PencilButton = new IconButton(DrawToolsContainer);
            PencilButton.SetIcon(15, 0);
            PencilButton.SetSelected(true);

            FillButton = new IconButton(DrawToolsContainer);
            FillButton.SetIcon(16, 0);
            FillButton.SetPosition(32, 0);

            EllipseButton = new IconButton(DrawToolsContainer);
            EllipseButton.SetIcon(17, 0);
            EllipseButton.SetPosition(64, 0);

            RectButton = new IconButton(DrawToolsContainer);
            RectButton.SetIcon(18, 0);
            RectButton.SetPosition(96, 0);

            SelectButton = new IconButton(DrawToolsContainer);
            SelectButton.SetIcon(19, 0);
            SelectButton.SetPosition(128, 0);
            SelectButton.OnSelection += delegate(BaseEventArgs e)
            {
                MapViewer.Cursor.SetVisible(false);
                Cursor.SetPosition(0, 0);
                Cursor.SetVisible(false);
            };
            SelectButton.OnDeselection += delegate(BaseEventArgs e)
            {
                UpdateCursor();
            };

            EraserButton = new IconButton(DrawToolsContainer);
            EraserButton.SetIcon(20, 0);
            EraserButton.SetPosition(160, 0);
            EraserButton.Toggleable   = true;
            EraserButton.OnSelection += delegate(BaseEventArgs e)
            {
                if (AutotileIndex != -1 || TilesetIndex != -1 || TileStartX != -1 || TileEndX != -1 || TileStartY != -1 || TileEndY != -1)
                {
                    SelectTile(null);
                }
            };
            EraserButton.OnDeselection += delegate(BaseEventArgs e)
            {
                if (AutotileIndex == -1 && TilesetIndex == -1 && TileStartX == -1 && TileEndX == -1 && TileStartY == -1 && TileEndY == -1 &&
                    !MapViewer.SelectionOnMap)
                {
                    SelectTile(0, 0, 0);
                }
                else
                {
                    UpdateCursor();
                }
            };

            SetSize(288, 200); // Dummy size so the sprites can be drawn properly
        }
Esempio n. 3
0
 public void SelectTile(int ContainerIndex, int TileX, int TileY)
 {
     if (ContainerIndex < AutotileContainers.Count) // Autotile
     {
         if (ContainerIndex == 0 && SingleAutotileCount > 0)
         {
             if (TileX + TileY * 8 >= SingleAutotileCount)
             {
                 return;
             }
             for (int i = 0; i < AutotileContainers.Count; i++)
             {
                 if (AutotileContainers[i] is int && (int)AutotileContainers[i] == TileX + TileY * 8)
                 {
                     this.AutotileIndex = i;
                 }
             }
         }
         else
         {
             int  container = SingleAutotileCount == 0 ? 0 : 1;
             int  idx       = -1;
             bool found     = false;
             for (int i = 0; i < AutotileContainers.Count; i++)
             {
                 if (AutotileContainers[i] is CollapsibleContainer)
                 {
                     if (container == ContainerIndex)
                     {
                         found = true;
                         idx   = (int)(AutotileContainers[i] as CollapsibleContainer).ObjectData;
                         break;
                     }
                     else
                     {
                         container++;
                     }
                 }
             }
             if (found)
             {
                 if (TileX > 1)
                 {
                     Autotile autotile = Data.Autotiles[MapData.AutotileIDs[idx]];
                     if (autotile.QuickIDs[TileX - 2] is null)
                     {
                         AutotilePickerMap atp = new AutotilePickerMap();
                         atp.SetAutotile(autotile);
                         atp.OnClosed += delegate(BaseEventArgs e)
                         {
                             if (atp.SelectedTileID != -1)
                             {
                                 this.AutotileIndex           = idx;
                                 this.AutotileCombination     = TileX - 2;
                                 autotile.QuickIDs[TileX - 2] = atp.SelectedTileID;
                                 DrawQuickAutotiles(idx);
                                 UpdateCursor();
                             }
                         };
                     }
                     else
                     {
                         if (TimerExists("double") && !TimerPassed("double") && DoubleClickIndex == idx && DoubleClickX == TileX)
                         {
                             AutotilePickerMap atp = new AutotilePickerMap();
                             atp.SetAutotile(autotile);
                             atp.OnClosed += delegate(BaseEventArgs e)
                             {
                                 if (atp.SelectedTileID != -1)
                                 {
                                     this.AutotileIndex           = idx;
                                     this.AutotileCombination     = TileX - 2;
                                     autotile.QuickIDs[TileX - 2] = atp.SelectedTileID;
                                     DrawQuickAutotiles(idx);
                                     UpdateCursor();
                                 }
                             };
                         }
                         if (TimerExists("double"))
                         {
                             DestroyTimer("double");
                         }
                         if (!TimerExists("double"))
                         {
                             SetTimer("double", 300);
                             DoubleClickIndex         = idx;
                             DoubleClickX             = TileX;
                             this.AutotileIndex       = idx;
                             this.AutotileCombination = TileX - 2;
                         }
                     }
                 }
                 else
                 {
                     this.AutotileIndex       = idx;
                     this.AutotileCombination = -1;
                 }
             }
             else
             {
                 throw new Exception("Couldn't find autotile index of the selected container.");
             }
         }
         this.TilesetIndex = this.TileStartX = this.TileEndX = this.TileStartY = this.TileEndY = -1;
     }
     else // Tileset
     {
         this.AutotileIndex       = -1;
         this.AutotileCombination = -1;
         this.TilesetIndex        = ContainerIndex - AutotileContainers.Count;
         this.TileStartX          = this.TileEndX = TileX;
         this.TileStartY          = this.TileEndY = TileY;
     }
     MapViewer.SelectionOnMap = false;
     if (EraserButton.Selected)
     {
         EraserButton.SetSelected(false);
     }
     if (SelectButton.Selected)
     {
         SelectButton.SetSelected(false);
         PencilButton.SetSelected(true);
     }
     UpdateCursor();
 }