Ejemplo n.º 1
0
        private void UpdateAbsoluteFieldsFromTicks(int ticksToUse)
        {
            var tileCoords = RemindersGameComponent.VectorForTime;

            if (!tileCoords.HasValue)
            {
                return;
            }
            var absTicks = GenDate.TickGameToAbs(ticksToUse);
            var coords   = tileCoords.Value;

            yearValue  = GenDate.Year(absTicks, coords.x);
            yearBuffer = yearValue.ToString();

            quadrumValue = GenDate.Quadrum(absTicks, coords.x);

            dayValue  = GenDate.DayOfQuadrum(absTicks, coords.x) + 1;
            dayBuffer = dayValue.ToString();

            hourValue  = GenDate.HourOfDay(absTicks, coords.x);
            hourBuffer = hourValue.ToString();

            Log.Debug($"Set defaults to {dayBuffer} {quadrumValue}, {yearBuffer} at {hourBuffer}.");
            Log.Debug($"Should have set to {GenDate.DateFullStringWithHourAt(absTicks, coords)}.");
        }
        private string CreateImageNameDateTime()
        {
            int   tick      = Find.TickManager.TicksAbs;
            float longitude = Find.WorldGrid.LongLatOf(map.Tile).x;
            int   year      = GenDate.Year(tick, longitude);
            int   quadrum   = MoreGenDate.QuadrumInteger(tick, longitude);
            int   day       = GenDate.DayOfQuadrum(tick, longitude) + 1;
            int   hour      = GenDate.HourInteger(tick, longitude);

            return("rimworld-" + Find.World.info.seedString + "-" + map.Tile + "-" + year + "-" + quadrum + "-" + ((day < 10) ? "0" : "") + day + "-" + ((hour < 10) ? "0" : "") + hour);
        }
Ejemplo n.º 3
0
        public override void Tick(int currentTick)
        {
            base.Tick(currentTick);

            int ticks = Find.TickManager.TicksAbs;

            if (ticks % GenDate.TicksPerHour != 0 || Find.CurrentMap == null || _store == null)
            {
                return;
            }

            Vector2 location     = Find.WorldGrid.LongLatOf(Find.CurrentMap.Tile);
            Quadrum quadrum      = GenDate.Quadrum(ticks, location.x);
            int     dayOfQuadrum = GenDate.DayOfQuadrum(ticks, location.x); // zero based
            int     hour         = GenDate.HourOfDay(ticks, location.x);

            // check settlement
            int     startTicks        = Find.TickManager.gameStartAbsTick;
            Quadrum settlementQuadrum = GenDate.Quadrum(startTicks, 0);
            int     settlementDay     = GenDate.DayOfQuadrum(startTicks, 0); // zero based
            int     settlementYears   = Mathf.RoundToInt(GenDate.YearsPassedFloat);

            if ((hour == 0 || _store.Settlement.Start() == hour) && settlementQuadrum == quadrum && settlementDay == dayOfQuadrum)
            {
                if (hour == 0)
                {
                    Messages.Message("DM.Message.TodaySettlement".Translate(settlementYears), MessageTypeDefOf.PositiveEvent);
                }
                else
                {
                    StartParty("DM.Letter.SettlementParty".Translate(), new List <Pawn>(), _store.Settlement == Duration.AllDay);
                }
            }

            // check built in days
            if (hour == 0 || _store.Birthdays.Start() == hour || _store.MarriageAnniversaries.Start() == hour || _store.LoversAnniversaries.Start() == hour)
            {
                Dictionary <Pawn, DirectPawnRelation> handledRelations = new Dictionary <Pawn, DirectPawnRelation>();

                var colonists = Find.CurrentMap.mapPawns.PawnsInFaction(Faction.OfPlayer);
                foreach (var colonist in colonists)
                {
                    if (colonist.Dead || !colonist.RaceProps.Humanlike)
                    {
                        continue;
                    }

                    // check marriage
                    List <DirectPawnRelation> marriageRelations = colonist.relations.DirectRelations.FindAll(x => x.def == PawnRelationDefOf.Spouse);
                    foreach (DirectPawnRelation relation in marriageRelations)
                    {
                        if (handledRelations.ContainsKey(colonist) || handledRelations.ContainsKey(relation.otherPawn))
                        {
                            continue;
                        }
                        handledRelations.Add(colonist, relation);
                        int     startTick    = relation.startTicks + startTicks;
                        int     startDay     = GenDate.DayOfQuadrum(startTick, location.x);
                        Quadrum startQuadrum = GenDate.Quadrum(startTick, location.x);
                        if (startDay == dayOfQuadrum && startQuadrum == quadrum)
                        {
                            if (hour == 0)
                            {
                                Messages.Message("DM.Message.TodayMarriageAnniversary".Translate(colonist.Name.ToStringShort, relation.otherPawn.Name.ToStringShort), MessageTypeDefOf.PositiveEvent);
                            }
                            else if (_store.MarriageAnniversaries.Start() == hour)
                            {
                                StartParty("DM.Letter.MarriageAnniversaryParty".Translate(colonist.Name.ToStringShort, relation.otherPawn.Name.ToStringShort), new List <Pawn> {
                                    colonist, relation.otherPawn
                                }, _store.MarriageAnniversaries == Duration.AllDay, colonist);
                            }
                        }
                    }

                    // check relationship
                    List <DirectPawnRelation> loverRelations = colonist.relations.DirectRelations.FindAll(x => x.def == PawnRelationDefOf.Lover);
                    foreach (DirectPawnRelation relation in loverRelations)
                    {
                        if (handledRelations.ContainsKey(colonist) || handledRelations.ContainsKey(relation.otherPawn))
                        {
                            continue;
                        }
                        handledRelations.Add(colonist, relation);
                        int     startTick    = relation.startTicks + startTicks;
                        int     startDay     = GenDate.DayOfQuadrum(startTick, location.x);
                        Quadrum startQuadrum = GenDate.Quadrum(startTick, location.x);
                        if (startDay == dayOfQuadrum && startQuadrum == quadrum)
                        {
                            if (hour == 0)
                            {
                                Messages.Message("DM.Message.TodayRelationshipAnniversary".Translate(colonist.Name.ToStringShort, relation.otherPawn.Name.ToStringShort), MessageTypeDefOf.PositiveEvent);
                            }
                            else if (_store.LoversAnniversaries.Start() == hour)
                            {
                                StartParty("DM.Letter.RelationshipAnniversaryParty".Translate(colonist.Name.ToStringShort, relation.otherPawn.Name.ToStringShort), new List <Pawn> {
                                    colonist, relation.otherPawn
                                }, _store.LoversAnniversaries == Duration.AllDay, colonist);
                            }
                        }
                    }

                    // check birthday
                    long    birthdayTick = colonist.ageTracker.BirthAbsTicks;
                    int     birthDate    = GenDate.DayOfQuadrum(birthdayTick, location.x); // zero based
                    Quadrum birthQuadrum = GenDate.Quadrum(birthdayTick, location.x);
                    int     colonistAge  = Mathf.RoundToInt(colonist.ageTracker.AgeChronologicalYearsFloat);
                    if (birthDate == dayOfQuadrum && birthQuadrum == quadrum)
                    {
                        if (hour == 0)
                        {
                            Messages.Message("DM.Message.TodayBirthday".Translate(colonist.Name.ToStringShort, colonistAge), MessageTypeDefOf.PositiveEvent);
                        }
                        else if (_store.Birthdays.Start() == hour)
                        {
                            StartParty("DM.Letter.BirthdayParty".Translate(colonist.Name.ToStringShort), new List <Pawn>(), _store.Birthdays == Duration.AllDay);
                        }
                    }
                }
            }

            // check custom days
            var matchedEvents = _store.MatteredDays.FindAll(x => x.DayOfQuadrum - 1 == dayOfQuadrum && x.Quadrum == quadrum);

            if (matchedEvents.Count == 0)
            {
                return;
            }

            foreach (MatteredDay day in matchedEvents)
            {
                if (hour == 0)
                {
                    Messages.Message("DM.Message.TodayCustomDay".Translate(day.Name), MessageTypeDefOf.PositiveEvent);
                }
                else if (day.Duration.Start() == hour)
                {
                    StartParty("DM.Letter.CustomDayParty".Translate(day.Name), new List <Pawn>(), day.Duration == Duration.AllDay);
                }
            }
        }
Ejemplo n.º 4
0
            public static void Fix(Pawn_AgeTracker __instance, ref int __result)
            {
                long birthAbsTicksInt = (long)BIRTH_ABS_TICKS_INT_FIELD.GetValue(__instance);

                __result = GenDate.DayOfQuadrum(birthAbsTicksInt, 0f);
            }
Ejemplo n.º 5
0
        public DialogList(ListType type)
        {
            forcePause = true;
            doCloseX   = true;
            // closeOnEscapeKey = true;
            closeOnClickedOutside   = true;
            absorbInputAroundWindow = true;

            int gameStartTick = Find.TickManager.gameStartAbsTick;
            var colonists     = Find.CurrentMap.mapPawns.PawnsInFaction(Faction.OfPlayer);

            switch (type)
            {
            case ListType.Birthdays:
                foreach (var colonist in colonists)
                {
                    if (colonist.Dead || colonist.NonHumanlikeOrWildMan())
                    {
                        continue;
                    }

                    long    birthdayTick = colonist.ageTracker.BirthAbsTicks;
                    int     birthDate    = GenDate.DayOfQuadrum(birthdayTick, 0); // zero based
                    Quadrum birthQuadrum = GenDate.Quadrum(birthdayTick, 0);
                    _list.Add(new QuadrumDayPair("DM.Letter.BirthdayParty".Translate(colonist.Name.ToStringShort), birthQuadrum, birthDate + 1));
                }
                break;

            case ListType.Relationships:
                Dictionary <Pawn, DirectPawnRelation> loverRelations = new Dictionary <Pawn, DirectPawnRelation>();
                foreach (var colonist in colonists)
                {
                    if (colonist.Dead || colonist.NonHumanlikeOrWildMan())
                    {
                        continue;
                    }

                    List <DirectPawnRelation> relations = colonist.relations.DirectRelations.FindAll(x => x.def == PawnRelationDefOf.Lover);
                    foreach (DirectPawnRelation relation in relations)
                    {
                        if (loverRelations.ContainsKey(colonist) || loverRelations.ContainsKey(relation.otherPawn))
                        {
                            continue;
                        }
                        loverRelations.Add(colonist, relation);
                        int     startTick    = relation.startTicks + gameStartTick;
                        int     startDay     = GenDate.DayOfQuadrum(startTick, 0);
                        Quadrum startQuadrum = GenDate.Quadrum(startTick, 0);
                        _list.Add(new QuadrumDayPair("DM.Letter.RelationshipAnniversaryParty".Translate(colonist.Name.ToStringShort, relation.otherPawn.Name.ToStringShort), startQuadrum, startDay + 1));
                    }
                }
                break;

            case ListType.Marriages:
                Dictionary <Pawn, DirectPawnRelation> marriageRelations = new Dictionary <Pawn, DirectPawnRelation>();
                foreach (var colonist in colonists)
                {
                    if (colonist.Dead || colonist.NonHumanlikeOrWildMan())
                    {
                        continue;
                    }

                    List <DirectPawnRelation> relations = colonist.relations.DirectRelations.FindAll(x => x.def == PawnRelationDefOf.Spouse);
                    foreach (DirectPawnRelation relation in relations)
                    {
                        if (marriageRelations.ContainsKey(colonist) || marriageRelations.ContainsKey(relation.otherPawn))
                        {
                            continue;
                        }
                        marriageRelations.Add(colonist, relation);
                        int     startTick    = relation.startTicks + gameStartTick;
                        int     startDay     = GenDate.DayOfQuadrum(startTick, 0);
                        Quadrum startQuadrum = GenDate.Quadrum(startTick, 0);
                        _list.Add(new QuadrumDayPair("DM.Letter.MarriageAnniversaryParty".Translate(colonist.Name.ToStringShort, relation.otherPawn.Name.ToStringShort), startQuadrum, startDay + 1));
                    }
                }
                break;

            default:
                break;
            }
        }
Ejemplo n.º 6
0
        public override void DoWindowContents(Rect rect)
        {
            const float scrollRectOffsetTop = ROW_HEIGHT * 2 + ROW_ADD_GAP;

            Text.Font = GameFont.Small;

            // draw event add row
            Rect rectAdd = new Rect(0f, 0f, ROW_ADD_WIDTH, ROW_HEIGHT);

            DrawRowAdd(rectAdd, () =>
            {
                _scrollPosition = new Vector2(0, ROW_HEIGHT * _store.MatteredDays.Count + ROW_HEIGHT * STATIC_ROW_COUNT - (rect.height - scrollRectOffsetTop));
            });

            // draw header
            Rect rectHeader = new Rect(0f, ROW_HEIGHT + ROW_ADD_GAP, rect.width - SCROLLBAR_WIDTH, ROW_HEIGHT);

            DrawHeader(rectHeader);

            // draw list
            if (_store.MatteredDays == null)
            {
                _store.MatteredDays = new List <MatteredDay>();
            }
            List <MatteredDay> list = _store.MatteredDays;

            Rect scrollRect = new Rect(0f, scrollRectOffsetTop, rect.width, rect.height - scrollRectOffsetTop);
            Rect viewRect   = new Rect(0f, 0f, scrollRect.width - SCROLLBAR_WIDTH, ROW_HEIGHT * list.Count + ROW_HEIGHT * STATIC_ROW_COUNT);

            Widgets.BeginScrollView(scrollRect, ref _scrollPosition, viewRect);
            Vector2 cur = Vector2.zero;

            // settlement
            int     startTicks        = Find.TickManager.gameStartAbsTick;
            Quadrum settlementQuadrum = GenDate.Quadrum(startTicks, 0);
            int     settlementDay     = GenDate.DayOfQuadrum(startTicks, 0) + 1;

            DrawRowWithFixedDate(new Rect(0f, cur.y, viewRect.width, ROW_HEIGHT), ref cur, "DM.Tab.BuiltIn.Settlement".Translate(), settlementQuadrum, settlementDay, _store.Settlement, () =>
            {
                FloatMenuUtility.MakeMenu(Enum.GetValues(typeof(Duration)).Cast <Duration>(), duration => duration.Label(), duration => delegate
                {
                    _store.Settlement = duration;
                });
            });

            // birthdays
            DrawRowWithNoDate(new Rect(0f, cur.y, viewRect.width, ROW_HEIGHT), ref cur, "DM.Tab.BuiltIn.ChronologicalBirthday".Translate(), _store.Birthdays, () =>
            {
                FloatMenuUtility.MakeMenu(Enum.GetValues(typeof(Duration)).Cast <Duration>(), duration => duration.Label(), duration => delegate
                {
                    _store.Birthdays = duration;
                });
            }, "DM.Tab.Misc.ShowAll".Translate(), () =>
            {
                Find.WindowStack.Add(new DialogList(DialogList.ListType.Birthdays));
            });

            // lovers anniversaries
            DrawRowWithNoDate(new Rect(0f, cur.y, viewRect.width, ROW_HEIGHT), ref cur, "DM.Tab.BuiltIn.RelationshipAnniversary".Translate(), _store.LoversAnniversaries, () =>
            {
                FloatMenuUtility.MakeMenu(Enum.GetValues(typeof(Duration)).Cast <Duration>(), duration => duration.Label(), duration => delegate
                {
                    _store.LoversAnniversaries = duration;
                });
            }, "DM.Tab.Misc.ShowAll".Translate(), () =>
            {
                Find.WindowStack.Add(new DialogList(DialogList.ListType.Relationships));
            });

            // marriage anniversaries
            DrawRowWithNoDate(new Rect(0f, cur.y, viewRect.width, ROW_HEIGHT), ref cur, "DM.Tab.BuiltIn.MarriageAnniversary".Translate(), _store.MarriageAnniversaries, () =>
            {
                FloatMenuUtility.MakeMenu(Enum.GetValues(typeof(Duration)).Cast <Duration>(), duration => duration.Label(), duration => delegate
                {
                    _store.MarriageAnniversaries = duration;
                });
            }, "DM.Tab.Misc.ShowAll".Translate(), () =>
            {
                Find.WindowStack.Add(new DialogList(DialogList.ListType.Marriages));
            });

            for (int index = 0; index < list.Count; index++)
            {
                if (list.Count <= index)
                {
                    break;
                }

                var row = new Rect(0f, cur.y, viewRect.width, ROW_HEIGHT);

                Widgets.DrawHighlightIfMouseover(row);
                GUI.color = new Color(1f, 1f, 1f, 0.2f);
                Widgets.DrawLineHorizontal(0f, cur.y, viewRect.width);
                GUI.color = Color.white;

                DrawRow(row, list[index], index);

                cur.y += ROW_HEIGHT;
            }
            Widgets.EndScrollView();
        }