Beispiel #1
0
        private void DrawToolbar()
        {
            GUILayout.BeginHorizontal(EditorStyles.toolbar);

            EditorGUI.BeginDisabledGroup(PrefabUtility.GetPrefabType(this.target) == PrefabType.Prefab || this.targets.Length != 1);
            if (this.target.IsEditable && GUILayout.Button(TileLang.OpensWindow(TileLang.ParticularText("Action", "Build Prefab")), RotorzEditorStyles.Instance.ToolbarButtonPaddedExtra))
            {
                TileSystemCommands.Command_BuildPrefab(this.target);
                GUIUtility.ExitGUI();
            }
            EditorGUI.EndDisabledGroup();

            GUILayout.FlexibleSpace();

            using (var content = ControlContent.Basic(
                       RotorzEditorStyles.Skin.GridToggle,
                       TileLang.ParticularText("Action", "Toggle Grid Display")
                       )) {
                RtsPreferences.ShowGrid.Value = GUILayout.Toggle(RtsPreferences.ShowGrid, content, RotorzEditorStyles.Instance.ToolbarButtonPadded);
            }

            using (var content = ControlContent.Basic(
                       RotorzEditorStyles.Skin.ChunkToggle,
                       TileLang.ParticularText("Action", "Toggle Chunk Display")
                       )) {
                RtsPreferences.ShowChunks.Value = GUILayout.Toggle(RtsPreferences.ShowChunks, content, RotorzEditorStyles.Instance.ToolbarButtonPadded);
            }

            EditorGUILayout.Space();

            this.DrawHelpButton();

            GUILayout.EndHorizontal();
        }
        //!TODO: The following should be refactored so that the tile system is passed in
        //       as the context object rather than using a closure.
        private EditorMenu BuildContextMenu(TileSystem system)
        {
            var contextMenu = new EditorMenu();

            contextMenu.AddCommand(TileLang.ParticularText("Action", "Inspect"))
            .Action(() => {
                EditorInternalUtility.FocusInspectorWindow();
            });

            contextMenu.AddSeparator();

            contextMenu.AddCommand(TileLang.ParticularText("Action", "Rename"))
            .Action(() => {
                this.BeginEditingName(system);
            });

            contextMenu.AddCommand(TileLang.ParticularText("Action", "Lock"))
            .Checked(system.Locked)
            .Action(() => {
                Undo.RecordObject(system, system.Locked
                        ? TileLang.ParticularText("Action", "Unlock Tile System")
                        : TileLang.ParticularText("Action", "Lock Tile System"));
                system.Locked = !system.Locked;
                EditorUtility.SetDirty(system);
                ToolUtility.RepaintScenePalette();
            });

            contextMenu.AddSeparator();

            contextMenu.AddCommand(TileLang.OpensWindow(TileLang.ParticularText("Action", "Refresh Tiles")))
            .Enabled(!system.Locked)
            .Action(() => {
                TileSystemCommands.Command_Refresh(system);
            });

            contextMenu.AddCommand(TileLang.OpensWindow(TileLang.ParticularText("Action", "Repair Tiles")))
            .Enabled(!system.Locked)
            .Action(() => {
                TileSystemCommands.Command_Repair(system);
            });

            contextMenu.AddCommand(TileLang.OpensWindow(TileLang.ParticularText("Action", "Clear Tiles")))
            .Enabled(!system.Locked)
            .Action(() => {
                TileSystemCommands.Command_Clear(system);
            });

            //contextMenu.AddSeparator();

            //contextMenu.AddCommand(TileLang.OpensWindow(TileLang.ParticularText("Action", "Refresh Plops")))
            //    .Enabled(!system.Locked)
            //    .Action(() => {
            //        TileSystemCommands.Command_RefreshPlops(system);
            //    });

            //contextMenu.AddCommand(TileLang.OpensWindow(TileLang.ParticularText("Action", "Clear Plops")))
            //    .Enabled(!system.Locked)
            //    .Action(() => {
            //        TileSystemCommands.Command_ClearPlops(system);
            //    });

            contextMenu.AddSeparator();

            contextMenu.AddCommand(TileLang.ParticularText("Action", "Delete"))
            .Enabled(!system.Locked)
            .Action(() => {
                Undo.DestroyObjectImmediate(system.gameObject);
            });

            contextMenu.AddSeparator();

            contextMenu.AddCommand(TileLang.OpensWindow(TileLang.ParticularText("Action", "Build Prefab")))
            .Action(() => {
                TileSystemCommands.Command_BuildPrefab(system);
            });

            return(contextMenu);
        }
Beispiel #3
0
        private void DrawModifyGridSection()
        {
            if (this.targets.Length > 1)
            {
                EditorGUILayout.HelpBox(TileLang.Text("Cannot modify structure of multiple tile systems at the same time."), MessageType.Info);
                return;
            }

            var tileSystem = this.target as TileSystem;

            if (PrefabUtility.GetPrefabType(tileSystem) == PrefabType.Prefab)
            {
                EditorGUILayout.HelpBox(TileLang.Text("Prefab must be instantiated in order to modify tile system structure."), MessageType.Info);
                return;
            }

            float restoreLabelWidth = EditorGUIUtility.labelWidth;

            bool hasGridSizeChanged;
            bool hasOffsetChanged;

            if (s_ModifyGridGroupStyle == null)
            {
                s_ModifyGridGroupStyle = new GUIStyle();
                s_ModifyGridGroupStyle.margin.right = 55;
            }

            Rect modifyGroupRect = EditorGUILayout.BeginVertical(s_ModifyGridGroupStyle);

            {
                ExtraEditorGUI.MultiPartPrefixLabel(TileLang.ParticularText("Property", "Grid Size (in tiles)"));
                GUILayout.BeginHorizontal();
                {
                    GUILayout.Space(18);
                    EditorGUIUtility.labelWidth = 65;

                    EditorGUILayout.PrefixLabel(TileLang.ParticularText("Property", "Rows"));
                    this.inputNewRows = Mathf.Max(1, EditorGUILayout.IntField(this.inputNewRows));
                    EditorGUILayout.PrefixLabel(TileLang.ParticularText("Property", "Columns"));
                    this.inputNewColumns = Mathf.Max(1, EditorGUILayout.IntField(this.inputNewColumns));

                    EditorGUIUtility.labelWidth = restoreLabelWidth;
                }
                GUILayout.EndHorizontal();

                ExtraEditorGUI.MultiPartPrefixLabel(TileLang.ParticularText("Property", "Offset Amount (in tiles)"));
                GUILayout.BeginHorizontal();
                {
                    GUILayout.Space(18);
                    EditorGUIUtility.labelWidth = 65;

                    EditorGUILayout.PrefixLabel(TileLang.ParticularText("Property", "Rows"));
                    this.inputRowOffset = EditorGUILayout.IntField(this.inputRowOffset);
                    EditorGUILayout.PrefixLabel(TileLang.ParticularText("Property", "Columns"));
                    this.inputColumnOffset = EditorGUILayout.IntField(this.inputColumnOffset);

                    EditorGUIUtility.labelWidth = restoreLabelWidth;
                }
                GUILayout.EndHorizontal();

                hasGridSizeChanged = (this.inputNewRows != tileSystem.RowCount || this.inputNewColumns != tileSystem.ColumnCount);
                hasOffsetChanged   = (this.inputRowOffset != 0 || this.inputColumnOffset != 0);

                if (hasGridSizeChanged)
                {
                    this.DrawMaintainTilePositionsInWorld(ref this.inputMaintainTilePositionsInWorldResize);
                }
                else if (hasOffsetChanged)
                {
                    this.DrawMaintainTilePositionsInWorld(ref this.inputMaintainTilePositionsInWorldOffset);
                }

                EditorGUIUtility.labelWidth = restoreLabelWidth;

                ExtraEditorGUI.MultiPartPrefixLabel(TileLang.ParticularText("Property", "Chunk Size (in tiles)"));
                GUILayout.BeginHorizontal();
                {
                    GUILayout.Space(18);
                    EditorGUIUtility.labelWidth = 65;

                    EditorGUILayout.PrefixLabel(TileLang.ParticularText("Property", "Height"));
                    this.inputNewChunkHeight = Mathf.Max(1, EditorGUILayout.IntField(this.inputNewChunkHeight));
                    EditorGUILayout.PrefixLabel(TileLang.ParticularText("Property", "Width"));
                    this.inputNewChunkWidth = Mathf.Max(1, EditorGUILayout.IntField(this.inputNewChunkWidth));

                    EditorGUIUtility.labelWidth = restoreLabelWidth;
                }
                GUILayout.EndHorizontal();
            }
            EditorGUILayout.EndVertical();


            Rect buttonRect = new Rect(modifyGroupRect.xMax + 5, modifyGroupRect.y + 3, 45, 35);

            using (var content = ControlContent.Basic(
                       RotorzEditorStyles.Skin.Trim,
                       TileLang.ParticularText("Action", "Trim")
                       )) {
                if (GUI.Button(buttonRect, content))
                {
                    this.OnTrimTileSystem();
                    GUIUtility.ExitGUI();
                }
            }

            buttonRect.y = buttonRect.yMax + 3;

            EditorGUI.BeginDisabledGroup(!hasGridSizeChanged);
            {
                using (var content = ControlContent.Basic(
                           RotorzEditorStyles.Skin.CentralizeUsed,
                           TileLang.ParticularText("Action", "Centralize Tile Bounds")
                           )) {
                    if (GUI.Button(buttonRect, content))
                    {
                        this.OnCentralizeUsedTileSystem();
                        GUIUtility.ExitGUI();
                    }
                }

                buttonRect.y = buttonRect.yMax + 3;

                using (var content = ControlContent.Basic(
                           RotorzEditorStyles.Skin.Centralize,
                           TileLang.ParticularText("Action", "Centralize")
                           )) {
                    if (GUI.Button(buttonRect, content))
                    {
                        this.OnCentralizeTileSystem();
                        GUIUtility.ExitGUI();
                    }
                }
            }
            EditorGUI.EndDisabledGroup();


            bool hasChunkSizeChanged = (this.inputNewChunkWidth != tileSystem.ChunkWidth || this.inputNewChunkHeight != tileSystem.ChunkHeight);

            // Display "Rebuild" button?
            if (hasGridSizeChanged || hasOffsetChanged || hasChunkSizeChanged)
            {
                GUILayout.Space(6);
                GUILayout.BeginHorizontal();
                {
                    EditorGUILayout.HelpBox(TileLang.Text("Tile system must be reconstructed, some tiles may be force refreshed."), MessageType.Warning);

                    if (GUILayout.Button(TileLang.ParticularText("Action", "Rebuild"), GUILayout.Width(75), GUILayout.Height(40)))
                    {
                        GUIUtility.keyboardControl = 0;
                        this.OnResizeTileSystem();
                        GUIUtility.ExitGUI();
                    }
                    if (GUILayout.Button(TileLang.ParticularText("Action", "Cancel"), GUILayout.Width(75), GUILayout.Height(40)))
                    {
                        GUIUtility.keyboardControl = 0;
                        this.RefreshModifyGridParamsFromTileSystem();
                        GUIUtility.ExitGUI();
                    }
                }
                GUILayout.EndHorizontal();
                GUILayout.Space(2);
            }

            ExtraEditorGUI.SeparatorLight();

            using (var content = ControlContent.Basic(
                       TileLang.ParticularText("Property", "Cell Size"),
                       TileLang.Text("Span of an individual tile.")
                       )) {
                Vector3 newCellSize = Vector3.Max(new Vector3(0.0001f, 0.0001f, 0.0001f), EditorGUILayout.Vector3Field(content, tileSystem.CellSize));
                if (tileSystem.CellSize != newCellSize)
                {
                    this.propertyCellSize.vector3Value      = newCellSize;
                    this.propertyHintForceRefresh.boolValue = true;
                }
            }

            GUILayout.Space(5);

            using (var content = ControlContent.Basic(
                       TileLang.ParticularText("Property", "Tiles Facing"),
                       TileLang.Text("Direction that tiles will face when painted. 'Sideways' is good for platform and 2D games. 'Upwards' is good for top-down.")
                       )) {
                TileFacing newTilesFacing = (TileFacing)EditorGUILayout.EnumPopup(content, tileSystem.TilesFacing);
                if (tileSystem.TilesFacing != newTilesFacing)
                {
                    this.propertyTilesFacing.intValue       = (int)newTilesFacing;
                    this.propertyHintForceRefresh.boolValue = true;
                }
            }

            GUILayout.Space(5);

            // Display suitable warning message when force refresh is required.
            if (this.propertyHintForceRefresh.boolValue)
            {
                if (!RotorzEditorGUI.InfoBoxClosable(TileLang.Text("Changes may not take effect until tile system is force refreshed without preserving manual offsets, or cleared."), MessageType.Warning))
                {
                    this.propertyHintForceRefresh.boolValue = false;
                    this.serializedObject.ApplyModifiedProperties();
                    GUIUtility.ExitGUI();
                }
            }
            else
            {
                ExtraEditorGUI.SeparatorLight(marginTop: 0, marginBottom: 0, thickness: 1);
            }

            GUILayout.Space(5);

            GUILayout.BeginHorizontal();
            {
                // Display extra padding to right of buttons to avoid accidental click when
                // clicking close button of warning message.
                GUILayoutOption columnWidth = GUILayout.Width((EditorGUIUtility.currentViewWidth - 30) / 3 - GUI.skin.button.margin.horizontal);

                GUILayout.BeginVertical(columnWidth);
                if (GUILayout.Button(TileLang.OpensWindow(TileLang.ParticularText("Action", "Refresh"))))
                {
                    TileSystemCommands.Command_Refresh(this.target);
                    GUIUtility.ExitGUI();
                }
                GUILayout.Space(2);
                if (GUILayout.Button(TileLang.OpensWindow(TileLang.ParticularText("Action", "Refresh Plops"))))
                {
                    TileSystemCommands.Command_RefreshPlops(this.target);
                    GUIUtility.ExitGUI();
                }
                GUILayout.EndVertical();

                GUILayout.BeginVertical(columnWidth);
                if (GUILayout.Button(TileLang.OpensWindow(TileLang.ParticularText("Action", "Repair"))))
                {
                    TileSystemCommands.Command_Repair(this.target);
                    GUIUtility.ExitGUI();
                }
                GUILayout.Space(2);
                if (GUILayout.Button(TileLang.OpensWindow(TileLang.ParticularText("Action", "Clear Plops"))))
                {
                    TileSystemCommands.Command_ClearPlops(this.target);
                    GUIUtility.ExitGUI();
                }
                GUILayout.EndVertical();

                GUILayout.BeginVertical(columnWidth);
                if (GUILayout.Button(TileLang.OpensWindow(TileLang.ParticularText("Action", "Clear"))))
                {
                    TileSystemCommands.Command_Clear(this.target);
                    GUIUtility.ExitGUI();
                }
                GUILayout.EndVertical();
            }
            GUILayout.EndHorizontal();

            GUILayout.Space(5);
        }
        private void _brushList_BrushContextMenu(Brush brush)
        {
            // Do not attempt to display context menu for "(Erase)" item.
            if (brush == null)
            {
                return;
            }

            var brushRecord = BrushDatabase.Instance.FindRecord(brush);

            var brushContextMenu = new EditorMenu();

            brushContextMenu.AddCommand(TileLang.OpensWindow(TileLang.ParticularText("Action", "Show in Designer")))
            .Enabled(!brushRecord.IsMaster)     // Cannot edit a master brush :)
            .Action(() => {
                ToolUtility.ShowBrushInDesigner(brush);
            });

            var selectedTilesetBrush = brush as TilesetBrush;

            if (selectedTilesetBrush != null)
            {
                brushContextMenu.AddCommand(TileLang.ParticularText("Action", "Goto Tileset"))
                .Action(() => {
                    this.brushList.Model.View            = BrushListView.Tileset;
                    this.brushList.Model.SelectedTileset = selectedTilesetBrush.Tileset;

                    var designerWindow = RotorzWindow.GetInstance <DesignerWindow>();
                    if (designerWindow != null && !designerWindow.IsLocked)
                    {
                        designerWindow.SelectedObject = selectedTilesetBrush.Tileset;
                    }

                    this.Repaint();
                });
            }

            brushContextMenu.AddCommand(TileLang.ParticularText("Action", "Reveal Asset"))
            .Action(() => {
                EditorGUIUtility.PingObject(brush);
            });

            brushContextMenu.AddSeparator();

            brushContextMenu.AddCommand(TileLang.ParticularText("Action", "Refresh Preview"))
            .Action(() => {
                BrushUtility.RefreshPreviewIncludingDependencies(brush);
            });

            brushContextMenu.AddSeparator();

            brushContextMenu.AddCommand(TileLang.OpensWindow(TileLang.ParticularText("Action", "Create Duplicate")))
            .Action(() => {
                var window = CreateBrushWindow.ShowWindow <DuplicateBrushCreator>();
                window.SharedProperties["targetBrush"] = brush;
            });

            var brushDescriptor = BrushUtility.GetDescriptor(brush.GetType());

            brushContextMenu.AddCommand(TileLang.OpensWindow(TileLang.ParticularText("Action", "Create Alias")))
            .Enabled(brushDescriptor.SupportsAliases)
            .Action(() => {
                var window = CreateBrushWindow.ShowWindow <AliasBrushCreator>();
                window.SharedProperties["targetBrush"] = brush;
            });

            brushContextMenu.AddCommand(TileLang.OpensWindow(TileLang.ParticularText("Action", "Delete Brush")))
            .Action(() => {
                TileSystemCommands.DeleteBrush(brush, ToolUtility.SharedBrushListModel.View == BrushListView.Tileset);
            });

            brushContextMenu.ShowAsContext();
        }