Skip to content

Commit

Permalink
Merge branch 'dev'
Browse files Browse the repository at this point in the history
  • Loading branch information
OndrejNepozitek committed Mar 8, 2020
2 parents 1caf8ee + a02dc24 commit e9faecd
Show file tree
Hide file tree
Showing 1,375 changed files with 155,966 additions and 268,593 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
[Bb]uilds/
Assets/AssetStoreTools*
Assets/Resources/Tilemaps/
Benchmarks/
exportedMapDescription.json

# Visual Studio cache directory
.vs/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
{
public enum EditorMode
{
Drag, MakeConnections
Basic = 0,
Drag = 1,
MakeConnections = 2,
}
}
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
namespace Assets.ProceduralLevelGenerator.Editor.LevelGraphEditor.EditorNodes
using Assets.ProceduralLevelGenerator.Scripts.Generators.Common.LevelGraph;

namespace Assets.ProceduralLevelGenerator.Editor.LevelGraphEditor.EditorNodes
{
using System;
using NodeBasedEditor;
using Scripts.Data.Graphs;
using UnityEditor;
using UnityEditor;
using UnityEngine;

public class ConnectionNode : IEditorNode<Connection>
Expand All @@ -17,18 +18,20 @@ public class ConnectionNode : IEditorNode<Connection>
public Action OnDelete;

private GUIStyle handleStyle;
private readonly GUIStyle activeStyle;

private int handleWidth;
private int handleWidth;

private bool isClickAfterContextMenu;

public ConnectionNode(Connection data, RoomNode from, RoomNode to, GUIStyle handleStyle, int handleWidth)
public ConnectionNode(Connection data, RoomNode from, RoomNode to, GUIStyle handleStyle, GUIStyle activeStyle, int handleWidth)
{
Data = data;
From = from;
To = to;
this.handleStyle = handleStyle;
this.handleWidth = handleWidth;
this.activeStyle = activeStyle;
this.handleWidth = handleWidth;
}

public bool ProcessEvents(Event e)
Expand All @@ -45,6 +48,12 @@ public bool ProcessEvents(Event e)
isClickAfterContextMenu = true;
}
}
if (e.button == 0 && GetHandleRect().Contains(e.mousePosition) && e.clickCount > 1)
{
Selection.activeObject = Data;
e.Use();
GUI.changed = true;
}

break;

Expand Down Expand Up @@ -77,7 +86,7 @@ private void OnClickDelete()
public void Draw()
{
Handles.DrawLine(From.Rect.center, To.Rect.center);
GUI.Box(GetHandleRect(), string.Empty, handleStyle);
GUI.Box(GetHandleRect(), string.Empty, Selection.activeObject == Data ? activeStyle : handleStyle);
}

public void Drag(Vector2 delta)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
namespace Assets.ProceduralLevelGenerator.Editor.LevelGraphEditor.EditorNodes
using Assets.ProceduralLevelGenerator.Scripts.Generators.Common.LevelGraph;

namespace Assets.ProceduralLevelGenerator.Editor.LevelGraphEditor.EditorNodes
{
using System;
using NodeBasedEditor;
using Scripts.Data.Graphs;
using UnityEditor;
using UnityEditor;
using UnityEngine;

public class RoomNode : IEditorNode<Room>
Expand All @@ -24,23 +25,26 @@ public class RoomNode : IEditorNode<Room>

private readonly GUIStyle style;

private bool isDragged;
private readonly GUIStyle activeStyle;

private bool isDragged;

private bool isClickAfterContextMenu;


public RoomNode(Room data, float width, float height, GUIStyle style, EditorMode mode)
public RoomNode(Room data, float width, float height, GUIStyle style, GUIStyle activeStyle, EditorMode mode)
{
Data = data;
this.style = style;
Rect = new Rect(Data.Position.x, Data.Position.y, width, height);
this.activeStyle = activeStyle;
Rect = new Rect(Data.Position.x, Data.Position.y, width, height);
this.Mode = mode;
}

// TODO: refactor
public bool ProcessEvents(Event e)
{
switch (e.type)
switch (e.type)
{
case EventType.MouseDown:
if (e.button == 1)
Expand All @@ -55,12 +59,22 @@ public bool ProcessEvents(Event e)
else if (e.button == 0 && Mode == EditorMode.MakeConnections && Rect.Contains(e.mousePosition))
{
OnStartConnection?.Invoke(e);
}
else if (Rect.Contains(e.mousePosition) && e.button == 0)
} else if (e.button == 0 && Mode == EditorMode.Drag && Rect.Contains(e.mousePosition) && e.clickCount > 1)
{
OnClickConfigure();
e.Use();
GUI.changed = true;
}
else if (Mode == EditorMode.Drag && Rect.Contains(e.mousePosition) && e.button == 0)
{
isDragged = true;
}

if (Rect.Contains(e.mousePosition))
{
e.Use();
}

break;

case EventType.MouseUp:
Expand Down Expand Up @@ -125,7 +139,7 @@ private void OnClickConfigure()

public void Draw()
{
GUI.Box(Rect, Data.Name, style);
GUI.Box(Rect, Data.ToString(), Selection.activeObject == Data ? activeStyle : style);
}

public void Drag(Vector2 delta)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
namespace Assets.ProceduralLevelGenerator.Editor.LevelGraphEditor
using Assets.ProceduralLevelGenerator.Scripts.Generators.Common.LevelGraph;

namespace Assets.ProceduralLevelGenerator.Editor.LevelGraphEditor
{
using System;
using Scripts.Data.Graphs;
using UnityEditor;
using UnityEditor;
using UnityEngine;

[CustomEditor(typeof(LevelGraph))]
Expand All @@ -15,29 +16,41 @@ public override void OnInspectorGUI()
{
serializedObject.Update();

defaultRoomTemplatesFoldout = EditorGUILayout.Foldout(defaultRoomTemplatesFoldout, "Default room templates");
var foldoutStyle = new GUIStyle(EditorStyles.foldout) {fontStyle = FontStyle.Bold};

defaultRoomTemplatesFoldout = EditorGUILayout.Foldout(defaultRoomTemplatesFoldout, "Default room templates", foldoutStyle);

if (defaultRoomTemplatesFoldout)
{
EditorGUI.indentLevel++;
// EditorGUILayout.PropertyField(serializedObject.FindProperty(nameof(LevelGraph.DefaultRoomTemplateSets)), true);
EditorGUILayout.PropertyField(serializedObject.FindProperty(nameof(LevelGraph.DefaultIndividualRoomTemplates)), true);
EditorGUILayout.PropertyField(
serializedObject.FindProperty(nameof(LevelGraph.DefaultIndividualRoomTemplates)),
new GUIContent("Room Templates"),
true);
EditorGUILayout.PropertyField(
serializedObject.FindProperty(nameof(LevelGraph.DefaultRoomTemplateSets)),
new GUIContent("Room Templates Sets"),
true);
EditorGUI.indentLevel--;
}

corridorRoomTemplatesFoldout = EditorGUILayout.Foldout(corridorRoomTemplatesFoldout, "Corridor room templates");
corridorRoomTemplatesFoldout = EditorGUILayout.Foldout(corridorRoomTemplatesFoldout, "Corridor room templates", foldoutStyle);

if (corridorRoomTemplatesFoldout)
{
EditorGUI.indentLevel++;
// EditorGUILayout.PropertyField(serializedObject.FindProperty(nameof(LevelGraph.CorridorRoomTemplateSets)), true);
EditorGUILayout.PropertyField(serializedObject.FindProperty(nameof(LevelGraph.CorridorIndividualRoomTemplates)), true);
EditorGUILayout.PropertyField(serializedObject.FindProperty(
nameof(LevelGraph.CorridorIndividualRoomTemplates)),
new GUIContent("Room Templates"),
true);
EditorGUILayout.PropertyField(
serializedObject.FindProperty(nameof(LevelGraph.CorridorRoomTemplateSets)),
new GUIContent("Room Templates Sets"),
true);
EditorGUI.indentLevel--;
}

EditorGUILayout.PropertyField(serializedObject.FindProperty(nameof(LevelGraph.RoomsGroups)), true);

if (GUILayout.Button("Open graph editor"))
if (GUILayout.Button("Open graph editor"))
{
var type = Type.GetType("UnityEditor.GameView,UnityEditor");
var window = EditorWindow.GetWindow<LevelGraphWindow>("Graph editor", type);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
namespace Assets.ProceduralLevelGenerator.Editor.LevelGraphEditor
using Assets.ProceduralLevelGenerator.Scripts.Generators.Common.LevelGraph;

namespace Assets.ProceduralLevelGenerator.Editor.LevelGraphEditor
{
using System.Collections.Generic;
using System.Linq;
using EditorNodes;
using NodeBasedEditor;
using Scripts.Data.Graphs;
using UnityEditor;
using UnityEditor;
using UnityEngine;
using RoomNode = EditorNodes.RoomNode;

Expand All @@ -19,20 +20,25 @@ public class LevelGraphWindow : NodeBasedEditorBase

private GUIStyle roomNodeStyle;

private GUIStyle roomNodeStyleActive;

private GUIStyle connectionHandleStyle;

private GUIStyle connectionHandleStyleActive;

private RoomNode connectionFrom;

private ConnectionProgressNode connectionProgress;

private EditorMode editorMode = EditorMode.Drag;

private int selectedToolbar = 0;

private int currentPickerWindow;

private bool doNotDrag;

private int roomWidth = 80;
private int roomHeight = 25;

public static LevelGraph StaticData { get; set; }

public void Initialize()
Expand Down Expand Up @@ -79,12 +85,26 @@ protected void SetupStyles()
roomNodeStyle.fontSize = 12;
roomNodeStyle.alignment = TextAnchor.MiddleCenter;

roomNodeStyleActive = new GUIStyle();
roomNodeStyleActive.normal.background = MakeTex(1, 1, new Color(0.2f, 0.2f, 0.2f, 0.85f));
roomNodeStyleActive.border = new RectOffset(12, 12, 12, 12);
roomNodeStyleActive.normal.textColor = Color.red;
roomNodeStyleActive.fontSize = 12;
roomNodeStyleActive.alignment = TextAnchor.MiddleCenter;

connectionHandleStyle = new GUIStyle();
connectionHandleStyle.normal.background = MakeTex(1, 1, new Color(0.3f, 0.3f, 0.3f, 0.6f));
connectionHandleStyle.border = new RectOffset(12, 12, 12, 12);
connectionHandleStyle.normal.textColor = Color.white;
connectionHandleStyle.fontSize = 12;
connectionHandleStyle.alignment = TextAnchor.MiddleCenter;

connectionHandleStyleActive = new GUIStyle();
connectionHandleStyleActive.normal.background = MakeTex(1, 1, new Color(0.8f, 0f, 0f, 0.2f));
connectionHandleStyleActive.border = new RectOffset(12, 12, 12, 12);
connectionHandleStyleActive.normal.textColor = Color.white;
connectionHandleStyleActive.fontSize = 12;
connectionHandleStyleActive.alignment = TextAnchor.MiddleCenter;
}

public override void OnGUI()
Expand All @@ -101,7 +121,16 @@ public override void OnGUI()
{
modeChanged = true;
editorMode = EditorMode.Drag;
}
}
//else if (!e.shift && editorMode == EditorMode.Drag)
//{
// modeChanged = true;
// editorMode = EditorMode.Basic;
//} else if (e.shift && editorMode == EditorMode.Basic)
//{
// modeChanged = true;
// editorMode = EditorMode.Drag;
//}

if (modeChanged)
{
Expand Down Expand Up @@ -176,11 +205,11 @@ protected override void ProcessEvents(Event e)
switch (e.type)
{
case EventType.MouseDown:
if (e.button == 1)
{
ProcessContextMenu(e.mousePosition);
doNotDrag = true;
}
if (e.button == 0 && e.clickCount > 1)
{
OnClickAddRoom(e.mousePosition);
doNotDrag = true;
}
break;

case EventType.MouseDrag:
Expand All @@ -190,13 +219,13 @@ protected override void ProcessEvents(Event e)
break;
}

if (e.button == 0 && editorMode != EditorMode.MakeConnections)
if (e.button == 1 && editorMode != EditorMode.MakeConnections)
{
OnDrag(e.delta);
}
break;
}
}
}

protected override IEnumerable<IEditorNodeBase> GetAllNodes()
{
Expand Down Expand Up @@ -226,15 +255,19 @@ protected override void ProcessContextMenu(Vector2 mousePosition)
}

protected void OnClickAddRoom(Vector2 mousePosition)
{
var room = CreateInstance<Room>();
{
// TODO: how to handle this properly?
var room = (Room) CreateInstance(Data.RoomType);

room.Position = mousePosition;
room.Position = mousePosition - new Vector2(roomWidth / 2f, roomHeight / 2f);
Data.Rooms.Add(room);
AssetDatabase.AddObjectToAsset(room, Data);

CreateNode(room);
}

Selection.activeObject = room;
GUI.changed = true;
}

protected void OnStartConnection(RoomNode roomNode, Event e)
{
Expand All @@ -254,8 +287,9 @@ protected void OnEndConnection(RoomNode roomNode, Event e)
var from = connectionFrom;
var to = roomNode;

var connection = CreateInstance<Connection>();
connection.From = connectionFrom.Data;
// TODO: how to handle this properly?
var connection = (Connection) CreateInstance(Data.ConnectionType);
connection.From = connectionFrom.Data;
connection.To = roomNode.Data;

if (from != to && !connectionNodes.Any(x => (x.From == @from && x.To == to) || (x.To == @from && x.From == to)))
Expand All @@ -273,7 +307,7 @@ protected void OnEndConnection(RoomNode roomNode, Event e)

protected RoomNode CreateNode(Room data)
{
var node = new RoomNode(data, 40, 40, roomNodeStyle, editorMode);
var node = new RoomNode(data, roomWidth, roomHeight, roomNodeStyle, roomNodeStyleActive, editorMode);

node.OnDelete += () => OnDeleteRoomNode(node);
node.OnStartConnection += (e) => OnStartConnection(node, e);
Expand All @@ -285,7 +319,7 @@ protected RoomNode CreateNode(Room data)

protected ConnectionNode CreateConnection(Connection data, RoomNode from, RoomNode to)
{
var node = new ConnectionNode(data, from, to, connectionHandleStyle, 12);
var node = new ConnectionNode(data, from, to, connectionHandleStyle, connectionHandleStyleActive, 12);

node.OnDelete += () => OnDeleteConnectionNode(node);
connectionNodes.Add(node);
Expand Down

0 comments on commit e9faecd

Please sign in to comment.