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); }
//!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); }