Exemplo n.º 1
0
        public static bool CheckAddOrRemoveAlert(AlertsReadout __instance, Alert alert, bool forceRemove)
        {
            if (DisableAlerts)
            {
                return(false);
            }
            if (!OverrideAlerts)
            {
                return(true);
            }

            try
            {
                var alertActive = false;
                var alertType   = alert.GetType();

                if (AlertFilter.TryGetValue(alertType, out var active))
                {
                    if (!active)
                    {
                        alert.Recalculate();
                        alertActive = alert.Active;
                    }
                    else // We ensure alerts show up so you can re-enable disabled alerts.
                    {
                        if (AlertRecalculate.Active)
                        {
                            var prof = ProfileController.Start(alertType.Name, () => alertType.FullName, alertType, null, null, AlertRecalculate.recalculate);

                            prof?.Stop();
                        }
                    }
                }
                else
                {
                    alert.Recalculate();
                    alertActive = alert.Active;
                }

                if (!forceRemove && alertActive)
                {
                    if (!__instance.activeAlerts.Contains(alert))
                    {
                        __instance.activeAlerts.Add(alert);
                        alert.Notify_Started();
                    }
                }
                else
                {
                    __instance.activeAlerts.Remove(alert);
                }
            }
            catch (Exception ex)
            {
                Log.ErrorOnce("Exception processing alert " + alert.ToString() + ": " + ex.ToString(), 743575, false);
                __instance.activeAlerts.Remove(alert);
            }

            return(false);
        }
Exemplo n.º 2
0
 public static void CheckAddOrRemoveAlert2(AlertsReadout __instance, Alert alert, bool forceRemove = false)
 {
     try
     {
         alert.Recalculate();
         if (!forceRemove && alert.Active)
         {
             if (!activeAlerts(__instance).Contains(alert))
             {
                 activeAlerts(__instance).Add(alert);
                 alert.Notify_Started();
             }
         }
         else
         {
             activeAlerts(__instance).Remove(alert);
         }
     }
     catch (Exception ex)
     {
         Log.ErrorOnce("Exception processing alert " + alert.ToString() + ": " + ex.ToString(), 743575);
         activeAlerts(__instance).Remove(alert);
     }
 }
        public void MissionInfoOnGUI()
        {
            if (Find.WindowStack.IsOpen <Screen_Credits>() || !(selectedMission?.def.failConditions != null || selectedObjective?.def.failConditions != null))
            {
                return;
            }
            Text.Font = GameFont.Small;
            AlertsReadout   alerts      = (Find.UIRoot as UIRoot_Play).alerts;
            LearningReadout readout     = Find.Tutor?.learningReadout;
            float           totalHeight = Math.Min(ContentHeight(), ((float)UI.screenHeight / 2f)); //+ 8f;
            float           heightLearn = 8f;

            if (Prefs.AdaptiveTrainingEnabled && readout != null)
            {
                float value = Traverse.Create(readout).Field("contentHeight").GetValue <float>();
                if (value > 0)
                {
                    heightLearn += value + 19f;
                }
            }
            float heightAlert = 0f;

            if (alerts != null)
            {
                float alertY = Find.LetterStack.LastTopY - Traverse.Create(alerts).Field("activeAlerts").GetValue <List <Alert> >().Count * 28f;
                float diff   = (totalHeight + heightLearn) - alertY;
                if (diff > 0)
                {
                    heightAlert = Math.Abs(diff) + 5f;
                }
            }
            float maxHeight = totalHeight - heightAlert;
            Rect  Main      = new Rect((float)UI.screenWidth - 208f, heightLearn, 200f, maxHeight);

            Find.WindowStack.ImmediateWindow(1582828288, Main, WindowLayer.GameUI, delegate
            {
                Widgets.DrawHighlight(new Rect(0f, 0f, Main.width, Main.height));
                Rect rect = new Rect(3f, 0f, Main.width, Main.height);
                Rect view = new Rect(0f, 0f, Main.width - 4f, totalHeight);
                DrawCustomScrollBar(new Rect(0f, 0f, rect.width, Main.height), totalHeight);
                Listing_Standard listing = new Listing_Standard();
                listing.verticalSpacing  = 2f;
                listing.Begin(view);
                Text.Font = GameFont.Tiny;
                Widgets.BeginScrollView(rect, ref extraInfoScrollPos, view, false);
                bool flag = false;
                if (selectedMission != null && selectedMission.def.failConditions != null)
                {
                    bool failed = selectedMission.LatestState == MOState.Failed;
                    listing.Label(failed ? "MissionFailed_SMO".Translate("'" + selectedMission.def.LabelCap + "'") : "Mission_SMO".Translate("'" + selectedMission.def.LabelCap + "'") + "... ");
                    if (!failed)
                    {
                        FailconReadout(selectedMission, selectedMission.def.failConditions, ref listing);
                    }
                    flag = true;
                }
                if (selectedObjective != null && selectedObjective.def.failConditions != null)
                {
                    if (flag)
                    {
                        listing.GapLine(6);
                    }
                    bool failed = selectedObjective.CurrentState == MOState.Failed;
                    listing.Label(failed ? "ObjectiveFailed_SMO".Translate("'" + selectedObjective.def.LabelCap + "'") : "Objective_SMO".Translate("'" + selectedObjective.def.LabelCap + "'") + "... ");
                    if (!failed)
                    {
                        FailconReadout(selectedObjective, selectedObjective.def.failConditions, ref listing);
                    }
                }
                Widgets.EndScrollView();
                listing.End();
            }, false, false, 0f);
        }
Exemplo n.º 4
0
        public static bool CheckAddOrRemoveAlert(AlertsReadout __instance, Alert alert, bool forceRemove)
        {
            if (Analyzer.Settings.DisableAlerts)
            {
                return(false);
            }
            //    return false;
            if (!Analyzer.Settings.OverrideAlerts && (!AnalyzerState.CurrentlyRunning || !Active))
            {
                return(true);
            }

            try
            {
                var typeis = alert.GetType();

                // if (Analyzer.loggingMode == LoggingMode.RenderingThings)
                //  {
                //name = $"{alert.GetType()}";
                //  }

                Profiler prof = null;
                if (Active && AnalyzerState.CurrentlyRunning)
                {
                    prof = Analyzer.Start(typeis.Name, () => typeis.FullName, typeis);
                }

                var ac = false;

                if (Analyzer.Settings.AlertFilter.ContainsKey(typeis))
                {
                    if (Analyzer.Settings.AlertFilter[typeis] == false)
                    {
                        alert.Recalculate();
                        ac = alert.Active;
                    }
                }
                else
                {
                    alert.Recalculate();
                    ac = alert.Active;
                }

                if (Active && AnalyzerState.CurrentlyRunning)
                {
                    prof.Stop();
                }

                if (!forceRemove && ac)
                {
                    if (!__instance.activeAlerts.Contains(alert))
                    {
                        __instance.activeAlerts.Add(alert);
                        alert.Notify_Started();
                    }
                }
                else
                {
                    __instance.activeAlerts.Remove(alert);
                }
            }
            catch (Exception ex)
            {
                Log.ErrorOnce("Exception processing alert " + alert.ToString() + ": " + ex.ToString(), 743575, false);
                __instance.activeAlerts.Remove(alert);
            }

            return(false);
        }
Exemplo n.º 5
0
        public static bool AlertsReadoutUpdate(AlertsReadout __instance)
        {
            if (!Analyzer.Settings.OverrideAlerts && !AnalyzerState.CurrentlyRunning)
            {
                return(true);
            }

            if (!Active)
            {
                return(true);
            }

            if (Mathf.Max(Find.TickManager.TicksGame, Find.TutorialState.endTick) < 600)
            {
                return(false);
            }
            if (Find.Storyteller.def.disableAlerts)
            {
                __instance.activeAlerts.Clear();
                return(false);
            }
            __instance.curAlertIndex++;
            if (__instance.curAlertIndex >= 24)
            {
                __instance.curAlertIndex = 0;
            }
            for (int i = __instance.curAlertIndex; i < __instance.AllAlerts.Count; i += 24)
            {
                __instance.CheckAddOrRemoveAlert(__instance.AllAlerts[i], false);
            }
            if (Time.frameCount % 20 == 0)
            {
                List <Quest> questsListForReading = Find.QuestManager.QuestsListForReading;
                for (int j = 0; j < questsListForReading.Count; j++)
                {
                    List <QuestPart> partsListForReading = questsListForReading[j].PartsListForReading;
                    for (int k = 0; k < partsListForReading.Count; k++)
                    {
                        QuestPartActivable questPartActivable = partsListForReading[k] as QuestPartActivable;
                        Alert cachedAlert = questPartActivable?.CachedAlert;
                        if (cachedAlert != null)
                        {
                            bool flag       = questsListForReading[j].State != QuestState.Ongoing || questPartActivable.State != QuestPartState.Enabled;
                            bool alertDirty = questPartActivable.AlertDirty;
                            __instance.CheckAddOrRemoveAlert(cachedAlert, flag || alertDirty);
                            if (alertDirty)
                            {
                                questPartActivable.ClearCachedAlert();
                            }
                        }
                    }
                }
            }

            for (int l = __instance.activeAlerts.Count - 1; l >= 0; l--)
            {
                Alert alert = __instance.activeAlerts[l];

                try
                {
                    var prof = Analyzer.Start(__instance.activeAlerts[l].GetHashCode().ToString(), () => __instance.activeAlerts[l] + " Update", __instance.activeAlerts[l].GetType());
                    __instance.activeAlerts[l].AlertActiveUpdate();
                    prof.Stop();
                }
                catch (Exception ex)
                {
                    Log.ErrorOnce($"Analyzer: Exception updating alert {alert.ToString()}, errored with the message {ex.ToString()}", 743575, false);
                    __instance.activeAlerts.RemoveAt(l);
                }
            }

            if (__instance.mouseoverAlertIndex >= 0 && __instance.mouseoverAlertIndex < __instance.activeAlerts.Count)
            {
                IEnumerable <GlobalTargetInfo> allCulprits = __instance.activeAlerts[__instance.mouseoverAlertIndex].GetReport().AllCulprits;
                if (allCulprits != null)
                {
                    foreach (GlobalTargetInfo target in allCulprits)
                    {
                        TargetHighlighter.Highlight(target, true, true, false);
                    }
                }
            }
            __instance.mouseoverAlertIndex = -1;

            return(false);
        }
Exemplo n.º 6
0
        public static bool AlertsReadoutOnGUI(AlertsReadout __instance)
        {
            if (Analyzer.Settings.DisableAlerts)
            {
                return(false);
            }

            if (!Analyzer.Settings.OverrideAlerts && (!AnalyzerState.CurrentlyRunning || !Active))
            {
                return(true);
            }

            if (!Active)
            {
                return(true);
            }

            if (Event.current.type == EventType.Layout || Event.current.type == EventType.MouseDrag)
            {
                return(false);
            }

            if (__instance.activeAlerts.Count == 0)
            {
                return(false);
            }

            Alert alert         = null;
            var   alertPriority = AlertPriority.Critical;
            var   flag          = false;
            var   num           = Find.LetterStack.LastTopY - __instance.activeAlerts.Count * 28f;
            var   rect          = new Rect(UI.screenWidth - 154f, num, 154f, __instance.lastFinalY - num);
            var   num2          = GenUI.BackgroundDarkAlphaForText();

            if (num2 > 0.001f)
            {
                GUI.color = new Color(1f, 1f, 1f, num2);
                Widgets.DrawShadowAround(rect);
                GUI.color = Color.white;
            }

            var num3 = num;

            if (num3 < 0f)
            {
                num3 = 0f;
            }

            for (var i = 0; i < __instance.PriosInDrawOrder.Count; i++)
            {
                var alertPriority2 = __instance.PriosInDrawOrder[i];
                for (var j = 0; j < __instance.activeAlerts.Count; j++)
                {
                    var alert2 = __instance.activeAlerts[j];
                    if (alert2.Priority == alertPriority2)
                    {
                        if (!flag)
                        {
                            alertPriority = alertPriority2;
                            flag          = true;
                        }

                        var key   = alert2.GetType();
                        var prof  = Analyzer.Start(key.Name, () => key.FullName, key);
                        var rect2 = alert2.DrawAt(num3, alertPriority2 != alertPriority);
                        prof.Stop();

                        if (Mouse.IsOver(rect2))
                        {
                            alert = alert2;
                            __instance.mouseoverAlertIndex = j;
                        }

                        num3 += rect2.height;
                    }
                }
            }

            __instance.lastFinalY = num3;
            UIHighlighter.HighlightOpportunity(rect, "Alerts");
            if (alert != null)
            {
                alert.DrawInfoPane();
                PlayerKnowledgeDatabase.KnowledgeDemonstrated(ConceptDefOf.Alerts, KnowledgeAmount.FrameDisplayed);
                __instance.CheckAddOrRemoveAlert(alert, false);
            }

            return(false);
        }
        public static bool AlertsReadoutUpdate(AlertsReadout __instance)
        {
            if (runonce && RimThreadedMod.Settings.showModConflictsAlert)
            {
                RimThreadedMod.getPotentialModConflicts_2(); //Not sure where to put this, making it run on the main menu without black screen will have been perfect.
                runonce = false;
            }
            if (Mathf.Max(Find.TickManager.TicksGame, Find.TutorialState.endTick) < 600)
            {
                return(false);
            }

            if (Find.Storyteller.def != null && Find.Storyteller.def.disableAlerts)
            {
                activeAlerts(__instance).Clear();
                return(false);
            }

            if (TickManager_Patch.curTimeSpeed(Find.TickManager) == TimeSpeed.Ultrafast && RimThreadedMod.Settings.disablesomealerts)
            {
                //this will disable alert checks on ultrafast speed for an added speed boost
                return(false);
            }

            curAlertIndex(__instance)++;
            if (curAlertIndex(__instance) >= 24)
            {
                curAlertIndex(__instance) = 0;
            }

            for (int i = curAlertIndex(__instance); i < AllAlerts(__instance).Count; i += 24)
            {
                //CheckAddOrRemoveAlert2(__instance, AllAlerts(__instance)[i]);
                actionCheckAddOrRemoveAlert(__instance, AllAlerts(__instance)[i], false);
            }

            if (Time.frameCount % 20 == 0)
            {
                List <Quest> questsListForReading = Find.QuestManager.QuestsListForReading;
                for (int j = 0; j < questsListForReading.Count; j++)
                {
                    List <QuestPart> partsListForReading = questsListForReading[j].PartsListForReading;
                    for (int k = 0; k < partsListForReading.Count; k++)
                    {
                        QuestPartActivable questPartActivable = partsListForReading[k] as QuestPartActivable;
                        if (questPartActivable == null)
                        {
                            continue;
                        }

                        Alert cachedAlert = questPartActivable.CachedAlert;
                        if (cachedAlert != null)
                        {
                            bool flag       = questsListForReading[j].State != QuestState.Ongoing || questPartActivable.State != QuestPartState.Enabled;
                            bool alertDirty = questPartActivable.AlertDirty;
                            //CheckAddOrRemoveAlert(__instance, cachedAlert, flag || alertDirty);
                            actionCheckAddOrRemoveAlert(__instance, cachedAlert, flag || alertDirty);
                            if (alertDirty)
                            {
                                questPartActivable.ClearCachedAlert();
                            }
                        }
                    }
                }
            }

            for (int num = activeAlerts(__instance).Count - 1; num >= 0; num--)
            {
                Alert alert = activeAlerts(__instance)[num];
                try
                {
                    activeAlerts(__instance)[num].AlertActiveUpdate();
                }
                catch (Exception ex)
                {
                    Log.ErrorOnce("Exception updating alert " + alert.ToString() + ": " + ex.ToString(), 743575);
                    activeAlerts(__instance).RemoveAt(num);
                }
            }

            if (mouseoverAlertIndex(__instance) >= 0 && mouseoverAlertIndex(__instance) < activeAlerts(__instance).Count)
            {
                IEnumerable <GlobalTargetInfo> allCulprits = activeAlerts(__instance)[mouseoverAlertIndex(__instance)].GetReport().AllCulprits;
                if (allCulprits != null)
                {
                    foreach (GlobalTargetInfo item in allCulprits)
                    {
                        TargetHighlighter.Highlight(item);
                    }
                }
            }

            mouseoverAlertIndex(__instance) = -1;
            return(false);
        }
Exemplo n.º 8
0
 public static bool AlertsReadoutUpdate(AlertsReadout __instance)
 {
     //this will disable alert checks on ultrafast speed for an added speed boost
     return(Find.TickManager.curTimeSpeed != TimeSpeed.Ultrafast || !RimThreadedMod.Settings.disablesomealerts);
 }
Exemplo n.º 9
0
        public static bool AlertsReadoutUpdate(AlertsReadout __instance)
        {
            if (Mathf.Max(Find.TickManager.TicksGame, Find.TutorialState.endTick) < 600)
            {
                return(false);
            }

            if (Find.Storyteller.def != null && Find.Storyteller.def.disableAlerts)
            {
                activeAlerts(__instance).Clear();
                return(false);
            }

            curAlertIndex(__instance)++;
            if (curAlertIndex(__instance) >= 24)
            {
                curAlertIndex(__instance) = 0;
            }

            for (int i = curAlertIndex(__instance); i < AllAlerts(__instance).Count; i += 24)
            {
                CheckAddOrRemoveAlert2(__instance, AllAlerts(__instance)[i]);
            }

            if (Time.frameCount % 20 == 0)
            {
                List <Quest> questsListForReading = Find.QuestManager.QuestsListForReading;
                for (int j = 0; j < questsListForReading.Count; j++)
                {
                    List <QuestPart> partsListForReading = questsListForReading[j].PartsListForReading;
                    for (int k = 0; k < partsListForReading.Count; k++)
                    {
                        QuestPartActivable questPartActivable = partsListForReading[k] as QuestPartActivable;
                        if (questPartActivable == null)
                        {
                            continue;
                        }

                        Alert cachedAlert = questPartActivable.CachedAlert;
                        if (cachedAlert != null)
                        {
                            bool flag       = questsListForReading[j].State != QuestState.Ongoing || questPartActivable.State != QuestPartState.Enabled;
                            bool alertDirty = questPartActivable.AlertDirty;
                            CheckAddOrRemoveAlert2(__instance, cachedAlert, flag || alertDirty);
                            if (alertDirty)
                            {
                                questPartActivable.ClearCachedAlert();
                            }
                        }
                    }
                }
            }

            for (int num = activeAlerts(__instance).Count - 1; num >= 0; num--)
            {
                Alert alert = activeAlerts(__instance)[num];
                try
                {
                    activeAlerts(__instance)[num].AlertActiveUpdate();
                }
                catch (Exception ex)
                {
                    Log.ErrorOnce("Exception updating alert " + alert.ToString() + ": " + ex.ToString(), 743575);
                    activeAlerts(__instance).RemoveAt(num);
                }
            }

            if (mouseoverAlertIndex(__instance) >= 0 && mouseoverAlertIndex(__instance) < activeAlerts(__instance).Count)
            {
                IEnumerable <GlobalTargetInfo> allCulprits = activeAlerts(__instance)[mouseoverAlertIndex(__instance)].GetReport().AllCulprits;
                if (allCulprits != null)
                {
                    foreach (GlobalTargetInfo item in allCulprits)
                    {
                        TargetHighlighter.Highlight(item);
                    }
                }
            }

            mouseoverAlertIndex(__instance) = -1;
            return(false);
        }
Exemplo n.º 10
0
 public AlertsReadoutComponent(AlertsReadout alertsReadout)
 {
     this.alertsReadout = alertsReadout;
 }