Skip to content

Commit

Permalink
feat(mod): Add buttons to open and change images directory
Browse files Browse the repository at this point in the history
  • Loading branch information
AamuLumi committed Jun 16, 2023
1 parent 287b9ca commit cba5f09
Show file tree
Hide file tree
Showing 9 changed files with 126 additions and 25 deletions.
2 changes: 1 addition & 1 deletion About/Manifest.xml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<Manifest>
<identifier>aamu.diary</identifier>
<version>1.1.5</version>
<version>1.1.6</version>
<dependencies>
<li>Ludeon.RimWorld</li>
<li>brrainz.harmony</li>
Expand Down
Binary file modified Assemblies/Diary.dll
Binary file not shown.
5 changes: 5 additions & 0 deletions CHANGELOG
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
# 1.1.6 (06/16/2023)

- Add a button to open the images directory
- Add a button to change the images directory

# 1.1.5 (05/13/2013)

- Fix RimWar compatibility by removing all hidden messages from Diary
Expand Down
25 changes: 13 additions & 12 deletions Languages/English/Keyed/Diary.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@
<Diary_Export_Successful>Export successful!</Diary_Export_Successful>
<Diary_Directory_Not_Found>Error during export : folder path doesn't exist.

Please create the folder or edit folder path in mod settings.
Please create the folder or edit folder path in mod settings.
</Diary_Directory_Not_Found>
<Diary_Error_During_Export>Error during export : an error happened.

Please check write access to the folder are correct or edit folder path in mod settings.
Please check write access to the folder are correct or edit folder path in mod settings.
</Diary_Error_During_Export>
<Diary_Export_Format>Export file format</Diary_Export_Format>
<Diary_Format_Text>Text (.txt)</Diary_Format_Text>
Expand All @@ -26,23 +26,24 @@
<Diary_Chats>Chats</Diary_Chats>
<Diary_Events>Events</Diary_Events>
<Diary_None>None</Diary_None>
<Diary_Export_Description_With_Events>Export description with events
</Diary_Export_Description_With_Events>
<Diary_Log_Writer_Filter_Explanation>Diary can write automatically logs in the Diary. You just have to set the next
option to the logs which must be written automatically.
</Diary_Log_Writer_Filter_Explanation>
<Diary_Export_Description_With_Events>Export description with events</Diary_Export_Description_With_Events>
<Diary_Log_Writer_Filter_Explanation>Diary can write automatically logs in the Diary. You just have to set the next option to the logs which must be written automatically.</Diary_Log_Writer_Filter_Explanation>
<Diary_Log_Writer_Filter>Automatic log writer filter</Diary_Log_Writer_Filter>
<Diary>Journal</Diary>
<Diary_Images>Images</Diary_Images>
<Diary_Connected_To_Progress_Renderer>Diary is correctly connected to Progress Renderer.
</Diary_Connected_To_Progress_Renderer>
<Diary_Not_Connected_To_Progress_Renderer>Diary is not connected to Progress Renderer. If Progress Renderer is
enabled, you have to place it before Diary.
</Diary_Not_Connected_To_Progress_Renderer>
<Diary_Connected_To_Progress_Renderer>Diary is correctly connected to Progress Renderer.</Diary_Connected_To_Progress_Renderer>
<Diary_Not_Connected_To_Progress_Renderer>Diary is not connected to Progress Renderer. If Progress Renderer is enabled, you have to place it before Diary.</Diary_Not_Connected_To_Progress_Renderer>
<Diary_Automatic_Export>Diary automatic export</Diary_Automatic_Export>
<Diary_Automatic_Export_Enabled>Auto export enabled</Diary_Automatic_Export_Enabled>
<Diary_Automatic_Export_Period>Export automatically the diary :</Diary_Automatic_Export_Period>
<Diary_Every_Day>Everyday</Diary_Every_Day>
<Diary_Every_Week>Every week</Diary_Every_Week>
<Diary_Every_Month>Every month</Diary_Every_Month>
<Diary_Open_Screenshot_Folder>Open screenshot folder</Diary_Open_Screenshot_Folder>
<Diary_Edit_Screenshot_Folder>Edit screenshot folder</Diary_Edit_Screenshot_Folder>
<Diary_Edit_Screenshot_Folder_Explanation>You can change the images folder used by Diary.
It will move images files if exists, or simply edit paths in memory if not.

This is only a modification for Diary. You have also to edit mod configuration for ProgressRenderer.
</Diary_Edit_Screenshot_Folder_Explanation>
</LanguageData>
23 changes: 13 additions & 10 deletions Languages/French/Keyed/Diary.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,11 @@
<Diary_Export_Successful>Export réussi !</Diary_Export_Successful>
<Diary_Directory_Not_Found>Erreur pendant l'export : le chemin du dossier n'existe pas.

Veuillez créer le dossier ou modifier le chemin dans les réglages du mod.
Veuillez créer le dossier ou modifier le chemin dans les réglages du mod.
</Diary_Directory_Not_Found>
<Diary_Error_During_Export>Erreur pendant l'export : une erreur est survenue.

Veuillez vérifier que les droits d'accès au dossier sont corrects ou modifier le chemin dans les réglages du
mod.

Veuillez vérifier que les droits d'accès au dossier sont corrects ou modifier le chemin dans les réglages du mod.
</Diary_Error_During_Export>
<Diary_Export_Format>Format du fichier d'export</Diary_Export_Format>
<Diary_Format_Text>Texte (.txt)</Diary_Format_Text>
Expand All @@ -29,21 +28,25 @@
<Diary_None>Aucun</Diary_None>
<Diary_Export_Description_With_Events>Exporter les descriptions avec les événements
</Diary_Export_Description_With_Events>
<Diary_Log_Writer_Filter_Explanation>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.
<Diary_Log_Writer_Filter_Explanation>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.
</Diary_Log_Writer_Filter_Explanation>
<Diary_Log_Writer_Filter>Filtre d'écriture automatique des informations</Diary_Log_Writer_Filter>
<Diary>Journal</Diary>
<Diary_Images>Images</Diary_Images>
<Diary_Connected_To_Progress_Renderer>Diary est correctement connecté à Progress Renderer.
</Diary_Connected_To_Progress_Renderer>
<Diary_Not_Connected_To_Progress_Renderer>Diary n'est pas connecté à Progress Renderer. Si Progress Renderer est
activé, veuillez le placer avant Diary.
<Diary_Connected_To_Progress_Renderer>Diary est correctement connecté à Progress Renderer.</Diary_Connected_To_Progress_Renderer>
<Diary_Not_Connected_To_Progress_Renderer>Diary n'est pas connecté à Progress Renderer. Si Progress Renderer est activé, veuillez le placer avant Diary.
</Diary_Not_Connected_To_Progress_Renderer>
<Diary_Automatic_Export>Export automatique du Journal</Diary_Automatic_Export>
<Diary_Automatic_Export_Enabled>Export automatique activé</Diary_Automatic_Export_Enabled>
<Diary_Automatic_Export_Period>Exporter le journal automatiquement :</Diary_Automatic_Export_Period>
<Diary_Every_Day>Tous les jours</Diary_Every_Day>
<Diary_Every_Week>Toutes les semaines</Diary_Every_Week>
<Diary_Every_Month>Tous les mois</Diary_Every_Month>
<Diary_Open_Screenshot_Folder>Ouvrir le dossier des images</Diary_Open_Screenshot_Folder>
<Diary_Edit_Screenshot_Folder>Modifier le dossier des images</Diary_Edit_Screenshot_Folder>
<Diary_Edit_Screenshot_Folder_Explanation>Vous pouvez modifier le dossier d'images utilisé par Diary.
Les fichiers d'images seront déplacés s'ils existent. Dans le cas contraire, les chemins des fichiers en mémoire seront simplement modifiés.

Cette modification n'affecte que Diary. Vous devez donc aussi modifier la configuration de ProgressRenderer.
</Diary_Edit_Screenshot_Folder_Explanation>
</LanguageData>
22 changes: 21 additions & 1 deletion Source/Core/DiaryService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -283,6 +283,27 @@ public void AddImageNow(string path)
allImages.Add(entryToAdd);
}

public void ChangeImagesFolder(string newFolderPath)
{
if (!Directory.Exists(newFolderPath)) Directory.CreateDirectory(newFolderPath);

foreach (var currentImage in allImages)
{
var newFilePath = Path.Combine(newFolderPath, Path.GetFileName(currentImage.Path));

if (File.Exists(currentImage.Path)) File.Move(currentImage.Path, newFilePath);

currentImage.Path = newFilePath;
}
}

public string GetCurrentImageFolderPath()
{
if (allImages.Count > 0) return Path.GetDirectoryName(allImages[0].Path);

return "";
}

public void Export(bool silent = false)
{
var folder = Path.GetFullPath(
Expand Down Expand Up @@ -373,7 +394,6 @@ public override void ExposeData()
if (currentImages == null) currentImages = new List<DiaryImageEntry>();

currentImages.Add(entry);

imagesPerDay.SetOrAdd(key, currentImages);
}
}
Expand Down
1 change: 1 addition & 0 deletions Source/Diary.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,7 @@
<Compile Include="Core\Types.cs" />
<Compile Include="Core\TimeTools.cs" />
<Compile Include="Patches\ActionTrackers\OnPawnDowned.cs" />
<Compile Include="UI\Dialog_EditImagesPath.cs" />
<Compile Include="UI\GUIDraggableTexture.cs" />
<Compile Include="Patches\ActionTrackers\OnPawnDie.cs" />
<Compile Include="Patches\ListenArchive_Add.cs" />
Expand Down
45 changes: 45 additions & 0 deletions Source/UI/Dialog_EditImagesPath.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
using UnityEngine;
using Verse;

namespace Diary
{
public class Dialog_EditImagesPath : Window
{
private string currentPath;

public Dialog_EditImagesPath(string currentPath)
{
this.currentPath = currentPath;
doCloseButton = false;
doCloseX = true;
}

public override void OnAcceptKeyPressed()
{
var service = Current.Game.GetComponent<DiaryService>();

service.ChangeImagesFolder(currentPath);

base.OnAcceptKeyPressed();
}

public override void DoWindowContents(Rect inRect)
{
var listingStandard = new Listing_Standard();
listingStandard.Begin(inRect);

listingStandard.Label("Diary_Edit_Screenshot_Folder_Explanation".Translate());

currentPath = listingStandard.TextEntry(currentPath);

listingStandard.End();

if (!Widgets.ButtonText(
new Rect(15f, (float)(inRect.height - 35.0 - 15.0), (float)(inRect.width - 15.0 - 15.0), 35f),
"OK"))
return;

OnAcceptKeyPressed();
}
}
}
28 changes: 27 additions & 1 deletion Source/UI/MainTabWindow_Diary.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using RimWorld;
using UnityEngine;
Expand Down Expand Up @@ -425,7 +426,7 @@ public override void DoWindowContents(Rect inRect)
Text.Font = GameFont.Small;
Widgets.BeginGroup(inRect);

if (allImages.Count > 0 &&
if (settings.ConnectedToProgressRenderer && allImages.Count > 0 &&
Widgets.ButtonText(new Rect(0.0f, dateRect.yMin, widthPerButton / 2, dateRect.yMax),
imageDisplayMode ? "Diary".Translate() : "Diary_Images".Translate()))
{
Expand Down Expand Up @@ -509,6 +510,31 @@ public override void DoWindowContents(Rect inRect)
}


if (settings.ConnectedToProgressRenderer && Widgets.ButtonImage(new Rect(
widthPerButton * 5f - dateRect.yMax, dateRect.yMin, dateRect.yMax,
dateRect.yMax), ContentFinder<Texture2D>.Get("UI/Icons/Options/OptionsGeneral"), Color.white))
{
var list = new List<FloatMenuOption>();

list.Add(new FloatMenuOption("Diary_Open_Screenshot_Folder".Translate(),
delegate
{
Process.Start(
$"file://{Current.Game.GetComponent<DiaryService>().GetCurrentImageFolderPath()}");
}));

list.Add(new FloatMenuOption("Diary_Edit_Screenshot_Folder".Translate(), delegate
{
Find.WindowStack.Add(
new Dialog_EditImagesPath(Current.Game.GetComponent<DiaryService>()
.GetCurrentImageFolderPath())
);
}));

Find.WindowStack.Add(new FloatMenu(list));
}


if (imageDisplayMode)
{
if (dayImages != null && dayImages.Count > 0)
Expand Down

0 comments on commit cba5f09

Please sign in to comment.