diff --git a/About/Manifest.xml b/About/Manifest.xml index a4e9a37..69b6b5f 100644 --- a/About/Manifest.xml +++ b/About/Manifest.xml @@ -1,7 +1,7 @@ aamu.diary - 1.0.1 + 1.1.0
  • Ludeon.RimWorld
  • brrainz.harmony
  • @@ -9,6 +9,7 @@
  • Ludeon.RimWorld
  • brrainz.harmony
  • +
  • neptimus7.progressrenderer
  • true diff --git a/Assemblies/Diary.dll b/Assemblies/Diary.dll index f4aa3bf..8846b37 100644 Binary files a/Assemblies/Diary.dll and b/Assemblies/Diary.dll differ diff --git a/Languages/English/Keyed/Diary.xml b/Languages/English/Keyed/Diary.xml index 2f8e445..34814a2 100644 --- a/Languages/English/Keyed/Diary.xml +++ b/Languages/English/Keyed/Diary.xml @@ -25,4 +25,8 @@ Please check write access to the folder are correct au dossier or edit folder pa None Diary can write automatically logs in the Diary. You just have to set the next option to the logs which must be written automatically. Automatic log writer filter + Journal + Images + Diary is correctly connected to Progress Renderer. + Diary is not connected to Progress Renderer. If Progress Renderer is enabled, you have to place it before Diary. \ No newline at end of file diff --git a/Languages/French/Keyed/Diary.xml b/Languages/French/Keyed/Diary.xml index c72ea14..107b5c7 100644 --- a/Languages/French/Keyed/Diary.xml +++ b/Languages/French/Keyed/Diary.xml @@ -25,4 +25,8 @@ Veuillez vérifier que les droits d'accès au dossier sont corrects ou modifier Aucun Diary peut écrire automatiquement les informations dans votre Journal. Vous devez simplement sélectionner via la prochaine option ce que vous voulez que le mod écrive automatiquement. Filtre d'écriture automatique des informations + Journal + Images + Diary est correctement connecté à Progress Renderer. + Diary n'est pas connecté à Progress Renderer. Si Progress Renderer est activé, veuillez le placer avant Diary. \ No newline at end of file diff --git a/Source/Diary.cs b/Source/Diary.cs index 4c8e5c7..6a39210 100644 --- a/Source/Diary.cs +++ b/Source/Diary.cs @@ -13,6 +13,7 @@ using Verse.AI; using Verse.Sound; using RimWorld.Planet; +using static UnityEngine.UI.Image; namespace Diary { @@ -21,10 +22,37 @@ public class Diary : Mod DiarySettings settings; public Diary(ModContentPack content) : base(content) + { + var harmony = new Harmony("aamulumi.diary"); + + Init(harmony); + + if (ModLister.GetActiveModWithIdentifier("neptimus7.progressrenderer") != null) + { + InitWithProgressRenderer(harmony); + } + } + + public void Init(Harmony harmony) { settings = GetSettings(); - new Harmony("aamulumi.diary").PatchAll(); + harmony.PatchAll(); + } + + public void InitWithProgressRenderer(Harmony harmony) + { + + var PR_RenderManager = System.Type.GetType("ProgressRenderer.MapComponent_RenderManager, Progress-Renderer"); + + if (PR_RenderManager != null) + { + var createFilePath = PR_RenderManager.GetMethod("CreateFilePath", AccessTools.all); + + harmony.Patch(createFilePath, postfix: new HarmonyMethod(typeof(ListenProgressRenderer_CreateFilePath).GetMethod("Postfix", AccessTools.all))); + + settings.ConnectedToProgressRenderer = true; + } } public override void DoSettingsWindowContents(Rect inRect) diff --git a/Source/DiaryService.cs b/Source/DiaryService.cs index 4b2de9e..c45715f 100644 --- a/Source/DiaryService.cs +++ b/Source/DiaryService.cs @@ -13,12 +13,14 @@ namespace Diary public class DiaryService : GameComponent { private Dictionary entries; - private Dictionary> images; + private Dictionary> imagesPerDay; + private List allImages; public DiaryService(Game game) { entries = new Dictionary(); - images = new Dictionary>(); + imagesPerDay = new Dictionary>(); + allImages = new List(); } private string[] GetTextEntriesToExport() @@ -120,6 +122,8 @@ public void WriteEntryNow(string data) public void AppendEntryNow(string data, bool onNewLine = true, bool writeCurrentHour = true) { string key = GetDictionaryKey(TimeTools.GetCurrentDay(), TimeTools.GetCurrentQuadrum(), TimeTools.GetCurrentYear()); + string currentEntry = entries.TryGetValue(key); + if (writeCurrentHour) { @@ -129,30 +133,55 @@ public void AppendEntryNow(string data, bool onNewLine = true, bool writeCurrent { data = $"\n{data}"; } + if (currentEntry != null) + { + data = $"{currentEntry}{data}"; + } - entries.SetOrAdd(key, $"{entries[key]}{data}"); + entries.SetOrAdd(key, data); } - public List ReadImages(int day, Quadrum quadrum, int year) + public List GetAllImages() { - DefaultMessage defaultMessageSetting = LoadedModManager.GetMod().GetSettings().DefaultMessage; + return allImages; + } + + public int GetIndexForAllImages(int day, Quadrum quadrum, int year) + { + for (int i = 0; i < allImages.Count; i++) + { + DiaryImageEntry entry = allImages[i]; + + if (entry.Year > year || (entry.Year == year && (entry.Quadrum > quadrum || (entry.Quadrum == quadrum && entry.Days >= day)))) + { + return i; + } + } - return images.TryGetValue(GetDictionaryKey(day, quadrum, year)); + return -1; + } + + public List ReadImages(int day, Quadrum quadrum, int year) + { + return imagesPerDay.TryGetValue(GetDictionaryKey(day, quadrum, year)); } public void AddImageNow(string path) { string key = GetDictionaryKey(TimeTools.GetCurrentDay(), TimeTools.GetCurrentQuadrum(), TimeTools.GetCurrentYear()); - List currentImages = images.TryGetValue(key); + List currentImages = imagesPerDay.TryGetValue(key); if (currentImages == null) { currentImages = new List(); } - currentImages.Add(new DiaryImageEntry(path, TimeTools.GetCurrentHour())); + DiaryImageEntry entryToAdd = new DiaryImageEntry(path, TimeTools.GetCurrentHour(), TimeTools.GetCurrentDay(), TimeTools.GetCurrentQuadrum(), TimeTools.GetCurrentYear()); + + currentImages.Add(entryToAdd); - images.SetOrAdd(key, currentImages); + imagesPerDay.SetOrAdd(key, currentImages); + allImages.Add(entryToAdd); } public void Export() @@ -201,8 +230,36 @@ public override void ExposeData() base.ExposeData(); Scribe_Collections.Look(ref entries, "entries", LookMode.Value, LookMode.Value); + Scribe_Collections.Look(ref allImages, "allImages", LookMode.Deep); + + if (Scribe.mode == LoadSaveMode.PostLoadInit) + { + if (entries == null) + { + entries = new Dictionary(); + } + if (allImages == null) + { + allImages = new List(); + imagesPerDay = new Dictionary>(); + } - Log.Message(entries.ToStringFullContents()); + foreach (DiaryImageEntry entry in allImages) + { + string key = GetDictionaryKey(entry.Days, entry.Quadrum, entry.Year); + + List currentImages = imagesPerDay.TryGetValue(key); + + if (currentImages == null) + { + currentImages = new List(); + } + + currentImages.Add(entry); + + imagesPerDay.SetOrAdd(key, currentImages); + } + } } public override void FinalizeInit() diff --git a/Source/DiarySettings.cs b/Source/DiarySettings.cs index 68aba91..e8ad2e8 100644 --- a/Source/DiarySettings.cs +++ b/Source/DiarySettings.cs @@ -15,6 +15,8 @@ public class DiarySettings : ModSettings private LogWriterFilter logWriterFilter; private LogFilter defaultLogFilter; + public bool ConnectedToProgressRenderer; + public string FolderPath { get { return folderPath; } @@ -44,6 +46,8 @@ public override void ExposeData() { base.ExposeData(); + ConnectedToProgressRenderer = false; + Scribe_Values.Look(ref folderPath, "folderPath", Application.dataPath); Scribe_Values.Look(ref exportFormat, "exportFormat", ExportFormat.Text); Scribe_Values.Look(ref defaultMessage, "defaultMessage", DefaultMessage.Empty); @@ -130,6 +134,15 @@ public void DoSettingsWindowContents(Rect inRect) Find.WindowStack.Add(new FloatMenu(list)); } + if (ConnectedToProgressRenderer) + { + listingStandard.Label("Diary_Connected_To_Progress_Renderer".Translate()); + } + else + { + listingStandard.Label("Diary_Not_Connected_To_Progress_Renderer".Translate()); + } + listingStandard.End(); } } diff --git a/Source/DiaryTimeTools.cs b/Source/DiaryTimeTools.cs index 681996d..f5683d9 100644 --- a/Source/DiaryTimeTools.cs +++ b/Source/DiaryTimeTools.cs @@ -42,6 +42,11 @@ public static Vector2 GetCurrentLocation() return vector; } + public static int GetCurrentTicks() + { + return Find.TickManager.TicksAbs; + } + public static int GetCurrentHour() { return GenDate.HourOfDay(Find.TickManager.TicksAbs, TimeTools.GetCurrentLocation().x); diff --git a/Source/DiaryTypes.cs b/Source/DiaryTypes.cs index 7a6f38f..b339e40 100644 --- a/Source/DiaryTypes.cs +++ b/Source/DiaryTypes.cs @@ -86,15 +86,34 @@ public static string GetLogWriterFilterName(LogWriterFilter f) } } - public class DiaryImageEntry + public class DiaryImageEntry : IExposable { public string Path; public int Hours; + public int Days; + public Quadrum Quadrum; + public int Year; - public DiaryImageEntry(string path, int hours) + public DiaryImageEntry() + { + } + + public DiaryImageEntry(string path, int hours, int day, Quadrum quadrum, int year) { Path = path; Hours = hours; + Days = day; + Quadrum = quadrum; + Year = year; + } + + public void ExposeData() + { + Scribe_Values.Look(ref Path, "Path"); + Scribe_Values.Look(ref Hours, "Hours"); + Scribe_Values.Look(ref Days, "Days"); + Scribe_Values.Look(ref Quadrum, "Quadrum"); + Scribe_Values.Look(ref Year, "Year"); } } } diff --git a/Source/GUIDraggableTexture.cs b/Source/GUIDraggableTexture.cs index 3b10063..692f041 100644 --- a/Source/GUIDraggableTexture.cs +++ b/Source/GUIDraggableTexture.cs @@ -35,6 +35,7 @@ public class GUIDraggableTexture private Rect outerRect; private Rect initialOuterRect; private bool mustRecomputeOuterRect; + private bool firstLoading; public GUIDraggableTexture() { @@ -42,6 +43,7 @@ public GUIDraggableTexture() imageRect = new Rect(0.0f, 0.0f, 1.0f, 1.0f); mustRecomputeOuterRect = false; + firstLoading = true; } public bool HasImageLoaded() @@ -56,7 +58,6 @@ public bool IsLoading() public void LoadTexture(string path) { - Log.Message($"Laod {path}"); imageLoading = true; imageLoadRequest = UnityWebRequestTexture.GetTexture($"file://{path}"); @@ -68,7 +69,11 @@ public void LoadTexture(string path) imageHeight = currentImageDisplayed.height; imageLoading = false; - mustRecomputeOuterRect = true; + if (firstLoading) + { + mustRecomputeOuterRect = true; + } + firstLoading = false; }; } diff --git a/Source/MainTabWindow_Diary.cs b/Source/MainTabWindow_Diary.cs index b500a39..86d5f93 100644 --- a/Source/MainTabWindow_Diary.cs +++ b/Source/MainTabWindow_Diary.cs @@ -30,7 +30,8 @@ public class MainTabWindow_Diary : MainTabWindow private bool imageDisplayMode; private GUIDraggableTexture draggableImage; private List dayImages; - private int selectedDayImagesIndex; + private List allImages; + private int selectedAllImagesIndex; private readonly List fastHourStrings; private Dictionary truncationCache = new Dictionary(); @@ -88,6 +89,8 @@ public MainTabWindow_Diary() imageDisplayMode = false; logFilter = settings.DefaultLogFilter; draggableImage = new GUIDraggableTexture(); + selectedAllImagesIndex = -1; + allImages = Current.Game.GetComponent().GetAllImages(); } public bool CanAccessToPreviousDay() @@ -95,11 +98,21 @@ public bool CanAccessToPreviousDay() return day != TimeTools.GetMinimumDay(quadrum, year) || quadrum != TimeTools.GetMinimumQuadrum(year) || year != TimeTools.GetMinimumYear(); } + public bool CanAccessToPreviousEntry() + { + return allImages != null && (selectedAllImagesIndex > 0); + } + public bool CanAccessToNextDay() { return day != TimeTools.GetMaximumDay(quadrum, year) || quadrum != TimeTools.GetMaximumQuadrum(year) || year != TimeTools.GetMaximumYear(); } + public bool CanAccessToNextEntry() + { + return allImages != null && (selectedAllImagesIndex < allImages.Count - 1); + } + public void SetCurrentDateToPreviousDay() { if (!CanAccessToPreviousDay()) @@ -260,6 +273,55 @@ private List GetLogsToDisplay() return logs; } + private void SetSelectedAllImagesIndex(int index) + { + if (allImages == null || index >= allImages.Count) + { + return; + } + + int previousSelectedAllImagesIndex = selectedAllImagesIndex; + + selectedAllImagesIndex = index; + + if (previousSelectedAllImagesIndex == -1) + { + dayImages = Current.Game.GetComponent().ReadImages(this.day, this.quadrum, this.year); + } + + if (selectedAllImagesIndex != -1) + { + draggableImage.LoadTexture(allImages[selectedAllImagesIndex].Path); + + DiaryImageEntry entry = allImages[selectedAllImagesIndex]; + + bool dateChanged = false; + + if (day != entry.Days) + { + day = entry.Days; + dateChanged = true; + } + + if (quadrum != entry.Quadrum) + { + quadrum = entry.Quadrum; + dateChanged = true; + } + + if (year != entry.Year) + { + year = entry.Year; + dateChanged = true; + } + + if (dateChanged) + { + dayImages = Current.Game.GetComponent().ReadImages(this.day, this.quadrum, this.year); + } + } + } + private void DoArchivableRow(Rect rect, IArchivable archivable, int index) { if (index % 2 == 1) @@ -388,27 +450,36 @@ public override void DoWindowContents(Rect inRect) Text.Font = GameFont.Small; Widgets.BeginGroup(inRect); - - if (Widgets.ButtonText(new Rect(0.0f, dateRect.yMin, widthPerButton / 2, dateRect.yMax), "IMG")) + if (allImages.Count > 0 && Widgets.ButtonText(new Rect(0.0f, dateRect.yMin, widthPerButton / 2, dateRect.yMax), imageDisplayMode ? "Diary".Translate() : "Diary_Images".Translate())) { imageDisplayMode = !imageDisplayMode; - dayImages = Current.Game.GetComponent().ReadImages(this.day, this.quadrum, this.year); - selectedDayImagesIndex = 0; - if (dayImages.Count > 0) + + SetSelectedAllImagesIndex(Current.Game.GetComponent().GetIndexForAllImages(this.day, this.quadrum, this.year)); + } + + if (imageDisplayMode) + { + if (CanAccessToPreviousEntry()) { - draggableImage.LoadTexture(dayImages[0].Path); + if (Widgets.ButtonText(new Rect(widthPerButton * 0.5f, dateRect.yMin, widthPerButton / 2, dateRect.yMax), "<")) + { + SetSelectedAllImagesIndex(selectedAllImagesIndex - 1); + } } } - - if (CanAccessToPreviousDay()) + else { - if (Widgets.ButtonText(new Rect(widthPerButton * 0.5f, dateRect.yMin, widthPerButton / 2, dateRect.yMax), "<")) + if (CanAccessToPreviousDay()) { - SetCurrentDateToPreviousDay(); + if (Widgets.ButtonText(new Rect(widthPerButton * 0.5f, dateRect.yMin, widthPerButton / 2, dateRect.yMax), "<")) + { + SetCurrentDateToPreviousDay(); + } } + } - if (Widgets.ButtonText(new Rect(widthPerButton * 1, dateRect.yMin, widthPerButton, dateRect.yMax), Find.ActiveLanguageWorker.OrdinalNumber(this.day + 1))) + if (Widgets.ButtonText(new Rect(imageDisplayMode ? widthPerButton * 1.5f : widthPerButton * 1f, dateRect.yMin, imageDisplayMode ? widthPerButton / 2 : widthPerButton, dateRect.yMax), Find.ActiveLanguageWorker.OrdinalNumber(this.day + 1))) { List list = new List(); for (int i = TimeTools.GetMinimumDay(quadrum, year); i <= TimeTools.GetMaximumDay(quadrum, year); i++) @@ -451,32 +522,54 @@ public override void DoWindowContents(Rect inRect) Find.WindowStack.Add(new FloatMenu(list)); } - if (CanAccessToNextDay()) + if (imageDisplayMode) { - if (Widgets.ButtonText(new Rect(widthPerButton * 4f, dateRect.yMin, widthPerButton / 2, dateRect.yMax), ">")) + if (CanAccessToNextEntry()) { - SetCurrentDateToNextDay(); + if (Widgets.ButtonText(new Rect(widthPerButton * 4f, dateRect.yMin, widthPerButton / 2, dateRect.yMax), ">")) + { + SetSelectedAllImagesIndex(selectedAllImagesIndex + 1); + } + } + } + else + { + if (CanAccessToNextDay()) + { + if (Widgets.ButtonText(new Rect(widthPerButton * 4f, dateRect.yMin, widthPerButton / 2, dateRect.yMax), ">")) + { + SetCurrentDateToNextDay(); + } } } + if (imageDisplayMode) { - DiaryImageEntry d = dayImages[selectedDayImagesIndex]; - - if (d != null && Widgets.ButtonText(new Rect(widthPerButton * 4.5f, dateRect.yMin, widthPerButton / 2, dateRect.yMax), fastHourStrings[d.Hours])) + if (dayImages != null && dayImages.Count > 0) { + DiaryImageEntry d = allImages[selectedAllImagesIndex]; - List list = new List(); - for (int i = 0; i < dayImages.Count; i++) + if (d != null && Widgets.ButtonText(new Rect(widthPerButton * 1f, dateRect.yMin, widthPerButton / 2, dateRect.yMax), fastHourStrings[d.Hours])) { - int current = i; - list.Add(new FloatMenuOption(fastHourStrings[dayImages[current].Hours], delegate + + List list = new List(); + for (int i = 0; i < dayImages.Count; i++) { - selectedDayImagesIndex = current; - draggableImage.LoadTexture(dayImages[current].Path); - })); + int current = i; + list.Add(new FloatMenuOption(fastHourStrings[dayImages[current].Hours], delegate + { + int newIndex = allImages.IndexOf(dayImages[current]); + + if (newIndex != -1) + { + selectedAllImagesIndex = newIndex; + draggableImage.LoadTexture(allImages[newIndex].Path); + } + })); + } + Find.WindowStack.Add(new FloatMenu(list)); } - Find.WindowStack.Add(new FloatMenu(list)); } DoImageDisplayContents(new Rect(0f, dateRect.yMax + 10f, inRect.width, inRect.height - dateRect.yMax)); diff --git a/Source/Patches/ListenProgressRenderer_CreateFilePath.cs b/Source/Patches/ListenProgressRenderer_CreateFilePath.cs index 6c6c1c9..eb9b6c6 100644 --- a/Source/Patches/ListenProgressRenderer_CreateFilePath.cs +++ b/Source/Patches/ListenProgressRenderer_CreateFilePath.cs @@ -5,12 +5,10 @@ namespace Diary { - [HarmonyPatch(typeof(ProgressRenderer.MapComponent_RenderManager), "CreateFilePath")] public static class ListenProgressRenderer_CreateFilePath { static void Postfix(ref string __result) { - Log.Message("Image created"); Current.Game.GetComponent().AddImageNow(__result); } }