Skip to content

Pr/48 dark mode #69

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -8,22 +8,20 @@ public class BehaviorTreePrinter {
private readonly Rect _containerSize;

private Vector2 _scrollPosition;

public static StatusIcons StatusIcons { get; private set; }
public static GuiStyleCollection SharedStyles { get; private set; }


public BehaviorTreePrinter (IBehaviorTree tree, Vector2 windowSize) {
StatusIcons = new StatusIcons();
SharedStyles = new GuiStyleCollection();

var container = new GraphContainerVertical();
container.SetGlobalPosition(SCROLL_PADDING, SCROLL_PADDING);
_root = new VisualTask(tree.Root, container);
container.CenterAlignChildren();
_containerSize = new Rect(0, 0,
container.Width + SCROLL_PADDING * 2,

_containerSize = new Rect(0, 0,
container.Width + SCROLL_PADDING * 2,
container.Height + SCROLL_PADDING * 2);

CenterScrollView(windowSize, container);
Expand All @@ -37,8 +35,8 @@ private void CenterScrollView (Vector2 windowSize, GraphContainerVertical contai

public void Print (Vector2 windowSize) {
_scrollPosition = GUI.BeginScrollView(
new Rect(0, 0, windowSize.x, windowSize.y),
_scrollPosition,
new Rect(0, 0, windowSize.x, windowSize.y),
_scrollPosition,
_containerSize);
_root.Print();
GUI.EndScrollView();
Expand All @@ -48,4 +46,4 @@ public void Unbind () {
_root.RecursiveTaskUnbind();
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ namespace CleverCrow.Fluid.BTs.Trees.Editors {
public static class AssetPath {
private const string PATH_PROJECT = "Assets/FluidBehaviorTree";
private const string PATH_PACKAGE = "Packages/com.fluid.behavior-tree";
private const string PATH_PACKAGE2 = "Assets/com.fluid.behavior-tree";

private static string _basePath;

Expand All @@ -19,6 +20,11 @@ public static string BasePath {
_basePath = PATH_PACKAGE;
return _basePath;
}

if (AssetDatabase.IsValidFolder(PATH_PACKAGE2)) {
_basePath = PATH_PACKAGE2;
return _basePath;
}

if (AssetDatabase.IsValidFolder(PATH_PROJECT)) {
_basePath = PATH_PROJECT;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
using System.Linq;
using UnityEngine;

/// <summary>
/// Display settings of the behaviour tree window
/// </summary>
public class DisplaySettings {
public static Color lightModeActive { get; } = new Color(0.39f, 0.78f, 0.39f);
public static Color lightModeInactive { get; } = new Color(0.65f, 0.65f, 0.65f);
public static Color lightModeActiveText { get; } = Color.white;
public static Color lightModeInactiveText { get; } = Color.black;
public static Color lightModeActiveMainIcon { get; } = new Color(1, 1, 1, 1f);
public static Color lightModeInactiveMainIcon { get; } = new Color(1, 1, 1, 0.3f);

public static Color darkModeActive { get; } = Color.white;
public static Color darkModeInactive { get; } = new Color(0f, 0f, 0f, 1f);
public static Color darkModeActiveText { get; } = Color.white;
public static Color darkModeInactiveText { get; } = Color.grey;
public static Color darkModeActiveMainIcon { get; } = new Color(1, 1, 1, 1f);
public static Color darkModeInactiveMainIcon { get; } = new Color(1, 1, 1, 0.3f);

public static GUIStyle taskFontFormat { get; } = new GUIStyle(GUI.skin.label) {
fontSize = 9,
alignment = TextAnchor.LowerCenter,
wordWrap = true,
padding = new RectOffset(3, 3, 3, 3),
};

public static GUIStyle lightModeBoxStyle = new GUIStyle(GUI.skin.box) {
// Perhaps make it better one day
};

public static GUIStyle darkModeBoxStyle = new GUIStyle(GUI.skin.box) {
// Perhaps make it better one day
};
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,20 +1,43 @@
using UnityEngine;
using UnityEditor;

namespace CleverCrow.Fluid.BTs.Trees.Editors {
public class NodeFaders {
public ColorFader BackgroundFader { get; } = new ColorFader(
new Color(0.65f, 0.65f, 0.65f), new Color(0.39f, 0.78f, 0.39f));

public ColorFader TextFader { get; } = new ColorFader(
Color.white, Color.black);

public ColorFader MainIconFader { get; } = new ColorFader(
new Color(1, 1, 1, 0.3f), new Color(1, 1, 1, 1f));
public ColorFader BackgroundFader { get; }

public ColorFader TextFader { get; }

public ColorFader MainIconFader { get; }

public NodeFaders() {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Digging this, makes sense.

// If in dark mode choose dark mode
if (EditorGUIUtility.isProSkin){
BackgroundFader = new ColorFader(
DisplaySettings.darkModeInactive,
DisplaySettings.darkModeActive);
TextFader = new ColorFader(
DisplaySettings.darkModeInactiveText,
DisplaySettings.darkModeActiveText);
MainIconFader = new ColorFader(
DisplaySettings.darkModeInactiveMainIcon,
DisplaySettings.darkModeActiveMainIcon);
}else {
BackgroundFader = new ColorFader(
DisplaySettings.lightModeInactive,
DisplaySettings.lightModeActive);
TextFader = new ColorFader(
DisplaySettings.lightModeInactiveText,
DisplaySettings.lightModeActiveText);
MainIconFader = new ColorFader(
DisplaySettings.lightModeInactiveMainIcon,
DisplaySettings.lightModeActiveMainIcon);
}
}

public void Update (bool active) {
BackgroundFader.Update(active);
TextFader.Update(active);
MainIconFader.Update(active);
}
}
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using System.Linq;
using CleverCrow.Fluid.BTs.TaskParents;
using UnityEngine;
using UnityEditor;

namespace CleverCrow.Fluid.BTs.Trees.Editors {
public class NodePrintController {
Expand All @@ -15,8 +16,6 @@ public class NodePrintController {
private Texture2D _verticalBottom;
private Texture2D _verticalTop;

private static GuiStyleCollection Styles => BehaviorTreePrinter.SharedStyles;

public NodePrintController (VisualTask node) {
_node = node;
_box = node.Box;
Expand All @@ -40,25 +39,38 @@ private void PaintBody () {
var prevBackgroundColor = GUI.backgroundColor;

var rect = new Rect(
_box.GlobalPositionX + _box.PaddingX,
_box.GlobalPositionX + _box.PaddingX,
_box.GlobalPositionY + _box.PaddingY,
_box.Width - _box.PaddingX,
_box.Width - _box.PaddingX,
_box.Height - _box.PaddingY);

if (_node.Task.HasBeenActive) {
GUI.backgroundColor = _faders.BackgroundFader.CurrentColor;
GUI.Box(rect, GUIContent.none, Styles.BoxActive.Style);

if (EditorGUIUtility.isProSkin) {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Move if block to a static DisplaySettings.GetBoxActiveStyle() method that can support caching

GUI.Box(rect, GUIContent.none, new GUIStyle(DisplaySettings.darkModeBoxStyle));
}
else {
GUI.Box(rect, GUIContent.none, new GUIStyle(DisplaySettings.lightModeBoxStyle));
}

GUI.backgroundColor = prevBackgroundColor;

PrintLastStatus(rect);
} else {
GUI.Box(rect, GUIContent.none, Styles.BoxInactive.Style);
}

else {
if (EditorGUIUtility.isProSkin) {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Move if block to a static DisplaySettings.GetBoxInactiveStyle() method that can support caching

GUI.Box(rect, GUIContent.none, new GUIStyle(DisplaySettings.darkModeBoxStyle));
}
else {
GUI.Box(rect, GUIContent.none, new GUIStyle(DisplaySettings.lightModeBoxStyle));
}
}

PrintIcon();

Styles.Title.normal.textColor = _faders.TextFader.CurrentColor;
GUI.Label(rect, _node.Task.Name, Styles.Title);
var textFormat = DisplaySettings.taskFontFormat;
textFormat.normal.textColor = _faders.TextFader.CurrentColor;
GUI.Label(rect, _node.Task.Name, textFormat);
}

private void PrintLastStatus (Rect rect) {
Expand Down