예제 #1
0
        /// <summary> Try to load the Graphic of appropriate type based on current life stage </summary>
        Graphic LoadGraphic(string variant)
        {
            string path = ageTracker.CurKindLifeStage.bodyGraphicData.texPath + "_" + variant;

            if (Prefs.DevMode)
            {
                Log.Message($"path: {path}");
            }
            // determine graphic class type
            System.Type type = null;
            if (contentHolder.Get(path + "_south") != null)
            {
                type = typeof(Graphic_Multi);
            }
            else if (contentHolder.Get(path) != null)
            {
                type = typeof(Graphic_Single);
            }

            if (type == null)
            {
                return(null);                // texture not found, skip graphic
            }
            var data = new GraphicData();

            data.CopyFrom(ageTracker.CurKindLifeStage.bodyGraphicData);
            data.texPath      = path;
            data.graphicClass = type;
            return(data.Graphic);
        }
예제 #2
0
        private static Graphic GhostGraphicFor(Graphic baseGraphic, ThingDef thingDef, Color ghostCol)
        {
            int num = 0;

            num = Gen.HashCombine <Graphic>(num, baseGraphic);
            num = Gen.HashCombine <ThingDef>(num, thingDef);
            num = Gen.HashCombineStruct <Color>(num, ghostCol);
            Graphic graphic;

            if (!GhostDrawer.ghostGraphics.TryGetValue(num, out graphic))
            {
                if (thingDef.graphicData.Linked || thingDef.IsDoor)
                {
                    graphic = GraphicDatabase.Get <Graphic_Single>(thingDef.uiIconPath, ShaderDatabase.Transparent, thingDef.graphicData.drawSize, ghostCol);
                }
                else
                {
                    if (baseGraphic == null)
                    {
                        baseGraphic = thingDef.graphic;
                    }
                    GraphicData graphicData = null;
                    if (baseGraphic.data != null && baseGraphic.ShadowGraphic != null)
                    {
                        graphicData = new GraphicData();
                        graphicData.CopyFrom(baseGraphic.data);
                        graphicData.shadowData = null;
                    }
                    graphic = GraphicDatabase.Get(baseGraphic.GetType(), baseGraphic.path, ShaderDatabase.Transparent, baseGraphic.drawSize, ghostCol, Color.white, graphicData);
                }
                GhostDrawer.ghostGraphics.Add(num, graphic);
            }
            return(graphic);
        }
예제 #3
0
        /// <summary> Set the movementGraphic based on the current life stage </summary>
        private Graphic LoadGraphic(string variant)
        {
            string path = ageTracker.CurKindLifeStage.bodyGraphicData.texPath + "_" + variant;

            // try getting the texture to see if it exists
            var texture = contentHolder.Get(path + "_south");

            if (texture == null)
            {
                return(null);
            }

            var data = new GraphicData();

            data.CopyFrom(ageTracker.CurKindLifeStage.bodyGraphicData);
            data.texPath = path;

            if (data.shadowData != null && variant == "moving")              // meerkat-specific shadow fix
            {
                var shadow = new ShadowData();
                shadow.volume   = data.shadowData.volume + new Vector3(0.15f, -0.15f, -0.1f);
                shadow.offset   = data.shadowData.offset + new Vector3(0.04f, 0, 0.18f);
                data.shadowData = shadow;
            }

            return(data.Graphic);
        }
예제 #4
0
        public static Graphic GhostGraphicFor(Graphic baseGraphic, ThingDef thingDef, Color ghostCol)
        {
            int seed = 0;

            seed = Gen.HashCombine(seed, baseGraphic);
            seed = Gen.HashCombine(seed, thingDef);
            seed = Gen.HashCombineStruct(seed, ghostCol);
            if (!ghostGraphics.TryGetValue(seed, out Graphic value))
            {
                if (thingDef.graphicData.Linked || thingDef.IsDoor)
                {
                    value = GraphicDatabase.Get <Graphic_Single>(thingDef.uiIconPath, ShaderTypeDefOf.EdgeDetect.Shader, thingDef.graphicData.drawSize, ghostCol);
                }
                else
                {
                    if (baseGraphic == null)
                    {
                        baseGraphic = thingDef.graphic;
                    }
                    GraphicData graphicData = null;
                    if (baseGraphic.data != null)
                    {
                        graphicData = new GraphicData();
                        graphicData.CopyFrom(baseGraphic.data);
                        graphicData.shadowData = null;
                    }
                    value = GraphicDatabase.Get(baseGraphic.GetType(), baseGraphic.path, ShaderTypeDefOf.EdgeDetect.Shader, baseGraphic.drawSize, ghostCol, Color.white, graphicData, null);
                }
                ghostGraphics.Add(seed, value);
            }
            return(value);
        }
예제 #5
0
 public GraphicRequest(Type graphicClass, string path, Shader shader, Vector2 drawSize, Color color, Color colorTwo, GraphicData graphicData, int renderQueue)
 {
     this.graphicClass = graphicClass;
     this.path         = path;
     this.shader       = shader;
     this.drawSize     = drawSize;
     this.color        = color;
     this.colorTwo     = colorTwo;
     this.graphicData  = graphicData;
     this.renderQueue  = renderQueue;
 }
예제 #6
0
 public GraphicRequest(Type graphicClass, string path, Shader shader, Vector2 drawSize, Color color, Color colorTwo, GraphicData graphicData, int renderQueue, List <ShaderParameter> shaderParameters)
 {
     this.graphicClass     = graphicClass;
     this.path             = path;
     this.shader           = shader;
     this.drawSize         = drawSize;
     this.color            = color;
     this.colorTwo         = colorTwo;
     this.graphicData      = graphicData;
     this.renderQueue      = renderQueue;
     this.shaderParameters = ((!shaderParameters.NullOrEmpty <ShaderParameter>()) ? shaderParameters : null);
 }
예제 #7
0
 public virtual Graphic GetShadowlessGraphic()
 {
     if (this.data != null && this.data.shadowData != null)
     {
         if (this.cachedShadowlessGraphicInt == null)
         {
             GraphicData graphicData = new GraphicData();
             graphicData.CopyFrom(this.data);
             graphicData.shadowData          = null;
             this.cachedShadowlessGraphicInt = graphicData.Graphic;
         }
         return(this.cachedShadowlessGraphicInt);
     }
     return(this);
 }
예제 #8
0
 public virtual Graphic GetShadowlessGraphic()
 {
     if (data == null || data.shadowData == null)
     {
         return(this);
     }
     if (cachedShadowlessGraphicInt == null)
     {
         GraphicData graphicData = new GraphicData();
         graphicData.CopyFrom(data);
         graphicData.shadowData     = null;
         cachedShadowlessGraphicInt = graphicData.Graphic;
     }
     return(cachedShadowlessGraphicInt);
 }
예제 #9
0
 public Graphic GetGraphic(Graphic other)
 {
     if (graphicData == null)
     {
         graphicData = new GraphicData();
     }
     graphicData.CopyFrom(other.data);
     if (!texPath.NullOrEmpty())
     {
         graphicData.texPath = texPath;
     }
     graphicData.color    = (color ?? other.color);
     graphicData.colorTwo = (colorTwo ?? other.colorTwo);
     return(graphicData.Graphic);
 }
 public void CopyFrom(GraphicData other)
 {
     this.texPath      = other.texPath;
     this.graphicClass = other.graphicClass;
     this.shaderType   = other.shaderType;
     this.color        = other.color;
     this.colorTwo     = other.colorTwo;
     this.drawSize     = other.drawSize;
     this.onGroundRandomRotateAngle = other.onGroundRandomRotateAngle;
     this.drawRotated       = other.drawRotated;
     this.allowFlip         = other.allowFlip;
     this.flipExtraRotation = other.flipExtraRotation;
     this.shadowData        = other.shadowData;
     this.damageData        = other.damageData;
     this.linkType          = other.linkType;
     this.linkFlags         = other.linkFlags;
 }
예제 #11
0
        public virtual Graphic GetShadowlessGraphic()
        {
            Graphic result;

            if (this.data == null || this.data.shadowData == null)
            {
                result = this;
            }
            else
            {
                if (this.cachedShadowlessGraphicInt == null)
                {
                    GraphicData graphicData = new GraphicData();
                    graphicData.CopyFrom(this.data);
                    graphicData.shadowData          = null;
                    this.cachedShadowlessGraphicInt = graphicData.Graphic;
                }
                result = this.cachedShadowlessGraphicInt;
            }
            return(result);
        }
예제 #12
0
 public void CopyFrom(GraphicData other)
 {
     texPath                   = other.texPath;
     graphicClass              = other.graphicClass;
     shaderType                = other.shaderType;
     color                     = other.color;
     colorTwo                  = other.colorTwo;
     drawSize                  = other.drawSize;
     drawOffset                = other.drawOffset;
     drawOffsetNorth           = other.drawOffsetNorth;
     drawOffsetEast            = other.drawOffsetEast;
     drawOffsetSouth           = other.drawOffsetSouth;
     drawOffsetWest            = other.drawOffsetSouth;
     onGroundRandomRotateAngle = other.onGroundRandomRotateAngle;
     drawRotated               = other.drawRotated;
     allowFlip                 = other.allowFlip;
     flipExtraRotation         = other.flipExtraRotation;
     shadowData                = other.shadowData;
     damageData                = other.damageData;
     linkType                  = other.linkType;
     linkFlags                 = other.linkFlags;
     cachedGraphic             = null;
 }
예제 #13
0
        public static Graphic Get(Type graphicClass, string path, Shader shader, Vector2 drawSize, Color color, Color colorTwo, GraphicData data, List <ShaderParameter> shaderParameters)
        {
            GraphicRequest graphicRequest = new GraphicRequest(graphicClass, path, shader, drawSize, color, colorTwo, data, 0, shaderParameters);

            if (graphicRequest.graphicClass == typeof(Graphic_Single))
            {
                return(GetInner <Graphic_Single>(graphicRequest));
            }
            if (graphicRequest.graphicClass == typeof(Graphic_Terrain))
            {
                return(GetInner <Graphic_Terrain>(graphicRequest));
            }
            if (graphicRequest.graphicClass == typeof(Graphic_Multi))
            {
                return(GetInner <Graphic_Multi>(graphicRequest));
            }
            if (graphicRequest.graphicClass == typeof(Graphic_Mote))
            {
                return(GetInner <Graphic_Mote>(graphicRequest));
            }
            if (graphicRequest.graphicClass == typeof(Graphic_Random))
            {
                return(GetInner <Graphic_Random>(graphicRequest));
            }
            if (graphicRequest.graphicClass == typeof(Graphic_Flicker))
            {
                return(GetInner <Graphic_Flicker>(graphicRequest));
            }
            if (graphicRequest.graphicClass == typeof(Graphic_Appearances))
            {
                return(GetInner <Graphic_Appearances>(graphicRequest));
            }
            if (graphicRequest.graphicClass == typeof(Graphic_StackCount))
            {
                return(GetInner <Graphic_StackCount>(graphicRequest));
            }
            try
            {
                return((Graphic)GenGeneric.InvokeStaticGenericMethod(typeof(GraphicDatabase), graphicRequest.graphicClass, "GetInner", graphicRequest));
            }
            catch (Exception ex)
            {
                Log.Error("Exception getting " + graphicClass + " at " + path + ": " + ex.ToString());
            }
            return(BaseContent.BadGraphic);
        }
예제 #14
0
 public static Graphic Get <T>(string path, Shader shader, Vector2 drawSize, Color color, Color colorTwo, GraphicData data) where T : Graphic, new()
 {
     return(GetInner <T>(new GraphicRequest(typeof(T), path, shader, drawSize, color, colorTwo, data, 0, null)));
 }
        public static Graphic Get(Type graphicClass, string path, Shader shader, Vector2 drawSize, Color color, Color colorTwo, GraphicData data, List <ShaderParameter> shaderParameters)
        {
            GraphicRequest graphicRequest = new GraphicRequest(graphicClass, path, shader, drawSize, color, colorTwo, data, 0, shaderParameters);
            Graphic        result;

            if (graphicRequest.graphicClass == typeof(Graphic_Single))
            {
                result = GraphicDatabase.GetInner <Graphic_Single>(graphicRequest);
            }
            else if (graphicRequest.graphicClass == typeof(Graphic_Terrain))
            {
                result = GraphicDatabase.GetInner <Graphic_Terrain>(graphicRequest);
            }
            else if (graphicRequest.graphicClass == typeof(Graphic_Multi))
            {
                result = GraphicDatabase.GetInner <Graphic_Multi>(graphicRequest);
            }
            else if (graphicRequest.graphicClass == typeof(Graphic_Mote))
            {
                result = GraphicDatabase.GetInner <Graphic_Mote>(graphicRequest);
            }
            else if (graphicRequest.graphicClass == typeof(Graphic_Random))
            {
                result = GraphicDatabase.GetInner <Graphic_Random>(graphicRequest);
            }
            else if (graphicRequest.graphicClass == typeof(Graphic_Flicker))
            {
                result = GraphicDatabase.GetInner <Graphic_Flicker>(graphicRequest);
            }
            else if (graphicRequest.graphicClass == typeof(Graphic_Appearances))
            {
                result = GraphicDatabase.GetInner <Graphic_Appearances>(graphicRequest);
            }
            else if (graphicRequest.graphicClass == typeof(Graphic_StackCount))
            {
                result = GraphicDatabase.GetInner <Graphic_StackCount>(graphicRequest);
            }
            else
            {
                try
                {
                    return((Graphic)GenGeneric.InvokeStaticGenericMethod(typeof(GraphicDatabase), graphicRequest.graphicClass, "GetInner", new object[]
                    {
                        graphicRequest
                    }));
                }
                catch (Exception ex)
                {
                    Log.Error(string.Concat(new object[]
                    {
                        "Exception getting ",
                        graphicClass,
                        " at ",
                        path,
                        ": ",
                        ex.ToString()
                    }), false);
                }
                result = BaseContent.BadGraphic;
            }
            return(result);
        }
예제 #16
0
        public static Graphic Get <T>(string path, Shader shader, Vector2 drawSize, Color color, Color colorTwo, GraphicData data) where T : Graphic, new()
        {
            GraphicRequest req = new GraphicRequest(typeof(T), path, shader, drawSize, color, colorTwo, data, 0);

            return((Graphic)(object)GraphicDatabase.GetInner <T>(req));
        }