Skip to content
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
4 changes: 4 additions & 0 deletions Source/PipeSystem/PipeSystem/Def/PipeNetDef.cs
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,10 @@ public class Resource
public class DeconstructOption
{
public string deconstructIconPath;
public string shaderPath;
public string maskTexturePath;
public Color color;
public Color colorTwo;
public DesignationCategoryDef designationCategoryDef;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,47 @@ public Designator_DeconstructPipe(PipeNetDef pipeNet)
pipeNetDef = pipeNet;
defaultLabel = "PipeSystem_DeconstructLabel".Translate(pipeNet.resource.name);
defaultDesc = "PipeSystem_DeconstructDesc".Translate(pipeNet.resource.name);
icon = ContentFinder<Texture2D>.Get(pipeNet.designator.deconstructIconPath);
hotKey = null;

var baseTexture = ContentFinder<Texture2D>.Get(pipeNet.designator.deconstructIconPath);
if (string.IsNullOrEmpty(pipeNetDef.designator.shaderPath))
{
icon = baseTexture;
}
else
{
var shader = Shader.Find(pipeNetDef.designator.shaderPath);
if (shader == null)
{
Log.Warning($"Designator_DeconstructPipe - invalid shader path {pipeNetDef.designator.shaderPath} - falling back to stock icon");
icon = baseTexture;
return;
}

var mat = MaterialPool.MatFrom(pipeNetDef.designator.deconstructIconPath, shader);
mat.SetColor(ShaderPropertyIDs.Color, pipeNetDef.designator.color);

// TODO: This checks specific, hardcoded shaders. It probably won't support fancy custom ones. It does work for CutoutComplex
if (ShaderUtility.SupportsMaskTex(shader))
{
var maskTexture = ContentFinder<Texture2D>.Get(pipeNet.designator.maskTexturePath);
mat.SetTexture(ShaderPropertyIDs.MaskTex, maskTexture);
mat.SetColor(ShaderPropertyIDs.ColorTwo, pipeNetDef.designator.colorTwo);
}

var renderTexture = RenderTexture.GetTemporary(baseTexture.width, baseTexture.height);

Graphics.Blit(baseTexture, renderTexture, mat);

var outputTexture = new Texture2D(renderTexture.width, renderTexture.height, TextureFormat.RGBA32, false);
outputTexture.ReadPixels(new Rect(0, 0, renderTexture.width, renderTexture.height), 0, 0);
outputTexture.Apply();

icon = outputTexture;

RenderTexture.ReleaseTemporary(renderTexture);

}
}

public override AcceptanceReport CanDesignateThing(Thing t)
Expand Down
4 changes: 2 additions & 2 deletions Source/PipeSystem/PipeSystem/Graphic/LinkedPipes.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System.Collections.Generic;
using UnityEngine;
using Verse;

namespace PipeSystem
Expand Down Expand Up @@ -38,8 +39,7 @@ static LinkedPipes()
for (int o = 0; o < netDef.pipeDefs.Count; o++)
{
var pipeDef = netDef.pipeDefs[o];

Graphic graphicP = GraphicDatabase.Get<Graphic_Single>(pipeDef.graphic.data.texPath, ShaderDatabase.Cutout);
Graphic graphicP = GraphicDatabase.Get<Graphic_Single>(pipeDef.graphic.data.texPath, ShaderDatabase.Cutout, Vector2.one, pipeDef.graphicData.color);
pipesLinked.Add(pipeDef, new Graphic_LinkedPipe(graphicP, netDef));
}
}
Expand Down
Binary file added Textures/UI/Gizmo/SimplePipe_Deconstruct_Mask.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.