/// <summary> /// Process dialog events /// </summary> public void ProcessDialogEvent(string eventId, string param) { if(gameObject.activeSelf == false || eventId == null || eventId.Length == 0) return; // Debug.Log ("eventId : " + eventId); // Debug.Log ("storyId : " + storyId); if(storyId == null || !eventId.StartsWith(storyId)) return; // Debug.Log ("Save last "); lastEventID = eventId; lastParam = param; if(param == "show") { UIDialog d = ui.GetDialog(eventId); //protect from too ealry or late process, //when dialog might not exist anymore if(d != null) { //// Log.Debug(gameObject.transform.parent.name+" SHOW Dialog:"+d.Id+","+d.Type); //for debug only lastId = d.Id; //get text, check type and show the right bubble/mc // // Log.GameTimes("Character "+d.CharacterImage.ToString()); SpeechBubble bubble = GetBubble(d.CharacterImage); //show debug info for bubble if(GameManager.Instance.debugMode) bubble.DebugText = d.Id; else bubble.DebugText = ""; switch(d.Type) { case DialogType.BUBBLE: if(d.CharacterImage == "Player") { //hide multi if(popup != null) popup.SetActive(false); uiCharacter = (UICharacter)ui.ActiveScreen.GetObject(d.CharacterImage); //// Log.Debug("d.CharImg:"+d.CharacterImage+" uiCharacter="+uiCharacter); if(uiCharacter != null) { d.Emotion = uiCharacter.Emotion; //set to settings from character bubble.gameObject.transform.position = uiCharacter.GameObject.transform.position + uiCharacter.bubblePosition; bubble.gameObject.transform.localScale = uiCharacter.bubbleScale; bubble.SetTail(uiCharacter.bubbleTail); //// Log.Debug("emotion: "+d.Emotion); } else { //set position bubble.gameObject.transform.position = defPlayerBubblePosition; bubble.gameObject.transform.localScale = defPlayerBubbleScale; } //d.Emotion = emotion; playerDialog = d; bubble.SetActive(true); bubble.Text = playerDialog.Text; bubble.Id = playerDialog.Id; bubble.Name = ""; } else { //set emotion level and bubble position for character UIObject obj = ui.ActiveScreen.GetObject(d.CharacterImage); if (obj.GetType() == UIType.Character) { UICharacter uiCharacter = (UICharacter)obj; //// Log.Debug("d.CharImg:"+d.CharacterImage+" uiCharacter="+uiCharacter); if(uiCharacter != null) { //uiCharacter.Visible = true; //d.Emotion = uiCharacter.Emotion; UICharacter player = (UICharacter)ui.ActiveScreen.GetObject("Player"); if(uiCharacter.Name.StartsWith("Engineer.") || uiCharacter.Name.StartsWith("CityHall.")) { d.Emotion = uiCharacter.Emotion; } else if(player.Emotion != EmotionType.NEUTRAL) { d.Emotion = player.Emotion; uiCharacter.Emotion = player.Emotion; } else { d.Emotion = EmotionType.NEUTRAL; uiCharacter.Emotion = EmotionType.NEUTRAL; } if(uiCharacter.Name == "ArtistCommunity.ArtistGirl") { UICharacter uiCharacterArtist = (UICharacter)ui.ActiveScreen.GetObject("ArtistBoy"); uiCharacterArtist.Emotion = uiCharacter.Emotion; } else if(uiCharacter.Name == "ArtistCommunity.ArtistBoy") { UICharacter uiCharacterArtist = (UICharacter)ui.ActiveScreen.GetObject("ArtistGirl"); uiCharacterArtist.Emotion = uiCharacter.Emotion; } //set to settings from character bubble.gameObject.transform.position = uiCharacter.GameObject.transform.position + uiCharacter.bubblePosition; bubble.gameObject.transform.localScale = uiCharacter.bubbleScale; bubble.SetTail(uiCharacter.bubbleTail); //// Log.Debug("--------------- TAIL"+uiCharacter.bubbleTail); } } else if (obj.GetType() == UIType.Skit) { skit = (UISkit)obj; if(skit != null) { skit.Show(); bubble.gameObject.transform.position = skit.GameObject.transform.position + skit.bubblePosition; bubble.gameObject.transform.localScale = skit.bubbleScale; bubble.SetTail(skit.bubbleTail); } } else { //set to defaults bubble.gameObject.transform.position = defNpcBubblePosition; bubble.gameObject.transform.localScale = defNpcBubbleScale; } //show and set emotion level npcDialog = d; bubble.SetActive(true); bubble.Text = d.Text; bubble.Name = d.CharacterName; bubble.Id = d.Id; } break; case DialogType.MULTICHOICE: if(d.CharacterImage != "Player") { // Log.Error("Only Player can have multichoice dialog: "+d.Id); return; } //hide player bubble.SetActive(false); playerDialog = d; popup.SetActive(true); UIManager.Instance.ShowModal(popup); ArrayList index = new ArrayList(new int[] {0, 1, 2}); int[] order = new int[3]; if (!GameManager.Instance.debugMode) { for (int i = 0; i < 3; i++) { int rnd = Random.Range(0, index.Count); order[i] = (int)index[rnd]; index.RemoveAt(rnd); } } else { order[0] = 0; order[1] = 1; order[2] = 2; } neutralButton.transform.position = multichoicePositions[order[0]]; negativeButton.transform.position = multichoicePositions[order[1]]; positiveButton.transform.position = multichoicePositions[order[2]]; neutralText.Text = playerDialog.GetText(EmotionType.NEUTRAL); positiveText.Text = playerDialog.GetText(EmotionType.POSITIVE); negativeText.Text = playerDialog.GetText(EmotionType.NEGATIVE); break; } } } else if(param == "hide") { // Log.Info(gameObject.transform.parent.name+" DialogView HIDE "+type+" event:"+eventId); if (skit != null) { skit.Hide(); skit = null; } if(npcDialog != null && eventId == npcDialog.Id) { SpeechBubble bubble = GetBubble(npcDialog.CharacterImage); bubble.SetActive(false); npcDialog = null; } else if(playerDialog != null && eventId == playerDialog.Id) { if(playerDialog.Type == DialogType.BUBBLE) { SpeechBubble bubble = GetBubble("Player"); bubble.SetActive(false); } else popup.SetActive(false); playerDialog = null; } } }