public void addNewTile()
        {
            //Return if unoriginal
            Mapfile.TileData ignoreButTex = new Mapfile.TileData("");
            ignoreButTex.setToIgnore();
            ignoreButTex.texture = editor.currentValues.texture;
            if (ignoreButTex.Equals(editor.currentTile))
            {
                return;
            }

            //Get tile data
            Mapfile.TileData tempData = editor.currentTile;
            numAdded++;

            //Create button
            GUIButton tempButton = new GUIButton(editor.editorGui, (tempData.texture == Mapfile.TileData.IGNORESTRING) ? null : editor.engine.resourceComponent.get(tempData.texture), text: ((tempData.texture == "") ? "n" : "") + numAdded.ToString());

            tempButton.size             = new Vector2(Tile.size, Tile.size);
            tempButton.mouseClickEvent += (mpos, mbutton) =>
            {
                editor.currentTile = tempData;
                editor.currentValues.overWriteData(editor.currentTile);
                updateStatus();
            };

            //Add button
            thumbs.add(tempButton);
            toolDialog.add(tempButton);
            editor.editorGui.add(tempButton); //should upwardly recursive add
            thumbs.performLayout();
        }
        public Tile prevTile;                   //The previous Tile under the mouse

        /*
         * Constructor. Instantiates the current brushes.
         */
        public EditorComponent(MirrorEngine engine)
            : base(engine)
        {
            lastPos = new Vector2(0, 0);

            currentValues = new Mapfile.TileData("");
            currentTile.setToIgnore();
            currentTile.texture = currentValues.texture;

            isActive = false;
        }
        public void drawTiles()
        {
            if (mode != Mode.paste)
            {
                return;
            }

            GraphicsComponent gc       = editor.engine.graphicsComponent;
            RectangleF        viewRect = gc.camera.viewRect;

            Mapfile.TileData ignoreTile = new Mapfile.TileData("");
            ignoreTile.setToIgnore();

            for (int x = 0; x <= (int)selection.width; x++)
            {
                for (int y = 0; y <= (int)selection.height; y++)
                {
                    if (ignoreTile.Equals(copiedTileData[x, y]))
                    {
                        continue;                                         //Not commutative
                    }
                    Tile t = new Tile(editor.engine.world, (int)selection.left + x, (int)selection.top + y, copiedTiles[x, y].tileData);

                    Vector2 pos      = gc.camera.world2Screen(new Vector2(t.x, t.y));
                    Vector2 specPos  = gc.camera.world2Screen(new Vector2(t.x + Tile.size / 2, t.y + Tile.size / 2));
                    int     flagSize = (int)(editor.editorGui.solid.getResource <Texture2D>().width *gc.camera.scale);

                    //texture
                    if (t.texture.key == "")
                    {
                        gc.drawText("nul", (int)pos.x, (int)pos.y, editor.editorGui.font, Color.WHITE, (int)(12 * gc.camera.scale));
                    }
                    else
                    {
                        gc.drawTex(editor.engine.resourceComponent.get(copiedTileData[x, y].texture), (int)pos.x, (int)pos.y, (int)(t.imageWidth * gc.camera.scale), (int)(t.imageHeight * gc.camera.scale), new Color(1, 1, 1, .4f));
                    }

                    //Nonstandard overlay
                    if (t.tileData.isNonstandard())
                    {
                        editor.editorGui.graphics.drawRect((int)(pos.x + (2 * gc.camera.scale)), (int)(pos.y + (2 * gc.camera.scale)), (int)((Tile.size - 4) * gc.camera.scale), (int)((Tile.size - 4) * gc.camera.scale), new Color(1, 0, 1, .3f));
                    }

                    //solidity
                    if (t.solidity)
                    {
                        gc.drawTex(editor.editorGui.solid, (int)pos.x, (int)pos.y, flagSize, flagSize, new Color(1, 1, 1, .8f));
                    }
                    else
                    {
                        gc.drawTex(editor.editorGui.solidX, (int)pos.x, (int)pos.y, flagSize, flagSize, new Color(1, 1, 1, .8f));
                    }

                    //opacity
                    if (t.opacityFlip)
                    {
                        gc.drawTex(editor.editorGui.opaque, (int)(specPos.x), (int)(specPos.y), flagSize, flagSize, new Color(1, 1, 1, .8f));
                    }
                    else
                    {
                        gc.drawTex(editor.editorGui.opacityX, (int)(specPos.x), (int)(specPos.y), flagSize, flagSize, new Color(1, 1, 1, .8f));
                    }
                }
            }
        }
Пример #4
0
        /**
         * desc here
         *
         * @param paramsdeschere
         *
         * @return returndeschere
         */
        public FillToolAction fill(Tile startTile)
        {
            Mapfile.TileData ignoreTile = new Mapfile.TileData();
            ignoreTile.setToIgnore();
            if (ignoreTile.Equals(fillCriteria))
            {
                return(null);
            }

            LinkedList <TextureData> changed = new LinkedList <TextureData>(); // for undo

            Mapfile.TileData std         = editor.engine.world.file.worldTileData[0, startTile.xIndex, startTile.yIndex];
            Mapfile.TileData tempCrit    = fillCriteria;
            bool             inSelection = false;

            if (!selectionBox.isDown && editor.selectionTool.selection.contains(new Vector2(startTile.xIndex, startTile.yIndex)))
            {
                inSelection = true;
            }

            tempCrit.overWriteData(std);

            //update actions
            Queue <Tile> applyToMe   = new Queue <Tile>();
            List <Tile>  appliedToMe = new List <Tile>();

            applyToMe.Enqueue(startTile);
            changed.AddLast(new TextureData(startTile.xIndex, startTile.yIndex));

            //Update start tile and its tiledata
            editor.engine.world.file.worldTileData[0, startTile.xIndex, startTile.yIndex].overWriteData(editor.currentTile);
            startTile.overWriteFromTileData(editor.currentTile);

            while (applyToMe.Count() > 0)
            {
                Tile mid = applyToMe.Dequeue();
                foreach (Tile tile in mid.adjacent)
                {
                    if (tile != null && !appliedToMe.Contains(tile))
                    {
                        Mapfile.TileData td = editor.engine.world.file.worldTileData[0, tile.xIndex, tile.yIndex];

                        bool apply = false;

                        //Constrain to opted criteria
                        if (opControl.pressed == (int)Operator.AND)
                        {
                            apply = td.Equals(tempCrit);
                        }
                        else if (opControl.pressed == (int)Operator.OR)
                        {
                            if (fillCriteria.texture != Mapfile.TileData.IGNORESTRING && td.texture == tempCrit.texture)
                            {
                                apply = true;
                            }
                            if (fillCriteria.solidity != Mapfile.TileData.IGNOREBYTE && td.solidity == tempCrit.solidity)
                            {
                                apply = true;
                            }
                            if (fillCriteria.opacityFlip != Mapfile.TileData.IGNOREBYTE && td.opacityFlip == tempCrit.opacityFlip)
                            {
                                apply = true;
                            }
                        }

                        //Constrain to selection border if opted
                        if (!selectionBox.isDown)
                        {
                            if (inSelection ^ editor.selectionTool.selection.contains(new Vector2(tile.xIndex, tile.yIndex)))
                            {
                                apply = false;
                            }
                        }

                        if (apply)
                        {
                            //Update actions
                            applyToMe.Enqueue(tile);
                            changed.AddLast(new TextureData(tile.xIndex, tile.yIndex));

                            //Update current tile and tiledata
                            editor.engine.world.file.worldTileData[0, tile.xIndex, tile.yIndex].overWriteData(editor.currentTile);
                            tile.overWriteFromTileData(editor.currentTile);
                        }
                    }
                    appliedToMe.Add(tile);
                }
            }
            return(new FillToolAction(changed, "", startTile, this));
        }