예제 #1
0
        public static Gizmo ReservedGizmoFor(Thing thing)
        {
            Pawn sampleColonist = thing.Map?.mapPawns?.FreeColonists?.FirstOrDefault();

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

            Pawn reserver = thing.Map?.reservationManager?.FirstRespectedReserver(thing, sampleColonist);

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

            Command_CenterOnTarget gizmo = new Command_CenterOnTarget()
            {
                defaultLabel = "TD.Reserved".Translate()
                               //defaultLabel = reserver.NameStringShort
            };

            if (PurposeInfo.Make(thing) is PurposeInfo info)
            {
                gizmo.selectedInfo = info;
            }
            PurposeInfo.AddTargetToGizmo(gizmo, reserver);

            return(gizmo);              //first is leftmost
        }
예제 #2
0
        public static Gizmo PurposeGizmoFor(Pawn gizmoPawn)
        {
            if (!ShouldDrawGizmoFor(gizmoPawn))
            {
                return(null);
            }

            Command_CenterOnTarget gizmo = new Command_CenterOnTarget(gizmoPawn);

            if (PurposeInfo.Make(gizmoPawn) is PurposeInfo info)
            {
                gizmo.selectedInfo = info;
            }
            if (gizmoPawn.CurJob != null)
            {
                gizmo.defaultLabel = gizmoPawn.jobs.curDriver.GetReport().Split(' ').FirstOrDefault();
                gizmo.defaultLabel.TrimEnd('.');
                PurposeInfo.AddTargetToGizmo(gizmo, gizmoPawn.CurJob.GetTarget(TargetIndex.A), TargetIndex.A);
                PurposeInfo.AddTargetToGizmo(gizmo, gizmoPawn.CurJob.GetTarget(TargetIndex.B), TargetIndex.B);
                PurposeInfo.AddTargetToGizmo(gizmo, gizmoPawn.CurJob.GetTarget(TargetIndex.C), TargetIndex.C);
            }
            else
            {
                gizmo.defaultLabel = "ActivityIconIdle".Translate();
            }

            return(gizmo);
        }
예제 #3
0
        private bool DoButton(PurposeInfo purposeInfo, Rect rect, float scale = 1.0f)
        {
            if (!purposeInfo.IsUsed())
            {
                return(false);
            }

            Texture icon = purposeInfo.icon;

            if (icon == null)
            {
                return(false);
            }

            if (Mouse.IsOver(rect))
            {
                GUI.color = GenUI.MouseoverColor;
            }
            else
            {
                GUI.color = purposeInfo.color;
            }
            Verse.Sound.MouseoverSounds.DoRegion(rect, SoundDefOf.Mouseover_Command);
            //GUI.DrawTexture(rect, Command.BGTex);
            Widgets.DrawTextureFitted(rect, icon, scale * purposeInfo.scale, purposeInfo.proportions, purposeInfo.texCoords);

            if (Widgets.ButtonInvisible(rect, false) || Mouse.IsOver(rect) && Input.GetMouseButton(0))
            {
                clickedPos = purposeInfo.pos;
                return(true);
            }

            return(false);
        }
예제 #4
0
	public void SetTarget(TargetIndex ind, PurposeInfo info)
	{
	  switch (ind)
	  {
		case TargetIndex.A: targetA = info; break;
		case TargetIndex.B: targetB = info; break;
		case TargetIndex.C: targetC = info; break;
	  }
	}
예제 #5
0
	public static void AddTargetToGizmo(Command_CenterOnTarget gizmo, LocalTargetInfo targetInfo, TargetIndex ind = TargetIndex.A)
	{
	  PurposeInfo purposeInfo = Make(targetInfo);
	  if (purposeInfo == null) return;
	  if (targetInfo.HasThing && purposeInfo.pos == null)
		purposeInfo.pos = gizmo.selectedInfo.pos;
	  if (purposeInfo.IsUsed())
	  {
		gizmo.SetTarget(ind, purposeInfo);
	  }
	}
예제 #6
0
        public static PurposeInfo Make(LocalTargetInfo targetInfo)
        {
            //reports of nullrefs in here for somereason.
            try
            {
                PurposeInfo purposeInfo = new PurposeInfo();
                if (targetInfo.IsValid)
                {
                    purposeInfo.pos = targetInfo.CenterVector3;
                }
                if (targetInfo.Thing is Thing target)
                {
                    target = MinifyUtility.GetInnerIfMinified(target);
                    BuildableDef def = target.def;

                    purposeInfo.pos   = target.DrawPos;
                    purposeInfo.color = target.DrawColor;

                    if (target is Pawn || target is Corpse)
                    {
                        Pawn pawn = target as Pawn;
                        if (pawn == null)
                        {
                            pawn = ((Corpse)target).InnerPawn;
                        }
                        if (!pawn.RaceProps.Humanlike)
                        {
                            //This seems unnecessary
                            //if (!pawn.Drawer.renderer.graphics.AllResolved)
                            //{
                            //	pawn.Drawer.renderer.graphics.ResolveAllGraphics();
                            //}
                            Material matSingle = pawn.Drawer.renderer.graphics.nakedGraphic.MatSingle;
                            purposeInfo.icon  = matSingle.mainTexture;
                            purposeInfo.color = matSingle.color;
                        }
                        else
                        {
                            purposeInfo.icon = PortraitsCache.Get(pawn, Vector2.one * Gizmo.Height, Rot4.South, cameraZoom: 1.5f);
                        }
                        purposeInfo.proportions = new Vector2(purposeInfo.icon.width, purposeInfo.icon.height);
                    }
                    else
                    {
                        if (target is IConstructible buildThing)
                        {
                            def = target.def.entityDefToBuild;
                            if (buildThing.EntityToBuildStuff() != null)
                            {
                                purposeInfo.color = buildThing.EntityToBuildStuff().stuffProps.color;
                            }
                            else
                            {
                                purposeInfo.color = def.uiIconColor;
                            }
                        }

                        purposeInfo.icon = def.uiIcon;

                        if (def is ThingDef td)
                        {
                            purposeInfo.proportions = td.graphicData.drawSize;
                            purposeInfo.scale       = GenUI.IconDrawScale(td);
                        }

                        if (def is TerrainDef)
                        {
                            //private static readonly Vector2 TerrainTextureCroppedSize = new Vector2(64f, 64f);
                            purposeInfo.texCoords = new Rect(0f, 0f, 64f / purposeInfo.icon.width, 64f / purposeInfo.icon.height);
                        }
                        else if (def.uiIconPath.NullOrEmpty())
                        {
                            Material iconMat = def.graphic.MatSingle;
                            purposeInfo.texCoords = new Rect(iconMat.mainTextureOffset, iconMat.mainTextureScale);
                        }
                    }
                }
                return(purposeInfo);
            }
            catch (NullReferenceException)
            {
                return(null);
            }
        }