fungus icon indicating copy to clipboard operation
fungus copied to clipboard

[FEATURE SUGGESTION] Custom blockname tint

Open TheEmbracedOne opened this issue 2 years ago • 0 comments

It'd be neat if users could choose to colour blocknames on nodes the exact same way as custom tint but for colouring the name of the block: Unity_hzHQ9mrrSr

Is your feature request related to a problem? Please describe. Since you're able to set block colour, I think it makes sense to be able to have full control over the colour of the blockname as well. The code that colours text white or black based on brightness is a little unreliable, Color.magenta for example doesnt get coloured black, and with white text it's quite hard to read, here I'd suggest replacing the following:

//replace this:
nodeStyle.normal.textColor = brightness >= 0.5 ? Color.black : Color.white;

//with this:
Color.RGBToHSV(graphics.tint, out _, out _, out float value);
nodeStyle.normal.textColor = value>= 0.45 ? Color.black : Color.white;

I also have a bunch of custom error checking features I added to Fungus on my end that checks for broken/missing references, null characters/targetblocks and so on, which modifies the custom tint colour of blocks in which it found problems, and being able to colour text too is really useful for me.

Describe the solution you'd like Normally I'd make a PR for this as I have written the functionality I desire, but I'm very pressed for time. I'll leave my notes and code here for either myself in the future or someone else to make a proper PR later:

Node.cs added:

[SerializeField] protected Color textTint = Color.white;
[SerializeField] protected bool useCustomTextColor;

public virtual bool UseCustomTextColor { get { return useCustomTextColor; } set { useCustomTextColor = value; } }
public virtual Color TextTint { get { return textTint; } set { textTint = value; } }

BlockEditor.cs:

SerializedProperty useCustomTextColorProp;
SerializedProperty textTintProp;

//----------------------------
//in DrawBlockGUI under the "EditorGUILayout.EndHorizontal();" below Custom Tint:
useCustomTextColorProp = serializedObject.FindProperty("useCustomTextColor");
textTintProp = serializedObject.FindProperty("textTint");

EditorGUILayout.BeginHorizontal();
useCustomTextColorProp.boolValue = GUILayout.Toggle(useCustomTextColorProp.boolValue, " Custom Text Tint");
if (useCustomTextColorProp.boolValue) {
	EditorGUILayout.PropertyField(textTintProp, GUIContent.none);
}
EditorGUILayout.EndHorizontal();

FlowchartWindow.cs: add "textColor" to BLockGraphics:

protected struct BlockGraphics {
	internal Color tint;
	internal Color textColor;
	internal Texture2D onTexture;
	internal Texture2D offTexture;
}

Then insert between graphics.tint = (block.UseCustomTint ? block.Tint : defaultTint) * FungusEditorPreferences.flowchartBlockTint; and return graphics; inside GetBlockGraphics(Block block):

float value;
Color.RGBToHSV(graphics.tint, out _, out _, out value);
Color defaultTextTint = value >= 0.45 ? Color.black : Color.white;

graphics.textColor = (block.UseCustomTextColor ? block.TextTint : defaultTextTint);

//if locked, grey blocks (makes it easier to notice the flowchart's locked
if (flowchart.locked) { graphics.tint.a = 0.75f; }

FungusConstants.cs:

public static Color DefaultChoiceBlockTextTint = new Color(1.00f, 1.00f, 1.000f);

TheEmbracedOne avatar Jun 27 '22 22:06 TheEmbracedOne