示例#1
0
        private void DrawColonistMouseAttachment(int index, Vector2 dragStartPos, int entryGroup)
        {
            Pawn    pawn   = null;
            Vector2 vector = default(Vector2);
            int     num    = 0;

            for (int i = 0; i < cachedEntries.Count; i++)
            {
                Entry entry = cachedEntries[i];
                if (entry.group == entryGroup)
                {
                    Entry entry2 = cachedEntries[i];
                    if (entry2.pawn != null)
                    {
                        if (num == index)
                        {
                            Entry entry3 = cachedEntries[i];
                            pawn   = entry3.pawn;
                            vector = cachedDrawLocs[i];
                            break;
                        }
                        num++;
                    }
                }
            }
            if (pawn != null)
            {
                RenderTexture renderTexture   = PortraitsCache.Get(pawn, ColonistBarColonistDrawer.PawnTextureSize, ColonistBarColonistDrawer.PawnTextureCameraOffset, 1.28205f);
                float         x               = vector.x;
                float         y               = vector.y;
                Vector2       size            = Size;
                float         x2              = size.x;
                Vector2       size2           = Size;
                Rect          rect            = new Rect(x, y, x2, size2.y);
                Rect          pawnTextureRect = drawer.GetPawnTextureRect(rect.position);
                pawnTextureRect.position += Event.current.mousePosition - dragStartPos;
                RenderTexture iconTex    = renderTexture;
                Rect?         customRect = pawnTextureRect;
                GenUI.DrawMouseAttachment(iconTex, string.Empty, 0f, default(Vector2), customRect);
            }
        }
        public void OnGUI(LocalTargetInfo target)
        {
            Texture2D icon = (!target.IsValid) ? TexCommand.CannotShoot : parent.def.uiIcon;

            GenUI.DrawMouseAttachment(icon);
        }
示例#3
0
 public void WorldRoutePlannerOnGUI()
 {
     if (this.active)
     {
         if (KeyBindingDefOf.Cancel.KeyDownEvent)
         {
             if (this.currentFormCaravanDialog != null)
             {
                 Find.WindowStack.Add(this.currentFormCaravanDialog);
             }
             else
             {
                 SoundDefOf.Tick_Low.PlayOneShotOnCamera(null);
             }
             this.Stop();
             Event.current.Use();
         }
         else
         {
             GenUI.DrawMouseAttachment(WorldRoutePlanner.MouseAttachment);
             if (Event.current.type == EventType.MouseDown && Event.current.button == 1)
             {
                 Caravan caravan = Find.WorldSelector.SelectableObjectsUnderMouse().FirstOrDefault <WorldObject>() as Caravan;
                 int     tile    = (caravan == null) ? GenWorld.MouseTile(true) : caravan.Tile;
                 if (tile >= 0)
                 {
                     RoutePlannerWaypoint waypoint = this.MostRecentWaypointAt(tile);
                     if (waypoint != null)
                     {
                         if (waypoint == this.waypoints[this.waypoints.Count - 1])
                         {
                             this.TryRemoveWaypoint(waypoint, true);
                         }
                         else
                         {
                             List <FloatMenuOption> list = new List <FloatMenuOption>();
                             list.Add(new FloatMenuOption("AddWaypoint".Translate(), delegate()
                             {
                                 this.TryAddWaypoint(tile, true);
                             }, MenuOptionPriority.Default, null, null, 0f, null, null));
                             list.Add(new FloatMenuOption("RemoveWaypoint".Translate(), delegate()
                             {
                                 this.TryRemoveWaypoint(waypoint, true);
                             }, MenuOptionPriority.Default, null, null, 0f, null, null));
                             Find.WindowStack.Add(new FloatMenu(list));
                         }
                     }
                     else
                     {
                         this.TryAddWaypoint(tile, true);
                     }
                     Event.current.Use();
                 }
             }
             this.DoRouteDetailsBox();
             if (!this.DoChooseRouteButton())
             {
                 this.DoTileTooltips();
             }
         }
     }
 }
示例#4
0
 public override void TargeterOnGUI()
 {
     GenUI.DrawMouseAttachment(mouseAttachment ?? CompLaunchable.TargeterMouseAttachment);
 }
示例#5
0
 public override void DrawMouseAttachments()
 {
     base.DrawMouseAttachments();
     GenUI.DrawMouseAttachment(icon, MainMod.SelectedPriority.ToString(), iconAngle, iconOffset, null);
 }
示例#6
0
        public bool BuildingDesignatorControl()
        {
            if (Find.CurrentMap == null || Find.DesignatorManager == null)
            {
                return(true);
            }
            var Dem = Find.DesignatorManager.SelectedDesignator;

            if (Dem != null && Dem is Designator_Build)
            {
                if (Event.current.type == EventType.MouseDown && Event.current.button == 2)
                {
                    //Better than UI.mousecell
                    MiddleClickCell = Find.CameraDriver.MapPosition;
                }

                //Middle click to select designator
                if (Event.current.type == EventType.MouseUp && Event.current.button == 2 && MiddleClickCell == Find.CameraDriver.MapPosition)
                {
                    Thing   targetThing = null;
                    IntVec3 UICell      = UI.MouseCell();
                    Map     map         = Find.CurrentMap;
                    if (map == null)
                    {
                        return(false);
                    }
                    if (!UICell.InBounds(map))
                    {
                        return(false);
                    }

                    //Search for blueprints
                    if (targetThing == null)
                    {
                        targetThing = UICell.GetFirstThing <Blueprint>(map);
                    }

                    //Search for frames
                    if (targetThing == null)
                    {
                        targetThing = UICell.GetFirstThing <Frame>(map);
                    }

                    //Search for Buildings
                    if (targetThing == null)
                    {
                        targetThing = UICell.GetFirstBuilding(map);
                    }

                    //Can't find things
                    if (targetThing == null)
                    {
                        //SoundDefOf.ClickReject.PlayOneShotOnCamera();
                        Event.current.Use();
                        return(false);
                    }

                    //Find designator
                    Designator_Build Desig = null;
                    Desig = BuildCopyCommandUtility.FindAllowedDesignator(targetThing.def);

                    if (Desig == null && (targetThing is Blueprint || targetThing is Frame))
                    {
                        Desig = BuildCopyCommandUtility.FindAllowedDesignator(targetThing.def.entityDefToBuild);
                    }

                    if ((targetThing.def.BuildableByPlayer || targetThing.def.entityDefToBuild?.BuildableByPlayer == true) && Desig != null)
                    {
                        //Set stuff

                        if (targetThing.Stuff != null)
                        {
                            Desig.SetStuffDef(targetThing.Stuff);
                        }
                        if ((targetThing as Blueprint_Build)?.stuffToUse != null)
                        {
                            Desig.SetStuffDef((targetThing as Blueprint_Build).stuffToUse);
                        }
                        if ((targetThing as Blueprint_Install)?.Stuff != null)
                        {
                            Desig.SetStuffDef((targetThing as Blueprint_Install).Stuff);
                        }
                        if ((targetThing as Frame)?.Stuff != null)
                        {
                            Desig.SetStuffDef((targetThing as Frame).Stuff);
                        }

                        Find.DesignatorManager.Select(Desig);
                        SoundDefOf.Click.PlayOneShotOnCamera();
                    }
                    else
                    {
                        //SoundDefOf.ClickReject.PlayOneShotOnCamera();
                    }

                    Event.current.Use();
                    return(false);
                }

                //Cancel drag

                //First, absorb Right click event, handle it manually
                if (Event.current.type == EventType.MouseDown && Event.current.button == 1)
                {
                    Event.current.Use();
                }

                if (IsCancelDragging)
                {
                    GenUI.DrawMouseAttachment(CancelIcon, string.Empty, 0);
                }
                if (Input.GetMouseButton(1))
                {
                    if (IsCancelDragging)
                    {
                        //RenderCancelHighlights();
                    }
                    else
                    {
                        //Start cancel dragging

                        IsCancelDragging = true;
                        DragStart        = UI.MouseCell();
                        SoundDefOf.Click.PlayOneShotOnCamera(null);
                    }
                }

                //Right click up
                else if (Event.current.type == EventType.MouseUp && Event.current.button == 1)
                {
                    IsCancelDragging = false;
                    selectedThings.Clear();
                    Event.current.Use();

                    if (selectedThings.Any())
                    {
                        selectedThings.Do(delegate(Thing t) { t.Destroy(DestroyMode.Cancel); });
                        SoundDefOf.Designate_Cancel.PlayOneShotOnCamera();
                    }
                    else
                    {
                        SoundDefOf.CancelMode.PlayOneShotOnCamera(null);
                        Find.DesignatorManager.Deselect();
                        return(false);
                    }
                }

                //While cancel dragging, left click to abort
                if (Event.current.type == EventType.MouseDown && Event.current.button == 0 && IsCancelDragging)
                {
                    selectedThings.Clear();
                    IsCancelDragging = false;
                    SoundDefOf.CancelMode.PlayOneShotOnCamera(null);
                    Find.DesignatorManager.Deselect();
                    Event.current.Use();
                    return(false);
                }

                //Drag to place blueprints

                var BuildDesignator = (Designator_Build)Dem;

                if (BuildDesignator.DraggableDimensions != 0)
                {
                    return(true);
                }

                if (Event.current.type == EventType.MouseDown && Event.current.button == 0)
                {
                    PreviousCell = IntVec3.Invalid;
                    ClickedFlag  = true;
                    Event.current.Use();
                }
                if (Event.current.type == EventType.MouseUp && Event.current.button == 0)
                {
                    PreviousCell = IntVec3.Invalid;
                    ClickedFlag  = false;
                    Event.current.Use();
                }

                if (Input.GetMouseButton(0) && !Mouse.IsInputBlockedNow && PreviousCell != UI.MouseCell() && ClickedFlag)
                {
                    var acceptanceReport = BuildDesignator.CanDesignateCell(UI.MouseCell());

                    if (DebugSettings.godMode && acceptanceReport.Accepted) //Handle god mode
                    {
                        Traverse     t        = Traverse.Create(BuildDesignator);
                        BuildableDef entDef   = t.Field("entDef").GetValue <BuildableDef>();
                        Rot4         rot      = t.Field("placingRot").GetValue <Rot4>();
                        CellRect     cellRect = GenAdj.OccupiedRect(UI.MouseCell(), rot, entDef.Size);
                        foreach (IntVec3 c in cellRect)
                        {
                            var thinglist = c.GetThingList(Find.CurrentMap);
                            for (int i = 0; i < thinglist.Count; i++)
                            {
                                var thing3 = thinglist[i];
                                if (!GenConstruct.CanPlaceBlueprintOver(entDef, thing3.def))
                                {
                                    acceptanceReport = new AcceptanceReport("SpaceAlreadyOccupied_DevFail");
                                }
                            }
                        }
                    }
                    if (acceptanceReport.Accepted)
                    {
                        BuildDesignator.DesignateSingleCell(UI.MouseCell());
                        BuildDesignator.Finalize(true);
                    }
                    else
                    {
                        //If this is first cell clicked
                        if (PreviousCell == IntVec3.Invalid)
                        {
                            Messages.Message(acceptanceReport.Reason, MessageTypeDefOf.SilentInput, false);
                            BuildDesignator.Finalize(false);
                        }
                    }

                    PreviousCell = UI.MouseCell();
                    //Event.current.Use();
                }
                return(false);
            }
            else //This is not Building designator
            {
                IsCancelDragging = false;
                return(true);
            }
        }
示例#7
0
 public void WorldRoutePlannerOnGUI()
 {
     if (active)
     {
         if (KeyBindingDefOf.Cancel.KeyDownEvent)
         {
             if (currentFormCaravanDialog != null)
             {
                 Find.WindowStack.Add(currentFormCaravanDialog);
             }
             else
             {
                 SoundDefOf.Tick_Low.PlayOneShotOnCamera();
             }
             Stop();
             Event.current.Use();
         }
         else
         {
             GenUI.DrawMouseAttachment(MouseAttachment);
             if (Event.current.type == EventType.MouseDown && Event.current.button == 1)
             {
                 int tile = (Find.WorldSelector.SelectableObjectsUnderMouse().FirstOrDefault() as Caravan)?.Tile ?? GenWorld.MouseTile(snapToExpandableWorldObjects: true);
                 if (tile >= 0)
                 {
                     RoutePlannerWaypoint waypoint = MostRecentWaypointAt(tile);
                     if (waypoint != null)
                     {
                         if (waypoint == waypoints[waypoints.Count - 1])
                         {
                             TryRemoveWaypoint(waypoint);
                         }
                         else
                         {
                             List <FloatMenuOption> list = new List <FloatMenuOption>();
                             list.Add(new FloatMenuOption("AddWaypoint".Translate(), delegate
                             {
                                 TryAddWaypoint(tile);
                             }));
                             list.Add(new FloatMenuOption("RemoveWaypoint".Translate(), delegate
                             {
                                 TryRemoveWaypoint(waypoint);
                             }));
                             Find.WindowStack.Add(new FloatMenu(list));
                         }
                     }
                     else
                     {
                         TryAddWaypoint(tile);
                     }
                     Event.current.Use();
                 }
             }
             DoRouteDetailsBox();
             if (!DoChooseRouteButton())
             {
                 DoTileTooltips();
             }
         }
     }
 }
示例#8
0
 public void WorldRoutePlannerOnGUI()
 {
     if (this.active)
     {
         if (Event.current.type == EventType.KeyDown && Event.current.keyCode == KeyCode.Escape)
         {
             if (this.currentFormCaravanDialog != null)
             {
                 Find.WindowStack.Add(this.currentFormCaravanDialog);
             }
             else
             {
                 SoundDefOf.TickLow.PlayOneShotOnCamera(null);
             }
             this.Stop();
             Event.current.Use();
         }
         else
         {
             GenUI.DrawMouseAttachment(WorldRoutePlanner.MouseAttachment);
             if (Event.current.type == EventType.MouseDown && Event.current.button == 1)
             {
                 Caravan caravan = Find.WorldSelector.SelectableObjectsUnderMouse().FirstOrDefault() as Caravan;
                 int     tile    = (caravan == null) ? GenWorld.MouseTile(true) : caravan.Tile;
                 if (tile >= 0)
                 {
                     RoutePlannerWaypoint waypoint = this.MostRecentWaypointAt(tile);
                     if (waypoint != null)
                     {
                         if (waypoint == this.waypoints[this.waypoints.Count - 1])
                         {
                             this.TryRemoveWaypoint(waypoint, true);
                         }
                         else
                         {
                             List <FloatMenuOption> list = new List <FloatMenuOption>();
                             list.Add(new FloatMenuOption("AddWaypoint".Translate(), delegate
                             {
                                 this.TryAddWaypoint(tile, true);
                             }, MenuOptionPriority.Default, null, null, 0f, null, null));
                             list.Add(new FloatMenuOption("RemoveWaypoint".Translate(), delegate
                             {
                                 this.TryRemoveWaypoint(waypoint, true);
                             }, MenuOptionPriority.Default, null, null, 0f, null, null));
                             Find.WindowStack.Add(new FloatMenu(list));
                         }
                     }
                     else
                     {
                         this.TryAddWaypoint(tile, true);
                     }
                     Event.current.Use();
                 }
             }
             float   num = (float)UI.screenWidth;
             Vector2 bottomWindowSize = WorldRoutePlanner.BottomWindowSize;
             double  x    = (num - bottomWindowSize.x) / 2.0;
             float   num2 = (float)UI.screenHeight;
             Vector2 bottomWindowSize2 = WorldRoutePlanner.BottomWindowSize;
             double  y = num2 - bottomWindowSize2.y - 45.0;
             Vector2 bottomWindowSize3 = WorldRoutePlanner.BottomWindowSize;
             float   x2 = bottomWindowSize3.x;
             Vector2 bottomWindowSize4 = WorldRoutePlanner.BottomWindowSize;
             Rect    rect = new Rect((float)x, (float)y, x2, bottomWindowSize4.y);
             if (Current.ProgramState == ProgramState.Entry)
             {
                 rect.y -= 22f;
             }
             Find.WindowStack.ImmediateWindow(1373514241, rect, WindowLayer.Dialog, delegate
             {
                 if (this.active)
                 {
                     GUI.color   = Color.white;
                     Text.Anchor = TextAnchor.UpperCenter;
                     Text.Font   = GameFont.Small;
                     float num3  = 6f;
                     if (this.waypoints.Count >= 2)
                     {
                         Widgets.Label(new Rect(0f, num3, rect.width, 25f), "RoutePlannerEstTimeToFinalDest".Translate(this.GetTicksToWaypoint(this.waypoints.Count - 1).ToStringTicksToDays("0.#")));
                     }
                     else if (this.cantRemoveFirstWaypoint)
                     {
                         Widgets.Label(new Rect(0f, num3, rect.width, 25f), "RoutePlannerAddOneOrMoreWaypoints".Translate());
                     }
                     else
                     {
                         Widgets.Label(new Rect(0f, num3, rect.width, 25f), "RoutePlannerAddTwoOrMoreWaypoints".Translate());
                     }
                     num3 = (float)(num3 + 20.0);
                     if (this.CaravanPawns.NullOrEmpty())
                     {
                         GUI.color = new Color(0.8f, 0.6f, 0.6f);
                         Widgets.Label(new Rect(0f, num3, rect.width, 25f), "RoutePlannerUsingAverageTicksPerMoveWarning".Translate());
                     }
                     else if (this.currentFormCaravanDialog == null && this.CaravanAtTheFirstWaypoint != null)
                     {
                         GUI.color = Color.gray;
                         Widgets.Label(new Rect(0f, num3, rect.width, 25f), "RoutePlannerUsingTicksPerMoveOfCaravan".Translate(this.CaravanAtTheFirstWaypoint.LabelCap));
                     }
                     num3      = (float)(num3 + 20.0);
                     GUI.color = Color.gray;
                     Widgets.Label(new Rect(0f, num3, rect.width, 25f), "RoutePlannerPressRMBToAddAndRemoveWaypoints".Translate());
                     num3 = (float)(num3 + 20.0);
                     if (this.currentFormCaravanDialog != null)
                     {
                         Widgets.Label(new Rect(0f, num3, rect.width, 25f), "RoutePlannerPressEscapeToReturnToCaravanFormationDialog".Translate());
                     }
                     else
                     {
                         Widgets.Label(new Rect(0f, num3, rect.width, 25f), "RoutePlannerPressEscapeToExit".Translate());
                     }
                     num3        = (float)(num3 + 20.0);
                     GUI.color   = Color.white;
                     Text.Anchor = TextAnchor.UpperLeft;
                 }
             }, true, false, 1f);
         }
     }
 }
示例#9
0
        public virtual void OnGUI(LocalTargetInfo target)
        {
            Texture2D icon = (!target.IsValid) ? TexCommand.CannotShoot : ((!(this.UIIcon != BaseContent.BadTex)) ? TexCommand.Attack : this.UIIcon);

            GenUI.DrawMouseAttachment(icon);
        }
示例#10
0
 public override void TargeterOnGUI()
 {
     DoExtraGuiControls();
     GenUI.DrawMouseAttachment(mouseAttachment ?? CompLaunchable.TargeterMouseAttachment);
 }