/// <summary> /// Populates and returns a data package suitable for TopicUI. Returns null if a problem. /// </summary> /// <param name="item"></param> /// <returns></returns> private TopicUIData GetTopicData(TutorialItem item) { if (item != null) { int index, limit, count; //data package TopicUIData data = new TopicUIData(); data.topicName = item.tag; data.header = item.query.queryHeader; data.text = item.query.queryText; data.isBoss = false; data.nodeID = -1; data.uiType = TopicDecisionType.Tutorial; data.spriteMain = GameManager.i.tutorialScript.tutorial.sprite; data.ignoreTooltipHeader = string.Format("<size=120%>{0}</size>", GameManager.Formatt("Disappointed", ColourType.badText)); data.ignoreTooltipMain = "Yes, I am. Being able to make a decision is important, what's wrong with you?"; data.ignoreTooltipDetails = string.Format("<size=115%>{0}</size>", GameManager.Formatt("I'll have to make it for you", ColourType.neutralText)); if (item.query.queryType != null) { //query item type GameManager.i.tutorialScript.queryType = item.query.queryType; //Topic options TopicOption[] arrayOfTopicOptions = GameManager.i.tutorialScript.tutorial.arrayOfOptions; if (arrayOfTopicOptions != null) { //ignore option TopicOption ignoreOption = GameManager.i.tutorialScript.tutorial.ignoreOption; if (ignoreOption != null) { //check there are four options and none are null if (arrayOfTopicOptions.Length == maxOptions) { bool isProceed = true; for (int i = 0; i < arrayOfTopicOptions.Length; i++) { if (arrayOfTopicOptions[i] == null) { Debug.LogErrorFormat("Invalid topicOption (Null) for tutorial \"{0}\" arrayOfTopicOptions[{1}]", GameManager.i.tutorialScript.tutorial.name, i); isProceed = false; } } if (isProceed == true) { //Tutorial options List <TutorialOption> listOfTutorialOptions = new List <TutorialOption>(); List <TutorialOption> listOfTutorialIgnoreOptions = new List <TutorialOption>(); //special cases where an Alt set of options may be needed switch (item.query.queryType.name) { case "Name": switch (GameManager.i.playerScript.sex) { case ActorSex.Male: listOfTutorialOptions = item.query.listOfOptions; listOfTutorialIgnoreOptions = item.query.listOfIgnoreOptions; break; case ActorSex.Female: listOfTutorialOptions = item.query.listOfOptionsAlt; listOfTutorialIgnoreOptions = item.query.listOfIgnoreOptionsAlt; break; default: Debug.LogWarningFormat("Unrecognised ActorSex \"{0}\"", GameManager.i.playerScript.sex); break; } break; default: listOfTutorialOptions = item.query.listOfOptions; listOfTutorialIgnoreOptions = item.query.listOfIgnoreOptions; break; } count = listOfTutorialOptions.Count; //create temp list by Value (will be deleting List <TutorialOption> listOfTempOptions = new List <TutorialOption>(listOfTutorialOptions) { }; // - - - RANDOM if (item.query.isRandomOptions == true) { limit = Mathf.Min(maxOptions, count); //select up to four tutorial options randomly for (int i = 0; i < limit; i++) { index = Random.Range(0, listOfTempOptions.Count); TutorialOption optionTutorial = listOfTempOptions[index]; if (optionTutorial != null) { //Get Topic options TopicOption optionTopic = arrayOfTopicOptions[i]; optionTopic.tag = optionTutorial.tag; optionTopic.textToDisplay = GameManager.i.topicScript.GetOptionString(optionTutorial.text); data.listOfOptions.Add(optionTopic); listOfTempOptions.RemoveAt(index); } else { Debug.LogWarningFormat("Invalid tutorialOption (Null) for isRandom listOfTempOptions[{0}]", index); } } } else { // - - - NOT random, take first four options limit = Mathf.Min(maxOptions, count); for (int i = 0; i < limit; i++) { TutorialOption optionTutorial = listOfTempOptions[i]; if (optionTutorial != null) { TopicOption optionTopic = arrayOfTopicOptions[i]; optionTopic.tag = optionTutorial.tag; optionTopic.textToDisplay = GameManager.i.topicScript.GetOptionString(optionTutorial.text); data.listOfOptions.Add(optionTopic); } else { Debug.LogWarningFormat("Invalid topicOption (Null) for normal listOfTempOptions[{0}]", i); } } } //IGNORE option if (listOfTutorialIgnoreOptions != null) { //needs to be one option (can be more but they are ignored) if (listOfTutorialIgnoreOptions.Count >= 1) { TutorialOption optionTutorial = listOfTutorialIgnoreOptions[0]; if (optionTutorial != null) { data.listOfIgnoreEffects.Add(ignoreOption.listOfGoodEffects[0]); //ignore option data GameManager.i.tutorialScript.optionIgnoreTag = optionTutorial.tag; } else { Debug.LogWarning("Invalid topicOption (Null) for IGNORE listOfTempOptions[0]"); } } else { Debug.LogWarningFormat("Invalid listOfIgnoreOptions (Empty) for topicItem \"{0}\"", item.name); } } else { Debug.LogWarningFormat("Invalid listOfIgnoreOptions (Null) for topicItem \"{0}\"", item.name); } //option tooltips and optionNumber (ignore option done above) for (index = 0; index < data.listOfOptions.Count; index++) { TopicOption option = data.listOfOptions[index]; if (option != null) { option.tooltipHeader = string.Format("<size=120%>{0}</size>", GameManager.Formatt(option.tag, ColourType.neutralText)); option.tooltipMain = GameManager.i.tutorialScript.GetTutorialTooltip(item.query.queryType); //reassign option number to be the position in the listOfOptions option.optionNumber = index; //set all options as Valid option.isValid = true; //copy data across to TutorialManager.cs fields switch (index) { case 0: GameManager.i.tutorialScript.option0Tag = option.tag; break; case 1: GameManager.i.tutorialScript.option1Tag = option.tag; break; case 2: GameManager.i.tutorialScript.option2Tag = option.tag; break; case 3: GameManager.i.tutorialScript.option3Tag = option.tag; break; default: Debug.LogWarningFormat("Invalid index \"{0}\"", index); break; } } else { Debug.LogWarningFormat("Invalid topicOption (Null) for data.listOfOptions[{0}]", index); } } } return(data); } else { Debug.LogErrorFormat("Invalid arrayOfTopicOptions (records, has {0}, needs {1}) for tutorial \"{2}\"", arrayOfTopicOptions.Length, maxOptions, GameManager.i.tutorialScript.tutorial.name); } } else { Debug.LogErrorFormat("Invalid ignoreOption (Null) for tutorial \"{0}\"", GameManager.i.tutorialScript.tutorial.name); } } else { Debug.LogError("Invalid tutorial.arrayOfOptions (Null)"); } } else { Debug.LogWarning("Invalid (Tutorial) item (Null)"); } } else { Debug.LogErrorFormat("Invalid queryType (Null) for TutorialItem \"{0}\"", item.name); } //fault condition return(null); }
/// <summary> /// Tutorial button on RHS clicked, open up relevant tutorial UI based on supplied item /// </summary> /// <param name="item"></param> private void OpenTutorialItem(int index = -1) { //flush input buffer Input.ResetInputAxes(); if (GameManager.i.inputScript.ModalState == ModalState.Normal) { if (index > -1) { //get tutorialItem if (index < listOfSetItems.Count) { currentItem = listOfSetItems[index]; if (currentItem != null) { //switch off all arrows for (int i = 0; i < numOfItems; i++) { listOfInteractions[i].arrowImage.gameObject.SetActive(false); } //display arrow next to selected + 1 tutorial button (shows the next one you need to click on) if (index + 1 < numOfItems) { listOfInteractions[index + 1].arrowImage.gameObject.SetActive(true); } //what type of item switch (currentItem.tutorialType.name) { case "Dialogue": //open special outcome window ModalOutcomeDetails details = new ModalOutcomeDetails() { side = GameManager.i.sideScript.PlayerSide, textTop = GameManager.Formatt(currentItem.dialogue.topText, ColourType.moccasinText), textBottom = currentItem.dialogue.bottomText, sprite = GameManager.i.tutorialScript.tutorial.sprite, isAction = false, isSpecial = true, isSpecialGood = true }; EventManager.i.PostNotification(EventType.OutcomeOpen, this, details); break; case "Goal": GameManager.i.tutorialScript.UpdateGoal(currentItem.goal); //change colour to completed (indicates that you're currently doing, or have done, the goal) ColorBlock goalColours = listOfButtons[index].colors; goalColours.normalColor = colourCompleted; listOfButtons[index].colors = goalColours; break; case "Information": EventManager.i.PostNotification(EventType.GameHelpOpen, this, currentItem.gameHelp); break; case "Query": /* * if (currentItem.isQueryDone == false) * { * TopicUIData data = GetTopicData(currentItem); * if (data != null) * { EventManager.i.PostNotification(EventType.TopicDisplayOpen, this, data); } * //change colour to completed (indicates that you're currently doing, or have done, the query) * ColorBlock itemColours = listOfButtons[index].colors; * itemColours.normalColor = colourCompleted; * listOfButtons[index].colors = itemColours; * } * else * { * //query has already been done * ModalOutcomeDetails detailsDone = new ModalOutcomeDetails() * { * side = GameManager.i.sideScript.PlayerSide, * textBottom = "Haven't we already covered that?<br><br>I must be having a <b>Senior Moment</b>", * sprite = GameManager.i.tutorialScript.tutorial.sprite, * isAction = false, * isSpecial = true, * isSpecialGood = false * }; * if (string.IsNullOrEmpty(currentItem.queryHeader) == false) * { detailsDone.textTop = GameManager.Formatt(currentItem.queryHeader, ColourType.moccasinText); } * else * { * detailsDone.textTop = GameManager.Formatt("I beg your pardon", ColourType.moccasinText); * Debug.LogWarningFormat("Invalid queryHeader (Null or Empty) for \"{0}\"", currentItem.name); * } * //special outcome * EventManager.i.PostNotification(EventType.OutcomeOpen, this, detailsDone); * }*/ TopicUIData data = GetTopicData(currentItem); if (data != null) { EventManager.i.PostNotification(EventType.TopicDisplayOpen, this, data); } /*//change colour to completed (indicates that you're currently doing, or have done, the query) * ColorBlock itemColours = listOfButtons[index].colors; * itemColours.normalColor = colourCompleted; * listOfButtons[index].colors = itemColours;*/ break; default: Debug.LogWarningFormat("Unrecognised item.TutorialType \"{0}\"", currentItem.tutorialType.name); break; } } else { Debug.LogWarningFormat("Invalid currentItem (tutorial) (Null)"); } } else { Debug.LogWarningFormat("Invalid index (is {0}, listOfSetItems.Count is {1})", index, listOfSetItems.Count); } } else { Debug.LogWarning("Invalid index (button.buttonInteraction.returnValue (-1)"); } } }