Browse Source

Add undo support on import. Use notifications instead of logging. #8

master
chrisgregan 10 years ago
parent
commit
8ebc4efe29
  1. 20
      Assets/Fungus/Flowchart/Editor/LanguageEditor.cs
  2. 27
      Assets/Fungus/Flowchart/Scripts/Language.cs

20
Assets/Fungus/Flowchart/Editor/LanguageEditor.cs

@ -59,6 +59,8 @@ namespace Fungus
string csvData = language.GetCSVData(); string csvData = language.GetCSVData();
File.WriteAllText(path, csvData); File.WriteAllText(path, csvData);
AssetDatabase.Refresh(); AssetDatabase.Refresh();
ShowNotification(language);
} }
public virtual void ExportStandardText(Language language) public virtual void ExportStandardText(Language language)
@ -72,8 +74,10 @@ namespace Fungus
string textData = language.GetStandardText(); string textData = language.GetStandardText();
File.WriteAllText(path, textData); File.WriteAllText(path, textData);
AssetDatabase.Refresh(); AssetDatabase.Refresh();
}
ShowNotification(language);
}
public virtual void ImportStandardText(Language language) public virtual void ImportStandardText(Language language)
{ {
string path = EditorUtility.OpenFilePanel("Import Standard Text", "Assets/", "txt"); string path = EditorUtility.OpenFilePanel("Import Standard Text", "Assets/", "txt");
@ -83,7 +87,19 @@ namespace Fungus
} }
string textData = File.ReadAllText(path); string textData = File.ReadAllText(path);
language.SetStandardText(textData); language.SetStandardText(textData);
ShowNotification(language);
}
protected virtual void ShowNotification(Language language)
{
EditorWindow window = EditorWindow.GetWindow(typeof(FlowchartWindow), false, "Flowchart");
if (window != null)
{
window.ShowNotification(new GUIContent(language.notificationText));
language.notificationText = "";
}
} }
} }

27
Assets/Fungus/Flowchart/Scripts/Language.cs

@ -1,4 +1,7 @@
using UnityEngine; using UnityEngine;
#if UNITY_EDITOR
using UnityEditor;
#endif
using System; using System;
using System.Collections; using System.Collections;
using System.Collections.Generic; using System.Collections.Generic;
@ -35,6 +38,12 @@ namespace Fungus
*/ */
public TextAsset localizationFile; public TextAsset localizationFile;
/**
* Stores any notification message from export / import methods.
*/
[NonSerialized]
public string notificationText = "";
public virtual void Start() public virtual void Start()
{ {
if (activeLanguage.Length > 0 && if (activeLanguage.Length > 0 &&
@ -102,7 +111,7 @@ namespace Fungus
rowCount++; rowCount++;
} }
Debug.Log("Exported " + rowCount + " localization text items."); notificationText = "Exported " + rowCount + " localization text items.";
return csvData; return csvData;
} }
@ -364,6 +373,10 @@ namespace Fungus
if (say.itemId == itemId && if (say.itemId == itemId &&
say.storyText != newText) say.storyText != newText)
{ {
#if UNITY_EDITOR
Undo.RecordObject(say, "Set Text");
#endif
say.storyText = newText; say.storyText = newText;
return true; return true;
} }
@ -393,6 +406,10 @@ namespace Fungus
if (menu.itemId == itemId && if (menu.itemId == itemId &&
menu.text != newText) menu.text != newText)
{ {
#if UNITY_EDITOR
Undo.RecordObject(menu, "Set Text");
#endif
menu.text = newText; menu.text = newText;
return true; return true;
} }
@ -416,6 +433,10 @@ namespace Fungus
if (character != null && if (character != null &&
character.nameText != newText) character.nameText != newText)
{ {
#if UNITY_EDITOR
Undo.RecordObject(character, "Set Text");
#endif
character.nameText = newText; character.nameText = newText;
return true; return true;
} }
@ -449,7 +470,7 @@ namespace Fungus
rowCount++; rowCount++;
} }
Debug.Log("Exported " + rowCount + " standard text items."); notificationText = "Exported " + rowCount + " standard text items.";
return textData; return textData;
} }
@ -512,7 +533,7 @@ namespace Fungus
} }
} }
Debug.Log("Updated " + updatedCount + " standard text items."); notificationText = "Updated " + updatedCount + " standard text items.";
} }
} }

Loading…
Cancel
Save