コード例 #1
0
        // Verse.AI.ToilEffects
        public static CaravanToil WithProgressBar(this CaravanToil CaravanToil, TargetIndex ind,
                                                  Func <float> progressGetter, bool interpolateBetweenActorAndTarget = false, float offsetZ = -0.5f)
        {
            WorldObject_ProgressBar progressBar = null;

            CaravanToil.AddPreTickAction(delegate
            {
                if (CaravanToil.actor.Faction != Faction.OfPlayer)
                {
                    return;
                }
                var curProgress = Mathf.Clamp01(progressGetter());
                //Log.Message(curProgress.ToString());
                //WorldProgressBarDrawer.DrawProgressBarOnGUIFor(target, curProgress);
                if (progressBar == null)
                {
                    progressBar =
                        (WorldObject_ProgressBar)WorldObjectMaker.MakeWorldObject(
                            DefDatabase <WorldObjectDef> .GetNamed("WorldObject_ProgressBar"));
                    progressBar.Tile = Find.World.GetComponent <CaravanJobGiver>().CurJob(CaravanToil.actor)
                                       .GetTarget(ind).Tile;
                    progressBar.offset = offsetZ;
                    Find.WorldObjects.Add(progressBar);
                }
                else
                {
                    progressBar.curProgress = Mathf.Clamp01(progressGetter());
                    if (CaravanToil.actor == null || !CaravanToil.actor.Spawned ||
                        CaravanToil.actor.Tile != Find.World.GetComponent <CaravanJobGiver>().CurJob(CaravanToil.actor)
                        .GetTarget(ind).Tile)
                    {
                        if (progressBar.Spawned)
                        {
                            Find.WorldObjects.Remove(progressBar);
                        }
                    }
                }
            });
            CaravanToil.AddFinishAction(delegate
            {
                if (progressBar != null && progressBar.Spawned)
                {
                    Find.WorldObjects.Remove(progressBar);
                    progressBar = null;
                }
            });
            return(CaravanToil);
        }
コード例 #2
0
        //public override Vector3 DrawPos
        //{
        //    get
        //    {
        //        float d = 0.15f * Find.WorldGrid.averageTileSize;
        //        Rand.PushState();
        //        Rand.Seed = this.ID;
        //        float f = Rand.Range(0f, 360f);
        //        Rand.PopState();
        //        Vector2 point = new Vector2(Mathf.Cos(f), Mathf.Sin(f)) * d;
        //        return WorldRendererUtility.ProjectOnQuadTangentialToPlanet(Find.WorldGrid.GetTileCenter(this.Tile), point);
        //    }
        //}


        public override void Draw()
        {
            if (curProgress < 0)
            {
                base.Draw();
            }
            else
            {
                float   averageTileSize = Find.WorldGrid.averageTileSize;
                float   totalSize       = 0.7f * averageTileSize;
                float   curSize         = totalSize * curProgress;
                Vector3 curPos          = this.DrawPos;
                //Log.ErrorOnce("CurPos: " + curPos.x + " " + curPos.y + " " + curPos.z, 12368123);
                curPos += new Vector3(0, 0, offset); //Progress bar offset
                //Log.ErrorOnce("NextCurPos: " + curPos.x + " " + curPos.y + " " + curPos.z, 12368124);
                WorldObject_ProgressBar.DrawShrinkableQuadTangentialToPlanet(curPos, curSize, totalSize, 1f, 0.3f, 0.035f, FilledMat, false, false, null);
                WorldObject_ProgressBar.DrawShrinkableQuadTangentialToPlanet(curPos, totalSize, totalSize, 1f, 0.3f, 0.033f, UnfilledMat, false, false, null);
            }
        }