Ejemplo n.º 1
0
        protected void displayInspectActions()
        {
            //Since InspectGizmoGrid is internal(you gotta love that vanilla codebase...) lets redo the entire code for the inspect toolbar
            List <Gizmo>  gizmoList       = new List <Gizmo>();
            List <object> selectedObjects = Find.Selector.SelectedObjectsListForReading;

            if (selectedObjects.NullOrEmpty())
            {
                return;
            }
            for (int i = 0; i < selectedObjects.Count; i++)
            {
                ISelectable selectable = selectedObjects[i] as ISelectable;
                if (selectable != null)
                {
                    foreach (Gizmo current in selectable.GetGizmos())
                    {
                        gizmoList.Add(current);
                    }
                }
            }
            for (int j = 0; j < selectedObjects.Count; j++)
            {
                Thing t = selectedObjects[j] as Thing;
                if (t != null)
                {
                    IEnumerable <Designator> allDesignators = Find.ReverseDesignatorDatabase.AllDesignators.Concat(designatorDebugDestroy);
                    foreach (Designator des in allDesignators)
                    {
                        if (des.CanDesignateThing(t).Accepted)
                        {
                            Command_Action command_Action = new Command_Action();
                            command_Action.defaultLabel = des.LabelCapReverseDesignating(t);
                            float   iconAngle;
                            Vector2 iconOffset;
                            command_Action.icon        = des.IconReverseDesignating(t, out iconAngle, out iconOffset);
                            command_Action.iconAngle   = iconAngle;
                            command_Action.iconOffset  = iconOffset;
                            command_Action.defaultDesc = des.DescReverseDesignating(t);
                            command_Action.action      = delegate
                            {
                                if (!TutorSystem.AllowAction(des.TutorTagDesignate))
                                {
                                    return;
                                }
                                des.DesignateThing(t);
                                des.Finalize(true);
                            };
                            command_Action.hotKey   = des.hotKey;
                            command_Action.groupKey = des.groupKey;
                            gizmoList.Add(command_Action);
                        }
                    }
                }
            }

            Gizmo mouseoverGizmo;

            GizmoGridDrawer.DrawGizmoGrid(gizmoList, 20f + windowRect.width, out mouseoverGizmo);
        }
Ejemplo n.º 2
0
        public override void ProcessInput(Event ev)
        {
            base.ProcessInput(ev);
            List <FloatMenuOption> list = new List <FloatMenuOption>();

            if (settables == null)
            {
                settables = new List <IPlantToGrowSettable>();
            }
            if (!settables.Contains(settable))
            {
                settables.Add(settable);
            }
            tmpAvailablePlants.Clear();
            foreach (ThingDef item in PlantUtility.ValidPlantTypesForGrowers(settables))
            {
                if (IsPlantAvailable(item, settable.Map))
                {
                    tmpAvailablePlants.Add(item);
                }
            }
            tmpAvailablePlants.SortBy((ThingDef x) => 0f - GetPlantListPriority(x), (ThingDef x) => x.label);
            for (int i = 0; i < tmpAvailablePlants.Count; i++)
            {
                ThingDef plantDef = tmpAvailablePlants[i];
                string   text     = plantDef.LabelCap;
                if (plantDef.plant.sowMinSkill > 0)
                {
                    text = text + (string)(" (" + "MinSkill".Translate() + ": ") + plantDef.plant.sowMinSkill + ")";
                }
                list.Add(new FloatMenuOption(text, delegate
                {
                    string s = tutorTag + "-" + plantDef.defName;
                    if (TutorSystem.AllowAction(s))
                    {
                        bool flag = true;
                        for (int j = 0; j < settables.Count; j++)
                        {
                            settables[j].SetPlantDefToGrow(plantDef);
                            if (flag && plantDef.plant.interferesWithRoof)
                            {
                                foreach (IntVec3 cell in settables[j].Cells)
                                {
                                    if (cell.Roofed(settables[j].Map))
                                    {
                                        Messages.Message("MessagePlantIncompatibleWithRoof".Translate(Find.ActiveLanguageWorker.Pluralize(plantDef.LabelCap)), MessageTypeDefOf.CautionInput, historical: false);
                                        flag = false;
                                        break;
                                    }
                                }
                            }
                        }
                        PlayerKnowledgeDatabase.KnowledgeDemonstrated(ConceptDefOf.SetGrowingZonePlant, KnowledgeAmount.Total);
                        WarnAsAppropriate(plantDef);
                        TutorSystem.Notify_Event(s);
                    }
                }, plantDef, MenuOptionPriority.Default, null, null, 29f, (Rect rect) => Widgets.InfoCardButton(rect.x + 5f, rect.y + (rect.height - 24f) / 2f, plantDef)));
            }
            Find.WindowStack.Add(new FloatMenu(list));
        }
Ejemplo n.º 3
0
            internal void <> m__0()
            {
                string s = this.$this.tutorTag + "-" + this.plantDef.defName;

                if (TutorSystem.AllowAction(s))
                {
                    bool flag = true;
                    for (int i = 0; i < this.$this.settables.Count; i++)
                    {
                        this.$this.settables[i].SetPlantDefToGrow(this.plantDef);
                        if (flag && this.plantDef.plant.interferesWithRoof)
                        {
                            foreach (IntVec3 c in this.$this.settables[i].Cells)
                            {
                                if (c.Roofed(this.$this.settables[i].Map))
                                {
                                    Messages.Message("MessagePlantIncompatibleWithRoof".Translate(new object[]
                                    {
                                        Find.ActiveLanguageWorker.Pluralize(this.plantDef.LabelCap, -1)
                                    }), MessageTypeDefOf.CautionInput, false);
                                    flag = false;
                                    break;
                                }
                            }
                        }
                    }
                    PlayerKnowledgeDatabase.KnowledgeDemonstrated(ConceptDefOf.SetGrowingZonePlant, KnowledgeAmount.Total);
                    this.$this.WarnAsAppropriate(this.plantDef);
                    TutorSystem.Notify_Event(s);
                }
            }
Ejemplo n.º 4
0
 public virtual void DesignateMultiCell(IEnumerable <IntVec3> cells)
 {
     if (!TutorSystem.TutorialMode || TutorSystem.AllowAction(new EventPack(TutorTagDesignate, cells)))
     {
         bool somethingSucceeded = false;
         bool flag = false;
         foreach (IntVec3 cell in cells)
         {
             if (CanDesignateCell(cell).Accepted)
             {
                 DesignateSingleCell(cell);
                 somethingSucceeded = true;
                 if (!flag)
                 {
                     flag = ShowWarningForCell(cell);
                 }
             }
         }
         Finalize(somethingSucceeded);
         if (TutorSystem.TutorialMode)
         {
             TutorSystem.Notify_Event(new EventPack(TutorTagDesignate, cells));
         }
     }
 }
        private void RandomizeCurPawn()
        {
            if (!TutorSystem.AllowAction("RandomizePawn"))
            {
                return;
            }
            int num = 0;

            while (true)
            {
                this.curPawn = StartingPawnUtility.RandomizeInPlace(this.curPawn);
                num++;
                if (num > 15)
                {
                    break;
                }
                if (StartingPawnUtility.WorkTypeRequirementsSatisfied())
                {
                    goto Block_3;
                }
            }
            return;

Block_3:
            TutorSystem.Notify_Event("RandomizePawn");
        }
Ejemplo n.º 6
0
        public virtual void DesignateMultiCell(IEnumerable <IntVec3> cells)
        {
            if (TutorSystem.TutorialMode && !TutorSystem.AllowAction(new EventPack(this.TutorTagDesignate, cells)))
            {
                return;
            }
            bool somethingSucceeded = false;
            bool flag = false;

            foreach (IntVec3 current in cells)
            {
                if (this.CanDesignateCell(current).Accepted)
                {
                    this.DesignateSingleCell(current);
                    somethingSucceeded = true;
                    if (!flag)
                    {
                        flag = this.ShowWarningForCell(current);
                    }
                }
            }
            this.Finalize(somethingSucceeded);
            if (TutorSystem.TutorialMode)
            {
                TutorSystem.Notify_Event(new EventPack(this.TutorTagDesignate, cells));
            }
        }
Ejemplo n.º 7
0
        protected override bool CanDoNext()
        {
            if (!base.CanDoNext())
            {
                return(false);
            }
            int selectedTile = Find.WorldInterface.SelectedTile;

            if (selectedTile < 0)
            {
                Messages.Message("MustSelectLandingSite".Translate(), MessageSound.RejectInput);
                return(false);
            }
            StringBuilder stringBuilder = new StringBuilder();

            if (!TileFinder.IsValidTileForNewSettlement(selectedTile, stringBuilder))
            {
                Messages.Message(stringBuilder.ToString(), MessageSound.RejectInput);
                return(false);
            }
            Tile item = Find.WorldGrid[selectedTile];

            if (!TutorSystem.AllowAction(string.Concat("ChooseBiome-", item.biome.defName, "-", item.hilliness.ToString())))
            {
                return(false);
            }
            return(true);
        }
Ejemplo n.º 8
0
        public GizmoResult DoGUI_Logic(bool mouseIsOver, bool commandIsTriggered)
        {
            if (commandIsTriggered)
            {
                if (gizmo.disabled)
                {
                    if (!gizmo.disabledReason.NullOrEmpty())
                    {
                        Messages.Message(gizmo.disabledReason, MessageTypeDefOf.RejectInput);
                    }
                    return(new GizmoResult(GizmoState.Mouseover, null));
                }
                if (!TutorSystem.AllowAction(gizmo.TutorTagSelect))
                {
                    return(new GizmoResult(GizmoState.Mouseover, null));
                }
                TutorSystem.Notify_Event(gizmo.TutorTagSelect);
                return(new GizmoResult(GizmoState.Interacted, Event.current));
            }

            if (mouseIsOver)
            {
                return(new GizmoResult(GizmoState.Mouseover, null));
            }

            return(new GizmoResult(GizmoState.Clear, null));
        }
Ejemplo n.º 9
0
 protected bool CheckCanInteract()
 {
     if (TutorSystem.TutorialMode && !TutorSystem.AllowAction(TutorTagSelect))
     {
         return(false);
     }
     return(true);
 }
Ejemplo n.º 10
0
        private static void InterfaceToggleTab(InspectTabBase tab, IInspectPane pane)
        {
            if (TutorSystem.TutorialMode && !IsOpen(tab, pane) &&
                !TutorSystem.AllowAction("ITab-" + tab.tutorTag + "-Open"))
            {
                return;
            }

            ToggleTab(tab, pane);
        }
 private void RandomizeCurPawn()
 {
     if (!TutorSystem.AllowAction("RandomizePawn"))
     {
         return;
     }
     do
     {
         this.curPawn = StartingPawnUtility.RandomizeInPlace(this.curPawn);
     }while (!StartingPawnUtility.WorkTypeRequirementsSatisfied());
     TutorSystem.Notify_Event("RandomizePawn");
 }
Ejemplo n.º 12
0
        public override void ProcessInput(Event ev)
        {
            base.ProcessInput(ev);
            List <FloatMenuOption> list = new List <FloatMenuOption>();

            if (this.settables == null)
            {
                this.settables = new List <IPlantToGrowSettable>();
            }
            if (!this.settables.Contains(this.settable))
            {
                this.settables.Add(this.settable);
            }
            foreach (ThingDef current in GenPlant.ValidPlantTypesForGrowers(this.settables))
            {
                if (this.IsPlantAvailable(current))
                {
                    ThingDef localPlantDef = current;
                    string   text          = current.LabelCap;
                    if (current.plant.sowMinSkill > 0)
                    {
                        string text2 = text;
                        text = string.Concat(new object[]
                        {
                            text2,
                            " (",
                            "MinSkill".Translate(),
                            ": ",
                            current.plant.sowMinSkill,
                            ")"
                        });
                    }
                    list.Add(new FloatMenuOption(text, delegate
                    {
                        string s = this.tutorTag + "-" + localPlantDef.defName;
                        if (!TutorSystem.AllowAction(s))
                        {
                            return;
                        }
                        for (int i = 0; i < this.settables.Count; i++)
                        {
                            this.settables[i].SetPlantDefToGrow(localPlantDef);
                        }
                        PlayerKnowledgeDatabase.KnowledgeDemonstrated(ConceptDefOf.SetGrowingZonePlant, KnowledgeAmount.Total);
                        this.WarnAsAppropriate(localPlantDef);
                        TutorSystem.Notify_Event(s);
                    }, MenuOptionPriority.Default, null, null, 29f, (Rect rect) => Widgets.InfoCardButton(rect.x + 5f, rect.y + (rect.height - 24f) / 2f, localPlantDef), null));
                }
            }
            Find.WindowStack.Add(new FloatMenu(list));
        }
        public override void ProcessInput(Event ev)
        {
            base.ProcessInput(ev);
            List <FloatMenuOption> list = new List <FloatMenuOption>();

            if (this.settables == null)
            {
                this.settables = new List <IPrisonerToSacrificeSettable>();
            }
            if (!this.settables.Contains(this.settable))
            {
                this.settables.Add(this.settable);
            }
            Map map = Find.VisibleMap;

            foreach (Pawn current in map.mapPawns.PrisonersOfColonySpawned)
            {
                if (!current.Dead)
                {
                    string text = current.LabelCap;
                    List <FloatMenuOption> arg_121_0      = list;
                    Func <Rect, bool>      extraPartOnGUI = (Rect rect) => Widgets.InfoCardButton(rect.x + 5f, rect.y + (rect.height - 24f) / 2f, localPlantDef);
                    arg_121_0.Add(new FloatMenuOption(text, delegate
                    {
                        string s = this.tutorTag + "-" + localPlantDef.defName;
                        if (!TutorSystem.AllowAction(s))
                        {
                            return;
                        }
                        for (int i = 0; i < this.settables.Count; i++)
                        {
                            this.settables[i].SetPlantDefToGrow(localPlantDef);
                        }
                        PlayerKnowledgeDatabase.KnowledgeDemonstrated(ConceptDefOf.SetGrowingZonePlant, KnowledgeAmount.Total);
                        this.WarnAsAppropriate(localPlantDef);
                        TutorSystem.Notify_Event(s);
                    }, MenuOptionPriority.Default, null, null, 29f, extraPartOnGUI, null));
                }
            }
            Find.WindowStack.Add(new FloatMenu(list));
        }
        public override GizmoResult GizmoOnGUI(Vector2 topLeft, float maxWidth)
        {
            Text.Font = GameFont.Tiny;
            Rect rect = new Rect(topLeft.x, topLeft.y, GetWidth(maxWidth), GizmoSize);
            bool flag = false;

            Rect      gizmoRect = new Rect(rect.x + 3.5f, rect.y, rect.width / 2, rect.height).ContractedBy(7);
            Texture2D badTex    = icon;

            if (badTex == null)
            {
                badTex = BaseContent.BadTex;
            }
            var gizmoColor  = GUI.color;
            var ammoColor   = GUI.color;
            var reloadColor = GUI.color;


            Material material = (!disabled) ? null : TexUI.GrayscaleGUI;

            GenUI.DrawTextureWithMaterial(rect, AmmoBG, material, default);
            Rect ammoRect   = new Rect(gizmoRect.x + gizmoRect.width + 7, gizmoRect.y, gizmoRect.width, (gizmoRect.height / 2) - 3.5f);
            Rect reloadRect = new Rect(gizmoRect.x + gizmoRect.width + 7, ammoRect.y + ammoRect.height + 7, gizmoRect.width, (gizmoRect.height / 2) - 3.5f);

            MouseoverSounds.DoRegion(gizmoRect, SoundDefOf.Mouseover_Command);
            MouseoverSounds.DoRegion(ammoRect, SoundDefOf.Mouseover_Command);
            MouseoverSounds.DoRegion(reloadRect, SoundDefOf.Mouseover_Command);

            if (Mouse.IsOver(gizmoRect))
            {
                flag = true;
                if (!disabled)
                {
                    GUI.color = GenUI.MouseoverColor;
                }
            }
            GenUI.DrawTextureWithMaterial(gizmoRect, BGTex, material, default);
            GUI.color = gizmoColor;
            if (cannon.cannonDef.ammoAllowed?.Any() ?? false)
            {
                if (Mouse.IsOver(ammoRect))
                {
                    flag = true;
                    if (!disabled)
                    {
                        GUI.color = GenUI.MouseoverColor;
                    }
                }
                GenUI.DrawTextureWithMaterial(ammoRect, BGTex, material, default);
                GUI.color = ammoColor;
                if (Mouse.IsOver(reloadRect))
                {
                    flag = true;
                    if (!disabled)
                    {
                        GUI.color = GenUI.MouseoverColor;
                    }
                }
                GenUI.DrawTextureWithMaterial(reloadRect, BGTex, material, default);
                GUI.color = reloadColor;
                Rect reloadLabel = new Rect(reloadRect.x + 10, reloadRect.y + reloadRect.height / 4, reloadRect.width - 10, reloadRect.height / 1.5f);
                Widgets.Label(reloadLabel, "Extract".Translate());
            }
            GUI.color = IconDrawColor;
            Widgets.DrawTextureFitted(gizmoRect, badTex, iconDrawScale * 0.85f, iconProportions, iconTexCoords, iconAngle, material);
            GUI.color = Color.white;
            bool    flag2   = false;
            bool    flag3   = false;
            bool    flag4   = false;
            KeyCode keyCode = (hotKey != null) ? hotKey.MainKey : KeyCode.None;

            if (keyCode != KeyCode.None && !GizmoGridDrawer.drawnHotKeys.Contains(keyCode))
            {
                Rect rect2 = new Rect(rect.x + 5f, rect.y + 5f, rect.width - 10f, 18f);
                Widgets.Label(rect2, keyCode.ToStringReadable());
                GizmoGridDrawer.drawnHotKeys.Add(keyCode);
                if (hotKey.KeyDownEvent)
                {
                    flag2 = true;
                    Event.current.Use();
                }
            }
            if (Widgets.ButtonInvisible(gizmoRect, false))
            {
                flag2 = true;
            }
            if (Widgets.ButtonInvisible(ammoRect, false))
            {
                flag3 = true;
            }
            if (Widgets.ButtonInvisible(reloadRect, false))
            {
                flag4 = false;
            }
            string labelCap = LabelCap;

            if (!labelCap.NullOrEmpty())
            {
                float num   = Text.CalcHeight(labelCap, rect.width);
                Rect  rect3 = new Rect(rect.x, rect.yMax - num + 12f, rect.width, num);
                GUI.DrawTexture(rect3, TexUI.GrayTextBG);
                GUI.color   = Color.white;
                Text.Anchor = TextAnchor.UpperCenter;
                Widgets.Label(rect3, labelCap);
                Text.Anchor = TextAnchor.UpperLeft;
                GUI.color   = Color.white;
            }
            GUI.color = Color.white;
            if (DoTooltip)
            {
                TipSignal tip = Desc;
                if (disabled && !disabledReason.NullOrEmpty())
                {
                    string text = tip.text;
                    tip.text = string.Concat(new string[]
                    {
                        text,
                        "\n\n",
                        "DisabledCommand".Translate(),
                        ": ",
                        disabledReason
                    });
                }
                TooltipHandler.TipRegion(gizmoRect, tip);
            }
            if (cannon.cooldownTicks > 0)
            {
                float percent = cannon.cooldownTicks / (float)cannon.MaxTicks;
                SPExtra.VerticalFillableBar(gizmoRect, percent, FillableBar, ClearBar);
            }
            if (!HighlightTag.NullOrEmpty() && (Find.WindowStack.FloatMenu == null || !Find.WindowStack.FloatMenu.windowRect.Overlaps(gizmoRect)))
            {
                UIHighlighter.HighlightOpportunity(gizmoRect, HighlightTag);
            }
            Text.Font = GameFont.Small;
            if (flag2)
            {
                if (disabled)
                {
                    if (!disabledReason.NullOrEmpty())
                    {
                        Messages.Message(disabledReason, MessageTypeDefOf.RejectInput, false);
                    }
                    return(new GizmoResult(GizmoState.Mouseover, null));
                }
                if (!TutorSystem.AllowAction(TutorTagSelect))
                {
                    return(new GizmoResult(GizmoState.Mouseover, null));
                }
                var result = new GizmoResult(GizmoState.Interacted, Event.current);
                TutorSystem.Notify_Event(TutorTagSelect);
                return(result);
            }
            if (flag3)
            {
                //Change later
                cannon.ReloadCannon(cannon.pawn.inventory.innerContainer.FirstOrDefault(x => cannon.cannonDef.ammoAllowed.Contains(x.def)).def);
            }
            if (flag4)
            {
                cannon.TryRemoveShell();
            }
            if (flag)
            {
                return(new GizmoResult(GizmoState.Mouseover, null));
            }
            return(new GizmoResult(GizmoState.Clear, null));
        }
Ejemplo n.º 15
0
        public override GizmoResult GizmoOnGUI(Vector2 topLeft, float maxWidth)
        {
            Rect rect = new Rect(topLeft.x, topLeft.y, this.GetWidth(maxWidth), 75f);
            bool flag = false;

            if (Mouse.IsOver(rect))
            {
                flag      = true;
                GUI.color = GenUI.MouseoverColor;
            }
            Texture2D badTex = LockUtility.GetData(parent).WantedState.locked ? lockTexture : unlockTexture;

            if (badTex == null)
            {
                badTex = BaseContent.BadTex;
            }
            GUI.DrawTexture(rect, BGTex);
            GUI.DrawTexture(rect, badTex);
            MouseoverSounds.DoRegion(rect, SoundDefOf.Mouseover_Command);
            bool    flag2   = false;
            KeyCode keyCode = (this.hotKey != null) ? hotKey.MainKey : KeyCode.None;

            if (keyCode != KeyCode.None && !GizmoGridDrawer.drawnHotKeys.Contains(keyCode))
            {
                Rect rect2 = new Rect(rect.x + 5f, rect.y + 5f, rect.width - 10f, 18f);
                Widgets.Label(rect2, keyCode.ToStringReadable());
                GizmoGridDrawer.drawnHotKeys.Add(keyCode);
                if (hotKey.KeyDownEvent)
                {
                    flag2 = true;
                    Event.current.Use();
                }
            }
            if (Widgets.ButtonInvisible(rect, false))
            {
                flag2 = true;
            }
            string labelCap = LabelCap;

            if (!labelCap.NullOrEmpty())
            {
                float num   = Text.CalcHeight(labelCap, rect.width);
                Rect  rect3 = new Rect(rect.x, rect.yMax - num + 12f, rect.width, num);
                GUI.DrawTexture(rect3, TexUI.GrayTextBG);
                GUI.color   = Color.white;
                Text.Anchor = TextAnchor.UpperCenter;
                Widgets.Label(rect3, labelCap);
                Text.Anchor = TextAnchor.UpperLeft;
                GUI.color   = Color.white;
            }
            GUI.color = Color.white;
            if (DoTooltip)
            {
                TipSignal tip = Desc;
                if (disabled && !disabledReason.NullOrEmpty())
                {
                    string text = tip.text;
                    tip.text = string.Concat(new string[]
                    {
                        text,
                        "\n\n",
                        "DisabledCommand".Translate(),
                        ": ",
                        disabledReason
                    });
                }
                TooltipHandler.TipRegion(rect, tip);
            }
            if (!HighlightTag.NullOrEmpty() && (Find.WindowStack.FloatMenu == null || !Find.WindowStack.FloatMenu.windowRect.Overlaps(rect)))
            {
                UIHighlighter.HighlightOpportunity(rect, HighlightTag);
            }
            if (flag2)
            {
                if (disabled)
                {
                    if (!disabledReason.NullOrEmpty())
                    {
                        Messages.Message(disabledReason, MessageTypeDefOf.RejectInput);
                    }
                    return(new GizmoResult(GizmoState.Mouseover, null));
                }
                if (!TutorSystem.AllowAction(TutorTagSelect))
                {
                    return(new GizmoResult(GizmoState.Mouseover, null));
                }
                GizmoResult result = new GizmoResult(GizmoState.Interacted, Event.current);
                TutorSystem.Notify_Event(TutorTagSelect);
                return(result);
            }
            else
            {
                if (flag)
                {
                    return(new GizmoResult(GizmoState.Mouseover, null));
                }
                return(new GizmoResult(GizmoState.Clear, null));
            }
        }
        public virtual bool DoGUI(Rect rect, bool colonistOrdering, FloatMenu floatMenu)
        {
            Rect rect2 = rect;

            rect2.height--;
            bool flag  = !Disabled && Mouse.IsOver(rect2);
            bool flag2 = false;

            Text.Font = CurrentFont;
            Rect rect3 = rect;

            rect3.xMin += 4f;
            rect3.xMax  = rect.x + 27f;
            rect3.yMin += 4f;
            rect3.yMax  = rect.y + 27f;
            if (flag)
            {
                rect3.x += 4f;
            }
            Rect rect4 = rect;

            rect4.xMin += HorizontalMargin;
            rect4.xMax -= HorizontalMargin;
            rect4.xMax -= 4f;
            rect4.xMax -= extraPartWidth + IconOffset;
            rect4.x    += IconOffset;
            if (flag)
            {
                rect4.x += 4f;
            }
            Rect rect5 = default(Rect);

            if (extraPartWidth != 0f)
            {
                float num = Mathf.Min(Text.CalcSize(Label).x, rect4.width - 4f);
                rect5 = new Rect(rect4.xMin + num, rect4.yMin, extraPartWidth, 30f);
                flag2 = Mouse.IsOver(rect5);
            }
            if (!Disabled)
            {
                MouseoverSounds.DoRegion(rect2);
            }
            Color color = GUI.color;

            if (Disabled)
            {
                GUI.color = ColorBGDisabled * color;
            }
            else if (flag && !flag2)
            {
                GUI.color = ColorBGActiveMouseover * color;
            }
            else
            {
                GUI.color = ColorBGActive * color;
            }
            GUI.DrawTexture(rect, BaseContent.WhiteTex);
            GUI.color = ((!Disabled) ? ColorTextActive : ColorTextDisabled) * color;
            if (sizeMode == FloatMenuSizeMode.Tiny)
            {
                rect4.y += 1f;
            }
            Widgets.DrawAtlas(rect, TexUI.FloatMenuOptionBG);
            Text.Anchor = TextAnchor.MiddleLeft;
            Widgets.Label(rect4, Label);
            Text.Anchor = TextAnchor.UpperLeft;
            GUI.color   = iconColor;
            if (shownItem != null || drawPlaceHolderIcon)
            {
                Widgets.DefIcon(rect3, shownItem, null, 1f, drawPlaceHolderIcon);
            }
            else if ((bool)itemIcon)
            {
                GUI.DrawTexture(rect3, itemIcon);
            }
            GUI.color = color;
            if (extraPartOnGUI != null)
            {
                bool num2 = extraPartOnGUI(rect5);
                GUI.color = color;
                if (num2)
                {
                    return(true);
                }
            }
            if (flag && mouseoverGuiAction != null)
            {
                mouseoverGuiAction();
            }
            if (tutorTag != null)
            {
                UIHighlighter.HighlightOpportunity(rect, tutorTag);
            }
            if (Widgets.ButtonInvisible(rect2))
            {
                if (tutorTag != null && !TutorSystem.AllowAction(tutorTag))
                {
                    return(false);
                }
                Chosen(colonistOrdering, floatMenu);
                if (tutorTag != null)
                {
                    TutorSystem.Notify_Event(tutorTag);
                }
                return(true);
            }
            return(false);
        }
Ejemplo n.º 17
0
        public override GizmoResult GizmoOnGUI(Vector2 topLeft)
        {
            Rect rect = new Rect(topLeft.x, topLeft.y, this.Width, 75f);
            bool flag = false;

            if (Mouse.IsOver(rect))
            {
                flag      = true;
                GUI.color = GenUI.MouseoverColor;
            }
            Texture2D badTex = this.icon;

            if (badTex == null)
            {
                badTex = BaseContent.BadTex;
            }

            GUI.DrawTexture(rect, Command.BGTex);
            MouseoverSounds.DoRegion(rect, SoundDefOf.MouseoverCommand);
            GUI.color = this.IconDrawColor;
            Widgets.DrawTextureFitted(new Rect(rect), badTex, this.iconDrawScale * 0.85f, this.iconProportions, this.iconTexCoords);
            GUI.color = Color.white;
            bool flag2   = false;
            Rect rectFil = new Rect(topLeft.x, topLeft.y, this.Width, this.Width);

            KeyCode keyCode = (this.hotKey != null) ? this.hotKey.MainKey : KeyCode.None;

            if (keyCode != KeyCode.None && !GizmoGridDrawer.drawnHotKeys.Contains(keyCode))
            {
                Rect rect2 = new Rect(rect.x + 5f, rect.y + 5f, rect.width - 10f, 18f);
                Widgets.Label(rect2, keyCode.ToStringReadable());
                GizmoGridDrawer.drawnHotKeys.Add(keyCode);
                if (this.hotKey.KeyDownEvent)
                {
                    flag2 = true;
                    Event.current.Use();
                }
            }
            if (Widgets.ButtonInvisible(rect, false))
            {
                flag2 = true;
            }
            string labelCap = this.LabelCap;

            if (!labelCap.NullOrEmpty())
            {
                float num = Text.CalcHeight(labelCap, rect.width);
                num -= 2f;
                Rect rect3 = new Rect(rect.x, rect.yMax - num + 12f, rect.width, num);
                GUI.DrawTexture(rect3, TexUI.GrayTextBG);
                GUI.color   = Color.white;
                Text.Anchor = TextAnchor.UpperCenter;
                Widgets.Label(rect3, labelCap);
                Text.Anchor = TextAnchor.UpperLeft;
                GUI.color   = Color.white;
            }
            GUI.color = Color.white;
            if (this.DoTooltip)
            {
                TipSignal tip = this.Desc;
                if (this.disabled && !this.disabledReason.NullOrEmpty())
                {
                    tip.text = tip.text + "\n\nDISABLED: " + this.disabledReason;
                }
                TooltipHandler.TipRegion(rect, tip);
            }
            if (!this.HighlightTag.NullOrEmpty() && (Find.WindowStack.FloatMenu == null || !Find.WindowStack.FloatMenu.windowRect.Overlaps(rect)))
            {
                UIHighlighter.HighlightOpportunity(rect, this.HighlightTag);
            }
            float x    = compPsyker.TicksToCast;
            float y    = compPsyker.TicksToCastMax;
            float fill = x / y;

            Widgets.FillableBar(rect, fill, FullTex, EmptyTex, false);
            if (flag2)
            {
                if (this.disabled)
                {
                    if (!this.disabledReason.NullOrEmpty())
                    {
                        Messages.Message(this.disabledReason, MessageSound.RejectInput);
                    }
                    return(new GizmoResult(GizmoState.Mouseover, null));
                }
                if (!TutorSystem.AllowAction(this.TutorTagSelect))
                {
                    return(new GizmoResult(GizmoState.Mouseover, null));
                }
                GizmoResult result = new GizmoResult(GizmoState.Interacted, Event.current);
                TutorSystem.Notify_Event(this.TutorTagSelect);
                return(result);
            }
            else
            {
                if (flag)
                {
                    return(new GizmoResult(GizmoState.Mouseover, null));
                }
                return(new GizmoResult(GizmoState.Clear, null));
            }
        }
        //public override bool GroupsWith(Gizmo other)
        //{
        //    if (other is Command_PawnAbility p && p.pawnAbility.Def.abilityClass == this.pawnAbility.Def.abilityClass)
        //        return true;
        //    return false;
        //}

        public override GizmoResult GizmoOnGUI(Vector2 topLeft, float maxWidth)
        {
            var rect        = new Rect(topLeft.x, topLeft.y, this.GetWidth(maxWidth), 75f);
            var isMouseOver = false;

            if (Mouse.IsOver(rect))
            {
                isMouseOver = true;
                GUI.color   = GenUI.MouseoverColor;
            }
            var badTex = icon;

            if (badTex == null)
            {
                badTex = BaseContent.BadTex;
            }

            GUI.DrawTexture(rect, BGTex);
            MouseoverSounds.DoRegion(rect, SoundDefOf.Mouseover_Command);
            GUI.color = IconDrawColor;
            Widgets.DrawTextureFitted(new Rect(rect), badTex, iconDrawScale * 0.85f, iconProportions, iconTexCoords);
            GUI.color = Color.white;
            var isUsed = false;
            //Rect rectFil = new Rect(topLeft.x, topLeft.y, this.Width, this.Width);

            var keyCode = hotKey != null ? hotKey.MainKey : KeyCode.None;

            if (keyCode != KeyCode.None && !GizmoGridDrawer.drawnHotKeys.Contains(keyCode))
            {
                var rect2 = new Rect(rect.x + 5f, rect.y + 5f, rect.width - 10f, 18f);
                Widgets.Label(rect2, keyCode.ToStringReadable());
                GizmoGridDrawer.drawnHotKeys.Add(keyCode);
                if (hotKey.KeyDownEvent)
                {
                    isUsed = true;
                    Event.current.Use();
                }
            }
            if (Widgets.ButtonInvisible(rect, false))
            {
                isUsed = true;
            }
            var labelCap = LabelCap;

            if (!labelCap.NullOrEmpty())
            {
                var num = Text.CalcHeight(labelCap, rect.width);
                num -= 2f;
                var rect3 = new Rect(rect.x, rect.yMax - num + 12f, rect.width, num);
                GUI.DrawTexture(rect3, TexUI.GrayTextBG);
                GUI.color   = Color.white;
                Text.Anchor = TextAnchor.UpperCenter;
                Widgets.Label(rect3, labelCap);
                Text.Anchor = TextAnchor.UpperLeft;
                GUI.color   = Color.white;
            }
            GUI.color = Color.white;
            if (DoTooltip)
            {
                TipSignal tip = Desc;
                if (disabled && !disabledReason.NullOrEmpty())
                {
                    tip.text = tip.text + "\n" + StringsToTranslate.AU_DISABLED + ": " + disabledReason;
                }
                TooltipHandler.TipRegion(rect, tip);
            }
            if (pawnAbility.CooldownTicksLeft != -1 && pawnAbility.CooldownTicksLeft < pawnAbility.MaxCastingTicks)
            {
                var math = curTicks / (float)pawnAbility.MaxCastingTicks;
                Widgets.FillableBar(rect, math, AbilityButtons.FullTex, AbilityButtons.EmptyTex, false);
            }
            if (!HighlightTag.NullOrEmpty() && (Find.WindowStack.FloatMenu == null ||
                                                !Find.WindowStack.FloatMenu.windowRect.Overlaps(rect)))
            {
                UIHighlighter.HighlightOpportunity(rect, HighlightTag);
            }
            if (isUsed)
            {
                if (disabled)
                {
                    if (!disabledReason.NullOrEmpty())
                    {
                        Messages.Message(disabledReason, MessageTypeDefOf.RejectInput);
                    }
                    return(new GizmoResult(GizmoState.Mouseover, null));
                }
                if (!TutorSystem.AllowAction(TutorTagSelect))
                {
                    return(new GizmoResult(GizmoState.Mouseover, null));
                }
                var result = new GizmoResult(GizmoState.Interacted, Event.current);
                TutorSystem.Notify_Event(TutorTagSelect);
                return(result);
            }
            if (isMouseOver)
            {
                return(new GizmoResult(GizmoState.Mouseover, null));
            }
            return(new GizmoResult(GizmoState.Clear, null));
        }
Ejemplo n.º 19
0
        // copy paste from Command.GizmoOnGUI
        public override GizmoResult GizmoOnGUI(Vector2 topLeft, float maxWidth)
        {
            Text.Font = GameFont.Tiny;
            Rect rect = new Rect(topLeft.x, topLeft.y, GetWidth(maxWidth), 75f);
            bool flag = false;

            if (Mouse.IsOver(rect))
            {
                flag = true;
                if (!disabled)
                {
                    GUI.color = GenUI.MouseoverColor;
                }
            }

            Material material = (!disabled) ? null : TexUI.GrayscaleGUI;

            GenUI.DrawTextureWithMaterial(rect, BGTex, material);
            MouseoverSounds.DoRegion(rect, SoundDefOf.Mouseover_Command);
            // BEGIN EDIT
            GUI.color = IconDrawColor;
            DrawToolbarIcon(rect);
            // END EDIT
            GUI.color = UnityEngine.Color.white;
            bool    flag2   = false;
            KeyCode keyCode = (hotKey != null) ? hotKey.MainKey : KeyCode.None;

            if (keyCode != 0 && !GizmoGridDrawer.drawnHotKeys.Contains(keyCode))
            {
                Rect rect2 = new Rect(rect.x + 5f, rect.y + 5f, rect.width - 10f, 18f);
                Widgets.Label(rect2, keyCode.ToStringReadable());
                GizmoGridDrawer.drawnHotKeys.Add(keyCode);
                if (hotKey.KeyDownEvent)
                {
                    flag2 = true;
                    Event.current.Use();
                }
            }
            if (Widgets.ButtonInvisible(rect))
            {
                flag2 = true;
            }
            string labelCap = LabelCap;

            if (!labelCap.NullOrEmpty())
            {
                float num   = Text.CalcHeight(labelCap, rect.width);
                Rect  rect3 = new Rect(rect.x, rect.yMax - num + 12f, rect.width, num);
                GUI.DrawTexture(rect3, TexUI.GrayTextBG);
                GUI.color   = UnityEngine.Color.white;
                Text.Anchor = TextAnchor.UpperCenter;
                Widgets.Label(rect3, labelCap);
                Text.Anchor = TextAnchor.UpperLeft;
                GUI.color   = UnityEngine.Color.white;
            }
            GUI.color = UnityEngine.Color.white;
            if (DoTooltip)
            {
                TipSignal tip = Desc;
                if (disabled && !disabledReason.NullOrEmpty())
                {
                    string text = tip.text;
                    tip.text = text + "\n\n" + "DisabledCommand".Translate() + ": " + disabledReason;
                }
                TooltipHandler.TipRegion(rect, tip);
            }
            if (!HighlightTag.NullOrEmpty() && (Find.WindowStack.FloatMenu == null || !Find.WindowStack.FloatMenu.windowRect.Overlaps(rect)))
            {
                UIHighlighter.HighlightOpportunity(rect, HighlightTag);
            }
            Text.Font = GameFont.Small;
            if (flag2)
            {
                if (disabled)
                {
                    if (!disabledReason.NullOrEmpty())
                    {
                        Messages.Message(disabledReason, MessageTypeDefOf.RejectInput, false);
                    }
                    return(new GizmoResult(GizmoState.Mouseover, null));
                }
                GizmoResult result;
                if (Event.current.button == 1)
                {
                    result = new GizmoResult(GizmoState.OpenedFloatMenu, Event.current);
                }
                else
                {
                    if (!TutorSystem.AllowAction(TutorTagSelect))
                    {
                        return(new GizmoResult(GizmoState.Mouseover, null));
                    }
                    result = new GizmoResult(GizmoState.Interacted, Event.current);
                    TutorSystem.Notify_Event(TutorTagSelect);
                }
                return(result);
            }
            if (flag)
            {
                return(new GizmoResult(GizmoState.Mouseover, null));
            }
            return(new GizmoResult(GizmoState.Clear, null));
        }
Ejemplo n.º 20
0
 protected bool CheckCanInteract()
 {
     return(!TutorSystem.TutorialMode || TutorSystem.AllowAction(this.TutorTagSelect));
 }
Ejemplo n.º 21
0
        public override void ProcessInput(Event ev)
        {
            base.ProcessInput(ev);
            List <FloatMenuOption> list = new List <FloatMenuOption>();

            if (this.settables == null)
            {
                this.settables = new List <IPlantToGrowSettable>();
            }
            if (!this.settables.Contains(this.settable))
            {
                this.settables.Add(this.settable);
            }
            Command_SetPlantToGrow.tmpAvailablePlants.Clear();
            foreach (ThingDef current in PlantUtility.ValidPlantTypesForGrowers(this.settables))
            {
                if (this.IsPlantAvailable(current, this.settable.Map))
                {
                    Command_SetPlantToGrow.tmpAvailablePlants.Add(current);
                }
            }
            Command_SetPlantToGrow.tmpAvailablePlants.SortBy((ThingDef x) => - this.GetPlantListPriority(x), (ThingDef x) => x.label);
            for (int i = 0; i < Command_SetPlantToGrow.tmpAvailablePlants.Count; i++)
            {
                ThingDef plantDef = Command_SetPlantToGrow.tmpAvailablePlants[i];
                string   text     = plantDef.LabelCap;
                if (plantDef.plant.sowMinSkill > 0)
                {
                    string text2 = text;
                    text = string.Concat(new object[]
                    {
                        text2,
                        " (",
                        "MinSkill".Translate(),
                        ": ",
                        plantDef.plant.sowMinSkill,
                        ")"
                    });
                }
                list.Add(new FloatMenuOption(text, delegate
                {
                    string s = this.tutorTag + "-" + plantDef.defName;
                    if (!TutorSystem.AllowAction(s))
                    {
                        return;
                    }
                    bool flag = true;
                    for (int j = 0; j < this.settables.Count; j++)
                    {
                        this.settables[j].SetPlantDefToGrow(plantDef);
                        if (flag && plantDef.plant.interferesWithRoof)
                        {
                            foreach (IntVec3 current2 in this.settables[j].Cells)
                            {
                                if (current2.Roofed(this.settables[j].Map))
                                {
                                    Messages.Message("MessagePlantIncompatibleWithRoof".Translate(Find.ActiveLanguageWorker.Pluralize(plantDef.LabelCap, -1)), MessageTypeDefOf.CautionInput, false);
                                    flag = false;
                                    break;
                                }
                            }
                        }
                    }
                    PlayerKnowledgeDatabase.KnowledgeDemonstrated(ConceptDefOf.SetGrowingZonePlant, KnowledgeAmount.Total);
                    this.WarnAsAppropriate(plantDef);
                    TutorSystem.Notify_Event(s);
                }, MenuOptionPriority.Default, null, null, 29f, (Rect rect) => Widgets.InfoCardButton(rect.x + 5f, rect.y + (rect.height - 24f) / 2f, plantDef), null));
            }
            Find.WindowStack.Add(new FloatMenu(list));
        }
Ejemplo n.º 22
0
        public virtual bool DoGUI(Rect rect, TieredFloatMenu floatMenu)
        {
            if (maxFloatMenuWidth != -1f)
            {
                rect.width = maxFloatMenuWidth;
            }
            Rect rect2 = rect;

            rect2.height--;
            bool flag  = !Disabled && Mouse.IsOver(rect2);
            bool flag2 = false;

            Text.Font = CurrentFont;
            Rect rect3 = rect;

            rect3.xMin += 4f;
            rect3.xMax  = rect.x + 27f;
            rect3.yMin += 4f;
            rect3.yMax  = rect.y + 27f;
            if (flag)
            {
                rect3.x += 4f;
            }
            Rect rect4 = rect;

            rect4.xMin += HorizontalMargin;
            rect4.xMax -= HorizontalMargin;
            rect4.xMax -= 4f;
            rect4.xMax -= extraPartWidth + IconOffset;
            rect4.x    += IconOffset;
            if (flag)
            {
                rect4.x += 4f;
            }
            Rect rect5 = default(Rect);

            if (extraPartWidth != 0f)
            {
                float num = Mathf.Min(Text.CalcSize(Label).x, rect4.width - 4f);
                rect5 = new Rect(rect4.xMin + num, rect4.yMin, extraPartWidth, 30f);
                flag2 = Mouse.IsOver(rect5);
            }
            Color color = GUI.color;

            //if (Disabled)
            //{
            //	GUI.color = ColorBGDisabled * color;
            //}
            //else if (flag && !flag2)
            //{
            //	GUI.color = ColorBGActiveMouseover * color;
            //}
            //else
            //{
            //	GUI.color = ColorBGActive * color;
            //}
            //GUI.DrawTexture(rect, BaseContent.WhiteTex);
            if (this.selected && iconSelected != null)
            {
                GUI.DrawTexture(rect, iconSelected);
            }
            else if (Mouse.IsOver(rect) && iconHover != null)
            {
                GUI.DrawTexture(rect, iconHover);
            }
            else if (curIcon != null)
            {
                GUI.DrawTexture(rect, curIcon);
            }
            if (toolTip.Length > 0)
            {
                TooltipHandler.TipRegion(rect, toolTip);
            }
            if (labelInt != null)
            {
                Text.Anchor = this.textAnchor;
                var textRect = new Rect(rect);
                textRect.x += this.leftTextIndent;
                Widgets.Label(textRect, Label);
                Text.Anchor = TextAnchor.UpperLeft;
            }
            GUI.color = ((!Disabled) ? ColorTextActive : ColorTextDisabled) * color;
            if (sizeMode == FloatMenuSizeMode.Tiny)
            {
                rect4.y += 1f;
            }
            Widgets.DrawAtlas(rect, TexUI.FloatMenuOptionBG);

            GUI.color = iconColor;
            if (shownItem != null || drawPlaceHolderIcon)
            {
                Widgets.DefIcon(rect3, shownItem, null, 1f, drawPlaceholder: drawPlaceHolderIcon);
            }
            else if ((bool)itemIcon)
            {
                GUI.DrawTexture(rect3, itemIcon);
            }
            GUI.color = color;
            if (extraPartOnGUI != null)
            {
                bool num2 = extraPartOnGUI(rect);
                GUI.color = color;
                if (num2)
                {
                    return(true);
                }
            }
            if (flag && mouseoverGuiAction != null)
            {
                mouseoverGuiAction();
            }
            if (tutorTag != null)
            {
                UIHighlighter.HighlightOpportunity(rect, tutorTag);
            }
            if (Widgets.ButtonInvisible(rect2))
            {
                if (tutorTag != null && !TutorSystem.AllowAction(tutorTag))
                {
                    return(false);
                }
                Chosen(floatMenu);
                if (tutorTag != null)
                {
                    TutorSystem.Notify_Event(tutorTag);
                }
                //return true;
            }
            return(false);
        }
Ejemplo n.º 23
0
        //public override bool GroupsWith(Gizmo other)
        //{
        //    return other is Command_PawnAbility p && p.pawnAbility.Def.abilityClass == pawnAbility.Def.abilityClass;
        //}

        protected override GizmoResult GizmoOnGUIInt(Rect butRect, GizmoRenderParms parms)
        {
            // TODO: This is based off Command.GizmoOnGUI at version ~A17, so it's very outdated. Actually use parms and other modern features.
            var isMouseOver = false;

            if (Mouse.IsOver(butRect))
            {
                isMouseOver = true;
                GUI.color   = GenUI.MouseoverColor;
            }
            var badTex = icon ?? BaseContent.BadTex;

            GUI.DrawTexture(butRect, BGTex);
            MouseoverSounds.DoRegion(butRect, SoundDefOf.Mouseover_Command);
            GUI.color = IconDrawColor;
            Widgets.DrawTextureFitted(new Rect(butRect), badTex, iconDrawScale * 0.85f, iconProportions, iconTexCoords);
            GUI.color = Color.white;
            var isUsed = false;

            var keyCode = hotKey != null ? hotKey.MainKey : KeyCode.None;

            if (keyCode != KeyCode.None && !GizmoGridDrawer.drawnHotKeys.Contains(keyCode))
            {
                var hotkeyRect = new Rect(butRect.x + 5f, butRect.y + 5f, butRect.width - 10f, 18f);
                Widgets.Label(hotkeyRect, keyCode.ToStringReadable());
                GizmoGridDrawer.drawnHotKeys.Add(keyCode);
                if (hotKey.KeyDownEvent)
                {
                    isUsed = true;
                    Event.current.Use();
                }
            }
            if (Widgets.ButtonInvisible(butRect, false))
            {
                isUsed = true;
            }
            var labelCap = LabelCap;

            if (!labelCap.NullOrEmpty())
            {
                var labelHeight = Text.CalcHeight(labelCap, butRect.width) - 2f;
                var labelRect   = new Rect(butRect.x, butRect.yMax - labelHeight + 12f, butRect.width, labelHeight);
                GUI.DrawTexture(labelRect, TexUI.GrayTextBG);
                GUI.color   = Color.white;
                Text.Anchor = TextAnchor.UpperCenter;
                Widgets.Label(labelRect, labelCap);
                Text.Anchor = TextAnchor.UpperLeft;
                GUI.color   = Color.white;
            }
            GUI.color = Color.white;
            if (DoTooltip)
            {
                TipSignal tip = Desc;
                if (disabled && !disabledReason.NullOrEmpty())
                {
                    tip.text += "\n" + StringsToTranslate.AU_DISABLED + ": " + disabledReason;
                }
                TooltipHandler.TipRegion(butRect, tip);
            }
            if (pawnAbility.CooldownTicksLeft != -1 && pawnAbility.CooldownTicksLeft < pawnAbility.MaxCastingTicks)
            {
                var math = curTicks / (float)pawnAbility.MaxCastingTicks;
                Widgets.FillableBar(butRect, math, AbilityButtons.FullTex, AbilityButtons.EmptyTex, false);
            }
            if (!HighlightTag.NullOrEmpty() && (Find.WindowStack.FloatMenu == null ||
                                                !Find.WindowStack.FloatMenu.windowRect.Overlaps(butRect)))
            {
                UIHighlighter.HighlightOpportunity(butRect, HighlightTag);
            }
            if (isUsed)
            {
                if (disabled)
                {
                    if (!disabledReason.NullOrEmpty())
                    {
                        Messages.Message(disabledReason, MessageTypeDefOf.RejectInput);
                    }
                    return(new GizmoResult(GizmoState.Mouseover, null));
                }
                if (!TutorSystem.AllowAction(TutorTagSelect))
                {
                    return(new GizmoResult(GizmoState.Mouseover, null));
                }
                var result = new GizmoResult(GizmoState.Interacted, Event.current);
                TutorSystem.Notify_Event(TutorTagSelect);
                return(result);
            }
            return(new GizmoResult(isMouseOver ? GizmoState.Mouseover : GizmoState.Clear, null));
        }
Ejemplo n.º 24
0
        public static List <FloatMenuOption> GetMenuItems(params Thing[] things)
        {
            List <FloatMenuOption> ret = new List <FloatMenuOption>();

            if (things == null)
            {
                return(ret);
            }

            var thing = things[0];

            var gizmos = thing.GetGizmos();

            foreach (var gizmo in gizmos)
            {
                var command = gizmo as Command;
                if (command == null)
                {
                    continue;
                }
                try {
                    ret.Add(new FloatMenuOption(command.LabelCap ?? command.Desc?.Split('\n')[0].CapitalizeFirst().Trim() ?? command.TutorTagSelect, () => {
                        if (!TutorSystem.AllowAction(command.TutorTagSelect))
                        {
                            return;
                        }
                        command.ProcessInput(null);
                    }));
                } catch {
                    Log.Message($"Unable to generate gizmo menu for:{gizmo}");
                }
            }

            var designators = Find.ReverseDesignatorDatabase.AllDesignators;

            foreach (var designator in designators)
            {
                if (designator.CanDesignateThing(thing).Accepted)
                {
                    var mainOption = new FloatMenuOption(designator.LabelCapReverseDesignating(thing), () => {
                        if (!TutorSystem.AllowAction(designator.TutorTagDesignate))
                        {
                            return;
                        }
                        things.Do(t => designator.DesignateThing(t));

                        designator.Finalize(true);
                    });
                    ret.Add(mainOption);

                    try {
                        if (controllerType == null)
                        {
                            break;
                        }

                        var field     = controllerType.GetProperty("MenuProviderInstances");
                        var providers = field.GetValue(null, null) as IEnumerable;

                        foreach (var provider in providers)
                        {
                            Type providerType   = provider.GetType();
                            var  designatorType = providerType.GetProperty("HandledDesignatorType").GetValue(provider, null) as Type;

                            if (designatorType.IsInstanceOfType(designator))
                            {
                                var listMenuEntriesMethod = providerType.GetMethod("ListMenuEntries", ExpandedContextMenu.BINDING_FLAGS);

                                if (listMenuEntriesMethod == null)
                                {
                                    Log.Message($"Checking base type for method on {providerType.Name}");
                                    listMenuEntriesMethod = providerType.BaseType.GetMethod("ListMenuEntries", ExpandedContextMenu.BINDING_FLAGS);
                                }

                                if (listMenuEntriesMethod != null)
                                {
                                    var extraOptions = listMenuEntriesMethod.Invoke(provider, new[] { designator }) as IEnumerable <FloatMenuOption>;
                                    var count        = 0;
                                    foreach (var option in extraOptions)
                                    {
                                        option.Label = $"- {option.Label}";
                                        ret.Add(option);
                                        count++;
                                    }
                                }
                                else
                                {
                                    Log.Message($"Unable to find method on {providerType.Name}");
                                }
                            }
                        }
                    } catch (Exception ex) {
                        Log.Message($"Unable to deal {ex}");
                    }
                }
            }

            Log.Message($"Returning {ret.Count} items.");
            return(ret);
        }
        public static void Detour(IEnumerable <object> selectedObjects, ref Gizmo mouseoverGizmo)
        {
            var DoRebuild = !(Analyzer.Settings.OptimizeDrawInspectGizmoGrid && Event.current.type != EventType.Repaint);

            Profiler prof = null;

            if (DoRebuild)
            {
                mouseoverGizmo = null;
                try
                {
                    InspectGizmoGrid.objList.Clear();
                    InspectGizmoGrid.objList.AddRange(selectedObjects);
                    InspectGizmoGrid.gizmoList.Clear();
                    var slam = InspectGizmoGrid.objList.Count;
                    for (var i = 0; i < slam; i++)
                    {
                        if (InspectGizmoGrid.objList[i] is ISelectable selectable)
                        {
                            if (Active)
                            {
                                var me = string.Intern($"{selectable.GetType()} Gizmos");
                                prof = Analyzer.Start(me);
                                InspectGizmoGrid.gizmoList.AddRange(selectable.GetGizmos());
                                prof.Stop();
                            }
                            else
                            {
                                InspectGizmoGrid.gizmoList.AddRange(selectable.GetGizmos());
                            }
                        }
                    }
                    for (var j = 0; j < InspectGizmoGrid.objList.Count; j++)
                    {
                        if (InspectGizmoGrid.objList[j] is Thing t)
                        {
                            var allDesignators = Find.ReverseDesignatorDatabase.AllDesignators;
                            var coo            = allDesignators.Count;
                            for (var k = 0; k < coo; k++)
                            {
                                Designator des = allDesignators[k];
                                if (des.CanDesignateThing(t).Accepted)
                                {
                                    var command_Action = new Command_Action
                                    {
                                        defaultLabel = des.LabelCapReverseDesignating(t),
                                        icon         = des.IconReverseDesignating(t, out var iconAngle, out var iconOffset),
                                        iconAngle    = iconAngle,
                                        iconOffset   = iconOffset,
                                        defaultDesc  = des.DescReverseDesignating(t),
                                        order        = (!(des is Designator_Uninstall) ? -20f : -11f),
                                        action       = delegate
                                        {
                                            if (!TutorSystem.AllowAction(des.TutorTagDesignate))
                                            {
                                                return;
                                            }

                                            des.DesignateThing(t);
                                            des.Finalize(true);
                                        },
                                        hotKey   = des.hotKey,
                                        groupKey = des.groupKey
                                    };
                                    InspectGizmoGrid.gizmoList.Add(command_Action);
                                }
                            }
                        }
                    }
                    InspectGizmoGrid.objList.Clear();
                }
                catch (Exception ex)
                {
                    Log.ErrorOnce(ex.ToString(), 3427734);
                }
            }

            if (Active)
            {
                prof = Analyzer.Start(str);
            }
            GizmoGridDrawer.DrawGizmoGrid(InspectGizmoGrid.gizmoList, InspectPaneUtility.PaneWidthFor(Find.WindowStack.WindowOfType <IInspectPane>()) + 20f, out mouseoverGizmo);
            if (Active)
            {
                prof.Stop();
            }
        }
        public virtual bool DoGUI(Rect rect, bool colonistOrdering, FloatMenu floatMenu)
        {
            Rect rect2 = rect;

            rect2.height -= 1f;
            bool flag  = !this.Disabled && Mouse.IsOver(rect2);
            bool flag2 = false;

            Text.Font = this.CurrentFont;
            Rect rect3 = rect;

            rect3.xMin += this.HorizontalMargin;
            rect3.xMax -= this.HorizontalMargin;
            rect3.xMax -= 4f;
            rect3.xMax -= this.extraPartWidth;
            if (flag)
            {
                rect3.x += 4f;
            }
            Rect rect4 = default(Rect);

            if (this.extraPartWidth != 0f)
            {
                float num = Mathf.Min(Text.CalcSize(this.Label).x, rect3.width - 4f);
                rect4 = new Rect(rect3.xMin + num, rect3.yMin, this.extraPartWidth, 30f);
                flag2 = Mouse.IsOver(rect4);
            }
            if (!this.Disabled)
            {
                MouseoverSounds.DoRegion(rect2);
            }
            Color color = GUI.color;

            if (this.Disabled)
            {
                GUI.color = FloatMenuOption.ColorBGDisabled * color;
            }
            else if (flag && !flag2)
            {
                GUI.color = FloatMenuOption.ColorBGActiveMouseover * color;
            }
            else
            {
                GUI.color = FloatMenuOption.ColorBGActive * color;
            }
            GUI.DrawTexture(rect, BaseContent.WhiteTex);
            GUI.color = (this.Disabled ? FloatMenuOption.ColorTextDisabled : FloatMenuOption.ColorTextActive) * color;
            if (this.sizeMode == FloatMenuSizeMode.Tiny)
            {
                rect3.y += 1f;
            }
            Widgets.DrawAtlas(rect, TexUI.FloatMenuOptionBG);
            Text.Anchor = TextAnchor.MiddleLeft;
            Widgets.Label(rect3, this.Label);
            Text.Anchor = TextAnchor.UpperLeft;
            GUI.color   = color;
            if (this.extraPartOnGUI != null)
            {
                bool flag3 = this.extraPartOnGUI(rect4);
                GUI.color = color;
                if (flag3)
                {
                    return(true);
                }
            }
            if (flag && this.mouseoverGuiAction != null)
            {
                this.mouseoverGuiAction();
            }
            if (this.tutorTag != null)
            {
                UIHighlighter.HighlightOpportunity(rect, this.tutorTag);
            }
            if (!Widgets.ButtonInvisible(rect2, false))
            {
                return(false);
            }
            if (this.tutorTag != null && !TutorSystem.AllowAction(this.tutorTag))
            {
                return(false);
            }
            this.Chosen(colonistOrdering, floatMenu);
            if (this.tutorTag != null)
            {
                TutorSystem.Notify_Event(this.tutorTag);
            }
            return(true);
        }
Ejemplo n.º 27
0
        public override GizmoResult GizmoOnGUI(Vector2 topLeft)
        {
            Rect rect = new Rect(topLeft.x, topLeft.y, this.Width, 75f);
            bool flag = false;

            if (Mouse.IsOver(rect))
            {
                flag      = true;
                GUI.color = GenUI.MouseoverColor;
            }
            Texture2D badTex = this.icon;

            if ((Object)badTex == (Object)null)
            {
                badTex = BaseContent.BadTex;
            }
            GUI.DrawTexture(rect, Command.BGTex);
            MouseoverSounds.DoRegion(rect, SoundDefOf.MouseoverCommand);
            GUI.color = this.IconDrawColor;
            Widgets.DrawTextureFitted(rect, badTex, (float)(this.iconDrawScale * 0.85000002384185791), this.iconProportions, this.iconTexCoords, this.iconAngle);
            GUI.color = Color.white;
            bool    flag2   = false;
            KeyCode keyCode = (this.hotKey != null) ? this.hotKey.MainKey : KeyCode.None;

            if (keyCode != 0 && !GizmoGridDrawer.drawnHotKeys.Contains(keyCode))
            {
                Rect rect2 = new Rect((float)(rect.x + 5.0), (float)(rect.y + 5.0), (float)(rect.width - 10.0), 18f);
                Widgets.Label(rect2, keyCode.ToStringReadable());
                GizmoGridDrawer.drawnHotKeys.Add(keyCode);
                if (this.hotKey.KeyDownEvent)
                {
                    flag2 = true;
                    Event.current.Use();
                }
            }
            if (Widgets.ButtonInvisible(rect, false))
            {
                flag2 = true;
            }
            string labelCap = this.LabelCap;

            if (!labelCap.NullOrEmpty())
            {
                float num   = Text.CalcHeight(labelCap, rect.width);
                Rect  rect3 = new Rect(rect.x, (float)(rect.yMax - num + 12.0), rect.width, num);
                GUI.DrawTexture(rect3, TexUI.GrayTextBG);
                GUI.color   = Color.white;
                Text.Anchor = TextAnchor.UpperCenter;
                Widgets.Label(rect3, labelCap);
                Text.Anchor = TextAnchor.UpperLeft;
                GUI.color   = Color.white;
            }
            GUI.color = Color.white;
            if (this.DoTooltip)
            {
                TipSignal tip = this.Desc;
                if (base.disabled && !base.disabledReason.NullOrEmpty())
                {
                    string text = tip.text;
                    tip.text = text + "\n\n" + "DisabledCommand".Translate() + ": " + base.disabledReason;
                }
                TooltipHandler.TipRegion(rect, tip);
            }
            if (!this.HighlightTag.NullOrEmpty() && (Find.WindowStack.FloatMenu == null || !Find.WindowStack.FloatMenu.windowRect.Overlaps(rect)))
            {
                UIHighlighter.HighlightOpportunity(rect, this.HighlightTag);
            }
            if (flag2)
            {
                if (base.disabled)
                {
                    if (!base.disabledReason.NullOrEmpty())
                    {
                        Messages.Message(base.disabledReason, MessageTypeDefOf.RejectInput);
                    }
                    return(new GizmoResult(GizmoState.Mouseover, null));
                }
                if (!TutorSystem.AllowAction(this.TutorTagSelect))
                {
                    return(new GizmoResult(GizmoState.Mouseover, null));
                }
                GizmoResult result = new GizmoResult(GizmoState.Interacted, Event.current);
                TutorSystem.Notify_Event(this.TutorTagSelect);
                return(result);
            }
            if (flag)
            {
                return(new GizmoResult(GizmoState.Mouseover, null));
            }
            return(new GizmoResult(GizmoState.Clear, null));
        }
Ejemplo n.º 28
0
        public override GizmoResult GizmoOnGUI(Vector2 topLeft, float maxWidth)
        {
            Text.Font = GameFont.Tiny;
            Rect rect = new Rect(topLeft.x, topLeft.y, this.GetWidth(maxWidth), 75f);
            bool flag = false;

            if (Mouse.IsOver(rect))
            {
                flag = true;
                if (!this.disabled)
                {
                    GUI.color = GenUI.MouseoverColor;
                }
            }
            Texture2D badTex = this.icon;

            if (badTex == null)
            {
                badTex = BaseContent.BadTex;
            }
            Material material = (!this.disabled) ? null : TexUI.GrayscaleGUI;

            GenUI.DrawTextureWithMaterial(rect, Command.BGTex, material, default(Rect));
            MouseoverSounds.DoRegion(rect, SoundDefOf.Mouseover_Command);
            Rect outerRect = rect;

            outerRect.position += new Vector2(this.iconOffset.x * outerRect.size.x, this.iconOffset.y * outerRect.size.y);
            GUI.color           = this.IconDrawColor;
            Widgets.DrawTextureFitted(outerRect, badTex, this.iconDrawScale * 0.85f, this.iconProportions, this.iconTexCoords, this.iconAngle, material);
            GUI.color = Color.white;
            bool    flag2   = false;
            KeyCode keyCode = (this.hotKey != null) ? this.hotKey.MainKey : KeyCode.None;

            if (keyCode != KeyCode.None && !GizmoGridDrawer.drawnHotKeys.Contains(keyCode))
            {
                Rect rect2 = new Rect(rect.x + 5f, rect.y + 5f, rect.width - 10f, 18f);
                Widgets.Label(rect2, keyCode.ToStringReadable());
                GizmoGridDrawer.drawnHotKeys.Add(keyCode);
                if (this.hotKey.KeyDownEvent)
                {
                    flag2 = true;
                    Event.current.Use();
                }
            }
            if (Widgets.ButtonInvisible(rect, false))
            {
                flag2 = true;
            }
            string labelCap = this.LabelCap;

            if (!labelCap.NullOrEmpty())
            {
                float num   = Text.CalcHeight(labelCap, rect.width);
                Rect  rect3 = new Rect(rect.x, rect.yMax - num + 12f, rect.width, num);
                GUI.DrawTexture(rect3, TexUI.GrayTextBG);
                GUI.color   = Color.white;
                Text.Anchor = TextAnchor.UpperCenter;
                Widgets.Label(rect3, labelCap);
                Text.Anchor = TextAnchor.UpperLeft;
                GUI.color   = Color.white;
            }
            GUI.color = Color.white;
            if (this.DoTooltip)
            {
                TipSignal tip = this.Desc;
                if (this.disabled && !this.disabledReason.NullOrEmpty())
                {
                    string text = tip.text;
                    tip.text = string.Concat(new string[]
                    {
                        text,
                        "\n\n",
                        "DisabledCommand".Translate(),
                        ": ",
                        this.disabledReason
                    });
                }
                TooltipHandler.TipRegion(rect, tip);
            }
            if (!this.HighlightTag.NullOrEmpty() && (Find.WindowStack.FloatMenu == null || !Find.WindowStack.FloatMenu.windowRect.Overlaps(rect)))
            {
                UIHighlighter.HighlightOpportunity(rect, this.HighlightTag);
            }
            Text.Font = GameFont.Small;
            if (flag2)
            {
                if (this.disabled)
                {
                    if (!this.disabledReason.NullOrEmpty())
                    {
                        Messages.Message(this.disabledReason, MessageTypeDefOf.RejectInput, false);
                    }
                    return(new GizmoResult(GizmoState.Mouseover, null));
                }
                GizmoResult result;
                if (Event.current.button == 1)
                {
                    result = new GizmoResult(GizmoState.OpenedFloatMenu, Event.current);
                }
                else
                {
                    if (!TutorSystem.AllowAction(this.TutorTagSelect))
                    {
                        return(new GizmoResult(GizmoState.Mouseover, null));
                    }
                    result = new GizmoResult(GizmoState.Interacted, Event.current);
                    TutorSystem.Notify_Event(this.TutorTagSelect);
                }
                return(result);
            }
            else
            {
                if (flag)
                {
                    return(new GizmoResult(GizmoState.Mouseover, null));
                }
                return(new GizmoResult(GizmoState.Clear, null));
            }
        }
Ejemplo n.º 29
0
        // copy paste from Command.GizmoOnGUI
        public override GizmoResult GizmoOnGUI(Vector2 topLeft, float maxWidth)
        {
            Text.Font = GameFont.Tiny;
            Rect rect = new Rect(topLeft.x, topLeft.y, GetWidth(maxWidth), 75f);
            bool flag = false;

            if (Mouse.IsOver(rect))
            {
                flag = true;
                if (!disabled)
                {
                    GUI.color = GenUI.MouseoverColor;
                }
            }
            Texture2D badTex = icon;

            if (badTex == null)
            {
                badTex = BaseContent.BadTex;
            }
            Material material = (!disabled) ? null : TexUI.GrayscaleGUI;

            GenUI.DrawTextureWithMaterial(rect, BGTex, material);
            MouseoverSounds.DoRegion(rect, SoundDefOf.Mouseover_Command);
            Rect    outerRect = rect;
            Vector2 position  = outerRect.position;
            float   x         = iconOffset.x;
            Vector2 size      = outerRect.size;
            float   x2        = x * size.x;
            float   y         = iconOffset.y;
            Vector2 size2     = outerRect.size;

            outerRect.position = position + new Vector2(x2, y * size2.y);
            GUI.color          = IconDrawColor;
            // BEGIN EDIT
            //Widgets.DrawTextureFitted(outerRect, badTex, iconDrawScale * 0.85f, iconProportions, iconTexCoords, iconAngle, material);
            {
                Rect  positionColor = new Rect(0f, 0f, iconProportions.x, iconProportions.y);
                float num;
                if (positionColor.width / positionColor.height < rect.width / rect.height)
                {
                    num = rect.height / positionColor.height;
                }
                else
                {
                    num = rect.width / positionColor.width;
                }
                num *= iconDrawScale * 0.85f;
                positionColor.width  *= num;
                positionColor.height *= num;
                positionColor.x       = rect.x + rect.width / 2f - positionColor.width / 2f;
                positionColor.y       = rect.y + rect.height / 2f - positionColor.height / 2f;

                Widgets.DrawBoxSolid(positionColor, PlanColorManager.PlanColor[Color]);

                Widgets.DrawTextureFitted(outerRect,
                                          MorePlanningMod.Instance.SelectedColor == Color
                        ? Resources.ToolBoxColorSelected
                        : Resources.ToolBoxColor, iconDrawScale * 0.85f, iconProportions, iconTexCoords);
            }
            // END EDIT
            GUI.color = UnityEngine.Color.white;
            bool    flag2   = false;
            KeyCode keyCode = (hotKey != null) ? hotKey.MainKey : KeyCode.None;

            if (keyCode != 0 && !GizmoGridDrawer.drawnHotKeys.Contains(keyCode))
            {
                Rect rect2 = new Rect(rect.x + 5f, rect.y + 5f, rect.width - 10f, 18f);
                Widgets.Label(rect2, keyCode.ToStringReadable());
                GizmoGridDrawer.drawnHotKeys.Add(keyCode);
                if (hotKey.KeyDownEvent)
                {
                    flag2 = true;
                    Event.current.Use();
                }
            }
            if (Widgets.ButtonInvisible(rect))
            {
                flag2 = true;
            }
            string labelCap = LabelCap;

            if (!labelCap.NullOrEmpty())
            {
                float num   = Text.CalcHeight(labelCap, rect.width);
                Rect  rect3 = new Rect(rect.x, rect.yMax - num + 12f, rect.width, num);
                GUI.DrawTexture(rect3, TexUI.GrayTextBG);
                GUI.color   = UnityEngine.Color.white;
                Text.Anchor = TextAnchor.UpperCenter;
                Widgets.Label(rect3, labelCap);
                Text.Anchor = TextAnchor.UpperLeft;
                GUI.color   = UnityEngine.Color.white;
            }
            GUI.color = UnityEngine.Color.white;
            if (DoTooltip)
            {
                TipSignal tip = Desc;
                if (disabled && !disabledReason.NullOrEmpty())
                {
                    string text = tip.text;
                    tip.text = text + "\n\n" + "DisabledCommand".Translate() + ": " + disabledReason;
                }
                TooltipHandler.TipRegion(rect, tip);
            }
            if (!HighlightTag.NullOrEmpty() && (Find.WindowStack.FloatMenu == null || !Find.WindowStack.FloatMenu.windowRect.Overlaps(rect)))
            {
                UIHighlighter.HighlightOpportunity(rect, HighlightTag);
            }
            Text.Font = GameFont.Small;
            if (flag2)
            {
                if (disabled)
                {
                    if (!disabledReason.NullOrEmpty())
                    {
                        Messages.Message(disabledReason, MessageTypeDefOf.RejectInput, false);
                    }
                    return(new GizmoResult(GizmoState.Mouseover, null));
                }
                GizmoResult result;
                if (Event.current.button == 1)
                {
                    result = new GizmoResult(GizmoState.OpenedFloatMenu, Event.current);
                }
                else
                {
                    if (!TutorSystem.AllowAction(TutorTagSelect))
                    {
                        return(new GizmoResult(GizmoState.Mouseover, null));
                    }
                    result = new GizmoResult(GizmoState.Interacted, Event.current);
                    TutorSystem.Notify_Event(TutorTagSelect);
                }
                return(result);
            }
            if (flag)
            {
                return(new GizmoResult(GizmoState.Mouseover, null));
            }
            return(new GizmoResult(GizmoState.Clear, null));
        }