From 881e539602cd0519f264459583cd26da2d289d3a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Romain=20Pell=C3=A9?= Date: Sun, 25 Jan 2015 16:00:11 +0100 Subject: [PATCH] =?UTF-8?q?Correction=20de=20l'API=20pour=20la=20fen=C3=AA?= =?UTF-8?q?tre=20de=20ChatWindow?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit deux méthodes publiques implémentées: writeDay: écrit les jours, appelées depuis DayController.cs writeMessage: écrit les messages, appelées depuis TchatAnim.cs Ajout de balise de style via les balises RichText. --- Assets/scene.unity | 2 +- Assets/scripts/ChatWindow.cs | 33 +++++++++++++++++++++++++++------ Assets/scripts/DayController.cs | 4 ++-- Assets/scripts/TchatAnim.cs | 12 ++++++++++++ 4 files changed, 42 insertions(+), 9 deletions(-) diff --git a/Assets/scene.unity b/Assets/scene.unity index 9e1f0ee..fcfb447 100644 --- a/Assets/scene.unity +++ b/Assets/scene.unity @@ -28527,7 +28527,7 @@ MonoBehaviour: m_Name: m_EditorClassIdentifier: machine: {fileID: 2130265911} - maxDay: 30 + maxDay: 10 maxNight: 5 maxKilling: 15 --- !u!1 &2136149714 diff --git a/Assets/scripts/ChatWindow.cs b/Assets/scripts/ChatWindow.cs index 4c8fa2c..1695611 100644 --- a/Assets/scripts/ChatWindow.cs +++ b/Assets/scripts/ChatWindow.cs @@ -7,15 +7,15 @@ public class ChatWindow : MonoBehaviour { public Text text_chat; public ScrollRect scrollrect; - GameObject chat_input; - TchatAnim tchatAnim; + //GameObject chat_input; + //TchatAnim tchatAnim; string message_old; // Use this for initialization void Start () { - chat_input = GameObject.Find ("tchat_complet"); - tchatAnim = chat_input.GetComponent (); + //chat_input = GameObject.Find ("tchat_complet"); + //tchatAnim = chat_input.GetComponent (); text_chat.text = ""; @@ -25,20 +25,41 @@ public class ChatWindow : MonoBehaviour { void Update () { - + /* a supp une fois le nouveau système de message fonctionelle if (Input.GetKeyDown ("space") && tchatAnim.message != message_old) { scrollrect.verticalNormalizedPosition = 0; text_chat.text += "perceval > " + tchatAnim.message + "\n"; message_old= tchatAnim.message; - } + }*/ } + + + //permet d'écrire du texte en brut dans la fenetre de chat. Sans style. A priori, ne doit pas etre utilisé... public void writeText(string text){ text_chat.text += text; } + //prend en arguement le nombre de jour écoulé pour l'afficher dans la fenetre de chat. + public void writeDay(int nbDay){ + + text_chat.text += "\n\n\n Day " + nbDay.ToString() + "\n" ; + scrollrect.verticalNormalizedPosition = 0; + + } + + //prend en argument le pseudo et le message reçu par TchatAnim.cs et l'inscrit dans la fenetre. + public void writeMessage(string nom, string message){ + + text_chat.text += "" + nom + ": "+ message + "\n"; + scrollrect.verticalNormalizedPosition = 0; + + } + + // TODO: rédiger des fonctions pour afficher les morts, les deconnections et certains évènement importants. + } diff --git a/Assets/scripts/DayController.cs b/Assets/scripts/DayController.cs index 73f0a1d..ccb2627 100644 --- a/Assets/scripts/DayController.cs +++ b/Assets/scripts/DayController.cs @@ -32,7 +32,7 @@ public class DayController : MonoBehaviour { chatWindow = chatWindowScroll.GetComponent (); dayNb = 1; - chatWindow.writeText("\n\n\n JOUR 1 \n"); + chatWindow.writeDay (dayNb); } @@ -80,7 +80,7 @@ public class DayController : MonoBehaviour { dayNb ++; string message = "\n\n\n JOUR "+ dayNb.ToString()+"\n"; - chatWindow.writeText(message); + chatWindow.writeDay(dayNb); print("le jour se lève, discutez!"); } diff --git a/Assets/scripts/TchatAnim.cs b/Assets/scripts/TchatAnim.cs index 3ffc963..b454032 100644 --- a/Assets/scripts/TchatAnim.cs +++ b/Assets/scripts/TchatAnim.cs @@ -13,11 +13,21 @@ public class TchatAnim : MonoBehaviour { int max_timer; public string message; + //appel de Window Chat + GameObject chatWindowScroll; + ChatWindow chatWindow; + + // Use this for initialization void Start () { timer_sec = 0; max_timer = 15; + + //appel de Window Chat + chatWindowScroll = GameObject.Find ("ChatWindowScroll"); + chatWindow = chatWindowScroll.GetComponent (); + } @@ -30,6 +40,7 @@ public class TchatAnim : MonoBehaviour { void Update () { + //print (machine.GetInteger("etat_chat")); if (myfield.isFocused) { img_bg.color = Color.green; @@ -82,6 +93,7 @@ public class TchatAnim : MonoBehaviour { //En cas de validation du message if(Input.GetKeyDown("space") && myfield.isFocused){ + chatWindow.writeMessage("perceval",myfield.text); myfield.gameObject.SetActive(false); myfield.text=" "; charac_nb.text="";