private Brush DrawBrushPreviewField(Brush brush) { Rect position = GUILayoutUtility.GetRect(144, 144, 144, 144); int controlID = GUIUtility.GetControlID(FocusType.Passive); Event e = Event.current; Brush draggedBrush = DragAndDrop.objectReferences.Length > 0 ? DragAndDrop.objectReferences[0] as Brush : null; switch (e.GetTypeForControl(controlID)) { case EventType.Repaint: Color restore = GUI.backgroundColor; if (DragAndDrop.activeControlID == controlID) { GUI.backgroundColor = new Color32(61, 128, 223, 255); } RotorzEditorStyles.Instance.TransparentBox.Draw(position, GUIContent.none, false, false, false, false); GUI.backgroundColor = restore; position.x += 2; position.y += 2; position.width -= 4; position.height -= 4; RotorzEditorGUI.DrawBrushPreview(position, brush); break; case EventType.DragUpdated: if (draggedBrush != null && position.Contains(e.mousePosition)) { DragAndDrop.visualMode = DragAndDropVisualMode.Link; DragAndDrop.activeControlID = controlID; GUIUtility.hotControl = 0; this.Repaint(); e.Use(); } break; case EventType.DragExited: this.Repaint(); break; case EventType.DragPerform: if (draggedBrush != null && position.Contains(e.mousePosition)) { brush = draggedBrush; DragAndDrop.AcceptDrag(); GUIUtility.hotControl = 0; e.Use(); } break; } return(brush); }
private void DrawPrimarySecondaryBrushSwitcher() { Rect r; GUILayout.Space(5); GUILayout.BeginHorizontal(); GUILayout.FlexibleSpace(); GUILayout.Label(RotorzEditorStyles.Skin.MouseLeft); GUILayout.Box(GUIContent.none, RotorzEditorStyles.Instance.SelectedBrushPreviewBox); r = GUILayoutUtility.GetLastRect(); if (ToolUtility.SelectedBrush != null) { RotorzEditorGUI.DrawBrushPreview(new Rect(r.x + 2, r.y + 2, r.width - 4, r.height - 4), ToolUtility.SelectedBrush); } else { GUI.Label(r, TileLang.ParticularText("Action", "Erase"), RotorzEditorStyles.Instance.MiniCenteredLabel); } GUILayout.Space(10); GUILayout.Label(RotorzEditorStyles.Skin.MouseRight); GUILayout.Box(GUIContent.none, RotorzEditorStyles.Instance.SelectedBrushPreviewBox); r = GUILayoutUtility.GetLastRect(); if (ToolUtility.SelectedBrushSecondary != null) { RotorzEditorGUI.DrawBrushPreview(new Rect(r.x + 2, r.y + 2, r.width - 4, r.height - 4), ToolUtility.SelectedBrushSecondary); } else { GUI.Label(r, TileLang.ParticularText("Action", "Erase"), RotorzEditorStyles.Instance.MiniCenteredLabel); } GUILayout.Space(5); using (var content = ControlContent.Basic( RotorzEditorStyles.Skin.SwitchPrimarySecondary, TileLang.ParticularText("Action", "Switch primary and secondary brushes (X)") )) { if (RotorzEditorGUI.HoverButton(content, GUILayout.Height(42))) { Brush t = ToolUtility.SelectedBrush; ToolUtility.SelectedBrush = ToolUtility.SelectedBrushSecondary; ToolUtility.SelectedBrushSecondary = t; GUIUtility.ExitGUI(); } } GUILayout.FlexibleSpace(); GUILayout.EndHorizontal(); GUILayout.Space(5); }
private void DrawLargeTilePreview() { Rect previewPosition = GUILayoutUtility.GetRect(160, 160, 150, 150, RotorzEditorStyles.Instance.Box); // Draw background box for larger tile preview. previewPosition.width -= 10; if (Event.current.type == EventType.Repaint) { RotorzEditorStyles.Instance.Box.Draw(previewPosition, GUIContent.none, 0); } // Draw tile preview. previewPosition.x += 2; previewPosition.y += 2; previewPosition.width -= 4; previewPosition.height -= 4; BrushAssetRecord record = BrushDatabase.Instance.FindRecord(this.Brush); RotorzEditorGUI.DrawBrushPreview(previewPosition, record); }
protected override void OnHeaderGUI() { if (!this.hasInitialized) { this.hasInitialized = true; // Find out whether brush asset is accessible via brush database. var record = BrushDatabase.Instance.FindRecord(target as Brush); this.hasRecord = (record != null); } if (this.hasRecord) { var brush = target as Brush; GUILayout.BeginHorizontal(RotorzEditorStyles.Instance.InspectorBigTitle); Rect previewPosition = GUILayoutUtility.GetRect(GUIContent.none, GUIStyle.none, GUILayout.Width(64), GUILayout.Height(65)); if (Event.current.type == EventType.Repaint) { RotorzEditorStyles.Instance.Box.Draw(new Rect(previewPosition.x - 2, previewPosition.y - 2, 68, 68), GUIContent.none, false, false, false, false); previewPosition = new Rect(previewPosition.x, previewPosition.y, 64, 64); RotorzEditorGUI.DrawBrushPreview(previewPosition, brush); } GUILayout.BeginVertical(); { GUILayout.Label(brush.name, EditorStyles.largeLabel); GUILayout.BeginHorizontal(); { GUILayout.FlexibleSpace(); var tilesetBrush = brush as TilesetBrush; if (tilesetBrush != null) { EditorGUI.BeginDisabledGroup(tilesetBrush.Tileset == null); if (GUILayout.Button(TileLang.OpensWindow(TileLang.ParticularText("Action", "Goto Tileset")), EditorStyles.miniButton)) { ToolUtility.ShowTilesetInDesigner(tilesetBrush.Tileset); GUIUtility.ExitGUI(); } EditorGUI.EndDisabledGroup(); } if (GUILayout.Button(TileLang.OpensWindow(TileLang.ParticularText("Action", "Show in Designer")), EditorStyles.miniButton)) { ToolUtility.ShowBrushInDesigner(brush); GUIUtility.ExitGUI(); } } GUILayout.EndHorizontal(); } GUILayout.EndVertical(); GUILayout.EndHorizontal(); } else { // Nope, assume default header! base.OnHeaderGUI(); } }
/// <inheritdoc/> public override void OnGUI() { // Permit shortcut key "F3". if (Event.current.type == EventType.KeyDown && Event.current.keyCode == KeyCode.F3) { Event.current.Use(); this.ShowTargetBrushInDesigner(); GUIUtility.ExitGUI(); } GUILayout.BeginHorizontal(); { GUILayout.BeginHorizontal(GUILayout.Width(114)); { // Draw preview. string tooltipText = !this.isTargetMasterBrush ? TileLang.Text("Double-click to edit target...") : ""; using (var content = ControlContent.Basic("", tooltipText)) { GUILayout.Box(content, GUILayout.Width(114), GUILayout.Height(114)); Rect previewRect = GUILayoutUtility.GetLastRect(); previewRect.x += 2; previewRect.y += 2; previewRect.width -= 4; previewRect.height -= 4; RotorzEditorGUI.DrawBrushPreview(previewRect, this.AliasBrush.target); // Select target brush for editing upon double-clicking Event e = Event.current; if (e.isMouse && e.clickCount == 2 && previewRect.Contains(e.mousePosition) && !this.isTargetMasterBrush) { this.ShowTargetBrushInDesigner(); GUIUtility.ExitGUI(); } } } GUILayout.EndHorizontal(); GUILayout.Space(10); GUILayout.BeginVertical(); { GUILayout.Space(15); ExtraEditorGUI.AbovePrefixLabel(TileLang.ParticularText("Property", "Alias Target:"), RotorzEditorStyles.Instance.BoldLabel); Brush newAliasTarget = RotorzEditorGUI.BrushField(this.AliasBrush.target, false); if (newAliasTarget != this.AliasBrush.target) { this.SetAliasTarget(newAliasTarget); } GUILayout.Space(5); EditorGUI.BeginDisabledGroup(this.AliasBrush.target == null); if (GUILayout.Button(TileLang.ParticularText("Action", "Revert To Target"), RotorzEditorStyles.Instance.ButtonWide)) { if (EditorUtility.DisplayDialog( TileLang.ParticularText("Dialog Title", "Confirmation"), TileLang.Text("Revert properties of alias brush to target brush?"), TileLang.ParticularText("Action", "Yes"), TileLang.ParticularText("Action", "No") )) { Undo.RecordObject(this.Brush, TileLang.ParticularText("Action", "Revert To Target")); GUIUtility.keyboardControl = 0; this.AliasBrush.RevertToTarget(); } GUIUtility.ExitGUI(); } EditorGUI.EndDisabledGroup(); } GUILayout.EndVertical(); } GUILayout.EndHorizontal(); // Do not display material mapper for 'tileset' targets. if (!(this.AliasBrush.target is TilesetBrush)) { this.Section_MaterialMapper(); } }