public void doPencil()
        {
            Vector2 screenPos = editor.engine.inputComponent.getMousePosition();
            Vector2 worldPos  = editor.engine.graphicsComponent.camera.screen2World(screenPos);

            Tile victim = editor.engine.world.getTileAt(worldPos);

            if (victim != null)
            {
                Mapfile.TileData td = editor.engine.world.file.worldTileData[0, victim.xIndex, victim.yIndex];
                if (td.Equals(editor.currentTile))
                {
                    return;
                }

                //Update Tiles and MapFile data
                editor.engine.world.file.worldTileData[0, victim.xIndex, victim.yIndex].overWriteData(editor.currentTile);
                victim.overWriteFromTileData(editor.currentTile);

                //Update actions
                LinkedList <TextureData> changed = new LinkedList <TextureData>();
                changed.AddLast(new TextureData(victim.xIndex, victim.yIndex));
                undos.Clear();
                toolAction.Push(new PencilToolAction(changed, new byte[] { 0 }, this));
            }
        }
        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();
        }
Пример #3
0
        /*
         * Uses the given TileData to update the tile's state
         */
        private void initFromTileData(Mapfile.TileData tileData)
        {
            this.tileData = tileData;
            texture       = world.engine.resourceComponent.get(tileData.texture);
            myBehavior    = world.constructTileBehavior(this, world.engine.resourceComponent.get(tileData.behavior));

            solidity    = tileData.solidity == 1;
            opacityFlip = tileData.opacityFlip == 1;
        }
Пример #4
0
        internal bool MAKERED;                //Dunno

        /**
         * Constructor. Initializes the tile using the given tileData
         */
        public Tile(World world, int xIndex, int yIndex, Mapfile.TileData tileData)
        {
            this.world  = world;
            this.xIndex = xIndex;
            this.yIndex = yIndex;
            actorsOn    = new List <Actor>();
            color       = new Color(world.ambientLight, world.ambientLight);

            initFromTileData(tileData);
        }
        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 copyAction(Vector2 pos, MouseKeyBinding.MouseButton button)
        {
            if (mode == Mode.paste)
            {
                return;
            }
            if (selection.topLeft == new Vector2(-1, -1))
            {
                return;
            }

            if (selection.size == Vector2.Zero)
            {
                editor.currentValues            = editor.engine.world.file.worldTileData[0, (int)selection.left, (int)selection.top];
                editor.currentValues.leftSlope  = 1f;
                editor.currentValues.rightSlope = 1f;
                editor.currentValues.normal     = 1;
                editor.currentTile = editor.currentValues;
                editor.pencilTool.updateStatus();
                return;
            }

            copiedSize     = selection.size;
            copiedTileData = new Mapfile.TileData[(int)selection.width + 1, (int)selection.height + 1];
            copiedTiles    = new Tile[(int)selection.width + 1, (int)selection.height + 1];
            Mapfile.TileData defaultTileData = new Mapfile.TileData("");

            for (int x = 0; x <= (int)selection.width; x++)
            {
                for (int y = 0; y <= (int)selection.height; y++)
                {
                    copiedTileData[x, y] = editor.engine.world.file.worldTileData[0, (int)selection.left + x, (int)selection.top + y];
                    if (copiedTileData[x, y].Equals(defaultTileData))
                    {
                        copiedTileData[x, y].setToIgnore();
                        copiedTiles[x, y] = new Tile(editor.engine.world, 0, 0, defaultTileData);
                    }
                    else
                    {
                        copiedTiles[x, y] = new Tile(editor.engine.world, (int)selection.left + x, (int)selection.top + y, copiedTileData[x, y]);
                    }
                }
            }

            mode = Mode.paste;
            modeControl.pressed = (int)mode;
        }
Пример #7
0
        /*
         * Overwrites the tile's state based on the non-ignore values of the given TileData
         */
        internal void overWriteFromTileData(Mapfile.TileData data)
        {
            tileData.overWriteData(data);

            if (data.texture != Mapfile.TileData.IGNORESTRING && data.texture != texture.key)
            {
                texture = world.engine.resourceComponent.get(data.texture);
            }
            if (data.behavior != Mapfile.TileData.IGNORESTRING && (myBehavior == null || data.behavior != myBehavior.scriptKey))
            {
                myBehavior = world.constructTileBehavior(this, world.engine.resourceComponent.get(data.behavior));
            }
            if (data.solidity != Mapfile.TileData.IGNOREBYTE)
            {
                solidity = data.solidity == 1;
            }
            if (data.opacityFlip != Mapfile.TileData.IGNOREBYTE)
            {
                opacityFlip = data.opacityFlip == 1;
            }
            //if (data.leftSlope != MapFile.TileData.IGNOREFLOAT) leftSlope = data.leftSlope;
            //if (data.rightSlope != MapFile.TileData.IGNOREFLOAT) rightSlope = data.rightSlope;
            //if (data.normal != MapFile.TileData.IGNOREBYTE) normal = data.normal;
        }
        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));
                    }
                }
            }
        }
        private void resize()
        {
            if (widthBox.text.Length == 0 || heightBox.text.Length == 0)
            {
                return;
            }

            //Get dimensions
            int width;
            int height;

            try
            {
                width  = Convert.ToInt32(widthBox.text);
                height = Convert.ToInt32(heightBox.text);
            }
            catch (Exception e) { return; }

            World   tempWorld = editor.engine.world;
            Mapfile tempFile  = tempWorld.file;

            Mapfile.TileData emptyTileData = new Mapfile.TileData("");

            //Create new arrays
            Tile[,] newTileArray = new Tile[width, height];
            Mapfile.TileData[, ,] newTileData = new Mapfile.TileData[1, width, height];

            //Transfer tiles
            for (int x = 0; x < width; x++)
            {
                for (int y = 0; y < height; y++)
                {
                    if (x < tempWorld.width && y < tempWorld.height)
                    {
                        newTileArray[x, y]   = tempWorld.tileArray[x, y];
                        newTileData[0, x, y] = tempFile.worldTileData[0, x, y];
                    }
                    else
                    {
                        newTileData[0, x, y] = emptyTileData;
                        newTileArray[x, y]   = new Tile(tempWorld, x, y, emptyTileData);
                    }
                }
            }

            //Erase actors
            List <Actor> actorsToErase = new List <Actor>();

            foreach (Actor a in tempWorld.actors)
            {
                if (tempWorld.getTileAt(a.position.x, a.position.y) == null)
                {
                    actorsToErase.Add(a);
                }
            }
            foreach (Actor a in actorsToErase)
            {
                Mapfile.ActorData w = new Mapfile.ActorData();
                w.id = (byte)editor.engine.world.actorFactory.names[a.actorName];
                w.x  = a.spawn.x;
                w.y  = a.spawn.y;
                w.z  = 0;
                editor.engine.world.file.worldActorData.Remove(w);
                editor.engine.world.actors.Remove(a);
            }

            //Overwrite
            tempFile.worldTileData = newTileData;
            tempWorld.tileArray    = newTileArray;
            tempWorld.width        = width;
            tempWorld.height       = height;
        }
Пример #10
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));
        }