Exemple #1
0
        public bool DrawTilePreviews(AutotileLayout layout, Texture2D tileset, bool innerJoins, ITilesetMetrics metrics)
        {
            int tileCount = 0;

            switch (layout)
            {
            //case AutotileStyle.tIDE:
            //    tileCount = 16;
            //    break;
            case AutotileLayout.Basic:
                tileCount = innerJoins ? 47 : 16;
                break;

            case AutotileLayout.Extended:
                tileCount = innerJoins ? 48 : 16;
                break;
            }

            if (tileCount == 0)
            {
                return(false);
            }

            return(this.DrawTilePreviews(tileset, metrics, tileCount));
        }
Exemple #2
0
        /// <summary>
        /// Initialize tileset for first time.
        /// </summary>
        /// <param name="material">Atlas material.</param>
        /// <param name="atlas">Atlas texture.</param>
        /// <param name="metrics">Object that contains metrics for tileset.</param>
        /// <exception cref="System.NotSupportedException">
        /// If tileset has already been initialized.
        /// </exception>
        /// <exception cref="System.ArgumentNullException">
        /// If <paramref name="atlas"/> is <c>null</c>.
        /// </exception>
        /// <exception cref="System.InvalidOperationException">
        /// If attempting to set metrics of tileset from itself.
        /// </exception>
        public void Initialize(AutotileLayout layout, bool hasInnerJoins, Material material, Texture2D atlas, ITilesetMetrics metrics)
        {
            base.Initialize(material, atlas, metrics);

            this.autotileLayout = layout;
            this.hasInnerJoins  = hasInnerJoins;
        }
Exemple #3
0
        public static void EstimateTileSize(AutotileLayout layout, Texture2D artwork, bool innerJoins, ref int tileWidth, ref int tileHeight)
        {
            switch (layout)
            {
            case AutotileLayout.Extended:
                tileWidth  = artwork.width / 3;
                tileHeight = artwork.height / (innerJoins ? 4 : 3);
                break;

            case AutotileLayout.Basic:
                tileWidth  = artwork.width / 2;
                tileHeight = artwork.height / (innerJoins ? 3 : 2);
                break;
            }
        }
Exemple #4
0
        { XH, XA, XA, XB, XG, 8, 11, XC, XG, 20, 23, XC, XF, XE, XE, XD };                    // 46

        #endregion


        public static void ApplyTileSizeConstraints(AutotileLayout layout, Texture2D artwork, bool innerJoins, ref int tileWidth, ref int tileHeight, ref int border)
        {
            // Apply minimum and maximum constraints.
            int maxTileWidth = 256, maxTileHeight = 256;

            if (artwork != null)
            {
                switch (layout)
                {
                case AutotileLayout.Extended:
                    maxTileWidth  = artwork.width / 3;
                    maxTileHeight = artwork.height / (innerJoins ? 4 : 3);
                    break;

                case AutotileLayout.Basic:
                    maxTileWidth  = artwork.width / 2;
                    maxTileHeight = artwork.height / (innerJoins ? 3 : 2);
                    break;
                }
            }

            // Constrain maximum tile size to 256x256.
            maxTileWidth  = Mathf.Min(256, maxTileWidth);
            maxTileHeight = Mathf.Min(256, maxTileHeight);

            tileWidth  = Mathf.Clamp(tileWidth, 1, maxTileWidth);
            tileHeight = Mathf.Clamp(tileHeight, 1, maxTileHeight);

            // Tile size must be divisible by 2.
            if (tileWidth % 2 == 1)
            {
                --tileWidth;
            }
            if (tileHeight % 2 == 1)
            {
                --tileHeight;
            }

            border = Mathf.Clamp(border, 0, Mathf.Min(tileWidth, tileHeight) / 2);
        }
Exemple #5
0
        /// <summary>
        /// Initializes a new instance of the autotile expander utility.
        /// </summary>
        /// <param name="layout">Layout style of autotile.</param>
        /// <param name="autotileArtwork">Autotile artwork to be expanded.</param>
        /// <param name="tileWidth">Width of tile in pixels.</param>
        /// <param name="tileHeight">Height of tile in pixels.</param>
        /// <param name="innerJoins">Indicates if inner joins should be generated.</param>
        /// <param name="border">Size of additional border in pixels to generate.</param>
        /// <param name="clampEdges">Indicates if edges should be clamped instead of tiled.</param>
        public AutotileExpanderUtility(AutotileLayout layout, Texture2D autotileArtwork, int tileWidth, int tileHeight, bool innerJoins, int border, bool clampEdges)
        {
            this.layout          = layout;
            this.autotileArtwork = autotileArtwork;

            switch (layout)
            {
            //case AutotileLayout.tIDE:
            //    _map = _TIDE_STYLE;
            //    break;

            case AutotileLayout.Extended:
                this.PrepareExtendedMap(innerJoins);
                break;

            case AutotileLayout.Basic:
                this.PrepareBasicMap(innerJoins);
                break;
            }

            if (tileWidth % 2 == 1 || tileHeight % 2 == 1)
            {
                throw new Exception(TileLang.ParticularText("Error", "Tile width and height must both be divisible by 2."));
            }

            this.tileWidth  = tileWidth;
            this.tileHeight = tileHeight;
            this.border     = border;
            this.clampEdges = clampEdges;

            this.halfTileWidth   = tileWidth / 2;
            this.halfTileHeight  = tileHeight / 2;
            this.tileOuterWidth  = tileWidth + border * 2;
            this.tileOuterHeight = tileHeight + border * 2;

            this.bufferWidth = tileWidth * 2;
            this.buffer      = new Color[this.bufferWidth * tileHeight * 2];
        }
Exemple #6
0
        protected override void OnModifyTilesetGUI()
        {
            AutotileLayout layout = this.autotileTileset.AutotileLayout;

            GUILayout.BeginVertical();

            EditorGUI.BeginChangeCheck();

            GUILayout.BeginHorizontal();
            GUILayout.Space(20);
            this.DrawAtlasTextureField();
            GUILayout.Space(15);
            this.DrawAtlasParametersGUI();
            GUILayout.Space(20);
            this.DrawEdgeCorrectionGUI();
            GUILayout.EndHorizontal();

            if (EditorGUI.EndChangeCheck())
            {
                this.invalidateAtlasDetails = true;
            }

            this.ApplyAutotileConstraintsToInputs();

            // Automatically refresh atlas details as needed.
            this.RefreshAtlasDetails();

            if (this.atlasDetails != null)
            {
                GUILayout.Space(5);
                GUILayout.BeginHorizontal();
                GUILayout.Space(150);
                GUILayout.Label(this.atlasDetails, EditorStyles.miniLabel);
                GUILayout.EndHorizontal();
            }

            GUILayout.EndVertical();
        }
Exemple #7
0
        private void DrawLayoutSelectionGUI()
        {
            Rect r = EditorGUILayout.BeginHorizontal();

            {
                GUILayout.Space(-11f);

                EditorGUI.BeginChangeCheck();
                {
                    s_SelectedTabIndex       = RotorzEditorGUI.TabSelector(s_SelectedTabIndex, s_TabLabels);
                    s_SelectedAutotileLayout = s_TabValues[s_SelectedTabIndex];
                }
                if (EditorGUI.EndChangeCheck())
                {
                    this.RecalculateTileSize();
                }

                GUILayout.Space(-10f);
            }
            EditorGUILayout.EndHorizontal();

            // Draw selected icon at top-right of window.
            GUI.DrawTexture(new Rect(r.x + r.width - 45f, r.y - 32f, 40f, 53f), s_SelectedAutotileLayout == AutotileLayout.Extended ? RotorzEditorStyles.Skin.AutotileExtendedIcon : RotorzEditorStyles.Skin.AutotileBasicIcon);
        }
Exemple #8
0
        public static Texture2D ExpandAutotileArtwork(AutotileLayout layout, Texture2D autotileArtwork, int tileWidth, int tileHeight, bool innerJoins, int border, bool clampEdges)
        {
            AutotileExpanderUtility expander = new AutotileExpanderUtility(layout, autotileArtwork, tileWidth, tileHeight, innerJoins, border, clampEdges);

            return(expander.Generate());
        }