示例#1
0
        public static void SetFuncTool(FuncTool tool)
        {
            EditorTools.funcTool = tool;
            EditorTools.tileTool = null;
            EditorTools.tempTool = null;
            EditorTools.autoTool.ClearAutoTiles();

            // Update Helper Text (if applicable)
            EditorTools.UpdateHelperText();
        }
示例#2
0
        public static void SetTileTool(TileTool tool, byte index = 0)
        {
            EditorTools.tileTool = tool;
            EditorTools.funcTool = null;
            EditorTools.tempTool = null;
            EditorTools.autoTool.ClearAutoTiles();

            EditorUI.currentSlotGroup = EditorTools.tileTool.slotGroup;

            // Assign Index and SubIndex to TileTool (if applicable)
            EditorTools.tileTool.SetIndex(index);

            // Update Helper Text (if applicable)
            EditorTools.UpdateHelperText();
        }
示例#3
0
        public void CloneTile(short gridX, short gridY)
        {
            RoomFormat roomData = this.levelContent.data.rooms[this.roomID];
            Dictionary <string, Dictionary <string, ArrayList> > layerData = null;
            bool isObject = false;

            if (LevelContent.VerifyTiles(roomData.obj, gridX, gridY))
            {
                layerData = roomData.obj; isObject = true;
            }
            else if (LevelContent.VerifyTiles(roomData.main, gridX, gridY))
            {
                layerData = roomData.main;
            }
            else if (LevelContent.VerifyTiles(roomData.fg, gridX, gridY))
            {
                layerData = roomData.fg;
            }
            else if (LevelContent.VerifyTiles(roomData.bg, gridX, gridY))
            {
                layerData = roomData.bg;
            }

            // If no tile is cloned, set the current Function Tool to "Select"
            if (layerData == null)
            {
                FuncToolSelect selectFunc = (FuncToolSelect)FuncTool.funcToolMap[(byte)FuncToolEnum.Select];
                EditorTools.SetFuncTool(selectFunc);
                selectFunc.ClearSelection();
                return;
            }

            // Get the Object from the Highlighted Tile (Search Front to Back until a tile is identified)
            byte[] tileData = LevelContent.GetTileData(layerData, gridX, gridY);

            // Identify the tile, and set it as the current editing tool (if applicable)
            TileTool clonedTool = TileTool.GetTileToolFromTileData(tileData, isObject);

            if (clonedTool is TileTool == true)
            {
                byte subIndex = clonedTool.subIndex;                 // Need to save this value to avoid subIndexSaves[] tracking.
                EditorTools.SetTileTool(clonedTool, (byte)clonedTool.index);
                clonedTool.SetSubIndex(subIndex);
            }
        }
示例#4
0
        public static void SetTileToolBySlotGroup(byte slotGroup, byte index = 0)
        {
            // If the current slot group is being changed:
            if (EditorTools.tileTool == null || EditorTools.tileTool.slotGroup != slotGroup)
            {
                if (TileTool.tileToolMap.ContainsKey(slotGroup))
                {
                    TileTool tool = TileTool.tileToolMap[slotGroup];
                    if (tool == null)
                    {
                        return;
                    }
                    EditorTools.SetTileTool(tool, tool.index);
                }
            }

            // If the current slot group is the same, need to change the index only.
            else
            {
                TileTool tool = EditorTools.tileTool;
                EditorTools.SetTileTool(tool, index);
            }
        }
示例#5
0
        public static TileTool GetTileToolFromTileData(byte[] tileData, bool isObject = false)
        {
            if (tileData == null)
            {
                return(null);
            }

            // If we're retrieving a object, verify that it exists in the Object Dictionary (otherwise it's invalid).
            if (isObject)
            {
                Dictionary <byte, System.Type> objDict = Systems.mapper.ObjectTypeDict;
                if (!objDict.ContainsKey(tileData[0]))
                {
                    return(null);
                }
            }

            // If we're retrieving a tile, verify that it exists in the Tile Dictionary (otherwise it's invalid).
            else
            {
                Dictionary <byte, TileObject> tileDict = Systems.mapper.TileDict;
                if (!tileDict.ContainsKey(tileData[0]))
                {
                    return(null);
                }
            }

            // Loop through every TileTool in an effort to locate a match for the tile data.
            for (byte slotGroupNum = 1; slotGroupNum < 13; slotGroupNum++)
            {
                List <EditorPlaceholder[]> placeholders = TileTool.tileToolMap[(byte)slotGroupNum].placeholders;

                // Loop through each placeholders to see if a tileData ID match is found.
                byte phLen = (byte)placeholders.Count;

                for (byte i = 0; i < phLen; i++)
                {
                    EditorPlaceholder[] pData = placeholders[i];

                    byte phSubLen = (byte)pData.Length;
                    for (byte s = 0; s < phSubLen; s++)
                    {
                        EditorPlaceholder ph = pData[s];

                        // Check if the placeholder matches the tileData correctly:
                        if (isObject)
                        {
                            if (tileData[0] != ph.objectId || tileData[1] != ph.subType)
                            {
                                continue;
                            }
                        }
                        else
                        {
                            if (tileData[0] != ph.tileId || tileData[1] != ph.subType)
                            {
                                continue;
                            }
                        }

                        // If the tileData[0] ID & SubType matches with the TileTool placeholder, we've found a match.
                        TileTool clonedTool = TileTool.tileToolMap[(byte)slotGroupNum];

                        // Set the default values for the tool.
                        clonedTool.index            = i;
                        clonedTool.subIndex         = s;
                        clonedTool.subIndexSaves[i] = s;

                        return(clonedTool);
                    }
                }
            }

            return(null);
        }
示例#6
0
        public void TileToolTick(short gridX, short gridY)
        {
            // Prevent drawing when a component is selected.
            if (UIComponent.ComponentWithFocus != null)
            {
                return;
            }

            // Make sure placement is in valid location:
            if (gridY < 0 || gridY > this.yCount)
            {
                return;
            }
            if (gridX < 0 || gridX > this.xCount)
            {
                return;
            }

            TileTool tool = EditorTools.tileTool;

            // Make sure the tile tool is set, or placement cannot occur:
            if (tool == null)
            {
                return;
            }

            // Check if AutoTile Tool is intended. Requires Control to be held down.
            if (Systems.input.LocalKeyDown(Keys.LeftControl))
            {
                // If left mouse button was just clicked, AutoTile is being activated.
                if (Cursor.LeftMouseState == Cursor.MouseDownState.Clicked)
                {
                    EditorTools.StartAutoTool(gridX, gridY);
                }
            }

            // If AutoTile Tool is active, run it's behavior:
            if (EditorTools.autoTool.IsActive)
            {
                // If left mouse was just released and AutoTile is active, place AutoTiles.
                if (Cursor.LeftMouseState == Cursor.MouseDownState.Released)
                {
                    EditorTools.autoTool.PlaceAutoTiles(this);
                }

                // If Control key is not held down, auto-tiles must be deactivated.
                else if (!Systems.input.LocalKeyDown(Keys.LeftControl))
                {
                    EditorTools.autoTool.ClearAutoTiles();
                }

                return;
            }

            // Left Mouse Button (Overwrite Current Tile)
            if (Cursor.mouseState.LeftButton == ButtonState.Pressed)
            {
                // Prevent repeat-draws on the same tile (e.g. within the last 100ms).
                if (!DrawTracker.AttemptPlace(gridX, gridY))
                {
                    return;
                }

                EditorPlaceholder ph = tool.CurrentPlaceholder;

                // Place Tile
                if (ph.tileId > 0)
                {
                    RoomFormat roomData = this.levelContent.data.rooms[this.roomID];

                    if (ph.layerEnum == LayerEnum.main)
                    {
                        // Check the Tile Limiter before placing the tile.
                        if (this.scene.limiter.AddLimitTile(this.scene.curRoomID, ph.tileId, ph.subType))
                        {
                            this.PlaceTile(roomData.main, ph.layerEnum, gridX, gridY, ph.tileId, ph.subType, null);
                        }

                        // If the Object Limiter failed, display the error message.
                        else
                        {
                            UIHandler.AddNotification(UIAlertType.Error, "Limit Reached", ObjectLimiter.LastFailMessage, 240);
                        }
                    }
                    else if (ph.layerEnum == LayerEnum.bg)
                    {
                        this.PlaceTile(roomData.bg, ph.layerEnum, gridX, gridY, ph.tileId, ph.subType, null);
                    }
                    else if (ph.layerEnum == LayerEnum.fg)
                    {
                        this.PlaceTile(roomData.fg, ph.layerEnum, gridX, gridY, ph.tileId, ph.subType, null);
                    }
                }

                // Place Object
                else if (ph.objectId > 0)
                {
                    // Check the Object Limiter before placing the tile.
                    if (this.scene.limiter.AddLimitObject(this.scene.curRoomID, ph.objectId))
                    {
                        this.PlaceTile(this.levelContent.data.rooms[this.roomID].obj, LayerEnum.obj, gridX, gridY, ph.objectId, ph.subType, null);
                    }

                    // If the Object Limiter failed, display the error message.
                    else
                    {
                        UIHandler.AddNotification(UIAlertType.Error, "Limit Reached", ObjectLimiter.LastFailMessage, 240);
                    }
                }

                return;
            }
        }