public void DrawCurrentGridSquare() { // Draw Currently Slotted Item & Highlighted Grid Square (if not overlapping a UI component) if (UIComponent.ComponentWithFocus == null) { // Draw Temporary Function Tool (if active) if (EditorTools.tempTool != null) { EditorTools.tempTool.DrawFuncTool(); } // Draw Function Tool (if active) else if (EditorTools.funcTool != null) { EditorTools.funcTool.DrawFuncTool(); } // Draw AutoTile Tool (if active) else if (EditorTools.autoTool.IsActive) { EditorTools.autoTool.DrawAutoTiles(); } // Draw Tile Tool (if active) else if (EditorTools.tileTool != null) { EditorPlaceholder ph = EditorTools.tileTool.CurrentPlaceholder; // Draw Tile if (ph.tileId > 0) { if (Systems.mapper.TileDict.ContainsKey(ph.tileId)) { TileObject tgo = Systems.mapper.TileDict[ph.tileId]; tgo.Draw(null, ph.subType, Cursor.TileGridX * (byte)TilemapEnum.TileWidth - Systems.camera.posX, Cursor.TileGridY * (byte)TilemapEnum.TileHeight - Systems.camera.posY); } } // Draw Object else if (ph.objectId > 0) { ShadowTile.Draw(ph.objectId, ph.subType, null, Cursor.TileGridX * (byte)TilemapEnum.TileWidth - Systems.camera.posX, Cursor.TileGridY * (byte)TilemapEnum.TileHeight - Systems.camera.posY); } Systems.spriteBatch.Draw(Systems.tex2dDarkRed, new Rectangle(Cursor.TileGridX * (byte)TilemapEnum.TileWidth - Systems.camera.posX, Cursor.TileGridY * (byte)TilemapEnum.TileHeight - Systems.camera.posY, (byte)TilemapEnum.TileWidth, (byte)TilemapEnum.TileHeight), Color.White * 0.25f); } } }
public static void UpdateHelperText() { if (Systems.scene is EditorScene == false) { return; } EditorScene editorScene = (EditorScene)Systems.scene; // Tile Tool Helper Text if (EditorTools.tileTool != null) { EditorPlaceholder ph = EditorTools.tileTool.CurrentPlaceholder; // Display Tile Helper Text if (ph.tileId > 0) { // If there's an error here, we need to add the value to TileDict. TileObject tile = Systems.mapper.TileDict[ph.tileId]; if (tile.titles != null) { editorScene.editorUI.statusText.SetText(tile.titles[ph.subType], tile.descriptions[ph.subType]); return; } else if (tile.title.Length > 0) { editorScene.editorUI.statusText.SetText(tile.title, tile.description); return; } } // Display Object Helper Text if (ph.objectId > 0) { string title = ShadowTile.ObjHelpText[ph.objectId][ph.subType][0]; string desc = ShadowTile.ObjHelpText[ph.objectId][ph.subType][1]; editorScene.editorUI.statusText.SetText(title, desc); return; } } editorScene.editorUI.statusText.ClearStatus(); }
public static void StartAutoTool(short gridX, short gridY) { // Can only set an AutoTile tool if a TileTool is also active. if (EditorTools.tileTool == null) { return; } EditorPlaceholder ph = EditorTools.tileTool.CurrentPlaceholder; EditorTools.autoTool.StartAutoTile(ph.tileId, ph.subType, ph.layerEnum, gridX, gridY); // Only disable other tools if the AutoTile tool started. if (EditorTools.autoTool.IsActive) { EditorTools.funcTool = null; EditorTools.tempTool = null; } }
public void Draw() { byte tileWidth = (byte)TilemapEnum.TileWidth + 2; // Draw Utility Bar Background Systems.spriteBatch.Draw(Systems.tex2dWhite, new Rectangle(this.x, this.y - 2, this.width, this.height + 2), Color.DarkSlateGray); Systems.spriteBatch.Draw(Systems.tex2dWhite, new Rectangle(this.x + 2, this.y, this.width - 2, this.height), Color.White); // Tile Outlines for (byte i = 0; i <= (byte)UtilityBarEnum.BarTiles; i++) { Systems.spriteBatch.Draw(Systems.tex2dWhite, new Rectangle(this.x + i * tileWidth, this.y, 2, this.height), Color.DarkSlateGray); } // Tile Icons if (TileTool.tileToolMap.ContainsKey(EditorUI.currentSlotGroup)) { List <EditorPlaceholder[]> placeholders = TileTool.tileToolMap[EditorUI.currentSlotGroup].placeholders; Dictionary <byte, TileObject> tileDict = Systems.mapper.TileDict; for (byte i = 0; i < 10; i++) { if (placeholders.Count <= i) { continue; } EditorPlaceholder ph = placeholders[i][0]; byte tileId = ph.tileId; // Draw Tile if (tileId > 0) { if (!tileDict.ContainsKey(tileId)) { continue; } tileDict[tileId].Draw(null, ph.subType, this.x + i * tileWidth + 2, this.y); } // Draw Object (if tile is not present) else if (ph.objectId > 0) { ShadowTile.Draw(ph.objectId, ph.subType, null, this.x + i * tileWidth + 2, this.y); } } } // Draw Keybind Text for (byte i = 0; i < 10; i++) { Systems.fonts.baseText.Draw((i + 1).ToString(), this.x + i * tileWidth + 4, this.y + this.height - 18, Color.DarkOrange); } // Function Icons foreach (KeyValuePair <byte, FuncButton> button in this.buttonMap) { byte barIndex = button.Key; button.Value.DrawFunctionTile(this.x + barIndex * tileWidth + 2, this.y); } // Hovering Visual if (UIComponent.ComponentWithFocus is UtilityBar) { short mx = (short)Snap.GridFloor(tileWidth, Cursor.MouseX - this.x); Systems.spriteBatch.Draw(Systems.tex2dDarkRed, new Rectangle(this.x + mx * tileWidth, this.y, tileWidth, this.height), Color.White * 0.5f); } }
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); }
public void Draw() { if (EditorTools.tileTool is TileTool == false) { return; } byte tileHeight = (byte)TilemapEnum.TileHeight + 2; // Draw Editor Scroller Background Systems.spriteBatch.Draw(Systems.tex2dWhite, new Rectangle(this.x, this.y, this.width, this.height), Color.DarkSlateGray); Systems.spriteBatch.Draw(Systems.tex2dWhite, new Rectangle(this.x + 2, this.y + 2, (byte)TilemapEnum.TileWidth, this.height - 6), Color.White); // Grid Outline for (byte i = 1; i < (byte)EScrollerEnum.NumTiles; i++) { Systems.spriteBatch.Draw(Systems.tex2dWhite, new Rectangle(this.x, this.y + i * tileHeight, this.width, 2), Color.DarkSlateGray); } // Draw TileTool Subtype Buttons List <EditorPlaceholder[]> placeholders = EditorTools.tileTool.placeholders; // Placeholder Loop byte len = (byte)placeholders.Count; EditorPlaceholder[] pData = placeholders[EditorTools.tileTool.index]; byte phSubLen = (byte)pData.Length; for (byte s = 0; s < phSubLen; s++) { EditorPlaceholder ph = pData[s]; byte subType = ph.subType; byte tileId = ph.tileId; // Draw Tiles if (tileId > 0) { if (Systems.mapper.TileDict.ContainsKey(tileId)) { TileObject tgo = Systems.mapper.TileDict[tileId]; tgo.Draw(null, subType, this.x + 2, this.y + 50 * s + 2); } } // Draw Objects else if (ph.objectId > 0) { ShadowTile.Draw(ph.objectId, ph.subType, null, this.x + 2, this.y + 50 * s + 2); } } // Highlight the active color short my = (short)Snap.GridFloor(tileHeight, EditorTools.tileTool.subIndex * tileHeight - this.y); Systems.spriteBatch.Draw(Systems.tex2dDarkRed, new Rectangle(this.x, this.y + my * tileHeight, this.width, tileHeight), Color.White * 0.5f); // Hovering Visual if (UIComponent.ComponentWithFocus is EditorScroller) { short my2 = (short)Snap.GridFloor(tileHeight, Cursor.MouseY - this.y); Systems.spriteBatch.Draw(Systems.tex2dDarkRed, new Rectangle(this.x, this.y + my2 * tileHeight, this.width, tileHeight), Color.White * 0.5f); } }
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; } }