Skip to content
This repository has been archived by the owner on Sep 18, 2023. It is now read-only.

Commit

Permalink
Bugfix: Can't edit character messages outside scene.
Browse files Browse the repository at this point in the history
Bugfix: Is necessary setting the Resources path manually.
Messages Manager is now scrolling!
  • Loading branch information
brunurd committed Feb 9, 2017
1 parent 56b7c2f commit 753eb46
Show file tree
Hide file tree
Showing 6 changed files with 52 additions and 36 deletions.
37 changes: 23 additions & 14 deletions Diplomata/Character.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,19 +31,22 @@ public class CharacterEditor : Editor {
SerializedProperty attributes;
SerializedProperty description;
SerializedProperty startOnPlay;

public static void SetCharacter(Character character) {
CharacterEditor.character = character;
}
SerializedProperty path;

public void OnEnable() {
attributes = serializedObject.FindProperty("attributes");
description = serializedObject.FindProperty("description");
startOnPlay = serializedObject.FindProperty("startOnPlay");
path = serializedObject.FindProperty("characterPath");

if (GameObject.Find(serializedObject.targetObject.name) != null) {
GameObject obj = GameObject.Find(serializedObject.targetObject.name);
character = obj.GetComponent<Character>();
}
attributes = serializedObject.FindProperty("attributes");
description = serializedObject.FindProperty("description");
startOnPlay = serializedObject.FindProperty("startOnPlay");

else {
character = (Character)AssetDatabase.LoadAssetAtPath(path.stringValue,typeof(Character));
}
}

public override void OnInspectorGUI() {
Expand Down Expand Up @@ -103,22 +106,17 @@ public class Character : MonoBehaviour {
private Message currentMessage;
private List<Message> currentChoices = new List<Message>();
private Events events;
public string characterPath;

public void Awake() {
InstantiateManager();
SetAttributes();
#if (UNITY_EDITOR)
CharacterEditor.SetCharacter(this);
#endif
}

public void Start() {
events = GetComponent<Events>();
events.SetCharacter(this);
#if (UNITY_EDITOR)
CharacterEditor.SetCharacter(this);
#endif


InstantiateManager();

talking = false;
Expand Down Expand Up @@ -302,5 +300,16 @@ public void SetInfluence() {
influence = (byte)tempInfluence;
}

public void Update() {
#if (UNITY_EDITOR)
if (characterPath == "" || characterPath == null) {
if (System.IO.File.Exists(AssetDatabase.GetAssetPath(PrefabUtility.GetPrefabParent(this)))) {
characterPath = AssetDatabase.GetAssetPath(PrefabUtility.GetPrefabParent(this));
PrefabUtility.ReplacePrefab(gameObject, PrefabUtility.GetPrefabParent(this), ReplacePrefabOptions.ConnectToPrefab);
}
}
#endif
}

}
}
12 changes: 3 additions & 9 deletions Diplomata/Editor/Preferences.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,16 +30,14 @@ static public void Init() {
GetPrefsStrings();

Preferences window = (Preferences)GetWindow(typeof(Preferences), false, "Preferences");
window.minSize = new Vector2(455,250);
window.Show();
}

public void OnGUI() {

int margin = 15;

GUILayout.Space(margin);
GUILayout.Label(Diplomata.Manager.logo, GUILayout.Width(Screen.width - 30), GUILayout.Height(30));

GUILayout.Space(margin);
GUILayout.BeginHorizontal();
GUILayout.BeginVertical(GUILayout.Width(Screen.width / 3 - 5));
Expand Down Expand Up @@ -94,11 +92,6 @@ public void OnGUI() {
SetPrefsStrings();
Diplomata.Manager.UpdatePreferences();
}
GUILayout.Space(margin);
GUILayout.Label("Diplomata Resources path: ");
resPath = GUILayout.TextField(resPath);

GUILayout.Space(margin);
}

public string[] ListToStringArray(List<string> list) {
Expand All @@ -113,12 +106,13 @@ public string[] ListToStringArray(List<string> list) {

public static void LoadJson() {
TextAsset json = (TextAsset)Resources.Load("preferences");
resPath = AssetDatabase.GetAssetPath(json);
preferences = JsonUtility.FromJson<Diplomata.Preferences>(json.text);
}

public void SaveJson() {
string json = JsonUtility.ToJson(preferences);
using (FileStream fs = new FileStream(resPath + "preferences.json", FileMode.Create)) {
using (FileStream fs = new FileStream(resPath, FileMode.Create)) {
using (StreamWriter writer = new StreamWriter(fs)) {
writer.Write(json);
}
Expand Down
Binary file modified Diplomata/Example/Example.prefab
Binary file not shown.
37 changes: 25 additions & 12 deletions Diplomata/MessageManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,24 +9,29 @@ namespace Diplomata {

public class MessageManager : EditorWindow {

public readonly static int headerSize = 62;
private readonly static int colunmLimit = 100;
private readonly static int rowLimit = 100;
private readonly static int windowContentWidth = colunmLimit * 170;
private readonly static int windowContentHeight = headerSize + (rowLimit * 135);

public static Character character;
private readonly Color bgColor1 = new Color(0.085f, 0.085f, 0.085f);
private readonly Color bgColor2 = new Color(0.125f, 0.125f, 0.125f);
private GUIStyle bgStyle;
public static List<List<Node>> colunms;
public static int headerSize = 62;
public static List<string> languages;
public static string[] languagesArray;
public static int languageIndex;
public static GUIStyle style;
public static bool close;
public Vector2 scrollPos;

static public void Init(Character character) {
close = false;
style = new GUIStyle();
MessageManager.character = character;
Manager.UpdatePreferences();
//character.messages = new List<Message>();
SetLanguages();
ResetColunms();
MessageManager window = (MessageManager)GetWindow(typeof(MessageManager), false, "Messages", true);
Expand Down Expand Up @@ -104,13 +109,17 @@ public static void ResetColunms() {

// Last add node in every colunm
for (int i = 0; i <= colunmsMax; i++) {
colunms[i].Add(new Node(i,colunms[i].Count,character));
if (colunms[i].Count < rowLimit) {
colunms[i].Add(new Node(i, colunms[i].Count, character));
}
}

// Add node in last colunm
if (character.messages.Count > 0) {
colunms.Add(new List<Node>());
colunms[colunms.Count - 1].Add(new Node(colunmsMax + 1, 0, character));
if (colunms.Count < colunmLimit) {
colunms.Add(new List<Node>());
colunms[colunms.Count - 1].Add(new Node(colunmsMax + 1, 0, character));
}
}

// Add node in first colunm
Expand All @@ -123,14 +132,14 @@ public static void ResetColunms() {
public void DrawBG() {
bool turn = false;
Color textColor;
for (int i = 0; i < 1700; i += 170) {
for (int i = 0; i < windowContentWidth; i += 170) {
if (turn) {
EditorGUI.DrawRect(new Rect(i, headerSize - 30, 170, Screen.height), bgColor2);
EditorGUI.DrawRect(new Rect(i, headerSize - 30, 170, windowContentHeight), bgColor2);
textColor = new Color(0.325f, 0.325f, 0.325f);
turn = false;
}
else {
EditorGUI.DrawRect(new Rect(i, headerSize - 30, 170, Screen.height), bgColor1);
EditorGUI.DrawRect(new Rect(i, headerSize - 30, 170, windowContentHeight), bgColor1);
textColor = new Color(0.285f, 0.285f, 0.285f);
turn = true;
}
Expand All @@ -155,11 +164,15 @@ public void DrawHeader() {
public void OnGUI() {
Character characterTemp = character;
int indexTemp = languageIndex;

EditorGUILayout.BeginScrollView(new Vector2(0,0));

DrawBG();
DrawHeader();

scrollPos = GUI.BeginScrollView(
new Rect(0, headerSize - 30, Screen.width, Screen.height - headerSize + 8),
scrollPos,
new Rect(0, headerSize - 30, windowContentWidth, windowContentHeight));

DrawBG();

if (languageIndex != indexTemp) {
Manager.UpdatePreferences();
Expand Down Expand Up @@ -193,7 +206,7 @@ public void OnGUI() {
}
}

EditorGUILayout.EndScrollView();
GUI.EndScrollView();

if (close) {
this.Close();
Expand Down
Binary file modified Diplomata/Resources/Diplomata.prefab
Binary file not shown.
2 changes: 1 addition & 1 deletion Diplomata/Resources/preferences.json
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{"attributes":["fear","politeness","argumentation","insistence","charm","confidence"],"subLanguages":["en-US"],"dubLanguages":["en-US"]}
{"attributes":["fear","politeness","argumentation","insistence","charm","confidence"],"subLanguages":["pt-BR","en-US"],"dubLanguages":["Dibberish"]}

0 comments on commit 753eb46

Please sign in to comment.