/// <summary> /// Add a dialog to available list /// </summary> public void AddDialog(UIDialog dialog) { if(!dialogs.ContainsKey(dialog.Id)) { Log.Debug("ADD dialog:"+dialog.Id); dialogs.Add(dialog.Id, dialog); } }//AddDialog()
//------------------------------------------------------------------------------ /// <summary> /// Fire this trigger. /// </summary> public override bool Fire() { //Log.Debug("fire:"+id); //call function(s) if Fire allowed if(base.Fire()) { //TODO: send trigger event to UI or register delegate from UI? //// Log.Debug("----> Dialog:"+id+" fired event:"+trigger+","+emotion); // //create Dialog model and send event UIDialog d = new UIDialog(id, dialogtype, screenId, characterImage, characterName, characterVisible, texts, position, npcPosition); UIManager.Instance.AddDialog(d); GameManager.Instance.Event("DIALOG", fullId, "show"); //only if not multichoice, //when we need to wait for the selected item if(dialogtype != DialogType.MULTICHOICE) { if(triggerDelay == 0) { //wait for user action triggerDelayObject = null; //GameManager.Instance.Event(GameEvent.DIALOG, trigger, "fire"); } else { triggerDelayObject = DelayedCommand(triggerDelay, "trigger"); } if(deleteEventDelay > 0) { //TODO might need to add triggerDelay as well? deleteDelayObject = DelayedCommand(deleteEventDelay, "delete"); } } return true; } return false; }
/// <summary> /// Process multi choice answer. /// TODO this is just an example for now, we can later improve this /// score Logic /// </summary> public void ProcessDialogAnswer(UIDialog dialog, EmotionType answer) { if(dialog.Id == "D002") { //ProcessQuestion1(answer); } else if(dialog.Id == "D006") { // ProcessQuestion2(answer); } }
/// <summary> /// This function handle the dialogView answer from player. /// Need to override it in the screen script. /// </summary> public virtual void ProcessAnswer(UIDialog dialog, EmotionType answer) { Log.Warning("Please OVERRIDE ME!! in:"+gameObject.name); }
/// <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; } } }