Skip to content

Commit

Permalink
BoolInput and regular block nodes working
Browse files Browse the repository at this point in the history
  • Loading branch information
Banane9 committed May 9, 2022
1 parent b78086e commit d12cc32
Show file tree
Hide file tree
Showing 6 changed files with 188 additions and 22 deletions.
134 changes: 123 additions & 11 deletions LogixVisualCustomizer/AssetExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,18 @@ internal static class Assets
{
public static StaticTexture2D GetBackgroundTexture(this World world)
{
if (world.KeyOwner($"Logix_CustomBackground_Texture_{world.LocalUser.UserID}") is StaticTexture2D customBackgroundTexture)
var key = $"Logix_CustomBackground_Texture_{world.LocalUser.UserID}";
if (world.KeyOwner(key) is StaticTexture2D customBackgroundTexture)
return customBackgroundTexture;

customBackgroundTexture = world.GetCustomizerAssets().AttachComponent<StaticTexture2D>();
customBackgroundTexture.URL.Value = LogixVisualCustomizer.BorderSpriteUri;
customBackgroundTexture.URL.Value = LogixVisualCustomizer.BackgroundSpriteUri;
customBackgroundTexture.WrapModeU.Value = TextureWrapMode.Clamp;
customBackgroundTexture.WrapModeV.Value = TextureWrapMode.Clamp;
customBackgroundTexture.FilterMode.Value = TextureFilterMode.Anisotropic;

customBackgroundTexture.AssignKey(key);

return customBackgroundTexture;
}

Expand All @@ -37,15 +40,18 @@ public static StaticTexture2D GetBorderTexture(this Worker worker)

public static StaticTexture2D GetBorderTexture(this World world)
{
if (world.KeyOwner($"Logix_CustomBorder_Texture_{world.LocalUser.UserID}") is StaticTexture2D customBorderTexture)
var key = $"Logix_CustomBorder_Texture_{world.LocalUser.UserID}";
if (world.KeyOwner(key) is StaticTexture2D customBorderTexture)
return customBorderTexture;

customBorderTexture = world.GetCustomizerAssets().AttachComponent<StaticTexture2D>();
customBorderTexture.URL.Value = LogixVisualCustomizer.BackgroundSpriteUri;
customBorderTexture.URL.Value = LogixVisualCustomizer.BorderSpriteUri;
customBorderTexture.WrapModeU.Value = TextureWrapMode.Clamp;
customBorderTexture.WrapModeV.Value = TextureWrapMode.Clamp;
customBorderTexture.FilterMode.Value = TextureFilterMode.Anisotropic;

customBorderTexture.AssignKey(key);

return customBorderTexture;
}

Expand All @@ -59,14 +65,50 @@ public static Slot GetCustomizerAssets(this World world)
return world.AssetsSlot.FindOrAdd("LogixCustomizerAssets");
}

public static SpriteProvider GetFullInputBackgroundProvider(this Worker worker)
{
return worker.World.GetFullInputBackgroundProvider();
}

public static SpriteProvider GetFullInputBackgroundProvider(this World world)
{
const string key = "Logix_FullInputBackground_SpriteProvider";
if (world.KeyOwner(key) is SpriteProvider backgroundSprite)
return backgroundSprite;

backgroundSprite = world.GetCustomizerAssets().AttachComponent<SpriteProvider>();

var textureOverride = backgroundSprite.Texture.GetUserOverride(true);
textureOverride.CreateOverrideOnWrite.Value = true;
textureOverride.Default.Target = world.GetSolidBackgroundTexture();
textureOverride.SetOverride(world.LocalUser, world.GetBackgroundTexture());

var rectOverride = backgroundSprite.Rect.GetUserOverride(true);
rectOverride.CreateOverrideOnWrite.Value = true;
rectOverride.SetOverride(world.LocalUser, LogixVisualCustomizer.FullBackgroundRect);

var bordersOverride = backgroundSprite.Borders.GetUserOverride(true);
bordersOverride.CreateOverrideOnWrite.Value = true;
bordersOverride.SetOverride(world.LocalUser, LogixVisualCustomizer.FullBackgroundBorders);

var scaleOverride = backgroundSprite.Scale.GetUserOverride(true);
scaleOverride.CreateOverrideOnWrite.Value = true;
scaleOverride.SetOverride(world.LocalUser, LogixVisualCustomizer.InputBackgroundScale);

backgroundSprite.AssignKey(key);

return backgroundSprite;
}

public static SpriteProvider GetFullInputBorderProvider(this Worker worker)
{
return worker.World.GetFullInputBorderProvider();
}

public static SpriteProvider GetFullInputBorderProvider(this World world)
{
if (world.KeyOwner("Logix_FullInputBorder_SpriteProvider") is SpriteProvider borderSprite)
const string key = "Logix_FullInputBorder_SpriteProvider";
if (world.KeyOwner(key) is SpriteProvider borderSprite)
return borderSprite;

borderSprite = world.GetCustomizerAssets().AttachComponent<SpriteProvider>();
Expand All @@ -88,6 +130,8 @@ public static SpriteProvider GetFullInputBorderProvider(this World world)
scaleOverride.CreateOverrideOnWrite.Value = true;
scaleOverride.SetOverride(world.LocalUser, LogixVisualCustomizer.InputBorderScale);

borderSprite.AssignKey(key);

return borderSprite;
}

Expand All @@ -98,23 +142,62 @@ public static SolidColorTexture GetHiddenBorderTexture(this Worker worker)

public static SolidColorTexture GetHiddenBorderTexture(this World world)
{
if (world.KeyOwner("Logix_HiddenBorder_Texture") is SolidColorTexture hiddenBorderTexture)
const string key = "Logix_HiddenBorder_Texture";
if (world.KeyOwner(key) is SolidColorTexture hiddenBorderTexture)
return hiddenBorderTexture;

hiddenBorderTexture = world.GetCustomizerAssets().AttachComponent<SolidColorTexture>();
hiddenBorderTexture.Color.Value = new color(1, 0);

hiddenBorderTexture.AssignKey(key);

return hiddenBorderTexture;
}

public static SpriteProvider GetLeftInputBackgroundProvider(this Worker worker)
{
return worker.World.GetLeftInputBackgroundProvider();
}

public static SpriteProvider GetLeftInputBackgroundProvider(this World world)
{
const string key = "Logix_LeftInputBackground_SpriteProvider";
if (world.KeyOwner(key) is SpriteProvider backgroundSprite)
return backgroundSprite;

backgroundSprite = world.GetCustomizerAssets().AttachComponent<SpriteProvider>();

var textureOverride = backgroundSprite.Texture.GetUserOverride(true);
textureOverride.CreateOverrideOnWrite.Value = true;
textureOverride.Default.Target = world.GetSolidBackgroundTexture();
textureOverride.SetOverride(world.LocalUser, world.GetBackgroundTexture());

var rectOverride = backgroundSprite.Rect.GetUserOverride(true);
rectOverride.CreateOverrideOnWrite.Value = true;
rectOverride.SetOverride(world.LocalUser, LogixVisualCustomizer.LeftBackgroundRect);

var bordersOverride = backgroundSprite.Borders.GetUserOverride(true);
bordersOverride.CreateOverrideOnWrite.Value = true;
bordersOverride.SetOverride(world.LocalUser, LogixVisualCustomizer.LeftBackgroundBorders);

var scaleOverride = backgroundSprite.Scale.GetUserOverride(true);
scaleOverride.CreateOverrideOnWrite.Value = true;
scaleOverride.SetOverride(world.LocalUser, LogixVisualCustomizer.InputBackgroundScale);

backgroundSprite.AssignKey(key);

return backgroundSprite;
}

public static SpriteProvider GetLeftInputBorderProvider(this Worker worker)
{
return worker.World.GetLeftInputBorderProvider();
}

public static SpriteProvider GetLeftInputBorderProvider(this World world)
{
if (world.KeyOwner("Logix_LeftInputBorder_SpriteProvider") is SpriteProvider borderSprite)
const string key = "Logix_LeftInputBorder_SpriteProvider";
if (world.KeyOwner(key) is SpriteProvider borderSprite)
return borderSprite;

borderSprite = world.GetCustomizerAssets().AttachComponent<SpriteProvider>();
Expand All @@ -136,6 +219,8 @@ public static SpriteProvider GetLeftInputBorderProvider(this World world)
scaleOverride.CreateOverrideOnWrite.Value = true;
scaleOverride.SetOverride(world.LocalUser, LogixVisualCustomizer.InputBorderScale);

borderSprite.AssignKey(key);

return borderSprite;
}

Expand All @@ -146,15 +231,16 @@ public static SpriteProvider GetNodeBackgroundProvider(this Worker worker)

public static SpriteProvider GetNodeBackgroundProvider(this World world)
{
if (world.KeyOwner("Logix_NodeBackground_SpriteProvider") is SpriteProvider backgroundSprite)
const string key = "Logix_NodeBackground_SpriteProvider";
if (world.KeyOwner(key) is SpriteProvider backgroundSprite)
return backgroundSprite;

backgroundSprite = world.GetCustomizerAssets().AttachComponent<SpriteProvider>();

var textureOverride = backgroundSprite.Texture.GetUserOverride(true);
textureOverride.CreateOverrideOnWrite.Value = true;
textureOverride.Default.Target = world.GetSolidBackgroundTexture();
textureOverride.SetOverride(world.LocalUser, world.GetBorderTexture());
textureOverride.SetOverride(world.LocalUser, world.GetBackgroundTexture());

var rectOverride = backgroundSprite.Rect.GetUserOverride(true);
rectOverride.CreateOverrideOnWrite.Value = true;
Expand All @@ -168,6 +254,8 @@ public static SpriteProvider GetNodeBackgroundProvider(this World world)
scaleOverride.CreateOverrideOnWrite.Value = true;
scaleOverride.SetOverride(world.LocalUser, LogixVisualCustomizer.NodeBackgroundScale);

backgroundSprite.AssignKey(key);

return backgroundSprite;
}

Expand All @@ -178,7 +266,8 @@ public static SpriteProvider GetNodeBorderProvider(this Worker worker)

public static SpriteProvider GetNodeBorderProvider(this World world)
{
if (world.KeyOwner("Logix_NodeBorder_SpriteProvider") is SpriteProvider borderSprite)
const string key = "Logix_NodeBorder_SpriteProvider";
if (world.KeyOwner(key) is SpriteProvider borderSprite)
return borderSprite;

borderSprite = world.GetCustomizerAssets().AttachComponent<SpriteProvider>();
Expand All @@ -200,6 +289,8 @@ public static SpriteProvider GetNodeBorderProvider(this World world)
scaleOverride.CreateOverrideOnWrite.Value = true;
scaleOverride.SetOverride(world.LocalUser, LogixVisualCustomizer.NodeBorderScale);

borderSprite.AssignKey(key);

return borderSprite;
}

Expand All @@ -210,12 +301,15 @@ public static SolidColorTexture GetSolidBackgroundTexture(this Worker worker)

public static SolidColorTexture GetSolidBackgroundTexture(this World world)
{
if (world.KeyOwner("Logix_DefaultBackground_Texture") is SolidColorTexture backgroundTexture)
const string key = "Logix_DefaultBackground_Texture";
if (world.KeyOwner(key) is SolidColorTexture backgroundTexture)
return backgroundTexture;

backgroundTexture = world.GetCustomizerAssets().AttachComponent<SolidColorTexture>();
backgroundTexture.Color.Value = LogixNode.DEFAULT_NODE_BACKGROUND;

backgroundTexture.AssignKey(key);

return backgroundTexture;
}

Expand Down Expand Up @@ -261,6 +355,24 @@ public static void UpdateCustomizerAssets(this World world)
background.URL.Value = LogixVisualCustomizer.BackgroundSpriteUri;
backgroundTexture = background;
}

var nodeBackgroundSprite = world.GetNodeBackgroundProvider();
nodeBackgroundSprite.Texture.Target = backgroundTexture;
nodeBackgroundSprite.Rect.Value = LogixVisualCustomizer.FullBackgroundRect;
nodeBackgroundSprite.Borders.Value = LogixVisualCustomizer.FullBackgroundBorders;
nodeBackgroundSprite.Scale.Value = LogixVisualCustomizer.NodeBackgroundScale;

var fullBackgroundSprite = world.GetFullInputBackgroundProvider();
fullBackgroundSprite.Texture.Target = backgroundTexture;
fullBackgroundSprite.Rect.Value = LogixVisualCustomizer.FullBackgroundRect;
fullBackgroundSprite.Borders.Value = LogixVisualCustomizer.FullBackgroundBorders;
fullBackgroundSprite.Scale.Value = LogixVisualCustomizer.InputBorderScale;

var leftBackgroundSprite = world.GetLeftInputBackgroundProvider();
leftBackgroundSprite.Texture.Target = backgroundTexture;
leftBackgroundSprite.Rect.Value = LogixVisualCustomizer.LeftBackgroundRect;
leftBackgroundSprite.Borders.Value = LogixVisualCustomizer.LeftBackgroundBorders;
leftBackgroundSprite.Scale.Value = LogixVisualCustomizer.InputBorderScale;
}
}
}
Binary file modified LogixVisualCustomizer/Assets/Border.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added LogixVisualCustomizer/Assets/Disc.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
21 changes: 20 additions & 1 deletion LogixVisualCustomizer/BoolInputPatch.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,26 @@ internal static class BoolInputPatch
[HarmonyPatch("OnGenerateVisual")]
private static void OnGenerateVisualPostfix(Slot root)
{
var textRect = root.GetComponentInChildren<Text>().RectTransform;
var button = root.GetComponentInChildren<Button>();
button.BaseColor.Value = LogixVisualCustomizer.InputBackgroundColor;
button.ColorDrivers[0].TintColorMode.Value = InteractionElement.ColorMode.Multiply;

var buttonSlot = button.Slot;

var buttonImage = buttonSlot.GetComponent<Image>();
buttonImage.Sprite.Target = root.GetLeftInputBackgroundProvider();

var borderSlot = buttonSlot.AddSlot("Border");
borderSlot.OrderOffset = -1;

var borderImage = borderSlot.AttachComponent<Image>();
borderImage.Tint.Value = LogixVisualCustomizer.InputBorderColor;
borderImage.Sprite.Target = root.GetLeftInputBorderProvider();

var buttonText = buttonSlot.GetComponentInChildren<Text>();
buttonText.Color.Value = LogixVisualCustomizer.TextColor;

var textRect = buttonText.RectTransform;
textRect.AnchorMin.Value = new float2(0.1f, 0.1f);
textRect.AnchorMax.Value = new float2(0.9f, 0.9f);
}
Expand Down
17 changes: 12 additions & 5 deletions LogixVisualCustomizer/LogixNodePatch.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,16 +20,23 @@ private static void GenerateUIPostfix(Slot root)
if (!LogixVisualCustomizer.EnableCustomLogixVisuals)
return;

var background = root[0][0].GetComponent<Image>();
var backgroundSlot = root.FindInChildren("Image");

var background = backgroundSlot.GetComponent<Image>();
background.Tint.Value = LogixVisualCustomizer.NodeBackgroundColor;
background.Sprite.Target = root.GetBackgroundProvider();
background.Sprite.Target = root.GetNodeBackgroundProvider();

var border = root.Find("Image").AddSlot("Border");
border.OrderOffset = -1;
var borderSlot = backgroundSlot.AddSlot("Border");
borderSlot.OrderOffset = -1;

var borderImage = border.AttachComponent<Image>();
var borderImage = borderSlot.AttachComponent<Image>();
borderImage.Tint.Value = LogixVisualCustomizer.NodeBorderColor;
borderImage.Sprite.Target = root.GetNodeBorderProvider();

backgroundSlot.ForeachComponentInChildren<Text>(text => text.Color.Value = LogixVisualCustomizer.TextColor);

foreach (var connector in backgroundSlot.Children.Where(child => child.Name == "Image").Select(child => child.GetComponent<Image>()))
connector.Tint.Value = connector.Tint.Value.SetA(1).AddValue(.1f);
}
}
}
Loading

0 comments on commit d12cc32

Please sign in to comment.